[Lldb-commits] [lldb] r341957 - Remove undefined behavior around the use of StateType

Shafik Yaghmour via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 11 09:08:05 PDT 2018


Author: shafik
Date: Tue Sep 11 09:08:05 2018
New Revision: 341957

URL: http://llvm.org/viewvc/llvm-project?rev=341957&view=rev
Log:
Remove undefined behavior around the use of StateType

rdar://problem/43530233

Patch by Shafik Yaghmour.

Differential Revision: https://reviews.llvm.org/D51445

Modified:
    lldb/trunk/include/lldb/lldb-enumerations.h
    lldb/trunk/scripts/Python/python-typemaps.swig
    lldb/trunk/unittests/Utility/StateTest.cpp

Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=341957&r1=341956&r2=341957&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Tue Sep 11 09:08:05 2018
@@ -54,9 +54,10 @@ enum StateType {
   eStateCrashed,   ///< Process or thread has crashed and can be examined.
   eStateDetached,  ///< Process has been detached and can't be examined.
   eStateExited,    ///< Process has exited and can't be examined.
-  eStateSuspended  ///< Process or thread is in a suspended state as far
+  eStateSuspended, ///< Process or thread is in a suspended state as far
                    ///< as the debugger is concerned while other processes
                    ///< or threads get the chance to run.
+  kLastStateType = eStateSuspended  
 };
 
 //----------------------------------------------------------------------

Modified: lldb/trunk/scripts/Python/python-typemaps.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-typemaps.swig?rev=341957&r1=341956&r2=341957&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/python-typemaps.swig (original)
+++ lldb/trunk/scripts/Python/python-typemaps.swig Tue Sep 11 09:08:05 2018
@@ -77,6 +77,26 @@
   }
 }
 
+%typemap(in) lldb::StateType {
+  using namespace lldb_private;
+  if (PythonInteger::Check($input))
+  {
+    PythonInteger py_int(PyRefType::Borrowed, $input);
+    int64_t state_type_value = py_int.GetInteger() ;
+
+    if (state_type_value > lldb::StateType::kLastStateType) {
+      PyErr_SetString(PyExc_ValueError, "Not a valid StateType value");
+      return nullptr;
+    }
+    $1 = static_cast<lldb::StateType>(state_type_value);
+  }
+  else
+  {
+    PyErr_SetString(PyExc_ValueError, "Expecting an integer");
+    return nullptr;
+  }
+}
+
 /* Typemap definitions to allow SWIG to properly handle char buffer. */
 
 // typemap for a char buffer

Modified: lldb/trunk/unittests/Utility/StateTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/StateTest.cpp?rev=341957&r1=341956&r2=341957&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/StateTest.cpp (original)
+++ lldb/trunk/unittests/Utility/StateTest.cpp Tue Sep 11 09:08:05 2018
@@ -15,7 +15,17 @@ using namespace lldb;
 using namespace lldb_private;
 
 TEST(StateTest, Formatv) {
-  EXPECT_EQ("exited", llvm::formatv("{0}", eStateExited).str());
+  EXPECT_EQ("invalid", llvm::formatv("{0}", eStateInvalid).str());
+  EXPECT_EQ("unloaded", llvm::formatv("{0}", eStateUnloaded).str());
+  EXPECT_EQ("connected", llvm::formatv("{0}", eStateConnected).str());
+  EXPECT_EQ("attaching", llvm::formatv("{0}", eStateAttaching).str());
+  EXPECT_EQ("launching", llvm::formatv("{0}", eStateLaunching).str());
   EXPECT_EQ("stopped", llvm::formatv("{0}", eStateStopped).str());
-  EXPECT_EQ("unknown", llvm::formatv("{0}", StateType(-1)).str());
+  EXPECT_EQ("running", llvm::formatv("{0}", eStateRunning).str());
+  EXPECT_EQ("stepping", llvm::formatv("{0}", eStateStepping).str());
+  EXPECT_EQ("crashed", llvm::formatv("{0}", eStateCrashed).str());
+  EXPECT_EQ("detached", llvm::formatv("{0}", eStateDetached).str());
+  EXPECT_EQ("exited", llvm::formatv("{0}", eStateExited).str());
+  EXPECT_EQ("suspended", llvm::formatv("{0}", eStateSuspended).str());
+  
 }




More information about the lldb-commits mailing list