labath updated this revision to Diff 102309.
labath marked an inline comment as done.
labath added a comment.
Use a switch instead of indexing the array with an enum value
https://reviews.llvm.org/D33998
Files:
include/lldb/Host/Host.h
include/lldb/Host/common/NativeProcessProtocol.h
include/lldb/lldb-private-enumerations.h
source/Host/common/Host.cpp
source/Host/common/NativeProcessProtocol.cpp
source/Plugins/Process/Darwin/NativeProcessDarwin.cpp
source/Plugins/Process/Linux/NativeProcessLinux.cpp
source/Plugins/Process/Linux/NativeProcessLinux.h
source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
unittests/Host/CMakeLists.txt
unittests/Host/HostTest.cpp
Index: unittests/Host/HostTest.cpp
===
--- /dev/null
+++ unittests/Host/HostTest.cpp
@@ -0,0 +1,22 @@
+//===-- HostTest.cpp *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "lldb/Host/Host.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+using namespace llvm;
+
+TEST(Host, WaitStatusFormat) {
+ EXPECT_EQ("W01", formatv("{0:g}", WaitStatus{WaitStatus::Exit, 1}).str());
+ EXPECT_EQ("X02", formatv("{0:g}", WaitStatus{WaitStatus::Signal, 2}).str());
+ EXPECT_EQ("S03", formatv("{0:g}", WaitStatus{WaitStatus::Stop, 3}).str());
+ EXPECT_EQ("Exited with status 4",
+formatv("{0}", WaitStatus{WaitStatus::Exit, 4}).str());
+}
Index: unittests/Host/CMakeLists.txt
===
--- unittests/Host/CMakeLists.txt
+++ unittests/Host/CMakeLists.txt
@@ -1,6 +1,7 @@
set (FILES
FileSpecTest.cpp
FileSystemTest.cpp
+ HostTest.cpp
MainLoopTest.cpp
SocketAddressTest.cpp
SocketTest.cpp
Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
===
--- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -370,53 +370,23 @@
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
// send W notification
- ExitType exit_type = ExitType::eExitTypeInvalid;
- int return_code = 0;
- std::string exit_description;
-
- const bool got_exit_info =
- process->GetExitStatus(&exit_type, &return_code, exit_description);
- if (!got_exit_info) {
-if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- ", failed to retrieve process exit status",
- __FUNCTION__, process->GetID());
+ auto wait_status = process->GetExitStatus();
+ if (!wait_status) {
+LLDB_LOG(log, "pid = {0}, failed to retrieve process exit status",
+ process->GetID());
StreamGDBRemote response;
response.PutChar('E');
response.PutHex8(GDBRemoteServerError::eErrorExitStatus);
return SendPacketNoLock(response.GetString());
- } else {
-if (log)
- log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
- ", returning exit type %d, return code %d [%s]",
- __FUNCTION__, process->GetID(), exit_type, return_code,
- exit_description.c_str());
-
-StreamGDBRemote response;
-
-char return_type_code;
-switch (exit_type) {
-case ExitType::eExitTypeExit:
- return_type_code = 'W';
- break;
-case ExitType::eExitTypeSignal:
- return_type_code = 'X';
- break;
-case ExitType::eExitTypeStop:
- return_type_code = 'S';
- break;
-case ExitType::eExitTypeInvalid:
- return_type_code = 'E';
- break;
-}
-response.PutChar(return_type_code);
+ }
-// POSIX exit status limited to unsigned 8 bits.
-response.PutHex8(return_code);
+ LLDB_LOG(log, "pid = {0}, returning exit type {1}", process->GetID(),
+ *wait_status);
-return SendPacketNoLock(response.GetString());
- }
+ StreamGDBRemote response;
+ response.Format("{0:g}", *wait_status);
+ return SendPacketNoLock(response.GetString());
}
static void AppendHexValue(StreamString &response, const uint8_t *buf,
Index: source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
===
--- source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
+++ source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
@@ -123,7 +123,7 @@
void AttachToInferior(MainLoop &mainloop, lldb::pid_t pid, Status &error);
void MonitorCallback(lldb::pid_t pid, int signal);
- void MonitorExited(lldb::pid_t pid, int signal, int