[Lldb-commits] [lldb] Add option to pass thread ID to thread select command (PR #73596)
Michael Christensen via lldb-commits
lldb-commits at lists.llvm.org
Tue Nov 28 18:09:04 PST 2023
mdko wrote:
[Latest changes](https://github.com/llvm/llvm-project/pull/73596/commits/34045b9b2e04e01fed142ad2d7f4503e69646c9f) implement reviewer suggestions:
* `thread_id` option is now `thread-id`
* This option takes a value rather than causing original argument to be interpreted differently
* This option is now in a separate grouping, so we can show the two separate ways of calling this command: `thread select <thread-index>` and ` thread select [-t <thread-id>]`. This is similar to what shows up with `memory write ...`
Example usage:
```
michristensen at devbig356 llvm/Debug » ./bin/lldb ~/scratch/cpp/virtual/a.out
error: module importing failed: This script interpreter does not support importing modules.
NAME PASS STOP NOTIFY
=========== ======= ======= =======
SIGPIPE true false false
(lldb) target create "/home/michristensen/scratch/cpp/virtual/a.out"
Current executable set to '/home/michristensen/scratch/cpp/virtual/a.out' (x86_64).
(lldb) b 18
Breakpoint 1: where = a.out`main + 13 at t2.cpp:20:14, address = 0x0000000000000c2d
(lldb) ^D
michristensen at devbig356 llvm/Debug »
michristensen at devbig356 llvm/Debug » ./bin/lldb ~/scratch/cpp/threading/a.out
error: module importing failed: This script interpreter does not support importing modules.
NAME PASS STOP NOTIFY
=========== ======= ======= =======
SIGPIPE true false false
(lldb) target create "/home/michristensen/scratch/cpp/threading/a.out"
Current executable set to '/home/michristensen/scratch/cpp/threading/a.out' (x86_64).
(lldb) b 18
Breakpoint 1: where = a.out`main + 80 at main.cpp:18:12, address = 0x0000000000000850
(lldb) run
Process 3517265 launched: '/home/michristensen/scratch/cpp/threading/a.out' (x86_64)
This is a thread, i=1
This is a thread, i=2
This is a thread, i=3
This is a thread, i=4
This is a thread, i=5
Process 3517265 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
frame #0: 0x0000555555400850 a.out`main at main.cpp:18:12
15 for (int i = 0; i < 5; i++) {
16 pthread_create(&thread_ids[i], NULL, foo, NULL);
17 }
-> 18 for (int i = 0; i < 5; i++) {
19 pthread_join(thread_ids[i], NULL);
20 }
21 return 0;
(lldb) thread select 2
* thread #2, name = 'a.out'
frame #0: 0x00007ffff68f9918 libc.so.6`__nanosleep + 72
libc.so.6`__nanosleep:
-> 0x7ffff68f9918 <+72>: cmpq $-0x1000, %rax ; imm = 0xF000
0x7ffff68f991e <+78>: ja 0x7ffff68f9952 ; <+130>
0x7ffff68f9920 <+80>: movl %edx, %edi
0x7ffff68f9922 <+82>: movl %eax, 0xc(%rsp)
(lldb) thread info
thread #2: tid = 3517533, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
(lldb) thread list
Process 3517265 stopped
thread #1: tid = 3517265, 0x0000555555400850 a.out`main at main.cpp:18:12, name = 'a.out', stop reason = breakpoint 1.1
* thread #2: tid = 3517533, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
thread #3: tid = 3517534, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
thread #4: tid = 3517535, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
thread #5: tid = 3517536, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
thread #6: tid = 3517537, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
(lldb) thread select 3517265
error: Invalid thread #3517265.
(lldb) thread select -t 3517265
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
frame #0: 0x0000555555400850 a.out`main at main.cpp:18:12
15 for (int i = 0; i < 5; i++) {
16 pthread_create(&thread_ids[i], NULL, foo, NULL);
17 }
-> 18 for (int i = 0; i < 5; i++) {
19 pthread_join(thread_ids[i], NULL);
20 }
21 return 0;
(lldb) thread select -t 3517534
* thread #3, name = 'a.out'
frame #0: 0x00007ffff68f9918 libc.so.6`__nanosleep + 72
libc.so.6`__nanosleep:
-> 0x7ffff68f9918 <+72>: cmpq $-0x1000, %rax ; imm = 0xF000
0x7ffff68f991e <+78>: ja 0x7ffff68f9952 ; <+130>
0x7ffff68f9920 <+80>: movl %edx, %edi
0x7ffff68f9922 <+82>: movl %eax, 0xc(%rsp)
(lldb) thread select 6
* thread #6, name = 'a.out'
frame #0: 0x00007ffff68f9918 libc.so.6`__nanosleep + 72
libc.so.6`__nanosleep:
-> 0x7ffff68f9918 <+72>: cmpq $-0x1000, %rax ; imm = 0xF000
0x7ffff68f991e <+78>: ja 0x7ffff68f9952 ; <+130>
0x7ffff68f9920 <+80>: movl %edx, %edi
0x7ffff68f9922 <+82>: movl %eax, 0xc(%rsp)
(lldb) thread info
thread #6: tid = 3517537, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
(lldb) thread select -t 3517536
* thread #5, name = 'a.out'
frame #0: 0x00007ffff68f9918 libc.so.6`__nanosleep + 72
libc.so.6`__nanosleep:
-> 0x7ffff68f9918 <+72>: cmpq $-0x1000, %rax ; imm = 0xF000
0x7ffff68f991e <+78>: ja 0x7ffff68f9952 ; <+130>
0x7ffff68f9920 <+80>: movl %edx, %edi
0x7ffff68f9922 <+82>: movl %eax, 0xc(%rsp)
(lldb) thread info
thread #5: tid = 3517536, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
(lldb) help thread select
Change the currently selected thread.
Syntax: thread select <cmd-options> <thread-index>
Command Options Usage:
thread select <thread-index>
thread select [-t <thread-id>]
-t <thread-id> ( --thread-id <thread-id> )
Provide a thread ID instead of a thread index.
This command takes options and free-form arguments. If your arguments
resemble option specifiers (i.e., they start with a - or --), you must use
' -- ' between the end of the command options and the beginning of the
arguments.
(lldb) thread select 0
error: Invalid thread #0.
(lldb) thread select -t 0
error: 'thread select' takes exactly one thread index argument, or a thread ID option:
Usage: thread select <cmd-options> <thread-index>
(lldb) thread select -t 1
error: Invalid thread ID 1.
(lldb) thread select -t 3517536 1
error: 'thread select' cannot take both a thread ID option and a thread index argument:
Usage: thread select <cmd-options> <thread-index>
```
https://github.com/llvm/llvm-project/pull/73596
More information about the lldb-commits
mailing list