This repository was archived by the owner on Sep 15, 2025. It is now read-only.
Commit 4051942
authored
Add option to pass thread ID to thread select command (llvm#73596)
We'd like a way to select the current thread by its thread ID (rather
than its internal LLDB thread index).
This PR adds a `-t` option (`--thread_id` long option) that tells the
`thread select` command to interpret the `<thread-index>` argument as a
thread ID.
Here's an example of it working:
```
michristensen@devbig356 llvm/llvm-project (thread-select-tid) » ../Debug/bin/lldb ~/scratch/cpp/threading/a.out
(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 215715 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 215715 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 = 216047, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
(lldb) thread list
Process 215715 stopped
thread #1: tid = 215715, 0x0000555555400850 a.out`main at main.cpp:18:12, name = 'a.out', stop reason = breakpoint 1.1
* thread #2: tid = 216047, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
thread #3: tid = 216048, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
thread llvm#4: tid = 216049, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
thread llvm#5: tid = 216050, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
thread llvm#6: tid = 216051, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
(lldb) thread select 215715
error: invalid thread #215715.
(lldb) thread select -t 215715
* 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 216051
* thread llvm#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 select 3
* 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 -t 216048
* 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 --thread_id 216048
* 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) help thread select
Change the currently selected thread.
Syntax: thread select <cmd-options> <thread-index>
Command Options Usage:
thread select [-t] <thread-index>
-t ( --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) c
Process 215715 resuming
Process 215715 exited with status = 0 (0x00000000)
```1 parent a590387 commit 4051942
File tree
7 files changed
+176
-52
lines changed- lldb
- include/lldb
- Interpreter
- source/Commands
- test/API/commands/thread/select
7 files changed
+176
-52
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
123 | 126 | | |
124 | 127 | | |
125 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| 195 | + | |
195 | 196 | | |
196 | 197 | | |
197 | 198 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1270 | 1270 | | |
1271 | 1271 | | |
1272 | 1272 | | |
1273 | | - | |
1274 | | - | |
1275 | | - | |
1276 | | - | |
1277 | | - | |
1278 | | - | |
1279 | | - | |
1280 | | - | |
1281 | | - | |
1282 | | - | |
1283 | | - | |
1284 | | - | |
1285 | | - | |
1286 | | - | |
1287 | | - | |
1288 | | - | |
1289 | | - | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
1294 | | - | |
1295 | | - | |
1296 | | - | |
1297 | | - | |
1298 | | - | |
1299 | | - | |
1300 | | - | |
1301 | | - | |
1302 | | - | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
1303 | 1305 | | |
1304 | 1306 | | |
1305 | 1307 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
86 | | - | |
| 87 | + | |
| 88 | + | |
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
91 | | - | |
| 93 | + | |
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
| |||
807 | 809 | | |
808 | 810 | | |
809 | 811 | | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
810 | 829 | | |
811 | 830 | | |
812 | 831 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1129 | 1129 | | |
1130 | 1130 | | |
1131 | 1131 | | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
1132 | 1135 | | |
1133 | 1136 | | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
1134 | 1173 | | |
1135 | 1174 | | |
1136 | | - | |
| 1175 | + | |
| 1176 | + | |
1137 | 1177 | | |
1138 | 1178 | | |
1139 | 1179 | | |
| |||
1143 | 1183 | | |
1144 | 1184 | | |
1145 | 1185 | | |
| 1186 | + | |
1146 | 1187 | | |
1147 | 1188 | | |
1148 | 1189 | | |
1149 | 1190 | | |
1150 | 1191 | | |
1151 | 1192 | | |
1152 | 1193 | | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
1153 | 1197 | | |
1154 | 1198 | | |
1155 | 1199 | | |
| |||
1165 | 1209 | | |
1166 | 1210 | | |
1167 | 1211 | | |
| 1212 | + | |
| 1213 | + | |
1168 | 1214 | | |
1169 | 1215 | | |
1170 | 1216 | | |
1171 | 1217 | | |
1172 | 1218 | | |
1173 | 1219 | | |
1174 | | - | |
| 1220 | + | |
| 1221 | + | |
1175 | 1222 | | |
1176 | | - | |
| 1223 | + | |
| 1224 | + | |
1177 | 1225 | | |
1178 | 1226 | | |
1179 | | - | |
1180 | | - | |
1181 | | - | |
1182 | | - | |
1183 | | - | |
1184 | | - | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
1185 | 1232 | | |
1186 | 1233 | | |
1187 | 1234 | | |
1188 | | - | |
1189 | | - | |
1190 | | - | |
1191 | | - | |
1192 | | - | |
1193 | | - | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
1194 | 1257 | | |
1195 | 1258 | | |
1196 | 1259 | | |
1197 | 1260 | | |
1198 | 1261 | | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
1199 | 1265 | | |
1200 | 1266 | | |
1201 | 1267 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1117 | 1117 | | |
1118 | 1118 | | |
1119 | 1119 | | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
1120 | 1126 | | |
1121 | 1127 | | |
1122 | 1128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | 15 | | |
19 | 16 | | |
20 | 17 | | |
21 | 18 | | |
22 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
23 | 35 | | |
24 | 36 | | |
25 | 37 | | |
26 | 38 | | |
27 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
28 | 55 | | |
0 commit comments