[Lldb-commits] [lldb] r140822 - in /lldb/trunk: include/lldb/Symbol/Block.h include/lldb/lldb-private-log.h source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp source/Symbol/Block.cpp source/lldb-log.cpp

Greg Clayton gclayton at apple.com
Thu Sep 29 16:41:34 PDT 2011


Author: gclayton
Date: Thu Sep 29 18:41:34 2011
New Revision: 140822

URL: http://llvm.org/viewvc/llvm-project?rev=140822&view=rev
Log:
Fixed an issue where a lexical block or inlined function might have bad debug
information generated for it. Say we have a concrete function "foo" which
has inlined function "a" which calls another inlined function "b":

    foo
1   {
2       {
            a ()
3           {
                b ()
4               {
                
                }
            }
        }
    }
    
Sometimes we see the compiler generate an address range in the DWARF for "foo"
(block 1 above) as say [0x1000-0x1100). Then the range for "a" is something
like [0x1050-0x1060) (note that it is correctly scoped within the "foo" 
address range). And then we get "b" which is a child of "a", yet the debug
info says it has a range of [0x1060-0x1080) (not contained within "a"). We now
detect this issue when making our blocks and add an extra range to "a".

Also added a new "lldb" logging category named "symbol" where we can find out
about symbol file errors and warnings.


Modified:
    lldb/trunk/include/lldb/Symbol/Block.h
    lldb/trunk/include/lldb/lldb-private-log.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/trunk/source/Symbol/Block.cpp
    lldb/trunk/source/lldb-log.cpp

Modified: lldb/trunk/include/lldb/Symbol/Block.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Block.h?rev=140822&r1=140821&r2=140822&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/Block.h (original)
+++ lldb/trunk/include/lldb/Symbol/Block.h Thu Sep 29 18:41:34 2011
@@ -97,7 +97,7 @@
     ///     describes the end address of a range for this block.
     //------------------------------------------------------------------
     void
-    AddRange(lldb::addr_t start_offset, lldb::addr_t end_offset);
+    AddRange (const VMRange& range);
 
     //------------------------------------------------------------------
     /// @copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*)

Modified: lldb/trunk/include/lldb/lldb-private-log.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-private-log.h?rev=140822&r1=140821&r2=140822&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-private-log.h (original)
+++ lldb/trunk/include/lldb/lldb-private-log.h Thu Sep 29 18:41:34 2011
@@ -39,6 +39,7 @@
 #define LIBLLDB_LOG_SCRIPT              (1u << 17)
 #define LIBLLDB_LOG_COMMANDS            (1U << 18)
 #define LIBLLDB_LOG_TYPES               (1u << 19)
+#define LIBLLDB_LOG_SYMBOLS             (1u << 20)
 #define LIBLLDB_LOG_ALL                 (UINT32_MAX)
 #define LIBLLDB_LOG_DEFAULT             (LIBLLDB_LOG_PROCESS              |\
                                          LIBLLDB_LOG_THREAD               |\
@@ -47,6 +48,7 @@
                                          LIBLLDB_LOG_WATCHPOINTS          |\
                                          LIBLLDB_LOG_STEP                 |\
                                          LIBLLDB_LOG_STATE                |\
+                                         LIBLLDB_LOG_SYMBOLS              |\
                                          LIBLLDB_LOG_COMMANDS)
 
 namespace lldb_private {

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=140822&r1=140821&r2=140822&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Thu Sep 29 18:41:34 2011
@@ -635,7 +635,7 @@
     const DWARFDebugRanges::Range *debug_range;
     for (range_idx = 0; (debug_range = ranges.RangeAtIndex(range_idx)) != NULL; range_idx++)
     {
-        block.AddRange(debug_range->begin_offset, debug_range->end_offset);
+        block.AddRange(VMRange (debug_range->begin_offset, debug_range->end_offset));
     }
 }
 

Modified: lldb/trunk/source/Symbol/Block.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Block.cpp?rev=140822&r1=140821&r2=140822&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Block.cpp (original)
+++ lldb/trunk/source/Symbol/Block.cpp Thu Sep 29 18:41:34 2011
@@ -8,9 +8,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/Symbol/Block.h"
-#include "lldb/Symbol/Function.h"
+
+#include "lldb/lldb-private-log.h"
+
+#include "lldb/Core/Log.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/Section.h"
+#include "lldb/Symbol/Function.h"
 #include "lldb/Symbol/SymbolFile.h"
 #include "lldb/Symbol/SymbolVendor.h"
 #include "lldb/Symbol/VariableList.h"
@@ -433,10 +437,53 @@
 }
 
 void
-Block::AddRange(addr_t start_offset, addr_t end_offset)
+Block::AddRange (const VMRange& new_range)
 {
-    m_ranges.resize(m_ranges.size()+1);
-    m_ranges.back().Reset(start_offset, end_offset);
+    Block *parent_block = GetParent ();
+    if (parent_block && !parent_block->Contains(new_range))
+    {
+        LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SYMBOLS));
+        if (log)
+        {
+            Module *module = m_parent_scope->CalculateSymbolContextModule();
+            Function *function = m_parent_scope->CalculateSymbolContextFunction();
+            const addr_t function_file_addr = function->GetAddressRange().GetBaseAddress().GetFileAddress();
+            const addr_t block_start_addr = function_file_addr + new_range.GetBaseAddress ();
+            const addr_t block_end_addr = function_file_addr + new_range.GetEndAddress ();
+            Type *func_type = function->GetType();
+            
+            const Declaration &func_decl = func_type->GetDeclaration();
+            if (func_decl.GetLine())
+            {
+                log->Printf ("warning: %s/%s:%u block {0x%8.8x} has range[%u] [0x%llx - 0x%llx) which is not contained in parent block {0x%8.8x} in function {0x%8.8x} from %s/%s",
+                             func_decl.GetFile().GetDirectory().GetCString(),
+                             func_decl.GetFile().GetFilename().GetCString(),
+                             func_decl.GetLine(),
+                             GetID(),
+                             (uint32_t)m_ranges.size(),
+                             block_start_addr,
+                             block_end_addr,
+                             parent_block->GetID(),
+                             function->GetID(),
+                             module->GetFileSpec().GetDirectory().GetCString(),
+                             module->GetFileSpec().GetFilename().GetCString());
+            }
+            else
+            {
+                log->Printf ("warning: block {0x%8.8x} has range[%u] [0x%llx - 0x%llx) which is not contained in parent block {0x%8.8x} in function {0x%8.8x} from %s/%s",
+                             GetID(),
+                             (uint32_t)m_ranges.size(),
+                             block_start_addr,
+                             block_end_addr,
+                             parent_block->GetID(),
+                             function->GetID(),
+                             module->GetFileSpec().GetDirectory().GetCString(),
+                             module->GetFileSpec().GetFilename().GetCString());
+            }
+        }
+        parent_block->AddRange (new_range);
+    }
+    m_ranges.push_back(new_range);
 }
 
 // Return the current number of bytes that this object occupies in memory
@@ -605,7 +652,7 @@
 {
     if (m_parent_scope)
     {
-        Block *parent_block = m_parent_scope->CalculateSymbolContextBlock();
+        Block *parent_block = GetParent();
         if (parent_block)
             return parent_block->GetSiblingForChild (this);
     }

Modified: lldb/trunk/source/lldb-log.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/lldb-log.cpp?rev=140822&r1=140821&r2=140822&view=diff
==============================================================================
--- lldb/trunk/source/lldb-log.cpp (original)
+++ lldb/trunk/source/lldb-log.cpp Thu Sep 29 18:41:34 2011
@@ -135,6 +135,7 @@
                 else if (0 == ::strncasecmp(arg, "host", 4))    flag_bits &= ~LIBLLDB_LOG_HOST;
                 else if (0 == ::strncasecmp(arg, "unwind", 6))  flag_bits &= ~LIBLLDB_LOG_UNWIND;
                 else if (0 == ::strncasecmp(arg, "types", 5))   flag_bits &= ~LIBLLDB_LOG_TYPES;
+                else if (0 == ::strncasecmp(arg, "symbol", 6))  flag_bits &= ~LIBLLDB_LOG_SYMBOLS;
                 else
                 {
                     feedback_strm->Printf ("error:  unrecognized log category '%s'\n", arg);
@@ -202,6 +203,7 @@
             else if (0 == ::strncasecmp(arg, "host", 4))    flag_bits |= LIBLLDB_LOG_HOST;
             else if (0 == ::strncasecmp(arg, "unwind", 6))  flag_bits |= LIBLLDB_LOG_UNWIND;
             else if (0 == ::strncasecmp(arg, "types", 5))   flag_bits |= LIBLLDB_LOG_TYPES;
+            else if (0 == ::strncasecmp(arg, "symbol", 6))  flag_bits |= LIBLLDB_LOG_SYMBOLS;
             else
             {
                 feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
@@ -241,6 +243,7 @@
         "  step - log step related activities\n"
         "  unwind - log stack unwind activities\n"
         "  verbose - enable verbose logging\n"
+        "  symbol - log symbol related issues and warnings\n"
         "  watch - log watchpoint related activities\n"
         "  types - log type system related activities\n");
 }





More information about the lldb-commits mailing list