sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- C startup stuff, reached from vg_startup.S. ---*/ |
| 4 | /*--- vg_main.c ---*/ |
| 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame] | 8 | This file is part of Valgrind, an extensible x86 protected-mode |
| 9 | emulator for monitoring program execution on x86-Unixes. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 10 | |
njn | 0e1b514 | 2003-04-15 14:58:06 +0000 | [diff] [blame] | 11 | Copyright (C) 2000-2003 Julian Seward |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 12 | jseward@acm.org |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 13 | |
| 14 | This program is free software; you can redistribute it and/or |
| 15 | modify it under the terms of the GNU General Public License as |
| 16 | published by the Free Software Foundation; either version 2 of the |
| 17 | License, or (at your option) any later version. |
| 18 | |
| 19 | This program is distributed in the hope that it will be useful, but |
| 20 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | General Public License for more details. |
| 23 | |
| 24 | You should have received a copy of the GNU General Public License |
| 25 | along with this program; if not, write to the Free Software |
| 26 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 27 | 02111-1307, USA. |
| 28 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 29 | The GNU General Public License is contained in the file COPYING. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 30 | */ |
| 31 | |
| 32 | #include "vg_include.h" |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 33 | |
| 34 | /* --------------------------------------------------------------------- |
| 35 | Compute offsets into baseBlock. See comments in vg_include.h. |
| 36 | ------------------------------------------------------------------ */ |
| 37 | |
| 38 | /* The variables storing offsets. */ |
| 39 | |
| 40 | #define INVALID_OFFSET (-1) |
| 41 | |
| 42 | Int VGOFF_(m_eax) = INVALID_OFFSET; |
| 43 | Int VGOFF_(m_ecx) = INVALID_OFFSET; |
| 44 | Int VGOFF_(m_edx) = INVALID_OFFSET; |
| 45 | Int VGOFF_(m_ebx) = INVALID_OFFSET; |
| 46 | Int VGOFF_(m_esp) = INVALID_OFFSET; |
| 47 | Int VGOFF_(m_ebp) = INVALID_OFFSET; |
| 48 | Int VGOFF_(m_esi) = INVALID_OFFSET; |
| 49 | Int VGOFF_(m_edi) = INVALID_OFFSET; |
| 50 | Int VGOFF_(m_eflags) = INVALID_OFFSET; |
sewardj | fa492d4 | 2002-12-08 18:20:01 +0000 | [diff] [blame] | 51 | Int VGOFF_(m_dflag) = INVALID_OFFSET; |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 52 | Int VGOFF_(m_ssestate) = INVALID_OFFSET; |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 53 | Int VGOFF_(ldt) = INVALID_OFFSET; |
| 54 | Int VGOFF_(m_cs) = INVALID_OFFSET; |
| 55 | Int VGOFF_(m_ss) = INVALID_OFFSET; |
| 56 | Int VGOFF_(m_ds) = INVALID_OFFSET; |
| 57 | Int VGOFF_(m_es) = INVALID_OFFSET; |
| 58 | Int VGOFF_(m_fs) = INVALID_OFFSET; |
| 59 | Int VGOFF_(m_gs) = INVALID_OFFSET; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 60 | Int VGOFF_(m_eip) = INVALID_OFFSET; |
| 61 | Int VGOFF_(spillslots) = INVALID_OFFSET; |
| 62 | Int VGOFF_(sh_eax) = INVALID_OFFSET; |
| 63 | Int VGOFF_(sh_ecx) = INVALID_OFFSET; |
| 64 | Int VGOFF_(sh_edx) = INVALID_OFFSET; |
| 65 | Int VGOFF_(sh_ebx) = INVALID_OFFSET; |
| 66 | Int VGOFF_(sh_esp) = INVALID_OFFSET; |
| 67 | Int VGOFF_(sh_ebp) = INVALID_OFFSET; |
| 68 | Int VGOFF_(sh_esi) = INVALID_OFFSET; |
| 69 | Int VGOFF_(sh_edi) = INVALID_OFFSET; |
| 70 | Int VGOFF_(sh_eflags) = INVALID_OFFSET; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 71 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 72 | Int VGOFF_(helper_idiv_64_32) = INVALID_OFFSET; |
| 73 | Int VGOFF_(helper_div_64_32) = INVALID_OFFSET; |
| 74 | Int VGOFF_(helper_idiv_32_16) = INVALID_OFFSET; |
| 75 | Int VGOFF_(helper_div_32_16) = INVALID_OFFSET; |
| 76 | Int VGOFF_(helper_idiv_16_8) = INVALID_OFFSET; |
| 77 | Int VGOFF_(helper_div_16_8) = INVALID_OFFSET; |
| 78 | Int VGOFF_(helper_imul_32_64) = INVALID_OFFSET; |
| 79 | Int VGOFF_(helper_mul_32_64) = INVALID_OFFSET; |
| 80 | Int VGOFF_(helper_imul_16_32) = INVALID_OFFSET; |
| 81 | Int VGOFF_(helper_mul_16_32) = INVALID_OFFSET; |
| 82 | Int VGOFF_(helper_imul_8_16) = INVALID_OFFSET; |
| 83 | Int VGOFF_(helper_mul_8_16) = INVALID_OFFSET; |
| 84 | Int VGOFF_(helper_CLD) = INVALID_OFFSET; |
| 85 | Int VGOFF_(helper_STD) = INVALID_OFFSET; |
| 86 | Int VGOFF_(helper_get_dirflag) = INVALID_OFFSET; |
sewardj | 7d78e78 | 2002-06-02 00:04:00 +0000 | [diff] [blame] | 87 | Int VGOFF_(helper_CLC) = INVALID_OFFSET; |
| 88 | Int VGOFF_(helper_STC) = INVALID_OFFSET; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 89 | Int VGOFF_(helper_shldl) = INVALID_OFFSET; |
| 90 | Int VGOFF_(helper_shldw) = INVALID_OFFSET; |
| 91 | Int VGOFF_(helper_shrdl) = INVALID_OFFSET; |
| 92 | Int VGOFF_(helper_shrdw) = INVALID_OFFSET; |
daywalker | b18d253 | 2003-09-27 20:15:01 +0000 | [diff] [blame] | 93 | Int VGOFF_(helper_IN) = INVALID_OFFSET; |
| 94 | Int VGOFF_(helper_OUT) = INVALID_OFFSET; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 95 | Int VGOFF_(helper_RDTSC) = INVALID_OFFSET; |
| 96 | Int VGOFF_(helper_CPUID) = INVALID_OFFSET; |
| 97 | Int VGOFF_(helper_BSWAP) = INVALID_OFFSET; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 98 | Int VGOFF_(helper_bsf) = INVALID_OFFSET; |
| 99 | Int VGOFF_(helper_bsr) = INVALID_OFFSET; |
| 100 | Int VGOFF_(helper_fstsw_AX) = INVALID_OFFSET; |
| 101 | Int VGOFF_(helper_SAHF) = INVALID_OFFSET; |
njn | d6251f1 | 2003-06-03 13:38:51 +0000 | [diff] [blame] | 102 | Int VGOFF_(helper_LAHF) = INVALID_OFFSET; |
sewardj | 4d0ab1f | 2002-03-24 10:00:09 +0000 | [diff] [blame] | 103 | Int VGOFF_(helper_DAS) = INVALID_OFFSET; |
sewardj | fe8a166 | 2002-03-24 11:54:07 +0000 | [diff] [blame] | 104 | Int VGOFF_(helper_DAA) = INVALID_OFFSET; |
sewardj | 5109643 | 2002-12-14 23:59:09 +0000 | [diff] [blame] | 105 | Int VGOFF_(helper_undefined_instruction) = INVALID_OFFSET; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 106 | |
| 107 | /* MAX_NONCOMPACT_HELPERS can be increased easily. If MAX_COMPACT_HELPERS is |
| 108 | * increased too much, they won't really be compact any more... */ |
| 109 | #define MAX_COMPACT_HELPERS 8 |
njn | fedb736 | 2003-02-24 10:21:45 +0000 | [diff] [blame] | 110 | #define MAX_NONCOMPACT_HELPERS 50 |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 111 | |
| 112 | UInt VG_(n_compact_helpers) = 0; |
| 113 | UInt VG_(n_noncompact_helpers) = 0; |
| 114 | |
| 115 | Addr VG_(compact_helper_addrs) [MAX_COMPACT_HELPERS]; |
| 116 | Int VG_(compact_helper_offsets)[MAX_COMPACT_HELPERS]; |
| 117 | Addr VG_(noncompact_helper_addrs) [MAX_NONCOMPACT_HELPERS]; |
| 118 | Int VG_(noncompact_helper_offsets)[MAX_NONCOMPACT_HELPERS]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 119 | |
| 120 | /* This is the actual defn of baseblock. */ |
| 121 | UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS]; |
| 122 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 123 | /* Client address space */ |
| 124 | Addr VG_(client_base); /* client address space limits */ |
| 125 | Addr VG_(client_end); |
| 126 | Addr VG_(client_mapbase); |
| 127 | Addr VG_(clstk_base); |
| 128 | Addr VG_(clstk_end); |
| 129 | Addr VG_(brk_base); /* start of brk */ |
| 130 | Addr VG_(brk_limit); /* current brk */ |
| 131 | Addr VG_(shadow_base); /* skin's shadow memory */ |
| 132 | Addr VG_(shadow_end); |
| 133 | Addr VG_(valgrind_base); /* valgrind's address range */ |
| 134 | Addr VG_(valgrind_mmap_end); /* valgrind's mmaps are between valgrind_base and here */ |
| 135 | Addr VG_(valgrind_end); |
| 136 | |
| 137 | /* stage1 (main) executable */ |
fitzhardinge | a49f9b5 | 2003-12-16 22:26:45 +0000 | [diff] [blame] | 138 | Int VG_(vgexecfd) = -1; |
| 139 | |
| 140 | /* client executable */ |
| 141 | Int VG_(clexecfd) = -1; |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 142 | |
| 143 | /* Path to library directory */ |
| 144 | const Char *VG_(libdir) = VG_LIBDIR; |
| 145 | |
| 146 | /* our argc/argv */ |
| 147 | Int VG_(vg_argc); |
| 148 | Char **VG_(vg_argv); |
| 149 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 150 | /* PID of the main thread */ |
| 151 | Int VG_(main_pid); |
| 152 | |
| 153 | /* PGRP of process */ |
| 154 | Int VG_(main_pgrp); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 155 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 156 | /* Words. */ |
| 157 | static Int baB_off = 0; |
| 158 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 159 | /* jmp_buf for fatal signals */ |
| 160 | Int VG_(fatal_sigNo) = -1; |
| 161 | Bool VG_(fatal_signal_set) = False; |
| 162 | jmp_buf VG_(fatal_signal_jmpbuf); |
| 163 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 164 | /* Returns the offset, in words. */ |
| 165 | static Int alloc_BaB ( Int words ) |
| 166 | { |
| 167 | Int off = baB_off; |
| 168 | baB_off += words; |
| 169 | if (baB_off >= VG_BASEBLOCK_WORDS) |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 170 | VG_(core_panic)( "alloc_BaB: baseBlock is too small"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 171 | |
| 172 | return off; |
| 173 | } |
| 174 | |
njn | 0c7a5b5 | 2003-04-30 09:00:33 +0000 | [diff] [blame] | 175 | /* Align offset, in *bytes* */ |
| 176 | static void align_BaB ( UInt align ) |
| 177 | { |
| 178 | vg_assert(2 == align || 4 == align || 8 == align || 16 == align); |
| 179 | baB_off += (align-1); |
| 180 | baB_off &= ~(align-1); |
| 181 | } |
| 182 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 183 | /* Allocate 1 word in baseBlock and set it to the given value. */ |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 184 | static Int alloc_BaB_1_set ( Addr a ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 185 | { |
| 186 | Int off = alloc_BaB(1); |
| 187 | VG_(baseBlock)[off] = (UInt)a; |
| 188 | return off; |
| 189 | } |
| 190 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 191 | /* Registers a function in compact_helper_addrs; compact_helper_offsets is |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 192 | filled in later. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 193 | void VG_(register_compact_helper)(Addr a) |
| 194 | { |
| 195 | if (MAX_COMPACT_HELPERS <= VG_(n_compact_helpers)) { |
| 196 | VG_(printf)("Can only register %d compact helpers\n", |
| 197 | MAX_COMPACT_HELPERS); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 198 | VG_(core_panic)("Too many compact helpers registered"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 199 | } |
| 200 | VG_(compact_helper_addrs)[VG_(n_compact_helpers)] = a; |
| 201 | VG_(n_compact_helpers)++; |
| 202 | } |
| 203 | |
| 204 | /* Registers a function in noncompact_helper_addrs; noncompact_helper_offsets |
| 205 | * is filled in later. |
| 206 | */ |
| 207 | void VG_(register_noncompact_helper)(Addr a) |
| 208 | { |
| 209 | if (MAX_NONCOMPACT_HELPERS <= VG_(n_noncompact_helpers)) { |
| 210 | VG_(printf)("Can only register %d non-compact helpers\n", |
| 211 | MAX_NONCOMPACT_HELPERS); |
| 212 | VG_(printf)("Try increasing MAX_NON_COMPACT_HELPERS\n"); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 213 | VG_(core_panic)("Too many non-compact helpers registered"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 214 | } |
| 215 | VG_(noncompact_helper_addrs)[VG_(n_noncompact_helpers)] = a; |
| 216 | VG_(n_noncompact_helpers)++; |
| 217 | } |
| 218 | |
| 219 | /* Allocate offsets in baseBlock for the skin helpers */ |
sewardj | 05bcdcb | 2003-05-18 10:05:38 +0000 | [diff] [blame] | 220 | static |
| 221 | void assign_helpers_in_baseBlock(UInt n, Int offsets[], Addr addrs[]) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 222 | { |
sewardj | 05bcdcb | 2003-05-18 10:05:38 +0000 | [diff] [blame] | 223 | UInt i; |
| 224 | for (i = 0; i < n; i++) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 225 | offsets[i] = alloc_BaB_1_set( addrs[i] ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 226 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 227 | |
njn | f4ce3d3 | 2003-02-10 10:17:26 +0000 | [diff] [blame] | 228 | Bool VG_(need_to_handle_esp_assignment)(void) |
| 229 | { |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 230 | return ( VG_(defined_new_mem_stack_4)() || |
| 231 | VG_(defined_die_mem_stack_4)() || |
| 232 | VG_(defined_new_mem_stack_8)() || |
| 233 | VG_(defined_die_mem_stack_8)() || |
| 234 | VG_(defined_new_mem_stack_12)() || |
| 235 | VG_(defined_die_mem_stack_12)() || |
| 236 | VG_(defined_new_mem_stack_16)() || |
| 237 | VG_(defined_die_mem_stack_16)() || |
| 238 | VG_(defined_new_mem_stack_32)() || |
| 239 | VG_(defined_die_mem_stack_32)() || |
| 240 | VG_(defined_new_mem_stack)() || |
| 241 | VG_(defined_die_mem_stack)() |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 242 | ); |
njn | f4ce3d3 | 2003-02-10 10:17:26 +0000 | [diff] [blame] | 243 | } |
| 244 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 245 | /* Here we assign actual offsets. It's important to get the most |
| 246 | popular referents within 128 bytes of the start, so we can take |
| 247 | advantage of short addressing modes relative to %ebp. Popularity |
| 248 | of offsets was measured on 22 Feb 02 running a KDE application, and |
| 249 | the slots rearranged accordingly, with a 1.5% reduction in total |
| 250 | size of translations. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 251 | static void vg_init_baseBlock ( void ) |
| 252 | { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 253 | /* Those with offsets under 128 are carefully chosen. */ |
| 254 | |
| 255 | /* WORD offsets in this column */ |
| 256 | /* 0 */ VGOFF_(m_eax) = alloc_BaB(1); |
| 257 | /* 1 */ VGOFF_(m_ecx) = alloc_BaB(1); |
| 258 | /* 2 */ VGOFF_(m_edx) = alloc_BaB(1); |
| 259 | /* 3 */ VGOFF_(m_ebx) = alloc_BaB(1); |
| 260 | /* 4 */ VGOFF_(m_esp) = alloc_BaB(1); |
| 261 | /* 5 */ VGOFF_(m_ebp) = alloc_BaB(1); |
| 262 | /* 6 */ VGOFF_(m_esi) = alloc_BaB(1); |
| 263 | /* 7 */ VGOFF_(m_edi) = alloc_BaB(1); |
| 264 | /* 8 */ VGOFF_(m_eflags) = alloc_BaB(1); |
| 265 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 266 | if (VG_(needs).shadow_regs) { |
| 267 | /* 9 */ VGOFF_(sh_eax) = alloc_BaB(1); |
| 268 | /* 10 */ VGOFF_(sh_ecx) = alloc_BaB(1); |
| 269 | /* 11 */ VGOFF_(sh_edx) = alloc_BaB(1); |
| 270 | /* 12 */ VGOFF_(sh_ebx) = alloc_BaB(1); |
| 271 | /* 13 */ VGOFF_(sh_esp) = alloc_BaB(1); |
| 272 | /* 14 */ VGOFF_(sh_ebp) = alloc_BaB(1); |
| 273 | /* 15 */ VGOFF_(sh_esi) = alloc_BaB(1); |
| 274 | /* 16 */ VGOFF_(sh_edi) = alloc_BaB(1); |
| 275 | /* 17 */ VGOFF_(sh_eflags) = alloc_BaB(1); |
| 276 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 277 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 278 | /* 9,10,11 or 18,19,20... depends on number whether shadow regs are used |
| 279 | * and on compact helpers registered */ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 280 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 281 | /* Make these most-frequently-called specialised ones compact, if they |
| 282 | are used. */ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 283 | if (VG_(defined_new_mem_stack_4)()) |
| 284 | VG_(register_compact_helper)( (Addr) VG_(tool_interface).track_new_mem_stack_4); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 285 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 286 | if (VG_(defined_die_mem_stack_4)()) |
| 287 | VG_(register_compact_helper)( (Addr) VG_(tool_interface).track_die_mem_stack_4); |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 288 | |
| 289 | /* (9 or 18) + n_compact_helpers */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 290 | /* Allocate slots for compact helpers */ |
| 291 | assign_helpers_in_baseBlock(VG_(n_compact_helpers), |
| 292 | VG_(compact_helper_offsets), |
| 293 | VG_(compact_helper_addrs)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 294 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 295 | /* (9/10 or 18/19) + n_compact_helpers */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 296 | VGOFF_(m_eip) = alloc_BaB(1); |
| 297 | |
| 298 | /* There are currently 24 spill slots */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 299 | /* (11+/20+ .. 32+/43+) + n_compact_helpers. This can overlap the magic |
| 300 | * boundary at >= 32 words, but most spills are to low numbered spill |
| 301 | * slots, so the ones above the boundary don't see much action. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 302 | VGOFF_(spillslots) = alloc_BaB(VG_MAX_SPILLSLOTS); |
| 303 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 304 | /* I gave up counting at this point. Since they're above the |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 305 | short-amode-boundary, there's no point. */ |
| 306 | |
sewardj | fa492d4 | 2002-12-08 18:20:01 +0000 | [diff] [blame] | 307 | VGOFF_(m_dflag) = alloc_BaB(1); |
| 308 | |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 309 | /* The FPU/SSE state. This _must_ be 16-byte aligned. */ |
njn | 0c7a5b5 | 2003-04-30 09:00:33 +0000 | [diff] [blame] | 310 | align_BaB(16); |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 311 | VGOFF_(m_ssestate) = alloc_BaB(VG_SIZE_OF_SSESTATE_W); |
| 312 | vg_assert( |
| 313 | ( ((UInt)(& VG_(baseBlock)[VGOFF_(m_ssestate)])) |
| 314 | % 16 ) |
| 315 | == 0 |
| 316 | ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 317 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 318 | /* This thread's LDT pointer, and segment registers. */ |
| 319 | VGOFF_(ldt) = alloc_BaB(1); |
| 320 | VGOFF_(m_cs) = alloc_BaB(1); |
| 321 | VGOFF_(m_ss) = alloc_BaB(1); |
| 322 | VGOFF_(m_ds) = alloc_BaB(1); |
| 323 | VGOFF_(m_es) = alloc_BaB(1); |
| 324 | VGOFF_(m_fs) = alloc_BaB(1); |
| 325 | VGOFF_(m_gs) = alloc_BaB(1); |
| 326 | |
sewardj | e104247 | 2002-09-30 12:33:11 +0000 | [diff] [blame] | 327 | VG_(register_noncompact_helper)( (Addr) & VG_(do_useseg) ); |
| 328 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 329 | #define REG(kind, size) \ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 330 | if (VG_(defined_##kind##_mem_stack##size)()) \ |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 331 | VG_(register_noncompact_helper)( \ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 332 | (Addr) VG_(tool_interface).track_##kind##_mem_stack##size ); |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 333 | |
| 334 | REG(new, _8); |
| 335 | REG(new, _12); |
| 336 | REG(new, _16); |
| 337 | REG(new, _32); |
| 338 | REG(new, ); |
| 339 | REG(die, _8); |
| 340 | REG(die, _12); |
| 341 | REG(die, _16); |
| 342 | REG(die, _32); |
| 343 | REG(die, ); |
| 344 | #undef REG |
| 345 | |
| 346 | if (VG_(need_to_handle_esp_assignment)()) |
| 347 | VG_(register_noncompact_helper)((Addr) VG_(unknown_esp_update)); |
| 348 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 349 | /* Helper functions. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 350 | VGOFF_(helper_idiv_64_32) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 351 | = alloc_BaB_1_set( (Addr) & VG_(helper_idiv_64_32)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 352 | VGOFF_(helper_div_64_32) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 353 | = alloc_BaB_1_set( (Addr) & VG_(helper_div_64_32)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 354 | VGOFF_(helper_idiv_32_16) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 355 | = alloc_BaB_1_set( (Addr) & VG_(helper_idiv_32_16)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 356 | VGOFF_(helper_div_32_16) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 357 | = alloc_BaB_1_set( (Addr) & VG_(helper_div_32_16)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 358 | VGOFF_(helper_idiv_16_8) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 359 | = alloc_BaB_1_set( (Addr) & VG_(helper_idiv_16_8)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 360 | VGOFF_(helper_div_16_8) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 361 | = alloc_BaB_1_set( (Addr) & VG_(helper_div_16_8)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 362 | |
| 363 | VGOFF_(helper_imul_32_64) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 364 | = alloc_BaB_1_set( (Addr) & VG_(helper_imul_32_64)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 365 | VGOFF_(helper_mul_32_64) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 366 | = alloc_BaB_1_set( (Addr) & VG_(helper_mul_32_64)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 367 | VGOFF_(helper_imul_16_32) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 368 | = alloc_BaB_1_set( (Addr) & VG_(helper_imul_16_32)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 369 | VGOFF_(helper_mul_16_32) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 370 | = alloc_BaB_1_set( (Addr) & VG_(helper_mul_16_32)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 371 | VGOFF_(helper_imul_8_16) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 372 | = alloc_BaB_1_set( (Addr) & VG_(helper_imul_8_16)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 373 | VGOFF_(helper_mul_8_16) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 374 | = alloc_BaB_1_set( (Addr) & VG_(helper_mul_8_16)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 375 | |
| 376 | VGOFF_(helper_CLD) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 377 | = alloc_BaB_1_set( (Addr) & VG_(helper_CLD)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 378 | VGOFF_(helper_STD) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 379 | = alloc_BaB_1_set( (Addr) & VG_(helper_STD)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 380 | VGOFF_(helper_get_dirflag) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 381 | = alloc_BaB_1_set( (Addr) & VG_(helper_get_dirflag)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 382 | |
sewardj | 7d78e78 | 2002-06-02 00:04:00 +0000 | [diff] [blame] | 383 | VGOFF_(helper_CLC) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 384 | = alloc_BaB_1_set( (Addr) & VG_(helper_CLC)); |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 385 | VGOFF_(helper_STC) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 386 | = alloc_BaB_1_set( (Addr) & VG_(helper_STC)); |
sewardj | 7d78e78 | 2002-06-02 00:04:00 +0000 | [diff] [blame] | 387 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 388 | VGOFF_(helper_shldl) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 389 | = alloc_BaB_1_set( (Addr) & VG_(helper_shldl)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 390 | VGOFF_(helper_shldw) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 391 | = alloc_BaB_1_set( (Addr) & VG_(helper_shldw)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 392 | VGOFF_(helper_shrdl) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 393 | = alloc_BaB_1_set( (Addr) & VG_(helper_shrdl)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 394 | VGOFF_(helper_shrdw) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 395 | = alloc_BaB_1_set( (Addr) & VG_(helper_shrdw)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 396 | |
| 397 | VGOFF_(helper_RDTSC) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 398 | = alloc_BaB_1_set( (Addr) & VG_(helper_RDTSC)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 399 | VGOFF_(helper_CPUID) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 400 | = alloc_BaB_1_set( (Addr) & VG_(helper_CPUID)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 401 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 402 | VGOFF_(helper_bsf) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 403 | = alloc_BaB_1_set( (Addr) & VG_(helper_bsf)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 404 | VGOFF_(helper_bsr) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 405 | = alloc_BaB_1_set( (Addr) & VG_(helper_bsr)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 406 | |
| 407 | VGOFF_(helper_fstsw_AX) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 408 | = alloc_BaB_1_set( (Addr) & VG_(helper_fstsw_AX)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 409 | VGOFF_(helper_SAHF) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 410 | = alloc_BaB_1_set( (Addr) & VG_(helper_SAHF)); |
njn | d6251f1 | 2003-06-03 13:38:51 +0000 | [diff] [blame] | 411 | VGOFF_(helper_LAHF) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 412 | = alloc_BaB_1_set( (Addr) & VG_(helper_LAHF)); |
sewardj | 4d0ab1f | 2002-03-24 10:00:09 +0000 | [diff] [blame] | 413 | VGOFF_(helper_DAS) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 414 | = alloc_BaB_1_set( (Addr) & VG_(helper_DAS)); |
sewardj | fe8a166 | 2002-03-24 11:54:07 +0000 | [diff] [blame] | 415 | VGOFF_(helper_DAA) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 416 | = alloc_BaB_1_set( (Addr) & VG_(helper_DAA)); |
daywalker | b18d253 | 2003-09-27 20:15:01 +0000 | [diff] [blame] | 417 | VGOFF_(helper_IN) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 418 | = alloc_BaB_1_set( (Addr) & VG_(helper_IN)); |
daywalker | b18d253 | 2003-09-27 20:15:01 +0000 | [diff] [blame] | 419 | VGOFF_(helper_OUT) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 420 | = alloc_BaB_1_set( (Addr) & VG_(helper_OUT)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 421 | |
sewardj | 5109643 | 2002-12-14 23:59:09 +0000 | [diff] [blame] | 422 | VGOFF_(helper_undefined_instruction) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 423 | = alloc_BaB_1_set( (Addr) & VG_(helper_undefined_instruction)); |
sewardj | 5109643 | 2002-12-14 23:59:09 +0000 | [diff] [blame] | 424 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 425 | /* Allocate slots for noncompact helpers */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 426 | assign_helpers_in_baseBlock(VG_(n_noncompact_helpers), |
| 427 | VG_(noncompact_helper_offsets), |
| 428 | VG_(noncompact_helper_addrs)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 429 | |
njn | cc7bb47 | 2002-10-14 09:25:19 +0000 | [diff] [blame] | 430 | |
| 431 | /* Initialise slots that require it */ |
| 432 | VG_(copy_m_state_static_to_baseBlock)(); |
| 433 | |
| 434 | /* Pretend the root thread has a completely empty LDT to start with. */ |
| 435 | VG_(baseBlock)[VGOFF_(ldt)] = (UInt)NULL; |
| 436 | |
| 437 | /* Initialise shadow regs */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 438 | if (VG_(needs).shadow_regs) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 439 | VG_(baseBlock)[VGOFF_(sh_esp)] = |
| 440 | VG_(baseBlock)[VGOFF_(sh_ebp)] = |
| 441 | VG_(baseBlock)[VGOFF_(sh_eax)] = |
| 442 | VG_(baseBlock)[VGOFF_(sh_ecx)] = |
| 443 | VG_(baseBlock)[VGOFF_(sh_edx)] = |
| 444 | VG_(baseBlock)[VGOFF_(sh_ebx)] = |
| 445 | VG_(baseBlock)[VGOFF_(sh_esi)] = |
njn | d304045 | 2003-05-19 15:04:06 +0000 | [diff] [blame] | 446 | VG_(baseBlock)[VGOFF_(sh_edi)] = 0; |
| 447 | VG_(baseBlock)[VGOFF_(sh_eflags)] = 0; |
| 448 | VG_TRACK( post_regs_write_init ); |
njn | cc7bb47 | 2002-10-14 09:25:19 +0000 | [diff] [blame] | 449 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | |
| 453 | /* --------------------------------------------------------------------- |
| 454 | Global entities which are not referenced from generated code. |
| 455 | ------------------------------------------------------------------ */ |
| 456 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 457 | /* Ditto our signal delivery stack. */ |
njn | 6eba4ef | 2003-05-01 08:06:41 +0000 | [diff] [blame] | 458 | UInt VG_(sigstack)[VG_SIGSTACK_SIZE_W]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 459 | |
| 460 | /* Saving stuff across system calls. */ |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 461 | __attribute__ ((aligned (16))) |
| 462 | UInt VG_(real_sse_state_saved_over_syscall)[VG_SIZE_OF_SSESTATE_W]; |
sewardj | 43c356f | 2002-06-02 00:21:08 +0000 | [diff] [blame] | 463 | Addr VG_(esp_saved_over_syscall); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 464 | |
| 465 | /* Counts downwards in vg_run_innerloop. */ |
| 466 | UInt VG_(dispatch_ctr); |
| 467 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 468 | |
| 469 | /* 64-bit counter for the number of basic blocks done. */ |
| 470 | ULong VG_(bbs_done); |
| 471 | /* 64-bit counter for the number of bbs to go before a debug exit. */ |
| 472 | ULong VG_(bbs_to_go); |
| 473 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 474 | /* This is the ThreadId of the last thread the scheduler ran. */ |
| 475 | ThreadId VG_(last_run_tid) = 0; |
| 476 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 477 | /* This is the argument to __NR_exit() supplied by the first thread to |
| 478 | call that syscall. We eventually pass that to __NR_exit() for |
| 479 | real. */ |
njn | 633de32 | 2003-05-12 20:40:13 +0000 | [diff] [blame] | 480 | Int VG_(exitcode) = 0; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 481 | |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 482 | /* Tell the logging mechanism whether we are logging to a file |
| 483 | descriptor or a socket descriptor. */ |
| 484 | Bool VG_(logging_to_filedes) = True; |
| 485 | |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 486 | /* Is this a SSE/SSE2-capable CPU? If so, we had better save/restore |
| 487 | the SSE state all over the place. This is set up very early, in |
| 488 | vg_startup.S. We have to determine it early since we can't even |
| 489 | correctly snapshot the startup machine state without it. */ |
| 490 | /* Initially True. Safer to err on the side of SSEness and get SIGILL |
daywalker | 7e73e5f | 2003-07-04 16:18:15 +0000 | [diff] [blame] | 491 | than to not notice for some reason that we have SSE and get weird |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 492 | errors later on. */ |
| 493 | Bool VG_(have_ssestate) = True; |
| 494 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 495 | |
| 496 | /* --------------------------------------------------------------------- |
| 497 | Counters, for informational purposes only. |
| 498 | ------------------------------------------------------------------ */ |
| 499 | |
| 500 | /* Number of lookups which miss the fast tt helper. */ |
| 501 | UInt VG_(tt_fast_misses) = 0; |
| 502 | |
| 503 | |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 504 | /* Counts for TT/TC informational messages. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 505 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 506 | /* Number and total o/t size of translations overall. */ |
| 507 | UInt VG_(overall_in_count) = 0; |
| 508 | UInt VG_(overall_in_osize) = 0; |
| 509 | UInt VG_(overall_in_tsize) = 0; |
| 510 | /* Number and total o/t size of discards overall. */ |
| 511 | UInt VG_(overall_out_count) = 0; |
| 512 | UInt VG_(overall_out_osize) = 0; |
| 513 | UInt VG_(overall_out_tsize) = 0; |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 514 | /* The number of discards of TT/TC. */ |
| 515 | UInt VG_(number_of_tc_discards) = 0; |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 516 | /* Counts of chain and unchain operations done. */ |
| 517 | UInt VG_(bb_enchain_count) = 0; |
| 518 | UInt VG_(bb_dechain_count) = 0; |
| 519 | /* Number of unchained jumps performed. */ |
| 520 | UInt VG_(unchained_jumps_done) = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 521 | |
| 522 | |
| 523 | /* Counts pertaining to the register allocator. */ |
| 524 | |
| 525 | /* total number of uinstrs input to reg-alloc */ |
| 526 | UInt VG_(uinstrs_prealloc) = 0; |
| 527 | |
| 528 | /* total number of uinstrs added due to spill code */ |
| 529 | UInt VG_(uinstrs_spill) = 0; |
| 530 | |
| 531 | /* number of bbs requiring spill code */ |
| 532 | UInt VG_(translations_needing_spill) = 0; |
| 533 | |
| 534 | /* total of register ranks over all translations */ |
| 535 | UInt VG_(total_reg_rank) = 0; |
| 536 | |
| 537 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 538 | /* Counts pertaining to internal sanity checking. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 539 | UInt VG_(sanity_fast_count) = 0; |
| 540 | UInt VG_(sanity_slow_count) = 0; |
| 541 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 542 | /* Counts pertaining to the scheduler. */ |
| 543 | UInt VG_(num_scheduling_events_MINOR) = 0; |
| 544 | UInt VG_(num_scheduling_events_MAJOR) = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 545 | |
| 546 | |
| 547 | /* --------------------------------------------------------------------- |
| 548 | Values derived from command-line options. |
| 549 | ------------------------------------------------------------------ */ |
| 550 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 551 | /* Define, and set defaults. */ |
| 552 | Bool VG_(clo_error_limit) = True; |
| 553 | Bool VG_(clo_GDB_attach) = False; |
sewardj | 6024b21 | 2003-07-13 10:54:33 +0000 | [diff] [blame] | 554 | Char* VG_(clo_GDB_path) = GDB_PATH; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 555 | Bool VG_(clo_gen_suppressions) = False; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 556 | Int VG_(sanity_level) = 1; |
| 557 | Int VG_(clo_verbosity) = 1; |
| 558 | Bool VG_(clo_demangle) = True; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 559 | Bool VG_(clo_trace_children) = False; |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 560 | |
nethercote | e173069 | 2003-11-20 10:38:07 +0000 | [diff] [blame] | 561 | /* See big comment in vg_include.h for meaning of these three. |
| 562 | fd is initially stdout, for --help, but gets moved to stderr by default |
| 563 | immediately afterwards. */ |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 564 | VgLogTo VG_(clo_log_to) = VgLogTo_Fd; |
nethercote | e173069 | 2003-11-20 10:38:07 +0000 | [diff] [blame] | 565 | Int VG_(clo_logfile_fd) = 1; |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 566 | Char* VG_(clo_logfile_name) = NULL; |
| 567 | |
sewardj | 6024b21 | 2003-07-13 10:54:33 +0000 | [diff] [blame] | 568 | Int VG_(clo_input_fd) = 0; /* stdin */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 569 | Int VG_(clo_n_suppressions) = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 570 | Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES]; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 571 | Bool VG_(clo_profile) = False; |
| 572 | Bool VG_(clo_single_step) = False; |
| 573 | Bool VG_(clo_optimise) = True; |
| 574 | UChar VG_(clo_trace_codegen) = 0; // 00000000b |
| 575 | Bool VG_(clo_trace_syscalls) = False; |
| 576 | Bool VG_(clo_trace_signals) = False; |
| 577 | Bool VG_(clo_trace_symtab) = False; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 578 | Bool VG_(clo_trace_sched) = False; |
| 579 | Int VG_(clo_trace_pthread_level) = 0; |
sewardj | 59438c0 | 2003-01-05 12:16:30 +0000 | [diff] [blame] | 580 | ULong VG_(clo_stop_after) = 1000000000000000LL; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 581 | Int VG_(clo_dump_error) = 0; |
| 582 | Int VG_(clo_backtrace_size) = 4; |
| 583 | Char* VG_(clo_weird_hacks) = NULL; |
sewardj | 858964b | 2002-10-05 14:15:43 +0000 | [diff] [blame] | 584 | Bool VG_(clo_run_libc_freeres) = True; |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 585 | Bool VG_(clo_track_fds) = False; |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 586 | Bool VG_(clo_chain_bb) = True; |
nethercote | 77eba60 | 2003-11-13 17:35:04 +0000 | [diff] [blame] | 587 | Bool VG_(clo_show_below_main) = False; |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 588 | Bool VG_(clo_pointercheck) = True; |
fitzhardinge | 462f4f9 | 2003-12-18 02:10:54 +0000 | [diff] [blame^] | 589 | Bool VG_(clo_branchpred) = False; |
sewardj | 2370f3b | 2002-11-30 15:01:01 +0000 | [diff] [blame] | 590 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 591 | static Bool VG_(clo_wait_for_gdb) = False; |
| 592 | |
| 593 | /* If we're doing signal routing, poll for signals every 50mS by |
| 594 | default. */ |
| 595 | Int VG_(clo_signal_polltime) = 50; |
| 596 | |
| 597 | /* These flags reduce thread wakeup latency on syscall completion and |
| 598 | signal delivery, respectively. The downside is possible unfairness. */ |
| 599 | Bool VG_(clo_lowlat_syscalls) = False; /* low-latency syscalls */ |
| 600 | Bool VG_(clo_lowlat_signals) = False; /* low-latency signals */ |
| 601 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 602 | /* This Bool is needed by wrappers in vg_clientmalloc.c to decide how |
| 603 | to behave. Initially we say False. */ |
| 604 | Bool VG_(running_on_simd_CPU) = False; |
| 605 | |
| 606 | /* Holds client's %esp at the point we gained control. */ |
| 607 | Addr VG_(esp_at_startup); |
| 608 | |
sewardj | d5815ec | 2003-04-06 12:23:27 +0000 | [diff] [blame] | 609 | /* Indicates presence, and holds address of client's sysinfo page, a |
| 610 | feature of some modern kernels used to provide vsyscalls, etc. */ |
| 611 | Bool VG_(sysinfo_page_exists) = False; |
| 612 | Addr VG_(sysinfo_page_addr) = 0; |
| 613 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 614 | /* As deduced from VG_(esp_at_startup), the client's argc, argv[] and |
| 615 | envp[] as extracted from the client's stack at startup-time. */ |
| 616 | Int VG_(client_argc); |
| 617 | Char** VG_(client_argv); |
| 618 | Char** VG_(client_envp); |
| 619 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 620 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 621 | Processing of command-line options. |
| 622 | ------------------------------------------------------------------ */ |
| 623 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 624 | void VG_(bad_option) ( Char* opt ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 625 | { |
| 626 | VG_(shutdown_logging)(); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 627 | VG_(clo_log_to) = VgLogTo_Fd; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 628 | VG_(clo_logfile_fd) = 2; /* stderr */ |
| 629 | VG_(printf)("valgrind.so: Bad option `%s'; aborting.\n", opt); |
| 630 | VG_(exit)(1); |
| 631 | } |
| 632 | |
| 633 | static void config_error ( Char* msg ) |
| 634 | { |
| 635 | VG_(shutdown_logging)(); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 636 | VG_(clo_log_to) = VgLogTo_Fd; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 637 | VG_(clo_logfile_fd) = 2; /* stderr */ |
sewardj | 19d8141 | 2002-06-03 01:10:40 +0000 | [diff] [blame] | 638 | VG_(printf)( |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 639 | "valgrind: Startup or configuration error:\n %s\n", msg); |
sewardj | 19d8141 | 2002-06-03 01:10:40 +0000 | [diff] [blame] | 640 | VG_(printf)( |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 641 | "valgrind: Unable to start up properly. Giving up.\n"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 642 | VG_(exit)(1); |
| 643 | } |
| 644 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 645 | void VG_(usage) ( void ) |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 646 | { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 647 | Char* usage1 = |
| 648 | "usage: valgrind [options] prog-and-args\n" |
| 649 | "\n" |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 650 | " common user options for all Valgrind tools, with defaults in [ ]:\n" |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 651 | " --tool=<name> Use the Valgrind tool named <name> [memcheck]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 652 | " --help show this message\n" |
| 653 | " --version show version\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 654 | " -q --quiet run silently; only print error msgs\n" |
| 655 | " -v --verbose be more verbose, incl counts of errors\n" |
nethercote | 77eba60 | 2003-11-13 17:35:04 +0000 | [diff] [blame] | 656 | " --trace-children=no|yes Valgrind-ise child processes? [no]\n" |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 657 | " --track-fds=no|yes Track open file descriptors? [no]\n" |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 658 | "\n" |
| 659 | " uncommon user options for all Valgrind tools:\n" |
nethercote | 77eba60 | 2003-11-13 17:35:04 +0000 | [diff] [blame] | 660 | " --run-libc-freeres=no|yes Free up glibc memory at exit? [yes]\n" |
| 661 | " --weird-hacks=hack1,hack2,... [none]\n" |
sewardj | 3d652a3 | 2002-10-20 18:11:49 +0000 | [diff] [blame] | 662 | " recognised hacks are: ioctl-VTIME truncate-writes lax-ioctls\n" |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 663 | " --signal-polltime=<time> time, in mS, we should poll for signals.\n" |
| 664 | " Only applies for older kernels which need\n" |
| 665 | " signal routing [50]\n" |
| 666 | " --lowlat-signals=no|yes improve wake-up latency when a thread receives\n" |
| 667 | " a signal [no]\n" |
| 668 | " --lowlat-syscalls=no|yes improve wake-up latency when a thread's\n" |
| 669 | " syscall completes [no]\n" |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 670 | " --pointercheck=no|yes enforce client address space limits [yes]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 671 | "\n" |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 672 | " user options for Valgrind tools that report errors:\n" |
| 673 | " --logfile-fd=<number> file descriptor for messages [2=stderr]\n" |
| 674 | " --logfile=<file> log messages to <file>.pid<pid>\n" |
| 675 | " --logsocket=ipaddr:port log messages to socket ipaddr:port\n" |
| 676 | " --demangle=no|yes automatically demangle C++ names? [yes]\n" |
| 677 | " --num-callers=<number> show <num> callers in stack traces [4]\n" |
| 678 | " --error-limit=no|yes stop showing new errors if too many? [yes]\n" |
| 679 | " --show-below-main=no|yes continue stack traces below main() [no]\n" |
| 680 | " --suppressions=<filename> suppress errors described in <filename>\n" |
| 681 | " --gen-suppressions=no|yes print suppressions for errors detected [no]\n" |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 682 | |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 683 | " --gdb-attach=no|yes start GDB when errors detected? [no]\n" |
| 684 | " --gdb-path=/path/to/gdb path to the GDB to use [/usr/bin/gdb]\n" |
| 685 | " --input-fd=<number> file descriptor for (gdb) input [0=stdin]\n" |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 686 | "\n"; |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 687 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 688 | Char* usage2 = |
| 689 | "\n" |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 690 | " debugging options for all Valgrind tools:\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 691 | " --sanity-level=<number> level of sanity checking to do [1]\n" |
| 692 | " --single-step=no|yes translate each instr separately? [no]\n" |
| 693 | " --optimise=no|yes improve intermediate code? [yes]\n" |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 694 | " --profile=no|yes profile? (tool must be built for it) [no]\n" |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 695 | " --chain-bb=no|yes do basic-block chaining? [yes]\n" |
fitzhardinge | 462f4f9 | 2003-12-18 02:10:54 +0000 | [diff] [blame^] | 696 | " --branchpred=yes|no generate branch prediction hints [no]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 697 | " --trace-codegen=<XXXXX> show generated code? (X = 0|1) [00000]\n" |
| 698 | " --trace-syscalls=no|yes show all system calls? [no]\n" |
| 699 | " --trace-signals=no|yes show signal handling details? [no]\n" |
| 700 | " --trace-symtab=no|yes show symbol table details? [no]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 701 | " --trace-sched=no|yes show thread scheduler details? [no]\n" |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 702 | " --trace-pthread=none|some|all show pthread event details? [none]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 703 | " --stop-after=<number> switch to real CPU after executing\n" |
| 704 | " <number> basic blocks [infinity]\n" |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 705 | " --wait-for-gdb=yes|no pause on startup to wait for gdb attach\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 706 | "\n" |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 707 | " debugging options for Valgrind tools that report errors\n" |
| 708 | " --dump-error=<number> show translation for basic block associated\n" |
| 709 | " with <number>'th error context [0=show none]\n" |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 710 | "\n"; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 711 | |
| 712 | Char* usage3 = |
| 713 | "\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 714 | " Extra options are read from env variable $VALGRIND_OPTS\n" |
| 715 | "\n" |
njn | 0e1b514 | 2003-04-15 14:58:06 +0000 | [diff] [blame] | 716 | " Valgrind is Copyright (C) 2000-2003 Julian Seward\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 717 | " and licensed under the GNU General Public License, version 2.\n" |
| 718 | " Bug reports, feedback, admiration, abuse, etc, to: %s.\n" |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 719 | "\n" |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 720 | " Tools are copyright and licensed by their authors. See each\n" |
| 721 | " tool's start-up message for more information.\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 722 | "\n"; |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 723 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 724 | VG_(printf)(usage1); |
| 725 | if (VG_(details).name) { |
| 726 | VG_(printf)(" user options for %s:\n", VG_(details).name); |
| 727 | /* Don't print skin string directly for security, ha! */ |
| 728 | if (VG_(needs).command_line_options) |
| 729 | SK_(print_usage)(); |
| 730 | else |
| 731 | VG_(printf)(" (none)\n"); |
| 732 | } |
| 733 | VG_(printf)(usage2); |
| 734 | |
| 735 | if (VG_(details).name) { |
| 736 | VG_(printf)(" debugging options for %s:\n", VG_(details).name); |
| 737 | |
| 738 | if (VG_(needs).command_line_options) |
| 739 | SK_(print_debug_usage)(); |
| 740 | else |
| 741 | VG_(printf)(" (none)\n"); |
| 742 | } |
nethercote | 421281e | 2003-11-20 16:20:55 +0000 | [diff] [blame] | 743 | VG_(printf)(usage3, VG_BUGS_TO); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 744 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 745 | VG_(shutdown_logging)(); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 746 | VG_(clo_log_to) = VgLogTo_Fd; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 747 | VG_(clo_logfile_fd) = 2; /* stderr */ |
| 748 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 749 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 750 | |
sewardj | 1c1b116 | 2003-02-23 01:25:51 +0000 | [diff] [blame] | 751 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 752 | static void process_cmd_line_options ( const KickstartParams *kp ) |
sewardj | 1c1b116 | 2003-02-23 01:25:51 +0000 | [diff] [blame] | 753 | { |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 754 | Int argc; |
| 755 | Char **argv; |
| 756 | Int i, eventually_logfile_fd; |
| 757 | Int *auxp; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 758 | |
| 759 | # define ISSPACE(cc) ((cc) == ' ' || (cc) == '\t' || (cc) == '\n') |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 760 | |
nethercote | e173069 | 2003-11-20 10:38:07 +0000 | [diff] [blame] | 761 | /* log to stderr by default, but usage message goes to stdout */ |
| 762 | eventually_logfile_fd = 2; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 763 | |
| 764 | /* Once logging is started, we can safely send messages pertaining |
| 765 | to failures in initialisation. */ |
| 766 | VG_(startup_logging)(); |
| 767 | |
sewardj | 19d8141 | 2002-06-03 01:10:40 +0000 | [diff] [blame] | 768 | /* Check for sane path in ./configure --prefix=... */ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 769 | if (VG_LIBDIR[0] != '/') |
sewardj | 19d8141 | 2002-06-03 01:10:40 +0000 | [diff] [blame] | 770 | config_error("Please use absolute paths in " |
| 771 | "./configure --prefix=... or --libdir=..."); |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 772 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 773 | for(auxp = kp->client_auxv; auxp[0] != VKI_AT_NULL; auxp += 2) { |
| 774 | switch(auxp[0]) { |
| 775 | case VKI_AT_SYSINFO: |
| 776 | VG_(sysinfo_page_exists) = True; |
| 777 | VG_(sysinfo_page_addr) = auxp[1]; |
| 778 | break; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 779 | } |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 780 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 781 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 782 | VG_(client_envp) = kp->client_envp; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 783 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 784 | argc = kp->argc; |
| 785 | argv = kp->argv; |
| 786 | |
| 787 | VG_(vg_argc) = argc; |
| 788 | VG_(vg_argv) = argv; |
| 789 | |
| 790 | /* We know the initial ESP is pointing at argc/argv */ |
| 791 | VG_(client_argc) = *(Int *)kp->client_esp; |
| 792 | VG_(client_argv) = (Char **)(kp->client_esp + sizeof(Int)); |
| 793 | |
| 794 | for (i = 1; i < argc; i++) { |
| 795 | /* Ignore these options - they've already been handled */ |
| 796 | if (VG_CLO_STREQN(7, argv[i], "--tool=") || |
| 797 | VG_CLO_STREQN(7, argv[i], "--skin=")) |
| 798 | continue; |
| 799 | if (VG_CLO_STREQN(7, argv[i], "--exec=")) |
| 800 | continue; |
| 801 | |
| 802 | if ( VG_CLO_STREQ(argv[i], "--")) |
| 803 | continue; |
| 804 | else if (VG_CLO_STREQ(argv[i], "-v") || |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 805 | VG_CLO_STREQ(argv[i], "--verbose")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 806 | VG_(clo_verbosity)++; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 807 | else if (VG_CLO_STREQ(argv[i], "-q") || |
| 808 | VG_CLO_STREQ(argv[i], "--quiet")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 809 | VG_(clo_verbosity)--; |
| 810 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 811 | else if (VG_CLO_STREQ(argv[i], "--error-limit=yes")) |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 812 | VG_(clo_error_limit) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 813 | else if (VG_CLO_STREQ(argv[i], "--error-limit=no")) |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 814 | VG_(clo_error_limit) = False; |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 815 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 816 | else if (VG_CLO_STREQ(argv[i], "--gdb-attach=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 817 | VG_(clo_GDB_attach) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 818 | else if (VG_CLO_STREQ(argv[i], "--gdb-attach=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 819 | VG_(clo_GDB_attach) = False; |
| 820 | |
sewardj | 6024b21 | 2003-07-13 10:54:33 +0000 | [diff] [blame] | 821 | else if (VG_CLO_STREQN(11,argv[i], "--gdb-path=")) |
| 822 | VG_(clo_GDB_path) = &argv[i][11]; |
| 823 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 824 | else if (VG_CLO_STREQ(argv[i], "--gen-suppressions=yes")) |
| 825 | VG_(clo_gen_suppressions) = True; |
| 826 | else if (VG_CLO_STREQ(argv[i], "--gen-suppressions=no")) |
| 827 | VG_(clo_gen_suppressions) = False; |
| 828 | |
nethercote | 77eba60 | 2003-11-13 17:35:04 +0000 | [diff] [blame] | 829 | else if (VG_CLO_STREQ(argv[i], "--show-below-main=yes")) |
| 830 | VG_(clo_show_below_main) = True; |
| 831 | else if (VG_CLO_STREQ(argv[i], "--show-below-main=no")) |
| 832 | VG_(clo_show_below_main) = False; |
| 833 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 834 | else if (VG_CLO_STREQ(argv[i], "--pointercheck=yes")) |
| 835 | VG_(clo_pointercheck) = True; |
| 836 | else if (VG_CLO_STREQ(argv[i], "--pointercheck=no")) |
| 837 | VG_(clo_pointercheck) = False; |
| 838 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 839 | else if (VG_CLO_STREQ(argv[i], "--demangle=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 840 | VG_(clo_demangle) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 841 | else if (VG_CLO_STREQ(argv[i], "--demangle=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 842 | VG_(clo_demangle) = False; |
| 843 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 844 | else if (VG_CLO_STREQ(argv[i], "--trace-children=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 845 | VG_(clo_trace_children) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 846 | else if (VG_CLO_STREQ(argv[i], "--trace-children=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 847 | VG_(clo_trace_children) = False; |
| 848 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 849 | else if (VG_CLO_STREQ(argv[i], "--run-libc-freeres=yes")) |
sewardj | 858964b | 2002-10-05 14:15:43 +0000 | [diff] [blame] | 850 | VG_(clo_run_libc_freeres) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 851 | else if (VG_CLO_STREQ(argv[i], "--run-libc-freeres=no")) |
sewardj | 858964b | 2002-10-05 14:15:43 +0000 | [diff] [blame] | 852 | VG_(clo_run_libc_freeres) = False; |
| 853 | |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 854 | else if (VG_CLO_STREQ(argv[i], "--track-fds=yes")) |
| 855 | VG_(clo_track_fds) = True; |
| 856 | else if (VG_CLO_STREQ(argv[i], "--track-fds=no")) |
| 857 | VG_(clo_track_fds) = False; |
| 858 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 859 | else if (VG_CLO_STREQN(15, argv[i], "--sanity-level=")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 860 | VG_(sanity_level) = (Int)VG_(atoll)(&argv[i][15]); |
| 861 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 862 | else if (VG_CLO_STREQN(13, argv[i], "--logfile-fd=")) { |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 863 | VG_(clo_log_to) = VgLogTo_Fd; |
| 864 | VG_(clo_logfile_name) = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 865 | eventually_logfile_fd = (Int)VG_(atoll)(&argv[i][13]); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 866 | } |
| 867 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 868 | else if (VG_CLO_STREQN(10, argv[i], "--logfile=")) { |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 869 | VG_(clo_log_to) = VgLogTo_File; |
| 870 | VG_(clo_logfile_name) = &argv[i][10]; |
| 871 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 872 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 873 | else if (VG_CLO_STREQN(12, argv[i], "--logsocket=")) { |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 874 | VG_(clo_log_to) = VgLogTo_Socket; |
| 875 | VG_(clo_logfile_name) = &argv[i][12]; |
| 876 | } |
| 877 | |
sewardj | 6024b21 | 2003-07-13 10:54:33 +0000 | [diff] [blame] | 878 | else if (VG_CLO_STREQN(11, argv[i], "--input-fd=")) |
| 879 | VG_(clo_input_fd) = (Int)VG_(atoll)(&argv[i][11]); |
| 880 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 881 | else if (VG_CLO_STREQN(15, argv[i], "--suppressions=")) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 882 | if (VG_(clo_n_suppressions) >= VG_CLO_MAX_SFILES) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 883 | VG_(message)(Vg_UserMsg, "Too many suppression files specified."); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 884 | VG_(message)(Vg_UserMsg, |
| 885 | "Increase VG_CLO_MAX_SFILES and recompile."); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 886 | VG_(bad_option)(argv[i]); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 887 | } |
| 888 | VG_(clo_suppressions)[VG_(clo_n_suppressions)] = &argv[i][15]; |
| 889 | VG_(clo_n_suppressions)++; |
| 890 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 891 | else if (VG_CLO_STREQ(argv[i], "--profile=yes")) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 892 | VG_(clo_profile) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 893 | else if (VG_CLO_STREQ(argv[i], "--profile=no")) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 894 | VG_(clo_profile) = False; |
| 895 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 896 | else if (VG_CLO_STREQ(argv[i], "--chain-bb=yes")) |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 897 | VG_(clo_chain_bb) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 898 | else if (VG_CLO_STREQ(argv[i], "--chain-bb=no")) |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 899 | VG_(clo_chain_bb) = False; |
| 900 | |
fitzhardinge | 462f4f9 | 2003-12-18 02:10:54 +0000 | [diff] [blame^] | 901 | else if (VG_CLO_STREQ(argv[i], "--branchpred=yes")) |
| 902 | VG_(clo_branchpred) = True; |
| 903 | else if (VG_CLO_STREQ(argv[i], "--branchpred=no")) |
| 904 | VG_(clo_branchpred) = False; |
| 905 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 906 | else if (VG_CLO_STREQ(argv[i], "--single-step=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 907 | VG_(clo_single_step) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 908 | else if (VG_CLO_STREQ(argv[i], "--single-step=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 909 | VG_(clo_single_step) = False; |
| 910 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 911 | else if (VG_CLO_STREQ(argv[i], "--optimise=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 912 | VG_(clo_optimise) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 913 | else if (VG_CLO_STREQ(argv[i], "--optimise=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 914 | VG_(clo_optimise) = False; |
| 915 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 916 | /* "vwxyz" --> 000zyxwv (binary) */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 917 | else if (VG_CLO_STREQN(16, argv[i], "--trace-codegen=")) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 918 | Int j; |
| 919 | char* opt = & argv[i][16]; |
| 920 | |
| 921 | if (5 != VG_(strlen)(opt)) { |
| 922 | VG_(message)(Vg_UserMsg, |
| 923 | "--trace-codegen argument must have 5 digits"); |
| 924 | VG_(bad_option)(argv[i]); |
| 925 | } |
| 926 | for (j = 0; j < 5; j++) { |
| 927 | if ('0' == opt[j]) { /* do nothing */ } |
| 928 | else if ('1' == opt[j]) VG_(clo_trace_codegen) |= (1 << j); |
| 929 | else { |
| 930 | VG_(message)(Vg_UserMsg, "--trace-codegen argument can only " |
| 931 | "contain 0s and 1s"); |
| 932 | VG_(bad_option)(argv[i]); |
| 933 | } |
| 934 | } |
| 935 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 936 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 937 | else if (VG_CLO_STREQ(argv[i], "--trace-syscalls=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 938 | VG_(clo_trace_syscalls) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 939 | else if (VG_CLO_STREQ(argv[i], "--trace-syscalls=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 940 | VG_(clo_trace_syscalls) = False; |
| 941 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 942 | else if (VG_CLO_STREQ(argv[i], "--trace-signals=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 943 | VG_(clo_trace_signals) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 944 | else if (VG_CLO_STREQ(argv[i], "--trace-signals=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 945 | VG_(clo_trace_signals) = False; |
| 946 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 947 | else if (VG_CLO_STREQ(argv[i], "--trace-symtab=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 948 | VG_(clo_trace_symtab) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 949 | else if (VG_CLO_STREQ(argv[i], "--trace-symtab=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 950 | VG_(clo_trace_symtab) = False; |
| 951 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 952 | else if (VG_CLO_STREQ(argv[i], "--trace-sched=yes")) |
sewardj | 8937c81 | 2002-04-12 20:12:20 +0000 | [diff] [blame] | 953 | VG_(clo_trace_sched) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 954 | else if (VG_CLO_STREQ(argv[i], "--trace-sched=no")) |
sewardj | 8937c81 | 2002-04-12 20:12:20 +0000 | [diff] [blame] | 955 | VG_(clo_trace_sched) = False; |
| 956 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 957 | else if (VG_CLO_STREQ(argv[i], "--trace-pthread=none")) |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 958 | VG_(clo_trace_pthread_level) = 0; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 959 | else if (VG_CLO_STREQ(argv[i], "--trace-pthread=some")) |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 960 | VG_(clo_trace_pthread_level) = 1; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 961 | else if (VG_CLO_STREQ(argv[i], "--trace-pthread=all")) |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 962 | VG_(clo_trace_pthread_level) = 2; |
sewardj | 8937c81 | 2002-04-12 20:12:20 +0000 | [diff] [blame] | 963 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 964 | else if (VG_CLO_STREQN(14, argv[i], "--weird-hacks=")) |
sewardj | 8d365b5 | 2002-05-12 10:52:16 +0000 | [diff] [blame] | 965 | VG_(clo_weird_hacks) = &argv[i][14]; |
sewardj | 3984b85 | 2002-05-12 03:00:17 +0000 | [diff] [blame] | 966 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 967 | else if (VG_CLO_STREQN(17, argv[i], "--signal-polltime=")) |
| 968 | VG_(clo_signal_polltime) = VG_(atoll)(&argv[i][17]); |
| 969 | |
| 970 | else if (VG_CLO_STREQ(argv[i], "--lowlat-signals=yes")) |
| 971 | VG_(clo_lowlat_signals) = True; |
| 972 | else if (VG_CLO_STREQ(argv[i], "--lowlat-signals=no")) |
| 973 | VG_(clo_lowlat_signals) = False; |
| 974 | |
| 975 | else if (VG_CLO_STREQ(argv[i], "--lowlat-syscalls=yes")) |
| 976 | VG_(clo_lowlat_syscalls) = True; |
| 977 | else if (VG_CLO_STREQ(argv[i], "--lowlat-syscalls=no")) |
| 978 | VG_(clo_lowlat_syscalls) = False; |
| 979 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 980 | else if (VG_CLO_STREQN(13, argv[i], "--stop-after=")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 981 | VG_(clo_stop_after) = VG_(atoll)(&argv[i][13]); |
| 982 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 983 | else if (VG_CLO_STREQN(13, argv[i], "--dump-error=")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 984 | VG_(clo_dump_error) = (Int)VG_(atoll)(&argv[i][13]); |
| 985 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 986 | else if (VG_CLO_STREQ(argv[i], "--wait-for-gdb=yes")) |
| 987 | VG_(clo_wait_for_gdb) = True; |
| 988 | else if (VG_CLO_STREQ(argv[i], "--wait-for-gdb=no")) |
| 989 | VG_(clo_wait_for_gdb) = False; |
| 990 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 991 | else if (VG_CLO_STREQN(14, argv[i], "--num-callers=")) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 992 | /* Make sure it's sane. */ |
| 993 | VG_(clo_backtrace_size) = (Int)VG_(atoll)(&argv[i][14]); |
njn | 6c84655 | 2003-09-16 07:41:43 +0000 | [diff] [blame] | 994 | if (VG_(clo_backtrace_size) < 1) |
| 995 | VG_(clo_backtrace_size) = 1; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 996 | if (VG_(clo_backtrace_size) >= VG_DEEPEST_BACKTRACE) |
| 997 | VG_(clo_backtrace_size) = VG_DEEPEST_BACKTRACE; |
| 998 | } |
| 999 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1000 | else if (VG_(needs).command_line_options) { |
| 1001 | Bool ok = SK_(process_cmd_line_option)(argv[i]); |
| 1002 | if (!ok) |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1003 | VG_(usage)(); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1004 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1005 | else |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1006 | VG_(usage)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | # undef ISSPACE |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1010 | |
njn | f9ebf67 | 2003-05-12 21:41:30 +0000 | [diff] [blame] | 1011 | if (VG_(clo_verbosity) < 0) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1012 | VG_(clo_verbosity) = 0; |
| 1013 | |
| 1014 | if (VG_(clo_GDB_attach) && VG_(clo_trace_children)) { |
| 1015 | VG_(message)(Vg_UserMsg, ""); |
| 1016 | VG_(message)(Vg_UserMsg, |
| 1017 | "--gdb-attach=yes conflicts with --trace-children=yes"); |
| 1018 | VG_(message)(Vg_UserMsg, |
| 1019 | "Please choose one or the other, but not both."); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1020 | VG_(bad_option)("--gdb-attach=yes and --trace-children=yes"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1023 | /* Set up logging now. After this is done, VG_(clo_logfile_fd) |
| 1024 | should be connected to whatever sink has been selected, and we |
| 1025 | indiscriminately chuck stuff into it without worrying what the |
| 1026 | nature of it is. Oh the wonder of Unix streams. */ |
| 1027 | |
nethercote | e173069 | 2003-11-20 10:38:07 +0000 | [diff] [blame] | 1028 | /* So far we should be still attached to stdout, so we can show on |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1029 | the terminal any problems to do with processing command line |
| 1030 | opts. */ |
nethercote | e173069 | 2003-11-20 10:38:07 +0000 | [diff] [blame] | 1031 | vg_assert(VG_(clo_logfile_fd) == 1 /* stdout */); |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1032 | vg_assert(VG_(logging_to_filedes) == True); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1033 | |
| 1034 | switch (VG_(clo_log_to)) { |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1035 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1036 | case VgLogTo_Fd: |
| 1037 | vg_assert(VG_(clo_logfile_name) == NULL); |
| 1038 | VG_(clo_logfile_fd) = eventually_logfile_fd; |
| 1039 | break; |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1040 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1041 | case VgLogTo_File: { |
| 1042 | Char logfilename[1000]; |
jsgf | f3c3f1a | 2003-10-14 22:13:28 +0000 | [diff] [blame] | 1043 | Int seq = 0; |
| 1044 | Int pid = VG_(getpid)(); |
| 1045 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1046 | vg_assert(VG_(clo_logfile_name) != NULL); |
| 1047 | vg_assert(VG_(strlen)(VG_(clo_logfile_name)) <= 900); /* paranoia */ |
jsgf | f3c3f1a | 2003-10-14 22:13:28 +0000 | [diff] [blame] | 1048 | |
| 1049 | for(;;) { |
| 1050 | if (seq == 0) |
| 1051 | VG_(sprintf)(logfilename, "%s.pid%d", |
| 1052 | VG_(clo_logfile_name), pid ); |
| 1053 | else |
| 1054 | VG_(sprintf)(logfilename, "%s.pid%d.%d", |
| 1055 | VG_(clo_logfile_name), pid, seq ); |
| 1056 | seq++; |
| 1057 | |
| 1058 | eventually_logfile_fd |
| 1059 | = VG_(open)(logfilename, |
| 1060 | VKI_O_CREAT|VKI_O_WRONLY|VKI_O_EXCL|VKI_O_TRUNC, |
| 1061 | VKI_S_IRUSR|VKI_S_IWUSR); |
| 1062 | if (eventually_logfile_fd >= 0) { |
| 1063 | VG_(clo_logfile_fd) = eventually_logfile_fd; |
| 1064 | break; |
| 1065 | } else { |
| 1066 | if (eventually_logfile_fd != -VKI_EEXIST) { |
| 1067 | VG_(message)(Vg_UserMsg, |
| 1068 | "Can't create/open log file `%s.pid%d'; giving up!", |
| 1069 | VG_(clo_logfile_name), pid); |
| 1070 | VG_(bad_option)( |
| 1071 | "--logfile=<file> didn't work out for some reason."); |
| 1072 | break; |
| 1073 | } |
| 1074 | } |
| 1075 | } |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1076 | break; |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | case VgLogTo_Socket: { |
| 1080 | vg_assert(VG_(clo_logfile_name) != NULL); |
| 1081 | vg_assert(VG_(strlen)(VG_(clo_logfile_name)) <= 900); /* paranoia */ |
| 1082 | eventually_logfile_fd |
| 1083 | = VG_(connect_via_socket)( VG_(clo_logfile_name) ); |
| 1084 | if (eventually_logfile_fd == -1) { |
| 1085 | VG_(message)(Vg_UserMsg, |
| 1086 | "Invalid --logsocket=ipaddr or --logsocket=ipaddr:port spec"); |
| 1087 | VG_(message)(Vg_UserMsg, |
| 1088 | "of `%s'; giving up!", VG_(clo_logfile_name) ); |
| 1089 | VG_(bad_option)( |
| 1090 | "--logsocket="); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1091 | } |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1092 | if (eventually_logfile_fd == -2) { |
| 1093 | VG_(message)(Vg_UserMsg, |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 1094 | "valgrind: failed to connect to logging server `%s'.", |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1095 | VG_(clo_logfile_name) ); |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 1096 | VG_(message)(Vg_UserMsg, |
| 1097 | "Log messages will sent to stderr instead." ); |
| 1098 | VG_(message)(Vg_UserMsg, |
| 1099 | "" ); |
| 1100 | /* We don't change anything here. */ |
| 1101 | } else { |
| 1102 | vg_assert(eventually_logfile_fd > 0); |
| 1103 | VG_(clo_logfile_fd) = eventually_logfile_fd; |
| 1104 | VG_(logging_to_filedes) = False; |
| 1105 | } |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1106 | break; |
| 1107 | } |
| 1108 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1111 | /* Move logfile_fd into the safe range, so it doesn't conflict with any app fds */ |
| 1112 | eventually_logfile_fd = VG_(fcntl)(VG_(clo_logfile_fd), VKI_F_DUPFD, VG_MAX_FD+1); |
| 1113 | if (eventually_logfile_fd < 0) |
| 1114 | VG_(message)(Vg_UserMsg, "valgrind: failed to move logfile fd into safe range"); |
| 1115 | else { |
| 1116 | VG_(clo_logfile_fd) = eventually_logfile_fd; |
| 1117 | VG_(fcntl)(VG_(clo_logfile_fd), VKI_F_SETFD, VKI_FD_CLOEXEC); |
| 1118 | } |
| 1119 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1120 | /* Ok, the logging sink is running now. Print a suitable preamble. |
| 1121 | If logging to file or a socket, write details of parent PID and |
| 1122 | command line args, to help people trying to interpret the |
| 1123 | results of a run which encompasses multiple processes. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1124 | |
sewardj | 83adf41 | 2002-05-01 01:25:45 +0000 | [diff] [blame] | 1125 | if (VG_(clo_verbosity > 0)) { |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1126 | /* Skin details */ |
| 1127 | VG_(message)(Vg_UserMsg, "%s%s%s, %s for x86-linux.", |
| 1128 | VG_(details).name, |
| 1129 | NULL == VG_(details).version ? "" : "-", |
| 1130 | NULL == VG_(details).version |
| 1131 | ? (Char*)"" : VG_(details).version, |
| 1132 | VG_(details).description); |
| 1133 | VG_(message)(Vg_UserMsg, "%s", VG_(details).copyright_author); |
sewardj | 3b2736a | 2002-03-24 12:18:35 +0000 | [diff] [blame] | 1134 | |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1135 | /* Core details */ |
| 1136 | VG_(message)(Vg_UserMsg, |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1137 | "Using valgrind-%s, a program supervision framework for x86-linux.", |
sewardj | 4aa62ba | 2002-10-05 15:49:27 +0000 | [diff] [blame] | 1138 | VERSION); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1139 | VG_(message)(Vg_UserMsg, |
njn | 0e1b514 | 2003-04-15 14:58:06 +0000 | [diff] [blame] | 1140 | "Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward."); |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1141 | } |
| 1142 | |
nethercote | c1e395d | 2003-11-10 13:26:49 +0000 | [diff] [blame] | 1143 | if (VG_(clo_verbosity) > 0 && VG_(clo_log_to) != VgLogTo_Fd) { |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1144 | VG_(message)(Vg_UserMsg, ""); |
| 1145 | VG_(message)(Vg_UserMsg, |
| 1146 | "My PID = %d, parent PID = %d. Prog and args are:", |
| 1147 | VG_(getpid)(), VG_(getppid)() ); |
| 1148 | for (i = 0; i < VG_(client_argc); i++) |
| 1149 | VG_(message)(Vg_UserMsg, " %s", VG_(client_argv)[i]); |
| 1150 | } |
| 1151 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1152 | if (VG_(clo_verbosity) > 1) { |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1153 | if (VG_(clo_log_to) != VgLogTo_Fd) |
| 1154 | VG_(message)(Vg_UserMsg, ""); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1155 | VG_(message)(Vg_UserMsg, "Valgrind library directory: %s", VG_(libdir)); |
njn | 86dc2bc | 2003-09-09 07:26:21 +0000 | [diff] [blame] | 1156 | VG_(message)(Vg_UserMsg, "Command line"); |
| 1157 | for (i = 0; i < VG_(client_argc); i++) |
| 1158 | VG_(message)(Vg_UserMsg, " %s", VG_(client_argv)[i]); |
| 1159 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1160 | VG_(message)(Vg_UserMsg, "Startup, with flags:"); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1161 | for (i = 1; i < argc; i++) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1162 | VG_(message)(Vg_UserMsg, " %s", argv[i]); |
| 1163 | } |
| 1164 | } |
| 1165 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1166 | if (VG_(clo_n_suppressions) < VG_CLO_MAX_SFILES-1 && |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1167 | (VG_(needs).core_errors || VG_(needs).skin_errors)) { |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1168 | /* If there are no suppression files specified and the skin |
| 1169 | needs one, load the default */ |
| 1170 | static const Char default_supp[] = "default.supp"; |
| 1171 | Int len = VG_(strlen)(VG_(libdir)) + 1 + sizeof(default_supp); |
| 1172 | Char *buf = VG_(arena_malloc)(VG_AR_CORE, len); |
| 1173 | VG_(sprintf)(buf, "%s/%s", VG_(libdir), default_supp); |
| 1174 | VG_(clo_suppressions)[VG_(clo_n_suppressions)] = buf; |
| 1175 | VG_(clo_n_suppressions)++; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1176 | } |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1177 | |
njn | 6a23053 | 2003-07-21 10:38:23 +0000 | [diff] [blame] | 1178 | if (VG_(clo_gen_suppressions) && |
| 1179 | !VG_(needs).core_errors && !VG_(needs).skin_errors) { |
| 1180 | config_error("Can't use --gen-suppressions=yes with this skin,\n" |
| 1181 | " as it doesn't generate errors."); |
| 1182 | } |
| 1183 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1186 | /* --------------------------------------------------------------------- |
| 1187 | Copying to/from m_state_static. |
| 1188 | ------------------------------------------------------------------ */ |
| 1189 | |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1190 | /* See comment about this in vg_include.h. Change only with |
| 1191 | great care. |
| 1192 | */ |
| 1193 | __attribute__ ((aligned (16))) |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1194 | UInt VG_(m_state_static) [6 /* segment regs, Intel order */ |
| 1195 | + 8 /* int regs, in Intel order */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1196 | + 1 /* %eflags */ |
| 1197 | + 1 /* %eip */ |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1198 | + VG_SIZE_OF_SSESTATE_W /* FPU state */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1199 | ]; |
| 1200 | |
sewardj | fa492d4 | 2002-12-08 18:20:01 +0000 | [diff] [blame] | 1201 | UInt VG_(insertDflag)(UInt eflags, Int d) |
| 1202 | { |
| 1203 | vg_assert(d == 1 || d == -1); |
| 1204 | eflags &= ~EFlagD; |
| 1205 | |
| 1206 | if (d < 0) |
| 1207 | eflags |= EFlagD; |
| 1208 | |
| 1209 | return eflags; |
| 1210 | } |
| 1211 | |
| 1212 | Int VG_(extractDflag)(UInt eflags) |
| 1213 | { |
| 1214 | Int ret; |
| 1215 | |
| 1216 | if (eflags & EFlagD) |
| 1217 | ret = -1; |
| 1218 | else |
| 1219 | ret = 1; |
| 1220 | |
| 1221 | return ret; |
| 1222 | } |
| 1223 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1224 | void VG_(copy_baseBlock_to_m_state_static) ( void ) |
| 1225 | { |
| 1226 | Int i; |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1227 | VG_(m_state_static)[ 0/4] = VG_(baseBlock)[VGOFF_(m_cs)]; |
| 1228 | VG_(m_state_static)[ 4/4] = VG_(baseBlock)[VGOFF_(m_ss)]; |
| 1229 | VG_(m_state_static)[ 8/4] = VG_(baseBlock)[VGOFF_(m_ds)]; |
| 1230 | VG_(m_state_static)[12/4] = VG_(baseBlock)[VGOFF_(m_es)]; |
| 1231 | VG_(m_state_static)[16/4] = VG_(baseBlock)[VGOFF_(m_fs)]; |
| 1232 | VG_(m_state_static)[20/4] = VG_(baseBlock)[VGOFF_(m_gs)]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1233 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1234 | VG_(m_state_static)[24/4] = VG_(baseBlock)[VGOFF_(m_eax)]; |
| 1235 | VG_(m_state_static)[28/4] = VG_(baseBlock)[VGOFF_(m_ecx)]; |
| 1236 | VG_(m_state_static)[32/4] = VG_(baseBlock)[VGOFF_(m_edx)]; |
| 1237 | VG_(m_state_static)[36/4] = VG_(baseBlock)[VGOFF_(m_ebx)]; |
| 1238 | VG_(m_state_static)[40/4] = VG_(baseBlock)[VGOFF_(m_esp)]; |
| 1239 | VG_(m_state_static)[44/4] = VG_(baseBlock)[VGOFF_(m_ebp)]; |
| 1240 | VG_(m_state_static)[48/4] = VG_(baseBlock)[VGOFF_(m_esi)]; |
| 1241 | VG_(m_state_static)[52/4] = VG_(baseBlock)[VGOFF_(m_edi)]; |
| 1242 | |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1243 | VG_(m_state_static)[56/4] |
| 1244 | = VG_(insertDflag)(VG_(baseBlock)[VGOFF_(m_eflags)], |
| 1245 | VG_(baseBlock)[VGOFF_(m_dflag)]); |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1246 | VG_(m_state_static)[60/4] = VG_(baseBlock)[VGOFF_(m_eip)]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1247 | |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1248 | for (i = 0; i < VG_SIZE_OF_SSESTATE_W; i++) |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1249 | VG_(m_state_static)[64/4 + i] |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1250 | = VG_(baseBlock)[VGOFF_(m_ssestate) + i]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | |
| 1254 | void VG_(copy_m_state_static_to_baseBlock) ( void ) |
| 1255 | { |
| 1256 | Int i; |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1257 | VG_(baseBlock)[VGOFF_(m_cs)] = VG_(m_state_static)[ 0/4]; |
| 1258 | VG_(baseBlock)[VGOFF_(m_ss)] = VG_(m_state_static)[ 4/4]; |
| 1259 | VG_(baseBlock)[VGOFF_(m_ds)] = VG_(m_state_static)[ 8/4]; |
| 1260 | VG_(baseBlock)[VGOFF_(m_es)] = VG_(m_state_static)[12/4]; |
| 1261 | VG_(baseBlock)[VGOFF_(m_fs)] = VG_(m_state_static)[16/4]; |
| 1262 | VG_(baseBlock)[VGOFF_(m_gs)] = VG_(m_state_static)[20/4]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1263 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1264 | VG_(baseBlock)[VGOFF_(m_eax)] = VG_(m_state_static)[24/4]; |
| 1265 | VG_(baseBlock)[VGOFF_(m_ecx)] = VG_(m_state_static)[28/4]; |
| 1266 | VG_(baseBlock)[VGOFF_(m_edx)] = VG_(m_state_static)[32/4]; |
| 1267 | VG_(baseBlock)[VGOFF_(m_ebx)] = VG_(m_state_static)[36/4]; |
| 1268 | VG_(baseBlock)[VGOFF_(m_esp)] = VG_(m_state_static)[40/4]; |
| 1269 | VG_(baseBlock)[VGOFF_(m_ebp)] = VG_(m_state_static)[44/4]; |
| 1270 | VG_(baseBlock)[VGOFF_(m_esi)] = VG_(m_state_static)[48/4]; |
| 1271 | VG_(baseBlock)[VGOFF_(m_edi)] = VG_(m_state_static)[52/4]; |
| 1272 | |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1273 | VG_(baseBlock)[VGOFF_(m_eflags)] |
| 1274 | = VG_(m_state_static)[56/4] & ~EFlagD; |
| 1275 | VG_(baseBlock)[VGOFF_(m_dflag)] |
| 1276 | = VG_(extractDflag)(VG_(m_state_static)[56/4]); |
sewardj | fa492d4 | 2002-12-08 18:20:01 +0000 | [diff] [blame] | 1277 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1278 | VG_(baseBlock)[VGOFF_(m_eip)] = VG_(m_state_static)[60/4]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1279 | |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1280 | for (i = 0; i < VG_SIZE_OF_SSESTATE_W; i++) |
| 1281 | VG_(baseBlock)[VGOFF_(m_ssestate) + i] |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1282 | = VG_(m_state_static)[64/4 + i]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1285 | Addr VG_(get_stack_pointer) ( void ) |
| 1286 | { |
| 1287 | return VG_(baseBlock)[VGOFF_(m_esp)]; |
| 1288 | } |
| 1289 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1290 | /* --------------------------------------------------------------------- |
| 1291 | Show accumulated counts. |
| 1292 | ------------------------------------------------------------------ */ |
| 1293 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1294 | static __inline__ Int safe_idiv(Int a, Int b) |
| 1295 | { |
| 1296 | return (b == 0 ? 0 : a / b); |
| 1297 | } |
| 1298 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1299 | static void vg_show_counts ( void ) |
| 1300 | { |
| 1301 | VG_(message)(Vg_DebugMsg, |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 1302 | " TT/TC: %d tc sectors discarded.", |
| 1303 | VG_(number_of_tc_discards) ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1304 | VG_(message)(Vg_DebugMsg, |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 1305 | " %d chainings, %d unchainings.", |
| 1306 | VG_(bb_enchain_count), VG_(bb_dechain_count) ); |
| 1307 | VG_(message)(Vg_DebugMsg, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1308 | "translate: new %d (%d -> %d; ratio %d:10)", |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1309 | VG_(overall_in_count), |
| 1310 | VG_(overall_in_osize), |
| 1311 | VG_(overall_in_tsize), |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1312 | safe_idiv(10*VG_(overall_in_tsize), VG_(overall_in_osize))); |
| 1313 | VG_(message)(Vg_DebugMsg, |
| 1314 | " discard %d (%d -> %d; ratio %d:10).", |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1315 | VG_(overall_out_count), |
| 1316 | VG_(overall_out_osize), |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1317 | VG_(overall_out_tsize), |
| 1318 | safe_idiv(10*VG_(overall_out_tsize), VG_(overall_out_osize))); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1319 | VG_(message)(Vg_DebugMsg, |
njn | e0205ff | 2003-04-08 00:56:14 +0000 | [diff] [blame] | 1320 | " dispatch: %llu jumps (bb entries), of which %u (%lu%%) were unchained.", |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 1321 | VG_(bbs_done), |
| 1322 | VG_(unchained_jumps_done), |
| 1323 | ((ULong)(100) * (ULong)(VG_(unchained_jumps_done))) |
| 1324 | / ( VG_(bbs_done)==0 ? 1 : VG_(bbs_done) ) |
| 1325 | ); |
| 1326 | |
| 1327 | VG_(message)(Vg_DebugMsg, |
| 1328 | " %d/%d major/minor sched events. %d tt_fast misses.", |
| 1329 | VG_(num_scheduling_events_MAJOR), |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1330 | VG_(num_scheduling_events_MINOR), |
| 1331 | VG_(tt_fast_misses)); |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 1332 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1333 | VG_(message)(Vg_DebugMsg, |
| 1334 | "reg-alloc: %d t-req-spill, " |
| 1335 | "%d+%d orig+spill uis, %d total-reg-r.", |
| 1336 | VG_(translations_needing_spill), |
| 1337 | VG_(uinstrs_prealloc), |
| 1338 | VG_(uinstrs_spill), |
| 1339 | VG_(total_reg_rank) ); |
| 1340 | VG_(message)(Vg_DebugMsg, |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1341 | " sanity: %d cheap, %d expensive checks.", |
| 1342 | VG_(sanity_fast_count), |
| 1343 | VG_(sanity_slow_count) ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1344 | VG_(print_ccall_stats)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | |
| 1348 | /* --------------------------------------------------------------------- |
| 1349 | Main! |
| 1350 | ------------------------------------------------------------------ */ |
| 1351 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1352 | /* Initialize the PID and PGRP of scheduler LWP; this is also called |
| 1353 | in any new children after fork. */ |
| 1354 | static void newpid(ThreadId unused) |
| 1355 | { |
| 1356 | /* PID of scheduler LWP */ |
| 1357 | VG_(main_pid) = VG_(getpid)(); |
| 1358 | VG_(main_pgrp) = VG_(getpgrp)(); |
| 1359 | } |
| 1360 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1361 | /* Where we jump to once Valgrind has got control, and the real |
| 1362 | machine's state has been copied to the m_state_static. */ |
| 1363 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1364 | void VG_(main) ( const KickstartParams *kp, void (*tool_init)(void), void *tool_dlhandle ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1365 | { |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1366 | VgSchedReturnCode src; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1367 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1368 | /* initial state */ |
| 1369 | if (0) |
| 1370 | VG_(printf)("starting esp=%p eip=%p, esp=%p\n", kp->client_esp, kp->client_eip, &src); |
| 1371 | VG_(esp_at_startup) = kp->client_esp; |
| 1372 | VG_(memset)(&VG_(m_state_static), 0, sizeof(VG_(m_state_static))); |
| 1373 | VG_(m_state_static)[40/4] = kp->client_esp; |
| 1374 | VG_(m_state_static)[60/4] = kp->client_eip; |
| 1375 | |
| 1376 | /* set up an initial FPU state (doesn't really matter what it is, |
| 1377 | so long as it's somewhat valid) */ |
| 1378 | if (!VG_(have_ssestate)) |
| 1379 | asm volatile("fwait; fnsave %0; fwait; frstor %0; fwait" |
| 1380 | : : "m" (VG_(m_state_static)[64/4]) : "cc", "memory"); |
| 1381 | else |
| 1382 | asm volatile("fwait; fxsave %0; fwait; andl $0xffbf, %1; fxrstor %0; fwait" |
| 1383 | : : "m" (VG_(m_state_static)[64/4]), "m" (VG_(m_state_static)[(64+24)/4]) : "cc", "memory"); |
| 1384 | |
| 1385 | VG_(brk_base) = VG_(brk_limit) = kp->client_brkbase; |
| 1386 | VG_(client_base) = kp->client_base; |
| 1387 | VG_(client_end) = kp->client_end; |
| 1388 | VG_(client_mapbase) = kp->client_mapbase; |
| 1389 | VG_(clstk_base) = kp->clstk_base; |
| 1390 | VG_(clstk_end) = kp->clstk_end; |
| 1391 | |
| 1392 | VG_(shadow_base) = kp->shadow_base; |
| 1393 | VG_(shadow_end) = kp->shadow_end; |
| 1394 | VG_(valgrind_base) = kp->vg_base; |
| 1395 | VG_(valgrind_mmap_end) = kp->vg_mmap_end; |
| 1396 | VG_(valgrind_end) = kp->vg_end; |
| 1397 | |
| 1398 | VG_(libdir) = kp->libdir; |
| 1399 | |
| 1400 | vg_assert(VG_(clstk_end) == VG_(client_end)); |
| 1401 | |
fitzhardinge | a49f9b5 | 2003-12-16 22:26:45 +0000 | [diff] [blame] | 1402 | if (kp->vgexecfd != -1) |
| 1403 | VG_(vgexecfd) = VG_(safe_fd)(kp->vgexecfd); |
| 1404 | if (kp->clexecfd != -1) |
| 1405 | VG_(clexecfd) = VG_(safe_fd)(kp->clexecfd); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1406 | |
njn | 0c7a5b5 | 2003-04-30 09:00:33 +0000 | [diff] [blame] | 1407 | if (0) { |
| 1408 | if (VG_(have_ssestate)) |
| 1409 | VG_(printf)("Looks like a SSE-capable CPU\n"); |
| 1410 | else |
| 1411 | VG_(printf)("Looks like a MMX-only CPU\n"); |
| 1412 | } |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1413 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1414 | VG_(atfork)(NULL, NULL, newpid); |
| 1415 | newpid(VG_INVALID_THREADID); |
| 1416 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1417 | /* Read /proc/self/maps into a buffer. Must be before: |
| 1418 | - SK_(pre_clo_init)(): so that if it calls VG_(malloc)(), any mmap'd |
| 1419 | superblocks are not erroneously identified as being owned by the |
| 1420 | client, which would be bad. |
| 1421 | - init_memory(): that's where the buffer is parsed |
| 1422 | - init_tt_tc(): so the anonymous mmaps for the translation table and |
| 1423 | translation cache aren't identified as part of the client, which would |
| 1424 | waste > 20M of virtual address space, and be bad. |
| 1425 | */ |
njn | fa1016e | 2003-09-25 17:54:11 +0000 | [diff] [blame] | 1426 | VG_(read_procselfmaps)(); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1427 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1428 | /* Setup stuff that depends on the skin. Must be before: |
| 1429 | - vg_init_baseBlock(): to register helpers |
| 1430 | - process_cmd_line_options(): to register skin name and description, |
| 1431 | and turn on/off 'command_line_options' need |
| 1432 | - init_memory() (to setup memory event trackers). |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1433 | */ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1434 | (*tool_init)(); |
| 1435 | VG_(tool_init_dlsym)(tool_dlhandle); |
| 1436 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1437 | VG_(sanity_check_needs)(); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1438 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1439 | /* Process Valgrind's command-line opts */ |
| 1440 | process_cmd_line_options(kp); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1441 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1442 | /* Hook to delay things long enough so we can get the pid and |
| 1443 | attach GDB in another shell. */ |
| 1444 | if (VG_(clo_wait_for_gdb)) { |
| 1445 | VG_(printf)("pid=%d\n", VG_(getpid)()); |
| 1446 | /* do "jump *$eip" to skip this in gdb */ |
| 1447 | VG_(do_syscall)(__NR_pause); |
| 1448 | } |
| 1449 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1450 | /* Do post command-line processing initialisation. Must be before: |
| 1451 | - vg_init_baseBlock(): to register any more helpers |
| 1452 | */ |
njn | cc7bb47 | 2002-10-14 09:25:19 +0000 | [diff] [blame] | 1453 | SK_(post_clo_init)(); |
| 1454 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1455 | /* Set up baseBlock offsets and copy the saved machine's state into it. */ |
njn | cc7bb47 | 2002-10-14 09:25:19 +0000 | [diff] [blame] | 1456 | vg_init_baseBlock(); |
| 1457 | |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 1458 | /* Search for file descriptors that are inherited from our parent. */ |
| 1459 | if (VG_(clo_track_fds)) |
| 1460 | VG_(init_preopened_fds)(); |
| 1461 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1462 | /* Initialise the scheduler, and copy the client's state from |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1463 | baseBlock into VG_(threads)[1]. Must be before: |
| 1464 | - VG_(sigstartup_actions)() |
| 1465 | */ |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1466 | VG_(scheduler_init)(); |
| 1467 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1468 | /* Set up the ProxyLWP machinery */ |
| 1469 | VG_(proxy_init)(); |
| 1470 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1471 | /* Initialise the signal handling subsystem, temporarily parking |
| 1472 | the saved blocking-mask in saved_sigmask. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1473 | VG_(sigstartup_actions)(); |
| 1474 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1475 | /* Perhaps we're profiling Valgrind? */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1476 | if (VG_(clo_profile)) |
| 1477 | VGP_(init_profiling)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1478 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1479 | /* Start calibration of our RDTSC-based clock. */ |
| 1480 | VG_(start_rdtsc_calibration)(); |
| 1481 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1482 | /* Parse /proc/self/maps to learn about startup segments. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1483 | VGP_PUSHCC(VgpInitMem); |
| 1484 | VG_(init_memory)(); |
| 1485 | VGP_POPCC(VgpInitMem); |
| 1486 | |
| 1487 | /* Read the list of errors to suppress. This should be found in |
| 1488 | the file specified by vg_clo_suppressions. */ |
| 1489 | if (VG_(needs).core_errors || VG_(needs).skin_errors) |
| 1490 | VG_(load_suppressions)(); |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1491 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1492 | /* End calibration of our RDTSC-based clock, leaving it as long as |
| 1493 | we can. */ |
| 1494 | VG_(end_rdtsc_calibration)(); |
| 1495 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1496 | /* Initialise translation table and translation cache. */ |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1497 | VG_(init_tt_tc)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1498 | |
| 1499 | if (VG_(clo_verbosity) == 1) { |
| 1500 | VG_(message)(Vg_UserMsg, |
| 1501 | "For more details, rerun with: -v"); |
| 1502 | } |
| 1503 | |
sewardj | 25c7c3a | 2003-07-10 00:17:58 +0000 | [diff] [blame] | 1504 | /* Force a read of the debug info so that we can look for |
| 1505 | glibc entry points to intercept. */ |
sewardj | 25c7c3a | 2003-07-10 00:17:58 +0000 | [diff] [blame] | 1506 | VG_(setup_code_redirect_table)(); |
| 1507 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1508 | /* Now it is safe for malloc et al in vg_clientmalloc.c to act |
| 1509 | instrumented-ly. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1510 | if (VG_(clo_verbosity) > 0) |
| 1511 | VG_(message)(Vg_UserMsg, ""); |
| 1512 | |
| 1513 | VG_(bbs_to_go) = VG_(clo_stop_after); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1514 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1515 | if (VG_(clo_pointercheck)) { |
| 1516 | vki_modify_ldt_t ldt = { VG_POINTERCHECK_SEGIDX, |
| 1517 | VG_(client_base), |
| 1518 | (VG_(client_end)-VG_(client_base)) / VKI_BYTES_PER_PAGE, |
| 1519 | 1, /* 32 bit */ |
| 1520 | 0, /* contents: data, RW, non-expanding */ |
| 1521 | 0, /* not read-exec only */ |
| 1522 | 1, /* limit in pages */ |
| 1523 | 0, /* !seg not present */ |
| 1524 | 1, /* usable */ |
| 1525 | }; |
| 1526 | Int ret = VG_(do_syscall)(__NR_modify_ldt, 1, &ldt, sizeof(ldt)); |
| 1527 | |
| 1528 | if (ret < 0) { |
| 1529 | VG_(message)(Vg_UserMsg, |
| 1530 | "Warning: ignoring --pointercheck=yes, " |
| 1531 | "because modify_ldt failed (errno=%d)", -ret); |
| 1532 | VG_(clo_pointercheck) = False; |
| 1533 | } |
| 1534 | } |
| 1535 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1536 | /* Run! */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1537 | VG_(running_on_simd_CPU) = True; |
sewardj | 671ff54 | 2002-05-07 09:25:30 +0000 | [diff] [blame] | 1538 | VGP_PUSHCC(VgpSched); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1539 | |
| 1540 | if (__builtin_setjmp(&VG_(fatal_signal_jmpbuf)) == 0) { |
| 1541 | VG_(fatal_signal_set) = True; |
| 1542 | src = VG_(scheduler)(); |
| 1543 | } else |
| 1544 | src = VgSrc_FatalSig; |
| 1545 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1546 | VGP_POPCC(VgpSched); |
| 1547 | VG_(running_on_simd_CPU) = False; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1548 | |
| 1549 | if (VG_(clo_verbosity) > 0) |
| 1550 | VG_(message)(Vg_UserMsg, ""); |
| 1551 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1552 | if (src == VgSrc_Deadlock) { |
| 1553 | VG_(message)(Vg_UserMsg, |
| 1554 | "Warning: pthread scheduler exited due to deadlock"); |
| 1555 | } |
| 1556 | |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 1557 | /* Print out file descriptor summary and stats. */ |
| 1558 | if(VG_(clo_track_fds)) |
| 1559 | VG_(fd_stats)(); |
| 1560 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1561 | if (VG_(needs).core_errors || VG_(needs).skin_errors) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1562 | VG_(show_all_errors)(); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1563 | |
njn | 7d9f94d | 2003-04-22 21:41:40 +0000 | [diff] [blame] | 1564 | SK_(fini)( VG_(exitcode) ); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1565 | |
sewardj | 0c3b53f | 2002-05-01 01:58:35 +0000 | [diff] [blame] | 1566 | VG_(do_sanity_checks)( True /*include expensive checks*/ ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1567 | |
| 1568 | if (VG_(clo_verbosity) > 1) |
| 1569 | vg_show_counts(); |
| 1570 | |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 1571 | if (VG_(clo_verbosity) > 3) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1572 | VG_(print_UInstr_histogram)(); |
| 1573 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1574 | if (0) { |
| 1575 | VG_(message)(Vg_DebugMsg, ""); |
| 1576 | VG_(message)(Vg_DebugMsg, |
| 1577 | "------ Valgrind's internal memory use stats follow ------" ); |
| 1578 | VG_(mallocSanityCheckAll)(); |
| 1579 | VG_(show_all_arena_stats)(); |
| 1580 | VG_(message)(Vg_DebugMsg, |
| 1581 | "------ Valgrind's ExeContext management stats follow ------" ); |
| 1582 | VG_(show_ExeContext_stats)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1585 | if (VG_(clo_profile)) |
| 1586 | VGP_(done_profiling)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1587 | |
| 1588 | VG_(shutdown_logging)(); |
| 1589 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1590 | /* We're exiting, so nuke all the threads and clean up the proxy LWPs */ |
| 1591 | vg_assert(src == VgSrc_FatalSig || |
| 1592 | VG_(threads)[VG_(last_run_tid)].status == VgTs_Runnable || |
| 1593 | VG_(threads)[VG_(last_run_tid)].status == VgTs_WaitJoiner); |
| 1594 | VG_(nuke_all_threads_except)(VG_INVALID_THREADID); |
| 1595 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1596 | /* Decide how to exit. This depends on what the scheduler |
| 1597 | returned. */ |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1598 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1599 | switch (src) { |
| 1600 | case VgSrc_ExitSyscall: /* the normal way out */ |
| 1601 | vg_assert(VG_(last_run_tid) > 0 |
| 1602 | && VG_(last_run_tid) < VG_N_THREADS); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1603 | VG_(proxy_shutdown)(); |
| 1604 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1605 | /* The thread's %EBX at the time it did __NR_exit() will hold |
| 1606 | the arg to __NR_exit(), so we just do __NR_exit() with |
| 1607 | that arg. */ |
| 1608 | VG_(exit)( VG_(exitcode) ); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1609 | /* NOT ALIVE HERE! */ |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 1610 | VG_(core_panic)("entered the afterlife in vg_main() -- ExitSyscall"); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1611 | break; /* what the hell :) */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1612 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1613 | case VgSrc_Deadlock: |
| 1614 | /* Just exit now. No point in continuing. */ |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1615 | VG_(proxy_shutdown)(); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1616 | VG_(exit)(0); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 1617 | VG_(core_panic)("entered the afterlife in vg_main() -- Deadlock"); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1618 | break; |
| 1619 | |
| 1620 | case VgSrc_BbsDone: |
| 1621 | /* Tricky; we have to try and switch back to the real CPU. |
| 1622 | This is all very dodgy and won't work at all in the |
| 1623 | presence of threads, or if the client happened to be |
| 1624 | running a signal handler. */ |
| 1625 | /* Prepare to restore state to the real CPU. */ |
sewardj | 839299f | 2003-06-14 11:57:59 +0000 | [diff] [blame] | 1626 | VG_(sigshutdown_actions)(); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1627 | VG_(load_thread_state)(1 /* root thread */ ); |
| 1628 | VG_(copy_baseBlock_to_m_state_static)(); |
| 1629 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1630 | VG_(proxy_shutdown)(); |
| 1631 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1632 | /* This pushes a return address on the simulator's stack, |
| 1633 | which is abandoned. We call vg_sigshutdown_actions() at |
| 1634 | the end of vg_switch_to_real_CPU(), so as to ensure that |
| 1635 | the original stack and machine state is restored before |
| 1636 | the real signal mechanism is restored. */ |
| 1637 | VG_(switch_to_real_CPU)(); |
| 1638 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1639 | case VgSrc_FatalSig: |
| 1640 | /* We were killed by a fatal signal, so replicate the effect */ |
| 1641 | vg_assert(VG_(fatal_sigNo) != -1); |
| 1642 | VG_(kill_self)(VG_(fatal_sigNo)); |
| 1643 | VG_(core_panic)("vg_main(): signal was supposed to be fatal"); |
| 1644 | break; |
| 1645 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1646 | default: |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 1647 | VG_(core_panic)("vg_main(): unexpected scheduler return code"); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1648 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | |
| 1652 | /* Debugging thing .. can be called from assembly with OYNK macro. */ |
| 1653 | void VG_(oynk) ( Int n ) |
| 1654 | { |
| 1655 | OINK(n); |
| 1656 | } |
| 1657 | |
| 1658 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1659 | /* Walk through a colon-separated environment variable, and remove the |
| 1660 | entries which matches file_pattern. It slides everything down over |
| 1661 | the removed entries, and pads the remaining space with '\0'. It |
| 1662 | modifies the entries in place (in the client address space), but it |
| 1663 | shouldn't matter too much, since we only do this just before an |
| 1664 | execve(). |
sewardj | 78e25c9 | 2002-05-20 23:38:33 +0000 | [diff] [blame] | 1665 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1666 | This is also careful to mop up any excess ':'s, since empty strings |
| 1667 | delimited by ':' are considered to be '.' in a path. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1668 | */ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1669 | void VG_(mash_colon_env)(Char *varp, const Char *remove_pattern) |
sewardj | 45b672d | 2003-07-25 19:58:11 +0000 | [diff] [blame] | 1670 | { |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1671 | Char *const start = varp; |
| 1672 | Char *entry_start = varp; |
| 1673 | Char *output = varp; |
sewardj | 45b672d | 2003-07-25 19:58:11 +0000 | [diff] [blame] | 1674 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1675 | if (varp == NULL) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1676 | return; |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1677 | |
| 1678 | while(*varp) { |
| 1679 | if (*varp == ':') { |
| 1680 | Char prev; |
| 1681 | Bool match; |
| 1682 | |
| 1683 | /* This is a bit subtle: we want to match against the entry |
| 1684 | we just copied, because it may have overlapped with |
| 1685 | itself, junking the original. */ |
| 1686 | |
| 1687 | prev = *output; |
| 1688 | *output = '\0'; |
| 1689 | |
| 1690 | match = VG_(string_match)(remove_pattern, entry_start); |
| 1691 | |
| 1692 | *output = prev; |
| 1693 | |
| 1694 | if (match) { |
| 1695 | output = entry_start; |
| 1696 | varp++; /* skip ':' after removed entry */ |
| 1697 | } else |
| 1698 | entry_start = output+1; /* entry starts after ':' */ |
| 1699 | } |
| 1700 | |
| 1701 | *output++ = *varp++; |
sewardj | 3e1eb1f | 2002-05-18 13:14:17 +0000 | [diff] [blame] | 1702 | } |
| 1703 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1704 | /* match against the last entry */ |
| 1705 | if (VG_(string_match)(remove_pattern, entry_start)) { |
| 1706 | output = entry_start; |
| 1707 | if (output > start) { |
| 1708 | /* remove trailing ':' */ |
| 1709 | output--; |
| 1710 | vg_assert(*output == ':'); |
| 1711 | } |
| 1712 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1713 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1714 | /* pad out the left-overs with '\0' */ |
| 1715 | while(output < varp) |
| 1716 | *output++ = '\0'; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | /* RUNS ON THE CLIENT'S STACK, but on the real CPU. Start GDB and get |
| 1720 | it to attach to this process. Called if the user requests this |
| 1721 | service after an error has been shown, so she can poke around and |
| 1722 | look at parameters, memory, etc. You can't meaningfully get GDB to |
| 1723 | continue the program, though; to continue, quit GDB. */ |
fitzhardinge | a49f9b5 | 2003-12-16 22:26:45 +0000 | [diff] [blame] | 1724 | void VG_(start_GDB_whilst_on_client_stack) ( void ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1725 | { |
sewardj | e6a2524 | 2002-04-21 22:03:07 +0000 | [diff] [blame] | 1726 | Int res; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1727 | UChar buf[100]; |
njn | 9315df3 | 2003-04-16 20:50:50 +0000 | [diff] [blame] | 1728 | |
fitzhardinge | a49f9b5 | 2003-12-16 22:26:45 +0000 | [diff] [blame] | 1729 | VG_(sprintf)(buf, "%s -nw /proc/%d/fd/%d %d", |
| 1730 | VG_(clo_GDB_path), VG_(getpid)(), VG_(clexecfd), VG_(getpid)()); |
sewardj | e6a2524 | 2002-04-21 22:03:07 +0000 | [diff] [blame] | 1731 | VG_(message)(Vg_UserMsg, "starting GDB with cmd: %s", buf); |
| 1732 | res = VG_(system)(buf); |
| 1733 | if (res == 0) { |
| 1734 | VG_(message)(Vg_UserMsg, ""); |
| 1735 | VG_(message)(Vg_UserMsg, |
| 1736 | "GDB has detached. Valgrind regains control. We continue."); |
| 1737 | } else { |
| 1738 | VG_(message)(Vg_UserMsg, "Apparently failed!"); |
| 1739 | VG_(message)(Vg_UserMsg, ""); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1740 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | |
| 1744 | /* Print some helpful-ish text about unimplemented things, and give |
| 1745 | up. */ |
sewardj | cfc39b2 | 2002-05-08 01:58:18 +0000 | [diff] [blame] | 1746 | void VG_(unimplemented) ( Char* msg ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1747 | { |
| 1748 | VG_(message)(Vg_UserMsg, ""); |
| 1749 | VG_(message)(Vg_UserMsg, |
| 1750 | "Valgrind detected that your program requires"); |
| 1751 | VG_(message)(Vg_UserMsg, |
| 1752 | "the following unimplemented functionality:"); |
| 1753 | VG_(message)(Vg_UserMsg, " %s", msg); |
| 1754 | VG_(message)(Vg_UserMsg, |
| 1755 | "This may be because the functionality is hard to implement,"); |
| 1756 | VG_(message)(Vg_UserMsg, |
| 1757 | "or because no reasonable program would behave this way,"); |
| 1758 | VG_(message)(Vg_UserMsg, |
nethercote | 421281e | 2003-11-20 16:20:55 +0000 | [diff] [blame] | 1759 | "or because nobody has yet needed it. In any case, let us know at"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1760 | VG_(message)(Vg_UserMsg, |
nethercote | 421281e | 2003-11-20 16:20:55 +0000 | [diff] [blame] | 1761 | "%s and/or try to work around the problem, if you can.", VG_BUGS_TO); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1762 | VG_(message)(Vg_UserMsg, |
| 1763 | ""); |
| 1764 | VG_(message)(Vg_UserMsg, |
| 1765 | "Valgrind has to exit now. Sorry. Bye!"); |
| 1766 | VG_(message)(Vg_UserMsg, |
| 1767 | ""); |
sewardj | 15a43e1 | 2002-04-17 19:35:12 +0000 | [diff] [blame] | 1768 | VG_(pp_sched_status)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1769 | VG_(exit)(1); |
| 1770 | } |
| 1771 | |
| 1772 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1773 | /* --------------------------------------------------------------------- |
| 1774 | Sanity check machinery (permanently engaged). |
| 1775 | ------------------------------------------------------------------ */ |
| 1776 | |
| 1777 | /* A fast sanity check -- suitable for calling circa once per |
| 1778 | millisecond. */ |
| 1779 | |
| 1780 | void VG_(do_sanity_checks) ( Bool force_expensive ) |
| 1781 | { |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1782 | VGP_PUSHCC(VgpCoreCheapSanity); |
| 1783 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1784 | if (VG_(sanity_level) < 1) return; |
| 1785 | |
| 1786 | /* --- First do all the tests that we can do quickly. ---*/ |
| 1787 | |
| 1788 | VG_(sanity_fast_count)++; |
| 1789 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1790 | /* Check stuff pertaining to the memory check system. */ |
| 1791 | |
| 1792 | /* Check that nobody has spuriously claimed that the first or |
| 1793 | last 16 pages of memory have become accessible [...] */ |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1794 | if (VG_(needs).sanity_checks) { |
| 1795 | VGP_PUSHCC(VgpSkinCheapSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1796 | vg_assert(SK_(cheap_sanity_check)()); |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1797 | VGP_POPCC(VgpSkinCheapSanity); |
| 1798 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1799 | |
| 1800 | /* --- Now some more expensive checks. ---*/ |
| 1801 | |
| 1802 | /* Once every 25 times, check some more expensive stuff. */ |
| 1803 | if ( force_expensive |
| 1804 | || VG_(sanity_level) > 1 |
| 1805 | || (VG_(sanity_level) == 1 && (VG_(sanity_fast_count) % 25) == 0)) { |
| 1806 | |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1807 | VGP_PUSHCC(VgpCoreExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1808 | VG_(sanity_slow_count)++; |
| 1809 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1810 | VG_(proxy_sanity)(); |
| 1811 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1812 | # if 0 |
| 1813 | { void zzzmemscan(void); zzzmemscan(); } |
| 1814 | # endif |
| 1815 | |
| 1816 | if ((VG_(sanity_fast_count) % 250) == 0) |
| 1817 | VG_(sanity_check_tc_tt)(); |
| 1818 | |
| 1819 | if (VG_(needs).sanity_checks) { |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1820 | VGP_PUSHCC(VgpSkinExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1821 | vg_assert(SK_(expensive_sanity_check)()); |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1822 | VGP_POPCC(VgpSkinExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1823 | } |
| 1824 | /* |
| 1825 | if ((VG_(sanity_fast_count) % 500) == 0) VG_(mallocSanityCheckAll)(); |
| 1826 | */ |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1827 | VGP_POPCC(VgpCoreExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | if (VG_(sanity_level) > 1) { |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1831 | VGP_PUSHCC(VgpCoreExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1832 | /* Check sanity of the low-level memory manager. Note that bugs |
| 1833 | in the client's code can cause this to fail, so we don't do |
| 1834 | this check unless specially asked for. And because it's |
| 1835 | potentially very expensive. */ |
| 1836 | VG_(mallocSanityCheckAll)(); |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1837 | VGP_POPCC(VgpCoreExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1838 | } |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1839 | VGP_POPCC(VgpCoreCheapSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1840 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1841 | /*--------------------------------------------------------------------*/ |
| 1842 | /*--- end vg_main.c ---*/ |
| 1843 | /*--------------------------------------------------------------------*/ |