[Lldb-commits] [lldb] r146899 - in /lldb/trunk: source/API/SBModule.cpp source/API/SBSection.cpp test/python_api/module_section/TestModuleAndSection.py

Johnny Chen johnny.chen at apple.com
Mon Dec 19 12:16:22 PST 2011


Author: johnny
Date: Mon Dec 19 14:16:22 2011
New Revision: 146899

URL: http://llvm.org/viewvc/llvm-project?rev=146899&view=rev
Log:
Work in progress for:

rdar://problem/10577182
Audit lldb API impl for places where we need to perform a NULL check

Add NULL checks for SBModule and SBSection APIs.

Modified:
    lldb/trunk/source/API/SBModule.cpp
    lldb/trunk/source/API/SBSection.cpp
    lldb/trunk/test/python_api/module_section/TestModuleAndSection.py

Modified: lldb/trunk/source/API/SBModule.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBModule.cpp?rev=146899&r1=146898&r2=146899&view=diff
==============================================================================
--- lldb/trunk/source/API/SBModule.cpp (original)
+++ lldb/trunk/source/API/SBModule.cpp Mon Dec 19 14:16:22 2011
@@ -342,7 +342,7 @@
 {
     if (!append)
         sc_list.Clear();
-    if (m_opaque_sp)
+    if (name && m_opaque_sp)
     {
         const bool symbols_ok = true;
         return m_opaque_sp->FindFunctions (ConstString(name),
@@ -360,7 +360,7 @@
 SBModule::FindGlobalVariables (SBTarget &target, const char *name, uint32_t max_matches)
 {
     SBValueList sb_value_list;
-    if (m_opaque_sp)
+    if (name && m_opaque_sp)
     {
         VariableList variable_list;
         const uint32_t match_count = m_opaque_sp->FindGlobalVariables (ConstString (name),
@@ -389,10 +389,10 @@
 }
 
 lldb::SBType
-SBModule::FindFirstType (const char* name_cstr)
+SBModule::FindFirstType (const char *name_cstr)
 {
     SBType sb_type;
-    if (IsValid())
+    if (name_cstr && IsValid())
     {
         SymbolContext sc;
         TypeList type_list;
@@ -413,12 +413,12 @@
 }
 
 lldb::SBTypeList
-SBModule::FindTypes (const char* type)
+SBModule::FindTypes (const char *type)
 {
     
     SBTypeList retval;
     
-    if (IsValid())
+    if (type && IsValid())
     {
         SymbolContext sc;
         TypeList type_list;
@@ -449,7 +449,7 @@
 {
     SBSection sb_section;
     
-    if (IsValid())
+    if (sect_name && IsValid())
     {
         ObjectFile *objfile = m_opaque_sp->GetObjectFile();
         if (objfile)

Modified: lldb/trunk/source/API/SBSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSection.cpp?rev=146899&r1=146898&r2=146899&view=diff
==============================================================================
--- lldb/trunk/source/API/SBSection.cpp (original)
+++ lldb/trunk/source/API/SBSection.cpp Mon Dec 19 14:16:22 2011
@@ -142,7 +142,7 @@
 SBSection::FindSubSection (const char *sect_name)
 {
     lldb::SBSection sb_section;
-    if (IsValid())
+    if (sect_name && IsValid())
     {
         ConstString const_sect_name(sect_name);
         sb_section.SetSection(m_opaque_ap->GetSection()->GetChildren ().FindSectionByName(const_sect_name).get());

Modified: lldb/trunk/test/python_api/module_section/TestModuleAndSection.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/module_section/TestModuleAndSection.py?rev=146899&r1=146898&r2=146899&view=diff
==============================================================================
--- lldb/trunk/test/python_api/module_section/TestModuleAndSection.py (original)
+++ lldb/trunk/test/python_api/module_section/TestModuleAndSection.py Mon Dec 19 14:16:22 2011
@@ -19,6 +19,12 @@
         self.buildDefault()
         self.module_and_section()
 
+    @python_api_test
+    def test_module_and_section_boundary_condition(self):
+        """Test module and section APIs by passing None when it expects a Python string."""
+        self.buildDefault()
+        self.module_and_section_boundary_condition()
+
     def module_and_section(self):
         exe = os.path.join(os.getcwd(), "a.out")
 
@@ -56,6 +62,43 @@
                         print INDENT2 + repr(sym)
                         print INDENT2 + "symbol type: %s" % symbol_type_to_str(sym.GetType())
 
+    def module_and_section_boundary_condition(self):
+        exe = os.path.join(os.getcwd(), "a.out")
+
+        target = self.dbg.CreateTarget(exe)
+        self.assertTrue(target, VALID_TARGET)
+        self.assertTrue(target.GetNumModules() > 0)
+
+        # Hide stdout if not running with '-t' option.
+        if not self.TraceOn():
+            self.HideStdout()
+
+        print "Number of modules for the target: %d" % target.GetNumModules()
+        for module in target.module_iter():
+            print module
+
+        # Get the executable module at index 0.
+        exe_module = target.GetModuleAtIndex(0)
+
+        print "Exe module: %s" % repr(exe_module)
+        print "Number of sections: %d" % exe_module.GetNumSections()
+
+        # Boundary condition testings.  Should not crash lldb!
+        exe_module.FindFirstType(None)
+        exe_module.FindTypes(None)
+        exe_module.FindGlobalVariables(target, None, 1)
+        exe_module.FindFunctions(None, 0, True, lldb.SBSymbolContextList())
+        exe_module.FindSection(None)
+
+        # Get the section at index 1.
+        if exe_module.GetNumSections() > 1:
+            sec1 = exe_module.GetSectionAtIndex(1)
+            print sec1
+        else:
+            sec1 = None
+
+        if sec1:
+            sec1.FindSubSection(None)
 
 if __name__ == '__main__':
     import atexit





More information about the lldb-commits mailing list