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