[Lldb-commits] [lldb] r148460 - in /lldb/trunk: include/lldb/Core/Disassembler.h include/lldb/Target/ObjCLanguageRuntime.h source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp source/Plugins/Disassembler/llvm/DisassemblerLLVM.h source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp source/Symbol/Symtab.cpp source/Target/ObjCLanguageRuntime.cpp

Greg Clayton gclayton at apple.com
Wed Jan 18 19:24:53 PST 2012


Author: gclayton
Date: Wed Jan 18 21:24:53 2012
New Revision: 148460

URL: http://llvm.org/viewvc/llvm-project?rev=148460&view=rev
Log:
Fixed an issue with the Instruction subclasses where the strings might
be fetched too many times and the DisassemblerLLVM was appending to strings
when the opcode, mnemonic and comment accessors were called multiple times
and if any of the strings were empty.

Also fixed the test suite failures from recent Objective C modifications.



Modified:
    lldb/trunk/include/lldb/Core/Disassembler.h
    lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h
    lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp
    lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/trunk/source/Symbol/Symtab.cpp
    lldb/trunk/source/Target/ObjCLanguageRuntime.cpp

Modified: lldb/trunk/include/lldb/Core/Disassembler.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Disassembler.h?rev=148460&r1=148459&r2=148460&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Disassembler.h (original)
+++ lldb/trunk/include/lldb/Core/Disassembler.h Wed Jan 18 21:24:53 2012
@@ -44,35 +44,26 @@
     const char *
     GetMnemonic (ExecutionContextScope *exe_scope)
     {
-        if (m_opcode_name.empty())
-            CalculateMnemonic(exe_scope);
+        CalculateMnemonicOperandsAndCommentIfNeeded (exe_scope);
         return m_opcode_name.c_str();
     }
     const char *
     GetOperands (ExecutionContextScope *exe_scope)
     {
-        if (m_mnemocics.empty())
-            CalculateOperands(exe_scope);
+        CalculateMnemonicOperandsAndCommentIfNeeded (exe_scope);
         return m_mnemocics.c_str();
     }
     
     const char *
     GetComment (ExecutionContextScope *exe_scope)
     {
-        if (m_comment.empty())
-            CalculateComment(exe_scope);
+        CalculateMnemonicOperandsAndCommentIfNeeded (exe_scope);
         return m_comment.c_str();
     }
 
     virtual void
-    CalculateMnemonic (ExecutionContextScope *exe_scope) = 0;
+    CalculateMnemonicOperandsAndComment (ExecutionContextScope *exe_scope) = 0;
     
-    virtual void
-    CalculateOperands (ExecutionContextScope *exe_scope) = 0;
-    
-    virtual void
-    CalculateComment (ExecutionContextScope *exe_scope) = 0;
-
     AddressClass
     GetAddressClass ();
 
@@ -144,7 +135,17 @@
     std::string m_opcode_name;
     std::string m_mnemocics;
     std::string m_comment;
+    bool m_calculated_strings;
 
+    void
+    CalculateMnemonicOperandsAndCommentIfNeeded (ExecutionContextScope *exe_scope)
+    {
+        if (!m_calculated_strings)
+        {
+            m_calculated_strings = true;
+            CalculateMnemonicOperandsAndComment(exe_scope);
+        }
+    }
 };
 
 
@@ -205,23 +206,13 @@
     DoesBranch () const;
 
     virtual void
-    CalculateMnemonic(ExecutionContextScope *exe_scope)
+    CalculateMnemonicOperandsAndComment (ExecutionContextScope *exe_scope)
     {
-        // TODO: fill this in and put opcode name into Instruction::m_opcode_name
+        // TODO: fill this in and put opcode name into Instruction::m_opcode_name,
+        // mnemonic into Instruction::m_mnemonics, and any comment into 
+        // Instruction::m_comment
     }
     
-    virtual void
-    CalculateOperands(ExecutionContextScope *exe_scope)
-    {
-        // TODO: fill this in and put opcode name into Instruction::m_mnemonics
-    }
-    
-    virtual void
-    CalculateComment(ExecutionContextScope *exe_scope)
-    {
-        // TODO: fill this in and put opcode name into Instruction::m_comment
-    }
-
     virtual size_t
     Decode (const Disassembler &disassembler,
             const DataExtractor &data,

Modified: lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h?rev=148460&r1=148459&r2=148460&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h (original)
+++ lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h Wed Jan 18 21:24:53 2012
@@ -99,14 +99,68 @@
     virtual size_t
     GetByteOffsetForIvar (ClangASTType &parent_qual_type, const char *ivar_name);
     
-    // If the passed in "name" is an ObjC method, return true.  Also, fill in any of the
-    // sub-parts that are passed in non-NULL.  The base_name means the name stripped of
-    // category attributes.
-    static bool
+    //------------------------------------------------------------------
+    /// Chop up an objective C function prototype.
+    ///
+    /// Chop up an objective C function fullname and optionally fill in
+    /// any non-NULL ConstString objects. If a ConstString * is NULL,
+    /// then this name doesn't get filled in
+    ///
+    /// @param[in] name
+    ///     A fully specified objective C function name. The string might
+    ///     contain a category and it includes the leading "+" or "-" and
+    ///     the square brackets, no types for the arguments, just the plain
+    ///     selector. A few examples:
+    ///         "-[NSStringDrawingContext init]"
+    ///         "-[NSStringDrawingContext addString:inRect:]"
+    ///         "-[NSString(NSStringDrawing) sizeWithAttributes:]"
+    ///         "+[NSString(NSStringDrawing) usesFontLeading]"
+    ///         
+    /// @param[out] class_name
+    ///     If non-NULL, this string will be filled in with the class
+    ///     name including the category. The examples above would return:
+    ///         "NSStringDrawingContext"
+    ///         "NSStringDrawingContext"
+    ///         "NSString(NSStringDrawing)"
+    ///         "NSString(NSStringDrawing)"
+    ///
+    /// @param[out] selector_name
+    ///     If non-NULL, this string will be filled in with the selector
+    ///     name. The examples above would return:
+    ///         "init"
+    ///         "addString:inRect:"
+    ///         "sizeWithAttributes:"
+    ///         "usesFontLeading"
+    ///
+    /// @param[out] name_sans_category
+    ///     If non-NULL, this string will be filled in with the class
+    ///     name _without_ the category. If there is no category, and empty
+    ///     string will be returned (as the result would be normally returned
+    ///     in the "class_name" argument). The examples above would return:
+    ///         <empty>
+    ///         <empty>
+    ///         "-[NSString sizeWithAttributes:]"
+    ///         "+[NSString usesFontLeading]"
+    ///
+    /// @param[out] class_name_sans_category
+    ///     If non-NULL, this string will be filled in with the prototype
+    ///     name _without_ the category. If there is no category, and empty
+    ///     string will be returned (as this is already the value that was
+    ///     passed in). The examples above would return:
+    ///         <empty>
+    ///         <empty>
+    ///         "NSString"
+    ///         "NSString"
+    ///
+    /// @return
+    ///     Returns the number of strings that were successfully filled
+    ///     in.
+    //------------------------------------------------------------------
+    static uint32_t
     ParseMethodName (const char *name, 
                      ConstString *class_name,               // Class name (with category if there is one)
                      ConstString *selector_name,            // selector only
-                     ConstString *name_sans_category,       // full function name with no category
+                     ConstString *name_sans_category,       // full function name with no category (empty if no category)
                      ConstString *class_name_sans_category);// Class name without category (empty if no category)
     
     static bool

Modified: lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp?rev=148460&r1=148459&r2=148460&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp (original)
+++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp Wed Jan 18 21:24:53 2012
@@ -437,7 +437,7 @@
 }
 
 void
-InstructionLLVM::CalculateMnemonic (ExecutionContextScope *exe_scope)
+InstructionLLVM::CalculateMnemonicOperandsAndComment (ExecutionContextScope *exe_scope)
 {
     const int num_tokens = EDNumTokens(m_inst);
     if (num_tokens > 0)
@@ -560,20 +560,6 @@
     }
 }
 
-void
-InstructionLLVM::CalculateOperands(ExecutionContextScope *exe_scope)
-{
-    // Do all of the work in CalculateMnemonic()
-    CalculateMnemonic (exe_scope);
-}
-
-void
-InstructionLLVM::CalculateComment(ExecutionContextScope *exe_scope)
-{
-    // Do all of the work in CalculateMnemonic()
-    CalculateMnemonic (exe_scope);    
-}
-
 bool
 InstructionLLVM::DoesBranch() const
 {

Modified: lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h?rev=148460&r1=148459&r2=148460&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h (original)
+++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h Wed Jan 18 21:24:53 2012
@@ -44,14 +44,8 @@
             uint32_t data_offset);
     
     virtual void
-    CalculateMnemonic (lldb_private::ExecutionContextScope *exe_scope);
+    CalculateMnemonicOperandsAndComment (lldb_private::ExecutionContextScope *exe_scope);
     
-    virtual void
-    CalculateOperands (lldb_private::ExecutionContextScope *exe_scope);
-    
-    virtual void
-    CalculateComment (lldb_private::ExecutionContextScope *exe_scope);
-
 protected:
     EDDisassemblerRef m_disassembler;
     EDInstRef m_inst;

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp?rev=148460&r1=148459&r2=148460&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp Wed Jan 18 21:24:53 2012
@@ -744,16 +744,15 @@
                                                                   &objc_fullname_no_category_name,
                                                                   &objc_class_name_no_category))
                         {
-                            objc_class_selectors.Insert(objc_class_name, die.GetOffset());
+                            func_fullnames.Insert (ConstString(name), die.GetOffset());
+                            if (objc_class_name)
+                                objc_class_selectors.Insert(objc_class_name, die.GetOffset());
                             if (objc_class_name_no_category)
                                 objc_class_selectors.Insert(objc_class_name_no_category, die.GetOffset());
-                            
-                            func_selectors.Insert (objc_selector_name, die.GetOffset());
-                            func_fullnames.Insert (ConstString(name), die.GetOffset());
+                            if (objc_selector_name)
+                                func_selectors.Insert (objc_selector_name, die.GetOffset());
                             if (objc_fullname_no_category_name)
-                            {
                                 func_fullnames.Insert (objc_fullname_no_category_name, die.GetOffset());
-                            }
                         }
                     }
                     // If we have a mangled name, then the DW_AT_name attribute

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=148460&r1=148459&r2=148460&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Wed Jan 18 21:24:53 2012
@@ -4898,8 +4898,13 @@
                         if (tag == DW_TAG_subprogram)
                         {
                             ConstString class_name;
-                            if (ObjCLanguageRuntime::ParseMethodName (type_name_cstr, NULL, NULL, NULL, &class_name))
+                            ConstString class_name_no_category;
+                            if (ObjCLanguageRuntime::ParseMethodName (type_name_cstr, &class_name, NULL, NULL, &class_name_no_category))
                             {
+                                // Use the class name with no category if there is one
+                                if (class_name_no_category)
+                                    class_name = class_name_no_category;
+
                                 SymbolContext empty_sc;
                                 clang_type_t class_opaque_type = NULL;
                                 if (class_name)

Modified: lldb/trunk/source/Symbol/Symtab.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symtab.cpp?rev=148460&r1=148459&r2=148460&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Symtab.cpp (original)
+++ lldb/trunk/source/Symbol/Symtab.cpp Wed Jan 18 21:24:53 2012
@@ -314,8 +314,7 @@
                                                       NULL,
                                                       NULL,
                                                       &objc_base_name,
-                                                      NULL)
-                && !objc_base_name.IsEmpty())
+                                                      NULL))
             {
                 entry.cstring = objc_base_name.GetCString();
                 m_name_to_index.Append (entry);

Modified: lldb/trunk/source/Target/ObjCLanguageRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ObjCLanguageRuntime.cpp?rev=148460&r1=148459&r2=148460&view=diff
==============================================================================
--- lldb/trunk/source/Target/ObjCLanguageRuntime.cpp (original)
+++ lldb/trunk/source/Target/ObjCLanguageRuntime.cpp Wed Jan 18 21:24:53 2012
@@ -101,7 +101,7 @@
 }
 
 
-bool
+uint32_t
 ObjCLanguageRuntime::ParseMethodName (const char *name, 
                                       ConstString *class_name,              // Class name (with category if any)
                                       ConstString *selector_name,           // selector on its own
@@ -117,6 +117,8 @@
     if (class_name_sans_category)
         class_name_sans_category->Clear();
     
+    uint32_t result = 0;
+
     if (IsPossibleObjCMethodName (name))
     {
         int name_len = strlen (name);
@@ -132,7 +134,10 @@
             if (selector_name_ptr)
             {
                 if (class_name)
+                {
                     class_name->SetCStringWithLength (name + 2, selector_name_ptr - name - 2);
+                    ++result;
+                }    
                 
                 // Skip the space
                 ++selector_name_ptr;
@@ -140,7 +145,10 @@
                 // accelerator tables
                 size_t selector_name_len = name_len - (selector_name_ptr - name) - 1;
                 if (selector_name)
+                {
                     selector_name->SetCStringWithLength (selector_name_ptr, selector_name_len);                                
+                    ++result;
+                }
                 
                 // Also see if this is a "category" on our class.  If so strip off the category name,
                 // and add the class name without it to the basename table. 
@@ -151,24 +159,26 @@
                     if (open_paren)
                     {
                         if (class_name_sans_category)
+                        {
                             class_name_sans_category->SetCStringWithLength (name + 2, open_paren - name - 2);
+                            ++result;
+                        }
                         
                         if (name_sans_category)
                         {
-                            const char *close_paren = strchr (name, ')');
-                            if (close_paren)
+                            const char *close_paren = strchr (open_paren, ')');
+                            if (open_paren < close_paren)
                             {
                                 std::string buffer (name, open_paren - name);
                                 buffer.append (close_paren + 1);
                                 name_sans_category->SetCString (buffer.c_str());
+                                ++result;
                             }
                         }
                     }
                 }
             }
-            return true;
         }
-        return false;
     }
-    return false;
+    return result;
 }





More information about the lldb-commits mailing list