1
0
mirror of https://github.com/ioacademy-jikim/debugging synced 2026-08-30 01:09:34 +00:00

first commit

This commit is contained in:
jikim
2015-12-13 22:34:58 +09:00
commit 0b589c7986
9455 changed files with 4350134 additions and 0 deletions
@@ -0,0 +1 @@
# dummy
@@ -0,0 +1 @@
# dummy
@@ -0,0 +1 @@
# dummy
@@ -0,0 +1 @@
# dummy
@@ -0,0 +1 @@
# dummy
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,38 @@
include $(top_srcdir)/Makefile.tool-tests.am
dist_noinst_SCRIPTS = filter_stderr
noinst_HEADERS = scalar.h
EXTRA_DIST = \
aio.stderr.exp aio.vgtest \
deep_badparam.stderr.exp deep_badparam.stdout.exp deep_badparam.vgtest \
env.stderr.exp env.vgtest \
ioctl-tiocsbrk.stderr.exp ioctl-tiocsbrk.vgtest \
pth-supp.stderr.exp pth-supp.vgtest \
pth-undocumented.stderr.exp pth-undocumented.stdout.exp pth-undocumented.vgtest \
mkfifo.stderr.exp mkfifo.vgtest \
scalar.stderr.exp scalar.vgtest \
scalar_fork.stderr.exp scalar_fork.vgtest \
scalar_nocancel.stderr.exp scalar_nocancel.vgtest \
scalar_vfork.stderr.exp scalar_vfork.vgtest
check_PROGRAMS = \
aio \
deep_badparam \
env \
ioctl-tiocsbrk \
pth-supp \
pth-undocumented \
mkfifo \
scalar \
scalar_fork \
scalar_nocancel \
scalar_vfork
AM_CFLAGS += $(AM_FLAG_M3264_PRI) $(FLAG_MMMX) $(FLAG_MSSE)
AM_CXXFLAGS += $(AM_FLAG_M3264_PRI) $(FLAG_MMMX) $(FLAG_MSSE)
AM_CCASFLAGS += $(AM_FLAG_M3264_PRI)
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,92 @@
#include <assert.h>
#include <aio.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int x;
int main(void)
{
#define LEN 10
char buf[LEN];
struct aiocb a;
struct sigevent s;
memset(&a, 0, sizeof(struct aiocb));
// Not sure if the sigevent is even looked at by aio_*... just zero it.
memset(&s, 0, sizeof(struct sigevent));
a.aio_fildes = -1;
a.aio_offset = 0;
a.aio_buf = NULL;
a.aio_nbytes = LEN;
a.aio_reqprio = 0;
a.aio_sigevent = s;
a.aio_lio_opcode = 0; // ignored
//------------------------------------------------------------------------
// The cases where aiocbp itself points to bogus memory is handled in
// memcheck/tests/darwin/scalar.c, so we don't check that here.
//------------------------------------------------------------------------
// XXX: This causes an unexpected undef value error later, at the XXX mark.
// Not sure why, it shouldn't.
// assert( aio_return(&a) < 0); // (aiocbp hasn't been inited)
//------------------------------------------------------------------------
assert( aio_read(&a) < 0); // invalid fd
//------------------------------------------------------------------------
a.aio_fildes = open("aio.c", O_RDONLY);
assert(a.aio_fildes >= 0);
assert( aio_read(&a) < 0); // unaddressable aio_buf
//------------------------------------------------------------------------
a.aio_buf = buf;
assert( aio_read(&a) == 0 );
assert( aio_read(&a) < 0 ); // (don't crash on the repeated &a)
while (0 != aio_error(&a)) { };
if (buf[0] == buf[9]) x++; // undefined -- aio_return() not called yet
assert( aio_return(&a) > 0 ); // XXX: (undefined value error here)
if (buf[0] == buf[9]) x++;
assert( aio_return(&a) < 0 ); // (repeated aio_return(); fails because
// Valgrind can't find &a in the table)
//------------------------------------------------------------------------
a.aio_buf = 0;
a.aio_fildes = creat("mytmpfile", S_IRUSR|S_IWUSR);
assert(a.aio_fildes >= 0);
assert( aio_write(&a) < 0); // unaddressable aio_buf
//------------------------------------------------------------------------
a.aio_buf = buf;
assert( aio_write(&a) == 0 );
assert( aio_write(&a) < 0 ); // (don't crash on the repeated &a)
while (0 != aio_error(&a)) { };
assert( aio_return(&a) > 0 );
assert( aio_return(&a) < 0 ); // (repeated aio_return(); fails because
// Valgrind can't find &a in the table)
unlink("mytmpfile");
return x;
};
@@ -0,0 +1,25 @@
Warning: invalid file descriptor -1 in syscall aio_read()
Syscall param aio_read(aiocbp->aio_buf) points to unaddressable byte(s)
at 0x........: aio_read (in /...libc...)
by 0x........: main (aio.c:45)
Address 0x........ is not stack'd, malloc'd or (recently) free'd
Conditional jump or move depends on uninitialised value(s)
at 0x........: main (aio.c:56)
Syscall param aio_write(aiocbp->aio_buf) points to unaddressable byte(s)
at 0x........: aio_write (in /...libc...)
by 0x........: main (aio.c:70)
Address 0x........ is not stack'd, malloc'd or (recently) free'd
HEAP SUMMARY:
in use at exit: ... bytes in ... blocks
total heap usage: ... allocs, ... frees, ... bytes allocated
For a detailed leak analysis, rerun with: --leak-check=full
For counts of detected and suppressed errors, rerun with: -v
Use --track-origins=yes to see where uninitialised values come from
ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)
@@ -0,0 +1,3 @@
prog: aio
vgopts: --leak-check=no
stderr_filter: ../filter_allocs
@@ -0,0 +1,41 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int func_six(int x)
{
char b[32];
int r = write(1, b, sizeof(b));
return x;
}
int func_five(int x)
{
return func_six(x + 5);
}
int func_four(int x)
{
return func_five(x + 4);
}
int func_three(int x)
{
return func_four(x + 3);
}
int func_two(int x)
{
return func_three(x + 2);
}
int func_one(int x)
{
return func_two(x + 1);
}
int main(void)
{
func_one(10);
return 0;
}
@@ -0,0 +1,12 @@
Syscall param write(buf) points to uninitialised byte(s)
...
by 0x........: func_six (deep_badparam.c:8)
by 0x........: func_five (deep_badparam.c:14)
by 0x........: func_four (deep_badparam.c:19)
by 0x........: func_three (deep_badparam.c:24)
by 0x........: func_two (deep_badparam.c:29)
by 0x........: func_one (deep_badparam.c:34)
by 0x........: main (deep_badparam.c:39)
Address 0x........ is on thread 1's stack
in frame #1, created by func_six (deep_badparam.c:6)
@@ -0,0 +1,2 @@
prog: deep_badparam
vgopts: -q
@@ -0,0 +1,31 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
// This tests that the suppression for the leak in setenv() works. See bug
// 188572.
int main(void)
{
char* val1 = "x";
char* val2 = "xx";
char* val3 = "xxx";
setenv("MYVAR", val1, /*overwrite*/0); // makes a copy which is later leaked
assert( 0 == strcmp(getenv("MYVAR"), val1) );
setenv("MYVAR", val2, /*overwrite*/1); // makes a copy which is later leaked
assert( 0 == strcmp(getenv("MYVAR"), val2) );
setenv("MYVAR", val3, /*overwrite*/0); // doesn't overwrite MYVAR=val2
assert( 0 == strcmp(getenv("MYVAR"), val2) );
putenv("MYVAR=xxxx"); // no leak for putenv()
assert( 0 == strcmp(getenv("MYVAR"), "xxxx") );
unsetenv("MYVAR");
assert( NULL == getenv("MYVAR") );
return 0;
}
@@ -0,0 +1,2 @@
prog: env
vgopts: -q --leak-check=full
@@ -0,0 +1,3 @@
#! /bin/sh
../filter_stderr "$@"
@@ -0,0 +1,14 @@
/* Tests for TIOCSBRK per https://bugs.kde.org/show_bug.cgi?id=208217
*/
#include <sys/ioctl.h>
int main(int argc, const char *argv[])
{
#ifdef TIOCSBRK
ioctl(1, TIOCSBRK, 0);
ioctl(1, TIOCCBRK, 0);
#endif
return 0;
}
@@ -0,0 +1,2 @@
prog: ioctl-tiocsbrk
vgopts: -q
@@ -0,0 +1,31 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <fcntl.h>
#ifndef SYS_mkfifo
# define SYS_mkfifo 132
#endif
static char f_name[]="mkfifo_data_file";
int mkfifo(const char *path)
{
return syscall(SYS_mkfifo, path);
}
int main(void)
{
int fd;
fd = mkfifo(f_name);
if (fd == -1)
perror("mkfifo"), exit(1);
unlink(f_name);
return 0;
}
@@ -0,0 +1,2 @@
prog: mkfifo
vgopts: -q
@@ -0,0 +1,9 @@
// This requires a suppression (macos-Cond-6). Bug 196528.
#include <pthread.h>
int main() {
pthread_rwlock_t mutex;
pthread_rwlock_init(&mutex, NULL);
return 0;
}
@@ -0,0 +1,2 @@
prog: pth-supp
vgopts: -q
@@ -0,0 +1,41 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <fcntl.h>
#ifndef SYS___pthread_chdir
# define SYS___pthread_chdir 348
#endif
#ifndef SYS___pthread_fchdir
# define SYS___pthread_fchdir 349
#endif
int __pthread_chdir(const char *path)
{
return syscall(SYS___pthread_chdir, path);
}
int __pthread_fchdir(int dirfd)
{
return syscall(SYS___pthread_fchdir, dirfd);
}
int main(void)
{
int dirfd;
dirfd = open("/", O_RDONLY);
if (dirfd == -1)
perror("open"), exit(1);
if (__pthread_chdir("/"))
perror("__pthread_chdir");
if (__pthread_fchdir(dirfd))
perror("__pthread_fchdir");
return 0;
}
@@ -0,0 +1,2 @@
prog: pth-undocumented
vgopts: -q
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,64 @@
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include "pub_tool_basics.h"
#include "vki/vki-scnums-darwin.h"
#include "pub_tool_vkiscnums.h"
// Since we use vki_unistd.h, we can't include <unistd.h>. So we have to
// declare this ourselves.
extern int syscall (int __sysno, ...);
// Thorough syscall scalar arg checking. Also serves as thorough checking
// for (very) basic syscall use. Generally not trying to do anything
// meaningful with the syscalls.
#define GO(__NR_xxx, N, s) \
fprintf(stderr, "-----------------------------------------------------\n" \
"x%lx(%d):%20s %s\n" \
"-----------------------------------------------------\n", \
(unsigned long)__NR_xxx, N, #__NR_xxx, s);
#define GO_UNIMP(n, s) \
fprintf(stderr, "-----------------------------------------------------\n" \
"%-17s%s\n" \
"-----------------------------------------------------\n", \
"("#n"): ", s);
#define SY(__NR_xxx, args...) res = syscall(__NR_xxx, ##args);
#define FAIL assert(-1 == res);
#define SUCC assert(-1 != res);
#define SUCC_OR_FAIL /* no test */
#define FAILx(E) \
do { \
int myerrno = errno; \
if (-1 == res) { \
if (E == myerrno) { \
/* as expected */ \
} else { \
fprintf(stderr, "Expected error %s (%d), got %d\n", #E, E, myerrno); \
exit(1); \
} \
} else { \
fprintf(stderr, "Expected error %s (%d), got success\n", #E, E); \
exit(1); \
} \
} while (0);
#define SUCC_OR_FAILx(E) \
do { \
int myerrno = errno; \
if (-1 == res) { \
if (E == myerrno) { \
/* as expected */ \
} else { \
fprintf(stderr, "Expected error %s (%d), got %d\n", #E, E, myerrno); \
exit(1); \
} \
} \
} while (0);
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,3 @@
prog: scalar
vgopts: -q --error-limit=no
args: < scalar.c
@@ -0,0 +1,12 @@
#include "scalar.h"
int main(void)
{
int res;
GO(__NR_fork, 2, "0e");
SY(__NR_fork);
return(0);
}
@@ -0,0 +1,3 @@
-----------------------------------------------------
x2000002(2): __NR_fork 0e
-----------------------------------------------------
@@ -0,0 +1,2 @@
prog: scalar_fork
vgopts: -q
@@ -0,0 +1,64 @@
#include "../../memcheck.h"
#include "scalar.h"
#include <unistd.h>
#include <sched.h>
#include <signal.h>
#include <sys/shm.h>
// See memcheck/tests/x86-linux/scalar.c for an explanation of what this test
// is doing.
int main(void)
{
// uninitialised, but we know px[0] is 0x0
long* px = malloc(sizeof(long));
long x0 = px[0];
long res;
VALGRIND_MAKE_MEM_NOACCESS(0, 0x1000);
// The nocancel syscalls all use the same wrappers as the corresponding
// non-nocancel syscall. This means that if we try to test both in the
// same file, the nocancel ones won't result in errors being generated
// because errors are too similar. So we test them in this separate file.
// __NR_read_nocancel 396
// __NR_write_nocancel 397
// __NR_open_nocancel 398
// __NR_close_nocancel 399
// __NR_wait4_nocancel 400
// __NR_recvmsg_nocancel 401
// __NR_sendmsg_nocancel 402
// __NR_recvfrom_nocancel 403
// __NR_accept_nocancel 404
// __NR_msync_nocancel 405
// __NR_fcntl_nocancel 406
// __NR_select_nocancel 407
// __NR_fsync_nocancel 408
// __NR_connect_nocancel 409
// __NR_sigsuspend_nocancel 410
GO(__NR_sigsuspend_nocancel, 410, "ignore");
// (I don't know how to test this...)
// __NR_readv_nocancel 411
// __NR_writev_nocancel 412
// __NR_sendto_nocancel 413
// __NR_pread_nocancel 414
// __NR_pwrite_nocancel 415
// __NR_waitid_nocancel 416
// __NR_poll_nocancel 417
// __NR_msgsnd_nocancel 418
// __NR_msgrcv_nocancel 419
// The error doesn't appear because it's a dup of the one from sem_wait.
GO(__NR_sem_wait_nocancel, 420, "1s 0m");
SY(__NR_sem_wait_nocancel, x0); FAIL;
// __NR_aio_suspend_nocancel 421
// __NR___sigwait_nocancel 422
// __NR___semwait_signal_nocancel 423
return 0;
}
@@ -0,0 +1,9 @@
-----------------------------------------------------
x200019a(410):__NR_sigsuspend_nocancel ignore
-----------------------------------------------------
-----------------------------------------------------
x20001a4(420):__NR_sem_wait_nocancel 1s 0m
-----------------------------------------------------
Syscall param sem_wait(sem) contains uninitialised byte(s)
...
@@ -0,0 +1,3 @@
prog: scalar_nocancel
vgopts: -q --error-limit=no
args: < scalar_nocancel.c
@@ -0,0 +1,13 @@
#include "scalar.h"
int main(void)
{
int res;
// __NR_vfork --> __NR_fork [we can't use vfork()]
GO(__NR_vfork, 66, "0e");
SY(__NR_vfork);
return(0);
}
@@ -0,0 +1,3 @@
-----------------------------------------------------
x2000042(66): __NR_vfork 0e
-----------------------------------------------------
@@ -0,0 +1,2 @@
prog: scalar_vfork
vgopts: -q