1 ////////////////////////////////////////////////////////////////////////////////
2 // $Id: callstack.h,v 1.10 2006/11/18 03:12:34 dmouldin Exp $
4 // Visual Leak Detector - CallStack Class Definitions
5 // Copyright (c) 2005-2006 Dan Moulding
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Lesser General Public License for more details.
17 // You should have received a copy of the GNU Lesser General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 // See COPYING.txt for the full terms of the GNU Lesser General Public License.
23 ////////////////////////////////////////////////////////////////////////////////
29 "This header should only be included by Visual Leak Detector when building it from source. \
30 Applications should never include this header."
35 #define CALLSTACKCHUNKSIZE 32 // Number of frame slots in each CallStack chunk.
37 ////////////////////////////////////////////////////////////////////////////////
39 // The CallStack Class
41 // CallStack objects can be used for obtaining, storing, and displaying the
42 // call stack at a given point during program execution.
44 // The primary data structure used by the CallStack is similar in concept to
45 // a STL vector, but is specifically tailored for use by VLD, making it more
46 // efficient than a standard STL vector.
48 // Inside the CallStack are a number of "chunks" which are arranged in a
49 // linked list. Each chunk contains an array of frames (each frame is
50 // represented by a program counter address). If we run out of space when
51 // pushing new frames onto an existing chunk in the CallStack chunk list,
52 // then a new chunk is allocated and appended to the end of the list. In this
53 // way, the CallStack can grow dynamically as needed. New frames are always
54 // pushed onto the chunk at the end of the list known as the "top" chunk.
60 CallStack (const CallStack &other);
63 // Public APIs - see each function definition for details.
65 VOID dump (BOOL showinternalframes) const;
66 virtual VOID getstacktrace (UINT32 maxdepth, SIZE_T *framepointer) = 0;
67 CallStack& operator = (const CallStack &other);
68 BOOL operator == (const CallStack &other) const;
69 SIZE_T operator [] (UINT32 index) const;
70 VOID push_back (const SIZE_T programcounter);
74 UINT32 m_status; // Status flags:
75 #define CALLSTACK_STATUS_INCOMPLETE 0x1 // If set, the stack trace stored in this CallStack appears to be incomplete.
78 // The chunk list is made of a linked list of Chunks.
79 typedef struct chunk_s {
80 struct chunk_s *next; // Pointer to the next chunk in the chunk list.
81 SIZE_T frames [CALLSTACKCHUNKSIZE]; // Pushed frames (program counter addresses) are stored in this array.
85 UINT32 m_capacity; // Current capacity limit (in frames)
86 UINT32 m_size; // Current size (in frames)
87 CallStack::chunk_t m_store; // Pointer to the underlying data store (i.e. head of the chunk list)
88 CallStack::chunk_t *m_topchunk; // Pointer to the chunk at the top of the stack
89 UINT32 m_topindex; // Index, within the top chunk, of the top of the stack
93 ////////////////////////////////////////////////////////////////////////////////
95 // The FastCallStack Class
97 // This class is a specialization of the CallStack class which provides a
98 // very fast stack tracing function.
100 class FastCallStack : public CallStack
103 VOID getstacktrace (UINT32 maxdepth, SIZE_T *framepointer);
106 ////////////////////////////////////////////////////////////////////////////////
108 // The SafeCallStack Class
110 // This class is a specialization of the CallStack class which provides a
111 // more robust, but quite slow, stack tracing function.
113 class SafeCallStack : public CallStack
116 VOID getstacktrace (UINT32 maxdepth, SIZE_T *framepointer);