annotate src/share/tools/hsdis/hsdis.c @ 24234:ea6f94ab283b default tip

Added tag jvmci-0.36 for changeset 8128b98d4736
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Mon, 18 Sep 2017 18:49:45 +0200
parents 3848113e3e6b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
1 /*
17524
89152779163c Merge with jdk8-b132
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14909
diff changeset
2 * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
4 *
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
7 * published by the Free Software Foundation.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
8 *
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
13 * accompanied this code).
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
14 *
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 844
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 844
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 844
diff changeset
21 * questions.
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
22 *
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
23 */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
24
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
25 /* hsdis.c -- dump a range of addresses as native instructions
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
26 This implements the plugin protocol required by the
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
27 HotSpot PrintAssembly option.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
28 */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
29
10320
ec922e5c545a 8012312: hsdis fails to compile with binutils-2.23.2
anoll
parents: 6933
diff changeset
30 #include <config.h> /* required by bfd.h */
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
31 #include <libiberty.h>
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
32 #include <bfd.h>
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
33 #include <dis-asm.h>
720
67a2f5ba5582 6684007: PrintAssembly plugin not available for linux or windows
never
parents: 100
diff changeset
34 #include <inttypes.h>
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
35 #include <string.h>
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
36 #include <errno.h>
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
37 #include "hsdis.h"
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
38
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
39 #ifndef bool
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
40 #define bool int
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
41 #define true 1
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
42 #define false 0
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
43 #endif /*bool*/
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
44
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
45 /* short names for stuff in hsdis.h */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
46 typedef decode_instructions_event_callback_ftype event_callback_t;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
47 typedef decode_instructions_printf_callback_ftype printf_callback_t;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
48
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
49 /* disassemble_info.application_data object */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
50 struct hsdis_app_data {
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
51 /* virtual address of data */
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
52 uintptr_t start_va, end_va;
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
53 /* the instructions to be decoded */
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
54 unsigned char* buffer;
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
55 uintptr_t length;
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
56 event_callback_t event_callback; void* event_stream;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
57 printf_callback_t printf_callback; void* printf_stream;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
58 bool losing;
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
59 bool do_newline;
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
60
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
61 /* the architecture being disassembled */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
62 const char* arch_name;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
63 const bfd_arch_info_type* arch_info;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
64
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
65 /* the disassembler we are going to use: */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
66 disassembler_ftype dfn;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
67 struct disassemble_info dinfo; /* the actual struct! */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
68
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
69 char mach_option[64];
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
70 char insn_options[256];
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
71 };
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
72
23352
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
73 #if defined(LIBARCH_i386) || defined(LIBARCH_amd64)
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
74 #ifdef ATT_SYNTAX
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
75 #define PLATFORM_OPTIONS "att"
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
76 #else
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
77 #define PLATFORM_OPTIONS "intel"
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
78 #endif
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
79 #else
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
80 #define PLATFORM_OPTIONS ""
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
81 #endif
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
82 static const char* platform_options = PLATFORM_OPTIONS;
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
83
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
84 const char* hsdis_version_string = "built from " BINUTILS " with disassembler options \"" PLATFORM_OPTIONS "\" on " __DATE__ " at " __TIME__;
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
85
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
86 static void* decode(struct hsdis_app_data* app_data, const char* options);
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
87
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
88 #define DECL_APP_DATA(dinfo) \
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
89 struct hsdis_app_data* app_data = (struct hsdis_app_data*) (dinfo)->application_data
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
90
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
91 #define DECL_EVENT_CALLBACK(app_data) \
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
92 event_callback_t event_callback = (app_data)->event_callback; \
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
93 void* event_stream = (app_data)->event_stream
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
94
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
95 #define DECL_PRINTF_CALLBACK(app_data) \
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
96 printf_callback_t printf_callback = (app_data)->printf_callback; \
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
97 void* printf_stream = (app_data)->printf_stream
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
98
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
99
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
100 static void print_help(struct hsdis_app_data* app_data,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
101 const char* msg, const char* arg);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
102 static void setup_app_data(struct hsdis_app_data* app_data,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
103 const char* options);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
104 static const char* format_insn_close(const char* close,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
105 disassemble_info* dinfo,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
106 char* buf, size_t bufsize);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
107
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
108 void*
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
109 #ifdef DLL_ENTRY
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
110 DLL_ENTRY
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
111 #endif
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
112 decode_instructions_virtual(uintptr_t start_va, uintptr_t end_va,
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
113 unsigned char* buffer, uintptr_t length,
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
114 event_callback_t event_callback_arg, void* event_stream_arg,
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
115 printf_callback_t printf_callback_arg, void* printf_stream_arg,
6933
3d701c802d01 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 6782
diff changeset
116 const char* options, int newline) {
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
117 struct hsdis_app_data app_data;
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
118 memset(&app_data, 0, sizeof(app_data));
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
119 app_data.start_va = start_va;
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
120 app_data.end_va = end_va;
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
121 app_data.buffer = buffer;
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
122 app_data.length = length;
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
123 app_data.event_callback = event_callback_arg;
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
124 app_data.event_stream = event_stream_arg;
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
125 app_data.printf_callback = printf_callback_arg;
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
126 app_data.printf_stream = printf_stream_arg;
6933
3d701c802d01 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 6782
diff changeset
127 app_data.do_newline = newline == 0 ? false : true;
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
128
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
129 return decode(&app_data, options);
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
130 }
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
131
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
132 /* This is the compatability interface for older version of hotspot */
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
133 void*
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
134 #ifdef DLL_ENTRY
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
135 DLL_ENTRY
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
136 #endif
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
137 decode_instructions(void* start_pv, void* end_pv,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
138 event_callback_t event_callback_arg, void* event_stream_arg,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
139 printf_callback_t printf_callback_arg, void* printf_stream_arg,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
140 const char* options) {
23352
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
141 return decode_instructions_virtual((uintptr_t)start_pv,
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
142 (uintptr_t)end_pv,
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
143 (unsigned char*)start_pv,
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
144 (uintptr_t)end_pv - (uintptr_t)start_pv,
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
145 event_callback_arg,
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
146 event_stream_arg,
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
147 printf_callback_arg,
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
148 printf_stream_arg,
6933
3d701c802d01 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 6782
diff changeset
149 options, false);
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
150 }
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
151
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
152 static void* decode(struct hsdis_app_data* app_data, const char* options) {
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
153 setup_app_data(app_data, options);
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
154 char buf[128];
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
155
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
156 {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
157 /* now reload everything from app_data: */
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
158 DECL_EVENT_CALLBACK(app_data);
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
159 DECL_PRINTF_CALLBACK(app_data);
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
160 uintptr_t start = app_data->start_va;
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
161 uintptr_t end = app_data->end_va;
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
162 uintptr_t p = start;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
163
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
164 (*event_callback)(event_stream, "insns", (void*)start);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
165
23352
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
166 (*event_callback)(event_stream, "options='%s'",
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
167 (void*) app_data->insn_options);
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
168 (*event_callback)(event_stream, "mach name='%s'",
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
169 (void*) app_data->arch_info->printable_name);
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
170 if (app_data->dinfo.bytes_per_line != 0) {
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
171 (*event_callback)(event_stream, "format bytes-per-line='%p'/",
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
172 (void*)(intptr_t) app_data->dinfo.bytes_per_line);
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
173 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
174
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
175 while (p < end && !app_data->losing) {
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
176 (*event_callback)(event_stream, "insn", (void*) p);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
177
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
178 /* reset certain state, so we can read it with confidence */
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
179 app_data->dinfo.insn_info_valid = 0;
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
180 app_data->dinfo.branch_delay_insns = 0;
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
181 app_data->dinfo.data_size = 0;
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
182 app_data->dinfo.insn_type = 0;
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
183
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
184 int size = (*app_data->dfn)((bfd_vma) p, &app_data->dinfo);
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
185
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
186 if (size > 0) p += size;
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
187 else app_data->losing = true;
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
188
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
189 if (!app_data->losing) {
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
190 const char* insn_close = format_insn_close("/insn", &app_data->dinfo,
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
191 buf, sizeof(buf));
6933
3d701c802d01 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 6782
diff changeset
192 (*event_callback)(event_stream, insn_close, (void*) p);
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
193
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
194 if (app_data->do_newline) {
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
195 /* follow each complete insn by a nice newline */
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
196 (*printf_callback)(printf_stream, "\n");
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
197 }
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
198 }
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
199 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
200
6933
3d701c802d01 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 6782
diff changeset
201 if (app_data->losing) (*event_callback)(event_stream, "/insns", (void*) p);
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
202 return (void*) p;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
203 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
204 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
205
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
206 /* take the address of the function, for luck, and also test the typedef: */
6933
3d701c802d01 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 6782
diff changeset
207 const decode_func_vtype decode_func_virtual_address = &decode_instructions_virtual;
3d701c802d01 8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents: 6782
diff changeset
208 const decode_func_stype decode_func_address = &decode_instructions;
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
209
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
210 static const char* format_insn_close(const char* close,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
211 disassemble_info* dinfo,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
212 char* buf, size_t bufsize) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
213 if (!dinfo->insn_info_valid)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
214 return close;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
215 enum dis_insn_type itype = dinfo->insn_type;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
216 int dsize = dinfo->data_size, delays = dinfo->branch_delay_insns;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
217 if ((itype == dis_nonbranch && (dsize | delays) == 0)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
218 || (strlen(close) + 3*20 > bufsize))
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
219 return close;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
220
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
221 const char* type = "unknown";
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
222 switch (itype) {
23352
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
223 case dis_noninsn:
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
224 case dis_nonbranch: type = NULL; break;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
225 case dis_branch: type = "branch"; break;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
226 case dis_condbranch: type = "condbranch"; break;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
227 case dis_jsr: type = "jsr"; break;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
228 case dis_condjsr: type = "condjsr"; break;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
229 case dis_dref: type = "dref"; break;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
230 case dis_dref2: type = "dref2"; break;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
231 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
232
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
233 strcpy(buf, close);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
234 char* p = buf;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
235 if (type) sprintf(p += strlen(p), " type='%s'", type);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
236 if (dsize) sprintf(p += strlen(p), " dsize='%d'", dsize);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
237 if (delays) sprintf(p += strlen(p), " delay='%d'", delays);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
238 return buf;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
239 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
240
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
241 /* handler functions */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
242
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
243 static int
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
244 hsdis_read_memory_func(bfd_vma memaddr,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
245 bfd_byte* myaddr,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
246 unsigned int length,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
247 struct disassemble_info* dinfo) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
248 DECL_APP_DATA(dinfo);
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
249 /* convert the virtual address memaddr into an address within memory buffer */
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
250 uintptr_t offset = ((uintptr_t) memaddr) - app_data->start_va;
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
251 if (offset + length > app_data->length) {
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
252 /* read is out of bounds */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
253 return EIO;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
254 } else {
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
255 memcpy(myaddr, (bfd_byte*) (app_data->buffer + offset), length);
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
256 return 0;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
257 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
258 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
259
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
260 static void
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
261 hsdis_print_address_func(bfd_vma vma, struct disassemble_info* dinfo) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
262 /* the actual value to print: */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
263 void* addr_value = (void*) (uintptr_t) vma;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
264 DECL_APP_DATA(dinfo);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
265 DECL_EVENT_CALLBACK(app_data);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
266
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
267 /* issue the event: */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
268 void* result =
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
269 (*event_callback)(event_stream, "addr/", addr_value);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
270 if (result == NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
271 /* event declined */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
272 generic_print_address(vma, dinfo);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
273 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
274 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
275
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
276
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
277 /* configuration */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
278
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
279 static void set_optional_callbacks(struct hsdis_app_data* app_data);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
280 static void parse_caller_options(struct hsdis_app_data* app_data,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
281 const char* caller_options);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
282 static const char* native_arch_name();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
283 static enum bfd_endian native_endian();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
284 static const bfd_arch_info_type* find_arch_info(const char* arch_nane);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
285 static bfd* get_native_bfd(const bfd_arch_info_type* arch_info,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
286 /* to avoid malloc: */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
287 bfd* empty_bfd, bfd_target* empty_xvec);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
288 static void init_disassemble_info_from_bfd(struct disassemble_info* dinfo,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
289 void *stream,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
290 fprintf_ftype fprintf_func,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
291 bfd* bfd,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
292 char* disassembler_options);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
293 static void parse_fake_insn(disassembler_ftype dfn,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
294 struct disassemble_info* dinfo);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
295
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
296 static void setup_app_data(struct hsdis_app_data* app_data,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
297 const char* caller_options) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
298 /* Make reasonable defaults for null callbacks.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
299 A non-null stream for a null callback is assumed to be a FILE* for output.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
300 Events are rendered as XML.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
301 */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
302 set_optional_callbacks(app_data);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
303
23352
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
304 memset(app_data->insn_options, 0, sizeof(app_data->insn_options));
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
305 if (platform_options != NULL) {
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
306 parse_caller_options(app_data, platform_options);
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
307 }
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
308 /* Look into caller_options for anything interesting. */
23352
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
309 if (caller_options != NULL) {
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
310 parse_caller_options(app_data, caller_options);
23352
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
311 }
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
312
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
313 /* Discover which architecture we are going to disassemble. */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
314 app_data->arch_name = &app_data->mach_option[0];
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
315 if (app_data->arch_name[0] == '\0')
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
316 app_data->arch_name = native_arch_name();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
317 app_data->arch_info = find_arch_info(app_data->arch_name);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
318
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
319 /* Make a fake bfd to hold the arch. and byteorder info. */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
320 struct {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
321 bfd_target empty_xvec;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
322 bfd empty_bfd;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
323 } buf;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
324 bfd* native_bfd = get_native_bfd(app_data->arch_info,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
325 /* to avoid malloc: */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
326 &buf.empty_bfd, &buf.empty_xvec);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
327 init_disassemble_info_from_bfd(&app_data->dinfo,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
328 app_data->printf_stream,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
329 app_data->printf_callback,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
330 native_bfd,
18041
52b4284cb496 Merge with jdk8u20-b26
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 17524
diff changeset
331 /* On PowerPC we get warnings, if we pass empty options */
52b4284cb496 Merge with jdk8u20-b26
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 17524
diff changeset
332 (caller_options == NULL) ? NULL : app_data->insn_options);
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
333
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
334 /* Finish linking together the various callback blocks. */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
335 app_data->dinfo.application_data = (void*) app_data;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
336 app_data->dfn = disassembler(native_bfd);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
337 app_data->dinfo.print_address_func = hsdis_print_address_func;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
338 app_data->dinfo.read_memory_func = hsdis_read_memory_func;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
339
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
340 if (app_data->dfn == NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
341 const char* bad = app_data->arch_name;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
342 static bool complained;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
343 if (bad == &app_data->mach_option[0])
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
344 print_help(app_data, "bad mach=%s", bad);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
345 else if (!complained)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
346 print_help(app_data, "bad native mach=%s; please port hsdis to this platform", bad);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
347 complained = true;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
348 /* must bail out */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
349 app_data->losing = true;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
350 return;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
351 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
352
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
353 parse_fake_insn(app_data->dfn, &app_data->dinfo);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
354 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
355
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
356
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
357 /* ignore all events, return a null */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
358 static void* null_event_callback(void* ignore_stream, const char* ignore_event, void* arg) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
359 return NULL;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
360 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
361
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
362 /* print all events as XML markup */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
363 static void* xml_event_callback(void* stream, const char* event, void* arg) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
364 FILE* fp = (FILE*) stream;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
365 #define NS_PFX "dis:"
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
366 if (event[0] != '/') {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
367 /* issue the tag, with or without a formatted argument */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
368 fprintf(fp, "<"NS_PFX);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
369 fprintf(fp, event, arg);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
370 fprintf(fp, ">");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
371 } else {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
372 ++event; /* skip slash */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
373 const char* argp = strchr(event, ' ');
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
374 if (argp == NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
375 /* no arguments; just issue the closing tag */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
376 fprintf(fp, "</"NS_PFX"%s>", event);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
377 } else {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
378 /* split out the closing attributes as <dis:foo_done attr='val'/> */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
379 int event_prefix = (argp - event);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
380 fprintf(fp, "<"NS_PFX"%.*s_done", event_prefix, event);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
381 fprintf(fp, argp, arg);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
382 fprintf(fp, "/></"NS_PFX"%.*s>", event_prefix, event);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
383 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
384 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
385 return NULL;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
386 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
387
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
388 static void set_optional_callbacks(struct hsdis_app_data* app_data) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
389 if (app_data->printf_callback == NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
390 int (*fprintf_callback)(FILE*, const char*, ...) = &fprintf;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
391 FILE* fprintf_stream = stdout;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
392 app_data->printf_callback = (printf_callback_t) fprintf_callback;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
393 if (app_data->printf_stream == NULL)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
394 app_data->printf_stream = (void*) fprintf_stream;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
395 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
396 if (app_data->event_callback == NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
397 if (app_data->event_stream == NULL)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
398 app_data->event_callback = &null_event_callback;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
399 else
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
400 app_data->event_callback = &xml_event_callback;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
401 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
402
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
403 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
404
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
405 static void parse_caller_options(struct hsdis_app_data* app_data, const char* caller_options) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
406 char* iop_base = app_data->insn_options;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
407 char* iop_limit = iop_base + sizeof(app_data->insn_options) - 1;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
408 char* iop = iop_base;
23352
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
409
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
410 // Move to the end of any options already in the buffer
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
411 while (*iop != '\0' && iop < iop_limit) {
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
412 iop++;
3848113e3e6b Update hsdis binaries
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18041
diff changeset
413 }
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
414 const char* p;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
415 for (p = caller_options; p != NULL; ) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
416 const char* q = strchr(p, ',');
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
417 size_t plen = (q == NULL) ? strlen(p) : ((q++) - p);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
418 if (plen == 4 && strncmp(p, "help", plen) == 0) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
419 print_help(app_data, NULL, NULL);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
420 } else if (plen >= 5 && strncmp(p, "mach=", 5) == 0) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
421 char* mach_option = app_data->mach_option;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
422 size_t mach_size = sizeof(app_data->mach_option);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
423 mach_size -= 1; /*leave room for the null*/
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
424 if (plen > mach_size) plen = mach_size;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
425 strncpy(mach_option, p, plen);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
426 mach_option[plen] = '\0';
4938
de34c646c3f7 7140985: HSDIS does not handle caller options correctly
kvn
parents: 2426
diff changeset
427 } else if (plen > 6 && strncmp(p, "hsdis-", 6) == 0) {
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
428 // do not pass these to the next level
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
429 } else {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
430 /* just copy it; {i386,sparc}-dis.c might like to see it */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
431 if (iop > iop_base && iop < iop_limit) (*iop++) = ',';
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
432 if (iop + plen > iop_limit)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
433 plen = iop_limit - iop;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
434 strncpy(iop, p, plen);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
435 iop += plen;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
436 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
437 p = q;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
438 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
439 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
440
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
441 static void print_help(struct hsdis_app_data* app_data,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
442 const char* msg, const char* arg) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
443 DECL_PRINTF_CALLBACK(app_data);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
444 if (msg != NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
445 (*printf_callback)(printf_stream, "hsdis: ");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
446 (*printf_callback)(printf_stream, msg, arg);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
447 (*printf_callback)(printf_stream, "\n");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
448 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
449 (*printf_callback)(printf_stream, "hsdis output options:\n");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
450 if (printf_callback == (printf_callback_t) &fprintf)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
451 disassembler_usage((FILE*) printf_stream);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
452 else
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
453 disassembler_usage(stderr); /* better than nothing */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
454 (*printf_callback)(printf_stream, " mach=<arch> select disassembly mode\n");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
455 #if defined(LIBARCH_i386) || defined(LIBARCH_amd64)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
456 (*printf_callback)(printf_stream, " mach=i386 select 32-bit mode\n");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
457 (*printf_callback)(printf_stream, " mach=x86-64 select 64-bit mode\n");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
458 (*printf_callback)(printf_stream, " suffix always print instruction suffix\n");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
459 #endif
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
460 (*printf_callback)(printf_stream, " help print this message\n");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
461 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
462
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
463
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
464 /* low-level bfd and arch stuff that binutils doesn't do for us */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
465
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
466 static const bfd_arch_info_type* find_arch_info(const char* arch_name) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
467 const bfd_arch_info_type* arch_info = bfd_scan_arch(arch_name);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
468 if (arch_info == NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
469 extern const bfd_arch_info_type bfd_default_arch_struct;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
470 arch_info = &bfd_default_arch_struct;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
471 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
472 return arch_info;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
473 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
474
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
475 static const char* native_arch_name() {
720
67a2f5ba5582 6684007: PrintAssembly plugin not available for linux or windows
never
parents: 100
diff changeset
476 const char* res = NULL;
67a2f5ba5582 6684007: PrintAssembly plugin not available for linux or windows
never
parents: 100
diff changeset
477 #ifdef LIBARCH_i386
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
478 res = "i386";
720
67a2f5ba5582 6684007: PrintAssembly plugin not available for linux or windows
never
parents: 100
diff changeset
479 #endif
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
480 #ifdef LIBARCH_amd64
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
481 res = "i386:x86-64";
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
482 #endif
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
483 #ifdef LIBARCH_sparc
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
484 res = "sparc:v8plusb";
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
485 #endif
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
486 #ifdef LIBARCH_sparcv9
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
487 res = "sparc:v9b";
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
488 #endif
18041
52b4284cb496 Merge with jdk8u20-b26
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 17524
diff changeset
489 #ifdef LIBARCH_ppc64
52b4284cb496 Merge with jdk8u20-b26
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 17524
diff changeset
490 res = "powerpc:common64";
52b4284cb496 Merge with jdk8u20-b26
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 17524
diff changeset
491 #endif
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
492 if (res == NULL)
720
67a2f5ba5582 6684007: PrintAssembly plugin not available for linux or windows
never
parents: 100
diff changeset
493 res = "architecture not set in Makefile!";
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
494 return res;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
495 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
496
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
497 static enum bfd_endian native_endian() {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
498 int32_t endian_test = 'x';
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
499 if (*(const char*) &endian_test == 'x')
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
500 return BFD_ENDIAN_LITTLE;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
501 else
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
502 return BFD_ENDIAN_BIG;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
503 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
504
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
505 static bfd* get_native_bfd(const bfd_arch_info_type* arch_info,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
506 bfd* empty_bfd, bfd_target* empty_xvec) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
507 memset(empty_bfd, 0, sizeof(*empty_bfd));
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
508 memset(empty_xvec, 0, sizeof(*empty_xvec));
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
509 empty_xvec->flavour = bfd_target_unknown_flavour;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
510 empty_xvec->byteorder = native_endian();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
511 empty_bfd->xvec = empty_xvec;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
512 empty_bfd->arch_info = arch_info;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
513 return empty_bfd;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
514 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
515
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
516 static int read_zero_data_only(bfd_vma ignore_p,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
517 bfd_byte* myaddr, unsigned int length,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
518 struct disassemble_info *ignore_info) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
519 memset(myaddr, 0, length);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
520 return 0;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
521 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
522 static int print_to_dev_null(void* ignore_stream, const char* ignore_format, ...) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
523 return 0;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
524 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
525
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
526 /* Prime the pump by running the selected disassembler on a null input.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
527 This forces the machine-specific disassembler to divulge invariant
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
528 information like bytes_per_line.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
529 */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
530 static void parse_fake_insn(disassembler_ftype dfn,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
531 struct disassemble_info* dinfo) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
532 typedef int (*read_memory_ftype)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
533 (bfd_vma memaddr, bfd_byte *myaddr, unsigned int length,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
534 struct disassemble_info *info);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
535 read_memory_ftype read_memory_func = dinfo->read_memory_func;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
536 fprintf_ftype fprintf_func = dinfo->fprintf_func;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
537
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
538 dinfo->read_memory_func = &read_zero_data_only;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
539 dinfo->fprintf_func = &print_to_dev_null;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
540 (*dfn)(0, dinfo);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
541
6782
5a98bf7d847b 6879063: SA should use hsdis for disassembly
minqi
parents: 4938
diff changeset
542 /* put it back */
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
543 dinfo->read_memory_func = read_memory_func;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
544 dinfo->fprintf_func = fprintf_func;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
545 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
546
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
547 static void init_disassemble_info_from_bfd(struct disassemble_info* dinfo,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
548 void *stream,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
549 fprintf_ftype fprintf_func,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
550 bfd* abfd,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
551 char* disassembler_options) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
552 init_disassemble_info(dinfo, stream, fprintf_func);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
553
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
554 dinfo->flavour = bfd_get_flavour(abfd);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
555 dinfo->arch = bfd_get_arch(abfd);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
556 dinfo->mach = bfd_get_mach(abfd);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
557 dinfo->disassembler_options = disassembler_options;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
558 dinfo->octets_per_byte = bfd_octets_per_byte (abfd);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
559 dinfo->skip_zeroes = sizeof(void*) * 2;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
560 dinfo->skip_zeroes_at_end = sizeof(void*)-1;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
561 dinfo->disassembler_needs_relocs = FALSE;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
562
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
563 if (bfd_big_endian(abfd))
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
564 dinfo->display_endian = dinfo->endian = BFD_ENDIAN_BIG;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
565 else if (bfd_little_endian(abfd))
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
566 dinfo->display_endian = dinfo->endian = BFD_ENDIAN_LITTLE;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
567 else
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
568 dinfo->endian = native_endian();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
569
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
570 disassemble_init_for_target(dinfo);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
571 }