diff options
author | Alex Langford <alangford@apple.com> | 2023-08-15 13:18:13 -0700 |
---|---|---|
committer | Alex Langford <alangford@apple.com> | 2023-08-17 10:32:23 -0700 |
commit | 90c5675a3db2319dd449a1753c79568355dfaaed (patch) | |
tree | 000ff294078d6427851e8cf67959af8d35d168ad /lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp | |
parent | 2d9c6e699a09d1363e435e6692508dd290984a00 (diff) | |
download | llvm-90c5675a3db2319dd449a1753c79568355dfaaed.zip llvm-90c5675a3db2319dd449a1753c79568355dfaaed.tar.gz llvm-90c5675a3db2319dd449a1753c79568355dfaaed.tar.bz2 |
[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
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp')
-rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 7eb29ee..68c3439 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -3379,23 +3379,20 @@ void ProcessGDBRemote::MonitorDebugserverProcess( if (state != eStateInvalid && state != eStateUnloaded && state != eStateExited && state != eStateDetached) { - char error_str[1024]; - if (signo) { - const char *signal_cstr = + StreamString stream; + if (signo == 0) + stream.Format(DEBUGSERVER_BASENAME " died with an exit status of {0:x8}", + exit_status); + else { + const char *signal_name = process_sp->GetUnixSignals()->GetSignalAsCString(signo); - if (signal_cstr) - ::snprintf(error_str, sizeof(error_str), - DEBUGSERVER_BASENAME " died with signal %s", signal_cstr); + const char *format_str = DEBUGSERVER_BASENAME " died with signal {0}"; + if (signal_name) + stream.Format(format_str, signal_name); else - ::snprintf(error_str, sizeof(error_str), - DEBUGSERVER_BASENAME " died with signal %i", signo); - } else { - ::snprintf(error_str, sizeof(error_str), - DEBUGSERVER_BASENAME " died with an exit status of 0x%8.8x", - exit_status); + stream.Format(format_str, signo); } - - process_sp->SetExitStatus(-1, error_str); + process_sp->SetExitStatus(-1, stream.GetString()); } // Debugserver has exited we need to let our ProcessGDBRemote know that it no // longer has a debugserver instance |