root/trunk/ElephantDebugApi/edbgstructures.h

Revision 5, 4.9 kB (checked in by qbert, 3 years ago)

Initial ( and last :( ) commit

Line 
1 #ifndef DDEBUG_STRUCTURES_H
2 #define DDEBUG_STRUCTURES_H
3
4 #include <windows.h>
5 #include <vector>
6 #include <string>
7
8 using std::vector;
9 using std::string;
10
11
12 #include "dmd_specifics.h"
13
14 typedef unsigned long ulong;
15 typedef unsigned int uint;
16
17 struct Data
18 {
19
20     virtual string toString() = 0;
21     virtual string toStringDetail() = 0;
22
23 };
24
25 struct BackTraceItem {
26     string symName;
27     string fileName;
28     int lineNumber;
29    
30     string moduleName;
31     string className;
32     string functionName;
33 };
34
35 struct DLLData : Data
36 {
37    
38     DLLData(LOAD_DLL_DEBUG_INFO i, string n,bool _loaded = true ) : info(i), name(n) , loaded(_loaded) {}
39
40     bool loaded;
41     LOAD_DLL_DEBUG_INFO info;
42     string name;
43
44     bool debugInfo() { return (info.nDebugInfoSize)?true:false; }
45
46     virtual string toString() { return name; }
47
48     virtual string toStringDetail() { return debugInfo() ? \t(Debug Info)":\t(No Debug Info)"; }
49 };
50
51 struct ProcessData : Data
52 {
53
54     ProcessData ()
55     {
56     }
57    
58     virtual string toString() { return "TODO"; }
59     virtual string toStringDetail() { return "TODO"; } 
60 };
61
62 struct RegisterDumpData : Data
63 {
64
65     // registers
66     ulong eax, ebx, ecx, edx, esi, edi;
67
68     // segments
69
70     ulong gs, fs, es, ds;
71
72     virtual string toString() { return toStringDetail(); }
73
74     virtual string toStringDetail()
75     {
76
77         char temp[4096];
78         sprintf(temp,"eax: %08lx , ebx: %08lx , ecx: %08lx , edx: %08lx , esi: %08lx , edi: %08lx\n"
79                 "gs: %08lx , fs: %08lx , es: %08lx , ds: %08lx ",eax,ebx,ecx,edx,esi,edi,gs,fs,es,ds );
80         return temp;
81
82     }
83
84     RegisterDumpData () {}
85
86     RegisterDumpData ( CONTEXT &context)
87     {
88
89         eax = context.Eax ;
90         ebx = context.Ebx ;
91         ecx = context.Ecx ;
92         edx =context.Edx ;
93         esi = context.Esi ;
94         edi = context.Edi ;
95         gs= context.SegGs;
96         fs= context.SegFs;
97         es= context.SegEs;
98         ds= context.SegDs;
99
100     }
101
102
103     ulong reg(int index)
104     {
105         switch (index)
106         {
107         case 0: return eax;
108         case 1: return ebx;
109         case 2: return ecx;
110         case 3: return edx;
111         case 4: return esi;
112         case 5: return edi;
113             //No break on purpose
114         }
115     }
116
117     string regName(int index)
118     {
119         switch (index)
120         {
121         case 0: return "eax";
122         case 1: return "ebx";
123         case 2: return "ecx";
124         case 3: return "edx";
125         case 4: return "esi";
126         case 5: return "edi";
127         default: return "error";
128         }
129     }
130
131
132     ulong seg(int index)
133     {
134         switch (index)
135         {
136         case 0: return gs;
137         case 1: return fs;
138         case 2: return es;
139         case 3: return ds;
140             //No break on purpose
141         }
142     }
143
144     string segName(int index)
145     {
146         switch (index)
147         {
148         case 0: return "gs";
149         case 1: return "fs";
150         case 2: return "es";
151         case 3: return "ds";
152         default: return "error";
153         }
154     }
155    
156     string regFormat(int index)
157     {
158         char temp[100]; //Constant string don't work for some reason
159         sprintf(temp,"%08lx", reg(index));
160         return temp;
161     }
162
163     string segFormat(int index)
164     {
165         char temp[100];//Constant string don't work for some reason
166         sprintf(temp,"%08lx", seg(index));
167         return temp;
168     }
169 };
170
171 struct ExceptionData : Data
172 {
173     string name;
174     string fileName;
175     uint lineNumber;
176     vector<BackTraceItem> backTraceItems;
177
178
179     virtual string toString() { return name; }
180
181     virtual string toStringDetail() { return ""; }
182
183     ExceptionData (string _name, string _fileName, uint _lineNumber)
184     {
185         name = _name;
186         fileName = _fileName;
187         lineNumber = _lineNumber;       
188
189     }
190    
191     ExceptionData (string _name, string _fileName, uint _lineNumber,vector<BackTraceItem>& bt)
192     {
193         name = _name;
194         fileName = _fileName;
195         lineNumber = _lineNumber;
196
197         for ( int i = 0;i < bt.size();i++) {
198
199             BackTraceItem data;
200             ::MessageBox(0,bt[i].symName.c_str(),"SYM",0);
201             data.symName = bt[i].symName;
202             data.fileName = bt[i].fileName;
203             data.lineNumber = bt[i].lineNumber;
204
205             string module = "", className = "", functionName = "";
206             demangle(data.symName,module,className,functionName);
207            
208             data.moduleName = module;
209             data.className = className;
210             data.functionName = functionName;
211            
212             backTraceItems.push_back(data);
213
214         }
215        
216     }
217 };
218
219 struct ThreadData : Data
220 {
221     virtual string toString() { return toStringDetail(); }
222
223     virtual string toStringDetail()
224     {
225         return "";
226     }
227    
228     ThreadData ()
229     {
230
231
232     }
233
234     ~ThreadData () {
235
236
237     }
238 };
239
240 struct BreakData
241 { 
242     ExceptionData *exception; //me
243     ThreadData thread;
244     RegisterDumpData registers;
245     ProcessData proccess;
246    
247     //string toString() { return "Break at " +  exception->strLineNumber(); }
248     string toStringDetail()
249     {
250         //      return exception.toStringDetail() ~ "\n" ~ thread.toStringDetail() ~  "\n" ~                   registers.toStringDetail ~ "\n" ~ proccess.toStringDetail() ~ "\n"; //TODO - remove end of lineNumber
251         return "";
252     }
253    
254     BreakData (ExceptionData &e, ThreadData &t, RegisterDumpData &r, ProcessData &p)
255     {
256        
257         exception = new ExceptionData(e);
258         thread = t;
259         registers = r;
260         proccess = p;
261        
262     }
263    
264     ~BreakData () {
265        
266        
267     }
268 };
269
270
271
272
273
274 #endif
275
276    
Note: See TracBrowser for help on using the browser.