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