aoqi@0: /* aoqi@0: * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: /* hsdis.c -- dump a range of addresses as native instructions aoqi@0: This implements the plugin protocol required by the aoqi@0: HotSpot PrintAssembly option. aoqi@0: */ aoqi@0: aoqi@0: #include /* required by bfd.h */ aoqi@0: #include aoqi@0: #include aoqi@0: #include aoqi@0: #include aoqi@0: #include aoqi@0: #include aoqi@0: #include "hsdis.h" aoqi@0: aoqi@0: #ifndef bool aoqi@0: #define bool int aoqi@0: #define true 1 aoqi@0: #define false 0 aoqi@0: #endif /*bool*/ aoqi@0: aoqi@0: /* short names for stuff in hsdis.h */ aoqi@0: typedef decode_instructions_event_callback_ftype event_callback_t; aoqi@0: typedef decode_instructions_printf_callback_ftype printf_callback_t; aoqi@0: aoqi@0: /* disassemble_info.application_data object */ aoqi@0: struct hsdis_app_data { aoqi@0: /* virtual address of data */ aoqi@0: uintptr_t start_va, end_va; aoqi@0: /* the instructions to be decoded */ aoqi@0: unsigned char* buffer; aoqi@0: uintptr_t length; aoqi@0: event_callback_t event_callback; void* event_stream; aoqi@0: printf_callback_t printf_callback; void* printf_stream; aoqi@0: bool losing; aoqi@0: bool do_newline; aoqi@0: aoqi@0: /* the architecture being disassembled */ aoqi@0: const char* arch_name; aoqi@0: const bfd_arch_info_type* arch_info; aoqi@0: aoqi@0: /* the disassembler we are going to use: */ aoqi@0: disassembler_ftype dfn; aoqi@0: struct disassemble_info dinfo; /* the actual struct! */ aoqi@0: aoqi@0: char mach_option[64]; aoqi@0: char insn_options[256]; aoqi@0: }; aoqi@0: aoqi@0: static void* decode(struct hsdis_app_data* app_data, const char* options); aoqi@0: aoqi@0: #define DECL_APP_DATA(dinfo) \ aoqi@0: struct hsdis_app_data* app_data = (struct hsdis_app_data*) (dinfo)->application_data aoqi@0: aoqi@0: #define DECL_EVENT_CALLBACK(app_data) \ aoqi@0: event_callback_t event_callback = (app_data)->event_callback; \ aoqi@0: void* event_stream = (app_data)->event_stream aoqi@0: aoqi@0: #define DECL_PRINTF_CALLBACK(app_data) \ aoqi@0: printf_callback_t printf_callback = (app_data)->printf_callback; \ aoqi@0: void* printf_stream = (app_data)->printf_stream aoqi@0: aoqi@0: aoqi@0: static void print_help(struct hsdis_app_data* app_data, aoqi@0: const char* msg, const char* arg); aoqi@0: static void setup_app_data(struct hsdis_app_data* app_data, aoqi@0: const char* options); aoqi@0: static const char* format_insn_close(const char* close, aoqi@0: disassemble_info* dinfo, aoqi@0: char* buf, size_t bufsize); aoqi@0: aoqi@0: void* aoqi@0: #ifdef DLL_ENTRY aoqi@0: DLL_ENTRY aoqi@0: #endif aoqi@0: decode_instructions_virtual(uintptr_t start_va, uintptr_t end_va, aoqi@0: unsigned char* buffer, uintptr_t length, aoqi@0: event_callback_t event_callback_arg, void* event_stream_arg, aoqi@0: printf_callback_t printf_callback_arg, void* printf_stream_arg, aoqi@0: const char* options, int newline) { aoqi@0: struct hsdis_app_data app_data; aoqi@0: memset(&app_data, 0, sizeof(app_data)); aoqi@0: app_data.start_va = start_va; aoqi@0: app_data.end_va = end_va; aoqi@0: app_data.buffer = buffer; aoqi@0: app_data.length = length; aoqi@0: app_data.event_callback = event_callback_arg; aoqi@0: app_data.event_stream = event_stream_arg; aoqi@0: app_data.printf_callback = printf_callback_arg; aoqi@0: app_data.printf_stream = printf_stream_arg; aoqi@0: app_data.do_newline = newline == 0 ? false : true; aoqi@0: aoqi@0: return decode(&app_data, options); aoqi@0: } aoqi@0: aoqi@0: /* This is the compatability interface for older version of hotspot */ aoqi@0: void* aoqi@0: #ifdef DLL_ENTRY aoqi@0: DLL_ENTRY aoqi@0: #endif aoqi@0: decode_instructions(void* start_pv, void* end_pv, aoqi@0: event_callback_t event_callback_arg, void* event_stream_arg, aoqi@0: printf_callback_t printf_callback_arg, void* printf_stream_arg, aoqi@0: const char* options) { aoqi@0: decode_instructions_virtual((uintptr_t)start_pv, aoqi@0: (uintptr_t)end_pv, aoqi@0: (unsigned char*)start_pv, aoqi@0: (uintptr_t)end_pv - (uintptr_t)start_pv, aoqi@0: event_callback_arg, aoqi@0: event_stream_arg, aoqi@0: printf_callback_arg, aoqi@0: printf_stream_arg, aoqi@0: options, false); aoqi@0: } aoqi@0: aoqi@0: static void* decode(struct hsdis_app_data* app_data, const char* options) { aoqi@0: setup_app_data(app_data, options); aoqi@0: char buf[128]; aoqi@0: aoqi@0: { aoqi@0: /* now reload everything from app_data: */ aoqi@0: DECL_EVENT_CALLBACK(app_data); aoqi@0: DECL_PRINTF_CALLBACK(app_data); aoqi@0: uintptr_t start = app_data->start_va; aoqi@0: uintptr_t end = app_data->end_va; aoqi@0: uintptr_t p = start; aoqi@0: aoqi@0: (*event_callback)(event_stream, "insns", (void*)start); aoqi@0: aoqi@0: (*event_callback)(event_stream, "mach name='%s'", aoqi@0: (void*) app_data->arch_info->printable_name); aoqi@0: if (app_data->dinfo.bytes_per_line != 0) { aoqi@0: (*event_callback)(event_stream, "format bytes-per-line='%p'/", aoqi@0: (void*)(intptr_t) app_data->dinfo.bytes_per_line); aoqi@0: } aoqi@0: aoqi@0: while (p < end && !app_data->losing) { aoqi@0: (*event_callback)(event_stream, "insn", (void*) p); aoqi@0: aoqi@0: /* reset certain state, so we can read it with confidence */ aoqi@0: app_data->dinfo.insn_info_valid = 0; aoqi@0: app_data->dinfo.branch_delay_insns = 0; aoqi@0: app_data->dinfo.data_size = 0; aoqi@0: app_data->dinfo.insn_type = 0; aoqi@0: aoqi@0: int size = (*app_data->dfn)((bfd_vma) p, &app_data->dinfo); aoqi@0: aoqi@0: if (size > 0) p += size; aoqi@0: else app_data->losing = true; aoqi@0: aoqi@0: if (!app_data->losing) { aoqi@0: const char* insn_close = format_insn_close("/insn", &app_data->dinfo, aoqi@0: buf, sizeof(buf)); aoqi@0: (*event_callback)(event_stream, insn_close, (void*) p); aoqi@0: aoqi@0: if (app_data->do_newline) { aoqi@0: /* follow each complete insn by a nice newline */ aoqi@0: (*printf_callback)(printf_stream, "\n"); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (app_data->losing) (*event_callback)(event_stream, "/insns", (void*) p); aoqi@0: return (void*) p; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /* take the address of the function, for luck, and also test the typedef: */ aoqi@0: const decode_func_vtype decode_func_virtual_address = &decode_instructions_virtual; aoqi@0: const decode_func_stype decode_func_address = &decode_instructions; aoqi@0: aoqi@0: static const char* format_insn_close(const char* close, aoqi@0: disassemble_info* dinfo, aoqi@0: char* buf, size_t bufsize) { aoqi@0: if (!dinfo->insn_info_valid) aoqi@0: return close; aoqi@0: enum dis_insn_type itype = dinfo->insn_type; aoqi@0: int dsize = dinfo->data_size, delays = dinfo->branch_delay_insns; aoqi@0: if ((itype == dis_nonbranch && (dsize | delays) == 0) aoqi@0: || (strlen(close) + 3*20 > bufsize)) aoqi@0: return close; aoqi@0: aoqi@0: const char* type = "unknown"; aoqi@0: switch (itype) { aoqi@0: case dis_nonbranch: type = NULL; break; aoqi@0: case dis_branch: type = "branch"; break; aoqi@0: case dis_condbranch: type = "condbranch"; break; aoqi@0: case dis_jsr: type = "jsr"; break; aoqi@0: case dis_condjsr: type = "condjsr"; break; aoqi@0: case dis_dref: type = "dref"; break; aoqi@0: case dis_dref2: type = "dref2"; break; aoqi@0: } aoqi@0: aoqi@0: strcpy(buf, close); aoqi@0: char* p = buf; aoqi@0: if (type) sprintf(p += strlen(p), " type='%s'", type); aoqi@0: if (dsize) sprintf(p += strlen(p), " dsize='%d'", dsize); aoqi@0: if (delays) sprintf(p += strlen(p), " delay='%d'", delays); aoqi@0: return buf; aoqi@0: } aoqi@0: aoqi@0: /* handler functions */ aoqi@0: aoqi@0: static int aoqi@0: hsdis_read_memory_func(bfd_vma memaddr, aoqi@0: bfd_byte* myaddr, aoqi@0: unsigned int length, aoqi@0: struct disassemble_info* dinfo) { aoqi@0: DECL_APP_DATA(dinfo); aoqi@0: /* convert the virtual address memaddr into an address within memory buffer */ aoqi@0: uintptr_t offset = ((uintptr_t) memaddr) - app_data->start_va; aoqi@0: if (offset + length > app_data->length) { aoqi@0: /* read is out of bounds */ aoqi@0: return EIO; aoqi@0: } else { aoqi@0: memcpy(myaddr, (bfd_byte*) (app_data->buffer + offset), length); aoqi@0: return 0; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: static void aoqi@0: hsdis_print_address_func(bfd_vma vma, struct disassemble_info* dinfo) { aoqi@0: /* the actual value to print: */ aoqi@0: void* addr_value = (void*) (uintptr_t) vma; aoqi@0: DECL_APP_DATA(dinfo); aoqi@0: DECL_EVENT_CALLBACK(app_data); aoqi@0: aoqi@0: /* issue the event: */ aoqi@0: void* result = aoqi@0: (*event_callback)(event_stream, "addr/", addr_value); aoqi@0: if (result == NULL) { aoqi@0: /* event declined */ aoqi@0: generic_print_address(vma, dinfo); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: /* configuration */ aoqi@0: aoqi@0: static void set_optional_callbacks(struct hsdis_app_data* app_data); aoqi@0: static void parse_caller_options(struct hsdis_app_data* app_data, aoqi@0: const char* caller_options); aoqi@0: static const char* native_arch_name(); aoqi@0: static enum bfd_endian native_endian(); aoqi@0: static const bfd_arch_info_type* find_arch_info(const char* arch_nane); aoqi@0: static bfd* get_native_bfd(const bfd_arch_info_type* arch_info, aoqi@0: /* to avoid malloc: */ aoqi@0: bfd* empty_bfd, bfd_target* empty_xvec); aoqi@0: static void init_disassemble_info_from_bfd(struct disassemble_info* dinfo, aoqi@0: void *stream, aoqi@0: fprintf_ftype fprintf_func, aoqi@0: bfd* bfd, aoqi@0: char* disassembler_options); aoqi@0: static void parse_fake_insn(disassembler_ftype dfn, aoqi@0: struct disassemble_info* dinfo); aoqi@0: aoqi@0: static void setup_app_data(struct hsdis_app_data* app_data, aoqi@0: const char* caller_options) { aoqi@0: /* Make reasonable defaults for null callbacks. aoqi@0: A non-null stream for a null callback is assumed to be a FILE* for output. aoqi@0: Events are rendered as XML. aoqi@0: */ aoqi@0: set_optional_callbacks(app_data); aoqi@0: aoqi@0: /* Look into caller_options for anything interesting. */ aoqi@0: if (caller_options != NULL) aoqi@0: parse_caller_options(app_data, caller_options); aoqi@0: aoqi@0: /* Discover which architecture we are going to disassemble. */ aoqi@0: app_data->arch_name = &app_data->mach_option[0]; aoqi@0: if (app_data->arch_name[0] == '\0') aoqi@0: app_data->arch_name = native_arch_name(); aoqi@0: app_data->arch_info = find_arch_info(app_data->arch_name); aoqi@0: aoqi@0: /* Make a fake bfd to hold the arch. and byteorder info. */ aoqi@0: struct { aoqi@0: bfd_target empty_xvec; aoqi@0: bfd empty_bfd; aoqi@0: } buf; aoqi@0: bfd* native_bfd = get_native_bfd(app_data->arch_info, aoqi@0: /* to avoid malloc: */ aoqi@0: &buf.empty_bfd, &buf.empty_xvec); aoqi@0: init_disassemble_info_from_bfd(&app_data->dinfo, aoqi@0: app_data->printf_stream, aoqi@0: app_data->printf_callback, aoqi@0: native_bfd, aoqi@0: /* On PowerPC we get warnings, if we pass empty options */ aoqi@0: (caller_options == NULL) ? NULL : app_data->insn_options); aoqi@0: aoqi@0: /* Finish linking together the various callback blocks. */ aoqi@0: app_data->dinfo.application_data = (void*) app_data; aoqi@0: app_data->dfn = disassembler(native_bfd); aoqi@0: app_data->dinfo.print_address_func = hsdis_print_address_func; aoqi@0: app_data->dinfo.read_memory_func = hsdis_read_memory_func; aoqi@0: aoqi@0: if (app_data->dfn == NULL) { aoqi@0: const char* bad = app_data->arch_name; aoqi@0: static bool complained; aoqi@0: if (bad == &app_data->mach_option[0]) aoqi@0: print_help(app_data, "bad mach=%s", bad); aoqi@0: else if (!complained) aoqi@0: print_help(app_data, "bad native mach=%s; please port hsdis to this platform", bad); aoqi@0: complained = true; aoqi@0: /* must bail out */ aoqi@0: app_data->losing = true; aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: parse_fake_insn(app_data->dfn, &app_data->dinfo); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: /* ignore all events, return a null */ aoqi@0: static void* null_event_callback(void* ignore_stream, const char* ignore_event, void* arg) { aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: /* print all events as XML markup */ aoqi@0: static void* xml_event_callback(void* stream, const char* event, void* arg) { aoqi@0: FILE* fp = (FILE*) stream; aoqi@0: #define NS_PFX "dis:" aoqi@0: if (event[0] != '/') { aoqi@0: /* issue the tag, with or without a formatted argument */ aoqi@0: fprintf(fp, "<"NS_PFX); aoqi@0: fprintf(fp, event, arg); aoqi@0: fprintf(fp, ">"); aoqi@0: } else { aoqi@0: ++event; /* skip slash */ aoqi@0: const char* argp = strchr(event, ' '); aoqi@0: if (argp == NULL) { aoqi@0: /* no arguments; just issue the closing tag */ aoqi@0: fprintf(fp, "", event); aoqi@0: } else { aoqi@0: /* split out the closing attributes as */ aoqi@0: int event_prefix = (argp - event); aoqi@0: fprintf(fp, "<"NS_PFX"%.*s_done", event_prefix, event); aoqi@0: fprintf(fp, argp, arg); aoqi@0: fprintf(fp, "/>", event_prefix, event); aoqi@0: } aoqi@0: } aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: static void set_optional_callbacks(struct hsdis_app_data* app_data) { aoqi@0: if (app_data->printf_callback == NULL) { aoqi@0: int (*fprintf_callback)(FILE*, const char*, ...) = &fprintf; aoqi@0: FILE* fprintf_stream = stdout; aoqi@0: app_data->printf_callback = (printf_callback_t) fprintf_callback; aoqi@0: if (app_data->printf_stream == NULL) aoqi@0: app_data->printf_stream = (void*) fprintf_stream; aoqi@0: } aoqi@0: if (app_data->event_callback == NULL) { aoqi@0: if (app_data->event_stream == NULL) aoqi@0: app_data->event_callback = &null_event_callback; aoqi@0: else aoqi@0: app_data->event_callback = &xml_event_callback; aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: aoqi@0: static void parse_caller_options(struct hsdis_app_data* app_data, const char* caller_options) { aoqi@0: char* iop_base = app_data->insn_options; aoqi@0: char* iop_limit = iop_base + sizeof(app_data->insn_options) - 1; aoqi@0: char* iop = iop_base; aoqi@0: const char* p; aoqi@0: for (p = caller_options; p != NULL; ) { aoqi@0: const char* q = strchr(p, ','); aoqi@0: size_t plen = (q == NULL) ? strlen(p) : ((q++) - p); aoqi@0: if (plen == 4 && strncmp(p, "help", plen) == 0) { aoqi@0: print_help(app_data, NULL, NULL); aoqi@0: } else if (plen >= 5 && strncmp(p, "mach=", 5) == 0) { aoqi@0: char* mach_option = app_data->mach_option; aoqi@0: size_t mach_size = sizeof(app_data->mach_option); aoqi@0: mach_size -= 1; /*leave room for the null*/ aoqi@0: if (plen > mach_size) plen = mach_size; aoqi@0: strncpy(mach_option, p, plen); aoqi@0: mach_option[plen] = '\0'; aoqi@0: } else if (plen > 6 && strncmp(p, "hsdis-", 6) == 0) { aoqi@0: // do not pass these to the next level aoqi@0: } else { aoqi@0: /* just copy it; {i386,sparc}-dis.c might like to see it */ aoqi@0: if (iop > iop_base && iop < iop_limit) (*iop++) = ','; aoqi@0: if (iop + plen > iop_limit) aoqi@0: plen = iop_limit - iop; aoqi@0: strncpy(iop, p, plen); aoqi@0: iop += plen; aoqi@0: } aoqi@0: p = q; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: static void print_help(struct hsdis_app_data* app_data, aoqi@0: const char* msg, const char* arg) { aoqi@0: DECL_PRINTF_CALLBACK(app_data); aoqi@0: if (msg != NULL) { aoqi@0: (*printf_callback)(printf_stream, "hsdis: "); aoqi@0: (*printf_callback)(printf_stream, msg, arg); aoqi@0: (*printf_callback)(printf_stream, "\n"); aoqi@0: } aoqi@0: (*printf_callback)(printf_stream, "hsdis output options:\n"); aoqi@0: if (printf_callback == (printf_callback_t) &fprintf) aoqi@0: disassembler_usage((FILE*) printf_stream); aoqi@0: else aoqi@0: disassembler_usage(stderr); /* better than nothing */ aoqi@0: (*printf_callback)(printf_stream, " mach= select disassembly mode\n"); aoqi@0: #if defined(LIBARCH_i386) || defined(LIBARCH_amd64) aoqi@0: (*printf_callback)(printf_stream, " mach=i386 select 32-bit mode\n"); aoqi@0: (*printf_callback)(printf_stream, " mach=x86-64 select 64-bit mode\n"); aoqi@0: (*printf_callback)(printf_stream, " suffix always print instruction suffix\n"); aoqi@0: #endif aoqi@0: (*printf_callback)(printf_stream, " help print this message\n"); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: /* low-level bfd and arch stuff that binutils doesn't do for us */ aoqi@0: aoqi@0: static const bfd_arch_info_type* find_arch_info(const char* arch_name) { aoqi@0: const bfd_arch_info_type* arch_info = bfd_scan_arch(arch_name); aoqi@0: if (arch_info == NULL) { aoqi@0: extern const bfd_arch_info_type bfd_default_arch_struct; aoqi@0: arch_info = &bfd_default_arch_struct; aoqi@0: } aoqi@0: return arch_info; aoqi@0: } aoqi@0: aoqi@0: static const char* native_arch_name() { aoqi@0: const char* res = NULL; aoqi@0: #ifdef LIBARCH_i386 aoqi@0: res = "i386"; aoqi@0: #endif aoqi@0: #ifdef LIBARCH_amd64 aoqi@0: res = "i386:x86-64"; aoqi@0: #endif aoqi@0: #ifdef LIBARCH_sparc aoqi@0: res = "sparc:v8plusb"; aoqi@0: #endif aoqi@0: #ifdef LIBARCH_sparcv9 aoqi@0: res = "sparc:v9b"; aoqi@0: #endif aoqi@0: #ifdef LIBARCH_ppc64 aoqi@0: res = "powerpc:common64"; aoqi@0: #endif aoqi@432: #ifdef LIBARCH_mips64 aoqi@432: #ifdef LOONGSON aoqi@432: res = "mips:loongson_3a"; aoqi@432: #else aoqi@432: res = "mips:isa64"; aoqi@432: #endif aoqi@432: #endif aoqi@0: if (res == NULL) aoqi@0: res = "architecture not set in Makefile!"; aoqi@0: return res; aoqi@0: } aoqi@0: aoqi@0: static enum bfd_endian native_endian() { aoqi@0: int32_t endian_test = 'x'; aoqi@0: if (*(const char*) &endian_test == 'x') aoqi@0: return BFD_ENDIAN_LITTLE; aoqi@0: else aoqi@0: return BFD_ENDIAN_BIG; aoqi@0: } aoqi@0: aoqi@0: static bfd* get_native_bfd(const bfd_arch_info_type* arch_info, aoqi@0: bfd* empty_bfd, bfd_target* empty_xvec) { aoqi@0: memset(empty_bfd, 0, sizeof(*empty_bfd)); aoqi@0: memset(empty_xvec, 0, sizeof(*empty_xvec)); aoqi@0: empty_xvec->flavour = bfd_target_unknown_flavour; aoqi@0: empty_xvec->byteorder = native_endian(); aoqi@0: empty_bfd->xvec = empty_xvec; aoqi@0: empty_bfd->arch_info = arch_info; aoqi@0: return empty_bfd; aoqi@0: } aoqi@0: aoqi@0: static int read_zero_data_only(bfd_vma ignore_p, aoqi@0: bfd_byte* myaddr, unsigned int length, aoqi@0: struct disassemble_info *ignore_info) { aoqi@0: memset(myaddr, 0, length); aoqi@0: return 0; aoqi@0: } aoqi@0: static int print_to_dev_null(void* ignore_stream, const char* ignore_format, ...) { aoqi@0: return 0; aoqi@0: } aoqi@0: aoqi@0: /* Prime the pump by running the selected disassembler on a null input. aoqi@0: This forces the machine-specific disassembler to divulge invariant aoqi@0: information like bytes_per_line. aoqi@0: */ aoqi@0: static void parse_fake_insn(disassembler_ftype dfn, aoqi@0: struct disassemble_info* dinfo) { aoqi@0: typedef int (*read_memory_ftype) aoqi@0: (bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, aoqi@0: struct disassemble_info *info); aoqi@0: read_memory_ftype read_memory_func = dinfo->read_memory_func; aoqi@0: fprintf_ftype fprintf_func = dinfo->fprintf_func; aoqi@0: aoqi@0: dinfo->read_memory_func = &read_zero_data_only; aoqi@0: dinfo->fprintf_func = &print_to_dev_null; aoqi@0: (*dfn)(0, dinfo); aoqi@0: aoqi@0: /* put it back */ aoqi@0: dinfo->read_memory_func = read_memory_func; aoqi@0: dinfo->fprintf_func = fprintf_func; aoqi@0: } aoqi@0: aoqi@0: static void init_disassemble_info_from_bfd(struct disassemble_info* dinfo, aoqi@0: void *stream, aoqi@0: fprintf_ftype fprintf_func, aoqi@0: bfd* abfd, aoqi@0: char* disassembler_options) { aoqi@0: init_disassemble_info(dinfo, stream, fprintf_func); aoqi@0: aoqi@0: dinfo->flavour = bfd_get_flavour(abfd); aoqi@0: dinfo->arch = bfd_get_arch(abfd); aoqi@0: dinfo->mach = bfd_get_mach(abfd); aoqi@0: dinfo->disassembler_options = disassembler_options; aoqi@0: dinfo->octets_per_byte = bfd_octets_per_byte (abfd); aoqi@0: dinfo->skip_zeroes = sizeof(void*) * 2; aoqi@0: dinfo->skip_zeroes_at_end = sizeof(void*)-1; aoqi@0: dinfo->disassembler_needs_relocs = FALSE; aoqi@0: aoqi@0: if (bfd_big_endian(abfd)) aoqi@0: dinfo->display_endian = dinfo->endian = BFD_ENDIAN_BIG; aoqi@0: else if (bfd_little_endian(abfd)) aoqi@0: dinfo->display_endian = dinfo->endian = BFD_ENDIAN_LITTLE; aoqi@0: else aoqi@0: dinfo->endian = native_endian(); aoqi@0: aoqi@0: disassemble_init_for_target(dinfo); aoqi@0: }