Mercurial > hg > truffle
annotate src/share/tools/hsdis/hsdis-demo.c @ 13705:ac5b0f31f7a2
Truffle API-change: FrameDescriptors are now stored in the RootNode in a final field instead of the CallTarget.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 17 Jan 2014 17:06:08 +0100 |
parents | 3d701c802d01 |
children |
rev | line source |
---|---|
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
1 /* |
6782 | 2 * Copyright (c) 2008, 2012, 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-demo.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 demonstrates the protocol required by the HotSpot PrintAssembly option. |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
27 */ |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
28 |
6782 | 29 #include <stdio.h> |
30 #include <stdlib.h> | |
31 #include <string.h> | |
32 #include <inttypes.h> | |
33 | |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
34 #include "hsdis.h" |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
35 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
36 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
37 void greet(const char*); |
6782 | 38 void disassemble(uintptr_t, uintptr_t); |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
39 void end_of_file(); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
40 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
41 const char* options = NULL; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
42 int raw = 0; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
43 int xml = 0; |
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 int main(int ac, char** av) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
46 int greeted = 0; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
47 int i; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
48 for (i = 1; i < ac; i++) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
49 const char* arg = av[i]; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
50 if (arg[0] == '-') { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
51 if (!strcmp(arg, "-xml")) |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
52 xml ^= 1; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
53 else if (!strcmp(arg, "-raw")) |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
54 raw ^= 1; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
55 else if (!strncmp(arg, "-options=", 9)) |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
56 options = arg+9; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
57 else |
720
67a2f5ba5582
6684007: PrintAssembly plugin not available for linux or windows
never
parents:
100
diff
changeset
|
58 { printf("Usage: %s [-xml] [name...]\n", av[0]); exit(2); } |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
59 continue; |
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 greet(arg); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
62 greeted = 1; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
63 } |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
64 if (!greeted) |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
65 greet("world"); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
66 printf("...And now for something completely different:\n"); |
6782 | 67 void *start = (void*) &main; |
68 void *end = (void*) &end_of_file; | |
69 #if defined(__ia64) || defined(__powerpc__) | |
70 /* On IA64 and PPC function pointers are pointers to function descriptors */ | |
71 start = *((void**)start); | |
72 end = *((void**)end); | |
73 #endif | |
74 disassemble(start, (end > start) ? end : start + 64); | |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
75 printf("Cheers!\n"); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
76 } |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
77 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
78 void greet(const char* whom) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
79 printf("Hello, %s!\n", whom); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
80 } |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
81 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
82 void end_of_file() { } |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
83 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
84 /* don't disassemble after this point... */ |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
85 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
86 #include "dlfcn.h" |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
87 |
6933
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
88 #define DECODE_INSTRUCTIONS_VIRTUAL_NAME "decode_instructions_virtual" |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
89 #define DECODE_INSTRUCTIONS_NAME "decode_instructions" |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
90 #define HSDIS_NAME "hsdis" |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
91 static void* decode_instructions_pv = 0; |
6933
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
92 static void* decode_instructions_sv = 0; |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
93 static const char* hsdis_path[] = { |
720
67a2f5ba5582
6684007: PrintAssembly plugin not available for linux or windows
never
parents:
100
diff
changeset
|
94 HSDIS_NAME"-"LIBARCH LIB_EXT, |
67a2f5ba5582
6684007: PrintAssembly plugin not available for linux or windows
never
parents:
100
diff
changeset
|
95 "./" HSDIS_NAME"-"LIBARCH LIB_EXT, |
67a2f5ba5582
6684007: PrintAssembly plugin not available for linux or windows
never
parents:
100
diff
changeset
|
96 #ifdef TARGET_DIR |
67a2f5ba5582
6684007: PrintAssembly plugin not available for linux or windows
never
parents:
100
diff
changeset
|
97 TARGET_DIR"/"HSDIS_NAME"-"LIBARCH LIB_EXT, |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
98 #endif |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
99 NULL |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
100 }; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
101 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
102 static const char* load_decode_instructions() { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
103 void* dllib = NULL; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
104 const char* *next_in_path = hsdis_path; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
105 while (1) { |
6933
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
106 decode_instructions_pv = dlsym(dllib, DECODE_INSTRUCTIONS_VIRTUAL_NAME); |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
107 decode_instructions_sv = dlsym(dllib, DECODE_INSTRUCTIONS_NAME); |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
108 if (decode_instructions_pv != NULL || decode_instructions_sv != NULL) |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
109 return NULL; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
110 if (dllib != NULL) |
6933
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
111 return "plugin does not defined "DECODE_INSTRUCTIONS_VIRTUAL_NAME" and "DECODE_INSTRUCTIONS_NAME; |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
112 for (dllib = NULL; dllib == NULL; ) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
113 const char* next_lib = (*next_in_path++); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
114 if (next_lib == NULL) |
720
67a2f5ba5582
6684007: PrintAssembly plugin not available for linux or windows
never
parents:
100
diff
changeset
|
115 return "cannot find plugin "HSDIS_NAME LIB_EXT; |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
116 dllib = dlopen(next_lib, RTLD_LAZY); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
117 } |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
118 } |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
119 } |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
120 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
121 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
122 static const char* lookup(void* addr) { |
6782 | 123 #if defined(__ia64) || defined(__powerpc__) |
124 /* On IA64 and PPC function pointers are pointers to function descriptors */ | |
125 #define CHECK_NAME(fn) \ | |
126 if (addr == *((void**) &fn)) return #fn; | |
127 #else | |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
128 #define CHECK_NAME(fn) \ |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
129 if (addr == (void*) &fn) return #fn; |
6782 | 130 #endif |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
131 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
132 CHECK_NAME(main); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
133 CHECK_NAME(greet); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
134 return NULL; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
135 } |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
136 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
137 /* does the event match the tag, followed by a null, space, or slash? */ |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
138 #define MATCH(event, tag) \ |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
139 (!strncmp(event, tag, sizeof(tag)-1) && \ |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
140 (!event[sizeof(tag)-1] || strchr(" /", event[sizeof(tag)-1]))) |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
141 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
142 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
143 static const char event_cookie[] = "event_cookie"; /* demo placeholder */ |
6782 | 144 static void* simple_handle_event(void* cookie, const char* event, void* arg) { |
145 if (MATCH(event, "/insn")) { | |
146 // follow each complete insn by a nice newline | |
147 printf("\n"); | |
148 } | |
149 return NULL; | |
150 } | |
151 | |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
152 static void* handle_event(void* cookie, const char* event, void* arg) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
153 #define NS_DEMO "demo:" |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
154 if (cookie != event_cookie) |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
155 printf("*** bad event cookie %p != %p\n", cookie, event_cookie); |
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 if (xml) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
158 /* We could almost do a printf(event, arg), |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
159 but for the sake of a better demo, |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
160 we dress the result up as valid XML. |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
161 */ |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
162 const char* fmt = strchr(event, ' '); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
163 int evlen = (fmt ? fmt - event : strlen(event)); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
164 if (!fmt) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
165 if (event[0] != '/') { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
166 printf("<"NS_DEMO"%.*s>", evlen, event); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
167 } else { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
168 printf("</"NS_DEMO"%.*s>", evlen-1, event+1); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
169 } |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
170 } else { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
171 if (event[0] != '/') { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
172 printf("<"NS_DEMO"%.*s", evlen, event); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
173 printf(fmt, arg); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
174 printf(">"); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
175 } else { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
176 printf("<"NS_DEMO"%.*s_done", evlen-1, event+1); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
177 printf(fmt, arg); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
178 printf("/></"NS_DEMO"%.*s>", evlen-1, event+1); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
179 } |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
180 } |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
181 } |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
182 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
183 if (MATCH(event, "insn")) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
184 const char* name = lookup(arg); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
185 if (name) printf("%s:\n", name); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
186 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
187 /* basic action for <insn>: */ |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
188 printf(" %p\t", arg); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
189 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
190 } else if (MATCH(event, "/insn")) { |
6782 | 191 // follow each complete insn by a nice newline |
192 printf("\n"); | |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
193 } else if (MATCH(event, "mach")) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
194 printf("Decoding for CPU '%s'\n", (char*) arg); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
195 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
196 } else if (MATCH(event, "addr")) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
197 /* basic action for <addr/>: */ |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
198 const char* name = lookup(arg); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
199 if (name) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
200 printf("&%s (%p)", name, arg); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
201 /* return non-null to notify hsdis not to print the addr */ |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
202 return arg; |
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 /* null return is always safe; can mean "I ignored it" */ |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
207 return NULL; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
208 } |
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 #define fprintf_callback \ |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
211 (decode_instructions_printf_callback_ftype)&fprintf |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
212 |
6782 | 213 void disassemble(uintptr_t from, uintptr_t to) { |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
214 const char* err = load_decode_instructions(); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
215 if (err != NULL) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
216 printf("%s: %s\n", err, dlerror()); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
217 exit(1); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
218 } |
6933
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
219 decode_func_vtype decode_instructions_v |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
220 = (decode_func_vtype) decode_instructions_pv; |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
221 decode_func_stype decode_instructions_s |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
222 = (decode_func_stype) decode_instructions_sv; |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
223 void* res; |
6933
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
224 if (decode_instructions_pv != NULL) { |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
225 printf("\nDecoding from %p to %p...with %s\n", from, to, DECODE_INSTRUCTIONS_VIRTUAL_NAME); |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
226 if (raw) { |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
227 res = (*decode_instructions_v)(from, to, |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
228 (unsigned char*)from, to - from, |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
229 simple_handle_event, stdout, |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
230 NULL, stdout, |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
231 options, 0); |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
232 } else { |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
233 res = (*decode_instructions_v)(from, to, |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
234 (unsigned char*)from, to - from, |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
235 handle_event, (void*) event_cookie, |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
236 fprintf_callback, stdout, |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
237 options, 0); |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
238 } |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
239 if (res != (void*)to) |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
240 printf("*** Result was %p!\n", res); |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
241 } |
6933
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
242 void* sres; |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
243 if (decode_instructions_sv != NULL) { |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
244 printf("\nDecoding from %p to %p...with old decode_instructions\n", from, to, DECODE_INSTRUCTIONS_NAME); |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
245 if (raw) { |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
246 sres = (*decode_instructions_s)(from, to, |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
247 simple_handle_event, stdout, |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
248 NULL, stdout, |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
249 options); |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
250 } else { |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
251 sres = (*decode_instructions_s)(from, to, |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
252 handle_event, (void*) event_cookie, |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
253 fprintf_callback, stdout, |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
254 options); |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
255 } |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
256 if (sres != (void *)to) |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
257 printf("*** Result of decode_instructions %p!\n", sres); |
3d701c802d01
8000489: older builds of hsdis don't work anymore after 6879063
minqi
parents:
6782
diff
changeset
|
258 } |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff
changeset
|
259 } |