blob: 349c16e12d195e0b6b8b6fa5d5ae55bf79431f50 [file] [log] [blame]
Sean Callanan95e5c632012-02-17 00:53:45 +00001//===-- DisassemblerLLVMC.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 "DisassemblerLLVMC.h"
11
12#include "llvm-c/Disassembler.h"
13#include "llvm/Support/TargetSelect.h"
14
15#include "lldb/Core/Address.h"
16#include "lldb/Core/DataExtractor.h"
17#include "lldb/Core/Stream.h"
18#include "lldb/Symbol/SymbolContext.h"
19#include "lldb/Target/ExecutionContext.h"
20#include "lldb/Target/Process.h"
21#include "lldb/Target/RegisterContext.h"
22#include "lldb/Target/Target.h"
23#include "lldb/Target/StackFrame.h"
24
25#include <regex.h>
26
27using namespace lldb;
28using namespace lldb_private;
29
30class InstructionLLVMC : public lldb_private::Instruction
31{
32public:
33 InstructionLLVMC (DisassemblerLLVMC &disasm,
34 const lldb_private::Address &address,
Greg Claytonc8e0c242012-04-13 00:07:34 +000035 AddressClass addr_class) :
Sean Callanan95e5c632012-02-17 00:53:45 +000036 Instruction(address, addr_class),
Sean Callanan95e5c632012-02-17 00:53:45 +000037 m_is_valid(false),
Bill Wendlinge6eeef02012-04-06 00:09:59 +000038 m_disasm(disasm),
Sean Callanan7e6d4e52012-08-01 18:50:59 +000039 m_disasm_sp(disasm.shared_from_this()),
Sean Callanan7725a462012-03-02 23:22:53 +000040 m_does_branch(eLazyBoolCalculate)
Sean Callanan95e5c632012-02-17 00:53:45 +000041 {
42 }
43
44 virtual
45 ~InstructionLLVMC ()
46 {
47 }
48
49 static void
50 PadToWidth (lldb_private::StreamString &ss,
51 int new_width)
52 {
53 int old_width = ss.GetSize();
54
55 if (old_width < new_width)
56 {
57 ss.Printf("%*s", new_width - old_width, "");
58 }
59 }
Sean Callanan95e5c632012-02-17 00:53:45 +000060
Sean Callanan95e5c632012-02-17 00:53:45 +000061 virtual bool
62 DoesBranch () const
63 {
Sean Callanan7725a462012-03-02 23:22:53 +000064 return m_does_branch == eLazyBoolYes;
Sean Callanan95e5c632012-02-17 00:53:45 +000065 }
66
67 virtual size_t
68 Decode (const lldb_private::Disassembler &disassembler,
69 const lldb_private::DataExtractor &data,
70 uint32_t data_offset)
71 {
Greg Claytonba812f42012-05-10 02:52:23 +000072 // All we have to do is read the opcode which can be easy for some
73 // architetures
74 bool got_op = false;
75 const ArchSpec &arch = m_disasm.GetArchitecture();
Sean Callanan95e5c632012-02-17 00:53:45 +000076
Greg Claytonba812f42012-05-10 02:52:23 +000077 const uint32_t min_op_byte_size = arch.GetMinimumOpcodeByteSize();
78 const uint32_t max_op_byte_size = arch.GetMaximumOpcodeByteSize();
79 if (min_op_byte_size == max_op_byte_size)
80 {
81 // Fixed size instructions, just read that amount of data.
82 if (!data.ValidOffsetForDataOfSize(data_offset, min_op_byte_size))
83 return false;
84
85 switch (min_op_byte_size)
86 {
87 case 1:
88 m_opcode.SetOpcode8 (data.GetU8 (&data_offset));
89 got_op = true;
90 break;
91
92 case 2:
93 m_opcode.SetOpcode16 (data.GetU16 (&data_offset));
94 got_op = true;
95 break;
96
97 case 4:
98 m_opcode.SetOpcode32 (data.GetU32 (&data_offset));
99 got_op = true;
100 break;
101
102 case 8:
103 m_opcode.SetOpcode64 (data.GetU64 (&data_offset));
104 got_op = true;
105 break;
106
107 default:
108 m_opcode.SetOpcodeBytes(data.PeekData(data_offset, min_op_byte_size), min_op_byte_size);
109 got_op = true;
110 break;
111 }
112 }
113 if (!got_op)
114 {
115 ::LLVMDisasmContextRef disasm_context = m_disasm.m_disasm_context;
116
117 bool is_altnernate_isa = false;
118 if (m_disasm.m_alternate_disasm_context)
119 {
120 const AddressClass address_class = GetAddressClass ();
121
122 if (address_class == eAddressClassCodeAlternateISA)
123 {
124 disasm_context = m_disasm.m_alternate_disasm_context;
125 is_altnernate_isa = true;
126 }
127 }
128 const llvm::Triple::ArchType machine = arch.GetMachine();
129 if (machine == llvm::Triple::arm || machine == llvm::Triple::thumb)
130 {
131 if (machine == llvm::Triple::thumb || is_altnernate_isa)
132 {
Greg Clayton79101b52012-08-07 01:29:29 +0000133 uint32_t thumb_opcode = data.GetU16(&data_offset);
Greg Claytonba812f42012-05-10 02:52:23 +0000134 if ((thumb_opcode & 0xe000) != 0xe000 || ((thumb_opcode & 0x1800u) == 0))
135 {
136 m_opcode.SetOpcode16 (thumb_opcode);
Sean Callanan5c97c2f2012-08-06 23:42:52 +0000137 m_is_valid = true;
Greg Claytonba812f42012-05-10 02:52:23 +0000138 }
139 else
140 {
Greg Clayton79101b52012-08-07 01:29:29 +0000141 thumb_opcode <<= 16;
142 thumb_opcode |= data.GetU16(&data_offset);
143 m_opcode.SetOpcode16_2 (thumb_opcode);
Greg Claytonba812f42012-05-10 02:52:23 +0000144 m_is_valid = true;
145 }
146 }
147 else
148 {
149 m_opcode.SetOpcode32 (data.GetU32(&data_offset));
Sean Callanan5c97c2f2012-08-06 23:42:52 +0000150 m_is_valid = true;
Greg Claytonba812f42012-05-10 02:52:23 +0000151 }
152 }
153 else
154 {
155 // The opcode isn't evenly sized, so we need to actually use the llvm
156 // disassembler to parse it and get the size.
157 char out_string[512];
158 m_disasm.Lock(this, NULL);
159 uint8_t *opcode_data = const_cast<uint8_t *>(data.PeekData (data_offset, 1));
160 const size_t opcode_data_len = data.GetByteSize() - data_offset;
161 const addr_t pc = m_address.GetFileAddress();
162 const size_t inst_size = ::LLVMDisasmInstruction (disasm_context,
163 opcode_data,
164 opcode_data_len,
165 pc, // PC value
166 out_string,
167 sizeof(out_string));
168 // The address lookup function could have caused us to fill in our comment
169 m_comment.clear();
170 m_disasm.Unlock();
171 if (inst_size == 0)
172 m_opcode.Clear();
173 else
174 {
175 m_opcode.SetOpcodeBytes(opcode_data, inst_size);
176 m_is_valid = true;
177 }
178 }
179 }
Sean Callanan95e5c632012-02-17 00:53:45 +0000180 return m_opcode.GetByteSize();
181 }
182
183 void
Greg Claytonba812f42012-05-10 02:52:23 +0000184 AppendComment (std::string &description)
Sean Callanan95e5c632012-02-17 00:53:45 +0000185 {
Greg Claytonba812f42012-05-10 02:52:23 +0000186 if (m_comment.empty())
187 m_comment.swap (description);
Sean Callanan95e5c632012-02-17 00:53:45 +0000188 else
Greg Claytonba812f42012-05-10 02:52:23 +0000189 {
190 m_comment.append(", ");
191 m_comment.append(description);
192 }
Sean Callanan95e5c632012-02-17 00:53:45 +0000193 }
194
195 virtual void
Greg Claytonba812f42012-05-10 02:52:23 +0000196 CalculateMnemonicOperandsAndComment (const lldb_private::ExecutionContext *exe_ctx)
Sean Callanan95e5c632012-02-17 00:53:45 +0000197 {
Greg Claytonba812f42012-05-10 02:52:23 +0000198 DataExtractor data;
199 const AddressClass address_class = GetAddressClass ();
200
201 if (m_opcode.GetData(data, address_class))
202 {
203 char out_string[512];
204
205 ::LLVMDisasmContextRef disasm_context;
206
207 if (address_class == eAddressClassCodeAlternateISA)
208 disasm_context = m_disasm.m_alternate_disasm_context;
209 else
210 disasm_context = m_disasm.m_disasm_context;
211
212 lldb::addr_t pc = LLDB_INVALID_ADDRESS;
213
214 if (exe_ctx)
215 {
216 Target *target = exe_ctx->GetTargetPtr();
217 if (target)
218 pc = m_address.GetLoadAddress(target);
219 }
220
221 if (pc == LLDB_INVALID_ADDRESS)
222 pc = m_address.GetFileAddress();
223
224 m_disasm.Lock(this, exe_ctx);
225 uint8_t *opcode_data = const_cast<uint8_t *>(data.PeekData (0, 1));
226 const size_t opcode_data_len = data.GetByteSize();
227 size_t inst_size = ::LLVMDisasmInstruction (disasm_context,
228 opcode_data,
229 opcode_data_len,
230 pc,
231 out_string,
232 sizeof(out_string));
233
234 m_disasm.Unlock();
235
236 if (inst_size == 0)
237 {
238 m_comment.assign ("unknown opcode");
239 inst_size = m_opcode.GetByteSize();
240 StreamString mnemonic_strm;
241 uint32_t offset = 0;
242 switch (inst_size)
243 {
244 case 1:
245 {
246 const uint8_t uval8 = data.GetU8 (&offset);
247 m_opcode.SetOpcode8 (uval8);
248 m_opcode_name.assign (".byte");
249 mnemonic_strm.Printf("0x%2.2x", uval8);
250 }
251 break;
252 case 2:
253 {
254 const uint16_t uval16 = data.GetU16(&offset);
255 m_opcode.SetOpcode16(uval16);
256 m_opcode_name.assign (".short");
257 mnemonic_strm.Printf("0x%4.4x", uval16);
258 }
259 break;
260 case 4:
261 {
262 const uint32_t uval32 = data.GetU32(&offset);
263 m_opcode.SetOpcode32(uval32);
264 m_opcode_name.assign (".long");
265 mnemonic_strm.Printf("0x%8.8x", uval32);
266 }
267 break;
268 case 8:
269 {
270 const uint64_t uval64 = data.GetU64(&offset);
271 m_opcode.SetOpcode64(uval64);
272 m_opcode_name.assign (".quad");
273 mnemonic_strm.Printf("0x%16.16llx", uval64);
274 }
275 break;
276 default:
277 if (inst_size == 0)
278 return;
279 else
280 {
281 const uint8_t *bytes = data.PeekData(offset, inst_size);
282 if (bytes == NULL)
283 return;
284 m_opcode_name.assign (".byte");
285 m_opcode.SetOpcodeBytes(bytes, inst_size);
286 mnemonic_strm.Printf("0x%2.2x", bytes[0]);
287 for (uint32_t i=1; i<inst_size; ++i)
288 mnemonic_strm.Printf(" 0x%2.2x", bytes[i]);
289 }
290 break;
291 }
292 m_mnemocics.swap(mnemonic_strm.GetString());
293 return;
294 }
295 else
296 {
297 if (m_does_branch == eLazyBoolCalculate)
298 {
299 if (StringRepresentsBranch (out_string, strlen(out_string)))
300 m_does_branch = eLazyBoolYes;
301 else
302 m_does_branch = eLazyBoolNo;
303 }
304 }
305
306 if (!s_regex_compiled)
307 {
308 ::regcomp(&s_regex, "[ \t]*([^ ^\t]+)[ \t]*([^ ^\t].*)?", REG_EXTENDED);
309 s_regex_compiled = true;
310 }
311
312 ::regmatch_t matches[3];
313
314 if (!::regexec(&s_regex, out_string, sizeof(matches) / sizeof(::regmatch_t), matches, 0))
315 {
316 if (matches[1].rm_so != -1)
317 m_opcode_name.assign(out_string + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so);
318 if (matches[2].rm_so != -1)
319 m_mnemocics.assign(out_string + matches[2].rm_so, matches[2].rm_eo - matches[2].rm_so);
320 }
321 }
Sean Callanan95e5c632012-02-17 00:53:45 +0000322 }
323
324 bool
325 IsValid ()
326 {
327 return m_is_valid;
328 }
329
330 size_t
331 GetByteSize ()
332 {
333 return m_opcode.GetByteSize();
334 }
335protected:
Sean Callanan95e5c632012-02-17 00:53:45 +0000336
Sean Callanan7725a462012-03-02 23:22:53 +0000337 bool StringRepresentsBranch (const char *data, size_t size)
338 {
339 const char *cursor = data;
340
341 bool inWhitespace = true;
342
343 while (inWhitespace && cursor < data + size)
344 {
345 switch (*cursor)
346 {
347 default:
348 inWhitespace = false;
349 break;
350 case ' ':
351 break;
352 case '\t':
353 break;
354 }
355
356 if (inWhitespace)
357 ++cursor;
358 }
359
360 if (cursor >= data + size)
361 return false;
362
363 llvm::Triple::ArchType arch = m_disasm.GetArchitecture().GetMachine();
364
365 switch (arch)
366 {
367 default:
368 return false;
369 case llvm::Triple::x86:
370 case llvm::Triple::x86_64:
371 switch (cursor[0])
372 {
373 default:
374 return false;
375 case 'j':
376 return true;
377 case 'c':
378 if (cursor[1] == 'a' &&
379 cursor[2] == 'l' &&
380 cursor[3] == 'l')
381 return true;
382 else
383 return false;
384 }
385 case llvm::Triple::arm:
386 case llvm::Triple::thumb:
387 switch (cursor[0])
388 {
389 default:
390 return false;
391 case 'b':
392 {
393 switch (cursor[1])
394 {
395 default:
Sean Callanan7725a462012-03-02 23:22:53 +0000396 return true;
Sean Callanan62ecb9b2012-04-10 21:51:12 +0000397 case 'f':
398 case 'i':
399 case 'k':
400 return false;
Sean Callanan7725a462012-03-02 23:22:53 +0000401 }
Sean Callanan7725a462012-03-02 23:22:53 +0000402 }
403 case 'c':
404 {
405 switch (cursor[1])
406 {
407 default:
408 return false;
409 case 'b':
410 return true;
411 }
412 }
413 }
414 }
415
416 return false;
417 }
418
Sean Callanan95e5c632012-02-17 00:53:45 +0000419 bool m_is_valid;
420 DisassemblerLLVMC &m_disasm;
Sean Callanan7e6d4e52012-08-01 18:50:59 +0000421 DisassemblerSP m_disasm_sp; // for ownership
Sean Callanan7725a462012-03-02 23:22:53 +0000422 LazyBool m_does_branch;
Sean Callanan95e5c632012-02-17 00:53:45 +0000423
424 static bool s_regex_compiled;
425 static ::regex_t s_regex;
426};
427
428bool InstructionLLVMC::s_regex_compiled = false;
429::regex_t InstructionLLVMC::s_regex;
430
431Disassembler *
432DisassemblerLLVMC::CreateInstance (const ArchSpec &arch)
433{
434 std::auto_ptr<DisassemblerLLVMC> disasm_ap (new DisassemblerLLVMC(arch));
435
436 if (disasm_ap.get() && disasm_ap->IsValid())
437 return disasm_ap.release();
438
439 return NULL;
440}
441
442DisassemblerLLVMC::DisassemblerLLVMC (const ArchSpec &arch) :
443 Disassembler(arch),
Greg Claytonba812f42012-05-10 02:52:23 +0000444 m_exe_ctx (NULL),
445 m_inst (NULL),
446 m_disasm_context (NULL),
447 m_alternate_disasm_context (NULL)
Sean Callanan95e5c632012-02-17 00:53:45 +0000448{
449 m_disasm_context = ::LLVMCreateDisasm(arch.GetTriple().getTriple().c_str(),
450 (void*)this,
451 /*TagType=*/1,
Sean Callanan6f298a62012-02-23 23:43:28 +0000452 NULL,
Sean Callanan95e5c632012-02-17 00:53:45 +0000453 DisassemblerLLVMC::SymbolLookupCallback);
454
455 if (arch.GetTriple().getArch() == llvm::Triple::arm)
456 {
Greg Claytonba812f42012-05-10 02:52:23 +0000457 ArchSpec thumb_arch(arch);
458 thumb_arch.GetTriple().setArchName(llvm::StringRef("thumbv7"));
459 std::string thumb_triple(thumb_arch.GetTriple().getTriple());
460
461 m_alternate_disasm_context = ::LLVMCreateDisasm(thumb_triple.c_str(),
Sean Callanan95e5c632012-02-17 00:53:45 +0000462 (void*)this,
463 /*TagType=*/1,
Sean Callanan6f298a62012-02-23 23:43:28 +0000464 NULL,
Sean Callanan95e5c632012-02-17 00:53:45 +0000465 DisassemblerLLVMC::SymbolLookupCallback);
466 }
467}
468
469DisassemblerLLVMC::~DisassemblerLLVMC()
470{
Sean Callanan2b54db72012-04-06 17:59:49 +0000471 if (m_disasm_context)
472 {
473 ::LLVMDisasmDispose(m_disasm_context);
474 m_disasm_context = NULL;
475 }
476 if (m_alternate_disasm_context)
477 {
478 ::LLVMDisasmDispose(m_alternate_disasm_context);
479 m_alternate_disasm_context = NULL;
480 }
Sean Callanan95e5c632012-02-17 00:53:45 +0000481}
482
483size_t
484DisassemblerLLVMC::DecodeInstructions (const Address &base_addr,
485 const DataExtractor& data,
486 uint32_t data_offset,
487 uint32_t num_instructions,
488 bool append)
489{
490 if (!append)
491 m_instruction_list.Clear();
492
493 if (!IsValid())
494 return 0;
495
496 uint32_t data_cursor = data_offset;
Greg Claytonba812f42012-05-10 02:52:23 +0000497 const size_t data_byte_size = data.GetByteSize();
Sean Callanan95e5c632012-02-17 00:53:45 +0000498 uint32_t instructions_parsed = 0;
Greg Claytonba812f42012-05-10 02:52:23 +0000499 Address inst_addr(base_addr);
Sean Callanan95e5c632012-02-17 00:53:45 +0000500
Greg Claytonba812f42012-05-10 02:52:23 +0000501 while (data_cursor < data_byte_size && instructions_parsed < num_instructions)
Sean Callanan95e5c632012-02-17 00:53:45 +0000502 {
Sean Callanan95e5c632012-02-17 00:53:45 +0000503
Greg Claytonba812f42012-05-10 02:52:23 +0000504 AddressClass address_class = eAddressClassCode;
Sean Callanan95e5c632012-02-17 00:53:45 +0000505
506 if (m_alternate_disasm_context)
Greg Claytonba812f42012-05-10 02:52:23 +0000507 address_class = inst_addr.GetAddressClass ();
Sean Callanan95e5c632012-02-17 00:53:45 +0000508
509 InstructionSP inst_sp(new InstructionLLVMC(*this,
Greg Claytonba812f42012-05-10 02:52:23 +0000510 inst_addr,
Sean Callanan95e5c632012-02-17 00:53:45 +0000511 address_class));
512
513 if (!inst_sp)
Greg Claytonba812f42012-05-10 02:52:23 +0000514 break;
515
Sean Callanan95e5c632012-02-17 00:53:45 +0000516 uint32_t inst_size = inst_sp->Decode(*this, data, data_cursor);
517
Greg Claytonba812f42012-05-10 02:52:23 +0000518 if (inst_size == 0)
519 break;
520
Sean Callanan95e5c632012-02-17 00:53:45 +0000521 m_instruction_list.Append(inst_sp);
Sean Callanan95e5c632012-02-17 00:53:45 +0000522 data_cursor += inst_size;
Greg Claytonba812f42012-05-10 02:52:23 +0000523 inst_addr.Slide(inst_size);
Sean Callanan95e5c632012-02-17 00:53:45 +0000524 instructions_parsed++;
525 }
526
527 return data_cursor - data_offset;
528}
529
530void
531DisassemblerLLVMC::Initialize()
532{
533 PluginManager::RegisterPlugin (GetPluginNameStatic(),
534 GetPluginDescriptionStatic(),
535 CreateInstance);
536
537 llvm::InitializeAllTargetInfos();
538 llvm::InitializeAllTargetMCs();
539 llvm::InitializeAllAsmParsers();
540 llvm::InitializeAllDisassemblers();
541}
542
543void
544DisassemblerLLVMC::Terminate()
545{
546 PluginManager::UnregisterPlugin (CreateInstance);
547}
548
549
550const char *
551DisassemblerLLVMC::GetPluginNameStatic()
552{
Greg Claytonf8712de2012-03-22 00:49:15 +0000553 return "llvm-mc";
Sean Callanan95e5c632012-02-17 00:53:45 +0000554}
555
556const char *
557DisassemblerLLVMC::GetPluginDescriptionStatic()
558{
Greg Claytonf8712de2012-03-22 00:49:15 +0000559 return "Disassembler that uses LLVM MC to disassemble i386, x86_64 and ARM.";
Sean Callanan95e5c632012-02-17 00:53:45 +0000560}
561
Greg Claytonba812f42012-05-10 02:52:23 +0000562int DisassemblerLLVMC::OpInfoCallback (void *disassembler,
563 uint64_t pc,
564 uint64_t offset,
565 uint64_t size,
566 int tag_type,
567 void *tag_bug)
Sean Callanan95e5c632012-02-17 00:53:45 +0000568{
Greg Claytonba812f42012-05-10 02:52:23 +0000569 return static_cast<DisassemblerLLVMC*>(disassembler)->OpInfo (pc,
570 offset,
571 size,
572 tag_type,
573 tag_bug);
Sean Callanan95e5c632012-02-17 00:53:45 +0000574}
575
Greg Claytonba812f42012-05-10 02:52:23 +0000576const char *DisassemblerLLVMC::SymbolLookupCallback (void *disassembler,
577 uint64_t value,
578 uint64_t *type,
579 uint64_t pc,
580 const char **name)
Sean Callanan95e5c632012-02-17 00:53:45 +0000581{
Greg Claytonba812f42012-05-10 02:52:23 +0000582 return static_cast<DisassemblerLLVMC*>(disassembler)->SymbolLookup(value,
583 type,
584 pc,
585 name);
Sean Callanan95e5c632012-02-17 00:53:45 +0000586}
587
588int DisassemblerLLVMC::OpInfo (uint64_t PC,
589 uint64_t Offset,
590 uint64_t Size,
Greg Claytonba812f42012-05-10 02:52:23 +0000591 int tag_type,
592 void *tag_bug)
Sean Callanan95e5c632012-02-17 00:53:45 +0000593{
Greg Claytonba812f42012-05-10 02:52:23 +0000594 switch (tag_type)
Sean Callanan95e5c632012-02-17 00:53:45 +0000595 {
596 default:
597 break;
598 case 1:
Greg Claytonba812f42012-05-10 02:52:23 +0000599 bzero (tag_bug, sizeof(::LLVMOpInfo1));
Sean Callanan95e5c632012-02-17 00:53:45 +0000600 break;
601 }
602 return 0;
603}
604
Greg Claytonba812f42012-05-10 02:52:23 +0000605const char *DisassemblerLLVMC::SymbolLookup (uint64_t value,
606 uint64_t *type_ptr,
607 uint64_t pc,
608 const char **name)
Sean Callanan95e5c632012-02-17 00:53:45 +0000609{
Greg Claytonba812f42012-05-10 02:52:23 +0000610 if (*type_ptr)
611 {
612 if (m_exe_ctx && m_inst)
613 {
614 //std::string remove_this_prior_to_checkin;
615 Address reference_address;
Sean Callanan95e5c632012-02-17 00:53:45 +0000616
Greg Claytonba812f42012-05-10 02:52:23 +0000617 Target *target = m_exe_ctx ? m_exe_ctx->GetTargetPtr() : NULL;
618
619 if (target && !target->GetSectionLoadList().IsEmpty())
620 target->GetSectionLoadList().ResolveLoadAddress(value, reference_address);
621 else
622 {
623 ModuleSP module_sp(m_inst->GetAddress().GetModule());
624 if (module_sp)
625 module_sp->ResolveFileAddress(value, reference_address);
626 }
627
Sean Callanan6f298a62012-02-23 23:43:28 +0000628 if (reference_address.IsValid() && reference_address.GetSection())
Sean Callanan95e5c632012-02-17 00:53:45 +0000629 {
Sean Callanan95e5c632012-02-17 00:53:45 +0000630 StreamString ss;
631
Sean Callanan6f298a62012-02-23 23:43:28 +0000632 reference_address.Dump (&ss,
633 target,
634 Address::DumpStyleResolvedDescriptionNoModule,
635 Address::DumpStyleSectionNameOffset);
Sean Callanan95e5c632012-02-17 00:53:45 +0000636
Sean Callanan745af462012-03-22 20:04:23 +0000637 if (!ss.GetString().empty())
Greg Claytonba812f42012-05-10 02:52:23 +0000638 {
639 //remove_this_prior_to_checkin = ss.GetString();
640 //if (*type_ptr)
641 m_inst->AppendComment(ss.GetString());
642 }
Sean Callanan95e5c632012-02-17 00:53:45 +0000643 }
Greg Claytonba812f42012-05-10 02:52:23 +0000644 //printf ("DisassemblerLLVMC::SymbolLookup (value=0x%16.16llx, type=%llu, pc=0x%16.16llx, name=\"%s\") m_exe_ctx=%p, m_inst=%p\n", value, *type_ptr, pc, remove_this_prior_to_checkin.c_str(), m_exe_ctx, m_inst);
Sean Callanan95e5c632012-02-17 00:53:45 +0000645 }
646 }
Greg Claytonba812f42012-05-10 02:52:23 +0000647
648 *type_ptr = LLVMDisassembler_ReferenceType_InOut_None;
649 *name = NULL;
650 return NULL;
Sean Callanan95e5c632012-02-17 00:53:45 +0000651}
652
653//------------------------------------------------------------------
654// PluginInterface protocol
655//------------------------------------------------------------------
656const char *
657DisassemblerLLVMC::GetPluginName()
658{
659 return "DisassemblerLLVMC";
660}
661
662const char *
663DisassemblerLLVMC::GetShortPluginName()
664{
665 return GetPluginNameStatic();
666}
667
668uint32_t
669DisassemblerLLVMC::GetPluginVersion()
670{
671 return 1;
672}
673