Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- Disassembler.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 "lldb/Core/Disassembler.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | #include "lldb/lldb-private.h" |
| 17 | #include "lldb/Core/Error.h" |
| 18 | #include "lldb/Core/DataBufferHeap.h" |
| 19 | #include "lldb/Core/DataExtractor.h" |
| 20 | #include "lldb/Core/Debugger.h" |
Caroline Tice | ad379efc | 2011-04-05 18:46:00 +0000 | [diff] [blame] | 21 | #include "lldb/Core/EmulateInstruction.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Core/Module.h" |
| 23 | #include "lldb/Core/PluginManager.h" |
| 24 | #include "lldb/Core/Timer.h" |
| 25 | #include "lldb/Symbol/ObjectFile.h" |
| 26 | #include "lldb/Target/ExecutionContext.h" |
| 27 | #include "lldb/Target/Process.h" |
| 28 | #include "lldb/Target/StackFrame.h" |
| 29 | #include "lldb/Target/Target.h" |
| 30 | |
| 31 | #define DEFAULT_DISASM_BYTE_SIZE 32 |
| 32 | |
| 33 | using namespace lldb; |
| 34 | using namespace lldb_private; |
| 35 | |
| 36 | |
| 37 | Disassembler* |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 38 | Disassembler::FindPlugin (const ArchSpec &arch, const char *plugin_name) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | { |
| 40 | Timer scoped_timer (__PRETTY_FUNCTION__, |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 41 | "Disassembler::FindPlugin (arch = %s, plugin_name = %s)", |
| 42 | arch.GetArchitectureName(), |
| 43 | plugin_name); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | |
| 45 | std::auto_ptr<Disassembler> disassembler_ap; |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 46 | DisassemblerCreateInstance create_callback = NULL; |
| 47 | |
| 48 | if (plugin_name) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | { |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 50 | create_callback = PluginManager::GetDisassemblerCreateCallbackForPluginName (plugin_name); |
| 51 | if (create_callback) |
| 52 | { |
| 53 | disassembler_ap.reset (create_callback(arch)); |
| 54 | |
| 55 | if (disassembler_ap.get()) |
| 56 | return disassembler_ap.release(); |
| 57 | } |
| 58 | } |
| 59 | else |
| 60 | { |
| 61 | for (uint32_t idx = 0; (create_callback = PluginManager::GetDisassemblerCreateCallbackAtIndex(idx)) != NULL; ++idx) |
| 62 | { |
| 63 | disassembler_ap.reset (create_callback(arch)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 64 | |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 65 | if (disassembler_ap.get()) |
| 66 | return disassembler_ap.release(); |
| 67 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 68 | } |
| 69 | return NULL; |
| 70 | } |
| 71 | |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 72 | |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 73 | static void |
| 74 | ResolveAddress (const ExecutionContext &exe_ctx, |
| 75 | const Address &addr, |
| 76 | Address &resolved_addr) |
| 77 | { |
| 78 | if (!addr.IsSectionOffset()) |
| 79 | { |
| 80 | // If we weren't passed in a section offset address range, |
| 81 | // try and resolve it to something |
| 82 | if (exe_ctx.target) |
| 83 | { |
| 84 | if (exe_ctx.target->GetSectionLoadList().IsEmpty()) |
| 85 | { |
| 86 | exe_ctx.target->GetImages().ResolveFileAddress (addr.GetOffset(), resolved_addr); |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | exe_ctx.target->GetSectionLoadList().ResolveLoadAddress (addr.GetOffset(), resolved_addr); |
| 91 | } |
| 92 | // We weren't able to resolve the address, just treat it as a |
| 93 | // raw address |
| 94 | if (resolved_addr.IsValid()) |
| 95 | return; |
| 96 | } |
| 97 | } |
| 98 | resolved_addr = addr; |
| 99 | } |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 100 | |
| 101 | size_t |
| 102 | Disassembler::Disassemble |
| 103 | ( |
| 104 | Debugger &debugger, |
| 105 | const ArchSpec &arch, |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 106 | const char *plugin_name, |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 107 | const ExecutionContext &exe_ctx, |
| 108 | SymbolContextList &sc_list, |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 109 | uint32_t num_instructions, |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 110 | uint32_t num_mixed_context_lines, |
| 111 | bool show_bytes, |
Sean Callanan | b3396b2 | 2011-03-10 23:35:12 +0000 | [diff] [blame] | 112 | bool raw, |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 113 | Stream &strm |
| 114 | ) |
| 115 | { |
| 116 | size_t success_count = 0; |
| 117 | const size_t count = sc_list.GetSize(); |
| 118 | SymbolContext sc; |
| 119 | AddressRange range; |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 120 | |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 121 | for (size_t i=0; i<count; ++i) |
| 122 | { |
| 123 | if (sc_list.GetContextAtIndex(i, sc) == false) |
| 124 | break; |
| 125 | if (sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, range)) |
| 126 | { |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 127 | if (Disassemble (debugger, |
| 128 | arch, |
| 129 | plugin_name, |
| 130 | exe_ctx, |
| 131 | range, |
| 132 | num_instructions, |
| 133 | num_mixed_context_lines, |
| 134 | show_bytes, |
| 135 | raw, |
| 136 | strm)) |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 137 | { |
| 138 | ++success_count; |
| 139 | strm.EOL(); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | return success_count; |
| 144 | } |
| 145 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 146 | bool |
| 147 | Disassembler::Disassemble |
| 148 | ( |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 149 | Debugger &debugger, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 150 | const ArchSpec &arch, |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 151 | const char *plugin_name, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 152 | const ExecutionContext &exe_ctx, |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 153 | const ConstString &name, |
| 154 | Module *module, |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 155 | uint32_t num_instructions, |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 156 | uint32_t num_mixed_context_lines, |
| 157 | bool show_bytes, |
Sean Callanan | b3396b2 | 2011-03-10 23:35:12 +0000 | [diff] [blame] | 158 | bool raw, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 159 | Stream &strm |
| 160 | ) |
| 161 | { |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 162 | SymbolContextList sc_list; |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 163 | if (name) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 164 | { |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 165 | const bool include_symbols = true; |
| 166 | if (module) |
| 167 | { |
| 168 | module->FindFunctions (name, |
| 169 | eFunctionNameTypeBase | |
| 170 | eFunctionNameTypeFull | |
| 171 | eFunctionNameTypeMethod | |
| 172 | eFunctionNameTypeSelector, |
| 173 | include_symbols, |
| 174 | true, |
| 175 | sc_list); |
| 176 | } |
| 177 | else if (exe_ctx.target) |
| 178 | { |
| 179 | exe_ctx.target->GetImages().FindFunctions (name, |
Greg Clayton | 6dbd398 | 2010-09-15 05:51:24 +0000 | [diff] [blame] | 180 | eFunctionNameTypeBase | |
| 181 | eFunctionNameTypeFull | |
| 182 | eFunctionNameTypeMethod | |
| 183 | eFunctionNameTypeSelector, |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 184 | include_symbols, |
Sean Callanan | 8ade104 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 185 | false, |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 186 | sc_list); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 187 | } |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | if (sc_list.GetSize ()) |
| 191 | { |
| 192 | return Disassemble (debugger, |
| 193 | arch, |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 194 | plugin_name, |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 195 | exe_ctx, |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 196 | sc_list, |
| 197 | num_instructions, |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 198 | num_mixed_context_lines, |
Sean Callanan | b3396b2 | 2011-03-10 23:35:12 +0000 | [diff] [blame] | 199 | show_bytes, |
| 200 | raw, |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 201 | strm); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 202 | } |
| 203 | return false; |
| 204 | } |
| 205 | |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 206 | |
| 207 | lldb::DisassemblerSP |
| 208 | Disassembler::DisassembleRange |
| 209 | ( |
| 210 | const ArchSpec &arch, |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 211 | const char *plugin_name, |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 212 | const ExecutionContext &exe_ctx, |
| 213 | const AddressRange &range |
| 214 | ) |
| 215 | { |
| 216 | lldb::DisassemblerSP disasm_sp; |
| 217 | if (range.GetByteSize() > 0 && range.GetBaseAddress().IsValid()) |
| 218 | { |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 219 | disasm_sp.reset (Disassembler::FindPlugin(arch, plugin_name)); |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 220 | |
| 221 | if (disasm_sp) |
| 222 | { |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 223 | size_t bytes_disassembled = disasm_sp->ParseInstructions (&exe_ctx, range); |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 224 | if (bytes_disassembled == 0) |
| 225 | disasm_sp.reset(); |
| 226 | } |
| 227 | } |
| 228 | return disasm_sp; |
| 229 | } |
| 230 | |
| 231 | |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 232 | bool |
| 233 | Disassembler::Disassemble |
| 234 | ( |
| 235 | Debugger &debugger, |
| 236 | const ArchSpec &arch, |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 237 | const char *plugin_name, |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 238 | const ExecutionContext &exe_ctx, |
| 239 | const AddressRange &disasm_range, |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 240 | uint32_t num_instructions, |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 241 | uint32_t num_mixed_context_lines, |
| 242 | bool show_bytes, |
Sean Callanan | b3396b2 | 2011-03-10 23:35:12 +0000 | [diff] [blame] | 243 | bool raw, |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 244 | Stream &strm |
| 245 | ) |
| 246 | { |
| 247 | if (disasm_range.GetByteSize()) |
| 248 | { |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 249 | std::auto_ptr<Disassembler> disasm_ap (Disassembler::FindPlugin(arch, plugin_name)); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 250 | |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 251 | if (disasm_ap.get()) |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 252 | { |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 253 | AddressRange range; |
| 254 | ResolveAddress (exe_ctx, disasm_range.GetBaseAddress(), range.GetBaseAddress()); |
| 255 | range.SetByteSize (disasm_range.GetByteSize()); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 256 | |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 257 | size_t bytes_disassembled = disasm_ap->ParseInstructions (&exe_ctx, range); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 258 | if (bytes_disassembled == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 259 | return false; |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 260 | |
| 261 | return PrintInstructions (disasm_ap.get(), |
| 262 | debugger, |
| 263 | arch, |
| 264 | exe_ctx, |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 265 | num_instructions, |
| 266 | num_mixed_context_lines, |
| 267 | show_bytes, |
| 268 | raw, |
| 269 | strm); |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | return false; |
| 273 | } |
| 274 | |
| 275 | bool |
| 276 | Disassembler::Disassemble |
| 277 | ( |
| 278 | Debugger &debugger, |
| 279 | const ArchSpec &arch, |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 280 | const char *plugin_name, |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 281 | const ExecutionContext &exe_ctx, |
| 282 | const Address &start_address, |
| 283 | uint32_t num_instructions, |
| 284 | uint32_t num_mixed_context_lines, |
| 285 | bool show_bytes, |
| 286 | bool raw, |
| 287 | Stream &strm |
| 288 | ) |
| 289 | { |
| 290 | if (num_instructions > 0) |
| 291 | { |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 292 | std::auto_ptr<Disassembler> disasm_ap (Disassembler::FindPlugin(arch, plugin_name)); |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 293 | if (disasm_ap.get()) |
| 294 | { |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 295 | Address addr; |
| 296 | ResolveAddress (exe_ctx, start_address, addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 297 | |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 298 | size_t bytes_disassembled = disasm_ap->ParseInstructions (&exe_ctx, addr, num_instructions); |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 299 | if (bytes_disassembled == 0) |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 300 | return false; |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 301 | return PrintInstructions (disasm_ap.get(), |
| 302 | debugger, |
| 303 | arch, |
| 304 | exe_ctx, |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 305 | num_instructions, |
| 306 | num_mixed_context_lines, |
| 307 | show_bytes, |
| 308 | raw, |
| 309 | strm); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 310 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 311 | } |
| 312 | return false; |
| 313 | } |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 314 | |
| 315 | bool |
| 316 | Disassembler::PrintInstructions |
| 317 | ( |
| 318 | Disassembler *disasm_ptr, |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 319 | Debugger &debugger, |
| 320 | const ArchSpec &arch, |
| 321 | const ExecutionContext &exe_ctx, |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 322 | uint32_t num_instructions, |
| 323 | uint32_t num_mixed_context_lines, |
| 324 | bool show_bytes, |
| 325 | bool raw, |
| 326 | Stream &strm |
| 327 | ) |
| 328 | { |
| 329 | // We got some things disassembled... |
| 330 | size_t num_instructions_found = disasm_ptr->GetInstructionList().GetSize(); |
| 331 | |
| 332 | if (num_instructions > 0 && num_instructions < num_instructions_found) |
| 333 | num_instructions_found = num_instructions; |
| 334 | |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 335 | const uint32_t max_opcode_byte_size = disasm_ptr->GetInstructionList().GetMaxOpcocdeByteSize (); |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 336 | uint32_t offset = 0; |
| 337 | SymbolContext sc; |
| 338 | SymbolContext prev_sc; |
| 339 | AddressRange sc_range; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 340 | Address *pc_addr_ptr = NULL; |
| 341 | if (exe_ctx.frame) |
| 342 | pc_addr_ptr = &exe_ctx.frame->GetFrameCodeAddress(); |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 343 | |
| 344 | for (size_t i=0; i<num_instructions_found; ++i) |
| 345 | { |
| 346 | Instruction *inst = disasm_ptr->GetInstructionList().GetInstructionAtIndex (i).get(); |
| 347 | if (inst) |
| 348 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 349 | const Address &addr = inst->GetAddress(); |
| 350 | const bool inst_is_at_pc = pc_addr_ptr && addr == *pc_addr_ptr; |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 351 | |
| 352 | prev_sc = sc; |
| 353 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 354 | Module *module = addr.GetModule(); |
| 355 | if (module) |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 356 | { |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 357 | uint32_t resolved_mask = module->ResolveSymbolContextForAddress(addr, eSymbolContextEverything, sc); |
| 358 | if (resolved_mask) |
| 359 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 360 | if (num_mixed_context_lines) |
| 361 | { |
| 362 | if (!sc_range.ContainsFileAddress (addr)) |
| 363 | { |
| 364 | sc.GetAddressRange (eSymbolContextEverything, sc_range); |
| 365 | |
| 366 | if (sc != prev_sc) |
| 367 | { |
| 368 | if (offset != 0) |
| 369 | strm.EOL(); |
| 370 | |
| 371 | sc.DumpStopContext(&strm, exe_ctx.process, addr, false, true, false); |
| 372 | strm.EOL(); |
| 373 | |
| 374 | if (sc.comp_unit && sc.line_entry.IsValid()) |
| 375 | { |
| 376 | debugger.GetSourceManager().DisplaySourceLinesWithLineNumbers (sc.line_entry.file, |
| 377 | sc.line_entry.line, |
| 378 | num_mixed_context_lines, |
| 379 | num_mixed_context_lines, |
| 380 | num_mixed_context_lines ? "->" : "", |
| 381 | &strm); |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | else if (!(prev_sc.function == sc.function || prev_sc.symbol == sc.symbol)) |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 387 | { |
| 388 | if (prev_sc.function || prev_sc.symbol) |
| 389 | strm.EOL(); |
| 390 | |
| 391 | strm << sc.module_sp->GetFileSpec().GetFilename(); |
| 392 | |
| 393 | if (sc.function) |
| 394 | strm << '`' << sc.function->GetMangled().GetName(); |
| 395 | else if (sc.symbol) |
| 396 | strm << '`' << sc.symbol->GetMangled().GetName(); |
| 397 | strm << ":\n"; |
| 398 | } |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 399 | } |
| 400 | else |
| 401 | { |
| 402 | sc.Clear(); |
| 403 | } |
| 404 | } |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 405 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 406 | if (pc_addr_ptr) |
| 407 | { |
| 408 | if (inst_is_at_pc) |
| 409 | strm.PutCString("-> "); |
| 410 | else |
| 411 | strm.PutCString(" "); |
| 412 | } |
| 413 | inst->Dump(&strm, max_opcode_byte_size, true, show_bytes, &exe_ctx, raw); |
| 414 | strm.EOL(); |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 415 | } |
| 416 | else |
| 417 | { |
| 418 | break; |
| 419 | } |
| 420 | } |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 421 | |
| 422 | return true; |
| 423 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 424 | |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 425 | |
| 426 | bool |
| 427 | Disassembler::Disassemble |
| 428 | ( |
| 429 | Debugger &debugger, |
| 430 | const ArchSpec &arch, |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 431 | const char *plugin_name, |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 432 | const ExecutionContext &exe_ctx, |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 433 | uint32_t num_instructions, |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 434 | uint32_t num_mixed_context_lines, |
| 435 | bool show_bytes, |
Sean Callanan | b3396b2 | 2011-03-10 23:35:12 +0000 | [diff] [blame] | 436 | bool raw, |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 437 | Stream &strm |
| 438 | ) |
| 439 | { |
| 440 | AddressRange range; |
| 441 | if (exe_ctx.frame) |
| 442 | { |
| 443 | SymbolContext sc(exe_ctx.frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol)); |
| 444 | if (sc.function) |
| 445 | { |
| 446 | range = sc.function->GetAddressRange(); |
| 447 | } |
| 448 | else if (sc.symbol && sc.symbol->GetAddressRangePtr()) |
| 449 | { |
| 450 | range = *sc.symbol->GetAddressRangePtr(); |
| 451 | } |
| 452 | else |
| 453 | { |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 454 | range.GetBaseAddress() = exe_ctx.frame->GetFrameCodeAddress(); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | if (range.GetBaseAddress().IsValid() && range.GetByteSize() == 0) |
| 458 | range.SetByteSize (DEFAULT_DISASM_BYTE_SIZE); |
| 459 | } |
| 460 | |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 461 | return Disassemble (debugger, |
| 462 | arch, |
| 463 | plugin_name, |
| 464 | exe_ctx, |
| 465 | range, |
| 466 | num_instructions, |
| 467 | num_mixed_context_lines, |
| 468 | show_bytes, |
| 469 | raw, |
| 470 | strm); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 473 | Instruction::Instruction(const Address &address, AddressClass addr_class) : |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 474 | m_address (address), |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 475 | m_address_class (addr_class), |
Greg Clayton | 1080edbc | 2011-03-25 18:03:16 +0000 | [diff] [blame] | 476 | m_opcode() |
Greg Clayton | 0ae9627 | 2011-03-24 23:53:38 +0000 | [diff] [blame] | 477 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 480 | Instruction::~Instruction() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 481 | { |
| 482 | } |
| 483 | |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 484 | AddressClass |
| 485 | Instruction::GetAddressClass () |
| 486 | { |
| 487 | if (m_address_class == eAddressClassInvalid) |
| 488 | m_address_class = m_address.GetAddressClass(); |
| 489 | return m_address_class; |
| 490 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 491 | |
Caroline Tice | 7c9dd3c | 2011-04-05 23:22:54 +0000 | [diff] [blame] | 492 | bool |
| 493 | Instruction::DumpEmulation (const ArchSpec &arch) |
| 494 | { |
| 495 | std::auto_ptr<EmulateInstruction> insn_emulator_ap (EmulateInstruction::FindPlugin (arch, NULL)); |
| 496 | if (insn_emulator_ap.get()) |
| 497 | { |
| 498 | insn_emulator_ap->SetInstruction (GetOpcode(), GetAddress()); |
| 499 | return insn_emulator_ap->EvaluateInstruction (); |
| 500 | } |
| 501 | |
| 502 | return false; |
| 503 | } |
| 504 | |
| 505 | bool |
Caroline Tice | 3ac6711 | 2011-04-19 23:30:03 +0000 | [diff] [blame] | 506 | Instruction::TestEmulation (Stream *out_stream, const char *file_name) |
| 507 | { |
| 508 | if (!out_stream) |
| 509 | return false; |
| 510 | |
| 511 | if (!file_name) |
| 512 | { |
Johnny Chen | ea80ba8 | 2011-04-21 20:27:45 +0000 | [diff] [blame^] | 513 | out_stream->Printf ("Instruction::TestEmulation: Missing file_name."); |
Caroline Tice | 3ac6711 | 2011-04-19 23:30:03 +0000 | [diff] [blame] | 514 | return false; |
| 515 | } |
| 516 | |
| 517 | FILE *test_file = fopen (file_name, "r"); |
| 518 | if (!test_file) |
| 519 | { |
Johnny Chen | ea80ba8 | 2011-04-21 20:27:45 +0000 | [diff] [blame^] | 520 | out_stream->Printf ("Instruction::TestEmulation: Attempt to open test file failed."); |
Caroline Tice | 3ac6711 | 2011-04-19 23:30:03 +0000 | [diff] [blame] | 521 | return false; |
| 522 | } |
| 523 | |
| 524 | ArchSpec arch; |
| 525 | char buffer[256]; |
| 526 | if (!fgets (buffer,255, test_file)) // Read/skip first line of file, which should be a comment line (description). |
| 527 | { |
Johnny Chen | ea80ba8 | 2011-04-21 20:27:45 +0000 | [diff] [blame^] | 528 | out_stream->Printf ("Instruction::TestEmulation: Read comment line failed."); |
Caroline Tice | 3ac6711 | 2011-04-19 23:30:03 +0000 | [diff] [blame] | 529 | fclose (test_file); |
| 530 | return false; |
| 531 | } |
| 532 | SetDescription (buffer); |
| 533 | |
| 534 | if (fscanf (test_file, "%s", buffer) != 1) // Read the arch or arch-triple from the file |
| 535 | { |
Johnny Chen | ea80ba8 | 2011-04-21 20:27:45 +0000 | [diff] [blame^] | 536 | out_stream->Printf ("Instruction::TestEmulation: Read arch failed."); |
Caroline Tice | 3ac6711 | 2011-04-19 23:30:03 +0000 | [diff] [blame] | 537 | fclose (test_file); |
| 538 | return false; |
| 539 | } |
| 540 | |
| 541 | const char *cptr = buffer; |
| 542 | arch.SetTriple (llvm::Triple (cptr)); |
| 543 | |
| 544 | bool success = false; |
| 545 | std::auto_ptr<EmulateInstruction> insn_emulator_ap (EmulateInstruction::FindPlugin (arch, NULL)); |
| 546 | if (insn_emulator_ap.get()) |
| 547 | success = insn_emulator_ap->TestEmulation (out_stream, test_file, arch); |
| 548 | |
| 549 | fclose (test_file); |
| 550 | |
| 551 | if (success) |
Johnny Chen | ea80ba8 | 2011-04-21 20:27:45 +0000 | [diff] [blame^] | 552 | out_stream->Printf ("Emulation test succeeded."); |
Caroline Tice | 3ac6711 | 2011-04-19 23:30:03 +0000 | [diff] [blame] | 553 | else |
Johnny Chen | ea80ba8 | 2011-04-21 20:27:45 +0000 | [diff] [blame^] | 554 | out_stream->Printf ("Emulation test failed."); |
Caroline Tice | 3ac6711 | 2011-04-19 23:30:03 +0000 | [diff] [blame] | 555 | |
| 556 | return success; |
| 557 | } |
| 558 | |
| 559 | bool |
Caroline Tice | 7c9dd3c | 2011-04-05 23:22:54 +0000 | [diff] [blame] | 560 | Instruction::Emulate (const ArchSpec &arch, |
Caroline Tice | 25d61ac | 2011-04-08 23:33:06 +0000 | [diff] [blame] | 561 | bool auto_advance_pc, |
Caroline Tice | 7c9dd3c | 2011-04-05 23:22:54 +0000 | [diff] [blame] | 562 | void *baton, |
| 563 | EmulateInstruction::ReadMemory read_mem_callback, |
| 564 | EmulateInstruction::WriteMemory write_mem_callback, |
| 565 | EmulateInstruction::ReadRegister read_reg_callback, |
| 566 | EmulateInstruction::WriteRegister write_reg_callback) |
| 567 | { |
| 568 | std::auto_ptr<EmulateInstruction> insn_emulator_ap (EmulateInstruction::FindPlugin (arch, NULL)); |
| 569 | if (insn_emulator_ap.get()) |
| 570 | { |
| 571 | insn_emulator_ap->SetBaton (baton); |
| 572 | insn_emulator_ap->SetCallbacks (read_mem_callback, write_mem_callback, read_reg_callback, write_reg_callback); |
| 573 | insn_emulator_ap->SetInstruction (GetOpcode(), GetAddress()); |
Caroline Tice | 25d61ac | 2011-04-08 23:33:06 +0000 | [diff] [blame] | 574 | insn_emulator_ap->SetAdvancePC (auto_advance_pc); |
Caroline Tice | 7c9dd3c | 2011-04-05 23:22:54 +0000 | [diff] [blame] | 575 | return insn_emulator_ap->EvaluateInstruction (); |
| 576 | } |
| 577 | |
| 578 | return false; |
| 579 | } |
| 580 | |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 581 | InstructionList::InstructionList() : |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 582 | m_instructions() |
| 583 | { |
| 584 | } |
| 585 | |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 586 | InstructionList::~InstructionList() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 587 | { |
| 588 | } |
| 589 | |
| 590 | size_t |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 591 | InstructionList::GetSize() const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 592 | { |
| 593 | return m_instructions.size(); |
| 594 | } |
| 595 | |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 596 | uint32_t |
| 597 | InstructionList::GetMaxOpcocdeByteSize () const |
| 598 | { |
| 599 | uint32_t max_inst_size = 0; |
| 600 | collection::const_iterator pos, end; |
| 601 | for (pos = m_instructions.begin(), end = m_instructions.end(); |
| 602 | pos != end; |
| 603 | ++pos) |
| 604 | { |
| 605 | uint32_t inst_size = (*pos)->GetOpcode().GetByteSize(); |
| 606 | if (max_inst_size < inst_size) |
| 607 | max_inst_size = inst_size; |
| 608 | } |
| 609 | return max_inst_size; |
| 610 | } |
| 611 | |
| 612 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 613 | |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 614 | InstructionSP |
| 615 | InstructionList::GetInstructionAtIndex (uint32_t idx) const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 616 | { |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 617 | InstructionSP inst_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 618 | if (idx < m_instructions.size()) |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 619 | inst_sp = m_instructions[idx]; |
| 620 | return inst_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | void |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 624 | InstructionList::Clear() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 625 | { |
| 626 | m_instructions.clear(); |
| 627 | } |
| 628 | |
| 629 | void |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 630 | InstructionList::Append (lldb::InstructionSP &inst_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 631 | { |
| 632 | if (inst_sp) |
| 633 | m_instructions.push_back(inst_sp); |
| 634 | } |
| 635 | |
| 636 | |
| 637 | size_t |
| 638 | Disassembler::ParseInstructions |
| 639 | ( |
| 640 | const ExecutionContext *exe_ctx, |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 641 | const AddressRange &range |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 642 | ) |
| 643 | { |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 644 | Target *target = exe_ctx->target; |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 645 | const addr_t byte_size = range.GetByteSize(); |
| 646 | if (target == NULL || byte_size == 0 || !range.GetBaseAddress().IsValid()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 647 | return 0; |
| 648 | |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 649 | DataBufferHeap *heap_buffer = new DataBufferHeap (byte_size, '\0'); |
| 650 | DataBufferSP data_sp(heap_buffer); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 651 | |
| 652 | Error error; |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 653 | const bool prefer_file_cache = true; |
| 654 | const size_t bytes_read = target->ReadMemory (range.GetBaseAddress(), |
| 655 | prefer_file_cache, |
| 656 | heap_buffer->GetBytes(), |
| 657 | heap_buffer->GetByteSize(), |
| 658 | error); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 659 | |
| 660 | if (bytes_read > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 661 | { |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 662 | if (bytes_read != heap_buffer->GetByteSize()) |
| 663 | heap_buffer->SetByteSize (bytes_read); |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 664 | DataExtractor data (data_sp, |
| 665 | m_arch.GetByteOrder(), |
| 666 | m_arch.GetAddressByteSize()); |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 667 | return DecodeInstructions (range.GetBaseAddress(), data, 0, UINT32_MAX, false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | return 0; |
| 671 | } |
| 672 | |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 673 | size_t |
| 674 | Disassembler::ParseInstructions |
| 675 | ( |
| 676 | const ExecutionContext *exe_ctx, |
| 677 | const Address &start, |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 678 | uint32_t num_instructions |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 679 | ) |
| 680 | { |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 681 | m_instruction_list.Clear(); |
| 682 | |
| 683 | if (num_instructions == 0 || !start.IsValid()) |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 684 | return 0; |
| 685 | |
| 686 | Target *target = exe_ctx->target; |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 687 | // Calculate the max buffer size we will need in order to disassemble |
| 688 | const addr_t byte_size = num_instructions * m_arch.GetMaximumOpcodeByteSize(); |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 689 | |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 690 | if (target == NULL || byte_size == 0) |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 691 | return 0; |
| 692 | |
| 693 | DataBufferHeap *heap_buffer = new DataBufferHeap (byte_size, '\0'); |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 694 | DataBufferSP data_sp (heap_buffer); |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 695 | |
| 696 | Error error; |
| 697 | bool prefer_file_cache = true; |
Greg Clayton | 357132e | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 698 | const size_t bytes_read = target->ReadMemory (start, |
| 699 | prefer_file_cache, |
| 700 | heap_buffer->GetBytes(), |
| 701 | byte_size, |
| 702 | error); |
| 703 | |
| 704 | if (bytes_read == 0) |
| 705 | return 0; |
| 706 | DataExtractor data (data_sp, |
| 707 | m_arch.GetByteOrder(), |
| 708 | m_arch.GetAddressByteSize()); |
| 709 | |
| 710 | const bool append_instructions = true; |
| 711 | DecodeInstructions (start, |
| 712 | data, |
| 713 | 0, |
| 714 | num_instructions, |
| 715 | append_instructions); |
| 716 | |
Jim Ingham | 37023b0 | 2011-03-22 01:48:42 +0000 | [diff] [blame] | 717 | return m_instruction_list.GetSize(); |
| 718 | } |
| 719 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 720 | //---------------------------------------------------------------------- |
| 721 | // Disassembler copy constructor |
| 722 | //---------------------------------------------------------------------- |
| 723 | Disassembler::Disassembler(const ArchSpec& arch) : |
| 724 | m_arch (arch), |
| 725 | m_instruction_list(), |
| 726 | m_base_addr(LLDB_INVALID_ADDRESS) |
| 727 | { |
| 728 | |
| 729 | } |
| 730 | |
| 731 | //---------------------------------------------------------------------- |
| 732 | // Destructor |
| 733 | //---------------------------------------------------------------------- |
| 734 | Disassembler::~Disassembler() |
| 735 | { |
| 736 | } |
| 737 | |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 738 | InstructionList & |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 739 | Disassembler::GetInstructionList () |
| 740 | { |
| 741 | return m_instruction_list; |
| 742 | } |
| 743 | |
Greg Clayton | 1d27316 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 744 | const InstructionList & |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 745 | Disassembler::GetInstructionList () const |
| 746 | { |
| 747 | return m_instruction_list; |
| 748 | } |
Caroline Tice | 3ac6711 | 2011-04-19 23:30:03 +0000 | [diff] [blame] | 749 | |
| 750 | //---------------------------------------------------------------------- |
| 751 | // Class PseudoInstruction |
| 752 | //---------------------------------------------------------------------- |
| 753 | PseudoInstruction::PseudoInstruction () : |
| 754 | Instruction (Address(), eAddressClassUnknown), |
| 755 | m_description () |
| 756 | { |
| 757 | } |
| 758 | |
| 759 | PseudoInstruction::~PseudoInstruction () |
| 760 | { |
| 761 | } |
| 762 | |
| 763 | void |
| 764 | PseudoInstruction::Dump (lldb_private::Stream *s, |
| 765 | uint32_t max_opcode_byte_size, |
| 766 | bool show_address, |
| 767 | bool show_bytes, |
| 768 | const lldb_private::ExecutionContext* exe_ctx, |
| 769 | bool raw) |
| 770 | { |
| 771 | if (!s) |
| 772 | return; |
| 773 | |
| 774 | if (show_bytes) |
| 775 | m_opcode.Dump (s, max_opcode_byte_size); |
| 776 | |
| 777 | if (m_description.size() > 0) |
| 778 | s->Printf ("%s", m_description.c_str()); |
| 779 | else |
| 780 | s->Printf ("<unknown>"); |
| 781 | |
| 782 | } |
| 783 | |
| 784 | bool |
| 785 | PseudoInstruction::DoesBranch () const |
| 786 | { |
| 787 | // This is NOT a valid question for a pseudo instruction. |
| 788 | return false; |
| 789 | } |
| 790 | |
| 791 | size_t |
| 792 | PseudoInstruction::Decode (const lldb_private::Disassembler &disassembler, |
| 793 | const lldb_private::DataExtractor &data, |
| 794 | uint32_t data_offset) |
| 795 | { |
| 796 | return m_opcode.GetByteSize(); |
| 797 | } |
| 798 | |
| 799 | |
| 800 | void |
| 801 | PseudoInstruction::SetOpcode (size_t opcode_size, void *opcode_data) |
| 802 | { |
| 803 | if (!opcode_data) |
| 804 | return; |
| 805 | |
| 806 | switch (opcode_size) |
| 807 | { |
| 808 | case 8: |
| 809 | { |
| 810 | uint8_t value8 = *((uint8_t *) opcode_data); |
| 811 | m_opcode.SetOpcode8 (value8); |
| 812 | break; |
| 813 | } |
| 814 | case 16: |
| 815 | { |
| 816 | uint16_t value16 = *((uint16_t *) opcode_data); |
| 817 | m_opcode.SetOpcode16 (value16); |
| 818 | break; |
| 819 | } |
| 820 | case 32: |
| 821 | { |
| 822 | uint32_t value32 = *((uint32_t *) opcode_data); |
| 823 | m_opcode.SetOpcode32 (value32); |
| 824 | break; |
| 825 | } |
| 826 | case 64: |
| 827 | { |
| 828 | uint64_t value64 = *((uint64_t *) opcode_data); |
| 829 | m_opcode.SetOpcode64 (value64); |
| 830 | break; |
| 831 | } |
| 832 | default: |
| 833 | break; |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | void |
| 838 | PseudoInstruction::SetDescription (const char *description) |
| 839 | { |
| 840 | if (description && strlen (description) > 0) |
| 841 | m_description = description; |
| 842 | } |