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