[Lldb-commits] [PATCH] D51445: Remove undefined behavior around the use of StateType
Shafik Yaghmour via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 30 17:02:30 PDT 2018
shafik updated this revision to Diff 163450.
shafik marked an inline comment as done.
shafik added a comment.
Switching enum guard to kLastStateType which references the last valid enum which lead to cleaner code instead of inventing a new value which does not have a good meaning in many cases.
https://reviews.llvm.org/D51445
Files:
include/lldb/lldb-enumerations.h
scripts/Python/python-typemaps.swig
unittests/Utility/StateTest.cpp
Index: unittests/Utility/StateTest.cpp
===================================================================
--- unittests/Utility/StateTest.cpp
+++ unittests/Utility/StateTest.cpp
@@ -15,7 +15,17 @@
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());
+
}
Index: scripts/Python/python-typemaps.swig
===================================================================
--- scripts/Python/python-typemaps.swig
+++ scripts/Python/python-typemaps.swig
@@ -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
Index: include/lldb/lldb-enumerations.h
===================================================================
--- include/lldb/lldb-enumerations.h
+++ include/lldb/lldb-enumerations.h
@@ -54,9 +54,10 @@
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
};
//----------------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51445.163450.patch
Type: text/x-patch
Size: 2936 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180831/32ee496b/attachment.bin>
More information about the lldb-commits
mailing list