[Lldb-commits] [lldb] r232399 - Handle PyLong return values in LLDBSwigPython_CalculateNumChildren.

Siva Chandra sivachandra at google.com
Mon Mar 16 12:01:34 PDT 2015


Author: sivachandra
Date: Mon Mar 16 14:01:33 2015
New Revision: 232399

URL: http://llvm.org/viewvc/llvm-project?rev=232399&view=rev
Log:
Handle PyLong return values in LLDBSwigPython_CalculateNumChildren.

Summary:
Also, change its return type to size_t to match the return types of
its callers.

With this change, std::vector and std::list data formatter tests
pass on Linux (when using libstdc++) with clang as well as with gcc.
These tests have also been enabled in this patch.

Test Plan: dotest.py -p <TestDataFormatterStdVector|TestDataFormatterStdList>

Reviewers: vharron, clayborg

Reviewed By: clayborg

Subscribers: zturner, lldb-commits

Differential Revision: http://reviews.llvm.org/D8337

Modified:
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
    lldb/trunk/scripts/Python/python-wrapper.swig
    lldb/trunk/source/API/SBCommandInterpreter.cpp
    lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
    lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/list/TestDataFormatterStdList.py
    lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/Makefile
    lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/TestDataFormatterStdVector.py

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h?rev=232399&r1=232398&r2=232399&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h Mon Mar 16 14:01:33 2015
@@ -119,7 +119,7 @@ public:
                                                const char *session_dictionary_name,
                                                const lldb::ProcessSP& process_sp);
     
-    typedef uint32_t        (*SWIGPythonCalculateNumChildren)                   (void *implementor);
+    typedef size_t          (*SWIGPythonCalculateNumChildren)                   (void *implementor);
     typedef void*           (*SWIGPythonGetChildAtIndex)                        (void *implementor, uint32_t idx);
     typedef int             (*SWIGPythonGetIndexOfChildWithName)                (void *implementor, const char* child_name);
     typedef void*           (*SWIGPythonCastPyObjectToSBValue)                  (void* data);

Modified: lldb/trunk/scripts/Python/python-wrapper.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-wrapper.swig?rev=232399&r1=232398&r2=232399&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/python-wrapper.swig (original)
+++ lldb/trunk/scripts/Python/python-wrapper.swig Mon Mar 16 14:01:33 2015
@@ -631,13 +631,14 @@ LLDBSwigPython_CallOptionalMember
     return py_return;
 }
 
-SWIGEXPORT uint32_t
+SWIGEXPORT size_t
 LLDBSwigPython_CalculateNumChildren
 (
     PyObject *implementor
 )
 {
-    uint32_t ret_val = UINT32_MAX;
+    size_t ret_val = UINT32_MAX;
+    bool int_match = false;
 
     static char callee_name[] = "num_children";
 
@@ -646,8 +647,27 @@ LLDBSwigPython_CalculateNumChildren
     if (!py_return)
         return ret_val;
 
-    if (PyInt_Check(py_return))
-        ret_val = PyInt_AsLong(py_return);
+    // PyInt_* are not available for Python 3 and above.
+#if PY_MAJOR_VERSION < 3
+    if (PyInt_Check (py_return))
+    {
+        int_match = true;
+        ret_val = static_cast<size_t> (PyInt_AsLong (py_return));
+    }
+#endif
+
+    // We want to check for PyLong only if the return value did not
+    // match PyInt. This is because we do not want to call PyLong_Check if
+    // PyInt_Check returns true but PyInt_AsLong generates an error.
+    if (!int_match && PyLong_Check (py_return))
+    {
+#if PY_MAJOR_VERSION < 3
+        ret_val = static_cast<size_t> (PyLong_AsUnsignedLong (py_return));
+#else
+        // PyLong_AsSize_t is available only for Python 3 and above.
+        ret_val = PyLong_AsSize_t (py_return);
+#endif
+    }
 
     Py_XDECREF(py_return);
 

Modified: lldb/trunk/source/API/SBCommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommandInterpreter.cpp?rev=232399&r1=232398&r2=232399&view=diff
==============================================================================
--- lldb/trunk/source/API/SBCommandInterpreter.cpp (original)
+++ lldb/trunk/source/API/SBCommandInterpreter.cpp Mon Mar 16 14:01:33 2015
@@ -619,7 +619,7 @@ LLDBSWIGPythonCallThreadPlan (void *impl
                               Event *event_sp,
                               bool &got_error);
 
-extern "C" uint32_t
+extern "C" size_t
 LLDBSwigPython_CalculateNumChildren (void *implementor);
 
 extern "C" void *

Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=232399&r1=232398&r2=232399&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Mon Mar 16 14:01:33 2015
@@ -2082,7 +2082,7 @@ ScriptInterpreterPython::CalculateNumChi
     if (!g_swig_calc_children)
         return 0;
 
-    uint32_t ret_val = 0;
+    size_t ret_val = 0;
     
     {
         Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);

Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/list/TestDataFormatterStdList.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/list/TestDataFormatterStdList.py?rev=232399&r1=232398&r2=232399&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/list/TestDataFormatterStdList.py (original)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/list/TestDataFormatterStdList.py Mon Mar 16 14:01:33 2015
@@ -21,8 +21,6 @@ class StdListDataFormatterTestCase(TestB
 
     @dwarf_test
     @expectedFailureFreeBSD("llvm.org/pr20548") # fails to build on lab.llvm.org buildbot
-    @expectedFailureLinux('llvm.org/pr15301', ['icc']) # LLDB prints incorrect sizes of STL containers
-    @expectedFailureGcc # llvm.org/pr17499 The data formatter cannot parse STL containers
     def test_with_dwarf_and_run_command(self):
         """Test data formatter commands."""
         self.buildDwarf()

Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/Makefile?rev=232399&r1=232398&r2=232399&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/Makefile (original)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/Makefile Mon Mar 16 14:01:33 2015
@@ -5,4 +5,11 @@ CXX_SOURCES := main.cpp
 CXXFLAGS := -O0
 USE_LIBSTDCPP := 1
 
+# clang-3.5+ outputs FullDebugInfo by default for Darwin/FreeBSD
+# # targets.  Other targets do not, which causes this test to fail.
+# # This flag enables FullDebugInfo for all targets.
+ifneq (,$(findstring clang,$(CC)))
+  CFLAGS_EXTRAS += -fstandalone-debug
+endif
+
 include $(LEVEL)/Makefile.rules

Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/TestDataFormatterStdVector.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/TestDataFormatterStdVector.py?rev=232399&r1=232398&r2=232399&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/TestDataFormatterStdVector.py (original)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/vector/TestDataFormatterStdVector.py Mon Mar 16 14:01:33 2015
@@ -21,16 +21,9 @@ class StdVectorDataFormatterTestCase(Tes
 
     @dwarf_test
     @skipIfFreeBSD
-    @expectedFailureLinux # non-core functionality, need to reenable and fix
-                          # later (DES 2014.11.07). Most likely failing because
-                          # of mis-match is version of libstdc++ supported by
-                          # the data-formatters.
     @expectedFailureIcc # llvm.org/pr15301 LLDB prints incorrect sizes of STL containers
-    @expectedFailureGcc # llvm.org/pr17499 The data formatter cannot parse STL containers
     def test_with_dwarf_and_run_command(self):
         """Test data formatter commands."""
-        if "gcc" in self.getCompiler() and "4.8" in self.getCompilerVersion():
-            self.skipTest("llvm.org/pr15301 LLDB prints incorrect sizes of STL containers")
         self.buildDwarf()
         self.data_formatter_commands()
 





More information about the lldb-commits mailing list