blob: 2f734c803ec81e2f3ad8385ef8dec3da4d6dd4d9 [file] [log] [blame]
njnea27e462005-05-31 02:38:09 +00001
2/*--------------------------------------------------------------------*/
3/*--- DebugInfo. pub_tool_debuginfo.h ---*/
4/*--------------------------------------------------------------------*/
5
6/*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
9
sewardj03f8d3f2012-08-05 15:46:46 +000010 Copyright (C) 2000-2012 Julian Seward
njnea27e462005-05-31 02:38:09 +000011 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. */
florian1636d332012-11-15 04:27:04 +000044extern Bool VG_(get_filename) ( Addr a, HChar* filename, Int n_filename );
45extern Bool VG_(get_fnname) ( Addr a, HChar* fnname, Int n_fnname );
njnea27e462005-05-31 02:38:09 +000046extern Bool VG_(get_linenum) ( Addr a, UInt* linenum );
47extern Bool VG_(get_fnname_w_offset)
florian1636d332012-11-15 04:27:04 +000048 ( Addr a, HChar* fnname, Int n_fnname );
njnea27e462005-05-31 02:38:09 +000049
sewardj7cee6f92005-06-13 17:39:06 +000050/* 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. */
njnea27e462005-05-31 02:38:09 +000061extern Bool VG_(get_filename_linenum)
sewardj7cee6f92005-06-13 17:39:06 +000062 ( Addr a,
florian1636d332012-11-15 04:27:04 +000063 /*OUT*/HChar* filename, Int n_filename,
64 /*OUT*/HChar* dirname, Int n_dirname,
sewardj7cee6f92005-06-13 17:39:06 +000065 /*OUT*/Bool* dirname_available,
66 /*OUT*/UInt* linenum );
njnea27e462005-05-31 02:38:09 +000067
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. */
florian1636d332012-11-15 04:27:04 +000075extern Bool VG_(get_fnname_if_entry) ( Addr a, HChar* fnname, Int n_fnname );
njnea27e462005-05-31 02:38:09 +000076
njn68824432009-02-10 06:48:00 +000077typedef
78 enum {
79 Vg_FnNameNormal, // A normal function.
80 Vg_FnNameMain, // "main"
81 Vg_FnNameBelowMain // Something below "main", eg. __libc_start_main.
82 } Vg_FnNameKind; // Such names are often filtered.
83
84/* Indicates what kind of fnname it is. */
florian1636d332012-11-15 04:27:04 +000085extern Vg_FnNameKind VG_(get_fnname_kind) ( HChar* name );
njn68824432009-02-10 06:48:00 +000086
87/* Like VG_(get_fnname_kind), but takes a code address. */
88extern Vg_FnNameKind VG_(get_fnname_kind_from_IP) ( Addr ip );
89
sewardjb8b79ad2008-03-03 01:35:41 +000090/* Looks up data_addr in the collection of data symbols, and if found
91 puts its name (or as much as will fit) into dname[0 .. n_dname-1],
92 which is guaranteed to be zero terminated. Also data_addr's offset
93 from the symbol start is put into *offset. */
94extern Bool VG_(get_datasym_and_offset)( Addr data_addr,
florian1636d332012-11-15 04:27:04 +000095 /*OUT*/HChar* dname, Int n_dname,
njnc4431bf2009-01-15 21:29:24 +000096 /*OUT*/PtrdiffT* offset );
sewardjb8b79ad2008-03-03 01:35:41 +000097
sewardj5d9dc752009-07-15 14:52:18 +000098/* Try to form some description of DATA_ADDR by looking at the DWARF3
philippe25963372013-01-16 22:07:02 +000099 debug info we have. This considers all global variables, and 8
sewardj5d9dc752009-07-15 14:52:18 +0000100 frames in the stacks of all threads. Result is written at the ends
101 of DNAME{1,2}V, which are XArray*s of HChar, that have been
102 initialised by the caller, and True is returned. If no description
103 is created, False is returned. Regardless of the return value,
104 DNAME{1,2}V are guaranteed to be zero terminated after the call.
105
106 Note that after the call, DNAME{1,2} may have more than one
107 trailing zero, so callers should establish the useful text length
108 using VG_(strlen) on the contents, rather than VG_(sizeXA) on the
109 XArray itself.
110*/
111Bool VG_(get_data_description)(
112 /*MOD*/ void* /* really, XArray* of HChar */ dname1v,
113 /*MOD*/ void* /* really, XArray* of HChar */ dname2v,
114 Addr data_addr
115 );
sewardjb8b79ad2008-03-03 01:35:41 +0000116
njnea27e462005-05-31 02:38:09 +0000117/* Succeeds if the address is within a shared object or the main executable.
118 It doesn't matter if debug info is present or not. */
florian1636d332012-11-15 04:27:04 +0000119extern Bool VG_(get_objname) ( Addr a, HChar* objname, Int n_objname );
njnea27e462005-05-31 02:38:09 +0000120
121/* Puts into 'buf' info about the code address %eip: the address, function
122 name (if known) and filename/line number (if known), like this:
123
124 0x4001BF05: realloc (vg_replace_malloc.c:339)
125
126 'n_buf' gives length of 'buf'. Returns 'buf'.
127*/
florian1636d332012-11-15 04:27:04 +0000128extern HChar* VG_(describe_IP)(Addr eip, HChar* buf, Int n_buf);
njnea27e462005-05-31 02:38:09 +0000129
sewardj9c606bd2008-09-18 18:12:50 +0000130
131/* Get an XArray of StackBlock which describe the stack (auto) blocks
132 for this ip. The caller is expected to free the XArray at some
133 point. If 'arrays_only' is True, only array-typed blocks are
134 returned; otherwise blocks of all types are returned. */
135
136typedef
137 struct {
njnc4431bf2009-01-15 21:29:24 +0000138 PtrdiffT base; /* offset from sp or fp */
139 SizeT szB; /* size in bytes */
140 Bool spRel; /* True => sp-rel, False => fp-rel */
141 Bool isVec; /* does block have an array type, or not? */
142 HChar name[16]; /* first 15 chars of name (asciiz) */
sewardj9c606bd2008-09-18 18:12:50 +0000143 }
144 StackBlock;
145
146extern void* /* really, XArray* of StackBlock */
147 VG_(di_get_stack_blocks_at_ip)( Addr ip, Bool arrays_only );
148
149
150/* Get an array of GlobalBlock which describe the global blocks owned
151 by the shared object characterised by the given di_handle. Asserts
152 if the handle is invalid. The caller is responsible for freeing
153 the array at some point. If 'arrays_only' is True, only
154 array-typed blocks are returned; otherwise blocks of all types are
155 returned. */
156
157typedef
158 struct {
159 Addr addr;
160 SizeT szB;
161 Bool isVec; /* does block have an array type, or not? */
162 HChar name[16]; /* first 15 chars of name (asciiz) */
163 HChar soname[16]; /* first 15 chars of name (asciiz) */
164 }
165 GlobalBlock;
166
167extern void* /* really, XArray* of GlobalBlock */
168VG_(di_get_global_blocks_from_dihandle) ( ULong di_handle,
169 Bool arrays_only );
170
171
njnea27e462005-05-31 02:38:09 +0000172/*====================================================================*/
sewardje3f1e592009-07-31 09:41:29 +0000173/*=== Obtaining debug information ===*/
njnea27e462005-05-31 02:38:09 +0000174/*====================================================================*/
175
sewardje3f1e592009-07-31 09:41:29 +0000176/* A way to make limited debuginfo queries on a per-mapped-object
177 basis. */
178typedef struct _DebugInfo DebugInfo;
njnea27e462005-05-31 02:38:09 +0000179
sewardjb8b79ad2008-03-03 01:35:41 +0000180/* Returns NULL if the DebugInfo isn't found. It doesn't matter if
181 debug info is present or not. */
sewardje3f1e592009-07-31 09:41:29 +0000182DebugInfo* VG_(find_DebugInfo) ( Addr a );
njnea27e462005-05-31 02:38:09 +0000183
sewardjb8b79ad2008-03-03 01:35:41 +0000184/* Fish bits out of DebugInfos. */
sewardje3f1e592009-07-31 09:41:29 +0000185Addr VG_(DebugInfo_get_text_avma) ( const DebugInfo *di );
186SizeT VG_(DebugInfo_get_text_size) ( const DebugInfo *di );
bart38980222013-08-24 17:52:26 +0000187Addr VG_(DebugInfo_get_bss_avma) ( const DebugInfo *di );
188SizeT VG_(DebugInfo_get_bss_size) ( const DebugInfo *di );
sewardje3f1e592009-07-31 09:41:29 +0000189Addr VG_(DebugInfo_get_plt_avma) ( const DebugInfo *di );
190SizeT VG_(DebugInfo_get_plt_size) ( const DebugInfo *di );
191Addr VG_(DebugInfo_get_gotplt_avma) ( const DebugInfo *di );
192SizeT VG_(DebugInfo_get_gotplt_size) ( const DebugInfo *di );
bart68347832012-09-06 14:08:26 +0000193Addr VG_(DebugInfo_get_got_avma) ( const DebugInfo *di );
194SizeT VG_(DebugInfo_get_got_size) ( const DebugInfo *di );
florian1636d332012-11-15 04:27:04 +0000195const HChar* VG_(DebugInfo_get_soname) ( const DebugInfo *di );
196const HChar* VG_(DebugInfo_get_filename) ( const DebugInfo *di );
sewardje3f1e592009-07-31 09:41:29 +0000197PtrdiffT VG_(DebugInfo_get_text_bias) ( const DebugInfo *di );
njnea27e462005-05-31 02:38:09 +0000198
sewardje3f1e592009-07-31 09:41:29 +0000199/* Function for traversing the DebugInfo list. When called with NULL
200 it returns the first element; otherwise it returns the given
201 element's successor. Note that the order of elements in the list
202 changes in response to most of the queries listed in this header,
203 that explicitly or implicitly have to search the list for a
204 particular code address. So it isn't safe to assume that the order
205 of the list stays constant. */
206const DebugInfo* VG_(next_DebugInfo) ( const DebugInfo *di );
sewardj0ec07f32006-01-12 12:32:32 +0000207
sewardjb8b79ad2008-03-03 01:35:41 +0000208/* Functions for traversing all the symbols in a DebugInfo. _howmany
sewardja5cace02011-08-15 09:42:34 +0000209 tells how many symbol table entries there are. _getidx retrieves
210 the n'th entry, for n in 0 .. _howmany-1. You may not modify the
211 function names thereby acquired; if you want to do so, first strdup
212 them. The primary name is returned in *pri_name, and *sec_names is
213 set either to NULL or to a NULL terminated vector containing
214 pointers to the secondary names. */
sewardje3f1e592009-07-31 09:41:29 +0000215Int VG_(DebugInfo_syms_howmany) ( const DebugInfo *di );
216void VG_(DebugInfo_syms_getidx) ( const DebugInfo *di,
217 Int idx,
sewardja5cace02011-08-15 09:42:34 +0000218 /*OUT*/Addr* avma,
219 /*OUT*/Addr* tocptr,
220 /*OUT*/UInt* size,
florian19f91bb2012-11-10 22:29:54 +0000221 /*OUT*/HChar** pri_name,
222 /*OUT*/HChar*** sec_names,
sewardja5cace02011-08-15 09:42:34 +0000223 /*OUT*/Bool* isText,
224 /*OUT*/Bool* isIFunc );
sewardj0ec07f32006-01-12 12:32:32 +0000225
sewardjb8b79ad2008-03-03 01:35:41 +0000226/* A simple enumeration to describe the 'kind' of various kinds of
227 segments that arise from the mapping of object files. */
njnea27e462005-05-31 02:38:09 +0000228typedef
229 enum {
230 Vg_SectUnknown,
231 Vg_SectText,
232 Vg_SectData,
233 Vg_SectBSS,
234 Vg_SectGOT,
sewardjb8b79ad2008-03-03 01:35:41 +0000235 Vg_SectPLT,
bart092b6262008-05-25 16:37:22 +0000236 Vg_SectGOTPLT,
sewardjb8b79ad2008-03-03 01:35:41 +0000237 Vg_SectOPD
njnea27e462005-05-31 02:38:09 +0000238 }
239 VgSectKind;
240
sewardjb8b79ad2008-03-03 01:35:41 +0000241/* Convert a VgSectKind to a string, which must be copied if you want
242 to change it. */
sewardjb8b79ad2008-03-03 01:35:41 +0000243const HChar* VG_(pp_SectKind)( VgSectKind kind );
njnea27e462005-05-31 02:38:09 +0000244
sewardjb8b79ad2008-03-03 01:35:41 +0000245/* Given an address 'a', make a guess of which section of which object
246 it comes from. If name is non-NULL, then the last n_name-1
247 characters of the object's name is put in name[0 .. n_name-2], and
248 name[n_name-1] is set to zero (guaranteed zero terminated). */
florian1636d332012-11-15 04:27:04 +0000249VgSectKind VG_(DebugInfo_sect_kind)( /*OUT*/HChar* name, SizeT n_name,
sewardje3f1e592009-07-31 09:41:29 +0000250 Addr a);
sewardjbbec7722007-11-25 14:08:53 +0000251
252
njnea27e462005-05-31 02:38:09 +0000253#endif // __PUB_TOOL_DEBUGINFO_H
254
255/*--------------------------------------------------------------------*/
256/*--- end ---*/
257/*--------------------------------------------------------------------*/