annotate src/debugger.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 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
7 The main debugger code. Handles win32 debugging events,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
8 manages breakpoints, calls the disassembler, etc.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
9 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
10
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
11 import std.file;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
12 import std.string;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
13 import std.format;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
14
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
15 import win32.winbase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
16 import win32.winuser;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
17 import win32.winnt;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
18 import win32.dbghelp;
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 import minidump;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
21 import container;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
22 import util;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
23 import breakpoint;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
24 import dbgprocess;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
25 import dbgthread;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
26 import disasm;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
27 import callstack;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
28 import expression.evaluationcontext;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
29 import expression.expression_apd;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
30 import expression.datahandler;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
31 import codeview.coff;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
32 import codeview.codeview;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
33 import cli.userinterface;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
34
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
35 const uint VERSION_MAJOR = 0,
3
47dd986a534e version no fix
marton@basel.hu
parents: 1
diff changeset
36 VERSION_MINOR = 13,
5
marton@basel.hu
parents: 4
diff changeset
37 VERSION_PATCH = 3;
1
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
38 const string VERSION_STRING = "Ddbg "~itoa(VERSION_MAJOR)~"."~itoa(VERSION_MINOR)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
39 ~(VERSION_PATCH>0?"."~itoa(VERSION_PATCH):"")~" beta",
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
40 WELCOME_STRING = VERSION_STRING~" - D Debugger\n"~
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
41 "Copyright (c) 2007 Jascha Wetzel\n"~
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
42 "see http://ddbg.mainia.de/doc.html for documentation\n";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
43
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
44 class DebuggerException : Exception
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
45 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
46 this(...)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
47 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
48 string str;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
49
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
50 void putc(dchar c)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
51 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
52 str ~= c;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
53 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
54
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
55 doFormat(&putc, _arguments, _argptr);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
56 super(str);
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 /**************************************************************************************************
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 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
63 class Debugger
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
64 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
65 const uint STATUS_DIGITAL_MARS_D_EXCEPTION = (3 << 30) | (1 << 29) | (0 << 28) | ('D' << 16) | 1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
66
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
67 //=============================================================================================
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
68 // variables
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
69 bool paused,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
70 process_loaded,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
71 abort,
4
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
72 single_step,
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
73 breakonmain =false
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
74 ;
1
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
75
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
76 size_t current_address;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
77 uint last_line;
5
marton@basel.hu
parents: 4
diff changeset
78 // uint repeat=0;
1
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
79 string[][string] source_files;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
80 string[] source_search_paths;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
81
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
82 string main_image_file;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
83 COFFImage main_image;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
84 ImageSet images;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
85
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
86 Breakpoint[uint] breakpoints;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
87 List!(Breakpoint) temp_breakpoints;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
88 Breakpoint passing_breakpoint;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
89 DbgProcess process;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
90 MiniDump miniDump;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
91
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
92 CallStack current_stack;
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 EXCEPTION_RECORD* exceptionRecord;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
95 DEBUG_EVENT debug_event;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
96 uint process_id,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
97 thread_id;
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 UserInterface ui;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
100
4
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
101 uint evaluationDepth = 2;
1
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
102 bool create_new_console;
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 //=============================================================================================
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
105 // construction
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
106
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
107 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
108 Uses the debugger's CLI arguments for the debuggee.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
109 Example: debugger debuggee arg0 arg1 ...
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 this(string debuggee, UserInterface _ui)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
112 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
113 assert(_ui !is null);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
114 images = new ImageSet;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
115 ui = _ui;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
116 openImage(debuggee);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
117 source_search_paths ~= ".\\";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
118 temp_breakpoints = new List!(Breakpoint);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
119 }
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 CallStack stack()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
122 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
123 if ( current_stack is null )
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 if ( process !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
126 current_stack = process.loadStack(process.threads[thread_id]);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
127 else if ( miniDump !is null ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
128 CONTEXT* ctx = miniDump.getContext;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
129 // TODO: where does that 4-byte offset come from
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
130 ubyte[] data = miniDump.getMemory(miniDump.thread.Stack.Memory)[4..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
131 current_stack = new CallStack(cast(size_t)miniDump.thread.Stack.StartOfMemoryRange+data.length, ctx.Esp, ctx.Ebp);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
132 current_stack.data = data;
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 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
135 return current_stack;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
136 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
137
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
138 /**********************************************************************************************
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 bool step(StepMode mode)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
142 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
143 if ( !process_loaded )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
144 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
145 Location loc = images.findLocation(current_address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
146
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
147 int bpi=-1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
148 Breakpoint bp;
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 switch ( mode )
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 //-------------------------------------------------------------------------------------
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
153 case StepMode.e_in:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
154 Location next_loc = images.findNextSrcLine(loc);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
155 if ( next_loc !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
156 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
157 bp = setBreakpoint(next_loc, bpi, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
158 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
159 addForeachBreakpoint(bp);
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
162 size_t disasm_end;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
163 if ( loc.codeblock !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
164 disasm_end = loc.codeblock.end+loc.getCodeBase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
165 DisAsm.disasm(
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
166 process, current_address, disasm_end,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
167 (ud_t* ud_obj) { return setBranchBreakpoints(ud_obj,StepMode.e_in); }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
168 );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
169 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
170 //-------------------------------------------------------------------------------------
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
171 case StepMode.e_out:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
172 uint ret_adr = getReturnAddress(loc);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
173 if ( ret_adr > 0 ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
174 debug DbgIO.println("setting step-out to 0x%08x", ret_adr);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
175 bp = setBreakpoint(ret_adr, bpi, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
176 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
177 bp.frame_ptr = getFramePointer(loc, 1);
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 else
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 debug DbgIO.println("no scope found - falling back on disasm-step-out");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
182 DisAsm.disasm(
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
183 process, current_address, 0,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
184 (ud_t* ud_obj) { return setBranchBreakpoints(ud_obj,StepMode.e_out); }
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 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
188 //-------------------------------------------------------------------------------------
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
189 case StepMode.e_over:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
190 Location next_loc = images.findNextSrcLine(loc);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
191 if ( next_loc !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
192 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
193 bp = setBreakpoint(next_loc, bpi, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
194 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
195 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
196 bp.frame_ptr = getFramePointer(loc);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
197 debug DbgIO.println("FP for step over is 0x%x", bp.frame_ptr);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
198 addForeachBreakpoint(bp);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
199 }
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 size_t disasm_end;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
203 if ( loc.codeblock !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
204 disasm_end = loc.codeblock.end+loc.getCodeBase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
205 DisAsm.disasm(
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
206 process, current_address, disasm_end,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
207 (ud_t* ud_obj) { return setBranchBreakpoints(ud_obj,StepMode.e_over); }
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 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
210 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
211 assert(0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
212 }
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 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
215 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
216
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
217 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
218
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
219 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
220 void addForeachBreakpoint(Breakpoint foreach_end)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
221 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
222 CodeView cv;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
223 CodeBlock cb = images.findCodeBlockAbs(current_address, cv);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
224 if ( cb !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
225 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
226 CodeBlock cbs[] = cb.segment.file.blocks_by_line[cb.line];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
227 if ( cbs.length > 1 && cb is cbs[0] )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
228 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
229 Location loc = images.findLocation(cbs[1].start+cv.getCodeBase);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
230 if ( loc.scope_sym !is null && find(loc.scope_sym.mangled_name, "__foreachbody") >= 0 )
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 int bpi;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
233 if ( getBreakpoint(loc.address, bpi) is null ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
234 Breakpoint bp = new Breakpoint(loc, true, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
235 bp.foreach_end = foreach_end;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
236 foreach_end.foreach_end = foreach_end;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
237 addBreakpoint(bp, -1);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
238 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
239 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
240 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
241 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
242 }
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
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 uint getReturnAddress(Location loc)
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 ProcedureSymbol psym = cast(ProcedureSymbol)loc.scope_sym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
250 if ( psym !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
251 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
252 uint index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
253 ubyte[] frame = stack.firstFrame(index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
254
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
255 if ( frame is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
256 throw new DebuggerException("getReturnAddress: null frame");
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 uint adr = current_address-psym.cvdata.offset-loc.getCodeBase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
259 if ( adr >= psym.cvdata.debug_start && adr < psym.cvdata.debug_end ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
260 frame = stack.prevFrame(index, index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
261 if ( frame.length >= 8 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
262 return (cast(uint[])frame)[1];
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 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
265 return 0;
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
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 uint getFramePointer(Location loc, uint level=0)
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 ProcedureSymbol psym = cast(ProcedureSymbol)loc.scope_sym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
274 if ( psym !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
275 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
276 uint frame_ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
277 if ( level > 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
278 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
279 uint index,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
280 l;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
281 ubyte[] frame = stack.firstFrame(index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
282 if ( frame is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
283 throw new DebuggerException("getCurrenFramePointer: null frame");
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 for ( l = 0; l < level && frame !is null; ++l )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
286 frame = stack.prevFrame(index, index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
287 if ( frame is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
288 throw new DebuggerException("getCurrenFramePointer: null frame at level %d", l);
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 frame_ptr = (cast(uint[])frame)[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
291 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
292 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
293 frame_ptr = stack.frame_ptr;
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 uint adr = current_address-psym.cvdata.offset-loc.getCodeBase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
296 if ( adr >= psym.cvdata.debug_start && adr < psym.cvdata.debug_end )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
297 return frame_ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
298 }
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 }
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
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 SymbolData evaluateExpression(string expr, uint frame_level=0, NamedSymbol symbol=null)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
306 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
307 SyntaxTree* root;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
308 bool success;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
309 try success = parse("", expr, root, true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
310 catch( ParserException e )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
311 throw new EvaluationException("Parser: "~e.toString);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
312 if ( !success )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
313 throw new EvaluationException("Parser: Invalid expression!");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
314
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
315 string elmtype;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
316 uint scope_address;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
317 if ( frame_level == 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
318 scope_address = current_address;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
319 else {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
320 ubyte[] frame = stack.getFrame(frame_level);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
321 scope_address = (cast(uint[])frame)[1];
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
324 SymbolData sd;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
325 auto loc = images.findLocation(current_address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
326 if ( loc.codeview is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
327 throw new EvaluationException("No debug symbols available");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
328 root.Expr(new EvaluationContext(
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
329 loc.codeview, scope_address,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
330 miniDump, process, process is null?null:process.threads[thread_id],
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
331 stack, frame_level), sd
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
332 );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
333 return sd;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
334 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
335
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
336 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
337
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
338 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
339 SymbolValue handleData(SymbolData sd, bool decreaseED)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
340 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
341 auto loc = images.findLocation(current_address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
342 if ( loc.codeview is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
343 throw new EvaluationException("No debug symbols available");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
344 EvaluationContext ctx = new EvaluationContext(
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
345 loc.codeview, 0,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
346 miniDump, process, process is null?null:process.threads[thread_id],
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
347 stack, 0
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
348 );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
349
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
350 ubyte[] data = sd.getData(ctx);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
351 if ( data.length <= 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
352 throw new EvaluationException("Expression evaluated to empty data");
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 uint ed = evaluationDepth;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
355 if ( decreaseED )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
356 --ed;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
357 SymbolValue val = DataHandler.handle(ctx, sd.type, data, ed);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
358 if ( val is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
359 throw new EvaluationException("No DataHandler for type "~sd.type);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
360 return val;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
361 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
362
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
363
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 uint getScopeAddress(uint frame_level)
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 uint scope_address;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
370 if ( frame_level == 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
371 scope_address = current_address;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
372 else {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
373 ubyte[] frame = stack.getFrame(frame_level);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
374 if ( frame !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
375 scope_address = (cast(uint[])frame)[1];
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 return scope_address;
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
380
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
381 //=============================================================================================
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
382 // process & thread handling
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
383
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
384 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
385
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
386 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
387 void selectThread(size_t threadId)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
388 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
389 thread_id = threadId;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
390 current_stack = null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
391
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
392 if ( process !is null ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
393 CONTEXT ctx;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
394 if ( !process.threads[threadId].getContext(ctx) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
395 throw new DebuggerException("Couldn't get thread's context");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
396 current_address = ctx.Eip;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
397 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
398 else if ( miniDump !is null ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
399 miniDump.selectThread(threadId);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
400 CONTEXT* ctx = miniDump.getContext;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
401 current_address = ctx.Eip;
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 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
404 throw new DebuggerException("Invalid debugger state");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
405 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
406
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
407 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
408 Loads and parses the PE image.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
409 Returns: success
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
410 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
411 void openImage(string filename)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
412 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
413 assert(filename.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
414 filename = strip(filename);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
415 if ( !exists(filename) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
416 filename ~= ".exe";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
417 if ( !exists(filename) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
418 throw new DebuggerException("Couldn't open \"%s\"", filename[0..$-4]);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
419 main_image_file = filename.dup;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
420
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
421 main_image = new COFFImage;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
422 main_image.load(main_image_file);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
423 // catch ( Exception e ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
424 // throw new DebuggerException("Failed to load COFF image \""~main_image_file~"\": "~e.msg);
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 if ( main_image.codeView is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
427 DbgIO.println("WARNING: No debugging symbols found in main image, try compiling and linking with -g");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
428 images ~= main_image;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
429 // return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
430 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
431
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 Creates the child process for the debuggee.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
434 Returns: success
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
435 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
436 bool createDebugProcess(string command_line)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
437 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
438 // initialiZe process startup information
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
439 STARTUPINFOA* startInfo = new STARTUPINFOA;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
440 startInfo.cb = STARTUPINFO.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
441 startInfo.dwFlags = STARTF_FORCEONFEEDBACK | STARTF_USESHOWWINDOW;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
442 startInfo.wShowWindow = SW_SHOWNORMAL;
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 PROCESS_INFORMATION procInfo; // process info
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
445
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
446 // create process
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
447 uint flags = DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
448 if ( create_new_console )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
449 flags |= CREATE_NEW_CONSOLE;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
450
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
451 bool suc = cast(bool)CreateProcessA(
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
452 toStringz(main_image_file), toStringz(command_line), cast(LPSECURITY_ATTRIBUTES)null,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
453 cast(LPSECURITY_ATTRIBUTES)null, false, flags, null, cast(char*)null,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
454 cast(LPSTARTUPINFOA)startInfo, cast(LPPROCESS_INFORMATION)&procInfo
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
455 );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
456 if( !suc )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
457 throw new DebuggerException("CreateProcess failed on %s", main_image_file);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
458 assert(procInfo.dwProcessId);
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 // open process for all access
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
461 HANDLE hChildProcess = OpenProcess(PROCESS_ALL_ACCESS, false, procInfo.dwProcessId);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
462 if( hChildProcess == null ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
463 TerminateProcess(procInfo.hProcess, 0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
464 throw new DebuggerException("OpenProcess failed");
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 process_id = procInfo.dwProcessId;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
467
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
468 CloseHandle(procInfo.hProcess);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
469 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
470 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
471
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
472 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
473
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
474 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
475 void resume()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
476 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
477 single_step = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
478 paused = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
479 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
480
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
481 //=============================================================================================
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
482 // exception handling
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
483
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
484 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
485 Debugger's main loop. Handles win32 debugging events.
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 void start(string command_line)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
488 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
489 createDebugProcess(command_line);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
490
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
491 while( !abort )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
492 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
493 if( WaitForDebugEvent(&debug_event, win32.winbase.INFINITE) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
494 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
495 if( debug_event.dwProcessId != process_id ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
496 debug DbgIO.println("WARNING: Exception for unhandled process received: PID=%d", debug_event.dwProcessId);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
497 ContinueDebugEvent(debug_event.dwProcessId, debug_event.dwThreadId, DBG_CONTINUE);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
498 continue;
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
501 current_stack = null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
502 thread_id = debug_event.dwThreadId;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
503 exceptionRecord = null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
504
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
505 bool exception_handled = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
506 switch( debug_event.dwDebugEventCode )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
507 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
508 case OUTPUT_DEBUG_STRING_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
509 char[] debug_string;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
510 paused = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
511
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
512 debug_string.length = debug_event.DebugString.nDebugStringLength;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
513 process.readProcessMemory(cast(uint)debug_event.DebugString.lpDebugStringData, debug_string.ptr, debug_string.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
514 if ( debug_event.DebugString.fUnicode )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
515 DbgIO.println("WARNING: Unicode debug strings not implemented, yet. Output might be corrupted");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
516
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
517 if ( debug_string.length > 3 && debug_string[0..4] == "DDL:" )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
518 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
519 string cmdStr = debug_string[4..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
520 if ( strip(cmdStr).length > 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
521 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
522 auto r = std.regexp.RegExp("(([^\" \\t]+)|(\"[^\"]+\"))+");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
523 string[] cmd;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
524 foreach ( m; r.search(strip(cmdStr)) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
525 cmd ~= r.match(0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
526 switch ( cmd[0] )
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 case "load":
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
529 DbgIO.println("loadImage not implemented, yet: %s %s", cmd[1], cmd[2]);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
530 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
531 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
532 DbgIO.println("WARNING: Unknown DDL command recieved: %s", cmdStr);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
533 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
534 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
535 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
536 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
537 else if ( debug_string.length > 5 && debug_string[0..5] == "Ddbg:" )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
538 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
539 ui.runCommands(debug_string[5..$]);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
540 paused = true;
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 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
543 ui.debugString(debug_string);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
544 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
545
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
546 case EXCEPTION_DEBUG_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
547 exceptionRecord = &debug_event.Exception.ExceptionRecord;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
548 exception_handled = handleExceptionEvent(exceptionRecord);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
549 break;
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 case LOAD_DLL_DEBUG_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
552 DLL dll = process.loadDLL(&debug_event.LoadDll);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
553 if ( dll.image !is null )
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 images ~= dll.image;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
556 foreach ( bp; breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
557 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
558 if ( bp.location.address == 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
559 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
560 debug DbgIO.println("binding bp %s", bp.toString);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
561 if ( bp.location.bind(images, source_search_paths) ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
562 debug DbgIO.println("activating bp %s", bp.toString);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
563 bp.activate(process);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
564 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
565 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
566 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
567 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
568 ui.loadedDLL(dll);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
569 paused = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
570 break;
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 case UNLOAD_DLL_DEBUG_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
573 // DebugDLL* dll = process.findDLL(cast(uint)debug_event.LoadDll.lpBaseOfDll);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
574 // ui.unloadedDLL(dll);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
575 // images.remove(dll.image);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
576 paused = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
577 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
578
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
579 case CREATE_THREAD_DEBUG_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
580 process.threads[debug_event.dwThreadId] = new DbgThread(debug_event.CreateThread.hThread, debug_event.dwThreadId);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
581 paused = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
582 break;
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 case EXIT_THREAD_DEBUG_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
585 process.threads.remove(debug_event.dwThreadId);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
586 paused = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
587 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
588
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
589 case CREATE_PROCESS_DEBUG_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
590 process = new DbgProcess;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
591 process.processId = process_id;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
592 process.process_handle = debug_event.CreateProcessInfo.hProcess;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
593 process.mainThreadId = debug_event.dwThreadId;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
594 process.threads[debug_event.dwThreadId] = new DbgThread(debug_event.CreateProcessInfo.hThread, debug_event.dwThreadId);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
595 process_loaded = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
596
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
597 if ( main_image !is null && main_image.codeView !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
598 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
599 DataSymbol mainds;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
600 if ( main_image.codeView.global_pub !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
601 mainds = main_image.codeView.global_pub.findDataSymbol("_main");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
602 if ( mainds !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
603 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
604 int bpi=-1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
605 Breakpoint bp = setBreakpoint(mainds.offset+main_image.getCodeBase, bpi, 0, true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
606 bp.deactivate_d_exception_handler = true;
4
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
607 debug DbgIO.println("set breakpoint");
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
608 }
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
609 {
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
610 int bpi=-1;
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
611 // stop on first line
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
612 if (breakonmain)
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
613 {
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
614 breakonmain=false;
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
615 mainds = main_image.codeView.global_pub.findDataSymbol("__Dmain");
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
616 if ( mainds !is null )
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
617 {
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
618 Breakpoint bp = setBreakpoint(mainds.offset+main_image.getCodeBase, bpi, thread_id);
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
619 }
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
620 }
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
621
1
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
622 }
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
625 foreach ( bp; breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
626 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
627 if ( bp.location.address != 0 && !bp.activate(process) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
628 throw new DebuggerException("Error: couldn't write breakpoint opcode at %s:%d", bp.file, bp.line);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
629 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
630 foreach ( bp; temp_breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
631 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
632 debug DbgIO.println("tbp activated %s", bp.value);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
633 if ( bp.value.location.address != 0 && !bp.value.activate(process) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
634 throw new DebuggerException("Error: couldn't write breakpoint opcode at %s:%d", bp.value.file, bp.value.line);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
635 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
636 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
637
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
638 case EXIT_PROCESS_DEBUG_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
639 process_loaded = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
640 delete process;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
641 paused = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
642 single_step = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
643 ui.exitProcess;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
644 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
645
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
646 case RIP_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
647 debug DbgIO.println("DebugEvent: "~getEventName(debug_event.dwDebugEventCode));
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
648 paused = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
649 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
650
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
651 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
652 throw new DebuggerException("Win32Debugger ERROR - unknown debug event: %d", debug_event.dwDebugEventCode);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
653 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
654
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
655 if ( single_step )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
656 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
657 ui.singleStep();
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
658 paused = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
659 activateSingleStep(true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
660 }
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 if ( paused )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
663 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
664 bool cont=false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
665 while ( !cont )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
666 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
667 debug
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
668 cont = ui.readCommand();
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
669 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
670 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
671 try cont = ui.readCommand();
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
672 catch ( Exception e )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
673 DbgIO.println("%s", e.msg);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
674 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
675 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
676 paused = false;
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
679 if ( !abort )
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 exceptionRecord = null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
682 ContinueDebugEvent(
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
683 debug_event.dwProcessId, debug_event.dwThreadId,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
684 exception_handled?DBG_CONTINUE:DBG_EXCEPTION_NOT_HANDLED
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
685 );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
686 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
687 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
688 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
689 throw new DebuggerException("ERROR: WaitForDebugEvent failed: %s", lastError);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
690 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
691 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
692
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
693 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
694 Activates single step execution by setting the trap flag in
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
695 the eflags register of the currently considered thread.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
696 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
697 void activateSingleStep(bool enable)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
698 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
699 if ( !(thread_id in process.threads) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
700 return;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
701 if ( enable )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
702 process.threads[thread_id].changeContext(delegate(ref CONTEXT ctx){ ctx.EFlags |= 1<<8; });
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
703 else if ( !enable )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
704 process.threads[thread_id].changeContext(delegate(ref CONTEXT ctx){ ctx.EFlags &= ~(1<<8); });
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
705 single_step = enable;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
706 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
707
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
708 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
709
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 void getExceptionNameMessage(size_t objPtr, out char[] class_name, out char[] msg)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
712 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
713 // get thrown object's class name
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
714 ClassInfo ci = process.getClassInfo(objPtr);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
715 class_name.length = ci.name.length;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
716 process.readProcessMemory(cast(uint)ci.name.ptr, class_name.ptr, class_name.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
717
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
718 // get object's data
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
719 uint[] objdata;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
720 objdata.length = ci.init.length;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
721 process.readProcessMemory(objPtr, objdata.ptr, objdata.length*uint.sizeof);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
722
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
723 char[] name;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
724 name ~= class_name;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
725 do
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
726 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
727 if ( name == "object.Exception" )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
728 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
729 msg.length = objdata[2];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
730 process.readProcessMemory(objdata[3], msg.ptr, msg.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
731 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
732 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
733
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
734 ubyte[] data;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
735 data.length = ClassInfo.classinfo.init.length;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
736 process.readProcessMemory(cast(uint)cast(void*)ci.base, data.ptr, data.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
737 ci = cast(ClassInfo)data.ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
738 name.length = ci.name.length;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
739 process.readProcessMemory(cast(uint)ci.name.ptr, name.ptr, name.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
740 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
741 while ( ci.base !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
742 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
743
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
744 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
745
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
746 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
747 bool handleExceptionEvent(EXCEPTION_RECORD* exrec)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
748 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
749 current_address = cast(uint)exrec.ExceptionAddress;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
750 Lswitch: switch ( exrec.ExceptionCode )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
751 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
752 case EXCEPTION_BREAKPOINT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
753 debug DbgIO.println("EXCEPTION_BREAKPOINT");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
754 int bp_index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
755 Breakpoint bp = getBreakpoint(current_address, bp_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
756 if ( bp !is null ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
757 handleBreakpoint(bp, bp_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
758 last_line = bp.line;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
759 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
760 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
761 ui.breakpoint(-1, new Breakpoint(images.findLocation(cast(uint)exrec.ExceptionAddress), false, 0, false), process.threads[thread_id]);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
762 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
763 case EXCEPTION_SINGLE_STEP:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
764 debug DbgIO.println("EXCEPTION_SINGLE_STEP");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
765 // check whether this is a HWBP or real single step
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
766 CONTEXT ctx;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
767 process.threads[thread_id].getContext(ctx, CONTEXT_DEBUG_REGISTERS);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
768
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
769 if ( (ctx.Dr6 & 0xf) > 0 )
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 debug DbgIO.println("Hardware breakpoint");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
772 size_t dr = void;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
773 if ( ctx.Dr6 & 1 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
774 dr = ctx.Dr0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
775 else if ( ctx.Dr6 & 2 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
776 dr = ctx.Dr1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
777 else if ( ctx.Dr6 & 4 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
778 dr = ctx.Dr2;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
779 else if ( ctx.Dr6 & 8 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
780 dr = ctx.Dr3;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
781 int bp_index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
782 foreach( i, bp; breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
783 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
784 if( !bp.hardware )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
785 continue;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
786 if ( dr == bp.address ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
787 handleBreakpoint(bp, i);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
788 break Lswitch;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
789 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
790 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
791
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
792 ui.breakpoint(-1, new Breakpoint(images.findLocation(dr), false, 0, false), process.threads[thread_id]);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
793 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
794 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
795 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
796 debug DbgIO.println("Single Step exception");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
797 // pause if interactive single step is active
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
798 paused = single_step;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
799
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
800 if ( passing_breakpoint !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
801 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
802 debug DbgIO.println("passing breakpoint");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
803 activateSingleStep(false);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
804 paused = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
805 if ( process !is null && !passing_breakpoint.activate(process) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
806 throw new DebuggerException("ERROR: Failed to write breakpoint opcode at %s:%d", passing_breakpoint.file, passing_breakpoint.line);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
807 passing_breakpoint = null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
808 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
809 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
810 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
811 // ctrl+c
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
812 case DBG_CONTROL_C:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
813 ui.userInterrupt();
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
814 paused = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
815 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
816 // D exceptions
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
817 case STATUS_DIGITAL_MARS_D_EXCEPTION:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
818 // normal non-post-mortem mode
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
819 if ( process !is null && !debug_event.Exception.dwFirstChance )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
820 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
821 char[] class_name, msg;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
822 getExceptionNameMessage(exrec.ExceptionInformation[0], class_name, msg);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
823 ui.exception(thread_id, class_name, msg, exrec.ExceptionInformation[0]);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
824 paused = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
825 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
826 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
827 // minidump mode
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
828 else if ( miniDump !is null )
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 string className,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
831 message;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
832 className = (cast(char*)exrec.ExceptionInformation[1])[0..exrec.ExceptionInformation[0]];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
833 message = (cast(char*)exrec.ExceptionInformation[3])[0..exrec.ExceptionInformation[2]];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
834 ui.exception(thread_id, className, message, 0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
835 paused = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
836 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
837 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
838 paused = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
839 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
840 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
841 ui.win32exception(thread_id, exrec);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
842 paused = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
843 single_step = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
844 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
845 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
846 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
847 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
848
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
849 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
850
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
851 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
852 void handleBreakpoint(Breakpoint bp, uint bp_index)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
853 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
854 CONTEXT ctx;
4
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
855 debug DbgIO.println("handling breakpoint");
1
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
856 if ( !process.threads[thread_id].getContext(ctx) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
857 throw new DebuggerException("Error: Couldn't GetThreadContext to reset instruction pointer: %s", lastError);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
858
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
859 if ( !bp.hardware )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
860 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
861 if ( process !is null && !bp.deactivate(process) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
862 throw new DebuggerException("ERROR: Failed to write opcode for breakpoint at %s:%d", bp.file, bp.line);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
863
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
864 // adjust for "int 3" instruction byte
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
865 --ctx.Eip;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
866 if ( !process.threads[thread_id].setContext(ctx) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
867 throw new DebuggerException("Error: Couldn't SetThreadContext to reset instruction pointer: %s", lastError);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
868 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
869
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
870 // check if we have a constrained thread
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
871 if ( bp.threadId > 0 && thread_id != bp.threadId )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
872 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
873 debug DbgIO.println("skipping bp in incorrect thread %d", thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
874 if ( !bp.hardware ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
875 passing_breakpoint = bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
876 activateSingleStep(true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
877 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
878 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
879 // check if breakpoint requires a certain frame
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
880 else if ( bp.frame_ptr > 0 && bp.frame_ptr != ctx.Ebp )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
881 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
882 debug DbgIO.println("skipping bp in incorrect frame, Ebp=0x%x required=0x%x", ctx.Ebp, bp.frame_ptr);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
883 if ( !bp.hardware ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
884 passing_breakpoint = bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
885 activateSingleStep(true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
886 }
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 // restore non-temporary breakpoints
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
889 else if ( !bp.temporary )
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 ui.breakpoint(bp_index, bp, process.threads[thread_id]);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
892 paused = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
893 if ( !bp.hardware ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
894 passing_breakpoint = bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
895 activateSingleStep(true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
896 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
897 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
898 // propagate breakpoints to jmp/call/ret destination
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
899 else if ( bp.propagate )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
900 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
901 debug DbgIO.println("propagate");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
902 foreach ( tbp; temp_breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
903 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
904 if ( tbp.value is bp ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
905 temp_breakpoints.remove(tbp);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
906 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
907 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
908 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
909 DisAsm.disasm(process, current_address, 0, (ud_t* ud_obj){return setPropagatedBreakpoint(ud_obj,bp);});
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
910 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
911 // temporary breakpoints
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
912 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
913 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
914 if ( bp.deactivate_d_exception_handler ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
915 debug DbgIO.println("deactivateDExceptionHandler");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
916 deactivateDExceptionHandler();
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
917 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
918 else {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
919 clearTemporaryBreakpoints();
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
920 paused = ui.breakpoint(-1, bp, process.threads[thread_id]);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
921 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
922 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
923 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
924
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
925 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
926
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
927 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
928 void deactivateDExceptionHandler()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
929 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
930 if ( main_image is null || main_image.codeView is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
931 return;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
932
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
933 // deactivate default D exception handling
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
934 bool found=false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
935 foreach ( ds; main_image.codeView.global_pub.data_symbols )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
936 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
937 if ( ds.name_notype == "_no_catch_exceptions" ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
938 uint address = ds.offset+main_image.getSectionBase(ds.cvdata.segment);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
939 bool nce = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
940 process.writeProcessMemory(address, &nce, bool.sizeof);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
941 found = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
942 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
943 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
944 else if ( ds.name_notype == "_cr_trapExceptions"
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
945 || ds.name_notype == "_rt_trapExceptions" )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
946 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
947 uint address = ds.offset+main_image.getSectionBase(ds.cvdata.segment);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
948 bool nce = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
949 process.writeProcessMemory(address, &nce, bool.sizeof);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
950 found = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
951 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
952 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
953 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
954 if ( !found ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
955 debug DbgIO.println("Neither Phobos nor Tango exception handler switch not found");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
956 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
957 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
958
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
959 //=============================================================================================
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
960 // source&symbol handling
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
961
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
962 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
963 Searches the cache for the given source file and loads it if nessecary.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
964 Tries to load the source file from all source_search_paths.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
965 Returns: Array of lines of the source file.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
966 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
967 string[] getSourceFile(string filename)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
968 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
969 if ( filename is null || filename.length <= 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
970 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
971 if ( !(filename in source_files) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
972 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
973 string full = getFullSourcePath(filename);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
974 if ( full is null || !exists(full) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
975 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
976 auto lines = splitlines(cast(string)read(full));
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
977 source_files[filename] = lines;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
978 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
979 return source_files[filename];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
980 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
981
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
982 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
983 Tries to find the source file in all source_search_paths.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
984 Returns: Full path of the file
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
985 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
986 string getFullSourcePath(string filename)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
987 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
988 string full = getFullPath(filename);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
989 if ( exists(full) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
990 return full;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
991 foreach ( string sp; source_search_paths )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
992 {
4
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
993 debug DbgIO.println("searching for source file %s",sp~filename);
1
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
994 full = getFullPath(sp~filename);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
995 if ( exists(full) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
996 return full;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
997 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
998 return filename;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
999 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1000
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1001
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1002 //=============================================================================================
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1003 // breakpoint handling
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1004
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1005 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1006
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1007 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1008 bool setPropagatedBreakpoint(ud* ud_obj, Breakpoint prev_bp)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1009 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1010 if ( ud_obj is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1011 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1012
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1013 int bpi=-1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1014 Breakpoint bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1015 if ( DisAsm.isConditionalJump(ud_obj.mnemonic)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1016 || ud_obj.mnemonic == ud_mnemonic_code.UD_Ijmp
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1017 || ud_obj.mnemonic == ud_mnemonic_code.UD_Icall )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1018 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1019 bool is_imm=false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1020 uint jmp_dest = DisAsm.calcJumpDestination(process, process.threads[thread_id], ud_obj, is_imm);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1021 assert(!is_imm);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1022 debug DbgIO.println("propagating jmp/call bp to 0x%x", jmp_dest);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1023 Location loc = images.findLocation(jmp_dest);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1024 if ( loc.file !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1025 bp = setBreakpoint(jmp_dest, bpi, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1026 else {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1027 debug DbgIO.println("not source info available - checking for unconditional jmp at destination");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1028 DisAsm.disasm(process, jmp_dest, 0, (ud_t* ud_obj){return propagateUncondJmp(ud_obj, prev_bp);});
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1029 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1030 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1031 bp.frame_ptr = prev_bp.frame_ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1032 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1033 else if ( ud_obj.mnemonic == ud_mnemonic_code.UD_Iret || ud_obj.mnemonic == ud_mnemonic_code.UD_Iretf )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1034 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1035 uint index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1036 size_t ret_adr = (cast(uint[])stack.data)[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1037 Location loc = images.findLocation(ret_adr);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1038 if ( loc.file !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1039 bp = setBreakpoint(ret_adr, bpi, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1040 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1041 debug DbgIO.println("not setting BP on unknown ret address 0x%x", ret_adr);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1042 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1043 bp.frame_ptr = prev_bp.frame_ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1044 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1045 else {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1046 debug DbgIO.println("unknown instruction for propagating breakpoint");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1047 assert(0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1048 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1049
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1050 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1051 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1052
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1053 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1054 Propagate breakpoint if unconditional jump is found.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1055 Used for virtual functions with redirectors.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1056 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1057 bool propagateUncondJmp(ud* ud_obj, Breakpoint prev_bp)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1058 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1059 if ( ud_obj is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1060 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1061
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1062 int bpi=-1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1063 Breakpoint bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1064 if ( DisAsm.isConditionalJump(ud_obj.mnemonic)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1065 || ud_obj.mnemonic == ud_mnemonic_code.UD_Icall )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1066 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1067 debug DbgIO.println("aborting propagateUncondJmp: condJmp or call");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1068 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1069 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1070 else if ( ud_obj.mnemonic == ud_mnemonic_code.UD_Ijmp )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1071 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1072 bool is_imm=false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1073 uint jmp_dest = DisAsm.calcJumpDestination(process, process.threads[thread_id], ud_obj, is_imm);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1074 debug DbgIO.println("propagating bp to 0x%x", jmp_dest);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1075 Location loc = images.findLocation(jmp_dest);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1076 if ( loc.file !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1077 bp = setBreakpoint(jmp_dest, bpi, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1078 else {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1079 debug DbgIO.println("not source info available - checking for unconditional jmp at destination");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1080 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1081 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1082 bp.frame_ptr = prev_bp.frame_ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1083
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1084 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1085 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1086 else if ( ud_obj.mnemonic == ud_mnemonic_code.UD_Iret || ud_obj.mnemonic == ud_mnemonic_code.UD_Iretf ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1087 debug DbgIO.println("aborting propagateUncondJmp: ret");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1088 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1089 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1090 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1091 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1092 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1093
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1094 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1095 If the opcode is an immediate jump or a call, sets a temporary breakpoint
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1096 at it's destination. If it's a memory call, sets a call-propagating breakpoint at
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1097 the call instruction.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1098 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1099 bool setBranchBreakpoints(ud_t* ud_obj, StepMode mode)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1100 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1101 // first call
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1102 if ( ud_obj is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1103 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1104
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1105 int bpi=-1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1106 Breakpoint bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1107
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1108 if ( DisAsm.isConditionalJump(ud_obj.mnemonic) || ud_obj.mnemonic == ud_mnemonic_code.UD_Ijmp )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1109 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1110 if ( mode!=StepMode.e_out )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1111 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1112 bool is_imm=true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1113 uint jmp_dest = DisAsm.calcJumpDestination(process, process.threads[thread_id], ud_obj, is_imm);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1114 if ( is_imm )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1115 bp = setBreakpoint(jmp_dest, bpi, thread_id, false);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1116 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1117 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1118 // set propagating breakpoint
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1119 bp = setBreakpoint(cast(size_t)ud_obj.insn_offset, bpi, thread_id, true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1120 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1121 bp.propagate = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1122 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1123 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1124 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1125 else if ( ud_obj.mnemonic == ud_mnemonic_code.UD_Icall )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1126 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1127 if ( mode==StepMode.e_in )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1128 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1129 bool is_imm=true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1130 uint jmp_dest = DisAsm.calcJumpDestination(process, process.threads[thread_id], ud_obj, is_imm);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1131 if ( is_imm )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1132 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1133 Location loc = images.findLocation(jmp_dest);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1134 if ( loc.file !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1135 bp = setBreakpoint(jmp_dest, bpi, thread_id, false);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1136 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1137 debug DbgIO.println("not setting BP on unknown call destination 0x%x", jmp_dest);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1138 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1139 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1140 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1141 // set propagating breakpoint
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1142 bp = setBreakpoint(cast(size_t)ud_obj.insn_offset, bpi, thread_id, true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1143 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1144 bp.propagate = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1145 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1146 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1147 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1148 else if ( ud_obj.mnemonic == ud_mnemonic_code.UD_Iret || ud_obj.mnemonic == ud_mnemonic_code.UD_Iretf )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1149 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1150 if ( mode!=StepMode.e_out )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1151 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1152 Location loc = images.findLocation(current_address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1153 if ( loc.scope_sym !is null && find(loc.scope_sym.mangled_name, "__foreachbody") >= 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1154 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1155 ProcedureSymbol ps = cast(ProcedureSymbol)loc.scope_sym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1156 if ( ps !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1157 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1158 setBreakpoint(ps.cvdata.offset+loc.getCodeBase, bpi, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1159 uint ret_adr = getReturnAddress(images.findLocation(getReturnAddress(loc)));
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1160 if ( ret_adr > 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1161 setBreakpoint(ret_adr, bpi, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1162 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1163 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1164 if ( mode != StepMode.e_over || loc.scope_sym is null || find(loc.scope_sym.mangled_name, "__foreachbody") < 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1165 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1166 uint ret_adr = getReturnAddress(loc);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1167 if ( ret_adr > 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1168 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1169 debug DbgIO.println("setBranchBPs: using return address from frame");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1170 loc = images.findLocation(ret_adr);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1171 if ( loc.file !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1172 bp = setBreakpoint(ret_adr, bpi, thread_id, true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1173 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1174 debug DbgIO.println("not setting BP on unknown ret address 0x%x", ret_adr);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1175 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1176 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1177 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1178 bp = setBreakpoint(cast(size_t)ud_obj.insn_offset, bpi, thread_id, true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1179 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1180 bp.propagate = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1181 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1182 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1183 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1184 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1185 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1186 bp = setBreakpoint(cast(size_t)ud_obj.insn_offset, bpi, thread_id, true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1187 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1188 bp.propagate = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1189 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1190 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1191 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1192 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1193
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1194 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1195 Removes breakpoint from list and deactivates it.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1196 Returns: success
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1197 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1198 bool removeBreakpoint(uint bp_index)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1199 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1200 if ( bp_index in breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1201 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1202 Breakpoint bp = breakpoints[bp_index];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1203 if ( process !is null && !bp.deactivate(process) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1204 throw new DebuggerException("ERROR: Failed to write breakpoint opcode at %s:%d", bp.file, bp.line);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1205 breakpoints.remove(bp_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1206 if ( passing_breakpoint is bp ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1207 passing_breakpoint = null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1208 activateSingleStep(false);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1209 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1210 delete bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1211 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1212 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1213 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1214 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1215
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1216 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1217
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1218 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1219 void clearTemporaryBreakpoints()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1220 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1221 debug DbgIO.println("clearing temporary breakpoints");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1222 if ( process !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1223 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1224 foreach ( bp; temp_breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1225 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1226 if ( bp.value.foreach_end !is null && bp.value.foreach_end.address != current_address )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1227 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1228 if ( !bp.value.hardware )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1229 passing_breakpoint = bp.value;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1230 activateSingleStep(true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1231 continue;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1232 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1233 if ( !bp.value.deactivate(process) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1234 throw new DebuggerException("ERROR: Failed to restore opcode for breakpoint at %s:%d", bp.value.file, bp.value.line);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1235 temp_breakpoints.remove(bp);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1236 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1237 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1238 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1239
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1240 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1241 Creates a breakpoint at the given location and adds it with the given index.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1242 Overwrites the breakpoint at the same index if existant.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1243 Adds a temporary breakpoint instead if index < 0.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1244 Reaturns: Existing breakpoint at the location or new breakpoint.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1245 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1246 Breakpoint setBreakpoint(Location loc, inout int new_index, uint threadId, bool hardware=false)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1247 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1248 if ( loc is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1249 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1250
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1251 // lookup existing breakpoint
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1252 Breakpoint bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1253 if ( new_index >= 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1254 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1255 int bp_index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1256 bp = getBreakpoint(loc, bp_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1257 if( bp !is null ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1258 new_index = bp_index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1259 return bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1260 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1261 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1262
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1263 // create a breakpoint
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1264 bp = new Breakpoint(loc, new_index<0, threadId, hardware);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1265 addBreakpoint(bp, new_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1266 return bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1267 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1268
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1269 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1270 Creates a breakpoint at the given address and adds it with the given index.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1271 Overwrites the breakpoint at the same index if existant.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1272 Adds a temporary breakpoint instead if index < 0.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1273 Reaturns: Existing breakpoint at the address or new breakpoint.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1274 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1275 Breakpoint setBreakpoint(size_t address, inout int new_index, uint threadId, bool set_on_current_line=false, bool hardware=false)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1276 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1277 Location loc = images.findLocation(address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1278
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1279 Breakpoint bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1280 int bp_index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1281 bp = getBreakpoint(address, bp_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1282 if( bp !is null ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1283 debug DbgIO.println("instead 0x%08x using existing breakpoint at 0x%08x", address, bp.address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1284 new_index = bp_index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1285 return bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1286 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1287
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1288 if ( !set_on_current_line && loc.codeblock !is null && current_address == loc.codeblock.start+loc.getCodeBase ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1289 debug DbgIO.println("not setting bp at current 0x%08x", address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1290 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1291 }
4
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
1292 debug DbgIO.println("setting breakpoint 0x%08x", address);
1
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1293 bp = new Breakpoint(loc, new_index<0, threadId, hardware);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1294 addBreakpoint(bp, new_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1295 return bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1296 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1297
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1298 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1299 Adds the given breakpoint with at the given index.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1300 Adds it as temporary breakpoint if new_index < 0.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1301 Activates the breakpoint.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1302 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1303 void addBreakpoint(Breakpoint bp, int new_index)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1304 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1305 // add to breakpoint list
4
a5fb1bc967e6 - = command does not need space after it
marton@basel.hu
parents: 3
diff changeset
1306 debug DbgIO.println("adding breakpoint 0x%08x", bp.address);
1
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1307 if ( bp.temporary )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1308 temp_breakpoints ~= bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1309 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1310 breakpoints[new_index] = bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1311
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1312 // set breakpoing as active in debugger
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1313 if ( process !is null && !bp.activate(process) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1314 throw new DebuggerException("ERROR: Failed to write breakpoint opcode at %s:%d", bp.file, bp.line);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1315 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1316
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1317 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1318 Searches the breakpoints for one that is set at the given source
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1319 location.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1320 Returns: Index of the breakpoint in the breakpoints array.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1321 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1322 Breakpoint getBreakpoint(Location loc, out int bp_index)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1323 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1324 foreach( uint i, Breakpoint bp; breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1325 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1326 if( !bp.hardware && bp.file == loc.file && bp.line == loc.line
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1327 || bp.hardware && bp.address == loc.address )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1328 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1329 bp_index = i;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1330 return bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1331 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1332 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1333 foreach( bp; temp_breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1334 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1335 if( !bp.value.hardware && bp.value.file == loc.file && bp.value.line == loc.line
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1336 || bp.value.hardware && bp.value.address == loc.address )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1337 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1338 bp_index = -1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1339 return bp.value;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1340 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1341 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1342 return getBreakpoint(loc.address, bp_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1343 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1344
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1345 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1346 Searches for a breakpoint at the given address.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1347 Returns: Index of breakpoint in breakpoints array.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1348 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1349 Breakpoint getBreakpoint(uint address, out int bp_index)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1350 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1351 foreach ( uint i, Breakpoint bp; breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1352 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1353 if ( bp.address == address ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1354 bp_index = i;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1355 return bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1356 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1357 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1358 foreach ( bp; temp_breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1359 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1360 if ( bp.value.address == address ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1361 bp_index = -1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1362 return bp.value;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1363 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1364 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1365 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1366 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1367
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1368 //=============================================================================================
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1369 // Minidumps
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1370
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1371 void writeMiniDump(string filename)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1372 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1373 char[] class_name, msg;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1374 if ( exceptionRecord !is null
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1375 && exceptionRecord.ExceptionCode != EXCEPTION_BREAKPOINT
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1376 && exceptionRecord.ExceptionCode != EXCEPTION_SINGLE_STEP
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1377 && exceptionRecord.ExceptionCode != DBG_CONTROL_C )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1378 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1379 getExceptionNameMessage(exceptionRecord.ExceptionInformation[0], class_name, msg);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1380 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1381 MiniDump.writeMiniDump(filename, process, thread_id, exceptionRecord, class_name, msg);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1382 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1383
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1384 void readMiniDump(string filename)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1385 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1386 try {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1387 miniDump = new MiniDump(filename);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1388 selectThread(miniDump.threads[miniDump.selectedThread].ThreadId);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1389 if ( miniDump.exceptionRecord !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1390 handleExceptionEvent(miniDump.exceptionRecord);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1391 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1392 thread_id = miniDump.threadInfo.currentThreadId;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1393 //miniDump.threadInfo.mainThreadId
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1394 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1395 catch ( Exception e )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1396 DbgIO.writeln("Error: "~e.msg);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1397 //return miniDump !is null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1398 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1399 }