sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1 | /* |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 2 | This file is part of drd, a thread error detector. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 3 | |
bart | d4bab99 | 2013-10-04 05:55:30 +0000 | [diff] [blame] | 4 | Copyright (C) 2006-2013 Bart Van Assche <bvanassche@acm.org>. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 5 | |
| 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 __SEGMENT_H |
| 26 | #define __SEGMENT_H |
| 27 | |
| 28 | |
bart | 62ada3f | 2009-02-14 17:19:58 +0000 | [diff] [blame] | 29 | /* |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 30 | * Segments and segment lists. A segment represents information about |
bart | 62ada3f | 2009-02-14 17:19:58 +0000 | [diff] [blame] | 31 | * a contiguous group of statements of a specific thread. There is a vector |
| 32 | * clock associated with each segment. |
| 33 | */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 34 | |
| 35 | |
| 36 | #include "drd_vc.h" |
| 37 | #include "pub_drd_bitmap.h" |
| 38 | #include "pub_tool_execontext.h" // ExeContext |
| 39 | #include "pub_tool_stacktrace.h" // StackTrace |
| 40 | |
| 41 | |
| 42 | typedef struct segment |
| 43 | { |
bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 44 | struct segment* g_next; |
| 45 | struct segment* g_prev; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 46 | /** Pointers to next and previous segments executed by the same thread. */ |
bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 47 | struct segment* thr_next; |
| 48 | struct segment* thr_prev; |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 49 | DrdThreadId tid; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 50 | /** Reference count: number of pointers that point to this segment. */ |
| 51 | int refcnt; |
| 52 | /** Stack trace of the first instruction of the segment. */ |
| 53 | ExeContext* stacktrace; |
| 54 | /** Vector clock associated with the segment. */ |
| 55 | VectorClock vc; |
| 56 | /** |
| 57 | * Bitmap representing the memory accesses by the instructions associated |
| 58 | * with the segment. |
| 59 | */ |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 60 | struct bitmap bm; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 61 | } Segment; |
| 62 | |
bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 63 | extern Segment* DRD_(g_sg_list); |
bart | a2b6e1b | 2008-03-17 18:32:39 +0000 | [diff] [blame] | 64 | |
bart | 2adfc2a | 2009-03-12 18:38:00 +0000 | [diff] [blame] | 65 | Segment* DRD_(sg_new)(const DrdThreadId creator, const DrdThreadId created); |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 66 | static int DRD_(sg_get_refcnt)(const Segment* const sg); |
bart | 62ada3f | 2009-02-14 17:19:58 +0000 | [diff] [blame] | 67 | Segment* DRD_(sg_get)(Segment* const sg); |
| 68 | void DRD_(sg_put)(Segment* const sg); |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 69 | static struct bitmap* DRD_(sg_bm)(Segment* const sg); |
| 70 | void DRD_(sg_merge)(Segment* const sg1, Segment* const sg2); |
| 71 | void DRD_(sg_print)(Segment* const sg); |
bart | 62ada3f | 2009-02-14 17:19:58 +0000 | [diff] [blame] | 72 | Bool DRD_(sg_get_trace)(void); |
| 73 | void DRD_(sg_set_trace)(const Bool trace_segment); |
| 74 | ULong DRD_(sg_get_segments_created_count)(void); |
| 75 | ULong DRD_(sg_get_segments_alive_count)(void); |
| 76 | ULong DRD_(sg_get_max_segments_alive_count)(void); |
bart | 1a3b0b3 | 2009-05-03 17:07:34 +0000 | [diff] [blame] | 77 | ULong DRD_(sg_get_segment_merge_count)(void); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 78 | |
| 79 | |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 80 | /** Query the reference count of the specified segment. */ |
| 81 | static __inline__ int DRD_(sg_get_refcnt)(const Segment* const sg) |
| 82 | { |
| 83 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 84 | tl_assert(sg); |
| 85 | #endif |
| 86 | |
| 87 | return sg->refcnt; |
| 88 | } |
| 89 | |
| 90 | /** Return the pointer to the bitmap of the segment. */ |
| 91 | static __inline__ struct bitmap* DRD_(sg_bm)(Segment* const sg) |
| 92 | { |
| 93 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 94 | tl_assert(sg); |
| 95 | #endif |
| 96 | |
| 97 | return &sg->bm; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 102 | #endif // __SEGMENT_H |