[Lldb-commits] [lldb] r121748 - in /lldb/trunk: include/lldb/API/SBBlock.h include/lldb/API/SBCompileUnit.h include/lldb/API/SBFunction.h include/lldb/API/SBSymbol.h lldb.xcodeproj/project.pbxproj source/API/SBBlock.cpp source/API/SBCompileUnit.cpp source/API/SBFrame.cpp source/API/SBFunction.cpp source/API/SBSymbol.cpp

Greg Clayton gclayton at apple.com
Mon Dec 13 20:58:53 PST 2010


Author: gclayton
Date: Mon Dec 13 22:58:53 2010
New Revision: 121748

URL: http://llvm.org/viewvc/llvm-project?rev=121748&view=rev
Log:
Fixed SBFrame to properly check to make sure it has a valid m_opaque_sp object
before trying to use it.


Modified:
    lldb/trunk/include/lldb/API/SBBlock.h
    lldb/trunk/include/lldb/API/SBCompileUnit.h
    lldb/trunk/include/lldb/API/SBFunction.h
    lldb/trunk/include/lldb/API/SBSymbol.h
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/source/API/SBBlock.cpp
    lldb/trunk/source/API/SBCompileUnit.cpp
    lldb/trunk/source/API/SBFrame.cpp
    lldb/trunk/source/API/SBFunction.cpp
    lldb/trunk/source/API/SBSymbol.cpp

Modified: lldb/trunk/include/lldb/API/SBBlock.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBBlock.h?rev=121748&r1=121747&r2=121748&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBBlock.h (original)
+++ lldb/trunk/include/lldb/API/SBBlock.h Mon Dec 13 22:58:53 2010
@@ -68,6 +68,9 @@
     const lldb_private::Block *
     get () const;
 
+    void
+    reset (lldb_private::Block *lldb_object_ptr);
+
     SBBlock (lldb_private::Block *lldb_object_ptr);
 
     void

Modified: lldb/trunk/include/lldb/API/SBCompileUnit.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBCompileUnit.h?rev=121748&r1=121747&r2=121748&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBCompileUnit.h (original)
+++ lldb/trunk/include/lldb/API/SBCompileUnit.h Mon Dec 13 22:58:53 2010
@@ -77,6 +77,9 @@
     const lldb_private::CompileUnit *
     get () const;
 
+    void
+    reset (lldb_private::CompileUnit *lldb_object_ptr);
+
 #endif
 
     lldb_private::CompileUnit *m_opaque_ptr;

Modified: lldb/trunk/include/lldb/API/SBFunction.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFunction.h?rev=121748&r1=121747&r2=121748&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBFunction.h (original)
+++ lldb/trunk/include/lldb/API/SBFunction.h Mon Dec 13 22:58:53 2010
@@ -56,9 +56,16 @@
 
 protected:
 
+#ifndef SWIG
+
     lldb_private::Function *
     get ();
 
+    void
+    reset (lldb_private::Function *lldb_object_ptr);
+
+#endif
+
 private:
     friend class SBFrame;
     friend class SBSymbolContext;

Modified: lldb/trunk/include/lldb/API/SBSymbol.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBSymbol.h?rev=121748&r1=121747&r2=121748&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBSymbol.h (original)
+++ lldb/trunk/include/lldb/API/SBSymbol.h Mon Dec 13 22:58:53 2010
@@ -57,8 +57,13 @@
 
 protected:
 
+#ifndef SWIG
     lldb_private::Symbol *
     get ();
+
+    void
+    reset (lldb_private::Symbol *);
+#endif
     
 private:
     friend class SBFrame;

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=121748&r1=121747&r2=121748&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Mon Dec 13 22:58:53 2010
@@ -2459,6 +2459,7 @@
 			isa = PBXProject;
 			buildConfigurationList = 1DEB91EF08733DB70010E9CD /* Build configuration list for PBXProject "lldb" */;
 			compatibilityVersion = "Xcode 3.1";
+			developmentRegion = English;
 			hasScannedForEncodings = 1;
 			knownRegions = (
 				en,

Modified: lldb/trunk/source/API/SBBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBBlock.cpp?rev=121748&r1=121747&r2=121748&view=diff
==============================================================================
--- lldb/trunk/source/API/SBBlock.cpp (original)
+++ lldb/trunk/source/API/SBBlock.cpp Mon Dec 13 22:58:53 2010
@@ -151,6 +151,11 @@
     return m_opaque_ptr;
 }
 
+void
+SBBlock::reset (lldb_private::Block *block)
+{
+    m_opaque_ptr = block;
+}
 
 bool
 SBBlock::GetDescription (SBStream &description)

Modified: lldb/trunk/source/API/SBCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCompileUnit.cpp?rev=121748&r1=121747&r2=121748&view=diff
==============================================================================
--- lldb/trunk/source/API/SBCompileUnit.cpp (original)
+++ lldb/trunk/source/API/SBCompileUnit.cpp Mon Dec 13 22:58:53 2010
@@ -170,6 +170,13 @@
 {
     return m_opaque_ptr;
 }
+
+void
+SBCompileUnit::reset (lldb_private::CompileUnit *lldb_object_ptr)
+{
+    m_opaque_ptr = lldb_object_ptr;
+}
+
     
 bool
 SBCompileUnit::GetDescription (SBStream &description)

Modified: lldb/trunk/source/API/SBFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=121748&r1=121747&r2=121748&view=diff
==============================================================================
--- lldb/trunk/source/API/SBFrame.cpp (original)
+++ lldb/trunk/source/API/SBFrame.cpp Mon Dec 13 22:58:53 2010
@@ -122,7 +122,10 @@
 SBModule
 SBFrame::GetModule () const
 {
-    SBModule sb_module (m_opaque_sp->GetSymbolContext (eSymbolContextModule).module_sp);
+    SBModule sb_module;
+    if (m_opaque_sp)
+        *sb_module = m_opaque_sp->GetSymbolContext (eSymbolContextModule).module_sp;
+
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)", 
@@ -134,8 +137,9 @@
 SBCompileUnit
 SBFrame::GetCompileUnit () const
 {
-    SBCompileUnit sb_comp_unit(m_opaque_sp->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
-
+    SBCompileUnit sb_comp_unit;
+    if (m_opaque_sp)
+        sb_comp_unit.reset (m_opaque_sp->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::GetModule () => SBCompileUnit(%p)", 
@@ -147,8 +151,9 @@
 SBFunction
 SBFrame::GetFunction () const
 {
-    SBFunction sb_function(m_opaque_sp->GetSymbolContext (eSymbolContextFunction).function);
-
+    SBFunction sb_function;
+    if (m_opaque_sp)
+        sb_function.reset(m_opaque_sp->GetSymbolContext (eSymbolContextFunction).function);
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)", 
@@ -160,7 +165,9 @@
 SBSymbol
 SBFrame::GetSymbol () const
 {
-    SBSymbol sb_symbol(m_opaque_sp->GetSymbolContext (eSymbolContextSymbol).symbol);
+    SBSymbol sb_symbol;
+    if (m_opaque_sp)
+        sb_symbol.reset(m_opaque_sp->GetSymbolContext (eSymbolContextSymbol).symbol);
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)", 
@@ -171,7 +178,9 @@
 SBBlock
 SBFrame::GetBlock () const
 {
-    SBBlock sb_block(m_opaque_sp->GetSymbolContext (eSymbolContextBlock).block);
+    SBBlock sb_block;
+    if (m_opaque_sp)
+        sb_block.reset (m_opaque_sp->GetSymbolContext (eSymbolContextBlock).block);
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)", 
@@ -182,7 +191,9 @@
 SBBlock
 SBFrame::GetFrameBlock () const
 {
-    SBBlock sb_block(m_opaque_sp->GetFrameBlock ());
+    SBBlock sb_block;
+    if (m_opaque_sp)
+        sb_block.reset(m_opaque_sp->GetFrameBlock ());
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)", 
@@ -193,7 +204,9 @@
 SBLineEntry
 SBFrame::GetLineEntry () const
 {
-    SBLineEntry sb_line_entry(&m_opaque_sp->GetSymbolContext (eSymbolContextLineEntry).line_entry);
+    SBLineEntry sb_line_entry;
+    if (m_opaque_sp)
+        sb_line_entry.SetLineEntry (m_opaque_sp->GetSymbolContext (eSymbolContextLineEntry).line_entry);
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
         log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)", 
@@ -216,7 +229,6 @@
 lldb::addr_t
 SBFrame::GetPC () const
 {
-
     lldb::addr_t addr = LLDB_INVALID_ADDRESS;
     if (m_opaque_sp)
         addr = m_opaque_sp->GetFrameCodeAddress().GetLoadAddress (&m_opaque_sp->GetThread().GetProcess().GetTarget());
@@ -231,7 +243,6 @@
 bool
 SBFrame::SetPC (lldb::addr_t new_pc)
 {
-
     bool ret_val = false;
     if (m_opaque_sp)
         ret_val = m_opaque_sp->GetRegisterContext()->SetPC (new_pc);
@@ -294,27 +305,26 @@
 SBFrame::LookupVar (const char *var_name)
 {
     lldb::VariableSP var_sp;
-    if (IsValid ())
+    if (m_opaque_sp && var_name && var_name[0])
     {
         lldb_private::VariableList variable_list;
-        SBSymbolContext sc = GetSymbolContext (eSymbolContextEverything);
-
-        SBBlock block = sc.GetBlock();
-        if (block.IsValid())
-            block.AppendVariables (true, true, &variable_list);
 
-        const uint32_t num_variables = variable_list.GetSize();
+        SymbolContext sc (m_opaque_sp->GetSymbolContext (eSymbolContextBlock));
 
-        bool found = false;
-        for (uint32_t i = 0; i < num_variables && !found; ++i)
+        if (sc.block)
         {
-            var_sp = variable_list.GetVariableAtIndex(i);
-            if (var_sp
-                && (var_sp.get()->GetName() == lldb_private::ConstString(var_name)))
-                found = true;
+            const bool can_create = true;
+            const bool get_parent_variables = true;
+            const bool stop_if_block_is_inlined_function = true;
+            
+            if (sc.block->AppendVariables (can_create, 
+                                           get_parent_variables,
+                                           stop_if_block_is_inlined_function,
+                                           &variable_list))
+            {
+                var_sp = variable_list.FindVariable (lldb_private::ConstString(var_name));
+            }
         }
-        if (!found)
-            var_sp.reset();
     }
     
     SBValue sb_value;
@@ -334,7 +344,7 @@
 SBFrame::LookupVarInScope (const char *var_name, const char *scope)
 {
     lldb::VariableSP var_sp;
-    if (IsValid())
+    if (m_opaque_sp && var_name && var_name[0] && scope && scope[0])
     {
         std::string scope_str = scope;
         lldb::ValueType var_scope = eValueTypeInvalid;
@@ -350,24 +360,31 @@
 
         if (var_scope != eValueTypeInvalid)
         {
-            lldb_private::VariableList *variable_list = m_opaque_sp->GetVariableList(true);
-            if (variable_list)
+            lldb_private::VariableList variable_list;
+
+            SymbolContext sc (m_opaque_sp->GetSymbolContext (eSymbolContextBlock));
+
+            const bool can_create = true;
+            const bool get_parent_variables = true;
+            const bool stop_if_block_is_inlined_function = true;
+
+            if (sc.block && sc.block->AppendVariables (can_create, 
+                                                       get_parent_variables,
+                                                       stop_if_block_is_inlined_function,
+                                                       &variable_list))
             {
-                const uint32_t num_variables = variable_list->GetSize();
-                bool found = false;
-                for (uint32_t i = 0; i < num_variables && !found; ++i)
+                lldb_private::ConstString const_var_name(var_name);
+                const uint32_t num_variables = variable_list.GetSize();
+                for (uint32_t i = 0; i < num_variables; ++i)
                 {
-                    var_sp = variable_list->GetVariableAtIndex(i);
-                    if (var_sp
-                        && (var_sp.get()->GetName() == lldb_private::ConstString(var_name))
-                        && var_sp.get()->GetScope() == var_scope)
+                    lldb::VariableSP curr_var_sp (variable_list.GetVariableAtIndex(i));
+                    if (curr_var_sp && curr_var_sp->GetScope() == var_scope &&
+                        curr_var_sp->GetName() == const_var_name)
                     {
-                        found = true;
+                        var_sp = curr_var_sp;
                         break;
                     }
                 }
-                if (!found)
-                    var_sp.reset();
             }
         }
     }
@@ -415,10 +432,9 @@
 {
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
 
-    //if (log)
-    //    log->Printf ("SBFrame::GetThread ()");
-
-    SBThread sb_thread (m_opaque_sp->GetThread().GetSP());
+    SBThread sb_thread;
+    if (m_opaque_sp)
+        sb_thread.SetThread (m_opaque_sp->GetThread().GetSP());
 
     if (log)
     {

Modified: lldb/trunk/source/API/SBFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFunction.cpp?rev=121748&r1=121747&r2=121748&view=diff
==============================================================================
--- lldb/trunk/source/API/SBFunction.cpp (original)
+++ lldb/trunk/source/API/SBFunction.cpp Mon Dec 13 22:58:53 2010
@@ -148,3 +148,9 @@
     return m_opaque_ptr;
 }
 
+void
+SBFunction::reset (lldb_private::Function *lldb_object_ptr)
+{
+    m_opaque_ptr = lldb_object_ptr;
+}
+

Modified: lldb/trunk/source/API/SBSymbol.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSymbol.cpp?rev=121748&r1=121747&r2=121748&view=diff
==============================================================================
--- lldb/trunk/source/API/SBSymbol.cpp (original)
+++ lldb/trunk/source/API/SBSymbol.cpp Mon Dec 13 22:58:53 2010
@@ -143,3 +143,9 @@
 {
     return m_opaque_ptr;
 }
+
+void
+SBSymbol::reset (lldb_private::Symbol *symbol)
+{
+    m_opaque_ptr = symbol;
+}





More information about the lldb-commits mailing list