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
10   Copyright (C) 2000-2013 Julian Seward
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.
38//--------------------------------------------------------------------
39
40#include "pub_tool_debuginfo.h"
41
42/* Initialise the entire module.  Must be called first of all. */
43extern void VG_(di_initialise) ( void );
44
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
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
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*/
65#if defined(VGO_linux) || defined(VGO_darwin)
66extern ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV, Int use_fd );
67
68extern void VG_(di_notify_munmap)( Addr a, SizeT len );
69
70extern void VG_(di_notify_mprotect)( Addr a, SizeT len, UInt prot );
71
72/* this should really return ULong, as per VG_(di_notify_mmap). */
73extern void VG_(di_notify_pdb_debuginfo)( Int fd, Addr avma,
74                                          SizeT total_size,
75                                          PtrdiffT bias );
76
77/* this should also really return ULong */
78extern void VG_(di_notify_vm_protect)( Addr a, SizeT len, UInt prot );
79#endif
80
81extern void VG_(di_discard_ALL_debuginfo)( void );
82
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. */
88extern
89Bool VG_(get_fnname_raw) ( Addr a, HChar* buf, Int nbuf );
90
91/* Like VG_(get_fnname), but without C++ demangling.  (But it does
92 * Z-demangling and below-main renaming.) */
93extern
94Bool VG_(get_fnname_no_cxx_demangle) ( Addr a, HChar* buf, Int nbuf );
95
96/* mips-linux only: find the offset of current address. This is needed for
97   stack unwinding for MIPS.
98*/
99extern
100Bool VG_(get_inst_offset_in_function)( Addr a, /*OUT*/PtrdiffT* offset );
101
102
103/* Use DWARF2/3 CFA information to do one step of stack unwinding.
104   D3UnwindRegs holds the current register values, and is
105   arch-specific.  Note that the x86 and amd64 definitions are shared
106   and so the regs are named 'xip' etc rather than 'eip' and 'rip'. */
107#if defined(VGA_amd64) || defined(VGA_x86)
108typedef
109   struct { Addr xip; Addr xsp; Addr xbp; }
110   D3UnwindRegs;
111#elif defined(VGA_arm)
112typedef
113   struct { Addr r15; Addr r14; Addr r13; Addr r12; Addr r11; Addr r7; }
114   D3UnwindRegs;
115#elif defined(VGA_arm64)
116typedef
117   struct { Addr pc; Addr sp; Addr x30; Addr x29; } /* PC, SP, LR, FP */
118   D3UnwindRegs;
119#elif defined(VGA_ppc32) || defined(VGA_ppc64)
120typedef
121   UChar  /* should be void, but gcc complains at use points */
122   D3UnwindRegs;
123#elif defined(VGA_s390x)
124typedef
125   struct { Addr ia; Addr sp; Addr fp; Addr lr;}
126   D3UnwindRegs;
127#elif defined(VGA_mips32) || defined(VGA_mips64)
128typedef
129   struct { Addr pc; Addr sp; Addr fp; Addr ra; }
130   D3UnwindRegs;
131#else
132#  error "Unsupported arch"
133#endif
134
135extern Bool VG_(use_CF_info) ( /*MOD*/D3UnwindRegs* uregs,
136                               Addr min_accessible,
137                               Addr max_accessible );
138
139/* returns the "generation" of the CF info.
140   Each time some debuginfo is changed (e.g. loaded or unloaded),
141   the VG_(CF_info_generation) value returned will be increased.
142   This can be used to flush cached information derived from the CF info. */
143extern UInt VG_(CF_info_generation) (void);
144
145
146
147/* Use MSVC FPO data to do one step of stack unwinding. */
148extern Bool VG_(use_FPO_info) ( /*MOD*/Addr* ipP,
149                                /*MOD*/Addr* spP,
150                                /*MOD*/Addr* fpP,
151                                Addr min_accessible,
152                                Addr max_accessible );
153
154/* ppc64-linux only: find the TOC pointer (R2 value) that should be in
155   force at the entry point address of the function containing
156   guest_code_addr.  Returns 0 if not known. */
157extern Addr VG_(get_tocptr) ( Addr guest_code_addr );
158
159/* Map a function name to its entry point and toc pointer.  Is done by
160   sequential search of all symbol tables, so is very slow.  To
161   mitigate the worst performance effects, you may specify a soname
162   pattern, and only objects matching that pattern are searched.
163   Therefore specify "*" to search all the objects.  On TOC-afflicted
164   platforms, a symbol is deemed to be found only if it has a nonzero
165   TOC pointer.  */
166extern
167Bool VG_(lookup_symbol_SLOW)(const HChar* sopatt, HChar* name, Addr* pEnt,
168                             Addr* pToc);
169
170#endif   // __PUB_CORE_DEBUGINFO_H
171
172/*--------------------------------------------------------------------*/
173/*--- end                                                          ---*/
174/*--------------------------------------------------------------------*/
175