From 5e4455bffd7cd5c4a948ce7f7f4be9da55c67fb4 Mon Sep 17 00:00:00 2001 From: Juan Cespedes Date: Sun, 24 Aug 1997 01:48:26 +0200 Subject: Version 0.1.3 * Added options `-i', `-S' * Added syscall names * Added signal names * Added `output.c', `signal.c' --- Makefile | 2 +- TODO | 2 -- debian/changelog | 9 +++++++++ ltrace.1 | 6 ++++++ ltrace.c | 16 ++++++---------- ltrace.h | 4 +++- output.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ output.h | 3 +++ process.c | 18 +++++++++++++----- process.h | 2 ++ signal.c | 35 +++++++++++++++++++++++++++++++++++ signal.h | 1 + syscall.c | 24 ++++++++++++------------ 13 files changed, 138 insertions(+), 31 deletions(-) create mode 100644 output.c create mode 100644 output.h create mode 100644 signal.c create mode 100644 signal.h diff --git a/Makefile b/Makefile index 4728de1..112049f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC = gcc CFLAGS = -O2 -g -Wall -OBJ = ltrace.o functions.o elf.o i386.o symbols.o process.o syscall.o +OBJ = ltrace.o functions.o elf.o i386.o symbols.o process.o syscall.o output.o signal.o all: ltrace diff --git a/TODO b/TODO index 13f4039..432a967 100644 --- a/TODO +++ b/TODO @@ -34,6 +34,4 @@ + Disabling breakpoints and displaying ``???'' as return value when a new function is called -* ltrace should accept '-s' option to trace syscalls, too. - * All architecture dependent stuff should be moved to ``arch.h'' diff --git a/debian/changelog b/debian/changelog index 71e9cd9..14a6d7c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +ltrace (0.1.3) experimental; urgency=low + + * Added options `-i', `-S' + * Added syscall names + * Added signal names + * Added `output.c', `signal.c' + + -- Juan Cespedes Sun, 24 Aug 1997 01:45:49 +0200 + ltrace (0.1.2) experimental; urgency=low * Updated ``TODO'' diff --git a/ltrace.1 b/ltrace.1 index 5ccc81a..e0951be 100644 --- a/ltrace.1 +++ b/ltrace.1 @@ -24,6 +24,12 @@ Its use is very similar to .I \-d Increase the debugging level. .TP +.I \-i +Print the instruction pointer at the time of the library call. +.TP +.I \-S +Display system calls as well as library calls +.TP .I \-o filename Write the trace output to the file .I filename diff --git a/ltrace.c b/ltrace.c index 00653f5..33bb24c 100644 --- a/ltrace.c +++ b/ltrace.c @@ -3,24 +3,18 @@ #include #include "elf.h" -#include "i386.h" -#include "symbols.h" -#include "functions.h" #include "process.h" extern void read_config_file(const char *); FILE * output = stderr; -int opt_d = 0; -int opt_i = 0; - -unsigned long return_addr; -unsigned char return_value; -struct library_symbol * current_symbol; +int opt_d = 0; /* debug */ +int opt_i = 0; /* instruction pointer */ +int opt_S = 0; /* syscalls */ static void usage(void) { - fprintf(stderr,"Usage: ltrace [-d] [-o filename] command [arg ...]\n\n"); + fprintf(stderr,"Usage: ltrace [-d] [-i] [-S] [-o filename] command [arg ...]\n\n"); } int main(int argc, char **argv) @@ -40,6 +34,8 @@ int main(int argc, char **argv) break; case 'i': opt_i++; break; + case 'S': opt_S++; + break; default: fprintf(stderr, "Unknown option '%c'\n", argv[1][1]); usage(); exit(1); diff --git a/ltrace.h b/ltrace.h index a40dbb7..a1617bd 100644 --- a/ltrace.h +++ b/ltrace.h @@ -1,4 +1,6 @@ +#include + extern FILE * output; extern int opt_d; extern int opt_i; - +extern int opt_S; diff --git a/output.c b/output.c new file mode 100644 index 0000000..93a409f --- /dev/null +++ b/output.c @@ -0,0 +1,47 @@ +#include + +#include "ltrace.h" +#include "process.h" + +static int new_line=1; + +void send_left(const char * fmt, ...) +{ + va_list args; + + va_start(args, fmt); + if (opt_i) { + fprintf(output, "[%08x] ", instruction_pointer); + } + vfprintf(output, fmt, args); + va_end(args); + new_line=0; +} + +void send_right(const char * fmt, ...) +{ + va_list args; + + if (new_line==0) { + va_start(args, fmt); + if (opt_i) { + fprintf(output, "[%08x] ", instruction_pointer); + } + vfprintf(output, fmt, args); + va_end(args); + } + new_line=1; +} + +void send_line(const char * fmt, ...) +{ + va_list args; + + va_start(args, fmt); + if (opt_i) { + fprintf(output, "[%08x] ", instruction_pointer); + } + vfprintf(output, fmt, args); + va_end(args); + new_line=1; +} diff --git a/output.h b/output.h new file mode 100644 index 0000000..fe83523 --- /dev/null +++ b/output.h @@ -0,0 +1,3 @@ +void send_left(const char * fmt, ...); +void send_right(const char * fmt, ...); +void send_line(const char * fmt, ...); diff --git a/process.c b/process.c index 8c86689..4f557be 100644 --- a/process.c +++ b/process.c @@ -15,9 +15,13 @@ #include "symbols.h" #include "functions.h" #include "syscall.h" +#include "signal.h" +#include "output.h" struct process * list_of_processes = NULL; +unsigned int instruction_pointer; + int execute_process(const char * file, char * const argv[]) { int pid = fork(); @@ -149,8 +153,9 @@ static void chld_handler() exit(1); } eip = get_eip(pid); + instruction_pointer = eip; if (WSTOPSIG(status) != SIGTRAP) { - fprintf(output, "[0x%08lx] Signal: %u\n", eip, WSTOPSIG(status)); + send_line("--- %s (%s) ---\n", signal_name[WSTOPSIG(status)], strsignal(WSTOPSIG(status))); continue_process(pid, WSTOPSIG(status)); return; } @@ -162,15 +167,17 @@ static void chld_handler() if (status==__NR_fork) { disable_all_breakpoints(pid); } - fprintf(output, "[0x%08lx] SYSCALL: %s()\n", eip, syscall_list[status]); + if (opt_S) { + send_line("SYSCALL: %s()\n", syscall_list[status]); + } continue_process(pid, 0); return; case PROC_SYSRET: if (status==__NR_fork) { enable_all_breakpoints(pid); } - if (opt_d>0) { - fprintf(output, "[0x%08lx] SYSRET: %u\n", eip, status); + if (opt_S && (opt_d>0)) { + send_line("SYSRET: %u\n", status); } continue_process(pid, 0); return; @@ -180,7 +187,8 @@ static void chld_handler() /* pid is breakpointed... */ /* TODO: I may be here after a PTRACE_SINGLESTEP ... */ esp = get_esp(pid); - fprintf(output,"[0x%08lx] ", get_return(pid,esp)); + instruction_pointer = get_return(pid, esp); + send_line(""); tmp = library_symbols; function_seen = 0; while(tmp) { diff --git a/process.h b/process.h index 9d25bc9..36c1bc2 100644 --- a/process.h +++ b/process.h @@ -27,6 +27,8 @@ struct process { extern struct process * list_of_processes; +unsigned int instruction_pointer; + int execute_process(const char * file, char * const argv[]); void init_sighandler(void); diff --git a/signal.c b/signal.c new file mode 100644 index 0000000..24b7c8b --- /dev/null +++ b/signal.c @@ -0,0 +1,35 @@ +char * signal_name[] = { "SIG_0", + "SIGHUP", + "SIGINT", + "SIGQUIT", + "SIGKILL", + "SIGTRAP", + "SIGABRT", + "SIGBUS", + "SIGFPE", + "SIGKILL", + + "SIGUSR1", + "SIGSEGV", + "SIGUSR2", + "SIGPIPE", + "SIGALRM", + "SIGTERM", + "SIGSTKFLT", + "SIGCHLD", + "SIGCONT", + "SIGSTOP", + "SIGTSTP", + "SIGTTIN", + "SIGTTOU", + "SIGURG", + "SIGXCPU", + "SIGXFSZ", + "SIGVTALRM", + "SIGPROF", + "SIGWINCH", + "SIGIO", + "SIGPWR", + "SIGUNUSED" +}; + diff --git a/signal.h b/signal.h new file mode 100644 index 0000000..0e4a269 --- /dev/null +++ b/signal.h @@ -0,0 +1 @@ +extern char * signal_name[]; diff --git a/syscall.c b/syscall.c index 36d6678..aca9623 100644 --- a/syscall.c +++ b/syscall.c @@ -48,7 +48,7 @@ char * syscall_list[] = { "setup", /* 0 */ "getgid", "signal", "geteuid", - "getegid", + "getegid", /* 50 */ "acct", "phys", "lock", @@ -58,7 +58,7 @@ char * syscall_list[] = { "setup", /* 0 */ "setpgid", "ulimit", "oldolduname", - "umask", + "umask", /* 60 */ "chroot", "ustat", "dup2", @@ -68,7 +68,7 @@ char * syscall_list[] = { "setup", /* 0 */ "sigaction", "sgetmask", "ssetmask", - "setreuid", + "setreuid", /* 70 */ "setregid", "sigsuspend", "sigpending", @@ -78,7 +78,7 @@ char * syscall_list[] = { "setup", /* 0 */ "getrusage", "gettimeofday", "settimeofday", - "getgroups", + "getgroups", /* 80 */ "setgroups", "select", "symlink", @@ -88,7 +88,7 @@ char * syscall_list[] = { "setup", /* 0 */ "swapon", "reboot", "readdir", - "mmap", + "mmap", /* 90 */ "munmap", "truncate", "ftruncate", @@ -98,7 +98,7 @@ char * syscall_list[] = { "setup", /* 0 */ "setpriority", "profil", "statfs", - "fstatfs", + "fstatfs", /* 100 */ "ioperm", "socketcall", "syslog", @@ -108,7 +108,7 @@ char * syscall_list[] = { "setup", /* 0 */ "lstat", "fstat", "olduname", - "iopl", + "iopl", /* 110 */ "vhangup", "idle", "vm86", @@ -118,7 +118,7 @@ char * syscall_list[] = { "setup", /* 0 */ "ipc", "fsync", "sigreturn", - "clone", + "clone", /* 120 */ "setdomainname", "uname", "modify_ldt", @@ -128,7 +128,7 @@ char * syscall_list[] = { "setup", /* 0 */ "create_module", "init_module", "delete_module", - "get_kernel_syms", + "get_kernel_syms", /* 130 */ "quotactl", "getpgid", "fchdir", @@ -138,7 +138,7 @@ char * syscall_list[] = { "setup", /* 0 */ "afs_syscall", "setfsuid", "setfsgid", - "_llseek", + "_llseek", /* 140 */ "getdents", "_newselect", "flock", @@ -148,7 +148,7 @@ char * syscall_list[] = { "setup", /* 0 */ "getsid", "fdatasync", "_sysctl", - "mlock", + "mlock", /* 150 */ "munlock", "mlockall", "munlockall", @@ -158,7 +158,7 @@ char * syscall_list[] = { "setup", /* 0 */ "sched_getscheduler", "sched_yield", "sched_get_priority_max", - "sched_get_priority_min", + "sched_get_priority_min", /* 160 */ "sched_rr_get_interval", "nanosleep", "mremap", -- cgit v1.2.3