drd/tests/swapcontext: Improve the portability of this test further
[valgrind.git] / drd / drd_error.h
blob742cd43a04b9d169e3438ef71bc76e2e9a635400
1 /*
2 This file is part of drd, a thread error detector.
4 Copyright (C) 2006-2020 Bart Van Assche <bvanassche@acm.org>.
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
19 The GNU General Public License is contained in the file COPYING.
23 #ifndef __DRD_ERROR_H
24 #define __DRD_ERROR_H
27 #include "pub_drd_bitmap.h" // BmAccessTypeT
28 #include "drd_thread.h" // DrdThreadId
29 #include "pub_tool_basics.h" // SizeT
30 #include "pub_tool_debuginfo.h" // SegInfo
31 #include "pub_tool_errormgr.h" // ExeContext
34 /* DRD error types. */
36 typedef enum {
37 #define STR_DataRaceErr "ConflictingAccess"
38 DataRaceErr = 1,
39 #define STR_MutexErr "MutexErr"
40 MutexErr = 2,
41 #define STR_CondErr "CondErr"
42 CondErr = 3,
43 #define STR_CondDestrErr "CondDestrErr"
44 CondDestrErr = 4,
45 #define STR_CondRaceErr "CondRaceErr"
46 CondRaceErr = 5,
47 #define STR_CondWaitErr "CondWaitErr"
48 CondWaitErr = 6,
49 #define STR_SemaphoreErr "SemaphoreErr"
50 SemaphoreErr = 7,
51 #define STR_BarrierErr "BarrierErr"
52 BarrierErr = 8,
53 #define STR_RwlockErr "RwlockErr"
54 RwlockErr = 9,
55 #define STR_HoldtimeErr "HoldtimeErr"
56 HoldtimeErr = 10,
57 #define STR_GenericErr "GenericErr"
58 GenericErr = 11,
59 #define STR_InvalidThreadId "InvalidThreadId"
60 InvalidThreadId = 12,
61 #define STR_UnimpHgClReq "UnimpHgClReq"
62 UnimpHgClReq = 13,
63 #define STR_UnimpDrdClReq "UnimpDrdClReq"
64 UnimpDrdClReq = 14,
65 } DrdErrorKind;
67 /* The classification of a faulting address. */
68 typedef
69 enum {
70 //Undescribed, // as-yet unclassified
71 eStack,
72 eUnknown, // classification yielded nothing useful
73 //Freed,
74 eMallocd,
75 eSegment, // in a segment (as defined in pub_tool_debuginfo.h)
76 //UserG, // in a user-defined block
77 //Mempool, // in a mempool
78 //Register, // in a register; for Param errors only
80 AddrKind;
82 /* Records info about a faulting address. */
83 typedef
84 struct { // Used by:
85 AddrKind akind; // ALL
86 SizeT size; // ALL
87 PtrdiffT rwoffset; // ALL
88 ExeContext* lastchange; // Mallocd
89 DrdThreadId stack_tid; // Stack
90 DebugInfo* debuginfo; // Segment
91 HChar name[256]; // Segment
92 HChar descr[256]; // Segment
93 } AddrInfo;
96 * NOTE: the first member of each error info structure MUST be the thread ID
97 * in which the error has been observed.
99 typedef struct {
100 DrdThreadId tid; // Thread ID of the running thread.
101 Addr addr; // Conflicting address in current thread.
102 SizeT size; // Size in bytes of conflicting operation.
103 BmAccessTypeT access_type; // Access type: load or store.
104 } DataRaceErrInfo;
106 typedef struct {
107 DrdThreadId tid;
108 Addr mutex;
109 Int recursion_count;
110 DrdThreadId owner;
111 } MutexErrInfo;
113 typedef struct {
114 DrdThreadId tid;
115 Addr cond;
116 } CondErrInfo;
118 typedef struct {
119 DrdThreadId tid;
120 Addr cond;
121 Addr mutex;
122 DrdThreadId owner;
123 } CondDestrErrInfo;
125 typedef struct {
126 DrdThreadId tid;
127 Addr cond;
128 Addr mutex;
129 } CondRaceErrInfo;
131 typedef struct {
132 DrdThreadId tid;
133 Addr cond;
134 Addr mutex1;
135 Addr mutex2;
136 } CondWaitErrInfo;
138 typedef struct {
139 DrdThreadId tid;
140 Addr semaphore;
141 } SemaphoreErrInfo;
143 typedef struct {
144 DrdThreadId tid;
145 Addr barrier;
146 DrdThreadId other_tid;
147 ExeContext* other_context;
148 } BarrierErrInfo;
150 typedef struct {
151 DrdThreadId tid;
152 Addr rwlock;
153 } RwlockErrInfo;
155 typedef struct {
156 DrdThreadId tid;
157 Addr synchronization_object;
158 ExeContext* acquired_at;
159 UInt hold_time_ms;
160 UInt threshold_ms;
161 } HoldtimeErrInfo;
163 typedef struct {
164 DrdThreadId tid;
165 Addr addr;
166 } GenericErrInfo;
168 typedef struct {
169 DrdThreadId tid;
170 ULong ptid;
171 } InvalidThreadIdInfo;
173 typedef struct {
174 DrdThreadId tid;
175 HChar* descr;
176 } UnimpClReqInfo;
178 void DRD_(set_show_conflicting_segments)(const Bool scs);
179 void DRD_(register_error_handlers)(void);
180 void DRD_(trace_msg)(const HChar* format, ...) PRINTF_CHECK(1, 2);
181 void DRD_(trace_msg_w_bt)(const HChar* format, ...) PRINTF_CHECK(1, 2);
184 #endif /* __DRD_ERROR_H */