File: StackInfo.h

package info (click to toggle)
storm-lang 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,004 kB
  • sloc: ansic: 261,462; cpp: 140,405; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (55 lines) | stat: -rw-r--r-- 1,734 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
#pragma once
#include "StackTrace.h"
#include "Lock.h"

/**
 * Pluggable output stream for the stack info.
 */
class GenericOutput : NoCopy {
public:
	virtual void put(const wchar *str) = 0;
	virtual void put(const char *str) = 0;
	virtual void put(size_t i) = 0;
	virtual void putHex(size_t i) = 0;

	// Called if a single frame consists of multiple frames due to inlining.
	virtual void nextFrame() = 0;
};

/**
 * wostream implementation.
 */
class StdOutput : public GenericOutput {
public:
	StdOutput(wostream &to) : to(to), frameNumber(0) {}

	virtual void put(const wchar *str) { to << str; }
	virtual void put(const char *str) { to << str; }
	virtual void put(size_t i) { to << i; }
	virtual void putHex(size_t i) { to << toHex(i); }
	virtual void nextFrame();
private:
	nat frameNumber;
	wostream &to;
};


/**
 * Pluggable interface for collecting and showing information on the stack.
 */
class StackInfo : NoCopy {
public:
	// Called when the system allocates an array of StackFrame structures so that a backend can keep
	// any data referred by the trace alive until the trace is not needed anymore. The function is
	// called after the stack trace is populated.
	virtual void alloc(StackFrame *frames, nat count) const;
	virtual void free(StackFrame *frames, nat count) const;

	// Called during stack trace collection to resolve a possibly garbage collected pointer into a
	// base pointer for the function and an offset. Returns true if we know of this function.
	virtual bool translate(void *ip, void *&fnBase, int &offset) const = 0;

	// Format a function call. Only called for the StackInfo instance whose 'translate' returned true.
	virtual void format(GenericOutput &to, void *fnBase, int offset) const = 0;
};