[Lldb-commits] [lldb] r204689 - Make "disassemble -a" work when the target is not running yet. It will dump all the functions matching that address, just like "disassemble -n" does before running.

Jim Ingham jingham at apple.com
Mon Mar 24 17:15:47 PDT 2014


Author: jingham
Date: Mon Mar 24 19:15:47 2014
New Revision: 204689

URL: http://llvm.org/viewvc/llvm-project?rev=204689&view=rev
Log:
Make "disassemble -a" work when the target is not running yet.  It will dump all the functions matching that address, just like "disassemble -n" does before running.

<rdar://problem/16406570>

Modified:
    lldb/trunk/source/Commands/CommandObjectDisassemble.cpp

Modified: lldb/trunk/source/Commands/CommandObjectDisassemble.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectDisassemble.cpp?rev=204689&r1=204688&r2=204689&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectDisassemble.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectDisassemble.cpp Mon Mar 24 19:15:47 2014
@@ -370,6 +370,7 @@ CommandObjectDisassemble::DoExecute (Arg
     } 
     else
     {
+        std::vector<AddressRange> ranges;
         AddressRange range;
         StackFrame *frame = m_exe_ctx.GetFramePtr();
         if (m_options.frame_line)
@@ -425,6 +426,7 @@ CommandObjectDisassemble::DoExecute (Arg
                     // Disassembling at the PC always disassembles some number of instructions (not the whole function).
                     m_options.num_instructions = DEFAULT_DISASM_NUM_INS;
                 }
+                ranges.push_back(range);
             }
             else
             {
@@ -440,50 +442,76 @@ CommandObjectDisassemble::DoExecute (Arg
                             return false;            
                         }
                         range.SetByteSize (m_options.end_addr - m_options.start_addr);
+                        ranges.push_back(range);
                     }
                 }
                 else
                 {
                     if (m_options.symbol_containing_addr != LLDB_INVALID_ADDRESS 
-                        && target 
-                        && !target->GetSectionLoadList().IsEmpty())
+                        && target)
                     {
-                        bool failed = false;
-                        Address symbol_containing_address;
-                        if (target->GetSectionLoadList().ResolveLoadAddress (m_options.symbol_containing_addr, symbol_containing_address))
+                        if (!target->GetSectionLoadList().IsEmpty())
                         {
-                            ModuleSP module_sp (symbol_containing_address.GetModule());
-                            SymbolContext sc;
-                            bool resolve_tail_call_address = true; // PC can be one past the address range of the function.
-                            module_sp->ResolveSymbolContextForAddress (symbol_containing_address, eSymbolContextEverything, sc,
-                                                                       resolve_tail_call_address);
-                            if (sc.function || sc.symbol)
+                            bool failed = false;
+                            Address symbol_containing_address;
+                            if (target->GetSectionLoadList().ResolveLoadAddress (m_options.symbol_containing_addr, symbol_containing_address))
                             {
-                                sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, range);
+                                ModuleSP module_sp (symbol_containing_address.GetModule());
+                                SymbolContext sc;
+                                bool resolve_tail_call_address = true; // PC can be one past the address range of the function.
+                                module_sp->ResolveSymbolContextForAddress (symbol_containing_address, eSymbolContextEverything, sc,
+                                                                           resolve_tail_call_address);
+                                if (sc.function || sc.symbol)
+                                {
+                                    sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, range);
+                                }
+                                else
+                                {
+                                    failed = true;
+                                }
                             }
                             else
                             {
                                 failed = true;
                             }
+                            if (failed)
+                            {
+                                result.AppendErrorWithFormat ("Could not find function bounds for address 0x%" PRIx64 "\n", m_options.symbol_containing_addr);
+                                result.SetStatus (eReturnStatusFailed);
+                                return false;
+                            }
+                            ranges.push_back(range);
                         }
                         else
                         {
-                            failed = true;
-                        }
-                        if (failed)
-                        {
-                            result.AppendErrorWithFormat ("Could not find function bounds for address 0x%" PRIx64 "\n", m_options.symbol_containing_addr);
-                            result.SetStatus (eReturnStatusFailed);
-                            return false;
+                            for (lldb::ModuleSP module_sp : target->GetImages().Modules())
+                            {
+                                lldb::addr_t file_addr = m_options.symbol_containing_addr;
+                                Address file_address;
+                                if (module_sp->ResolveFileAddress(file_addr, file_address))
+                                {
+                                    SymbolContext sc;
+                                    bool resolve_tail_call_address = true; // PC can be one past the address range of the function.
+                                    module_sp->ResolveSymbolContextForAddress (file_address, eSymbolContextEverything, sc, resolve_tail_call_address);
+                                    if (sc.function || sc.symbol)
+                                    {
+                                        sc.GetAddressRange (eSymbolContextFunction | eSymbolContextSymbol, 0, false, range);
+                                        ranges.push_back(range);
+                                    }
+                                }
+                            }
+                            
                         }
                     }
                 }
             }
         }
+        else
+            ranges.push_back(range);
 
         if (m_options.num_instructions != 0)
         {
-            if (!range.GetBaseAddress().IsValid())
+            if (ranges.size() == 0)
             {
                 // The default action is to disassemble the current frame function.
                 if (frame)
@@ -504,29 +532,38 @@ CommandObjectDisassemble::DoExecute (Arg
                     return false;
                 }
             }
-
-            if (Disassembler::Disassemble (m_interpreter.GetDebugger(), 
-                                           m_options.arch,
-                                           plugin_name,
-                                           flavor_string,
-                                           m_exe_ctx,
-                                           range.GetBaseAddress(),
-                                           m_options.num_instructions,
-                                           m_options.show_mixed ? m_options.num_lines_context : 0,
-                                           options,
-                                           result.GetOutputStream()))
-            {
-                result.SetStatus (eReturnStatusSuccessFinishResult);
-            }
-            else
-            {
-                result.AppendErrorWithFormat ("Failed to disassemble memory at 0x%8.8" PRIx64 ".\n", m_options.start_addr);
-                result.SetStatus (eReturnStatusFailed);            
+            
+            bool print_sc_header = ranges.size() > 1;
+            for (AddressRange cur_range : ranges)
+            {
+                if (Disassembler::Disassemble (m_interpreter.GetDebugger(),
+                                               m_options.arch,
+                                               plugin_name,
+                                               flavor_string,
+                                               m_exe_ctx,
+                                               cur_range.GetBaseAddress(),
+                                               m_options.num_instructions,
+                                               m_options.show_mixed ? m_options.num_lines_context : 0,
+                                               options,
+                                               result.GetOutputStream()))
+                {
+                    result.SetStatus (eReturnStatusSuccessFinishResult);
+                }
+                else
+                {
+                    if (m_options.start_addr != LLDB_INVALID_ADDRESS)
+                        result.AppendErrorWithFormat ("Failed to disassemble memory at 0x%8.8" PRIx64 ".\n", m_options.start_addr);
+                    else if (m_options.symbol_containing_addr != LLDB_INVALID_ADDRESS)
+                        result.AppendErrorWithFormat ("Failed to disassemble memory in function at 0x%8.8" PRIx64 ".\n", m_options.symbol_containing_addr);
+                    result.SetStatus (eReturnStatusFailed);
+                }
             }
+            if (print_sc_header)
+                result.AppendMessage("\n");
         }
         else
         {
-            if (!range.GetBaseAddress().IsValid())
+            if (ranges.size() == 0)
             {
                 // The default action is to disassemble the current frame function.
                 if (frame)
@@ -548,27 +585,35 @@ CommandObjectDisassemble::DoExecute (Arg
                     result.SetStatus (eReturnStatusFailed);
                     return false;
                 }
+                ranges.push_back(range);
             }
-            if (range.GetByteSize() == 0)
-                range.SetByteSize(DEFAULT_DISASM_BYTE_SIZE);
-
-            if (Disassembler::Disassemble (m_interpreter.GetDebugger(), 
-                                           m_options.arch,
-                                           plugin_name,
-                                           flavor_string,
-                                           m_exe_ctx,
-                                           range,
-                                           m_options.num_instructions,
-                                           m_options.show_mixed ? m_options.num_lines_context : 0,
-                                           options,
-                                           result.GetOutputStream()))
-            {
-                result.SetStatus (eReturnStatusSuccessFinishResult);
-            }
-            else
+            
+            bool print_sc_header = ranges.size() > 1;
+            for (AddressRange cur_range : ranges)
             {
-                result.AppendErrorWithFormat ("Failed to disassemble memory at 0x%8.8" PRIx64 ".\n", m_options.start_addr);
-                result.SetStatus (eReturnStatusFailed);            
+                if (cur_range.GetByteSize() == 0)
+                    cur_range.SetByteSize(DEFAULT_DISASM_BYTE_SIZE);
+
+                if (Disassembler::Disassemble (m_interpreter.GetDebugger(),
+                                               m_options.arch,
+                                               plugin_name,
+                                               flavor_string,
+                                               m_exe_ctx,
+                                               cur_range,
+                                               m_options.num_instructions,
+                                               m_options.show_mixed ? m_options.num_lines_context : 0,
+                                               options,
+                                               result.GetOutputStream()))
+                {
+                    result.SetStatus (eReturnStatusSuccessFinishResult);
+                }
+                else
+                {
+                    result.AppendErrorWithFormat ("Failed to disassemble memory at 0x%8.8" PRIx64 ".\n", m_options.start_addr);
+                    result.SetStatus (eReturnStatusFailed);            
+                }
+                if (print_sc_header)
+                    result.AppendMessage("\n");
             }
         }
     }





More information about the lldb-commits mailing list