[Lldb-commits] [PATCH] D29036: Add format_provider for lldb::StateType

2017-01-24 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL292920: Add format_provider for lldb::StateType (authored by 
labath).

Changed prior to commit:
  https://reviews.llvm.org/D29036?vs=85419&id=85559#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29036

Files:
  lldb/trunk/include/lldb/Core/State.h
  lldb/trunk/source/Core/State.cpp
  lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/trunk/unittests/Core/CMakeLists.txt
  lldb/trunk/unittests/Core/StateTest.cpp

Index: lldb/trunk/unittests/Core/StateTest.cpp
===
--- lldb/trunk/unittests/Core/StateTest.cpp
+++ lldb/trunk/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());
+}
Index: lldb/trunk/unittests/Core/CMakeLists.txt
===
--- lldb/trunk/unittests/Core/CMakeLists.txt
+++ lldb/trunk/unittests/Core/CMakeLists.txt
@@ -6,6 +6,7 @@
   ListenerTest.cpp
   LogTest.cpp
   ScalarTest.cpp
+  StateTest.cpp
   StructuredDataTest.cpp
   TimerTest.cpp
   )
Index: lldb/trunk/source/Core/State.cpp
===
--- lldb/trunk/source/Core/State.cpp
+++ lldb/trunk/source/Core/State.cpp
@@ -44,10 +44,7 @@
   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) {
Index: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
===
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -567,7 +567,7 @@
 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 @@
   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 @@
 }
 
 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 @@
   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 @@
 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");
   }
 }
Index: lldb/trunk/include/lldb/Core/State.h
===
--- lldb/trunk/include/lldb/Core/State.h
+++ lldb/trunk/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 @@
 
 } // namespace lldb_private
 
+namespace llvm {
+template <> struct format_provider {
+  static void format(const lldb::StateType &state, raw_ostream &Stream,
+ StringRef Style) {
+Stream 

[Lldb-commits] [PATCH] D29036: Add format_provider for lldb::StateType

2017-01-23 Thread Greg Clayton via Phabricator via lldb-commits
clayborg accepted this revision.
clayborg added a comment.
This revision is now accepted and ready to land.

Looks good as long as the test suite is happy.


https://reviews.llvm.org/D29036



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D29036: Add format_provider for lldb::StateType

2017-01-23 Thread Pavel Labath via Phabricator via lldb-commits
labath updated this revision to Diff 85419.
labath added a comment.

In this case, StateAsCString was returning a pointer to a static buffer in a
scarily non-thread-safe way. I've changed it to print "unknown" instead and test
for that.


https://reviews.llvm.org/D29036

Files:
  include/lldb/Core/State.h
  source/Core/State.cpp
  source/Plugins/Process/Linux/NativeProcessLinux.cpp
  unittests/Core/CMakeLists.txt
  unittests/Core/StateTest.cpp

Index: unittests/Core/StateTest.cpp
===
--- /dev/null
+++ 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());
+}
Index: unittests/Core/CMakeLists.txt
===
--- unittests/Core/CMakeLists.txt
+++ unittests/Core/CMakeLists.txt
@@ -6,6 +6,7 @@
   ListenerTest.cpp
   LogTest.cpp
   ScalarTest.cpp
+  StateTest.cpp
   StructuredDataTest.cpp
   TimerTest.cpp
   )
Index: source/Plugins/Process/Linux/NativeProcessLinux.cpp
===
--- source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -567,7 +567,7 @@
 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 @@
   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 @@
 }
 
 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 @@
   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 @@
 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");
   }
 }
Index: source/Core/State.cpp
===
--- source/Core/State.cpp
+++ source/Core/State.cpp
@@ -44,10 +44,7 @@
   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) {
Index: include/lldb/Core/State.h
===
--- include/lldb/Core/State.h
+++ 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 @@
 
 } // namespace lldb_private
 
+namespace llvm {
+template <> struct format_provider {
+  static void format(const lldb::StateType &state, raw_ostream &Stream,
+ StringRef Style) {
+Stream << lldb_private::StateAsCString(state);
+  }
+};
+}
+
 #endif // liblldb_State_h_
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D29036: Add format_provider for lldb::StateType

2017-01-23 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added inline comments.



Comment at: unittests/Core/StateTest.cpp:19
+  EXPECT_EQ("exited", llvm::formatv("{0}", eStateExited).str());
+  EXPECT_EQ("stopped", llvm::formatv("{0}", eStateStopped).str());
+}

Add a test like:

```
EXPECT_EQ("(null)", llvm::formatv("{0}", static_cast(-1)).str());
```


https://reviews.llvm.org/D29036



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D29036: Add format_provider for lldb::StateType

2017-01-23 Thread Greg Clayton via Phabricator via lldb-commits
clayborg requested changes to this revision.
clayborg added a comment.
This revision now requires changes to proceed.

Very close, just add a test for a bad value since someone can have code like:

  StateType state;
  llvm::formatv("{0}", state);

Just to make sure we don't crash during logging. Can remember what 
lldb_private::StateAsCString(...) returns, but I am guessing it is NULL for a 
bad state, so we need to make sure the logging won't crash with that.


https://reviews.llvm.org/D29036



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D29036: Add format_provider for lldb::StateType

2017-01-23 Thread Pavel Labath via Phabricator via lldb-commits
labath created this revision.
Herald added a subscriber: mgorny.

https://reviews.llvm.org/D29036

Files:
  include/lldb/Core/State.h
  source/Plugins/Process/Linux/NativeProcessLinux.cpp
  unittests/Core/CMakeLists.txt
  unittests/Core/StateTest.cpp

Index: unittests/Core/StateTest.cpp
===
--- /dev/null
+++ unittests/Core/StateTest.cpp
@@ -0,0 +1,20 @@
+//===-- 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());
+}
Index: unittests/Core/CMakeLists.txt
===
--- unittests/Core/CMakeLists.txt
+++ unittests/Core/CMakeLists.txt
@@ -6,6 +6,7 @@
   ListenerTest.cpp
   LogTest.cpp
   ScalarTest.cpp
+  StateTest.cpp
   StructuredDataTest.cpp
   TimerTest.cpp
   )
Index: source/Plugins/Process/Linux/NativeProcessLinux.cpp
===
--- source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -567,7 +567,7 @@
 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 @@
   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 @@
 }
 
 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 @@
   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 @@
 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");
   }
 }
Index: include/lldb/Core/State.h
===
--- include/lldb/Core/State.h
+++ 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 @@
 
 } // namespace lldb_private
 
+namespace llvm {
+template <> struct format_provider {
+  static void format(const lldb::StateType &state, raw_ostream &Stream,
+ StringRef Style) {
+Stream << lldb_private::StateAsCString(state);
+  }
+};
+}
+
 #endif // liblldb_State_h_
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits