File: pub_tool_addrinfo.h

package info (click to toggle)
valgrind 1%3A3.12.0~svn20160714-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 120,428 kB
  • ctags: 70,855
  • sloc: ansic: 674,645; exp: 26,134; xml: 21,574; asm: 7,570; cpp: 7,567; makefile: 7,380; sh: 6,188; perl: 5,855; haskell: 195
file content (226 lines) | stat: -rw-r--r-- 8,526 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226

/*--------------------------------------------------------------------*/
/*--- Obtaining information about an address.  pub_tool_addrinfo.h ---*/
/*--------------------------------------------------------------------*/

/*
   This file is part of Valgrind, a dynamic binary instrumentation
   framework.

   Copyright (C) 2000-2015 Julian Seward
      jseward@acm.org

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307, USA.

   The GNU General Public License is contained in the file COPYING.
*/

#ifndef __PUB_TOOL_ADDRINFO_H
#define __PUB_TOOL_ADDRINFO_H

#include "pub_tool_basics.h"   // VG_ macro
#include "pub_tool_aspacemgr.h"  // SegKind

/*====================================================================*/
/*=== Obtaining information about an address                       ===*/
/*====================================================================*/

// Different kinds of blocks.
// Block_Mallocd is used by tools that maintain detailed information about
//   Client allocated heap blocks.
// Block_Freed is used by tools such as memcheck that maintain a 'quarantine' 
//   list of blocks freed by the Client but not yet physically freed.
// Block_MempoolChunk and Block_UserG are used for mempool or user defined heap
//   blocks.
// Block_ClientArenaMallocd and Block_ClientArenaFree are used when the tool
//   replaces the malloc/free/... functions but does not maintain detailed
//   information about Client allocated heap blocks.
// Block_ValgrindArenaMallocd and Block_ValgrindArenaFree are used for heap
//   blocks of Valgrind internal heap.
typedef enum {
   Block_Mallocd = 111,
   Block_Freed,
   Block_MempoolChunk,
   Block_UserG,
   Block_ClientArenaMallocd,
   Block_ClientArenaFree,
   Block_ValgrindArenaMallocd,
   Block_ValgrindArenaFree,
} BlockKind;

/* ------------------ Addresses -------------------- */

/* The classification of a faulting address. */
typedef 
   enum { 
      Addr_Undescribed, // as-yet unclassified
      Addr_Unknown,     // classification yielded nothing useful
      Addr_Block,       // in malloc'd/free'd block
      Addr_Stack,       // on a thread's stack       
      Addr_DataSym,     // in a global data sym
      Addr_Variable,    // variable described by the debug info
      Addr_SectKind,    // Section from a mmap-ed object file
      Addr_BrkSegment,  // address in brk data segment
      Addr_SegmentKind  // Client segment (mapped memory)
   }
   AddrTag;

/* For an address in a stack, gives the address position in this stack. */
typedef 
   enum {
      StackPos_stacked,         // Addressable and 'active' stack zone.
      StackPos_below_stack_ptr, // Below stack ptr
      StackPos_guard_page       // In the guard page
   }
   StackPos;


/* Note about ThreadInfo tid and tnr in various parts of _Addrinfo:
   A tid is an index in the VG_(threads)[] array. The entries
   in  VG_(threads) array are re-used, so the tid in an 'old' _Addrinfo
   might be misleading: if the thread that was using tid has been terminated
   and the tid was re-used by another thread, the tid will very probably
   be wrongly interpreted by the user.
   So, such an _Addrinfo should be printed just after it has been produced,
   before the tid could possibly be re-used by another thread.

   A tool such as helgrind is uniquely/unambiguously identifying each thread
   by a number. If the tool sets tnr between the call to
   VG_(describe_addr) and the call to VG_(pp_addrinfo), then VG_(pp_addrinfo)
   will by preference print tnr instead of tid.
   Visually, a tid will be printed as   thread %d
   while a tnr will be printed as       thread #%d
*/

typedef
   struct _ThreadInfo {
      ThreadId tid;   // 0 means thread not known.
      UInt     tnr;   // 0 means no tool specific thread nr, or not known.
   } ThreadInfo;

/* Zeroes/clear all the fields of *tinfo. */
extern void VG_(initThreadInfo) (ThreadInfo *tinfo);

typedef
   struct _AddrInfo
   AddrInfo;
   
struct _AddrInfo {
   AddrTag tag;
   union {
      // As-yet unclassified.
      struct { } Undescribed;

      // On a stack. tinfo indicates which thread's stack?
      // IP is the address of an instruction of the function where the
      // stack address was. 0 if not found.
      // frameNo is the frame nr of the call where the stack address was.
      // -1 if not found.
      // stackPos describes the address 'position' in the stack.
      // If stackPos is StackPos_below_stack_ptr or StackPos_guard_page,
      // spoffset gives the offset from the thread stack pointer.
      // (spoffset will be negative, as stacks are assumed growing down).
      struct {
         ThreadInfo tinfo;
         Addr     IP;
         Int      frameNo;
         StackPos stackPos;
         PtrdiffT spoffset;
      } Stack;

      // This covers heap blocks (normal and from mempools), user-defined
      // blocks and Arena blocks.
      // alloc_tinfo identifies the thread that has allocated the block.
      // This is used by tools such as helgrind that maintain
      // more detailed informations about client blocks.
      struct {
         BlockKind   block_kind;
         const HChar* block_desc;   // "block","mempool","user-defined",arena
         SizeT       block_szB;
         PtrdiffT    rwoffset;
         ExeContext* allocated_at;  // might be null_ExeContext.
         ThreadInfo  alloc_tinfo;   // which thread did alloc this block.
         ExeContext* freed_at;      // might be null_ExeContext.
      } Block;

      // In a global .data symbol.  This holds
      // the variable's name (zero terminated), plus a (memory) offset.
      struct {
         HChar   *name;
         PtrdiffT offset;
      } DataSym;

      // Is described by Dwarf debug info.  XArray*s of HChar.
      struct {
         XArray* /* of HChar */ descr1;
         XArray* /* of HChar */ descr2;
      } Variable;

      // Could only narrow it down to be the PLT/GOT/etc of a given
      // object.  Better than nothing, perhaps.
      struct {
         HChar      *objname;
         VgSectKind kind;
      } SectKind;

      // Described address is or was in the brk data segment.
      // brk_limit is the limit that was in force
      // at the time address was described. 
      // If address is >= brk_limit, it means address is in a zone
      // of the data segment that was shrinked.
      struct {
         Addr brk_limit; // limit in force when address was described.
      } BrkSegment;

      struct {
         SegKind segkind;   // SkAnonC, SkFileC or SkShmC.
         HChar   *filename; // NULL if segkind != SkFileC
         Bool    hasR;
         Bool    hasW;
         Bool    hasX;
      } SegmentKind;

      // Classification yielded nothing useful.
      struct { } Unknown;

   } Addr;
};


/* Describe an address as best you can, putting the result in ai.
   On entry, ai->tag must be equal to Addr_Undescribed.
   This might allocate some memory, that can be cleared with
   VG_(clear_addrinfo). */
extern void VG_(describe_addr) ( Addr a, /*OUT*/AddrInfo* ai );

extern void VG_(clear_addrinfo) ( AddrInfo* ai);

/* Prints the AddrInfo ai describing a.
   Note that an ai with tag Addr_Undescribed will cause an assert.*/
extern void VG_(pp_addrinfo) ( Addr a, const AddrInfo* ai );

/* Same as VG_(pp_addrinfo) but provides some memcheck specific behaviour:
   * maybe_gcc indicates Addr a was just below the stack ptr when the error
     with a was encountered.
   * the message for Unknown tag is slightly different, as memcheck
     has a recently freed list. */
extern void VG_(pp_addrinfo_mc) ( Addr a, const AddrInfo* ai, Bool maybe_gcc );

#endif   // __PUB_TOOL_ADDRINFO_H

/*--------------------------------------------------------------------*/
/*--- end                                                          ---*/
/*--------------------------------------------------------------------*/