blob: f54bc9e8a6cd1d4b229fc473be69806d4c2a1e7c [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- CommandObjectDisassemble.cpp ----------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "CommandObjectDisassemble.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Core/AddressRange.h"
Jim Ingham84cdc152010-06-15 19:49:27 +000017#include "lldb/Interpreter/Args.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/Interpreter/CommandCompletions.h"
19#include "lldb/Interpreter/CommandInterpreter.h"
20#include "lldb/Interpreter/CommandReturnObject.h"
21#include "lldb/Core/Disassembler.h"
Jim Ingham84cdc152010-06-15 19:49:27 +000022#include "lldb/Interpreter/Options.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Core/SourceManager.h"
24#include "lldb/Target/StackFrame.h"
25#include "lldb/Symbol/Symbol.h"
26#include "lldb/Target/Process.h"
27#include "lldb/Target/Target.h"
28
29#define DEFAULT_DISASM_BYTE_SIZE 32
Jim Inghamaa3e3e12011-03-22 01:48:42 +000030#define DEFAULT_DISASM_NUM_INS 4
Chris Lattner24943d22010-06-08 16:52:24 +000031
32using namespace lldb;
33using namespace lldb_private;
34
Greg Claytonf15996e2011-04-07 22:46:35 +000035CommandObjectDisassemble::CommandOptions::CommandOptions (CommandInterpreter &interpreter) :
Johnny Chen0e0636d2011-04-08 22:15:29 +000036 Options(interpreter),
Jim Inghamaa3e3e12011-03-22 01:48:42 +000037 num_lines_context(0),
38 num_instructions (0),
Greg Clayton24bc5d92011-03-30 18:16:51 +000039 func_name(),
40 start_addr(),
41 end_addr (),
42 at_pc (false),
43 frame_line (false),
44 plugin_name (),
45 arch()
Chris Lattner24943d22010-06-08 16:52:24 +000046{
Greg Clayton143fcc32011-04-13 00:18:08 +000047 OptionParsingStarting();
Chris Lattner24943d22010-06-08 16:52:24 +000048}
49
50CommandObjectDisassemble::CommandOptions::~CommandOptions ()
51{
52}
53
54Error
Greg Clayton143fcc32011-04-13 00:18:08 +000055CommandObjectDisassemble::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
Chris Lattner24943d22010-06-08 16:52:24 +000056{
57 Error error;
58
59 char short_option = (char) m_getopt_table[option_idx].val;
60
Jim Inghamaa3e3e12011-03-22 01:48:42 +000061 bool success;
62
Chris Lattner24943d22010-06-08 16:52:24 +000063 switch (short_option)
64 {
65 case 'm':
66 show_mixed = true;
67 break;
68
Greg Clayton889fbd02011-03-26 19:14:58 +000069 case 'C':
Jim Inghamaa3e3e12011-03-22 01:48:42 +000070 num_lines_context = Args::StringToUInt32(option_arg, 0, 0, &success);
71 if (!success)
72 error.SetErrorStringWithFormat ("Invalid num context lines string: \"%s\".\n", option_arg);
73 break;
74
Chris Lattner24943d22010-06-08 16:52:24 +000075 case 'c':
Jim Inghamaa3e3e12011-03-22 01:48:42 +000076 num_instructions = Args::StringToUInt32(option_arg, 0, 0, &success);
77 if (!success)
78 error.SetErrorStringWithFormat ("Invalid num of instructions string: \"%s\".\n", option_arg);
Chris Lattner24943d22010-06-08 16:52:24 +000079 break;
80
81 case 'b':
82 show_bytes = true;
83 break;
84
Jim Ingham34e9a982010-06-15 18:47:14 +000085 case 's':
Greg Clayton24bc5d92011-03-30 18:16:51 +000086 start_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0);
87 if (start_addr == LLDB_INVALID_ADDRESS)
88 start_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16);
Chris Lattner24943d22010-06-08 16:52:24 +000089
Greg Clayton24bc5d92011-03-30 18:16:51 +000090 if (start_addr == LLDB_INVALID_ADDRESS)
Jim Inghamaa3e3e12011-03-22 01:48:42 +000091 error.SetErrorStringWithFormat ("Invalid start address string '%s'.\n", option_arg);
Jim Ingham34e9a982010-06-15 18:47:14 +000092 break;
93 case 'e':
Greg Clayton24bc5d92011-03-30 18:16:51 +000094 end_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0);
95 if (end_addr == LLDB_INVALID_ADDRESS)
96 end_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16);
Jim Ingham34e9a982010-06-15 18:47:14 +000097
Greg Clayton24bc5d92011-03-30 18:16:51 +000098 if (end_addr == LLDB_INVALID_ADDRESS)
Jim Inghamaa3e3e12011-03-22 01:48:42 +000099 error.SetErrorStringWithFormat ("Invalid end address string '%s'.\n", option_arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000100 break;
101
102 case 'n':
Greg Clayton24bc5d92011-03-30 18:16:51 +0000103 func_name.assign (option_arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000104 break;
105
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000106 case 'p':
Greg Clayton24bc5d92011-03-30 18:16:51 +0000107 at_pc = true;
108 break;
109
110 case 'l':
111 frame_line = true;
112 // Disassemble the current source line kind of implies showing mixed
113 // source code context.
114 show_mixed = true;
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000115 break;
116
Greg Clayton149731c2011-03-25 18:03:16 +0000117 case 'P':
Greg Clayton24bc5d92011-03-30 18:16:51 +0000118 plugin_name.assign (option_arg);
Greg Clayton149731c2011-03-25 18:03:16 +0000119 break;
120
Chris Lattner24943d22010-06-08 16:52:24 +0000121 case 'r':
122 raw = true;
123 break;
124
Johnny Chen61c1b8b2010-10-29 19:33:40 +0000125 case 'f':
126 // The default action is to disassemble the function for the current frame.
127 // There's no need to set any flag.
128 break;
129
Greg Clayton889fbd02011-03-26 19:14:58 +0000130 case 'a':
Greg Claytonb72d0f02011-04-12 05:54:46 +0000131 arch.SetTriple (option_arg, m_interpreter.GetPlatform (true).get());
Greg Clayton889fbd02011-03-26 19:14:58 +0000132 break;
133
Chris Lattner24943d22010-06-08 16:52:24 +0000134 default:
135 error.SetErrorStringWithFormat("Unrecognized short option '%c'.\n", short_option);
136 break;
137 }
138
139 return error;
140}
141
142void
Greg Clayton143fcc32011-04-13 00:18:08 +0000143CommandObjectDisassemble::CommandOptions::OptionParsingStarting ()
Chris Lattner24943d22010-06-08 16:52:24 +0000144{
Chris Lattner24943d22010-06-08 16:52:24 +0000145 show_mixed = false;
146 show_bytes = false;
147 num_lines_context = 0;
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000148 num_instructions = 0;
Greg Clayton24bc5d92011-03-30 18:16:51 +0000149 func_name.clear();
150 at_pc = false;
151 frame_line = false;
152 start_addr = LLDB_INVALID_ADDRESS;
153 end_addr = LLDB_INVALID_ADDRESS;
Sean Callanan944be702010-06-17 00:32:05 +0000154 raw = false;
Greg Clayton24bc5d92011-03-30 18:16:51 +0000155 plugin_name.clear();
156 arch.Clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000157}
158
Greg Claytonb3448432011-03-24 21:19:54 +0000159const OptionDefinition*
Chris Lattner24943d22010-06-08 16:52:24 +0000160CommandObjectDisassemble::CommandOptions::GetDefinitions ()
161{
162 return g_option_table;
163}
164
Greg Claytonb3448432011-03-24 21:19:54 +0000165OptionDefinition
Chris Lattner24943d22010-06-08 16:52:24 +0000166CommandObjectDisassemble::CommandOptions::g_option_table[] =
167{
Greg Clayton889fbd02011-03-26 19:14:58 +0000168{ LLDB_OPT_SET_ALL , false , "bytes", 'b', no_argument , NULL, 0, eArgTypeNone, "Show opcode bytes when disassembling."},
169{ LLDB_OPT_SET_ALL , false , "context", 'C', required_argument , NULL, 0, eArgTypeNumLines, "Number of context lines of source to show."},
170{ LLDB_OPT_SET_ALL , false , "mixed", 'm', no_argument , NULL, 0, eArgTypeNone, "Enable mixed source and assembly display."},
171{ LLDB_OPT_SET_ALL , false , "raw", 'r', no_argument , NULL, 0, eArgTypeNone, "Print raw disassembly with no symbol information."},
172{ LLDB_OPT_SET_ALL , false , "plugin", 'P', required_argument , NULL, 0, eArgTypePlugin, "Name of the disassembler plugin you want to use."},
173{ LLDB_OPT_SET_ALL , false , "arch", 'a', required_argument , NULL, 0, eArgTypeArchitecture,"Specify the architecture to use from cross disassembly."},
174{ LLDB_OPT_SET_1 |
175 LLDB_OPT_SET_2 , true , "start-address" , 's', required_argument , NULL, 0, eArgTypeStartAddress,"Address at which to start disassembling."},
176{ LLDB_OPT_SET_1 , false , "end-address" , 'e', required_argument , NULL, 0, eArgTypeEndAddress, "Address at which to end disassembling."},
177{ LLDB_OPT_SET_2 |
178 LLDB_OPT_SET_3 |
179 LLDB_OPT_SET_4 |
180 LLDB_OPT_SET_5 , false , "count", 'c', required_argument , NULL, 0, eArgTypeNumLines, "Number of instructions to display."},
181{ LLDB_OPT_SET_3 , true , "name", 'n', required_argument , NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Disassemble entire contents of the given function name."},
182{ LLDB_OPT_SET_4 , true , "frame", 'f', no_argument , NULL, 0, eArgTypeNone, "Disassemble from the start of the current frame's function."},
Greg Clayton24bc5d92011-03-30 18:16:51 +0000183{ LLDB_OPT_SET_5 , true , "pc", 'p', no_argument , NULL, 0, eArgTypeNone, "Disassemble around the current pc."},
184{ LLDB_OPT_SET_6 , true , "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."},
Greg Clayton889fbd02011-03-26 19:14:58 +0000185{ 0 , false , NULL, 0, 0 , NULL, 0, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000186};
187
188
189
190//-------------------------------------------------------------------------
191// CommandObjectDisassemble
192//-------------------------------------------------------------------------
193
Greg Clayton238c0a12010-09-18 01:14:36 +0000194CommandObjectDisassemble::CommandObjectDisassemble (CommandInterpreter &interpreter) :
195 CommandObject (interpreter,
196 "disassemble",
197 "Disassemble bytes in the current function, or elsewhere in the executable program as specified by the user.",
Greg Claytonf15996e2011-04-07 22:46:35 +0000198 "disassemble [<cmd-options>]"),
199 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000200{
201}
202
203CommandObjectDisassemble::~CommandObjectDisassemble()
204{
205}
206
Chris Lattner24943d22010-06-08 16:52:24 +0000207bool
208CommandObjectDisassemble::Execute
209(
210 Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000211 CommandReturnObject &result
212)
213{
Greg Clayton238c0a12010-09-18 01:14:36 +0000214 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000215 if (target == NULL)
216 {
217 result.AppendError ("invalid target, set executable file using 'file' command");
218 result.SetStatus (eReturnStatusFailed);
219 return false;
220 }
Greg Clayton24bc5d92011-03-30 18:16:51 +0000221 if (!m_options.arch.IsValid())
222 m_options.arch = target->GetArchitecture();
Chris Lattner24943d22010-06-08 16:52:24 +0000223
Greg Clayton24bc5d92011-03-30 18:16:51 +0000224 if (!m_options.arch.IsValid())
Chris Lattner24943d22010-06-08 16:52:24 +0000225 {
Greg Clayton889fbd02011-03-26 19:14:58 +0000226 result.AppendError ("use the --arch option or set the target architecure to disassemble");
Chris Lattner24943d22010-06-08 16:52:24 +0000227 result.SetStatus (eReturnStatusFailed);
228 return false;
229 }
230
Greg Clayton149731c2011-03-25 18:03:16 +0000231 const char *plugin_name = m_options.GetPluginName ();
Greg Clayton24bc5d92011-03-30 18:16:51 +0000232 Disassembler *disassembler = Disassembler::FindPlugin(m_options.arch, plugin_name);
Chris Lattner24943d22010-06-08 16:52:24 +0000233
234 if (disassembler == NULL)
235 {
Greg Clayton149731c2011-03-25 18:03:16 +0000236 if (plugin_name)
Greg Clayton889fbd02011-03-26 19:14:58 +0000237 result.AppendErrorWithFormat ("Unable to find Disassembler plug-in named '%s' that supports the '%s' architecture.\n",
238 plugin_name,
Greg Clayton24bc5d92011-03-30 18:16:51 +0000239 m_options.arch.GetArchitectureName());
Greg Clayton149731c2011-03-25 18:03:16 +0000240 else
Greg Clayton889fbd02011-03-26 19:14:58 +0000241 result.AppendErrorWithFormat ("Unable to find Disassembler plug-in for the '%s' architecture.\n",
Greg Clayton24bc5d92011-03-30 18:16:51 +0000242 m_options.arch.GetArchitectureName());
Chris Lattner24943d22010-06-08 16:52:24 +0000243 result.SetStatus (eReturnStatusFailed);
244 return false;
245 }
246
247 result.SetStatus (eReturnStatusSuccessFinishResult);
248
Greg Clayton70436352010-06-30 23:03:03 +0000249 if (command.GetArgumentCount() != 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000250 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000251 result.AppendErrorWithFormat ("\"disassemble\" arguments are specified as options.\n");
Greg Claytonf15996e2011-04-07 22:46:35 +0000252 GetOptions()->GenerateOptionUsage (result.GetErrorStream(), this);
Jim Ingham34e9a982010-06-15 18:47:14 +0000253 result.SetStatus (eReturnStatusFailed);
254 return false;
255 }
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000256
Greg Clayton70436352010-06-30 23:03:03 +0000257 if (m_options.show_mixed && m_options.num_lines_context == 0)
Greg Clayton1924e242010-09-15 05:51:24 +0000258 m_options.num_lines_context = 1;
Chris Lattner24943d22010-06-08 16:52:24 +0000259
Greg Claytonb72d0f02011-04-12 05:54:46 +0000260 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000261
Greg Clayton24bc5d92011-03-30 18:16:51 +0000262 if (!m_options.func_name.empty())
Greg Clayton70436352010-06-30 23:03:03 +0000263 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000264 ConstString name(m_options.func_name.c_str());
Greg Clayton70436352010-06-30 23:03:03 +0000265
Greg Clayton238c0a12010-09-18 01:14:36 +0000266 if (Disassembler::Disassemble (m_interpreter.GetDebugger(),
Greg Clayton24bc5d92011-03-30 18:16:51 +0000267 m_options.arch,
Greg Clayton149731c2011-03-25 18:03:16 +0000268 plugin_name,
Greg Clayton70436352010-06-30 23:03:03 +0000269 exe_ctx,
270 name,
271 NULL, // Module *
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000272 m_options.num_instructions,
Greg Clayton70436352010-06-30 23:03:03 +0000273 m_options.show_mixed ? m_options.num_lines_context : 0,
274 m_options.show_bytes,
Sean Callanana846cc32011-03-10 23:35:12 +0000275 m_options.raw,
Greg Clayton70436352010-06-30 23:03:03 +0000276 result.GetOutputStream()))
Chris Lattner24943d22010-06-08 16:52:24 +0000277 {
Greg Clayton70436352010-06-30 23:03:03 +0000278 result.SetStatus (eReturnStatusSuccessFinishResult);
Chris Lattner24943d22010-06-08 16:52:24 +0000279 }
280 else
281 {
282 result.AppendErrorWithFormat ("Unable to find symbol with name '%s'.\n", name.GetCString());
283 result.SetStatus (eReturnStatusFailed);
Chris Lattner24943d22010-06-08 16:52:24 +0000284 }
Greg Clayton70436352010-06-30 23:03:03 +0000285 }
Jim Ingham34e9a982010-06-15 18:47:14 +0000286 else
Chris Lattner24943d22010-06-08 16:52:24 +0000287 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000288 AddressRange range;
289 if (m_options.frame_line)
Greg Clayton70436352010-06-30 23:03:03 +0000290 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000291 LineEntry pc_line_entry (exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry).line_entry);
292 if (pc_line_entry.IsValid())
Greg Clayton70436352010-06-30 23:03:03 +0000293 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000294 range = pc_line_entry.range;
Greg Clayton70436352010-06-30 23:03:03 +0000295 }
Greg Clayton24bc5d92011-03-30 18:16:51 +0000296 else
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000297 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000298 m_options.at_pc = true; // No line entry, so just disassemble around the current pc
299 m_options.show_mixed = false;
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000300 }
Greg Clayton70436352010-06-30 23:03:03 +0000301 }
Greg Clayton24bc5d92011-03-30 18:16:51 +0000302
303 // Did the "m_options.frame_line" find a valid range already? If so
304 // skip the rest...
305 if (range.GetByteSize() == 0)
Greg Clayton70436352010-06-30 23:03:03 +0000306 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000307 if (m_options.at_pc)
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000308 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000309 if (exe_ctx.frame == NULL)
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000310 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000311 result.AppendError ("Cannot disassemble around the current PC without a selected frame.\n");
312 result.SetStatus (eReturnStatusFailed);
313 return false;
314 }
315 range.GetBaseAddress() = exe_ctx.frame->GetFrameCodeAddress();
316 if (m_options.num_instructions == 0)
317 {
318 // Disassembling at the PC always disassembles some number of instructions (not the whole function).
319 m_options.num_instructions = DEFAULT_DISASM_NUM_INS;
320 }
321 }
322 else
323 {
324 range.GetBaseAddress().SetOffset (m_options.start_addr);
325 if (range.GetBaseAddress().IsValid())
326 {
327 if (m_options.end_addr != LLDB_INVALID_ADDRESS)
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000328 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000329 if (m_options.end_addr <= m_options.start_addr)
330 {
331 result.AppendErrorWithFormat ("End address before start address.\n");
332 result.SetStatus (eReturnStatusFailed);
333 return false;
334 }
335 range.SetByteSize (m_options.end_addr - m_options.start_addr);
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000336 }
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000337 }
338 }
339 }
340
341 if (m_options.num_instructions != 0)
342 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000343 if (!range.GetBaseAddress().IsValid())
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000344 {
345 // The default action is to disassemble the current frame function.
346 if (exe_ctx.frame)
347 {
348 SymbolContext sc(exe_ctx.frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol));
349 if (sc.function)
Greg Clayton24bc5d92011-03-30 18:16:51 +0000350 range.GetBaseAddress() = sc.function->GetAddressRange().GetBaseAddress();
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000351 else if (sc.symbol && sc.symbol->GetAddressRangePtr())
Greg Clayton24bc5d92011-03-30 18:16:51 +0000352 range.GetBaseAddress() = sc.symbol->GetAddressRangePtr()->GetBaseAddress();
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000353 else
Greg Clayton24bc5d92011-03-30 18:16:51 +0000354 range.GetBaseAddress() = exe_ctx.frame->GetFrameCodeAddress();
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000355 }
356
Greg Clayton24bc5d92011-03-30 18:16:51 +0000357 if (!range.GetBaseAddress().IsValid())
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000358 {
359 result.AppendError ("invalid frame");
360 result.SetStatus (eReturnStatusFailed);
361 return false;
362 }
363 }
364
365 if (Disassembler::Disassemble (m_interpreter.GetDebugger(),
Greg Clayton24bc5d92011-03-30 18:16:51 +0000366 m_options.arch,
Greg Clayton149731c2011-03-25 18:03:16 +0000367 plugin_name,
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000368 exe_ctx,
Greg Clayton24bc5d92011-03-30 18:16:51 +0000369 range.GetBaseAddress(),
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000370 m_options.num_instructions,
371 m_options.show_mixed ? m_options.num_lines_context : 0,
372 m_options.show_bytes,
373 m_options.raw,
374 result.GetOutputStream()))
375 {
376 result.SetStatus (eReturnStatusSuccessFinishResult);
377 }
378 else
379 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000380 result.AppendErrorWithFormat ("Failed to disassemble memory at 0x%8.8llx.\n", m_options.start_addr);
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000381 result.SetStatus (eReturnStatusFailed);
382 }
383 }
384 else
385 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000386 if (!range.GetBaseAddress().IsValid())
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000387 {
388 // The default action is to disassemble the current frame function.
389 if (exe_ctx.frame)
390 {
391 SymbolContext sc(exe_ctx.frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol));
392 if (sc.function)
393 range = sc.function->GetAddressRange();
394 else if (sc.symbol && sc.symbol->GetAddressRangePtr())
395 range = *sc.symbol->GetAddressRangePtr();
396 else
397 range.GetBaseAddress() = exe_ctx.frame->GetFrameCodeAddress();
398 }
399 else
400 {
401 result.AppendError ("invalid frame");
402 result.SetStatus (eReturnStatusFailed);
403 return false;
404 }
405 }
406 if (range.GetByteSize() == 0)
407 range.SetByteSize(DEFAULT_DISASM_BYTE_SIZE);
408
409 if (Disassembler::Disassemble (m_interpreter.GetDebugger(),
Greg Clayton24bc5d92011-03-30 18:16:51 +0000410 m_options.arch,
Greg Clayton149731c2011-03-25 18:03:16 +0000411 plugin_name,
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000412 exe_ctx,
413 range,
414 m_options.num_instructions,
415 m_options.show_mixed ? m_options.num_lines_context : 0,
416 m_options.show_bytes,
417 m_options.raw,
418 result.GetOutputStream()))
419 {
420 result.SetStatus (eReturnStatusSuccessFinishResult);
421 }
422 else
423 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000424 result.AppendErrorWithFormat ("Failed to disassemble memory at 0x%8.8llx.\n", m_options.start_addr);
Jim Inghamaa3e3e12011-03-22 01:48:42 +0000425 result.SetStatus (eReturnStatusFailed);
426 }
Greg Clayton70436352010-06-30 23:03:03 +0000427 }
Chris Lattner24943d22010-06-08 16:52:24 +0000428 }
429
Jim Ingham34e9a982010-06-15 18:47:14 +0000430 return result.Succeeded();
Chris Lattner24943d22010-06-08 16:52:24 +0000431}