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)
> 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)
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
+
+
RSS Feed