annotate src/debugger.d @ 3:47dd986a534e

version no fix
author marton@basel.hu
date Tue, 05 Apr 2011 20:56:40 +0200
parents 4a9dcbd9e54f
children a5fb1bc967e6
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,
47dd986a534e version no fix
marton@basel.hu
parents: 1
diff changeset
37 VERSION_PATCH = 1;
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,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
72 single_step;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
73
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
74 size_t current_address;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
75 uint last_line;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
76
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
77 string[][string] source_files;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
78 string[] source_search_paths;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
79
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
80 string main_image_file;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
81 COFFImage main_image;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
82 ImageSet images;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
83
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
84 Breakpoint[uint] breakpoints;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
85 List!(Breakpoint) temp_breakpoints;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
86 Breakpoint passing_breakpoint;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
87 DbgProcess process;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
88 MiniDump miniDump;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
89
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
90 CallStack current_stack;
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 EXCEPTION_RECORD* exceptionRecord;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
93 DEBUG_EVENT debug_event;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
94 uint process_id,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
95 thread_id;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
96
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
97 UserInterface ui;
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 uint evaluationDepth = 1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
100 bool create_new_console;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
101
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
102 //=============================================================================================
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
103 // construction
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 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
106 Uses the debugger's CLI arguments for the debuggee.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
107 Example: debugger debuggee arg0 arg1 ...
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
108 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
109 this(string debuggee, UserInterface _ui)
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 assert(_ui !is null);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
112 images = new ImageSet;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
113 ui = _ui;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
114 openImage(debuggee);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
115 source_search_paths ~= ".\\";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
116 temp_breakpoints = new List!(Breakpoint);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
117 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
118
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
119 CallStack stack()
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 if ( current_stack is null )
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 ( process !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
124 current_stack = process.loadStack(process.threads[thread_id]);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
125 else if ( miniDump !is null ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
126 CONTEXT* ctx = miniDump.getContext;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
127 // TODO: where does that 4-byte offset come from
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
128 ubyte[] data = miniDump.getMemory(miniDump.thread.Stack.Memory)[4..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
129 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
130 current_stack.data = data;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
131 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
132 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
133 return current_stack;
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
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 bool step(StepMode mode)
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 if ( !process_loaded )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
142 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
143 Location loc = images.findLocation(current_address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
144
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
145 int bpi=-1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
146 Breakpoint bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
147
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
148 switch ( mode )
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 //-------------------------------------------------------------------------------------
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
151 case StepMode.e_in:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
152 Location next_loc = images.findNextSrcLine(loc);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
153 if ( next_loc !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
154 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
155 bp = setBreakpoint(next_loc, bpi, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
156 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
157 addForeachBreakpoint(bp);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
158 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
159
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
160 size_t disasm_end;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
161 if ( loc.codeblock !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
162 disasm_end = loc.codeblock.end+loc.getCodeBase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
163 DisAsm.disasm(
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
164 process, current_address, disasm_end,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
165 (ud_t* ud_obj) { return setBranchBreakpoints(ud_obj,StepMode.e_in); }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
166 );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
167 break;
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 case StepMode.e_out:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
170 uint ret_adr = getReturnAddress(loc);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
171 if ( ret_adr > 0 ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
172 debug DbgIO.println("setting step-out to 0x%08x", ret_adr);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
173 bp = setBreakpoint(ret_adr, bpi, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
174 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
175 bp.frame_ptr = getFramePointer(loc, 1);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
176 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
177 else
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 debug DbgIO.println("no scope found - falling back on disasm-step-out");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
180 DisAsm.disasm(
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
181 process, current_address, 0,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
182 (ud_t* ud_obj) { return setBranchBreakpoints(ud_obj,StepMode.e_out); }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
183 );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
184 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
185 break;
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 case StepMode.e_over:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
188 Location next_loc = images.findNextSrcLine(loc);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
189 if ( next_loc !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
190 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
191 bp = setBreakpoint(next_loc, bpi, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
192 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
193 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
194 bp.frame_ptr = getFramePointer(loc);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
195 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
196 addForeachBreakpoint(bp);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
197 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
198 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
199
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
200 size_t disasm_end;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
201 if ( loc.codeblock !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
202 disasm_end = loc.codeblock.end+loc.getCodeBase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
203 DisAsm.disasm(
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
204 process, current_address, disasm_end,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
205 (ud_t* ud_obj) { return setBranchBreakpoints(ud_obj,StepMode.e_over); }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
206 );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
207 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
208 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
209 assert(0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
210 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
211
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
212 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
213 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
214
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
215 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
216
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 void addForeachBreakpoint(Breakpoint foreach_end)
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 CodeView cv;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
221 CodeBlock cb = images.findCodeBlockAbs(current_address, cv);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
222 if ( cb !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
223 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
224 CodeBlock cbs[] = cb.segment.file.blocks_by_line[cb.line];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
225 if ( cbs.length > 1 && cb is cbs[0] )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
226 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
227 Location loc = images.findLocation(cbs[1].start+cv.getCodeBase);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
228 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
229 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
230 int bpi;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
231 if ( getBreakpoint(loc.address, bpi) is null ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
232 Breakpoint bp = new Breakpoint(loc, true, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
233 bp.foreach_end = foreach_end;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
234 foreach_end.foreach_end = foreach_end;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
235 addBreakpoint(bp, -1);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
236 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
237 }
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 uint getReturnAddress(Location loc)
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 ProcedureSymbol psym = cast(ProcedureSymbol)loc.scope_sym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
248 if ( psym !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
249 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
250 uint index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
251 ubyte[] frame = stack.firstFrame(index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
252
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
253 if ( frame is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
254 throw new DebuggerException("getReturnAddress: null frame");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
255
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
256 uint adr = current_address-psym.cvdata.offset-loc.getCodeBase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
257 if ( adr >= psym.cvdata.debug_start && adr < psym.cvdata.debug_end ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
258 frame = stack.prevFrame(index, index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
259 if ( frame.length >= 8 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
260 return (cast(uint[])frame)[1];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
261 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
262 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
263 return 0;
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
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 uint getFramePointer(Location loc, uint level=0)
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 ProcedureSymbol psym = cast(ProcedureSymbol)loc.scope_sym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
272 if ( psym !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
273 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
274 uint frame_ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
275 if ( level > 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
276 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
277 uint index,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
278 l;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
279 ubyte[] frame = stack.firstFrame(index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
280 if ( frame is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
281 throw new DebuggerException("getCurrenFramePointer: null frame");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
282
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
283 for ( l = 0; l < level && frame !is null; ++l )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
284 frame = stack.prevFrame(index, index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
285 if ( frame is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
286 throw new DebuggerException("getCurrenFramePointer: null frame at level %d", l);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
287
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
288 frame_ptr = (cast(uint[])frame)[0];
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 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
291 frame_ptr = stack.frame_ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
292
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
293 uint adr = current_address-psym.cvdata.offset-loc.getCodeBase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
294 if ( adr >= psym.cvdata.debug_start && adr < psym.cvdata.debug_end )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
295 return frame_ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
296 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
297 return 0;
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
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 SymbolData evaluateExpression(string expr, uint frame_level=0, NamedSymbol symbol=null)
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 SyntaxTree* root;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
306 bool success;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
307 try success = parse("", expr, root, true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
308 catch( ParserException e )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
309 throw new EvaluationException("Parser: "~e.toString);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
310 if ( !success )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
311 throw new EvaluationException("Parser: Invalid expression!");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
312
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
313 string elmtype;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
314 uint scope_address;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
315 if ( frame_level == 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
316 scope_address = current_address;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
317 else {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
318 ubyte[] frame = stack.getFrame(frame_level);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
319 scope_address = (cast(uint[])frame)[1];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
320 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
321
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
322 SymbolData sd;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
323 auto loc = images.findLocation(current_address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
324 if ( loc.codeview is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
325 throw new EvaluationException("No debug symbols available");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
326 root.Expr(new EvaluationContext(
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
327 loc.codeview, scope_address,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
328 miniDump, process, process is null?null:process.threads[thread_id],
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
329 stack, frame_level), sd
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
330 );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
331 return 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
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 SymbolValue handleData(SymbolData sd, bool decreaseED)
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 auto loc = images.findLocation(current_address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
340 if ( loc.codeview is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
341 throw new EvaluationException("No debug symbols available");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
342 EvaluationContext ctx = new EvaluationContext(
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
343 loc.codeview, 0,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
344 miniDump, process, process is null?null:process.threads[thread_id],
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
345 stack, 0
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
346 );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
347
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
348 ubyte[] data = sd.getData(ctx);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
349 if ( data.length <= 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
350 throw new EvaluationException("Expression evaluated to empty data");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
351
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
352 uint ed = evaluationDepth;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
353 if ( decreaseED )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
354 --ed;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
355 SymbolValue val = DataHandler.handle(ctx, sd.type, data, ed);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
356 if ( val is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
357 throw new EvaluationException("No DataHandler for type "~sd.type);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
358 return val;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
359 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
360
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 uint getScopeAddress(uint frame_level)
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 scope_address;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
368 if ( frame_level == 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
369 scope_address = current_address;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
370 else {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
371 ubyte[] frame = stack.getFrame(frame_level);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
372 if ( frame !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
373 scope_address = (cast(uint[])frame)[1];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
374 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
375 return scope_address;
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
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 // process & thread handling
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 /**********************************************************************************************
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 void selectThread(size_t threadId)
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 thread_id = threadId;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
388 current_stack = null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
389
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
390 if ( process !is null ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
391 CONTEXT ctx;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
392 if ( !process.threads[threadId].getContext(ctx) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
393 throw new DebuggerException("Couldn't get thread's context");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
394 current_address = ctx.Eip;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
395 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
396 else if ( miniDump !is null ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
397 miniDump.selectThread(threadId);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
398 CONTEXT* ctx = miniDump.getContext;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
399 current_address = ctx.Eip;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
400 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
401 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
402 throw new DebuggerException("Invalid debugger state");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
403 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
404
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
405 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
406 Loads and parses the PE image.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
407 Returns: success
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
408 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
409 void openImage(string filename)
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 assert(filename.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
412 filename = strip(filename);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
413 if ( !exists(filename) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
414 filename ~= ".exe";
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 throw new DebuggerException("Couldn't open \"%s\"", filename[0..$-4]);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
417 main_image_file = filename.dup;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
418
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
419 main_image = new COFFImage;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
420 main_image.load(main_image_file);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
421 // catch ( Exception e ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
422 // 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
423 // }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
424 if ( main_image.codeView is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
425 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
426 images ~= main_image;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
427 // return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
428 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
429
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
430 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
431 Creates the child process for the debuggee.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
432 Returns: success
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
433 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
434 bool createDebugProcess(string command_line)
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 // initialiZe process startup information
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
437 STARTUPINFOA* startInfo = new STARTUPINFOA;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
438 startInfo.cb = STARTUPINFO.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
439 startInfo.dwFlags = STARTF_FORCEONFEEDBACK | STARTF_USESHOWWINDOW;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
440 startInfo.wShowWindow = SW_SHOWNORMAL;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
441
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
442 PROCESS_INFORMATION procInfo; // process info
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 // create process
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
445 uint flags = DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
446 if ( create_new_console )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
447 flags |= CREATE_NEW_CONSOLE;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
448
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
449 bool suc = cast(bool)CreateProcessA(
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
450 toStringz(main_image_file), toStringz(command_line), cast(LPSECURITY_ATTRIBUTES)null,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
451 cast(LPSECURITY_ATTRIBUTES)null, false, flags, null, cast(char*)null,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
452 cast(LPSTARTUPINFOA)startInfo, cast(LPPROCESS_INFORMATION)&procInfo
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
453 );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
454 if( !suc )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
455 throw new DebuggerException("CreateProcess failed on %s", main_image_file);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
456 assert(procInfo.dwProcessId);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
457
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
458 // open process for all access
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
459 HANDLE hChildProcess = OpenProcess(PROCESS_ALL_ACCESS, false, procInfo.dwProcessId);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
460 if( hChildProcess == null ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
461 TerminateProcess(procInfo.hProcess, 0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
462 throw new DebuggerException("OpenProcess failed");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
463 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
464 process_id = procInfo.dwProcessId;
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 CloseHandle(procInfo.hProcess);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
467 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
468 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
469
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
470 /**********************************************************************************************
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 void resume()
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 single_step = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
476 paused = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
477 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
478
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 // exception handling
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 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
483 Debugger's main loop. Handles win32 debugging events.
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 void start(string command_line)
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 createDebugProcess(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 while( !abort )
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 if( WaitForDebugEvent(&debug_event, win32.winbase.INFINITE) )
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( debug_event.dwProcessId != process_id ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
494 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
495 ContinueDebugEvent(debug_event.dwProcessId, debug_event.dwThreadId, DBG_CONTINUE);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
496 continue;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
497 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
498
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
499 current_stack = null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
500 thread_id = debug_event.dwThreadId;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
501 exceptionRecord = null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
502
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
503 bool exception_handled = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
504 switch( debug_event.dwDebugEventCode )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
505 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
506 case OUTPUT_DEBUG_STRING_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
507 char[] debug_string;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
508 paused = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
509
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
510 debug_string.length = debug_event.DebugString.nDebugStringLength;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
511 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
512 if ( debug_event.DebugString.fUnicode )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
513 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
514
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
515 if ( debug_string.length > 3 && debug_string[0..4] == "DDL:" )
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 string cmdStr = debug_string[4..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
518 if ( strip(cmdStr).length > 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
519 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
520 auto r = std.regexp.RegExp("(([^\" \\t]+)|(\"[^\"]+\"))+");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
521 string[] cmd;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
522 foreach ( m; r.search(strip(cmdStr)) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
523 cmd ~= r.match(0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
524 switch ( cmd[0] )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
525 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
526 case "load":
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
527 DbgIO.println("loadImage not implemented, yet: %s %s", cmd[1], cmd[2]);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
528 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
529 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
530 DbgIO.println("WARNING: Unknown DDL command recieved: %s", cmdStr);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
531 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
532 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
533 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
534 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
535 else if ( debug_string.length > 5 && debug_string[0..5] == "Ddbg:" )
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 ui.runCommands(debug_string[5..$]);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
538 paused = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
539 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
540 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
541 ui.debugString(debug_string);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
542 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
543
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
544 case EXCEPTION_DEBUG_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
545 exceptionRecord = &debug_event.Exception.ExceptionRecord;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
546 exception_handled = handleExceptionEvent(exceptionRecord);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
547 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
548
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
549 case LOAD_DLL_DEBUG_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
550 DLL dll = process.loadDLL(&debug_event.LoadDll);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
551 if ( dll.image !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
552 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
553 images ~= dll.image;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
554 foreach ( bp; breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
555 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
556 if ( bp.location.address == 0 )
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 debug DbgIO.println("binding bp %s", bp.toString);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
559 if ( bp.location.bind(images, source_search_paths) ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
560 debug DbgIO.println("activating bp %s", bp.toString);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
561 bp.activate(process);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
562 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
563 }
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 ui.loadedDLL(dll);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
567 paused = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
568 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
569
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
570 case UNLOAD_DLL_DEBUG_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
571 // DebugDLL* dll = process.findDLL(cast(uint)debug_event.LoadDll.lpBaseOfDll);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
572 // ui.unloadedDLL(dll);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
573 // images.remove(dll.image);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
574 paused = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
575 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
576
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
577 case CREATE_THREAD_DEBUG_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
578 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
579 paused = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
580 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
581
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
582 case EXIT_THREAD_DEBUG_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
583 process.threads.remove(debug_event.dwThreadId);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
584 paused = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
585 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
586
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
587 case CREATE_PROCESS_DEBUG_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
588 process = new DbgProcess;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
589 process.processId = process_id;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
590 process.process_handle = debug_event.CreateProcessInfo.hProcess;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
591 process.mainThreadId = debug_event.dwThreadId;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
592 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
593 process_loaded = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
594
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
595 if ( main_image !is null && main_image.codeView !is null )
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 DataSymbol mainds;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
598 if ( main_image.codeView.global_pub !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
599 mainds = main_image.codeView.global_pub.findDataSymbol("_main");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
600 if ( mainds !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
601 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
602 int bpi=-1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
603 Breakpoint bp = setBreakpoint(mainds.offset+main_image.getCodeBase, bpi, 0, true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
604 bp.deactivate_d_exception_handler = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
605 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
606 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
607
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
608 foreach ( bp; breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
609 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
610 if ( bp.location.address != 0 && !bp.activate(process) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
611 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
612 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
613 foreach ( bp; temp_breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
614 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
615 debug DbgIO.println("tbp activated %s", bp.value);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
616 if ( bp.value.location.address != 0 && !bp.value.activate(process) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
617 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
618 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
619 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
620
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
621 case EXIT_PROCESS_DEBUG_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
622 process_loaded = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
623 delete process;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
624 paused = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
625 single_step = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
626 ui.exitProcess;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
627 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
628
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
629 case RIP_EVENT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
630 debug DbgIO.println("DebugEvent: "~getEventName(debug_event.dwDebugEventCode));
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
631 paused = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
632 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
633
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
634 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
635 throw new DebuggerException("Win32Debugger ERROR - unknown debug event: %d", debug_event.dwDebugEventCode);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
636 }
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 if ( single_step )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
639 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
640 ui.singleStep();
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 activateSingleStep(true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
643 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
644
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
645 if ( paused )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
646 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
647 bool cont=false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
648 while ( !cont )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
649 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
650 debug
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
651 cont = ui.readCommand();
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
652 else
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 try cont = ui.readCommand();
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
655 catch ( Exception e )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
656 DbgIO.println("%s", e.msg);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
657 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
658 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
659 paused = false;
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 ( !abort )
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 exceptionRecord = null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
665 ContinueDebugEvent(
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
666 debug_event.dwProcessId, debug_event.dwThreadId,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
667 exception_handled?DBG_CONTINUE:DBG_EXCEPTION_NOT_HANDLED
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
668 );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
669 }
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 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
672 throw new DebuggerException("ERROR: WaitForDebugEvent failed: %s", lastError);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
673 }
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 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
677 Activates single step execution by setting the trap flag in
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
678 the eflags register of the currently considered thread.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
679 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
680 void activateSingleStep(bool enable)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
681 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
682 if ( !(thread_id in process.threads) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
683 return;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
684 if ( enable )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
685 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
686 else if ( !enable )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
687 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
688 single_step = enable;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
689 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
690
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 void getExceptionNameMessage(size_t objPtr, out char[] class_name, out char[] msg)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
695 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
696 // get thrown object's class name
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
697 ClassInfo ci = process.getClassInfo(objPtr);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
698 class_name.length = ci.name.length;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
699 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
700
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
701 // get object's data
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
702 uint[] objdata;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
703 objdata.length = ci.init.length;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
704 process.readProcessMemory(objPtr, objdata.ptr, objdata.length*uint.sizeof);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
705
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
706 char[] name;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
707 name ~= class_name;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
708 do
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 if ( name == "object.Exception" )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
711 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
712 msg.length = objdata[2];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
713 process.readProcessMemory(objdata[3], msg.ptr, msg.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
714 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
715 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
716
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
717 ubyte[] data;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
718 data.length = ClassInfo.classinfo.init.length;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
719 process.readProcessMemory(cast(uint)cast(void*)ci.base, data.ptr, data.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
720 ci = cast(ClassInfo)data.ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
721 name.length = ci.name.length;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
722 process.readProcessMemory(cast(uint)ci.name.ptr, name.ptr, name.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
723 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
724 while ( ci.base !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
725 }
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 /**********************************************************************************************
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 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
730 bool handleExceptionEvent(EXCEPTION_RECORD* exrec)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
731 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
732 current_address = cast(uint)exrec.ExceptionAddress;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
733 Lswitch: switch ( exrec.ExceptionCode )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
734 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
735 case EXCEPTION_BREAKPOINT:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
736 debug DbgIO.println("EXCEPTION_BREAKPOINT");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
737 int bp_index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
738 Breakpoint bp = getBreakpoint(current_address, bp_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
739 if ( bp !is null ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
740 handleBreakpoint(bp, bp_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
741 last_line = bp.line;
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 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
744 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
745 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
746 case EXCEPTION_SINGLE_STEP:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
747 debug DbgIO.println("EXCEPTION_SINGLE_STEP");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
748 // check whether this is a HWBP or real single step
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
749 CONTEXT ctx;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
750 process.threads[thread_id].getContext(ctx, CONTEXT_DEBUG_REGISTERS);
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 if ( (ctx.Dr6 & 0xf) > 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
753 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
754 debug DbgIO.println("Hardware breakpoint");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
755 size_t dr = void;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
756 if ( ctx.Dr6 & 1 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
757 dr = ctx.Dr0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
758 else if ( ctx.Dr6 & 2 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
759 dr = ctx.Dr1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
760 else if ( ctx.Dr6 & 4 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
761 dr = ctx.Dr2;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
762 else if ( ctx.Dr6 & 8 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
763 dr = ctx.Dr3;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
764 int bp_index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
765 foreach( i, bp; breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
766 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
767 if( !bp.hardware )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
768 continue;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
769 if ( dr == bp.address ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
770 handleBreakpoint(bp, i);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
771 break Lswitch;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
772 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
773 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
774
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
775 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
776 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
777 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
778 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
779 debug DbgIO.println("Single Step exception");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
780 // pause if interactive single step is active
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
781 paused = single_step;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
782
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
783 if ( passing_breakpoint !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
784 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
785 debug DbgIO.println("passing breakpoint");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
786 activateSingleStep(false);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
787 paused = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
788 if ( process !is null && !passing_breakpoint.activate(process) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
789 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
790 passing_breakpoint = null;
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 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
793 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
794 // ctrl+c
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
795 case DBG_CONTROL_C:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
796 ui.userInterrupt();
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
797 paused = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
798 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
799 // D exceptions
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
800 case STATUS_DIGITAL_MARS_D_EXCEPTION:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
801 // normal non-post-mortem mode
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
802 if ( process !is null && !debug_event.Exception.dwFirstChance )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
803 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
804 char[] class_name, msg;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
805 getExceptionNameMessage(exrec.ExceptionInformation[0], class_name, msg);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
806 ui.exception(thread_id, class_name, msg, exrec.ExceptionInformation[0]);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
807 paused = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
808 return false;
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 // minidump mode
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
811 else if ( miniDump !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
812 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
813 string className,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
814 message;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
815 className = (cast(char*)exrec.ExceptionInformation[1])[0..exrec.ExceptionInformation[0]];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
816 message = (cast(char*)exrec.ExceptionInformation[3])[0..exrec.ExceptionInformation[2]];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
817 ui.exception(thread_id, className, message, 0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
818 paused = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
819 return false;
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 paused = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
822 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
823 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
824 ui.win32exception(thread_id, exrec);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
825 paused = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
826 single_step = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
827 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
828 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
829 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
830 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
831
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
832 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
833
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
834 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
835 void handleBreakpoint(Breakpoint bp, uint bp_index)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
836 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
837 CONTEXT ctx;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
838 if ( !process.threads[thread_id].getContext(ctx) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
839 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
840
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
841 if ( !bp.hardware )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
842 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
843 if ( process !is null && !bp.deactivate(process) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
844 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
845
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
846 // adjust for "int 3" instruction byte
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
847 --ctx.Eip;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
848 if ( !process.threads[thread_id].setContext(ctx) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
849 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
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 // check if we have a constrained thread
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
853 if ( bp.threadId > 0 && thread_id != bp.threadId )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
854 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
855 debug DbgIO.println("skipping bp in incorrect thread %d", thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
856 if ( !bp.hardware ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
857 passing_breakpoint = bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
858 activateSingleStep(true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
859 }
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 // check if breakpoint requires a certain frame
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
862 else if ( bp.frame_ptr > 0 && bp.frame_ptr != ctx.Ebp )
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 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
865 if ( !bp.hardware ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
866 passing_breakpoint = bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
867 activateSingleStep(true);
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 // restore non-temporary breakpoints
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
871 else if ( !bp.temporary )
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 ui.breakpoint(bp_index, bp, process.threads[thread_id]);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
874 paused = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
875 if ( !bp.hardware ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
876 passing_breakpoint = bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
877 activateSingleStep(true);
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 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
880 // propagate breakpoints to jmp/call/ret destination
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
881 else if ( bp.propagate )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
882 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
883 debug DbgIO.println("propagate");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
884 foreach ( tbp; temp_breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
885 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
886 if ( tbp.value is bp ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
887 temp_breakpoints.remove(tbp);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
888 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
889 }
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 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
892 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
893 // temporary breakpoints
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
894 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
895 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
896 if ( bp.deactivate_d_exception_handler ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
897 debug DbgIO.println("deactivateDExceptionHandler");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
898 deactivateDExceptionHandler();
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
899 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
900 else {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
901 clearTemporaryBreakpoints();
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
902 paused = ui.breakpoint(-1, bp, process.threads[thread_id]);
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 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
905 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
906
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 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
910 void deactivateDExceptionHandler()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
911 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
912 if ( main_image is null || main_image.codeView is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
913 return;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
914
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
915 // deactivate default D exception handling
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
916 bool found=false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
917 foreach ( ds; main_image.codeView.global_pub.data_symbols )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
918 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
919 if ( ds.name_notype == "_no_catch_exceptions" ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
920 uint address = ds.offset+main_image.getSectionBase(ds.cvdata.segment);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
921 bool nce = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
922 process.writeProcessMemory(address, &nce, bool.sizeof);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
923 found = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
924 break;
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 else if ( ds.name_notype == "_cr_trapExceptions"
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
927 || ds.name_notype == "_rt_trapExceptions" )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
928 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
929 uint address = ds.offset+main_image.getSectionBase(ds.cvdata.segment);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
930 bool nce = false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
931 process.writeProcessMemory(address, &nce, bool.sizeof);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
932 found = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
933 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
934 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
935 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
936 if ( !found ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
937 debug DbgIO.println("Neither Phobos nor Tango exception handler switch not found");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
938 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
939 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
940
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
941 //=============================================================================================
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
942 // source&symbol handling
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 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
945 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
946 Tries to load the source file from all source_search_paths.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
947 Returns: Array of lines of the source file.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
948 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
949 string[] getSourceFile(string filename)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
950 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
951 if ( filename is null || filename.length <= 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
952 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
953 if ( !(filename in source_files) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
954 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
955 string full = getFullSourcePath(filename);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
956 if ( full is null || !exists(full) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
957 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
958 auto lines = splitlines(cast(string)read(full));
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
959 source_files[filename] = lines;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
960 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
961 return source_files[filename];
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
964 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
965 Tries to find the source file in all source_search_paths.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
966 Returns: Full path of the file
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
967 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
968 string getFullSourcePath(string filename)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
969 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
970 string full = getFullPath(filename);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
971 if ( exists(full) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
972 return full;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
973 foreach ( string sp; source_search_paths )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
974 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
975 full = getFullPath(sp~filename);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
976 if ( exists(full) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
977 return full;
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 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 //=============================================================================================
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
984 // breakpoint handling
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 /**********************************************************************************************
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 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
989 bool setPropagatedBreakpoint(ud* ud_obj, Breakpoint prev_bp)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
990 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
991 if ( ud_obj is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
992 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
993
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
994 int bpi=-1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
995 Breakpoint bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
996 if ( DisAsm.isConditionalJump(ud_obj.mnemonic)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
997 || ud_obj.mnemonic == ud_mnemonic_code.UD_Ijmp
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
998 || ud_obj.mnemonic == ud_mnemonic_code.UD_Icall )
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 bool is_imm=false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1001 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
1002 assert(!is_imm);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1003 debug DbgIO.println("propagating jmp/call bp to 0x%x", jmp_dest);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1004 Location loc = images.findLocation(jmp_dest);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1005 if ( loc.file !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1006 bp = setBreakpoint(jmp_dest, bpi, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1007 else {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1008 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
1009 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
1010 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1011 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1012 bp.frame_ptr = prev_bp.frame_ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1013 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1014 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
1015 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1016 uint index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1017 size_t ret_adr = (cast(uint[])stack.data)[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1018 Location loc = images.findLocation(ret_adr);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1019 if ( loc.file !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1020 bp = setBreakpoint(ret_adr, bpi, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1021 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1022 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
1023 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1024 bp.frame_ptr = prev_bp.frame_ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1025 }
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("unknown instruction for propagating breakpoint");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1028 assert(0);
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1031 return false;
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
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 Propagate breakpoint if unconditional jump is found.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1036 Used for virtual functions with redirectors.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1037 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1038 bool propagateUncondJmp(ud* ud_obj, Breakpoint prev_bp)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1039 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1040 if ( ud_obj is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1041 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1042
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1043 int bpi=-1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1044 Breakpoint bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1045 if ( DisAsm.isConditionalJump(ud_obj.mnemonic)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1046 || ud_obj.mnemonic == ud_mnemonic_code.UD_Icall )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1047 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1048 debug DbgIO.println("aborting propagateUncondJmp: condJmp or call");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1049 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1050 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1051 else if ( ud_obj.mnemonic == ud_mnemonic_code.UD_Ijmp )
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 bool is_imm=false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1054 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
1055 debug DbgIO.println("propagating bp to 0x%x", jmp_dest);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1056 Location loc = images.findLocation(jmp_dest);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1057 if ( loc.file !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1058 bp = setBreakpoint(jmp_dest, bpi, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1059 else {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1060 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
1061 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1062 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1063 bp.frame_ptr = prev_bp.frame_ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1064
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1065 return false;
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 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
1068 debug DbgIO.println("aborting propagateUncondJmp: ret");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1069 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1070 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1071 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1072 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1073 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1074
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1075 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1076 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
1077 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
1078 the call instruction.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1079 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1080 bool setBranchBreakpoints(ud_t* ud_obj, StepMode mode)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1081 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1082 // first call
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1083 if ( ud_obj is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1084 return true;
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 int bpi=-1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1087 Breakpoint bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1088
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1089 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
1090 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1091 if ( mode!=StepMode.e_out )
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 bool is_imm=true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1094 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
1095 if ( is_imm )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1096 bp = setBreakpoint(jmp_dest, bpi, thread_id, false);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1097 else
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 // set propagating breakpoint
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1100 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
1101 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1102 bp.propagate = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1103 }
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 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1106 else if ( ud_obj.mnemonic == ud_mnemonic_code.UD_Icall )
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 ( mode==StepMode.e_in )
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 bool is_imm=true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1111 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
1112 if ( is_imm )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1113 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1114 Location loc = images.findLocation(jmp_dest);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1115 if ( loc.file !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1116 bp = setBreakpoint(jmp_dest, bpi, thread_id, false);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1117 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1118 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
1119 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1120 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1121 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1122 // set propagating breakpoint
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1123 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
1124 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1125 bp.propagate = true;
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 }
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 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
1130 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1131 if ( mode!=StepMode.e_out )
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(current_address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1134 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
1135 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1136 ProcedureSymbol ps = cast(ProcedureSymbol)loc.scope_sym;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1137 if ( ps !is null )
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 setBreakpoint(ps.cvdata.offset+loc.getCodeBase, bpi, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1140 uint ret_adr = getReturnAddress(images.findLocation(getReturnAddress(loc)));
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1141 if ( ret_adr > 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1142 setBreakpoint(ret_adr, bpi, thread_id);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1143 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1144 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1145 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
1146 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1147 uint ret_adr = getReturnAddress(loc);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1148 if ( ret_adr > 0 )
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 debug DbgIO.println("setBranchBPs: using return address from frame");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1151 loc = images.findLocation(ret_adr);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1152 if ( loc.file !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1153 bp = setBreakpoint(ret_adr, bpi, thread_id, true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1154 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1155 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
1156 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1157 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1158 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1159 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
1160 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1161 bp.propagate = true;
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 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1165 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1166 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1167 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
1168 if ( bp !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1169 bp.propagate = true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1170 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1171 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1172 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1173 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1174
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 Removes breakpoint from list and deactivates it.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1177 Returns: success
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1178 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1179 bool removeBreakpoint(uint bp_index)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1180 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1181 if ( bp_index in breakpoints )
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 Breakpoint bp = breakpoints[bp_index];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1184 if ( process !is null && !bp.deactivate(process) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1185 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
1186 breakpoints.remove(bp_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1187 if ( passing_breakpoint is bp ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1188 passing_breakpoint = null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1189 activateSingleStep(false);
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 delete bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1192 return true;
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 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1195 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1196
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
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 void clearTemporaryBreakpoints()
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 debug DbgIO.println("clearing temporary breakpoints");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1203 if ( process !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1204 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1205 foreach ( bp; temp_breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1206 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1207 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
1208 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1209 if ( !bp.value.hardware )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1210 passing_breakpoint = bp.value;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1211 activateSingleStep(true);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1212 continue;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1213 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1214 if ( !bp.value.deactivate(process) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1215 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
1216 temp_breakpoints.remove(bp);
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 }
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 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1222 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
1223 Overwrites the breakpoint at the same index if existant.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1224 Adds a temporary breakpoint instead if index < 0.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1225 Reaturns: Existing breakpoint at the location or new breakpoint.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1226 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1227 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
1228 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1229 if ( loc is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1230 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1231
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1232 // lookup existing breakpoint
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1233 Breakpoint bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1234 if ( new_index >= 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1235 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1236 int bp_index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1237 bp = getBreakpoint(loc, bp_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1238 if( bp !is null ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1239 new_index = bp_index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1240 return bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1241 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1242 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1243
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1244 // create a breakpoint
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1245 bp = new Breakpoint(loc, new_index<0, threadId, hardware);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1246 addBreakpoint(bp, new_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1247 return bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1248 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1249
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 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
1252 Overwrites the breakpoint at the same index if existant.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1253 Adds a temporary breakpoint instead if index < 0.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1254 Reaturns: Existing breakpoint at the address or new breakpoint.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1255 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1256 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
1257 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1258 Location loc = images.findLocation(address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1259
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1260 Breakpoint bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1261 int bp_index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1262 bp = getBreakpoint(address, bp_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1263 if( bp !is null ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1264 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
1265 new_index = bp_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 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
1270 debug DbgIO.println("not setting bp at current 0x%08x", address);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1271 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1272 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1273 bp = new Breakpoint(loc, new_index<0, threadId, hardware);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1274 addBreakpoint(bp, new_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1275 return bp;
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
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 Adds the given breakpoint with at the given index.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1280 Adds it as temporary breakpoint if new_index < 0.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1281 Activates the breakpoint.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1282 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1283 void addBreakpoint(Breakpoint bp, int new_index)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1284 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1285 // add to breakpoint list
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1286 if ( bp.temporary )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1287 temp_breakpoints ~= bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1288 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1289 breakpoints[new_index] = bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1290
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1291 // set breakpoing as active in debugger
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1292 if ( process !is null && !bp.activate(process) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1293 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
1294 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1295
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 Searches the breakpoints for one that is set at the given source
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1298 location.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1299 Returns: Index of the breakpoint in the breakpoints array.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1300 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1301 Breakpoint getBreakpoint(Location loc, out int bp_index)
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 foreach( uint i, Breakpoint bp; breakpoints )
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 if( !bp.hardware && bp.file == loc.file && bp.line == loc.line
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1306 || bp.hardware && bp.address == loc.address )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1307 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1308 bp_index = i;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1309 return bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1310 }
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 foreach( bp; temp_breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1313 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1314 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
1315 || bp.value.hardware && bp.value.address == loc.address )
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 bp_index = -1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1318 return bp.value;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1319 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1320 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1321 return getBreakpoint(loc.address, bp_index);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1322 }
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 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1325 Searches for a breakpoint at the given address.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1326 Returns: Index of breakpoint in breakpoints array.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1327 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1328 Breakpoint getBreakpoint(uint address, out int bp_index)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1329 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1330 foreach ( uint i, Breakpoint bp; breakpoints )
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 if ( bp.address == address ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1333 bp_index = i;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1334 return bp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1335 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1336 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1337 foreach ( bp; temp_breakpoints )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1338 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1339 if ( bp.value.address == address ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1340 bp_index = -1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1341 return bp.value;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1342 }
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 return null;
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
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1347 //=============================================================================================
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1348 // Minidumps
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1349
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1350 void writeMiniDump(string filename)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1351 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1352 char[] class_name, msg;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1353 if ( exceptionRecord !is null
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1354 && exceptionRecord.ExceptionCode != EXCEPTION_BREAKPOINT
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1355 && exceptionRecord.ExceptionCode != EXCEPTION_SINGLE_STEP
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1356 && exceptionRecord.ExceptionCode != DBG_CONTROL_C )
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 getExceptionNameMessage(exceptionRecord.ExceptionInformation[0], class_name, msg);
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 MiniDump.writeMiniDump(filename, process, thread_id, exceptionRecord, class_name, msg);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1361 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1362
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1363 void readMiniDump(string filename)
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 try {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1366 miniDump = new MiniDump(filename);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1367 selectThread(miniDump.threads[miniDump.selectedThread].ThreadId);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1368 if ( miniDump.exceptionRecord !is null )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1369 handleExceptionEvent(miniDump.exceptionRecord);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1370 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1371 thread_id = miniDump.threadInfo.currentThreadId;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1372 //miniDump.threadInfo.mainThreadId
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1373 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1374 catch ( Exception e )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1375 DbgIO.writeln("Error: "~e.msg);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1376 //return miniDump !is null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1377 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1378 }