Arun Sharma wrote:
Kyle Galloway wrote:
The error message in there is mine, but unw_step returns -8 after the
second frame, which I think is UNW_EINVAL. As can be seen, these
results don't make much sense. There should definitely be more than
one frame, and I'm not getting step errors when tracing the main
thread. This code works fine if I try to trace the main thread on
both architectures with or without the second ptrace call for the
second thread.
Any ideas?
Hi Kyle,
It'd help quite a bit if you post a minimal program to reproduce and a
debug log after configuring with --enable-debug and
UNW_DEBUG_LEVEL=<sufficiently high number>
-Arun
I wrote a simple app that just traces the second thread of some
process. I have attached it, it builds by:
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"minimal.d"
-MT"minimal.d" -o"minimal.o" "minimal.c"
gcc -o"unwinddebug" ./minimal.o -lunwind -lunwind-ptrace
-lunwind-generic
I have also rebuilt libunwind with --enable-debug UNW_DEBUG_LEVEL=16.
Am I correct that to do this I run configure with "./configure
--enable-debug UNW_DEBUG_LEVEL=16", because this gives me no output.
Here is the result on x86_64
Enter the PID of the main therad: 20294
Assuming second thread is pid 20295
Tracing main thread!
Frames of pid 20294:
found frame 0
found frame 1
found frame 2
found frame 3
found frame 4
found frame 5
Trace Depth = 6
Tracing second thread!
Frames of pid 20295:
found frame 0
Trace Depth = 1
And on x86
Enter the PID of the main therad: 9269
Assuming second thread is pid 9270
Tracing main thread!
Frames of pid 9269:
found frame 0
found frame 1
found frame 2
found frame 3
found frame 4
found frame 5
found frame 6
found frame 7
found frame 8
found frame 9
found frame 10
found frame 11
Trace Depth = 12
Tracing second thread!
Frames of pid 9270:
found frame 0
found frame 1
Step Error: -8
Trace Depth = 2
As I mentioned, I didn't get any debug output, did I do something wrong
trying to set that up?
Thanks,
Kyle
#include <libunwind.h>
#include <libunwind-ptrace.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
int main()
{
pid_t pid;
printf("Enter the PID of the main therad: ");
scanf("%ld", &pid);
printf("Assuming second thread is pid %ld\n", (pid+1));
int error = ptrace(PTRACE_ATTACH, pid, (void *) 0, (void *) 0);
if(error != 0)
printf("Ptrace attach main error: %d\n", error);
waitpid(pid, NULL, __WALL);
error = ptrace(PTRACE_ATTACH, (pid+1), (void *) 0, (void *) 0);
if(error != 0)
printf("Ptrace attach thread 2 error: %d\n", error);
waitpid(pid+1, NULL, __WALL);
printf("Tracing main thread!\n");
trace(pid);
printf("Tracing second thread!\n");
trace(pid+1);
error = ptrace(PTRACE_DETACH, (pid+1), (void *) 0, (void *) 0);
if (error != 0)
printf ("Ptrace detach second thread error: %d\n", error);
error = ptrace(PTRACE_DETACH, (pid), (void *) 0, (void *) 0);
if (error != 0)
printf ("Ptrace detach main thread error: %d\n", error);
}
void trace(pid_t pid)
{
int count = 0;
unw_addr_space_t uwas = unw_create_addr_space (&_UPT_accessors, 0);
if (uwas == NULL)
printf ("uwas == NULL\n");
void *arg3 = _UPT_create(pid);
if(arg3 == NULL)
printf ("arg3 == NULL\n");
unw_cursor_t cur;
int error = unw_init_remote(&cur, uwas, arg3);
if(error != 0)
printf ("InitRemote Error: %d\n", error);
printf ("Frames of pid %d: \n\n", pid);
do{
printf("found frame %d\n", count);
count++;
error = unw_step (&cur);
if (error < 0)
printf ("Step Error: %d\n", error);
}while (error > 0);
printf("\nTrace Depth = %d\n\n", count);
_UPT_destroy(arg3);
unw_destroy_addr_space(uwas);
}
_______________________________________________
Libunwind-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/libunwind-devel