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