Mark Seaborn | 26 Jan 21:11

[PATCH] Add -i option for displaying the instruction pointer

Here's a patch to add the -i option that the regular strace supports.

A minor problem is that it doesn't work on the exit_group() syscall.

diff --git a/strace.py b/strace.py
index 9de9213..eec013e 100755
--- a/strace.py
+++ b/strace.py
@@ -62,6 +62,8 @@ class SyscallTracer(Application):
             action="store_true", default=False)
         parser.add_option("--list-syscalls", help="Display system calls and exit",
             action="store_true", default=False)
+        parser.add_option("-i", help="print instruction pointer at time of syscall",
+            action="store_true", default=False, dest="show_ip")

         self.createLogOptions(parser)

@@ -136,8 +138,10 @@ class SyscallTracer(Application):
         text = syscall.format()
         if syscall.result is not None:
             text = "%-40s = %s" % (text, syscall.result_text)
+        if self.options.show_ip:
+            text = "[%x] %s" % (syscall.process.getInstrPointer(), text)
         if self.options.show_pid:
-            text = "[%s] %s" % (syscall.process.pid, text)
+            text = "[pid %s] %s" % (syscall.process.pid, text)
         error(text)

     def syscallTrace(self, process):

(Continue reading)

Victor Stinner | 26 Jan 22:51

Re: [PATCH] Add -i option for displaying the instruction pointer

Hi,

Le Monday 26 January 2009 21:11:58 Mark Seaborn, vous avez écrit :
> Here's a patch to add the -i option that the regular strace supports.

Oh, cool, a new contribution to python-ptrace ;-)

> A minor problem is that it doesn't work on the exit_group() syscall.

I choosed to read the instruction pointer in PtraceSyscall instead of 
strace.py directly.

>          if self.options.show_pid:
> -            text = "[%s] %s" % (syscall.process.pid, text)
> +            text = "[pid %s] %s" % (syscall.process.pid, text)
>          error(text)

Why did you add "pid " prefix? I prefer to keep a short prefix. So it now 
looks like (show ip and pid):

[16166][0xffffe410] close(1)                                 = 0
[16166][0xffffe410] munmap(0xb7ccb000, 4096)                 = 0
[16166][0xffffe410] exit_group(0)

or (show only pid)

[16172] close(1)                                 = 0
[16172] munmap(0xb7cc9000, 4096)                 = 0
[16172] exit_group(0)

(Continue reading)

Mark Seaborn | 27 Jan 19:49

Re: [PATCH] Add -i option for displaying the instruction pointer

Victor Stinner <victor.stinner@...> wrote:

> >          if self.options.show_pid:
> > -            text = "[%s] %s" % (syscall.process.pid, text)
> > +            text = "[pid %s] %s" % (syscall.process.pid, text)
> >          error(text)
>
> Why did you add "pid " prefix?  I prefer to keep a short prefix.

To distinguish it from the instruction pointer and for consistency
with regular strace.  But I don't have a strong preference.

Cheers,
Mark

Mark Seaborn | 26 Jan 22:14

[PATCH] itrace tool

python-ptrace is a useful library - thanks for writing it!

Here is a tool which I have been using to debug libc startup code
where I didn't find gdb very helpful.  It single steps the process and
prints each instruction pointer address.  To go faster, it allows a
number of syscalls to run before starting single-stepping.

It's possible to pipe the addresses through addr2line to get a very
simple tracing debugger. :-)

I couldn't see a way to catch syscalls and single step at the same
time.  As a consequence the tool can't handle multiple threads.

Mark

diff --git a/itrace.py b/itrace.py
new file mode 100755
index 0000000..ce15e9d
--- /dev/null
+++ b/itrace.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+
+import signal
+
+from ptrace.debugger import (PtraceDebugger, Application,
+    ProcessExit, ProcessSignal, NewProcessEvent, ProcessExecution)
+import strace
+
+
(Continue reading)

Victor Stinner | 26 Jan 23:07

Re: [PATCH] itrace tool

Hi,

Le Monday 26 January 2009 22:14:35 Mark Seaborn, vous avez écrit :
> python-ptrace is a useful library - thanks for writing it!

You're welcome.

> Here is a tool which I have been using to debug libc startup code
> where I didn't find gdb very helpful.

Wow. Are you debugging the libc??

> It single steps the process and prints each instruction pointer address.  
> To go faster, it allows a number of syscalls to run before 
> starting single-stepping. 

With no option, your script "skip" all syscalls (just print a counter). Is it 
the expected behaviour?

I don't think that this script would be reused by anyone else, but who knows? 
So I pushed it into examples/itrace.py with your email as the documentation.

> It's possible to pipe the addresses through addr2line to get a very
> simple tracing debugger. :-)

Yeah, but it would be easier to integrate addr2line (or anything else) 
directly into python-ptrace. A friend told me that he wrote an ELF parser in 
Python. We can maybe reuse it... or libbfd, or elfsh, or ...

I'm prefer to work on Fusil than on python-ptrace. Current status of 
(Continue reading)

Mark Seaborn | 27 Jan 20:21

Re: [PATCH] itrace tool

Victor Stinner <victor.stinner@...> wrote:

> > Here is a tool which I have been using to debug libc startup code
> > where I didn't find gdb very helpful.
> 
> Wow. Are you debugging the libc??

I'm porting glibc to Google Native Client (NaCl) [1].

> > It single steps the process and prints each instruction pointer address.  
> > To go faster, it allows a number of syscalls to run before 
> > starting single-stepping. 
>
> With no option, your script "skip" all syscalls (just print a
> counter). Is it the expected behaviour?

Yes.  The use case was that I run it once to see how many syscalls it
does before segfaulting, and then run it again with the syscall limit.
Obviously this could be automated.  Initially I just changed strace.py
directly; itrace.py is a tidied up version of those changes.

> I don't think that this script would be reused by anyone else, but
> who knows? So I pushed it into examples/itrace.py with your email as
> the documentation.

Thanks.

> > It's possible to pipe the addresses through addr2line to get a very
> > simple tracing debugger. :-)
> 
(Continue reading)


Gmane