blob: 0387d1fe4f8c3f74f115b9e7a252dfd8125c6916 [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
sewardj9ebd6e02007-01-08 06:01:59 +000010 Copyright (C) 2000-2007 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. */
44extern Bool VG_(get_filename) ( Addr a, Char* filename, Int n_filename );
45extern Bool VG_(get_fnname) ( Addr a, Char* fnname, Int n_fnname );
46extern Bool VG_(get_linenum) ( Addr a, UInt* linenum );
47extern Bool VG_(get_fnname_w_offset)
48 ( Addr a, Char* fnname, Int n_fnname );
49
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,
63 /*OUT*/Char* filename, Int n_filename,
64 /*OUT*/Char* dirname, Int n_dirname,
65 /*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. */
75extern Bool VG_(get_fnname_if_entry) ( Addr a, Char* fnname, Int n_fnname );
76
77/* Succeeds if the address is within a shared object or the main executable.
78 It doesn't matter if debug info is present or not. */
79extern Bool VG_(get_objname) ( Addr a, Char* objname, Int n_objname );
80
81/* Puts into 'buf' info about the code address %eip: the address, function
82 name (if known) and filename/line number (if known), like this:
83
84 0x4001BF05: realloc (vg_replace_malloc.c:339)
85
86 'n_buf' gives length of 'buf'. Returns 'buf'.
87*/
88extern Char* VG_(describe_IP)(Addr eip, Char* buf, Int n_buf);
89
njnea27e462005-05-31 02:38:09 +000090
91/*====================================================================*/
92/*=== Obtaining segment information ===*/
93/*====================================================================*/
94
95/* A way to get information about what segments are mapped */
96typedef struct _SegInfo SegInfo;
97
98/* Returns NULL if the SegInfo isn't found. It doesn't matter if debug info
99 is present or not. */
njn3c45f5b2005-07-06 13:19:11 +0000100extern SegInfo* VG_(find_seginfo) ( Addr a );
njnea27e462005-05-31 02:38:09 +0000101
sewardj0ec07f32006-01-12 12:32:32 +0000102/* Fish bits out of SegInfos. */
njnd9e5fd72005-06-25 19:51:33 +0000103extern Addr VG_(seginfo_start) ( const SegInfo *si );
104extern SizeT VG_(seginfo_size) ( const SegInfo *si );
njn4f612c22005-06-25 20:22:43 +0000105extern const UChar* VG_(seginfo_soname) ( const SegInfo *si );
njnd9e5fd72005-06-25 19:51:33 +0000106extern const UChar* VG_(seginfo_filename) ( const SegInfo *si );
107extern ULong VG_(seginfo_sym_offset)( const SegInfo *si );
njnea27e462005-05-31 02:38:09 +0000108
sewardj0ec07f32006-01-12 12:32:32 +0000109/* Function for traversing the seginfo list. When called with NULL it
110 returns the first element; otherwise it returns the given element's
111 successor. */
112extern const SegInfo* VG_(next_seginfo) ( const SegInfo *si );
113
114/* Functions for traversing all the symbols in a SegInfo. _howmany
115 tells how many there are. _getidx retrieves the n'th, for n in 0
116 .. _howmany-1. You may not modify the function name thereby
117 acquired; if you want to do so, first strdup it. */
118extern Int VG_(seginfo_syms_howmany) ( const SegInfo *si );
119extern void VG_(seginfo_syms_getidx) ( const SegInfo *si,
120 Int idx,
121 /*OUT*/Addr* addr,
sewardj811469c2006-10-17 01:36:37 +0000122 /*OUT*/Addr* tocptr,
sewardj0ec07f32006-01-12 12:32:32 +0000123 /*OUT*/UInt* size,
124 /*OUT*/HChar** name );
125
njnea27e462005-05-31 02:38:09 +0000126typedef
127 enum {
128 Vg_SectUnknown,
129 Vg_SectText,
130 Vg_SectData,
131 Vg_SectBSS,
132 Vg_SectGOT,
133 Vg_SectPLT
134 }
135 VgSectKind;
136
njnd9e5fd72005-06-25 19:51:33 +0000137extern VgSectKind VG_(seginfo_sect_kind)(Addr);
njnea27e462005-05-31 02:38:09 +0000138
sewardjbbec7722007-11-25 14:08:53 +0000139extern Char* VG_(seginfo_sect_kind_name)(Addr a, Char* buf, UInt n_buf);
140
141
njnea27e462005-05-31 02:38:09 +0000142#endif // __PUB_TOOL_DEBUGINFO_H
143
144/*--------------------------------------------------------------------*/
145/*--- end ---*/
146/*--------------------------------------------------------------------*/