[Lldb-commits] [lldb] r151878 - in /lldb/trunk: include/lldb/Symbol/Symbol.h source/Symbol/Symbol.cpp source/Symbol/SymbolContext.cpp source/Symbol/Symtab.cpp

Greg Clayton gclayton at apple.com
Thu Mar 1 19:01:16 PST 2012


Author: gclayton
Date: Thu Mar  1 21:01:16 2012
New Revision: 151878

URL: http://llvm.org/viewvc/llvm-project?rev=151878&view=rev
Log:
Fixed Symbol objects being able to get their byte size.


Modified:
    lldb/trunk/include/lldb/Symbol/Symbol.h
    lldb/trunk/source/Symbol/Symbol.cpp
    lldb/trunk/source/Symbol/SymbolContext.cpp
    lldb/trunk/source/Symbol/Symtab.cpp

Modified: lldb/trunk/include/lldb/Symbol/Symbol.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Symbol.h?rev=151878&r1=151877&r2=151878&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/Symbol.h (original)
+++ lldb/trunk/include/lldb/Symbol/Symbol.h Thu Mar  1 21:01:16 2012
@@ -108,7 +108,7 @@
     GetSiblingIndex () const;
 
     lldb::addr_t
-    GetByteSize () const { return m_addr_range.GetByteSize(); }
+    GetByteSize () const;
 
     lldb::SymbolType
     GetType () const { return (lldb::SymbolType)m_type; }
@@ -211,6 +211,7 @@
                     m_is_external:1,        // non-zero if this symbol is globally visible
                     m_size_is_sibling:1,    // m_size contains the index of this symbol's sibling
                     m_size_is_synthesized:1,// non-zero if this symbol's size was calculated using a delta between this symbol and the next
+                    m_calculated_size:1,
                     m_type:8;
     uint32_t        m_flags;                // A copy of the flags from the original symbol table, the ObjectFile plug-in can interpret these
     AddressRange    m_addr_range;           // Contains the value, or the section offset address when the value is an address in a section, and the size (if any)

Modified: lldb/trunk/source/Symbol/Symbol.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symbol.cpp?rev=151878&r1=151877&r2=151878&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Symbol.cpp (original)
+++ lldb/trunk/source/Symbol/Symbol.cpp Thu Mar  1 21:01:16 2012
@@ -30,6 +30,7 @@
     m_is_external (false),
     m_size_is_sibling (false),
     m_size_is_synthesized (false),
+    m_calculated_size (false),
     m_type (eSymbolTypeInvalid),
     m_flags (),
     m_addr_range ()
@@ -61,6 +62,7 @@
     m_is_external (external),
     m_size_is_sibling (false),
     m_size_is_synthesized (false),
+    m_calculated_size (size > 0),
     m_type (type),
     m_flags (flags),
     m_addr_range (section_sp, offset, size)
@@ -90,6 +92,7 @@
     m_is_external (external),
     m_size_is_sibling (false),
     m_size_is_synthesized (false),
+    m_calculated_size (range.GetByteSize() > 0),
     m_type (type),
     m_flags (flags),
     m_addr_range (range)
@@ -107,6 +110,7 @@
     m_is_external (rhs.m_is_external),
     m_size_is_sibling (rhs.m_size_is_sibling),
     m_size_is_synthesized (false),
+    m_calculated_size (rhs.m_calculated_size),
     m_type (rhs.m_type),
     m_flags (rhs.m_flags),
     m_addr_range (rhs.m_addr_range)
@@ -128,6 +132,7 @@
         m_is_external = rhs.m_is_external;
         m_size_is_sibling = rhs.m_size_is_sibling;
         m_size_is_synthesized = rhs.m_size_is_sibling;
+        m_calculated_size = rhs.m_calculated_size;
         m_type = rhs.m_type;
         m_flags = rhs.m_flags;
         m_addr_range = rhs.m_addr_range;
@@ -147,6 +152,7 @@
     m_is_external = false;
     m_size_is_sibling = false;
     m_size_is_synthesized = false;
+    m_calculated_size = false;
     m_type = eSymbolTypeInvalid;
     m_flags = 0;
     m_addr_range.Clear();
@@ -156,7 +162,11 @@
 Symbol::GetAddressRangePtr()
 {
     if (m_addr_range.GetBaseAddress().GetSection())
+    {
+        if (!m_calculated_size)
+            GetByteSize();
         return &m_addr_range;
+    }
     return NULL;
 }
 
@@ -164,7 +174,11 @@
 Symbol::GetAddressRangePtr() const
 {
     if (m_addr_range.GetBaseAddress().GetSection())
+    {
+        if (!m_calculated_size)
+            GetByteSize();
         return &m_addr_range;
+    }
     return NULL;
 }
 
@@ -395,3 +409,32 @@
 }
 
 
+lldb::addr_t
+Symbol::GetByteSize () const
+{
+    addr_t byte_size = m_addr_range.GetByteSize();
+    if (byte_size == 0 && !m_calculated_size)
+    {
+        const_cast<Symbol*>(this)->m_calculated_size = true;
+        const AddressRange *range = GetAddressRangePtr();
+        if (range)
+        {
+            ModuleSP module_sp (range->GetBaseAddress().GetModule());
+            if (module_sp)
+            {
+                ObjectFile *objfile = module_sp->GetObjectFile();
+                if (objfile)
+                {
+                    Symtab *symtab = objfile->GetSymtab();
+                    if (symtab)
+                    {
+                        const_cast<AddressRange &>(m_addr_range).SetByteSize(symtab->CalculateSymbolSize (const_cast<Symbol *>(this)));
+                        byte_size = m_addr_range.GetByteSize();
+                    }
+                }
+            }
+        }
+    }
+    return byte_size;
+}
+

Modified: lldb/trunk/source/Symbol/SymbolContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolContext.cpp?rev=151878&r1=151877&r2=151878&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/SymbolContext.cpp (original)
+++ lldb/trunk/source/Symbol/SymbolContext.cpp Thu Mar  1 21:01:16 2012
@@ -427,26 +427,16 @@
         }            
     } 
     
-    if ((scope & eSymbolContextSymbol) && (symbol != NULL) && (symbol->GetAddressRangePtr() != NULL))
+    if ((scope & eSymbolContextSymbol) && (symbol != NULL))
     {
         if (range_idx == 0)
         {
-            range = *symbol->GetAddressRangePtr();
-
-            if (range.GetByteSize() == 0)
+            const AddressRange *range_ptr = symbol->GetAddressRangePtr();
+            if (range_ptr)
             {
-                if (module_sp)
-                {
-                    ObjectFile *objfile = module_sp->GetObjectFile();
-                    if (objfile)
-                    {
-                        Symtab *symtab = objfile->GetSymtab();
-                        if (symtab)
-                            range.SetByteSize(symtab->CalculateSymbolSize (symbol));
-                    }
-                }
+                range = *range_ptr;
+                return true;
             }
-            return true;
         }
     }
     range.Clear();

Modified: lldb/trunk/source/Symbol/Symtab.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symtab.cpp?rev=151878&r1=151877&r2=151878&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Symtab.cpp (original)
+++ lldb/trunk/source/Symbol/Symtab.cpp Thu Mar  1 21:01:16 2012
@@ -929,7 +929,7 @@
             return info.match_symbol;
         }
 
-        const size_t symbol_byte_size = CalculateSymbolSize(info.match_symbol);
+        const size_t symbol_byte_size = info.match_symbol->GetByteSize();
         
         if (symbol_byte_size == 0)
         {





More information about the lldb-commits mailing list