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