annotate src/codeview/codeview.d @ 5:496dfd8f7342 default tip

added: -repeat option for "in", "ov" -run until a line option -run until a function option -break on a function start -n is an alias for ov
author marton@basel.hu
date Sun, 17 Apr 2011 11:05:31 +0200
parents a5fb1bc967e6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1 /* Ddbg - Win32 Debugger for the D programming language
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
2 * Copyright (c) 2007 Jascha Wetzel
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
3 * All rights reserved. See LICENSE.TXT for details.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
4 */
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
5
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
6 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
5
marton@basel.hu
parents: 4
diff changeset
215 /**********************************************************************************************
marton@basel.hu
parents: 4
diff changeset
216 Find matching data symbols by a substring in its name.
marton@basel.hu
parents: 4
diff changeset
217 **********************************************************************************************/
marton@basel.hu
parents: 4
diff changeset
218 DataSymbol[] findDataSymbolBySubstring(string name)
marton@basel.hu
parents: 4
diff changeset
219 {
marton@basel.hu
parents: 4
diff changeset
220 DataSymbol[] found;
marton@basel.hu
parents: 4
diff changeset
221 foreach ( ds; data_symbols )
marton@basel.hu
parents: 4
diff changeset
222 {
marton@basel.hu
parents: 4
diff changeset
223 if ( find(ds.name_notype,name)>=0 )
marton@basel.hu
parents: 4
diff changeset
224 found~=ds;
marton@basel.hu
parents: 4
diff changeset
225 }
marton@basel.hu
parents: 4
diff changeset
226 return found;
marton@basel.hu
parents: 4
diff changeset
227 }
marton@basel.hu
parents: 4
diff changeset
228
1
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 Find nearest data symbol to the given address.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
231 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
232 DataSymbol findNearestDataSymbol(uint address, inout uint min_dist, uint segment)
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 DataSymbol min_ds;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
235 foreach ( ds; data_symbols )
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 if ( address < ds.cvdata.offset || ds.cvdata.segment != segment )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
238 continue;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
239 uint dist = abs(cast(int)address-cast(int)ds.cvdata.offset);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
240 if ( dist < min_dist ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
241 min_dist = dist;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
242 min_ds = ds;
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 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
245 return min_ds;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
246 }
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
249 class Module
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
250 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
251 ModuleHeader* header;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
252 SegInfo[] seginfos;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
253 string name;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
254 ushort pe_section;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
255
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
256 SymbolSet symbols;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
257
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
258 SourceModule source_module;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
259
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
260 CodeView codeview;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
261
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
262 this(CodeView cv)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
263 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
264 symbols = new SymbolSet;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
265 codeview = cv;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
266 }
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
269 class Location
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 string path;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
272
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
273 ScopeSymbol scope_sym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
274 DataSymbol data_sym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
275 Module mod;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
276 CodeBlock codeblock;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
277 CodeView codeview;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
278 uint address;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
279
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
280 this(uint addr, CodeView cv)
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 codeview = cv;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
283 address = addr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
284 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
285
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
286 this(uint addr)
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 address = addr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
289 }
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 this(string p)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
292 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
293 path = p;
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 uint line()
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 if ( codeblock is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
299 return 0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
300 return codeblock.line;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
301 }
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 string file()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
304 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
305 if ( codeblock is null || codeblock.segment is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
306 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
307 return codeblock.segment.file.name;
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
310 size_t getCodeBase()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
311 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
312 return mod.codeview.image.getCodeBase;
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 bool bind(ImageSet images, string[] source_search_paths)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
316 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
317 if ( path is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
318 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
319
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
320 if ( find(path, '"') >= 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
321 path = replace(path, "\"", "");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
322
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
323 string[] file_line = split(path, ":");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
324 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
325 DbgIO.println("Invalid location format. Use <part of filename>:<linenumber>");
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 string file = join(file_line[0..$-1], ":"),
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
330 line = file_line[$-1];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
331
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
332 if ( find(file, '/') >= 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
333 file = replace(file, "/", "\\");
4
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 1
diff changeset
334 debug DbgIO.println("searching in %s", file);
1
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
335 SourceFile[] sfs = images.findSrcFiles(file);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
336 if ( sfs.length == 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
337 sfs = images.findSrcFiles(file, source_search_paths);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
338 if ( sfs.length == 0 ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
339 DbgIO.println("Source file \"%s\" not found", file);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
340 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
341 }
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 uint linenum = cast(uint)atoi(line);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
344 Location loc;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
345 foreach ( sf; sfs )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
346 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
347 debug DbgIO.println("searching sf %s", sf.name);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
348 auto loc2 = images.findSrcLine(sf, linenum);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
349 if ( loc is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
350 loc = loc2;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
351 else if ( loc2 !is null && loc2.line < loc.line )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
352 loc = loc2;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
353 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
354 if ( loc is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
355 DbgIO.println("Line %d in \"%s\" not found", linenum, sfs[0].name);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
356
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
357 scope_sym = loc.scope_sym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
358 data_sym = loc.data_sym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
359 mod = loc.mod;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
360 codeblock = loc.codeblock;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
361 address = loc.address;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
362 path = null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
363 return true;
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 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
366
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
367 class UserDefinedType
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
368 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
369 ushort type_index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
370 string name;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
371 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
372
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 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
375 information. Objects of this class get created by CodeViewParser.parse.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
376 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
377 class CodeView : DebugInfo
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 Module[string] modulesByName;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
380 Module[] modulesByIndex;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
381
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
382 SymbolSet global_pub,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
383 global_sym,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
384 static_sym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
385 UserDefinedType[] udtypes;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
386 Leaf[][] type_strings;
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 Leaf[string] UDTsByName;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
389
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
390 string[] libraries,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
391 segnames;
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 COFFImage image;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
394
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
395 AVLTree!(NamedSymbol) globalNamedSymbols;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
396
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
397 size_t getCodeBase()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
398 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
399 return image.getCodeBase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
400 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
401
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
402 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
403 Find the module and segment covering the given address.
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 Module findModule(uint vaddress, out uint segment)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
406 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
407 uint address = vaddress-image.getCodeBase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
408 foreach ( m; modulesByIndex )
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 foreach ( s; m.seginfos )
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 if ( address < s.offset )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
413 continue;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
414 if ( address-s.offset < s.cbSeg ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
415 segment = s.Seg;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
416 return m;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
417 }
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 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
421 }
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 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
424 Find next source line from the given location.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
425 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
426 Location findNextSrcLine(Location loc)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
427 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
428 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
429 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
430 Location nextloc = findLocation(loc.codeblock.end+image.getCodeBase);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
431 return nextloc;
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
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 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
436 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
437 Location findPrevSrcLine(Location loc)
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 if ( loc is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
440 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
441 if ( loc.codeblock !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
442 return loc;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
443
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
444 AVLNode!(CodeBlock) node;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
445 if ( !codeblocks.find(loc.address-1+image.getCodeBase, node) )
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 if ( node.value.start > loc.address )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
448 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
449 if ( !node.findPrev(node) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
450 return null;
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 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
453 Location prevloc = new Location(node.value.start, this);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
454 prevloc.codeblock = node.value;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
455 findSymbolForLocation(prevloc);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
456 assert(prevloc.line != 0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
457 return prevloc;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
458 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
459
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
460 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
461 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
462 and a start address >= min_start.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
463 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
464 Location findSrcLine(SourceFile sf, uint min_line, size_t min_start=0)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
465 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
466 if ( sf is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
467 return null;
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 pragma(msg, TODO(__FILE__,__LINE__,"use binary search here"));
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
470 foreach ( l; sf.lines )
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 if ( l < min_line )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
473 continue;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
474 foreach ( cb; sf.blocks_by_line[l] )
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 if ( cb.start < min_start || cb.end <= cb.start )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
477 continue;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
478 Location loc = new Location(cb.start+image.getCodeBase, this);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
479 loc.codeblock = cb;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
480 findSymbolForLocation(loc);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
481 return loc;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
482 }
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 return null;
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
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 Find all debug information available for the given address.
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 Location findLocation(uint vaddress)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
491 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
492 Location loc = new Location(vaddress, this);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
493 CodeBlock cb = findCodeBlockAbs(vaddress);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
494 loc.codeblock = cb;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
495 findSymbolForLocation(loc);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
496 return loc;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
497 }
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 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
501 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
502 void findSymbolForLocation(Location loc)
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 ProcedureSymbol psym = findProcedureSymbol(loc.address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
505 if ( psym !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
506 loc.scope_sym = psym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
507 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
508 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
509 DataSymbol dsym = findDataSymbol(loc.address, 2);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
510 if ( dsym !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
511 loc.data_sym = dsym;
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 uint seg;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
515 Module mod = findModule(loc.address, seg);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
516 if ( mod !is null )
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 loc.mod = mod;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
519 if ( loc.data_sym is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
520 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
521 uint min_dist = uint.max;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
522 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
523 if ( loc.data_sym is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
524 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
525 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
526 }
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
529 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
530 Find procedure symbol covering the given address.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
531 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
532 ProcedureSymbol findProcedureSymbol(uint vaddress)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
533 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
534 uint address = vaddress-image.getCodeBase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
535 ProcedureSymbol ps;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
536 foreach ( m; modulesByIndex )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
537 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
538 ps = m.symbols.findProcedureSymbol(address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
539 if ( ps !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
540 return ps;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
541 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
542 ps = global_sym.findProcedureSymbol(address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
543 if ( ps is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
544 ps = static_sym.findProcedureSymbol(address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
545 if ( ps is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
546 ps = global_pub.findProcedureSymbol(address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
547 return ps;
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
550 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
551 Find data symbol covering the given address.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
552 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
553 DataSymbol findDataSymbol(uint vaddress, uint segment=0)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
554 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
555 uint address = vaddress-image.getCodeBase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
556 DataSymbol ps;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
557 foreach ( m; modulesByIndex )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
558 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
559 ps = m.symbols.findDataSymbol(address, segment);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
560 if ( ps !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
561 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
562 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
563 ps = global_sym.findDataSymbol(address, segment);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
564 if ( ps is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
565 ps = static_sym.findDataSymbol(address, segment);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
566 if ( ps is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
567 ps = global_pub.findDataSymbol(address, segment);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
568 return ps;
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 a D mangled name from a CodeView symbol.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
573 Uses available mangled type info if available, mangles CodeView type info else.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
574 Returns: Symbol name with mangled type info.
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 string mangle(NamedSymbol s)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
577 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
578 // use mangled typeinfo if available
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
579 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
580 return s.mangled_name;
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 return "_D"~mangleName(s.name_type)~mangleType(s);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
583 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
584
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
585 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
586 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
587 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
588 string mangleType(Symbol s)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
589 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
590 DataSymbol ds = cast(DataSymbol)s;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
591 ushort cvtype;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
592 if ( ds !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
593 cvtype = ds.cvdata.type;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
594 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
595 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
596 StackSymbol ss = cast(StackSymbol)s;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
597 if ( ss !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
598 cvtype = ss.cvdata.type;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
599 else {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
600 pragma(msg, TODO(__FILE__,__LINE__,"implement procedure symbol mangling"));
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
601 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
602 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
603 return mangleCVtype(cvtype);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
604 }
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 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
607 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
608 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
609 string mangleCVtype(ushort cvtype)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
610 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
611 if ( cvtype >= 0x1000 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
612 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
613 uint typeindex = cvtype-0x1000;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
614 if ( typeindex >= type_strings.length ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
615 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
616 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
617 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
618 Leaf[] typestring = type_strings[typeindex];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
619
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
620 while ( typestring.length > 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
621 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
622 switch ( typestring[0].leaf_index )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
623 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
624 case LF_MODIFIER_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
625 LeafModifer lm = cast(LeafModifer)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
626 assert ( lm !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
627 return mangleCVtype(lm.index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
628 case LF_POINTER_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
629 LeafPointer lp = cast(LeafPointer)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
630 assert ( lp !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
631 return "P"~mangleCVtype(lp.type);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
632 // do not insert new cases here
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
633 case LF_CLASS_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
634 LeafClassStruc lcs = cast(LeafClassStruc)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
635 assert ( lcs !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
636 return "C"~mangleName(lcs.name);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
637 case LF_ARRAY_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
638 LeafArray la = cast(LeafArray)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
639 assert ( la !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
640 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
641 uint count = la.length.getUint,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
642 elmsize = sizeofCV(la.elemtype);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
643 if ( elmsize > 0 ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
644 count /= elmsize;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
645 assert(la.length.getUint % sizeofCV(la.elemtype) == 0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
646 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
647 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
648 debug DbgIO.println("WARNING: elm size == 0");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
649 return "G"~.toString(count)~mangleCVtype(la.elemtype);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
650 case LF_OEM_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
651 LeafDynArray lda = cast(LeafDynArray)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
652 if ( lda !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
653 return "A"~mangleCVtype(lda.elem_type);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
654 LeafAssocArray laa = cast(LeafAssocArray)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
655 if ( laa !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
656 return "H"~mangleCVtype(laa.key_type)~mangleCVtype(laa.elem_type);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
657 LeafDelegate ld = cast(LeafDelegate)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
658 if ( ld !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
659 return "D"~mangleCVtype(ld.func_type);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
660 assert(0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
661
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
662 case LF_STRUCTURE_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
663 LeafClassStruc lcs = cast(LeafClassStruc)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
664 assert ( lcs !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
665 return "S"~mangleName(lcs.name);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
666 case LF_PROCEDURE_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
667 case LF_METHODLIST_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
668 debug(cvparser) DbgIO.println("unmangled procedure or methodlist in complex type");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
669 return "";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
670 case LF_UNION_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
671 LeafUnion lu = cast(LeafUnion)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
672 return "S"~mangleName(lu.name);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
673 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
674 DbgIO.println("mangleCVtype: unsupported type leaf 0x%x", typestring[0].leaf_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
675 typestring = typestring[1..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
676 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
677 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
678 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
679 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
680
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
681 switch ( cvtype )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
682 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
683 case T_NOTYPE:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
684 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
685 case T_VOID:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
686 return "v";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
687 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
688 return "Pv";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
689
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
690 case T_CHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
691 return "g";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
692 case T_UCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
693 return "h";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
694 case T_RCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
695 return "a";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
696 case T_WCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
697 return "u";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
698 case T_DCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
699 return "w";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
700 case T_32PDCHAR: case T_32PFDCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
701 return "Pw";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
702 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
703 return "Pa";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
704 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
705 return "Pu";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
706 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
707 return "Pg";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
708 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
709 return "Ph";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
710
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
711 case T_SHORT: case T_INT2:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
712 return "s";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
713 case T_USHORT: case T_UINT2:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
714 return "t";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
715 case T_PINT2: case T_PSHORT: case T_32PSHORT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
716 return "Ps";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
717 case T_PUSHORT: case T_PUINT2: case T_32PUSHORT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
718 return "Pt";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
719 case T_INT4:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
720 case T_LONG:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
721 return "i";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
722 case T_UINT4:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
723 case T_ULONG:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
724 return "k";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
725 case T_32PINT4: case T_PINT4:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
726 return "Pi";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
727 case T_32PUINT4: case T_PUINT4:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
728 return "Pk";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
729 case T_QUAD:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
730 return "l";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
731 case T_UQUAD:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
732 return "m";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
733 case T_32PQUAD: case T_PQUAD:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
734 return "Pl";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
735 case T_32PUQUAD: case T_PUQUAD:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
736 return "Pm";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
737 case T_REAL32:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
738 return "f";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
739 case T_32PREAL32: case T_PREAL32:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
740 return "Pf";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
741 case T_REAL64:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
742 return "d";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
743 case T_32PREAL64: case T_PREAL64:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
744 return "Pd";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
745 case T_REAL80:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
746 return "e";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
747 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
748 return "Pe";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
749 case T_BOOL08:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
750 return "b";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
751 case T_32PBOOL08: case T_32PFBOOL08:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
752 return "Pb";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
753 case T_CPLX80:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
754 return "c";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
755 case T_CPLX64:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
756 return "r";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
757 case T_CPLX32:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
758 return "q";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
759 case T_32PCPLX80: case T_32PFCPLX80:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
760 return "Pc";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
761 case T_32PCPLX64: case T_32PFCPLX64:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
762 return "Pr";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
763 case T_32PCPLX32: case T_32PFCPLX32:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
764 return "Pq";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
765 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
766 debug DbgIO.println("mangleCVtype: unknown codeview type 0x%x", cvtype);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
767 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
768 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
769 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
770
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
771
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
772 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
773 Returns: size of demangled type
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
774 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
775 uint sizeofMangled(string m)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
776 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
777 assert(m.length > 0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
778 switch ( m[0] )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
779 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
780 case 'A': return ulong.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
781 case 'G':
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
782 string n = m[1..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
783 size_t count = parseNumber(n);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
784 return count*sizeofMangled(n);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
785 case 'P': return size_t.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
786 case 'H': return size_t.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
787 case 'v': return void.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
788 case 'b': return bit.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
789 case 'x': return bool.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
790 case 'g': return byte.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
791 case 'h': return ubyte.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
792 case 's': return short.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
793 case 't': return ushort.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
794 case 'i': return int.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
795 case 'k': return uint.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
796 case 'l': return long.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
797 case 'm': return ulong.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
798 case 'f': return float.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
799 case 'd': return double.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
800 case 'e': return real.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
801 case 'o': return ifloat.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
802 case 'p': return idouble.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
803 case 'j': return ireal.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
804 case 'q': return cfloat.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
805 case 'r': return cdouble.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
806 case 'c': return creal.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
807 case 'a': return char.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
808 case 'u': return wchar.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
809 case 'w': return dchar.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
810 case 'C':
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
811 case 'S':
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
812 string mangled_name = m[1..$],
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
813 name = demangleNameSkip(mangled_name);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
814 if ( name in UDTsByName ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
815 LeafClassStruc lcs = cast(LeafClassStruc)UDTsByName[name];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
816 if ( lcs !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
817 return lcs.length.getUint;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
818 LeafUnion lu = cast(LeafUnion)UDTsByName[name];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
819 if ( lu !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
820 return lu.length.getUint;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
821 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
822 assert(0, "unknown struct in sizeofMangled: "~name);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
823 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
824 assert(0, "unknown type in sizeofMangled: "~m);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
825 }
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
829
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 Calculates the size of the type specified by a CodeView type 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 uint sizeofCV(uint cvtype)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
834 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
835 if ( cvtype >= 0x1000 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
836 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
837 uint typeindex = cvtype-0x1000;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
838 if ( typeindex >= type_strings.length ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
839 debug DbgIO.println("sizeofCV: undefined complex type 0x%x", cvtype);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
840 return 0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
841 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
842 Leaf[] typestring = type_strings[typeindex];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
843 while ( typestring.length > 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
844 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
845 switch ( typestring[0].leaf_index )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
846 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
847 case LF_MODIFIER_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
848 LeafModifer lm = cast(LeafModifer)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
849 assert ( lm !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
850 return sizeofCV(lm.index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
851 case LF_ARRAY_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
852 LeafArray la = cast(LeafArray)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
853 assert ( la !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
854 return la.length.getUint;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
855 case LF_POINTER_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
856 case LF_CLASS_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
857 return 4;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
858 case LF_STRUCTURE_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
859 LeafClassStruc lcs = cast(LeafClassStruc)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
860 assert ( lcs !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
861 return lcs.length.getUint;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
862 case LF_PROCEDURE_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
863 case LF_METHODLIST_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
864 debug DbgIO.println("unmangled procedure or methodlist in complex type");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
865 return 0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
866 case LF_UNION_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
867 LeafUnion lu = cast(LeafUnion)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
868 return lu.length.getUint;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
869 case LF_OEM_16t:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
870 LeafDynArray lda = cast(LeafDynArray)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
871 if ( lda !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
872 return size_t.sizeof*2;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
873 LeafAssocArray laa = cast(LeafAssocArray)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
874 if ( laa !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
875 return size_t.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
876 LeafDelegate ld = cast(LeafDelegate)typestring[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
877 if ( ld !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
878 return size_t.sizeof*2;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
879 assert(0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
880
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
881 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
882 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
883 typestring = typestring[1..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
884 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
885 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
886 return 0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
887 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
888
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
889 switch ( cvtype )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
890 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
891 case T_NOTYPE:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
892 return 0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
893 case T_VOID:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
894 case T_CHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
895 case T_UCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
896 case T_RCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
897 case T_BOOL08:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
898 return 1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
899 case T_SHORT: case T_INT2:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
900 case T_USHORT: case T_UINT2:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
901 case T_WCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
902 return 2;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
903 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
904 case T_DCHAR: case T_32PDCHAR: case T_32PFDCHAR:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
905 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
906 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
907 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
908 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
909 case T_PINT2: case T_PSHORT: case T_32PSHORT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
910 case T_PUSHORT: case T_PUINT2: case T_32PUSHORT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
911 case T_32PBOOL08: case T_32PFBOOL08:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
912 case T_INT4:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
913 case T_UINT4:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
914 case T_32PINT4: case T_PINT4:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
915 case T_32PUINT4: case T_PUINT4:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
916 case T_32PQUAD: case T_PQUAD:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
917 case T_32PUQUAD: case T_PUQUAD:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
918 case T_ULONG:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
919 case T_REAL32:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
920 case T_32PREAL32: case T_PREAL32:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
921 case T_32PREAL64: case T_PREAL64:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
922 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
923 case T_CPLX32:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
924 case T_32PCPLX32: case T_32PFCPLX32:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
925 case T_32PCPLX64: case T_32PFCPLX64:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
926 case T_32PCPLX80: case T_32PFCPLX80:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
927 return 4;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
928 case T_QUAD:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
929 case T_UQUAD:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
930 case T_REAL64:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
931 case T_CPLX64:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
932 return 8;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
933 case T_CPLX80:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
934 case T_REAL80:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
935 return 10;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
936 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
937 debug DbgIO.println("sizeofCV: unknown codeview type 0x%x", cvtype);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
938 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
939 return 0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
940 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
941 }