diff options
50 files changed, 468 insertions, 451 deletions
diff --git a/Makefile.in b/Makefile.in index 372ccb9..6e396a0 100644 --- a/Makefile.in +++ b/Makefile.in @@ -25,7 +25,7 @@ INSTALL_PROGRAM = $(INSTALL) -p -m 755 INSTALL_SCRIPT = $(INSTALL) -p -m 755 INSTALL_DIR = $(INSTALL) -p -d -m 755 -OBJ = ltrace.o options.o elf.o output.o read_config_file.o \ +OBJ = main.o options.o elf.o output.o read_config_file.o \ execute_program.o process_event.o display_args.o \ breakpoints.o proc.o demangle.o dict.o debug.o summary.o @@ -33,9 +33,12 @@ VERSION = @PACKAGE_VERSION@ all: ltrace -ltrace: sysdeps/sysdep.o $(OBJ) +ltrace: ltrace.o libltrace.a $(CC) $(LDFLAGS) $^ $(LIBS) -o $@ +libltrace.a: sysdeps/sysdep.o $(OBJ) + $(AR) rcv $@ $^ + sysdeps/sysdep.o: dummy $(MAKE) -C sysdeps/$(OS) diff --git a/breakpoints.c b/breakpoints.c index c39151b..e0cdb6d 100644 --- a/breakpoints.c +++ b/breakpoints.c @@ -10,7 +10,7 @@ #include <sys/ptrace.h> #endif -#include "ltrace.h" +#include "main.h" #include "options.h" #include "debug.h" #include "dict.h" diff --git a/display_args.c b/display_args.c index cbc482b..9b51c7d 100644 --- a/display_args.c +++ b/display_args.c @@ -8,7 +8,7 @@ #include <string.h> #include <limits.h> -#include "ltrace.h" +#include "main.h" #include "options.h" static int display_char(int what); @@ -12,7 +12,7 @@ #include <string.h> #include <unistd.h> -#include "ltrace.h" +#include "main.h" #include "elf.h" #include "debug.h" #include "options.h" @@ -4,7 +4,7 @@ #include <gelf.h> #include <stdlib.h> -#include "ltrace.h" +#include "main.h" struct ltelf { int fd; diff --git a/execute_program.c b/execute_program.c index 8bc4f97..6704d51 100644 --- a/execute_program.c +++ b/execute_program.c @@ -12,7 +12,7 @@ #include <pwd.h> #include <grp.h> -#include "ltrace.h" +#include "main.h" #include "options.h" #include "debug.h" #include "sysdep.h" @@ -1,127 +1,8 @@ -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <errno.h> -#include <sys/param.h> -#include <signal.h> -#include <sys/wait.h> - #include "ltrace.h" -#include "output.h" -#include "read_config_file.h" -#include "options.h" -#include "debug.h" - -char *command = NULL; -Process *list_of_processes = NULL; - -int exiting = 0; /* =1 if a SIGINT or SIGTERM has been received */ - -static void -signal_alarm(int sig) { - Process *tmp = list_of_processes; - - signal(SIGALRM, SIG_DFL); - while (tmp) { - struct opt_p_t *tmp2 = opt_p; - while (tmp2) { - if (tmp->pid == tmp2->pid) { - tmp = tmp->next; - if (!tmp) { - return; - } - tmp2 = opt_p; - continue; - } - tmp2 = tmp2->next; - } - debug(2, "Sending SIGSTOP to process %u\n", tmp->pid); - kill(tmp->pid, SIGSTOP); - tmp = tmp->next; - } -} - -static void -signal_exit(int sig) { - exiting = 1; - debug(1, "Received interrupt signal; exiting..."); - signal(SIGINT, SIG_IGN); - signal(SIGTERM, SIG_IGN); - signal(SIGALRM, signal_alarm); - if (opt_p) { - struct opt_p_t *tmp = opt_p; - while (tmp) { - debug(2, "Sending SIGSTOP to process %u\n", tmp->pid); - kill(tmp->pid, SIGSTOP); - tmp = tmp->next; - } - } - alarm(1); -} - -static void -normal_exit(void) { - output_line(0, 0); - if (options.summary) { - show_summary(); - } - if (options.output) { - fclose(options.output); - options.output = NULL; - } -} int -main(int argc, char **argv) { - struct opt_p_t *opt_p_tmp; - - atexit(normal_exit); - signal(SIGINT, signal_exit); /* Detach processes when interrupted */ - signal(SIGTERM, signal_exit); /* ... or killed */ - - argv = process_options(argc, argv); - while (opt_F) { - /* If filename begins with ~, expand it to the user's home */ - /* directory. This does not correctly handle ~yoda, but that */ - /* isn't as bad as it seems because the shell will normally */ - /* be doing the expansion for us; only the hardcoded */ - /* ~/.ltrace.conf should ever use this code. */ - if (opt_F->filename[0] == '~') { - char path[PATH_MAX]; - char *home_dir = getenv("HOME"); - if (home_dir) { - strncpy(path, home_dir, PATH_MAX - 1); - path[PATH_MAX - 1] = '\0'; - strncat(path, opt_F->filename + 1, - PATH_MAX - strlen(path) - 1); - read_config_file(path); - } - } else { - read_config_file(opt_F->filename); - } - opt_F = opt_F->next; - } - if (opt_e) { - struct opt_e_t *tmp = opt_e; - while (tmp) { - debug(1, "Option -e: %s\n", tmp->name); - tmp = tmp->next; - } - } - if (command) { - execute_program(open_program(command, 0), argv); - } - opt_p_tmp = opt_p; - while (opt_p_tmp) { - open_pid(opt_p_tmp->pid, 1); - opt_p_tmp = opt_p_tmp->next; - } - while (1) { - process_event(next_event()); - } +main(int argc, char *argv[]) { + ltrace_init(argc, argv); + ltrace_main(); + return 0; } @@ -1,279 +1,2 @@ -#ifndef _HCK_LTRACE_H -#define _HCK_LTRACE_H - -#include <sys/types.h> -#include <sys/time.h> -#include <stdio.h> - -#include "defs.h" -#include "dict.h" - -/* BREAKPOINT_LENGTH is defined in "sysdep.h" */ -#include "sysdep.h" - -#define MAX_LIBRARY 30 - -#if defined HAVE_LIBIBERTY || defined HAVE_LIBSUPC__ -# define USE_DEMANGLE -#endif - -extern char *command; - -extern int exiting; /* =1 if we have to exit ASAP */ - -typedef struct Breakpoint Breakpoint; -struct Breakpoint { - void *addr; - unsigned char orig_value[BREAKPOINT_LENGTH]; - int enabled; - struct library_symbol *libsym; -#ifdef __arm__ - int thumb_mode; -#endif -}; - -enum arg_type { - ARGTYPE_UNKNOWN = -1, - ARGTYPE_VOID, - ARGTYPE_INT, - ARGTYPE_UINT, - ARGTYPE_LONG, - ARGTYPE_ULONG, - ARGTYPE_OCTAL, - ARGTYPE_CHAR, - ARGTYPE_SHORT, - ARGTYPE_USHORT, - ARGTYPE_FLOAT, /* float value, may require index */ - ARGTYPE_DOUBLE, /* double value, may require index */ - ARGTYPE_ADDR, - ARGTYPE_FILE, - ARGTYPE_FORMAT, /* printf-like format */ - ARGTYPE_STRING, /* NUL-terminated string */ - ARGTYPE_STRING_N, /* String of known maxlen */ - ARGTYPE_ARRAY, /* Series of values in memory */ - ARGTYPE_ENUM, /* Enumeration */ - ARGTYPE_STRUCT, /* Structure of values */ - ARGTYPE_POINTER, /* Pointer to some other type */ - ARGTYPE_COUNT /* number of ARGTYPE_* values */ -}; - -typedef struct arg_type_info_t { - enum arg_type type; - union { - /* ARGTYPE_ENUM */ - struct { - size_t entries; - char **keys; - int *values; - } enum_info; - - /* ARGTYPE_ARRAY */ - struct { - struct arg_type_info_t *elt_type; - size_t elt_size; - int len_spec; - } array_info; - - /* ARGTYPE_STRING_N */ - struct { - int size_spec; - } string_n_info; - - /* ARGTYPE_STRUCT */ - struct { - struct arg_type_info_t **fields; /* NULL-terminated */ - size_t *offset; - size_t size; - } struct_info; - - /* ARGTYPE_POINTER */ - struct { - struct arg_type_info_t *info; - } ptr_info; - - /* ARGTYPE_FLOAT */ - struct { - size_t float_index; - } float_info; - - /* ARGTYPE_DOUBLE */ - struct { - size_t float_index; - } double_info; - } u; -} arg_type_info; - -enum tof { - LT_TOF_NONE = 0, - LT_TOF_FUNCTION, /* A real library function */ - LT_TOF_FUNCTIONR, /* Return from a real library function */ - LT_TOF_SYSCALL, /* A syscall */ - LT_TOF_SYSCALLR, /* Return from a syscall */ - LT_TOF_STRUCT /* Not a function; read args from struct */ -}; - -typedef struct Function Function; -struct Function { - const char *name; - arg_type_info *return_info; - int num_params; - arg_type_info *arg_info[MAX_ARGS]; - int params_right; - Function *next; -}; - -enum toplt { - LS_TOPLT_NONE = 0, /* PLT not used for this symbol. */ - LS_TOPLT_EXEC, /* PLT for this symbol is executable. */ - LS_TOPLT_POINT /* PLT for this symbol is a non-executable. */ -}; - -extern Function *list_of_functions; -extern char *PLTs_initialized_by_here; - -struct library_symbol { - char *name; - void *enter_addr; - char needs_init; - enum toplt plt_type; - char is_weak; - struct library_symbol *next; -}; - -struct callstack_element { - union { - int syscall; - struct library_symbol *libfunc; - } c_un; - int is_syscall; - void *return_addr; - struct timeval time_spent; -}; - -#define MAX_CALLDEPTH 64 - -typedef enum Process_State Process_State; -enum Process_State { - STATE_ATTACHED = 0, - STATE_BEING_CREATED, - STATE_IGNORED /* ignore this process (it's a fork and no -f was used) */ -}; - -typedef struct Process Process; -struct Process { - Process_State state; - Process *parent; /* needed by STATE_BEING_CREATED */ - char *filename; - pid_t pid; - struct dict *breakpoints; - int breakpoints_enabled; /* -1:not enabled yet, 0:disabled, 1:enabled */ - int mask_32bit; /* 1 if 64-bit ltrace is tracing 32-bit process */ - unsigned int personality; - int tracesysgood; /* signal indicating a PTRACE_SYSCALL trap */ - - int callstack_depth; - struct callstack_element callstack[MAX_CALLDEPTH]; - struct library_symbol *list_of_symbols; - - /* Arch-dependent: */ - void *instruction_pointer; - void *stack_pointer; /* To get return addr, args... */ - void *return_addr; - Breakpoint *breakpoint_being_enabled; - void *arch_ptr; - short e_machine; - short need_to_reinitialize_breakpoints; -#ifdef __arm__ - int thumb_mode; /* ARM execution mode: 0: ARM, 1: Thumb */ -#endif - - /* output: */ - enum tof type_being_displayed; - - Process *next; -}; - -typedef struct Event Event; -struct Event { - Process *proc; - enum { - EVENT_NONE, - EVENT_SIGNAL, - EVENT_EXIT, - EVENT_EXIT_SIGNAL, - EVENT_SYSCALL, - EVENT_SYSRET, - EVENT_ARCH_SYSCALL, - EVENT_ARCH_SYSRET, - EVENT_CLONE, - EVENT_EXEC, - EVENT_BREAKPOINT, - EVENT_NEW /* in this case, proc is NULL */ - } type; - union { - int ret_val; /* EVENT_EXIT */ - int signum; /* EVENT_SIGNAL, EVENT_EXIT_SIGNAL */ - int sysnum; /* EVENT_SYSCALL, EVENT_SYSRET */ - void *brk_addr; /* EVENT_BREAKPOINT */ - int newpid; /* EVENT_CLONE, EVENT_NEW */ - } e_un; -}; - -struct opt_c_struct { - int count; - struct timeval tv; -}; -extern struct dict *dict_opt_c; - -extern Process *list_of_processes; - -extern void *instruction_pointer; - -extern Event *next_event(void); -extern Process * pid2proc(pid_t pid); -extern void process_event(Event *event); -extern void execute_program(Process *, char **); -extern int display_arg(enum tof type, Process *proc, int arg_num, arg_type_info *info); -extern Breakpoint *address2bpstruct(Process *proc, void *addr); -extern void breakpoints_init(Process *proc); -extern void insert_breakpoint(Process *proc, void *addr, struct library_symbol *libsym); -extern void delete_breakpoint(Process *proc, void *addr); -extern void enable_all_breakpoints(Process *proc); -extern void disable_all_breakpoints(Process *proc); -extern void reinitialize_breakpoints(Process *); - -extern Process *open_program(char *filename, pid_t pid); -extern void open_pid(pid_t pid, int verbose); -extern void show_summary(void); -extern arg_type_info *lookup_prototype(enum arg_type at); - -/* Arch-dependent stuff: */ -extern char *pid2name(pid_t pid); -extern void trace_set_options(Process *proc, pid_t pid); -extern void trace_me(void); -extern int trace_pid(pid_t pid); -extern void untrace_pid(pid_t pid); -extern void get_arch_dep(Process *proc); -extern void *get_instruction_pointer(Process *proc); -extern void set_instruction_pointer(Process *proc, void *addr); -extern void *get_stack_pointer(Process *proc); -extern void *get_return_addr(Process *proc, void *stack_pointer); -extern void enable_breakpoint(pid_t pid, Breakpoint *sbp); -extern void disable_breakpoint(pid_t pid, const Breakpoint *sbp); -extern int syscall_p(Process *proc, int status, int *sysnum); -extern void continue_process(pid_t pid); -extern void continue_after_signal(pid_t pid, int signum); -extern void continue_after_breakpoint(Process *proc, Breakpoint *sbp); -extern void continue_enabling_breakpoint(pid_t pid, Breakpoint *sbp); -extern long gimme_arg(enum tof type, Process *proc, int arg_num, arg_type_info *info); -extern void save_register_args(enum tof type, Process *proc); -extern int umovestr(Process *proc, void *addr, int len, void *laddr); -extern int umovelong (Process *proc, void *addr, long *result, arg_type_info *info); -extern int ffcheck(void *maddr); -extern void *sym2addr(Process *, struct library_symbol *); - -#if 0 /* not yet */ -extern int umoven(Process *proc, void *addr, int len, void *laddr); -#endif - -#endif +extern void ltrace_init(int argc, char **argv); +extern void ltrace_main(void); @@ -0,0 +1,131 @@ +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <sys/param.h> +#include <signal.h> +#include <sys/wait.h> + +#include "main.h" +#include "output.h" +#include "read_config_file.h" +#include "options.h" +#include "debug.h" + +char *command = NULL; +Process *list_of_processes = NULL; + +int exiting = 0; /* =1 if a SIGINT or SIGTERM has been received */ + +static void +signal_alarm(int sig) { + Process *tmp = list_of_processes; + + signal(SIGALRM, SIG_DFL); + while (tmp) { + struct opt_p_t *tmp2 = opt_p; + while (tmp2) { + if (tmp->pid == tmp2->pid) { + tmp = tmp->next; + if (!tmp) { + return; + } + tmp2 = opt_p; + continue; + } + tmp2 = tmp2->next; + } + debug(2, "Sending SIGSTOP to process %u\n", tmp->pid); + kill(tmp->pid, SIGSTOP); + tmp = tmp->next; + } +} + +static void +signal_exit(int sig) { + exiting = 1; + debug(1, "Received interrupt signal; exiting..."); + signal(SIGINT, SIG_IGN); + signal(SIGTERM, SIG_IGN); + signal(SIGALRM, signal_alarm); + if (opt_p) { + struct opt_p_t *tmp = opt_p; + while (tmp) { + debug(2, "Sending SIGSTOP to process %u\n", tmp->pid); + kill(tmp->pid, SIGSTOP); + tmp = tmp->next; + } + } + alarm(1); +} + +static void +normal_exit(void) { + output_line(0, 0); + if (options.summary) { + show_summary(); + } + if (options.output) { + fclose(options.output); + options.output = NULL; + } +} + +void +ltrace_init(int argc, char **argv) { + struct opt_p_t *opt_p_tmp; + + atexit(normal_exit); + signal(SIGINT, signal_exit); /* Detach processes when interrupted */ + signal(SIGTERM, signal_exit); /* ... or killed */ + + argv = process_options(argc, argv); + while (opt_F) { + /* If filename begins with ~, expand it to the user's home */ + /* directory. This does not correctly handle ~yoda, but that */ + /* isn't as bad as it seems because the shell will normally */ + /* be doing the expansion for us; only the hardcoded */ + /* ~/.ltrace.conf should ever use this code. */ + if (opt_F->filename[0] == '~') { + char path[PATH_MAX]; + char *home_dir = getenv("HOME"); + if (home_dir) { + strncpy(path, home_dir, PATH_MAX - 1); + path[PATH_MAX - 1] = '\0'; + strncat(path, opt_F->filename + 1, + PATH_MAX - strlen(path) - 1); + read_config_file(path); + } + } else { + read_config_file(opt_F->filename); + } + opt_F = opt_F->next; + } + if (opt_e) { + struct opt_e_t *tmp = opt_e; + while (tmp) { + debug(1, "Option -e: %s\n", tmp->name); + tmp = tmp->next; + } + } + if (command) { + execute_program(open_program(command, 0), argv); + } + opt_p_tmp = opt_p; + while (opt_p_tmp) { + open_pid(opt_p_tmp->pid, 1); + opt_p_tmp = opt_p_tmp->next; + } +} + +void +ltrace_main(void) { + while (1) { + process_event(next_event()); + } +} @@ -0,0 +1,279 @@ +#ifndef _HCK_LTRACE_H +#define _HCK_LTRACE_H + +#include <sys/types.h> +#include <sys/time.h> +#include <stdio.h> + +#include "defs.h" +#include "dict.h" + +/* BREAKPOINT_LENGTH is defined in "sysdep.h" */ +#include "sysdep.h" + +#define MAX_LIBRARY 30 + +#if defined HAVE_LIBIBERTY || defined HAVE_LIBSUPC__ +# define USE_DEMANGLE +#endif + +extern char *command; + +extern int exiting; /* =1 if we have to exit ASAP */ + +typedef struct Breakpoint Breakpoint; +struct Breakpoint { + void *addr; + unsigned char orig_value[BREAKPOINT_LENGTH]; + int enabled; + struct library_symbol *libsym; +#ifdef __arm__ + int thumb_mode; +#endif +}; + +enum arg_type { + ARGTYPE_UNKNOWN = -1, + ARGTYPE_VOID, + ARGTYPE_INT, + ARGTYPE_UINT, + ARGTYPE_LONG, + ARGTYPE_ULONG, + ARGTYPE_OCTAL, + ARGTYPE_CHAR, + ARGTYPE_SHORT, + ARGTYPE_USHORT, + ARGTYPE_FLOAT, /* float value, may require index */ + ARGTYPE_DOUBLE, /* double value, may require index */ + ARGTYPE_ADDR, + ARGTYPE_FILE, + ARGTYPE_FORMAT, /* printf-like format */ + ARGTYPE_STRING, /* NUL-terminated string */ + ARGTYPE_STRING_N, /* String of known maxlen */ + ARGTYPE_ARRAY, /* Series of values in memory */ + ARGTYPE_ENUM, /* Enumeration */ + ARGTYPE_STRUCT, /* Structure of values */ + ARGTYPE_POINTER, /* Pointer to some other type */ + ARGTYPE_COUNT /* number of ARGTYPE_* values */ +}; + +typedef struct arg_type_info_t { + enum arg_type type; + union { + /* ARGTYPE_ENUM */ + struct { + size_t entries; + char **keys; + int *values; + } enum_info; + + /* ARGTYPE_ARRAY */ + struct { + struct arg_type_info_t *elt_type; + size_t elt_size; + int len_spec; + } array_info; + + /* ARGTYPE_STRING_N */ + struct { + int size_spec; + } string_n_info; + + /* ARGTYPE_STRUCT */ + struct { + struct arg_type_info_t **fields; /* NULL-terminated */ + size_t *offset; + size_t size; + } struct_info; + + /* ARGTYPE_POINTER */ + struct { + struct arg_type_info_t *info; + } ptr_info; + + /* ARGTYPE_FLOAT */ + struct { + size_t float_index; + } float_info; + + /* ARGTYPE_DOUBLE */ + struct { + size_t float_index; + } double_info; + } u; +} arg_type_info; + +enum tof { + LT_TOF_NONE = 0, + LT_TOF_FUNCTION, /* A real library function */ + LT_TOF_FUNCTIONR, /* Return from a real library function */ + LT_TOF_SYSCALL, /* A syscall */ + LT_TOF_SYSCALLR, /* Return from a syscall */ + LT_TOF_STRUCT /* Not a function; read args from struct */ +}; + +typedef struct Function Function; +struct Function { + const char *name; + arg_type_info *return_info; + int num_params; + arg_type_info *arg_info[MAX_ARGS]; + int params_right; + Function *next; +}; + +enum toplt { + LS_TOPLT_NONE = 0, /* PLT not used for this symbol. */ + LS_TOPLT_EXEC, /* PLT for this symbol is executable. */ + LS_TOPLT_POINT /* PLT for this symbol is a non-executable. */ +}; + +extern Function *list_of_functions; +extern char *PLTs_initialized_by_here; + +struct library_symbol { + char *name; + void *enter_addr; + char needs_init; + enum toplt plt_type; + char is_weak; + struct library_symbol *next; +}; + +struct callstack_element { + union { + int syscall; + struct library_symbol *libfunc; + } c_un; + int is_syscall; + void *return_addr; + struct timeval time_spent; +}; + +#define MAX_CALLDEPTH 64 + +typedef enum Process_State Process_State; +enum Process_State { + STATE_ATTACHED = 0, + STATE_BEING_CREATED, + STATE_IGNORED /* ignore this process (it's a fork and no -f was used) */ +}; + +typedef struct Process Process; +struct Process { + Process_State state; + Process *parent; /* needed by STATE_BEING_CREATED */ + char *filename; + pid_t pid; + struct dict *breakpoints; + int breakpoints_enabled; /* -1:not enabled yet, 0:disabled, 1:enabled */ + int mask_32bit; /* 1 if 64-bit ltrace is tracing 32-bit process */ + unsigned int personality; + int tracesysgood; /* signal indicating a PTRACE_SYSCALL trap */ + + int callstack_depth; + struct callstack_element callstack[MAX_CALLDEPTH]; + struct library_symbol *list_of_symbols; + + /* Arch-dependent: */ + void *instruction_pointer; + void *stack_pointer; /* To get return addr, args... */ + void *return_addr; + Breakpoint *breakpoint_being_enabled; + void *arch_ptr; + short e_machine; + short need_to_reinitialize_breakpoints; +#ifdef __arm__ + int thumb_mode; /* ARM execution mode: 0: ARM, 1: Thumb */ +#endif + + /* output: */ + enum tof type_being_displayed; + + Process *next; +}; + +typedef struct Event Event; +struct Event { + Process *proc; + enum { + EVENT_NONE, + EVENT_SIGNAL, + EVENT_EXIT, + EVENT_EXIT_SIGNAL, + EVENT_SYSCALL, + EVENT_SYSRET, + EVENT_ARCH_SYSCALL, + EVENT_ARCH_SYSRET, + EVENT_CLONE, + EVENT_EXEC, + EVENT_BREAKPOINT, + EVENT_NEW /* in this case, proc is NULL */ + } type; + union { + int ret_val; /* EVENT_EXIT */ + int signum; /* EVENT_SIGNAL, EVENT_EXIT_SIGNAL */ + int sysnum; /* EVENT_SYSCALL, EVENT_SYSRET */ + void *brk_addr; /* EVENT_BREAKPOINT */ + int newpid; /* EVENT_CLONE, EVENT_NEW */ + } e_un; +}; + +struct opt_c_struct { + int count; + struct timeval tv; +}; +extern struct dict *dict_opt_c; + +extern Process *list_of_processes; + +extern void *instruction_pointer; + +extern Event *next_event(void); +extern Process * pid2proc(pid_t pid); +extern void process_event(Event *event); +extern void execute_program(Process *, char **); +extern int display_arg(enum tof type, Process *proc, int arg_num, arg_type_info *info); +extern Breakpoint *address2bpstruct(Process *proc, void *addr); +extern void breakpoints_init(Process *proc); +extern void insert_breakpoint(Process *proc, void *addr, struct library_symbol *libsym); +extern void delete_breakpoint(Process *proc, void *addr); +extern void enable_all_breakpoints(Process *proc); +extern void disable_all_breakpoints(Process *proc); +extern void reinitialize_breakpoints(Process *); + +extern Process *open_program(char *filename, pid_t pid); +extern void open_pid(pid_t pid, int verbose); +extern void show_summary(void); +extern arg_type_info *lookup_prototype(enum arg_type at); + +/* Arch-dependent stuff: */ +extern char *pid2name(pid_t pid); +extern void trace_set_options(Process *proc, pid_t pid); +extern void trace_me(void); +extern int trace_pid(pid_t pid); +extern void untrace_pid(pid_t pid); +extern void get_arch_dep(Process *proc); +extern void *get_instruction_pointer(Process *proc); +extern void set_instruction_pointer(Process *proc, void *addr); +extern void *get_stack_pointer(Process *proc); +extern void *get_return_addr(Process *proc, void *stack_pointer); +extern void enable_breakpoint(pid_t pid, Breakpoint *sbp); +extern void disable_breakpoint(pid_t pid, const Breakpoint *sbp); +extern int syscall_p(Process *proc, int status, int *sysnum); +extern void continue_process(pid_t pid); +extern void continue_after_signal(pid_t pid, int signum); +extern void continue_after_breakpoint(Process *proc, Breakpoint *sbp); +extern void continue_enabling_breakpoint(pid_t pid, Breakpoint *sbp); +extern long gimme_arg(enum tof type, Process *proc, int arg_num, arg_type_info *info); +extern void save_register_args(enum tof type, Process *proc); +extern int umovestr(Process *proc, void *addr, int len, void *laddr); +extern int umovelong (Process *proc, void *addr, long *result, arg_type_info *info); +extern int ffcheck(void *maddr); +extern void *sym2addr(Process *, struct library_symbol *); + +#if 0 /* not yet */ +extern int umoven(Process *proc, void *addr, int len, void *laddr); +#endif + +#endif @@ -14,7 +14,7 @@ #include <getopt.h> #endif -#include "ltrace.h" +#include "main.h" #include "options.h" #include "defs.h" @@ -10,7 +10,7 @@ #include <sys/time.h> #include <unistd.h> -#include "ltrace.h" +#include "main.h" #include "options.h" #include "output.h" #include "dict.h" @@ -19,7 +19,7 @@ #include "demangle.h" #endif -/* TODO FIXME XXX: include in ltrace.h: */ +/* TODO FIXME XXX: include in main.h: */ extern struct timeval current_time_spent; struct dict *dict_opt_c = NULL; @@ -1,6 +1,6 @@ #include <sys/types.h> -#include "ltrace.h" +#include "main.h" void output_line(Process *proc, char *fmt, ...); @@ -8,7 +8,7 @@ #include <errno.h> #include <stdlib.h> -#include "ltrace.h" +#include "main.h" #include "options.h" #include "elf.h" diff --git a/process_event.c b/process_event.c index 48c3a75..169db09 100644 --- a/process_event.c +++ b/process_event.c @@ -10,7 +10,7 @@ #include <assert.h> #include <sys/time.h> -#include "ltrace.h" +#include "main.h" #include "output.h" #include "options.h" #include "elf.h" diff --git a/read_config_file.c b/read_config_file.c index 0664968..dee5d21 100644 --- a/read_config_file.c +++ b/read_config_file.c @@ -6,7 +6,7 @@ #include <stdlib.h> #include <ctype.h> -#include "ltrace.h" +#include "main.h" #include "read_config_file.h" #include "output.h" #include "debug.h" @@ -49,7 +49,7 @@ static struct list_of_pt_t { /* Array of prototype objects for each of the types. The order in this * array must exactly match the list of enumerated values in - * ltrace.h */ + * main.h */ static arg_type_info arg_type_prototypes[] = { { ARGTYPE_VOID }, { ARGTYPE_INT }, @@ -6,7 +6,7 @@ #include <stdlib.h> #include <sys/time.h> -#include "ltrace.h" +#include "main.h" #include "options.h" #ifdef USE_DEMANGLE diff --git a/sysdeps/linux-gnu/alpha/plt.c b/sysdeps/linux-gnu/alpha/plt.c index e3ce5c7..4d7002d 100644 --- a/sysdeps/linux-gnu/alpha/plt.c +++ b/sysdeps/linux-gnu/alpha/plt.c @@ -1,5 +1,5 @@ #include <gelf.h> -#include "ltrace.h" +#include "main.h" #include "elf.h" GElf_Addr diff --git a/sysdeps/linux-gnu/alpha/regs.c b/sysdeps/linux-gnu/alpha/regs.c index 31a4460..9e5e4e7 100644 --- a/sysdeps/linux-gnu/alpha/regs.c +++ b/sysdeps/linux-gnu/alpha/regs.c @@ -6,7 +6,7 @@ #include <sys/ptrace.h> #include <asm/ptrace.h> -#include "ltrace.h" +#include "main.h" #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) # define PTRACE_PEEKUSER PTRACE_PEEKUSR diff --git a/sysdeps/linux-gnu/alpha/trace.c b/sysdeps/linux-gnu/alpha/trace.c index 216fe15..ceda5a5 100644 --- a/sysdeps/linux-gnu/alpha/trace.c +++ b/sysdeps/linux-gnu/alpha/trace.c @@ -8,7 +8,7 @@ #include <sys/ptrace.h> #include <asm/ptrace.h> -#include "ltrace.h" +#include "main.h" #include "debug.h" #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) diff --git a/sysdeps/linux-gnu/arm/plt.c b/sysdeps/linux-gnu/arm/plt.c index 5ebc4bd..fa3cf9b 100644 --- a/sysdeps/linux-gnu/arm/plt.c +++ b/sysdeps/linux-gnu/arm/plt.c @@ -1,5 +1,5 @@ #include <gelf.h> -#include "ltrace.h" +#include "main.h" #include "elf.h" GElf_Addr diff --git a/sysdeps/linux-gnu/arm/regs.c b/sysdeps/linux-gnu/arm/regs.c index fbef512..80cf8d9 100644 --- a/sysdeps/linux-gnu/arm/regs.c +++ b/sysdeps/linux-gnu/arm/regs.c @@ -6,7 +6,7 @@ #include <sys/ptrace.h> #include <asm/ptrace.h> -#include "ltrace.h" +#include "main.h" #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) # define PTRACE_PEEKUSER PTRACE_PEEKUSR diff --git a/sysdeps/linux-gnu/arm/trace.c b/sysdeps/linux-gnu/arm/trace.c index 9dee174..fbbdaa0 100644 --- a/sysdeps/linux-gnu/arm/trace.c +++ b/sysdeps/linux-gnu/arm/trace.c @@ -9,7 +9,7 @@ #include <sys/ptrace.h> #include <asm/ptrace.h> -#include "ltrace.h" +#include "main.h" #include "output.h" #include "ptrace.h" diff --git a/sysdeps/linux-gnu/events.c b/sysdeps/linux-gnu/events.c index a68bacc..af8b27f 100644 --- a/sysdeps/linux-gnu/events.c +++ b/sysdeps/linux-gnu/events.c @@ -11,7 +11,7 @@ #include <string.h> #include <sys/ptrace.h> -#include "ltrace.h" +#include "main.h" #include "options.h" #include "output.h" #include "debug.h" diff --git a/sysdeps/linux-gnu/i386/plt.c b/sysdeps/linux-gnu/i386/plt.c index 86afe55..2f7e238 100644 --- a/sysdeps/linux-gnu/i386/plt.c +++ b/sysdeps/linux-gnu/i386/plt.c @@ -1,5 +1,5 @@ #include <gelf.h> -#include "ltrace.h" +#include "main.h" #include "elf.h" GElf_Addr diff --git a/sysdeps/linux-gnu/i386/regs.c b/sysdeps/linux-gnu/i386/regs.c index 5468583..cb74cfb 100644 --- a/sysdeps/linux-gnu/i386/regs.c +++ b/sysdeps/linux-gnu/i386/regs.c @@ -6,7 +6,7 @@ #include <sys/ptrace.h> #include <asm/ptrace.h> -#include "ltrace.h" +#include "main.h" #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) # define PTRACE_PEEKUSER PTRACE_PEEKUSR diff --git a/sysdeps/linux-gnu/i386/trace.c b/sysdeps/linux-gnu/i386/trace.c index 8785150..fb0e392 100644 --- a/sysdeps/linux-gnu/i386/trace.c +++ b/sysdeps/linux-gnu/i386/trace.c @@ -9,7 +9,7 @@ #include <sys/ptrace.h> #include <asm/ptrace.h> -#include "ltrace.h" +#include "main.h" #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) # define PTRACE_PEEKUSER PTRACE_PEEKUSR diff --git a/sysdeps/linux-gnu/ia64/plt.c b/sysdeps/linux-gnu/ia64/plt.c index e988472..2f8bb3c 100644 --- a/sysdeps/linux-gnu/ia64/plt.c +++ b/sysdeps/linux-gnu/ia64/plt.c @@ -1,5 +1,5 @@ #include <gelf.h> -#include "ltrace.h" +#include "main.h" #include "elf.h" #include "debug.h" diff --git a/sysdeps/linux-gnu/ia64/regs.c b/sysdeps/linux-gnu/ia64/regs.c index 559fd0d..dd7041e 100644 --- a/sysdeps/linux-gnu/ia64/regs.c +++ b/sysdeps/linux-gnu/ia64/regs.c @@ -10,7 +10,7 @@ #include <stddef.h> #include "debug.h" -#include "ltrace.h" +#include "main.h" void * get_instruction_pointer(Process *proc) { diff --git a/sysdeps/linux-gnu/ia64/trace.c b/sysdeps/linux-gnu/ia64/trace.c index ea0e75c..842b7c0 100644 --- a/sysdeps/linux-gnu/ia64/trace.c +++ b/sysdeps/linux-gnu/ia64/trace.c @@ -12,7 +12,7 @@ #include <asm/ptrace_offsets.h> #include <asm/rse.h> -#include "ltrace.h" +#include "main.h" /* What we think of as a bundle, ptrace thinks of it as two unsigned * longs */ diff --git a/sysdeps/linux-gnu/m68k/plt.c b/sysdeps/linux-gnu/m68k/plt.c index c027c5f..5ef1e4c 100644 --- a/sysdeps/linux-gnu/m68k/plt.c +++ b/sysdeps/linux-gnu/m68k/plt.c @@ -1,5 +1,5 @@ #include <gelf.h> -#include "ltrace.h" +#include "main.h" #include "elf.h" GElf_Addr diff --git a/sysdeps/linux-gnu/m68k/regs.c b/sysdeps/linux-gnu/m68k/regs.c index 627a3ba..55c1fd0 100644 --- a/sysdeps/linux-gnu/m68k/regs.c +++ b/sysdeps/linux-gnu/m68k/regs.c @@ -6,7 +6,7 @@ #include <sys/ptrace.h> #include <asm/ptrace.h> -#include "ltrace.h" +#include "main.h" #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) # define PTRACE_PEEKUSER PTRACE_PEEKUSR diff --git a/sysdeps/linux-gnu/m68k/trace.c b/sysdeps/linux-gnu/m68k/trace.c index 09c71b2..513a4be 100644 --- a/sysdeps/linux-gnu/m68k/trace.c +++ b/sysdeps/linux-gnu/m68k/trace.c @@ -8,7 +8,7 @@ #include <sys/ptrace.h> #include <asm/ptrace.h> -#include "ltrace.h" +#include "main.h" #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) # define PTRACE_PEEKUSER PTRACE_PEEKUSR diff --git a/sysdeps/linux-gnu/mipsel/plt.c b/sysdeps/linux-gnu/mipsel/plt.c index e3f3811..94a9a6d 100644 --- a/sysdeps/linux-gnu/mipsel/plt.c +++ b/sysdeps/linux-gnu/mipsel/plt.c @@ -1,7 +1,7 @@ #include <debug.h> #include <gelf.h> #include <sys/ptrace.h> -#include "ltrace.h" +#include "main.h" #include "ltrace_elf.h" /** diff --git a/sysdeps/linux-gnu/mipsel/regs.c b/sysdeps/linux-gnu/mipsel/regs.c index e7c591b..ac9ebdc 100644 --- a/sysdeps/linux-gnu/mipsel/regs.c +++ b/sysdeps/linux-gnu/mipsel/regs.c @@ -7,7 +7,7 @@ #include <asm/ptrace.h> #include <linux/user.h> -#include "ltrace.h" +#include "main.h" #include "mipsel.h" #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) diff --git a/sysdeps/linux-gnu/mipsel/trace.c b/sysdeps/linux-gnu/mipsel/trace.c index 1399b9f..57fa4f2 100644 --- a/sysdeps/linux-gnu/mipsel/trace.c +++ b/sysdeps/linux-gnu/mipsel/trace.c @@ -8,7 +8,7 @@ #include <sys/ptrace.h> #include <asm/ptrace.h> #include "debug.h" -#include "ltrace.h" +#include "main.h" #include "mipsel.h" #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) # define PTRACE_PEEKUSER PTRACE_PEEKUSR diff --git a/sysdeps/linux-gnu/ppc/plt.c b/sysdeps/linux-gnu/ppc/plt.c index da26cf8..55bca66 100644 --- a/sysdeps/linux-gnu/ppc/plt.c +++ b/sysdeps/linux-gnu/ppc/plt.c @@ -1,5 +1,5 @@ #include <gelf.h> -#include "ltrace.h" +#include "main.h" #include "elf.h" #include "debug.h" #include "ptrace.h" diff --git a/sysdeps/linux-gnu/ppc/regs.c b/sysdeps/linux-gnu/ppc/regs.c index 2ccad8a..e81b35f 100644 --- a/sysdeps/linux-gnu/ppc/regs.c +++ b/sysdeps/linux-gnu/ppc/regs.c @@ -6,7 +6,7 @@ #include <sys/ptrace.h> #include <asm/ptrace.h> -#include "ltrace.h" +#include "main.h" #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) # define PTRACE_PEEKUSER PTRACE_PEEKUSR diff --git a/sysdeps/linux-gnu/ppc/trace.c b/sysdeps/linux-gnu/ppc/trace.c index 1d8ba25..d430cbd 100644 --- a/sysdeps/linux-gnu/ppc/trace.c +++ b/sysdeps/linux-gnu/ppc/trace.c @@ -10,7 +10,7 @@ #include <elf.h> #include <errno.h> -#include "ltrace.h" +#include "main.h" #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) # define PTRACE_PEEKUSER PTRACE_PEEKUSR diff --git a/sysdeps/linux-gnu/s390/plt.c b/sysdeps/linux-gnu/s390/plt.c index 4a03c93..adeb04f 100644 --- a/sysdeps/linux-gnu/s390/plt.c +++ b/sysdeps/linux-gnu/s390/plt.c @@ -1,5 +1,5 @@ #include <gelf.h> -#include "ltrace.h" +#include "main.h" #include "elf.h" GElf_Addr diff --git a/sysdeps/linux-gnu/s390/regs.c b/sysdeps/linux-gnu/s390/regs.c index 91fd68d..600eced 100644 --- a/sysdeps/linux-gnu/s390/regs.c +++ b/sysdeps/linux-gnu/s390/regs.c @@ -11,7 +11,7 @@ #include <sys/ptrace.h> #include <asm/ptrace.h> -#include "ltrace.h" +#include "main.h" #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) # define PTRACE_PEEKUSER PTRACE_PEEKUSR diff --git a/sysdeps/linux-gnu/s390/trace.c b/sysdeps/linux-gnu/s390/trace.c index 9c2e14a..418892c 100644 --- a/sysdeps/linux-gnu/s390/trace.c +++ b/sysdeps/linux-gnu/s390/trace.c @@ -19,7 +19,7 @@ #include <sys/ptrace.h> #include <asm/ptrace.h> -#include "ltrace.h" +#include "main.h" #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) # define PTRACE_PEEKUSER PTRACE_PEEKUSR diff --git a/sysdeps/linux-gnu/sparc/plt.c b/sysdeps/linux-gnu/sparc/plt.c index a9ca725..a0d8bb6 100644 --- a/sysdeps/linux-gnu/sparc/plt.c +++ b/sysdeps/linux-gnu/sparc/plt.c @@ -1,5 +1,5 @@ #include <gelf.h> -#include "ltrace.h" +#include "main.h" #include "elf.h" GElf_Addr diff --git a/sysdeps/linux-gnu/sparc/ptrace.h b/sysdeps/linux-gnu/sparc/ptrace.h index 953b72a..2c4aa1d 100644 --- a/sysdeps/linux-gnu/sparc/ptrace.h +++ b/sysdeps/linux-gnu/sparc/ptrace.h @@ -12,7 +12,7 @@ #define PTRACE_DETACH PTRACE_SUNDETACH #include <asm/reg.h> -#include "ltrace.h" +#include "main.h" typedef struct { int valid; diff --git a/sysdeps/linux-gnu/sparc/regs.c b/sysdeps/linux-gnu/sparc/regs.c index 17ffd9e..ff967c0 100644 --- a/sysdeps/linux-gnu/sparc/regs.c +++ b/sysdeps/linux-gnu/sparc/regs.c @@ -4,7 +4,7 @@ #include <sys/types.h> #include "ptrace.h" -#include "ltrace.h" +#include "main.h" void * get_instruction_pointer(Process *proc) { diff --git a/sysdeps/linux-gnu/sparc/trace.c b/sysdeps/linux-gnu/sparc/trace.c index 8e8db81..069c0f5 100644 --- a/sysdeps/linux-gnu/sparc/trace.c +++ b/sysdeps/linux-gnu/sparc/trace.c @@ -8,7 +8,7 @@ #include <signal.h> #include <string.h> #include "ptrace.h" -#include "ltrace.h" +#include "main.h" void get_arch_dep(Process *proc) { diff --git a/sysdeps/linux-gnu/trace.c b/sysdeps/linux-gnu/trace.c index b8d0868..15b597b 100644 --- a/sysdeps/linux-gnu/trace.c +++ b/sysdeps/linux-gnu/trace.c @@ -8,7 +8,7 @@ #include "ptrace.h" #include <asm/unistd.h> -#include "ltrace.h" +#include "main.h" #include "options.h" #include "sysdep.h" #include "debug.h" diff --git a/sysdeps/linux-gnu/x86_64/plt.c b/sysdeps/linux-gnu/x86_64/plt.c index 86afe55..2f7e238 100644 --- a/sysdeps/linux-gnu/x86_64/plt.c +++ b/sysdeps/linux-gnu/x86_64/plt.c @@ -1,5 +1,5 @@ #include <gelf.h> -#include "ltrace.h" +#include "main.h" #include "elf.h" GElf_Addr diff --git a/sysdeps/linux-gnu/x86_64/regs.c b/sysdeps/linux-gnu/x86_64/regs.c index e9c991d..50da342 100644 --- a/sysdeps/linux-gnu/x86_64/regs.c +++ b/sysdeps/linux-gnu/x86_64/regs.c @@ -6,7 +6,7 @@ #include <sys/ptrace.h> #include <sys/reg.h> -#include "ltrace.h" +#include "main.h" #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) # define PTRACE_PEEKUSER PTRACE_PEEKUSR diff --git a/sysdeps/linux-gnu/x86_64/trace.c b/sysdeps/linux-gnu/x86_64/trace.c index bbaa5f7..585b85e 100644 --- a/sysdeps/linux-gnu/x86_64/trace.c +++ b/sysdeps/linux-gnu/x86_64/trace.c @@ -9,7 +9,7 @@ #include <sys/ptrace.h> #include <sys/reg.h> -#include "ltrace.h" +#include "main.h" #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) # define PTRACE_PEEKUSER PTRACE_PEEKUSR |