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 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 35 | CommandObjectDisassemble::CommandOptions::CommandOptions (CommandInterpreter &interpreter) : |
Johnny Chen | 0e0636d | 2011-04-08 22:15:29 +0000 | [diff] [blame] | 36 | Options(interpreter), |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 37 | num_lines_context(0), |
| 38 | num_instructions (0), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 39 | func_name(), |
| 40 | start_addr(), |
| 41 | end_addr (), |
| 42 | at_pc (false), |
| 43 | frame_line (false), |
| 44 | plugin_name (), |
| 45 | arch() |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | { |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 47 | OptionParsingStarting(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | CommandObjectDisassemble::CommandOptions::~CommandOptions () |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | Error |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 55 | CommandObjectDisassemble::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 56 | { |
| 57 | Error error; |
| 58 | |
| 59 | char short_option = (char) m_getopt_table[option_idx].val; |
| 60 | |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 61 | bool success; |
| 62 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 63 | switch (short_option) |
| 64 | { |
| 65 | case 'm': |
| 66 | show_mixed = true; |
| 67 | break; |
| 68 | |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 69 | case 'C': |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 70 | 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | case 'c': |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 76 | 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 79 | break; |
| 80 | |
| 81 | case 'b': |
| 82 | show_bytes = true; |
| 83 | break; |
| 84 | |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 85 | case 's': |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 86 | 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 89 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 90 | if (start_addr == LLDB_INVALID_ADDRESS) |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 91 | error.SetErrorStringWithFormat ("Invalid start address string '%s'.\n", option_arg); |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 92 | break; |
| 93 | case 'e': |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 94 | 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 Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 97 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 98 | if (end_addr == LLDB_INVALID_ADDRESS) |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 99 | error.SetErrorStringWithFormat ("Invalid end address string '%s'.\n", option_arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 100 | break; |
| 101 | |
| 102 | case 'n': |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 103 | func_name.assign (option_arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 104 | break; |
| 105 | |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 106 | case 'p': |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 107 | 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 Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 115 | break; |
| 116 | |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 117 | case 'P': |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 118 | plugin_name.assign (option_arg); |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 119 | break; |
| 120 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 121 | case 'r': |
| 122 | raw = true; |
| 123 | break; |
| 124 | |
Johnny Chen | 61c1b8b | 2010-10-29 19:33:40 +0000 | [diff] [blame] | 125 | 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 Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 130 | case 'a': |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 131 | arch.SetTriple (option_arg, m_interpreter.GetPlatform (true).get()); |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 132 | break; |
| 133 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 134 | default: |
| 135 | error.SetErrorStringWithFormat("Unrecognized short option '%c'.\n", short_option); |
| 136 | break; |
| 137 | } |
| 138 | |
| 139 | return error; |
| 140 | } |
| 141 | |
| 142 | void |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 143 | CommandObjectDisassemble::CommandOptions::OptionParsingStarting () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 144 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 145 | show_mixed = false; |
| 146 | show_bytes = false; |
| 147 | num_lines_context = 0; |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 148 | num_instructions = 0; |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 149 | func_name.clear(); |
| 150 | at_pc = false; |
| 151 | frame_line = false; |
| 152 | start_addr = LLDB_INVALID_ADDRESS; |
| 153 | end_addr = LLDB_INVALID_ADDRESS; |
Sean Callanan | 944be70 | 2010-06-17 00:32:05 +0000 | [diff] [blame] | 154 | raw = false; |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 155 | plugin_name.clear(); |
| 156 | arch.Clear(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 159 | const OptionDefinition* |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 160 | CommandObjectDisassemble::CommandOptions::GetDefinitions () |
| 161 | { |
| 162 | return g_option_table; |
| 163 | } |
| 164 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 165 | OptionDefinition |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 166 | CommandObjectDisassemble::CommandOptions::g_option_table[] = |
| 167 | { |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 168 | { 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 Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 183 | { 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 Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 185 | { 0 , false , NULL, 0, 0 , NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 186 | }; |
| 187 | |
| 188 | |
| 189 | |
| 190 | //------------------------------------------------------------------------- |
| 191 | // CommandObjectDisassemble |
| 192 | //------------------------------------------------------------------------- |
| 193 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 194 | CommandObjectDisassemble::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 Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 198 | "disassemble [<cmd-options>]"), |
| 199 | m_options (interpreter) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 200 | { |
| 201 | } |
| 202 | |
| 203 | CommandObjectDisassemble::~CommandObjectDisassemble() |
| 204 | { |
| 205 | } |
| 206 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 207 | bool |
| 208 | CommandObjectDisassemble::Execute |
| 209 | ( |
| 210 | Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 211 | CommandReturnObject &result |
| 212 | ) |
| 213 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 214 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 215 | if (target == NULL) |
| 216 | { |
Greg Clayton | e1f50b9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 217 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 218 | result.SetStatus (eReturnStatusFailed); |
| 219 | return false; |
| 220 | } |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 221 | if (!m_options.arch.IsValid()) |
| 222 | m_options.arch = target->GetArchitecture(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 223 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 224 | if (!m_options.arch.IsValid()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 225 | { |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 226 | result.AppendError ("use the --arch option or set the target architecure to disassemble"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 227 | result.SetStatus (eReturnStatusFailed); |
| 228 | return false; |
| 229 | } |
| 230 | |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 231 | const char *plugin_name = m_options.GetPluginName (); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 232 | Disassembler *disassembler = Disassembler::FindPlugin(m_options.arch, plugin_name); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 233 | |
| 234 | if (disassembler == NULL) |
| 235 | { |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 236 | if (plugin_name) |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 237 | result.AppendErrorWithFormat ("Unable to find Disassembler plug-in named '%s' that supports the '%s' architecture.\n", |
| 238 | plugin_name, |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 239 | m_options.arch.GetArchitectureName()); |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 240 | else |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 241 | result.AppendErrorWithFormat ("Unable to find Disassembler plug-in for the '%s' architecture.\n", |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 242 | m_options.arch.GetArchitectureName()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 243 | result.SetStatus (eReturnStatusFailed); |
| 244 | return false; |
| 245 | } |
| 246 | |
| 247 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 248 | |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 249 | if (command.GetArgumentCount() != 0) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 250 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 251 | result.AppendErrorWithFormat ("\"disassemble\" arguments are specified as options.\n"); |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 252 | GetOptions()->GenerateOptionUsage (result.GetErrorStream(), this); |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 253 | result.SetStatus (eReturnStatusFailed); |
| 254 | return false; |
| 255 | } |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 256 | |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 257 | if (m_options.show_mixed && m_options.num_lines_context == 0) |
Greg Clayton | 1924e24 | 2010-09-15 05:51:24 +0000 | [diff] [blame] | 258 | m_options.num_lines_context = 1; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 259 | |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 260 | ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); |
Greg Clayton | 6377f5c | 2011-06-28 19:01:40 +0000 | [diff] [blame^] | 261 | // Always show the PC in the disassembly |
| 262 | uint32_t options = Disassembler::eOptionMarkPCAddress; |
Greg Clayton | 4bb0f19 | 2011-06-22 01:39:49 +0000 | [diff] [blame] | 263 | |
Greg Clayton | 6377f5c | 2011-06-28 19:01:40 +0000 | [diff] [blame^] | 264 | // Mark the source line for the current PC only if we are doing mixed source and assembly |
| 265 | if (m_options.show_mixed) |
| 266 | options |= Disassembler::eOptionMarkPCSourceLine; |
Greg Clayton | 4bb0f19 | 2011-06-22 01:39:49 +0000 | [diff] [blame] | 267 | |
| 268 | if (m_options.show_bytes) |
| 269 | options |= Disassembler::eOptionShowBytes; |
| 270 | |
| 271 | if (m_options.raw) |
| 272 | options |= Disassembler::eOptionRawOuput; |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 273 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 274 | if (!m_options.func_name.empty()) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 275 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 276 | ConstString name(m_options.func_name.c_str()); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 277 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 278 | if (Disassembler::Disassemble (m_interpreter.GetDebugger(), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 279 | m_options.arch, |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 280 | plugin_name, |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 281 | exe_ctx, |
| 282 | name, |
| 283 | NULL, // Module * |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 284 | m_options.num_instructions, |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 285 | m_options.show_mixed ? m_options.num_lines_context : 0, |
Greg Clayton | 4bb0f19 | 2011-06-22 01:39:49 +0000 | [diff] [blame] | 286 | options, |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 287 | result.GetOutputStream())) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 288 | { |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 289 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 290 | } |
| 291 | else |
| 292 | { |
| 293 | result.AppendErrorWithFormat ("Unable to find symbol with name '%s'.\n", name.GetCString()); |
| 294 | result.SetStatus (eReturnStatusFailed); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 295 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 296 | } |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 297 | else |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 298 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 299 | AddressRange range; |
| 300 | if (m_options.frame_line) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 301 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 302 | LineEntry pc_line_entry (exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry).line_entry); |
| 303 | if (pc_line_entry.IsValid()) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 304 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 305 | range = pc_line_entry.range; |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 306 | } |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 307 | else |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 308 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 309 | m_options.at_pc = true; // No line entry, so just disassemble around the current pc |
| 310 | m_options.show_mixed = false; |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 311 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 312 | } |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 313 | |
| 314 | // Did the "m_options.frame_line" find a valid range already? If so |
| 315 | // skip the rest... |
| 316 | if (range.GetByteSize() == 0) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 317 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 318 | if (m_options.at_pc) |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 319 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 320 | if (exe_ctx.frame == NULL) |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 321 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 322 | result.AppendError ("Cannot disassemble around the current PC without a selected frame.\n"); |
| 323 | result.SetStatus (eReturnStatusFailed); |
| 324 | return false; |
| 325 | } |
| 326 | range.GetBaseAddress() = exe_ctx.frame->GetFrameCodeAddress(); |
| 327 | if (m_options.num_instructions == 0) |
| 328 | { |
| 329 | // Disassembling at the PC always disassembles some number of instructions (not the whole function). |
| 330 | m_options.num_instructions = DEFAULT_DISASM_NUM_INS; |
| 331 | } |
| 332 | } |
| 333 | else |
| 334 | { |
| 335 | range.GetBaseAddress().SetOffset (m_options.start_addr); |
| 336 | if (range.GetBaseAddress().IsValid()) |
| 337 | { |
| 338 | if (m_options.end_addr != LLDB_INVALID_ADDRESS) |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 339 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 340 | if (m_options.end_addr <= m_options.start_addr) |
| 341 | { |
| 342 | result.AppendErrorWithFormat ("End address before start address.\n"); |
| 343 | result.SetStatus (eReturnStatusFailed); |
| 344 | return false; |
| 345 | } |
| 346 | range.SetByteSize (m_options.end_addr - m_options.start_addr); |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 347 | } |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | if (m_options.num_instructions != 0) |
| 353 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 354 | if (!range.GetBaseAddress().IsValid()) |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 355 | { |
| 356 | // The default action is to disassemble the current frame function. |
| 357 | if (exe_ctx.frame) |
| 358 | { |
| 359 | SymbolContext sc(exe_ctx.frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol)); |
| 360 | if (sc.function) |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 361 | range.GetBaseAddress() = sc.function->GetAddressRange().GetBaseAddress(); |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 362 | else if (sc.symbol && sc.symbol->GetAddressRangePtr()) |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 363 | range.GetBaseAddress() = sc.symbol->GetAddressRangePtr()->GetBaseAddress(); |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 364 | else |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 365 | range.GetBaseAddress() = exe_ctx.frame->GetFrameCodeAddress(); |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 368 | if (!range.GetBaseAddress().IsValid()) |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 369 | { |
| 370 | result.AppendError ("invalid frame"); |
| 371 | result.SetStatus (eReturnStatusFailed); |
| 372 | return false; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | if (Disassembler::Disassemble (m_interpreter.GetDebugger(), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 377 | m_options.arch, |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 378 | plugin_name, |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 379 | exe_ctx, |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 380 | range.GetBaseAddress(), |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 381 | m_options.num_instructions, |
| 382 | m_options.show_mixed ? m_options.num_lines_context : 0, |
Greg Clayton | 4bb0f19 | 2011-06-22 01:39:49 +0000 | [diff] [blame] | 383 | options, |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 384 | result.GetOutputStream())) |
| 385 | { |
| 386 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 387 | } |
| 388 | else |
| 389 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 390 | result.AppendErrorWithFormat ("Failed to disassemble memory at 0x%8.8llx.\n", m_options.start_addr); |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 391 | result.SetStatus (eReturnStatusFailed); |
| 392 | } |
| 393 | } |
| 394 | else |
| 395 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 396 | if (!range.GetBaseAddress().IsValid()) |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 397 | { |
| 398 | // The default action is to disassemble the current frame function. |
| 399 | if (exe_ctx.frame) |
| 400 | { |
| 401 | SymbolContext sc(exe_ctx.frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol)); |
| 402 | if (sc.function) |
| 403 | range = sc.function->GetAddressRange(); |
| 404 | else if (sc.symbol && sc.symbol->GetAddressRangePtr()) |
| 405 | range = *sc.symbol->GetAddressRangePtr(); |
| 406 | else |
| 407 | range.GetBaseAddress() = exe_ctx.frame->GetFrameCodeAddress(); |
| 408 | } |
| 409 | else |
| 410 | { |
| 411 | result.AppendError ("invalid frame"); |
| 412 | result.SetStatus (eReturnStatusFailed); |
| 413 | return false; |
| 414 | } |
| 415 | } |
| 416 | if (range.GetByteSize() == 0) |
| 417 | range.SetByteSize(DEFAULT_DISASM_BYTE_SIZE); |
| 418 | |
| 419 | if (Disassembler::Disassemble (m_interpreter.GetDebugger(), |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 420 | m_options.arch, |
Greg Clayton | 149731c | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 421 | plugin_name, |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 422 | exe_ctx, |
| 423 | range, |
| 424 | m_options.num_instructions, |
| 425 | m_options.show_mixed ? m_options.num_lines_context : 0, |
Greg Clayton | 4bb0f19 | 2011-06-22 01:39:49 +0000 | [diff] [blame] | 426 | options, |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 427 | result.GetOutputStream())) |
| 428 | { |
| 429 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 430 | } |
| 431 | else |
| 432 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 433 | result.AppendErrorWithFormat ("Failed to disassemble memory at 0x%8.8llx.\n", m_options.start_addr); |
Jim Ingham | aa3e3e1 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 434 | result.SetStatus (eReturnStatusFailed); |
| 435 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 436 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 437 | } |
| 438 | |
Jim Ingham | 34e9a98 | 2010-06-15 18:47:14 +0000 | [diff] [blame] | 439 | return result.Succeeded(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 440 | } |