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