[Lldb-commits] [lldb] r179258 - Change the disassemble option to specify the architecture from '-a'

Jason Molenda jmolenda at apple.com
Wed Apr 10 20:14:01 PDT 2013


Author: jmolenda
Date: Wed Apr 10 22:14:01 2013
New Revision: 179258

URL: http://llvm.org/viewvc/llvm-project?rev=179258&view=rev
Log:
Change the disassemble option to specify the architecture from '-a'
to '-A'.

Add option '-a' / '--address' to disassemble which will find the
function that contains that address, and disassemble the entire function.

<rdar://problem/13436207> 

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

Modified: lldb/trunk/source/Commands/CommandObjectDisassemble.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectDisassemble.cpp?rev=179258&r1=179257&r2=179258&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectDisassemble.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectDisassemble.cpp Wed Apr 10 22:14:01 2013
@@ -17,6 +17,7 @@
 // Project includes
 #include "lldb/Core/AddressRange.h"
 #include "lldb/Core/Disassembler.h"
+#include "lldb/Core/Module.h"
 #include "lldb/Core/SourceManager.h"
 #include "lldb/Interpreter/Args.h"
 #include "lldb/Interpreter/CommandCompletions.h"
@@ -48,7 +49,8 @@ CommandObjectDisassemble::CommandOptions
     plugin_name (),
     flavor_string(),
     arch(),
-    some_location_specified (false) 
+    some_location_specified (false),
+    symbol_containing_addr () 
 {
     OptionParsingStarting();
 }
@@ -147,11 +149,22 @@ CommandObjectDisassemble::CommandOptions
         some_location_specified = true;
         break;
 
-    case 'a':
+    case 'A':
         if (!arch.SetTriple (option_arg, m_interpreter.GetPlatform (true).get()))
             arch.SetTriple (option_arg);
         break;
 
+    case 'a':
+        {
+            ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
+            symbol_containing_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error);
+            if (symbol_containing_addr != LLDB_INVALID_ADDRESS)
+            {
+                some_location_specified = true;
+            }
+        }
+        break;
+
     default:
         error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
         break;
@@ -173,6 +186,7 @@ CommandObjectDisassemble::CommandOptions
     frame_line = false;
     start_addr = LLDB_INVALID_ADDRESS;
     end_addr = LLDB_INVALID_ADDRESS;
+    symbol_containing_addr = LLDB_INVALID_ADDRESS;
     raw = false;
     plugin_name.clear();
     
@@ -225,7 +239,7 @@ CommandObjectDisassemble::CommandOptions
 { LLDB_OPT_SET_ALL, false, "flavor"       , 'F', required_argument  , NULL, 0, eArgTypeDisassemblyFlavor,        "Name of the disassembly flavor you want to use.  "
                                                                                                     "Currently the only valid options are default, and for Intel"
                                                                                                     " architectures, att and intel."},
-{ LLDB_OPT_SET_ALL, false, "arch"         , 'a', required_argument  , NULL, 0, eArgTypeArchitecture,"Specify the architecture to use from cross disassembly."},
+{ LLDB_OPT_SET_ALL, false, "arch"         , 'A', required_argument  , NULL, 0, eArgTypeArchitecture,"Specify the architecture to use from cross disassembly."},
 { LLDB_OPT_SET_1  |
   LLDB_OPT_SET_2  , true , "start-address", 's', required_argument  , NULL, 0, eArgTypeAddressOrExpression,"Address at which to start disassembling."},
 { LLDB_OPT_SET_1  , false, "end-address"  , 'e', required_argument  , NULL, 0, eArgTypeAddressOrExpression,  "Address at which to end disassembling."},
@@ -238,6 +252,7 @@ CommandObjectDisassemble::CommandOptions
 { LLDB_OPT_SET_4  , false, "frame"        , 'f', no_argument        , NULL, 0, eArgTypeNone,        "Disassemble from the start of the current frame's function."},
 { LLDB_OPT_SET_5  , false, "pc"           , 'p', no_argument        , NULL, 0, eArgTypeNone,        "Disassemble around the current pc."},
 { LLDB_OPT_SET_6  , false, "line"         , 'l', no_argument        , NULL, 0, eArgTypeNone,        "Disassemble the current frame's current source line instructions if there debug line table information, else disasemble around the pc."},
+{ LLDB_OPT_SET_7  , false, "address"      , 'a', required_argument  , NULL, 0, eArgTypeAddressOrExpression, "Disassemble function containing this address."},
 { 0               , false, NULL           ,   0, 0                  , NULL, 0, eArgTypeNone,        NULL }
 };
 
@@ -426,9 +441,43 @@ CommandObjectDisassemble::DoExecute (Arg
                         range.SetByteSize (m_options.end_addr - m_options.start_addr);
                     }
                 }
+                else
+                {
+                    if (m_options.symbol_containing_addr != LLDB_INVALID_ADDRESS 
+                        && target 
+                        && !target->GetSectionLoadList().IsEmpty())
+                    {
+                        bool failed = false;
+                        Address symbol_containing_address;
+                        if (target->GetSectionLoadList().ResolveLoadAddress (m_options.symbol_containing_addr, symbol_containing_address))
+                        {
+                            ModuleSP module_sp (symbol_containing_address.GetModule());
+                            SymbolContext sc;
+                            module_sp->ResolveSymbolContextForAddress (symbol_containing_address, eSymbolContextEverything, sc);
+                            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;
+                        }
+                    }
+                }
             }
         }
-        
+
         if (m_options.num_instructions != 0)
         {
             if (!range.GetBaseAddress().IsValid())

Modified: lldb/trunk/source/Commands/CommandObjectDisassemble.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectDisassemble.h?rev=179258&r1=179257&r2=179258&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectDisassemble.h (original)
+++ lldb/trunk/source/Commands/CommandObjectDisassemble.h Wed Apr 10 22:14:01 2013
@@ -80,6 +80,7 @@ public:
         ArchSpec arch;
         bool some_location_specified; // If no location was specified, we'll select "at_pc".  This should be set
                                       // in SetOptionValue if anything the selects a location is set.
+        lldb::addr_t symbol_containing_addr;
         static OptionDefinition g_option_table[];
     };
 





More information about the lldb-commits mailing list