[lldb-dev] thread debugging
Michael Sartain
mikesart at gmail.com
Fri Sep 6 11:32:12 PDT 2013
These situations came up in a separate conversation with Ed Maste, and I'm
e-mailing to get thoughts on what the expected behavior would be.
This is all done with clang 3.3 on Ubuntu 12.04 x64. Code here:
https://gist.github.com/mikesart/6467648
For case #1, I set a breakpoint on the final printf() statement, hit run,
and everything runs like I'd expect.
For case #2, I set a breakpoint on the sleep call in the threadproc, and
the sleep call in main.
- When it hits the breakpoint in threadproc, it also seems to hit some
thread spawned breakpoint at the same time. Is this expected? We don't see
anything about this breakpoint in the first run.
- When I type "n", it looks like we hit two breakpoints again at the same
time - the one in main and the one in threadproc. This also seems a bit
confusing. Which thread am I on? I don't believe I've ever used a debugger
that shows two breakpoints being hit at the same time before. Would it make
sense to queue them up and show them one at a time?
Thanks.
-Mike
#
# Case 1: breakpoint on last statement in app
#
mikesart at mikesart64:~/data/src/blah/build64$ lldb -- pthreads
Current executable set to 'pthreads' (x86_64).
(lldb) # set breakpoint on last printf statement in test app
(lldb) b 122
Breakpoint 1: where = pthreads`main + 611 at pthreads.cpp:122, address =
0x00000000004010b3
(lldb) r
Process 13815 launched: '/home/mikesart/data/src/blah/build64/pthreads'
(x86_64)
num_threads:2
'mainthrd' [#-1 LWP:-1 0x7fc8fba1a740] pthread_create:0 (Success)
pthread_t:7fc8fa82c700
'thread_0' [#0 LWP:-1 0x7fc8fa82c700] pthread_setname_np('thread_0')
'thread_0' [#0 LWP:-1 0x7fc8fa82c700] sleep(5)
'mainthrd' [#-1 LWP:-1 0x7fc8fba1a740] pthread_create:0 (Success)
pthread_t:7fc8fa02b700
'thread_1' [#1 LWP:-1 0x7fc8fa02b700] pthread_setname_np('thread_1')
'thread_1' [#1 LWP:-1 0x7fc8fa02b700] sleep(5)
'mainthrd' [#-1 LWP:-1 0x7fc8fba1a740] Waiting for thread #0
'thread_0' [#0 LWP:-1 0x7fc8fa82c700] pthread_exit(-1)
'thread_1' [#1 LWP:-1 0x7fc8fa02b700] pthread_exit(-1)
'mainthrd' [#-1 LWP:-1 0x7fc8fba1a740] Thread #0 rc:0 status:-1
'mainthrd' [#-1 LWP:-1 0x7fc8fba1a740] Waiting for thread #1
'mainthrd' [#-1 LWP:-1 0x7fc8fba1a740] Thread #1 rc:0 status:-1
Process 13815 stopped
* thread #1: tid = 13815, 0x00000000004010b3 pthreads`main(argc=1,
argv=0x00007ffff37f4048) + 611 at pthreads.cpp:122, name = 'pthreads', stop
reason = breakpoint 1.1
frame #0: 0x00000000004010b3 pthreads`main(argc=1,
argv=0x00007ffff37f4048) + 611 at pthreads.cpp:122
119 logit("Thread #%zu rc:%d status:%d\n", i, rc,
(int)(intptr_t)status);
120 }
121
-> 122 printf("done.\n");
123 return 0;
124 }
(lldb)
#
# Case 2: breakpoint on sleep in threadproc and sleep in main, then hit
"next"
#
mikesart at mikesart64:~/data/src/blah/build64$ lldb -- pthreads
Current executable set to 'pthreads' (x86_64).
(lldb) # breakpoint on sleep in threadproc and sleep in main
(lldb) b 81
Breakpoint 1: where = pthreads`thread_proc(void*) + 152 at pthreads.cpp:81,
address = 0x0000000000400e18
(lldb) b 111
Breakpoint 2: where = pthreads`main + 431 at pthreads.cpp:111, address =
0x0000000000400fff
(lldb) r
Process 16446 launched: '/home/mikesart/data/src/blah/build64/pthreads'
(x86_64)
num_threads:2
'mainthrd' [#-1 LWP:-1 0x7fb7de190740] pthread_create:0 (Success)
pthread_t:7fb7dcfa2700
'thread_0' [#0 LWP:-1 0x7fb7dcfa2700] pthread_setname_np('thread_0')
'thread_0' [#0 LWP:-1 0x7fb7dcfa2700] sleep(5)
Process 16446 stopped
thread #1: tid = 16446, 0x00007fb7dd096c91 libc.so.6`__clone + 49 at
clone.S:84, name = 'pthreads', stop reason = thread spawned
frame #0: 0x00007fb7dd096c91 libc.so.6`__clone + 49 at clone.S:84
81 cfi_endproc;
82 syscall
83
-> 84 testq %rax,%rax
85 jl SYSCALL_ERROR_LABEL
86 jz L(thread_start)
87
* thread #2: tid = 16450, 0x0000000000400e18
pthreads`thread_proc(arg=0x0000000000000000) + 152 at pthreads.cpp:81, name
= 'pthreads', stop reason = breakpoint 1.1
frame #0: 0x0000000000400e18
pthreads`thread_proc(arg=0x0000000000000000) + 152 at pthreads.cpp:81
78 setname(g_threadname);
79
80 logit("sleep(5)\n");
-> 81 sleep(5);
82
83 pid_t tid = gettid();
84 logit("pthread_exit(%d)\n", tid);
(lldb) n
(lldb) 'mainthrd' [#-1 LWP:-1 0x7fb7de190740] pthread_create:0 (Success)
pthread_t:7fb7dc7a1700
'thread_1' [#1 LWP:-1 0x7fb7dc7a1700] pthread_setname_np('thread_1')
'thread_1' [#1 LWP:-1 0x7fb7dc7a1700] sleep(5)
Process 16446 stopped
* thread #1: tid = 16446, 0x0000000000400fff pthreads`main(argc=1,
argv=0x00007fffbddb6d98) + 431 at pthreads.cpp:111, name = 'pthreads', stop
reason = breakpoint 2.1
frame #0: 0x0000000000400fff pthreads`main(argc=1,
argv=0x00007fffbddb6d98) + 431 at pthreads.cpp:111
108 logit("pthread_create:%d (%s) pthread_t:%lx\n", err,
strerror(err), threadids[i]);
109 }
110
-> 111 sleep(1);
112
113 for(size_t i = 0; i < num_threads; i++)
114 {
thread #3: tid = 16451, 0x0000000000400e18
pthreads`thread_proc(arg=0x0000000000000001) + 152 at pthreads.cpp:81, name
= 'pthreads', stop reason = breakpoint 1.1
frame #0: 0x0000000000400e18
pthreads`thread_proc(arg=0x0000000000000001) + 152 at pthreads.cpp:81
78 setname(g_threadname);
79
80 logit("sleep(5)\n");
-> 81 sleep(5);
82
83 pid_t tid = gettid();
84 logit("pthread_exit(%d)\n", tid);
(lldb) bt
* thread #1: tid = 23965, 0x0000000000400fff pthreads`main(argc=1,
argv=0x00007fff4d574e48) + 431 at pthreads.cpp:111, name = 'pthreads', stop
reason = breakpoint 2.1
frame #0: 0x0000000000400fff pthreads`main(argc=1,
argv=0x00007fff4d574e48) + 431 at pthreads.cpp:111
frame #1: 0x00007f85a8fc676d
libc.so.6`__libc_start_main(main=0x0000000000400e50, argc=1,
ubp_av=0x00007fff4d574e48, init=<unavailable>, fini=<unavailable>,
rtld_fini=<unavailable>, stack_end=0x00007fff4d574e38) + 237 at
libc-start.c:226
#
# Same run with gdb
#
mikesart at mikesart64:~/data/src/blah/build64$ gdb -- pthreads
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html
>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/mikesart/data/src/blah/build64/pthreads...done.
(gdb) b 81
Breakpoint 1 at 0x400e18: file /home/mikesart/data/src/blah/pthreads.cpp,
line 81.
(gdb) b 111
Breakpoint 2 at 0x400fff: file /home/mikesart/data/src/blah/pthreads.cpp,
line 111.
(gdb) r
Starting program: /home/mikesart/data/src/blah/build64/pthreads
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
num_threads:2
[New Thread 0x7ffff6de7700 (LWP 25890)]
'thread_0' [#0 LWP:-1 0x7ffff6de7700] pthread_setname_np('thread_0')
'thread_0' [#0 LWP:-1 0x7ffff6de7700] sleep(5)
'mainthrd' [#-1 LWP:-1 0x7ffff7fd4740] pthread_create:0 (Success)
pthread_t:7ffff6de7700
[Switching to Thread 0x7ffff6de7700 (LWP 25890)]
Breakpoint 1, thread_proc (arg=0x0) at
/home/mikesart/data/src/blah/pthreads.cpp:81
81 sleep(5);
(gdb) n
[New Thread 0x7ffff65e6700 (LWP 25964)]
'mainthrd' [#-1 LWP:-1 0x7ffff7fd4740] pthread_create:0 (Success)
pthread_t:7ffff65e6700
'thread_1' [#1 LWP:-1 0x7ffff65e6700] pthread_setname_np('thread_1')
'thread_1' [#1 LWP:-1 0x7ffff65e6700] sleep(5)
[Switching to Thread 0x7ffff7fd4740 (LWP 25887)]
Breakpoint 2, main (argc=1, argv=0x7fffffffd678) at
/home/mikesart/data/src/blah/pthreads.cpp:111
111 sleep(1);
(gdb) n
[Switching to Thread 0x7ffff65e6700 (LWP 25964)]
Breakpoint 1, thread_proc (arg=0x1) at
/home/mikesart/data/src/blah/pthreads.cpp:81
81 sleep(5);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20130906/d129b751/attachment.html>
More information about the lldb-dev
mailing list