Skip to content

Commit d6b3de7

Browse files
committed
[lldb] [llgs] Fix signo sent with fork/vfork/vforkdone events
Fix ThreadStopInfo struct to include the signal number for all events. Since signo was not included in the details for fork, vfork and vforkdone stops, the code incidentally referenced the wrong union member, resulting in wrong signo being sent. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.llvm.org/D127193
1 parent 5b04eb2 commit d6b3de7

8 files changed

Lines changed: 44 additions & 41 deletions

File tree

lldb/include/lldb/Host/Debug.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,8 @@ class ResumeActionList {
130130

131131
struct ThreadStopInfo {
132132
lldb::StopReason reason;
133+
uint32_t signo;
133134
union {
134-
// eStopReasonSignal
135-
struct {
136-
uint32_t signo;
137-
} signal;
138-
139135
// eStopReasonException
140136
struct {
141137
uint64_t type;

lldb/source/Plugins/Process/FreeBSD/NativeThreadFreeBSD.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void NativeThreadFreeBSD::SetStoppedBySignal(uint32_t signo,
8181
SetStopped();
8282

8383
m_stop_info.reason = StopReason::eStopReasonSignal;
84-
m_stop_info.details.signal.signo = signo;
84+
m_stop_info.signo = signo;
8585

8686
m_stop_description.clear();
8787
if (info) {
@@ -100,19 +100,19 @@ void NativeThreadFreeBSD::SetStoppedBySignal(uint32_t signo,
100100
void NativeThreadFreeBSD::SetStoppedByBreakpoint() {
101101
SetStopped();
102102
m_stop_info.reason = StopReason::eStopReasonBreakpoint;
103-
m_stop_info.details.signal.signo = SIGTRAP;
103+
m_stop_info.signo = SIGTRAP;
104104
}
105105

106106
void NativeThreadFreeBSD::SetStoppedByTrace() {
107107
SetStopped();
108108
m_stop_info.reason = StopReason::eStopReasonTrace;
109-
m_stop_info.details.signal.signo = SIGTRAP;
109+
m_stop_info.signo = SIGTRAP;
110110
}
111111

112112
void NativeThreadFreeBSD::SetStoppedByExec() {
113113
SetStopped();
114114
m_stop_info.reason = StopReason::eStopReasonExec;
115-
m_stop_info.details.signal.signo = SIGTRAP;
115+
m_stop_info.signo = SIGTRAP;
116116
}
117117

118118
void NativeThreadFreeBSD::SetStoppedByWatchpoint(uint32_t wp_index) {
@@ -127,14 +127,15 @@ void NativeThreadFreeBSD::SetStoppedByWatchpoint(uint32_t wp_index) {
127127
SetStopped();
128128
m_stop_description = ostr.str();
129129
m_stop_info.reason = StopReason::eStopReasonWatchpoint;
130-
m_stop_info.details.signal.signo = SIGTRAP;
130+
m_stop_info.signo = SIGTRAP;
131131
}
132132

133133
void NativeThreadFreeBSD::SetStoppedByFork(lldb::pid_t child_pid,
134134
lldb::tid_t child_tid) {
135135
SetStopped();
136136

137137
m_stop_info.reason = StopReason::eStopReasonFork;
138+
m_stop_info.signo = SIGTRAP;
138139
m_stop_info.details.fork.child_pid = child_pid;
139140
m_stop_info.details.fork.child_tid = child_tid;
140141
}
@@ -144,6 +145,7 @@ void NativeThreadFreeBSD::SetStoppedByVFork(lldb::pid_t child_pid,
144145
SetStopped();
145146

146147
m_stop_info.reason = StopReason::eStopReasonVFork;
148+
m_stop_info.signo = SIGTRAP;
147149
m_stop_info.details.fork.child_pid = child_pid;
148150
m_stop_info.details.fork.child_tid = child_tid;
149151
}
@@ -152,13 +154,14 @@ void NativeThreadFreeBSD::SetStoppedByVForkDone() {
152154
SetStopped();
153155

154156
m_stop_info.reason = StopReason::eStopReasonVForkDone;
157+
m_stop_info.signo = SIGTRAP;
155158
}
156159

157160
void NativeThreadFreeBSD::SetStoppedWithNoReason() {
158161
SetStopped();
159162

160163
m_stop_info.reason = StopReason::eStopReasonNone;
161-
m_stop_info.details.signal.signo = 0;
164+
m_stop_info.signo = 0;
162165
}
163166

164167
void NativeThreadFreeBSD::SetStopped() {

lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,27 @@ void LogThreadStopInfo(Log &log, const ThreadStopInfo &stop_info,
4848
return;
4949
case eStopReasonTrace:
5050
log.Printf("%s: %s trace, stopping signal 0x%" PRIx32, __FUNCTION__, header,
51-
stop_info.details.signal.signo);
51+
stop_info.signo);
5252
return;
5353
case eStopReasonBreakpoint:
5454
log.Printf("%s: %s breakpoint, stopping signal 0x%" PRIx32, __FUNCTION__,
55-
header, stop_info.details.signal.signo);
55+
header, stop_info.signo);
5656
return;
5757
case eStopReasonWatchpoint:
5858
log.Printf("%s: %s watchpoint, stopping signal 0x%" PRIx32, __FUNCTION__,
59-
header, stop_info.details.signal.signo);
59+
header, stop_info.signo);
6060
return;
6161
case eStopReasonSignal:
6262
log.Printf("%s: %s signal 0x%02" PRIx32, __FUNCTION__, header,
63-
stop_info.details.signal.signo);
63+
stop_info.signo);
6464
return;
6565
case eStopReasonException:
6666
log.Printf("%s: %s exception type 0x%02" PRIx64, __FUNCTION__, header,
6767
stop_info.details.exception.type);
6868
return;
6969
case eStopReasonExec:
7070
log.Printf("%s: %s exec, stopping signal 0x%" PRIx32, __FUNCTION__, header,
71-
stop_info.details.signal.signo);
71+
stop_info.signo);
7272
return;
7373
case eStopReasonPlanComplete:
7474
log.Printf("%s: %s plan complete", __FUNCTION__, header);
@@ -285,7 +285,7 @@ void NativeThreadLinux::SetStoppedBySignal(uint32_t signo,
285285
SetStopped();
286286

287287
m_stop_info.reason = StopReason::eStopReasonSignal;
288-
m_stop_info.details.signal.signo = signo;
288+
m_stop_info.signo = signo;
289289

290290
m_stop_description.clear();
291291
if (info) {
@@ -371,7 +371,7 @@ bool NativeThreadLinux::IsStopped(int *signo) {
371371
// If we are stopped by a signal, return the signo.
372372
if (signo && m_state == StateType::eStateStopped &&
373373
m_stop_info.reason == StopReason::eStopReasonSignal) {
374-
*signo = m_stop_info.details.signal.signo;
374+
*signo = m_stop_info.signo;
375375
}
376376

377377
// Regardless, we are stopped.
@@ -398,14 +398,14 @@ void NativeThreadLinux::SetStoppedByExec() {
398398
SetStopped();
399399

400400
m_stop_info.reason = StopReason::eStopReasonExec;
401-
m_stop_info.details.signal.signo = SIGSTOP;
401+
m_stop_info.signo = SIGSTOP;
402402
}
403403

404404
void NativeThreadLinux::SetStoppedByBreakpoint() {
405405
SetStopped();
406406

407407
m_stop_info.reason = StopReason::eStopReasonBreakpoint;
408-
m_stop_info.details.signal.signo = SIGTRAP;
408+
m_stop_info.signo = SIGTRAP;
409409
m_stop_description.clear();
410410
}
411411

@@ -434,7 +434,7 @@ void NativeThreadLinux::SetStoppedByWatchpoint(uint32_t wp_index) {
434434
m_stop_description = ostr.str();
435435

436436
m_stop_info.reason = StopReason::eStopReasonWatchpoint;
437-
m_stop_info.details.signal.signo = SIGTRAP;
437+
m_stop_info.signo = SIGTRAP;
438438
}
439439

440440
bool NativeThreadLinux::IsStoppedAtBreakpoint() {
@@ -451,14 +451,15 @@ void NativeThreadLinux::SetStoppedByTrace() {
451451
SetStopped();
452452

453453
m_stop_info.reason = StopReason::eStopReasonTrace;
454-
m_stop_info.details.signal.signo = SIGTRAP;
454+
m_stop_info.signo = SIGTRAP;
455455
}
456456

457457
void NativeThreadLinux::SetStoppedByFork(bool is_vfork, lldb::pid_t child_pid) {
458458
SetStopped();
459459

460460
m_stop_info.reason =
461461
is_vfork ? StopReason::eStopReasonVFork : StopReason::eStopReasonFork;
462+
m_stop_info.signo = SIGTRAP;
462463
m_stop_info.details.fork.child_pid = child_pid;
463464
m_stop_info.details.fork.child_tid = child_pid;
464465
}
@@ -467,21 +468,22 @@ void NativeThreadLinux::SetStoppedByVForkDone() {
467468
SetStopped();
468469

469470
m_stop_info.reason = StopReason::eStopReasonVForkDone;
471+
m_stop_info.signo = SIGTRAP;
470472
}
471473

472474
void NativeThreadLinux::SetStoppedWithNoReason() {
473475
SetStopped();
474476

475477
m_stop_info.reason = StopReason::eStopReasonNone;
476-
m_stop_info.details.signal.signo = 0;
478+
m_stop_info.signo = 0;
477479
}
478480

479481
void NativeThreadLinux::SetStoppedByProcessorTrace(
480482
llvm::StringRef description) {
481483
SetStopped();
482484

483485
m_stop_info.reason = StopReason::eStopReasonProcessorTrace;
484-
m_stop_info.details.signal.signo = 0;
486+
m_stop_info.signo = 0;
485487
m_stop_description = description.str();
486488
}
487489

lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void NativeThreadNetBSD::SetStoppedBySignal(uint32_t signo,
8181
SetStopped();
8282

8383
m_stop_info.reason = StopReason::eStopReasonSignal;
84-
m_stop_info.details.signal.signo = signo;
84+
m_stop_info.signo = signo;
8585

8686
m_stop_description.clear();
8787
if (info) {
@@ -100,19 +100,19 @@ void NativeThreadNetBSD::SetStoppedBySignal(uint32_t signo,
100100
void NativeThreadNetBSD::SetStoppedByBreakpoint() {
101101
SetStopped();
102102
m_stop_info.reason = StopReason::eStopReasonBreakpoint;
103-
m_stop_info.details.signal.signo = SIGTRAP;
103+
m_stop_info.signo = SIGTRAP;
104104
}
105105

106106
void NativeThreadNetBSD::SetStoppedByTrace() {
107107
SetStopped();
108108
m_stop_info.reason = StopReason::eStopReasonTrace;
109-
m_stop_info.details.signal.signo = SIGTRAP;
109+
m_stop_info.signo = SIGTRAP;
110110
}
111111

112112
void NativeThreadNetBSD::SetStoppedByExec() {
113113
SetStopped();
114114
m_stop_info.reason = StopReason::eStopReasonExec;
115-
m_stop_info.details.signal.signo = SIGTRAP;
115+
m_stop_info.signo = SIGTRAP;
116116
}
117117

118118
void NativeThreadNetBSD::SetStoppedByWatchpoint(uint32_t wp_index) {
@@ -127,14 +127,15 @@ void NativeThreadNetBSD::SetStoppedByWatchpoint(uint32_t wp_index) {
127127
SetStopped();
128128
m_stop_description = ostr.str();
129129
m_stop_info.reason = StopReason::eStopReasonWatchpoint;
130-
m_stop_info.details.signal.signo = SIGTRAP;
130+
m_stop_info.signo = SIGTRAP;
131131
}
132132

133133
void NativeThreadNetBSD::SetStoppedByFork(lldb::pid_t child_pid,
134134
lldb::tid_t child_tid) {
135135
SetStopped();
136136

137137
m_stop_info.reason = StopReason::eStopReasonFork;
138+
m_stop_info.signo = SIGTRAP;
138139
m_stop_info.details.fork.child_pid = child_pid;
139140
m_stop_info.details.fork.child_tid = child_tid;
140141
}
@@ -144,6 +145,7 @@ void NativeThreadNetBSD::SetStoppedByVFork(lldb::pid_t child_pid,
144145
SetStopped();
145146

146147
m_stop_info.reason = StopReason::eStopReasonVFork;
148+
m_stop_info.signo = SIGTRAP;
147149
m_stop_info.details.fork.child_pid = child_pid;
148150
m_stop_info.details.fork.child_tid = child_tid;
149151
}
@@ -152,13 +154,14 @@ void NativeThreadNetBSD::SetStoppedByVForkDone() {
152154
SetStopped();
153155

154156
m_stop_info.reason = StopReason::eStopReasonVForkDone;
157+
m_stop_info.signo = SIGTRAP;
155158
}
156159

157160
void NativeThreadNetBSD::SetStoppedWithNoReason() {
158161
SetStopped();
159162

160163
m_stop_info.reason = StopReason::eStopReasonNone;
161-
m_stop_info.details.signal.signo = 0;
164+
m_stop_info.signo = 0;
162165
}
163166

164167
void NativeThreadNetBSD::SetStopped() {

lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,12 @@ void NativeProcessWindows::SetStopReasonForThread(NativeThreadWindows &thread,
253253

254254
ThreadStopInfo stop_info;
255255
stop_info.reason = reason;
256-
257256
// No signal support on Windows but required to provide a 'valid' signum.
257+
stop_info.signo = SIGTRAP;
258+
258259
if (reason == StopReason::eStopReasonException) {
259260
stop_info.details.exception.type = 0;
260261
stop_info.details.exception.data_count = 0;
261-
} else {
262-
stop_info.details.signal.signo = SIGTRAP;
263262
}
264263

265264
thread.SetStopReason(stop_info, description);

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ GetJSONThreadsInfo(NativeProcessProtocol &process, bool abridged) {
728728
return llvm::make_error<llvm::StringError>(
729729
"failed to get stop reason", llvm::inconvertibleErrorCode());
730730

731-
const int signum = tid_stop_info.details.signal.signo;
731+
const int signum = tid_stop_info.signo;
732732
if (log) {
733733
LLDB_LOGF(log,
734734
"GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
@@ -804,7 +804,7 @@ GDBRemoteCommunicationServerLLGS::PrepareStopReplyPacketForThread(
804804

805805
// Output the T packet with the thread
806806
response.PutChar('T');
807-
int signum = tid_stop_info.details.signal.signo;
807+
int signum = tid_stop_info.signo;
808808
LLDB_LOG(
809809
log,
810810
"pid {0}, tid {1}, got signal signo = {2}, reason = {3}, exc_type = {4}",

lldb/test/API/tools/lldb-server/TestGdbRemoteFork.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_fork_multithreaded(self):
1515
self.reset_test_sequence()
1616

1717
# continue and expect fork
18-
fork_regex = "[$]T.*;fork:p([0-9a-f]+)[.]([0-9a-f]+).*"
18+
fork_regex = "[$]T05.*;fork:p([0-9a-f]+)[.]([0-9a-f]+).*"
1919
self.test_sequence.add_log_lines([
2020
"read packet: $c#00",
2121
{"direction": "send", "regex": fork_regex,
@@ -49,7 +49,7 @@ def fork_and_detach_test(self, variant):
4949
self.reset_test_sequence()
5050

5151
# continue and expect fork
52-
fork_regex = "[$]T.*;{}:p([0-9a-f]+)[.]([0-9a-f]+).*".format(variant)
52+
fork_regex = "[$]T05.*;{}:p([0-9a-f]+)[.]([0-9a-f]+).*".format(variant)
5353
self.test_sequence.add_log_lines([
5454
"read packet: $c#00",
5555
{"direction": "send", "regex": fork_regex,
@@ -85,7 +85,7 @@ def test_vfork(self):
8585
# resume the parent
8686
self.test_sequence.add_log_lines([
8787
"read packet: $c#00",
88-
{"direction": "send", "regex": r"[$]T.*vforkdone.*"},
88+
{"direction": "send", "regex": r"[$]T05.*vforkdone.*"},
8989
"read packet: $c#00",
9090
{"direction": "send", "regex": r"[$]W00;process:[0-9a-f]+#.*"},
9191
], True)

lldb/tools/debugserver/source/RNBRemote.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,7 +2704,7 @@ rnb_err_t RNBRemote::SendStopReplyPacketForThread(nub_thread_t tid) {
27042704
std::ostringstream ostrm;
27052705
// Output the T packet with the thread
27062706
ostrm << 'T';
2707-
int signum = tid_stop_info.details.signal.signo;
2707+
int signum = tid_stop_info.signo;
27082708
DNBLogThreadedIf(
27092709
LOG_RNB_PROC, "%8d %s got signal signo = %u, exc_type = %u",
27102710
(uint32_t)m_comm.Timer().ElapsedMicroSeconds(true), __FUNCTION__,
@@ -5450,9 +5450,9 @@ RNBRemote::GetJSONThreadsInfo(bool threads_with_valid_stop_info_only) {
54505450
break;
54515451

54525452
case eStopTypeSignal:
5453-
if (tid_stop_info.details.signal.signo != 0) {
5453+
if (tid_stop_info.signo != 0) {
54545454
thread_dict_sp->AddIntegerItem("signal",
5455-
tid_stop_info.details.signal.signo);
5455+
tid_stop_info.signo);
54565456
reason_value = "signal";
54575457
}
54585458
break;

0 commit comments

Comments
 (0)