sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Management of error messages. vg_errcontext.c ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, an extensible x86 protected-mode |
| 8 | emulator for monitoring program execution on x86-Unixes. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 9 | |
nethercote | bb1c991 | 2004-01-04 16:43:23 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2004 Julian Seward |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 11 | jseward@acm.org |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 28 | The GNU General Public License is contained in the file COPYING. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 29 | */ |
| 30 | |
| 31 | #include "vg_include.h" |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 32 | |
| 33 | /*------------------------------------------------------------*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 34 | /*--- Globals ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 35 | /*------------------------------------------------------------*/ |
| 36 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 37 | /* The list of error contexts found, both suppressed and unsuppressed. |
| 38 | Initially empty, and grows as errors are detected. */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 39 | static Error* vg_errors = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 40 | |
| 41 | /* The list of suppression directives, as read from the specified |
| 42 | suppressions file. */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 43 | static Supp* vg_suppressions = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 44 | |
| 45 | /* Running count of unsuppressed errors detected. */ |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 46 | UInt VG_(n_errs_found) = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 47 | |
| 48 | /* Running count of suppressed errors detected. */ |
| 49 | static UInt vg_n_errs_suppressed = 0; |
| 50 | |
| 51 | /* forwards ... */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 52 | static Supp* is_suppressible_error ( Error* err ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 53 | |
| 54 | |
| 55 | /*------------------------------------------------------------*/ |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame^] | 56 | /*--- Error type ---*/ |
| 57 | /*------------------------------------------------------------*/ |
| 58 | |
| 59 | /* Note: it is imperative this doesn't overlap with (0..) at all, as skins |
| 60 | * effectively extend it by defining their own enums in the (0..) range. */ |
| 61 | typedef |
| 62 | enum { |
| 63 | PThreadErr = -1, // Pthreading error |
| 64 | } |
| 65 | CoreErrorKind; |
| 66 | |
| 67 | /* Errors. Extensible (via the 'extra' field). Tools can use a normal |
| 68 | enum (with element values in the normal range (0..)) for `ekind'. |
| 69 | Functions for getting/setting the tool-relevant fields are in |
| 70 | include/vg_skin.h. |
| 71 | |
| 72 | When errors are found and recorded with VG_(maybe_record_error)(), all |
| 73 | the tool must do is pass in the four parameters; core will |
| 74 | allocate/initialise the error record. |
| 75 | */ |
| 76 | struct _Error { |
| 77 | struct _Error* next; |
| 78 | // NULL if unsuppressed; or ptr to suppression record. |
| 79 | Supp* supp; |
| 80 | Int count; |
| 81 | ThreadId tid; |
| 82 | |
| 83 | // The tool-specific part |
| 84 | ExeContext* where; // Initialised by core |
| 85 | Int ekind; // Used by ALL. Must be in the range (0..) |
| 86 | Addr addr; // Used frequently |
| 87 | Char* string; // Used frequently |
| 88 | void* extra; // For any tool-specific extras |
| 89 | }; |
| 90 | |
| 91 | ExeContext* VG_(get_error_where) ( Error* err ) |
| 92 | { |
| 93 | return err->where; |
| 94 | } |
| 95 | |
| 96 | ErrorKind VG_(get_error_kind) ( Error* err ) |
| 97 | { |
| 98 | return err->ekind; |
| 99 | } |
| 100 | |
| 101 | Addr VG_(get_error_address) ( Error* err ) |
| 102 | { |
| 103 | return err->addr; |
| 104 | } |
| 105 | |
| 106 | Char* VG_(get_error_string) ( Error* err ) |
| 107 | { |
| 108 | return err->string; |
| 109 | } |
| 110 | |
| 111 | void* VG_(get_error_extra) ( Error* err ) |
| 112 | { |
| 113 | return err->extra; |
| 114 | } |
| 115 | |
| 116 | /*------------------------------------------------------------*/ |
| 117 | /*--- Suppression type ---*/ |
| 118 | /*------------------------------------------------------------*/ |
| 119 | |
| 120 | /* Note: it is imperative this doesn't overlap with (0..) at all, as tools |
| 121 | * effectively extend it by defining their own enums in the (0..) range. */ |
| 122 | typedef |
| 123 | enum { |
| 124 | PThreadSupp = -1, /* Matches PThreadErr */ |
| 125 | } |
| 126 | CoreSuppKind; |
| 127 | |
| 128 | /* For each caller specified for a suppression, record the nature of |
| 129 | the caller name. Not of interest to tools. */ |
| 130 | typedef |
| 131 | enum { |
| 132 | ObjName, /* Name is of an shared object file. */ |
| 133 | FunName /* Name is of a function. */ |
| 134 | } |
| 135 | SuppLocTy; |
| 136 | |
| 137 | /* Suppressions. Tools can get/set tool-relevant parts with functions |
| 138 | declared in include/vg_skin.h. Extensible via the 'extra' field. |
| 139 | Tools can use a normal enum (with element values in the normal range |
| 140 | (0..)) for `skind'. */ |
| 141 | struct _Supp { |
| 142 | struct _Supp* next; |
| 143 | Int count; // The number of times this error has been suppressed. |
| 144 | Char* sname; // The name by which the suppression is referred to. |
| 145 | /* First two (name of fn where err occurs, and immediate caller) |
| 146 | * are mandatory; extra two are optional. */ |
| 147 | SuppLocTy caller_ty[VG_N_SUPP_CALLERS]; |
| 148 | Char* caller [VG_N_SUPP_CALLERS]; |
| 149 | |
| 150 | /* The tool-specific part */ |
| 151 | SuppKind skind; // What kind of suppression. Must use the range (0..). |
| 152 | Char* string; // String -- use is optional. NULL by default. |
| 153 | void* extra; // Anything else -- use is optional. NULL by default. |
| 154 | }; |
| 155 | |
| 156 | SuppKind VG_(get_supp_kind) ( Supp* su ) |
| 157 | { |
| 158 | return su->skind; |
| 159 | } |
| 160 | |
| 161 | Char* VG_(get_supp_string) ( Supp* su ) |
| 162 | { |
| 163 | return su->string; |
| 164 | } |
| 165 | |
| 166 | void* VG_(get_supp_extra) ( Supp* su ) |
| 167 | { |
| 168 | return su->extra; |
| 169 | } |
| 170 | |
| 171 | |
| 172 | void VG_(set_supp_kind) ( Supp* su, SuppKind skind ) |
| 173 | { |
| 174 | su->skind = skind; |
| 175 | } |
| 176 | |
| 177 | void VG_(set_supp_string) ( Supp* su, Char* string ) |
| 178 | { |
| 179 | su->string = string; |
| 180 | } |
| 181 | |
| 182 | void VG_(set_supp_extra) ( Supp* su, void* extra ) |
| 183 | { |
| 184 | su->extra = extra; |
| 185 | } |
| 186 | |
| 187 | |
| 188 | /*------------------------------------------------------------*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 189 | /*--- Helper fns ---*/ |
| 190 | /*------------------------------------------------------------*/ |
| 191 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 192 | /* Compare error contexts, to detect duplicates. Note that if they |
| 193 | are otherwise the same, the faulting addrs and associated rwoffsets |
| 194 | are allowed to be different. */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 195 | static Bool eq_Error ( VgRes res, Error* e1, Error* e2 ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 196 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 197 | if (e1->ekind != e2->ekind) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 198 | return False; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 199 | if (!VG_(eq_ExeContext)(res, e1->where, e2->where)) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 200 | return False; |
| 201 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 202 | switch (e1->ekind) { |
sewardj | 4dced35 | 2002-06-04 22:54:20 +0000 | [diff] [blame] | 203 | case PThreadErr: |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 204 | vg_assert(VG_(needs).core_errors); |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 205 | if (e1->string == e2->string) |
sewardj | 4dced35 | 2002-06-04 22:54:20 +0000 | [diff] [blame] | 206 | return True; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 207 | if (0 == VG_(strcmp)(e1->string, e2->string)) |
sewardj | 4dced35 | 2002-06-04 22:54:20 +0000 | [diff] [blame] | 208 | return True; |
| 209 | return False; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 210 | default: |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 211 | if (VG_(needs).skin_errors) |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 212 | return SK_(eq_SkinError)(res, e1, e2); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 213 | else { |
| 214 | VG_(printf)("\nUnhandled error type: %u. VG_(needs).skin_errors\n" |
| 215 | "probably needs to be set.\n", |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 216 | e1->ekind); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 217 | VG_(skin_panic)("unhandled error type"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 218 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 222 | static void pp_Error ( Error* err, Bool printCount ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 223 | { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 224 | if (printCount) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 225 | VG_(message)(Vg_UserMsg, "Observed %d times:", err->count ); |
| 226 | if (err->tid > 1) |
| 227 | VG_(message)(Vg_UserMsg, "Thread %d:", err->tid ); |
| 228 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 229 | switch (err->ekind) { |
sewardj | 4dced35 | 2002-06-04 22:54:20 +0000 | [diff] [blame] | 230 | case PThreadErr: |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 231 | vg_assert(VG_(needs).core_errors); |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 232 | VG_(message)(Vg_UserMsg, "%s", err->string ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 233 | VG_(pp_ExeContext)(err->where); |
sewardj | 4dced35 | 2002-06-04 22:54:20 +0000 | [diff] [blame] | 234 | break; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 235 | default: |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 236 | if (VG_(needs).skin_errors) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 237 | SK_(pp_SkinError)( err ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 238 | else { |
| 239 | VG_(printf)("\nUnhandled error type: %u. VG_(needs).skin_errors\n" |
| 240 | "probably needs to be set?\n", |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 241 | err->ekind); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 242 | VG_(skin_panic)("unhandled error type"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 243 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 247 | /* Figure out if we want to perform a given action for this error, possibly |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 248 | by asking the user. */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 249 | Bool VG_(is_action_requested) ( Char* action, Bool* clo ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 250 | { |
| 251 | Char ch, ch2; |
| 252 | Int res; |
| 253 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 254 | if (*clo == False) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 255 | return False; |
| 256 | |
| 257 | VG_(message)(Vg_UserMsg, ""); |
| 258 | |
| 259 | again: |
| 260 | VG_(printf)( |
| 261 | "==%d== " |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 262 | "---- %s ? --- [Return/N/n/Y/y/C/c] ---- ", |
| 263 | VG_(getpid)(), action |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 264 | ); |
| 265 | |
sewardj | 6024b21 | 2003-07-13 10:54:33 +0000 | [diff] [blame] | 266 | res = VG_(read)(VG_(clo_input_fd), &ch, 1); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 267 | if (res != 1) goto ioerror; |
| 268 | /* res == 1 */ |
| 269 | if (ch == '\n') return False; |
| 270 | if (ch != 'N' && ch != 'n' && ch != 'Y' && ch != 'y' |
| 271 | && ch != 'C' && ch != 'c') goto again; |
| 272 | |
sewardj | 6024b21 | 2003-07-13 10:54:33 +0000 | [diff] [blame] | 273 | res = VG_(read)(VG_(clo_input_fd), &ch2, 1); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 274 | if (res != 1) goto ioerror; |
| 275 | if (ch2 != '\n') goto again; |
| 276 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 277 | /* No, don't want to do action. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 278 | if (ch == 'n' || ch == 'N') return False; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 279 | /* Yes, want to do action. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 280 | if (ch == 'y' || ch == 'Y') return True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 281 | /* No, don't want to do action, and don't ask again either. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 282 | vg_assert(ch == 'c' || ch == 'C'); |
| 283 | |
| 284 | ioerror: |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 285 | *clo = False; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 286 | return False; |
| 287 | } |
| 288 | |
| 289 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 290 | /* I've gone all object-oriented... initialisation depends on where the |
| 291 | error comes from: |
| 292 | |
| 293 | - If from generated code (tst == NULL), the %EIP/%EBP values that we |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 294 | need in order to attach GDB are picked up out of VG_(baseBlock) rather |
| 295 | than from the thread table (vg_threads in vg_scheduler.c). |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 296 | |
| 297 | - If not from generated code but in response to requests passed back to |
| 298 | the scheduler (tst != NULL), we pick up %EIP/%EBP values from the |
| 299 | stored thread state, not from VG_(baseBlock). |
| 300 | */ |
| 301 | static __inline__ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 302 | void construct_error ( Error* err, ThreadId tid, ErrorKind ekind, Addr a, |
| 303 | Char* s, void* extra, ExeContext* where ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 304 | { |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 305 | sk_assert(tid < VG_N_THREADS); |
| 306 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 307 | /* Core-only parts */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 308 | err->next = NULL; |
| 309 | err->supp = NULL; |
| 310 | err->count = 1; |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 311 | err->tid = tid; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 312 | if (NULL == where) |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 313 | err->where = VG_(get_ExeContext)( tid ); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 314 | else |
| 315 | err->where = where; |
njn | 1d6c4bc | 2002-11-21 13:38:08 +0000 | [diff] [blame] | 316 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 317 | /* Skin-relevant parts */ |
| 318 | err->ekind = ekind; |
| 319 | err->addr = a; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 320 | err->extra = extra; |
sewardj | a602261 | 2003-07-24 23:50:17 +0000 | [diff] [blame] | 321 | err->string = s; |
| 322 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 323 | /* sanity... */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 324 | vg_assert( tid < VG_N_THREADS ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 325 | } |
| 326 | |
nethercote | 10d481a | 2004-01-25 20:33:53 +0000 | [diff] [blame] | 327 | static void gen_suppression(Error* err) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 328 | { |
sewardj | 05bcdcb | 2003-05-18 10:05:38 +0000 | [diff] [blame] | 329 | Int i; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 330 | UChar buf[M_VG_ERRTXT]; |
nethercote | 77eba60 | 2003-11-13 17:35:04 +0000 | [diff] [blame] | 331 | Bool main_done = False; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 332 | ExeContext* ec = VG_(get_error_where)(err); |
| 333 | Int stop_at = VG_(clo_backtrace_size); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 334 | |
njn | 633de32 | 2003-05-12 20:40:13 +0000 | [diff] [blame] | 335 | if (stop_at > 4) stop_at = 4; /* At most four names */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 336 | vg_assert(stop_at > 0); |
| 337 | |
| 338 | VG_(printf)("{\n"); |
| 339 | VG_(printf)(" <insert a suppression name here>\n"); |
njn | 6a23053 | 2003-07-21 10:38:23 +0000 | [diff] [blame] | 340 | |
| 341 | if (PThreadErr == err->ekind) { |
| 342 | VG_(printf)(" core:PThread\n"); |
| 343 | |
| 344 | } else { |
| 345 | Char* name = SK_(get_error_name)(err); |
| 346 | if (NULL == name) { |
| 347 | VG_(message)(Vg_UserMsg, |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 348 | "(tool does not allow error to be suppressed)"); |
njn | 6a23053 | 2003-07-21 10:38:23 +0000 | [diff] [blame] | 349 | return; |
| 350 | } |
| 351 | VG_(printf)(" %s:%s\n", VG_(details).name, name); |
| 352 | SK_(print_extra_suppression_info)(err); |
| 353 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 354 | |
| 355 | /* This loop condensed from VG_(mini_stack_dump)() */ |
| 356 | i = 0; |
| 357 | do { |
| 358 | Addr eip = ec->eips[i]; |
nethercote | 77eba60 | 2003-11-13 17:35:04 +0000 | [diff] [blame] | 359 | if (i > 0) eip--; /* point to calling line */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 360 | if ( VG_(get_fnname_nodemangle) (eip, buf, M_VG_ERRTXT) ) { |
nethercote | 77eba60 | 2003-11-13 17:35:04 +0000 | [diff] [blame] | 361 | // Stop after "main"; if main() is recursive, stop after last main(). |
| 362 | |
| 363 | if ( ! VG_(clo_show_below_main)) { |
| 364 | if (VG_STREQ(buf, "main")) |
| 365 | main_done = True; |
| 366 | else if (main_done) |
| 367 | break; |
| 368 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 369 | VG_(printf)(" fun:%s\n", buf); |
| 370 | } else if ( VG_(get_objname)(eip, buf, M_VG_ERRTXT) ) { |
| 371 | VG_(printf)(" obj:%s\n", buf); |
| 372 | } else { |
| 373 | VG_(printf)(" ???:??? " |
nethercote | 125c91e | 2004-06-27 12:38:17 +0000 | [diff] [blame] | 374 | "# unknown, suppression will not work, sorry\n"); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 375 | } |
| 376 | i++; |
| 377 | } while (i < stop_at && ec->eips[i] != 0); |
| 378 | |
| 379 | VG_(printf)("}\n"); |
| 380 | } |
| 381 | |
njn | b4aee05 | 2003-04-15 14:09:58 +0000 | [diff] [blame] | 382 | static |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 383 | void do_actions_on_error(Error* err, Bool allow_db_attach) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 384 | { |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 385 | /* Perhaps we want a debugger attach at this point? */ |
| 386 | if (allow_db_attach && |
| 387 | VG_(is_action_requested)( "Attach to debugger", & VG_(clo_db_attach) )) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 388 | { |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 389 | VG_(printf)("starting debugger\n"); |
| 390 | VG_(start_debugger)( err->tid ); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 391 | } |
| 392 | /* Or maybe we want to generate the error's suppression? */ |
| 393 | if (VG_(is_action_requested)( "Print suppression", |
| 394 | & VG_(clo_gen_suppressions) )) { |
nethercote | 42602b1 | 2004-01-25 19:30:29 +0000 | [diff] [blame] | 395 | gen_suppression(err); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | |
| 399 | /* Shared between VG_(maybe_record_error)() and VG_(unique_error)(), |
| 400 | just for pretty printing purposes. */ |
| 401 | static Bool is_first_shown_context = True; |
| 402 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 403 | /* Top-level entry point to the error management subsystem. |
| 404 | All detected errors are notified here; this routine decides if/when the |
| 405 | user should see the error. */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 406 | void VG_(maybe_record_error) ( ThreadId tid, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 407 | ErrorKind ekind, Addr a, Char* s, void* extra ) |
| 408 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 409 | Error err; |
| 410 | Error* p; |
| 411 | Error* p_prev; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 412 | UInt extra_size; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 413 | VgRes exe_res = Vg_MedRes; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 414 | static Bool stopping_message = False; |
| 415 | static Bool slowdown_message = False; |
| 416 | static Int vg_n_errs_shown = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 417 | |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 418 | /* After M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN different errors have |
| 419 | been found, or M_VG_COLLECT_NO_ERRORS_AFTER_FOUND total errors |
| 420 | have been found, just refuse to collect any more. This stops |
| 421 | the burden of the error-management system becoming excessive in |
| 422 | extremely buggy programs, although it does make it pretty |
| 423 | pointless to continue the Valgrind run after this point. */ |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 424 | if (VG_(clo_error_limit) |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 425 | && (vg_n_errs_shown >= M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 426 | || VG_(n_errs_found) >= M_VG_COLLECT_NO_ERRORS_AFTER_FOUND)) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 427 | if (!stopping_message) { |
| 428 | VG_(message)(Vg_UserMsg, ""); |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 429 | |
| 430 | if (vg_n_errs_shown >= M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN) { |
| 431 | VG_(message)(Vg_UserMsg, |
| 432 | "More than %d different errors detected. " |
| 433 | "I'm not reporting any more.", |
| 434 | M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN ); |
| 435 | } else { |
| 436 | VG_(message)(Vg_UserMsg, |
| 437 | "More than %d total errors detected. " |
| 438 | "I'm not reporting any more.", |
| 439 | M_VG_COLLECT_NO_ERRORS_AFTER_FOUND ); |
| 440 | } |
| 441 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 442 | VG_(message)(Vg_UserMsg, |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 443 | "Final error counts will be inaccurate. Go fix your program!"); |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 444 | VG_(message)(Vg_UserMsg, |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 445 | "Rerun with --error-limit=no to disable this cutoff. Note"); |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 446 | VG_(message)(Vg_UserMsg, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 447 | "that errors may occur in your program without prior warning from"); |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 448 | VG_(message)(Vg_UserMsg, |
| 449 | "Valgrind, because errors are no longer being displayed."); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 450 | VG_(message)(Vg_UserMsg, ""); |
| 451 | stopping_message = True; |
| 452 | } |
| 453 | return; |
| 454 | } |
| 455 | |
| 456 | /* After M_VG_COLLECT_ERRORS_SLOWLY_AFTER different errors have |
| 457 | been found, be much more conservative about collecting new |
| 458 | ones. */ |
| 459 | if (vg_n_errs_shown >= M_VG_COLLECT_ERRORS_SLOWLY_AFTER) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 460 | exe_res = Vg_LowRes; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 461 | if (!slowdown_message) { |
| 462 | VG_(message)(Vg_UserMsg, ""); |
| 463 | VG_(message)(Vg_UserMsg, |
| 464 | "More than %d errors detected. Subsequent errors", |
| 465 | M_VG_COLLECT_ERRORS_SLOWLY_AFTER); |
| 466 | VG_(message)(Vg_UserMsg, |
| 467 | "will still be recorded, but in less detail than before."); |
| 468 | slowdown_message = True; |
| 469 | } |
| 470 | } |
| 471 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 472 | /* Build ourselves the error */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 473 | construct_error ( &err, tid, ekind, a, s, extra, NULL ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 474 | |
| 475 | /* First, see if we've got an error record matching this one. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 476 | p = vg_errors; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 477 | p_prev = NULL; |
| 478 | while (p != NULL) { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 479 | if (eq_Error(exe_res, p, &err)) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 480 | /* Found it. */ |
| 481 | p->count++; |
| 482 | if (p->supp != NULL) { |
| 483 | /* Deal correctly with suppressed errors. */ |
| 484 | p->supp->count++; |
| 485 | vg_n_errs_suppressed++; |
| 486 | } else { |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 487 | VG_(n_errs_found)++; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | /* Move p to the front of the list so that future searches |
| 491 | for it are faster. */ |
| 492 | if (p_prev != NULL) { |
| 493 | vg_assert(p_prev->next == p); |
| 494 | p_prev->next = p->next; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 495 | p->next = vg_errors; |
| 496 | vg_errors = p; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 497 | } |
sewardj | 7ebf7c3 | 2003-07-24 21:29:40 +0000 | [diff] [blame] | 498 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 499 | return; |
| 500 | } |
| 501 | p_prev = p; |
| 502 | p = p->next; |
| 503 | } |
| 504 | |
| 505 | /* Didn't see it. Copy and add. */ |
| 506 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 507 | /* OK, we're really going to collect it. The context is on the stack and |
| 508 | will disappear shortly, so we must copy it. First do the main |
| 509 | (non-`extra') part. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 510 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 511 | Then SK_(update_extra) can update the `extra' part. This is for when |
| 512 | there are more details to fill in which take time to work out but |
| 513 | don't affect our earlier decision to include the error -- by |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 514 | postponing those details until now, we avoid the extra work in the |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 515 | case where we ignore the error. Ugly. |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 516 | |
| 517 | Then, if there is an `extra' part, copy it too, using the size that |
njn | a70114c | 2003-08-19 16:14:42 +0000 | [diff] [blame] | 518 | SK_(update_extra) returned. Also allow for people using the void* |
| 519 | extra field for a scalar value like an integer. |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 520 | */ |
| 521 | |
| 522 | /* copy main part */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 523 | p = VG_(arena_malloc)(VG_AR_ERRORS, sizeof(Error)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 524 | *p = err; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 525 | |
njn | 6a23053 | 2003-07-21 10:38:23 +0000 | [diff] [blame] | 526 | /* update `extra', for non-core errors (core ones don't use 'extra') */ |
njn | a70114c | 2003-08-19 16:14:42 +0000 | [diff] [blame] | 527 | if (VG_(needs).skin_errors && PThreadErr != ekind) { |
njn | 6a23053 | 2003-07-21 10:38:23 +0000 | [diff] [blame] | 528 | extra_size = SK_(update_extra)(p); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 529 | |
njn | a70114c | 2003-08-19 16:14:42 +0000 | [diff] [blame] | 530 | /* copy block pointed to by `extra', if there is one */ |
| 531 | if (NULL != p->extra && 0 != extra_size) { |
njn | 6a23053 | 2003-07-21 10:38:23 +0000 | [diff] [blame] | 532 | void* new_extra = VG_(malloc)(extra_size); |
| 533 | VG_(memcpy)(new_extra, p->extra, extra_size); |
| 534 | p->extra = new_extra; |
| 535 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 536 | } |
| 537 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 538 | p->next = vg_errors; |
| 539 | p->supp = is_suppressible_error(&err); |
| 540 | vg_errors = p; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 541 | if (p->supp == NULL) { |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 542 | VG_(n_errs_found)++; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 543 | if (!is_first_shown_context) |
| 544 | VG_(message)(Vg_UserMsg, ""); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 545 | pp_Error(p, False); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 546 | is_first_shown_context = False; |
| 547 | vg_n_errs_shown++; |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 548 | do_actions_on_error(p, /*allow_db_attach*/True); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 549 | } else { |
| 550 | vg_n_errs_suppressed++; |
| 551 | p->supp->count++; |
| 552 | } |
| 553 | } |
| 554 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 555 | /* Second top-level entry point to the error management subsystem, for |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 556 | errors that the tool wants to report immediately, eg. because they're |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 557 | guaranteed to only happen once. This avoids all the recording and |
| 558 | comparing stuff. But they can be suppressed; returns True if it is |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 559 | suppressed. Bool `print_error' dictates whether to print the error. |
| 560 | Bool `count_error' dictates whether to count the error in VG_(n_errs_found) |
| 561 | */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 562 | Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind, Addr a, Char* s, |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 563 | void* extra, ExeContext* where, Bool print_error, |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 564 | Bool allow_db_attach, Bool count_error ) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 565 | { |
| 566 | Error err; |
| 567 | |
| 568 | /* Build ourselves the error */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 569 | construct_error ( &err, tid, ekind, a, s, extra, where ); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 570 | |
| 571 | /* Unless it's suppressed, we're going to show it. Don't need to make |
| 572 | a copy, because it's only temporary anyway. |
| 573 | |
| 574 | Then update the `extra' part with SK_(update_extra), because that can |
| 575 | have an affect on whether it's suppressed. Ignore the size return |
| 576 | value of SK_(update_extra), because we're not copying `extra'. */ |
| 577 | (void)SK_(update_extra)(&err); |
| 578 | |
| 579 | if (NULL == is_suppressible_error(&err)) { |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 580 | if (count_error) |
| 581 | VG_(n_errs_found)++; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 582 | |
| 583 | if (print_error) { |
| 584 | if (!is_first_shown_context) |
| 585 | VG_(message)(Vg_UserMsg, ""); |
| 586 | pp_Error(&err, False); |
| 587 | is_first_shown_context = False; |
| 588 | } |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 589 | do_actions_on_error(&err, allow_db_attach); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 590 | |
| 591 | return False; |
| 592 | |
| 593 | } else { |
| 594 | vg_n_errs_suppressed++; |
| 595 | return True; |
| 596 | } |
| 597 | } |
| 598 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 599 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 600 | /*------------------------------------------------------------*/ |
| 601 | /*--- Exported fns ---*/ |
| 602 | /*------------------------------------------------------------*/ |
| 603 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 604 | /* These are called not from generated code but from the scheduler */ |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 605 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 606 | void VG_(record_pthread_error) ( ThreadId tid, Char* msg ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 607 | { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 608 | if (! VG_(needs).core_errors) return; |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 609 | VG_(maybe_record_error)( tid, PThreadErr, /*addr*/0, msg, /*extra*/NULL ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 610 | } |
| 611 | |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 612 | /*------------------------------*/ |
| 613 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 614 | void VG_(show_all_errors) ( void ) |
| 615 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 616 | Int i, n_min; |
| 617 | Int n_err_contexts, n_supp_contexts; |
| 618 | Error *p, *p_min; |
| 619 | Supp *su; |
| 620 | Bool any_supp; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 621 | |
| 622 | if (VG_(clo_verbosity) == 0) |
| 623 | return; |
| 624 | |
| 625 | n_err_contexts = 0; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 626 | for (p = vg_errors; p != NULL; p = p->next) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 627 | if (p->supp == NULL) |
| 628 | n_err_contexts++; |
| 629 | } |
| 630 | |
| 631 | n_supp_contexts = 0; |
| 632 | for (su = vg_suppressions; su != NULL; su = su->next) { |
| 633 | if (su->count > 0) |
| 634 | n_supp_contexts++; |
| 635 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 636 | VG_(message)(Vg_UserMsg, |
| 637 | "ERROR SUMMARY: " |
| 638 | "%d errors from %d contexts (suppressed: %d from %d)", |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 639 | VG_(n_errs_found), n_err_contexts, |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 640 | vg_n_errs_suppressed, n_supp_contexts ); |
| 641 | |
| 642 | if (VG_(clo_verbosity) <= 1) |
| 643 | return; |
| 644 | |
| 645 | /* Print the contexts in order of increasing error count. */ |
| 646 | for (i = 0; i < n_err_contexts; i++) { |
| 647 | n_min = (1 << 30) - 1; |
| 648 | p_min = NULL; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 649 | for (p = vg_errors; p != NULL; p = p->next) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 650 | if (p->supp != NULL) continue; |
| 651 | if (p->count < n_min) { |
| 652 | n_min = p->count; |
| 653 | p_min = p; |
| 654 | } |
| 655 | } |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 656 | if (p_min == NULL) VG_(skin_panic)("show_all_errors()"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 657 | |
| 658 | VG_(message)(Vg_UserMsg, ""); |
| 659 | VG_(message)(Vg_UserMsg, "%d errors in context %d of %d:", |
| 660 | p_min->count, |
| 661 | i+1, n_err_contexts); |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 662 | pp_Error( p_min, False ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 663 | |
| 664 | if ((i+1 == VG_(clo_dump_error))) { |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 665 | VG_(translate) ( 0 /* dummy ThreadId; irrelevant due to below NULLs */, |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 666 | p_min->where->eips[0], NULL, NULL, NULL, NULL ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | p_min->count = 1 << 30; |
| 670 | } |
| 671 | |
| 672 | if (n_supp_contexts > 0) |
| 673 | VG_(message)(Vg_DebugMsg, ""); |
| 674 | any_supp = False; |
| 675 | for (su = vg_suppressions; su != NULL; su = su->next) { |
| 676 | if (su->count > 0) { |
| 677 | any_supp = True; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 678 | VG_(message)(Vg_DebugMsg, "supp: %4d %s", su->count, su->sname); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 679 | } |
| 680 | } |
| 681 | |
| 682 | if (n_err_contexts > 0) { |
| 683 | if (any_supp) |
| 684 | VG_(message)(Vg_UserMsg, ""); |
| 685 | VG_(message)(Vg_UserMsg, |
| 686 | "IN SUMMARY: " |
| 687 | "%d errors from %d contexts (suppressed: %d from %d)", |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 688 | VG_(n_errs_found), n_err_contexts, |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 689 | vg_n_errs_suppressed, |
| 690 | n_supp_contexts ); |
| 691 | VG_(message)(Vg_UserMsg, ""); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | /*------------------------------------------------------------*/ |
| 696 | /*--- Standard suppressions ---*/ |
| 697 | /*------------------------------------------------------------*/ |
| 698 | |
| 699 | /* Get a non-blank, non-comment line of at most nBuf chars from fd. |
| 700 | Skips leading spaces on the line. Return True if EOF was hit instead. |
| 701 | */ |
| 702 | |
| 703 | #define VG_ISSPACE(ch) (((ch)==' ') || ((ch)=='\n') || ((ch)=='\t')) |
| 704 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 705 | Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 706 | { |
| 707 | Char ch; |
| 708 | Int n, i; |
| 709 | while (True) { |
| 710 | /* First, read until a non-blank char appears. */ |
| 711 | while (True) { |
| 712 | n = VG_(read)(fd, &ch, 1); |
| 713 | if (n == 1 && !VG_ISSPACE(ch)) break; |
| 714 | if (n == 0) return True; |
| 715 | } |
| 716 | |
| 717 | /* Now, read the line into buf. */ |
| 718 | i = 0; |
| 719 | buf[i++] = ch; buf[i] = 0; |
| 720 | while (True) { |
| 721 | n = VG_(read)(fd, &ch, 1); |
| 722 | if (n == 0) return False; /* the next call will return True */ |
| 723 | if (ch == '\n') break; |
| 724 | if (i > 0 && i == nBuf-1) i--; |
| 725 | buf[i++] = ch; buf[i] = 0; |
| 726 | } |
| 727 | while (i > 1 && VG_ISSPACE(buf[i-1])) { |
| 728 | i--; buf[i] = 0; |
| 729 | }; |
| 730 | |
| 731 | /* VG_(printf)("The line is `%s'\n", buf); */ |
| 732 | /* Ok, we have a line. If a non-comment line, return. |
| 733 | If a comment line, start all over again. */ |
| 734 | if (buf[0] != '#') return False; |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | |
| 739 | /* *p_caller contains the raw name of a caller, supposedly either |
| 740 | fun:some_function_name or |
| 741 | obj:some_object_name. |
| 742 | Set *p_ty accordingly and advance *p_caller over the descriptor |
| 743 | (fun: or obj:) part. |
| 744 | Returns False if failed. |
| 745 | */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 746 | static Bool setLocationTy ( Char** p_caller, SuppLocTy* p_ty ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 747 | { |
| 748 | if (VG_(strncmp)(*p_caller, "fun:", 4) == 0) { |
| 749 | (*p_caller) += 4; |
| 750 | *p_ty = FunName; |
| 751 | return True; |
| 752 | } |
| 753 | if (VG_(strncmp)(*p_caller, "obj:", 4) == 0) { |
| 754 | (*p_caller) += 4; |
| 755 | *p_ty = ObjName; |
| 756 | return True; |
| 757 | } |
| 758 | VG_(printf)("location should start with fun: or obj:\n"); |
| 759 | return False; |
| 760 | } |
| 761 | |
| 762 | |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 763 | /* Look for "tool" in a string like "tool1,tool2,tool3" */ |
njn | 11cc925 | 2002-10-07 14:42:59 +0000 | [diff] [blame] | 764 | static __inline__ |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 765 | Bool tool_name_present(Char *name, Char *names) |
njn | 11cc925 | 2002-10-07 14:42:59 +0000 | [diff] [blame] | 766 | { |
| 767 | Bool found; |
| 768 | Char *s = NULL; /* Shut gcc up */ |
| 769 | Int len = VG_(strlen)(name); |
| 770 | |
| 771 | found = (NULL != (s = VG_(strstr)(names, name)) && |
| 772 | (s == names || *(s-1) == ',') && |
| 773 | (*(s+len) == ',' || *(s+len) == '\0') |
| 774 | ); |
| 775 | |
| 776 | return found; |
| 777 | } |
| 778 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 779 | /* Read suppressions from the file specified in vg_clo_suppressions |
| 780 | and place them in the suppressions list. If there's any difficulty |
| 781 | doing this, just give up -- there's no point in trying to recover. |
| 782 | */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 783 | static void load_one_suppressions_file ( Char* filename ) |
| 784 | { |
| 785 | # define N_BUF 200 |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 786 | Int fd, i; |
| 787 | Bool eof; |
| 788 | Char buf[N_BUF+1]; |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 789 | Char* tool_names; |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 790 | Char* supp_name; |
| 791 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 792 | fd = VG_(open)( filename, VKI_O_RDONLY, 0 ); |
jsgf | f3c3f1a | 2003-10-14 22:13:28 +0000 | [diff] [blame] | 793 | if (fd < 0) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 794 | VG_(message)(Vg_UserMsg, "FATAL: can't open suppressions file `%s'", |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 795 | filename ); |
| 796 | VG_(exit)(1); |
| 797 | } |
| 798 | |
| 799 | while (True) { |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 800 | /* Assign and initialise the two suppression halves (core and tool) */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 801 | Supp* supp; |
| 802 | supp = VG_(arena_malloc)(VG_AR_CORE, sizeof(Supp)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 803 | supp->count = 0; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 804 | for (i = 0; i < VG_N_SUPP_CALLERS; i++) supp->caller[i] = NULL; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 805 | supp->string = supp->extra = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 806 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 807 | eof = VG_(get_line) ( fd, buf, N_BUF ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 808 | if (eof) break; |
| 809 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 810 | if (!VG_STREQ(buf, "{")) goto syntax_error; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 811 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 812 | eof = VG_(get_line) ( fd, buf, N_BUF ); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 813 | if (eof || VG_STREQ(buf, "}")) goto syntax_error; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 814 | supp->sname = VG_(arena_strdup)(VG_AR_CORE, buf); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 815 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 816 | eof = VG_(get_line) ( fd, buf, N_BUF ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 817 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 818 | if (eof) goto syntax_error; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 819 | |
njn | 11cc925 | 2002-10-07 14:42:59 +0000 | [diff] [blame] | 820 | /* Check it has the "skin1,skin2,...:supp" form (look for ':') */ |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 821 | i = 0; |
| 822 | while (True) { |
| 823 | if (buf[i] == ':') break; |
| 824 | if (buf[i] == '\0') goto syntax_error; |
| 825 | i++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 826 | } |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 827 | buf[i] = '\0'; /* Replace ':', splitting into two strings */ |
| 828 | |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 829 | tool_names = & buf[0]; |
njn | 11cc925 | 2002-10-07 14:42:59 +0000 | [diff] [blame] | 830 | supp_name = & buf[i+1]; |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 831 | |
njn | 11cc925 | 2002-10-07 14:42:59 +0000 | [diff] [blame] | 832 | /* Is it a core suppression? */ |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 833 | if (VG_(needs).core_errors && tool_name_present("core", tool_names)) |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 834 | { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 835 | if (VG_STREQ(supp_name, "PThread")) |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 836 | supp->skind = PThreadSupp; |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 837 | else |
| 838 | goto syntax_error; |
| 839 | } |
| 840 | |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 841 | /* Is it a tool suppression? */ |
njn | 11cc925 | 2002-10-07 14:42:59 +0000 | [diff] [blame] | 842 | else if (VG_(needs).skin_errors && |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 843 | tool_name_present(VG_(details).name, tool_names)) |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 844 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 845 | if (SK_(recognised_suppression)(supp_name, supp)) |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 846 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 847 | /* Do nothing, function fills in supp->skind */ |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 848 | } else |
| 849 | goto syntax_error; |
| 850 | } |
| 851 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 852 | else { |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 853 | /* Ignore rest of suppression */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 854 | while (True) { |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 855 | eof = VG_(get_line) ( fd, buf, N_BUF ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 856 | if (eof) goto syntax_error; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 857 | if (VG_STREQ(buf, "}")) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 858 | break; |
| 859 | } |
| 860 | continue; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 861 | } |
| 862 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 863 | if (VG_(needs).skin_errors && |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 864 | !SK_(read_extra_suppression_info)(fd, buf, N_BUF, supp)) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 865 | goto syntax_error; |
| 866 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 867 | /* "i > 0" ensures at least one caller read. */ |
njn | 633de32 | 2003-05-12 20:40:13 +0000 | [diff] [blame] | 868 | for (i = 0; i <= VG_N_SUPP_CALLERS; i++) { |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 869 | eof = VG_(get_line) ( fd, buf, N_BUF ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 870 | if (eof) goto syntax_error; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 871 | if (i > 0 && VG_STREQ(buf, "}")) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 872 | break; |
njn | 633de32 | 2003-05-12 20:40:13 +0000 | [diff] [blame] | 873 | if (i == VG_N_SUPP_CALLERS) |
| 874 | break; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 875 | supp->caller[i] = VG_(arena_strdup)(VG_AR_CORE, buf); |
| 876 | if (!setLocationTy(&(supp->caller[i]), &(supp->caller_ty[i]))) |
| 877 | goto syntax_error; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 878 | } |
| 879 | |
sewardj | 57a8f5f | 2003-07-06 01:40:11 +0000 | [diff] [blame] | 880 | /* make sure to grab the '}' if the num callers is >= |
| 881 | VG_N_SUPP_CALLERS */ |
| 882 | if (!VG_STREQ(buf, "}")) { |
| 883 | do { |
| 884 | eof = VG_(get_line) ( fd, buf, N_BUF ); |
| 885 | } while (!eof && !VG_STREQ(buf, "}")); |
| 886 | } |
| 887 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 888 | supp->next = vg_suppressions; |
| 889 | vg_suppressions = supp; |
| 890 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 891 | VG_(close)(fd); |
| 892 | return; |
| 893 | |
| 894 | syntax_error: |
| 895 | if (eof) { |
| 896 | VG_(message)(Vg_UserMsg, |
| 897 | "FATAL: in suppressions file `%s': unexpected EOF", |
| 898 | filename ); |
| 899 | } else { |
| 900 | VG_(message)(Vg_UserMsg, |
njn | 11cc925 | 2002-10-07 14:42:59 +0000 | [diff] [blame] | 901 | "FATAL: in suppressions file: `%s': syntax error on: %s", |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 902 | filename, buf ); |
| 903 | } |
| 904 | VG_(close)(fd); |
| 905 | VG_(message)(Vg_UserMsg, "exiting now."); |
| 906 | VG_(exit)(1); |
| 907 | |
| 908 | # undef N_BUF |
| 909 | } |
| 910 | |
| 911 | |
| 912 | void VG_(load_suppressions) ( void ) |
| 913 | { |
| 914 | Int i; |
| 915 | vg_suppressions = NULL; |
| 916 | for (i = 0; i < VG_(clo_n_suppressions); i++) { |
| 917 | if (VG_(clo_verbosity) > 1) { |
| 918 | VG_(message)(Vg_UserMsg, "Reading suppressions file: %s", |
| 919 | VG_(clo_suppressions)[i] ); |
| 920 | } |
| 921 | load_one_suppressions_file( VG_(clo_suppressions)[i] ); |
| 922 | } |
| 923 | } |
| 924 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 925 | /* Return the name of an erring fn in a way which is useful |
| 926 | for comparing against the contents of a suppressions file. |
| 927 | Doesn't demangle the fn name, because we want to refer to |
| 928 | mangled names in the suppressions file. |
sewardj | 99aac97 | 2002-12-26 01:53:45 +0000 | [diff] [blame] | 929 | */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 930 | static void get_objname_fnname ( Addr a, Char* obj_buf, Int n_obj_buf, |
| 931 | Char* fun_buf, Int n_fun_buf ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 932 | { |
| 933 | (void)VG_(get_objname) ( a, obj_buf, n_obj_buf ); |
| 934 | (void)VG_(get_fnname_nodemangle)( a, fun_buf, n_fun_buf ); |
| 935 | } |
| 936 | |
| 937 | static __inline__ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 938 | Bool supp_matches_error(Supp* su, Error* err) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 939 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 940 | switch (su->skind) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 941 | case PThreadSupp: |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 942 | return (err->ekind == PThreadErr); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 943 | default: |
| 944 | if (VG_(needs).skin_errors) { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 945 | return SK_(error_matches_suppression)(err, su); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 946 | } else { |
| 947 | VG_(printf)( |
| 948 | "\nUnhandled suppression type: %u. VG_(needs).skin_errors\n" |
| 949 | "probably needs to be set.\n", |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 950 | err->ekind); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 951 | VG_(skin_panic)("unhandled suppression type"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 952 | } |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | static __inline__ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 957 | Bool supp_matches_callers(Supp* su, Char caller_obj[][M_VG_ERRTXT], |
| 958 | Char caller_fun[][M_VG_ERRTXT]) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 959 | { |
| 960 | Int i; |
| 961 | |
njn | 633de32 | 2003-05-12 20:40:13 +0000 | [diff] [blame] | 962 | for (i = 0; i < VG_N_SUPP_CALLERS && su->caller[i] != NULL; i++) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 963 | switch (su->caller_ty[i]) { |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 964 | case ObjName: if (VG_(string_match)(su->caller[i], |
| 965 | caller_obj[i])) break; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 966 | return False; |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 967 | case FunName: if (VG_(string_match)(su->caller[i], |
| 968 | caller_fun[i])) break; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 969 | return False; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 970 | default: VG_(skin_panic)("supp_matches_callers"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 971 | } |
| 972 | } |
| 973 | |
| 974 | /* If we reach here, it's a match */ |
| 975 | return True; |
| 976 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 977 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 978 | /* Does an error context match a suppression? ie is this a suppressible |
| 979 | error? If so, return a pointer to the Supp record, otherwise NULL. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 980 | Tries to minimise the number of symbol searches since they are expensive. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 981 | */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 982 | static Supp* is_suppressible_error ( Error* err ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 983 | { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 984 | Int i; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 985 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 986 | Char caller_obj[VG_N_SUPP_CALLERS][M_VG_ERRTXT]; |
| 987 | Char caller_fun[VG_N_SUPP_CALLERS][M_VG_ERRTXT]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 988 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 989 | Supp* su; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 990 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 991 | /* get_objname_fnname() writes the function name and object name if |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 992 | it finds them in the debug info. So the strings in the suppression |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 993 | file should match these. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 994 | */ |
| 995 | |
| 996 | /* Initialise these strs so they are always safe to compare, even |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 997 | if get_objname_fnname doesn't write anything to them. */ |
| 998 | for (i = 0; i < VG_N_SUPP_CALLERS; i++) |
| 999 | caller_obj[i][0] = caller_fun[i][0] = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1000 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1001 | for (i = 0; i < VG_N_SUPP_CALLERS && i < VG_(clo_backtrace_size); i++) { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 1002 | get_objname_fnname ( err->where->eips[i], caller_obj[i], M_VG_ERRTXT, |
| 1003 | caller_fun[i], M_VG_ERRTXT ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | /* See if the error context matches any suppression. */ |
| 1007 | for (su = vg_suppressions; su != NULL; su = su->next) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1008 | if (supp_matches_error(su, err) && |
| 1009 | supp_matches_callers(su, caller_obj, caller_fun)) { |
| 1010 | return su; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1011 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1012 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1013 | return NULL; /* no matches */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1016 | /*--------------------------------------------------------------------*/ |
| 1017 | /*--- end vg_errcontext.c ---*/ |
| 1018 | /*--------------------------------------------------------------------*/ |