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