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 | 0f157dd | 2013-10-18 14:27:36 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2013 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" |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 33 | #include "pub_core_libcsetjmp.h" |
njn | 24a6efb | 2005-06-20 03:36:51 +0000 | [diff] [blame] | 34 | #include "pub_core_threadstate.h" // For VG_N_THREADS |
njn | 75b65aa | 2005-06-19 19:25:44 +0000 | [diff] [blame] | 35 | #include "pub_core_debugger.h" |
njn | ea27e46 | 2005-05-31 02:38:09 +0000 | [diff] [blame] | 36 | #include "pub_core_debuginfo.h" |
philippe | 5ab7ce8 | 2014-06-24 20:48:25 +0000 | [diff] [blame] | 37 | #include "pub_core_debuglog.h" |
njn | d2b1711 | 2005-04-19 04:10:25 +0000 | [diff] [blame] | 38 | #include "pub_core_errormgr.h" |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 39 | #include "pub_core_execontext.h" |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 40 | #include "pub_core_gdbserver.h" |
njn | 97405b2 | 2005-06-02 03:39:33 +0000 | [diff] [blame] | 41 | #include "pub_core_libcbase.h" |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 42 | #include "pub_core_libcassert.h" |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 43 | #include "pub_core_libcfile.h" |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 44 | #include "pub_core_libcprint.h" |
njn | 24a6efb | 2005-06-20 03:36:51 +0000 | [diff] [blame] | 45 | #include "pub_core_libcproc.h" // For VG_(getpid)() |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 46 | #include "pub_core_seqmatch.h" |
njn | af1d7df | 2005-06-11 01:31:52 +0000 | [diff] [blame] | 47 | #include "pub_core_mallocfree.h" |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 48 | #include "pub_core_options.h" |
njn | d0d7c1f | 2005-06-21 00:33:19 +0000 | [diff] [blame] | 49 | #include "pub_core_stacktrace.h" |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 50 | #include "pub_core_tooliface.h" |
njn | 24a6efb | 2005-06-20 03:36:51 +0000 | [diff] [blame] | 51 | #include "pub_core_translate.h" // for VG_(translate)() |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 52 | #include "pub_core_xarray.h" // VG_(xaprintf) et al |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 53 | |
philippe | 5ab7ce8 | 2014-06-24 20:48:25 +0000 | [diff] [blame] | 54 | #define DEBUG_ERRORMGR 0 // set to 1 for heavyweight tracing |
| 55 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 56 | /*------------------------------------------------------------*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 57 | /*--- Globals ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 58 | /*------------------------------------------------------------*/ |
| 59 | |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 60 | /* After this many different unsuppressed errors have been observed, |
| 61 | be more conservative about collecting new ones. */ |
sewardj | 1d1a226 | 2005-10-20 01:57:29 +0000 | [diff] [blame] | 62 | #define M_COLLECT_ERRORS_SLOWLY_AFTER 100 |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 63 | |
| 64 | /* After this many different unsuppressed errors have been observed, |
| 65 | stop collecting errors at all, and tell the user their program is |
| 66 | evidently a steaming pile of camel dung. */ |
sewardj | 1d1a226 | 2005-10-20 01:57:29 +0000 | [diff] [blame] | 67 | #define M_COLLECT_NO_ERRORS_AFTER_SHOWN 1000 |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 68 | |
| 69 | /* After this many total errors have been observed, stop collecting |
| 70 | errors at all. Counterpart to M_COLLECT_NO_ERRORS_AFTER_SHOWN. */ |
sewardj | 513646f | 2006-05-12 23:12:30 +0000 | [diff] [blame] | 71 | #define M_COLLECT_NO_ERRORS_AFTER_FOUND 10000000 |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 72 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 73 | /* The list of error contexts found, both suppressed and unsuppressed. |
| 74 | Initially empty, and grows as errors are detected. */ |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 75 | static Error* errors = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 76 | |
| 77 | /* The list of suppression directives, as read from the specified |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 78 | suppressions file. Note that the list gets rearranged as a result |
| 79 | of the searches done by is_suppressible_error(). */ |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 80 | static Supp* suppressions = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 81 | |
| 82 | /* Running count of unsuppressed errors detected. */ |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 83 | static UInt n_errs_found = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 84 | |
| 85 | /* Running count of suppressed errors detected. */ |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 86 | static UInt n_errs_suppressed = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 87 | |
philippe | baf6964 | 2012-02-15 22:29:30 +0000 | [diff] [blame] | 88 | /* Running count of errors shown. */ |
| 89 | static UInt n_errs_shown = 0; |
| 90 | |
njn | 606a4ae | 2009-08-11 00:52:40 +0000 | [diff] [blame] | 91 | /* Running count of unsuppressed error contexts. */ |
| 92 | static UInt n_err_contexts = 0; |
| 93 | |
| 94 | /* Running count of suppressed error contexts. */ |
| 95 | static UInt n_supp_contexts = 0; |
| 96 | |
| 97 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 98 | /* forwards ... */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 99 | static Supp* is_suppressible_error ( Error* err ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 100 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 101 | static ThreadId last_tid_printed = 1; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 102 | |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 103 | /* Stats: number of searches of the error list initiated. */ |
| 104 | static UWord em_errlist_searches = 0; |
| 105 | |
| 106 | /* Stats: number of comparisons done during error list |
| 107 | searching. */ |
| 108 | static UWord em_errlist_cmps = 0; |
| 109 | |
| 110 | /* Stats: number of searches of the suppression list initiated. */ |
| 111 | static UWord em_supplist_searches = 0; |
| 112 | |
| 113 | /* Stats: number of comparisons done during suppression list |
| 114 | searching. */ |
| 115 | static UWord em_supplist_cmps = 0; |
| 116 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 117 | /*------------------------------------------------------------*/ |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 118 | /*--- Error type ---*/ |
| 119 | /*------------------------------------------------------------*/ |
| 120 | |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 121 | /* Errors. Extensible (via the 'extra' field). Tools can use a normal |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 122 | enum (with element values in the normal range (0..)) for 'ekind'. |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 123 | Functions for getting/setting the tool-relevant fields are in |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 124 | include/pub_tool_errormgr.h. |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 125 | |
| 126 | When errors are found and recorded with VG_(maybe_record_error)(), all |
| 127 | the tool must do is pass in the four parameters; core will |
| 128 | allocate/initialise the error record. |
| 129 | */ |
| 130 | struct _Error { |
| 131 | struct _Error* next; |
sewardj | dbada27 | 2005-07-02 21:16:30 +0000 | [diff] [blame] | 132 | // Unique tag. This gives the error a unique identity (handle) by |
| 133 | // which it can be referred to afterwords. Currently only used for |
| 134 | // XML printing. |
| 135 | UInt unique; |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 136 | // NULL if unsuppressed; or ptr to suppression record. |
| 137 | Supp* supp; |
| 138 | Int count; |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 139 | |
| 140 | // The tool-specific part |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 141 | ThreadId tid; // Initialised by core |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 142 | ExeContext* where; // Initialised by core |
njn | d2b1711 | 2005-04-19 04:10:25 +0000 | [diff] [blame] | 143 | ErrorKind ekind; // Used by ALL. Must be in the range (0..) |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 144 | Addr addr; // Used frequently |
florian | e543f30 | 2012-10-21 19:43:43 +0000 | [diff] [blame] | 145 | const HChar* string; // Used frequently |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 146 | void* extra; // For any tool-specific extras |
| 147 | }; |
| 148 | |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 149 | |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 150 | ExeContext* VG_(get_error_where) ( Error* err ) |
| 151 | { |
| 152 | return err->where; |
| 153 | } |
| 154 | |
| 155 | ErrorKind VG_(get_error_kind) ( Error* err ) |
| 156 | { |
| 157 | return err->ekind; |
| 158 | } |
| 159 | |
| 160 | Addr VG_(get_error_address) ( Error* err ) |
| 161 | { |
| 162 | return err->addr; |
| 163 | } |
| 164 | |
florian | e543f30 | 2012-10-21 19:43:43 +0000 | [diff] [blame] | 165 | const HChar* VG_(get_error_string) ( Error* err ) |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 166 | { |
| 167 | return err->string; |
| 168 | } |
| 169 | |
| 170 | void* VG_(get_error_extra) ( Error* err ) |
| 171 | { |
| 172 | return err->extra; |
| 173 | } |
| 174 | |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 175 | UInt VG_(get_n_errs_found)( void ) |
| 176 | { |
| 177 | return n_errs_found; |
| 178 | } |
| 179 | |
philippe | baf6964 | 2012-02-15 22:29:30 +0000 | [diff] [blame] | 180 | UInt VG_(get_n_errs_shown)( void ) |
| 181 | { |
| 182 | return n_errs_shown; |
| 183 | } |
| 184 | |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 185 | /*------------------------------------------------------------*/ |
| 186 | /*--- Suppression type ---*/ |
| 187 | /*------------------------------------------------------------*/ |
| 188 | |
| 189 | /* Note: it is imperative this doesn't overlap with (0..) at all, as tools |
| 190 | * effectively extend it by defining their own enums in the (0..) range. */ |
| 191 | typedef |
| 192 | enum { |
njn | a86f29e | 2006-12-14 02:55:58 +0000 | [diff] [blame] | 193 | // Nb: thread errors are a relic of the time when Valgrind's core |
| 194 | // could detect them. This example is left commented-out as an |
| 195 | // example should new core errors ever be added. |
| 196 | ThreadSupp = -1, /* Matches ThreadErr */ |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 197 | } |
| 198 | CoreSuppKind; |
| 199 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 200 | /* Max number of callers for context in a suppression. */ |
| 201 | #define VG_MAX_SUPP_CALLERS 24 |
| 202 | |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 203 | /* For each caller specified for a suppression, record the nature of |
| 204 | the caller name. Not of interest to tools. */ |
| 205 | typedef |
| 206 | enum { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 207 | NoName, /* Error case */ |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 208 | ObjName, /* Name is of an shared object file. */ |
sewardj | 5e51930 | 2008-11-03 23:10:25 +0000 | [diff] [blame] | 209 | FunName, /* Name is of a function. */ |
| 210 | DotDotDot /* Frame-level wildcard */ |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 211 | } |
| 212 | SuppLocTy; |
| 213 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 214 | typedef |
| 215 | struct { |
| 216 | SuppLocTy ty; |
philippe | 2c5c05e | 2012-07-26 21:37:36 +0000 | [diff] [blame] | 217 | Bool name_is_simple_str; /* True if name is a string without |
| 218 | '?' and '*' wildcard characters. */ |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 219 | HChar* name; /* NULL for NoName and DotDotDot */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 220 | } |
| 221 | SuppLoc; |
| 222 | |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 223 | /* Suppressions. Tools can get/set tool-relevant parts with functions |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 224 | declared in include/pub_tool_errormgr.h. Extensible via the 'extra' field. |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 225 | Tools can use a normal enum (with element values in the normal range |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 226 | (0..)) for 'skind'. */ |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 227 | struct _Supp { |
| 228 | struct _Supp* next; |
| 229 | Int count; // The number of times this error has been suppressed. |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 230 | HChar* sname; // The name by which the suppression is referred to. |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 231 | |
philippe | 362441d | 2013-07-22 22:00:13 +0000 | [diff] [blame] | 232 | // Index in VG_(clo_suppressions) giving filename from which suppression |
| 233 | // was read, and the lineno in this file where sname was read. |
| 234 | Int clo_suppressions_i; |
| 235 | Int sname_lineno; |
| 236 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 237 | // Length of 'callers' |
| 238 | Int n_callers; |
| 239 | // Array of callers, for matching stack traces. First one (name of fn |
| 240 | // where err occurs) is mandatory; rest are optional. |
| 241 | SuppLoc* callers; |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 242 | |
| 243 | /* The tool-specific part */ |
| 244 | SuppKind skind; // What kind of suppression. Must use the range (0..). |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 245 | HChar* string; // String -- use is optional. NULL by default. |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 246 | void* extra; // Anything else -- use is optional. NULL by default. |
| 247 | }; |
| 248 | |
| 249 | SuppKind VG_(get_supp_kind) ( Supp* su ) |
| 250 | { |
| 251 | return su->skind; |
| 252 | } |
| 253 | |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 254 | HChar* VG_(get_supp_string) ( Supp* su ) |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 255 | { |
| 256 | return su->string; |
| 257 | } |
| 258 | |
| 259 | void* VG_(get_supp_extra) ( Supp* su ) |
| 260 | { |
| 261 | return su->extra; |
| 262 | } |
| 263 | |
| 264 | |
| 265 | void VG_(set_supp_kind) ( Supp* su, SuppKind skind ) |
| 266 | { |
| 267 | su->skind = skind; |
| 268 | } |
| 269 | |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 270 | void VG_(set_supp_string) ( Supp* su, HChar* string ) |
nethercote | 4a18490 | 2004-08-02 12:21:09 +0000 | [diff] [blame] | 271 | { |
| 272 | su->string = string; |
| 273 | } |
| 274 | |
| 275 | void VG_(set_supp_extra) ( Supp* su, void* extra ) |
| 276 | { |
| 277 | su->extra = extra; |
| 278 | } |
| 279 | |
| 280 | |
| 281 | /*------------------------------------------------------------*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 282 | /*--- Helper fns ---*/ |
| 283 | /*------------------------------------------------------------*/ |
| 284 | |
njn | 0087c50 | 2005-07-01 04:15:36 +0000 | [diff] [blame] | 285 | // Only show core errors if the tool wants to, we're not running with -q, |
| 286 | // and were not outputting XML. |
| 287 | Bool VG_(showing_core_errors)(void) |
| 288 | { |
| 289 | return VG_(needs).core_errors && VG_(clo_verbosity) >= 1 && !VG_(clo_xml); |
| 290 | } |
| 291 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 292 | /* Compare errors, to detect duplicates. |
| 293 | */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 294 | static Bool eq_Error ( VgRes res, Error* e1, Error* e2 ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 295 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 296 | if (e1->ekind != e2->ekind) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 297 | return False; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 298 | if (!VG_(eq_ExeContext)(res, e1->where, e2->where)) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 299 | return False; |
| 300 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 301 | switch (e1->ekind) { |
njn | a86f29e | 2006-12-14 02:55:58 +0000 | [diff] [blame] | 302 | //(example code, see comment on CoreSuppKind above) |
| 303 | //case ThreadErr: |
| 304 | // vg_assert(VG_(needs).core_errors); |
| 305 | // return <something> |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 306 | default: |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 307 | if (VG_(needs).tool_errors) { |
| 308 | return VG_TDICT_CALL(tool_eq_Error, res, e1, e2); |
| 309 | } else { |
njn | 95ec870 | 2004-11-22 16:46:13 +0000 | [diff] [blame] | 310 | VG_(printf)("\nUnhandled error type: %u. VG_(needs).tool_errors\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 311 | "probably needs to be set.\n", |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 312 | e1->ekind); |
njn | 6799325 | 2004-11-22 18:02:32 +0000 | [diff] [blame] | 313 | VG_(tool_panic)("unhandled error type"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 314 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 318 | |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 319 | /* Helper functions for suppression generation: print a single line of |
| 320 | a suppression pseudo-stack-trace, either in XML or text mode. It's |
| 321 | important that the behaviour of these two functions exactly |
| 322 | corresponds. |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 323 | */ |
| 324 | #define ERRTXT_LEN 4096 |
| 325 | |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 326 | static void printSuppForIp_XML(UInt n, Addr ip, void* uu_opaque) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 327 | { |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 328 | static HChar buf[ERRTXT_LEN]; |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 329 | InlIPCursor* iipc = VG_(new_IIPC)(ip); |
| 330 | do { |
| 331 | if ( VG_(get_fnname_no_cxx_demangle) (ip, buf, ERRTXT_LEN, iipc) ) { |
| 332 | VG_(printf_xml)(" <sframe> <fun>%pS</fun> </sframe>\n", buf); |
| 333 | } else |
| 334 | if ( VG_(get_objname)(ip, buf, ERRTXT_LEN) ) { |
| 335 | VG_(printf_xml)(" <sframe> <obj>%pS</obj> </sframe>\n", buf); |
| 336 | } else { |
| 337 | VG_(printf_xml)(" <sframe> <obj>*</obj> </sframe>\n"); |
| 338 | } |
| 339 | } while (VG_(next_IIPC)(iipc)); |
| 340 | VG_(delete_IIPC)(iipc); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 341 | } |
| 342 | |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 343 | static void printSuppForIp_nonXML(UInt n, Addr ip, void* textV) |
| 344 | { |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 345 | static HChar buf[ERRTXT_LEN]; |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 346 | XArray* /* of HChar */ text = (XArray*)textV; |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 347 | InlIPCursor* iipc = VG_(new_IIPC)(ip); |
| 348 | do { |
| 349 | if ( VG_(get_fnname_no_cxx_demangle) (ip, buf, ERRTXT_LEN, iipc) ) { |
| 350 | VG_(xaprintf)(text, " fun:%s\n", buf); |
| 351 | } else |
| 352 | if ( VG_(get_objname)(ip, buf, ERRTXT_LEN) ) { |
| 353 | VG_(xaprintf)(text, " obj:%s\n", buf); |
| 354 | } else { |
| 355 | VG_(xaprintf)(text, " obj:*\n"); |
| 356 | } |
| 357 | } while (VG_(next_IIPC)(iipc)); |
| 358 | VG_(delete_IIPC)(iipc); |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 359 | } |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 360 | |
| 361 | /* Generate a suppression for an error, either in text or XML mode. |
| 362 | */ |
| 363 | static void gen_suppression(Error* err) |
| 364 | { |
florian | 54fe202 | 2012-10-27 23:07:42 +0000 | [diff] [blame] | 365 | HChar xtra[256]; /* assumed big enough (is overrun-safe) */ |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 366 | Bool anyXtra; |
florian | dbb3584 | 2012-10-27 18:39:11 +0000 | [diff] [blame] | 367 | const HChar* name; |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 368 | ExeContext* ec; |
| 369 | XArray* /* HChar */ text; |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 370 | |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 371 | const HChar* dummy_name = "insert_a_suppression_name_here"; |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 372 | |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 373 | vg_assert(err); |
| 374 | |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 375 | ec = VG_(get_error_where)(err); |
| 376 | vg_assert(ec); |
| 377 | |
| 378 | name = VG_TDICT_CALL(tool_get_error_name, err); |
| 379 | if (NULL == name) { |
| 380 | VG_(umsg)("(%s does not allow error to be suppressed)\n", |
| 381 | VG_(details).name); |
| 382 | return; |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 383 | } |
| 384 | |
tom | 7420e0a | 2011-07-06 14:08:24 +0000 | [diff] [blame] | 385 | /* In XML mode, we also need to print the plain text version of the |
| 386 | suppresion in a CDATA section. What that really means is, we |
| 387 | need to generate the plaintext version both in XML and text |
| 388 | mode. So generate it into TEXT. */ |
| 389 | text = VG_(newXA)( VG_(malloc), "errormgr.gen_suppression.1", |
| 390 | VG_(free), sizeof(HChar) ); |
| 391 | vg_assert(text); |
| 392 | |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 393 | /* Ok. Generate the plain text version into TEXT. */ |
| 394 | VG_(xaprintf)(text, "{\n"); |
| 395 | VG_(xaprintf)(text, " <%s>\n", dummy_name); |
| 396 | VG_(xaprintf)(text, " %s:%s\n", VG_(details).name, name); |
| 397 | |
| 398 | VG_(memset)(xtra, 0, sizeof(xtra)); |
| 399 | anyXtra = VG_TDICT_CALL(tool_get_extra_suppression_info, |
| 400 | err, xtra, sizeof(xtra)); |
| 401 | vg_assert(xtra[sizeof(xtra)-1] == 0); |
| 402 | |
| 403 | if (anyXtra) |
| 404 | VG_(xaprintf)(text, " %s\n", xtra); |
| 405 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 406 | // Print stack trace elements |
sewardj | 2f340eb | 2011-01-28 00:44:52 +0000 | [diff] [blame] | 407 | UInt n_ips = VG_(get_ExeContext_n_ips)(ec); |
| 408 | tl_assert(n_ips > 0); |
| 409 | if (n_ips > VG_MAX_SUPP_CALLERS) |
| 410 | n_ips = VG_MAX_SUPP_CALLERS; |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 411 | VG_(apply_StackTrace)(printSuppForIp_nonXML, |
| 412 | text, |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 413 | VG_(get_ExeContext_StackTrace)(ec), |
sewardj | 2f340eb | 2011-01-28 00:44:52 +0000 | [diff] [blame] | 414 | n_ips); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 415 | |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 416 | VG_(xaprintf)(text, "}\n"); |
| 417 | // zero terminate |
| 418 | VG_(xaprintf)(text, "%c", (HChar)0 ); |
| 419 | // VG_(printf) of text |
| 420 | |
| 421 | /* And now display it. */ |
| 422 | if (! VG_(clo_xml) ) { |
| 423 | |
| 424 | // the simple case |
| 425 | VG_(printf)("%s", (HChar*) VG_(indexXA)(text, 0) ); |
| 426 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 427 | } else { |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 428 | |
| 429 | /* Now we have to print the XML directly. No need to go to the |
| 430 | effort of stuffing it in an XArray, since we won't need it |
| 431 | again. */ |
| 432 | VG_(printf_xml)(" <suppression>\n"); |
| 433 | VG_(printf_xml)(" <sname>%s</sname>\n", dummy_name); |
bart | b3af9cf | 2011-10-06 19:08:37 +0000 | [diff] [blame] | 434 | VG_(printf_xml)( |
| 435 | " <skind>%pS:%pS</skind>\n", VG_(details).name, name); |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 436 | if (anyXtra) |
bart | b3af9cf | 2011-10-06 19:08:37 +0000 | [diff] [blame] | 437 | VG_(printf_xml)(" <skaux>%pS</skaux>\n", xtra); |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 438 | |
| 439 | // Print stack trace elements |
| 440 | VG_(apply_StackTrace)(printSuppForIp_XML, |
| 441 | NULL, |
| 442 | VG_(get_ExeContext_StackTrace)(ec), |
| 443 | VG_(get_ExeContext_n_ips)(ec)); |
| 444 | |
| 445 | // And now the cdata bit |
| 446 | // XXX FIXME! properly handle the case where the raw text |
| 447 | // itself contains "]]>", as specified in Protocol 4. |
| 448 | VG_(printf_xml)(" <rawtext>\n"); |
| 449 | VG_(printf_xml)("<![CDATA[\n"); |
sewardj | de78f9a | 2009-08-15 23:33:04 +0000 | [diff] [blame] | 450 | VG_(printf_xml)("%s", (HChar*) VG_(indexXA)(text, 0) ); |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 451 | VG_(printf_xml)("]]>\n"); |
| 452 | VG_(printf_xml)(" </rawtext>\n"); |
| 453 | VG_(printf_xml)(" </suppression>\n"); |
| 454 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 455 | } |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 456 | |
| 457 | VG_(deleteXA)(text); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | |
| 461 | /* Figure out if we want to perform a given action for this error, |
| 462 | possibly by asking the user. |
| 463 | */ |
florian | 2b8059a | 2012-10-14 16:45:23 +0000 | [diff] [blame] | 464 | Bool VG_(is_action_requested) ( const HChar* action, Bool* clo ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 465 | { |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 466 | HChar ch, ch2; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 467 | Int res; |
| 468 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 469 | /* First off, we shouldn't be asking the user anything if |
| 470 | we're in XML mode. */ |
| 471 | if (VG_(clo_xml)) |
| 472 | return False; /* That's a Nein, oder Nay as they say down here in B-W */ |
| 473 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 474 | if (*clo == False) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 475 | return False; |
| 476 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 477 | VG_(umsg)("\n"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 478 | |
| 479 | again: |
| 480 | VG_(printf)( |
| 481 | "==%d== " |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 482 | "---- %s ? --- [Return/N/n/Y/y/C/c] ---- ", |
| 483 | VG_(getpid)(), action |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 484 | ); |
| 485 | |
sewardj | 6024b21 | 2003-07-13 10:54:33 +0000 | [diff] [blame] | 486 | res = VG_(read)(VG_(clo_input_fd), &ch, 1); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 487 | if (res != 1) goto ioerror; |
| 488 | /* res == 1 */ |
| 489 | if (ch == '\n') return False; |
| 490 | if (ch != 'N' && ch != 'n' && ch != 'Y' && ch != 'y' |
| 491 | && ch != 'C' && ch != 'c') goto again; |
| 492 | |
sewardj | 6024b21 | 2003-07-13 10:54:33 +0000 | [diff] [blame] | 493 | res = VG_(read)(VG_(clo_input_fd), &ch2, 1); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 494 | if (res != 1) goto ioerror; |
| 495 | if (ch2 != '\n') goto again; |
| 496 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 497 | /* No, don't want to do action. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 498 | if (ch == 'n' || ch == 'N') return False; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 499 | /* Yes, want to do action. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 500 | if (ch == 'y' || ch == 'Y') return True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 501 | /* No, don't want to do action, and don't ask again either. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 502 | vg_assert(ch == 'c' || ch == 'C'); |
| 503 | |
| 504 | ioerror: |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 505 | *clo = False; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 506 | return False; |
| 507 | } |
| 508 | |
| 509 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 510 | /* Do text-mode actions on error, that is, immediately after an error |
| 511 | is printed. These are: |
| 512 | * possibly, attach to a debugger |
| 513 | * possibly, generate a suppression. |
| 514 | Note this should not be called in XML mode! |
| 515 | */ |
| 516 | static |
| 517 | void do_actions_on_error(Error* err, Bool allow_db_attach) |
| 518 | { |
| 519 | Bool still_noisy = True; |
| 520 | |
| 521 | /* Should be assured by caller */ |
| 522 | vg_assert( ! VG_(clo_xml) ); |
| 523 | |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 524 | /* if user wants to debug from a certain error nr, then wait for gdb/vgdb */ |
| 525 | if (VG_(clo_vgdb) != Vg_VgdbNo |
| 526 | && allow_db_attach |
philippe | baf6964 | 2012-02-15 22:29:30 +0000 | [diff] [blame] | 527 | && VG_(dyn_vgdb_error) <= n_errs_shown) { |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 528 | VG_(umsg)("(action on error) vgdb me ... \n"); |
| 529 | VG_(gdbserver)( err->tid ); |
| 530 | VG_(umsg)("Continuing ...\n"); |
| 531 | } |
| 532 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 533 | /* Perhaps we want a debugger attach at this point? */ |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 534 | /* GDBTD ??? maybe we should/could remove the below assuming the |
| 535 | gdbserver interface is better ??? */ |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 536 | if (allow_db_attach && |
| 537 | VG_(is_action_requested)( "Attach to debugger", & VG_(clo_db_attach) )) |
| 538 | { |
| 539 | if (0) VG_(printf)("starting debugger\n"); |
| 540 | VG_(start_debugger)( err->tid ); |
| 541 | } |
| 542 | /* Or maybe we want to generate the error's suppression? */ |
| 543 | if (VG_(clo_gen_suppressions) == 2 |
| 544 | || (VG_(clo_gen_suppressions) == 1 |
| 545 | && VG_(is_action_requested)( "Print suppression", &still_noisy )) |
| 546 | ) { |
| 547 | gen_suppression(err); |
| 548 | } |
| 549 | if (VG_(clo_gen_suppressions) == 1 && !still_noisy) |
| 550 | VG_(clo_gen_suppressions) = 0; |
| 551 | } |
| 552 | |
| 553 | |
| 554 | /* Prints an error. Not entirely simple because of the differences |
| 555 | between XML and text mode output. |
| 556 | |
| 557 | In XML mode: |
| 558 | |
| 559 | * calls the tool's pre-show method, so the tool can create any |
| 560 | preamble ahead of the message, if it wants. |
| 561 | |
| 562 | * prints the opening tag, and the <unique> and <tid> fields |
| 563 | |
| 564 | * prints the tool-specific parts of the message |
| 565 | |
| 566 | * if suppression generation is required, a suppression |
| 567 | |
| 568 | * the closing tag |
| 569 | |
| 570 | In text mode: |
| 571 | |
| 572 | * calls the tool's pre-show method, so the tool can create any |
| 573 | preamble ahead of the message, if it wants. |
| 574 | |
| 575 | * prints the tool-specific parts of the message |
| 576 | |
| 577 | * calls do_actions_on_error. This optionally does a debugger |
| 578 | attach (and detach), and optionally prints a suppression; both |
| 579 | of these may require user input. |
| 580 | */ |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 581 | static void pp_Error ( Error* err, Bool allow_db_attach, Bool xml ) |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 582 | { |
| 583 | /* If this fails, you probably specified your tool's method |
| 584 | dictionary incorrectly. */ |
| 585 | vg_assert(VG_(needs).tool_errors); |
| 586 | |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 587 | if (xml) { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 588 | |
| 589 | /* Note, allow_db_attach is ignored in here. */ |
| 590 | |
| 591 | /* Ensure that suppression generation is either completely |
| 592 | enabled or completely disabled; either way, we won't require |
| 593 | any user input. m_main.process_cmd_line_options should |
| 594 | ensure the asserted condition holds. */ |
| 595 | vg_assert( VG_(clo_gen_suppressions) == 0 /* disabled */ |
| 596 | || VG_(clo_gen_suppressions) == 2 /* for all errors */ ); |
| 597 | |
| 598 | /* Pre-show it to the tool */ |
| 599 | VG_TDICT_CALL( tool_before_pp_Error, err ); |
| 600 | |
| 601 | /* standard preamble */ |
| 602 | VG_(printf_xml)("<error>\n"); |
| 603 | VG_(printf_xml)(" <unique>0x%x</unique>\n", err->unique); |
| 604 | VG_(printf_xml)(" <tid>%d</tid>\n", err->tid); |
florian | 4978951 | 2013-09-16 17:08:50 +0000 | [diff] [blame] | 605 | ThreadState* tst = VG_(get_ThreadState)(err->tid); |
| 606 | if (tst->thread_name) { |
| 607 | VG_(printf_xml)(" <threadname>%s</threadname>\n", tst->thread_name); |
| 608 | } |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 609 | |
| 610 | /* actually print it */ |
| 611 | VG_TDICT_CALL( tool_pp_Error, err ); |
| 612 | |
| 613 | if (VG_(clo_gen_suppressions) > 0) |
| 614 | gen_suppression(err); |
| 615 | |
| 616 | /* postamble */ |
| 617 | VG_(printf_xml)("</error>\n"); |
njn | b6267bd | 2009-08-12 00:14:16 +0000 | [diff] [blame] | 618 | VG_(printf_xml)("\n"); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 619 | |
| 620 | } else { |
| 621 | |
| 622 | VG_TDICT_CALL( tool_before_pp_Error, err ); |
| 623 | |
| 624 | if (VG_(tdict).tool_show_ThreadIDs_for_errors |
| 625 | && err->tid > 0 && err->tid != last_tid_printed) { |
florian | 4978951 | 2013-09-16 17:08:50 +0000 | [diff] [blame] | 626 | ThreadState* tst = VG_(get_ThreadState)(err->tid); |
| 627 | if (tst->thread_name) { |
| 628 | VG_(umsg)("Thread %d %s:\n", err->tid, tst->thread_name ); |
| 629 | } else { |
| 630 | VG_(umsg)("Thread %d:\n", err->tid ); |
| 631 | } |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 632 | last_tid_printed = err->tid; |
| 633 | } |
| 634 | |
| 635 | VG_TDICT_CALL( tool_pp_Error, err ); |
njn | b6267bd | 2009-08-12 00:14:16 +0000 | [diff] [blame] | 636 | VG_(umsg)("\n"); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 637 | |
| 638 | do_actions_on_error(err, allow_db_attach); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | |
| 642 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 643 | /* Construct an error */ |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 644 | static |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 645 | void construct_error ( Error* err, ThreadId tid, ErrorKind ekind, Addr a, |
florian | e543f30 | 2012-10-21 19:43:43 +0000 | [diff] [blame] | 646 | const HChar* s, void* extra, ExeContext* where ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 647 | { |
sewardj | dbada27 | 2005-07-02 21:16:30 +0000 | [diff] [blame] | 648 | /* DO NOT MAKE unique_counter NON-STATIC */ |
| 649 | static UInt unique_counter = 0; |
| 650 | |
njn | ca82cc0 | 2004-11-22 17:18:48 +0000 | [diff] [blame] | 651 | tl_assert(tid < VG_N_THREADS); |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 652 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 653 | /* Core-only parts */ |
sewardj | dbada27 | 2005-07-02 21:16:30 +0000 | [diff] [blame] | 654 | err->unique = unique_counter++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 655 | err->next = NULL; |
| 656 | err->supp = NULL; |
| 657 | err->count = 1; |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 658 | err->tid = tid; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 659 | if (NULL == where) |
sewardj | adb102f | 2007-11-09 23:21:44 +0000 | [diff] [blame] | 660 | err->where = VG_(record_ExeContext)( tid, 0 ); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 661 | else |
| 662 | err->where = where; |
njn | 1d6c4bc | 2002-11-21 13:38:08 +0000 | [diff] [blame] | 663 | |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 664 | /* Tool-relevant parts */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 665 | err->ekind = ekind; |
| 666 | err->addr = a; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 667 | err->extra = extra; |
sewardj | a602261 | 2003-07-24 23:50:17 +0000 | [diff] [blame] | 668 | err->string = s; |
| 669 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 670 | /* sanity... */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 671 | vg_assert( tid < VG_N_THREADS ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 672 | } |
| 673 | |
njn | 83f9e79 | 2005-06-11 05:04:09 +0000 | [diff] [blame] | 674 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 675 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 676 | /* Top-level entry point to the error management subsystem. |
| 677 | All detected errors are notified here; this routine decides if/when the |
| 678 | user should see the error. */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 679 | void VG_(maybe_record_error) ( ThreadId tid, |
florian | e543f30 | 2012-10-21 19:43:43 +0000 | [diff] [blame] | 680 | ErrorKind ekind, Addr a, const HChar* s, void* extra ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 681 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 682 | Error err; |
| 683 | Error* p; |
| 684 | Error* p_prev; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 685 | UInt extra_size; |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 686 | VgRes exe_res = Vg_MedRes; |
| 687 | static Bool stopping_message = False; |
| 688 | static Bool slowdown_message = False; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 689 | |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 690 | /* After M_COLLECT_NO_ERRORS_AFTER_SHOWN different errors have |
| 691 | been found, or M_COLLECT_NO_ERRORS_AFTER_FOUND total errors |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 692 | have been found, just refuse to collect any more. This stops |
| 693 | the burden of the error-management system becoming excessive in |
| 694 | extremely buggy programs, although it does make it pretty |
| 695 | pointless to continue the Valgrind run after this point. */ |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 696 | if (VG_(clo_error_limit) |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 697 | && (n_errs_shown >= M_COLLECT_NO_ERRORS_AFTER_SHOWN |
sewardj | 8a05172 | 2005-06-30 00:10:16 +0000 | [diff] [blame] | 698 | || n_errs_found >= M_COLLECT_NO_ERRORS_AFTER_FOUND) |
| 699 | && !VG_(clo_xml)) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 700 | if (!stopping_message) { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 701 | VG_(umsg)("\n"); |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 702 | |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 703 | if (n_errs_shown >= M_COLLECT_NO_ERRORS_AFTER_SHOWN) { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 704 | VG_(umsg)( |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 705 | "More than %d different errors detected. " |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 706 | "I'm not reporting any more.\n", |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 707 | M_COLLECT_NO_ERRORS_AFTER_SHOWN ); |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 708 | } else { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 709 | VG_(umsg)( |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 710 | "More than %d total errors detected. " |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 711 | "I'm not reporting any more.\n", |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 712 | M_COLLECT_NO_ERRORS_AFTER_FOUND ); |
sewardj | f2537be | 2002-04-24 21:03:47 +0000 | [diff] [blame] | 713 | } |
| 714 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 715 | VG_(umsg)("Final error counts will be inaccurate. " |
| 716 | "Go fix your program!\n"); |
| 717 | VG_(umsg)("Rerun with --error-limit=no to disable " |
| 718 | "this cutoff. Note\n"); |
| 719 | VG_(umsg)("that errors may occur in your program without " |
| 720 | "prior warning from\n"); |
| 721 | VG_(umsg)("Valgrind, because errors are no longer " |
| 722 | "being displayed.\n"); |
| 723 | VG_(umsg)("\n"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 724 | stopping_message = True; |
| 725 | } |
| 726 | return; |
| 727 | } |
| 728 | |
sewardj | dc873c0 | 2011-07-24 16:02:33 +0000 | [diff] [blame] | 729 | /* Ignore it if error acquisition is disabled for this thread. */ |
| 730 | { ThreadState* tst = VG_(get_ThreadState)(tid); |
| 731 | if (tst->err_disablement_level > 0) |
| 732 | return; |
| 733 | } |
| 734 | |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 735 | /* After M_COLLECT_ERRORS_SLOWLY_AFTER different errors have |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 736 | been found, be much more conservative about collecting new |
| 737 | ones. */ |
sewardj | 8a05172 | 2005-06-30 00:10:16 +0000 | [diff] [blame] | 738 | if (n_errs_shown >= M_COLLECT_ERRORS_SLOWLY_AFTER |
| 739 | && !VG_(clo_xml)) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 740 | exe_res = Vg_LowRes; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 741 | if (!slowdown_message) { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 742 | VG_(umsg)("\n"); |
| 743 | VG_(umsg)("More than %d errors detected. Subsequent errors\n", |
| 744 | M_COLLECT_ERRORS_SLOWLY_AFTER); |
| 745 | VG_(umsg)("will still be recorded, but in less " |
| 746 | "detail than before.\n"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 747 | slowdown_message = True; |
| 748 | } |
| 749 | } |
| 750 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 751 | /* Build ourselves the error */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 752 | construct_error ( &err, tid, ekind, a, s, extra, NULL ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 753 | |
| 754 | /* First, see if we've got an error record matching this one. */ |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 755 | em_errlist_searches++; |
| 756 | p = errors; |
| 757 | p_prev = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 758 | while (p != NULL) { |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 759 | em_errlist_cmps++; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 760 | if (eq_Error(exe_res, p, &err)) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 761 | /* Found it. */ |
| 762 | p->count++; |
| 763 | if (p->supp != NULL) { |
| 764 | /* Deal correctly with suppressed errors. */ |
| 765 | p->supp->count++; |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 766 | n_errs_suppressed++; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 767 | } else { |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 768 | n_errs_found++; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | /* Move p to the front of the list so that future searches |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 772 | for it are faster. It also allows to print the last |
| 773 | error (see VG_(show_last_error). */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 774 | if (p_prev != NULL) { |
| 775 | vg_assert(p_prev->next == p); |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 776 | p_prev->next = p->next; |
| 777 | p->next = errors; |
| 778 | errors = p; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 779 | } |
sewardj | 7ebf7c3 | 2003-07-24 21:29:40 +0000 | [diff] [blame] | 780 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 781 | return; |
| 782 | } |
| 783 | p_prev = p; |
| 784 | p = p->next; |
| 785 | } |
| 786 | |
| 787 | /* Didn't see it. Copy and add. */ |
| 788 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 789 | /* OK, we're really going to collect it. The context is on the stack and |
| 790 | will disappear shortly, so we must copy it. First do the main |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 791 | (non-'extra') part. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 792 | |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 793 | Then VG_(tdict).tool_update_extra can update the 'extra' part. This |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 794 | is for when there are more details to fill in which take time to work |
| 795 | out but don't affect our earlier decision to include the error -- by |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 796 | postponing those details until now, we avoid the extra work in the |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 797 | case where we ignore the error. Ugly. |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 798 | |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 799 | 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] | 800 | VG_(tdict).tool_update_extra returned. Also allow for people using |
| 801 | the void* extra field for a scalar value like an integer. |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 802 | */ |
| 803 | |
| 804 | /* copy main part */ |
florian | a2968cc | 2013-09-20 21:34:40 +0000 | [diff] [blame] | 805 | p = VG_(malloc)("errormgr.mre.1", sizeof(Error)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 806 | *p = err; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 807 | |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 808 | /* update 'extra' */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 809 | switch (ekind) { |
njn | a86f29e | 2006-12-14 02:55:58 +0000 | [diff] [blame] | 810 | //(example code, see comment on CoreSuppKind above) |
| 811 | //case ThreadErr: |
| 812 | // vg_assert(VG_(needs).core_errors); |
| 813 | // extra_size = <something> |
| 814 | // break; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 815 | default: |
| 816 | vg_assert(VG_(needs).tool_errors); |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 817 | extra_size = VG_TDICT_CALL(tool_update_extra, p); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 818 | break; |
| 819 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 820 | |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 821 | /* copy block pointed to by 'extra', if there is one */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 822 | if (NULL != p->extra && 0 != extra_size) { |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 823 | void* new_extra = VG_(malloc)("errormgr.mre.2", extra_size); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 824 | VG_(memcpy)(new_extra, p->extra, extra_size); |
| 825 | p->extra = new_extra; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 826 | } |
| 827 | |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 828 | p->next = errors; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 829 | p->supp = is_suppressible_error(&err); |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 830 | errors = p; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 831 | if (p->supp == NULL) { |
philippe | baf6964 | 2012-02-15 22:29:30 +0000 | [diff] [blame] | 832 | /* update stats */ |
njn | 606a4ae | 2009-08-11 00:52:40 +0000 | [diff] [blame] | 833 | n_err_contexts++; |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 834 | n_errs_found++; |
philippe | baf6964 | 2012-02-15 22:29:30 +0000 | [diff] [blame] | 835 | n_errs_shown++; |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 836 | /* Actually show the error; more complex than you might think. */ |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 837 | pp_Error( p, /*allow_db_attach*/True, VG_(clo_xml) ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 838 | } else { |
njn | 606a4ae | 2009-08-11 00:52:40 +0000 | [diff] [blame] | 839 | n_supp_contexts++; |
nethercote | f2b1148 | 2004-08-02 12:36:01 +0000 | [diff] [blame] | 840 | n_errs_suppressed++; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 841 | p->supp->count++; |
| 842 | } |
| 843 | } |
| 844 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 845 | /* Second top-level entry point to the error management subsystem, for |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 846 | errors that the tool wants to report immediately, eg. because they're |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 847 | guaranteed to only happen once. This avoids all the recording and |
| 848 | comparing stuff. But they can be suppressed; returns True if it is |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 849 | suppressed. Bool 'print_error' dictates whether to print the error. |
njn | 18afe5d | 2009-08-10 08:25:39 +0000 | [diff] [blame] | 850 | Bool 'count_error' dictates whether to count the error in n_errs_found. |
njn | 47363ab | 2003-04-21 13:24:40 +0000 | [diff] [blame] | 851 | */ |
florian | e543f30 | 2012-10-21 19:43:43 +0000 | [diff] [blame] | 852 | Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind, Addr a, const HChar* s, |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 853 | void* extra, ExeContext* where, Bool print_error, |
njn | 18afe5d | 2009-08-10 08:25:39 +0000 | [diff] [blame] | 854 | Bool allow_db_attach, Bool count_error ) |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 855 | { |
njn | fb289bc | 2007-01-12 23:59:50 +0000 | [diff] [blame] | 856 | Error err; |
| 857 | Supp *su; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 858 | |
sewardj | dc873c0 | 2011-07-24 16:02:33 +0000 | [diff] [blame] | 859 | /* Ignore it if error acquisition is disabled for this thread. */ |
| 860 | ThreadState* tst = VG_(get_ThreadState)(tid); |
| 861 | if (tst->err_disablement_level > 0) |
| 862 | return False; /* ignored, not suppressed */ |
| 863 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 864 | /* Build ourselves the error */ |
njn | 7271864 | 2003-07-24 08:45:32 +0000 | [diff] [blame] | 865 | construct_error ( &err, tid, ekind, a, s, extra, where ); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 866 | |
| 867 | /* Unless it's suppressed, we're going to show it. Don't need to make |
| 868 | a copy, because it's only temporary anyway. |
| 869 | |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 870 | Then update the 'extra' part with VG_(tdict).tool_update_extra), |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 871 | because that can have an affect on whether it's suppressed. Ignore |
| 872 | the size return value of VG_(tdict).tool_update_extra, because we're |
njn | 02bc4b8 | 2005-05-15 17:28:26 +0000 | [diff] [blame] | 873 | not copying 'extra'. */ |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 874 | (void)VG_TDICT_CALL(tool_update_extra, &err); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 875 | |
njn | fb289bc | 2007-01-12 23:59:50 +0000 | [diff] [blame] | 876 | su = is_suppressible_error(&err); |
| 877 | if (NULL == su) { |
njn | 606a4ae | 2009-08-11 00:52:40 +0000 | [diff] [blame] | 878 | if (count_error) { |
njn | 18afe5d | 2009-08-10 08:25:39 +0000 | [diff] [blame] | 879 | n_errs_found++; |
njn | 606a4ae | 2009-08-11 00:52:40 +0000 | [diff] [blame] | 880 | n_err_contexts++; |
| 881 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 882 | |
| 883 | if (print_error) { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 884 | /* update stats */ |
njn | fb289bc | 2007-01-12 23:59:50 +0000 | [diff] [blame] | 885 | n_errs_shown++; |
philippe | baf6964 | 2012-02-15 22:29:30 +0000 | [diff] [blame] | 886 | /* Actually show the error; more complex than you might think. */ |
| 887 | pp_Error(&err, allow_db_attach, VG_(clo_xml)); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 888 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 889 | return False; |
| 890 | |
| 891 | } else { |
njn | 663ab79 | 2009-08-13 04:24:38 +0000 | [diff] [blame] | 892 | if (count_error) { |
| 893 | n_errs_suppressed++; |
| 894 | n_supp_contexts++; |
| 895 | } |
njn | fb289bc | 2007-01-12 23:59:50 +0000 | [diff] [blame] | 896 | su->count++; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 897 | return True; |
| 898 | } |
| 899 | } |
| 900 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 901 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 902 | /*------------------------------------------------------------*/ |
| 903 | /*--- Exported fns ---*/ |
| 904 | /*------------------------------------------------------------*/ |
| 905 | |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 906 | /* Show the used suppressions. Returns False if no suppression |
| 907 | got used. */ |
| 908 | static Bool show_used_suppressions ( void ) |
| 909 | { |
| 910 | Supp *su; |
| 911 | Bool any_supp; |
| 912 | |
sewardj | 7c9e57c | 2005-05-24 14:21:45 +0000 | [diff] [blame] | 913 | if (VG_(clo_xml)) |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 914 | VG_(printf_xml)("<suppcounts>\n"); |
sewardj | 7c9e57c | 2005-05-24 14:21:45 +0000 | [diff] [blame] | 915 | |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 916 | any_supp = False; |
| 917 | for (su = suppressions; su != NULL; su = su->next) { |
| 918 | if (su->count <= 0) |
| 919 | continue; |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 920 | if (VG_(clo_xml)) { |
bart | b3af9cf | 2011-10-06 19:08:37 +0000 | [diff] [blame] | 921 | VG_(printf_xml)( " <pair>\n" |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 922 | " <count>%d</count>\n" |
bart | b3af9cf | 2011-10-06 19:08:37 +0000 | [diff] [blame] | 923 | " <name>%pS</name>\n" |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 924 | " </pair>\n", |
| 925 | su->count, su->sname ); |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 926 | } else { |
philippe | 4e32d67 | 2013-10-17 22:10:41 +0000 | [diff] [blame] | 927 | HChar xtra[256]; /* assumed big enough (is overrun-safe) */ |
| 928 | Bool anyXtra; |
sewardj | 2d9e874 | 2009-08-07 15:46:56 +0000 | [diff] [blame] | 929 | // blank line before the first shown suppression, if any |
| 930 | if (!any_supp) |
| 931 | VG_(dmsg)("\n"); |
philippe | 4e32d67 | 2013-10-17 22:10:41 +0000 | [diff] [blame] | 932 | VG_(memset)(xtra, 0, sizeof(xtra)); |
| 933 | anyXtra = VG_TDICT_CALL(tool_print_extra_suppression_use, |
| 934 | su, xtra, sizeof(xtra)); |
| 935 | vg_assert(xtra[sizeof(xtra)-1] == 0); |
| 936 | VG_(dmsg)("used_suppression: %6d %s %s:%d%s%s\n", su->count, su->sname, |
philippe | 362441d | 2013-07-22 22:00:13 +0000 | [diff] [blame] | 937 | VG_(clo_suppressions)[su->clo_suppressions_i], |
philippe | 4e32d67 | 2013-10-17 22:10:41 +0000 | [diff] [blame] | 938 | su->sname_lineno, |
| 939 | anyXtra ? " " : "", xtra); |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 940 | } |
sewardj | 2d9e874 | 2009-08-07 15:46:56 +0000 | [diff] [blame] | 941 | any_supp = True; |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 942 | } |
| 943 | |
sewardj | 7c9e57c | 2005-05-24 14:21:45 +0000 | [diff] [blame] | 944 | if (VG_(clo_xml)) |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 945 | VG_(printf_xml)("</suppcounts>\n"); |
sewardj | 7c9e57c | 2005-05-24 14:21:45 +0000 | [diff] [blame] | 946 | |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 947 | return any_supp; |
| 948 | } |
| 949 | |
sewardj | 9f297ca | 2005-05-20 02:29:52 +0000 | [diff] [blame] | 950 | /* Show all the errors that occurred, and possibly also the |
| 951 | suppressions used. */ |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 952 | void VG_(show_all_errors) ( Int verbosity, Bool xml ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 953 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 954 | Int i, n_min; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 955 | Error *p, *p_min; |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 956 | Bool any_supp; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 957 | |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 958 | if (verbosity == 0) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 959 | return; |
| 960 | |
njn | 606a4ae | 2009-08-11 00:52:40 +0000 | [diff] [blame] | 961 | /* If we're printing XML, just show the suppressions and stop. */ |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 962 | if (xml) { |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 963 | (void)show_used_suppressions(); |
| 964 | return; |
| 965 | } |
| 966 | |
| 967 | /* We only get here if not printing XML. */ |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 968 | VG_(umsg)("ERROR SUMMARY: " |
| 969 | "%d errors from %d contexts (suppressed: %d from %d)\n", |
| 970 | n_errs_found, n_err_contexts, |
| 971 | n_errs_suppressed, n_supp_contexts ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 972 | |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 973 | if (verbosity <= 1) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 974 | return; |
| 975 | |
sewardj | 2d9e874 | 2009-08-07 15:46:56 +0000 | [diff] [blame] | 976 | // We do the following only at -v or above, and only in non-XML |
| 977 | // mode |
| 978 | |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 979 | /* Print the contexts in order of increasing error count. |
| 980 | Once an error is shown, we add a huge value to its count to filter it |
philippe | 362441d | 2013-07-22 22:00:13 +0000 | [diff] [blame] | 981 | out. |
| 982 | After having shown all errors, we reset count to the original value. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 983 | for (i = 0; i < n_err_contexts; i++) { |
| 984 | n_min = (1 << 30) - 1; |
| 985 | p_min = NULL; |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 986 | for (p = errors; p != NULL; p = p->next) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 987 | if (p->supp != NULL) continue; |
| 988 | if (p->count < n_min) { |
| 989 | n_min = p->count; |
| 990 | p_min = p; |
| 991 | } |
| 992 | } |
njn | 663ab79 | 2009-08-13 04:24:38 +0000 | [diff] [blame] | 993 | // XXX: this isn't right. See bug 203651. |
| 994 | if (p_min == NULL) continue; //VG_(tool_panic)("show_all_errors()"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 995 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 996 | VG_(umsg)("\n"); |
| 997 | VG_(umsg)("%d errors in context %d of %d:\n", |
| 998 | p_min->count, i+1, n_err_contexts); |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 999 | pp_Error( p_min, False/*allow_db_attach*/, False /* xml */ ); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1000 | |
| 1001 | // We're not printing XML -- we'd have exited above if so. |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 1002 | vg_assert(! xml); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1003 | |
| 1004 | if ((i+1 == VG_(clo_dump_error))) { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1005 | StackTrace ips = VG_(get_ExeContext_StackTrace)(p_min->where); |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 1006 | VG_(translate) ( 0 /* dummy ThreadId; irrelevant due to debugging*/, |
njn | 394213a | 2005-06-19 18:38:24 +0000 | [diff] [blame] | 1007 | ips[0], /*debugging*/True, 0xFE/*verbosity*/, |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1008 | /*bbs_done*/0, |
| 1009 | /*allow redir?*/True); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 1012 | p_min->count = p_min->count + (1 << 30); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 1015 | /* reset the counts, otherwise a 2nd call does not show anything anymore */ |
| 1016 | for (p = errors; p != NULL; p = p->next) { |
| 1017 | if (p->count >= (1 << 30)) |
| 1018 | p->count = p->count - (1 << 30); |
| 1019 | } |
| 1020 | |
| 1021 | |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 1022 | any_supp = show_used_suppressions(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1023 | |
sewardj | 2d9e874 | 2009-08-07 15:46:56 +0000 | [diff] [blame] | 1024 | if (any_supp) |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1025 | VG_(umsg)("\n"); |
sewardj | 2d9e874 | 2009-08-07 15:46:56 +0000 | [diff] [blame] | 1026 | // reprint this, so users don't have to scroll way up to find |
| 1027 | // the first printing |
| 1028 | VG_(umsg)("ERROR SUMMARY: " |
| 1029 | "%d errors from %d contexts (suppressed: %d from %d)\n", |
| 1030 | n_errs_found, n_err_contexts, n_errs_suppressed, |
| 1031 | n_supp_contexts ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 1034 | void VG_(show_last_error) ( void ) |
| 1035 | { |
| 1036 | if (n_err_contexts == 0) { |
| 1037 | VG_(umsg)("No errors yet\n"); |
| 1038 | return; |
| 1039 | } |
| 1040 | |
| 1041 | pp_Error( errors, False/*allow_db_attach*/, False/*xml*/ ); |
| 1042 | } |
| 1043 | |
sewardj | 9f297ca | 2005-05-20 02:29:52 +0000 | [diff] [blame] | 1044 | |
| 1045 | /* Show occurrence counts of all errors, in XML form. */ |
| 1046 | void VG_(show_error_counts_as_XML) ( void ) |
| 1047 | { |
| 1048 | Error* err; |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1049 | VG_(printf_xml)("<errorcounts>\n"); |
sewardj | 9f297ca | 2005-05-20 02:29:52 +0000 | [diff] [blame] | 1050 | for (err = errors; err != NULL; err = err->next) { |
| 1051 | if (err->supp != NULL) |
| 1052 | continue; |
| 1053 | if (err->count <= 0) |
| 1054 | continue; |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1055 | VG_(printf_xml)(" <pair>\n"); |
| 1056 | VG_(printf_xml)(" <count>%d</count>\n", err->count); |
| 1057 | VG_(printf_xml)(" <unique>0x%x</unique>\n", err->unique); |
| 1058 | VG_(printf_xml)(" </pair>\n"); |
sewardj | 9f297ca | 2005-05-20 02:29:52 +0000 | [diff] [blame] | 1059 | } |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1060 | VG_(printf_xml)("</errorcounts>\n"); |
njn | b6267bd | 2009-08-12 00:14:16 +0000 | [diff] [blame] | 1061 | VG_(printf_xml)("\n"); |
sewardj | 9f297ca | 2005-05-20 02:29:52 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1065 | /*------------------------------------------------------------*/ |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1066 | /*--- Suppression parsing ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1067 | /*------------------------------------------------------------*/ |
| 1068 | |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1069 | /* Get the next char from fd into *out_buf. Returns 1 if success, |
| 1070 | 0 if eof or < 0 if error. */ |
| 1071 | |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 1072 | static Int get_char ( Int fd, HChar* out_buf ) |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1073 | { |
| 1074 | Int r; |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 1075 | static HChar buf[256]; |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1076 | static Int buf_size = 0; |
| 1077 | static Int buf_used = 0; |
sewardj | 89c5bd8 | 2008-10-23 10:15:37 +0000 | [diff] [blame] | 1078 | vg_assert(buf_size >= 0 && buf_size <= 256); |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1079 | vg_assert(buf_used >= 0 && buf_used <= buf_size); |
| 1080 | if (buf_used == buf_size) { |
sewardj | 89c5bd8 | 2008-10-23 10:15:37 +0000 | [diff] [blame] | 1081 | r = VG_(read)(fd, buf, 256); |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1082 | if (r < 0) return r; /* read failed */ |
sewardj | 89c5bd8 | 2008-10-23 10:15:37 +0000 | [diff] [blame] | 1083 | vg_assert(r >= 0 && r <= 256); |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1084 | buf_size = r; |
| 1085 | buf_used = 0; |
| 1086 | } |
| 1087 | if (buf_size == 0) |
| 1088 | return 0; /* eof */ |
sewardj | 89c5bd8 | 2008-10-23 10:15:37 +0000 | [diff] [blame] | 1089 | vg_assert(buf_size >= 0 && buf_size <= 256); |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1090 | vg_assert(buf_used >= 0 && buf_used < buf_size); |
| 1091 | *out_buf = buf[buf_used]; |
| 1092 | buf_used++; |
| 1093 | return 1; |
| 1094 | } |
| 1095 | |
philippe | 2193a7c | 2012-12-08 17:54:16 +0000 | [diff] [blame] | 1096 | // Get a non blank non comment line. |
| 1097 | // Returns True if eof. |
| 1098 | static Bool get_nbnc_line ( Int fd, HChar** bufpp, SizeT* nBufp, Int* lineno ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1099 | { |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 1100 | HChar* buf = *bufpp; |
njn | 35db56c | 2009-07-24 07:38:29 +0000 | [diff] [blame] | 1101 | SizeT nBuf = *nBufp; |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 1102 | HChar ch; |
njn | 35db56c | 2009-07-24 07:38:29 +0000 | [diff] [blame] | 1103 | Int n, i; |
philippe | 362441d | 2013-07-22 22:00:13 +0000 | [diff] [blame] | 1104 | |
| 1105 | vg_assert(lineno); // lineno needed to correctly track line numbers. |
| 1106 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1107 | while (True) { |
philippe | 2193a7c | 2012-12-08 17:54:16 +0000 | [diff] [blame] | 1108 | buf[0] = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1109 | /* First, read until a non-blank char appears. */ |
| 1110 | while (True) { |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1111 | n = get_char(fd, &ch); |
njn | 0c0f32a | 2005-03-26 04:14:01 +0000 | [diff] [blame] | 1112 | if (n == 1 && !VG_(isspace)(ch)) break; |
bart | 050eec5 | 2009-07-27 12:03:03 +0000 | [diff] [blame] | 1113 | if (n == 1 && ch == '\n' && lineno) |
| 1114 | (*lineno)++; |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1115 | if (n <= 0) return True; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | /* Now, read the line into buf. */ |
| 1119 | i = 0; |
| 1120 | buf[i++] = ch; buf[i] = 0; |
| 1121 | while (True) { |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1122 | n = get_char(fd, &ch); |
| 1123 | if (n <= 0) return False; /* the next call will return True */ |
bart | 050eec5 | 2009-07-27 12:03:03 +0000 | [diff] [blame] | 1124 | if (ch == '\n' && lineno) |
| 1125 | (*lineno)++; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1126 | if (ch == '\n') break; |
njn | 35db56c | 2009-07-24 07:38:29 +0000 | [diff] [blame] | 1127 | if (i > 0 && i == nBuf-1) { |
| 1128 | *nBufp = nBuf = nBuf * 2; |
| 1129 | #define RIDICULOUS 100000 |
| 1130 | vg_assert2(nBuf < RIDICULOUS, // Just a sanity check, really. |
| 1131 | "VG_(get_line): line longer than %d chars, aborting\n", |
| 1132 | RIDICULOUS); |
| 1133 | *bufpp = buf = VG_(realloc)("errormgr.get_line.1", buf, nBuf); |
| 1134 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1135 | buf[i++] = ch; buf[i] = 0; |
| 1136 | } |
njn | 0c0f32a | 2005-03-26 04:14:01 +0000 | [diff] [blame] | 1137 | while (i > 1 && VG_(isspace)(buf[i-1])) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1138 | i--; buf[i] = 0; |
| 1139 | }; |
| 1140 | |
philippe | 362441d | 2013-07-22 22:00:13 +0000 | [diff] [blame] | 1141 | // VG_(printf)("The line *%p %d is '%s'\n", lineno, *lineno, buf); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1142 | /* Ok, we have a line. If a non-comment line, return. |
| 1143 | If a comment line, start all over again. */ |
| 1144 | if (buf[0] != '#') return False; |
| 1145 | } |
| 1146 | } |
| 1147 | |
philippe | 2193a7c | 2012-12-08 17:54:16 +0000 | [diff] [blame] | 1148 | // True if buf starts with fun: or obj: or is ... |
| 1149 | static Bool is_location_line (HChar* buf) |
| 1150 | { |
| 1151 | return VG_(strncmp)(buf, "fun:", 4) == 0 |
| 1152 | || VG_(strncmp)(buf, "obj:", 4) == 0 |
| 1153 | || VG_(strcmp)(buf, "...") == 0; |
| 1154 | } |
| 1155 | |
| 1156 | Bool VG_(get_line) ( Int fd, HChar** bufpp, SizeT* nBufp, Int* lineno ) |
| 1157 | { |
| 1158 | Bool eof = get_nbnc_line (fd, bufpp, nBufp, lineno); |
| 1159 | |
| 1160 | if (eof) |
| 1161 | return True; |
| 1162 | |
| 1163 | if (is_location_line(*bufpp)) |
| 1164 | return True; // Not a extra suppr line |
| 1165 | else |
philippe | 362441d | 2013-07-22 22:00:13 +0000 | [diff] [blame] | 1166 | return False; // A suppression extra line |
philippe | 2193a7c | 2012-12-08 17:54:16 +0000 | [diff] [blame] | 1167 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1168 | |
philippe | 2c5c05e | 2012-07-26 21:37:36 +0000 | [diff] [blame] | 1169 | /* True if s contains no wildcard (?, *) characters. */ |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 1170 | static Bool is_simple_str (const HChar *s) |
philippe | 2c5c05e | 2012-07-26 21:37:36 +0000 | [diff] [blame] | 1171 | { |
philippe | 2c5c05e | 2012-07-26 21:37:36 +0000 | [diff] [blame] | 1172 | while (*s) { |
| 1173 | if (*s == '?' || *s == '*') |
| 1174 | return False; |
| 1175 | s++; |
| 1176 | } |
| 1177 | return True; |
| 1178 | } |
| 1179 | |
philippe | 7d69fd9 | 2012-02-26 21:26:00 +0000 | [diff] [blame] | 1180 | /* buf contains the raw name of a caller, supposedly either |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1181 | fun:some_function_name or |
philippe | 7d69fd9 | 2012-02-26 21:26:00 +0000 | [diff] [blame] | 1182 | obj:some_object_name or |
| 1183 | ... |
| 1184 | Set p->ty and p->name accordingly. |
| 1185 | p->name is allocated and set to the string |
| 1186 | after the descriptor (fun: or obj:) part. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1187 | Returns False if failed. |
| 1188 | */ |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 1189 | static Bool setLocationTy ( SuppLoc* p, HChar *buf ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1190 | { |
philippe | 7d69fd9 | 2012-02-26 21:26:00 +0000 | [diff] [blame] | 1191 | if (VG_(strncmp)(buf, "fun:", 4) == 0) { |
| 1192 | p->name = VG_(arena_strdup)(VG_AR_CORE, |
| 1193 | "errormgr.sLTy.1", buf+4); |
philippe | 2c5c05e | 2012-07-26 21:37:36 +0000 | [diff] [blame] | 1194 | p->name_is_simple_str = is_simple_str (p->name); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1195 | p->ty = FunName; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1196 | return True; |
| 1197 | } |
philippe | 7d69fd9 | 2012-02-26 21:26:00 +0000 | [diff] [blame] | 1198 | if (VG_(strncmp)(buf, "obj:", 4) == 0) { |
| 1199 | p->name = VG_(arena_strdup)(VG_AR_CORE, |
| 1200 | "errormgr.sLTy.2", buf+4); |
philippe | 2c5c05e | 2012-07-26 21:37:36 +0000 | [diff] [blame] | 1201 | p->name_is_simple_str = is_simple_str (p->name); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1202 | p->ty = ObjName; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1203 | return True; |
| 1204 | } |
philippe | 7d69fd9 | 2012-02-26 21:26:00 +0000 | [diff] [blame] | 1205 | if (VG_(strcmp)(buf, "...") == 0) { |
sewardj | 5e51930 | 2008-11-03 23:10:25 +0000 | [diff] [blame] | 1206 | p->name = NULL; |
philippe | 2c5c05e | 2012-07-26 21:37:36 +0000 | [diff] [blame] | 1207 | p->name_is_simple_str = False; |
sewardj | 5e51930 | 2008-11-03 23:10:25 +0000 | [diff] [blame] | 1208 | p->ty = DotDotDot; |
| 1209 | return True; |
| 1210 | } |
| 1211 | VG_(printf)("location should be \"...\", or should start " |
| 1212 | "with \"fun:\" or \"obj:\"\n"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1213 | return False; |
| 1214 | } |
| 1215 | |
| 1216 | |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 1217 | /* Look for "tool" in a string like "tool1,tool2,tool3" */ |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 1218 | static Bool tool_name_present(const HChar *name, HChar *names) |
njn | 11cc925 | 2002-10-07 14:42:59 +0000 | [diff] [blame] | 1219 | { |
| 1220 | Bool found; |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 1221 | HChar *s = NULL; /* Shut gcc up */ |
njn | 11cc925 | 2002-10-07 14:42:59 +0000 | [diff] [blame] | 1222 | Int len = VG_(strlen)(name); |
| 1223 | |
| 1224 | found = (NULL != (s = VG_(strstr)(names, name)) && |
| 1225 | (s == names || *(s-1) == ',') && |
| 1226 | (*(s+len) == ',' || *(s+len) == '\0') |
| 1227 | ); |
| 1228 | |
| 1229 | return found; |
| 1230 | } |
| 1231 | |
philippe | 362441d | 2013-07-22 22:00:13 +0000 | [diff] [blame] | 1232 | /* Read suppressions from the file specified in |
| 1233 | VG_(clo_suppressions)[clo_suppressions_i] |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1234 | and place them in the suppressions list. If there's any difficulty |
| 1235 | doing this, just give up -- there's no point in trying to recover. |
| 1236 | */ |
philippe | 362441d | 2013-07-22 22:00:13 +0000 | [diff] [blame] | 1237 | static void load_one_suppressions_file ( Int clo_suppressions_i ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1238 | { |
philippe | 362441d | 2013-07-22 22:00:13 +0000 | [diff] [blame] | 1239 | const HChar* filename = VG_(clo_suppressions)[clo_suppressions_i]; |
sewardj | 9264559 | 2005-07-23 09:18:34 +0000 | [diff] [blame] | 1240 | SysRes sres; |
sewardj | 5e51930 | 2008-11-03 23:10:25 +0000 | [diff] [blame] | 1241 | Int fd, i, j, lineno = 0; |
philippe | 2193a7c | 2012-12-08 17:54:16 +0000 | [diff] [blame] | 1242 | Bool got_a_location_line_read_by_tool; |
sewardj | 9264559 | 2005-07-23 09:18:34 +0000 | [diff] [blame] | 1243 | Bool eof; |
njn | 35db56c | 2009-07-24 07:38:29 +0000 | [diff] [blame] | 1244 | SizeT nBuf = 200; |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 1245 | HChar* buf = VG_(malloc)("errormgr.losf.1", nBuf); |
| 1246 | HChar* tool_names; |
| 1247 | HChar* supp_name; |
florian | 2b8059a | 2012-10-14 16:45:23 +0000 | [diff] [blame] | 1248 | const HChar* err_str = NULL; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1249 | SuppLoc tmp_callers[VG_MAX_SUPP_CALLERS]; |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 1250 | |
njn | cc37d2e | 2009-06-24 03:49:19 +0000 | [diff] [blame] | 1251 | // Check it's not a directory. |
| 1252 | if (VG_(is_dir)( filename )) { |
| 1253 | if (VG_(clo_xml)) |
sewardj | 09361bf | 2011-01-28 00:19:25 +0000 | [diff] [blame] | 1254 | VG_(printf_xml)("</valgrindoutput>\n"); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1255 | VG_(umsg)("FATAL: suppressions file \"%s\" is a directory\n", filename ); |
njn | cc37d2e | 2009-06-24 03:49:19 +0000 | [diff] [blame] | 1256 | VG_(exit)(1); |
| 1257 | } |
| 1258 | |
| 1259 | // Open the suppression file. |
sewardj | 9264559 | 2005-07-23 09:18:34 +0000 | [diff] [blame] | 1260 | sres = VG_(open)( filename, VKI_O_RDONLY, 0 ); |
njn | cda2f0f | 2009-05-18 02:12:08 +0000 | [diff] [blame] | 1261 | if (sr_isError(sres)) { |
sewardj | f349d55 | 2005-11-14 17:01:01 +0000 | [diff] [blame] | 1262 | if (VG_(clo_xml)) |
sewardj | 09361bf | 2011-01-28 00:19:25 +0000 | [diff] [blame] | 1263 | VG_(printf_xml)("</valgrindoutput>\n"); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1264 | VG_(umsg)("FATAL: can't open suppressions file \"%s\"\n", filename ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1265 | VG_(exit)(1); |
| 1266 | } |
njn | cda2f0f | 2009-05-18 02:12:08 +0000 | [diff] [blame] | 1267 | fd = sr_Res(sres); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1268 | |
sewardj | 9264559 | 2005-07-23 09:18:34 +0000 | [diff] [blame] | 1269 | # define BOMB(S) { err_str = S; goto syntax_error; } |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1270 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1271 | while (True) { |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 1272 | /* Assign and initialise the two suppression halves (core and tool) */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1273 | Supp* supp; |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 1274 | supp = VG_(arena_malloc)(VG_AR_CORE, "errormgr.losf.1", |
| 1275 | sizeof(Supp)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1276 | supp->count = 0; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1277 | |
| 1278 | // Initialise temporary reading-in buffer. |
| 1279 | for (i = 0; i < VG_MAX_SUPP_CALLERS; i++) { |
| 1280 | tmp_callers[i].ty = NoName; |
philippe | 2c5c05e | 2012-07-26 21:37:36 +0000 | [diff] [blame] | 1281 | tmp_callers[i].name_is_simple_str = False; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1282 | tmp_callers[i].name = NULL; |
| 1283 | } |
| 1284 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1285 | supp->string = supp->extra = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1286 | |
philippe | 2193a7c | 2012-12-08 17:54:16 +0000 | [diff] [blame] | 1287 | eof = get_nbnc_line ( fd, &buf, &nBuf, &lineno ); |
philippe | 7d69fd9 | 2012-02-26 21:26:00 +0000 | [diff] [blame] | 1288 | if (eof) { |
| 1289 | VG_(arena_free)(VG_AR_CORE, supp); |
| 1290 | break; |
| 1291 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1292 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1293 | if (!VG_STREQ(buf, "{")) BOMB("expected '{' or end-of-file"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1294 | |
philippe | 2193a7c | 2012-12-08 17:54:16 +0000 | [diff] [blame] | 1295 | eof = get_nbnc_line ( fd, &buf, &nBuf, &lineno ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1296 | |
| 1297 | if (eof || VG_STREQ(buf, "}")) BOMB("unexpected '}'"); |
| 1298 | |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 1299 | supp->sname = VG_(arena_strdup)(VG_AR_CORE, "errormgr.losf.2", buf); |
philippe | 362441d | 2013-07-22 22:00:13 +0000 | [diff] [blame] | 1300 | supp->clo_suppressions_i = clo_suppressions_i; |
| 1301 | supp->sname_lineno = lineno; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1302 | |
philippe | 2193a7c | 2012-12-08 17:54:16 +0000 | [diff] [blame] | 1303 | eof = get_nbnc_line ( fd, &buf, &nBuf, &lineno ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1304 | |
philippe | 2193a7c | 2012-12-08 17:54:16 +0000 | [diff] [blame] | 1305 | if (eof) BOMB("unexpected end-of-file (expecting tool:suppr)"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1306 | |
njn | 94065fd | 2004-11-22 19:26:27 +0000 | [diff] [blame] | 1307 | /* Check it has the "tool1,tool2,...:supp" form (look for ':') */ |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 1308 | i = 0; |
| 1309 | while (True) { |
| 1310 | if (buf[i] == ':') break; |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1311 | if (buf[i] == '\0') BOMB("malformed 'tool1,tool2,...:supp' line"); |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 1312 | i++; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1313 | } |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 1314 | buf[i] = '\0'; /* Replace ':', splitting into two strings */ |
| 1315 | |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 1316 | tool_names = & buf[0]; |
njn | 11cc925 | 2002-10-07 14:42:59 +0000 | [diff] [blame] | 1317 | supp_name = & buf[i+1]; |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 1318 | |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 1319 | if (VG_(needs).core_errors && tool_name_present("core", tool_names)) |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 1320 | { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1321 | // A core suppression |
njn | a86f29e | 2006-12-14 02:55:58 +0000 | [diff] [blame] | 1322 | //(example code, see comment on CoreSuppKind above) |
| 1323 | //if (VG_STREQ(supp_name, "Thread")) |
| 1324 | // supp->skind = ThreadSupp; |
| 1325 | //else |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1326 | BOMB("unknown core suppression type"); |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 1327 | } |
njn | 95ec870 | 2004-11-22 16:46:13 +0000 | [diff] [blame] | 1328 | else if (VG_(needs).tool_errors && |
nethercote | 7cc9c23 | 2004-01-21 15:08:04 +0000 | [diff] [blame] | 1329 | tool_name_present(VG_(details).name, tool_names)) |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 1330 | { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1331 | // A tool suppression |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1332 | if (VG_TDICT_CALL(tool_recognised_suppression, supp_name, supp)) { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1333 | /* Do nothing, function fills in supp->skind */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1334 | } else { |
| 1335 | BOMB("unknown tool suppression type"); |
| 1336 | } |
njn | c40c3a8 | 2002-10-02 11:02:27 +0000 | [diff] [blame] | 1337 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1338 | else { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1339 | // Ignore rest of suppression |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1340 | while (True) { |
philippe | 2193a7c | 2012-12-08 17:54:16 +0000 | [diff] [blame] | 1341 | eof = get_nbnc_line ( fd, &buf, &nBuf, &lineno ); |
| 1342 | if (eof) BOMB("unexpected end-of-file (when skipping suppression)"); |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 1343 | if (VG_STREQ(buf, "}")) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1344 | break; |
| 1345 | } |
philippe | 7d69fd9 | 2012-02-26 21:26:00 +0000 | [diff] [blame] | 1346 | VG_(arena_free)(VG_AR_CORE, supp->sname); |
| 1347 | VG_(arena_free)(VG_AR_CORE, supp); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1348 | continue; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
philippe | 2193a7c | 2012-12-08 17:54:16 +0000 | [diff] [blame] | 1351 | buf[0] = 0; |
| 1352 | // tool_read_extra_suppression_info might read lines |
| 1353 | // from fd till a location line. |
njn | 95ec870 | 2004-11-22 16:46:13 +0000 | [diff] [blame] | 1354 | if (VG_(needs).tool_errors && |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1355 | !VG_TDICT_CALL(tool_read_extra_suppression_info, |
philippe | 362441d | 2013-07-22 22:00:13 +0000 | [diff] [blame] | 1356 | fd, &buf, &nBuf, &lineno, supp)) |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1357 | { |
| 1358 | BOMB("bad or missing extra suppression info"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
philippe | 2193a7c | 2012-12-08 17:54:16 +0000 | [diff] [blame] | 1361 | got_a_location_line_read_by_tool = buf[0] != 0 && is_location_line(buf); |
| 1362 | |
sewardj | 5e51930 | 2008-11-03 23:10:25 +0000 | [diff] [blame] | 1363 | /* the main frame-descriptor reading loop */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1364 | i = 0; |
| 1365 | while (True) { |
philippe | 2193a7c | 2012-12-08 17:54:16 +0000 | [diff] [blame] | 1366 | if (got_a_location_line_read_by_tool) { |
| 1367 | got_a_location_line_read_by_tool = False; |
| 1368 | eof = False; |
| 1369 | } else { |
| 1370 | eof = get_nbnc_line ( fd, &buf, &nBuf, &lineno ); |
| 1371 | } |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1372 | if (eof) |
philippe | 2193a7c | 2012-12-08 17:54:16 +0000 | [diff] [blame] | 1373 | BOMB("unexpected end-of-file (when reading stack trace)"); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1374 | if (VG_STREQ(buf, "}")) { |
| 1375 | if (i > 0) { |
| 1376 | break; |
| 1377 | } else { |
| 1378 | BOMB("missing stack trace"); |
| 1379 | } |
| 1380 | } |
| 1381 | if (i == VG_MAX_SUPP_CALLERS) |
| 1382 | BOMB("too many callers in stack trace"); |
| 1383 | if (i > 0 && i >= VG_(clo_backtrace_size)) |
| 1384 | break; |
philippe | 7d69fd9 | 2012-02-26 21:26:00 +0000 | [diff] [blame] | 1385 | if (!setLocationTy(&(tmp_callers[i]), buf)) |
sewardj | 5e51930 | 2008-11-03 23:10:25 +0000 | [diff] [blame] | 1386 | BOMB("location should be \"...\", or should start " |
| 1387 | "with \"fun:\" or \"obj:\""); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1388 | i++; |
| 1389 | } |
| 1390 | |
| 1391 | // If the num callers is >= VG_(clo_backtrace_size), ignore any extra |
| 1392 | // lines and grab the '}'. |
sewardj | 57a8f5f | 2003-07-06 01:40:11 +0000 | [diff] [blame] | 1393 | if (!VG_STREQ(buf, "}")) { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1394 | do { |
philippe | 2193a7c | 2012-12-08 17:54:16 +0000 | [diff] [blame] | 1395 | eof = get_nbnc_line ( fd, &buf, &nBuf, &lineno ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1396 | } while (!eof && !VG_STREQ(buf, "}")); |
| 1397 | } |
| 1398 | |
sewardj | 5e51930 | 2008-11-03 23:10:25 +0000 | [diff] [blame] | 1399 | // Reject entries which are entirely composed of frame |
| 1400 | // level wildcards. |
| 1401 | vg_assert(i > 0); // guaranteed by frame-descriptor reading loop |
| 1402 | for (j = 0; j < i; j++) { |
| 1403 | if (tmp_callers[j].ty == FunName || tmp_callers[j].ty == ObjName) |
| 1404 | break; |
| 1405 | vg_assert(tmp_callers[j].ty == DotDotDot); |
| 1406 | } |
| 1407 | vg_assert(j >= 0 && j <= i); |
| 1408 | if (j == i) { |
| 1409 | // we didn't find any non-"..." entries |
| 1410 | BOMB("suppression must contain at least one location " |
| 1411 | "line which is not \"...\""); |
| 1412 | } |
| 1413 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1414 | // Copy tmp_callers[] into supp->callers[] |
| 1415 | supp->n_callers = i; |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 1416 | supp->callers = VG_(arena_malloc)(VG_AR_CORE, "errormgr.losf.4", |
| 1417 | i*sizeof(SuppLoc)); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1418 | for (i = 0; i < supp->n_callers; i++) { |
| 1419 | supp->callers[i] = tmp_callers[i]; |
sewardj | 57a8f5f | 2003-07-06 01:40:11 +0000 | [diff] [blame] | 1420 | } |
| 1421 | |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 1422 | supp->next = suppressions; |
| 1423 | suppressions = supp; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1424 | } |
njn | 35db56c | 2009-07-24 07:38:29 +0000 | [diff] [blame] | 1425 | VG_(free)(buf); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1426 | VG_(close)(fd); |
| 1427 | return; |
| 1428 | |
| 1429 | syntax_error: |
sewardj | f349d55 | 2005-11-14 17:01:01 +0000 | [diff] [blame] | 1430 | if (VG_(clo_xml)) |
sewardj | 09361bf | 2011-01-28 00:19:25 +0000 | [diff] [blame] | 1431 | VG_(printf_xml)("</valgrindoutput>\n"); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1432 | VG_(umsg)("FATAL: in suppressions file \"%s\" near line %d:\n", |
njn | 6f74a7e | 2009-03-12 00:06:45 +0000 | [diff] [blame] | 1433 | filename, lineno ); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1434 | VG_(umsg)(" %s\n", err_str ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1435 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1436 | VG_(close)(fd); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1437 | VG_(umsg)("exiting now.\n"); |
nethercote | 8ed8a89 | 2004-11-08 13:24:25 +0000 | [diff] [blame] | 1438 | VG_(exit)(1); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1439 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1440 | # undef BOMB |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | |
| 1444 | void VG_(load_suppressions) ( void ) |
| 1445 | { |
| 1446 | Int i; |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 1447 | suppressions = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1448 | for (i = 0; i < VG_(clo_n_suppressions); i++) { |
| 1449 | if (VG_(clo_verbosity) > 1) { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1450 | VG_(dmsg)("Reading suppressions file: %s\n", |
| 1451 | VG_(clo_suppressions)[i] ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1452 | } |
philippe | 362441d | 2013-07-22 22:00:13 +0000 | [diff] [blame] | 1453 | load_one_suppressions_file( i ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1454 | } |
| 1455 | } |
| 1456 | |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1457 | |
| 1458 | /*------------------------------------------------------------*/ |
| 1459 | /*--- Matching errors to suppressions ---*/ |
| 1460 | /*------------------------------------------------------------*/ |
| 1461 | |
| 1462 | /* Parameterising functions for the use of VG_(generic_match) in |
| 1463 | suppression-vs-error matching. The suppression frames (SuppLoc) |
| 1464 | play the role of 'pattern'-element, and the error frames (IPs, |
| 1465 | hence simply Addrs) play the role of 'input'. In short then, we're |
| 1466 | matching a sequence of Addrs against a pattern composed of a |
| 1467 | sequence of SuppLocs. |
| 1468 | */ |
florian | 3e79863 | 2012-11-24 19:41:54 +0000 | [diff] [blame] | 1469 | static Bool supploc_IsStar ( const void* supplocV ) |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1470 | { |
florian | 3e79863 | 2012-11-24 19:41:54 +0000 | [diff] [blame] | 1471 | const SuppLoc* supploc = supplocV; |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1472 | return supploc->ty == DotDotDot; |
| 1473 | } |
| 1474 | |
florian | 3e79863 | 2012-11-24 19:41:54 +0000 | [diff] [blame] | 1475 | static Bool supploc_IsQuery ( const void* supplocV ) |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1476 | { |
| 1477 | return False; /* there's no '?' equivalent in the supp syntax */ |
| 1478 | } |
| 1479 | |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1480 | /* IPtoFunOrObjCompleter is a lazy completer of the IPs |
| 1481 | needed to match an error with the suppression patterns. |
| 1482 | The matching between an IP and a suppression pattern is done either |
| 1483 | with the IP function name or with the IP object name. |
| 1484 | First time the fun or obj name is needed for an IP member |
| 1485 | of a stack trace, it will be computed and stored in names. |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1486 | Also, if the IP corresponds to one or more inlined function calls, |
| 1487 | the inlined function names are expanded. |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1488 | The IPtoFunOrObjCompleter type is designed to minimise the nr of |
| 1489 | allocations and the nr of debuginfo search. */ |
| 1490 | typedef |
| 1491 | struct { |
| 1492 | StackTrace ips; // stack trace we are lazily completing. |
| 1493 | UWord n_ips; // nr of elements in ips. |
| 1494 | |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1495 | // VG_(generic_match) calls haveInputInpC to check |
| 1496 | // for the presence of an input element identified by ixInput |
| 1497 | // (i.e. a number that identifies the ixInput element of the |
| 1498 | // input sequence). It calls supp_pattEQinp to match this input |
| 1499 | // element with a pattern. |
| 1500 | // When inlining info is used to provide inlined function calls |
| 1501 | // in stacktraces, one IP in ips can be expanded in several |
| 1502 | // function names. So, each time input (or presence of input) |
| 1503 | // is requested by VG_(generic_match), we will expand |
| 1504 | // more IP of ips till we have expanded enough to reach the |
| 1505 | // input element requested (or we cannot expand anymore). |
| 1506 | |
| 1507 | UWord n_ips_expanded; |
| 1508 | // n_ips_expanded maintains the nr of elements in ips that we have |
| 1509 | // already expanded. |
| 1510 | UWord n_expanded; |
| 1511 | // n_expanded maintains the nr of elements resulting from the expansion |
| 1512 | // of the n_ips_expanded IPs. Without inlined function calls, |
| 1513 | // n_expanded == n_ips_expanded. With inlining info, |
| 1514 | // n_expanded >= n_ips_expanded. |
| 1515 | |
| 1516 | Int* n_offsets_per_ip; |
| 1517 | // n_offsets_per_ip[i] gives the nr of offsets in fun_offsets and obj_offsets |
| 1518 | // resulting of the expansion of ips[i]. |
| 1519 | // The sum of all n_expanded_per_ip must be equal to n_expanded. |
| 1520 | // This array allows to retrieve the position in ips corresponding to an ixInput. |
| 1521 | |
| 1522 | // size (in elements) of fun_offsets and obj_offsets. |
| 1523 | // (fun|obj)_offsets are reallocated if more space is needed |
| 1524 | // to expand an IP. |
| 1525 | UWord sz_offsets; |
| 1526 | |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1527 | Int* fun_offsets; |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1528 | // fun_offsets[ixInput] is the offset in names where the |
| 1529 | // function name for the ixInput element of the input sequence |
| 1530 | // can be found. As one IP of ips can be expanded in several |
| 1531 | // function calls due to inlined function calls, we can have more |
| 1532 | // elements in fun_offsets than in ips. |
| 1533 | // An offset -1 means the function name has not yet been computed. |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1534 | Int* obj_offsets; |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1535 | // Similarly, obj_offsets[ixInput] gives the offset for the |
| 1536 | // object name for ips[ixInput] |
| 1537 | // (-1 meaning object name not yet been computed). |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1538 | |
| 1539 | // All function names and object names will be concatenated |
| 1540 | // in names. names is reallocated on demand. |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 1541 | HChar *names; |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1542 | Int names_szB; // size of names. |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 1543 | Int names_free; // offset first free HChar in names. |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1544 | } |
| 1545 | IPtoFunOrObjCompleter; |
| 1546 | |
philippe | 5ab7ce8 | 2014-06-24 20:48:25 +0000 | [diff] [blame] | 1547 | static void pp_ip2fo (IPtoFunOrObjCompleter* ip2fo) |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1548 | { |
philippe | 5ab7ce8 | 2014-06-24 20:48:25 +0000 | [diff] [blame] | 1549 | Int i, j; |
| 1550 | Int o; |
| 1551 | |
| 1552 | VG_(printf)("n_ips %lu n_ips_expanded %lu resulting in n_expanded %lu\n", |
| 1553 | ip2fo->n_ips, ip2fo->n_ips_expanded, ip2fo->n_expanded); |
| 1554 | for (i = 0; i < ip2fo->n_ips_expanded; i++) { |
| 1555 | o = 0; |
| 1556 | for (j = 0; j < i; j++) |
| 1557 | o += ip2fo->n_offsets_per_ip[j]; |
| 1558 | VG_(printf)("ips %d 0x08%lx offset [%d,%d] ", |
| 1559 | i, ip2fo->ips[i], |
| 1560 | o, o+ip2fo->n_offsets_per_ip[i]-1); |
| 1561 | for (j = 0; j < ip2fo->n_offsets_per_ip[i]; j++) { |
| 1562 | VG_(printf)("%sfun:%s obj:%s\n", |
| 1563 | j == 0 ? "" : " ", |
| 1564 | ip2fo->fun_offsets[o+j] == -1 ? |
| 1565 | "<not expanded>" : &ip2fo->names[ip2fo->fun_offsets[o+j]], |
| 1566 | ip2fo->obj_offsets[o+j] == -1 ? |
| 1567 | "<not expanded>" : &ip2fo->names[ip2fo->obj_offsets[o+j]]); |
| 1568 | } |
| 1569 | } |
| 1570 | } |
| 1571 | |
| 1572 | /* free the memory in ip2fo. |
| 1573 | At debuglog 4, su (or NULL) will be used to show the matching (or non matching) |
| 1574 | with ip2fo. */ |
| 1575 | static void clearIPtoFunOrObjCompleter ( Supp *su, IPtoFunOrObjCompleter* ip2fo) |
| 1576 | { |
| 1577 | if (DEBUG_ERRORMGR || VG_(debugLog_getLevel)() >= 4) { |
| 1578 | if (su) |
| 1579 | VG_(dmsg)("errormgr matching end suppression %s %s:%d matched:\n", |
| 1580 | su->sname, |
| 1581 | VG_(clo_suppressions)[su->clo_suppressions_i], |
| 1582 | su->sname_lineno); |
| 1583 | else |
| 1584 | VG_(dmsg)("errormgr matching end no suppression matched:\n"); |
| 1585 | VG_(pp_StackTrace) (ip2fo->ips, ip2fo->n_ips); |
| 1586 | pp_ip2fo(ip2fo); |
| 1587 | } |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1588 | if (ip2fo->n_offsets_per_ip) VG_(free)(ip2fo->n_offsets_per_ip); |
| 1589 | if (ip2fo->fun_offsets) VG_(free)(ip2fo->fun_offsets); |
| 1590 | if (ip2fo->obj_offsets) VG_(free)(ip2fo->obj_offsets); |
| 1591 | if (ip2fo->names) VG_(free)(ip2fo->names); |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1592 | } |
| 1593 | |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1594 | /* Grow ip2fo->names to ensure we have ERRTXT_LEN characters available |
| 1595 | in ip2fo->names and returns a pointer to the first free char. */ |
| 1596 | static HChar* grow_names(IPtoFunOrObjCompleter* ip2fo) |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1597 | { |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1598 | if (ip2fo->names_szB |
| 1599 | < ip2fo->names_free + ERRTXT_LEN) { |
| 1600 | ip2fo->names |
| 1601 | = VG_(realloc)("foc_names", |
| 1602 | ip2fo->names, |
| 1603 | ip2fo->names_szB + ERRTXT_LEN); |
| 1604 | ip2fo->names_szB += ERRTXT_LEN; |
| 1605 | } |
| 1606 | return ip2fo->names + ip2fo->names_free; |
| 1607 | } |
| 1608 | |
| 1609 | /* foComplete returns the function name or object name for ixInput. |
| 1610 | If needFun, returns the function name for this input |
| 1611 | else returns the object name for this input. |
| 1612 | The function name or object name will be computed and added in |
| 1613 | names if not yet done. */ |
| 1614 | static HChar* foComplete(IPtoFunOrObjCompleter* ip2fo, |
| 1615 | Int ixInput, Bool needFun) |
| 1616 | { |
| 1617 | vg_assert (ixInput < ip2fo->n_expanded); |
| 1618 | vg_assert (VG_(clo_read_inline_info) || ixInput < ip2fo->n_ips); |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1619 | |
| 1620 | // ptr to the offset array for function offsets (if needFun) |
| 1621 | // or object offsets (if !needFun). |
| 1622 | Int** offsets; |
| 1623 | if (needFun) |
| 1624 | offsets = &ip2fo->fun_offsets; |
| 1625 | else |
| 1626 | offsets = &ip2fo->obj_offsets; |
| 1627 | |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1628 | // Complete Fun name or Obj name for IP if not yet done. |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1629 | if ((*offsets)[ixInput] == -1) { |
| 1630 | HChar* caller_name = grow_names(ip2fo); |
| 1631 | (*offsets)[ixInput] = ip2fo->names_free; |
philippe | 5ab7ce8 | 2014-06-24 20:48:25 +0000 | [diff] [blame] | 1632 | if (DEBUG_ERRORMGR) VG_(printf)("marking %s ixInput %d offset %d\n", |
| 1633 | needFun ? "fun" : "obj", |
| 1634 | ixInput, ip2fo->names_free); |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1635 | if (needFun) { |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1636 | // With inline info, fn names must have been completed already. |
| 1637 | vg_assert (!VG_(clo_read_inline_info)); |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1638 | /* Get the function name into 'caller_name', or "???" |
| 1639 | if unknown. */ |
| 1640 | // Nb: C++-mangled names are used in suppressions. Do, though, |
| 1641 | // Z-demangle them, since otherwise it's possible to wind |
| 1642 | // up comparing "malloc" in the suppression against |
| 1643 | // "_vgrZU_libcZdsoZa_malloc" in the backtrace, and the |
| 1644 | // two of them need to be made to match. |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1645 | if (!VG_(get_fnname_no_cxx_demangle)(ip2fo->ips[ixInput], |
| 1646 | caller_name, ERRTXT_LEN, |
| 1647 | NULL)) |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1648 | VG_(strcpy)(caller_name, "???"); |
| 1649 | } else { |
| 1650 | /* Get the object name into 'caller_name', or "???" |
| 1651 | if unknown. */ |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1652 | UWord i; |
| 1653 | UWord last_expand_pos_ips = 0; |
| 1654 | UWord pos_ips; |
| 1655 | |
| 1656 | /* First get the pos in ips corresponding to ixInput */ |
| 1657 | for (pos_ips = 0; pos_ips < ip2fo->n_expanded; pos_ips++) { |
| 1658 | last_expand_pos_ips += ip2fo->n_offsets_per_ip[pos_ips]; |
philippe | 5ab7ce8 | 2014-06-24 20:48:25 +0000 | [diff] [blame] | 1659 | if (ixInput < last_expand_pos_ips) |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1660 | break; |
| 1661 | } |
| 1662 | /* pos_ips is the position in ips corresponding to ixInput. |
| 1663 | last_expand_pos_ips is the last offset in fun/obj where |
| 1664 | ips[pos_ips] has been expanded. */ |
| 1665 | |
| 1666 | if (!VG_(get_objname)(ip2fo->ips[pos_ips], caller_name, ERRTXT_LEN)) |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1667 | VG_(strcpy)(caller_name, "???"); |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1668 | |
| 1669 | // Have all inlined calls pointing at this object name |
philippe | 5ab7ce8 | 2014-06-24 20:48:25 +0000 | [diff] [blame] | 1670 | for (i = last_expand_pos_ips - ip2fo->n_offsets_per_ip[pos_ips] + 1; |
| 1671 | i < last_expand_pos_ips; |
| 1672 | i++) { |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1673 | ip2fo->obj_offsets[i] = ip2fo->names_free; |
philippe | 5ab7ce8 | 2014-06-24 20:48:25 +0000 | [diff] [blame] | 1674 | if (DEBUG_ERRORMGR) |
| 1675 | VG_(printf) (" set obj_offset %lu to %d\n", i, ip2fo->names_free); |
| 1676 | } |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1677 | } |
| 1678 | ip2fo->names_free += VG_(strlen)(caller_name) + 1; |
philippe | 5ab7ce8 | 2014-06-24 20:48:25 +0000 | [diff] [blame] | 1679 | if (DEBUG_ERRORMGR) pp_ip2fo(ip2fo); |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1682 | return ip2fo->names + (*offsets)[ixInput]; |
| 1683 | } |
| 1684 | |
| 1685 | // Grow fun and obj _offsets arrays to have at least n_req elements. |
| 1686 | // Ensure n_offsets_per_ip is allocated. |
| 1687 | static void grow_offsets(IPtoFunOrObjCompleter* ip2fo, Int n_req) |
| 1688 | { |
| 1689 | Int i; |
| 1690 | |
| 1691 | // n_offsets_per_ip must always have the size of the ips array |
| 1692 | if (ip2fo->n_offsets_per_ip == NULL) { |
| 1693 | ip2fo->n_offsets_per_ip = VG_(malloc)("grow_offsets", |
| 1694 | ip2fo->n_ips * sizeof(Int)); |
| 1695 | for (i = 0; i < ip2fo->n_ips; i++) |
| 1696 | ip2fo->n_offsets_per_ip[i] = 0; |
| 1697 | } |
| 1698 | |
| 1699 | if (ip2fo->sz_offsets >= n_req) |
| 1700 | return; |
| 1701 | |
| 1702 | // Avoid too much re-allocation by allocating at least ip2fo->n_ips |
| 1703 | // elements and at least a few more elements than the current size. |
| 1704 | if (n_req < ip2fo->n_ips) |
| 1705 | n_req = ip2fo->n_ips; |
| 1706 | if (n_req < ip2fo->sz_offsets + 5) |
| 1707 | n_req = ip2fo->sz_offsets + 5; |
| 1708 | |
| 1709 | ip2fo->fun_offsets = VG_(realloc)("grow_offsets", ip2fo->fun_offsets, |
| 1710 | n_req * sizeof(Int)); |
| 1711 | for (i = ip2fo->sz_offsets; i < n_req; i++) |
| 1712 | ip2fo->fun_offsets[i] = -1; |
| 1713 | |
| 1714 | ip2fo->obj_offsets = VG_(realloc)("grow_offsets", ip2fo->obj_offsets, |
| 1715 | n_req * sizeof(Int)); |
| 1716 | for (i = ip2fo->sz_offsets; i < n_req; i++) |
| 1717 | ip2fo->obj_offsets[i] = -1; |
| 1718 | |
| 1719 | ip2fo->sz_offsets = n_req; |
| 1720 | } |
| 1721 | |
| 1722 | // Expands more IPs from ip2fo->ips. |
| 1723 | static void expandInput (IPtoFunOrObjCompleter* ip2fo, UWord ixInput ) |
| 1724 | { |
| 1725 | while (ip2fo->n_ips_expanded < ip2fo->n_ips |
| 1726 | && ip2fo->n_expanded <= ixInput) { |
| 1727 | if (VG_(clo_read_inline_info)) { |
| 1728 | // Expand one more IP in one or more calls. |
| 1729 | const Addr IP = ip2fo->ips[ip2fo->n_ips_expanded]; |
| 1730 | InlIPCursor *iipc; |
| 1731 | |
| 1732 | iipc = VG_(new_IIPC)(IP); |
| 1733 | // The only thing we really need is the nr of inlined fn calls |
| 1734 | // corresponding to the IP we will expand. |
| 1735 | // However, computing this is mostly the same as finding |
| 1736 | // the function name. So, let's directly complete the function name. |
| 1737 | do { |
| 1738 | HChar* caller_name = grow_names(ip2fo); |
| 1739 | grow_offsets(ip2fo, ip2fo->n_expanded+1); |
| 1740 | ip2fo->fun_offsets[ip2fo->n_expanded] = ip2fo->names_free; |
| 1741 | if (!VG_(get_fnname_no_cxx_demangle)(IP, |
| 1742 | caller_name, ERRTXT_LEN, |
| 1743 | iipc)) |
| 1744 | VG_(strcpy)(caller_name, "???"); |
| 1745 | ip2fo->names_free += VG_(strlen)(caller_name) + 1; |
| 1746 | ip2fo->n_expanded++; |
| 1747 | ip2fo->n_offsets_per_ip[ip2fo->n_ips_expanded]++; |
| 1748 | } while (VG_(next_IIPC)(iipc)); |
| 1749 | ip2fo->n_ips_expanded++; |
| 1750 | VG_(delete_IIPC) (iipc); |
| 1751 | } else { |
| 1752 | // Without inlined fn call info, expansion simply |
| 1753 | // consists in allocating enough elements in (fun|obj)_offsets. |
| 1754 | // The function or object names themselves will be completed |
| 1755 | // when requested. |
| 1756 | Int i; |
| 1757 | grow_offsets(ip2fo, ip2fo->n_ips); |
| 1758 | ip2fo->n_ips_expanded = ip2fo->n_ips; |
| 1759 | ip2fo->n_expanded = ip2fo->n_ips; |
| 1760 | for (i = 0; i < ip2fo->n_ips; i++) |
| 1761 | ip2fo->n_offsets_per_ip[i] = 1; |
| 1762 | } |
| 1763 | } |
| 1764 | } |
| 1765 | |
| 1766 | static Bool haveInputInpC (void* inputCompleter, UWord ixInput ) |
| 1767 | { |
| 1768 | IPtoFunOrObjCompleter* ip2fo = inputCompleter; |
| 1769 | expandInput(ip2fo, ixInput); |
| 1770 | return ixInput < ip2fo->n_expanded; |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
florian | 3e79863 | 2012-11-24 19:41:54 +0000 | [diff] [blame] | 1773 | static Bool supp_pattEQinp ( const void* supplocV, const void* addrV, |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1774 | void* inputCompleter, UWord ixInput ) |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1775 | { |
florian | 3e79863 | 2012-11-24 19:41:54 +0000 | [diff] [blame] | 1776 | const SuppLoc* supploc = supplocV; /* PATTERN */ |
florian | 3e79863 | 2012-11-24 19:41:54 +0000 | [diff] [blame] | 1777 | IPtoFunOrObjCompleter* ip2fo = inputCompleter; |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 1778 | HChar* funobj_name; // Fun or Obj name. |
philippe | 5ab7ce8 | 2014-06-24 20:48:25 +0000 | [diff] [blame] | 1779 | Bool ret; |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1780 | |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1781 | expandInput(ip2fo, ixInput); |
| 1782 | vg_assert(ixInput < ip2fo->n_expanded); |
| 1783 | |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1784 | /* So, does this IP address match this suppression-line? */ |
| 1785 | switch (supploc->ty) { |
| 1786 | case DotDotDot: |
| 1787 | /* supp_pattEQinp is a callback from VG_(generic_match). As |
| 1788 | per the spec thereof (see include/pub_tool_seqmatch.h), we |
| 1789 | should never get called with a pattern value for which the |
| 1790 | _IsStar or _IsQuery function would return True. Hence |
| 1791 | this can't happen. */ |
| 1792 | vg_assert(0); |
| 1793 | case ObjName: |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1794 | funobj_name = foComplete(ip2fo, ixInput, False /*needFun*/); |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1795 | break; |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1796 | case FunName: |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1797 | funobj_name = foComplete(ip2fo, ixInput, True /*needFun*/); |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1798 | break; |
| 1799 | default: |
| 1800 | vg_assert(0); |
| 1801 | } |
| 1802 | |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1803 | /* So now we have the function or object name in funobj_name, and |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1804 | the pattern (at the character level) to match against is in |
| 1805 | supploc->name. Hence (and leading to a re-entrant call of |
philippe | 2c5c05e | 2012-07-26 21:37:36 +0000 | [diff] [blame] | 1806 | VG_(generic_match) if there is a wildcard character): */ |
| 1807 | if (supploc->name_is_simple_str) |
philippe | 5ab7ce8 | 2014-06-24 20:48:25 +0000 | [diff] [blame] | 1808 | ret = VG_(strcmp) (supploc->name, funobj_name) == 0; |
philippe | 2c5c05e | 2012-07-26 21:37:36 +0000 | [diff] [blame] | 1809 | else |
philippe | 5ab7ce8 | 2014-06-24 20:48:25 +0000 | [diff] [blame] | 1810 | ret = VG_(string_match)(supploc->name, funobj_name); |
| 1811 | if (DEBUG_ERRORMGR) |
| 1812 | VG_(printf) ("supp_pattEQinp %s patt %s ixUnput %lu value:%s match:%s\n", |
| 1813 | supploc->ty == FunName ? "fun" : "obj", |
| 1814 | supploc->name, ixInput, funobj_name, |
| 1815 | ret ? "yes" : "no"); |
| 1816 | return ret; |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | ///////////////////////////////////////////////////// |
| 1820 | |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1821 | static Bool supp_matches_callers(IPtoFunOrObjCompleter* ip2fo, Supp* su) |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1822 | { |
| 1823 | /* Unwrap the args and set up the correct parameterisation of |
| 1824 | VG_(generic_match), using supploc_IsStar, supploc_IsQuery and |
| 1825 | supp_pattEQinp. */ |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1826 | /* note, StackTrace ip2fo->ips === Addr* */ |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1827 | SuppLoc* supps = su->callers; |
| 1828 | UWord n_supps = su->n_callers; |
| 1829 | UWord szbPatt = sizeof(SuppLoc); |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1830 | Bool matchAll = False; /* we just want to match a prefix */ |
philippe | 5ab7ce8 | 2014-06-24 20:48:25 +0000 | [diff] [blame] | 1831 | if (DEBUG_ERRORMGR) |
| 1832 | VG_(dmsg)(" errormgr Checking match with %s %s:%d\n", |
| 1833 | su->sname, |
| 1834 | VG_(clo_suppressions)[su->clo_suppressions_i], |
| 1835 | su->sname_lineno); |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1836 | return |
| 1837 | VG_(generic_match)( |
| 1838 | matchAll, |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1839 | /*PATT*/supps, szbPatt, n_supps, 0/*initial ixPatt*/, |
| 1840 | /*INPUT*/ |
| 1841 | NULL, 0, 0, /* input/szbInput/nInput 0, as using an inputCompleter */ |
| 1842 | 0/*initial ixInput*/, |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1843 | supploc_IsStar, supploc_IsQuery, supp_pattEQinp, |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1844 | ip2fo, haveInputInpC |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1845 | ); |
| 1846 | } |
| 1847 | |
| 1848 | ///////////////////////////////////////////////////// |
| 1849 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1850 | static |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1851 | Bool supp_matches_error(Supp* su, Error* err) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1852 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1853 | switch (su->skind) { |
njn | a86f29e | 2006-12-14 02:55:58 +0000 | [diff] [blame] | 1854 | //(example code, see comment on CoreSuppKind above) |
| 1855 | //case ThreadSupp: |
| 1856 | // return (err->ekind == ThreadErr); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1857 | default: |
njn | 95ec870 | 2004-11-22 16:46:13 +0000 | [diff] [blame] | 1858 | if (VG_(needs).tool_errors) { |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1859 | return VG_TDICT_CALL(tool_error_matches_suppression, err, su); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1860 | } else { |
| 1861 | VG_(printf)( |
njn | 95ec870 | 2004-11-22 16:46:13 +0000 | [diff] [blame] | 1862 | "\nUnhandled suppression type: %u. VG_(needs).tool_errors\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1863 | "probably needs to be set.\n", |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1864 | err->ekind); |
njn | 6799325 | 2004-11-22 18:02:32 +0000 | [diff] [blame] | 1865 | VG_(tool_panic)("unhandled suppression type"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1866 | } |
| 1867 | } |
| 1868 | } |
| 1869 | |
sewardj | d7a02db | 2008-12-12 08:07:49 +0000 | [diff] [blame] | 1870 | ///////////////////////////////////////////////////// |
sewardj | 5e51930 | 2008-11-03 23:10:25 +0000 | [diff] [blame] | 1871 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1872 | /* Does an error context match a suppression? ie is this a suppressible |
| 1873 | error? If so, return a pointer to the Supp record, otherwise NULL. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1874 | Tries to minimise the number of symbol searches since they are expensive. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1875 | */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1876 | static Supp* is_suppressible_error ( Error* err ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1877 | { |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1878 | Supp* su; |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1879 | Supp* su_prev; |
| 1880 | |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1881 | IPtoFunOrObjCompleter ip2fo; |
| 1882 | /* Conceptually, ip2fo contains an array of function names and an array of |
| 1883 | object names, corresponding to the array of IP of err->where. |
| 1884 | These names are just computed 'on demand' (so once maximum), |
philippe | 4e32d67 | 2013-10-17 22:10:41 +0000 | [diff] [blame] | 1885 | then stored (efficiently, avoiding too many allocs) in ip2fo to be |
| 1886 | re-usable for the matching of the same IP with the next suppression |
| 1887 | pattern. |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1888 | |
| 1889 | VG_(generic_match) gets this 'IP to Fun or Obj name completer' as one |
| 1890 | of its arguments. It will then pass it to the function |
| 1891 | supp_pattEQinp which will then lazily complete the IP function name or |
| 1892 | object name inside ip2fo. Next time the fun or obj name for the same |
| 1893 | IP is needed (i.e. for the matching with the next suppr pattern), then |
| 1894 | the fun or obj name will not be searched again in the debug info. */ |
| 1895 | |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1896 | /* stats gathering */ |
| 1897 | em_supplist_searches++; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1898 | |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1899 | /* Prepare the lazy input completer. */ |
| 1900 | ip2fo.ips = VG_(get_ExeContext_StackTrace)(err->where); |
| 1901 | ip2fo.n_ips = VG_(get_ExeContext_n_ips)(err->where); |
philippe | a0a7393 | 2014-06-15 15:42:20 +0000 | [diff] [blame] | 1902 | ip2fo.n_ips_expanded = 0; |
| 1903 | ip2fo.n_expanded = 0; |
| 1904 | ip2fo.sz_offsets = 0; |
| 1905 | ip2fo.n_offsets_per_ip = NULL; |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1906 | ip2fo.fun_offsets = NULL; |
| 1907 | ip2fo.obj_offsets = NULL; |
| 1908 | ip2fo.names = NULL; |
| 1909 | ip2fo.names_szB = 0; |
| 1910 | ip2fo.names_free = 0; |
| 1911 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1912 | /* See if the error context matches any suppression. */ |
philippe | 5ab7ce8 | 2014-06-24 20:48:25 +0000 | [diff] [blame] | 1913 | if (DEBUG_ERRORMGR || VG_(debugLog_getLevel)() >= 4) |
| 1914 | VG_(dmsg)("errormgr matching begin\n"); |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1915 | su_prev = NULL; |
njn | 695c16e | 2005-03-27 03:40:28 +0000 | [diff] [blame] | 1916 | for (su = suppressions; su != NULL; su = su->next) { |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1917 | em_supplist_cmps++; |
philippe | 13a5952 | 2012-08-03 23:11:39 +0000 | [diff] [blame] | 1918 | if (supp_matches_error(su, err) |
| 1919 | && supp_matches_callers(&ip2fo, su)) { |
philippe | 4e32d67 | 2013-10-17 22:10:41 +0000 | [diff] [blame] | 1920 | /* got a match. */ |
| 1921 | /* Inform the tool that err is suppressed by su. */ |
| 1922 | (void)VG_TDICT_CALL(tool_update_extra_suppression_use, err, su); |
| 1923 | /* Move this entry to the head of the list |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1924 | in the hope of making future searches cheaper. */ |
| 1925 | if (su_prev) { |
| 1926 | vg_assert(su_prev->next == su); |
| 1927 | su_prev->next = su->next; |
| 1928 | su->next = suppressions; |
| 1929 | suppressions = su; |
| 1930 | } |
philippe | 5ab7ce8 | 2014-06-24 20:48:25 +0000 | [diff] [blame] | 1931 | clearIPtoFunOrObjCompleter(su, &ip2fo); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1932 | return su; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1933 | } |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1934 | su_prev = su; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1935 | } |
philippe | 5ab7ce8 | 2014-06-24 20:48:25 +0000 | [diff] [blame] | 1936 | clearIPtoFunOrObjCompleter(NULL, &ip2fo); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1937 | return NULL; /* no matches */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1938 | } |
| 1939 | |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1940 | /* Show accumulated error-list and suppression-list search stats. |
| 1941 | */ |
| 1942 | void VG_(print_errormgr_stats) ( void ) |
| 1943 | { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1944 | VG_(dmsg)( |
| 1945 | " errormgr: %'lu supplist searches, %'lu comparisons during search\n", |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1946 | em_supplist_searches, em_supplist_cmps |
| 1947 | ); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1948 | VG_(dmsg)( |
| 1949 | " errormgr: %'lu errlist searches, %'lu comparisons during search\n", |
sewardj | 8a7d4e4 | 2006-10-17 01:41:17 +0000 | [diff] [blame] | 1950 | em_errlist_searches, em_errlist_cmps |
| 1951 | ); |
| 1952 | } |
| 1953 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1954 | /*--------------------------------------------------------------------*/ |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 1955 | /*--- end ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1956 | /*--------------------------------------------------------------------*/ |