1 // Copyright 2007 Edd Dawson.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef STACK_HPP_0022_01092007
7 #define STACK_HPP_0022_01092007
15 //! stack_frame objects are collected by a stack object. They contain information about the instruction pointer,
16 //! the name of the corresponding function and the "module" (executable or library) in which the function resides.
19 stack_frame(const void *instruction, const std::string &function, unsigned int line, const std::string &module);
21 const void *instruction;
27 //! Allows you to write a stack_frame object to an std::ostream
28 std::ostream &operator<< (std::ostream &out, const stack_frame &frame);
30 //! Instantiate a dbg::stack object to collect information about the current call stack. Once created, a stack object
31 //! may be freely copied about and will continue to contain the information about the scope in which collection occurred.
35 typedef std::list<stack_frame>::size_type depth_type;
36 typedef std::list<stack_frame>::const_iterator const_iterator;
38 //! Collect information about the current call stack. Information on the most recent frames will be collected
39 //! up to the specified limit. 0 means unlimited.
40 //! An std::runtime_error may be thrown on failure.
41 stack(depth_type limit = 0);
43 //! Returns an iterator referring to the "top" stack frame
44 const_iterator begin() const;
46 //! Returns an iterator referring to one past the "bottom" stack frame
47 const_iterator end() const;
49 //! Returns the number of frames collected
50 depth_type depth() const;
53 std::list<stack_frame> frames_;
56 } // close namespace dbg
58 #endif // STACK_HPP_0022_01092007