summaryrefslogtreecommitdiff
path: root/src/lib/stack.hpp
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-05-21 12:56:47 +0100
committerCarl Hetherington <cth@carlh.net>2013-05-21 12:56:47 +0100
commit5f0f0de782100a5cb558f30c7768c8af0c19bcb7 (patch)
treeacb5c1624e6b5687f94eca0882c37afb0971018c /src/lib/stack.hpp
parent3fc3aad8735903ced3dae65f764eb33e3f5b3f11 (diff)
parent47e6b6725168213f2a7db24c2965cfa173f755b4 (diff)
Merge master.
Diffstat (limited to 'src/lib/stack.hpp')
-rw-r--r--src/lib/stack.hpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/lib/stack.hpp b/src/lib/stack.hpp
new file mode 100644
index 000000000..2b622d020
--- /dev/null
+++ b/src/lib/stack.hpp
@@ -0,0 +1,60 @@
+/** -*- c-basic-offset: 4; default-tab-width: 4; indent-tabs-mode: nil; -*- */
+
+// Copyright 2007 Edd Dawson.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef STACK_HPP_0022_01092007
+#define STACK_HPP_0022_01092007
+
+#include <string>
+#include <list>
+#include <iosfwd>
+
+namespace dbg
+{
+ //! stack_frame objects are collected by a stack object. They contain information about the instruction pointer,
+ //! the name of the corresponding function and the "module" (executable or library) in which the function resides.
+ struct stack_frame
+ {
+ stack_frame(const void *instruction, const std::string &function, unsigned int line, const std::string &module);
+
+ const void *instruction;
+ std::string function;
+ unsigned int line;
+ std::string module;
+ };
+
+ //! Allows you to write a stack_frame object to an std::ostream
+ std::ostream &operator<< (std::ostream &out, const stack_frame &frame);
+
+ //! Instantiate a dbg::stack object to collect information about the current call stack. Once created, a stack object
+ //! may be freely copied about and will continue to contain the information about the scope in which collection occurred.
+ class stack
+ {
+ public:
+ typedef std::list<stack_frame>::size_type depth_type;
+ typedef std::list<stack_frame>::const_iterator const_iterator;
+
+ //! Collect information about the current call stack. Information on the most recent frames will be collected
+ //! up to the specified limit. 0 means unlimited.
+ //! An std::runtime_error may be thrown on failure.
+ stack(depth_type limit = 0);
+
+ //! Returns an iterator referring to the "top" stack frame
+ const_iterator begin() const;
+
+ //! Returns an iterator referring to one past the "bottom" stack frame
+ const_iterator end() const;
+
+ //! Returns the number of frames collected
+ depth_type depth() const;
+
+ private:
+ std::list<stack_frame> frames_;
+ };
+
+} // close namespace dbg
+
+#endif // STACK_HPP_0022_01092007