annotate src/codeview/codeview.d @ 4:a5fb1bc967e6

- = command does not need space after it - before using r command, ov command runs the program and stops at main - more source file lines are shown at each step
author marton@basel.hu
date Sun, 10 Apr 2011 12:15:04 +0200
parents 4a9dcbd9e54f
children 496dfd8f7342
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 module codeview.codeview;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
7
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
8 import std.ctype;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
9 import std.string;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
10 import std.math;
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 import util;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
13 import container;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
14 import codeview.coff;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
15 import codeview.decl;
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 public import codeview.debuginfo;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
18
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
19 //=================================================================================================
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
20 // classes for accessing CodeView data
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 abstract class Symbol
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
23 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
24 SymbolIndex symbol_index;
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(SymbolIndex si) { symbol_index = si; }
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
29 class ReturnSymbol : Symbol
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
30 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
31 CVReturnSymbol* cvdata;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
32 ubyte[] registers;
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 this(CVReturnSymbol* cv) { super(SymbolIndex.S_RETURN); cvdata = cv; }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
35 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
36
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
37 class StringWrap
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 string str;
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 this(string _str) { str = _str; }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
42
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
43 int opCmp(Object o)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
44 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
45 NamedSymbol ns = cast(NamedSymbol)o;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
46 if ( ns !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
47 return -ns.opCmp(this);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
48
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
49 StringWrap sw = cast(StringWrap)o;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
50 if ( sw is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
51 return -1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
52 if ( str == sw.str )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
53 return 0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
54 if ( str < sw.str )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
55 return -1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
56 return 1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
57 }
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
60 abstract class NamedSymbol : Symbol
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
61 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
62 string mangled_name,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
63 name_type,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
64 name_notype;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
65
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
66 this(SymbolIndex si) { super(si); }
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 int opCmp(Object o)
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 string str;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
71 NamedSymbol ns = cast(NamedSymbol)o;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
72 if ( ns is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
73 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
74 StringWrap sw = cast(StringWrap)o;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
75 if ( sw is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
76 return -1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
77 str = sw.str;
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 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
80 str = ns.name_notype;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
81 if ( name_notype == str )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
82 return 0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
83 if ( name_notype < str )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
84 return -1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
85 return 1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
86 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
87 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
88
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
89 class StackSymbol : NamedSymbol
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
90 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
91 CVStackSymbol* cvdata;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
92 int size;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
93
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
94 this(CVStackSymbol* cv)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
95 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
96 super(SymbolIndex.S_BPREL32);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
97 cvdata=cv;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
98 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
99
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
100 uint offset() { return cvdata.offset; }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
101 uint cvtype() { return cvdata.type; }
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
104 class DataSymbol : NamedSymbol
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
105 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
106 CVDataSymbol* cvdata;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
107 uint size;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
108
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
109 this(SymbolIndex si, CVDataSymbol* cv)
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 super(si);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
112 cvdata=cv;
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
115 uint offset() { return cvdata.offset; }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
116 uint cvtype() { return cvdata.type; }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
117 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
118
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
119 abstract class ScopeSymbol : NamedSymbol
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
120 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
121 ScopeSymbol parent_scope;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
122 SymbolSet symbols;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
123 uint lfo;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
124
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
125 this(SymbolIndex si, uint _lfo) { super(si); lfo = _lfo; symbols = new SymbolSet; }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
126 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
127
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
128 class ProcedureSymbol : ScopeSymbol
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
129 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
130 CVProcedureSymbol* cvdata;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
131 SymbolSet arguments;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
132 ReturnSymbol return_sym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
133
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
134 this(SymbolIndex si, uint lfo, CVProcedureSymbol* cvd)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
135 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
136 super(si,lfo);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
137 cvdata = cvd;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
138 arguments = new SymbolSet;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
139 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
140 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
141
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
142 class SymbolSet
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
143 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
144 ProcedureSymbol[] proc_symbols;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
145 StackSymbol[] stack_symbols;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
146 DataSymbol[] data_symbols;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
147 NamedSymbol[] named_symbols;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
148 Symbol[] symbols;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
149
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
150 void opCatAssign(SymbolSet s)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
151 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
152 symbols ~= s.symbols;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
153 named_symbols ~= s.named_symbols;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
154 data_symbols ~= s.data_symbols;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
155 stack_symbols ~= s.stack_symbols;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
156 proc_symbols ~= s.proc_symbols;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
157 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
158
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
159 void add(Symbol s)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
160 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
161 NamedSymbol ns = cast(NamedSymbol)s;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
162 if ( ns is null ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
163 symbols ~= s;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
164 return;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
165 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
166 named_symbols ~= ns;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
167 ClassInfo ci = s.classinfo;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
168 if ( ci == ProcedureSymbol.classinfo )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
169 proc_symbols ~= cast(ProcedureSymbol)s;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
170 else if ( ci == StackSymbol.classinfo )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
171 stack_symbols ~= cast(StackSymbol)s;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
172 else if ( ci == DataSymbol.classinfo )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
173 data_symbols ~= cast(DataSymbol)s;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
174 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
175
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
176 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
177 Find procedure symbol covering the given address.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
178 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
179 ProcedureSymbol findProcedureSymbol(uint address)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
180 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
181 foreach ( ps; proc_symbols )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
182 if ( address >= ps.cvdata.offset && address < ps.cvdata.offset+ps.cvdata.proc_length )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
183 return ps;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
184 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
185 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
186
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
187 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
188 Find data symbol covering the given address.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
189 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
190 DataSymbol findDataSymbol(uint address, uint segment)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
191 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
192 foreach ( ds; data_symbols )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
193 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
194 if ( segment > 0 && ds.cvdata.segment != segment )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
195 continue;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
196 if ( address == ds.cvdata.offset )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
197 return ds;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
198 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
199 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
200 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
201
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
202 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
203 Find data symbol by name.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
204 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
205 DataSymbol findDataSymbol(string name)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
206 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
207 foreach ( ds; data_symbols )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
208 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
209 if ( ds.name_notype == name )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
210 return ds;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
211 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
212 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
213 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
214
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
215 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
216 Find nearest data symbol to the given address.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
217 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
218 DataSymbol findNearestDataSymbol(uint address, inout uint min_dist, uint segment)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
219 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
220 DataSymbol min_ds;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
221 foreach ( ds; data_symbols )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
222 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
223 if ( address < ds.cvdata.offset || ds.cvdata.segment != segment )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
224 continue;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
225 uint dist = abs(cast(int)address-cast(int)ds.cvdata.offset);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
226 if ( dist < min_dist ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
227 min_dist = dist;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
228 min_ds = ds;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
229 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
230 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
231 return min_ds;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
232 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
233 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
234
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
235 class Module
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
236 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
237 ModuleHeader* header;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
238 SegInfo[] seginfos;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
239 string name;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
240 ushort pe_section;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
241
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
242 SymbolSet symbols;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
243
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
244 SourceModule source_module;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
245
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
246 CodeView codeview;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
247
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
248 this(CodeView cv)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
249 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
250 symbols = new SymbolSet;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
251 codeview = cv;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
252 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
253 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
254
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
255 class Location
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
256 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
257 string path;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
258
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
259 ScopeSymbol scope_sym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
260 DataSymbol data_sym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
261 Module mod;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
262 CodeBlock codeblock;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
263 CodeView codeview;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
264 uint address;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
265
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
266 this(uint addr, CodeView cv)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
267 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
268 codeview = cv;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
269 address = addr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
270 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
271
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
272 this(uint addr)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
273 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
274 address = addr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
275 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
276
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
277 this(string p)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
278 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
279 path = p;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
280 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
281
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
282 uint line()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
283 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
284 if ( codeblock is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
285 return 0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
286 return codeblock.line;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
287 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
288
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
289 string file()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
290 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
291 if ( codeblock is null || codeblock.segment is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
292 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
293 return codeblock.segment.file.name;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
294 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
295
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
296 size_t getCodeBase()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
297 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
298 return mod.codeview.image.getCodeBase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
299 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
300
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
301 bool bind(ImageSet images, string[] source_search_paths)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
302 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
303 if ( path is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
304 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
305
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
306 if ( find(path, '"') >= 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
307 path = replace(path, "\"", "");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
308
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
309 string[] file_line = split(path, ":");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
310 if ( file_line is null || file_line.length < 2 || !isNumeric(file_line[$-1]) ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
311 DbgIO.println("Invalid location format. Use <part of filename>:<linenumber>");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
312 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
313 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
314
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
315 string file = join(file_line[0..$-1], ":"),
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
316 line = file_line[$-1];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
317
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
318 if ( find(file, '/') >= 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
319 file = replace(file, "/", "\\");
4
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 1
diff changeset
320 debug DbgIO.println("searching in %s", file);
1
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
321 SourceFile[] sfs = images.findSrcFiles(file);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
322 if ( sfs.length == 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
323 sfs = images.findSrcFiles(file, source_search_paths);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
324 if ( sfs.length == 0 ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
325 DbgIO.println("Source file \"%s\" not found", file);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
326 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
327 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
328
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
329 uint linenum = cast(uint)atoi(line);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
330 Location loc;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
331 foreach ( sf; sfs )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
332 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
333 debug DbgIO.println("searching sf %s", sf.name);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
334 auto loc2 = images.findSrcLine(sf, linenum);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
335 if ( loc is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
336 loc = loc2;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
337 else if ( loc2 !is null && loc2.line < loc.line )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
338 loc = loc2;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
339 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
340 if ( loc is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
341 DbgIO.println("Line %d in \"%s\" not found", linenum, sfs[0].name);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
342
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
343 scope_sym = loc.scope_sym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
344 data_sym = loc.data_sym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
345 mod = loc.mod;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
346 codeblock = loc.codeblock;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
347 address = loc.address;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
348 path = null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
349 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
350 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
351 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
352
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
353 class UserDefinedType
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
354 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
355 ushort type_index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
356 string name;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
357 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
358
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
359 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
360 Represents the CodeView information of an executable image. Provides methods to browse the
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
361 information. Objects of this class get created by CodeViewParser.parse.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
362 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
363 class CodeView : DebugInfo
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
364 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
365 Module[string] modulesByName;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
366 Module[] modulesByIndex;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
367
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
368 SymbolSet global_pub,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
369 global_sym,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
370 static_sym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
371 UserDefinedType[] udtypes;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
372 Leaf[][] type_strings;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
373
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
374 Leaf[string] UDTsByName;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
375
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
376 string[] libraries,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
377 segnames;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
378
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
379 COFFImage image;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
380
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
381 AVLTree!(NamedSymbol) globalNamedSymbols;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
382
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
383 size_t getCodeBase()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
384 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
385 return image.getCodeBase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
386 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
387
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
388 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
389 Find the module and segment covering the given address.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
390 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
391 Module findModule(uint vaddress, out uint segment)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
392 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
393 uint address = vaddress-image.getCodeBase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
394 foreach ( m; modulesByIndex )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
395 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
396 foreach ( s; m.seginfos )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
397 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
398 if ( address < s.offset )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
399 continue;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
400 if ( address-s.offset < s.cbSeg ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
401 segment = s.Seg;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
402 return m;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
403 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
404 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
405 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
406 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
407 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
408
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
409 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
410 Find next source line from the given location.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
411 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
412 Location findNextSrcLine(Location loc)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
413 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
414 if ( loc is null || loc.codeblock is null || loc.codeblock.segment is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
415 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
416 Location nextloc = findLocation(loc.codeblock.end+image.getCodeBase);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
417 return nextloc;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
418 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
419
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
420 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
421 Find previous source line from location that isn't covered by a source codeblock.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
422 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
423 Location findPrevSrcLine(Location loc)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
424 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
425 if ( loc is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
426 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
427 if ( loc.codeblock !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
428 return loc;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
429
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
430 AVLNode!(CodeBlock) node;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
431 if ( !codeblocks.find(loc.address-1+image.getCodeBase, node) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
432 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
433 if ( node.value.start > loc.address )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
434 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
435 if ( !node.findPrev(node) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
436 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
437 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
438 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
439 Location prevloc = new Location(node.value.start, this);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
440 prevloc.codeblock = node.value;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
441 findSymbolForLocation(prevloc);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
442 assert(prevloc.line != 0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
443 return prevloc;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
444 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
445
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
446 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
447 Find first source line in the given file that has a line number >= line
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
448 and a start address >= min_start.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
449 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
450 Location findSrcLine(SourceFile sf, uint min_line, size_t min_start=0)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
451 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
452 if ( sf is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
453 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
454
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
455 pragma(msg, TODO(__FILE__,__LINE__,"use binary search here"));
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
456 foreach ( l; sf.lines )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
457 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
458 if ( l < min_line )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
459 continue;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
460 foreach ( cb; sf.blocks_by_line[l] )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
461 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
462 if ( cb.start < min_start || cb.end <= cb.start )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
463 continue;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
464 Location loc = new Location(cb.start+image.getCodeBase, this);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
465 loc.codeblock = cb;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
466 findSymbolForLocation(loc);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
467 return loc;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
468 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
469 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
470 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
471 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
472
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
473 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
474 Find all debug information available for the given address.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
475 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
476 Location findLocation(uint vaddress)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
477 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
478 Location loc = new Location(vaddress, this);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
479 CodeBlock cb = findCodeBlockAbs(vaddress);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
480 loc.codeblock = cb;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
481 findSymbolForLocation(loc);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
482 return loc;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
483 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
484
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
485 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
486 Fill out symbol information (as opposed to source line information) in the given location.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
487 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
488 void findSymbolForLocation(Location loc)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
489 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
490 ProcedureSymbol psym = findProcedureSymbol(loc.address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
491 if ( psym !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
492 loc.scope_sym = psym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
493 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
494 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
495 DataSymbol dsym = findDataSymbol(loc.address, 2);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
496 if ( dsym !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
497 loc.data_sym = dsym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
498 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
499
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
500 uint seg;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
501 Module mod = findModule(loc.address, seg);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
502 if ( mod !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
503 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
504 loc.mod = mod;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
505 if ( loc.data_sym is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
506 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
507 uint min_dist = uint.max;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
508 loc.data_sym = global_sym.findNearestDataSymbol(loc.address-image.getCodeBase, min_dist, image.code_section_index+1);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
509 if ( loc.data_sym is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
510 loc.data_sym = global_pub.findNearestDataSymbol(loc.address-image.getCodeBase, min_dist, image.code_section_index+1);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
511 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
512 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
513 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
514
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
515 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
516 Find procedure symbol covering the given address.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
517 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
518 ProcedureSymbol findProcedureSymbol(uint vaddress)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
519 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
520 uint address = vaddress-image.getCodeBase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
521 ProcedureSymbol ps;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
522 foreach ( m; modulesByIndex )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
523 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
524 ps = m.symbols.findProcedureSymbol(address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
525 if ( ps !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
526 return ps;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
527 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
528 ps = global_sym.findProcedureSymbol(address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
529 if ( ps is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
530 ps = static_sym.findProcedureSymbol(address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
531 if ( ps is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
532 ps = global_pub.findProcedureSymbol(address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
533 return ps;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
534 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
535
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
536 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
537 Find data symbol covering the given address.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
538 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
539 DataSymbol findDataSymbol(uint vaddress, uint segment=0)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
540 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
541 uint address = vaddress-image.getCodeBase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
542 DataSymbol ps;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
543 foreach ( m; modulesByIndex )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
544 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
545 ps = m.symbols.findDataSymbol(address, segment);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
546 if ( ps !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
547 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
548 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
549 ps = global_sym.findDataSymbol(address, segment);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
550 if ( ps is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
551 ps = static_sym.findDataSymbol(address, segment);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
552 if ( ps is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
553 ps = global_pub.findDataSymbol(address, segment);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
554 return ps;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
555 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
556
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
557 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
558 Creates a D mangled name from a CodeView symbol.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
559 Uses available mangled type info if available, mangles CodeView type info else.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
560 Returns: Symbol name with mangled type info.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
561 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
562 string mangle(NamedSymbol s)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
563 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
564 // use mangled typeinfo if available
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
565 if ( s.mangled_name !is null && s.mangled_name.length > 2 && s.mangled_name[0..2] == "_D" && isdigit(s.mangled_name[2]) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
566 return s.mangled_name;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
567
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
568 return "_D"~mangleName(s.name_type)~mangleType(s);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
569 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
570
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
571 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
572 Creates the type part of a D mangled name for a CodeView symbol.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
573 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
574 string mangleType(Symbol s)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
575 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
576 DataSymbol ds = cast(DataSymbol)s;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
577 ushort cvtype;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
578 if ( ds !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
579 cvtype = ds.cvdata.type;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
580 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
581 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
582 StackSymbol ss = cast(StackSymbol)s;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
583 if ( ss !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
584 cvtype = ss.cvdata.type;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
585 else {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
586 pragma(msg, TODO(__FILE__,__LINE__,"implement procedure symbol mangling"));
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
587 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
588 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
589 return mangleCVtype(cvtype);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
590 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
591
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
592 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
593 Creates the type part of a D mangled name for a CodeView type index.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
594 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
595 string mangleCVtype(ushort cvtype)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
596 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
597 if ( cvtype >= 0x1000 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
598 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
599 uint typeindex = cvtype-0x1000;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
600 if ( typeindex >= type_strings.length ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
601 debug DbgIO.println("undefined complex type 0x%x largest known type 0x%x", cvtype, type_strings.length-1);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
602 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
603 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
604 Leaf[] typestring = type_strings[typeindex];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
605
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
606 while ( typestring.length > 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
607 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
608 switch ( typestring[0].leaf_index )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
609 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
610 case LF_MODIFIER_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
611 LeafModifer lm = cast(LeafModifer)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
612 assert ( lm !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
613 return mangleCVtype(lm.index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
614 case LF_POINTER_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
615 LeafPointer lp = cast(LeafPointer)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
616 assert ( lp !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
617 return "P"~mangleCVtype(lp.type);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
618 // do not insert new cases here
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
619 case LF_CLASS_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
620 LeafClassStruc lcs = cast(LeafClassStruc)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
621 assert ( lcs !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
622 return "C"~mangleName(lcs.name);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
623 case LF_ARRAY_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
624 LeafArray la = cast(LeafArray)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
625 assert ( la !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
626 debug(cvparser) DbgIO.println("Static array elemtype 0x%x idxtype 0x%x length %d", la.elemtype, la.idxtype, la.length.getUint);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
627 uint count = la.length.getUint,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
628 elmsize = sizeofCV(la.elemtype);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
629 if ( elmsize > 0 ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
630 count /= elmsize;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
631 assert(la.length.getUint % sizeofCV(la.elemtype) == 0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
632 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
633 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
634 debug DbgIO.println("WARNING: elm size == 0");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
635 return "G"~.toString(count)~mangleCVtype(la.elemtype);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
636 case LF_OEM_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
637 LeafDynArray lda = cast(LeafDynArray)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
638 if ( lda !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
639 return "A"~mangleCVtype(lda.elem_type);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
640 LeafAssocArray laa = cast(LeafAssocArray)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
641 if ( laa !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
642 return "H"~mangleCVtype(laa.key_type)~mangleCVtype(laa.elem_type);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
643 LeafDelegate ld = cast(LeafDelegate)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
644 if ( ld !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
645 return "D"~mangleCVtype(ld.func_type);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
646 assert(0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
647
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
648 case LF_STRUCTURE_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
649 LeafClassStruc lcs = cast(LeafClassStruc)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
650 assert ( lcs !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
651 return "S"~mangleName(lcs.name);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
652 case LF_PROCEDURE_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
653 case LF_METHODLIST_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
654 debug(cvparser) DbgIO.println("unmangled procedure or methodlist in complex type");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
655 return "";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
656 case LF_UNION_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
657 LeafUnion lu = cast(LeafUnion)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
658 return "S"~mangleName(lu.name);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
659 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
660 DbgIO.println("mangleCVtype: unsupported type leaf 0x%x", typestring[0].leaf_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
661 typestring = typestring[1..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
662 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
663 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
664 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
665 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
666
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
667 switch ( cvtype )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
668 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
669 case T_NOTYPE:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
670 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
671 case T_VOID:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
672 return "v";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
673 case T_PVOID: case T_PFVOID: case T_PHVOID: case T_32PVOID: case T_32PFVOID:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
674 return "Pv";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
675
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
676 case T_CHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
677 return "g";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
678 case T_UCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
679 return "h";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
680 case T_RCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
681 return "a";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
682 case T_WCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
683 return "u";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
684 case T_DCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
685 return "w";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
686 case T_32PDCHAR: case T_32PFDCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
687 return "Pw";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
688 case T_PFRCHAR: case T_PHRCHAR: case T_32PRCHAR: case T_32PFRCHAR: case T_PRCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
689 return "Pa";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
690 case T_PFWCHAR: case T_PHWCHAR: case T_32PWCHAR: case T_32PFWCHAR: case T_PWCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
691 return "Pu";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
692 case T_PFCHAR: case T_PHCHAR: case T_32PCHAR: case T_32PFCHAR: case T_PCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
693 return "Pg";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
694 case T_PFUCHAR: case T_PHUCHAR: case T_32PUCHAR: case T_32PFUCHAR: case T_PUCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
695 return "Ph";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
696
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
697 case T_SHORT: case T_INT2:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
698 return "s";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
699 case T_USHORT: case T_UINT2:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
700 return "t";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
701 case T_PINT2: case T_PSHORT: case T_32PSHORT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
702 return "Ps";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
703 case T_PUSHORT: case T_PUINT2: case T_32PUSHORT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
704 return "Pt";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
705 case T_INT4:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
706 case T_LONG:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
707 return "i";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
708 case T_UINT4:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
709 case T_ULONG:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
710 return "k";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
711 case T_32PINT4: case T_PINT4:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
712 return "Pi";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
713 case T_32PUINT4: case T_PUINT4:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
714 return "Pk";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
715 case T_QUAD:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
716 return "l";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
717 case T_UQUAD:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
718 return "m";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
719 case T_32PQUAD: case T_PQUAD:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
720 return "Pl";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
721 case T_32PUQUAD: case T_PUQUAD:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
722 return "Pm";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
723 case T_REAL32:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
724 return "f";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
725 case T_32PREAL32: case T_PREAL32:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
726 return "Pf";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
727 case T_REAL64:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
728 return "d";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
729 case T_32PREAL64: case T_PREAL64:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
730 return "Pd";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
731 case T_REAL80:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
732 return "e";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
733 case T_PREAL80: case T_PFREAL80: case T_PHREAL80: case T_32PREAL80: case T_32PFREAL80:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
734 return "Pe";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
735 case T_BOOL08:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
736 return "b";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
737 case T_32PBOOL08: case T_32PFBOOL08:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
738 return "Pb";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
739 case T_CPLX80:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
740 return "c";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
741 case T_CPLX64:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
742 return "r";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
743 case T_CPLX32:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
744 return "q";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
745 case T_32PCPLX80: case T_32PFCPLX80:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
746 return "Pc";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
747 case T_32PCPLX64: case T_32PFCPLX64:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
748 return "Pr";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
749 case T_32PCPLX32: case T_32PFCPLX32:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
750 return "Pq";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
751 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
752 debug DbgIO.println("mangleCVtype: unknown codeview type 0x%x", cvtype);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
753 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
754 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
755 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
756
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
757
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
758 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
759 Returns: size of demangled type
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
760 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
761 uint sizeofMangled(string m)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
762 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
763 assert(m.length > 0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
764 switch ( m[0] )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
765 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
766 case 'A': return ulong.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
767 case 'G':
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
768 string n = m[1..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
769 size_t count = parseNumber(n);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
770 return count*sizeofMangled(n);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
771 case 'P': return size_t.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
772 case 'H': return size_t.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
773 case 'v': return void.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
774 case 'b': return bit.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
775 case 'x': return bool.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
776 case 'g': return byte.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
777 case 'h': return ubyte.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
778 case 's': return short.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
779 case 't': return ushort.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
780 case 'i': return int.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
781 case 'k': return uint.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
782 case 'l': return long.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
783 case 'm': return ulong.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
784 case 'f': return float.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
785 case 'd': return double.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
786 case 'e': return real.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
787 case 'o': return ifloat.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
788 case 'p': return idouble.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
789 case 'j': return ireal.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
790 case 'q': return cfloat.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
791 case 'r': return cdouble.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
792 case 'c': return creal.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
793 case 'a': return char.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
794 case 'u': return wchar.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
795 case 'w': return dchar.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
796 case 'C':
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
797 case 'S':
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
798 string mangled_name = m[1..$],
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
799 name = demangleNameSkip(mangled_name);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
800 if ( name in UDTsByName ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
801 LeafClassStruc lcs = cast(LeafClassStruc)UDTsByName[name];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
802 if ( lcs !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
803 return lcs.length.getUint;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
804 LeafUnion lu = cast(LeafUnion)UDTsByName[name];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
805 if ( lu !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
806 return lu.length.getUint;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
807 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
808 assert(0, "unknown struct in sizeofMangled: "~name);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
809 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
810 assert(0, "unknown type in sizeofMangled: "~m);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
811 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
812 return 0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
813 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
814
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
815
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
816 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
817 Calculates the size of the type specified by a CodeView type index.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
818 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
819 uint sizeofCV(uint cvtype)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
820 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
821 if ( cvtype >= 0x1000 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
822 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
823 uint typeindex = cvtype-0x1000;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
824 if ( typeindex >= type_strings.length ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
825 debug DbgIO.println("sizeofCV: undefined complex type 0x%x", cvtype);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
826 return 0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
827 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
828 Leaf[] typestring = type_strings[typeindex];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
829 while ( typestring.length > 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
830 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
831 switch ( typestring[0].leaf_index )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
832 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
833 case LF_MODIFIER_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
834 LeafModifer lm = cast(LeafModifer)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
835 assert ( lm !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
836 return sizeofCV(lm.index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
837 case LF_ARRAY_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
838 LeafArray la = cast(LeafArray)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
839 assert ( la !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
840 return la.length.getUint;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
841 case LF_POINTER_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
842 case LF_CLASS_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
843 return 4;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
844 case LF_STRUCTURE_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
845 LeafClassStruc lcs = cast(LeafClassStruc)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
846 assert ( lcs !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
847 return lcs.length.getUint;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
848 case LF_PROCEDURE_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
849 case LF_METHODLIST_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
850 debug DbgIO.println("unmangled procedure or methodlist in complex type");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
851 return 0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
852 case LF_UNION_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
853 LeafUnion lu = cast(LeafUnion)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
854 return lu.length.getUint;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
855 case LF_OEM_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
856 LeafDynArray lda = cast(LeafDynArray)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
857 if ( lda !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
858 return size_t.sizeof*2;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
859 LeafAssocArray laa = cast(LeafAssocArray)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
860 if ( laa !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
861 return size_t.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
862 LeafDelegate ld = cast(LeafDelegate)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
863 if ( ld !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
864 return size_t.sizeof*2;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
865 assert(0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
866
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
867 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
868 DbgIO.println("sizeofCV: unsupported complex type leaf 0x%x", typestring[0].leaf_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
869 typestring = typestring[1..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
870 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
871 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
872 return 0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
873 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
874
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
875 switch ( cvtype )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
876 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
877 case T_NOTYPE:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
878 return 0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
879 case T_VOID:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
880 case T_CHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
881 case T_UCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
882 case T_RCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
883 case T_BOOL08:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
884 return 1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
885 case T_SHORT: case T_INT2:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
886 case T_USHORT: case T_UINT2:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
887 case T_WCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
888 return 2;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
889 case T_PVOID: case T_PFVOID: case T_PHVOID: case T_32PVOID: case T_32PFVOID:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
890 case T_DCHAR: case T_32PDCHAR: case T_32PFDCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
891 case T_PFCHAR: case T_PHCHAR: case T_32PCHAR: case T_32PFCHAR: case T_PCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
892 case T_PFUCHAR: case T_PHUCHAR: case T_32PUCHAR: case T_32PFUCHAR: case T_PUCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
893 case T_PRCHAR: case T_PFRCHAR: case T_PHRCHAR: case T_32PRCHAR: case T_32PFRCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
894 case T_PWCHAR: case T_PFWCHAR: case T_PHWCHAR: case T_32PWCHAR: case T_32PFWCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
895 case T_PINT2: case T_PSHORT: case T_32PSHORT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
896 case T_PUSHORT: case T_PUINT2: case T_32PUSHORT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
897 case T_32PBOOL08: case T_32PFBOOL08:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
898 case T_INT4:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
899 case T_UINT4:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
900 case T_32PINT4: case T_PINT4:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
901 case T_32PUINT4: case T_PUINT4:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
902 case T_32PQUAD: case T_PQUAD:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
903 case T_32PUQUAD: case T_PUQUAD:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
904 case T_ULONG:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
905 case T_REAL32:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
906 case T_32PREAL32: case T_PREAL32:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
907 case T_32PREAL64: case T_PREAL64:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
908 case T_PREAL80: case T_PFREAL80: case T_PHREAL80: case T_32PREAL80: case T_32PFREAL80:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
909 case T_CPLX32:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
910 case T_32PCPLX32: case T_32PFCPLX32:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
911 case T_32PCPLX64: case T_32PFCPLX64:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
912 case T_32PCPLX80: case T_32PFCPLX80:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
913 return 4;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
914 case T_QUAD:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
915 case T_UQUAD:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
916 case T_REAL64:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
917 case T_CPLX64:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
918 return 8;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
919 case T_CPLX80:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
920 case T_REAL80:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
921 return 10;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
922 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
923 debug DbgIO.println("sizeofCV: unknown codeview type 0x%x", cvtype);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
924 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
925 return 0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
926 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
927 }