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 | |
| 10 | Copyright (C) 2000-2002 Julian Seward |
| 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. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 39 | static CoreError* 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. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 43 | static CoreSupp* vg_suppressions = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 44 | |
| 45 | /* Running count of unsuppressed errors detected. */ |
| 46 | static UInt vg_n_errs_found = 0; |
| 47 | |
| 48 | /* Running count of suppressed errors detected. */ |
| 49 | static UInt vg_n_errs_suppressed = 0; |
| 50 | |
| 51 | /* forwards ... */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 52 | static CoreSupp* is_suppressible_error ( CoreError* err ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 53 | |
| 54 | |
| 55 | /*------------------------------------------------------------*/ |
| 56 | /*--- Helper fns ---*/ |
| 57 | /*------------------------------------------------------------*/ |
| 58 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 59 | /* Compare error contexts, to detect duplicates. Note that if they |
| 60 | are otherwise the same, the faulting addrs and associated rwoffsets |
| 61 | are allowed to be different. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 62 | static Bool eq_CoreError ( VgRes res, CoreError* e1, CoreError* e2 ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 63 | { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 64 | if (e1->skin_err.ekind != e2->skin_err.ekind) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 65 | return False; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 66 | if (!VG_(eq_ExeContext)(res, e1->where, e2->where)) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 67 | return False; |
| 68 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 69 | switch (e1->skin_err.ekind) { |
sewardj | 4dced35 | 2002-06-04 22:54:20 +0000 | [diff] [blame] | 70 | case PThreadErr: |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 71 | vg_assert(VG_(needs).core_errors); |
| 72 | if (e1->skin_err.string == e2->skin_err.string) |
sewardj | 4dced35 | 2002-06-04 22:54:20 +0000 | [diff] [blame] | 73 | return True; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 74 | if (0 == VG_(strcmp)(e1->skin_err.string, e2->skin_err.string)) |
sewardj | 4dced35 | 2002-06-04 22:54:20 +0000 | [diff] [blame] | 75 | return True; |
| 76 | return False; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 77 | default: |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 78 | if (VG_(needs).skin_errors) |
| 79 | return SK_(eq_SkinError)(res, &e1->skin_err, &e2->skin_err); |
| 80 | else { |
| 81 | VG_(printf)("\nUnhandled error type: %u. VG_(needs).skin_errors\n" |
| 82 | "probably needs to be set.\n", |
| 83 | e1->skin_err.ekind); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 84 | VG_(skin_panic)("unhandled error type"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 85 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 89 | static void pp_CoreError ( CoreError* err, Bool printCount ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 90 | { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 91 | /* Closure for printing where the error occurred. Abstracts details |
| 92 | about the `where' field away from the skin. */ |
| 93 | void pp_ExeContextClosure(void) |
| 94 | { |
| 95 | VG_(pp_ExeContext) ( err->where ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 96 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 97 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 98 | if (printCount) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 99 | VG_(message)(Vg_UserMsg, "Observed %d times:", err->count ); |
| 100 | if (err->tid > 1) |
| 101 | VG_(message)(Vg_UserMsg, "Thread %d:", err->tid ); |
| 102 | |
| 103 | switch (err->skin_err.ekind) { |
sewardj | 4dced35 | 2002-06-04 22:54:20 +0000 | [diff] [blame] | 104 | case PThreadErr: |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 105 | vg_assert(VG_(needs).core_errors); |
| 106 | VG_(message)(Vg_UserMsg, "%s", err->skin_err.string ); |
| 107 | VG_(pp_ExeContext)(err->where); |
sewardj | 4dced35 | 2002-06-04 22:54:20 +0000 | [diff] [blame] | 108 | break; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 109 | default: |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 110 | if (VG_(needs).skin_errors) |
| 111 | SK_(pp_SkinError)( &err->skin_err, &pp_ExeContextClosure ); |
| 112 | else { |
| 113 | VG_(printf)("\nUnhandled error type: %u. VG_(needs).skin_errors\n" |
| 114 | "probably needs to be set?\n", |
| 115 | err->skin_err.ekind); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 116 | VG_(skin_panic)("unhandled error type"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 117 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 121 | /* Figure out if we want to attach for GDB for this error, possibly |
| 122 | by asking the user. */ |
| 123 | static |
| 124 | Bool vg_is_GDB_attach_requested ( void ) |
| 125 | { |
| 126 | Char ch, ch2; |
| 127 | Int res; |
| 128 | |
| 129 | if (VG_(clo_GDB_attach) == False) |
| 130 | return False; |
| 131 | |
| 132 | VG_(message)(Vg_UserMsg, ""); |
| 133 | |
| 134 | again: |
| 135 | VG_(printf)( |
| 136 | "==%d== " |
| 137 | "---- Attach to GDB ? --- [Return/N/n/Y/y/C/c] ---- ", |
| 138 | VG_(getpid)() |
| 139 | ); |
| 140 | |
| 141 | res = VG_(read)(0 /*stdin*/, &ch, 1); |
| 142 | if (res != 1) goto ioerror; |
| 143 | /* res == 1 */ |
| 144 | if (ch == '\n') return False; |
| 145 | if (ch != 'N' && ch != 'n' && ch != 'Y' && ch != 'y' |
| 146 | && ch != 'C' && ch != 'c') goto again; |
| 147 | |
| 148 | res = VG_(read)(0 /*stdin*/, &ch2, 1); |
| 149 | if (res != 1) goto ioerror; |
| 150 | if (ch2 != '\n') goto again; |
| 151 | |
| 152 | /* No, don't want to attach. */ |
| 153 | if (ch == 'n' || ch == 'N') return False; |
| 154 | /* Yes, want to attach. */ |
| 155 | if (ch == 'y' || ch == 'Y') return True; |
| 156 | /* No, don't want to attach, and don't ask again either. */ |
| 157 | vg_assert(ch == 'c' || ch == 'C'); |
| 158 | |
| 159 | ioerror: |
| 160 | VG_(clo_GDB_attach) = False; |
| 161 | return False; |
| 162 | } |
| 163 | |
| 164 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 165 | /* I've gone all object-oriented... initialisation depends on where the |
| 166 | error comes from: |
| 167 | |
| 168 | - If from generated code (tst == NULL), the %EIP/%EBP values that we |
| 169 | need in order to create proper error messages are picked up out of |
| 170 | VG_(baseBlock) rather than from the thread table (vg_threads in |
| 171 | vg_scheduler.c). |
| 172 | |
| 173 | - If not from generated code but in response to requests passed back to |
| 174 | the scheduler (tst != NULL), we pick up %EIP/%EBP values from the |
| 175 | stored thread state, not from VG_(baseBlock). |
| 176 | */ |
| 177 | static __inline__ |
| 178 | void construct_error ( CoreError* err, ThreadState* tst, |
| 179 | ErrorKind ekind, Addr a, Char* s, void* extra ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 180 | { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 181 | /* CoreError parts */ |
| 182 | err->next = NULL; |
| 183 | err->supp = NULL; |
| 184 | err->count = 1; |
| 185 | if (NULL == tst) { |
| 186 | err->tid = VG_(get_current_tid)(); |
| 187 | err->where = |
| 188 | VG_(get_ExeContext2)( VG_(baseBlock)[VGOFF_(m_eip)], |
| 189 | VG_(baseBlock)[VGOFF_(m_ebp)], |
| 190 | VG_(baseBlock)[VGOFF_(m_esp)], |
| 191 | VG_(threads)[err->tid].stack_highest_word); |
| 192 | err->m_eip = VG_(baseBlock)[VGOFF_(m_eip)]; |
| 193 | err->m_esp = VG_(baseBlock)[VGOFF_(m_esp)]; |
| 194 | err->m_ebp = VG_(baseBlock)[VGOFF_(m_ebp)]; |
| 195 | } else { |
| 196 | err->where = VG_(get_ExeContext) ( tst ); |
| 197 | err->tid = tst->tid; |
| 198 | err->m_eip = tst->m_eip; |
| 199 | err->m_esp = tst->m_esp; |
| 200 | err->m_ebp = tst->m_ebp; |
| 201 | } |
| 202 | |
| 203 | /* SkinError parts */ |
| 204 | err->skin_err.ekind = ekind; |
| 205 | err->skin_err.addr = a; |
| 206 | err->skin_err.string = s; |
| 207 | err->skin_err.extra = extra; |
| 208 | |
| 209 | /* sanity... */ |
| 210 | vg_assert(err->tid >= 0 && err->tid < VG_N_THREADS); |
| 211 | } |
| 212 | |
| 213 | /* Top-level entry point to the error management subsystem. |
| 214 | All detected errors are notified here; this routine decides if/when the |
| 215 | user should see the error. */ |
| 216 | void VG_(maybe_record_error) ( ThreadState* tst, |
| 217 | ErrorKind ekind, Addr a, Char* s, void* extra ) |
| 218 | { |
| 219 | CoreError err; |
| 220 | CoreError* p; |
| 221 | CoreError* p_prev; |
| 222 | VgRes exe_res = Vg_MedRes; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 223 | static Bool is_first_shown_context = True; |
| 224 | static Bool stopping_message = False; |
| 225 | static Bool slowdown_message = False; |
| 226 | static Int vg_n_errs_shown = 0; |
| 227 | |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 228 | /* After M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN different errors have |
| 229 | been found, or M_VG_COLLECT_NO_ERRORS_AFTER_FOUND total errors |
| 230 | have been found, just refuse to collect any more. This stops |
| 231 | the burden of the error-management system becoming excessive in |
| 232 | extremely buggy programs, although it does make it pretty |
| 233 | pointless to continue the Valgrind run after this point. */ |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 234 | if (VG_(clo_error_limit) |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 235 | && (vg_n_errs_shown >= M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN |
| 236 | || vg_n_errs_found >= M_VG_COLLECT_NO_ERRORS_AFTER_FOUND)) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 237 | if (!stopping_message) { |
| 238 | VG_(message)(Vg_UserMsg, ""); |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 239 | |
| 240 | if (vg_n_errs_shown >= M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN) { |
| 241 | VG_(message)(Vg_UserMsg, |
| 242 | "More than %d different errors detected. " |
| 243 | "I'm not reporting any more.", |
| 244 | M_VG_COLLECT_NO_ERRORS_AFTER_SHOWN ); |
| 245 | } else { |
| 246 | VG_(message)(Vg_UserMsg, |
| 247 | "More than %d total errors detected. " |
| 248 | "I'm not reporting any more.", |
| 249 | M_VG_COLLECT_NO_ERRORS_AFTER_FOUND ); |
| 250 | } |
| 251 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 252 | VG_(message)(Vg_UserMsg, |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 253 | "Final error counts will be inaccurate. Go fix your program!"); |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 254 | VG_(message)(Vg_UserMsg, |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 255 | "Rerun with --error-limit=no to disable this cutoff. Note"); |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 256 | VG_(message)(Vg_UserMsg, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 257 | "that errors may occur in your program without prior warning from"); |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 258 | VG_(message)(Vg_UserMsg, |
| 259 | "Valgrind, because errors are no longer being displayed."); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 260 | VG_(message)(Vg_UserMsg, ""); |
| 261 | stopping_message = True; |
| 262 | } |
| 263 | return; |
| 264 | } |
| 265 | |
| 266 | /* After M_VG_COLLECT_ERRORS_SLOWLY_AFTER different errors have |
| 267 | been found, be much more conservative about collecting new |
| 268 | ones. */ |
| 269 | if (vg_n_errs_shown >= M_VG_COLLECT_ERRORS_SLOWLY_AFTER) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 270 | exe_res = Vg_LowRes; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 271 | if (!slowdown_message) { |
| 272 | VG_(message)(Vg_UserMsg, ""); |
| 273 | VG_(message)(Vg_UserMsg, |
| 274 | "More than %d errors detected. Subsequent errors", |
| 275 | M_VG_COLLECT_ERRORS_SLOWLY_AFTER); |
| 276 | VG_(message)(Vg_UserMsg, |
| 277 | "will still be recorded, but in less detail than before."); |
| 278 | slowdown_message = True; |
| 279 | } |
| 280 | } |
| 281 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 282 | /* Build ourselves the error */ |
| 283 | construct_error ( &err, tst, ekind, a, s, extra ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 284 | |
| 285 | /* First, see if we've got an error record matching this one. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 286 | p = vg_errors; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 287 | p_prev = NULL; |
| 288 | while (p != NULL) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 289 | if (eq_CoreError(exe_res, p, &err)) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 290 | /* Found it. */ |
| 291 | p->count++; |
| 292 | if (p->supp != NULL) { |
| 293 | /* Deal correctly with suppressed errors. */ |
| 294 | p->supp->count++; |
| 295 | vg_n_errs_suppressed++; |
| 296 | } else { |
| 297 | vg_n_errs_found++; |
| 298 | } |
| 299 | |
| 300 | /* Move p to the front of the list so that future searches |
| 301 | for it are faster. */ |
| 302 | if (p_prev != NULL) { |
| 303 | vg_assert(p_prev->next == p); |
| 304 | p_prev->next = p->next; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 305 | p->next = vg_errors; |
| 306 | vg_errors = p; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 307 | } |
| 308 | return; |
| 309 | } |
| 310 | p_prev = p; |
| 311 | p = p->next; |
| 312 | } |
| 313 | |
| 314 | /* Didn't see it. Copy and add. */ |
| 315 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 316 | /* OK, we're really going to collect it. First make a copy, |
| 317 | because the error context is on the stack and will disappear shortly. |
| 318 | We can duplicate the main part ourselves, but use |
| 319 | SK_(dup_extra_and_update) to duplicate the 'extra' part (unless it's |
| 320 | NULL). |
| 321 | |
| 322 | SK_(dup_extra_and_update) can also update the SkinError. This is |
| 323 | for when there are more details to fill in which take time to work out |
| 324 | but don't affect our earlier decision to include the error -- by |
| 325 | postponing those details until now, we avoid the extra work in the |
| 326 | case where we ignore the error. |
| 327 | */ |
| 328 | p = VG_(arena_malloc)(VG_AR_ERRORS, sizeof(CoreError)); |
| 329 | *p = err; |
| 330 | if (NULL != err.skin_err.extra) |
| 331 | SK_(dup_extra_and_update)(&p->skin_err); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 332 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 333 | p->next = vg_errors; |
| 334 | p->supp = is_suppressible_error(&err); |
| 335 | vg_errors = p; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 336 | if (p->supp == NULL) { |
| 337 | vg_n_errs_found++; |
| 338 | if (!is_first_shown_context) |
| 339 | VG_(message)(Vg_UserMsg, ""); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 340 | pp_CoreError(p, False); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 341 | is_first_shown_context = False; |
| 342 | vg_n_errs_shown++; |
| 343 | /* Perhaps we want a GDB attach at this point? */ |
| 344 | if (vg_is_GDB_attach_requested()) { |
sewardj | 3580542 | 2002-04-21 13:05:34 +0000 | [diff] [blame] | 345 | VG_(swizzle_esp_then_start_GDB)( |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 346 | err.m_eip, err.m_esp, err.m_ebp); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 347 | } |
| 348 | } else { |
| 349 | vg_n_errs_suppressed++; |
| 350 | p->supp->count++; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 355 | /*------------------------------------------------------------*/ |
| 356 | /*--- Exported fns ---*/ |
| 357 | /*------------------------------------------------------------*/ |
| 358 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 359 | /* These are called not from generated code but from the scheduler */ |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 360 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 361 | void VG_(record_pthread_error) ( ThreadId tid, Char* msg ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 362 | { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 363 | if (! VG_(needs).core_errors) return; |
| 364 | VG_(maybe_record_error)( &VG_(threads)[tid], PThreadErr, /*addr*/0, msg, |
| 365 | /*extra*/NULL ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 366 | } |
| 367 | |
sewardj | 8c82451 | 2002-04-14 04:16:48 +0000 | [diff] [blame] | 368 | /*------------------------------*/ |
| 369 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 370 | void VG_(show_all_errors) ( void ) |
| 371 | { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 372 | Int i, n_min; |
| 373 | Int n_err_contexts, n_supp_contexts; |
| 374 | CoreError *p, *p_min; |
| 375 | CoreSupp *su; |
| 376 | Bool any_supp; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 377 | |
| 378 | if (VG_(clo_verbosity) == 0) |
| 379 | return; |
| 380 | |
| 381 | n_err_contexts = 0; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 382 | for (p = vg_errors; p != NULL; p = p->next) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 383 | if (p->supp == NULL) |
| 384 | n_err_contexts++; |
| 385 | } |
| 386 | |
| 387 | n_supp_contexts = 0; |
| 388 | for (su = vg_suppressions; su != NULL; su = su->next) { |
| 389 | if (su->count > 0) |
| 390 | n_supp_contexts++; |
| 391 | } |
| 392 | |
| 393 | VG_(message)(Vg_UserMsg, |
| 394 | "ERROR SUMMARY: " |
| 395 | "%d errors from %d contexts (suppressed: %d from %d)", |
| 396 | vg_n_errs_found, n_err_contexts, |
| 397 | vg_n_errs_suppressed, n_supp_contexts ); |
| 398 | |
| 399 | if (VG_(clo_verbosity) <= 1) |
| 400 | return; |
| 401 | |
| 402 | /* Print the contexts in order of increasing error count. */ |
| 403 | for (i = 0; i < n_err_contexts; i++) { |
| 404 | n_min = (1 << 30) - 1; |
| 405 | p_min = NULL; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 406 | for (p = vg_errors; p != NULL; p = p->next) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 407 | if (p->supp != NULL) continue; |
| 408 | if (p->count < n_min) { |
| 409 | n_min = p->count; |
| 410 | p_min = p; |
| 411 | } |
| 412 | } |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 413 | if (p_min == NULL) VG_(skin_panic)("show_all_errors()"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 414 | |
| 415 | VG_(message)(Vg_UserMsg, ""); |
| 416 | VG_(message)(Vg_UserMsg, "%d errors in context %d of %d:", |
| 417 | p_min->count, |
| 418 | i+1, n_err_contexts); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 419 | pp_CoreError( p_min, False ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 420 | |
| 421 | if ((i+1 == VG_(clo_dump_error))) { |
sewardj | 1e8cdc9 | 2002-04-18 11:37:52 +0000 | [diff] [blame] | 422 | VG_(translate) ( 0 /* dummy ThreadId; irrelevant due to below NULLs */, |
| 423 | p_min->where->eips[0], NULL, NULL, NULL ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | p_min->count = 1 << 30; |
| 427 | } |
| 428 | |
| 429 | if (n_supp_contexts > 0) |
| 430 | VG_(message)(Vg_DebugMsg, ""); |
| 431 | any_supp = False; |
| 432 | for (su = vg_suppressions; su != NULL; su = su->next) { |
| 433 | if (su->count > 0) { |
| 434 | any_supp = True; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 435 | VG_(message)(Vg_DebugMsg, "supp: %4d %s", su->count, su->sname); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | |
| 439 | if (n_err_contexts > 0) { |
| 440 | if (any_supp) |
| 441 | VG_(message)(Vg_UserMsg, ""); |
| 442 | VG_(message)(Vg_UserMsg, |
| 443 | "IN SUMMARY: " |
| 444 | "%d errors from %d contexts (suppressed: %d from %d)", |
| 445 | vg_n_errs_found, n_err_contexts, |
| 446 | vg_n_errs_suppressed, |
| 447 | n_supp_contexts ); |
| 448 | VG_(message)(Vg_UserMsg, ""); |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | /*------------------------------------------------------------*/ |
| 453 | /*--- Standard suppressions ---*/ |
| 454 | /*------------------------------------------------------------*/ |
| 455 | |
| 456 | /* Get a non-blank, non-comment line of at most nBuf chars from fd. |
| 457 | Skips leading spaces on the line. Return True if EOF was hit instead. |
| 458 | */ |
| 459 | |
| 460 | #define VG_ISSPACE(ch) (((ch)==' ') || ((ch)=='\n') || ((ch)=='\t')) |
| 461 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 462 | Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 463 | { |
| 464 | Char ch; |
| 465 | Int n, i; |
| 466 | while (True) { |
| 467 | /* First, read until a non-blank char appears. */ |
| 468 | while (True) { |
| 469 | n = VG_(read)(fd, &ch, 1); |
| 470 | if (n == 1 && !VG_ISSPACE(ch)) break; |
| 471 | if (n == 0) return True; |
| 472 | } |
| 473 | |
| 474 | /* Now, read the line into buf. */ |
| 475 | i = 0; |
| 476 | buf[i++] = ch; buf[i] = 0; |
| 477 | while (True) { |
| 478 | n = VG_(read)(fd, &ch, 1); |
| 479 | if (n == 0) return False; /* the next call will return True */ |
| 480 | if (ch == '\n') break; |
| 481 | if (i > 0 && i == nBuf-1) i--; |
| 482 | buf[i++] = ch; buf[i] = 0; |
| 483 | } |
| 484 | while (i > 1 && VG_ISSPACE(buf[i-1])) { |
| 485 | i--; buf[i] = 0; |
| 486 | }; |
| 487 | |
| 488 | /* VG_(printf)("The line is `%s'\n", buf); */ |
| 489 | /* Ok, we have a line. If a non-comment line, return. |
| 490 | If a comment line, start all over again. */ |
| 491 | if (buf[0] != '#') return False; |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | |
| 496 | /* *p_caller contains the raw name of a caller, supposedly either |
| 497 | fun:some_function_name or |
| 498 | obj:some_object_name. |
| 499 | Set *p_ty accordingly and advance *p_caller over the descriptor |
| 500 | (fun: or obj:) part. |
| 501 | Returns False if failed. |
| 502 | */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 503 | static Bool setLocationTy ( Char** p_caller, SuppLocTy* p_ty ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 504 | { |
| 505 | if (VG_(strncmp)(*p_caller, "fun:", 4) == 0) { |
| 506 | (*p_caller) += 4; |
| 507 | *p_ty = FunName; |
| 508 | return True; |
| 509 | } |
| 510 | if (VG_(strncmp)(*p_caller, "obj:", 4) == 0) { |
| 511 | (*p_caller) += 4; |
| 512 | *p_ty = ObjName; |
| 513 | return True; |
| 514 | } |
| 515 | VG_(printf)("location should start with fun: or obj:\n"); |
| 516 | return False; |
| 517 | } |
| 518 | |
| 519 | |
| 520 | /* Read suppressions from the file specified in vg_clo_suppressions |
| 521 | and place them in the suppressions list. If there's any difficulty |
| 522 | doing this, just give up -- there's no point in trying to recover. |
| 523 | */ |
| 524 | #define STREQ(s1,s2) (s1 != NULL && s2 != NULL \ |
| 525 | && VG_(strcmp)((s1),(s2))==0) |
| 526 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 527 | static void load_one_suppressions_file ( Char* filename ) |
| 528 | { |
| 529 | # define N_BUF 200 |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 530 | Int fd, i; |
| 531 | Bool eof; |
| 532 | Char buf[N_BUF+1]; |
| 533 | Char* skin_name; |
| 534 | Char* supp_name; |
| 535 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 536 | fd = VG_(open)( filename, VKI_O_RDONLY, 0 ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 537 | if (fd == -1) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 538 | VG_(message)(Vg_UserMsg, "FATAL: can't open suppressions file `%s'", |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 539 | filename ); |
| 540 | VG_(exit)(1); |
| 541 | } |
| 542 | |
| 543 | while (True) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 544 | /* Assign and initialise the two suppression halves (core and skin) */ |
| 545 | CoreSupp* supp; |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 546 | supp = VG_(arena_malloc)(VG_AR_CORE, sizeof(CoreSupp)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 547 | supp->count = 0; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 548 | for (i = 0; i < VG_N_SUPP_CALLERS; i++) supp->caller[i] = NULL; |
| 549 | supp->skin_supp.string = supp->skin_supp.extra = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 550 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 551 | eof = VG_(get_line) ( fd, buf, N_BUF ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 552 | if (eof) break; |
| 553 | |
| 554 | if (!STREQ(buf, "{")) goto syntax_error; |
| 555 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 556 | eof = VG_(get_line) ( fd, buf, N_BUF ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 557 | if (eof || STREQ(buf, "}")) goto syntax_error; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 558 | supp->sname = VG_(arena_strdup)(VG_AR_CORE, buf); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 559 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 560 | eof = VG_(get_line) ( fd, buf, N_BUF ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 561 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 562 | if (eof) goto syntax_error; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 563 | |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 564 | /* Check it has the "skin_name:supp_name" form (ie. look for ':') */ |
| 565 | i = 0; |
| 566 | while (True) { |
| 567 | if (buf[i] == ':') break; |
| 568 | if (buf[i] == '\0') goto syntax_error; |
| 569 | i++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 570 | } |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 571 | buf[i] = '\0'; /* Replace ':', splitting into two strings */ |
| 572 | |
| 573 | skin_name = & buf[0]; |
| 574 | supp_name = & buf[i+1]; |
| 575 | |
| 576 | /* Is it a core suppression? (core:<supp_name>) */ |
| 577 | if (VG_(needs).core_errors && STREQ(skin_name, "core")) |
| 578 | { |
| 579 | if (STREQ(supp_name, "PThread")) |
| 580 | supp->skin_supp.skind = PThreadSupp; |
| 581 | else |
| 582 | goto syntax_error; |
| 583 | } |
| 584 | |
| 585 | /* Is it a skin suppression? (<skin_name>:<supp_name>") */ |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 586 | else if (VG_(needs).skin_errors && STREQ(skin_name, VG_(details).name)) |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 587 | { |
| 588 | if (SK_(recognised_suppression)(supp_name, & supp->skin_supp.skind)) |
| 589 | { |
| 590 | /* Do nothing, function fills in supp->skin_supp.skind */ |
| 591 | } else |
| 592 | goto syntax_error; |
| 593 | } |
| 594 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 595 | else { |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 596 | /* Ignore rest of suppression */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 597 | while (True) { |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 598 | eof = VG_(get_line) ( fd, buf, N_BUF ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 599 | if (eof) goto syntax_error; |
| 600 | if (STREQ(buf, "}")) |
| 601 | break; |
| 602 | } |
| 603 | continue; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 604 | } |
| 605 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 606 | if (VG_(needs).skin_errors && |
| 607 | !SK_(read_extra_suppression_info)(fd, buf, N_BUF, &supp->skin_supp)) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 608 | goto syntax_error; |
| 609 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 610 | /* "i > 0" ensures at least one caller read. */ |
| 611 | for (i = 0; i < VG_N_SUPP_CALLERS; i++) { |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 612 | eof = VG_(get_line) ( fd, buf, N_BUF ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 613 | if (eof) goto syntax_error; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 614 | if (i > 0 && STREQ(buf, "}")) |
| 615 | break; |
| 616 | supp->caller[i] = VG_(arena_strdup)(VG_AR_CORE, buf); |
| 617 | if (!setLocationTy(&(supp->caller[i]), &(supp->caller_ty[i]))) |
| 618 | goto syntax_error; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | supp->next = vg_suppressions; |
| 622 | vg_suppressions = supp; |
| 623 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 624 | VG_(close)(fd); |
| 625 | return; |
| 626 | |
| 627 | syntax_error: |
| 628 | if (eof) { |
| 629 | VG_(message)(Vg_UserMsg, |
| 630 | "FATAL: in suppressions file `%s': unexpected EOF", |
| 631 | filename ); |
| 632 | } else { |
| 633 | VG_(message)(Vg_UserMsg, |
| 634 | "FATAL: in suppressions file `%s': syntax error on: %s", |
| 635 | filename, buf ); |
| 636 | } |
| 637 | VG_(close)(fd); |
| 638 | VG_(message)(Vg_UserMsg, "exiting now."); |
| 639 | VG_(exit)(1); |
| 640 | |
| 641 | # undef N_BUF |
| 642 | } |
| 643 | |
| 644 | |
| 645 | void VG_(load_suppressions) ( void ) |
| 646 | { |
| 647 | Int i; |
| 648 | vg_suppressions = NULL; |
| 649 | for (i = 0; i < VG_(clo_n_suppressions); i++) { |
| 650 | if (VG_(clo_verbosity) > 1) { |
| 651 | VG_(message)(Vg_UserMsg, "Reading suppressions file: %s", |
| 652 | VG_(clo_suppressions)[i] ); |
| 653 | } |
| 654 | load_one_suppressions_file( VG_(clo_suppressions)[i] ); |
| 655 | } |
| 656 | } |
| 657 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 658 | /* Return the name of an erring fn in a way which is useful |
| 659 | for comparing against the contents of a suppressions file. |
| 660 | Doesn't demangle the fn name, because we want to refer to |
| 661 | mangled names in the suppressions file. |
| 662 | */ |
| 663 | static |
| 664 | void get_objname_fnname ( Addr a, |
| 665 | Char* obj_buf, Int n_obj_buf, |
| 666 | Char* fun_buf, Int n_fun_buf ) |
| 667 | { |
| 668 | (void)VG_(get_objname) ( a, obj_buf, n_obj_buf ); |
| 669 | (void)VG_(get_fnname_nodemangle)( a, fun_buf, n_fun_buf ); |
| 670 | } |
| 671 | |
| 672 | static __inline__ |
| 673 | Bool supp_matches_error(CoreSupp* su, CoreError* err) |
| 674 | { |
| 675 | switch (su->skin_supp.skind) { |
| 676 | case PThreadSupp: |
| 677 | return (err->skin_err.ekind == PThreadErr); |
| 678 | default: |
| 679 | if (VG_(needs).skin_errors) { |
| 680 | return (SK_(error_matches_suppression)(&err->skin_err, |
| 681 | &su->skin_supp)); |
| 682 | } else { |
| 683 | VG_(printf)( |
| 684 | "\nUnhandled suppression type: %u. VG_(needs).skin_errors\n" |
| 685 | "probably needs to be set.\n", |
| 686 | err->skin_err.ekind); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 687 | VG_(skin_panic)("unhandled suppression type"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | static __inline__ |
| 693 | Bool supp_matches_callers(CoreSupp* su, Char caller_obj[][M_VG_ERRTXT], |
| 694 | Char caller_fun[][M_VG_ERRTXT]) |
| 695 | { |
| 696 | Int i; |
| 697 | |
| 698 | for (i = 0; su->caller[i] != NULL; i++) { |
| 699 | switch (su->caller_ty[i]) { |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 700 | case ObjName: if (VG_(string_match)(su->caller[i], |
| 701 | caller_obj[i])) break; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 702 | return False; |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 703 | case FunName: if (VG_(string_match)(su->caller[i], |
| 704 | caller_fun[i])) break; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 705 | return False; |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 706 | default: VG_(skin_panic)("is_suppressible_error"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | |
| 710 | /* If we reach here, it's a match */ |
| 711 | return True; |
| 712 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 713 | |
| 714 | /* Does an error context match a suppression? ie is this a |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 715 | suppressible error? If so, return a pointer to the CoreSupp |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 716 | record, otherwise NULL. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 717 | Tries to minimise the number of symbol searches since they are expensive. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 718 | */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 719 | static CoreSupp* is_suppressible_error ( CoreError* err ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 720 | { |
| 721 | # define STREQ(s1,s2) (s1 != NULL && s2 != NULL \ |
| 722 | && VG_(strcmp)((s1),(s2))==0) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 723 | Int i; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 724 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 725 | Char caller_obj[VG_N_SUPP_CALLERS][M_VG_ERRTXT]; |
| 726 | Char caller_fun[VG_N_SUPP_CALLERS][M_VG_ERRTXT]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 727 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 728 | CoreSupp* su; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 729 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 730 | /* get_objname_fnname() writes the function name and object name if |
| 731 | it finds them in the debug info. so the strings in the suppression |
| 732 | file should match these. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 733 | */ |
| 734 | |
| 735 | /* Initialise these strs so they are always safe to compare, even |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 736 | if get_objname_fnname doesn't write anything to them. */ |
| 737 | for (i = 0; i < VG_N_SUPP_CALLERS; i++) |
| 738 | caller_obj[i][0] = caller_fun[i][0] = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 739 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 740 | for (i = 0; i < VG_N_SUPP_CALLERS && i < VG_(clo_backtrace_size); i++) { |
| 741 | get_objname_fnname ( err->where->eips[i], |
| 742 | caller_obj[i], M_VG_ERRTXT, |
| 743 | caller_fun[i], M_VG_ERRTXT ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | /* See if the error context matches any suppression. */ |
| 747 | for (su = vg_suppressions; su != NULL; su = su->next) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 748 | if (supp_matches_error(su, err) && |
| 749 | supp_matches_callers(su, caller_obj, caller_fun)) { |
| 750 | return su; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 751 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 752 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 753 | return NULL; /* no matches */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 754 | |
| 755 | # undef STREQ |
| 756 | } |
| 757 | |
| 758 | /*--------------------------------------------------------------------*/ |
| 759 | /*--- end vg_errcontext.c ---*/ |
| 760 | /*--------------------------------------------------------------------*/ |