blob: 9722c2f31c204cb87f64dd4a3c6d26fa2dd9efbb [file] [log] [blame]
nethercote37aac2e2004-09-02 08:54:27 +00001/*-*- c -*- ----------------------------------------------------------*/
2/*--- The only header your tool will ever need to #include... ---*/
3/*--- tool.h ---*/
4/*--------------------------------------------------------------------*/
5
6/*
7 This file is part of Valgrind, an extensible x86 protected-mode
8 emulator for monitoring program execution on x86-Unixes.
9
10 Copyright (C) 2000-2004 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 __TOOL_H
32#define __TOOL_H
33
34#include <stdarg.h> /* ANSI varargs stuff */
35#include <setjmp.h> /* for jmp_buf */
36
nethercoteebf1d862004-11-01 18:22:05 +000037#include "basic_types.h"
nethercote13343132004-09-02 15:49:09 +000038#include "tool_asm.h" // asm stuff
nethercotec06e2132004-09-03 13:45:29 +000039#include "tool_arch.h" // arch-specific tool stuff
nethercote73b526f2004-10-31 18:48:21 +000040#include "vki.h"
nethercote37aac2e2004-09-02 08:54:27 +000041
sewardj8b635a42004-11-22 19:01:47 +000042#include "libvex.h"
43#include "libvex_ir.h"
44
nethercote37aac2e2004-09-02 08:54:27 +000045/*====================================================================*/
46/*=== Build options and table sizes. ===*/
47/*====================================================================*/
48
49/* You should be able to change these options or sizes, recompile, and
50 still have a working system. */
51
52/* The maximum number of pthreads that we support. This is
53 deliberately not very high since our implementation of some of the
54 scheduler algorithms is surely O(N) in the number of threads, since
55 that's simple, at least. And (in practice) we hope that most
56 programs do not need many threads. */
57#define VG_N_THREADS 100
58
59/* Maximum number of pthread keys available. Again, we start low until
60 the need for a higher number presents itself. */
61#define VG_N_THREAD_KEYS 50
62
nethercote37aac2e2004-09-02 08:54:27 +000063
64/*====================================================================*/
nethercote2e05c332004-09-06 16:43:37 +000065/*=== Useful macros ===*/
nethercote37aac2e2004-09-02 08:54:27 +000066/*====================================================================*/
67
nethercote37aac2e2004-09-02 08:54:27 +000068#define mycat_wrk(aaa,bbb) aaa##bbb
69#define mycat(aaa,bbb) mycat_wrk(aaa,bbb)
70
71/* No, really. I _am_ that strange. */
72#define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn)
73
nethercote37aac2e2004-09-02 08:54:27 +000074/* Path to all our library/aux files */
75extern const Char *VG_(libdir);
76
77
78/*====================================================================*/
79/*=== Core/tool interface version ===*/
80/*====================================================================*/
81
82/* The major version number indicates binary-incompatible changes to the
83 interface; if the core and tool major versions don't match, Valgrind
84 will abort. The minor version indicates binary-compatible changes.
nethercote836d46c2004-11-18 12:58:53 +000085
86 (Update: as it happens, we're never using the minor version number, because
87 there's no point in doing so.)
nethercote37aac2e2004-09-02 08:54:27 +000088*/
nethercote836d46c2004-11-18 12:58:53 +000089#define VG_CORE_INTERFACE_MAJOR_VERSION 7
nethercote37aac2e2004-09-02 08:54:27 +000090#define VG_CORE_INTERFACE_MINOR_VERSION 0
91
92typedef struct _ToolInfo {
93 Int sizeof_ToolInfo;
94 Int interface_major_version;
95 Int interface_minor_version;
96
97 /* Initialise tool. Must do the following:
98 - initialise the `details' struct, via the VG_(details_*)() functions
99 - register any helpers called by generated code
100
101 May do the following:
102 - initialise the `needs' struct to indicate certain requirements, via
103 the VG_(needs_*)() functions
104 - initialize all the tool's entrypoints via the VG_(init_*)() functions
105 - register any tool-specific profiling events
106 - any other tool-specific initialisation
107 */
njnd2252832004-11-26 10:53:33 +0000108 void (*tl_pre_clo_init) ( void );
nethercote37aac2e2004-09-02 08:54:27 +0000109
110 /* Specifies how big the shadow segment should be as a ratio to the
111 client address space. 0 for no shadow segment. */
112 float shadow_ratio;
113} ToolInfo;
114
115/* Every tool must include this macro somewhere, exactly once. */
116#define VG_DETERMINE_INTERFACE_VERSION(pre_clo_init, shadow) \
njn26f02512004-11-22 18:33:15 +0000117 const ToolInfo TL_(tool_info) = { \
nethercote37aac2e2004-09-02 08:54:27 +0000118 .sizeof_ToolInfo = sizeof(ToolInfo), \
119 .interface_major_version = VG_CORE_INTERFACE_MAJOR_VERSION, \
120 .interface_minor_version = VG_CORE_INTERFACE_MINOR_VERSION, \
njnd2252832004-11-26 10:53:33 +0000121 .tl_pre_clo_init = pre_clo_init, \
nethercote37aac2e2004-09-02 08:54:27 +0000122 .shadow_ratio = shadow, \
123 };
124
125/*====================================================================*/
126/*=== Command-line options ===*/
127/*====================================================================*/
128
129/* Use this for normal null-termination-style string comparison */
130#define VG_STREQ(s1,s2) (s1 != NULL && s2 != NULL \
131 && VG_(strcmp)((s1),(s2))==0)
132
133/* Use these for recognising tool command line options -- stops comparing
134 once whitespace is reached. */
135#define VG_CLO_STREQ(s1,s2) (0==VG_(strcmp_ws)((s1),(s2)))
136#define VG_CLO_STREQN(nn,s1,s2) (0==VG_(strncmp_ws)((s1),(s2),(nn)))
137
138// Higher-level command-line option recognisers; use in if/else chains
139
140#define VG_BOOL_CLO(qq_option, qq_var) \
141 if (VG_CLO_STREQ(arg, qq_option"=yes")) { (qq_var) = True; } \
142 else if (VG_CLO_STREQ(arg, qq_option"=no")) { (qq_var) = False; }
143
144#define VG_STR_CLO(qq_option, qq_var) \
145 if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, arg, qq_option"=")) { \
146 (qq_var) = &arg[ VG_(strlen)(qq_option)+1 ]; \
147 }
148
149#define VG_NUM_CLO(qq_option, qq_var) \
150 if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, arg, qq_option"=")) { \
151 (qq_var) = (Int)VG_(atoll)( &arg[ VG_(strlen)(qq_option)+1 ] ); \
152 }
153
154// Bounded integer arg
155#define VG_BNUM_CLO(qq_option, qq_var, qq_lo, qq_hi) \
156 if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, arg, qq_option"=")) { \
157 (qq_var) = (Int)VG_(atoll)( &arg[ VG_(strlen)(qq_option)+1 ] ); \
158 if ((qq_var) < (qq_lo)) (qq_var) = (qq_lo); \
159 if ((qq_var) > (qq_hi)) (qq_var) = (qq_hi); \
160 }
161
162
163/* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
164extern Int VG_(clo_verbosity);
165
166/* Profile? */
167extern Bool VG_(clo_profile);
168
169/* Call this if a recognised option was bad for some reason.
170 Note: don't use it just because an option was unrecognised -- return 'False'
njn94065fd2004-11-22 19:26:27 +0000171 from TL_(process_cmd_line_option) to indicate that. */
nethercote37aac2e2004-09-02 08:54:27 +0000172extern void VG_(bad_option) ( Char* opt );
173
174/* Client args */
175extern Int VG_(client_argc);
176extern Char** VG_(client_argv);
177
178/* Client environment. Can be inspected with VG_(getenv)() */
179extern Char** VG_(client_envp);
180
181
182/*====================================================================*/
183/*=== Printing messages for the user ===*/
184/*====================================================================*/
185
186/* Print a message prefixed by "??<pid>?? "; '?' depends on the VgMsgKind.
187 Should be used for all user output. */
188
189typedef
190 enum { Vg_UserMsg, /* '?' == '=' */
191 Vg_DebugMsg, /* '?' == '-' */
192 Vg_DebugExtraMsg, /* '?' == '+' */
193 Vg_ClientMsg, /* '?' == '*' */
194 }
195 VgMsgKind;
196
197/* Functions for building a message from multiple parts. */
198extern int VG_(start_msg) ( VgMsgKind kind );
199extern int VG_(add_to_msg) ( Char* format, ... );
200/* Ends and prints the message. Appends a newline. */
201extern int VG_(end_msg) ( void );
202
203/* Send a single-part message. Appends a newline. */
204extern int VG_(message) ( VgMsgKind kind, Char* format, ... );
205extern int VG_(vmessage) ( VgMsgKind kind, Char* format, va_list vargs );
206
207
208/*====================================================================*/
209/*=== Profiling ===*/
210/*====================================================================*/
211
212/* Nb: VGP_(register_profile_event)() relies on VgpUnc being the first one */
213#define VGP_CORE_LIST \
214 /* These ones depend on the core */ \
215 VGP_PAIR(VgpUnc, "unclassified"), \
216 VGP_PAIR(VgpStartup, "startup"), \
217 VGP_PAIR(VgpRun, "running"), \
218 VGP_PAIR(VgpSched, "scheduler"), \
219 VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \
220 VGP_PAIR(VgpCliMalloc, "client malloc/free"), \
221 VGP_PAIR(VgpTranslate, "translate-main"), \
222 VGP_PAIR(VgpToUCode, "to-ucode"), \
223 VGP_PAIR(VgpFromUcode, "from-ucode"), \
224 VGP_PAIR(VgpImprove, "improve"), \
225 VGP_PAIR(VgpESPUpdate, "ESP-update"), \
226 VGP_PAIR(VgpRegAlloc, "reg-alloc"), \
227 VGP_PAIR(VgpLiveness, "liveness-analysis"), \
228 VGP_PAIR(VgpDoLRU, "do-lru"), \
229 VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \
230 VGP_PAIR(VgpExeContext, "exe-context"), \
231 VGP_PAIR(VgpReadSyms, "read-syms"), \
232 VGP_PAIR(VgpSearchSyms, "search-syms"), \
233 VGP_PAIR(VgpAddToT, "add-to-transtab"), \
234 VGP_PAIR(VgpCoreSysWrap, "core-syscall-wrapper"), \
235 VGP_PAIR(VgpDemangle, "demangle"), \
236 VGP_PAIR(VgpCoreCheapSanity, "core-cheap-sanity"), \
237 VGP_PAIR(VgpCoreExpensiveSanity, "core-expensive-sanity"), \
238 /* These ones depend on the tool */ \
239 VGP_PAIR(VgpPreCloInit, "pre-clo-init"), \
240 VGP_PAIR(VgpPostCloInit, "post-clo-init"), \
241 VGP_PAIR(VgpInstrument, "instrument"), \
njn26f02512004-11-22 18:33:15 +0000242 VGP_PAIR(VgpToolSysWrap, "tool-syscall-wrapper"), \
243 VGP_PAIR(VgpToolCheapSanity, "tool-cheap-sanity"), \
244 VGP_PAIR(VgpToolExpensiveSanity, "tool-expensive-sanity"), \
nethercote37aac2e2004-09-02 08:54:27 +0000245 VGP_PAIR(VgpFini, "fini")
246
247#define VGP_PAIR(n,name) n
248typedef enum { VGP_CORE_LIST } VgpCoreCC;
249#undef VGP_PAIR
250
251/* When registering tool profiling events, ensure that the 'n' value is in
252 * the range (VgpFini+1..) */
253extern void VGP_(register_profile_event) ( Int n, Char* name );
254
255extern void VGP_(pushcc) ( UInt cc );
256extern void VGP_(popcc) ( UInt cc );
257
258/* Define them only if they haven't already been defined by vg_profile.c */
259#ifndef VGP_PUSHCC
260# define VGP_PUSHCC(x)
261#endif
262#ifndef VGP_POPCC
263# define VGP_POPCC(x)
264#endif
265
266
267/*====================================================================*/
268/*=== Useful stuff to call from generated code ===*/
269/*====================================================================*/
270
271/* ------------------------------------------------------------------ */
272/* General stuff */
273
274/* 64-bit counter for the number of basic blocks done. */
275extern ULong VG_(bbs_done);
276
njnc6168192004-11-29 13:54:10 +0000277/* Check if an address is aligned */
278#define IS_ALIGNED4_ADDR(aaa_p) (0 == (((Addr)(aaa_p)) & 3))
279#define IS_ALIGNED8_ADDR(aaa_p) (0 == (((Addr)(aaa_p)) & 7))
280#define IS_WORD_ALIGNED_ADDR(aaa_p) (0 == (((Addr)(aaa_p)) & (sizeof(Addr)-1)))
nethercote37aac2e2004-09-02 08:54:27 +0000281
282
283/* ------------------------------------------------------------------ */
284/* Thread-related stuff */
285
286/* Special magic value for an invalid ThreadId. It corresponds to
287 LinuxThreads using zero as the initial value for
288 pthread_mutex_t.__m_owner and pthread_cond_t.__c_waiting. */
289#define VG_INVALID_THREADID ((ThreadId)(0))
290
291/* ThreadIds are simply indices into the VG_(threads)[] array. */
292typedef
293 UInt
294 ThreadId;
295
sewardj2a99cf62004-11-24 10:44:19 +0000296/* Returns the tid of the currently running thread. Only call it when
297 running generated code. It will barf if there is no running thread.
298 Will never return zero.
299*/
300extern ThreadId VG_(get_current_tid) ( void );
nethercote37aac2e2004-09-02 08:54:27 +0000301
sewardj2a99cf62004-11-24 10:44:19 +0000302/* Does the scheduler think we are running generated code right now? */
303extern Bool VG_(running_a_thread) ( void );
nethercote37aac2e2004-09-02 08:54:27 +0000304
305/* Searches through all thread's stacks to see if any match. Returns
306 VG_INVALID_THREADID if none match. */
307extern ThreadId VG_(first_matching_thread_stack)
308 ( Bool (*p) ( Addr stack_min, Addr stack_max, void* d ),
309 void* d );
310
sewardj2a99cf62004-11-24 10:44:19 +0000311/* Get the simulated %esp */
312extern Addr VG_(get_stack_pointer) ( ThreadId tid );
313
nethercote37aac2e2004-09-02 08:54:27 +0000314
315/*====================================================================*/
316/*=== Valgrind's version of libc ===*/
317/*====================================================================*/
318
319/* Valgrind doesn't use libc at all, for good reasons (trust us). So here
320 are its own versions of C library functions, but with VG_ prefixes. Note
321 that the types of some are slightly different to the real ones. Some
322 additional useful functions are provided too; descriptions of how they
323 work are given below. */
324
325#if !defined(NULL)
326# define NULL ((void*)0)
327#endif
328
329
330/* ------------------------------------------------------------------ */
331/* stdio.h
332 *
333 * Note that they all output to the file descriptor given by the
334 * --log-fd/--log-file/--log-socket argument, which defaults to 2 (stderr).
335 * Hence no need for VG_(fprintf)().
336 */
337extern UInt VG_(printf) ( const char *format, ... );
338/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
339extern UInt VG_(sprintf) ( Char* buf, Char *format, ... );
340extern UInt VG_(vprintf) ( void(*send)(Char),
341 const Char *format, va_list vargs );
342
343extern Int VG_(rename) ( Char* old_name, Char* new_name );
344
345/* ------------------------------------------------------------------ */
346/* stdlib.h */
347
nethercote7ac7f7b2004-11-02 12:36:02 +0000348extern void* VG_(malloc) ( SizeT nbytes );
nethercote37aac2e2004-09-02 08:54:27 +0000349extern void VG_(free) ( void* p );
nethercote7ac7f7b2004-11-02 12:36:02 +0000350extern void* VG_(calloc) ( SizeT n, SizeT nbytes );
351extern void* VG_(realloc) ( void* p, SizeT size );
352extern void* VG_(malloc_aligned) ( SizeT align_bytes, SizeT nbytes );
nethercote37aac2e2004-09-02 08:54:27 +0000353
354extern void VG_(print_malloc_stats) ( void );
355
356
357extern void VG_(exit)( Int status )
358 __attribute__ ((__noreturn__));
359/* Prints a panic message (a constant string), appends newline and bug
360 reporting info, aborts. */
361__attribute__ ((__noreturn__))
njn67993252004-11-22 18:02:32 +0000362extern void VG_(tool_panic) ( Char* str );
nethercote37aac2e2004-09-02 08:54:27 +0000363
364/* Looks up VG_(client_envp) */
365extern Char* VG_(getenv) ( Char* name );
366
367/* Get client resource limit*/
368extern Int VG_(getrlimit) ( Int resource, struct vki_rlimit *rlim );
369
370/* Set client resource limit*/
371extern Int VG_(setrlimit) ( Int resource, struct vki_rlimit *rlim );
372
373/* Crude stand-in for the glibc system() call. */
374extern Int VG_(system) ( Char* cmd );
375
376extern Long VG_(atoll) ( Char* str );
377
378/* Like atoll(), but converts a number of base 16 */
379extern Long VG_(atoll16) ( Char* str );
380
381/* Like atoll(), but converts a number of base 2..36 */
382extern Long VG_(atoll36) ( UInt base, Char* str );
383
384/* Like qsort(), but does shell-sort. The size==1/2/4 cases are specialised. */
nethercote928a5f72004-11-03 18:10:37 +0000385extern void VG_(ssort)( void* base, SizeT nmemb, SizeT size,
nethercote37aac2e2004-09-02 08:54:27 +0000386 Int (*compar)(void*, void*) );
387
388
389/* ------------------------------------------------------------------ */
390/* ctype.h */
391extern Bool VG_(isspace) ( Char c );
392extern Bool VG_(isdigit) ( Char c );
393extern Char VG_(toupper) ( Char c );
394
395
396/* ------------------------------------------------------------------ */
397/* string.h */
398extern Int VG_(strlen) ( const Char* str );
399extern Char* VG_(strcat) ( Char* dest, const Char* src );
400extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n );
401extern Char* VG_(strpbrk) ( const Char* s, const Char* accept );
402extern Char* VG_(strcpy) ( Char* dest, const Char* src );
403extern Char* VG_(strncpy) ( Char* dest, const Char* src, Int ndest );
404extern Int VG_(strcmp) ( const Char* s1, const Char* s2 );
405extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax );
406extern Char* VG_(strstr) ( const Char* haystack, Char* needle );
407extern Char* VG_(strchr) ( const Char* s, Char c );
408extern Char* VG_(strrchr) ( const Char* s, Char c );
409extern Char* VG_(strdup) ( const Char* s);
410extern void* VG_(memcpy) ( void *d, const void *s, Int sz );
411extern void* VG_(memset) ( void *s, Int c, Int sz );
412extern Int VG_(memcmp) ( const void* s1, const void* s2, Int n );
413
414/* Like strcmp() and strncmp(), but stop comparing at any whitespace. */
415extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );
416extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax );
417
418/* Like strncpy(), but if 'src' is longer than 'ndest' inserts a '\0' as the
419 last character. */
420extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest );
421
422/* Mini-regexp function. Searches for 'pat' in 'str'. Supports
423 * meta-symbols '*' and '?'. '\' escapes meta-symbols. */
424extern Bool VG_(string_match) ( const Char* pat, const Char* str );
425
426
427/* ------------------------------------------------------------------ */
428/* math.h */
429/* Returns the base-2 logarithm of x. */
430extern Int VG_(log2) ( Int x );
431
432
433/* ------------------------------------------------------------------ */
434/* unistd.h, fcntl.h, sys/stat.h */
435extern Int VG_(getdents)( UInt fd, struct vki_dirent *dirp, UInt count );
436extern Int VG_(readlink)( Char* path, Char* buf, UInt bufsize );
437extern Int VG_(getpid) ( void );
438extern Int VG_(getppid) ( void );
439extern Int VG_(getpgrp) ( void );
440extern Int VG_(gettid) ( void );
441extern Int VG_(setpgid) ( Int pid, Int pgrp );
442
443extern Int VG_(open) ( const Char* pathname, Int flags, Int mode );
444extern Int VG_(read) ( Int fd, void* buf, Int count);
445extern Int VG_(write) ( Int fd, const void* buf, Int count);
nethercote5b9fafd2004-11-04 18:39:22 +0000446extern OffT VG_(lseek) ( Int fd, OffT offset, Int whence);
nethercote37aac2e2004-09-02 08:54:27 +0000447extern void VG_(close) ( Int fd );
448
449extern Int VG_(pipe) ( Int fd[2] );
450
451/* Nb: VG_(rename)() declared in stdio.h section above */
452extern Int VG_(unlink) ( Char* file_name );
453extern Int VG_(stat) ( Char* file_name, struct vki_stat* buf );
454extern Int VG_(fstat) ( Int fd, struct vki_stat* buf );
455extern Int VG_(dup2) ( Int oldfd, Int newfd );
456
nethercote928a5f72004-11-03 18:10:37 +0000457extern Char* VG_(getcwd) ( Char* buf, SizeT size );
nethercote37aac2e2004-09-02 08:54:27 +0000458
459/* Easier to use than VG_(getcwd)() -- does the buffer fiddling itself.
460 String put into 'cwd' is VG_(malloc)'d, and should be VG_(free)'d.
461 Returns False if it fails. Will fail if the pathname is > 65535 bytes. */
462extern Bool VG_(getcwd_alloc) ( Char** cwd );
463
464/* ------------------------------------------------------------------ */
465/* assert.h */
466/* Asserts permanently enabled -- no turning off with NDEBUG. Hurrah! */
467#define VG__STRING(__str) #__str
468
njnca82cc02004-11-22 17:18:48 +0000469#define tl_assert(expr) \
nethercote37aac2e2004-09-02 08:54:27 +0000470 ((void) ((expr) ? 0 : \
njn94065fd2004-11-22 19:26:27 +0000471 (VG_(tool_assert_fail) (VG__STRING(expr), \
nethercote37aac2e2004-09-02 08:54:27 +0000472 __FILE__, __LINE__, \
473 __PRETTY_FUNCTION__), 0)))
474
475__attribute__ ((__noreturn__))
njn94065fd2004-11-22 19:26:27 +0000476extern void VG_(tool_assert_fail) ( const Char* expr, const Char* file,
nethercote37aac2e2004-09-02 08:54:27 +0000477 Int line, const Char* fn );
478
479
480/* ------------------------------------------------------------------ */
481/* Get memory by anonymous mmap. */
nethercote8b5f40c2004-11-02 13:29:50 +0000482extern void* VG_(get_memory_from_mmap) ( SizeT nBytes, Char* who );
nethercote37aac2e2004-09-02 08:54:27 +0000483
484extern Bool VG_(is_client_addr) (Addr a);
485extern Addr VG_(get_client_base)(void);
486extern Addr VG_(get_client_end) (void);
487extern Addr VG_(get_client_size)(void);
488
489extern Bool VG_(is_shadow_addr) (Addr a);
490extern Addr VG_(get_shadow_base)(void);
491extern Addr VG_(get_shadow_end) (void);
492extern Addr VG_(get_shadow_size)(void);
493
494extern void *VG_(shadow_alloc)(UInt size);
495
nethercote928a5f72004-11-03 18:10:37 +0000496extern Bool VG_(is_addressable)(Addr p, SizeT sz);
nethercote37aac2e2004-09-02 08:54:27 +0000497
nethercote928a5f72004-11-03 18:10:37 +0000498extern Addr VG_(client_alloc)(Addr base, SizeT len, UInt prot, UInt flags);
nethercote37aac2e2004-09-02 08:54:27 +0000499extern void VG_(client_free)(Addr addr);
500
501extern Bool VG_(is_valgrind_addr)(Addr a);
502
503/* initialize shadow pages in the range [p, p+sz) This calls
504 init_shadow_page for each one. It should be a lot more efficient
505 for bulk-initializing shadow pages than faulting on each one.
506*/
507extern void VG_(init_shadow_range)(Addr p, UInt sz, Bool call_init);
508
509/* ------------------------------------------------------------------ */
510/* signal.h.
511
512 Note that these use the vk_ (kernel) structure
513 definitions, which are different in places from those that glibc
nethercote73b526f2004-10-31 18:48:21 +0000514 defines. Since we're operating right at the kernel interface, glibc's view
515 of the world is entirely irrelevant. */
nethercote37aac2e2004-09-02 08:54:27 +0000516
517/* --- Signal set ops --- */
nethercote73b526f2004-10-31 18:48:21 +0000518extern Int VG_(sigfillset) ( vki_sigset_t* set );
519extern Int VG_(sigemptyset) ( vki_sigset_t* set );
nethercote37aac2e2004-09-02 08:54:27 +0000520
nethercote73b526f2004-10-31 18:48:21 +0000521extern Bool VG_(isfullsigset) ( vki_sigset_t* set );
522extern Bool VG_(isemptysigset) ( vki_sigset_t* set );
nethercote37aac2e2004-09-02 08:54:27 +0000523
nethercote73b526f2004-10-31 18:48:21 +0000524extern Int VG_(sigaddset) ( vki_sigset_t* set, Int signum );
525extern Int VG_(sigdelset) ( vki_sigset_t* set, Int signum );
526extern Int VG_(sigismember) ( vki_sigset_t* set, Int signum );
nethercote37aac2e2004-09-02 08:54:27 +0000527
nethercote73b526f2004-10-31 18:48:21 +0000528extern void VG_(sigaddset_from_set) ( vki_sigset_t* dst, vki_sigset_t* src );
529extern void VG_(sigdelset_from_set) ( vki_sigset_t* dst, vki_sigset_t* src );
nethercote37aac2e2004-09-02 08:54:27 +0000530
531/* --- Mess with the kernel's sig state --- */
nethercote73b526f2004-10-31 18:48:21 +0000532extern Int VG_(sigprocmask) ( Int how, const vki_sigset_t* set,
533 vki_sigset_t* oldset );
534extern Int VG_(sigaction) ( Int signum,
535 const struct vki_sigaction* act,
536 struct vki_sigaction* oldact );
nethercote37aac2e2004-09-02 08:54:27 +0000537
nethercote73b526f2004-10-31 18:48:21 +0000538extern Int VG_(sigtimedwait)( const vki_sigset_t *, vki_siginfo_t *,
539 const struct vki_timespec * );
nethercote37aac2e2004-09-02 08:54:27 +0000540
nethercote73b526f2004-10-31 18:48:21 +0000541extern Int VG_(signal) ( Int signum, void (*sighandler)(Int) );
542extern Int VG_(sigaltstack) ( const vki_stack_t* ss, vki_stack_t* oss );
nethercote37aac2e2004-09-02 08:54:27 +0000543
nethercote73b526f2004-10-31 18:48:21 +0000544extern Int VG_(kill) ( Int pid, Int signo );
njnc6168192004-11-29 13:54:10 +0000545extern Int VG_(tkill) ( ThreadId tid, Int signo );
nethercote73b526f2004-10-31 18:48:21 +0000546extern Int VG_(sigpending) ( vki_sigset_t* set );
nethercote37aac2e2004-09-02 08:54:27 +0000547
nethercote73b526f2004-10-31 18:48:21 +0000548extern Int VG_(waitpid) ( Int pid, Int *status, Int options );
nethercote37aac2e2004-09-02 08:54:27 +0000549
550/* ------------------------------------------------------------------ */
551/* socket.h. */
552
553extern Int VG_(getsockname) ( Int sd, struct vki_sockaddr *name, Int *namelen);
554extern Int VG_(getpeername) ( Int sd, struct vki_sockaddr *name, Int *namelen);
555extern Int VG_(getsockopt) ( Int sd, Int level, Int optname, void *optval,
556 Int *optlen);
557
558/* ------------------------------------------------------------------ */
559/* other, randomly useful functions */
560extern UInt VG_(read_millisecond_timer) ( void );
561
562extern void VG_(cpuid) ( UInt eax,
563 UInt *eax_ret, UInt *ebx_ret,
564 UInt *ecx_ret, UInt *edx_ret );
565
nethercote37aac2e2004-09-02 08:54:27 +0000566/*====================================================================*/
567/*=== Execution contexts ===*/
568/*====================================================================*/
569
570/* Generic resolution type used in a few different ways, such as deciding
571 how closely to compare two errors for equality. */
572typedef
573 enum { Vg_LowRes, Vg_MedRes, Vg_HighRes }
574 VgRes;
575
576typedef
577 struct _ExeContext
578 ExeContext;
579
580/* Compare two ExeContexts. Number of callers considered depends on `res':
581 Vg_LowRes: 2
582 Vg_MedRes: 4
583 Vg_HighRes: all */
584extern Bool VG_(eq_ExeContext) ( VgRes res,
585 ExeContext* e1, ExeContext* e2 );
586
587/* Print an ExeContext. */
588extern void VG_(pp_ExeContext) ( ExeContext* );
589
590/* Take a snapshot of the client's stack. Search our collection of
591 ExeContexts to see if we already have it, and if not, allocate a
592 new one. Either way, return a pointer to the context. Context size
593 controlled by --num-callers option.
594
595 If called from generated code, use VG_(get_current_tid)() to get the
596 current ThreadId. If called from non-generated code, the current
597 ThreadId should be passed in by the core.
598*/
599extern ExeContext* VG_(get_ExeContext) ( ThreadId tid );
600
nethercote86c5dcb2004-09-05 21:32:37 +0000601/* Get the nth IP from the ExeContext. 0 is the IP of the top function, 1
nethercote37aac2e2004-09-02 08:54:27 +0000602 is its caller, etc. Returns 0 if there isn't one, or if n is greater
603 than VG_(clo_backtrace_size), set by the --num-callers option. */
604extern Addr VG_(get_EIP_from_ExeContext) ( ExeContext* e, UInt n );
605
nethercote86c5dcb2004-09-05 21:32:37 +0000606/* Just grab the client's IP, as a much smaller and cheaper
nethercote37aac2e2004-09-02 08:54:27 +0000607 indication of where they are. Use is basically same as for
608 VG_(get_ExeContext)() above.
609*/
610extern Addr VG_(get_EIP)( ThreadId tid );
611
612/* For tools needing more control over stack traces: walks the stack to get
nethercote86c5dcb2004-09-05 21:32:37 +0000613 instruction pointers from the top stack frames for thread 'tid'. Maximum of
614 'n_ips' addresses put into 'ips'; 0 is the top of the stack, 1 is its
615 caller, etc. */
616extern UInt VG_(stack_snapshot) ( ThreadId tid, Addr* ips, UInt n_ips );
nethercote37aac2e2004-09-02 08:54:27 +0000617
618/* Does the same thing as VG_(pp_ExeContext)(), just with slightly
619 different input. */
nethercote86c5dcb2004-09-05 21:32:37 +0000620extern void VG_(mini_stack_dump) ( Addr ips[], UInt n_ips );
nethercote37aac2e2004-09-02 08:54:27 +0000621
622
623/*====================================================================*/
624/*=== Error reporting ===*/
625/*====================================================================*/
626
627/* ------------------------------------------------------------------ */
628/* Suppressions describe errors which we want to suppress, ie, not
629 show the user, usually because it is caused by a problem in a library
630 which we can't fix, replace or work around. Suppressions are read from
631 a file at startup time. This gives flexibility so that new
632 suppressions can be added to the file as and when needed.
633*/
634
635typedef
636 Int /* Do not make this unsigned! */
637 SuppKind;
638
639/* The tool-relevant parts of a suppression are:
640 kind: what kind of suppression; must be in the range (0..)
641 string: use is optional. NULL by default.
642 extra: use is optional. NULL by default. void* so it's extensible.
643*/
644typedef
645 struct _Supp
646 Supp;
647
njn26f02512004-11-22 18:33:15 +0000648/* Useful in TL_(error_matches_suppression)() */
nethercote37aac2e2004-09-02 08:54:27 +0000649SuppKind VG_(get_supp_kind) ( Supp* su );
650Char* VG_(get_supp_string) ( Supp* su );
651void* VG_(get_supp_extra) ( Supp* su );
652
653/* Must be used in VG_(recognised_suppression)() */
654void VG_(set_supp_kind) ( Supp* su, SuppKind suppkind );
655/* May be used in VG_(read_extra_suppression_info)() */
656void VG_(set_supp_string) ( Supp* su, Char* string );
657void VG_(set_supp_extra) ( Supp* su, void* extra );
658
659
660/* ------------------------------------------------------------------ */
661/* Error records contain enough info to generate an error report. The idea
662 is that (typically) the same few points in the program generate thousands
663 of errors, and we don't want to spew out a fresh error message for each
664 one. Instead, we use these structures to common up duplicates.
665*/
666
667typedef
668 Int /* Do not make this unsigned! */
669 ErrorKind;
670
671/* The tool-relevant parts of an Error are:
672 kind: what kind of error; must be in the range (0..)
673 addr: use is optional. 0 by default.
674 string: use is optional. NULL by default.
675 extra: use is optional. NULL by default. void* so it's extensible.
676*/
677typedef
678 struct _Error
679 Error;
680
njn26f02512004-11-22 18:33:15 +0000681/* Useful in TL_(error_matches_suppression)(), TL_(pp_Error)(), etc */
nethercote37aac2e2004-09-02 08:54:27 +0000682ExeContext* VG_(get_error_where) ( Error* err );
683SuppKind VG_(get_error_kind) ( Error* err );
684Addr VG_(get_error_address) ( Error* err );
685Char* VG_(get_error_string) ( Error* err );
686void* VG_(get_error_extra) ( Error* err );
687
688/* Call this when an error occurs. It will be recorded if it hasn't been
689 seen before. If it has, the existing error record will have its count
690 incremented.
691
692 'tid' can be found as for VG_(get_ExeContext)(). The `extra' field can
693 be stack-allocated; it will be copied by the core if needed (but it
694 won't be copied if it's NULL).
695
696 If no 'a', 's' or 'extra' of interest needs to be recorded, just use
697 NULL for them. */
698extern void VG_(maybe_record_error) ( ThreadId tid, ErrorKind ekind,
699 Addr a, Char* s, void* extra );
700
701/* Similar to VG_(maybe_record_error)(), except this one doesn't record the
702 error -- useful for errors that can only happen once. The errors can be
703 suppressed, though. Return value is True if it was suppressed.
704 `print_error' dictates whether to print the error, which is a bit of a
705 hack that's useful sometimes if you just want to know if the error would
706 be suppressed without possibly printing it. `count_error' dictates
707 whether to add the error in the error total count (another mild hack). */
708extern Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind,
709 Addr a, Char* s, void* extra,
710 ExeContext* where, Bool print_error,
711 Bool allow_GDB_attach, Bool count_error );
712
713/* Gets a non-blank, non-comment line of at most nBuf chars from fd.
714 Skips leading spaces on the line. Returns True if EOF was hit instead.
715 Useful for reading in extra tool-specific suppression lines. */
716extern Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf );
717
718
719/*====================================================================*/
720/*=== Obtaining debug information ===*/
721/*====================================================================*/
722
723/* Get the file/function/line number of the instruction at address
724 'a'. For these four, if debug info for the address is found, it
725 copies the info into the buffer/UInt and returns True. If not, it
726 returns False and nothing is copied. VG_(get_fnname) always
727 demangles C++ function names. VG_(get_fnname_w_offset) is the
728 same, except it appends "+N" to symbol names to indicate offsets. */
729extern Bool VG_(get_filename) ( Addr a, Char* filename, Int n_filename );
730extern Bool VG_(get_fnname) ( Addr a, Char* fnname, Int n_fnname );
731extern Bool VG_(get_linenum) ( Addr a, UInt* linenum );
732extern Bool VG_(get_fnname_w_offset)
733 ( Addr a, Char* fnname, Int n_fnname );
734
735/* This one is more efficient if getting both filename and line number,
736 because the two lookups are done together. */
737extern Bool VG_(get_filename_linenum)
738 ( Addr a, Char* filename, Int n_filename,
739 UInt* linenum );
740
741/* Succeeds only if we find from debug info that 'a' is the address of the
742 first instruction in a function -- as opposed to VG_(get_fnname) which
743 succeeds if we find from debug info that 'a' is the address of any
744 instruction in a function. Use this to instrument the start of
745 a particular function. Nb: if an executable/shared object is stripped
746 of its symbols, this function will not be able to recognise function
747 entry points within it. */
748extern Bool VG_(get_fnname_if_entry) ( Addr a, Char* fnname, Int n_fnname );
749
750/* Succeeds if the address is within a shared object or the main executable.
751 It doesn't matter if debug info is present or not. */
752extern Bool VG_(get_objname) ( Addr a, Char* objname, Int n_objname );
753
754/* Puts into 'buf' info about the code address %eip: the address, function
755 name (if known) and filename/line number (if known), like this:
756
757 0x4001BF05: realloc (vg_replace_malloc.c:339)
758
759 'n_buf' gives length of 'buf'. Returns 'buf'.
760*/
761extern Char* VG_(describe_eip)(Addr eip, Char* buf, Int n_buf);
762
763/* Returns a string containing an expression for the given
764 address. String is malloced with VG_(malloc)() */
765Char *VG_(describe_addr)(ThreadId, Addr);
766
767/* A way to get information about what segments are mapped */
768typedef struct _SegInfo SegInfo;
769
770/* Returns NULL if the SegInfo isn't found. It doesn't matter if debug info
771 is present or not. */
772extern SegInfo* VG_(get_obj) ( Addr a );
773
774extern const SegInfo* VG_(next_seginfo) ( const SegInfo *seg );
775extern Addr VG_(seg_start) ( const SegInfo *seg );
nethercote928a5f72004-11-03 18:10:37 +0000776extern SizeT VG_(seg_size) ( const SegInfo *seg );
nethercote37aac2e2004-09-02 08:54:27 +0000777extern const UChar* VG_(seg_filename) ( const SegInfo *seg );
nethercote928a5f72004-11-03 18:10:37 +0000778extern ULong VG_(seg_sym_offset)( const SegInfo *seg );
nethercote37aac2e2004-09-02 08:54:27 +0000779
780typedef
781 enum {
782 Vg_SectUnknown,
783 Vg_SectText,
784 Vg_SectData,
785 Vg_SectBSS,
786 Vg_SectGOT,
787 Vg_SectPLT,
788 }
789 VgSectKind;
790
791extern VgSectKind VG_(seg_sect_kind)(Addr);
792
nethercote37aac2e2004-09-02 08:54:27 +0000793/*====================================================================*/
794/*=== Generic hash table ===*/
795/*====================================================================*/
796
797/* Generic type for a separately-chained hash table. Via a kind of dodgy
798 C-as-C++ style inheritance, tools can extend the VgHashNode type, so long
799 as the first two fields match the sizes of these two fields. Requires
800 a bit of casting by the tool. */
801typedef
802 struct _VgHashNode {
803 struct _VgHashNode * next;
nethercote3d6b6112004-11-04 16:39:43 +0000804 UWord key;
nethercote37aac2e2004-09-02 08:54:27 +0000805 }
806 VgHashNode;
807
808typedef
809 VgHashNode**
810 VgHashTable;
811
812/* Make a new table. */
813extern VgHashTable VG_(HT_construct) ( void );
814
815/* Count the number of nodes in a table. */
816extern Int VG_(HT_count_nodes) ( VgHashTable table );
817
818/* Add a node to the table. */
819extern void VG_(HT_add_node) ( VgHashTable t, VgHashNode* node );
820
821/* Looks up a node in the hash table. Also returns the address of the
822 previous node's `next' pointer which allows it to be removed from the
823 list later without having to look it up again. */
nethercote3d6b6112004-11-04 16:39:43 +0000824extern VgHashNode* VG_(HT_get_node) ( VgHashTable t, UWord key,
nethercote37aac2e2004-09-02 08:54:27 +0000825 /*OUT*/VgHashNode*** next_ptr );
826
827/* Allocates an array of pointers to all the shadow chunks of malloc'd
828 blocks. Must be freed with VG_(free)(). */
829extern VgHashNode** VG_(HT_to_array) ( VgHashTable t, /*OUT*/ UInt* n_shadows );
830
831/* Returns first node that matches predicate `p', or NULL if none do.
832 Extra arguments can be implicitly passed to `p' using `d' which is an
833 opaque pointer passed to `p' each time it is called. */
834extern VgHashNode* VG_(HT_first_match) ( VgHashTable t,
835 Bool (*p)(VgHashNode*, void*),
836 void* d );
837
838/* Applies a function f() once to each node. Again, `d' can be used
839 to pass extra information to the function. */
840extern void VG_(HT_apply_to_all_nodes)( VgHashTable t,
841 void (*f)(VgHashNode*, void*),
842 void* d );
843
844/* Destroy a table. */
845extern void VG_(HT_destruct) ( VgHashTable t );
846
847
848/*====================================================================*/
849/*=== A generic skiplist ===*/
850/*====================================================================*/
851
852/*
853 The idea here is that the skiplist puts its per-element data at the
854 end of the structure. When you initialize the skiplist, you tell
855 it what structure your list elements are going to be. Then you
856 should allocate them with VG_(SkipNode_Alloc), which will allocate
857 enough memory for the extra bits.
858 */
nethercote37aac2e2004-09-02 08:54:27 +0000859
860typedef struct _SkipList SkipList;
861typedef struct _SkipNode SkipNode;
862
863typedef Int (*SkipCmp_t)(const void *key1, const void *key2);
864
865struct _SkipList {
866 const Short arena; /* allocation arena */
867 const UShort size; /* structure size (not including SkipNode) */
868 const UShort keyoff; /* key offset */
869 const SkipCmp_t cmp; /* compare two keys */
870 Char * (*strkey)(void *); /* stringify a key (for debugging) */
871 SkipNode *head; /* list head */
872};
873
874/* Use this macro to initialize your skiplist head. The arguments are pretty self explanitory:
875 _type is the type of your element structure
876 _key is the field within that type which you want to use as the key
877 _cmp is the comparison function for keys - it gets two typeof(_key) pointers as args
878 _strkey is a function which can return a string of your key - it's only used for debugging
879 _arena is the arena to use for allocation - -1 is the default
880 */
881#define SKIPLIST_INIT(_type, _key, _cmp, _strkey, _arena) \
882 { \
883 .arena = _arena, \
884 .size = sizeof(_type), \
885 .keyoff = offsetof(_type, _key), \
886 .cmp = _cmp, \
887 .strkey = _strkey, \
888 .head = NULL, \
889 }
890
891/* List operations:
892 SkipList_Find searchs a list. If it can't find an exact match, it either
893 returns NULL or a pointer to the element before where k would go
894 SkipList_Insert inserts a new element into the list. Duplicates are
895 forbidden. The element must have been created with SkipList_Alloc!
896 SkipList_Remove removes an element from the list and returns it. It
897 doesn't free the memory.
898*/
899extern void *VG_(SkipList_Find) (const SkipList *l, void *key);
900extern void VG_(SkipList_Insert)( SkipList *l, void *data);
901extern void *VG_(SkipList_Remove)( SkipList *l, void *key);
902
903/* Node (element) operations:
904 SkipNode_Alloc: allocate memory for a new element on the list. Must be
905 used before an element can be inserted! Returns NULL if not enough
906 memory.
907 SkipNode_Free: free memory allocated above
908 SkipNode_First: return the first element on the list
909 SkipNode_Next: return the next element after "data" on the list -
910 NULL for none
911
912 You can iterate through a SkipList like this:
913
914 for(x = VG_(SkipNode_First)(&list); // or SkipList_Find
915 x != NULL;
916 x = VG_(SkipNode_Next)(&list, x)) { ... }
917*/
918extern void *VG_(SkipNode_Alloc) (const SkipList *l);
919extern void VG_(SkipNode_Free) (const SkipList *l, void *p);
920extern void *VG_(SkipNode_First) (const SkipList *l);
921extern void *VG_(SkipNode_Next) (const SkipList *l, void *data);
922
njnabb14ad2004-11-24 16:57:16 +0000923
nethercote37aac2e2004-09-02 08:54:27 +0000924/*====================================================================*/
925/*=== Functions for shadow registers ===*/
926/*====================================================================*/
927
njnabb14ad2004-11-24 16:57:16 +0000928// For get/set, 'area' is where the asked-for shadow state will be copied
929// into/from.
930extern void VG_(get_shadow_regs_area) ( ThreadId tid, OffT guest_state_offset,
931 SizeT size, UChar* area );
932extern void VG_(set_shadow_regs_area) ( ThreadId tid, OffT guest_state_offset,
933 SizeT size, const UChar* area );
nethercote37aac2e2004-09-02 08:54:27 +0000934
935/* This one lets you override the shadow of the return value register for a
njn26f02512004-11-22 18:33:15 +0000936 syscall. Call it from TL_(post_syscall)() (not TL_(pre_syscall)()!) to
nethercote37aac2e2004-09-02 08:54:27 +0000937 override the default shadow register value. */
938extern void VG_(set_return_from_syscall_shadow) ( ThreadId tid,
njncf45fd42004-11-24 16:30:22 +0000939 UWord ret_shadow );
nethercote37aac2e2004-09-02 08:54:27 +0000940
njn26f02512004-11-22 18:33:15 +0000941/* This can be called from TL_(fini)() to find the shadow of the argument
nethercote37aac2e2004-09-02 08:54:27 +0000942 to exit(), ie. the shadow of the program's return value. */
sewardj2a99cf62004-11-24 10:44:19 +0000943extern UInt VG_(get_exit_status_shadow) ( ThreadId );
nethercote37aac2e2004-09-02 08:54:27 +0000944
945
946/*====================================================================*/
947/*=== Specific stuff for replacing malloc() and friends ===*/
948/*====================================================================*/
949
950/* If a tool replaces malloc() et al, the easiest way to do so is to
951 link with vg_replace_malloc.o into its vgpreload_*.so file, and
952 follow the following instructions. You can do it from scratch,
953 though, if you enjoy that sort of thing. */
954
955/* Arena size for valgrind's own malloc(); default value is 0, but can
956 be overridden by tool -- but must be done so *statically*, eg:
957
nethercote7ac7f7b2004-11-02 12:36:02 +0000958 UInt VG_(vg_malloc_redzone_szB) = 4;
nethercote37aac2e2004-09-02 08:54:27 +0000959
njn26f02512004-11-22 18:33:15 +0000960 It can't be done from a function like TL_(pre_clo_init)(). So it can't,
nethercote37aac2e2004-09-02 08:54:27 +0000961 for example, be controlled with a command line option, unfortunately. */
962extern UInt VG_(vg_malloc_redzone_szB);
963
njn26f02512004-11-22 18:33:15 +0000964/* Can be called from TL_(malloc) et al to do the actual alloc/freeing. */
nethercote7ac7f7b2004-11-02 12:36:02 +0000965extern void* VG_(cli_malloc) ( SizeT align, SizeT nbytes );
nethercote37aac2e2004-09-02 08:54:27 +0000966extern void VG_(cli_free) ( void* p );
967
968/* Check if an address is within a range, allowing for redzones at edges */
nethercote7ac7f7b2004-11-02 12:36:02 +0000969extern Bool VG_(addr_is_in_block)( Addr a, Addr start, SizeT size );
nethercote37aac2e2004-09-02 08:54:27 +0000970
971/* ------------------------------------------------------------------ */
972/* Some options that can be used by a tool if malloc() et al are replaced.
973 The tool should call the functions in the appropriate places to give
974 control over these aspects of Valgrind's version of malloc(). */
975
976/* Round malloc sizes upwards to integral number of words? default: NO */
977extern Bool VG_(clo_sloppy_malloc);
978/* DEBUG: print malloc details? default: NO */
979extern Bool VG_(clo_trace_malloc);
980/* Minimum alignment in functions that don't specify alignment explicitly.
981 default: 0, i.e. use default of the machine (== 4) */
nethercote7ac7f7b2004-11-02 12:36:02 +0000982extern UInt VG_(clo_alignment);
nethercote37aac2e2004-09-02 08:54:27 +0000983
984extern Bool VG_(replacement_malloc_process_cmd_line_option) ( Char* arg );
985extern void VG_(replacement_malloc_print_usage) ( void );
986extern void VG_(replacement_malloc_print_debug_usage) ( void );
987
988
989/*====================================================================*/
990/*=== Tool-specific stuff ===*/
991/*====================================================================*/
992
993/* ------------------------------------------------------------------ */
994/* Details */
995
996/* Default value for avg_translations_sizeB (in bytes), indicating typical
997 code expansion of about 6:1. */
998#define VG_DEFAULT_TRANS_SIZEB 100
999
1000/* Information used in the startup message. `name' also determines the
1001 string used for identifying suppressions in a suppression file as
1002 belonging to this tool. `version' can be NULL, in which case (not
1003 surprisingly) no version info is printed; this mechanism is designed for
1004 tools distributed with Valgrind that share a version number with
1005 Valgrind. Other tools not distributed as part of Valgrind should
1006 probably have their own version number. */
1007extern void VG_(details_name) ( Char* name );
1008extern void VG_(details_version) ( Char* version );
1009extern void VG_(details_description) ( Char* description );
1010extern void VG_(details_copyright_author) ( Char* copyright_author );
1011
1012/* Average size of a translation, in bytes, so that the translation
1013 storage machinery can allocate memory appropriately. Not critical,
1014 setting is optional. */
1015extern void VG_(details_avg_translation_sizeB) ( UInt size );
1016
njn67993252004-11-22 18:02:32 +00001017/* String printed if an `tl_assert' assertion fails or VG_(tool_panic)
nethercote37aac2e2004-09-02 08:54:27 +00001018 is called. Should probably be an email address. */
1019extern void VG_(details_bug_reports_to) ( Char* bug_reports_to );
1020
1021/* ------------------------------------------------------------------ */
1022/* Needs */
1023
1024/* Booleans that decide core behaviour, but don't require extra
1025 operations to be defined if `True' */
1026
1027/* Should __libc_freeres() be run? Bugs in it can crash the tool. */
1028extern void VG_(needs_libc_freeres) ( void );
1029
1030/* Want to have errors detected by Valgrind's core reported? Includes:
1031 - pthread API errors (many; eg. unlocking a non-locked mutex)
1032 - invalid file descriptors to blocking syscalls read() and write()
1033 - bad signal numbers passed to sigaction()
1034 - attempt to install signal handler for SIGKILL or SIGSTOP */
1035extern void VG_(needs_core_errors) ( void );
1036
1037/* Booleans that indicate extra operations are defined; if these are True,
1038 the corresponding template functions (given below) must be defined. A
1039 lot like being a member of a type class. */
1040
1041/* Want to report errors from tool? This implies use of suppressions, too. */
njn95ec8702004-11-22 16:46:13 +00001042extern void VG_(needs_tool_errors) ( void );
nethercote37aac2e2004-09-02 08:54:27 +00001043
1044/* Is information kept about specific individual basic blocks? (Eg. for
1045 cachegrind there are cost-centres for every instruction, stored at a
1046 basic block level.) If so, it sometimes has to be discarded, because
1047 .so mmap/munmap-ping or self-modifying code (informed by the
1048 DISCARD_TRANSLATIONS user request) can cause one instruction address
1049 to be used for more than one instruction in one program run... */
1050extern void VG_(needs_basic_block_discards) ( void );
1051
nethercote37aac2e2004-09-02 08:54:27 +00001052/* Tool defines its own command line options? */
1053extern void VG_(needs_command_line_options) ( void );
1054
1055/* Tool defines its own client requests? */
1056extern void VG_(needs_client_requests) ( void );
1057
nethercote37aac2e2004-09-02 08:54:27 +00001058/* Tool does stuff before and/or after system calls? */
1059extern void VG_(needs_syscall_wrapper) ( void );
1060
1061/* Are tool-state sanity checks performed? */
1062extern void VG_(needs_sanity_checks) ( void );
1063
1064/* Do we need to see data symbols? */
1065extern void VG_(needs_data_syms) ( void );
1066
1067/* Does the tool need shadow memory allocated (if you set this, you must also statically initialize
njn26f02512004-11-22 18:33:15 +00001068 float TL_(shadow_ratio) = n./m;
nethercote37aac2e2004-09-02 08:54:27 +00001069 to define how many shadow bits you need per client address space bit.
1070*/
1071extern void VG_(needs_shadow_memory)( void );
njn26f02512004-11-22 18:33:15 +00001072extern float TL_(shadow_ratio);
nethercote37aac2e2004-09-02 08:54:27 +00001073
1074/* ------------------------------------------------------------------ */
1075/* Core events to track */
1076
1077/* Part of the core from which this call was made. Useful for determining
1078 what kind of error message should be emitted. */
1079typedef
njncf45fd42004-11-24 16:30:22 +00001080 enum { Vg_CoreStartup, Vg_CorePThread, Vg_CoreSignal, Vg_CoreSysCall,
1081 Vg_CoreTranslate, Vg_CoreClientReq }
nethercote37aac2e2004-09-02 08:54:27 +00001082 CorePart;
1083
1084/* Useful to use in VG_(get_Xreg_usage)() */
1085#define VG_UINSTR_READS_REG(ono,regs,isWrites) \
1086 { if (mycat(u->tag,ono) == tag) \
1087 { regs[n] = mycat(u->val,ono); \
1088 isWrites[n] = False; \
1089 n++; \
1090 } \
1091 }
1092#define VG_UINSTR_WRITES_REG(ono,regs,isWrites) \
1093 { if (mycat(u->tag,ono) == tag) \
1094 { regs[n] = mycat(u->val,ono); \
1095 isWrites[n] = True; \
1096 n++; \
1097 } \
1098 }
1099
1100#endif /* NDEF __TOOL_H */
1101
1102/* gen_toolint.pl will put the VG_(init_*)() functions here: */