Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Ingham | 84cdc15 | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 17 | #include "lldb/Interpreter/Args.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Interpreter/CommandCompletions.h" |
| 19 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 20 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 21 | #include "lldb/Core/Disassembler.h" |
Jim Ingham | 84cdc15 | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 22 | #include "lldb/Interpreter/Options.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #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 Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 30 | #define DEFAULT_DISASM_NUM_INS 4 |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | |
| 32 | using namespace lldb; |
| 33 | using namespace lldb_private; |
| 34 | |
| 35 | CommandObjectDisassemble::CommandOptions::CommandOptions () : |
| 36 | Options(), |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 37 | num_lines_context(0), |
| 38 | num_instructions (0), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | m_func_name(), |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 40 | m_start_addr(), |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 41 | m_end_addr (), |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame^] | 42 | m_at_pc (false), |
| 43 | m_plugin_name () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | { |
| 45 | ResetOptionValues(); |
| 46 | } |
| 47 | |
| 48 | CommandObjectDisassemble::CommandOptions::~CommandOptions () |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | Error |
| 53 | CommandObjectDisassemble::CommandOptions::SetOptionValue (int option_idx, const char *option_arg) |
| 54 | { |
| 55 | Error error; |
| 56 | |
| 57 | char short_option = (char) m_getopt_table[option_idx].val; |
| 58 | |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 59 | bool success; |
| 60 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | switch (short_option) |
| 62 | { |
| 63 | case 'm': |
| 64 | show_mixed = true; |
| 65 | break; |
| 66 | |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 67 | case 'x': |
| 68 | num_lines_context = Args::StringToUInt32(option_arg, 0, 0, &success); |
| 69 | if (!success) |
| 70 | error.SetErrorStringWithFormat ("Invalid num context lines string: \"%s\".\n", option_arg); |
| 71 | break; |
| 72 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 73 | case 'c': |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 74 | num_instructions = Args::StringToUInt32(option_arg, 0, 0, &success); |
| 75 | if (!success) |
| 76 | error.SetErrorStringWithFormat ("Invalid num of instructions string: \"%s\".\n", option_arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 77 | break; |
| 78 | |
| 79 | case 'b': |
| 80 | show_bytes = true; |
| 81 | break; |
| 82 | |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 83 | case 's': |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 84 | m_start_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0); |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 85 | if (m_start_addr == LLDB_INVALID_ADDRESS) |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 86 | m_start_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 87 | |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 88 | if (m_start_addr == LLDB_INVALID_ADDRESS) |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 89 | error.SetErrorStringWithFormat ("Invalid start address string '%s'.\n", option_arg); |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 90 | break; |
| 91 | case 'e': |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 92 | m_end_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0); |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 93 | if (m_end_addr == LLDB_INVALID_ADDRESS) |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 94 | m_end_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 16); |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 95 | |
| 96 | if (m_end_addr == LLDB_INVALID_ADDRESS) |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 97 | error.SetErrorStringWithFormat ("Invalid end address string '%s'.\n", option_arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 98 | break; |
| 99 | |
| 100 | case 'n': |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame^] | 101 | m_func_name.assign (option_arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 102 | break; |
| 103 | |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 104 | case 'p': |
| 105 | m_at_pc = true; |
| 106 | break; |
| 107 | |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame^] | 108 | case 'P': |
| 109 | m_plugin_name.assign (option_arg); |
| 110 | break; |
| 111 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 112 | case 'r': |
| 113 | raw = true; |
| 114 | break; |
| 115 | |
Johnny Chen | 61c1b8b | 2010-10-29 19:33:40 +0000 | [diff] [blame] | 116 | case 'f': |
| 117 | // The default action is to disassemble the function for the current frame. |
| 118 | // There's no need to set any flag. |
| 119 | break; |
| 120 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 121 | default: |
| 122 | error.SetErrorStringWithFormat("Unrecognized short option '%c'.\n", short_option); |
| 123 | break; |
| 124 | } |
| 125 | |
| 126 | return error; |
| 127 | } |
| 128 | |
| 129 | void |
| 130 | CommandObjectDisassemble::CommandOptions::ResetOptionValues () |
| 131 | { |
| 132 | Options::ResetOptionValues(); |
| 133 | show_mixed = false; |
| 134 | show_bytes = false; |
| 135 | num_lines_context = 0; |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 136 | num_instructions = 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 137 | m_func_name.clear(); |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 138 | m_at_pc = false; |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 139 | m_start_addr = LLDB_INVALID_ADDRESS; |
| 140 | m_end_addr = LLDB_INVALID_ADDRESS; |
Sean Callanan | 944be70 | 2010-06-17 00:32:05 +0000 | [diff] [blame] | 141 | raw = false; |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame^] | 142 | m_plugin_name.clear(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 145 | const OptionDefinition* |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 146 | CommandObjectDisassemble::CommandOptions::GetDefinitions () |
| 147 | { |
| 148 | return g_option_table; |
| 149 | } |
| 150 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 151 | OptionDefinition |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 152 | CommandObjectDisassemble::CommandOptions::g_option_table[] = |
| 153 | { |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame^] | 154 | { LLDB_OPT_SET_ALL, false, "bytes", 'b', no_argument, NULL, 0, eArgTypeNone, "Show opcode bytes when disassembling."}, |
| 155 | { LLDB_OPT_SET_ALL, false, "context", 'x', required_argument, NULL, 0, eArgTypeNumLines,"Number of context lines of source to show."}, |
| 156 | { LLDB_OPT_SET_ALL, false, "mixed", 'm', no_argument, NULL, 0, eArgTypeNone, "Enable mixed source and assembly display."}, |
| 157 | { LLDB_OPT_SET_ALL, false, "raw", 'r', no_argument, NULL, 0, eArgTypeNone, "Print raw disassembly with no symbol information."}, |
| 158 | { LLDB_OPT_SET_ALL, false, "plugin", 'P', required_argument, NULL, 0, eArgTypePlugin, "Name of the disassembler plugin you want to use."}, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 159 | |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 160 | { LLDB_OPT_SET_1, true, "start-address", 's', required_argument, NULL, 0, eArgTypeStartAddress, "Address at which to start disassembling."}, |
| 161 | { LLDB_OPT_SET_1, false, "end-address", 'e', required_argument, NULL, 0, eArgTypeEndAddress, "Address at which to end disassembling."}, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 162 | |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 163 | { LLDB_OPT_SET_2, true, "start-address", 's', required_argument, NULL, 0, eArgTypeStartAddress, "Address at which to start disassembling."}, |
| 164 | { LLDB_OPT_SET_2, false, "instruction-count", 'c', required_argument, NULL, 0, eArgTypeNumLines, "Number of instructions to display."}, |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 165 | |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 166 | { LLDB_OPT_SET_3, true, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Disassemble entire contents of the given function name."}, |
| 167 | { LLDB_OPT_SET_3, false, "instruction-count", 'c', required_argument, NULL, 0, eArgTypeNumLines, "Number of instructions to display."}, |
| 168 | |
| 169 | { LLDB_OPT_SET_4, true, "current-frame", 'f', no_argument, NULL, 0, eArgTypeNone, "Disassemble from the start of the current frame's function."}, |
| 170 | { LLDB_OPT_SET_4, false, "instruction-count", 'c', required_argument, NULL, 0, eArgTypeNumLines, "Number of instructions to display."}, |
| 171 | |
| 172 | { LLDB_OPT_SET_5, true, "current-pc", 'p', no_argument, NULL, 0, eArgTypeNone, "Disassemble from the current pc."}, |
| 173 | { LLDB_OPT_SET_5, false, "instruction-count", 'c', required_argument, NULL, 0, eArgTypeNumLines, "Number of instructions to display."}, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 174 | |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 175 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | |
| 179 | |
| 180 | //------------------------------------------------------------------------- |
| 181 | // CommandObjectDisassemble |
| 182 | //------------------------------------------------------------------------- |
| 183 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 184 | CommandObjectDisassemble::CommandObjectDisassemble (CommandInterpreter &interpreter) : |
| 185 | CommandObject (interpreter, |
| 186 | "disassemble", |
| 187 | "Disassemble bytes in the current function, or elsewhere in the executable program as specified by the user.", |
| 188 | "disassemble [<cmd-options>]") |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 189 | { |
| 190 | } |
| 191 | |
| 192 | CommandObjectDisassemble::~CommandObjectDisassemble() |
| 193 | { |
| 194 | } |
| 195 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 196 | bool |
| 197 | CommandObjectDisassemble::Execute |
| 198 | ( |
| 199 | Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 200 | CommandReturnObject &result |
| 201 | ) |
| 202 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 203 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 204 | if (target == NULL) |
| 205 | { |
| 206 | result.AppendError ("invalid target, set executable file using 'file' command"); |
| 207 | result.SetStatus (eReturnStatusFailed); |
| 208 | return false; |
| 209 | } |
| 210 | |
| 211 | ArchSpec arch(target->GetArchitecture()); |
| 212 | if (!arch.IsValid()) |
| 213 | { |
| 214 | result.AppendError ("target needs valid architecure in order to be able to disassemble"); |
| 215 | result.SetStatus (eReturnStatusFailed); |
| 216 | return false; |
| 217 | } |
| 218 | |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame^] | 219 | const char *plugin_name = m_options.GetPluginName (); |
| 220 | Disassembler *disassembler = Disassembler::FindPlugin(arch, plugin_name); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 221 | |
| 222 | if (disassembler == NULL) |
| 223 | { |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame^] | 224 | if (plugin_name) |
| 225 | result.AppendErrorWithFormat ("Unable to find Disassembler plug-in for %s architecture named '%s'.\n", |
| 226 | arch.GetArchitectureName(), |
| 227 | plugin_name); |
| 228 | else |
| 229 | result.AppendErrorWithFormat ("Unable to find Disassembler plug-in for %s architecture.\n", |
| 230 | arch.GetArchitectureName()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 231 | result.SetStatus (eReturnStatusFailed); |
| 232 | return false; |
| 233 | } |
| 234 | |
| 235 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 236 | |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 237 | if (command.GetArgumentCount() != 0) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 238 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 239 | result.AppendErrorWithFormat ("\"disassemble\" arguments are specified as options.\n"); |
| 240 | GetOptions()->GenerateOptionUsage (m_interpreter, |
| 241 | result.GetErrorStream(), |
| 242 | this); |
| 243 | |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 244 | result.SetStatus (eReturnStatusFailed); |
| 245 | return false; |
| 246 | } |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 247 | |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 248 | if (m_options.show_mixed && m_options.num_lines_context == 0) |
Greg Clayton | 1924e24 | 2010-09-15 05:51:24 +0000 | [diff] [blame] | 249 | m_options.num_lines_context = 1; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 250 | |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 251 | ExecutionContext exe_ctx(m_interpreter.GetDebugger().GetExecutionContext()); |
| 252 | |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 253 | if (!m_options.m_func_name.empty()) |
| 254 | { |
| 255 | ConstString name(m_options.m_func_name.c_str()); |
| 256 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 257 | if (Disassembler::Disassemble (m_interpreter.GetDebugger(), |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 258 | arch, |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame^] | 259 | plugin_name, |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 260 | exe_ctx, |
| 261 | name, |
| 262 | NULL, // Module * |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 263 | m_options.num_instructions, |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 264 | m_options.show_mixed ? m_options.num_lines_context : 0, |
| 265 | m_options.show_bytes, |
Sean Callanan | a846cc3 | 2011-03-10 23:35:12 +0000 | [diff] [blame] | 266 | m_options.raw, |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 267 | result.GetOutputStream())) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 268 | { |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 269 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 270 | } |
| 271 | else |
| 272 | { |
| 273 | result.AppendErrorWithFormat ("Unable to find symbol with name '%s'.\n", name.GetCString()); |
| 274 | result.SetStatus (eReturnStatusFailed); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 275 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 276 | } |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 277 | else |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 278 | { |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 279 | Address start_addr; |
| 280 | lldb::addr_t range_byte_size = DEFAULT_DISASM_BYTE_SIZE; |
| 281 | |
| 282 | if (m_options.m_at_pc) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 283 | { |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 284 | if (exe_ctx.frame == NULL) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 285 | { |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 286 | result.AppendError ("Cannot disassemble around the current PC without a selected frame.\n"); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 287 | result.SetStatus (eReturnStatusFailed); |
| 288 | return false; |
| 289 | } |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 290 | start_addr = exe_ctx.frame->GetFrameCodeAddress(); |
| 291 | if (m_options.num_instructions == 0) |
| 292 | { |
| 293 | // Disassembling at the PC always disassembles some number of instructions (not the whole function). |
| 294 | m_options.num_instructions = DEFAULT_DISASM_NUM_INS; |
| 295 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 296 | } |
| 297 | else |
| 298 | { |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 299 | start_addr.SetOffset (m_options.m_start_addr); |
| 300 | if (start_addr.IsValid()) |
| 301 | { |
| 302 | if (m_options.m_end_addr != LLDB_INVALID_ADDRESS) |
| 303 | { |
| 304 | if (m_options.m_end_addr < m_options.m_start_addr) |
| 305 | { |
| 306 | result.AppendErrorWithFormat ("End address before start address.\n"); |
| 307 | result.SetStatus (eReturnStatusFailed); |
| 308 | return false; |
| 309 | } |
| 310 | range_byte_size = m_options.m_end_addr - m_options.m_start_addr; |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | if (m_options.num_instructions != 0) |
| 316 | { |
| 317 | if (!start_addr.IsValid()) |
| 318 | { |
| 319 | // The default action is to disassemble the current frame function. |
| 320 | if (exe_ctx.frame) |
| 321 | { |
| 322 | SymbolContext sc(exe_ctx.frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol)); |
| 323 | if (sc.function) |
| 324 | start_addr = sc.function->GetAddressRange().GetBaseAddress(); |
| 325 | else if (sc.symbol && sc.symbol->GetAddressRangePtr()) |
| 326 | start_addr = sc.symbol->GetAddressRangePtr()->GetBaseAddress(); |
| 327 | else |
| 328 | start_addr = exe_ctx.frame->GetFrameCodeAddress(); |
| 329 | } |
| 330 | |
| 331 | if (!start_addr.IsValid()) |
| 332 | { |
| 333 | result.AppendError ("invalid frame"); |
| 334 | result.SetStatus (eReturnStatusFailed); |
| 335 | return false; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | if (Disassembler::Disassemble (m_interpreter.GetDebugger(), |
| 340 | arch, |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame^] | 341 | plugin_name, |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 342 | exe_ctx, |
| 343 | start_addr, |
| 344 | m_options.num_instructions, |
| 345 | m_options.show_mixed ? m_options.num_lines_context : 0, |
| 346 | m_options.show_bytes, |
| 347 | m_options.raw, |
| 348 | result.GetOutputStream())) |
| 349 | { |
| 350 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 351 | } |
| 352 | else |
| 353 | { |
| 354 | result.AppendErrorWithFormat ("Failed to disassemble memory at 0x%8.8llx.\n", m_options.m_start_addr); |
| 355 | result.SetStatus (eReturnStatusFailed); |
| 356 | } |
| 357 | } |
| 358 | else |
| 359 | { |
| 360 | AddressRange range; |
| 361 | if (start_addr.IsValid()) |
| 362 | { |
| 363 | range.GetBaseAddress() = start_addr; |
| 364 | range.SetByteSize (range_byte_size); |
| 365 | } |
| 366 | else |
| 367 | { |
| 368 | // The default action is to disassemble the current frame function. |
| 369 | if (exe_ctx.frame) |
| 370 | { |
| 371 | SymbolContext sc(exe_ctx.frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol)); |
| 372 | if (sc.function) |
| 373 | range = sc.function->GetAddressRange(); |
| 374 | else if (sc.symbol && sc.symbol->GetAddressRangePtr()) |
| 375 | range = *sc.symbol->GetAddressRangePtr(); |
| 376 | else |
| 377 | range.GetBaseAddress() = exe_ctx.frame->GetFrameCodeAddress(); |
| 378 | } |
| 379 | else |
| 380 | { |
| 381 | result.AppendError ("invalid frame"); |
| 382 | result.SetStatus (eReturnStatusFailed); |
| 383 | return false; |
| 384 | } |
| 385 | } |
| 386 | if (range.GetByteSize() == 0) |
| 387 | range.SetByteSize(DEFAULT_DISASM_BYTE_SIZE); |
| 388 | |
| 389 | if (Disassembler::Disassemble (m_interpreter.GetDebugger(), |
| 390 | arch, |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame^] | 391 | plugin_name, |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 392 | exe_ctx, |
| 393 | range, |
| 394 | m_options.num_instructions, |
| 395 | m_options.show_mixed ? m_options.num_lines_context : 0, |
| 396 | m_options.show_bytes, |
| 397 | m_options.raw, |
| 398 | result.GetOutputStream())) |
| 399 | { |
| 400 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 401 | } |
| 402 | else |
| 403 | { |
| 404 | result.AppendErrorWithFormat ("Failed to disassemble memory at 0x%8.8llx.\n", m_options.m_start_addr); |
| 405 | result.SetStatus (eReturnStatusFailed); |
| 406 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 407 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 408 | } |
| 409 | |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 410 | return result.Succeeded(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 411 | } |