OSDN Git Service

6f5b3c8677d86dc4009127a4f14e9870627cbd50
[pf3gnuchains/gcc-fork.git] / boehm-gc / include / private / dbg_mlc.h
1 /* 
2  * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3  * Copyright (c) 1991-1995 by Xerox Corporation.  All rights reserved.
4  * Copyright (c) 1997 by Silicon Graphics.  All rights reserved.
5  * Copyright (c) 1999 by Hewlett-Packard Company.  All rights reserved.
6  *
7  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
9  *
10  * Permission is hereby granted to use or copy this program
11  * for any purpose,  provided the above notices are retained on all copies.
12  * Permission to modify the code and to distribute modified code is granted,
13  * provided the above notices are retained, and a notice that the code was
14  * modified is included with the above copyright notice.
15  */
16
17 /*
18  * This is mostly an internal header file.  Typical clients should
19  * not use it.  Clients that define their own object kinds with
20  * debugging allocators will probably want to include this, however.
21  * No attempt is made to keep the namespace clean.  This should not be
22  * included from header files that are frequently included by clients.
23  */
24
25 #ifndef _DBG_MLC_H
26
27 #define _DBG_MLC_H
28
29 # define I_HIDE_POINTERS
30 # include "gc_priv.h"
31 # ifdef KEEP_BACK_PTRS
32 #   include "gc_backptr.h"
33 # endif
34
35 #ifndef HIDE_POINTER
36   /* Gc.h was previously included, and hence the I_HIDE_POINTERS        */
37   /* definition had no effect.  Repeat the gc.h definitions here to     */
38   /* get them anyway.                                                   */
39     typedef GC_word GC_hidden_pointer;
40 #   define HIDE_POINTER(p) (~(GC_hidden_pointer)(p))
41 #   define REVEAL_POINTER(p) ((GC_PTR)(HIDE_POINTER(p)))
42 #endif /* HIDE_POINTER */
43
44 # define START_FLAG ((word)0xfedcedcb)
45 # define END_FLAG ((word)0xbcdecdef)
46         /* Stored both one past the end of user object, and one before  */
47         /* the end of the object as seen by the allocator.              */
48
49 # if defined(KEEP_BACK_PTRS) || defined(PRINT_BLACK_LIST)
50     /* Pointer "source"s that aren't real locations.    */
51     /* Used in oh_back_ptr fields and as "source"       */
52     /* argument to some marking functions.              */
53 #       define NOT_MARKED (ptr_t)(0)
54 #       define MARKED_FOR_FINALIZATION (ptr_t)(2)
55             /* Object was marked because it is finalizable.     */
56 #       define MARKED_FROM_REGISTER (ptr_t)(4)
57             /* Object was marked from a rgister.  Hence the     */
58             /* source of the reference doesn't have an address. */
59 # endif /* KEEP_BACK_PTRS || PRINT_BLACK_LIST */
60
61 /* Object header */
62 typedef struct {
63 #   ifdef KEEP_BACK_PTRS
64         GC_hidden_pointer oh_back_ptr;
65             /* We make sure that we only store even valued      */
66             /* pointers here, so that the hidden version has    */
67             /* the least significant bit set.  We never         */
68             /* overwrite a value with the least significant     */
69             /* bit clear, thus ensuring that we never overwrite */
70             /* a free list link field.                          */
71             /* Note that blocks dropped by black-listing will   */
72             /* also have the lsb clear once debugging has       */
73             /* started.                                         */
74             /* The following are special back pointer values.   */
75             /* Note that the "hidden" (i.e. bitwise             */
76             /* complemented version) of these is actually       */
77             /* stored.                                          */
78 #       if ALIGNMENT == 1
79           /* Fudge back pointer to be even.  */
80 #         define HIDE_BACK_PTR(p) HIDE_POINTER(~1 & (GC_word)(p))
81 #       else
82 #         define HIDE_BACK_PTR(p) HIDE_POINTER(p)
83 #       endif
84 #       ifdef ALIGN_DOUBLE
85           word oh_dummy;
86 #       endif
87 #   endif
88     GC_CONST char * oh_string;  /* object descriptor string     */
89     word oh_int;                /* object descriptor integers   */
90 #   ifdef NEED_CALLINFO
91       struct callinfo oh_ci[NFRAMES];
92 #   endif
93 #   ifndef SHORT_DBG_HDRS
94       word oh_sz;                       /* Original malloc arg.         */
95       word oh_sf;                       /* start flag */
96 #   endif /* SHORT_DBG_HDRS */
97 } oh;
98 /* The size of the above structure is assumed not to dealign things,    */
99 /* and to be a multiple of the word length.                             */
100
101 #ifdef SHORT_DBG_HDRS
102 #   define DEBUG_BYTES (sizeof (oh))
103 #else
104     /* Add space for END_FLAG, but use any extra space that was already */
105     /* added to catch off-the-end pointers.                             */
106 #   define DEBUG_BYTES (sizeof (oh) + sizeof (word) - EXTRA_BYTES)
107 #endif
108 #define USR_PTR_FROM_BASE(p) ((ptr_t)(p) + sizeof(oh))
109
110 /* Round bytes to words without adding extra byte at end.       */
111 #define SIMPLE_ROUNDED_UP_WORDS(n) BYTES_TO_WORDS((n) + WORDS_TO_BYTES(1) - 1)
112
113 #ifdef SAVE_CALL_CHAIN
114 #   define ADD_CALL_CHAIN(base, ra) GC_save_callers(((oh *)(base)) -> oh_ci)
115 #   define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
116 #else
117 # ifdef GC_ADD_CALLER
118 #   define ADD_CALL_CHAIN(base, ra) ((oh *)(base)) -> oh_ci[0].ci_pc = (ra)
119 #   define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
120 # else
121 #   define ADD_CALL_CHAIN(base, ra)
122 #   define PRINT_CALL_CHAIN(base)
123 # endif
124 #endif
125
126 # ifdef GC_ADD_CALLER
127 #   define OPT_RA ra,
128 # else
129 #   define OPT_RA
130 # endif
131
132
133 /* Check whether object with base pointer p has debugging info  */ 
134 /* p is assumed to point to a legitimate object in our part     */
135 /* of the heap.                                                 */
136 #ifdef SHORT_DBG_HDRS
137 # define GC_has_other_debug_info(p) TRUE
138 #else
139   GC_bool GC_has_other_debug_info(/* p */);
140 #endif
141
142 #ifdef KEEP_BACK_PTRS
143 # define GC_HAS_DEBUG_INFO(p) \
144         ((((oh *)p)->oh_back_ptr & 1) && GC_has_other_debug_info(p))
145 #else
146 # define GC_HAS_DEBUG_INFO(p) GC_has_other_debug_info(p)
147 #endif
148
149 /* Store debugging info into p.  Return displaced pointer. */
150 /* Assumes we don't hold allocation lock.                  */
151 ptr_t GC_store_debug_info(/* p, sz, string, integer */);
152
153 #endif /* _DBG_MLC_H */