File: StackTrace.hpp

package info (click to toggle)
fauhdlc 20180504-3.1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 3,064 kB
  • sloc: cpp: 23,188; ansic: 6,077; yacc: 3,764; lex: 763; makefile: 605; python: 412; xml: 403; sh: 61
file content (67 lines) | stat: -rw-r--r-- 2,092 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* $Id$
 *
 * Helper to obtain the current stack trace. Should not be used in the actual
 * compiler (only there for debugging).
 *
 * Copyright (C) 2008-2009 FAUmachine Team <info@faumachine.org>.
 * This program is free software. You can redistribute it and/or modify it
 * under the terms of the GNU General Public License, either version 2 of
 * the License, or (at your option) any later version. See COPYING.
 */

#ifndef __STACK_TRACKE_HPP_DEFINED
#define __STACK_TRACKE_HPP_DEFINED

#include <iostream>
#include <list>
#include <map>

namespace ast {
//! Helper to obtain the current stack trace.
/** This class can be used to obtain the current (c++) stack trace.
 *  It should not be used for anything in the compiler, apart from casual
 *  debugging.
 *
 *  To use this class, fauhdlc must be compiled with 
 *  -fno-omit-frame-pointers (otherwise g++ seems to omit frame pointers)
 *  and 
 *  -rdynamic (to tell the linker to store all symbols in the dynamic symbol
 *             table; otherwise name resolution will utterly fail).
 */
class StackTrace {
public:
	//! obtain the current stack trace.
	/** @return instance filled with the current stack trace.
	 */
	static StackTrace *getStackTrace(void);

	/** actual stack trace (symbol names) */
	std::list<std::string> stackTrace;

	//! put the stack trace to a stream.
	void put(std::ostream &stream) const;
private:
	//! dummy c'tor. use getStackTrace instead.
	StackTrace() {}

	//! resolve a symbol to the demangled entry.
	/** @param sym name of mangled symbol
	 *  @return name of demangled symbol (or sym in case demangling
	 *          doesn't succeed
	 */
	static std::string resolveSym(std::string sym);

	static std::map<std::string, std::string> mangleMap;
};

/** overloaded operator to conveniently output a StackTrace
 * @param stream stream to which a location should get written to.
 * @param st StackTrace instance to write to the stream.
 * @return modified stream
 */
std::ostream&
operator <<(std::ostream &stream, const StackTrace &st);

}; /* namespace ast */

#endif /* __STACK_TRACKE_HPP_DEFINED */