Skip to content

Commit 287ce6b

Browse files
committed
[lldb] [Commands] Implement "thread siginfo"
Differential Revision: https://reviews.llvm.org/D118473
1 parent 70066dd commit 287ce6b

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

lldb/source/Commands/CommandObjectThread.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,53 @@ class CommandObjectThreadException : public CommandObjectIterateOverThreads {
13201320
}
13211321
};
13221322

1323+
class CommandObjectThreadSiginfo : public CommandObjectIterateOverThreads {
1324+
public:
1325+
CommandObjectThreadSiginfo(CommandInterpreter &interpreter)
1326+
: CommandObjectIterateOverThreads(
1327+
interpreter, "thread siginfo",
1328+
"Display the current siginfo object for a thread. Defaults to "
1329+
"the current thread.",
1330+
"thread siginfo",
1331+
eCommandRequiresProcess | eCommandTryTargetAPILock |
1332+
eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1333+
1334+
~CommandObjectThreadSiginfo() override = default;
1335+
1336+
void
1337+
HandleArgumentCompletion(CompletionRequest &request,
1338+
OptionElementVector &opt_element_vector) override {
1339+
CommandCompletions::InvokeCommonCompletionCallbacks(
1340+
GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
1341+
request, nullptr);
1342+
}
1343+
1344+
bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
1345+
ThreadSP thread_sp =
1346+
m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
1347+
if (!thread_sp) {
1348+
result.AppendErrorWithFormat("thread no longer exists: 0x%" PRIx64 "\n",
1349+
tid);
1350+
return false;
1351+
}
1352+
1353+
Stream &strm = result.GetOutputStream();
1354+
if (!thread_sp->GetDescription(strm, eDescriptionLevelFull, false, false)) {
1355+
result.AppendErrorWithFormat("error displaying info for thread: \"%d\"\n",
1356+
thread_sp->GetIndexID());
1357+
return false;
1358+
}
1359+
ValueObjectSP exception_object_sp = thread_sp->GetSiginfoValue();
1360+
if (exception_object_sp)
1361+
exception_object_sp->Dump(strm);
1362+
else
1363+
strm.Printf("(no siginfo)\n");
1364+
strm.PutChar('\n');
1365+
1366+
return true;
1367+
}
1368+
};
1369+
13231370
// CommandObjectThreadReturn
13241371
#define LLDB_OPTIONS_thread_return
13251372
#include "CommandOptions.inc"
@@ -2293,6 +2340,8 @@ CommandObjectMultiwordThread::CommandObjectMultiwordThread(
22932340
CommandObjectSP(new CommandObjectThreadInfo(interpreter)));
22942341
LoadSubCommand("exception", CommandObjectSP(new CommandObjectThreadException(
22952342
interpreter)));
2343+
LoadSubCommand("siginfo",
2344+
CommandObjectSP(new CommandObjectThreadSiginfo(interpreter)));
22962345
LoadSubCommand("step-in",
22972346
CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
22982347
interpreter, "thread step-in",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <assert.h>
2+
#include <signal.h>
3+
#include <stdio.h>
4+
#include <unistd.h>
5+
#include <sys/wait.h>
6+
7+
void handler(int signo) {
8+
printf("SIGCHLD\n");
9+
}
10+
11+
int main() {
12+
void *ret = signal(SIGINT, handler);
13+
assert (ret != SIG_ERR);
14+
15+
pid_t child_pid = fork();
16+
assert (child_pid != -1);
17+
18+
if (child_pid == 0) {
19+
sleep(1);
20+
_exit(14);
21+
}
22+
23+
printf("signo = %d\n", SIGCHLD);
24+
printf("code = %d\n", CLD_EXITED);
25+
printf("child_pid = %d\n", child_pid);
26+
printf("uid = %d\n", getuid());
27+
pid_t waited = wait(NULL);
28+
assert(waited == child_pid);
29+
30+
return 0;
31+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# REQUIRES: system-linux
2+
# RUN: %clang_host -g %S/Inputs/sigchld.c -o %t
3+
# RUN: %lldb %t -b -s %s | FileCheck %s
4+
5+
process launch -s
6+
process handle SIGCHLD -s true
7+
process continue
8+
# CHECK: signo = [[SIGNO:[0-9]+]]
9+
# CHECK: code = [[CODE:[0-9]+]]
10+
# CHECK: child_pid = [[PID:[0-9]+]]
11+
# CHECK: uid = [[UID:[0-9]+]]
12+
# CHECK: stop reason = signal SIGCHLD
13+
thread siginfo
14+
# CHECK-DAG: si_signo = [[SIGNO]]
15+
# CHECK-DAG: si_errno = 0
16+
# CHECK-DAG: si_code = [[CODE]]
17+
# CHECK-DAG: si_pid = [[PID]]
18+
# CHECK-DAG: si_uid = [[UID]]
19+
# CHECK-DAG: si_status = 14

0 commit comments

Comments
 (0)