aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Wienand <ianw@ieee.org>2006-02-16 06:00:00 +0100
committerIan Wienand <ianw@debian.org>2006-02-16 06:00:00 +0100
commit3219f320604810532a4938dda8f9dfadb0e840f3 (patch)
treef2430182cafc250b2fcb9eb5c05730b2ce0d802f
parente1dd50cdd23a11bf7be6c81b3a2acbe35f19fdea (diff)
downloadltrace-3219f320604810532a4938dda8f9dfadb0e840f3.tar.gz
Some fixes...
* read_config_file.c: initialise pt stack argument to stop warning * summary.c: make show_summary() obey -C for demangaling function names
-rw-r--r--ChangeLog11
-rw-r--r--Makefile.in5
-rw-r--r--breakpoints.c78
-rw-r--r--debian/changelog1
-rw-r--r--debug.c4
-rw-r--r--demangle.c22
-rw-r--r--dict.c87
-rw-r--r--display_args.c273
-rw-r--r--elf.c564
-rw-r--r--execute_program.c16
-rw-r--r--ltrace.c86
-rw-r--r--options.c340
-rw-r--r--output.c151
-rw-r--r--proc.c22
-rw-r--r--process_event.c268
-rw-r--r--read_config_file.c131
-rw-r--r--summary.c54
-rw-r--r--sysdeps/linux-gnu/alpha/plt.c5
-rw-r--r--sysdeps/linux-gnu/alpha/regs.c24
-rw-r--r--sysdeps/linux-gnu/alpha/trace.c46
-rw-r--r--sysdeps/linux-gnu/arm/plt.c5
-rw-r--r--sysdeps/linux-gnu/arm/regs.c16
-rw-r--r--sysdeps/linux-gnu/arm/trace.c51
-rw-r--r--sysdeps/linux-gnu/breakpoint.c52
-rw-r--r--sysdeps/linux-gnu/i386/plt.c5
-rw-r--r--sysdeps/linux-gnu/i386/regs.c22
-rw-r--r--sysdeps/linux-gnu/i386/trace.c61
-rw-r--r--sysdeps/linux-gnu/m68k/plt.c7
-rw-r--r--sysdeps/linux-gnu/m68k/regs.c22
-rw-r--r--sysdeps/linux-gnu/m68k/trace.c69
-rw-r--r--sysdeps/linux-gnu/ppc/plt.c5
-rw-r--r--sysdeps/linux-gnu/ppc/regs.c24
-rw-r--r--sysdeps/linux-gnu/ppc/trace.c40
-rw-r--r--sysdeps/linux-gnu/proc.c10
-rw-r--r--sysdeps/linux-gnu/s390/plt.c5
-rw-r--r--sysdeps/linux-gnu/s390/regs.c22
-rw-r--r--sysdeps/linux-gnu/s390/trace.c56
-rw-r--r--sysdeps/linux-gnu/sparc/plt.c5
-rw-r--r--sysdeps/linux-gnu/sparc/regs.c24
-rw-r--r--sysdeps/linux-gnu/sparc/trace.c36
-rw-r--r--sysdeps/linux-gnu/trace.c74
-rw-r--r--sysdeps/linux-gnu/x86_64/plt.c5
-rw-r--r--sysdeps/linux-gnu/x86_64/regs.c22
-rw-r--r--sysdeps/linux-gnu/x86_64/trace.c85
-rw-r--r--wait_for_something.c45
45 files changed, 1601 insertions, 1355 deletions
diff --git a/ChangeLog b/ChangeLog
index f8f0b90..08b0d62 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,12 @@
+2006-02-16 Ian Wienand <ianw@ieee.org>
+
+ * read_config_file.c: initialise pt stack argument to stop warning
+ * summary.c: make show_summary() obey -C for demangaling function names
+
2006-02-16 Richard Kettlewell <rjk@nchiper.com>
- * display_args.c: update to handle variable length strings arguments
+ * display_args.c: update to handle variable length strings
+ arguments
* ltrace.h: likewise
* output.c: likewise
* read_config_file.c: likewise
@@ -20,7 +26,6 @@
2006-02-16 Ian Wienand <ianw@ieee.org>
* README: update
- * Makefile.in: remove obsolete -I- for -iquote
+ * Makefile.in: remove obsolete -I- for -iquote, add TAGS target
* debug.c, debug.h: __PRETTY_FUNCTION__ is const; change specifier
to stop warnings.
- * read_config_file.c: initialise pt stack argument to stop warning \ No newline at end of file
diff --git a/Makefile.in b/Makefile.in
index 2324d68..c59b021 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -63,6 +63,9 @@ install: ltrace
dummy:
-.PHONY: all clean distclean dist install dummy
+TAGS:
+ find -name '*.c' -o -name '*.h' | xargs etags -a
+
+.PHONY: all clean distclean dist install dummy TAGS
.EXPORT_ALL_VARIABLES:
diff --git a/breakpoints.c b/breakpoints.c
index f91e62c..fbeac81 100644
--- a/breakpoints.c
+++ b/breakpoints.c
@@ -18,54 +18,58 @@
/*****************************************************************************/
-struct breakpoint *
-address2bpstruct(struct process * proc, void * addr) {
+struct breakpoint *address2bpstruct(struct process *proc, void *addr)
+{
return dict_find_entry(proc->breakpoints, addr);
}
-void
-insert_breakpoint(struct process * proc, void * addr) {
- struct breakpoint * sbp;
+void insert_breakpoint(struct process *proc, void *addr)
+{
+ struct breakpoint *sbp;
if (!proc->breakpoints) {
- proc->breakpoints = dict_init(dict_key2hash_int, dict_key_cmp_int);
- /* atexit(brk_dict_clear); */ /* why bother to do this on exit? */
+ proc->breakpoints =
+ dict_init(dict_key2hash_int, dict_key_cmp_int);
+ /* atexit(brk_dict_clear); *//* why bother to do this on exit? */
}
sbp = dict_find_entry(proc->breakpoints, addr);
if (!sbp) {
sbp = malloc(sizeof(struct breakpoint));
if (!sbp) {
- return; /* TODO FIXME XXX: error_mem */
+ return; /* TODO FIXME XXX: error_mem */
}
dict_enter(proc->breakpoints, addr, sbp);
sbp->addr = addr;
sbp->enabled = 0;
}
sbp->enabled++;
- if (sbp->enabled==1 && proc->pid) enable_breakpoint(proc->pid, sbp);
+ if (sbp->enabled == 1 && proc->pid)
+ enable_breakpoint(proc->pid, sbp);
}
-void
-delete_breakpoint(struct process * proc, void * addr) {
- struct breakpoint * sbp = dict_find_entry(proc->breakpoints, addr);
- assert(sbp); /* FIXME: remove after debugging has been done. */
+void delete_breakpoint(struct process *proc, void *addr)
+{
+ struct breakpoint *sbp = dict_find_entry(proc->breakpoints, addr);
+ assert(sbp); /* FIXME: remove after debugging has been done. */
/* This should only happen on out-of-memory conditions. */
- if (sbp == NULL) return;
+ if (sbp == NULL)
+ return;
sbp->enabled--;
- if (sbp->enabled == 0) disable_breakpoint(proc->pid, sbp);
+ if (sbp->enabled == 0)
+ disable_breakpoint(proc->pid, sbp);
assert(sbp->enabled >= 0);
}
-static void
-enable_bp_cb(void * addr, void * sbp, void * proc) {
+static void enable_bp_cb(void *addr, void *sbp, void *proc)
+{
if (((struct breakpoint *)sbp)->enabled) {
enable_breakpoint(((struct process *)proc)->pid, sbp);
}
}
-void
-enable_all_breakpoints(struct process * proc) {
+void enable_all_breakpoints(struct process *proc)
+{
if (proc->breakpoints_enabled <= 0) {
#ifdef __powerpc__
unsigned long a;
@@ -76,7 +80,8 @@ enable_all_breakpoints(struct process * proc) {
* dont enable the breakpoints
*/
if (opt_L) {
- a = ptrace(PTRACE_PEEKTEXT, proc->pid, proc->list_of_symbols->enter_addr, 0);
+ a = ptrace(PTRACE_PEEKTEXT, proc->pid,
+ proc->list_of_symbols->enter_addr, 0);
if (a == 0x0)
return;
}
@@ -84,21 +89,22 @@ enable_all_breakpoints(struct process * proc) {
debug(1, "Enabling breakpoints for pid %u...", proc->pid);
if (proc->breakpoints) {
- dict_apply_to_all(proc->breakpoints, enable_bp_cb, proc);
+ dict_apply_to_all(proc->breakpoints, enable_bp_cb,
+ proc);
}
}
proc->breakpoints_enabled = 1;
}
-static void
-disable_bp_cb(void * addr, void * sbp, void * proc) {
+static void disable_bp_cb(void *addr, void *sbp, void *proc)
+{
if (((struct breakpoint *)sbp)->enabled) {
disable_breakpoint(((struct process *)proc)->pid, sbp);
}
}
-void
-disable_all_breakpoints(struct process * proc) {
+void disable_all_breakpoints(struct process *proc)
+{
if (proc->breakpoints_enabled) {
debug(1, "Disabling breakpoints for pid %u...", proc->pid);
dict_apply_to_all(proc->breakpoints, disable_bp_cb, proc);
@@ -106,17 +112,17 @@ disable_all_breakpoints(struct process * proc) {
proc->breakpoints_enabled = 0;
}
-static void
-free_bp_cb(void * addr, void * sbp, void * data) {
+static void free_bp_cb(void *addr, void *sbp, void *data)
+{
assert(sbp);
free(sbp);
}
-void
-breakpoints_init(struct process * proc) {
- struct library_symbol * sym;
+void breakpoints_init(struct process *proc)
+{
+ struct library_symbol *sym;
- if (proc->breakpoints) { /* let's remove that struct */
+ if (proc->breakpoints) { /* let's remove that struct */
/* TODO FIXME XXX: free() all "struct breakpoint"s */
dict_apply_to_all(proc->breakpoints, free_bp_cb, NULL);
dict_clear(proc->breakpoints);
@@ -126,12 +132,12 @@ breakpoints_init(struct process * proc) {
if (opt_L && proc->filename) {
proc->list_of_symbols = read_elf(proc->filename);
if (opt_e) {
- struct library_symbol ** tmp1 = &(proc->list_of_symbols);
- while(*tmp1) {
- struct opt_e_t * tmp2 = opt_e;
+ struct library_symbol **tmp1 = &(proc->list_of_symbols);
+ while (*tmp1) {
+ struct opt_e_t *tmp2 = opt_e;
int keep = !opt_e_enable;
- while(tmp2) {
+ while (tmp2) {
if (!strcmp((*tmp1)->name, tmp2->name)) {
keep = opt_e_enable;
}
@@ -149,7 +155,7 @@ breakpoints_init(struct process * proc) {
}
sym = proc->list_of_symbols;
while (sym) {
- insert_breakpoint(proc, sym->enter_addr); /* proc->pid==0 delays enabling. */
+ insert_breakpoint(proc, sym->enter_addr); /* proc->pid==0 delays enabling. */
sym = sym->next;
}
proc->callstack_depth = 0;
diff --git a/debian/changelog b/debian/changelog
index 5337602..1ed1c27 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -5,6 +5,7 @@ ltrace (0.3.37.1) unstable; urgency=low
* Closes: #127503,#280608 -- update man page typos
* Closes: #339348 -- fix putenv typo in ltrace.conf
* Closes: #257903 -- incorporate variable length args patch
+ * Closes: #282051 -- demange names when -c used with -C
* See "upstream" ChangeLog for other changes (mostly warning fixes)
* Update README to point to Alioth home: http://ltrace.alioth.debian.org
diff --git a/debug.c b/debug.c
index dd2cebd..6b5bb8e 100644
--- a/debug.c
+++ b/debug.c
@@ -5,8 +5,8 @@
#include "options.h"
#include "output.h"
-void
-debug_(int level, char *file, int line, const char *func, char *fmt, ...) {
+void debug_(int level, char *file, int line, const char *func, char *fmt, ...)
+{
char buf[1024];
va_list args;
diff --git a/demangle.c b/demangle.c
index 63b7da6..0d86888 100644
--- a/demangle.c
+++ b/demangle.c
@@ -16,19 +16,19 @@
/*****************************************************************************/
-static struct dict * d = NULL;
+static struct dict *d = NULL;
-static void
-my_demangle_dict_clear(void) {
+static void my_demangle_dict_clear(void)
+{
/* FIXME TODO XXX: I should also free all (key,value) pairs */
dict_clear(d);
}
-const char *
-my_demangle(const char * function_name) {
- const char * tmp, * fn_copy;
+const char *my_demangle(const char *function_name)
+{
+ const char *tmp, *fn_copy;
#if !defined HAVE_LIBIBERTY && defined HAVE_LIBSUPC__
- extern char *__cxa_demangle (const char *, char *, size_t *, int *);
+ extern char *__cxa_demangle(const char *, char *, size_t *, int *);
int status = 0;
#endif
@@ -36,7 +36,7 @@ my_demangle(const char * function_name) {
d = dict_init(dict_key2hash_string, dict_key_cmp_string);
atexit(my_demangle_dict_clear);
}
-
+
tmp = dict_find_entry(d, (void *)function_name);
if (!tmp) {
fn_copy = strdup(function_name);
@@ -45,8 +45,10 @@ my_demangle(const char * function_name) {
#elif defined HAVE_LIBSUPC__
tmp = __cxa_demangle(function_name, NULL, NULL, &status);
#endif
- if (!tmp) tmp = fn_copy;
- if (tmp) dict_enter(d, (void *)fn_copy, (void *)tmp);
+ if (!tmp)
+ tmp = fn_copy;
+ if (tmp)
+ dict_enter(d, (void *)fn_copy, (void *)tmp);
}
return tmp;
}
diff --git a/dict.c b/dict.c
index 944c202..a1ec8c1 100644
--- a/dict.c
+++ b/dict.c
@@ -13,26 +13,27 @@
struct dict_entry {
unsigned int hash;
- void * key;
- void * value;
- struct dict_entry * next;
+ void *key;
+ void *value;
+ struct dict_entry *next;
};
/* #define DICTTABLESIZE 97 */
-#define DICTTABLESIZE 997 /* Semi-randomly selected prime number. */
+#define DICTTABLESIZE 997 /* Semi-randomly selected prime number. */
/* #define DICTTABLESIZE 9973 */
/* #define DICTTABLESIZE 99991 */
/* #define DICTTABLESIZE 999983 */
struct dict {
- struct dict_entry * buckets[DICTTABLESIZE];
- unsigned int (*key2hash)(void *);
- int (*key_cmp)(void *, void *);
+ struct dict_entry *buckets[DICTTABLESIZE];
+ unsigned int (*key2hash) (void *);
+ int (*key_cmp) (void *, void *);
};
-struct dict *
-dict_init(unsigned int (*key2hash)(void *), int (*key_cmp)(void *, void *)) {
- struct dict * d;
+struct dict *dict_init(unsigned int (*key2hash) (void *),
+ int (*key_cmp) (void *, void *))
+{
+ struct dict *d;
int i;
d = malloc(sizeof(struct dict));
@@ -40,7 +41,7 @@ dict_init(unsigned int (*key2hash)(void *), int (*key_cmp)(void *, void *)) {
perror("malloc()");
exit(1);
}
- for (i = 0; i < DICTTABLESIZE; i++) { /* better use memset()? */
+ for (i = 0; i < DICTTABLESIZE; i++) { /* better use memset()? */
d->buckets[i] = NULL;
}
d->key2hash = key2hash;
@@ -48,10 +49,10 @@ dict_init(unsigned int (*key2hash)(void *), int (*key_cmp)(void *, void *)) {
return d;
}
-void
-dict_clear(struct dict * d) {
+void dict_clear(struct dict *d)
+{
int i;
- struct dict_entry * entry, * nextentry;
+ struct dict_entry *entry, *nextentry;
assert(d);
for (i = 0; i < DICTTABLESIZE; i++) {
@@ -64,9 +65,9 @@ dict_clear(struct dict * d) {
free(d);
}
-int
-dict_enter(struct dict * d, void * key, void * value) {
- struct dict_entry * entry, * newentry;
+int dict_enter(struct dict *d, void *key, void *value)
+{
+ struct dict_entry *entry, *newentry;
unsigned int hash = d->key2hash(key);
unsigned int bucketpos = hash % DICTTABLESIZE;
@@ -77,26 +78,30 @@ dict_enter(struct dict * d, void * key, void * value) {
exit(1);
}
- newentry->hash = hash;
- newentry->key = key;
+ newentry->hash = hash;
+ newentry->key = key;
newentry->value = value;
- newentry->next = NULL;
+ newentry->next = NULL;
entry = d->buckets[bucketpos];
- while (entry && entry->next) entry = entry->next;
+ while (entry && entry->next)
+ entry = entry->next;
- if (entry) entry->next = newentry;
- else d->buckets[bucketpos] = newentry;
+ if (entry)
+ entry->next = newentry;
+ else
+ d->buckets[bucketpos] = newentry;
- debug(3, "new dict entry at %p[%d]: (%p,%p)\n", d, bucketpos, key, value);
+ debug(3, "new dict entry at %p[%d]: (%p,%p)\n", d, bucketpos, key,
+ value);
return 0;
}
-void *
-dict_find_entry(struct dict * d, void * key) {
+void *dict_find_entry(struct dict *d, void *key)
+{
unsigned int hash = d->key2hash(key);
unsigned int bucketpos = hash % DICTTABLESIZE;
- struct dict_entry * entry;
+ struct dict_entry *entry;
assert(d);
for (entry = d->buckets[bucketpos]; entry; entry = entry->next) {
@@ -111,14 +116,16 @@ dict_find_entry(struct dict * d, void * key) {
}
void
-dict_apply_to_all(struct dict * d, void (*func)(void *key, void *value, void *data), void *data) {
+dict_apply_to_all(struct dict *d,
+ void (*func) (void *key, void *value, void *data), void *data)
+{
int i;
if (!d) {
return;
}
for (i = 0; i < DICTTABLESIZE; i++) {
- struct dict_entry * entry = d->buckets[i];
+ struct dict_entry *entry = d->buckets[i];
while (entry) {
func(entry->key, entry->value, data);
entry = entry->next;
@@ -128,35 +135,35 @@ dict_apply_to_all(struct dict * d, void (*func)(void *key, void *value, void *da
/*****************************************************************************/
-unsigned int
-dict_key2hash_string(void * key) {
- const char * s = (const char *)key;
+unsigned int dict_key2hash_string(void *key)
+{
+ const char *s = (const char *)key;
unsigned int total = 0, shift = 0;
assert(key);
while (*s) {
total = total ^ ((*s) << shift);
shift += 5;
- if (shift > 24) shift -= 24;
+ if (shift > 24)
+ shift -= 24;
s++;
}
return total;
}
-int
-dict_key_cmp_string(void * key1, void * key2) {
+int dict_key_cmp_string(void *key1, void *key2)
+{
assert(key1);
assert(key2);
return strcmp((const char *)key1, (const char *)key2);
}
-unsigned int
-dict_key2hash_int(void * key) {
+unsigned int dict_key2hash_int(void *key)
+{
return (unsigned long)key;
}
-int
-dict_key_cmp_int(void * key1, void * key2) {
+int dict_key_cmp_int(void *key1, void *key2)
+{
return key1 - key2;
}
-
diff --git a/display_args.c b/display_args.c
index 9a988e1..b8dc0f6 100644
--- a/display_args.c
+++ b/display_args.c
@@ -11,97 +11,110 @@
#include "options.h"
static int display_char(int what);
-static int display_string(enum tof type, struct process * proc, int arg_num);
-static int display_stringN(int arg2, enum tof type, struct process * proc, int arg_num);
-static int display_unknown(enum tof type, struct process * proc, int arg_num);
-static int display_format(enum tof type, struct process * proc, int arg_num);
+static int display_string(enum tof type, struct process *proc, int arg_num);
+static int display_stringN(int arg2, enum tof type, struct process *proc,
+ int arg_num);
+static int display_unknown(enum tof type, struct process *proc, int arg_num);
+static int display_format(enum tof type, struct process *proc, int arg_num);
int
-display_arg(enum tof type, struct process * proc, int arg_num, const struct complete_arg_type *at) {
+display_arg(enum tof type, struct process *proc, int arg_num,
+ const struct complete_arg_type *at)
+{
int tmp;
long arg;
- if(!at)
+ if (!at)
+ return display_unknown(type, proc, arg_num);
+ switch (at->at) {
+ case ARGTYPE_VOID:
+ return 0;
+ case ARGTYPE_INT:
+ return fprintf(output, "%d",
+ (int)gimme_arg(type, proc, arg_num));
+ case ARGTYPE_UINT:
+ return fprintf(output, "%u",
+ (unsigned)gimme_arg(type, proc, arg_num));
+ case ARGTYPE_LONG:
+ return fprintf(output, "%ld", gimme_arg(type, proc, arg_num));
+ case ARGTYPE_ULONG:
+ return fprintf(output, "%lu",
+ (unsigned long)gimme_arg(type, proc, arg_num));
+ case ARGTYPE_OCTAL:
+ return fprintf(output, "0%o",
+ (unsigned)gimme_arg(type, proc, arg_num));
+ case ARGTYPE_CHAR:
+ tmp = fprintf(output, "'");
+ tmp += display_char((int)gimme_arg(type, proc, arg_num));
+ tmp += fprintf(output, "'");
+ return tmp;
+ case ARGTYPE_ADDR:
+ arg = gimme_arg(type, proc, arg_num);
+ if (!arg) {
+ return fprintf(output, "NULL");
+ } else {
+ return fprintf(output, "%p", (void *)arg);
+ }
+ case ARGTYPE_FORMAT:
+ return display_format(type, proc, arg_num);
+ case ARGTYPE_STRING:
+ return display_string(type, proc, arg_num);
+ case ARGTYPE_STRINGN:
+ return display_stringN(at->argno, type, proc, arg_num);
+ case ARGTYPE_UNKNOWN:
+ default:
return display_unknown(type, proc, arg_num);
- switch(at->at) {
- case ARGTYPE_VOID:
- return 0;
- case ARGTYPE_INT:
- return fprintf(output, "%d", (int)gimme_arg(type, proc, arg_num));
- case ARGTYPE_UINT:
- return fprintf(output, "%u", (unsigned)gimme_arg(type, proc, arg_num));
- case ARGTYPE_LONG:
- return fprintf(output, "%ld", gimme_arg(type, proc, arg_num));
- case ARGTYPE_ULONG:
- return fprintf(output, "%lu", (unsigned long)gimme_arg(type, proc, arg_num));
- case ARGTYPE_OCTAL:
- return fprintf(output, "0%o", (unsigned)gimme_arg(type, proc, arg_num));
- case ARGTYPE_CHAR:
- tmp = fprintf(output, "'");
- tmp += display_char((int)gimme_arg(type, proc, arg_num));
- tmp += fprintf(output, "'");
- return tmp;
- case ARGTYPE_ADDR:
- arg = gimme_arg(type, proc, arg_num);
- if (!arg) {
- return fprintf(output, "NULL");
- } else {
- return fprintf(output, "%p", (void *)arg);
- }
- case ARGTYPE_FORMAT:
- return display_format(type, proc, arg_num);
- case ARGTYPE_STRING:
- return display_string(type, proc, arg_num);
- case ARGTYPE_STRINGN:
- return display_stringN(at->argno, type, proc, arg_num);
- case ARGTYPE_UNKNOWN:
- default:
- return display_unknown(type, proc, arg_num);
}
return fprintf(output, "?");
}
-static int
-display_char(int what) {
- switch(what) {
- case -1: return fprintf(output, "EOF");
- case '\r': return fprintf(output, "\\r");
- case '\n': return fprintf(output, "\\n");
- case '\t': return fprintf(output, "\\t");
- case '\b': return fprintf(output, "\\b");
- case '\\': return fprintf(output, "\\\\");
- default:
- if ((what<32) || (what>126)) {
- return fprintf(output, "\\%03o", (unsigned char)what);
- } else {
- return fprintf(output, "%c", what);
- }
+static int display_char(int what)
+{
+ switch (what) {
+ case -1:
+ return fprintf(output, "EOF");
+ case '\r':
+ return fprintf(output, "\\r");
+ case '\n':
+ return fprintf(output, "\\n");
+ case '\t':
+ return fprintf(output, "\\t");
+ case '\b':
+ return fprintf(output, "\\b");
+ case '\\':
+ return fprintf(output, "\\\\");
+ default:
+ if ((what < 32) || (what > 126)) {
+ return fprintf(output, "\\%03o", (unsigned char)what);
+ } else {
+ return fprintf(output, "%c", what);
+ }
}
}
-static int string_maxlength=INT_MAX;
+static int string_maxlength = INT_MAX;
#define MIN(a,b) (((a)<(b)) ? (a) : (b))
-static int
-display_string(enum tof type, struct process * proc, int arg_num) {
- void * addr;
- unsigned char * str1;
+static int display_string(enum tof type, struct process *proc, int arg_num)
+{
+ void *addr;
+ unsigned char *str1;
int i;
- int len=0;
+ int len = 0;
addr = (void *)gimme_arg(type, proc, arg_num);
if (!addr) {
return fprintf(output, "NULL");
}
- str1 = malloc(MIN(opt_s,string_maxlength)+3);
+ str1 = malloc(MIN(opt_s, string_maxlength) + 3);
if (!str1) {
return fprintf(output, "???");
}
- umovestr(proc, addr, MIN(opt_s,string_maxlength)+1, str1);
+ umovestr(proc, addr, MIN(opt_s, string_maxlength) + 1, str1);
len = fprintf(output, "\"");
- for(i=0; i<MIN(opt_s,string_maxlength); i++) {
+ for (i = 0; i < MIN(opt_s, string_maxlength); i++) {
if (str1[i]) {
len += display_char(str1[i]);
} else {
@@ -117,47 +130,48 @@ display_string(enum tof type, struct process * proc, int arg_num) {
}
static int
-display_stringN(int arg2, enum tof type, struct process * proc, int arg_num) {
+display_stringN(int arg2, enum tof type, struct process *proc, int arg_num)
+{
int a;
- string_maxlength=gimme_arg(type, proc, arg2-1);
+ string_maxlength = gimme_arg(type, proc, arg2 - 1);
a = display_string(type, proc, arg_num);
- string_maxlength=INT_MAX;
+ string_maxlength = INT_MAX;
return a;
}
-static int
-display_unknown(enum tof type, struct process * proc, int arg_num) {
+static int display_unknown(enum tof type, struct process *proc, int arg_num)
+{
long tmp;
tmp = gimme_arg(type, proc, arg_num);
- if (tmp<1000000 && tmp>-1000000) {
+ if (tmp < 1000000 && tmp > -1000000) {
return fprintf(output, "%ld", tmp);
} else {
return fprintf(output, "%p", (void *)tmp);
}
}
-static int
-display_format(enum tof type, struct process * proc, int arg_num) {
- void * addr;
- unsigned char * str1;
+static int display_format(enum tof type, struct process *proc, int arg_num)
+{
+ void *addr;
+ unsigned char *str1;
int i;
- int len=0;
+ int len = 0;
addr = (void *)gimme_arg(type, proc, arg_num);
if (!addr) {
return fprintf(output, "NULL");
}
- str1 = malloc(MIN(opt_s,string_maxlength)+3);
+ str1 = malloc(MIN(opt_s, string_maxlength) + 3);
if (!str1) {
return fprintf(output, "???");
}
- umovestr(proc, addr, MIN(opt_s,string_maxlength)+1, str1);
+ umovestr(proc, addr, MIN(opt_s, string_maxlength) + 1, str1);
len = fprintf(output, "\"");
- for(i=0; len<MIN(opt_s,string_maxlength)+1; i++) {
+ for (i = 0; len < MIN(opt_s, string_maxlength) + 1; i++) {
if (str1[i]) {
len += display_char(str1[i]);
} else {
@@ -168,67 +182,114 @@ display_format(enum tof type, struct process * proc, int arg_num) {
if (str1[i] && (opt_s <= string_maxlength)) {
len += fprintf(output, "...");
}
- for(i=0; str1[i]; i++) {
- if (str1[i]=='%') {
+ for (i = 0; str1[i]; i++) {
+ if (str1[i] == '%') {
int is_long = 0;
- while(1) {
+ while (1) {
unsigned char c = str1[++i];
if (c == '%') {
break;
} else if (!c) {
break;
- } else if (strchr ("lzZtj", c)) {
+ } else if (strchr("lzZtj", c)) {
is_long++;
if (c == 'j')
is_long++;
- if (is_long > 1 && sizeof (long) < sizeof (long long)) {
+ if (is_long > 1
+ && sizeof(long) <
+ sizeof(long long)) {
len += fprintf(output, ", ...");
- str1[i+1]='\0';
+ str1[i + 1] = '\0';
break;
}
- } else if (c=='d' || c=='i') {
+ } else if (c == 'd' || c == 'i') {
if (is_long)
- len += fprintf(output, ", %d", (int)gimme_arg(type, proc, ++arg_num));
+ len +=
+ fprintf(output, ", %d",
+ (int)gimme_arg(type,
+ proc,
+ ++arg_num));
else
- len += fprintf(output, ", %ld", gimme_arg(type, proc, ++arg_num));
+ len +=
+ fprintf(output, ", %ld",
+ gimme_arg(type,
+ proc,
+ ++arg_num));
break;
- } else if (c=='u') {
+ } else if (c == 'u') {
if (is_long)
- len += fprintf(output, ", %u", (int)gimme_arg(type, proc, ++arg_num));
+ len +=
+ fprintf(output, ", %u",
+ (int)gimme_arg(type,
+ proc,
+ ++arg_num));
else
- len += fprintf(output, ", %lu", gimme_arg(type, proc, ++arg_num));
+ len +=
+ fprintf(output, ", %lu",
+ gimme_arg(type,
+ proc,
+ ++arg_num));
break;
- } else if (c=='o') {
+ } else if (c == 'o') {
if (is_long)
- len += fprintf(output, ", 0%o", (int)gimme_arg(type, proc, ++arg_num));
+ len +=
+ fprintf(output, ", 0%o",
+ (int)gimme_arg(type,
+ proc,
+ ++arg_num));
else
- len += fprintf(output, ", 0%lo", gimme_arg(type, proc, ++arg_num));
+ len +=
+ fprintf(output, ", 0%lo",
+ gimme_arg(type,
+ proc,
+ ++arg_num));
break;
- } else if (c=='x' || c=='X') {
+ } else if (c == 'x' || c == 'X') {
if (is_long)
- len += fprintf(output, ", %#x", (int)gimme_arg(type, proc, ++arg_num));
+ len +=
+ fprintf(output, ", %#x",
+ (int)gimme_arg(type,
+ proc,
+ ++arg_num));
else
- len += fprintf(output, ", %#lx", gimme_arg(type, proc, ++arg_num));
+ len +=
+ fprintf(output, ", %#lx",
+ gimme_arg(type,
+ proc,
+ ++arg_num));
break;
} else if (strchr("eEfFgGaACS", c)
- || (is_long && (c=='c' || c=='s'))) {
+ || (is_long
+ && (c == 'c' || c == 's'))) {
len += fprintf(output, ", ...");
- str1[i+1]='\0';
+ str1[i + 1] = '\0';
break;
- } else if (c=='c') {
+ } else if (c == 'c') {
len += fprintf(output, ", '");
- len += display_char((int)gimme_arg(type, proc, ++arg_num));
+ len += display_char((int)
+ gimme_arg(type,
+ proc,
+ ++arg_num));
len += fprintf(output, "'");
break;
- } else if (c=='s') {
+ } else if (c == 's') {
len += fprintf(output, ", ");
- len += display_string(type, proc, ++arg_num);
+ len +=
+ display_string(type, proc,
+ ++arg_num);
break;
- } else if (c=='p' || c=='n') {
- len += fprintf(output, ", %p", (void *)gimme_arg(type, proc, ++arg_num));
+ } else if (c == 'p' || c == 'n') {
+ len +=
+ fprintf(output, ", %p",
+ (void *)gimme_arg(type,
+ proc,
+ ++arg_num));
break;
- } else if (c=='*') {
- len += fprintf(output, ", %d", (int)gimme_arg(type, proc, ++arg_num));
+ } else if (c == '*') {
+ len +=
+ fprintf(output, ", %d",
+ (int)gimme_arg(type, proc,
+ ++arg_num));
}
}
}
diff --git a/elf.c b/elf.c
index 1d37eb9..4f543d7 100644
--- a/elf.c
+++ b/elf.c
@@ -16,322 +16,320 @@
#include "elf.h"
#include "debug.h"
-static void do_init_elf (struct ltelf *lte, const char *filename);
-static void do_close_elf (struct ltelf *lte);
-static void add_library_symbol (GElf_Addr addr, const char *name,
- struct library_symbol **library_symbolspp);
-static int in_load_libraries (const char *name, struct ltelf *lte);
+static void do_init_elf(struct ltelf *lte, const char *filename);
+static void do_close_elf(struct ltelf *lte);
+static void add_library_symbol(GElf_Addr addr, const char *name,
+ struct library_symbol **library_symbolspp);
+static int in_load_libraries(const char *name, struct ltelf *lte);
-static void
-do_init_elf (struct ltelf *lte, const char *filename)
+static void do_init_elf(struct ltelf *lte, const char *filename)
{
- int i;
- GElf_Addr relplt_addr = 0;
- size_t relplt_size = 0;
+ int i;
+ GElf_Addr relplt_addr = 0;
+ size_t relplt_size = 0;
- debug (1, "Reading ELF from %s...", filename);
+ debug(1, "Reading ELF from %s...", filename);
- memset (lte, 0, sizeof (*lte));
- lte->fd = open (filename, O_RDONLY);
- if (lte->fd == -1)
- error (EXIT_FAILURE, errno, "Can't open \"%s\"", filename);
+ memset(lte, 0, sizeof(*lte));
+ lte->fd = open(filename, O_RDONLY);
+ if (lte->fd == -1)
+ error(EXIT_FAILURE, errno, "Can't open \"%s\"", filename);
#ifdef HAVE_ELF_C_READ_MMAP
- lte->elf = elf_begin (lte->fd, ELF_C_READ_MMAP, NULL);
+ lte->elf = elf_begin(lte->fd, ELF_C_READ_MMAP, NULL);
#else
- lte->elf = elf_begin (lte->fd, ELF_C_READ, NULL);
+ lte->elf = elf_begin(lte->fd, ELF_C_READ, NULL);
#endif
- if (lte->elf == NULL || elf_kind (lte->elf) != ELF_K_ELF)
- error (EXIT_FAILURE, 0, "Can't open ELF file \"%s\"", filename);
+ if (lte->elf == NULL || elf_kind(lte->elf) != ELF_K_ELF)
+ error(EXIT_FAILURE, 0, "Can't open ELF file \"%s\"", filename);
- if (gelf_getehdr (lte->elf, &lte->ehdr) == NULL)
- error (EXIT_FAILURE, 0, "Can't read ELF header of \"%s\"", filename);
+ if (gelf_getehdr(lte->elf, &lte->ehdr) == NULL)
+ error(EXIT_FAILURE, 0, "Can't read ELF header of \"%s\"",
+ filename);
- if (lte->ehdr.e_type != ET_EXEC && lte->ehdr.e_type != ET_DYN)
- error (EXIT_FAILURE, 0, "\"%s\" is not an ELF executable nor shared library",
- filename);
+ if (lte->ehdr.e_type != ET_EXEC && lte->ehdr.e_type != ET_DYN)
+ error(EXIT_FAILURE, 0,
+ "\"%s\" is not an ELF executable nor shared library",
+ filename);
- if (lte->ehdr.e_ident[EI_CLASS] != LT_ELFCLASS
- || (lte->ehdr.e_machine != LT_ELF_MACHINE
+ if (lte->ehdr.e_ident[EI_CLASS] != LT_ELFCLASS
+ || (lte->ehdr.e_machine != LT_ELF_MACHINE
#ifdef LT_ELF_MACHINE2
- && lte->ehdr.e_machine != LT_ELF_MACHINE2
+ && lte->ehdr.e_machine != LT_ELF_MACHINE2
#endif
#ifdef LT_ELF_MACHINE3
- && lte->ehdr.e_machine != LT_ELF_MACHINE3
+ && lte->ehdr.e_machine != LT_ELF_MACHINE3
#endif
- ))
- error (EXIT_FAILURE, 0, "\"%s\" is ELF from incompatible architecture",
- filename);
-
- for (i = 1; i < lte->ehdr.e_shnum; ++i)
- {
- Elf_Scn *scn;
- GElf_Shdr shdr;
- const char *name;
-
- scn = elf_getscn (lte->elf, i);
- if (scn == NULL || gelf_getshdr (scn, &shdr) == NULL)
- error (EXIT_FAILURE, 0, "Couldn't get section header from \"%s\"",
- filename);
-
- name = elf_strptr (lte->elf, lte->ehdr.e_shstrndx, shdr.sh_name);
- if (name == NULL)
- error (EXIT_FAILURE, 0, "Couldn't get section header from \"%s\"",
- filename);
-
- if (shdr.sh_type == SHT_DYNSYM)
- {
- Elf_Data *data;
-
- lte->dynsym = elf_getdata (scn, NULL);
- lte->dynsym_count = shdr.sh_size / shdr.sh_entsize;
- if (lte->dynsym == NULL || elf_getdata (scn, lte->dynsym) != NULL)
- error (EXIT_FAILURE, 0, "Couldn't get .dynsym data from \"%s\"",
- filename);
-
- scn = elf_getscn (lte->elf, shdr.sh_link);
- if (scn == NULL || gelf_getshdr (scn, &shdr) == NULL)
- error (EXIT_FAILURE, 0, "Couldn't get section header from \"%s\"",
- filename);
-
- data = elf_getdata (scn, NULL);
- if (data == NULL || elf_getdata (scn, data) != NULL
- || shdr.sh_size != data->d_size || data->d_off)
- error (EXIT_FAILURE, 0, "Couldn't get .dynstr data from \"%s\"",
- filename);
-
- lte->dynstr = data->d_buf;
- }
- else if (shdr.sh_type == SHT_DYNAMIC)
- {
- Elf_Data *data;
- size_t j;
-
- data = elf_getdata (scn, NULL);
- if (data == NULL || elf_getdata (scn, data) != NULL)
- error (EXIT_FAILURE, 0, "Couldn't get .dynamic data from \"%s\"",
- filename);
-
- for (j = 0; j < shdr.sh_size / shdr.sh_entsize; ++j)
- {
- GElf_Dyn dyn;
-
- if (gelf_getdyn (data, j, &dyn) == NULL)
- error (EXIT_FAILURE, 0, "Couldn't get .dynamic data from \"%s\"",
- filename);
-
- if (dyn.d_tag == DT_JMPREL)
- relplt_addr = dyn.d_un.d_ptr;
- else if (dyn.d_tag == DT_PLTRELSZ)
- relplt_size = dyn.d_un.d_val;
- }
- }
- else if (shdr.sh_type == SHT_HASH)
- {
- Elf_Data *data;
- size_t j;
-
- data = elf_getdata (scn, NULL);
- if (data == NULL || elf_getdata (scn, data) != NULL
- || data->d_off || data->d_size != shdr.sh_size)
- error (EXIT_FAILURE, 0, "Couldn't get .hash data from \"%s\"",
- filename);
-
- if (shdr.sh_entsize == 4)
- {
- /* Standard conforming ELF. */
- if (data->d_type != ELF_T_WORD)
- error (EXIT_FAILURE, 0, "Couldn't get .hash data from \"%s\"",
- filename);
- lte->hash = (Elf32_Word *) data->d_buf;
- }
- else if (shdr.sh_entsize == 8)
- {
- /* Alpha or s390x. */
- Elf32_Word *dst, *src;
- size_t hash_count = data->d_size / 8;
-
- lte->hash = (Elf32_Word *)
- malloc (hash_count * sizeof (Elf32_Word));
- if (lte->hash == NULL)
- error (EXIT_FAILURE, 0, "Couldn't convert .hash section from \"%s\"",
- filename);
- lte->hash_malloced = 1;
- dst = lte->hash;
- src = (Elf32_Word *) data->d_buf;
- if ((data->d_type == ELF_T_WORD && __BYTE_ORDER == __BIG_ENDIAN)
- || (data->d_type == ELF_T_XWORD
- && lte->ehdr.e_ident[EI_DATA] == ELFDATA2MSB))
- ++src;
- for (j = 0; j < hash_count; ++j, src += 2)
- *dst++ = *src;
- }
- else
- error (EXIT_FAILURE, 0, "Unknown .hash sh_entsize in \"%s\"",
- filename);
- }
- else if ((shdr.sh_type == SHT_PROGBITS || shdr.sh_type == SHT_NOBITS)
- && strcmp (name, ".plt") == 0)
- lte->plt_addr = shdr.sh_addr;
- }
-
- if (lte->dynsym == NULL || lte->dynstr == NULL)
- error (EXIT_FAILURE, 0, "Couldn't find .dynsym or .dynstr in \"%s\"",
- filename);
-
- if (!relplt_addr || !lte->plt_addr)
- {
- debug (1, "%s has no PLT relocations", filename);
- lte->relplt = NULL;
- lte->relplt_count = 0;
- }
- else
- {
- for (i = 1; i < lte->ehdr.e_shnum; ++i)
- {
- Elf_Scn *scn;
- GElf_Shdr shdr;
-
- scn = elf_getscn (lte->elf, i);
- if (scn == NULL || gelf_getshdr (scn, &shdr) == NULL)
- error (EXIT_FAILURE, 0, "Couldn't get section header from \"%s\"",
- filename);
- if (shdr.sh_addr == relplt_addr && shdr.sh_size == relplt_size)
- {
- lte->relplt = elf_getdata (scn, NULL);
- lte->relplt_count = shdr.sh_size / shdr.sh_entsize;
- if (lte->relplt == NULL
- || elf_getdata (scn, lte->relplt) != NULL)
- error (EXIT_FAILURE, 0, "Couldn't get .rel*.plt data from \"%s\"",
- filename);
- break;
- }
+ ))
+ error(EXIT_FAILURE, 0,
+ "\"%s\" is ELF from incompatible architecture", filename);
+
+ for (i = 1; i < lte->ehdr.e_shnum; ++i) {
+ Elf_Scn *scn;
+ GElf_Shdr shdr;
+ const char *name;
+
+ scn = elf_getscn(lte->elf, i);
+ if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL)
+ error(EXIT_FAILURE, 0,
+ "Couldn't get section header from \"%s\"",
+ filename);
+
+ name = elf_strptr(lte->elf, lte->ehdr.e_shstrndx, shdr.sh_name);
+ if (name == NULL)
+ error(EXIT_FAILURE, 0,
+ "Couldn't get section header from \"%s\"",
+ filename);
+
+ if (shdr.sh_type == SHT_DYNSYM) {
+ Elf_Data *data;
+
+ lte->dynsym = elf_getdata(scn, NULL);
+ lte->dynsym_count = shdr.sh_size / shdr.sh_entsize;
+ if (lte->dynsym == NULL
+ || elf_getdata(scn, lte->dynsym) != NULL)
+ error(EXIT_FAILURE, 0,
+ "Couldn't get .dynsym data from \"%s\"",
+ filename);
+
+ scn = elf_getscn(lte->elf, shdr.sh_link);
+ if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL)
+ error(EXIT_FAILURE, 0,
+ "Couldn't get section header from \"%s\"",
+ filename);
+
+ data = elf_getdata(scn, NULL);
+ if (data == NULL || elf_getdata(scn, data) != NULL
+ || shdr.sh_size != data->d_size || data->d_off)
+ error(EXIT_FAILURE, 0,
+ "Couldn't get .dynstr data from \"%s\"",
+ filename);
+
+ lte->dynstr = data->d_buf;
+ } else if (shdr.sh_type == SHT_DYNAMIC) {
+ Elf_Data *data;
+ size_t j;
+
+ data = elf_getdata(scn, NULL);
+ if (data == NULL || elf_getdata(scn, data) != NULL)
+ error(EXIT_FAILURE, 0,
+ "Couldn't get .dynamic data from \"%s\"",
+ filename);
+
+ for (j = 0; j < shdr.sh_size / shdr.sh_entsize; ++j) {
+ GElf_Dyn dyn;
+
+ if (gelf_getdyn(data, j, &dyn) == NULL)
+ error(EXIT_FAILURE, 0,
+ "Couldn't get .dynamic data from \"%s\"",
+ filename);
+
+ if (dyn.d_tag == DT_JMPREL)
+ relplt_addr = dyn.d_un.d_ptr;
+ else if (dyn.d_tag == DT_PLTRELSZ)
+ relplt_size = dyn.d_un.d_val;
+ }
+ } else if (shdr.sh_type == SHT_HASH) {
+ Elf_Data *data;
+ size_t j;
+
+ data = elf_getdata(scn, NULL);
+ if (data == NULL || elf_getdata(scn, data) != NULL
+ || data->d_off || data->d_size != shdr.sh_size)
+ error(EXIT_FAILURE, 0,
+ "Couldn't get .hash data from \"%s\"",
+ filename);
+
+ if (shdr.sh_entsize == 4) {
+ /* Standard conforming ELF. */
+ if (data->d_type != ELF_T_WORD)
+ error(EXIT_FAILURE, 0,
+ "Couldn't get .hash data from \"%s\"",
+ filename);
+ lte->hash = (Elf32_Word *) data->d_buf;
+ } else if (shdr.sh_entsize == 8) {
+ /* Alpha or s390x. */
+ Elf32_Word *dst, *src;
+ size_t hash_count = data->d_size / 8;
+
+ lte->hash = (Elf32_Word *)
+ malloc(hash_count * sizeof(Elf32_Word));
+ if (lte->hash == NULL)
+ error(EXIT_FAILURE, 0,
+ "Couldn't convert .hash section from \"%s\"",
+ filename);
+ lte->hash_malloced = 1;
+ dst = lte->hash;
+ src = (Elf32_Word *) data->d_buf;
+ if ((data->d_type == ELF_T_WORD
+ && __BYTE_ORDER == __BIG_ENDIAN)
+ || (data->d_type == ELF_T_XWORD
+ && lte->ehdr.e_ident[EI_DATA] ==
+ ELFDATA2MSB))
+ ++src;
+ for (j = 0; j < hash_count; ++j, src += 2)
+ *dst++ = *src;
+ } else
+ error(EXIT_FAILURE, 0,
+ "Unknown .hash sh_entsize in \"%s\"",
+ filename);
+ } else
+ if ((shdr.sh_type == SHT_PROGBITS
+ || shdr.sh_type == SHT_NOBITS)
+ && strcmp(name, ".plt") == 0)
+ lte->plt_addr = shdr.sh_addr;
}
- if (i == lte->ehdr.e_shnum)
- error (EXIT_FAILURE, 0, "Couldn't find .rel*.plt section in \"%s\"",
- filename);
-
- debug (1, "%s %zd PLT relocations", filename, lte->relplt_count);
- }
+ if (lte->dynsym == NULL || lte->dynstr == NULL)
+ error(EXIT_FAILURE, 0,
+ "Couldn't find .dynsym or .dynstr in \"%s\"", filename);
+
+ if (!relplt_addr || !lte->plt_addr) {
+ debug(1, "%s has no PLT relocations", filename);
+ lte->relplt = NULL;
+ lte->relplt_count = 0;
+ } else {
+ for (i = 1; i < lte->ehdr.e_shnum; ++i) {
+ Elf_Scn *scn;
+ GElf_Shdr shdr;
+
+ scn = elf_getscn(lte->elf, i);
+ if (scn == NULL || gelf_getshdr(scn, &shdr) == NULL)
+ error(EXIT_FAILURE, 0,
+ "Couldn't get section header from \"%s\"",
+ filename);
+ if (shdr.sh_addr == relplt_addr
+ && shdr.sh_size == relplt_size) {
+ lte->relplt = elf_getdata(scn, NULL);
+ lte->relplt_count =
+ shdr.sh_size / shdr.sh_entsize;
+ if (lte->relplt == NULL
+ || elf_getdata(scn, lte->relplt) != NULL)
+ error(EXIT_FAILURE, 0,
+ "Couldn't get .rel*.plt data from \"%s\"",
+ filename);
+ break;
+ }
+ }
+
+ if (i == lte->ehdr.e_shnum)
+ error(EXIT_FAILURE, 0,
+ "Couldn't find .rel*.plt section in \"%s\"",
+ filename);
+
+ debug(1, "%s %zd PLT relocations", filename, lte->relplt_count);
+ }
}
-static void
-do_close_elf (struct ltelf *lte)
+static void do_close_elf(struct ltelf *lte)
{
- if (lte->hash_malloced)
- free ((char *) lte->hash);
- elf_end (lte->elf);
- close (lte->fd);
+ if (lte->hash_malloced)
+ free((char *)lte->hash);
+ elf_end(lte->elf);
+ close(lte->fd);
}
static void
-add_library_symbol (GElf_Addr addr, const char *name,
- struct library_symbol **library_symbolspp)
+add_library_symbol(GElf_Addr addr, const char *name,
+ struct library_symbol **library_symbolspp)
{
- struct library_symbol *s;
- s = malloc (sizeof (struct library_symbol) + strlen (name) + 1);
- if (s == NULL)
- error (EXIT_FAILURE, errno, "add_library_symbol failed");
-
- s->next = *library_symbolspp;
- s->enter_addr = (void *) (uintptr_t) addr;
- s->name = (char *) (s + 1);
- strcpy (s->name, name);
- *library_symbolspp = s;
-
- debug (2, "addr: %p, symbol: \"%s\"", (void *) (uintptr_t) addr, name);
+ struct library_symbol *s;
+ s = malloc(sizeof(struct library_symbol) + strlen(name) + 1);
+ if (s == NULL)
+ error(EXIT_FAILURE, errno, "add_library_symbol failed");
+
+ s->next = *library_symbolspp;
+ s->enter_addr = (void *)(uintptr_t) addr;
+ s->name = (char *)(s + 1);
+ strcpy(s->name, name);
+ *library_symbolspp = s;
+
+ debug(2, "addr: %p, symbol: \"%s\"", (void *)(uintptr_t) addr, name);
}
-static int
-in_load_libraries (const char *name, struct ltelf *lte)
+static int in_load_libraries(const char *name, struct ltelf *lte)
{
- size_t i;
- unsigned long hash;
-
- if (!library_num)
- return 1;
-
- hash = elf_hash (name);
- for (i = 1; i <= library_num; ++i)
- {
- Elf32_Word nbuckets, symndx;
- Elf32_Word *buckets, *chain;
-
- if (lte[i].hash == NULL)
- continue;
-
- nbuckets = lte[i].hash[0];
- buckets = &lte[i].hash[2];
- chain = &lte[i].hash[2 + nbuckets];
- for (symndx = buckets[hash % nbuckets];
- symndx != STN_UNDEF;
- symndx = chain[symndx])
- {
- GElf_Sym sym;
-
- if (gelf_getsym (lte[i].dynsym, symndx, &sym) == NULL)
- error (EXIT_FAILURE, 0, "Couldn't get symbol from .dynsym");
-
- if (sym.st_value != 0
- && sym.st_shndx != SHN_UNDEF
- && strcmp (name, lte[i].dynstr + sym.st_name) == 0)
- return 1;
+ size_t i;
+ unsigned long hash;
+
+ if (!library_num)
+ return 1;
+
+ hash = elf_hash(name);
+ for (i = 1; i <= library_num; ++i) {
+ Elf32_Word nbuckets, symndx;
+ Elf32_Word *buckets, *chain;
+
+ if (lte[i].hash == NULL)
+ continue;
+
+ nbuckets = lte[i].hash[0];
+ buckets = &lte[i].hash[2];
+ chain = &lte[i].hash[2 + nbuckets];
+ for (symndx = buckets[hash % nbuckets];
+ symndx != STN_UNDEF; symndx = chain[symndx]) {
+ GElf_Sym sym;
+
+ if (gelf_getsym(lte[i].dynsym, symndx, &sym) == NULL)
+ error(EXIT_FAILURE, 0,
+ "Couldn't get symbol from .dynsym");
+
+ if (sym.st_value != 0
+ && sym.st_shndx != SHN_UNDEF
+ && strcmp(name, lte[i].dynstr + sym.st_name) == 0)
+ return 1;
+ }
}
- }
- return 0;
+ return 0;
}
-struct library_symbol *
-read_elf (const char *filename)
+struct library_symbol *read_elf(const char *filename)
{
- struct library_symbol *library_symbols = NULL;
- struct ltelf lte[MAX_LIBRARY + 1];
- size_t i;
-
- elf_version (EV_CURRENT);
-
- do_init_elf (lte, filename);
- for (i = 0; i < library_num; ++i)
- do_init_elf (&lte[i + 1], library[i]);
-
- for (i = 0; i < lte->relplt_count; ++i)
- {
- GElf_Rel rel;
- GElf_Rela rela;
- GElf_Sym sym;
- GElf_Addr addr;
- void *ret;
- const char *name;
-
- if (lte->relplt->d_type == ELF_T_REL)
- {
- ret = gelf_getrel (lte->relplt, i, &rel);
- rela.r_offset = rel.r_offset;
- rela.r_info = rel.r_info;
- rela.r_addend = 0;
- }
- else
- ret = gelf_getrela (lte->relplt, i, &rela);
-
- if (ret == NULL
- || ELF64_R_SYM (rela.r_info) >= lte->dynsym_count
- || gelf_getsym (lte->dynsym, ELF64_R_SYM (rela.r_info), &sym) == NULL)
- error (EXIT_FAILURE, 0, "Couldn't get relocation from \"%s\"",
- filename);
-
- name = lte->dynstr + sym.st_name;
- if (in_load_libraries (name, lte))
- {
- addr = arch_plt_sym_val (lte, i, &rela);
- if (addr != 0)
- add_library_symbol (addr, name, &library_symbols);
+ struct library_symbol *library_symbols = NULL;
+ struct ltelf lte[MAX_LIBRARY + 1];
+ size_t i;
+
+ elf_version(EV_CURRENT);
+
+ do_init_elf(lte, filename);
+ for (i = 0; i < library_num; ++i)
+ do_init_elf(&lte[i + 1], library[i]);
+
+ for (i = 0; i < lte->relplt_count; ++i) {
+ GElf_Rel rel;
+ GElf_Rela rela;
+ GElf_Sym sym;
+ GElf_Addr addr;
+ void *ret;
+ const char *name;
+
+ if (lte->relplt->d_type == ELF_T_REL) {
+ ret = gelf_getrel(lte->relplt, i, &rel);
+ rela.r_offset = rel.r_offset;
+ rela.r_info = rel.r_info;
+ rela.r_addend = 0;
+ } else
+ ret = gelf_getrela(lte->relplt, i, &rela);
+
+ if (ret == NULL
+ || ELF64_R_SYM(rela.r_info) >= lte->dynsym_count
+ || gelf_getsym(lte->dynsym, ELF64_R_SYM(rela.r_info),
+ &sym) == NULL)
+ error(EXIT_FAILURE, 0,
+ "Couldn't get relocation from \"%s\"", filename);
+
+ name = lte->dynstr + sym.st_name;
+ if (in_load_libraries(name, lte)) {
+ addr = arch_plt_sym_val(lte, i, &rela);
+ if (addr != 0)
+ add_library_symbol(addr, name,
+ &library_symbols);
+ }
}
- }
- for (i = 0; i < library_num + 1; ++i)
- do_close_elf (&lte[i]);
+ for (i = 0; i < library_num + 1; ++i)
+ do_close_elf(&lte[i]);
- return library_symbols;
+ return library_symbols;
}
diff --git a/execute_program.c b/execute_program.c
index 09db44a..6697386 100644
--- a/execute_program.c
+++ b/execute_program.c
@@ -17,8 +17,8 @@
#include "debug.h"
#include "sysdep.h"
-static void
-change_uid(struct process * proc) {
+static void change_uid(struct process *proc)
+{
uid_t run_uid, run_euid;
gid_t run_gid, run_egid;
@@ -26,7 +26,8 @@ change_uid(struct process * proc) {
struct passwd *pent;
if (getuid() != 0 || geteuid() != 0) {
- fprintf(stderr, "you must be root to use the -u option\n");
+ fprintf(stderr,
+ "you must be root to use the -u option\n");
exit(1);
}
if ((pent = getpwnam(opt_u)) == NULL) {
@@ -68,21 +69,22 @@ change_uid(struct process * proc) {
}
}
-void
-execute_program(struct process * sp, char **argv) {
+void execute_program(struct process *sp, char **argv)
+{
pid_t pid;
debug(1, "Executing `%s'...", sp->filename);
pid = fork();
- if (pid<0) {
+ if (pid < 0) {
perror("ltrace: fork");
exit(1);
} else if (!pid) { /* child */
change_uid(sp);
trace_me();
execvp(sp->filename, argv);
- fprintf(stderr, "Can't execute `%s': %s\n", sp->filename, strerror(errno));
+ fprintf(stderr, "Can't execute `%s': %s\n", sp->filename,
+ strerror(errno));
exit(1);
}
diff --git a/ltrace.c b/ltrace.c
index 4a51f8f..0e60839 100644
--- a/ltrace.c
+++ b/ltrace.c
@@ -22,19 +22,19 @@
#define SYSCONFDIR "/etc"
#endif
-char * command = NULL;
-struct process * list_of_processes = NULL;
+char *command = NULL;
+struct process *list_of_processes = NULL;
-int exiting=0; /* =1 if a SIGINT or SIGTERM has been received */
+int exiting = 0; /* =1 if a SIGINT or SIGTERM has been received */
-static void
-signal_alarm(int sig) {
- struct process * tmp = list_of_processes;
+static void signal_alarm(int sig)
+{
+ struct process *tmp = list_of_processes;
- signal(SIGALRM,SIG_DFL);
- while(tmp) {
- struct opt_p_t * tmp2 = opt_p;
- while(tmp2) {
+ 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) {
@@ -44,23 +44,23 @@ signal_alarm(int sig) {
}
tmp2 = tmp2->next;
}
- debug(2,"Sending SIGSTOP to process %u\n",tmp->pid);
+ 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);
+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);
+ 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;
}
@@ -68,41 +68,41 @@ signal_exit(int sig) {
alarm(1);
}
-static void
-normal_exit(void) {
- output_line(0,0);
+static void normal_exit(void)
+{
+ output_line(0, 0);
if (opt_c) {
show_summary();
}
}
-static void
-guess_cols(void) {
+static void guess_cols(void)
+{
struct winsize ws;
- char * c;
+ char *c;
opt_a = DEFAULT_ACOLUMN;
c = getenv("COLUMNS");
if (c && *c) {
- char * endptr;
+ char *endptr;
int cols;
cols = strtol(c, &endptr, 0);
- if (cols>0 && !*endptr) {
- opt_a = cols * 5/8;
+ if (cols > 0 && !*endptr) {
+ opt_a = cols * 5 / 8;
}
- } else if (ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col>0) {
- opt_a = ws.ws_col * 5/8;
+ } else if (ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col > 0) {
+ opt_a = ws.ws_col * 5 / 8;
}
}
-int
-main(int argc, char **argv) {
- struct opt_p_t * opt_p_tmp;
- char * home;
+int main(int argc, char **argv)
+{
+ struct opt_p_t *opt_p_tmp;
+ char *home;
atexit(normal_exit);
- signal(SIGINT,signal_exit); /* Detach processes when interrupted */
- signal(SIGTERM,signal_exit); /* ... or killed */
+ signal(SIGINT, signal_exit); /* Detach processes when interrupted */
+ signal(SIGTERM, signal_exit); /* ... or killed */
guess_cols();
argv = process_options(argc, argv);
@@ -110,7 +110,7 @@ main(int argc, char **argv) {
home = getenv("HOME");
if (home) {
char path[PATH_MAX];
- if (strlen(home) > PATH_MAX-15) {
+ if (strlen(home) > PATH_MAX - 15) {
fprintf(stderr, "Error: $HOME too long\n");
exit(1);
}
@@ -119,9 +119,9 @@ main(int argc, char **argv) {
read_config_file(path);
}
if (opt_e) {
- struct opt_e_t * tmp = opt_e;
- while(tmp) {
- debug(1,"Option -e: %s\n", tmp->name);
+ struct opt_e_t *tmp = opt_e;
+ while (tmp) {
+ debug(1, "Option -e: %s\n", tmp->name);
tmp = tmp->next;
}
}
@@ -133,7 +133,7 @@ main(int argc, char **argv) {
open_pid(opt_p_tmp->pid, 1);
opt_p_tmp = opt_p_tmp->next;
}
- while(1) {
+ while (1) {
process_event(wait_for_something());
}
}
diff --git a/options.c b/options.c
index aff93af..24e548e 100644
--- a/options.c
+++ b/options.c
@@ -25,7 +25,7 @@
char *library[MAX_LIBRARY];
int library_num = 0;
static char *progname; /* Program name (`ltrace') */
-FILE * output;
+FILE *output;
int opt_a = DEFAULT_ACOLUMN; /* default alignment column for results */
int opt_c = 0; /* Count time, calls, and report a summary on program exit */
int opt_d = 0; /* debug */
@@ -34,7 +34,7 @@ int opt_s = DEFAULT_STRLEN; /* default maximum # of bytes printed in strings */
int opt_S = 0; /* display syscalls */
int opt_L = 1; /* display library calls */
int opt_f = 0; /* trace child processes as they are created */
-char * opt_u = NULL; /* username to run command as */
+char *opt_u = NULL; /* username to run command as */
int opt_r = 0; /* print relative timestamp */
int opt_t = 0; /* print absolute timestamp */
#ifdef USE_DEMANGLE
@@ -44,82 +44,81 @@ int opt_n = 0; /* indent trace output according to program flow */
int opt_T = 0; /* show the time spent inside each call */
/* List of pids given to option -p: */
-struct opt_p_t * opt_p = NULL; /* attach to process with a given pid */
+struct opt_p_t *opt_p = NULL; /* attach to process with a given pid */
/* List of function names given to option -e: */
-struct opt_e_t * opt_e = NULL;
-int opt_e_enable=1;
+struct opt_e_t *opt_e = NULL;
+int opt_e_enable = 1;
-static void
-usage(void) {
+static void usage(void)
+{
#if !(HAVE_GETOPT || HAVE_GETOPT_LONG)
fprintf(stdout, "Usage: %s [command [arg ...]]\n"
-"Trace library calls of a given program.\n\n", progname);
+ "Trace library calls of a given program.\n\n", progname);
#else
fprintf(stdout, "Usage: %s [option ...] [command [arg ...]]\n"
-"Trace library calls of a given program.\n\n"
-
+ "Trace library calls of a given program.\n\n"
# if HAVE_GETOPT_LONG
-" -a, --align=COLUMN align return values in a secific column.\n"
+ " -a, --align=COLUMN align return values in a secific column.\n"
# else
-" -a COLUMN align return values in a secific column.\n"
+ " -a COLUMN align return values in a secific column.\n"
# endif
-" -c count time and calls, and report a summary on exit.\n"
+ " -c count time and calls, and report a summary on exit.\n"
# ifdef USE_DEMANGLE
# if HAVE_GETOPT_LONG
-" -C, --demangle decode low-level symbol names into user-level names.\n"
+ " -C, --demangle decode low-level symbol names into user-level names.\n"
# else
-" -C decode low-level symbol names into user-level names.\n"
+ " -C decode low-level symbol names into user-level names.\n"
# endif
# endif
# if HAVE_GETOPT_LONG
-" -d, --debug print debugging info.\n"
+ " -d, --debug print debugging info.\n"
# else
-" -d print debugging info.\n"
+ " -d print debugging info.\n"
# endif
-" -e expr modify which events to trace.\n"
-" -f follow forks.\n"
+ " -e expr modify which events to trace.\n"
+ " -f follow forks.\n"
# if HAVE_GETOPT_LONG
-" -h, --help display this help and exit.\n"
+ " -h, --help display this help and exit.\n"
# else
-" -h display this help and exit.\n"
+ " -h display this help and exit.\n"
# endif
-" -i print instruction pointer at time of library call.\n"
+ " -i print instruction pointer at time of library call.\n"
# if HAVE_GETOPT_LONG
-" -l, --library=FILE print library calls from this library only.\n"
+ " -l, --library=FILE print library calls from this library only.\n"
# else
-" -l FILE print library calls from this library only.\n"
+ " -l FILE print library calls from this library only.\n"
# endif
-" -L do NOT display library calls.\n"
+ " -L do NOT display library calls.\n"
# if HAVE_GETOPT_LONG
-" -n, --indent=NR indent output by NR spaces for each call level nesting.\n"
+ " -n, --indent=NR indent output by NR spaces for each call level nesting.\n"
# else
-" -n NR indent output by NR spaces for each call level nesting.\n"
+ " -n NR indent output by NR spaces for each call level nesting.\n"
# endif
# if HAVE_GETOPT_LONG
-" -o, --output=FILE write the trace output to that file.\n"
+ " -o, --output=FILE write the trace output to that file.\n"
# else
-" -o FILE write the trace output to that file.\n"
+ " -o FILE write the trace output to that file.\n"
# endif
-" -p PID attach to the process with the process ID pid.\n"
-" -r print relative timestamps.\n"
-" -s STRLEN specify the maximum string size to print.\n"
-" -S display system calls.\n"
-" -t, -tt, -ttt print absolute timestamps.\n"
-" -T show the time spent inside each call.\n"
-" -u USERNAME run command with the userid, groupid of username.\n"
+ " -p PID attach to the process with the process ID pid.\n"
+ " -r print relative timestamps.\n"
+ " -s STRLEN specify the maximum string size to print.\n"
+ " -S display system calls.\n"
+ " -t, -tt, -ttt print absolute timestamps.\n"
+ " -T show the time spent inside each call.\n"
+ " -u USERNAME run command with the userid, groupid of username.\n"
# if HAVE_GETOPT_LONG
-" -V, --version output version information and exit.\n"
+ " -V, --version output version information and exit.\n"
# else
-" -V output version information and exit.\n"
+ " -V output version information and exit.\n"
# endif
-"\nReport bugs to Juan Cespedes <cespedes@debian.org>\n"
- , progname);
+ "\nReport bugs to Juan Cespedes <cespedes@debian.org>\n",
+ progname);
#endif
}
-static char *
-search_for_command(char * filename) {
+static char *search_for_command(char *filename)
+{
static char pathname[PATH_MAX];
char *path;
int m, n;
@@ -150,164 +149,193 @@ search_for_command(char * filename) {
return filename;
}
-char **
-process_options(int argc, char **argv) {
+char **process_options(int argc, char **argv)
+{
progname = argv[0];
output = stderr;
#if HAVE_GETOPT || HAVE_GETOPT_LONG
- while(1) {
+ while (1) {
int c;
#if HAVE_GETOPT_LONG
int option_index = 0;
static struct option long_options[] = {
- { "align", 1, 0, 'a'},
- { "debug", 0, 0, 'd'},
+ {"align", 1, 0, 'a'},
+ {"debug", 0, 0, 'd'},
# ifdef USE_DEMANGLE
- { "demangle", 0, 0, 'C'},
+ {"demangle", 0, 0, 'C'},
#endif
- { "indent", 1, 0, 'n'},
- { "help", 0, 0, 'h'},
- { "library", 1, 0, 'l'},
- { "output", 1, 0, 'o'},
- { "version", 0, 0, 'V'},
- { 0, 0, 0, 0}
+ {"indent", 1, 0, 'n'},
+ {"help", 0, 0, 'h'},
+ {"library", 1, 0, 'l'},
+ {"output", 1, 0, 'o'},
+ {"version", 0, 0, 'V'},
+ {0, 0, 0, 0}
};
c = getopt_long(argc, argv, "+cdfhiLrStTV"
# ifdef USE_DEMANGLE
- "C"
+ "C"
# endif
- "a:e:l:n:o:p:s:u:", long_options, &option_index);
+ "a:e:l:n:o:p:s:u:", long_options,
+ &option_index);
#else
c = getopt(argc, argv, "+cdfhiLrStTV"
# ifdef USE_DEMANGLE
- "C"
+ "C"
# endif
- "a:e:l:n:o:p:s:u:");
+ "a:e:l:n:o:p:s:u:");
#endif
- if (c==-1) {
+ if (c == -1) {
break;
}
- switch(c) {
- case 'a': opt_a = atoi(optarg);
- break;
- case 'c': opt_c++;
- break;
+ switch (c) {
+ case 'a':
+ opt_a = atoi(optarg);
+ break;
+ case 'c':
+ opt_c++;
+ break;
#ifdef USE_DEMANGLE
- case 'C': opt_C++;
- break;
+ case 'C':
+ opt_C++;
+ break;
#endif
- case 'd': opt_d++;
- break;
- case 'e':
- {
- char * str_e = strdup(optarg);
- if (!str_e) {
- perror("ltrace: strdup");
- exit(1);
- }
- if (str_e[0]=='!') {
- opt_e_enable=0;
- str_e++;
- }
- while(*str_e) {
- struct opt_e_t * tmp;
- char *str2 = strchr(str_e,',');
- if (str2) {
- *str2 = '\0';
- }
- tmp = malloc(sizeof(struct opt_e_t));
- if (!tmp) {
- perror("ltrace: malloc");
- exit(1);
- }
- tmp->name = str_e;
- tmp->next = opt_e;
- opt_e = tmp;
- if (str2) {
- str_e = str2+1;
- } else {
- break;
- }
- }
- break;
+ case 'd':
+ opt_d++;
+ break;
+ case 'e':
+ {
+ char *str_e = strdup(optarg);
+ if (!str_e) {
+ perror("ltrace: strdup");
+ exit(1);
}
- case 'f': opt_f = 1;
- break;
- case 'h': usage();
- exit(0);
- case 'i': opt_i++;
- break;
- case 'l': if (library_num == MAX_LIBRARY) {
- fprintf(stderr, "Too many libraries. Maximum is %i.\n", MAX_LIBRARY);
- exit(1);
- }
- library[library_num++] = optarg;
- break;
- case 'L': opt_L = 0;
- break;
- case 'n': opt_n = atoi(optarg);
- break;
- case 'o': output = fopen(optarg, "w");
- if (!output) {
- fprintf(stderr, "Can't open %s for output: %s\n", optarg, strerror(errno));
- exit(1);
- }
- setvbuf(output, (char *)NULL, _IOLBF, 0);
- fcntl(fileno(output), F_SETFD, FD_CLOEXEC);
- break;
- case 'p':
- {
- struct opt_p_t * tmp = malloc(sizeof(struct opt_p_t));
+ if (str_e[0] == '!') {
+ opt_e_enable = 0;
+ str_e++;
+ }
+ while (*str_e) {
+ struct opt_e_t *tmp;
+ char *str2 = strchr(str_e, ',');
+ if (str2) {
+ *str2 = '\0';
+ }
+ tmp = malloc(sizeof(struct opt_e_t));
if (!tmp) {
perror("ltrace: malloc");
exit(1);
}
- tmp->pid = atoi(optarg);
- tmp->next = opt_p;
- opt_p = tmp;
- break;
- }
- case 'r': opt_r++;
+ tmp->name = str_e;
+ tmp->next = opt_e;
+ opt_e = tmp;
+ if (str2) {
+ str_e = str2 + 1;
+ } else {
break;
- case 's': opt_s = atoi(optarg);
- break;
- case 'S': opt_S = 1;
- break;
- case 't': opt_t++;
- break;
- case 'T': opt_T++;
- break;
- case 'u': opt_u = optarg;
- break;
- case 'V': printf("ltrace version " VERSION ".\n"
-"Copyright (C) 1997-2004 Juan Cespedes <cespedes@debian.org>.\n"
-"This is free software; see the GNU General Public Licence\n"
-"version 2 or later for copying conditions. There is NO warranty.\n");
- exit(0);
+ }
+ }
+ break;
+ }
+ case 'f':
+ opt_f = 1;
+ break;
+ case 'h':
+ usage();
+ exit(0);
+ case 'i':
+ opt_i++;
+ break;
+ case 'l':
+ if (library_num == MAX_LIBRARY) {
+ fprintf(stderr,
+ "Too many libraries. Maximum is %i.\n",
+ MAX_LIBRARY);
+ exit(1);
+ }
+ library[library_num++] = optarg;
+ break;
+ case 'L':
+ opt_L = 0;
+ break;
+ case 'n':
+ opt_n = atoi(optarg);
+ break;
+ case 'o':
+ output = fopen(optarg, "w");
+ if (!output) {
+ fprintf(stderr,
+ "Can't open %s for output: %s\n",
+ optarg, strerror(errno));
+ exit(1);
+ }
+ setvbuf(output, (char *)NULL, _IOLBF, 0);
+ fcntl(fileno(output), F_SETFD, FD_CLOEXEC);
+ break;
+ case 'p':
+ {
+ struct opt_p_t *tmp =
+ malloc(sizeof(struct opt_p_t));
+ if (!tmp) {
+ perror("ltrace: malloc");
+ exit(1);
+ }
+ tmp->pid = atoi(optarg);
+ tmp->next = opt_p;
+ opt_p = tmp;
+ break;
+ }
+ case 'r':
+ opt_r++;
+ break;
+ case 's':
+ opt_s = atoi(optarg);
+ break;
+ case 'S':
+ opt_S = 1;
+ break;
+ case 't':
+ opt_t++;
+ break;
+ case 'T':
+ opt_T++;
+ break;
+ case 'u':
+ opt_u = optarg;
+ break;
+ case 'V':
+ printf("ltrace version " VERSION ".\n"
+ "Copyright (C) 1997-2004 Juan Cespedes <cespedes@debian.org>.\n"
+ "This is free software; see the GNU General Public Licence\n"
+ "version 2 or later for copying conditions. There is NO warranty.\n");
+ exit(0);
- default:
+ default:
#if HAVE_GETOPT_LONG
- fprintf(stderr, "Try `%s --help' for more information\n", progname);
+ fprintf(stderr,
+ "Try `%s --help' for more information\n",
+ progname);
#else
- fprintf(stderr, "Try `%s -h' for more information\n", progname);
+ fprintf(stderr, "Try `%s -h' for more information\n",
+ progname);
#endif
- exit(1);
+ exit(1);
}
}
- argc -= optind; argv += optind;
+ argc -= optind;
+ argv += optind;
#endif
- if (!opt_p && argc<1) {
+ if (!opt_p && argc < 1) {
fprintf(stderr, "%s: too few arguments\n", progname);
usage();
exit(1);
}
if (opt_r && opt_t) {
- fprintf(stderr, "%s: Incompatible options -r and -t\n", progname);
+ fprintf(stderr, "%s: Incompatible options -r and -t\n",
+ progname);
exit(1);
}
- if (argc>0) {
+ if (argc > 0) {
command = search_for_command(argv[0]);
}
return &argv[0];
diff --git a/output.c b/output.c
index 6c8b13a..b7759a6 100644
--- a/output.c
+++ b/output.c
@@ -22,24 +22,25 @@
/* TODO FIXME XXX: include in ltrace.h: */
extern struct timeval current_time_spent;
-struct dict * dict_opt_c = NULL;
+struct dict *dict_opt_c = NULL;
static pid_t current_pid = 0;
static int current_depth = 0;
static int current_column = 0;
-static void
-output_indent(struct process * proc) {
- current_column += fprintf(output, "%*s", opt_n * proc->callstack_depth, "");
+static void output_indent(struct process *proc)
+{
+ current_column +=
+ fprintf(output, "%*s", opt_n * proc->callstack_depth, "");
}
-static void
-begin_of_line(enum tof type, struct process * proc) {
+static void begin_of_line(enum tof type, struct process *proc)
+{
current_column = 0;
if (!proc) {
return;
}
- if ((output!=stderr) && (opt_p || opt_f)) {
+ if ((output != stderr) && (opt_p || opt_f)) {
current_column += fprintf(output, "%u ", proc->pid);
} else if (list_of_processes->next) {
current_column += fprintf(output, "[pid %u] ", proc->pid);
@@ -47,14 +48,14 @@ begin_of_line(enum tof type, struct process * proc) {
if (opt_r) {
struct timeval tv;
struct timezone tz;
- static struct timeval old_tv={0,0};
+ static struct timeval old_tv = { 0, 0 };
struct timeval diff;
gettimeofday(&tv, &tz);
- if (old_tv.tv_sec==0 && old_tv.tv_usec==0) {
- old_tv.tv_sec=tv.tv_sec;
- old_tv.tv_usec=tv.tv_usec;
+ if (old_tv.tv_sec == 0 && old_tv.tv_usec == 0) {
+ old_tv.tv_sec = tv.tv_sec;
+ old_tv.tv_usec = tv.tv_usec;
}
diff.tv_sec = tv.tv_sec - old_tv.tv_sec;
if (tv.tv_usec >= old_tv.tv_usec) {
@@ -66,47 +67,50 @@ begin_of_line(enum tof type, struct process * proc) {
old_tv.tv_sec = tv.tv_sec;
old_tv.tv_usec = tv.tv_usec;
current_column += fprintf(output, "%3lu.%06d ",
- diff.tv_sec, (int)diff.tv_usec);
+ diff.tv_sec, (int)diff.tv_usec);
}
if (opt_t) {
struct timeval tv;
struct timezone tz;
gettimeofday(&tv, &tz);
- if (opt_t>2) {
+ if (opt_t > 2) {
current_column += fprintf(output, "%lu.%06d ",
- tv.tv_sec, (int)tv.tv_usec);
- } else if (opt_t>1) {
- struct tm * tmp = localtime(&tv.tv_sec);
- current_column += fprintf(output, "%02d:%02d:%02d.%06d ",
- tmp->tm_hour, tmp->tm_min, tmp->tm_sec, (int)tv.tv_usec);
+ tv.tv_sec, (int)tv.tv_usec);
+ } else if (opt_t > 1) {
+ struct tm *tmp = localtime(&tv.tv_sec);
+ current_column +=
+ fprintf(output, "%02d:%02d:%02d.%06d ",
+ tmp->tm_hour, tmp->tm_min, tmp->tm_sec,
+ (int)tv.tv_usec);
} else {
- struct tm * tmp = localtime(&tv.tv_sec);
+ struct tm *tmp = localtime(&tv.tv_sec);
current_column += fprintf(output, "%02d:%02d:%02d ",
- tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+ tmp->tm_hour, tmp->tm_min,
+ tmp->tm_sec);
}
}
if (opt_i) {
- if (type==LT_TOF_FUNCTION || type==LT_TOF_FUNCTIONR) {
+ if (type == LT_TOF_FUNCTION || type == LT_TOF_FUNCTIONR) {
current_column += fprintf(output, "[%p] ",
- proc->return_addr);
+ proc->return_addr);
} else {
current_column += fprintf(output, "[%p] ",
- proc->instruction_pointer);
+ proc->instruction_pointer);
}
}
- if (opt_n > 0 && type!=LT_TOF_NONE) {
+ if (opt_n > 0 && type != LT_TOF_NONE) {
output_indent(proc);
}
}
-static struct function *
-name2func(char * name) {
- struct function * tmp;
- const char * str1, * str2;
+static struct function *name2func(char *name)
+{
+ struct function *tmp;
+ const char *str1, *str2;
tmp = list_of_functions;
- while(tmp) {
+ while (tmp) {
#ifdef USE_DEMANGLE
str1 = opt_C ? my_demangle(tmp->name) : tmp->name;
str2 = opt_C ? my_demangle(name) : name;
@@ -123,8 +127,8 @@ name2func(char * name) {
return NULL;
}
-void
-output_line(struct process * proc, char *fmt, ...) {
+void output_line(struct process *proc, char *fmt, ...)
+{
va_list args;
if (opt_c) {
@@ -133,7 +137,7 @@ output_line(struct process * proc, char *fmt, ...) {
if (current_pid) {
fprintf(output, " <unfinished ...>\n");
}
- current_pid=0;
+ current_pid = 0;
if (!fmt) {
return;
}
@@ -143,34 +147,36 @@ output_line(struct process * proc, char *fmt, ...) {
vfprintf(output, fmt, args);
fprintf(output, "\n");
va_end(args);
- current_column=0;
+ current_column = 0;
}
-static void
-tabto(int col) {
+static void tabto(int col)
+{
if (current_column < col) {
- fprintf(output, "%*s", col-current_column, "");
+ fprintf(output, "%*s", col - current_column, "");
}
}
-void
-output_left(enum tof type, struct process * proc, char * function_name) {
- struct function * func;
+void output_left(enum tof type, struct process *proc, char *function_name)
+{
+ struct function *func;
if (opt_c) {
return;
}
if (current_pid) {
fprintf(output, " <unfinished ...>\n");
- current_pid=0;
- current_column=0;
+ current_pid = 0;
+ current_column = 0;
}
current_pid = proc->pid;
current_depth = proc->callstack_depth;
proc->type_being_displayed = type;
begin_of_line(type, proc);
#ifdef USE_DEMANGLE
- current_column += fprintf(output, "%s(", opt_C ? my_demangle(function_name): function_name);
+ current_column +=
+ fprintf(output, "%s(",
+ opt_C ? my_demangle(function_name) : function_name);
#else
current_column += fprintf(output, "%s(", function_name);
#endif
@@ -178,7 +184,7 @@ output_left(enum tof type, struct process * proc, char * function_name) {
func = name2func(function_name);
if (!func) {
int i;
- for(i=0; i<4; i++) {
+ for (i = 0; i < 4; i++) {
current_column += display_arg(type, proc, i, 0);
current_column += fprintf(output, ", ");
}
@@ -186,12 +192,14 @@ output_left(enum tof type, struct process * proc, char * function_name) {
return;
} else {
int i;
- for(i=0; i< func->num_params - func->params_right - 1; i++) {
- current_column += display_arg(type, proc, i, &func->arg_types[i]);
+ for (i = 0; i < func->num_params - func->params_right - 1; i++) {
+ current_column +=
+ display_arg(type, proc, i, &func->arg_types[i]);
current_column += fprintf(output, ", ");
}
- if (func->num_params>func->params_right) {
- current_column += display_arg(type, proc, i, &func->arg_types[i]);
+ if (func->num_params > func->params_right) {
+ current_column +=
+ display_arg(type, proc, i, &func->arg_types[i]);
if (func->params_right) {
current_column += fprintf(output, ", ");
}
@@ -202,14 +210,16 @@ output_left(enum tof type, struct process * proc, char * function_name) {
}
}
-void
-output_right(enum tof type, struct process * proc, char * function_name) {
- struct function * func = name2func(function_name);
+void output_right(enum tof type, struct process *proc, char *function_name)
+{
+ struct function *func = name2func(function_name);
if (opt_c) {
- struct opt_c_struct * st;
+ struct opt_c_struct *st;
if (!dict_opt_c) {
- dict_opt_c = dict_init(dict_key2hash_string, dict_key_cmp_string);
+ dict_opt_c =
+ dict_init(dict_key2hash_string,
+ dict_key_cmp_string);
}
st = dict_find_entry(dict_opt_c, function_name);
if (!st) {
@@ -233,41 +243,47 @@ output_right(enum tof type, struct process * proc, char * function_name) {
st->count++;
st->tv.tv_sec += current_time_spent.tv_sec;
-// fprintf(output, "%s <%lu.%06d>\n", function_name,
-// current_time_spent.tv_sec, (int)current_time_spent.tv_usec);
+// fprintf(output, "%s <%lu.%06d>\n", function_name,
+// current_time_spent.tv_sec, (int)current_time_spent.tv_usec);
return;
}
- if (current_pid && (current_pid!=proc->pid ||
- current_depth != proc->callstack_depth)) {
+ if (current_pid && (current_pid != proc->pid ||
+ current_depth != proc->callstack_depth)) {
fprintf(output, " <unfinished ...>\n");
current_pid = 0;
}
if (current_pid != proc->pid) {
begin_of_line(type, proc);
#ifdef USE_DEMANGLE
- current_column += fprintf(output, "<... %s resumed> ", opt_C ? my_demangle(function_name) : function_name);
+ current_column +=
+ fprintf(output, "<... %s resumed> ",
+ opt_C ? my_demangle(function_name) : function_name);
#else
- current_column += fprintf(output, "<... %s resumed> ", function_name);
+ current_column +=
+ fprintf(output, "<... %s resumed> ", function_name);
#endif
}
if (!func) {
current_column += fprintf(output, ") ");
- tabto(opt_a-1);
+ tabto(opt_a - 1);
fprintf(output, "= ");
display_arg(type, proc, -1, 0);
} else {
int i;
- for(i=func->num_params-func->params_right; i<func->num_params-1; i++) {
- current_column += display_arg(type, proc, i, &func->arg_types[i]);
+ for (i = func->num_params - func->params_right;
+ i < func->num_params - 1; i++) {
+ current_column +=
+ display_arg(type, proc, i, &func->arg_types[i]);
current_column += fprintf(output, ", ");
}
if (func->params_right) {
- current_column += display_arg(type, proc, i, &func->arg_types[i]);
+ current_column +=
+ display_arg(type, proc, i, &func->arg_types[i]);
}
current_column += fprintf(output, ") ");
- tabto(opt_a-1);
- fprintf(output, "= ");
+ tabto(opt_a - 1);
+ fprintf(output, "= ");
if (func->return_type.at == ARGTYPE_VOID) {
fprintf(output, "<void>");
} else {
@@ -276,9 +292,10 @@ output_right(enum tof type, struct process * proc, char * function_name) {
}
if (opt_T) {
fprintf(output, " <%lu.%06d>",
- current_time_spent.tv_sec, (int)current_time_spent.tv_usec);
+ current_time_spent.tv_sec,
+ (int)current_time_spent.tv_usec);
}
fprintf(output, "\n");
- current_pid=0;
- current_column=0;
+ current_pid = 0;
+ current_column = 0;
}
diff --git a/proc.c b/proc.c
index 67b88f1..083f6a9 100644
--- a/proc.c
+++ b/proc.c
@@ -12,9 +12,9 @@
#include "options.h"
#include "elf.h"
-struct process *
-open_program(char * filename) {
- struct process * proc;
+struct process *open_program(char *filename)
+{
+ struct process *proc;
proc = malloc(sizeof(struct process));
if (!proc) {
perror("malloc");
@@ -35,13 +35,14 @@ open_program(char * filename) {
return proc;
}
-void
-open_pid(pid_t pid, int verbose) {
- struct process * proc;
- char * filename;
+void open_pid(pid_t pid, int verbose)
+{
+ struct process *proc;
+ char *filename;
- if (trace_pid(pid)<0) {
- fprintf(stderr, "Cannot attach to pid %u: %s\n", pid, strerror(errno));
+ if (trace_pid(pid) < 0) {
+ fprintf(stderr, "Cannot attach to pid %u: %s\n", pid,
+ strerror(errno));
return;
}
@@ -50,7 +51,8 @@ open_pid(pid_t pid, int verbose) {
#if 0
if (!filename) {
if (verbose) {
- fprintf(stderr, "Cannot trace pid %u: %s\n", pid, strerror(errno));
+ fprintf(stderr, "Cannot trace pid %u: %s\n", pid,
+ strerror(errno));
}
return;
}
diff --git a/process_event.c b/process_event.c
index 096cd30..1323d39 100644
--- a/process_event.c
+++ b/process_event.c
@@ -20,22 +20,23 @@
#include <sys/ptrace.h>
#endif
-static void process_signal(struct event * event);
-static void process_exit(struct event * event);
-static void process_exit_signal(struct event * event);
-static void process_syscall(struct event * event);
-static void process_sysret(struct event * event);
-static void process_breakpoint(struct event * event);
-static void remove_proc(struct process * proc);
-
-static void callstack_push_syscall(struct process * proc, int sysnum);
-static void callstack_push_symfunc(struct process * proc, struct library_symbol * sym);
-static void callstack_pop(struct process * proc);
-
-static char *
-shortsignal(int signum) {
- static char * signalent0[] = {
- #include "signalent.h"
+static void process_signal(struct event *event);
+static void process_exit(struct event *event);
+static void process_exit_signal(struct event *event);
+static void process_syscall(struct event *event);
+static void process_sysret(struct event *event);
+static void process_breakpoint(struct event *event);
+static void remove_proc(struct process *proc);
+
+static void callstack_push_syscall(struct process *proc, int sysnum);
+static void callstack_push_symfunc(struct process *proc,
+ struct library_symbol *sym);
+static void callstack_pop(struct process *proc);
+
+static char *shortsignal(int signum)
+{
+ static char *signalent0[] = {
+#include "signalent.h"
};
int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
@@ -46,11 +47,11 @@ shortsignal(int signum) {
}
}
-static char *
-sysname(int sysnum) {
+static char *sysname(int sysnum)
+{
static char result[128];
- static char * syscalent0[] = {
- #include "syscallent.h"
+ static char *syscalent0[] = {
+#include "syscallent.h"
};
int nsyscals0 = sizeof syscalent0 / sizeof syscalent0[0];
@@ -63,44 +64,48 @@ sysname(int sysnum) {
}
}
-void
-process_event(struct event * event) {
+void process_event(struct event *event)
+{
switch (event->thing) {
- case LT_EV_NONE:
- debug(1, "event: none");
- return;
- case LT_EV_SIGNAL:
- debug(1, "event: signal (%s [%d])", shortsignal(event->e_un.signum), event->e_un.signum);
- process_signal(event);
- return;
- case LT_EV_EXIT:
- debug(1, "event: exit (%d)", event->e_un.ret_val);
- process_exit(event);
- return;
- case LT_EV_EXIT_SIGNAL:
- debug(1, "event: exit signal (%s [%d])", shortsignal(event->e_un.signum), event->e_un.signum);
- process_exit_signal(event);
- return;
- case LT_EV_SYSCALL:
- debug(1, "event: syscall (%s [%d])", sysname (event->e_un.sysnum), event->e_un.sysnum);
- process_syscall(event);
- return;
- case LT_EV_SYSRET:
- debug(1, "event: sysret (%s [%d])", sysname (event->e_un.sysnum), event->e_un.sysnum);
- process_sysret(event);
- return;
- case LT_EV_BREAKPOINT:
- debug(1, "event: breakpoint");
- process_breakpoint(event);
- return;
- default:
- fprintf(stderr, "Error! unknown event?\n");
- exit(1);
+ case LT_EV_NONE:
+ debug(1, "event: none");
+ return;
+ case LT_EV_SIGNAL:
+ debug(1, "event: signal (%s [%d])",
+ shortsignal(event->e_un.signum), event->e_un.signum);
+ process_signal(event);
+ return;
+ case LT_EV_EXIT:
+ debug(1, "event: exit (%d)", event->e_un.ret_val);
+ process_exit(event);
+ return;
+ case LT_EV_EXIT_SIGNAL:
+ debug(1, "event: exit signal (%s [%d])",
+ shortsignal(event->e_un.signum), event->e_un.signum);
+ process_exit_signal(event);
+ return;
+ case LT_EV_SYSCALL:
+ debug(1, "event: syscall (%s [%d])",
+ sysname(event->e_un.sysnum), event->e_un.sysnum);
+ process_syscall(event);
+ return;
+ case LT_EV_SYSRET:
+ debug(1, "event: sysret (%s [%d])", sysname(event->e_un.sysnum),
+ event->e_un.sysnum);
+ process_sysret(event);
+ return;
+ case LT_EV_BREAKPOINT:
+ debug(1, "event: breakpoint");
+ process_breakpoint(event);
+ return;
+ default:
+ fprintf(stderr, "Error! unknown event?\n");
+ exit(1);
}
}
-static void
-process_signal(struct event * event) {
+static void process_signal(struct event *event)
+{
if (exiting && event->e_un.signum == SIGSTOP) {
pid_t pid = event->proc->pid;
disable_all_breakpoints(event->proc);
@@ -110,26 +115,27 @@ process_signal(struct event * event) {
return;
}
output_line(event->proc, "--- %s (%s) ---",
- shortsignal(event->e_un.signum), strsignal(event->e_un.signum));
+ shortsignal(event->e_un.signum),
+ strsignal(event->e_un.signum));
continue_after_signal(event->proc->pid, event->e_un.signum);
}
-static void
-process_exit(struct event * event) {
+static void process_exit(struct event *event)
+{
output_line(event->proc, "+++ exited (status %d) +++",
- event->e_un.ret_val);
+ event->e_un.ret_val);
remove_proc(event->proc);
}
-static void
-process_exit_signal(struct event * event) {
+static void process_exit_signal(struct event *event)
+{
output_line(event->proc, "+++ killed by %s +++",
- shortsignal(event->e_un.signum));
+ shortsignal(event->e_un.signum));
remove_proc(event->proc);
}
-static void
-remove_proc(struct process * proc) {
+static void remove_proc(struct process *proc)
+{
struct process *tmp, *tmp2;
debug(1, "Removing pid %u\n", proc->pid);
@@ -141,8 +147,8 @@ remove_proc(struct process * proc) {
return;
}
tmp = list_of_processes;
- while(tmp->next) {
- if (tmp->next==proc) {
+ while (tmp->next) {
+ if (tmp->next == proc) {
tmp2 = tmp->next;
tmp->next = tmp->next->next;
free(tmp2);
@@ -152,10 +158,11 @@ remove_proc(struct process * proc) {
}
}
-static void
-process_syscall(struct event * event) {
+static void process_syscall(struct event *event)
+{
if (opt_S) {
- output_left(LT_TOF_SYSCALL, event->proc, sysname(event->e_un.sysnum));
+ output_left(LT_TOF_SYSCALL, event->proc,
+ sysname(event->e_un.sysnum));
}
if (fork_p(event->e_un.sysnum)) {
disable_all_breakpoints(event->proc);
@@ -168,14 +175,14 @@ process_syscall(struct event * event) {
struct timeval current_time_spent;
-static void
-calc_time_spent(struct process * proc) {
+static void calc_time_spent(struct process *proc)
+{
struct timeval tv;
struct timezone tz;
struct timeval diff;
- struct callstack_element * elem;
+ struct callstack_element *elem;
- elem = & proc->callstack[proc->callstack_depth-1];
+ elem = &proc->callstack[proc->callstack_depth - 1];
gettimeofday(&tv, &tz);
@@ -189,15 +196,16 @@ calc_time_spent(struct process * proc) {
current_time_spent = diff;
}
-static void
-process_sysret(struct event * event) {
+static void process_sysret(struct event *event)
+{
if (opt_T || opt_c) {
calc_time_spent(event->proc);
}
if (fork_p(event->e_un.sysnum)) {
if (opt_f) {
- pid_t child = gimme_arg(LT_TOF_SYSCALLR,event->proc,-1);
- if (child>0) {
+ pid_t child =
+ gimme_arg(LT_TOF_SYSCALLR, event->proc, -1);
+ if (child > 0) {
open_pid(child, 0);
}
}
@@ -205,10 +213,11 @@ process_sysret(struct event * event) {
}
callstack_pop(event->proc);
if (opt_S) {
- output_right(LT_TOF_SYSCALLR, event->proc, sysname(event->e_un.sysnum));
+ output_right(LT_TOF_SYSCALLR, event->proc,
+ sysname(event->e_un.sysnum));
}
if (exec_p(event->e_un.sysnum)) {
- if (gimme_arg(LT_TOF_SYSCALLR,event->proc,-1)==0) {
+ if (gimme_arg(LT_TOF_SYSCALLR, event->proc, -1) == 0) {
event->proc->filename = pid2name(event->proc->pid);
breakpoints_init(event->proc);
}
@@ -216,40 +225,45 @@ process_sysret(struct event * event) {
continue_process(event->proc->pid);
}
-static void
-process_breakpoint(struct event * event) {
- struct library_symbol * tmp;
- int i,j;
+static void process_breakpoint(struct event *event)
+{
+ struct library_symbol *tmp;
+ int i, j;
debug(2, "event: breakpoint (%p)", event->e_un.brk_addr);
if (event->proc->breakpoint_being_enabled) {
/* Reinsert breakpoint */
- continue_enabling_breakpoint(event->proc->pid, event->proc->breakpoint_being_enabled);
+ continue_enabling_breakpoint(event->proc->pid,
+ event->proc->
+ breakpoint_being_enabled);
event->proc->breakpoint_being_enabled = NULL;
return;
}
- for(i=event->proc->callstack_depth-1; i>=0; i--) {
- if (event->e_un.brk_addr == event->proc->callstack[i].return_addr) {
+ for (i = event->proc->callstack_depth - 1; i >= 0; i--) {
+ if (event->e_un.brk_addr ==
+ event->proc->callstack[i].return_addr) {
#ifdef __powerpc__
- unsigned long a;
- unsigned long addr = event->proc->callstack[i].c_un.libfunc->enter_addr;
- struct breakpoint *sbp = address2bpstruct(event->proc, addr);
- unsigned char break_insn[] = BREAKPOINT_VALUE;
-
- /*
- * PPC HACK! (XXX FIXME TODO)
- * The PLT gets modified during the first call,
- * so be sure to re-enable the breakpoint.
- */
- a = ptrace(PTRACE_PEEKTEXT, event->proc->pid, addr);
-
- if (memcmp(&a, break_insn, 4)) {
- sbp->enabled--;
- insert_breakpoint(event->proc, addr);
- }
+ unsigned long a;
+ unsigned long addr =
+ event->proc->callstack[i].c_un.libfunc->enter_addr;
+ struct breakpoint *sbp =
+ address2bpstruct(event->proc, addr);
+ unsigned char break_insn[] = BREAKPOINT_VALUE;
+
+ /*
+ * PPC HACK! (XXX FIXME TODO)
+ * The PLT gets modified during the first call,
+ * so be sure to re-enable the breakpoint.
+ */
+ a = ptrace(PTRACE_PEEKTEXT, event->proc->pid, addr);
+
+ if (memcmp(&a, break_insn, 4)) {
+ sbp->enabled--;
+ insert_breakpoint(event->proc, addr);
+ }
#endif
- for(j=event->proc->callstack_depth-1; j>i; j--) {
+ for (j = event->proc->callstack_depth - 1; j > i; j--) {
callstack_pop(event->proc);
}
if (opt_T || opt_c) {
@@ -258,41 +272,50 @@ process_breakpoint(struct event * event) {
callstack_pop(event->proc);
event->proc->return_addr = event->e_un.brk_addr;
output_right(LT_TOF_FUNCTIONR, event->proc,
- event->proc->callstack[i].c_un.libfunc->name);
+ event->proc->callstack[i].c_un.libfunc->
+ name);
continue_after_breakpoint(event->proc,
- address2bpstruct(event->proc, event->e_un.brk_addr));
+ address2bpstruct(event->proc,
+ event->e_un.
+ brk_addr));
return;
}
}
tmp = event->proc->list_of_symbols;
- while(tmp) {
+ while (tmp) {
if (event->e_un.brk_addr == tmp->enter_addr) {
- event->proc->stack_pointer = get_stack_pointer(event->proc);
- event->proc->return_addr = get_return_addr(event->proc, event->proc->stack_pointer);
+ event->proc->stack_pointer =
+ get_stack_pointer(event->proc);
+ event->proc->return_addr =
+ get_return_addr(event->proc,
+ event->proc->stack_pointer);
output_left(LT_TOF_FUNCTION, event->proc, tmp->name);
callstack_push_symfunc(event->proc, tmp);
- continue_after_breakpoint(event->proc, address2bpstruct(event->proc, tmp->enter_addr));
+ continue_after_breakpoint(event->proc,
+ address2bpstruct(event->proc,
+ tmp->
+ enter_addr));
return;
}
tmp = tmp->next;
}
output_line(event->proc, "breakpointed at %p (?)",
- (void *)event->e_un.brk_addr);
+ (void *)event->e_un.brk_addr);
continue_process(event->proc->pid);
}
-static void
-callstack_push_syscall(struct process * proc, int sysnum) {
- struct callstack_element * elem;
+static void callstack_push_syscall(struct process *proc, int sysnum)
+{
+ struct callstack_element *elem;
/* FIXME: not good -- should use dynamic allocation. 19990703 mortene. */
- if (proc->callstack_depth == MAX_CALLDEPTH-1) {
+ if (proc->callstack_depth == MAX_CALLDEPTH - 1) {
fprintf(stderr, "Error: call nesting too deep!\n");
return;
}
- elem = & proc->callstack[proc->callstack_depth];
+ elem = &proc->callstack[proc->callstack_depth];
elem->is_syscall = 1;
elem->c_un.syscall = sysnum;
elem->return_addr = NULL;
@@ -305,16 +328,17 @@ callstack_push_syscall(struct process * proc, int sysnum) {
}
static void
-callstack_push_symfunc(struct process * proc, struct library_symbol * sym) {
- struct callstack_element * elem;
+callstack_push_symfunc(struct process *proc, struct library_symbol *sym)
+{
+ struct callstack_element *elem;
/* FIXME: not good -- should use dynamic allocation. 19990703 mortene. */
- if (proc->callstack_depth == MAX_CALLDEPTH-1) {
+ if (proc->callstack_depth == MAX_CALLDEPTH - 1) {
fprintf(stderr, "Error: call nesting too deep!\n");
return;
}
- elem = & proc->callstack[proc->callstack_depth];
+ elem = &proc->callstack[proc->callstack_depth];
elem->is_syscall = 0;
elem->c_un.libfunc = sym;
@@ -328,12 +352,12 @@ callstack_push_symfunc(struct process * proc, struct library_symbol * sym) {
}
}
-static void
-callstack_pop(struct process * proc) {
- struct callstack_element * elem;
+static void callstack_pop(struct process *proc)
+{
+ struct callstack_element *elem;
assert(proc->callstack_depth > 0);
- elem = & proc->callstack[proc->callstack_depth-1];
+ elem = &proc->callstack[proc->callstack_depth - 1];
if (!elem->is_syscall) {
delete_breakpoint(proc, elem->return_addr);
}
diff --git a/read_config_file.c b/read_config_file.c
index ddaa742..e5c3f6b 100644
--- a/read_config_file.c
+++ b/read_config_file.c
@@ -24,46 +24,46 @@
* "addr" ARGTYPE_ADDR
*/
-struct function * list_of_functions = NULL;
+struct function *list_of_functions = NULL;
static struct list_of_pt_t {
- char * name;
+ char *name;
enum arg_type pt;
} list_of_pt[] = {
- { "void", ARGTYPE_VOID },
- { "int", ARGTYPE_INT },
- { "uint", ARGTYPE_UINT },
- { "long", ARGTYPE_LONG },
- { "ulong", ARGTYPE_ULONG },
- { "octal", ARGTYPE_OCTAL },
- { "char", ARGTYPE_CHAR },
- { "addr", ARGTYPE_ADDR },
- { "file", ARGTYPE_FILE },
- { "format", ARGTYPE_FORMAT },
- { "string", ARGTYPE_STRING },
- { NULL, ARGTYPE_UNKNOWN } /* Must finish with NULL */
+ {
+ "void", ARGTYPE_VOID}, {
+ "int", ARGTYPE_INT}, {
+ "uint", ARGTYPE_UINT}, {
+ "long", ARGTYPE_LONG}, {
+ "ulong", ARGTYPE_ULONG}, {
+ "octal", ARGTYPE_OCTAL}, {
+ "char", ARGTYPE_CHAR}, {
+ "addr", ARGTYPE_ADDR}, {
+ "file", ARGTYPE_FILE}, {
+ "format", ARGTYPE_FORMAT}, {
+ "string", ARGTYPE_STRING}, {
+ NULL, ARGTYPE_UNKNOWN} /* Must finish with NULL */
};
-static struct complete_arg_type
-str2type(char ** str) {
- struct list_of_pt_t * tmp = &list_of_pt[0];
- struct complete_arg_type pt = {0,0};
+static struct complete_arg_type str2type(char **str)
+{
+ struct list_of_pt_t *tmp = &list_of_pt[0];
+ struct complete_arg_type pt = { 0, 0 };
- if (!strncmp(*str, "string", 6)
- && isdigit((unsigned char)(*str)[6]))
- {
+ if (!strncmp(*str, "string", 6)
+ && isdigit((unsigned char)(*str)[6])) {
pt.at = ARGTYPE_STRINGN;
pt.argno = atoi(*str + 6);
*str += strspn(*str, "string0123456789");
return pt;
- }
+ }
- while(tmp->name) {
+ while (tmp->name) {
if (!strncmp(*str, tmp->name, strlen(tmp->name))
- && index(" ,)#", *(*str+strlen(tmp->name)))) {
- *str += strlen(tmp->name);
- pt.at = tmp->pt;
- return pt;
+ && index(" ,)#", *(*str + strlen(tmp->name)))) {
+ *str += strlen(tmp->name);
+ pt.at = tmp->pt;
+ return pt;
}
tmp++;
}
@@ -71,9 +71,9 @@ str2type(char ** str) {
return pt;
}
-static void
-eat_spaces(char ** str) {
- while(**str==' ') {
+static void eat_spaces(char **str)
+{
+ while (**str == ' ') {
(*str)++;
}
}
@@ -82,22 +82,28 @@ eat_spaces(char ** str) {
Returns position in string at the left parenthesis which starts the
function's argument signature. Returns NULL on error.
*/
-static char *
-start_of_arg_sig(char * str) {
- char * pos;
+static char *start_of_arg_sig(char *str)
+{
+ char *pos;
int stacked = 0;
- if (!strlen(str)) return NULL;
+ if (!strlen(str))
+ return NULL;
pos = &str[strlen(str)];
do {
pos--;
- if (pos < str) return NULL;
- while ((pos > str) && (*pos != ')') && (*pos != '(')) pos--;
-
- if (*pos == ')') stacked++;
- else if (*pos == '(') stacked--;
- else return NULL;
+ if (pos < str)
+ return NULL;
+ while ((pos > str) && (*pos != ')') && (*pos != '('))
+ pos--;
+
+ if (*pos == ')')
+ stacked++;
+ else if (*pos == '(')
+ stacked--;
+ else
+ return NULL;
} while (stacked > 0);
@@ -105,21 +111,21 @@ start_of_arg_sig(char * str) {
}
static int line_no;
-static char * filename;
+static char *filename;
-static struct function *
-process_line (char * buf) {
+static struct function *process_line(char *buf)
+{
struct function fun;
- struct function * fun_p;
- char * str = buf;
- char * tmp;
+ struct function *fun_p;
+ char *str = buf;
+ char *tmp;
int i;
line_no++;
debug(3, "Reading line %d of `%s'", line_no, filename);
eat_spaces(&str);
fun.return_type = str2type(&str);
- if (fun.return_type.at==ARGTYPE_UNKNOWN) {
+ if (fun.return_type.at == ARGTYPE_UNKNOWN) {
debug(3, " Skipping line %d", line_no);
return NULL;
}
@@ -127,38 +133,41 @@ process_line (char * buf) {
eat_spaces(&str);
tmp = start_of_arg_sig(str);
if (!tmp) {
- output_line(0, "Syntax error in `%s', line %d", filename, line_no);
+ output_line(0, "Syntax error in `%s', line %d", filename,
+ line_no);
return NULL;
}
*tmp = '\0';
fun.name = strdup(str);
- str = tmp+1;
+ str = tmp + 1;
debug(3, " name = %s", fun.name);
fun.params_right = 0;
- for(i=0; i<MAX_ARGS; i++) {
+ for (i = 0; i < MAX_ARGS; i++) {
eat_spaces(&str);
if (*str == ')') {
break;
}
- if (str[0]=='+') {
+ if (str[0] == '+') {
fun.params_right++;
str++;
} else if (fun.params_right) {
fun.params_right++;
}
fun.arg_types[i] = str2type(&str);
- if (fun.return_type.at==ARGTYPE_UNKNOWN) {
- output_line(0, "Syntax error in `%s', line %d", filename, line_no);
+ if (fun.return_type.at == ARGTYPE_UNKNOWN) {
+ output_line(0, "Syntax error in `%s', line %d",
+ filename, line_no);
return NULL;
}
eat_spaces(&str);
- if (*str==',') {
+ if (*str == ',') {
str++;
continue;
- } else if (*str==')') {
+ } else if (*str == ')') {
continue;
} else {
- output_line(0, "Syntax error in `%s', line %d", filename, line_no);
+ output_line(0, "Syntax error in `%s', line %d",
+ filename, line_no);
return NULL;
}
}
@@ -168,9 +177,9 @@ process_line (char * buf) {
return fun_p;
}
-void
-read_config_file(char * file) {
- FILE * stream;
+void read_config_file(char *file)
+{
+ FILE *stream;
char buf[1024];
filename = file;
@@ -181,9 +190,9 @@ read_config_file(char * file) {
if (!stream) {
return;
}
- line_no=0;
+ line_no = 0;
while (fgets(buf, 1024, stream)) {
- struct function * tmp = process_line(buf);
+ struct function *tmp = process_line(buf);
if (tmp) {
debug(2, "New function: `%s'", tmp->name);
diff --git a/summary.c b/summary.c
index 2cfe4d6..7dc2c07 100644
--- a/summary.c
+++ b/summary.c
@@ -1,24 +1,33 @@
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include "ltrace.h"
+#include "options.h"
+
+#ifdef USE_DEMANGLE
+#include "demangle.h"
+#endif
static int num_entries = 0;
static struct entry_st {
char *name;
int count;
struct timeval tv;
-} * entries = NULL;
+} *entries = NULL;
static int tot_count = 0;
static unsigned long int tot_usecs = 0;
-static void
-fill_struct(void * key, void * value, void * data) {
- struct opt_c_struct * st = (struct opt_c_struct *)value;
+static void fill_struct(void *key, void *value, void *data)
+{
+ struct opt_c_struct *st = (struct opt_c_struct *)value;
- entries = realloc(entries, (num_entries+1)*sizeof(struct entry_st));
+ entries = realloc(entries, (num_entries + 1) * sizeof(struct entry_st));
if (!entries) {
perror("realloc()");
exit(1);
@@ -28,14 +37,14 @@ fill_struct(void * key, void * value, void * data) {
entries[num_entries].tv = st->tv;
tot_count += st->count;
- tot_usecs += 1000000*st->tv.tv_sec;
+ tot_usecs += 1000000 * st->tv.tv_sec;
tot_usecs += st->tv.tv_usec;
num_entries++;
}
-static int
-compar(const void *a, const void *b) {
+static int compar(const void *a, const void *b)
+{
struct entry_st *en1, *en2;
en1 = (struct entry_st *)a;
@@ -48,8 +57,8 @@ compar(const void *a, const void *b) {
}
}
-void
-show_summary(void) {
+void show_summary(void)
+{
int i;
num_entries = 0;
@@ -60,20 +69,23 @@ show_summary(void) {
qsort(entries, num_entries, sizeof(*entries), compar);
printf("%% time seconds usecs/call calls function\n");
- printf( "------ ----------- ----------- --------- --------------------\n");
- for(i=0; i<num_entries; i++) {
+ printf
+ ("------ ----------- ----------- --------- --------------------\n");
+ for (i = 0; i < num_entries; i++) {
unsigned long long int c;
unsigned long long int p;
- c = 1000000 * (int)entries[i].tv.tv_sec + (int)entries[i].tv.tv_usec;
+ c = 1000000 * (int)entries[i].tv.tv_sec +
+ (int)entries[i].tv.tv_usec;
p = 100000 * c / tot_usecs + 5;
printf("%3lu.%02lu %4d.%06d %11lu %9d %s\n",
- (unsigned long int)(p / 1000),
- (unsigned long int)((p / 10) % 100),
- (int)entries[i].tv.tv_sec, (int)entries[i].tv.tv_usec,
- (unsigned long int)(c / entries[i].count),
- entries[i].count, entries[i].name);
+ (unsigned long int)(p / 1000),
+ (unsigned long int)((p / 10) % 100),
+ (int)entries[i].tv.tv_sec, (int)entries[i].tv.tv_usec,
+ (unsigned long int)(c / entries[i].count),
+ entries[i].count, opt_C ? my_demangle(entries[i].name) : entries[i].name);
}
- printf("------ ----------- ----------- --------- --------------------\n");
- printf("100.00 %4lu.%06lu %9d total\n",
- tot_usecs / 1000000, tot_usecs % 1000000, tot_count);
+ printf
+ ("------ ----------- ----------- --------- --------------------\n");
+ printf("100.00 %4lu.%06lu %9d total\n", tot_usecs / 1000000,
+ tot_usecs % 1000000, tot_count);
}
diff --git a/sysdeps/linux-gnu/alpha/plt.c b/sysdeps/linux-gnu/alpha/plt.c
index a626d59..32dfafb 100644
--- a/sysdeps/linux-gnu/alpha/plt.c
+++ b/sysdeps/linux-gnu/alpha/plt.c
@@ -2,8 +2,7 @@
#include "ltrace.h"
#include "elf.h"
-GElf_Addr
-arch_plt_sym_val (struct ltelf *lte, size_t ndx, GElf_Rela *rela)
+GElf_Addr arch_plt_sym_val(struct ltelf * lte, size_t ndx, GElf_Rela * rela)
{
- return lte->plt_addr + ndx * 12 + 32;
+ return lte->plt_addr + ndx * 12 + 32;
}
diff --git a/sysdeps/linux-gnu/alpha/regs.c b/sysdeps/linux-gnu/alpha/regs.c
index c59eee9..fcba535 100644
--- a/sysdeps/linux-gnu/alpha/regs.c
+++ b/sysdeps/linux-gnu/alpha/regs.c
@@ -16,22 +16,22 @@
# define PTRACE_POKEUSER PTRACE_POKEUSR
#endif
-void *
-get_instruction_pointer(struct process * proc) {
- return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 64 /* REG_PC */, 0);
+void *get_instruction_pointer(struct process *proc)
+{
+ return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 64 /* REG_PC */ , 0);
}
-void
-set_instruction_pointer(struct process * proc, void * addr) {
- ptrace(PTRACE_POKEUSER, proc->pid, 64 /* REG_PC */, addr);
+void set_instruction_pointer(struct process *proc, void *addr)
+{
+ ptrace(PTRACE_POKEUSER, proc->pid, 64 /* REG_PC */ , addr);
}
-void *
-get_stack_pointer(struct process * proc) {
- return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 30 /* REG_FP */, 0);
+void *get_stack_pointer(struct process *proc)
+{
+ return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 30 /* REG_FP */ , 0);
}
-void *
-get_return_addr(struct process * proc, void * stack_pointer) {
- return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 26 /* RA */, 0);
+void *get_return_addr(struct process *proc, void *stack_pointer)
+{
+ return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 26 /* RA */ , 0);
}
diff --git a/sysdeps/linux-gnu/alpha/trace.c b/sysdeps/linux-gnu/alpha/trace.c
index 872d0e9..3d35cf2 100644
--- a/sysdeps/linux-gnu/alpha/trace.c
+++ b/sysdeps/linux-gnu/alpha/trace.c
@@ -25,45 +25,51 @@ void get_arch_dep(struct process *proc)
/* Returns 1 if syscall, 2 if sysret, 0 otherwise.
*/
-int
-syscall_p(struct process * proc, int status, int * sysnum) {
- if (WIFSTOPPED(status) && WSTOPSIG(status)==SIGTRAP) {
- char *ip=get_instruction_pointer(proc) - 4;
+int syscall_p(struct process *proc, int status, int *sysnum)
+{
+ if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
+ char *ip = get_instruction_pointer(proc) - 4;
long x = ptrace(PTRACE_PEEKTEXT, proc->pid, ip, 0);
debug(2, "instr: %016lx", x);
- if((x & 0xffffffff) != 0x00000083)
+ if ((x & 0xffffffff) != 0x00000083)
return 0;
- *sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 0 /* REG_R0 */, 0);
- if (proc->callstack_depth > 0 && proc->callstack[proc->callstack_depth-1].is_syscall) {
+ *sysnum =
+ ptrace(PTRACE_PEEKUSER, proc->pid, 0 /* REG_R0 */ , 0);
+ if (proc->callstack_depth > 0
+ && proc->callstack[proc->callstack_depth - 1].is_syscall) {
return 2;
}
- if (*sysnum>=0 && *sysnum<500) {
+ if (*sysnum >= 0 && *sysnum < 500) {
return 1;
}
}
return 0;
}
-long
-gimme_arg(enum tof type, struct process * proc, int arg_num) {
- if (arg_num==-1) { /* return value */
- return ptrace(PTRACE_PEEKUSER, proc->pid, 0 /* REG_R0 */, 0);
+long gimme_arg(enum tof type, struct process *proc, int arg_num)
+{
+ if (arg_num == -1) { /* return value */
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 0 /* REG_R0 */ , 0);
}
- if (type==LT_TOF_FUNCTION || type==LT_TOF_FUNCTIONR) {
- if(arg_num <= 5)
- return ptrace(PTRACE_PEEKUSER, proc->pid, arg_num + 16 /* REG_A0 */, 0);
+ if (type == LT_TOF_FUNCTION || type == LT_TOF_FUNCTIONR) {
+ if (arg_num <= 5)
+ return ptrace(PTRACE_PEEKUSER, proc->pid,
+ arg_num + 16 /* REG_A0 */ , 0);
else
- return ptrace(PTRACE_PEEKTEXT, proc->pid, proc->stack_pointer+8*(arg_num-6), 0);
- } else if (type==LT_TOF_SYSCALL || type==LT_TOF_SYSCALLR) {
- return ptrace(PTRACE_PEEKUSER, proc->pid, arg_num + 16 /* REG_A0 */, 0);
+ return ptrace(PTRACE_PEEKTEXT, proc->pid,
+ proc->stack_pointer + 8 * (arg_num - 6),
+ 0);
+ } else if (type == LT_TOF_SYSCALL || type == LT_TOF_SYSCALLR) {
+ return ptrace(PTRACE_PEEKUSER, proc->pid,
+ arg_num + 16 /* REG_A0 */ , 0);
} else {
fprintf(stderr, "gimme_arg called with wrong arguments\n");
exit(1);
}
return 0;
}
-
-void save_register_args(enum tof type, struct process * proc)
+
+void save_register_args(enum tof type, struct process *proc)
{
}
diff --git a/sysdeps/linux-gnu/arm/plt.c b/sysdeps/linux-gnu/arm/plt.c
index 635b4ce..1dae91f 100644
--- a/sysdeps/linux-gnu/arm/plt.c
+++ b/sysdeps/linux-gnu/arm/plt.c
@@ -2,8 +2,7 @@
#include "ltrace.h"
#include "elf.h"
-GElf_Addr
-arch_plt_sym_val (struct ltelf *lte, size_t ndx, GElf_Rela *rela)
+GElf_Addr arch_plt_sym_val(struct ltelf * lte, size_t ndx, GElf_Rela * rela)
{
- return lte->plt_addr + 20 + ndx * 12;
+ return lte->plt_addr + 20 + ndx * 12;
}
diff --git a/sysdeps/linux-gnu/arm/regs.c b/sysdeps/linux-gnu/arm/regs.c
index 70ead10..819754f 100644
--- a/sysdeps/linux-gnu/arm/regs.c
+++ b/sysdeps/linux-gnu/arm/regs.c
@@ -20,24 +20,24 @@
#define off_lr 56
#define off_sp 52
-void *
-get_instruction_pointer(struct process * proc) {
+void *get_instruction_pointer(struct process *proc)
+{
return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, off_pc, 0);
}
-void
-set_instruction_pointer(struct process * proc, void * addr) {
+void set_instruction_pointer(struct process *proc, void *addr)
+{
ptrace(PTRACE_POKEUSER, proc->pid, off_pc, addr);
}
-void *
-get_stack_pointer(struct process * proc) {
+void *get_stack_pointer(struct process *proc)
+{
return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, off_sp, 0);
}
/* really, this is given the *stack_pointer expecting
* a CISC architecture; in our case, we don't need that */
-void *
-get_return_addr(struct process * proc, void * stack_pointer) {
+void *get_return_addr(struct process *proc, void *stack_pointer)
+{
return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, off_lr, 0);
}
diff --git a/sysdeps/linux-gnu/arm/trace.c b/sysdeps/linux-gnu/arm/trace.c
index 7f7a677..0d68ae0 100644
--- a/sysdeps/linux-gnu/arm/trace.c
+++ b/sysdeps/linux-gnu/arm/trace.c
@@ -26,47 +26,54 @@
#define off_ip 48
#define off_pc 60
-void
-get_arch_dep(struct process * proc) {
+void get_arch_dep(struct process *proc)
+{
}
/* Returns 1 if syscall, 2 if sysret, 0 otherwise.
*/
-int
-syscall_p(struct process * proc, int status, int * sysnum) {
- if (WIFSTOPPED(status) && WSTOPSIG(status)==SIGTRAP) {
+int syscall_p(struct process *proc, int status, int *sysnum)
+{
+ if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
/* get the user's pc (plus 8) */
int pc = ptrace(PTRACE_PEEKUSER, proc->pid, off_pc, 0);
/* fetch the SWI instruction */
- int insn = ptrace(PTRACE_PEEKTEXT, proc->pid, pc-4, 0) ;
-
+ int insn = ptrace(PTRACE_PEEKTEXT, proc->pid, pc - 4, 0);
+
*sysnum = insn & 0xFFFF;
/* if it is a syscall, return 1 or 2 */
if ((insn & 0xFFFF0000) == 0xef900000) {
- return ptrace(PTRACE_PEEKUSER, proc->pid, off_ip, 0) ? 2 : 1;
+ return ptrace(PTRACE_PEEKUSER, proc->pid, off_ip,
+ 0) ? 2 : 1;
}
}
return 0;
}
-
-long
-gimme_arg(enum tof type, struct process * proc, int arg_num) {
- if (arg_num==-1) { /* return value */
+
+long gimme_arg(enum tof type, struct process *proc, int arg_num)
+{
+ if (arg_num == -1) { /* return value */
return ptrace(PTRACE_PEEKUSER, proc->pid, off_r0, 0);
}
/* deal with the ARM calling conventions */
- if (type==LT_TOF_FUNCTION || type==LT_TOF_FUNCTIONR) {
- if (arg_num<4) {
- return ptrace(PTRACE_PEEKUSER, proc->pid, 4*arg_num, 0);
+ if (type == LT_TOF_FUNCTION || type == LT_TOF_FUNCTIONR) {
+ if (arg_num < 4) {
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * arg_num,
+ 0);
} else {
- return ptrace(PTRACE_PEEKDATA, proc->pid, proc->stack_pointer+4*(arg_num-4), 0);
+ return ptrace(PTRACE_PEEKDATA, proc->pid,
+ proc->stack_pointer + 4 * (arg_num - 4),
+ 0);
}
- } else if (type==LT_TOF_SYSCALL || type==LT_TOF_SYSCALLR) {
- if (arg_num<5) {
- return ptrace(PTRACE_PEEKUSER, proc->pid, 4*arg_num, 0);
+ } else if (type == LT_TOF_SYSCALL || type == LT_TOF_SYSCALLR) {
+ if (arg_num < 5) {
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * arg_num,
+ 0);
} else {
- return ptrace(PTRACE_PEEKDATA, proc->pid, proc->stack_pointer+4*(arg_num-5), 0);
+ return ptrace(PTRACE_PEEKDATA, proc->pid,
+ proc->stack_pointer + 4 * (arg_num - 5),
+ 0);
}
} else {
fprintf(stderr, "gimme_arg called with wrong arguments\n");
@@ -76,6 +83,6 @@ gimme_arg(enum tof type, struct process * proc, int arg_num) {
return 0;
}
-void
-save_register_args(enum tof type, struct process * proc) {
+void save_register_args(enum tof type, struct process *proc)
+{
}
diff --git a/sysdeps/linux-gnu/breakpoint.c b/sysdeps/linux-gnu/breakpoint.c
index 38a68cc..5701c15 100644
--- a/sysdeps/linux-gnu/breakpoint.c
+++ b/sysdeps/linux-gnu/breakpoint.c
@@ -9,41 +9,49 @@
static unsigned char break_insn[] = BREAKPOINT_VALUE;
-void
-enable_breakpoint(pid_t pid, struct breakpoint * sbp) {
- int i,j;
+void enable_breakpoint(pid_t pid, struct breakpoint *sbp)
+{
+ int i, j;
- if (opt_d>1) {
+ if (opt_d > 1) {
output_line(0, "enable_breakpoint(%d,%p)", pid, sbp->addr);
}
- for(i=0; i < 1+((BREAKPOINT_LENGTH-1)/sizeof(long)); i++) {
- long a = ptrace(PTRACE_PEEKTEXT, pid, sbp->addr + i*sizeof(long), 0);
- for(j=0; j<sizeof(long) && i*sizeof(long)+j < BREAKPOINT_LENGTH; j++) {
- unsigned char * bytes = (unsigned char *)&a;
-
- sbp->orig_value[i*sizeof(long)+j] = bytes[+j];
- bytes[j] = break_insn[i*sizeof(long)+j];
+ for (i = 0; i < 1 + ((BREAKPOINT_LENGTH - 1) / sizeof(long)); i++) {
+ long a =
+ ptrace(PTRACE_PEEKTEXT, pid, sbp->addr + i * sizeof(long),
+ 0);
+ for (j = 0;
+ j < sizeof(long)
+ && i * sizeof(long) + j < BREAKPOINT_LENGTH; j++) {
+ unsigned char *bytes = (unsigned char *)&a;
+
+ sbp->orig_value[i * sizeof(long) + j] = bytes[+j];
+ bytes[j] = break_insn[i * sizeof(long) + j];
}
- ptrace(PTRACE_POKETEXT, pid, sbp->addr + i*sizeof(long), a);
+ ptrace(PTRACE_POKETEXT, pid, sbp->addr + i * sizeof(long), a);
}
}
-void
-disable_breakpoint(pid_t pid, const struct breakpoint * sbp) {
- int i,j;
+void disable_breakpoint(pid_t pid, const struct breakpoint *sbp)
+{
+ int i, j;
- if (opt_d>1) {
+ if (opt_d > 1) {
output_line(0, "disable_breakpoint(%d,%p)", pid, sbp->addr);
}
- for(i=0; i < 1+((BREAKPOINT_LENGTH-1)/sizeof(long)); i++) {
- long a = ptrace(PTRACE_PEEKTEXT, pid, sbp->addr + i*sizeof(long), 0);
- for(j=0; j<sizeof(long) && i*sizeof(long)+j < BREAKPOINT_LENGTH; j++) {
- unsigned char * bytes = (unsigned char *)&a;
+ for (i = 0; i < 1 + ((BREAKPOINT_LENGTH - 1) / sizeof(long)); i++) {
+ long a =
+ ptrace(PTRACE_PEEKTEXT, pid, sbp->addr + i * sizeof(long),
+ 0);
+ for (j = 0;
+ j < sizeof(long)
+ && i * sizeof(long) + j < BREAKPOINT_LENGTH; j++) {
+ unsigned char *bytes = (unsigned char *)&a;
- bytes[j] = sbp->orig_value[i*sizeof(long)+j];
+ bytes[j] = sbp->orig_value[i * sizeof(long) + j];
}
- ptrace(PTRACE_POKETEXT, pid, sbp->addr + i*sizeof(long), a);
+ ptrace(PTRACE_POKETEXT, pid, sbp->addr + i * sizeof(long), a);
}
}
diff --git a/sysdeps/linux-gnu/i386/plt.c b/sysdeps/linux-gnu/i386/plt.c
index e40b03a..939bc4e 100644
--- a/sysdeps/linux-gnu/i386/plt.c
+++ b/sysdeps/linux-gnu/i386/plt.c
@@ -2,8 +2,7 @@
#include "ltrace.h"
#include "elf.h"
-GElf_Addr
-arch_plt_sym_val (struct ltelf *lte, size_t ndx, GElf_Rela *rela)
+GElf_Addr arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela)
{
- return lte->plt_addr + (ndx + 1) * 16;
+ return lte->plt_addr + (ndx + 1) * 16;
}
diff --git a/sysdeps/linux-gnu/i386/regs.c b/sysdeps/linux-gnu/i386/regs.c
index 75268e9..158fa24 100644
--- a/sysdeps/linux-gnu/i386/regs.c
+++ b/sysdeps/linux-gnu/i386/regs.c
@@ -16,22 +16,22 @@
# define PTRACE_POKEUSER PTRACE_POKEUSR
#endif
-void *
-get_instruction_pointer(struct process * proc) {
- return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4*EIP, 0);
+void *get_instruction_pointer(struct process *proc)
+{
+ return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EIP, 0);
}
-void
-set_instruction_pointer(struct process * proc, void * addr) {
- ptrace(PTRACE_POKEUSER, proc->pid, 4*EIP, (long)addr);
+void set_instruction_pointer(struct process *proc, void *addr)
+{
+ ptrace(PTRACE_POKEUSER, proc->pid, 4 * EIP, (long)addr);
}
-void *
-get_stack_pointer(struct process * proc) {
- return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4*UESP, 0);
+void *get_stack_pointer(struct process *proc)
+{
+ return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4 * UESP, 0);
}
-void *
-get_return_addr(struct process * proc, void * stack_pointer) {
+void *get_return_addr(struct process *proc, void *stack_pointer)
+{
return (void *)ptrace(PTRACE_PEEKTEXT, proc->pid, stack_pointer, 0);
}
diff --git a/sysdeps/linux-gnu/i386/trace.c b/sysdeps/linux-gnu/i386/trace.c
index e6d77f7..fe9d8a4 100644
--- a/sysdeps/linux-gnu/i386/trace.c
+++ b/sysdeps/linux-gnu/i386/trace.c
@@ -19,51 +19,58 @@
# define PTRACE_POKEUSER PTRACE_POKEUSR
#endif
-void
-get_arch_dep(struct process * proc) {
+void get_arch_dep(struct process *proc)
+{
}
/* Returns 1 if syscall, 2 if sysret, 0 otherwise.
*/
-int
-syscall_p(struct process * proc, int status, int * sysnum) {
- if (WIFSTOPPED(status) && WSTOPSIG(status)==SIGTRAP) {
- *sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 4*ORIG_EAX, 0);
+int syscall_p(struct process *proc, int status, int *sysnum)
+{
+ if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
+ *sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 4 * ORIG_EAX, 0);
if (proc->callstack_depth > 0 &&
- proc->callstack[proc->callstack_depth-1].is_syscall) {
+ proc->callstack[proc->callstack_depth - 1].is_syscall) {
return 2;
}
- if (*sysnum>=0) {
+ if (*sysnum >= 0) {
return 1;
}
}
return 0;
}
-long
-gimme_arg(enum tof type, struct process * proc, int arg_num) {
- if (arg_num==-1) { /* return value */
- return ptrace(PTRACE_PEEKUSER, proc->pid, 4*EAX, 0);
+long gimme_arg(enum tof type, struct process *proc, int arg_num)
+{
+ if (arg_num == -1) { /* return value */
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EAX, 0);
}
- if (type==LT_TOF_FUNCTION || type==LT_TOF_FUNCTIONR) {
- return ptrace(PTRACE_PEEKTEXT, proc->pid, proc->stack_pointer+4*(arg_num+1), 0);
- } else if (type==LT_TOF_SYSCALL || type==LT_TOF_SYSCALLR) {
+ if (type == LT_TOF_FUNCTION || type == LT_TOF_FUNCTIONR) {
+ return ptrace(PTRACE_PEEKTEXT, proc->pid,
+ proc->stack_pointer + 4 * (arg_num + 1), 0);
+ } else if (type == LT_TOF_SYSCALL || type == LT_TOF_SYSCALLR) {
#if 0
- switch(arg_num) {
- case 0: return ptrace(PTRACE_PEEKUSER, proc->pid, 4*EBX, 0);
- case 1: return ptrace(PTRACE_PEEKUSER, proc->pid, 4*ECX, 0);
- case 2: return ptrace(PTRACE_PEEKUSER, proc->pid, 4*EDX, 0);
- case 3: return ptrace(PTRACE_PEEKUSER, proc->pid, 4*ESI, 0);
- case 4: return ptrace(PTRACE_PEEKUSER, proc->pid, 4*EDI, 0);
- default:
- fprintf(stderr, "gimme_arg called with wrong arguments\n");
- exit(2);
+ switch (arg_num) {
+ case 0:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EBX, 0);
+ case 1:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * ECX, 0);
+ case 2:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EDX, 0);
+ case 3:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * ESI, 0);
+ case 4:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * EDI, 0);
+ default:
+ fprintf(stderr,
+ "gimme_arg called with wrong arguments\n");
+ exit(2);
}
#else
- return ptrace(PTRACE_PEEKUSER, proc->pid, 4*arg_num, 0);
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * arg_num, 0);
#endif
} else {
fprintf(stderr, "gimme_arg called with wrong arguments\n");
@@ -73,6 +80,6 @@ gimme_arg(enum tof type, struct process * proc, int arg_num) {
return 0;
}
-void
-save_register_args(enum tof type, struct process * proc) {
+void save_register_args(enum tof type, struct process *proc)
+{
}
diff --git a/sysdeps/linux-gnu/m68k/plt.c b/sysdeps/linux-gnu/m68k/plt.c
index f20986c..09168e9 100644
--- a/sysdeps/linux-gnu/m68k/plt.c
+++ b/sysdeps/linux-gnu/m68k/plt.c
@@ -2,9 +2,8 @@
#include "ltrace.h"
#include "elf.h"
-GElf_Addr
-arch_plt_sym_val (struct ltelf *lte, size_t ndx, GElf_Rela *rela)
+GElf_Addr arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela)
{
- return lte->plt_addr + (ndx + 1)
- * ((lte->ehdr.e_flags & EF_CPU32) ? 24 : 12);
+ return lte->plt_addr + (ndx + 1)
+ * ((lte->ehdr.e_flags & EF_CPU32) ? 24 : 12);
}
diff --git a/sysdeps/linux-gnu/m68k/regs.c b/sysdeps/linux-gnu/m68k/regs.c
index 187cef5..d953d28 100644
--- a/sysdeps/linux-gnu/m68k/regs.c
+++ b/sysdeps/linux-gnu/m68k/regs.c
@@ -16,22 +16,22 @@
# define PTRACE_POKEUSER PTRACE_POKEUSR
#endif
-void *
-get_instruction_pointer(struct process * proc) {
- return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_PC, 0);
+void *get_instruction_pointer(struct process *proc)
+{
+ return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_PC, 0);
}
-void
-set_instruction_pointer(struct process * proc, void * addr) {
- ptrace(PTRACE_POKEUSER, proc->pid, 4*PT_PC, addr);
+void set_instruction_pointer(struct process *proc, void *addr)
+{
+ ptrace(PTRACE_POKEUSER, proc->pid, 4 * PT_PC, addr);
}
-void *
-get_stack_pointer(struct process * proc) {
- return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_USP, 0);
+void *get_stack_pointer(struct process *proc)
+{
+ return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_USP, 0);
}
-void *
-get_return_addr(struct process * proc, void * stack_pointer) {
+void *get_return_addr(struct process *proc, void *stack_pointer)
+{
return (void *)ptrace(PTRACE_PEEKTEXT, proc->pid, stack_pointer, 0);
}
diff --git a/sysdeps/linux-gnu/m68k/trace.c b/sysdeps/linux-gnu/m68k/trace.c
index 88caca7..b4e1b88 100644
--- a/sysdeps/linux-gnu/m68k/trace.c
+++ b/sysdeps/linux-gnu/m68k/trace.c
@@ -18,24 +18,26 @@
# define PTRACE_POKEUSER PTRACE_POKEUSR
#endif
-void
-get_arch_dep(struct process * proc) {
+void get_arch_dep(struct process *proc)
+{
}
/* Returns 1 if syscall, 2 if sysret, 0 otherwise.
*/
-int
-syscall_p(struct process * proc, int status, int * sysnum) {
+int syscall_p(struct process *proc, int status, int *sysnum)
+{
int depth;
- if (WIFSTOPPED(status) && WSTOPSIG(status)==SIGTRAP) {
- *sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_ORIG_D0, 0);
- if (*sysnum == -1) return 0;
- if (*sysnum>=0) {
+ if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
+ *sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_ORIG_D0, 0);
+ if (*sysnum == -1)
+ return 0;
+ if (*sysnum >= 0) {
depth = proc->callstack_depth;
- if (depth>0 &&
- proc->callstack[depth-1].is_syscall &&
- proc->callstack[depth-1].c_un.syscall==*sysnum) {
+ if (depth > 0 &&
+ proc->callstack[depth - 1].is_syscall &&
+ proc->callstack[depth - 1].c_un.syscall ==
+ *sysnum) {
return 2;
} else {
return 1;
@@ -45,29 +47,36 @@ syscall_p(struct process * proc, int status, int * sysnum) {
return 0;
}
-long
-gimme_arg(enum tof type, struct process * proc, int arg_num) {
- if (arg_num==-1) { /* return value */
- return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D0, 0);
+long gimme_arg(enum tof type, struct process *proc, int arg_num)
+{
+ if (arg_num == -1) { /* return value */
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_D0, 0);
}
- if (type==LT_TOF_FUNCTION || type==LT_TOF_FUNCTIONR) {
- return ptrace(PTRACE_PEEKTEXT, proc->pid, proc->stack_pointer+4*(arg_num+1), 0);
- } else if (type==LT_TOF_SYSCALL || type==LT_TOF_SYSCALLR) {
+ if (type == LT_TOF_FUNCTION || type == LT_TOF_FUNCTIONR) {
+ return ptrace(PTRACE_PEEKTEXT, proc->pid,
+ proc->stack_pointer + 4 * (arg_num + 1), 0);
+ } else if (type == LT_TOF_SYSCALL || type == LT_TOF_SYSCALLR) {
#if 0
- switch(arg_num) {
- case 0: return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D1, 0);
- case 1: return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D2, 0);
- case 2: return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D3, 0);
- case 3: return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D4, 0);
- case 4: return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_D5, 0);
- default:
- fprintf(stderr, "gimme_arg called with wrong arguments\n");
- exit(2);
+ switch (arg_num) {
+ case 0:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_D1, 0);
+ case 1:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_D2, 0);
+ case 2:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_D3, 0);
+ case 3:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_D4, 0);
+ case 4:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_D5, 0);
+ default:
+ fprintf(stderr,
+ "gimme_arg called with wrong arguments\n");
+ exit(2);
}
#else
/* That hack works on m68k, too */
- return ptrace(PTRACE_PEEKUSER, proc->pid, 4*arg_num, 0);
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * arg_num, 0);
#endif
} else {
fprintf(stderr, "gimme_arg called with wrong arguments\n");
@@ -77,6 +86,6 @@ gimme_arg(enum tof type, struct process * proc, int arg_num) {
return 0;
}
-void
-save_register_args(enum tof type, struct process * proc) {
+void save_register_args(enum tof type, struct process *proc)
+{
}
diff --git a/sysdeps/linux-gnu/ppc/plt.c b/sysdeps/linux-gnu/ppc/plt.c
index 9e2c094..19991b5 100644
--- a/sysdeps/linux-gnu/ppc/plt.c
+++ b/sysdeps/linux-gnu/ppc/plt.c
@@ -2,8 +2,7 @@
#include "ltrace.h"
#include "elf.h"
-GElf_Addr
-arch_plt_sym_val (struct ltelf *lte, size_t ndx, GElf_Rela *rela)
+GElf_Addr arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela)
{
- return rela->r_offset;
+ return rela->r_offset;
}
diff --git a/sysdeps/linux-gnu/ppc/regs.c b/sysdeps/linux-gnu/ppc/regs.c
index 9916750..d0d51e3 100644
--- a/sysdeps/linux-gnu/ppc/regs.c
+++ b/sysdeps/linux-gnu/ppc/regs.c
@@ -16,22 +16,22 @@
# define PTRACE_POKEUSER PTRACE_POKEUSR
#endif
-void *
-get_instruction_pointer(struct process * proc) {
- return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_NIP, 0);
+void *get_instruction_pointer(struct process *proc)
+{
+ return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_NIP, 0);
}
-void
-set_instruction_pointer(struct process * proc, void * addr) {
- ptrace(PTRACE_POKEUSER, proc->pid, 4*PT_NIP, addr);
+void set_instruction_pointer(struct process *proc, void *addr)
+{
+ ptrace(PTRACE_POKEUSER, proc->pid, 4 * PT_NIP, addr);
}
-void *
-get_stack_pointer(struct process * proc) {
- return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_R1, 0);
+void *get_stack_pointer(struct process *proc)
+{
+ return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_R1, 0);
}
-void *
-get_return_addr(struct process * proc, void * stack_pointer) {
- return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_LNK, 0);
+void *get_return_addr(struct process *proc, void *stack_pointer)
+{
+ return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_LNK, 0);
}
diff --git a/sysdeps/linux-gnu/ppc/trace.c b/sysdeps/linux-gnu/ppc/trace.c
index 22e1de6..6670be1 100644
--- a/sysdeps/linux-gnu/ppc/trace.c
+++ b/sysdeps/linux-gnu/ppc/trace.c
@@ -18,23 +18,25 @@
# define PTRACE_POKEUSER PTRACE_POKEUSR
#endif
-void
-get_arch_dep(struct process * proc) {
+void get_arch_dep(struct process *proc)
+{
}
/* Returns 1 if syscall, 2 if sysret, 0 otherwise.
*/
#define SYSCALL_INSN 0x44000002
-int
-syscall_p(struct process * proc, int status, int * sysnum) {
- if (WIFSTOPPED(status) && WSTOPSIG(status)==SIGTRAP) {
- int pc = ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_NIP, 0);
- int insn = ptrace(PTRACE_PEEKTEXT, proc->pid, pc-4, 0);
+int syscall_p(struct process *proc, int status, int *sysnum)
+{
+ if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
+ int pc = ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_NIP, 0);
+ int insn = ptrace(PTRACE_PEEKTEXT, proc->pid, pc - 4, 0);
if (insn == SYSCALL_INSN) {
- *sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_R0, 0);
- if (proc->callstack_depth > 0 &&
- proc->callstack[proc->callstack_depth-1].is_syscall) {
+ *sysnum =
+ ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_R0, 0);
+ if (proc->callstack_depth > 0
+ && proc->callstack[proc->callstack_depth -
+ 1].is_syscall) {
return 2;
}
return 1;
@@ -43,18 +45,20 @@ syscall_p(struct process * proc, int status, int * sysnum) {
return 0;
}
-long
-gimme_arg(enum tof type, struct process * proc, int arg_num) {
- if (arg_num==-1) { /* return value */
- return ptrace(PTRACE_PEEKUSER, proc->pid, 4*PT_R3, 0);
+long gimme_arg(enum tof type, struct process *proc, int arg_num)
+{
+ if (arg_num == -1) { /* return value */
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_R3, 0);
} else if (arg_num < 8) {
- return ptrace(PTRACE_PEEKUSER, proc->pid, 4*(arg_num+PT_R3), 0);
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 4 * (arg_num + PT_R3),
+ 0);
} else {
- return ptrace(PTRACE_PEEKDATA, proc->pid, proc->stack_pointer+8*(arg_num-8), 0);
+ return ptrace(PTRACE_PEEKDATA, proc->pid,
+ proc->stack_pointer + 8 * (arg_num - 8), 0);
}
return 0;
}
-void
-save_register_args(enum tof type, struct process * proc) {
+void save_register_args(enum tof type, struct process *proc)
+{
}
diff --git a/sysdeps/linux-gnu/proc.c b/sysdeps/linux-gnu/proc.c
index a5c18f6..201fb6d 100644
--- a/sysdeps/linux-gnu/proc.c
+++ b/sysdeps/linux-gnu/proc.c
@@ -13,21 +13,21 @@
* have a bit delay
*/
-#define MAX_DELAY 100000 /* 100000 microseconds = 0.1 seconds */
+#define MAX_DELAY 100000 /* 100000 microseconds = 0.1 seconds */
/*
* Returns a file name corresponding to a running pid
*/
-char *
-pid2name(pid_t pid) {
+char *pid2name(pid_t pid)
+{
char proc_exe[1024];
if (!kill(pid, 0)) {
- int delay=0;
+ int delay = 0;
sprintf(proc_exe, "/proc/%d/exe", pid);
- while(delay<MAX_DELAY) {
+ while (delay < MAX_DELAY) {
if (!access(proc_exe, F_OK)) {
return strdup(proc_exe);
}
diff --git a/sysdeps/linux-gnu/s390/plt.c b/sysdeps/linux-gnu/s390/plt.c
index df31b48..deb612e 100644
--- a/sysdeps/linux-gnu/s390/plt.c
+++ b/sysdeps/linux-gnu/s390/plt.c
@@ -2,8 +2,7 @@
#include "ltrace.h"
#include "elf.h"
-GElf_Addr
-arch_plt_sym_val (struct ltelf *lte, size_t ndx, GElf_Rela *rela)
+GElf_Addr arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela)
{
- return lte->plt_addr + (ndx + 1) * 32;
+ return lte->plt_addr + (ndx + 1) * 32;
}
diff --git a/sysdeps/linux-gnu/s390/regs.c b/sysdeps/linux-gnu/s390/regs.c
index 3dbf871..efba7f8 100644
--- a/sysdeps/linux-gnu/s390/regs.c
+++ b/sysdeps/linux-gnu/s390/regs.c
@@ -21,22 +21,24 @@
# define PTRACE_POKEUSER PTRACE_POKEUSR
#endif
-void *
-get_instruction_pointer(struct process * proc) {
- return (void *)(ptrace(PTRACE_PEEKUSER, proc->pid, PT_PSWADDR, 0) & 0x7fffffff);
+void *get_instruction_pointer(struct process *proc)
+{
+ return (void *)(ptrace(PTRACE_PEEKUSER, proc->pid, PT_PSWADDR, 0) &
+ 0x7fffffff);
}
-void
-set_instruction_pointer(struct process * proc, void * addr) {
+void set_instruction_pointer(struct process *proc, void *addr)
+{
ptrace(PTRACE_POKEUSER, proc->pid, PT_PSWADDR, addr);
}
-void *
-get_stack_pointer(struct process * proc) {
+void *get_stack_pointer(struct process *proc)
+{
return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR15, 0);
}
-void *
-get_return_addr(struct process * proc, void * stack_pointer) {
- return (void *)(ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR14, 0) & 0x7fffffff);
+void *get_return_addr(struct process *proc, void *stack_pointer)
+{
+ return (void *)(ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR14, 0) &
+ 0x7fffffff);
}
diff --git a/sysdeps/linux-gnu/s390/trace.c b/sysdeps/linux-gnu/s390/trace.c
index 21f82df..2208555 100644
--- a/sysdeps/linux-gnu/s390/trace.c
+++ b/sysdeps/linux-gnu/s390/trace.c
@@ -28,23 +28,24 @@
# define PTRACE_POKEUSER PTRACE_POKEUSR
#endif
-void
-get_arch_dep(struct process * proc) {
+void get_arch_dep(struct process *proc)
+{
}
/* Returns 1 if syscall, 2 if sysret, 0 otherwise.
*/
-int
-syscall_p(struct process * proc, int status, int * sysnum) {
+int syscall_p(struct process *proc, int status, int *sysnum)
+{
long pswa;
long svcinst;
long svcno;
long svcop;
- if (WIFSTOPPED(status) && WSTOPSIG(status)==SIGTRAP) {
+ if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
pswa = ptrace(PTRACE_PEEKUSER, proc->pid, PT_PSWADDR, 0);
- svcinst = ptrace(PTRACE_PEEKTEXT, proc->pid, (char *)(pswa-4),0);
+ svcinst =
+ ptrace(PTRACE_PEEKTEXT, proc->pid, (char *)(pswa - 4), 0);
svcop = (svcinst >> 8) & 0xFF;
svcno = svcinst & 0xFF;
@@ -57,16 +58,16 @@ syscall_p(struct process * proc, int status, int * sysnum) {
/* Breakpoint was hit... */
return 0;
}
- if (svcop == 10 && *sysnum>=0) {
+ if (svcop == 10 && *sysnum >= 0) {
/* System call was encountered... */
if (proc->callstack_depth > 0 &&
- proc->callstack[proc->callstack_depth-1].is_syscall) {
+ proc->callstack[proc->callstack_depth -
+ 1].is_syscall) {
return 2;
} else {
return 1;
}
- }
- else {
+ } else {
/* Unknown trap was encountered... */
return 0;
}
@@ -75,22 +76,27 @@ syscall_p(struct process * proc, int status, int * sysnum) {
return 0;
}
-long
-gimme_arg(enum tof type, struct process * proc, int arg_num) {
- switch(arg_num) {
- case -1: /* return value */
- return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR2, 0);
- case 0: return ptrace(PTRACE_PEEKUSER, proc->pid, PT_ORIGGPR2, 0);
- case 1: return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR3, 0);
- case 2: return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR4, 0);
- case 3: return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR5, 0);
- case 4: return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR6, 0);
- default:
- fprintf(stderr, "gimme_arg called with wrong arguments\n");
- exit(2);
+long gimme_arg(enum tof type, struct process *proc, int arg_num)
+{
+ switch (arg_num) {
+ case -1: /* return value */
+ return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR2, 0);
+ case 0:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, PT_ORIGGPR2, 0);
+ case 1:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR3, 0);
+ case 2:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR4, 0);
+ case 3:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR5, 0);
+ case 4:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, PT_GPR6, 0);
+ default:
+ fprintf(stderr, "gimme_arg called with wrong arguments\n");
+ exit(2);
}
}
-void
-save_register_args(enum tof type, struct process * proc) {
+void save_register_args(enum tof type, struct process *proc)
+{
}
diff --git a/sysdeps/linux-gnu/sparc/plt.c b/sysdeps/linux-gnu/sparc/plt.c
index 52b2208..5a2edac 100644
--- a/sysdeps/linux-gnu/sparc/plt.c
+++ b/sysdeps/linux-gnu/sparc/plt.c
@@ -2,8 +2,7 @@
#include "ltrace.h"
#include "elf.h"
-GElf_Addr
-arch_plt_sym_val (struct ltelf *lte, size_t ndx, GElf_Rela *rela)
+GElf_Addr arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela)
{
- return rela->r_offset + 4;
+ return rela->r_offset + 4;
}
diff --git a/sysdeps/linux-gnu/sparc/regs.c b/sysdeps/linux-gnu/sparc/regs.c
index 78efec3..1f2861a 100644
--- a/sysdeps/linux-gnu/sparc/regs.c
+++ b/sysdeps/linux-gnu/sparc/regs.c
@@ -6,32 +6,32 @@
#include "ptrace.h"
#include "ltrace.h"
-void *
-get_instruction_pointer(struct process * proc) {
- proc_archdep *a = (proc_archdep *)(proc->arch_ptr);
+void *get_instruction_pointer(struct process *proc)
+{
+ proc_archdep *a = (proc_archdep *) (proc->arch_ptr);
if (a->valid)
return (void *)a->regs.r_pc;
return (void *)-1;
}
-void
-set_instruction_pointer(struct process * proc, void * addr) {
- proc_archdep *a = (proc_archdep *)(proc->arch_ptr);
+void set_instruction_pointer(struct process *proc, void *addr)
+{
+ proc_archdep *a = (proc_archdep *) (proc->arch_ptr);
if (a->valid)
a->regs.r_pc = (long)addr;
}
-void *
-get_stack_pointer(struct process * proc) {
- proc_archdep *a = (proc_archdep *)(proc->arch_ptr);
+void *get_stack_pointer(struct process *proc)
+{
+ proc_archdep *a = (proc_archdep *) (proc->arch_ptr);
if (a->valid)
return (void *)a->regs.r_o6;
return (void *)-1;
}
-void *
-get_return_addr(struct process * proc, void * stack_pointer) {
- proc_archdep *a = (proc_archdep *)(proc->arch_ptr);
+void *get_return_addr(struct process *proc, void *stack_pointer)
+{
+ proc_archdep *a = (proc_archdep *) (proc->arch_ptr);
unsigned int t;
if (!a->valid)
return (void *)-1;
diff --git a/sysdeps/linux-gnu/sparc/trace.c b/sysdeps/linux-gnu/sparc/trace.c
index f88d503..1f407e5 100644
--- a/sysdeps/linux-gnu/sparc/trace.c
+++ b/sysdeps/linux-gnu/sparc/trace.c
@@ -18,8 +18,8 @@ void get_arch_dep(struct process *proc)
proc_archdep *a;
if (!proc->arch_ptr)
proc->arch_ptr = (void *)malloc(sizeof(proc_archdep));
- a = (proc_archdep *)(proc->arch_ptr);
- a->valid = (ptrace (PTRACE_GETREGS, proc->pid, &a->regs, 0) >= 0);
+ a = (proc_archdep *) (proc->arch_ptr);
+ a->valid = (ptrace(PTRACE_GETREGS, proc->pid, &a->regs, 0) >= 0);
}
/* Returns syscall number if `pid' stopped because of a syscall.
@@ -27,16 +27,19 @@ void get_arch_dep(struct process *proc)
*/
int syscall_p(struct process *proc, int status, int *sysnum)
{
- if (WIFSTOPPED(status) && WSTOPSIG(status)==SIGTRAP) {
+ if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
void *ip = get_instruction_pointer(proc);
unsigned int insn;
- if (ip == (void *)-1) return 0;
+ if (ip == (void *)-1)
+ return 0;
insn = ptrace(PTRACE_PEEKTEXT, proc->pid, ip, 0);
if ((insn & 0xc1f8007f) == 0x81d00010) {
- *sysnum = ((proc_archdep *)proc->arch_ptr)->regs.r_g1;
- if ((proc->callstack_depth > 0) && proc->callstack[proc->callstack_depth-1].is_syscall) {
+ *sysnum = ((proc_archdep *) proc->arch_ptr)->regs.r_g1;
+ if ((proc->callstack_depth > 0)
+ && proc->callstack[proc->callstack_depth -
+ 1].is_syscall) {
return 2;
- } else if(*sysnum>=0) {
+ } else if (*sysnum >= 0) {
return 1;
}
}
@@ -44,23 +47,24 @@ int syscall_p(struct process *proc, int status, int *sysnum)
return 0;
}
-long gimme_arg(enum tof type, struct process * proc, int arg_num)
+long gimme_arg(enum tof type, struct process *proc, int arg_num)
{
- proc_archdep * a = (proc_archdep *)proc->arch_ptr;
+ proc_archdep *a = (proc_archdep *) proc->arch_ptr;
if (!a->valid) {
fprintf(stderr, "Could not get child registers\n");
exit(1);
}
- if (arg_num==-1) /* return value */
+ if (arg_num == -1) /* return value */
return a->regs.r_o0;
- if (type==LT_TOF_FUNCTION || type==LT_TOF_SYSCALL || arg_num >= 6) {
+ if (type == LT_TOF_FUNCTION || type == LT_TOF_SYSCALL || arg_num >= 6) {
if (arg_num < 6)
return ((int *)&a->regs.r_o0)[arg_num];
- return ptrace(PTRACE_PEEKTEXT, proc->pid, proc->stack_pointer+64*(arg_num + 1));
- } else if (type==LT_TOF_FUNCTIONR)
+ return ptrace(PTRACE_PEEKTEXT, proc->pid,
+ proc->stack_pointer + 64 * (arg_num + 1));
+ } else if (type == LT_TOF_FUNCTIONR)
return a->func_arg[arg_num];
- else if (type==LT_TOF_SYSCALLR)
+ else if (type == LT_TOF_SYSCALLR)
return a->sysc_arg[arg_num];
else {
fprintf(stderr, "gimme_arg called with wrong arguments\n");
@@ -69,9 +73,9 @@ long gimme_arg(enum tof type, struct process * proc, int arg_num)
return 0;
}
-void save_register_args(enum tof type, struct process * proc)
+void save_register_args(enum tof type, struct process *proc)
{
- proc_archdep * a = (proc_archdep *)proc->arch_ptr;
+ proc_archdep *a = (proc_archdep *) proc->arch_ptr;
if (a->valid) {
if (type == LT_TOF_FUNCTION)
memcpy(a->func_arg, &a->regs.r_o0, sizeof(a->func_arg));
diff --git a/sysdeps/linux-gnu/trace.c b/sysdeps/linux-gnu/trace.c
index 8df75d0..81a154f 100644
--- a/sysdeps/linux-gnu/trace.c
+++ b/sysdeps/linux-gnu/trace.c
@@ -14,69 +14,70 @@
* (ie, with fork() or clone())
* Returns 0 otherwise.
*/
-int
-fork_p(int sysnum) {
+int fork_p(int sysnum)
+{
return 0
#if defined(__NR_fork)
- || (sysnum == __NR_fork)
+ || (sysnum == __NR_fork)
#endif
#if defined(__NR_clone)
- || (sysnum == __NR_clone)
+ || (sysnum == __NR_clone)
#endif
#if defined(__NR_vfork)
- || (sysnum == __NR_vfork)
+ || (sysnum == __NR_vfork)
#endif
- ;
+ ;
}
/* Returns 1 if the sysnum may make the process exec other program
*/
-int
-exec_p(int sysnum) {
+int exec_p(int sysnum)
+{
return (sysnum == __NR_execve);
}
-void
-trace_me(void) {
- if (ptrace(PTRACE_TRACEME, 0, 1, 0)<0) {
+void trace_me(void)
+{
+ if (ptrace(PTRACE_TRACEME, 0, 1, 0) < 0) {
perror("PTRACE_TRACEME");
exit(1);
}
}
-int
-trace_pid(pid_t pid) {
+int trace_pid(pid_t pid)
+{
if (ptrace(PTRACE_ATTACH, pid, 1, 0) < 0) {
return -1;
}
return 0;
}
-void
-untrace_pid(pid_t pid) {
+void untrace_pid(pid_t pid)
+{
ptrace(PTRACE_DETACH, pid, 1, 0);
}
-void
-continue_after_signal(pid_t pid, int signum) {
+void continue_after_signal(pid_t pid, int signum)
+{
/* We should always trace syscalls to be able to control fork(), clone(), execve()... */
ptrace(PTRACE_SYSCALL, pid, 0, signum);
}
-void
-continue_process(pid_t pid) {
+void continue_process(pid_t pid)
+{
continue_after_signal(pid, 0);
}
-void
-continue_enabling_breakpoint(pid_t pid, struct breakpoint * sbp) {
+void continue_enabling_breakpoint(pid_t pid, struct breakpoint *sbp)
+{
enable_breakpoint(pid, sbp);
continue_process(pid);
}
-void
-continue_after_breakpoint(struct process *proc, struct breakpoint * sbp) {
- if (sbp->enabled) disable_breakpoint(proc->pid, sbp);
+void continue_after_breakpoint(struct process *proc, struct breakpoint *sbp)
+{
+ if (sbp->enabled)
+ disable_breakpoint(proc->pid, sbp);
set_instruction_pointer(proc, sbp->addr);
if (sbp->enabled == 0) {
continue_process(proc->pid);
@@ -90,24 +91,27 @@ continue_after_breakpoint(struct process *proc, struct breakpoint * sbp) {
}
}
-int
-umovestr(struct process * proc, void * addr, int len, void * laddr) {
- union { long a; char c[sizeof(long)]; } a;
+int umovestr(struct process *proc, void *addr, int len, void *laddr)
+{
+ union {
+ long a;
+ char c[sizeof(long)];
+ } a;
int i;
- int offset=0;
+ int offset = 0;
- while(offset<len) {
- a.a = ptrace(PTRACE_PEEKTEXT, proc->pid, addr+offset, 0);
- for(i=0; i<sizeof(long); i++) {
- if (a.c[i] && offset+i < len) {
- *(char *)(laddr+offset+i) = a.c[i];
+ while (offset < len) {
+ a.a = ptrace(PTRACE_PEEKTEXT, proc->pid, addr + offset, 0);
+ for (i = 0; i < sizeof(long); i++) {
+ if (a.c[i] && offset + i < len) {
+ *(char *)(laddr + offset + i) = a.c[i];
} else {
- *(char *)(laddr+offset+i) = '\0';
+ *(char *)(laddr + offset + i) = '\0';
return 0;
}
}
offset += sizeof(long);
}
- *(char *)(laddr+offset) = '\0';
+ *(char *)(laddr + offset) = '\0';
return 0;
}
diff --git a/sysdeps/linux-gnu/x86_64/plt.c b/sysdeps/linux-gnu/x86_64/plt.c
index e40b03a..939bc4e 100644
--- a/sysdeps/linux-gnu/x86_64/plt.c
+++ b/sysdeps/linux-gnu/x86_64/plt.c
@@ -2,8 +2,7 @@
#include "ltrace.h"
#include "elf.h"
-GElf_Addr
-arch_plt_sym_val (struct ltelf *lte, size_t ndx, GElf_Rela *rela)
+GElf_Addr arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela)
{
- return lte->plt_addr + (ndx + 1) * 16;
+ return lte->plt_addr + (ndx + 1) * 16;
}
diff --git a/sysdeps/linux-gnu/x86_64/regs.c b/sysdeps/linux-gnu/x86_64/regs.c
index 176a894..a2a27a9 100644
--- a/sysdeps/linux-gnu/x86_64/regs.c
+++ b/sysdeps/linux-gnu/x86_64/regs.c
@@ -16,22 +16,22 @@
# define PTRACE_POKEUSER PTRACE_POKEUSR
#endif
-void *
-get_instruction_pointer(struct process * proc) {
- return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 8*RIP, 0);
+void *get_instruction_pointer(struct process *proc)
+{
+ return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 8 * RIP, 0);
}
-void
-set_instruction_pointer(struct process * proc, void * addr) {
- ptrace(PTRACE_POKEUSER, proc->pid, 8*RIP, addr);
+void set_instruction_pointer(struct process *proc, void *addr)
+{
+ ptrace(PTRACE_POKEUSER, proc->pid, 8 * RIP, addr);
}
-void *
-get_stack_pointer(struct process * proc) {
- return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 8*RSP, 0);
+void *get_stack_pointer(struct process *proc)
+{
+ return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 8 * RSP, 0);
}
-void *
-get_return_addr(struct process * proc, void * stack_pointer) {
+void *get_return_addr(struct process *proc, void *stack_pointer)
+{
return (void *)ptrace(PTRACE_PEEKTEXT, proc->pid, stack_pointer, 0);
}
diff --git a/sysdeps/linux-gnu/x86_64/trace.c b/sysdeps/linux-gnu/x86_64/trace.c
index 46db01d..3232afd 100644
--- a/sysdeps/linux-gnu/x86_64/trace.c
+++ b/sysdeps/linux-gnu/x86_64/trace.c
@@ -25,54 +25,69 @@ void get_arch_dep(struct process *proc)
/* Returns 1 if syscall, 2 if sysret, 0 otherwise.
*/
-int
-syscall_p(struct process * proc, int status, int * sysnum) {
- if (WIFSTOPPED(status) && WSTOPSIG(status)==SIGTRAP) {
- *sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 8*ORIG_RAX, 0);
+int syscall_p(struct process *proc, int status, int *sysnum)
+{
+ if (WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP) {
+ *sysnum = ptrace(PTRACE_PEEKUSER, proc->pid, 8 * ORIG_RAX, 0);
if (proc->callstack_depth > 0 &&
- proc->callstack[proc->callstack_depth-1].is_syscall) {
+ proc->callstack[proc->callstack_depth - 1].is_syscall) {
return 2;
}
- if (*sysnum>=0) {
+ if (*sysnum >= 0) {
return 1;
}
}
return 0;
}
-long
-gimme_arg(enum tof type, struct process * proc, int arg_num) {
- if (arg_num==-1) { /* return value */
- return ptrace(PTRACE_PEEKUSER, proc->pid, 8*RAX, 0);
+long gimme_arg(enum tof type, struct process *proc, int arg_num)
+{
+ if (arg_num == -1) { /* return value */
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 8 * RAX, 0);
}
- if (type==LT_TOF_FUNCTION || type==LT_TOF_FUNCTIONR) {
- switch(arg_num) {
- case 0: return ptrace(PTRACE_PEEKUSER, proc->pid, 8*RDI, 0);
- case 1: return ptrace(PTRACE_PEEKUSER, proc->pid, 8*RSI, 0);
- case 2: return ptrace(PTRACE_PEEKUSER, proc->pid, 8*RDX, 0);
- case 3: return ptrace(PTRACE_PEEKUSER, proc->pid, 8*RCX, 0);
- case 4: return ptrace(PTRACE_PEEKUSER, proc->pid, 8*R8, 0);
- case 5: return ptrace(PTRACE_PEEKUSER, proc->pid, 8*R9, 0);
- default:
- return ptrace(PTRACE_PEEKTEXT, proc->pid,
- proc->stack_pointer + 8 * (arg_num - 6 + 1), 0);
- fprintf(stderr, "gimme_arg called with wrong arguments\n");
- exit(2);
+ if (type == LT_TOF_FUNCTION || type == LT_TOF_FUNCTIONR) {
+ switch (arg_num) {
+ case 0:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 8 * RDI, 0);
+ case 1:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 8 * RSI, 0);
+ case 2:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 8 * RDX, 0);
+ case 3:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 8 * RCX, 0);
+ case 4:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 8 * R8, 0);
+ case 5:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 8 * R9, 0);
+ default:
+ return ptrace(PTRACE_PEEKTEXT, proc->pid,
+ proc->stack_pointer + 8 * (arg_num - 6 +
+ 1), 0);
+ fprintf(stderr,
+ "gimme_arg called with wrong arguments\n");
+ exit(2);
}
- } else if (type==LT_TOF_SYSCALL || LT_TOF_SYSCALLR) {
- switch(arg_num) {
- case 0: return ptrace(PTRACE_PEEKUSER, proc->pid, 8*RDI, 0);
- case 1: return ptrace(PTRACE_PEEKUSER, proc->pid, 8*RSI, 0);
- case 2: return ptrace(PTRACE_PEEKUSER, proc->pid, 8*RDX, 0);
- case 3: return ptrace(PTRACE_PEEKUSER, proc->pid, 8*R10, 0);
- case 4: return ptrace(PTRACE_PEEKUSER, proc->pid, 8*R8, 0);
- case 5: return ptrace(PTRACE_PEEKUSER, proc->pid, 8*R9, 0);
- default:
- fprintf(stderr, "gimme_arg called with wrong arguments\n");
- exit(2);
+ } else if (type == LT_TOF_SYSCALL || LT_TOF_SYSCALLR) {
+ switch (arg_num) {
+ case 0:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 8 * RDI, 0);
+ case 1:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 8 * RSI, 0);
+ case 2:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 8 * RDX, 0);
+ case 3:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 8 * R10, 0);
+ case 4:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 8 * R8, 0);
+ case 5:
+ return ptrace(PTRACE_PEEKUSER, proc->pid, 8 * R9, 0);
+ default:
+ fprintf(stderr,
+ "gimme_arg called with wrong arguments\n");
+ exit(2);
}
} else {
fprintf(stderr, "gimme_arg called with wrong arguments\n");
@@ -82,6 +97,6 @@ gimme_arg(enum tof type, struct process * proc, int arg_num) {
return 0;
}
-void save_register_args(enum tof type, struct process * proc)
+void save_register_args(enum tof type, struct process *proc)
{
}
diff --git a/wait_for_something.c b/wait_for_something.c
index 363782b..e24ee95 100644
--- a/wait_for_something.c
+++ b/wait_for_something.c
@@ -18,10 +18,10 @@ static struct event event;
/* This should also update `current_process' */
-static struct process * pid2proc(int pid);
+static struct process *pid2proc(int pid);
-struct event *
-wait_for_something(void) {
+struct event *wait_for_something(void)
+{
pid_t pid;
int status;
int tmp;
@@ -31,11 +31,11 @@ wait_for_something(void) {
exit(0);
}
pid = wait(&status);
- if (pid==-1) {
- if (errno==ECHILD) {
+ if (pid == -1) {
+ if (errno == ECHILD) {
debug(1, "No more children");
exit(0);
- } else if (errno==EINTR) {
+ } else if (errno == EINTR) {
debug(1, "wait received EINTR ?");
event.thing = LT_EV_NONE;
return &event;
@@ -58,15 +58,18 @@ wait_for_something(void) {
return &event;
}
if (opt_i) {
- event.proc->instruction_pointer = get_instruction_pointer(event.proc);
+ event.proc->instruction_pointer =
+ get_instruction_pointer(event.proc);
}
- switch(syscall_p(event.proc, status, &tmp)) {
- case 1: event.thing = LT_EV_SYSCALL;
- event.e_un.sysnum = tmp;
- return &event;
- case 2: event.thing = LT_EV_SYSRET;
- event.e_un.sysnum = tmp;
- return &event;
+ switch (syscall_p(event.proc, status, &tmp)) {
+ case 1:
+ event.thing = LT_EV_SYSCALL;
+ event.e_un.sysnum = tmp;
+ return &event;
+ case 2:
+ event.thing = LT_EV_SYSRET;
+ event.e_un.sysnum = tmp;
+ return &event;
}
if (WIFEXITED(status)) {
event.thing = LT_EV_EXIT;
@@ -89,18 +92,20 @@ wait_for_something(void) {
}
event.thing = LT_EV_BREAKPOINT;
if (!event.proc->instruction_pointer) {
- event.proc->instruction_pointer = get_instruction_pointer(event.proc);
+ event.proc->instruction_pointer =
+ get_instruction_pointer(event.proc);
}
- event.e_un.brk_addr = event.proc->instruction_pointer - DECR_PC_AFTER_BREAK;
+ event.e_un.brk_addr =
+ event.proc->instruction_pointer - DECR_PC_AFTER_BREAK;
return &event;
}
-static struct process *
-pid2proc(pid_t pid) {
- struct process * tmp;
+static struct process *pid2proc(pid_t pid)
+{
+ struct process *tmp;
tmp = list_of_processes;
- while(tmp) {
+ while (tmp) {
if (pid == tmp->pid) {
return tmp;
}