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