1 /*
2  * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  *
23  */
24 
25 /* decode_instructions -- dump a range of addresses as native instructions
26    This implements the protocol required by the HotSpot PrintAssembly option.
27 
28    The start_va, end_va is the virtual address the region of memory to
29    disasemble and buffer contains the instructions to decode,
30    Disassembling instructions in the current address space is done by
31    having start_va == buffer.
32 
33    The option string, if not empty, is interpreted by the disassembler implementation.
34 
35    The printf callback is 'fprintf' or any other workalike.
36    It is called as (*printf_callback)(printf_stream, "some format...", some, format, args).
37 
38    The event callback receives an event tag (a string) and an argument (a void*).
39    It is called as (*event_callback)(event_stream, "tag", arg).
40 
41    Events:
42      <insn pc='%p'>             begin an instruction, at a given location
43      </insn pc='%d'>            end an instruction, at a given location
44      <addr value='%p'/>         emit the symbolic value of an address
45 
46    A tag format is one of three basic forms: "tag", "/tag", "tag/",
47    where tag is a simple identifier, signifying (as in XML) a element start,
48    element end, and standalone element.  (To render as XML, add angle brackets.)
49 */
50 #ifndef SHARED_TOOLS_HSDIS_H
51 #define SHARED_TOOLS_HSDIS_H
52 
53 extern
54 #ifdef DLL_EXPORT
55   DLL_EXPORT
56 #endif
57 void* decode_instructions_virtual(uintptr_t start_va, uintptr_t end_va,
58                                   unsigned char* buffer, uintptr_t length,
59                                   void* (*event_callback)(void*, const char*, void*),
60                                   void* event_stream,
61                                   int (*printf_callback)(void*, const char*, ...),
62                                   void* printf_stream,
63                                   const char* options,
64                                   int newline /* bool value for nice new line */);
65 
66 /* This is the compatability interface for older versions of hotspot */
67 extern
68 #ifdef DLL_ENTRY
69   DLL_ENTRY
70 #endif
71 void* decode_instructions(void* start_pv, void* end_pv,
72                     void* (*event_callback)(void*, const char*, void*),
73                     void* event_stream,
74                     int   (*printf_callback)(void*, const char*, ...),
75                     void* printf_stream,
76                     const char* options);
77 
78 /* convenience typedefs */
79 
80 typedef void* (*decode_instructions_event_callback_ftype)  (void*, const char*, void*);
81 typedef int   (*decode_instructions_printf_callback_ftype) (void*, const char*, ...);
82 typedef void* (*decode_func_vtype) (uintptr_t start_va, uintptr_t end_va,
83                                     unsigned char* buffer, uintptr_t length,
84                                     decode_instructions_event_callback_ftype event_callback,
85                                     void* event_stream,
86                                     decode_instructions_printf_callback_ftype printf_callback,
87                                     void* printf_stream,
88                                     const char* options,
89                                     int newline);
90 typedef void* (*decode_func_stype) (void* start_pv, void* end_pv,
91                                     decode_instructions_event_callback_ftype event_callback,
92                                     void* event_stream,
93                                     decode_instructions_printf_callback_ftype printf_callback,
94                                     void* printf_stream,
95                                     const char* options);
96 #endif /* SHARED_TOOLS_HSDIS_H */
97