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