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