]> git.lyx.org Git - lyx.git/blob - development/Win32/vld/src/callstack.h
Add support for glue length in parskip (#12867)
[lyx.git] / development / Win32 / vld / src / callstack.h
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 //  Visual Leak Detector - CallStack Class Definitions
4 //  Copyright (c) 2005-2006 Dan Moulding
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License, or (at your option) any later version.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 //
20 //  See COPYING.txt for the full terms of the GNU Lesser General Public License.
21 //
22 ////////////////////////////////////////////////////////////////////////////////
23
24 #pragma once
25
26 #ifndef VLDBUILD
27 #error \
28 "This header should only be included by Visual Leak Detector when building it from source. \
29 Applications should never include this header."
30 #endif
31
32 #include <windows.h>
33
34 #define CALLSTACKCHUNKSIZE 32 // Number of frame slots in each CallStack chunk.
35
36 ////////////////////////////////////////////////////////////////////////////////
37 //
38 //  The CallStack Class
39 //
40 //    CallStack objects can be used for obtaining, storing, and displaying the
41 //    call stack at a given point during program execution.
42 //
43 //    The primary data structure used by the CallStack is similar in concept to
44 //    a STL vector, but is specifically tailored for use by VLD, making it more
45 //    efficient than a standard STL vector.
46 //
47 //    Inside the CallStack are a number of "chunks" which are arranged in a
48 //    linked list. Each chunk contains an array of frames (each frame is
49 //    represented by a program counter address). If we run out of space when
50 //    pushing new frames onto an existing chunk in the CallStack chunk list,
51 //    then a new chunk is allocated and appended to the end of the list. In this
52 //    way, the CallStack can grow dynamically as needed. New frames are always
53 //    pushed onto the chunk at the end of the list known as the "top" chunk.
54 //
55 class CallStack
56 {
57 public:
58     CallStack ();
59     CallStack (const CallStack &other);
60     ~CallStack ();
61
62     // Public APIs - see each function definition for details.
63     VOID clear ();
64     VOID dump (BOOL showinternalframes) const;
65     virtual VOID getstacktrace (UINT32 maxdepth, SIZE_T *framepointer) = 0;
66     CallStack& operator = (const CallStack &other);
67     BOOL operator == (const CallStack &other) const;
68     SIZE_T operator [] (UINT32 index) const;
69     VOID push_back (const SIZE_T programcounter);
70
71 protected:
72     // Protected data.
73     UINT32 m_status;                    // Status flags:
74 #define CALLSTACK_STATUS_INCOMPLETE 0x1 //   If set, the stack trace stored in this CallStack appears to be incomplete.
75
76 private:
77     // The chunk list is made of a linked list of Chunks.
78     typedef struct chunk_s {
79         struct chunk_s *next;                        // Pointer to the next chunk in the chunk list.
80         SIZE_T          frames [CALLSTACKCHUNKSIZE]; // Pushed frames (program counter addresses) are stored in this array.
81     } chunk_t;
82
83     // Private data.
84     UINT32              m_capacity; // Current capacity limit (in frames)
85     UINT32              m_size;     // Current size (in frames)
86     CallStack::chunk_t  m_store;    // Pointer to the underlying data store (i.e. head of the chunk list)
87     CallStack::chunk_t *m_topchunk; // Pointer to the chunk at the top of the stack
88     UINT32              m_topindex; // Index, within the top chunk, of the top of the stack
89 };
90
91
92 ////////////////////////////////////////////////////////////////////////////////
93 //
94 //  The FastCallStack Class
95 //
96 //    This class is a specialization of the CallStack class which provides a
97 //    very fast stack tracing function.
98 //
99 class FastCallStack : public CallStack
100 {
101 public:
102     VOID getstacktrace (UINT32 maxdepth, SIZE_T *framepointer);
103 };
104
105 ////////////////////////////////////////////////////////////////////////////////
106 //
107 //  The SafeCallStack Class
108 //
109 //    This class is a specialization of the CallStack class which provides a
110 //    more robust, but quite slow, stack tracing function.
111 //
112 class SafeCallStack : public CallStack
113 {
114 public:
115     VOID getstacktrace (UINT32 maxdepth, SIZE_T *framepointer);
116 };