Skip to content

Commit 90c5675

Browse files
committed
[lldb][NFCI] Rewrite error-handling code in ProcessGDBRemote::MonitorDebugserverProcess
I'm rewriting this for 2 reasons: 1) Although a 1024 char buffer is probably enough space, the error string may grow beyond that and we could lose some information. Using StringStream (as we do in the rest of ProcessGDBRemote) seems like a sensible solution. 2) I am planning on changing `UnixSignals::GetSignalAsCString`, rewriting things with `llvm::formatv` will make that process easier. Differential Revision: https://reviews.llvm.org/D158017
1 parent 2d9c6e6 commit 90c5675

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3379,23 +3379,20 @@ void ProcessGDBRemote::MonitorDebugserverProcess(
33793379

33803380
if (state != eStateInvalid && state != eStateUnloaded &&
33813381
state != eStateExited && state != eStateDetached) {
3382-
char error_str[1024];
3383-
if (signo) {
3384-
const char *signal_cstr =
3382+
StreamString stream;
3383+
if (signo == 0)
3384+
stream.Format(DEBUGSERVER_BASENAME " died with an exit status of {0:x8}",
3385+
exit_status);
3386+
else {
3387+
const char *signal_name =
33853388
process_sp->GetUnixSignals()->GetSignalAsCString(signo);
3386-
if (signal_cstr)
3387-
::snprintf(error_str, sizeof(error_str),
3388-
DEBUGSERVER_BASENAME " died with signal %s", signal_cstr);
3389+
const char *format_str = DEBUGSERVER_BASENAME " died with signal {0}";
3390+
if (signal_name)
3391+
stream.Format(format_str, signal_name);
33893392
else
3390-
::snprintf(error_str, sizeof(error_str),
3391-
DEBUGSERVER_BASENAME " died with signal %i", signo);
3392-
} else {
3393-
::snprintf(error_str, sizeof(error_str),
3394-
DEBUGSERVER_BASENAME " died with an exit status of 0x%8.8x",
3395-
exit_status);
3393+
stream.Format(format_str, signo);
33963394
}
3397-
3398-
process_sp->SetExitStatus(-1, error_str);
3395+
process_sp->SetExitStatus(-1, stream.GetString());
33993396
}
34003397
// Debugserver has exited we need to let our ProcessGDBRemote know that it no
34013398
// longer has a debugserver instance

0 commit comments

Comments
 (0)