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;
37 fprintf(out, "Asm output not supported on this arch\n");
41 /* Currently only source supported in x86. */
42 disasm_info.endian = BFD_ENDIAN_LITTLE;
43 if (type == DISAS_I386_I386)
44 disasm_info.mach = bfd_mach_i386_i386;
46 disasm_info.mach = bfd_mach_i386_i8086;
47 print_insn = print_insn_i386;
50 for (pc = code; pc < (uint8_t *)code + size; pc += count) {
51 fprintf(out, "0x%08lx: ", (long)pc);
52 count = print_insn((long)pc, &disasm_info);
59 /* Look up symbol for debugging purpose. Returns "" if unknown. */
60 const char *lookup_symbol(void *orig_addr)
63 /* Hack, because we know this is x86. */
64 Elf32_Sym *sym = disas_symtab;
66 for (i = 0; i < disas_num_syms; i++) {
67 if (sym[i].st_shndx == SHN_UNDEF
68 || sym[i].st_shndx >= SHN_LORESERVE)
71 if (ELF_ST_TYPE(sym[i].st_info) != STT_FUNC)
74 if ((long)orig_addr >= sym[i].st_value
75 && (long)orig_addr < sym[i].st_value + sym[i].st_size)
76 return disas_strtab + sym[i].st_name;