1 ////////////////////////////////////////////////////////////////////////////////
3 // Visual Leak Detector - CallStack Class Definitions
4 // Copyright (c) 2005-2006 Dan Moulding
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.
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.
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
20 // See COPYING.txt for the full terms of the GNU Lesser General Public License.
22 ////////////////////////////////////////////////////////////////////////////////
28 "This header should only be included by Visual Leak Detector when building it from source. \
29 Applications should never include this header."
34 #define CALLSTACKCHUNKSIZE 32 // Number of frame slots in each CallStack chunk.
36 ////////////////////////////////////////////////////////////////////////////////
38 // The CallStack Class
40 // CallStack objects can be used for obtaining, storing, and displaying the
41 // call stack at a given point during program execution.
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.
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.
59 CallStack (const CallStack &other);
62 // Public APIs - see each function definition for details.
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);
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.
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.
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
92 ////////////////////////////////////////////////////////////////////////////////
94 // The FastCallStack Class
96 // This class is a specialization of the CallStack class which provides a
97 // very fast stack tracing function.
99 class FastCallStack : public CallStack
102 VOID getstacktrace (UINT32 maxdepth, SIZE_T *framepointer);
105 ////////////////////////////////////////////////////////////////////////////////
107 // The SafeCallStack Class
109 // This class is a specialization of the CallStack class which provides a
110 // more robust, but quite slow, stack tracing function.
112 class SafeCallStack : public CallStack
115 VOID getstacktrace (UINT32 maxdepth, SIZE_T *framepointer);