summaryrefslogtreecommitdiffstats
path: root/lldb
diff options
context:
space:
mode:
Diffstat (limited to 'lldb')
-rw-r--r--lldb/include/lldb/Core/State.h14
-rw-r--r--lldb/source/Core/State.cpp5
-rw-r--r--lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp10
-rw-r--r--lldb/unittests/Core/CMakeLists.txt1
-rw-r--r--lldb/unittests/Core/StateTest.cpp21
5 files changed, 38 insertions, 13 deletions
diff --git a/lldb/include/lldb/Core/State.h b/lldb/include/lldb/Core/State.h
index a9d7692ca45..e49e68f4597 100644
--- a/lldb/include/lldb/Core/State.h
+++ b/lldb/include/lldb/Core/State.h
@@ -10,11 +10,8 @@
#ifndef liblldb_State_h_
#define liblldb_State_h_
-// C Includes
-// C++ Includes
-// Other libraries and framework includes
-// Project includes
#include "lldb/lldb-private.h"
+#include "llvm/Support/FormatProviders.h"
namespace lldb_private {
@@ -71,4 +68,13 @@ const char *GetPermissionsAsCString(uint32_t permissions);
} // namespace lldb_private
+namespace llvm {
+template <> struct format_provider<lldb::StateType> {
+ static void format(const lldb::StateType &state, raw_ostream &Stream,
+ StringRef Style) {
+ Stream << lldb_private::StateAsCString(state);
+ }
+};
+}
+
#endif // liblldb_State_h_
diff --git a/lldb/source/Core/State.cpp b/lldb/source/Core/State.cpp
index 80497dd77b8..6bc7ce6b448 100644
--- a/lldb/source/Core/State.cpp
+++ b/lldb/source/Core/State.cpp
@@ -44,10 +44,7 @@ const char *lldb_private::StateAsCString(StateType state) {
case eStateSuspended:
return "suspended";
}
- static char unknown_state_string[64];
- snprintf(unknown_state_string, sizeof(unknown_state_string), "StateType = %i",
- state);
- return unknown_state_string;
+ return "unknown";
}
const char *lldb_private::GetPermissionsAsCString(uint32_t permissions) {
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index a20b709d58c..8032a773b09 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -567,7 +567,7 @@ void NativeProcessLinux::MonitorCallback(lldb::pid_t pid, bool exited,
pid,
thread_found ? "stopped tracking thread metadata"
: "thread metadata not found",
- StateAsCString(GetState()));
+ GetState());
// The main thread exited. We're done monitoring. Report to delegate.
SetExitStatus(convert_pid_status_to_exit_type(status),
convert_pid_status_to_return_code(status), nullptr, true);
@@ -1033,7 +1033,7 @@ void NativeProcessLinux::MonitorSignal(const siginfo_t &info,
LLDB_LOG(log,
"pid {0} tid {1}, thread was already marked as a stopped "
"state (state={2}), leaving stop signal as is",
- GetID(), thread.GetID(), StateAsCString(thread_state));
+ GetID(), thread.GetID(), thread_state);
SignalIfAllThreadsStopped();
}
@@ -1263,7 +1263,7 @@ Error NativeProcessLinux::Resume(const ResumeActionList &resume_actions) {
}
LLDB_LOG(log, "processing resume action state {0} for pid {1} tid {2}",
- StateAsCString(action->state), GetID(), thread_sp->GetID());
+ action->state, GetID(), thread_sp->GetID());
switch (action->state) {
case eStateRunning:
@@ -1393,7 +1393,7 @@ Error NativeProcessLinux::Kill() {
case StateType::eStateUnloaded:
// Nothing to do - the process is already dead.
LLDB_LOG(log, "ignored for PID {0} due to current state: {1}", GetID(),
- StateAsCString(m_state));
+ m_state);
return error;
case StateType::eStateConnected:
@@ -2273,7 +2273,7 @@ Error NativeProcessLinux::ResumeThread(NativeThreadLinux &thread,
return step_result;
}
default:
- LLDB_LOG(log, "Unhandled state {0}.", StateAsCString(state));
+ LLDB_LOG(log, "Unhandled state {0}.", state);
llvm_unreachable("Unhandled state for resume");
}
}
diff --git a/lldb/unittests/Core/CMakeLists.txt b/lldb/unittests/Core/CMakeLists.txt
index d5a7d533637..7ac9e777f6b 100644
--- a/lldb/unittests/Core/CMakeLists.txt
+++ b/lldb/unittests/Core/CMakeLists.txt
@@ -6,6 +6,7 @@ add_lldb_unittest(LLDBCoreTests
ListenerTest.cpp
LogTest.cpp
ScalarTest.cpp
+ StateTest.cpp
StructuredDataTest.cpp
TimerTest.cpp
)
diff --git a/lldb/unittests/Core/StateTest.cpp b/lldb/unittests/Core/StateTest.cpp
new file mode 100644
index 00000000000..76cdaac8205
--- /dev/null
+++ b/lldb/unittests/Core/StateTest.cpp
@@ -0,0 +1,21 @@
+//===-- StateTest.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/Core/State.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "gtest/gtest.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+TEST(StateTest, Formatv) {
+ EXPECT_EQ("exited", llvm::formatv("{0}", eStateExited).str());
+ EXPECT_EQ("stopped", llvm::formatv("{0}", eStateStopped).str());
+ EXPECT_EQ("unknown", llvm::formatv("{0}", StateType(-1)).str());
+}
OpenPOWER on IntegriCloud