blob: 7a2bbac8d766f1b8d12d5a72aaeee003bdc526e7 [file] [log] [blame]
sewardjaf44c822007-11-25 14:01:38 +00001/*
bart86562bd2009-02-16 19:43:56 +00002 This file is part of drd, a thread error detector.
sewardjaf44c822007-11-25 14:01:38 +00003
Elliott Hughesed398002017-06-21 14:41:24 -07004 Copyright (C) 2006-2017 Bart Van Assche <bvanassche@acm.org>.
sewardjaf44c822007-11-25 14:01:38 +00005
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.
10
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.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307, USA.
20
21 The GNU General Public License is contained in the file COPYING.
22*/
23
24
25#ifndef __DRD_ERROR_H
26#define __DRD_ERROR_H
27
28
bartb515eb12008-03-07 18:52:38 +000029#include "pub_drd_bitmap.h" // BmAccessTypeT
sewardjaf44c822007-11-25 14:01:38 +000030#include "drd_thread.h" // DrdThreadId
31#include "pub_tool_basics.h" // SizeT
32#include "pub_tool_debuginfo.h" // SegInfo
33#include "pub_tool_errormgr.h" // ExeContext
34
35
36/* DRD error types. */
37
38typedef enum {
bart5fc70e62008-03-23 07:54:02 +000039#define STR_DataRaceErr "ConflictingAccess"
sewardjaf44c822007-11-25 14:01:38 +000040 DataRaceErr = 1,
bart5fc70e62008-03-23 07:54:02 +000041#define STR_MutexErr "MutexErr"
sewardjaf44c822007-11-25 14:01:38 +000042 MutexErr = 2,
bart5fc70e62008-03-23 07:54:02 +000043#define STR_CondErr "CondErr"
bart3b1ee452008-02-29 19:28:15 +000044 CondErr = 3,
bart5fc70e62008-03-23 07:54:02 +000045#define STR_CondDestrErr "CondDestrErr"
bart3bb1cec2008-06-28 16:01:43 +000046 CondDestrErr = 4,
47#define STR_CondRaceErr "CondRaceErr"
48 CondRaceErr = 5,
49#define STR_CondWaitErr "CondWaitErr"
50 CondWaitErr = 6,
bart5fc70e62008-03-23 07:54:02 +000051#define STR_SemaphoreErr "SemaphoreErr"
bart3bb1cec2008-06-28 16:01:43 +000052 SemaphoreErr = 7,
bart5fc70e62008-03-23 07:54:02 +000053#define STR_BarrierErr "BarrierErr"
bart3bb1cec2008-06-28 16:01:43 +000054 BarrierErr = 8,
bart5fc70e62008-03-23 07:54:02 +000055#define STR_RwlockErr "RwlockErr"
bart3bb1cec2008-06-28 16:01:43 +000056 RwlockErr = 9,
bart9d5b7962008-05-14 12:25:00 +000057#define STR_HoldtimeErr "HoldtimeErr"
bart3bb1cec2008-06-28 16:01:43 +000058 HoldtimeErr = 10,
bart5fc70e62008-03-23 07:54:02 +000059#define STR_GenericErr "GenericErr"
bart3bb1cec2008-06-28 16:01:43 +000060 GenericErr = 11,
bartb48bde22009-07-31 08:26:17 +000061#define STR_InvalidThreadId "InvalidThreadId"
62 InvalidThreadId = 12,
bart141a7ed2010-03-21 17:28:10 +000063#define STR_UnimpHgClReq "UnimpHgClReq"
64 UnimpHgClReq = 13,
65#define STR_UnimpDrdClReq "UnimpDrdClReq"
66 UnimpDrdClReq = 14,
sewardjaf44c822007-11-25 14:01:38 +000067} DrdErrorKind;
68
69/* The classification of a faulting address. */
bart31b983d2010-02-21 14:52:59 +000070typedef
71enum {
sewardjaf44c822007-11-25 14:01:38 +000072 //Undescribed, // as-yet unclassified
bart31b983d2010-02-21 14:52:59 +000073 eStack,
sewardjaf44c822007-11-25 14:01:38 +000074 eUnknown, // classification yielded nothing useful
75 //Freed,
bart31b983d2010-02-21 14:52:59 +000076 eMallocd,
sewardjaf44c822007-11-25 14:01:38 +000077 eSegment, // in a segment (as defined in pub_tool_debuginfo.h)
78 //UserG, // in a user-defined block
79 //Mempool, // in a mempool
80 //Register, // in a register; for Param errors only
81}
82 AddrKind;
83
84/* Records info about a faulting address. */
85typedef
86struct { // Used by:
87 AddrKind akind; // ALL
88 SizeT size; // ALL
njnc4431bf2009-01-15 21:29:24 +000089 PtrdiffT rwoffset; // ALL
sewardjaf44c822007-11-25 14:01:38 +000090 ExeContext* lastchange; // Mallocd
91 DrdThreadId stack_tid; // Stack
sewardjb8b79ad2008-03-03 01:35:41 +000092 DebugInfo* debuginfo; // Segment
florian19f91bb2012-11-10 22:29:54 +000093 HChar name[256]; // Segment
94 HChar descr[256]; // Segment
bartd45d9952009-05-31 18:53:54 +000095} AddrInfo;
sewardjaf44c822007-11-25 14:01:38 +000096
bartd45d9952009-05-31 18:53:54 +000097/*
98 * NOTE: the first member of each error info structure MUST be the thread ID
99 * in which the error has been observed.
100 */
sewardjaf44c822007-11-25 14:01:38 +0000101typedef struct {
bart354009c2008-03-16 10:42:33 +0000102 DrdThreadId tid; // Thread ID of the running thread.
sewardjaf44c822007-11-25 14:01:38 +0000103 Addr addr; // Conflicting address in current thread.
104 SizeT size; // Size in bytes of conflicting operation.
105 BmAccessTypeT access_type; // Access type: load or store.
106} DataRaceErrInfo;
107
108typedef struct {
bartd45d9952009-05-31 18:53:54 +0000109 DrdThreadId tid;
110 Addr mutex;
111 Int recursion_count;
sewardjaf44c822007-11-25 14:01:38 +0000112 DrdThreadId owner;
113} MutexErrInfo;
114
115typedef struct {
bartd45d9952009-05-31 18:53:54 +0000116 DrdThreadId tid;
117 Addr cond;
bart3b1ee452008-02-29 19:28:15 +0000118} CondErrInfo;
119
120typedef struct {
bartd45d9952009-05-31 18:53:54 +0000121 DrdThreadId tid;
bart3bb1cec2008-06-28 16:01:43 +0000122 Addr cond;
123 Addr mutex;
bartd45d9952009-05-31 18:53:54 +0000124 DrdThreadId owner;
bart3bb1cec2008-06-28 16:01:43 +0000125} CondDestrErrInfo;
126
127typedef struct {
bartd45d9952009-05-31 18:53:54 +0000128 DrdThreadId tid;
129 Addr cond;
130 Addr mutex;
sewardjaf44c822007-11-25 14:01:38 +0000131} CondRaceErrInfo;
132
133typedef struct {
bartd45d9952009-05-31 18:53:54 +0000134 DrdThreadId tid;
135 Addr cond;
136 Addr mutex1;
137 Addr mutex2;
bart3bb1cec2008-06-28 16:01:43 +0000138} CondWaitErrInfo;
bart3b1ee452008-02-29 19:28:15 +0000139
140typedef struct {
bartd45d9952009-05-31 18:53:54 +0000141 DrdThreadId tid;
142 Addr semaphore;
bart3b1ee452008-02-29 19:28:15 +0000143} SemaphoreErrInfo;
144
145typedef struct {
bartd45d9952009-05-31 18:53:54 +0000146 DrdThreadId tid;
bartd2c5eae2009-02-21 15:27:04 +0000147 Addr barrier;
148 DrdThreadId other_tid;
149 ExeContext* other_context;
bart3b1ee452008-02-29 19:28:15 +0000150} BarrierErrInfo;
sewardjaf44c822007-11-25 14:01:38 +0000151
barte883bc82008-02-26 19:13:04 +0000152typedef struct {
bartd45d9952009-05-31 18:53:54 +0000153 DrdThreadId tid;
154 Addr rwlock;
bart777f7fe2008-03-02 17:43:18 +0000155} RwlockErrInfo;
156
157typedef struct {
bartd45d9952009-05-31 18:53:54 +0000158 DrdThreadId tid;
bartbedfd232009-03-26 19:07:15 +0000159 Addr synchronization_object;
160 ExeContext* acquired_at;
161 UInt hold_time_ms;
162 UInt threshold_ms;
bart9d5b7962008-05-14 12:25:00 +0000163} HoldtimeErrInfo;
164
165typedef struct {
bartd45d9952009-05-31 18:53:54 +0000166 DrdThreadId tid;
bart62cc2322010-03-07 10:54:21 +0000167 Addr addr;
barte883bc82008-02-26 19:13:04 +0000168} GenericErrInfo;
169
bartb48bde22009-07-31 08:26:17 +0000170typedef struct {
171 DrdThreadId tid;
172 ULong ptid;
173} InvalidThreadIdInfo;
bart16d76e52008-03-18 17:08:08 +0000174
bart66f196d2009-08-15 10:50:35 +0000175typedef struct {
176 DrdThreadId tid;
florian19f91bb2012-11-10 22:29:54 +0000177 HChar* descr;
bart66f196d2009-08-15 10:50:35 +0000178} UnimpClReqInfo;
179
bart246fbf22009-02-15 14:46:17 +0000180void DRD_(set_show_conflicting_segments)(const Bool scs);
bart1335ecc2009-02-14 16:10:53 +0000181void DRD_(register_error_handlers)(void);
florian19f91bb2012-11-10 22:29:54 +0000182void DRD_(trace_msg)(const HChar* format, ...) PRINTF_CHECK(1, 2);
183void DRD_(trace_msg_w_bt)(const HChar* format, ...) PRINTF_CHECK(1, 2);
sewardjaf44c822007-11-25 14:01:38 +0000184
185
186#endif /* __DRD_ERROR_H */