File: Debug.cpp

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 (76 lines) | stat: -rw-r--r-- 1,533 bytes parent folder | download | duplicates (2)
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
68
69
70
71
72
73
74
75
76
#include "stdafx.h"
#include "Debug.h"

// For debugging!
#include "Utils/TIB.h"
#include "Code/WindowsEh/SafeSeh.h"

namespace code {

#if defined(X86) && defined(WINDOWS)

	struct SehFrame {
		SehFrame *prev;
		void *fn;

		// From the storm code generation.
		void *block, *part;
	};

	void dumpStack() {
		void *stackPtr;
		SehFrame *top;
		__asm {
			mov eax, fs:[0];
			mov top, eax;
			mov stackPtr, esp;
		};

		PLN("---- STACK DUMP ----");

		NT_TIB *tib = getTIB();
		PLN("Stack base: " << tib->StackBase);
		PLN("Stack top: " << tib->StackLimit);
		PLN("Stack ptr: " << stackPtr);
		PLN("Stack size: " << (nat(tib->StackBase) - nat(tib->StackLimit)));
		if (stackPtr > tib->StackBase)
			PLN("Above stack.");
		if (stackPtr < tib->StackLimit)
			PLN("Below stack.");

		for (nat i = 0; i < 10; i++) {
			PLN("SEH at: " << top);
			nat addr = nat(top);
			if (addr == null || addr == 0xFFFFFFFF)
				break;

			PLN("Handler: " << top->fn << " (storm: " << &x86SafeSEH << ")");
			if (nat(top) % 4 != 0)
				PLN("ERROR: STACK IS NOT WORD-ALIGNED");

			if (top->fn == &x86SafeSEH) {
				void **ebp = (void **)(top + 1);
				PLN("Ebp: " << ebp);

				for (nat p = 0; p < 3; p++)
					PLN("Param " << p << ": " << ebp[2 + p]);
				for (nat v = 0; v < 5; v++)
					PLN("Local " << v << ": " << ebp[-5 - v]);
			}

			top = top->prev;
		}

		PLN("---- DONE ----");
	}

#else

	void dumpStack() {
		PLN("Stack dumping is not implemented for your system yet!");
		PLN("See Code/Debug.h for where to implement it.");
	}

#endif

}