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 { |
njn | 966d663 | 2005-08-18 15:49:21 +0000 | [diff] [blame^] | 394 | VG_(printf)(" obj:*\n"); |
njn | f426131 | 2005-03-20 23:45:36 +0000 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | |
nethercote | 10d481a | 2004-01-25 20:33:53 +0000 | [diff] [blame] | 398 | static void gen_suppression(Error* err) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 399 | { |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 400 | ExeContext* ec = VG_(get_error_where)(err); |
| 401 | Int stop_at = VG_(clo_backtrace_size); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 402 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 403 | /* At most VG_MAX_SUPP_CALLERS names */ |
| 404 | if (stop_at > VG_MAX_SUPP_CALLERS) stop_at = VG_MAX_SUPP_CALLERS; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 405 | vg_assert(stop_at > 0); |
| 406 | |
| 407 | VG_(printf)("{\n"); |
| 408 | VG_(printf)(" <insert a suppression name here>\n"); |
njn | 6a23053 | 2003-07-21 10:38:23 +0000 | [diff] [blame] | 409 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 410 | if (ThreadErr == err->ekind || MutexErr == err->ekind) { |
njn | 6a23053 | 2003-07-21 10:38:23 +0000 | [diff] [blame] | 411 | VG_(printf)(" core:PThread\n"); |
| 412 | |
| 413 | } else { |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 414 | Char* name = VG_TDICT_CALL(tool_get_error_name, err); |
njn | 6a23053 | 2003-07-21 10:38:23 +0000 | [diff] [blame] | 415 | if (NULL == name) { |
| 416 | VG_(message)(Vg_UserMsg, |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 417 | "(tool does not allow error to be suppressed)"); |
njn | 6a23053 | 2003-07-21 10:38:23 +0000 | [diff] [blame] | 418 | return; |
| 419 | } |
| 420 | VG_(printf)(" %s:%s\n", VG_(details).name, name); |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 421 | VG_TDICT_CALL(tool_print_extra_suppression_info, err); |
njn | 6a23053 | 2003-07-21 10:38:23 +0000 | [diff] [blame] | 422 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 423 | |
njn | f426131 | 2005-03-20 23:45:36 +0000 | [diff] [blame] | 424 | // Print stack trace elements |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 425 | VG_(apply_StackTrace)(printSuppForIp, VG_(extract_StackTrace)(ec), stop_at); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 426 | |
| 427 | VG_(printf)("}\n"); |
| 428 | } |
| 429 | |
njn | b4aee05 | 2003-04-15 14:09:58 +0000 | [diff] [blame] | 430 | static |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 431 | void do_actions_on_error(Error* err, Bool allow_db_attach) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 432 | { |
sewardj | d153fae | 2005-01-10 17:24:47 +0000 | [diff] [blame] | 433 | Bool still_noisy = True; |
| 434 | |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 435 | /* Perhaps we want a debugger attach at this point? */ |
| 436 | if (allow_db_attach && |
njn | d2b1711 | 2005-04-19 04:10:25 +0000 | [diff] [blame] | 437 | VG_(is_action_requested)( "Attach to debugger", & VG_(clo_db_attach) )) |
| 438 | { |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 439 | VG_(printf)("starting debugger\n"); |
| 440 | VG_(start_debugger)( err->tid ); |
njn | d2b1711 | 2005-04-19 04:10:25 +0000 | [diff] [blame] | 441 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 442 | /* Or maybe we want to generate the error's suppression? */ |
sewardj | d153fae | 2005-01-10 17:24:47 +0000 | [diff] [blame] | 443 | if (VG_(clo_gen_suppressions) == 2 |
| 444 | || (VG_(clo_gen_suppressions) == 1 |
njn | d2b1711 | 2005-04-19 04:10:25 +0000 | [diff] [blame] | 445 | && VG_(is_action_requested)( "Print suppression", &still_noisy )) |
sewardj | d153fae | 2005-01-10 17:24:47 +0000 | [diff] [blame] | 446 | ) { |
nethercote | 42602b1 | 2004-01-25 19:30:29 +0000 | [diff] [blame] | 447 | gen_suppression(err); |
sewardj | d153fae | 2005-01-10 17:24:47 +0000 | [diff] [blame] | 448 | if (VG_(clo_gen_suppressions) == 1 && !still_noisy) |
| 449 | VG_(clo_gen_suppressions) = 0; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | |
| 453 | /* Shared between VG_(maybe_record_error)() and VG_(unique_error)(), |
| 454 | just for pretty printing purposes. */ |
| 455 | static Bool is_first_shown_context = True; |
| 456 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 457 | /* Top-level entry point to the error management subsystem. |
| 458 | All detected errors are notified here; this routine decides if/when the |
| 459 | user should see the error. */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 460 | void VG_(maybe_record_error) ( ThreadId tid, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 461 | ErrorKind ekind, Addr a, Char* s, void* extra ) |
| 462 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 463 | Error err; |
| 464 | Error* p; |
| 465 | Error* p_prev; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 466 | UInt extra_size; |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 467 | VgRes exe_res = Vg_MedRes; |
| 468 | static Bool stopping_message = False; |
| 469 | static Bool slowdown_message = False; |
| 470 | static Int n_errs_shown = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 471 | |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 472 | /* After M_COLLECT_NO_ERRORS_AFTER_SHOWN different errors have |
| 473 | been found, or M_COLLECT_NO_ERRORS_AFTER_FOUND total errors |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 474 | have been found, just refuse to collect any more. This stops |
| 475 | the burden of the error-management system becoming excessive in |
| 476 | extremely buggy programs, although it does make it pretty |
| 477 | pointless to continue the Valgrind run after this point. */ |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 478 | if (VG_(clo_error_limit) |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 479 | && (n_errs_shown >= M_COLLECT_NO_ERRORS_AFTER_SHOWN |
sewardj | 8a05172 | 2005-06-30 00:10:16 +0000 | [diff] [blame] | 480 | || n_errs_found >= M_COLLECT_NO_ERRORS_AFTER_FOUND) |
| 481 | && !VG_(clo_xml)) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 482 | if (!stopping_message) { |
| 483 | VG_(message)(Vg_UserMsg, ""); |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 484 | |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 485 | if (n_errs_shown >= M_COLLECT_NO_ERRORS_AFTER_SHOWN) { |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 486 | VG_(message)(Vg_UserMsg, |
| 487 | "More than %d different errors detected. " |
| 488 | "I'm not reporting any more.", |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 489 | M_COLLECT_NO_ERRORS_AFTER_SHOWN ); |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 490 | } else { |
| 491 | VG_(message)(Vg_UserMsg, |
| 492 | "More than %d total errors detected. " |
| 493 | "I'm not reporting any more.", |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 494 | M_COLLECT_NO_ERRORS_AFTER_FOUND ); |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 495 | } |
| 496 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 497 | VG_(message)(Vg_UserMsg, |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 498 | "Final error counts will be inaccurate. Go fix your program!"); |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 499 | VG_(message)(Vg_UserMsg, |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 500 | "Rerun with --error-limit=no to disable this cutoff. Note"); |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 501 | VG_(message)(Vg_UserMsg, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 502 | "that errors may occur in your program without prior warning from"); |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 503 | VG_(message)(Vg_UserMsg, |
| 504 | "Valgrind, because errors are no longer being displayed."); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 505 | VG_(message)(Vg_UserMsg, ""); |
| 506 | stopping_message = True; |
| 507 | } |
| 508 | return; |
| 509 | } |
| 510 | |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 511 | /* After M_COLLECT_ERRORS_SLOWLY_AFTER different errors have |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 512 | been found, be much more conservative about collecting new |
| 513 | ones. */ |
sewardj | 8a05172 | 2005-06-30 00:10:16 +0000 | [diff] [blame] | 514 | if (n_errs_shown >= M_COLLECT_ERRORS_SLOWLY_AFTER |
| 515 | && !VG_(clo_xml)) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 516 | exe_res = Vg_LowRes; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 517 | if (!slowdown_message) { |
| 518 | VG_(message)(Vg_UserMsg, ""); |
| 519 | VG_(message)(Vg_UserMsg, |
| 520 | "More than %d errors detected. Subsequent errors", |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 521 | M_COLLECT_ERRORS_SLOWLY_AFTER); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 522 | VG_(message)(Vg_UserMsg, |
| 523 | "will still be recorded, but in less detail than before."); |
| 524 | slowdown_message = True; |
| 525 | } |
| 526 | } |
| 527 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 528 | /* Build ourselves the error */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 529 | construct_error ( &err, tid, ekind, a, s, extra, NULL ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 530 | |
| 531 | /* First, see if we've got an error record matching this one. */ |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 532 | p = errors; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 533 | p_prev = NULL; |
| 534 | while (p != NULL) { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 535 | if (eq_Error(exe_res, p, &err)) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 536 | /* Found it. */ |
| 537 | p->count++; |
| 538 | if (p->supp != NULL) { |
| 539 | /* Deal correctly with suppressed errors. */ |
| 540 | p->supp->count++; |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 541 | n_errs_suppressed++; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 542 | } else { |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 543 | n_errs_found++; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | /* Move p to the front of the list so that future searches |
| 547 | for it are faster. */ |
| 548 | if (p_prev != NULL) { |
| 549 | vg_assert(p_prev->next == p); |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 550 | p_prev->next = p->next; |
| 551 | p->next = errors; |
| 552 | errors = p; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 553 | } |
sewardj | 7ebf7c3 | 2003-07-24 21:29:40 +0000 | [diff] [blame] | 554 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 555 | return; |
| 556 | } |
| 557 | p_prev = p; |
| 558 | p = p->next; |
| 559 | } |
| 560 | |
| 561 | /* Didn't see it. Copy and add. */ |
| 562 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 563 | /* OK, we're really going to collect it. The context is on the stack and |
| 564 | will disappear shortly, so we must copy it. First do the main |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 565 | (non-'extra') part. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 566 | |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 567 | Then VG_(tdict).tool_update_extra can update the 'extra' part. This |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 568 | is for when there are more details to fill in which take time to work |
| 569 | out but don't affect our earlier decision to include the error -- by |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 570 | postponing those details until now, we avoid the extra work in the |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 571 | case where we ignore the error. Ugly. |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 572 | |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 573 | 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] | 574 | VG_(tdict).tool_update_extra returned. Also allow for people using |
| 575 | the void* extra field for a scalar value like an integer. |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 576 | */ |
| 577 | |
| 578 | /* copy main part */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 579 | p = VG_(arena_malloc)(VG_AR_ERRORS, sizeof(Error)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 580 | *p = err; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 581 | |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 582 | /* update 'extra' */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 583 | switch (ekind) { |
| 584 | // case ThreadErr: |
| 585 | // case MutexErr: |
| 586 | // vg_assert(VG_(needs).core_errors); |
| 587 | // extra_size = VG_(tm_error_update_extra)(p); |
| 588 | // break; |
| 589 | default: |
| 590 | vg_assert(VG_(needs).tool_errors); |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 591 | extra_size = VG_TDICT_CALL(tool_update_extra, p); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 592 | break; |
| 593 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 594 | |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 595 | /* copy block pointed to by 'extra', if there is one */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 596 | if (NULL != p->extra && 0 != extra_size) { |
| 597 | void* new_extra = VG_(malloc)(extra_size); |
| 598 | VG_(memcpy)(new_extra, p->extra, extra_size); |
| 599 | p->extra = new_extra; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 600 | } |
| 601 | |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 602 | p->next = errors; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 603 | p->supp = is_suppressible_error(&err); |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 604 | errors = p; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 605 | if (p->supp == NULL) { |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 606 | n_errs_found++; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 607 | if (!is_first_shown_context) |
| 608 | VG_(message)(Vg_UserMsg, ""); |
njn | b0eb66e | 2005-07-10 16:57:24 +0000 | [diff] [blame] | 609 | pp_Error(p); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 610 | is_first_shown_context = False; |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 611 | n_errs_shown++; |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 612 | do_actions_on_error(p, /*allow_db_attach*/True); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 613 | } else { |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 614 | n_errs_suppressed++; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 615 | p->supp->count++; |
| 616 | } |
| 617 | } |
| 618 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 619 | /* Second top-level entry point to the error management subsystem, for |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 620 | errors that the tool wants to report immediately, eg. because they're |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 621 | guaranteed to only happen once. This avoids all the recording and |
| 622 | comparing stuff. But they can be suppressed; returns True if it is |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 623 | suppressed. Bool 'print_error' dictates whether to print the error. |
| 624 | Bool 'count_error' dictates whether to count the error in n_errs_found. |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 625 | */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 626 | Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind, Addr a, Char* s, |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 627 | void* extra, ExeContext* where, Bool print_error, |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 628 | Bool allow_db_attach, Bool count_error ) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 629 | { |
| 630 | Error err; |
| 631 | |
| 632 | /* Build ourselves the error */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 633 | construct_error ( &err, tid, ekind, a, s, extra, where ); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 634 | |
| 635 | /* Unless it's suppressed, we're going to show it. Don't need to make |
| 636 | a copy, because it's only temporary anyway. |
| 637 | |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 638 | Then update the 'extra' part with VG_(tdict).tool_update_extra), |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 639 | because that can have an affect on whether it's suppressed. Ignore |
| 640 | the size return value of VG_(tdict).tool_update_extra, because we're |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 641 | not copying 'extra'. */ |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 642 | (void)VG_TDICT_CALL(tool_update_extra, &err); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 643 | |
| 644 | if (NULL == is_suppressible_error(&err)) { |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 645 | if (count_error) |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 646 | n_errs_found++; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 647 | |
| 648 | if (print_error) { |
| 649 | if (!is_first_shown_context) |
| 650 | VG_(message)(Vg_UserMsg, ""); |
njn | b0eb66e | 2005-07-10 16:57:24 +0000 | [diff] [blame] | 651 | pp_Error(&err); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 652 | is_first_shown_context = False; |
| 653 | } |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 654 | do_actions_on_error(&err, allow_db_attach); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 655 | |
| 656 | return False; |
| 657 | |
| 658 | } else { |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 659 | n_errs_suppressed++; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 660 | return True; |
| 661 | } |
| 662 | } |
| 663 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 664 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 665 | /*------------------------------------------------------------*/ |
| 666 | /*--- Exported fns ---*/ |
| 667 | /*------------------------------------------------------------*/ |
| 668 | |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 669 | /* Show the used suppressions. Returns False if no suppression |
| 670 | got used. */ |
| 671 | static Bool show_used_suppressions ( void ) |
| 672 | { |
| 673 | Supp *su; |
| 674 | Bool any_supp; |
| 675 | |
sewardj | 7c9e57c | 2005-05-24 14:21:45 +0000 | [diff] [blame] | 676 | if (VG_(clo_xml)) |
| 677 | VG_(message)(Vg_DebugMsg, "<suppcounts>"); |
| 678 | |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 679 | any_supp = False; |
| 680 | for (su = suppressions; su != NULL; su = su->next) { |
| 681 | if (su->count <= 0) |
| 682 | continue; |
| 683 | any_supp = True; |
| 684 | if (VG_(clo_xml)) { |
| 685 | VG_(message)(Vg_DebugMsg, |
sewardj | 753673f | 2005-08-09 22:03:08 +0000 | [diff] [blame] | 686 | " <pair>\n" |
| 687 | " <count>%d</count>\n" |
| 688 | " <name>%t</name>\n" |
| 689 | " </pair>", |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 690 | su->count, su->sname); |
| 691 | } else { |
| 692 | VG_(message)(Vg_DebugMsg, "supp: %4d %s", su->count, su->sname); |
| 693 | } |
| 694 | } |
| 695 | |
sewardj | 7c9e57c | 2005-05-24 14:21:45 +0000 | [diff] [blame] | 696 | if (VG_(clo_xml)) |
sewardj | 8665d8e | 2005-06-01 17:35:23 +0000 | [diff] [blame] | 697 | VG_(message)(Vg_DebugMsg, "</suppcounts>"); |
sewardj | 7c9e57c | 2005-05-24 14:21:45 +0000 | [diff] [blame] | 698 | |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 699 | return any_supp; |
| 700 | } |
| 701 | |
| 702 | |
sewardj | 9f297ca | 2005-05-20 02:29:52 +0000 | [diff] [blame] | 703 | /* Show all the errors that occurred, and possibly also the |
| 704 | suppressions used. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 705 | void VG_(show_all_errors) ( void ) |
| 706 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 707 | Int i, n_min; |
| 708 | Int n_err_contexts, n_supp_contexts; |
| 709 | Error *p, *p_min; |
| 710 | Supp *su; |
| 711 | Bool any_supp; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 712 | |
| 713 | if (VG_(clo_verbosity) == 0) |
| 714 | return; |
| 715 | |
| 716 | n_err_contexts = 0; |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 717 | for (p = errors; p != NULL; p = p->next) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 718 | if (p->supp == NULL) |
| 719 | n_err_contexts++; |
| 720 | } |
| 721 | |
| 722 | n_supp_contexts = 0; |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 723 | for (su = suppressions; su != NULL; su = su->next) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 724 | if (su->count > 0) |
| 725 | n_supp_contexts++; |
| 726 | } |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 727 | |
| 728 | /* If we're printing XML, just show the suppressions and stop. |
| 729 | */ |
| 730 | if (VG_(clo_xml)) { |
| 731 | (void)show_used_suppressions(); |
| 732 | return; |
| 733 | } |
| 734 | |
| 735 | /* We only get here if not printing XML. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 736 | VG_(message)(Vg_UserMsg, |
| 737 | "ERROR SUMMARY: " |
| 738 | "%d errors from %d contexts (suppressed: %d from %d)", |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 739 | n_errs_found, n_err_contexts, |
| 740 | n_errs_suppressed, n_supp_contexts ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 741 | |
| 742 | if (VG_(clo_verbosity) <= 1) |
| 743 | return; |
| 744 | |
| 745 | /* Print the contexts in order of increasing error count. */ |
| 746 | for (i = 0; i < n_err_contexts; i++) { |
| 747 | n_min = (1 << 30) - 1; |
| 748 | p_min = NULL; |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 749 | for (p = errors; p != NULL; p = p->next) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 750 | if (p->supp != NULL) continue; |
| 751 | if (p->count < n_min) { |
| 752 | n_min = p->count; |
| 753 | p_min = p; |
| 754 | } |
| 755 | } |
njn | 6799325 | 2004-11-22 18:02:32 +0000 | [diff] [blame] | 756 | if (p_min == NULL) VG_(tool_panic)("show_all_errors()"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 757 | |
| 758 | VG_(message)(Vg_UserMsg, ""); |
| 759 | VG_(message)(Vg_UserMsg, "%d errors in context %d of %d:", |
| 760 | p_min->count, |
| 761 | i+1, n_err_contexts); |
njn | b0eb66e | 2005-07-10 16:57:24 +0000 | [diff] [blame] | 762 | pp_Error( p_min ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 763 | |
| 764 | if ((i+1 == VG_(clo_dump_error))) { |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 765 | StackTrace ips = VG_(extract_StackTrace)(p_min->where); |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 766 | VG_(translate) ( 0 /* dummy ThreadId; irrelevant due to debugging*/, |
njn | 394213a | 2005-06-19 18:38:24 +0000 | [diff] [blame] | 767 | ips[0], /*debugging*/True, 0xFE/*verbosity*/, |
| 768 | /*bbs_done*/0); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | p_min->count = 1 << 30; |
| 772 | } |
| 773 | |
| 774 | if (n_supp_contexts > 0) |
| 775 | VG_(message)(Vg_DebugMsg, ""); |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 776 | any_supp = show_used_suppressions(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 777 | |
| 778 | if (n_err_contexts > 0) { |
| 779 | if (any_supp) |
| 780 | VG_(message)(Vg_UserMsg, ""); |
| 781 | VG_(message)(Vg_UserMsg, |
| 782 | "IN SUMMARY: " |
| 783 | "%d errors from %d contexts (suppressed: %d from %d)", |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 784 | n_errs_found, n_err_contexts, n_errs_suppressed, |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 785 | n_supp_contexts ); |
| 786 | VG_(message)(Vg_UserMsg, ""); |
| 787 | } |
| 788 | } |
| 789 | |
sewardj | 9f297ca | 2005-05-20 02:29:52 +0000 | [diff] [blame] | 790 | |
| 791 | /* Show occurrence counts of all errors, in XML form. */ |
| 792 | void VG_(show_error_counts_as_XML) ( void ) |
| 793 | { |
| 794 | Error* err; |
| 795 | VG_(message)(Vg_UserMsg, "<errorcounts>"); |
| 796 | for (err = errors; err != NULL; err = err->next) { |
| 797 | if (err->supp != NULL) |
| 798 | continue; |
| 799 | if (err->count <= 0) |
| 800 | continue; |
| 801 | VG_(message)( |
sewardj | 753673f | 2005-08-09 22:03:08 +0000 | [diff] [blame] | 802 | Vg_UserMsg, " <pair>\n" |
| 803 | " <count>%d</count>\n" |
cerion | 3a24e72 | 2005-08-09 22:34:18 +0000 | [diff] [blame] | 804 | " <unique>0x%x</unique>\n" |
sewardj | 753673f | 2005-08-09 22:03:08 +0000 | [diff] [blame] | 805 | " </pair>", |
sewardj | 3961820 | 2005-08-09 21:50:18 +0000 | [diff] [blame] | 806 | err->count, err->unique |
sewardj | 9f297ca | 2005-05-20 02:29:52 +0000 | [diff] [blame] | 807 | ); |
| 808 | } |
| 809 | VG_(message)(Vg_UserMsg, "</errorcounts>"); |
| 810 | } |
| 811 | |
| 812 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 813 | /*------------------------------------------------------------*/ |
| 814 | /*--- Standard suppressions ---*/ |
| 815 | /*------------------------------------------------------------*/ |
| 816 | |
| 817 | /* Get a non-blank, non-comment line of at most nBuf chars from fd. |
| 818 | Skips leading spaces on the line. Return True if EOF was hit instead. |
| 819 | */ |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 820 | Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 821 | { |
| 822 | Char ch; |
| 823 | Int n, i; |
| 824 | while (True) { |
| 825 | /* First, read until a non-blank char appears. */ |
| 826 | while (True) { |
| 827 | n = VG_(read)(fd, &ch, 1); |
njn | 0c0f32a | 2005-03-26 04:14:01 +0000 | [diff] [blame] | 828 | if (n == 1 && !VG_(isspace)(ch)) break; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 829 | if (n == 0) return True; |
| 830 | } |
| 831 | |
| 832 | /* Now, read the line into buf. */ |
| 833 | i = 0; |
| 834 | buf[i++] = ch; buf[i] = 0; |
| 835 | while (True) { |
| 836 | n = VG_(read)(fd, &ch, 1); |
| 837 | if (n == 0) return False; /* the next call will return True */ |
| 838 | if (ch == '\n') break; |
| 839 | if (i > 0 && i == nBuf-1) i--; |
| 840 | buf[i++] = ch; buf[i] = 0; |
| 841 | } |
njn | 0c0f32a | 2005-03-26 04:14:01 +0000 | [diff] [blame] | 842 | while (i > 1 && VG_(isspace)(buf[i-1])) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 843 | i--; buf[i] = 0; |
| 844 | }; |
| 845 | |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 846 | /* VG_(printf)("The line is '%s'\n", buf); */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 847 | /* Ok, we have a line. If a non-comment line, return. |
| 848 | If a comment line, start all over again. */ |
| 849 | if (buf[0] != '#') return False; |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | |
| 854 | /* *p_caller contains the raw name of a caller, supposedly either |
| 855 | fun:some_function_name or |
| 856 | obj:some_object_name. |
| 857 | Set *p_ty accordingly and advance *p_caller over the descriptor |
| 858 | (fun: or obj:) part. |
| 859 | Returns False if failed. |
| 860 | */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 861 | static Bool setLocationTy ( SuppLoc* p ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 862 | { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 863 | if (VG_(strncmp)(p->name, "fun:", 4) == 0) { |
| 864 | p->name += 4; |
| 865 | p->ty = FunName; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 866 | return True; |
| 867 | } |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 868 | if (VG_(strncmp)(p->name, "obj:", 4) == 0) { |
| 869 | p->name += 4; |
| 870 | p->ty = ObjName; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 871 | return True; |
| 872 | } |
| 873 | VG_(printf)("location should start with fun: or obj:\n"); |
| 874 | return False; |
| 875 | } |
| 876 | |
| 877 | |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 878 | /* Look for "tool" in a string like "tool1,tool2,tool3" */ |
njn | 11cc925 | 2002-10-07 14:42:59 +0000 | [diff] [blame] | 879 | static __inline__ |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 880 | Bool tool_name_present(Char *name, Char *names) |
njn | 11cc925 | 2002-10-07 14:42:59 +0000 | [diff] [blame] | 881 | { |
| 882 | Bool found; |
| 883 | Char *s = NULL; /* Shut gcc up */ |
| 884 | Int len = VG_(strlen)(name); |
| 885 | |
| 886 | found = (NULL != (s = VG_(strstr)(names, name)) && |
| 887 | (s == names || *(s-1) == ',') && |
| 888 | (*(s+len) == ',' || *(s+len) == '\0') |
| 889 | ); |
| 890 | |
| 891 | return found; |
| 892 | } |
| 893 | |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 894 | /* Read suppressions from the file specified in VG_(clo_suppressions) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 895 | and place them in the suppressions list. If there's any difficulty |
| 896 | doing this, just give up -- there's no point in trying to recover. |
| 897 | */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 898 | static void load_one_suppressions_file ( Char* filename ) |
| 899 | { |
| 900 | # define N_BUF 200 |
sewardj | 9264559 | 2005-07-23 09:18:34 +0000 | [diff] [blame] | 901 | SysRes sres; |
| 902 | Int fd, i; |
| 903 | Bool eof; |
| 904 | Char buf[N_BUF+1]; |
| 905 | Char* tool_names; |
| 906 | Char* supp_name; |
| 907 | Char* err_str = NULL; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 908 | SuppLoc tmp_callers[VG_MAX_SUPP_CALLERS]; |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 909 | |
sewardj | 9264559 | 2005-07-23 09:18:34 +0000 | [diff] [blame] | 910 | fd = -1; |
| 911 | sres = VG_(open)( filename, VKI_O_RDONLY, 0 ); |
| 912 | if (sres.isError) { |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 913 | VG_(message)(Vg_UserMsg, "FATAL: can't open suppressions file '%s'", |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 914 | filename ); |
| 915 | VG_(exit)(1); |
| 916 | } |
sewardj | 9264559 | 2005-07-23 09:18:34 +0000 | [diff] [blame] | 917 | fd = sres.val; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 918 | |
sewardj | 9264559 | 2005-07-23 09:18:34 +0000 | [diff] [blame] | 919 | # define BOMB(S) { err_str = S; goto syntax_error; } |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 920 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 921 | while (True) { |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 922 | /* Assign and initialise the two suppression halves (core and tool) */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 923 | Supp* supp; |
| 924 | supp = VG_(arena_malloc)(VG_AR_CORE, sizeof(Supp)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 925 | supp->count = 0; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 926 | |
| 927 | // Initialise temporary reading-in buffer. |
| 928 | for (i = 0; i < VG_MAX_SUPP_CALLERS; i++) { |
| 929 | tmp_callers[i].ty = NoName; |
| 930 | tmp_callers[i].name = NULL; |
| 931 | } |
| 932 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 933 | supp->string = supp->extra = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 934 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 935 | eof = VG_(get_line) ( fd, buf, N_BUF ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 936 | if (eof) break; |
| 937 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 938 | if (!VG_STREQ(buf, "{")) BOMB("expected '{' or end-of-file"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 939 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 940 | eof = VG_(get_line) ( fd, buf, N_BUF ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 941 | |
| 942 | if (eof || VG_STREQ(buf, "}")) BOMB("unexpected '}'"); |
| 943 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 944 | supp->sname = VG_(arena_strdup)(VG_AR_CORE, buf); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 945 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 946 | eof = VG_(get_line) ( fd, buf, N_BUF ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 947 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 948 | if (eof) BOMB("unexpected end-of-file"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 949 | |
njn | 94065fd | 2004-11-22 19:26:27 +0000 | [diff] [blame] | 950 | /* Check it has the "tool1,tool2,...:supp" form (look for ':') */ |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 951 | i = 0; |
| 952 | while (True) { |
| 953 | if (buf[i] == ':') break; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 954 | if (buf[i] == '\0') BOMB("malformed 'tool1,tool2,...:supp' line"); |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 955 | i++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 956 | } |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 957 | buf[i] = '\0'; /* Replace ':', splitting into two strings */ |
| 958 | |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 959 | tool_names = & buf[0]; |
njn | 11cc925 | 2002-10-07 14:42:59 +0000 | [diff] [blame] | 960 | supp_name = & buf[i+1]; |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 961 | |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 962 | if (VG_(needs).core_errors && tool_name_present("core", tool_names)) |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 963 | { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 964 | // A core suppression |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 965 | if (VG_STREQ(supp_name, "PThread")) |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 966 | supp->skind = PThreadSupp; |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 967 | else |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 968 | BOMB("unknown core suppression type"); |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 969 | } |
njn | 95ec870 | 2004-11-22 16:46:13 +0000 | [diff] [blame] | 970 | else if (VG_(needs).tool_errors && |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 971 | tool_name_present(VG_(details).name, tool_names)) |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 972 | { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 973 | // A tool suppression |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 974 | if (VG_TDICT_CALL(tool_recognised_suppression, supp_name, supp)) { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 975 | /* Do nothing, function fills in supp->skind */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 976 | } else { |
| 977 | BOMB("unknown tool suppression type"); |
| 978 | } |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 979 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 980 | else { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 981 | // Ignore rest of suppression |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 982 | while (True) { |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 983 | eof = VG_(get_line) ( fd, buf, N_BUF ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 984 | if (eof) BOMB("unexpected end-of-file"); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 985 | if (VG_STREQ(buf, "}")) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 986 | break; |
| 987 | } |
| 988 | continue; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 989 | } |
| 990 | |
njn | 95ec870 | 2004-11-22 16:46:13 +0000 | [diff] [blame] | 991 | if (VG_(needs).tool_errors && |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 992 | !VG_TDICT_CALL(tool_read_extra_suppression_info, fd, buf, N_BUF, supp)) |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 993 | { |
| 994 | BOMB("bad or missing extra suppression info"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 995 | } |
| 996 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 997 | i = 0; |
| 998 | while (True) { |
| 999 | eof = VG_(get_line) ( fd, buf, N_BUF ); |
| 1000 | if (eof) |
| 1001 | BOMB("unexpected end-of-file"); |
| 1002 | if (VG_STREQ(buf, "}")) { |
| 1003 | if (i > 0) { |
| 1004 | break; |
| 1005 | } else { |
| 1006 | BOMB("missing stack trace"); |
| 1007 | } |
| 1008 | } |
| 1009 | if (i == VG_MAX_SUPP_CALLERS) |
| 1010 | BOMB("too many callers in stack trace"); |
| 1011 | if (i > 0 && i >= VG_(clo_backtrace_size)) |
| 1012 | break; |
| 1013 | tmp_callers[i].name = VG_(arena_strdup)(VG_AR_CORE, buf); |
| 1014 | if (!setLocationTy(&(tmp_callers[i]))) |
| 1015 | BOMB("location should start with 'fun:' or 'obj:'"); |
| 1016 | i++; |
| 1017 | } |
| 1018 | |
| 1019 | // If the num callers is >= VG_(clo_backtrace_size), ignore any extra |
| 1020 | // lines and grab the '}'. |
sewardj | 57a8f5f | 2003-07-06 01:40:11 +0000 | [diff] [blame] | 1021 | if (!VG_STREQ(buf, "}")) { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1022 | do { |
| 1023 | eof = VG_(get_line) ( fd, buf, N_BUF ); |
| 1024 | } while (!eof && !VG_STREQ(buf, "}")); |
| 1025 | } |
| 1026 | |
| 1027 | // Copy tmp_callers[] into supp->callers[] |
| 1028 | supp->n_callers = i; |
| 1029 | supp->callers = VG_(arena_malloc)(VG_AR_CORE, i*sizeof(SuppLoc)); |
| 1030 | for (i = 0; i < supp->n_callers; i++) { |
| 1031 | supp->callers[i] = tmp_callers[i]; |
sewardj | 57a8f5f | 2003-07-06 01:40:11 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 1034 | supp->next = suppressions; |
| 1035 | suppressions = supp; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1036 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1037 | VG_(close)(fd); |
| 1038 | return; |
| 1039 | |
| 1040 | syntax_error: |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1041 | VG_(message)(Vg_UserMsg, |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 1042 | "FATAL: in suppressions file '%s': %s", filename, err_str ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1043 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1044 | VG_(close)(fd); |
| 1045 | VG_(message)(Vg_UserMsg, "exiting now."); |
nethercote | 8ed8a89 | 2004-11-08 13:24:25 +0000 | [diff] [blame] | 1046 | VG_(exit)(1); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1047 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1048 | # undef BOMB |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1049 | # undef N_BUF |
| 1050 | } |
| 1051 | |
| 1052 | |
| 1053 | void VG_(load_suppressions) ( void ) |
| 1054 | { |
| 1055 | Int i; |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 1056 | suppressions = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1057 | for (i = 0; i < VG_(clo_n_suppressions); i++) { |
| 1058 | if (VG_(clo_verbosity) > 1) { |
njn | 3f04d24 | 2005-03-20 18:21:14 +0000 | [diff] [blame] | 1059 | VG_(message)(Vg_DebugMsg, "Reading suppressions file: %s", |
| 1060 | VG_(clo_suppressions)[i] ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1061 | } |
| 1062 | load_one_suppressions_file( VG_(clo_suppressions)[i] ); |
| 1063 | } |
| 1064 | } |
| 1065 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1066 | static |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1067 | Bool supp_matches_error(Supp* su, Error* err) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1068 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1069 | switch (su->skind) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1070 | case PThreadSupp: |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1071 | return (err->ekind == ThreadErr || err->ekind == MutexErr); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1072 | default: |
njn | 95ec870 | 2004-11-22 16:46:13 +0000 | [diff] [blame] | 1073 | if (VG_(needs).tool_errors) { |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1074 | return VG_TDICT_CALL(tool_error_matches_suppression, err, su); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1075 | } else { |
| 1076 | VG_(printf)( |
njn | 95ec870 | 2004-11-22 16:46:13 +0000 | [diff] [blame] | 1077 | "\nUnhandled suppression type: %u. VG_(needs).tool_errors\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1078 | "probably needs to be set.\n", |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1079 | err->ekind); |
njn | 6799325 | 2004-11-22 18:02:32 +0000 | [diff] [blame] | 1080 | VG_(tool_panic)("unhandled suppression type"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1081 | } |
| 1082 | } |
| 1083 | } |
| 1084 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1085 | static |
| 1086 | Bool supp_matches_callers(Error* err, Supp* su) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1087 | { |
| 1088 | Int i; |
njn | 83f9e79 | 2005-06-11 05:04:09 +0000 | [diff] [blame] | 1089 | Char caller_name[ERRTXT_LEN]; |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 1090 | StackTrace ips = VG_(extract_StackTrace)(err->where); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1091 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1092 | for (i = 0; i < su->n_callers; i++) { |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 1093 | Addr a = ips[i]; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1094 | vg_assert(su->callers[i].name != NULL); |
njn | 966d663 | 2005-08-18 15:49:21 +0000 | [diff] [blame^] | 1095 | // The string to be used in the unknown case ("???") can be anything |
| 1096 | // that couldn't be a valid function or objname. --gen-suppressions |
| 1097 | // prints 'obj:*' for such an entry, which will match any string we |
| 1098 | // use. |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1099 | switch (su->callers[i].ty) { |
| 1100 | case ObjName: |
njn | 83f9e79 | 2005-06-11 05:04:09 +0000 | [diff] [blame] | 1101 | if (!VG_(get_objname)(a, caller_name, ERRTXT_LEN)) |
njn | 966d663 | 2005-08-18 15:49:21 +0000 | [diff] [blame^] | 1102 | VG_(strcpy)(caller_name, "???"); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1103 | break; |
| 1104 | |
| 1105 | case FunName: |
| 1106 | // Nb: mangled names used in suppressions |
njn | 83f9e79 | 2005-06-11 05:04:09 +0000 | [diff] [blame] | 1107 | if (!VG_(get_fnname_nodemangle)(a, caller_name, ERRTXT_LEN)) |
njn | 966d663 | 2005-08-18 15:49:21 +0000 | [diff] [blame^] | 1108 | VG_(strcpy)(caller_name, "???"); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1109 | break; |
njn | 6799325 | 2004-11-22 18:02:32 +0000 | [diff] [blame] | 1110 | default: VG_(tool_panic)("supp_matches_callers"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1111 | } |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1112 | if (!VG_(string_match)(su->callers[i].name, caller_name)) |
| 1113 | return False; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | /* If we reach here, it's a match */ |
| 1117 | return True; |
| 1118 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1119 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1120 | /* Does an error context match a suppression? ie is this a suppressible |
| 1121 | error? If so, return a pointer to the Supp record, otherwise NULL. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1122 | Tries to minimise the number of symbol searches since they are expensive. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1123 | */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1124 | static Supp* is_suppressible_error ( Error* err ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1125 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1126 | Supp* 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 | /* See if the error context matches any suppression. */ |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 1129 | for (su = suppressions; su != NULL; su = su->next) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1130 | if (supp_matches_error(su, err) && |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1131 | supp_matches_callers(err, su)) |
| 1132 | { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1133 | return su; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1134 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1135 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1136 | return NULL; /* no matches */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1139 | /*--------------------------------------------------------------------*/ |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 1140 | /*--- end ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1141 | /*--------------------------------------------------------------------*/ |