sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
sewardj | 267100d | 2005-04-24 12:33:12 +0000 | [diff] [blame] | 3 | /*--- Management of error messages. m_errormgr.c ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 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 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2005 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" |
njn | d2b1711 | 2005-04-19 04:10:25 +0000 | [diff] [blame] | 32 | #include "pub_core_errormgr.h" |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 33 | #include "pub_core_execontext.h" |
njn | d2b1711 | 2005-04-19 04:10:25 +0000 | [diff] [blame] | 34 | #include "pub_core_stacktrace.h" |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 35 | |
| 36 | /*------------------------------------------------------------*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 37 | /*--- Globals ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 38 | /*------------------------------------------------------------*/ |
| 39 | |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 40 | /* After this many different unsuppressed errors have been observed, |
| 41 | be more conservative about collecting new ones. */ |
| 42 | #define M_COLLECT_ERRORS_SLOWLY_AFTER 50 |
| 43 | |
| 44 | /* After this many different unsuppressed errors have been observed, |
| 45 | stop collecting errors at all, and tell the user their program is |
| 46 | evidently a steaming pile of camel dung. */ |
| 47 | #define M_COLLECT_NO_ERRORS_AFTER_SHOWN 300 |
| 48 | |
| 49 | /* After this many total errors have been observed, stop collecting |
| 50 | errors at all. Counterpart to M_COLLECT_NO_ERRORS_AFTER_SHOWN. */ |
| 51 | #define M_COLLECT_NO_ERRORS_AFTER_FOUND 30000 |
| 52 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 53 | /* The list of error contexts found, both suppressed and unsuppressed. |
| 54 | Initially empty, and grows as errors are detected. */ |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 55 | static Error* errors = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 56 | |
| 57 | /* The list of suppression directives, as read from the specified |
| 58 | suppressions file. */ |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 59 | static Supp* suppressions = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 60 | |
| 61 | /* Running count of unsuppressed errors detected. */ |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 62 | static UInt n_errs_found = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 63 | |
| 64 | /* Running count of suppressed errors detected. */ |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 65 | static UInt n_errs_suppressed = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 66 | |
| 67 | /* forwards ... */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 68 | static Supp* is_suppressible_error ( Error* err ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 69 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 70 | static ThreadId last_tid_printed = 1; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 71 | |
| 72 | /*------------------------------------------------------------*/ |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 73 | /*--- Error type ---*/ |
| 74 | /*------------------------------------------------------------*/ |
| 75 | |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 76 | /* 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] | 77 | * effectively extend it by defining their own enums in the (0..) range. */ |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 78 | |
| 79 | /* Errors. Extensible (via the 'extra' field). Tools can use a normal |
| 80 | enum (with element values in the normal range (0..)) for `ekind'. |
| 81 | Functions for getting/setting the tool-relevant fields are in |
nethercote | 4606320 | 2004-09-02 08:51:43 +0000 | [diff] [blame] | 82 | include/tool.h. |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 83 | |
| 84 | When errors are found and recorded with VG_(maybe_record_error)(), all |
| 85 | the tool must do is pass in the four parameters; core will |
| 86 | allocate/initialise the error record. |
| 87 | */ |
| 88 | struct _Error { |
| 89 | struct _Error* next; |
| 90 | // NULL if unsuppressed; or ptr to suppression record. |
| 91 | Supp* supp; |
| 92 | Int count; |
| 93 | ThreadId tid; |
| 94 | |
| 95 | // The tool-specific part |
| 96 | ExeContext* where; // Initialised by core |
njn | d2b1711 | 2005-04-19 04:10:25 +0000 | [diff] [blame] | 97 | ErrorKind ekind; // Used by ALL. Must be in the range (0..) |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 98 | Addr addr; // Used frequently |
| 99 | Char* string; // Used frequently |
| 100 | void* extra; // For any tool-specific extras |
| 101 | }; |
| 102 | |
| 103 | ExeContext* VG_(get_error_where) ( Error* err ) |
| 104 | { |
| 105 | return err->where; |
| 106 | } |
| 107 | |
| 108 | ErrorKind VG_(get_error_kind) ( Error* err ) |
| 109 | { |
| 110 | return err->ekind; |
| 111 | } |
| 112 | |
| 113 | Addr VG_(get_error_address) ( Error* err ) |
| 114 | { |
| 115 | return err->addr; |
| 116 | } |
| 117 | |
| 118 | Char* VG_(get_error_string) ( Error* err ) |
| 119 | { |
| 120 | return err->string; |
| 121 | } |
| 122 | |
| 123 | void* VG_(get_error_extra) ( Error* err ) |
| 124 | { |
| 125 | return err->extra; |
| 126 | } |
| 127 | |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 128 | UInt VG_(get_n_errs_found)( void ) |
| 129 | { |
| 130 | return n_errs_found; |
| 131 | } |
| 132 | |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 133 | /*------------------------------------------------------------*/ |
| 134 | /*--- Suppression type ---*/ |
| 135 | /*------------------------------------------------------------*/ |
| 136 | |
| 137 | /* Note: it is imperative this doesn't overlap with (0..) at all, as tools |
| 138 | * effectively extend it by defining their own enums in the (0..) range. */ |
| 139 | typedef |
| 140 | enum { |
| 141 | PThreadSupp = -1, /* Matches PThreadErr */ |
| 142 | } |
| 143 | CoreSuppKind; |
| 144 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 145 | /* Max number of callers for context in a suppression. */ |
| 146 | #define VG_MAX_SUPP_CALLERS 24 |
| 147 | |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 148 | /* For each caller specified for a suppression, record the nature of |
| 149 | the caller name. Not of interest to tools. */ |
| 150 | typedef |
| 151 | enum { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 152 | NoName, /* Error case */ |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 153 | ObjName, /* Name is of an shared object file. */ |
| 154 | FunName /* Name is of a function. */ |
| 155 | } |
| 156 | SuppLocTy; |
| 157 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 158 | typedef |
| 159 | struct { |
| 160 | SuppLocTy ty; |
| 161 | Char* name; |
| 162 | } |
| 163 | SuppLoc; |
| 164 | |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 165 | /* Suppressions. Tools can get/set tool-relevant parts with functions |
nethercote | 4606320 | 2004-09-02 08:51:43 +0000 | [diff] [blame] | 166 | declared in include/tool.h. Extensible via the 'extra' field. |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 167 | Tools can use a normal enum (with element values in the normal range |
| 168 | (0..)) for `skind'. */ |
| 169 | struct _Supp { |
| 170 | struct _Supp* next; |
| 171 | Int count; // The number of times this error has been suppressed. |
| 172 | Char* sname; // The name by which the suppression is referred to. |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 173 | |
| 174 | // Length of 'callers' |
| 175 | Int n_callers; |
| 176 | // Array of callers, for matching stack traces. First one (name of fn |
| 177 | // where err occurs) is mandatory; rest are optional. |
| 178 | SuppLoc* callers; |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 179 | |
| 180 | /* The tool-specific part */ |
| 181 | SuppKind skind; // What kind of suppression. Must use the range (0..). |
| 182 | Char* string; // String -- use is optional. NULL by default. |
| 183 | void* extra; // Anything else -- use is optional. NULL by default. |
| 184 | }; |
| 185 | |
| 186 | SuppKind VG_(get_supp_kind) ( Supp* su ) |
| 187 | { |
| 188 | return su->skind; |
| 189 | } |
| 190 | |
| 191 | Char* VG_(get_supp_string) ( Supp* su ) |
| 192 | { |
| 193 | return su->string; |
| 194 | } |
| 195 | |
| 196 | void* VG_(get_supp_extra) ( Supp* su ) |
| 197 | { |
| 198 | return su->extra; |
| 199 | } |
| 200 | |
| 201 | |
| 202 | void VG_(set_supp_kind) ( Supp* su, SuppKind skind ) |
| 203 | { |
| 204 | su->skind = skind; |
| 205 | } |
| 206 | |
| 207 | void VG_(set_supp_string) ( Supp* su, Char* string ) |
| 208 | { |
| 209 | su->string = string; |
| 210 | } |
| 211 | |
| 212 | void VG_(set_supp_extra) ( Supp* su, void* extra ) |
| 213 | { |
| 214 | su->extra = extra; |
| 215 | } |
| 216 | |
| 217 | |
| 218 | /*------------------------------------------------------------*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 219 | /*--- Helper fns ---*/ |
| 220 | /*------------------------------------------------------------*/ |
| 221 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 222 | /* Compare error contexts, to detect duplicates. Note that if they |
| 223 | are otherwise the same, the faulting addrs and associated rwoffsets |
| 224 | are allowed to be different. */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 225 | static Bool eq_Error ( VgRes res, Error* e1, Error* e2 ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 226 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 227 | if (e1->ekind != e2->ekind) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 228 | return False; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 229 | if (!VG_(eq_ExeContext)(res, e1->where, e2->where)) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 230 | return False; |
| 231 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 232 | switch (e1->ekind) { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 233 | // case ThreadErr: |
| 234 | // case MutexErr: |
| 235 | // vg_assert(VG_(needs).core_errors); |
| 236 | // return VG_(tm_error_equal)(res, e1, e2); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 237 | default: |
njn | 95ec870 | 2004-11-22 16:46:13 +0000 | [diff] [blame] | 238 | if (VG_(needs).tool_errors) |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 239 | return TL_(eq_Error)(res, e1, e2); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 240 | else { |
njn | 95ec870 | 2004-11-22 16:46:13 +0000 | [diff] [blame] | 241 | VG_(printf)("\nUnhandled error type: %u. VG_(needs).tool_errors\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 242 | "probably needs to be set.\n", |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 243 | e1->ekind); |
njn | 6799325 | 2004-11-22 18:02:32 +0000 | [diff] [blame] | 244 | VG_(tool_panic)("unhandled error type"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 245 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 249 | static void pp_Error ( Error* err, Bool printCount ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 250 | { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 251 | if (printCount) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 252 | VG_(message)(Vg_UserMsg, "Observed %d times:", err->count ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 253 | if (err->tid > 0 && err->tid != last_tid_printed) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 254 | VG_(message)(Vg_UserMsg, "Thread %d:", err->tid ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 255 | last_tid_printed = err->tid; |
| 256 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 257 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 258 | switch (err->ekind) { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 259 | // case ThreadErr: |
| 260 | // case MutexErr: |
| 261 | // vg_assert(VG_(needs).core_errors); |
| 262 | // VG_(tm_error_print)(err); |
| 263 | // break; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 264 | default: |
njn | 95ec870 | 2004-11-22 16:46:13 +0000 | [diff] [blame] | 265 | if (VG_(needs).tool_errors) |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 266 | TL_(pp_Error)( err ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 267 | else { |
njn | 95ec870 | 2004-11-22 16:46:13 +0000 | [diff] [blame] | 268 | VG_(printf)("\nUnhandled error type: %u. VG_(needs).tool_errors\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 269 | "probably needs to be set?\n", |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 270 | err->ekind); |
njn | 6799325 | 2004-11-22 18:02:32 +0000 | [diff] [blame] | 271 | VG_(tool_panic)("unhandled error type"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 272 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 273 | } |
| 274 | } |
| 275 | |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 276 | /* 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] | 277 | by asking the user. */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 278 | Bool VG_(is_action_requested) ( Char* action, Bool* clo ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 279 | { |
| 280 | Char ch, ch2; |
| 281 | Int res; |
| 282 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 283 | if (*clo == False) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 284 | return False; |
| 285 | |
| 286 | VG_(message)(Vg_UserMsg, ""); |
| 287 | |
| 288 | again: |
| 289 | VG_(printf)( |
| 290 | "==%d== " |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 291 | "---- %s ? --- [Return/N/n/Y/y/C/c] ---- ", |
| 292 | VG_(getpid)(), action |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 293 | ); |
| 294 | |
sewardj | 6024b21 | 2003-07-13 10:54:33 +0000 | [diff] [blame] | 295 | res = VG_(read)(VG_(clo_input_fd), &ch, 1); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 296 | if (res != 1) goto ioerror; |
| 297 | /* res == 1 */ |
| 298 | if (ch == '\n') return False; |
| 299 | if (ch != 'N' && ch != 'n' && ch != 'Y' && ch != 'y' |
| 300 | && ch != 'C' && ch != 'c') goto again; |
| 301 | |
sewardj | 6024b21 | 2003-07-13 10:54:33 +0000 | [diff] [blame] | 302 | res = VG_(read)(VG_(clo_input_fd), &ch2, 1); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 303 | if (res != 1) goto ioerror; |
| 304 | if (ch2 != '\n') goto again; |
| 305 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 306 | /* No, don't want to do action. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 307 | if (ch == 'n' || ch == 'N') return False; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 308 | /* Yes, want to do action. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 309 | if (ch == 'y' || ch == 'Y') return True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 310 | /* No, don't want to do action, and don't ask again either. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 311 | vg_assert(ch == 'c' || ch == 'C'); |
| 312 | |
| 313 | ioerror: |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 314 | *clo = False; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 315 | return False; |
| 316 | } |
| 317 | |
| 318 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 319 | /* Construct an error */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 320 | static __inline__ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 321 | void construct_error ( Error* err, ThreadId tid, ErrorKind ekind, Addr a, |
| 322 | Char* s, void* extra, ExeContext* where ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 323 | { |
njn | ca82cc0 | 2004-11-22 17:18:48 +0000 | [diff] [blame] | 324 | tl_assert(tid < VG_N_THREADS); |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 325 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 326 | /* Core-only parts */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 327 | err->next = NULL; |
| 328 | err->supp = NULL; |
| 329 | err->count = 1; |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 330 | err->tid = tid; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 331 | if (NULL == where) |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 332 | err->where = VG_(record_ExeContext)( tid ); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 333 | else |
| 334 | err->where = where; |
njn | 1d6c4bc | 2002-11-21 13:38:08 +0000 | [diff] [blame] | 335 | |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 336 | /* Tool-relevant parts */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 337 | err->ekind = ekind; |
| 338 | err->addr = a; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 339 | err->extra = extra; |
sewardj | a602261 | 2003-07-24 23:50:17 +0000 | [diff] [blame] | 340 | err->string = s; |
| 341 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 342 | /* sanity... */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 343 | vg_assert( tid < VG_N_THREADS ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 344 | } |
| 345 | |
njn | f426131 | 2005-03-20 23:45:36 +0000 | [diff] [blame] | 346 | static void printSuppForIp(UInt n, Addr ip) |
| 347 | { |
njn | 47b209a | 2005-03-25 23:47:16 +0000 | [diff] [blame] | 348 | static UChar buf[VG_ERRTXT_LEN]; |
njn | f426131 | 2005-03-20 23:45:36 +0000 | [diff] [blame] | 349 | |
njn | 47b209a | 2005-03-25 23:47:16 +0000 | [diff] [blame] | 350 | if ( VG_(get_fnname_nodemangle) (ip, buf, VG_ERRTXT_LEN) ) { |
njn | f426131 | 2005-03-20 23:45:36 +0000 | [diff] [blame] | 351 | VG_(printf)(" fun:%s\n", buf); |
njn | 47b209a | 2005-03-25 23:47:16 +0000 | [diff] [blame] | 352 | } else if ( VG_(get_objname)(ip, buf+7, VG_ERRTXT_LEN-7) ) { |
njn | f426131 | 2005-03-20 23:45:36 +0000 | [diff] [blame] | 353 | VG_(printf)(" obj:%s\n", buf); |
| 354 | } else { |
| 355 | VG_(printf)(" ???:??? " |
| 356 | "# unknown, suppression will not work, sorry\n"); |
| 357 | } |
| 358 | } |
| 359 | |
nethercote | 10d481a | 2004-01-25 20:33:53 +0000 | [diff] [blame] | 360 | static void gen_suppression(Error* err) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 361 | { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 362 | ExeContext* ec = VG_(get_error_where)(err); |
| 363 | Int stop_at = VG_(clo_backtrace_size); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 364 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 365 | /* At most VG_MAX_SUPP_CALLERS names */ |
| 366 | if (stop_at > VG_MAX_SUPP_CALLERS) stop_at = VG_MAX_SUPP_CALLERS; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 367 | vg_assert(stop_at > 0); |
| 368 | |
| 369 | VG_(printf)("{\n"); |
| 370 | VG_(printf)(" <insert a suppression name here>\n"); |
njn | 6a23053 | 2003-07-21 10:38:23 +0000 | [diff] [blame] | 371 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 372 | if (ThreadErr == err->ekind || MutexErr == err->ekind) { |
njn | 6a23053 | 2003-07-21 10:38:23 +0000 | [diff] [blame] | 373 | VG_(printf)(" core:PThread\n"); |
| 374 | |
| 375 | } else { |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 376 | Char* name = TL_(get_error_name)(err); |
njn | 6a23053 | 2003-07-21 10:38:23 +0000 | [diff] [blame] | 377 | if (NULL == name) { |
| 378 | VG_(message)(Vg_UserMsg, |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 379 | "(tool does not allow error to be suppressed)"); |
njn | 6a23053 | 2003-07-21 10:38:23 +0000 | [diff] [blame] | 380 | return; |
| 381 | } |
| 382 | VG_(printf)(" %s:%s\n", VG_(details).name, name); |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 383 | TL_(print_extra_suppression_info)(err); |
njn | 6a23053 | 2003-07-21 10:38:23 +0000 | [diff] [blame] | 384 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 385 | |
njn | f426131 | 2005-03-20 23:45:36 +0000 | [diff] [blame] | 386 | // Print stack trace elements |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 387 | VG_(apply_StackTrace)(printSuppForIp, VG_(extract_StackTrace)(ec), stop_at); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 388 | |
| 389 | VG_(printf)("}\n"); |
| 390 | } |
| 391 | |
njn | b4aee05 | 2003-04-15 14:09:58 +0000 | [diff] [blame] | 392 | static |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 393 | void do_actions_on_error(Error* err, Bool allow_db_attach) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 394 | { |
sewardj | d153fae | 2005-01-10 17:24:47 +0000 | [diff] [blame] | 395 | Bool still_noisy = True; |
| 396 | |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 397 | /* Perhaps we want a debugger attach at this point? */ |
| 398 | if (allow_db_attach && |
njn | d2b1711 | 2005-04-19 04:10:25 +0000 | [diff] [blame] | 399 | VG_(is_action_requested)( "Attach to debugger", & VG_(clo_db_attach) )) |
| 400 | { |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 401 | VG_(printf)("starting debugger\n"); |
| 402 | VG_(start_debugger)( err->tid ); |
njn | d2b1711 | 2005-04-19 04:10:25 +0000 | [diff] [blame] | 403 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 404 | /* Or maybe we want to generate the error's suppression? */ |
sewardj | d153fae | 2005-01-10 17:24:47 +0000 | [diff] [blame] | 405 | if (VG_(clo_gen_suppressions) == 2 |
| 406 | || (VG_(clo_gen_suppressions) == 1 |
njn | d2b1711 | 2005-04-19 04:10:25 +0000 | [diff] [blame] | 407 | && VG_(is_action_requested)( "Print suppression", &still_noisy )) |
sewardj | d153fae | 2005-01-10 17:24:47 +0000 | [diff] [blame] | 408 | ) { |
nethercote | 42602b1 | 2004-01-25 19:30:29 +0000 | [diff] [blame] | 409 | gen_suppression(err); |
sewardj | d153fae | 2005-01-10 17:24:47 +0000 | [diff] [blame] | 410 | if (VG_(clo_gen_suppressions) == 1 && !still_noisy) |
| 411 | VG_(clo_gen_suppressions) = 0; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | |
| 415 | /* Shared between VG_(maybe_record_error)() and VG_(unique_error)(), |
| 416 | just for pretty printing purposes. */ |
| 417 | static Bool is_first_shown_context = True; |
| 418 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 419 | /* Top-level entry point to the error management subsystem. |
| 420 | All detected errors are notified here; this routine decides if/when the |
| 421 | user should see the error. */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 422 | void VG_(maybe_record_error) ( ThreadId tid, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 423 | ErrorKind ekind, Addr a, Char* s, void* extra ) |
| 424 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 425 | Error err; |
| 426 | Error* p; |
| 427 | Error* p_prev; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 428 | UInt extra_size; |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 429 | VgRes exe_res = Vg_MedRes; |
| 430 | static Bool stopping_message = False; |
| 431 | static Bool slowdown_message = False; |
| 432 | static Int n_errs_shown = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 433 | |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 434 | /* After M_COLLECT_NO_ERRORS_AFTER_SHOWN different errors have |
| 435 | been found, or M_COLLECT_NO_ERRORS_AFTER_FOUND total errors |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 436 | have been found, just refuse to collect any more. This stops |
| 437 | the burden of the error-management system becoming excessive in |
| 438 | extremely buggy programs, although it does make it pretty |
| 439 | pointless to continue the Valgrind run after this point. */ |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 440 | if (VG_(clo_error_limit) |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 441 | && (n_errs_shown >= M_COLLECT_NO_ERRORS_AFTER_SHOWN |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 442 | || n_errs_found >= M_COLLECT_NO_ERRORS_AFTER_FOUND)) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 443 | if (!stopping_message) { |
| 444 | VG_(message)(Vg_UserMsg, ""); |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 445 | |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 446 | if (n_errs_shown >= M_COLLECT_NO_ERRORS_AFTER_SHOWN) { |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 447 | VG_(message)(Vg_UserMsg, |
| 448 | "More than %d different errors detected. " |
| 449 | "I'm not reporting any more.", |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 450 | M_COLLECT_NO_ERRORS_AFTER_SHOWN ); |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 451 | } else { |
| 452 | VG_(message)(Vg_UserMsg, |
| 453 | "More than %d total errors detected. " |
| 454 | "I'm not reporting any more.", |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 455 | M_COLLECT_NO_ERRORS_AFTER_FOUND ); |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 456 | } |
| 457 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 458 | VG_(message)(Vg_UserMsg, |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 459 | "Final error counts will be inaccurate. Go fix your program!"); |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 460 | VG_(message)(Vg_UserMsg, |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 461 | "Rerun with --error-limit=no to disable this cutoff. Note"); |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 462 | VG_(message)(Vg_UserMsg, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 463 | "that errors may occur in your program without prior warning from"); |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 464 | VG_(message)(Vg_UserMsg, |
| 465 | "Valgrind, because errors are no longer being displayed."); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 466 | VG_(message)(Vg_UserMsg, ""); |
| 467 | stopping_message = True; |
| 468 | } |
| 469 | return; |
| 470 | } |
| 471 | |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 472 | /* After M_COLLECT_ERRORS_SLOWLY_AFTER different errors have |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 473 | been found, be much more conservative about collecting new |
| 474 | ones. */ |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 475 | if (n_errs_shown >= M_COLLECT_ERRORS_SLOWLY_AFTER) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 476 | exe_res = Vg_LowRes; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 477 | if (!slowdown_message) { |
| 478 | VG_(message)(Vg_UserMsg, ""); |
| 479 | VG_(message)(Vg_UserMsg, |
| 480 | "More than %d errors detected. Subsequent errors", |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 481 | M_COLLECT_ERRORS_SLOWLY_AFTER); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 482 | VG_(message)(Vg_UserMsg, |
| 483 | "will still be recorded, but in less detail than before."); |
| 484 | slowdown_message = True; |
| 485 | } |
| 486 | } |
| 487 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 488 | /* Build ourselves the error */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 489 | construct_error ( &err, tid, ekind, a, s, extra, NULL ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 490 | |
| 491 | /* First, see if we've got an error record matching this one. */ |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 492 | p = errors; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 493 | p_prev = NULL; |
| 494 | while (p != NULL) { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 495 | if (eq_Error(exe_res, p, &err)) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 496 | /* Found it. */ |
| 497 | p->count++; |
| 498 | if (p->supp != NULL) { |
| 499 | /* Deal correctly with suppressed errors. */ |
| 500 | p->supp->count++; |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 501 | n_errs_suppressed++; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 502 | } else { |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 503 | n_errs_found++; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | /* Move p to the front of the list so that future searches |
| 507 | for it are faster. */ |
| 508 | if (p_prev != NULL) { |
| 509 | vg_assert(p_prev->next == p); |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 510 | p_prev->next = p->next; |
| 511 | p->next = errors; |
| 512 | errors = p; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 513 | } |
sewardj | 7ebf7c3 | 2003-07-24 21:29:40 +0000 | [diff] [blame] | 514 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 515 | return; |
| 516 | } |
| 517 | p_prev = p; |
| 518 | p = p->next; |
| 519 | } |
| 520 | |
| 521 | /* Didn't see it. Copy and add. */ |
| 522 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 523 | /* OK, we're really going to collect it. The context is on the stack and |
| 524 | will disappear shortly, so we must copy it. First do the main |
| 525 | (non-`extra') part. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 526 | |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 527 | Then TL_(update_extra) can update the `extra' part. This is for when |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 528 | there are more details to fill in which take time to work out but |
| 529 | don't affect our earlier decision to include the error -- by |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 530 | postponing those details until now, we avoid the extra work in the |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 531 | case where we ignore the error. Ugly. |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 532 | |
| 533 | 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] | 534 | TL_(update_extra) returned. Also allow for people using the void* |
njn | a70114c | 2003-08-19 16:14:42 +0000 | [diff] [blame] | 535 | extra field for a scalar value like an integer. |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 536 | */ |
| 537 | |
| 538 | /* copy main part */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 539 | p = VG_(arena_malloc)(VG_AR_ERRORS, sizeof(Error)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 540 | *p = err; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 541 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 542 | /* update `extra' */ |
| 543 | switch (ekind) { |
| 544 | // case ThreadErr: |
| 545 | // case MutexErr: |
| 546 | // vg_assert(VG_(needs).core_errors); |
| 547 | // extra_size = VG_(tm_error_update_extra)(p); |
| 548 | // break; |
| 549 | default: |
| 550 | vg_assert(VG_(needs).tool_errors); |
| 551 | extra_size = TL_(update_extra)(p); |
| 552 | break; |
| 553 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 554 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 555 | /* copy block pointed to by `extra', if there is one */ |
| 556 | if (NULL != p->extra && 0 != extra_size) { |
| 557 | void* new_extra = VG_(malloc)(extra_size); |
| 558 | VG_(memcpy)(new_extra, p->extra, extra_size); |
| 559 | p->extra = new_extra; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 560 | } |
| 561 | |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 562 | p->next = errors; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 563 | p->supp = is_suppressible_error(&err); |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 564 | errors = p; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 565 | if (p->supp == NULL) { |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 566 | n_errs_found++; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 567 | if (!is_first_shown_context) |
| 568 | VG_(message)(Vg_UserMsg, ""); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 569 | pp_Error(p, False); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 570 | is_first_shown_context = False; |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 571 | n_errs_shown++; |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 572 | do_actions_on_error(p, /*allow_db_attach*/True); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 573 | } else { |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 574 | n_errs_suppressed++; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 575 | p->supp->count++; |
| 576 | } |
| 577 | } |
| 578 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 579 | /* Second top-level entry point to the error management subsystem, for |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 580 | errors that the tool wants to report immediately, eg. because they're |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 581 | guaranteed to only happen once. This avoids all the recording and |
| 582 | comparing stuff. But they can be suppressed; returns True if it is |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 583 | suppressed. Bool `print_error' dictates whether to print the error. |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 584 | Bool `count_error' dictates whether to count the error in n_errs_found. |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 585 | */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 586 | Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind, Addr a, Char* s, |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 587 | void* extra, ExeContext* where, Bool print_error, |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 588 | Bool allow_db_attach, Bool count_error ) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 589 | { |
| 590 | Error err; |
| 591 | |
| 592 | /* Build ourselves the error */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 593 | construct_error ( &err, tid, ekind, a, s, extra, where ); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 594 | |
| 595 | /* Unless it's suppressed, we're going to show it. Don't need to make |
| 596 | a copy, because it's only temporary anyway. |
| 597 | |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 598 | Then update the `extra' part with TL_(update_extra), because that can |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 599 | have an affect on whether it's suppressed. Ignore the size return |
njn | 26f0251 | 2004-11-22 18:33:15 +0000 | [diff] [blame] | 600 | value of TL_(update_extra), because we're not copying `extra'. */ |
| 601 | (void)TL_(update_extra)(&err); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 602 | |
| 603 | if (NULL == is_suppressible_error(&err)) { |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 604 | if (count_error) |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 605 | n_errs_found++; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 606 | |
| 607 | if (print_error) { |
| 608 | if (!is_first_shown_context) |
| 609 | VG_(message)(Vg_UserMsg, ""); |
| 610 | pp_Error(&err, False); |
| 611 | is_first_shown_context = False; |
| 612 | } |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 613 | do_actions_on_error(&err, allow_db_attach); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 614 | |
| 615 | return False; |
| 616 | |
| 617 | } else { |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 618 | n_errs_suppressed++; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 619 | return True; |
| 620 | } |
| 621 | } |
| 622 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 623 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 624 | /*------------------------------------------------------------*/ |
| 625 | /*--- Exported fns ---*/ |
| 626 | /*------------------------------------------------------------*/ |
| 627 | |
njn | b9ecfe3 | 2005-03-13 05:27:57 +0000 | [diff] [blame] | 628 | /* This is called not from generated code but from the scheduler */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 629 | void VG_(show_all_errors) ( void ) |
| 630 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 631 | Int i, n_min; |
| 632 | Int n_err_contexts, n_supp_contexts; |
| 633 | Error *p, *p_min; |
| 634 | Supp *su; |
| 635 | Bool any_supp; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 636 | |
| 637 | if (VG_(clo_verbosity) == 0) |
| 638 | return; |
| 639 | |
| 640 | n_err_contexts = 0; |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 641 | for (p = errors; p != NULL; p = p->next) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 642 | if (p->supp == NULL) |
| 643 | n_err_contexts++; |
| 644 | } |
| 645 | |
| 646 | n_supp_contexts = 0; |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 647 | for (su = suppressions; su != NULL; su = su->next) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 648 | if (su->count > 0) |
| 649 | n_supp_contexts++; |
| 650 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 651 | VG_(message)(Vg_UserMsg, |
| 652 | "ERROR SUMMARY: " |
| 653 | "%d errors from %d contexts (suppressed: %d from %d)", |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 654 | n_errs_found, n_err_contexts, |
| 655 | n_errs_suppressed, n_supp_contexts ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 656 | |
| 657 | if (VG_(clo_verbosity) <= 1) |
| 658 | return; |
| 659 | |
| 660 | /* Print the contexts in order of increasing error count. */ |
| 661 | for (i = 0; i < n_err_contexts; i++) { |
| 662 | n_min = (1 << 30) - 1; |
| 663 | p_min = NULL; |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 664 | for (p = errors; p != NULL; p = p->next) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 665 | if (p->supp != NULL) continue; |
| 666 | if (p->count < n_min) { |
| 667 | n_min = p->count; |
| 668 | p_min = p; |
| 669 | } |
| 670 | } |
njn | 6799325 | 2004-11-22 18:02:32 +0000 | [diff] [blame] | 671 | if (p_min == NULL) VG_(tool_panic)("show_all_errors()"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 672 | |
| 673 | VG_(message)(Vg_UserMsg, ""); |
| 674 | VG_(message)(Vg_UserMsg, "%d errors in context %d of %d:", |
| 675 | p_min->count, |
| 676 | i+1, n_err_contexts); |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 677 | pp_Error( p_min, False ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 678 | |
| 679 | if ((i+1 == VG_(clo_dump_error))) { |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 680 | StackTrace ips = VG_(extract_StackTrace)(p_min->where); |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 681 | VG_(translate) ( 0 /* dummy ThreadId; irrelevant due to debugging*/, |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 682 | ips[0], /*debugging*/True, 0xFE/*verbosity*/); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | p_min->count = 1 << 30; |
| 686 | } |
| 687 | |
| 688 | if (n_supp_contexts > 0) |
| 689 | VG_(message)(Vg_DebugMsg, ""); |
| 690 | any_supp = False; |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 691 | for (su = suppressions; su != NULL; su = su->next) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 692 | if (su->count > 0) { |
| 693 | any_supp = True; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 694 | VG_(message)(Vg_DebugMsg, "supp: %4d %s", su->count, su->sname); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | |
| 698 | if (n_err_contexts > 0) { |
| 699 | if (any_supp) |
| 700 | VG_(message)(Vg_UserMsg, ""); |
| 701 | VG_(message)(Vg_UserMsg, |
| 702 | "IN SUMMARY: " |
| 703 | "%d errors from %d contexts (suppressed: %d from %d)", |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 704 | n_errs_found, n_err_contexts, n_errs_suppressed, |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 705 | n_supp_contexts ); |
| 706 | VG_(message)(Vg_UserMsg, ""); |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | /*------------------------------------------------------------*/ |
| 711 | /*--- Standard suppressions ---*/ |
| 712 | /*------------------------------------------------------------*/ |
| 713 | |
| 714 | /* Get a non-blank, non-comment line of at most nBuf chars from fd. |
| 715 | Skips leading spaces on the line. Return True if EOF was hit instead. |
| 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); |
njn | 0c0f32a | 2005-03-26 04:14:01 +0000 | [diff] [blame] | 725 | if (n == 1 && !VG_(isspace)(ch)) break; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 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 | } |
njn | 0c0f32a | 2005-03-26 04:14:01 +0000 | [diff] [blame] | 739 | while (i > 1 && VG_(isspace)(buf[i-1])) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 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 | |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 791 | /* Read suppressions from the file specified in VG_(clo_suppressions) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 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 | |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 928 | supp->next = suppressions; |
| 929 | suppressions = supp; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 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; |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 950 | suppressions = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 951 | for (i = 0; i < VG_(clo_n_suppressions); i++) { |
| 952 | if (VG_(clo_verbosity) > 1) { |
njn | 3f04d24 | 2005-03-20 18:21:14 +0000 | [diff] [blame] | 953 | VG_(message)(Vg_DebugMsg, "Reading suppressions file: %s", |
| 954 | VG_(clo_suppressions)[i] ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 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; |
njn | 47b209a | 2005-03-25 23:47:16 +0000 | [diff] [blame] | 983 | Char caller_name[VG_ERRTXT_LEN]; |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 984 | StackTrace ips = VG_(extract_StackTrace)(err->where); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 985 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 986 | for (i = 0; i < su->n_callers; i++) { |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 987 | Addr a = ips[i]; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 988 | vg_assert(su->callers[i].name != NULL); |
| 989 | switch (su->callers[i].ty) { |
| 990 | case ObjName: |
njn | 47b209a | 2005-03-25 23:47:16 +0000 | [diff] [blame] | 991 | if (!VG_(get_objname)(a, caller_name, VG_ERRTXT_LEN)) |
njn | 58c9f81 | 2005-03-11 04:46:09 +0000 | [diff] [blame] | 992 | return False; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 993 | break; |
| 994 | |
| 995 | case FunName: |
| 996 | // Nb: mangled names used in suppressions |
njn | 47b209a | 2005-03-25 23:47:16 +0000 | [diff] [blame] | 997 | if (!VG_(get_fnname_nodemangle)(a, caller_name, VG_ERRTXT_LEN)) |
njn | 58c9f81 | 2005-03-11 04:46:09 +0000 | [diff] [blame] | 998 | return False; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 999 | break; |
njn | 6799325 | 2004-11-22 18:02:32 +0000 | [diff] [blame] | 1000 | default: VG_(tool_panic)("supp_matches_callers"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1001 | } |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1002 | if (!VG_(string_match)(su->callers[i].name, caller_name)) |
| 1003 | return False; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | /* If we reach here, it's a match */ |
| 1007 | return True; |
| 1008 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1009 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1010 | /* Does an error context match a suppression? ie is this a suppressible |
| 1011 | error? If so, return a pointer to the Supp record, otherwise NULL. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1012 | Tries to minimise the number of symbol searches since they are expensive. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1013 | */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1014 | static Supp* is_suppressible_error ( Error* err ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1015 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1016 | Supp* su; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1017 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1018 | /* See if the error context matches any suppression. */ |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 1019 | for (su = suppressions; su != NULL; su = su->next) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1020 | if (supp_matches_error(su, err) && |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1021 | supp_matches_callers(err, su)) |
| 1022 | { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1023 | return su; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1024 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1025 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1026 | return NULL; /* no matches */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1029 | /*--------------------------------------------------------------------*/ |
sewardj | 267100d | 2005-04-24 12:33:12 +0000 | [diff] [blame] | 1030 | /*--- end m_errormgr.c ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1031 | /*--------------------------------------------------------------------*/ |