blob: 49ceffbdfe3c9896efae709d790093e8457c03d9 [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
sewardjb3a1e4b2015-08-21 11:32:26 +000010 Copyright (C) 2000-2015 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
florian535fb1b2013-09-15 13:54:34 +000034#include "pub_tool_basics.h" // VG_ macro
florian09a8b142015-08-09 16:27:44 +000035#include "pub_tool_xarray.h" // XArray
florian535fb1b2013-09-15 13:54:34 +000036
njnea27e462005-05-31 02:38:09 +000037/*====================================================================*/
38/*=== Obtaining debug information ===*/
39/*====================================================================*/
40
41/* Get the file/function/line number of the instruction at address
42 'a'. For these four, if debug info for the address is found, it
43 copies the info into the buffer/UInt and returns True. If not, it
florian46cc0452014-10-25 19:20:38 +000044 returns False. VG_(get_fnname) always
njnea27e462005-05-31 02:38:09 +000045 demangles C++ function names. VG_(get_fnname_w_offset) is the
46 same, except it appends "+N" to symbol names to indicate offsets. */
florian10ef7252014-10-27 12:06:35 +000047extern Bool VG_(get_filename) ( Addr a, const HChar** filename );
florian46cc0452014-10-25 19:20:38 +000048extern Bool VG_(get_fnname) ( Addr a, const HChar** fnname );
njnea27e462005-05-31 02:38:09 +000049extern Bool VG_(get_linenum) ( Addr a, UInt* linenum );
50extern Bool VG_(get_fnname_w_offset)
florian46cc0452014-10-25 19:20:38 +000051 ( Addr a, const HChar** fnname );
njnea27e462005-05-31 02:38:09 +000052
sewardj7cee6f92005-06-13 17:39:06 +000053/* This one is the most general. It gives filename, line number and
54 optionally directory name. filename and linenum may not be NULL.
55 dirname may be NULL, meaning that the caller does not want
florianf4384f42014-12-16 20:55:58 +000056 directory name info.
57 If dirname is non-null, directory info is written to *dirname, if
sewardj7cee6f92005-06-13 17:39:06 +000058 it is available; if not available, '\0' is written to the first
florianf4384f42014-12-16 20:55:58 +000059 byte.
sewardj7cee6f92005-06-13 17:39:06 +000060
florian10ef7252014-10-27 12:06:35 +000061 The character strings returned in *filename and *dirname are not
62 persistent. They will be freed when the DebugInfo they belong to
63 is discarded.
64
sewardj7cee6f92005-06-13 17:39:06 +000065 Returned value indicates whether any filename/line info could be
66 found. */
njnea27e462005-05-31 02:38:09 +000067extern Bool VG_(get_filename_linenum)
sewardj7cee6f92005-06-13 17:39:06 +000068 ( Addr a,
florian10ef7252014-10-27 12:06:35 +000069 /*OUT*/const HChar** filename,
70 /*OUT*/const HChar** dirname,
sewardj7cee6f92005-06-13 17:39:06 +000071 /*OUT*/UInt* linenum );
njnea27e462005-05-31 02:38:09 +000072
73/* Succeeds only if we find from debug info that 'a' is the address of the
74 first instruction in a function -- as opposed to VG_(get_fnname) which
75 succeeds if we find from debug info that 'a' is the address of any
76 instruction in a function. Use this to instrument the start of
77 a particular function. Nb: if an executable/shared object is stripped
78 of its symbols, this function will not be able to recognise function
79 entry points within it. */
florian46cc0452014-10-25 19:20:38 +000080extern Bool VG_(get_fnname_if_entry) ( Addr a, const HChar** fnname );
njnea27e462005-05-31 02:38:09 +000081
njn68824432009-02-10 06:48:00 +000082typedef
83 enum {
84 Vg_FnNameNormal, // A normal function.
85 Vg_FnNameMain, // "main"
86 Vg_FnNameBelowMain // Something below "main", eg. __libc_start_main.
87 } Vg_FnNameKind; // Such names are often filtered.
88
89/* Indicates what kind of fnname it is. */
florian46cc0452014-10-25 19:20:38 +000090extern Vg_FnNameKind VG_(get_fnname_kind) ( const HChar* name );
njn68824432009-02-10 06:48:00 +000091
92/* Like VG_(get_fnname_kind), but takes a code address. */
93extern Vg_FnNameKind VG_(get_fnname_kind_from_IP) ( Addr ip );
94
sewardjb8b79ad2008-03-03 01:35:41 +000095/* Looks up data_addr in the collection of data symbols, and if found
96 puts its name (or as much as will fit) into dname[0 .. n_dname-1],
97 which is guaranteed to be zero terminated. Also data_addr's offset
98 from the symbol start is put into *offset. */
99extern Bool VG_(get_datasym_and_offset)( Addr data_addr,
florian46cc0452014-10-25 19:20:38 +0000100 /*OUT*/const HChar** dname,
njnc4431bf2009-01-15 21:29:24 +0000101 /*OUT*/PtrdiffT* offset );
sewardjb8b79ad2008-03-03 01:35:41 +0000102
sewardj5d9dc752009-07-15 14:52:18 +0000103/* Try to form some description of DATA_ADDR by looking at the DWARF3
philippe25963372013-01-16 22:07:02 +0000104 debug info we have. This considers all global variables, and 8
sewardj5d9dc752009-07-15 14:52:18 +0000105 frames in the stacks of all threads. Result is written at the ends
106 of DNAME{1,2}V, which are XArray*s of HChar, that have been
107 initialised by the caller, and True is returned. If no description
108 is created, False is returned. Regardless of the return value,
109 DNAME{1,2}V are guaranteed to be zero terminated after the call.
110
111 Note that after the call, DNAME{1,2} may have more than one
112 trailing zero, so callers should establish the useful text length
113 using VG_(strlen) on the contents, rather than VG_(sizeXA) on the
114 XArray itself.
115*/
116Bool VG_(get_data_description)(
florian09a8b142015-08-09 16:27:44 +0000117 /*MOD*/ XArray* /* of HChar */ dname1v,
118 /*MOD*/ XArray* /* of HChar */ dname2v,
sewardj5d9dc752009-07-15 14:52:18 +0000119 Addr data_addr
120 );
sewardjb8b79ad2008-03-03 01:35:41 +0000121
njnea27e462005-05-31 02:38:09 +0000122/* Succeeds if the address is within a shared object or the main executable.
123 It doesn't matter if debug info is present or not. */
florian46cc0452014-10-25 19:20:38 +0000124extern Bool VG_(get_objname) ( Addr a, const HChar** objname );
njnea27e462005-05-31 02:38:09 +0000125
philippea0a73932014-06-15 15:42:20 +0000126
127/* Cursor allowing to describe inlined function calls at an IP,
128 by doing successive calls to VG_(describe_IP). */
129typedef struct _InlIPCursor InlIPCursor;
130
florian770a8d22014-11-03 22:43:42 +0000131/* Returns info about the code address %eip: the address, function
njnea27e462005-05-31 02:38:09 +0000132 name (if known) and filename/line number (if known), like this:
133
134 0x4001BF05: realloc (vg_replace_malloc.c:339)
135
philippea0a73932014-06-15 15:42:20 +0000136 eip can possibly corresponds to inlined function call(s).
137 To describe eip and the inlined function calls, the following must
138 be done:
139 InlIPCursor *iipc = VG_(new_IIPC)(eip);
140 do {
florian770a8d22014-11-03 22:43:42 +0000141 buf = VG_(describe_IP)(eip, iipc);
philippea0a73932014-06-15 15:42:20 +0000142 ... use buf ...
143 } while (VG_(next_IIPC)(iipc));
144 VG_(delete_IIPC)(iipc);
145
146 To only describe eip, without the inlined calls at eip, give a NULL iipc:
florian770a8d22014-11-03 22:43:42 +0000147 buf = VG_(describe_IP)(eip, NULL);
148
149 Note, that the returned string is allocated in a static buffer local to
150 VG_(describe_IP). That buffer will be overwritten with every invocation.
151 Therefore, callers need to possibly stash away the string.
njnea27e462005-05-31 02:38:09 +0000152*/
florian770a8d22014-11-03 22:43:42 +0000153extern const HChar* VG_(describe_IP)(Addr eip, const InlIPCursor* iipc);
philippea0a73932014-06-15 15:42:20 +0000154
155/* Builds a IIPC (Inlined IP Cursor) to describe eip and all the inlined calls
156 at eip. Such a cursor must be deleted after use using VG_(delete_IIPC). */
157extern InlIPCursor* VG_(new_IIPC)(Addr eip);
158/* Move the cursor to the next call to describe.
159 Returns True if there are still calls to describe.
160 False if nothing to describe anymore. */
161extern Bool VG_(next_IIPC)(InlIPCursor *iipc);
162/* Free all memory associated with iipc. */
163extern void VG_(delete_IIPC)(InlIPCursor *iipc);
164
njnea27e462005-05-31 02:38:09 +0000165
sewardj9c606bd2008-09-18 18:12:50 +0000166
167/* Get an XArray of StackBlock which describe the stack (auto) blocks
168 for this ip. The caller is expected to free the XArray at some
169 point. If 'arrays_only' is True, only array-typed blocks are
170 returned; otherwise blocks of all types are returned. */
171
172typedef
173 struct {
njnc4431bf2009-01-15 21:29:24 +0000174 PtrdiffT base; /* offset from sp or fp */
175 SizeT szB; /* size in bytes */
176 Bool spRel; /* True => sp-rel, False => fp-rel */
177 Bool isVec; /* does block have an array type, or not? */
178 HChar name[16]; /* first 15 chars of name (asciiz) */
sewardj9c606bd2008-09-18 18:12:50 +0000179 }
180 StackBlock;
181
florian09a8b142015-08-09 16:27:44 +0000182extern XArray* /* of StackBlock */
183VG_(di_get_stack_blocks_at_ip)( Addr ip, Bool arrays_only );
sewardj9c606bd2008-09-18 18:12:50 +0000184
185
186/* Get an array of GlobalBlock which describe the global blocks owned
187 by the shared object characterised by the given di_handle. Asserts
188 if the handle is invalid. The caller is responsible for freeing
189 the array at some point. If 'arrays_only' is True, only
190 array-typed blocks are returned; otherwise blocks of all types are
191 returned. */
192
193typedef
194 struct {
195 Addr addr;
196 SizeT szB;
197 Bool isVec; /* does block have an array type, or not? */
198 HChar name[16]; /* first 15 chars of name (asciiz) */
199 HChar soname[16]; /* first 15 chars of name (asciiz) */
200 }
201 GlobalBlock;
202
florian09a8b142015-08-09 16:27:44 +0000203extern XArray* /* of GlobalBlock */
sewardj9c606bd2008-09-18 18:12:50 +0000204VG_(di_get_global_blocks_from_dihandle) ( ULong di_handle,
205 Bool arrays_only );
206
207
njnea27e462005-05-31 02:38:09 +0000208/*====================================================================*/
sewardje3f1e592009-07-31 09:41:29 +0000209/*=== Obtaining debug information ===*/
njnea27e462005-05-31 02:38:09 +0000210/*====================================================================*/
211
sewardje3f1e592009-07-31 09:41:29 +0000212/* A way to make limited debuginfo queries on a per-mapped-object
213 basis. */
214typedef struct _DebugInfo DebugInfo;
njnea27e462005-05-31 02:38:09 +0000215
sewardjb8b79ad2008-03-03 01:35:41 +0000216/* Returns NULL if the DebugInfo isn't found. It doesn't matter if
217 debug info is present or not. */
sewardje3f1e592009-07-31 09:41:29 +0000218DebugInfo* VG_(find_DebugInfo) ( Addr a );
njnea27e462005-05-31 02:38:09 +0000219
sewardjb8b79ad2008-03-03 01:35:41 +0000220/* Fish bits out of DebugInfos. */
sewardje3f1e592009-07-31 09:41:29 +0000221Addr VG_(DebugInfo_get_text_avma) ( const DebugInfo *di );
222SizeT VG_(DebugInfo_get_text_size) ( const DebugInfo *di );
bart38980222013-08-24 17:52:26 +0000223Addr VG_(DebugInfo_get_bss_avma) ( const DebugInfo *di );
224SizeT VG_(DebugInfo_get_bss_size) ( const DebugInfo *di );
sewardje3f1e592009-07-31 09:41:29 +0000225Addr VG_(DebugInfo_get_plt_avma) ( const DebugInfo *di );
226SizeT VG_(DebugInfo_get_plt_size) ( const DebugInfo *di );
227Addr VG_(DebugInfo_get_gotplt_avma) ( const DebugInfo *di );
228SizeT VG_(DebugInfo_get_gotplt_size) ( const DebugInfo *di );
bart68347832012-09-06 14:08:26 +0000229Addr VG_(DebugInfo_get_got_avma) ( const DebugInfo *di );
230SizeT VG_(DebugInfo_get_got_size) ( const DebugInfo *di );
florian1636d332012-11-15 04:27:04 +0000231const HChar* VG_(DebugInfo_get_soname) ( const DebugInfo *di );
232const HChar* VG_(DebugInfo_get_filename) ( const DebugInfo *di );
sewardje3f1e592009-07-31 09:41:29 +0000233PtrdiffT VG_(DebugInfo_get_text_bias) ( const DebugInfo *di );
njnea27e462005-05-31 02:38:09 +0000234
sewardje3f1e592009-07-31 09:41:29 +0000235/* Function for traversing the DebugInfo list. When called with NULL
236 it returns the first element; otherwise it returns the given
237 element's successor. Note that the order of elements in the list
238 changes in response to most of the queries listed in this header,
239 that explicitly or implicitly have to search the list for a
240 particular code address. So it isn't safe to assume that the order
241 of the list stays constant. */
242const DebugInfo* VG_(next_DebugInfo) ( const DebugInfo *di );
sewardj0ec07f32006-01-12 12:32:32 +0000243
sewardjb8b79ad2008-03-03 01:35:41 +0000244/* A simple enumeration to describe the 'kind' of various kinds of
245 segments that arise from the mapping of object files. */
njnea27e462005-05-31 02:38:09 +0000246typedef
247 enum {
248 Vg_SectUnknown,
249 Vg_SectText,
250 Vg_SectData,
251 Vg_SectBSS,
252 Vg_SectGOT,
sewardjb8b79ad2008-03-03 01:35:41 +0000253 Vg_SectPLT,
bart092b6262008-05-25 16:37:22 +0000254 Vg_SectGOTPLT,
sewardjb8b79ad2008-03-03 01:35:41 +0000255 Vg_SectOPD
njnea27e462005-05-31 02:38:09 +0000256 }
257 VgSectKind;
258
sewardjb8b79ad2008-03-03 01:35:41 +0000259/* Convert a VgSectKind to a string, which must be copied if you want
260 to change it. */
sewardjb8b79ad2008-03-03 01:35:41 +0000261const HChar* VG_(pp_SectKind)( VgSectKind kind );
njnea27e462005-05-31 02:38:09 +0000262
sewardjb8b79ad2008-03-03 01:35:41 +0000263/* Given an address 'a', make a guess of which section of which object
floriane08950b2014-11-13 21:41:28 +0000264 it comes from. If name is non-NULL, then the object's name is put
265 into *name. The returned name is persistent as long as the debuginfo
266 it belongs to isn't discarded. */
267VgSectKind VG_(DebugInfo_sect_kind)( /*OUT*/const HChar** name, Addr a);
sewardjbbec7722007-11-25 14:08:53 +0000268
269
njnea27e462005-05-31 02:38:09 +0000270#endif // __PUB_TOOL_DEBUGINFO_H
271
272/*--------------------------------------------------------------------*/
273/*--- end ---*/
274/*--------------------------------------------------------------------*/