[Lldb-commits] [lldb] r112230 - in /lldb/trunk: include/lldb/Interpreter/CommandInterpreter.h include/lldb/Target/StackFrame.h include/lldb/Target/StackID.h source/Commands/CommandObjectMultiword.cpp source/Interpreter/CommandInterpreter.cpp source/Target/StackFrame.cpp

Greg Clayton gclayton at apple.com
Thu Aug 26 15:05:43 PDT 2010


Author: gclayton
Date: Thu Aug 26 17:05:43 2010
New Revision: 112230

URL: http://llvm.org/viewvc/llvm-project?rev=112230&view=rev
Log:
Changed the StackID to store its start PC address as a load address instead of 
a section offset address.

Fixed up some very inefficient STL code.


Modified:
    lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
    lldb/trunk/include/lldb/Target/StackFrame.h
    lldb/trunk/include/lldb/Target/StackID.h
    lldb/trunk/source/Commands/CommandObjectMultiword.cpp
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp
    lldb/trunk/source/Target/StackFrame.cpp

Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=112230&r1=112229&r2=112230&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Thu Aug 26 17:05:43 2010
@@ -230,7 +230,7 @@
     RemoveLogChannel (const char *name);
 #endif
 
-    std::string
+    size_t
     FindLongestCommandWord (CommandObject::CommandMap &dict);
 
     void

Modified: lldb/trunk/include/lldb/Target/StackFrame.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/StackFrame.h?rev=112230&r1=112229&r2=112230&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/StackFrame.h (original)
+++ lldb/trunk/include/lldb/Target/StackFrame.h Thu Aug 26 17:05:43 2010
@@ -139,7 +139,7 @@
     uint32_t m_concrete_frame_index;
     lldb::RegisterContextSP m_reg_context_sp;
     StackID m_id;
-    Address m_pc;   // PC as a section/offset address
+    Address m_frame_code_addr;   // The frame code address (might not be the same as the actual PC for inlined frames) as a section/offset address
     SymbolContext   m_sc;
     Flags m_flags;
     Scalar m_frame_base;

Modified: lldb/trunk/include/lldb/Target/StackID.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/StackID.h?rev=112230&r1=112229&r2=112230&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/StackID.h (original)
+++ lldb/trunk/include/lldb/Target/StackID.h Thu Aug 26 17:05:43 2010
@@ -26,29 +26,22 @@
     // Constructors and Destructors
     //------------------------------------------------------------------
     StackID () :
-        m_start_address(),
-        m_cfa (0),
-        m_inline_block_id (0)
+        m_start_pc (LLDB_INVALID_ADDRESS),
+        m_cfa (LLDB_INVALID_ADDRESS),
+        m_inline_block_id (LLDB_INVALID_UID)
     {
     }
 
     explicit 
-    StackID (lldb::addr_t cfa, lldb::user_id_t inline_block_id) :
-        m_start_address (),
-        m_cfa (cfa),
-        m_inline_block_id (inline_block_id)
-    {
-    }
-
-    StackID (const Address& start_address, lldb::addr_t cfa, uint32_t inline_block_id) : 
-        m_start_address (start_address),
+    StackID (lldb::addr_t start_pc, lldb::addr_t cfa, lldb::user_id_t inline_block_id) :
+        m_start_pc (),
         m_cfa (cfa),
         m_inline_block_id (inline_block_id)
     {
     }
 
     StackID (const StackID& rhs) :
-        m_start_address (rhs.m_start_address),
+        m_start_pc (rhs.m_start_pc),
         m_cfa (rhs.m_cfa),
         m_inline_block_id (rhs.m_inline_block_id)
     {
@@ -58,16 +51,16 @@
     {
     }
 
-    const Address&
+    const lldb::addr_t
     GetStartAddress() const
     {
-        return m_start_address;
+        return m_start_pc;
     }
 
     void
-    SetStartAddress(const Address& start_address)
+    SetStartAddress(lldb::addr_t start_pc)
     {
-        m_start_address = start_address;
+        m_start_pc = start_pc;
     }
 
     lldb::addr_t
@@ -96,7 +89,7 @@
     {
         if (this != &rhs)
         {
-            m_start_address = rhs.m_start_address;
+            m_start_pc = rhs.m_start_pc;
             m_cfa = rhs.m_cfa;
             m_inline_block_id = rhs.m_inline_block_id;
         }
@@ -107,7 +100,7 @@
     //------------------------------------------------------------------
     // Classes that inherit from StackID can see and modify these
     //------------------------------------------------------------------
-    Address m_start_address;            // The address range for the function for this frame
+    lldb::addr_t m_start_pc;            // The start address for the function/symbol for this frame
     lldb::addr_t m_cfa;                 // The call frame address (stack pointer) value
                                         // at the beginning of the function that uniquely
                                         // identifies this frame (along with m_inline_block_id below)

Modified: lldb/trunk/source/Commands/CommandObjectMultiword.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMultiword.cpp?rev=112230&r1=112229&r2=112230&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectMultiword.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectMultiword.cpp Thu Aug 26 17:05:43 2010
@@ -188,11 +188,10 @@
     output_stream.PutCString ("The following subcommands are supported:\n\n");
 
     CommandMap::iterator pos;
-    std::string longest_word = interpreter.FindLongestCommandWord (m_subcommand_dict);
-    uint32_t max_len = 0;
+    uint32_t max_len = interpreter.FindLongestCommandWord (m_subcommand_dict);
 
-    if (! longest_word.empty())
-        max_len = strlen (longest_word.c_str()) + 4; // Indent the output by 4 spaces.
+    if (max_len)
+        max_len += 4; // Indent the output by 4 spaces.
 
     for (pos = m_subcommand_dict.begin(); pos != m_subcommand_dict.end(); ++pos)
     {

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=112230&r1=112229&r2=112230&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Thu Aug 26 17:05:43 2010
@@ -494,25 +494,20 @@
     help_string.Printf ("'");
 }
 
-std::string
+size_t
 CommandInterpreter::FindLongestCommandWord (CommandObject::CommandMap &dict)
 {
     CommandObject::CommandMap::const_iterator pos;
-    int max_len = 0;
-    CommandObjectSP cmd_sp;
-    std::string longest_word;
-
-    for (pos = dict.begin(); pos != dict.end(); ++pos)
-      {
-        if ((max_len == 0)
-            || (strlen (pos->first.c_str()) > max_len))
-          {
-            longest_word = pos->first;
-            max_len = strlen (longest_word.c_str());
-          }
-    }
+    CommandObject::CommandMap::const_iterator end = dict.end();
+    size_t max_len = 0;
 
-    return longest_word;
+    for (pos = dict.begin(); pos != end; ++pos)
+    {
+        size_t len = pos->first.size();
+        if (max_len < len)
+            max_len = len;
+    }
+    return max_len;
 }
 
 void
@@ -521,8 +516,7 @@
     CommandObject::CommandMap::const_iterator pos;
     result.AppendMessage("The following is a list of built-in, permanent debugger commands:");
     result.AppendMessage("");
-    std::string longest_word  = FindLongestCommandWord (m_command_dict);
-    uint32_t max_len = strlen (longest_word.c_str());
+    uint32_t max_len = FindLongestCommandWord (m_command_dict);
 
     for (pos = m_command_dict.begin(); pos != m_command_dict.end(); ++pos)
     {
@@ -535,8 +529,8 @@
     {
         result.AppendMessage("The following is a list of your current command abbreviations (see 'commands alias' for more info):");
         result.AppendMessage("");
-        longest_word = FindLongestCommandWord (m_alias_dict);
-        max_len = strlen (longest_word.c_str());
+        max_len = FindLongestCommandWord (m_alias_dict);
+
         for (pos = m_alias_dict.begin(); pos != m_alias_dict.end(); ++pos)
         {
             StreamString sstr;

Modified: lldb/trunk/source/Target/StackFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StackFrame.cpp?rev=112230&r1=112229&r2=112230&view=diff
==============================================================================
--- lldb/trunk/source/Target/StackFrame.cpp (original)
+++ lldb/trunk/source/Target/StackFrame.cpp Thu Aug 26 17:05:43 2010
@@ -48,8 +48,8 @@
     m_concrete_frame_index (concrete_frame_index),    
     m_thread (thread),
     m_reg_context_sp (),
-    m_id (cfa, 0),
-    m_pc (NULL, pc),
+    m_id (LLDB_INVALID_UID, cfa, LLDB_INVALID_UID),
+    m_frame_code_addr (NULL, pc),
     m_sc (),
     m_flags (),
     m_frame_base (),
@@ -78,8 +78,8 @@
     m_concrete_frame_index (concrete_frame_index),    
     m_thread (thread),
     m_reg_context_sp (reg_context_sp),
-    m_id (cfa, 0),
-    m_pc (NULL, pc),
+    m_id (LLDB_INVALID_UID, cfa, LLDB_INVALID_UID),
+    m_frame_code_addr (NULL, pc),
     m_sc (),
     m_flags (),
     m_frame_base (),
@@ -114,8 +114,8 @@
     m_concrete_frame_index (concrete_frame_index),    
     m_thread (thread),
     m_reg_context_sp (reg_context_sp),
-    m_id (cfa, 0),
-    m_pc (pc_addr),
+    m_id (LLDB_INVALID_UID, cfa, LLDB_INVALID_UID),
+    m_frame_code_addr (pc_addr),
     m_sc (),
     m_flags (),
     m_frame_base (),
@@ -157,9 +157,10 @@
 StackID&
 StackFrame::GetStackID()
 {
-    // Make sure we have resolved our stack ID's address range before we give
-    // it out to any external clients
-    if (m_id.GetStartAddress().IsValid() == 0 && m_flags.IsClear(RESOLVED_FRAME_ID))
+    // Make sure we have resolved our stack ID's start PC before we give
+    // it out to any external clients. This allows us to not have to lookup
+    // this information if it is never asked for.
+    if (m_flags.IsClear(RESOLVED_FRAME_ID) && m_id.GetStartAddress() == LLDB_INVALID_ADDRESS)
     {
         m_flags.Set (RESOLVED_FRAME_ID);
 
@@ -171,14 +172,19 @@
 
         if (GetSymbolContext (eSymbolContextFunction).function)
         {
-            m_id.SetStartAddress (m_sc.function->GetAddressRange().GetBaseAddress());
+            m_id.SetStartAddress (m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (&m_thread.GetProcess()));
         }
         else if (GetSymbolContext (eSymbolContextSymbol).symbol)
         {
             AddressRange *symbol_range_ptr = m_sc.symbol->GetAddressRangePtr();
             if (symbol_range_ptr)
-                m_id.SetStartAddress(symbol_range_ptr->GetBaseAddress());
+                m_id.SetStartAddress(symbol_range_ptr->GetBaseAddress().GetLoadAddress (&m_thread.GetProcess()));
         }
+        
+        // We didn't find a function or symbol, just use the frame code address
+        // which will be the same as the PC in the frame.
+        if (m_id.GetStartAddress() == LLDB_INVALID_ADDRESS)
+            m_id.SetStartAddress (m_frame_code_addr.GetLoadAddress (&m_thread.GetProcess()));
     }
     return m_id;
 }
@@ -186,17 +192,17 @@
 Address&
 StackFrame::GetFrameCodeAddress()
 {
-    if (m_flags.IsClear(RESOLVED_FRAME_ADDR) && !m_pc.IsSectionOffset())
+    if (m_flags.IsClear(RESOLVED_FRAME_ADDR) && !m_frame_code_addr.IsSectionOffset())
     {
         m_flags.Set (RESOLVED_FRAME_ADDR);
 
         // Resolve the PC into a temporary address because if ResolveLoadAddress
         // fails to resolve the address, it will clear the address object...
         Address resolved_pc;
-        if (m_thread.GetProcess().ResolveLoadAddress(m_pc.GetOffset(), resolved_pc))
+        if (m_thread.GetProcess().ResolveLoadAddress(m_frame_code_addr.GetOffset(), resolved_pc))
         {
-            m_pc = resolved_pc;
-            const Section *section = m_pc.GetSection();
+            m_frame_code_addr = resolved_pc;
+            const Section *section = m_frame_code_addr.GetSection();
             if (section)
             {
                 Module *module = section->GetModule();
@@ -209,14 +215,14 @@
             }
         }
     }
-    return m_pc;
+    return m_frame_code_addr;
 }
 
 void
 StackFrame::ChangePC (addr_t pc)
 {
-    m_pc.SetOffset(pc);
-    m_pc.SetSection(NULL);
+    m_frame_code_addr.SetOffset(pc);
+    m_frame_code_addr.SetSection(NULL);
     m_sc.Clear();
     m_flags.SetAllFlagBits(0);
     m_thread.ClearStackFrames ();
@@ -473,11 +479,7 @@
 bool
 StackFrame::IsInlined ()
 {
-    Block *block = GetSymbolContext (eSymbolContextBlock).block;
-    if (block)
-        return block->GetContainingInlinedBlock() != NULL;
-    else
-        return false;
+    return m_id.GetInlineBlockID() != LLDB_INVALID_UID;
 }
 
 Target *





More information about the lldb-commits mailing list