File: StackInfo.cpp

package info (click to toggle)
storm-lang 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • 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 (53 lines) | stat: -rw-r--r-- 1,116 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
#include "stdafx.h"
#include "StackInfo.h"
#include "Utils/StackInfoSet.h"
#include "Gc/DwarfTable.h"
#include "Code/Binary.h"
#include "LookupHook.h"

namespace code {
	namespace eh {

		/**
		 * Function lookup using the Dwarf table.
		 */

		class DwarfInfo : public StackInfo {
		public:
			virtual bool translate(void *ip, void *&fnBase, int &offset) const {
				FDE *fde = dwarfTable().find(ip);
				if (!fde)
					return false;

				byte *start = (byte *)fde->codeStart();
				if (fde->codeSize() != runtime::codeSize(start)) {
					// Something is strange...
					WARNING(L"This does not seem like code we know...");
					return false;
				}

				fnBase = start;
				offset = int((byte *)ip - start);
				return true;
			}

			virtual void format(GenericOutput &to, void *fnBase, int offset) const {
				Binary *owner = codeBinary(fnBase);
				Str *name = owner->ownerName();
				if (name) {
					to.put(name->c_str());
				} else {
					to.put(S("<unnamed Storm function>"));
				}
			}
		};

		void activatePosixInfo() {
#ifdef POSIX
			initHook();
#endif
			static RegisterInfo<DwarfInfo> info;
		}

	}
}