1 /* General "disassemble this chunk" code. Used for debugging. */
6 /* Filled in by elfload.c. Simplistic, but will do for now. */
7 unsigned int disas_num_syms
;
9 const char *disas_strtab
;
11 /* Disassemble this for me please... (debugging). */
12 void disas(FILE *out
, void *code
, unsigned long size
, enum disas_type type
)
16 struct disassemble_info disasm_info
;
17 int (*print_insn
)(bfd_vma pc
, disassemble_info
*info
);
19 INIT_DISASSEMBLE_INFO(disasm_info
, out
, fprintf
);
21 disasm_info
.buffer
= code
;
22 disasm_info
.buffer_vma
= (unsigned long)code
;
23 disasm_info
.buffer_length
= size
;
25 if (type
== DISAS_TARGET
) {
26 #ifdef WORDS_BIGENDIAN
27 disasm_info
.endian
= BFD_ENDIAN_BIG
;
29 disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
32 disasm_info
.mach
= bfd_mach_i386_i386
;
33 print_insn
= print_insn_i386
;
34 #elif defined(__powerpc__)
35 print_insn
= print_insn_ppc
;
36 #elif defined(__alpha__)
37 print_insn
= print_insn_alpha
;
39 fprintf(out
, "Asm output not supported on this arch\n");
43 /* Currently only source supported in x86. */
44 disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
45 if (type
== DISAS_I386_I386
)
46 disasm_info
.mach
= bfd_mach_i386_i386
;
48 disasm_info
.mach
= bfd_mach_i386_i8086
;
49 print_insn
= print_insn_i386
;
52 for (pc
= code
; pc
< (uint8_t *)code
+ size
; pc
+= count
) {
53 fprintf(out
, "0x%08lx: ", (long)pc
);
54 count
= print_insn((unsigned long)pc
, &disasm_info
);
61 /* Look up symbol for debugging purpose. Returns "" if unknown. */
62 const char *lookup_symbol(void *orig_addr
)
65 /* Hack, because we know this is x86. */
66 Elf32_Sym
*sym
= disas_symtab
;
68 for (i
= 0; i
< disas_num_syms
; i
++) {
69 if (sym
[i
].st_shndx
== SHN_UNDEF
70 || sym
[i
].st_shndx
>= SHN_LORESERVE
)
73 if (ELF_ST_TYPE(sym
[i
].st_info
) != STT_FUNC
)
76 if ((long)orig_addr
>= sym
[i
].st_value
77 && (long)orig_addr
< sym
[i
].st_value
+ sym
[i
].st_size
)
78 return disas_strtab
+ sym
[i
].st_name
;