Some fixes...
* read_config_file.c: initialise pt stack argument to stop warning
* summary.c: make show_summary() obey -C for demangaling function names
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 @@
/* 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 @@
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;
+ 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];
+ 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 @@
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 @@
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 @@
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 @@
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 @@
/* 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 @@
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 @@
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 @@
*/
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 @@
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 @@
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 @@
}
}
-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 @@
/* 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 @@
return 0;
}
-void save_register_args(enum tof type, struct process * proc)
+void save_register_args(enum tof type, struct process *proc)
{
}