blob: 7af6783f10a175e4cdf9367e40f77d60ca224446 [file] [log] [blame]
njnd2b17112005-04-19 04:10:25 +00001/*--------------------------------------------------------------------*/
2/*--- ErrorMgr: management of errors and suppressions. ---*/
3/*--- pub_tool_errormgr.h ---*/
4/*--------------------------------------------------------------------*/
5
6/*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
9
Elliott Hughesed398002017-06-21 14:41:24 -070010 Copyright (C) 2000-2017 Julian Seward
njnd2b17112005-04-19 04:10:25 +000011 jseward@acm.org
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
28 The GNU General Public License is contained in the file COPYING.
29*/
30
31#ifndef __PUB_TOOL_ERRORMGR_H
32#define __PUB_TOOL_ERRORMGR_H
33
34#include "pub_tool_execontext.h"
35
36/* ------------------------------------------------------------------ */
37/* Error records contain enough info to generate an error report. The idea
38 is that (typically) the same few points in the program generate thousands
39 of errors, and we don't want to spew out a fresh error message for each
40 one. Instead, we use these structures to common up duplicates.
41*/
42
43typedef
44 Int /* Do not make this unsigned! */
45 ErrorKind;
46
47/* The tool-relevant parts of an Error are:
48 kind: what kind of error; must be in the range (0..)
49 addr: use is optional. 0 by default.
50 string: use is optional. NULL by default.
51 extra: use is optional. NULL by default. void* so it's extensible.
52*/
53typedef
54 struct _Error
55 Error;
56
njn51d827b2005-05-09 01:02:08 +000057/* Useful in VG_(tdict).tool_error_matches_suppression(),
58 * VG_(tdict).tool_pp_Error(), etc */
florian8e3fbb52014-10-20 19:02:38 +000059ExeContext* VG_(get_error_where) ( const Error* err );
60ErrorKind VG_(get_error_kind) ( const Error* err );
61Addr VG_(get_error_address) ( const Error* err );
62const HChar* VG_(get_error_string) ( const Error* err );
63void* VG_(get_error_extra) ( const Error* err );
njnd2b17112005-04-19 04:10:25 +000064
65/* Call this when an error occurs. It will be recorded if it hasn't been
66 seen before. If it has, the existing error record will have its count
67 incremented.
68
philippec06f6842014-07-30 22:20:29 +000069 'tid' can be found as for VG_(record_ExeContext)(). The `s' string
70 and `extra' field can be stack-allocated; they will be copied by the core
71 if needed (but it won't be copied if it's NULL).
72 Note that `ekind' and `s' are also used to generate a suppression.
73 `s' should therefore not contain data depending on the specific
74 execution (such as addresses, values) but should rather contain
75 e.g. a system call parameter symbolic name.
76 `extra' is also (optionally) used for generating a suppression
77 (see pub_tool_tooliface.h print_extra_suppression_info).
njnd2b17112005-04-19 04:10:25 +000078
79 If no 'a', 's' or 'extra' of interest needs to be recorded, just use
80 NULL for them. */
81extern void VG_(maybe_record_error) ( ThreadId tid, ErrorKind ekind,
floriane543f302012-10-21 19:43:43 +000082 Addr a, const HChar* s, void* extra );
njnd2b17112005-04-19 04:10:25 +000083
84/* Similar to VG_(maybe_record_error)(), except this one doesn't record the
85 error -- useful for errors that can only happen once. The errors can be
86 suppressed, though. Return value is True if it was suppressed.
njn02977032005-05-17 04:00:11 +000087 'print_error' dictates whether to print the error, which is a bit of a
njnd2b17112005-04-19 04:10:25 +000088 hack that's useful sometimes if you just want to know if the error would
njn02977032005-05-17 04:00:11 +000089 be suppressed without possibly printing it. 'count_error' dictates
njnd2b17112005-04-19 04:10:25 +000090 whether to add the error in the error total count (another mild hack). */
91extern Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind,
floriane543f302012-10-21 19:43:43 +000092 Addr a, const HChar* s, void* extra,
njnd2b17112005-04-19 04:10:25 +000093 ExeContext* where, Bool print_error,
njn18afe5d2009-08-10 08:25:39 +000094 Bool allow_GDB_attach, Bool count_error );
njnd2b17112005-04-19 04:10:25 +000095
philippe2193a7c2012-12-08 17:54:16 +000096/* Gets from fd (an opened suppression file) a non-blank, non-comment
97 line containing suppression extra information (e.g. the syscall
98 line for the Param memcheck suppression kind. bufpp is a pointer
florian0acd3ce2014-09-01 15:56:05 +000099 to a buffer that must be allocated with VG_(malloc);
philippe2193a7c2012-12-08 17:54:16 +0000100 nBufp is a pointer to size_t holding its size; if the buffer is too
101 small for the line, it will be realloc'd until big enough (updating
102 *bufpp and *nBufp in the process). (It will bomb out if the size
103 gets ridiculous). Skips leading spaces on the line. Increments
florian190bd522014-09-01 21:03:54 +0000104 *lineno with the number of lines read. Returns True if no extra
105 information line could be read. */
florian19f91bb2012-11-10 22:29:54 +0000106extern Bool VG_(get_line) ( Int fd, HChar** bufpp, SizeT* nBufp, Int* lineno );
njnd2b17112005-04-19 04:10:25 +0000107
108
109/* ------------------------------------------------------------------ */
110/* Suppressions describe errors which we want to suppress, ie, not
111 show the user, usually because it is caused by a problem in a library
112 which we can't fix, replace or work around. Suppressions are read from
113 a file at startup time. This gives flexibility so that new
114 suppressions can be added to the file as and when needed.
115*/
116typedef
117 Int /* Do not make this unsigned! */
118 SuppKind;
119
120/* The tool-relevant parts of a suppression are:
121 kind: what kind of suppression; must be in the range (0..)
122 string: use is optional. NULL by default.
123 extra: use is optional. NULL by default. void* so it's extensible.
124*/
125typedef
126 struct _Supp
127 Supp;
128
njn51d827b2005-05-09 01:02:08 +0000129/* Useful in VG_(tdict).tool_error_matches_suppression() */
florian8e3fbb52014-10-20 19:02:38 +0000130SuppKind VG_(get_supp_kind) ( const Supp* su );
131HChar* VG_(get_supp_string) ( const Supp* su );
132void* VG_(get_supp_extra) ( const Supp* su );
njnd2b17112005-04-19 04:10:25 +0000133
134/* Must be used in VG_(recognised_suppression)() */
135void VG_(set_supp_kind) ( Supp* su, SuppKind suppkind );
136/* May be used in VG_(read_extra_suppression_info)() */
florian19f91bb2012-11-10 22:29:54 +0000137void VG_(set_supp_string) ( Supp* su, HChar* string );
njnd2b17112005-04-19 04:10:25 +0000138void VG_(set_supp_extra) ( Supp* su, void* extra );
139
140
141#endif // __PUB_TOOL_ERRORMGR_H
142
143/*--------------------------------------------------------------------*/
144/*--- end ---*/
145/*--------------------------------------------------------------------*/