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