njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Debug info. pub_core_debuginfo.h ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
sewardj | b3a1e4b | 2015-08-21 11:32:26 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2015 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_CORE_DEBUGINFO_H |
| 32 | #define __PUB_CORE_DEBUGINFO_H |
| 33 | |
| 34 | //-------------------------------------------------------------------- |
| 35 | // PURPOSE: This module deals with reading debug info and symbol tables |
| 36 | // to get file and function names, line numbers, variable types, and |
| 37 | // to help stack unwinding. |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 38 | //-------------------------------------------------------------------- |
| 39 | |
| 40 | #include "pub_tool_debuginfo.h" |
| 41 | |
sewardj | f98e1c0 | 2008-10-25 16:22:41 +0000 | [diff] [blame] | 42 | /* Initialise the entire module. Must be called first of all. */ |
| 43 | extern void VG_(di_initialise) ( void ); |
| 44 | |
sewardj | 811469c | 2006-10-17 01:36:37 +0000 | [diff] [blame] | 45 | /* LINUX: Notify the debuginfo system about a new mapping, or the |
| 46 | disappearance of such, or a permissions change on an existing |
| 47 | mapping. This is the way new debug information gets loaded. If |
| 48 | allow_SkFileV is True, it will try load debug info if the mapping |
| 49 | at 'a' belongs to Valgrind; whereas normally (False) it will not do |
| 50 | that. This allows us to carefully control when the thing will read |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 51 | symbols from the Valgrind executable itself. |
| 52 | |
| 53 | If a call to VG_(di_notify_mmap) causes debug info to be read, then |
| 54 | the returned ULong is an abstract handle which can later be used to |
| 55 | refer to the debuginfo read as a result of this specific mapping, |
| 56 | in later queries to m_debuginfo. In this case the handle value |
| 57 | will be one or above. If the returned value is zero, no debug info |
sewardj | 5f2dcad | 2011-10-24 08:53:03 +0000 | [diff] [blame] | 58 | was read. |
| 59 | |
| 60 | For VG_(di_notify_mmap), if use_fd is not -1, that is used instead |
| 61 | of the filename; this avoids perturbing fcntl locks, which are |
| 62 | released by simply re-opening and closing the same file (even via |
| 63 | different fd!). |
| 64 | */ |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 65 | #if defined(VGO_linux) || defined(VGO_darwin) || defined(VGO_solaris) |
sewardj | 5f2dcad | 2011-10-24 08:53:03 +0000 | [diff] [blame] | 66 | extern ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV, Int use_fd ); |
sewardj | f72cced | 2005-11-08 00:45:47 +0000 | [diff] [blame] | 67 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 68 | extern void VG_(di_notify_munmap)( Addr a, SizeT len ); |
sewardj | f72cced | 2005-11-08 00:45:47 +0000 | [diff] [blame] | 69 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 70 | extern void VG_(di_notify_mprotect)( Addr a, SizeT len, UInt prot ); |
sewardj | c8259b8 | 2009-04-22 22:42:10 +0000 | [diff] [blame] | 71 | |
| 72 | /* this should really return ULong, as per VG_(di_notify_mmap). */ |
| 73 | extern void VG_(di_notify_pdb_debuginfo)( Int fd, Addr avma, |
| 74 | SizeT total_size, |
sewardj | 54c45db | 2012-07-13 12:58:55 +0000 | [diff] [blame] | 75 | PtrdiffT bias ); |
sewardj | 731f9cf | 2011-09-21 08:43:08 +0000 | [diff] [blame] | 76 | |
| 77 | /* this should also really return ULong */ |
| 78 | extern void VG_(di_notify_vm_protect)( Addr a, SizeT len, UInt prot ); |
sewardj | 811469c | 2006-10-17 01:36:37 +0000 | [diff] [blame] | 79 | #endif |
| 80 | |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 81 | extern void VG_(di_discard_ALL_debuginfo)( void ); |
| 82 | |
njn | 6b7611b | 2009-02-11 06:06:10 +0000 | [diff] [blame] | 83 | /* Like VG_(get_fnname), but it does not do C++ demangling nor Z-demangling |
| 84 | * nor below-main renaming. |
| 85 | * It should not be used for any names that will be shown to users. |
| 86 | * It should only be used in cases where the names of interest will have |
| 87 | * particular (ie. non-mangled) forms, or the mangled form is acceptable. */ |
| 88 | extern |
florian | 46cc045 | 2014-10-25 19:20:38 +0000 | [diff] [blame] | 89 | Bool VG_(get_fnname_raw) ( Addr a, const HChar** buf ); |
njn | 6b7611b | 2009-02-11 06:06:10 +0000 | [diff] [blame] | 90 | |
| 91 | /* Like VG_(get_fnname), but without C++ demangling. (But it does |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 92 | Z-demangling and below-main renaming.) |
| 93 | iipc argument: same usage as in VG_(describe_IP) in pub_tool_debuginfo.h. */ |
njn | 6b7611b | 2009-02-11 06:06:10 +0000 | [diff] [blame] | 94 | extern |
florian | 46cc045 | 2014-10-25 19:20:38 +0000 | [diff] [blame] | 95 | Bool VG_(get_fnname_no_cxx_demangle) ( Addr a, const HChar** buf, |
| 96 | const InlIPCursor* iipc ); |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 97 | |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 98 | /* mips-linux only: find the offset of current address. This is needed for |
| 99 | stack unwinding for MIPS. |
| 100 | */ |
| 101 | extern |
| 102 | Bool VG_(get_inst_offset_in_function)( Addr a, /*OUT*/PtrdiffT* offset ); |
| 103 | |
sewardj | 3026f71 | 2010-01-01 18:46:41 +0000 | [diff] [blame] | 104 | |
| 105 | /* Use DWARF2/3 CFA information to do one step of stack unwinding. |
| 106 | D3UnwindRegs holds the current register values, and is |
| 107 | arch-specific. Note that the x86 and amd64 definitions are shared |
| 108 | and so the regs are named 'xip' etc rather than 'eip' and 'rip'. */ |
| 109 | #if defined(VGA_amd64) || defined(VGA_x86) |
| 110 | typedef |
| 111 | struct { Addr xip; Addr xsp; Addr xbp; } |
| 112 | D3UnwindRegs; |
| 113 | #elif defined(VGA_arm) |
| 114 | typedef |
sewardj | fa5ce56 | 2010-09-23 22:05:59 +0000 | [diff] [blame] | 115 | struct { Addr r15; Addr r14; Addr r13; Addr r12; Addr r11; Addr r7; } |
sewardj | 3026f71 | 2010-01-01 18:46:41 +0000 | [diff] [blame] | 116 | D3UnwindRegs; |
sewardj | f0c1250 | 2014-01-12 12:54:00 +0000 | [diff] [blame] | 117 | #elif defined(VGA_arm64) |
| 118 | typedef |
sewardj | 821283b | 2014-01-13 00:21:09 +0000 | [diff] [blame] | 119 | struct { Addr pc; Addr sp; Addr x30; Addr x29; } /* PC, SP, LR, FP */ |
sewardj | f0c1250 | 2014-01-12 12:54:00 +0000 | [diff] [blame] | 120 | D3UnwindRegs; |
carll | cae0cc2 | 2014-08-07 23:17:29 +0000 | [diff] [blame] | 121 | #elif defined(VGA_ppc32) || defined(VGA_ppc64be) || defined(VGA_ppc64le) |
sewardj | 3026f71 | 2010-01-01 18:46:41 +0000 | [diff] [blame] | 122 | typedef |
sewardj | f5f1e12 | 2010-01-02 13:24:58 +0000 | [diff] [blame] | 123 | UChar /* should be void, but gcc complains at use points */ |
sewardj | 3026f71 | 2010-01-01 18:46:41 +0000 | [diff] [blame] | 124 | D3UnwindRegs; |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 125 | #elif defined(VGA_s390x) |
| 126 | typedef |
| 127 | struct { Addr ia; Addr sp; Addr fp; Addr lr;} |
| 128 | D3UnwindRegs; |
petarj | 4df0bfc | 2013-02-27 23:17:33 +0000 | [diff] [blame] | 129 | #elif defined(VGA_mips32) || defined(VGA_mips64) |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 130 | typedef |
| 131 | struct { Addr pc; Addr sp; Addr fp; Addr ra; } |
| 132 | D3UnwindRegs; |
sewardj | 112711a | 2015-04-10 12:30:09 +0000 | [diff] [blame] | 133 | #elif defined(VGA_tilegx) |
| 134 | typedef |
| 135 | struct { Addr pc; Addr sp; Addr fp; Addr lr; } |
| 136 | D3UnwindRegs; |
sewardj | 3026f71 | 2010-01-01 18:46:41 +0000 | [diff] [blame] | 137 | #else |
| 138 | # error "Unsupported arch" |
| 139 | #endif |
| 140 | |
| 141 | extern Bool VG_(use_CF_info) ( /*MOD*/D3UnwindRegs* uregs, |
sewardj | eadcd86 | 2006-04-04 15:12:44 +0000 | [diff] [blame] | 142 | Addr min_accessible, |
| 143 | Addr max_accessible ); |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 144 | |
philippe | f7bbd79 | 2015-05-26 21:26:39 +0000 | [diff] [blame] | 145 | /* returns the "generation" of the debug info. |
philippe | 20ede3a | 2013-01-30 23:18:11 +0000 | [diff] [blame] | 146 | Each time some debuginfo is changed (e.g. loaded or unloaded), |
philippe | f7bbd79 | 2015-05-26 21:26:39 +0000 | [diff] [blame] | 147 | the VG_(debuginfo_generation)() value returned will be increased. |
| 148 | This can be used to flush cached information derived from debug |
| 149 | info (e.g. CFI info or FPO info or ...). */ |
| 150 | extern UInt VG_(debuginfo_generation) (void); |
philippe | 20ede3a | 2013-01-30 23:18:11 +0000 | [diff] [blame] | 151 | |
| 152 | |
sewardj | 3026f71 | 2010-01-01 18:46:41 +0000 | [diff] [blame] | 153 | |
philippe | f7bbd79 | 2015-05-26 21:26:39 +0000 | [diff] [blame] | 154 | /* True if some FPO information is loaded. |
| 155 | It is useless to call VG_(use_FPO_info) if this returns False. |
| 156 | Note that the return value should preferrably be cached in |
| 157 | the stack unwind code, and re-queried when the debug info generation |
| 158 | changes. */ |
| 159 | extern Bool VG_(FPO_info_present)(void); |
| 160 | |
sewardj | c8259b8 | 2009-04-22 22:42:10 +0000 | [diff] [blame] | 161 | /* Use MSVC FPO data to do one step of stack unwinding. */ |
| 162 | extern Bool VG_(use_FPO_info) ( /*MOD*/Addr* ipP, |
| 163 | /*MOD*/Addr* spP, |
| 164 | /*MOD*/Addr* fpP, |
| 165 | Addr min_accessible, |
| 166 | Addr max_accessible ); |
| 167 | |
philippe | 97bfa19 | 2015-06-02 22:09:42 +0000 | [diff] [blame] | 168 | /* Print the unwind info (if there is some) for the given address |
| 169 | range [from,to]. */ |
| 170 | extern void VG_(ppUnwindInfo) (Addr from, Addr to); |
| 171 | |
philippe | 4cace66 | 2014-08-13 21:25:45 +0000 | [diff] [blame] | 172 | /* AVMAs for a symbol. Usually only the lowest address of the entity. |
| 173 | On ppc64 platforms, also contains tocptr and local_ep. |
| 174 | These fields should only be accessed using the macros |
| 175 | GET_TOCPTR_AVMA/SET_TOCPTR_AVMA/GET_LOCAL_EP_AVMA/SET_LOCAL_EP_AVMA. */ |
| 176 | typedef |
| 177 | struct { |
| 178 | Addr main; /* lowest address of entity */ |
| 179 | # if defined(VGA_ppc64be) || defined(VGA_ppc64le) |
| 180 | Addr tocptr; /* ppc64be/le-linux only: value that R2 should have */ |
| 181 | # endif |
| 182 | # if defined(VGA_ppc64le) |
| 183 | Addr local_ep; /* address for local entry point, ppc64le only */ |
| 184 | # endif |
| 185 | } |
| 186 | SymAVMAs; |
| 187 | |
| 188 | #if defined(VGA_ppc64be) || defined(VGA_ppc64le) |
| 189 | # define GET_TOCPTR_AVMA(_sym_avmas) (_sym_avmas).tocptr |
| 190 | # define SET_TOCPTR_AVMA(_sym_avmas, _val) (_sym_avmas).tocptr = (_val) |
| 191 | #else |
| 192 | # define GET_TOCPTR_AVMA(_sym_avmas) ((Addr)0) |
| 193 | # define SET_TOCPTR_AVMA(_sym_avmas, _val) /* */ |
| 194 | #endif |
| 195 | |
| 196 | #if defined(VGA_ppc64le) |
| 197 | # define GET_LOCAL_EP_AVMA(_sym_avmas) (_sym_avmas).local_ep |
| 198 | # define SET_LOCAL_EP_AVMA(_sym_avmas, _val) (_sym_avmas).local_ep = (_val) |
| 199 | #else |
| 200 | # define GET_LOCAL_EP_AVMA(_sym_avmas) ((Addr)0) |
| 201 | # define SET_LOCAL_EP_AVMA(_sym_avmas, _val) /* */ |
| 202 | #endif |
| 203 | |
| 204 | /* Functions for traversing all the symbols in a DebugInfo. _howmany |
| 205 | tells how many symbol table entries there are. _getidx retrieves |
| 206 | the n'th entry, for n in 0 .. _howmany-1. You may not modify the |
| 207 | function names thereby acquired; if you want to do so, first strdup |
| 208 | them. The primary name is returned in *pri_name, and *sec_names is |
| 209 | set either to NULL or to a NULL terminated vector containing |
| 210 | pointers to the secondary names. */ |
| 211 | Int VG_(DebugInfo_syms_howmany) ( const DebugInfo *di ); |
| 212 | void VG_(DebugInfo_syms_getidx) ( const DebugInfo *di, |
| 213 | Int idx, |
| 214 | /*OUT*/SymAVMAs* ad, |
| 215 | /*OUT*/UInt* size, |
florian | 1ef70c6 | 2014-10-22 17:42:37 +0000 | [diff] [blame] | 216 | /*OUT*/const HChar** pri_name, |
| 217 | /*OUT*/const HChar*** sec_names, |
philippe | 4cace66 | 2014-08-13 21:25:45 +0000 | [diff] [blame] | 218 | /*OUT*/Bool* isText, |
| 219 | /*OUT*/Bool* isIFunc ); |
sewardj | 40c186c | 2006-01-17 01:54:16 +0000 | [diff] [blame] | 220 | /* ppc64-linux only: find the TOC pointer (R2 value) that should be in |
| 221 | force at the entry point address of the function containing |
| 222 | guest_code_addr. Returns 0 if not known. */ |
| 223 | extern Addr VG_(get_tocptr) ( Addr guest_code_addr ); |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 224 | |
philippe | 4cace66 | 2014-08-13 21:25:45 +0000 | [diff] [blame] | 225 | /* Map a function name to its SymAVMAs. Is done by |
sewardj | 811469c | 2006-10-17 01:36:37 +0000 | [diff] [blame] | 226 | sequential search of all symbol tables, so is very slow. To |
| 227 | mitigate the worst performance effects, you may specify a soname |
| 228 | pattern, and only objects matching that pattern are searched. |
| 229 | Therefore specify "*" to search all the objects. On TOC-afflicted |
| 230 | platforms, a symbol is deemed to be found only if it has a nonzero |
| 231 | TOC pointer. */ |
| 232 | extern |
florian | 518850b | 2014-10-22 22:25:30 +0000 | [diff] [blame] | 233 | Bool VG_(lookup_symbol_SLOW)(const HChar* sopatt, const HChar* name, |
| 234 | SymAVMAs* avmas); |
sewardj | 811469c | 2006-10-17 01:36:37 +0000 | [diff] [blame] | 235 | |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 236 | #endif // __PUB_CORE_DEBUGINFO_H |
| 237 | |
| 238 | /*--------------------------------------------------------------------*/ |
| 239 | /*--- end ---*/ |
| 240 | /*--------------------------------------------------------------------*/ |