1 /*
   2  * Copyright 2008 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any 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 extern
  51 #ifdef DLL_EXPORT
  52   DLL_EXPORT
  53 #endif
  54 void* decode_instructions_virtual(uintptr_t start_va, uintptr_t end_va,
  55                                   unsigned char* buffer, uintptr_t length,
  56                                   void* (*event_callback)(void*, const char*, void*),
  57                                   void* event_stream,
  58                                   int (*printf_callback)(void*, const char*, ...),
  59                                   void* printf_stream,
  60                                   const char* options);
  61 
  62 /* convenience typedefs */
  63 
  64 typedef void* (*decode_instructions_event_callback_ftype)  (void*, const char*, void*);
  65 typedef int   (*decode_instructions_printf_callback_ftype) (void*, const char*, ...);
  66 typedef void* (*decode_instructions_ftype) (uintptr_t start_va, uintptr_t end_va,
  67                                             unsigned char* buffer, uintptr_t length,
  68                                             decode_instructions_event_callback_ftype event_callback,
  69                                             void* event_stream,
  70                                             decode_instructions_printf_callback_ftype printf_callback,
  71                                             void* printf_stream,
  72                                             const char* options);