annotate src/callstack.d @ 1:4a9dcbd9e54f

-files of 0.13 beta -fixes so that it now compiles with the current dmd version
author marton@basel.hu
date Tue, 05 Apr 2011 20:44:01 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1 /* Ddbg - Win32 Debugger for the D programming language
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
2 * Copyright (c) 2007 Jascha Wetzel
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
3 * All rights reserved. See LICENSE.TXT for details.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
4 */
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
5
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
6 import util;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
7 import codeview.codeview;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
8 import expression.evaluationcontext;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
9
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
10 import std.string;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
11
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
12 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
13 Wraps the raw stack data with functions for unwinding it.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
14 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
15 class CallStack
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
16 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
17 ubyte[] data;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
18 uint base_ptr, // the "base" of the stack, i.e. the largest address
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
19 top_ptr, // the current top of the stack = Esp
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
20 frame_ptr; // the current frame pointer
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
21
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
22 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
23 Initializes the object with pointers to base, top (esp) and frame (ebp)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
24 of the stack. Resizes the data array to the required size.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
25 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
26 this(uint base_ptr_, uint top_ptr_, uint frame_ptr_)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
27 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
28 base_ptr = base_ptr_;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
29 top_ptr = top_ptr_;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
30 frame_ptr = frame_ptr_;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
31 data.length = base_ptr-top_ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
32 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
33
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
34 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
35 Calculates the first frame.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
36 Params: prev_index = first byte of previous frame pointer
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
37 Returns: Array covering the frame.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
38 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
39 ubyte[] firstFrame(out uint prev_index)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
40 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
41 prev_index = frame_ptr-top_ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
42 if ( prev_index >= data.length )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
43 return data;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
44 return data[0..prev_index];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
45 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
46
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
47 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
48 Calculates the previous frame.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
49 Params:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
50 frame_index = start of desired frame in data array
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
51 prev_index = start of previous to desired frame in data array
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
52 Returns: Array covering the previous frame.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
53 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
54 ubyte[] prevFrame(in uint frame_index, out uint prev_index)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
55 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
56 if ( frame_index >= data.length-4 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
57 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
58
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
59 uint prev_frame_ptr = (cast(uint[])data)[frame_index>>2];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
60 if ( prev_frame_ptr < top_ptr || prev_frame_ptr > base_ptr )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
61 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
62
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
63 prev_index = prev_frame_ptr-top_ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
64 assert( prev_index > frame_index && prev_index <= data.length );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
65 return data[frame_index..prev_index];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
66 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
67
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
68 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
69
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
70 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
71 ubyte[] getFrame(uint frame_level)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
72 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
73 uint prev_frame_idx;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
74 ubyte[] frame = firstFrame(prev_frame_idx);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
75 for ( ; frame_level > 0; --frame_level )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
76 frame = prevFrame(prev_frame_idx, prev_frame_idx);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
77 return frame;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
78 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
79
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
80 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
81 Loads data from the stack for a given symbol.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
82 Returns: Array of bytes continaing the data
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
83 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
84 bool loadSymbolData(StackSymbol sym, SymbolData symdata, uint frame_level=0)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
85 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
86 if ( sym is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
87 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
88 uint prev_frame_idx;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
89 ubyte[] frame = firstFrame(prev_frame_idx);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
90 for ( ; frame_level > 0; --frame_level )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
91 frame = prevFrame(prev_frame_idx, prev_frame_idx);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
92
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
93 symdata.defered_load = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
94
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
95 bool loadSymbolData(uint offset)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
96 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
97 // index is in this frame
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
98 if ( offset <= frame.length-sym.size ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
99 symdata.len = sym.size;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
100 symdata.ptr = top_ptr + (frame.ptr - data.ptr) + offset;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
101 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
102 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
103 assert( offset >= frame.length );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
104 // consider previous frame
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
105 offset -= frame.length;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
106 frame = prevFrame(prev_frame_idx, prev_frame_idx);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
107 if ( frame !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
108 return loadSymbolData(offset);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
109 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
110 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
111
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
112 return loadSymbolData(frame.length+sym.cvdata.offset);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
113 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
114 }