njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- DebugInfo. pub_tool_debuginfo.h ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
sewardj | 4d474d0 | 2008-02-11 11:34:59 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2008 Julian Seward |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 11 | jseward@acm.org |
| 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __PUB_TOOL_DEBUGINFO_H |
| 32 | #define __PUB_TOOL_DEBUGINFO_H |
| 33 | |
| 34 | /*====================================================================*/ |
| 35 | /*=== Obtaining debug information ===*/ |
| 36 | /*====================================================================*/ |
| 37 | |
| 38 | /* Get the file/function/line number of the instruction at address |
| 39 | 'a'. For these four, if debug info for the address is found, it |
| 40 | copies the info into the buffer/UInt and returns True. If not, it |
| 41 | returns False and nothing is copied. VG_(get_fnname) always |
| 42 | demangles C++ function names. VG_(get_fnname_w_offset) is the |
| 43 | same, except it appends "+N" to symbol names to indicate offsets. */ |
| 44 | extern Bool VG_(get_filename) ( Addr a, Char* filename, Int n_filename ); |
| 45 | extern Bool VG_(get_fnname) ( Addr a, Char* fnname, Int n_fnname ); |
| 46 | extern Bool VG_(get_linenum) ( Addr a, UInt* linenum ); |
| 47 | extern Bool VG_(get_fnname_w_offset) |
| 48 | ( Addr a, Char* fnname, Int n_fnname ); |
| 49 | |
sewardj | 7cee6f9 | 2005-06-13 17:39:06 +0000 | [diff] [blame] | 50 | /* This one is the most general. It gives filename, line number and |
| 51 | optionally directory name. filename and linenum may not be NULL. |
| 52 | dirname may be NULL, meaning that the caller does not want |
| 53 | directory name info, in which case dirname_available must also be |
| 54 | NULL. If dirname is non-null, directory info is written to it, if |
| 55 | it is available; if not available, '\0' is written to the first |
| 56 | byte. In either case *dirname_available is set to indicate whether |
| 57 | or not directory information was available. |
| 58 | |
| 59 | Returned value indicates whether any filename/line info could be |
| 60 | found. */ |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 61 | extern Bool VG_(get_filename_linenum) |
sewardj | 7cee6f9 | 2005-06-13 17:39:06 +0000 | [diff] [blame] | 62 | ( Addr a, |
| 63 | /*OUT*/Char* filename, Int n_filename, |
| 64 | /*OUT*/Char* dirname, Int n_dirname, |
| 65 | /*OUT*/Bool* dirname_available, |
| 66 | /*OUT*/UInt* linenum ); |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 67 | |
| 68 | /* Succeeds only if we find from debug info that 'a' is the address of the |
| 69 | first instruction in a function -- as opposed to VG_(get_fnname) which |
| 70 | succeeds if we find from debug info that 'a' is the address of any |
| 71 | instruction in a function. Use this to instrument the start of |
| 72 | a particular function. Nb: if an executable/shared object is stripped |
| 73 | of its symbols, this function will not be able to recognise function |
| 74 | entry points within it. */ |
| 75 | extern Bool VG_(get_fnname_if_entry) ( Addr a, Char* fnname, Int n_fnname ); |
| 76 | |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 77 | /* Looks up data_addr in the collection of data symbols, and if found |
| 78 | puts its name (or as much as will fit) into dname[0 .. n_dname-1], |
| 79 | which is guaranteed to be zero terminated. Also data_addr's offset |
| 80 | from the symbol start is put into *offset. */ |
| 81 | extern Bool VG_(get_datasym_and_offset)( Addr data_addr, |
| 82 | /*OUT*/Char* dname, Int n_dname, |
| 83 | /*OUT*/OffT* offset ); |
| 84 | |
| 85 | /* Try to form some description of data_addr by looking at the DWARF3 |
| 86 | debug info we have. This considers all global variables, and all |
| 87 | frames in the stacks of all threads. Result (or as much as will |
| 88 | fit) is put into into dname{1,2}[0 .. n_dname-1] and is guaranteed |
| 89 | to be zero terminated. */ |
| 90 | extern Bool VG_(get_data_description)( /*OUT*/Char* dname1, |
| 91 | /*OUT*/Char* dname2, |
| 92 | Int n_dname, |
| 93 | Addr data_addr ); |
| 94 | |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 95 | /* Succeeds if the address is within a shared object or the main executable. |
| 96 | It doesn't matter if debug info is present or not. */ |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 97 | extern Bool VG_(get_objname) ( Addr a, Char* objname, Int n_objname ); |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 98 | |
| 99 | /* Puts into 'buf' info about the code address %eip: the address, function |
| 100 | name (if known) and filename/line number (if known), like this: |
| 101 | |
| 102 | 0x4001BF05: realloc (vg_replace_malloc.c:339) |
| 103 | |
| 104 | 'n_buf' gives length of 'buf'. Returns 'buf'. |
| 105 | */ |
| 106 | extern Char* VG_(describe_IP)(Addr eip, Char* buf, Int n_buf); |
| 107 | |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 108 | |
| 109 | /* Get an XArray of StackBlock which describe the stack (auto) blocks |
| 110 | for this ip. The caller is expected to free the XArray at some |
| 111 | point. If 'arrays_only' is True, only array-typed blocks are |
| 112 | returned; otherwise blocks of all types are returned. */ |
| 113 | |
| 114 | typedef |
| 115 | struct { |
| 116 | OffT base; /* offset from sp or fp */ |
| 117 | SizeT szB; /* size in bytes */ |
| 118 | Bool spRel; /* True => sp-rel, False => fp-rel */ |
| 119 | Bool isVec; /* does block have an array type, or not? */ |
| 120 | HChar name[16]; /* first 15 chars of name (asciiz) */ |
| 121 | } |
| 122 | StackBlock; |
| 123 | |
| 124 | extern void* /* really, XArray* of StackBlock */ |
| 125 | VG_(di_get_stack_blocks_at_ip)( Addr ip, Bool arrays_only ); |
| 126 | |
| 127 | |
| 128 | /* Get an array of GlobalBlock which describe the global blocks owned |
| 129 | by the shared object characterised by the given di_handle. Asserts |
| 130 | if the handle is invalid. The caller is responsible for freeing |
| 131 | the array at some point. If 'arrays_only' is True, only |
| 132 | array-typed blocks are returned; otherwise blocks of all types are |
| 133 | returned. */ |
| 134 | |
| 135 | typedef |
| 136 | struct { |
| 137 | Addr addr; |
| 138 | SizeT szB; |
| 139 | Bool isVec; /* does block have an array type, or not? */ |
| 140 | HChar name[16]; /* first 15 chars of name (asciiz) */ |
| 141 | HChar soname[16]; /* first 15 chars of name (asciiz) */ |
| 142 | } |
| 143 | GlobalBlock; |
| 144 | |
| 145 | extern void* /* really, XArray* of GlobalBlock */ |
| 146 | VG_(di_get_global_blocks_from_dihandle) ( ULong di_handle, |
| 147 | Bool arrays_only ); |
| 148 | |
| 149 | |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 150 | /*====================================================================*/ |
| 151 | /*=== Obtaining segment information ===*/ |
| 152 | /*====================================================================*/ |
| 153 | |
| 154 | /* A way to get information about what segments are mapped */ |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 155 | typedef struct _DebugInfo DebugInfo; |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 156 | |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 157 | /* Returns NULL if the DebugInfo isn't found. It doesn't matter if |
| 158 | debug info is present or not. */ |
| 159 | extern DebugInfo* VG_(find_seginfo) ( Addr a ); |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 160 | |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 161 | /* Fish bits out of DebugInfos. */ |
| 162 | extern Addr VG_(seginfo_get_text_avma)( const DebugInfo *di ); |
| 163 | extern SizeT VG_(seginfo_get_text_size)( const DebugInfo *di ); |
bart | 092b626 | 2008-05-25 16:37:22 +0000 | [diff] [blame] | 164 | extern Addr VG_(seginfo_get_plt_avma) ( const DebugInfo *di ); |
| 165 | extern SizeT VG_(seginfo_get_plt_size) ( const DebugInfo *di ); |
| 166 | extern Addr VG_(seginfo_get_gotplt_avma)( const DebugInfo *di ); |
| 167 | extern SizeT VG_(seginfo_get_gotplt_size)( const DebugInfo *di ); |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 168 | extern const UChar* VG_(seginfo_soname) ( const DebugInfo *di ); |
| 169 | extern const UChar* VG_(seginfo_filename) ( const DebugInfo *di ); |
| 170 | extern ULong VG_(seginfo_get_text_bias)( const DebugInfo *di ); |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 171 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 172 | /* Function for traversing the seginfo list. When called with NULL it |
| 173 | returns the first element; otherwise it returns the given element's |
| 174 | successor. */ |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 175 | extern const DebugInfo* VG_(next_seginfo) ( const DebugInfo *di ); |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 176 | |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 177 | /* Functions for traversing all the symbols in a DebugInfo. _howmany |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 178 | tells how many there are. _getidx retrieves the n'th, for n in 0 |
| 179 | .. _howmany-1. You may not modify the function name thereby |
| 180 | acquired; if you want to do so, first strdup it. */ |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 181 | extern Int VG_(seginfo_syms_howmany) ( const DebugInfo *di ); |
| 182 | extern void VG_(seginfo_syms_getidx) ( const DebugInfo *di, |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 183 | Int idx, |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 184 | /*OUT*/Addr* avma, |
sewardj | 811469c | 2006-10-17 01:36:37 +0000 | [diff] [blame] | 185 | /*OUT*/Addr* tocptr, |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 186 | /*OUT*/UInt* size, |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 187 | /*OUT*/HChar** name, |
| 188 | /*OUT*/Bool* isText ); |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 189 | |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 190 | /* A simple enumeration to describe the 'kind' of various kinds of |
| 191 | segments that arise from the mapping of object files. */ |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 192 | typedef |
| 193 | enum { |
| 194 | Vg_SectUnknown, |
| 195 | Vg_SectText, |
| 196 | Vg_SectData, |
| 197 | Vg_SectBSS, |
| 198 | Vg_SectGOT, |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 199 | Vg_SectPLT, |
bart | 092b626 | 2008-05-25 16:37:22 +0000 | [diff] [blame] | 200 | Vg_SectGOTPLT, |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 201 | Vg_SectOPD |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 202 | } |
| 203 | VgSectKind; |
| 204 | |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 205 | /* Convert a VgSectKind to a string, which must be copied if you want |
| 206 | to change it. */ |
| 207 | extern |
| 208 | const HChar* VG_(pp_SectKind)( VgSectKind kind ); |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 209 | |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 210 | /* Given an address 'a', make a guess of which section of which object |
| 211 | it comes from. If name is non-NULL, then the last n_name-1 |
| 212 | characters of the object's name is put in name[0 .. n_name-2], and |
| 213 | name[n_name-1] is set to zero (guaranteed zero terminated). */ |
| 214 | extern |
| 215 | VgSectKind VG_(seginfo_sect_kind)( /*OUT*/UChar* name, SizeT n_name, |
| 216 | Addr a); |
sewardj | bbec772 | 2007-11-25 14:08:53 +0000 | [diff] [blame] | 217 | |
| 218 | |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 219 | #endif // __PUB_TOOL_DEBUGINFO_H |
| 220 | |
| 221 | /*--------------------------------------------------------------------*/ |
| 222 | /*--- end ---*/ |
| 223 | /*--------------------------------------------------------------------*/ |