[Ltrace-devel] Re: [Fwd: Patch for tracing fork]
supriya kannery
supriyak at in.ibm.com
Tue Oct 3 07:56:06 UTC 2006
supriya kannery wrote:
> Ian Wienand wrote:
>
>> On Fri, Sep 22, 2006 at 02:48:23PM +0530, supriya kannery wrote:
>>
>>
>>> Could you please comment on this patch. Please let me know if I
>>> need to make more changes into this or whether this could be
>>> considered for mainline.
>>>
>>
>>
>> Hi,
>>
>> I get a regression for at least IA64 with this patch; the test case
>> fails. However there was issues when applying the patch.
>>
>> Can you update it against the current subversion head for me and I'll
>> try again. Also, I don't see this problem generally, is it only an
>> issue on your architectures?
>>
>> -i
>>
>>
> Ian,
> Thanks! for your comments. I got trunk-68 downloaded. Since this
> level has got recent code changes related to
> breakpoints, few more changes need to be done to fork-patch inorder
> to include "PTRACE_O_TRACEFORK"
> option. I will do more analysis and send the upgraded patch.
> Yes, missing to trace some of the initial library calls in the child
> process, was observed in ppc
> and s390x architectures. This was not observed in i386.
>
>
> _______________________________________________
> Ltrace-devel mailing list
> Ltrace-devel at lists.alioth.debian.org
> http://lists.alioth.debian.org/mailman/listinfo/ltrace-devel
Ian,
Pls find the upgraded patch for tracing fork. This is prepared over
trunk-68 level and tested in x86_64 and ppc architectures. Please comment.
Thanks & Rgds, Supriya
-------------- next part --------------
diff -Naurp trunk/ltrace.c trunk-mod/ltrace.c
--- trunk/ltrace.c 2006-10-03 11:57:18.000000000 +0530
+++ trunk-mod/ltrace.c 2006-10-03 12:03:34.000000000 +0530
@@ -97,6 +97,8 @@ int main(int argc, char **argv)
struct opt_p_t *opt_p_tmp;
atexit(normal_exit);
+ int options = 0;
+
signal(SIGINT, signal_exit); /* Detach processes when interrupted */
signal(SIGTERM, signal_exit); /* ... or killed */
@@ -133,7 +135,8 @@ int main(int argc, char **argv)
}
opt_p_tmp = opt_p;
while (opt_p_tmp) {
- open_pid(opt_p_tmp->pid, 1);
+ options = P_OPTION_SET | VERBOSE;
+ open_pid(opt_p_tmp->pid, options);
opt_p_tmp = opt_p_tmp->next;
}
while (1) {
diff -Naurp trunk/ltrace.h trunk-mod/ltrace.h
--- trunk/ltrace.h 2006-10-03 11:57:22.000000000 +0530
+++ trunk-mod/ltrace.h 2006-10-03 12:03:42.000000000 +0530
@@ -12,6 +12,10 @@
#include "sysdep.h"
#define MAX_LIBRARY 30
+#define TRACE_FORK 1
+#define VERBOSE 0x00000001
+#define P_OPTION_SET 0x00000002
+
#if defined HAVE_LIBIBERTY || defined HAVE_LIBSUPC__
# define USE_DEMANGLE
@@ -229,7 +233,7 @@ extern arg_type_info *lookup_prototype(e
/* Arch-dependent stuff: */
extern char *pid2name(pid_t pid);
-extern void trace_set_options(struct process *proc, pid_t pid);
+extern void trace_set_options(struct process *proc, pid_t pid, int option);
extern void trace_me(void);
extern int trace_pid(pid_t pid);
extern void untrace_pid(pid_t pid);
@@ -258,5 +262,5 @@ extern void *sym2addr(struct process *,
#if 0 /* not yet */
extern int umoven(struct process *proc, void *addr, int len, void *laddr);
#endif
-
+extern ulong get_child_pid(pid_t pid);
#endif
diff -Naurp trunk/proc.c trunk-mod/proc.c
--- trunk/proc.c 2006-10-03 11:56:33.000000000 +0530
+++ trunk-mod/proc.c 2006-10-03 12:03:16.000000000 +0530
@@ -22,25 +22,28 @@ struct process *open_program(char *filen
}
proc->filename = filename;
proc->breakpoints_enabled = -1;
+ proc->pid = 0;
+ breakpoints_init(proc);
if (pid) {
proc->pid = pid;
}
- breakpoints_init(proc);
-
proc->next = list_of_processes;
list_of_processes = proc;
return proc;
}
-void open_pid(pid_t pid, int verbose)
+void open_pid(pid_t pid, int options)
+
{
struct process *proc;
char *filename;
- if (trace_pid(pid) < 0) {
- fprintf(stderr, "Cannot attach to pid %u: %s\n", pid,
+ if(options & P_OPTION_SET){
+ if ((trace_pid(pid) < 0) && (options & VERBOSE)){
+ fprintf(stderr, "Cannot attach to pid %u: %s\n", pid,
strerror(errno));
- return;
+ return;
+ }
}
filename = pid2name(pid);
@@ -56,5 +59,5 @@ void open_pid(pid_t pid, int verbose)
#endif
proc = open_program(filename, pid);
- proc->breakpoints_enabled = 1;
+ proc->breakpoints_enabled = -1;
}
diff -Naurp trunk/process_event.c trunk-mod/process_event.c
--- trunk/process_event.c 2006-10-03 11:57:33.000000000 +0530
+++ trunk-mod/process_event.c 2006-10-03 12:03:52.000000000 +0530
@@ -223,19 +223,6 @@ static void process_sysret(struct event
if (opt_T || opt_c) {
calc_time_spent(event->proc);
}
- if (fork_p(event->proc, event->e_un.sysnum)) {
- if (opt_f) {
- arg_type_info info;
- info.arg_num = -1; /* Return value */
- info.type = ARGTYPE_LONG;
- pid_t child =
- gimme_arg(LT_TOF_SYSCALLR, event->proc, &info);
- if (child > 0) {
- open_pid(child, 0);
- }
- }
- enable_all_breakpoints(event->proc);
- }
callstack_pop(event->proc);
if (opt_S) {
output_right(LT_TOF_SYSCALLR, event->proc,
diff -Naurp trunk/sysdeps/linux-gnu/trace.c trunk-mod/sysdeps/linux-gnu/trace.c
--- trunk/sysdeps/linux-gnu/trace.c 2006-10-03 11:58:36.000000000 +0530
+++ trunk-mod/sysdeps/linux-gnu/trace.c 2006-10-03 12:05:15.000000000 +0530
@@ -90,7 +90,7 @@ int trace_pid(pid_t pid)
return 0;
}
-void trace_set_options(struct process *proc, pid_t pid)
+void trace_set_options(struct process *proc, pid_t pid, int option)
{
#ifndef PTRACE_SETOPTIONS
#define PTRACE_SETOPTIONS 0x4200
@@ -101,9 +101,20 @@ void trace_set_options(struct process *p
#ifndef PTRACE_O_TRACESYSGOOD
#define PTRACE_O_TRACESYSGOOD 0x00000001
#endif
+#ifndef PTRACE_O_TRACEFORK
+#define PTRACE_O_TRACEFORK 0x00000002
+#endif
+
+ ulong setoptions = 0;
+
if (proc->tracesysgood & 0x80)
return;
- if (ptrace(PTRACE_SETOPTIONS, pid, 0, PTRACE_O_TRACESYSGOOD) < 0 &&
+
+ setoptions |= PTRACE_O_TRACESYSGOOD;
+ if (TRACE_FORK == option){
+ setoptions |= PTRACE_O_TRACEFORK;
+ }
+ if (ptrace(PTRACE_SETOPTIONS, pid, 0, setoptions) < 0 &&
ptrace(PTRACE_OLDSETOPTIONS, pid, 0, PTRACE_O_TRACESYSGOOD) < 0) {
perror("PTRACE_SETOPTIONS");
return;
@@ -193,3 +204,19 @@ int umovestr(struct process *proc, void
*(char *)(laddr + offset) = '\0';
return 0;
}
+
+ulong get_child_pid(pid_t pid)
+{
+#ifndef PTRACE_GETEVENTMSG
+#define PTRACE_GETEVENTMSG 0x4201
+#endif
+ ulong child_pid = 9999;
+
+ if( ptrace(PTRACE_GETEVENTMSG, pid, 0, &child_pid) < 0) {
+ perror("PTRACE_GETEVENTMSG");
+ return 0;
+ }
+ return child_pid;
+}
+
+
diff -Naurp trunk/wait_for_something.c trunk-mod/wait_for_something.c
--- trunk/wait_for_something.c 2006-10-03 11:57:06.000000000 +0530
+++ trunk-mod/wait_for_something.c 2006-10-03 12:09:56.000000000 +0530
@@ -14,6 +14,7 @@
#include "options.h"
#include "debug.h"
+#define FORK_MASK 0x00010000
static struct event event;
/* This should also update `current_process' */
@@ -22,7 +23,7 @@ static struct process *pid2proc(int pid)
struct event *wait_for_something(void)
{
- pid_t pid;
+ pid_t pid, child_pid;
int status;
int tmp;
@@ -52,9 +53,18 @@ struct event *wait_for_something(void)
event.proc->instruction_pointer = NULL;
debug(3, "signal from pid %u", pid);
if (event.proc->breakpoints_enabled == -1) {
+#ifdef PLT_REINITALISATION_BP
+ reinitialize_breakpoints(event.proc);
+ event.proc->breakpoints_enabled = 1;
+#else
enable_all_breakpoints(event.proc);
+#endif
event.thing = LT_EV_NONE;
- trace_set_options(event.proc, event.proc->pid);
+ if(opt_f){
+ trace_set_options(event.proc, event.proc->pid, TRACE_FORK);
+ }else{
+ trace_set_options(event.proc, event.proc->pid, 0);
+ }
continue_process(event.proc->pid);
return &event;
}
@@ -92,6 +102,18 @@ struct event *wait_for_something(void)
event.e_un.signum = WSTOPSIG(status);
return &event;
}
+ if((WSTOPSIG(status) == SIGTRAP) && (status & FORK_MASK)) {
+ event.thing = LT_EV_NONE;
+ event.e_un.signum = WSTOPSIG(status);
+ child_pid = (pid_t) get_child_pid(event.proc->pid);
+ if (child_pid){
+ open_pid(child_pid,0);
+ }
+ enable_all_breakpoints(event.proc);
+ continue_after_signal(event.proc->pid, event.e_un.signum);
+ return &event;
+ }
+
event.thing = LT_EV_BREAKPOINT;
if (!event.proc->instruction_pointer) {
event.proc->instruction_pointer =
More information about the Ltrace-devel
mailing list