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