Mercurial > projects > ddbg_continued
comparison src/cli/ddbgcli.d @ 5:496dfd8f7342 default tip
added:
-repeat option for "in", "ov"
-run until a line option
-run until a function option
-break on a function start
-n is an alias for ov
author | marton@basel.hu |
---|---|
date | Sun, 17 Apr 2011 11:05:31 +0200 |
parents | a5fb1bc967e6 |
children |
comparison
equal
deleted
inserted
replaced
4:a5fb1bc967e6 | 5:496dfd8f7342 |
---|---|
55 | 55 |
56 uint lastEvaluationDepth = 1; | 56 uint lastEvaluationDepth = 1; |
57 | 57 |
58 bool auto_find_scope_frame, /// find frame of last active scope if current frame has no source/symbols | 58 bool auto_find_scope_frame, /// find frame of last active scope if current frame has no source/symbols |
59 jump_to_last_known_location_on_exception = true; | 59 jump_to_last_known_location_on_exception = true; |
60 | |
61 uint repeat = 0; | |
60 | 62 |
61 /********************************************************************************************** | 63 /********************************************************************************************** |
62 | 64 |
63 **********************************************************************************************/ | 65 **********************************************************************************************/ |
64 void init(string[] args) | 66 void init(string[] args) |
106 | 108 |
107 **********************************************************************************************/ | 109 **********************************************************************************************/ |
108 void exitProcess() | 110 void exitProcess() |
109 { | 111 { |
110 DbgIO.println("Process terminated"); | 112 DbgIO.println("Process terminated"); |
113 repeat = 0; | |
111 cmdQueue ~= ontermCommands; | 114 cmdQueue ~= ontermCommands; |
112 } | 115 } |
113 | 116 |
114 /********************************************************************************************** | 117 /********************************************************************************************** |
115 | 118 |
226 **********************************************************************************************/ | 229 **********************************************************************************************/ |
227 void debugString(string str) | 230 void debugString(string str) |
228 { | 231 { |
229 printf("OUTPUT DEBUG STRING:\n%s\n", toStringz(str)); | 232 printf("OUTPUT DEBUG STRING:\n%s\n", toStringz(str)); |
230 } | 233 } |
234 bool setBreakpointByFunctionname(char[][] lastcmd,uint threadId, int index) | |
235 { | |
236 DataSymbol[] ds; | |
237 size_t codebase; | |
238 // int index; | |
239 | |
240 foreach ( img; dbg.images.images ) | |
241 { | |
242 if ( img.codeView is null ) | |
243 continue; | |
244 DataSymbol[] tds; | |
245 ds ~= img.codeView.global_pub.findDataSymbolBySubstring(lastcmd[1]); | |
246 ds ~= img.codeView.global_sym.findDataSymbolBySubstring(lastcmd[1]); | |
247 ds ~= img.codeView.static_sym.findDataSymbolBySubstring(lastcmd[1]); | |
248 | |
249 foreach ( m; img.codeView.modulesByIndex ) | |
250 ds ~= m.symbols.findDataSymbolBySubstring(lastcmd[1]); | |
251 if (ds.length>0) | |
252 codebase=img.getCodeBase; | |
253 | |
254 } | |
255 debug DbgIO.println("Found candidates:%d",ds.length); | |
256 if (ds.length==1) | |
257 { | |
258 //Location loc = new Location(lastcmd[1]); | |
259 //loc.bind(dbg.images, dbg.source_search_paths); | |
260 if (index>=0) | |
261 if ( lastcmd.length > 2 ) | |
262 index = cast(int)atoi(lastcmd[2]); | |
263 | |
264 Breakpoint bp; | |
265 if (index>=0) // not temporary | |
266 {if ( index <= 0 && dbg.breakpoints.length > 0 ) | |
267 index = dbg.breakpoints.keys.dup.sort[$-1]+1; | |
268 } | |
269 else | |
270 index=-1; | |
271 bp = dbg.setBreakpoint(ds[0].offset+codebase, index, threadId); | |
272 | |
273 DbgIO.println("Breakpoint set: %s", bp.toString); | |
274 } | |
275 else | |
276 if (ds.length==0) | |
277 { | |
278 DbgIO.println("Breakpoint is not set:no matching functions are found!"); | |
279 return false; | |
280 } | |
281 else | |
282 { | |
283 DbgIO.println("Breakpoint is not set:too many matching functions are found!"); | |
284 int maxi=ds.length; | |
285 if (maxi>20) | |
286 { | |
287 DbgIO.println("There are more than 20 possibilities, first twenty is snown:"); | |
288 maxi=20; | |
289 } | |
290 else | |
291 { | |
292 DbgIO.println("These are the matched function names:"); | |
293 } | |
294 foreach (s;ds[0..maxi]) | |
295 { | |
296 //DbgIO.println(s.name_notype); | |
297 printSymbol(s); | |
298 } | |
299 return false; | |
300 } | |
301 return true; | |
302 } | |
231 | 303 |
232 /********************************************************************************************** | 304 /********************************************************************************************** |
233 Command line parser. Gets called when debuggee is suspended. | 305 Command line parser. Gets called when debuggee is suspended. |
234 **********************************************************************************************/ | 306 **********************************************************************************************/ |
235 bool parseCommand(string input) | 307 bool parseCommand(string input) |
280 int index; | 352 int index; |
281 if ( lastcmd.length < 2 ) { | 353 if ( lastcmd.length < 2 ) { |
282 DbgIO.println("invalid syntax - see help for details"); | 354 DbgIO.println("invalid syntax - see help for details"); |
283 break; | 355 break; |
284 } | 356 } |
285 | 357 |
286 int pos = find(lastcmd[1], '#'); | 358 int pos = find(lastcmd[1], '#'); |
287 uint threadId; | 359 uint threadId; |
288 if ( pos > 0 ) | 360 if ( pos > 0 ) |
289 { | 361 { |
290 threadId = cast(uint)atoi(lastcmd[1][pos+1..$]); | 362 threadId = cast(uint)atoi(lastcmd[1][pos+1..$]); |
298 Breakpoint bp; | 370 Breakpoint bp; |
299 if ( index <= 0 && dbg.breakpoints.length > 0 ) | 371 if ( index <= 0 && dbg.breakpoints.length > 0 ) |
300 index = dbg.breakpoints.keys.dup.sort[$-1]+1; | 372 index = dbg.breakpoints.keys.dup.sort[$-1]+1; |
301 bp = dbg.setBreakpoint(loc, index, threadId); | 373 bp = dbg.setBreakpoint(loc, index, threadId); |
302 DbgIO.println("Breakpoint set: %s", bp.toString); | 374 DbgIO.println("Breakpoint set: %s", bp.toString); |
375 break; | |
376 case "bpf": | |
377 int index; | |
378 if ( lastcmd.length < 2 ) { | |
379 DbgIO.println("invalid syntax - see help for details"); | |
380 break; | |
381 } | |
382 | |
383 int pos = find(lastcmd[1], '#'); | |
384 uint threadId; | |
385 if ( pos > 0 ) | |
386 { | |
387 threadId = cast(uint)atoi(lastcmd[1][pos+1..$]); | |
388 lastcmd[1] = lastcmd[1][0..pos]; | |
389 } | |
390 if (lastcmd.length>1) | |
391 setBreakpointByFunctionname(lastcmd,threadId,0); | |
392 break; | |
393 | |
394 | |
395 | |
303 break; | 396 break; |
304 // delete breakpoint | 397 // delete breakpoint |
305 case "dbp": | 398 case "dbp": |
306 if ( lastcmd.length > 1 ) | 399 if ( lastcmd.length > 1 ) |
307 { | 400 { |
837 case "q": | 930 case "q": |
838 dbg.abort = true; | 931 dbg.abort = true; |
839 quit = true; | 932 quit = true; |
840 return true; | 933 return true; |
841 // run/continue | 934 // run/continue |
842 case "r": | 935 case "r": case "rf": |
843 if ( dbg.miniDump !is null ) { | 936 if ( dbg.miniDump !is null ) { |
844 DbgIO.println("Command not valid in post-mortem mode"); | 937 DbgIO.println("Command not valid in post-mortem mode"); |
845 break; | 938 break; |
939 } | |
940 int index; | |
941 if ( lastcmd[0]=="r" && lastcmd.length == 2 ) { | |
942 | |
943 | |
944 int pos = find(lastcmd[1], '#'); | |
945 uint threadId; | |
946 if ( pos > 0 ) | |
947 { | |
948 threadId = cast(uint)atoi(lastcmd[1][pos+1..$]); | |
949 lastcmd[1] = lastcmd[1][0..pos]; | |
950 } | |
951 Location loc = new Location(lastcmd[1]); | |
952 if (!loc.bind(dbg.images, dbg.source_search_paths)) | |
953 break; | |
954 //if ( lastcmd.length > 2 ) | |
955 // index = cast(int)atoi(lastcmd[2]); | |
956 index=-1; | |
957 Breakpoint bp; | |
958 if ( index <= 0 && dbg.breakpoints.length > 0 ) | |
959 index = dbg.breakpoints.keys.dup.sort[$-1]+1; | |
960 bp = dbg.setBreakpoint(loc, index, threadId); | |
961 DbgIO.println("Breakpoint set: %s", bp.toString); | |
962 } | |
963 if ( lastcmd[0]=="rf" && lastcmd.length == 2 ) { | |
964 int pos = find(lastcmd[1], '#'); | |
965 uint threadId; | |
966 if ( pos > 0 ) | |
967 { | |
968 threadId = cast(uint)atoi(lastcmd[1][pos+1..$]); | |
969 lastcmd[1] = lastcmd[1][0..pos]; | |
970 } | |
971 if (!setBreakpointByFunctionname(lastcmd,threadId,-1)) | |
972 break; | |
973 | |
974 | |
846 } | 975 } |
847 if ( dbg.process_loaded ) { | 976 if ( dbg.process_loaded ) { |
848 dbg.resume; | 977 dbg.resume; |
849 return true; | 978 return true; |
850 } | 979 } |
903 } | 1032 } |
904 } | 1033 } |
905 } | 1034 } |
906 break; | 1035 break; |
907 // step over | 1036 // step over |
908 case "ov": | 1037 case "n": case "ov": |
909 if ( dbg.miniDump !is null ) { | 1038 if ( dbg.miniDump !is null ) { |
910 DbgIO.println("Command not valid in post-mortem mode"); | 1039 DbgIO.println("Command not valid in post-mortem mode"); |
911 break; | 1040 break; |
1041 } | |
1042 if ( lastcmd.length ==2 ) { | |
1043 repeat=cast(uint)atoi(lastcmd[1]); | |
1044 repeat--; | |
1045 lastcmd.length = 1; | |
912 } | 1046 } |
913 if ( dbg.process_loaded && dbg.step(StepMode.e_over) ) | 1047 if ( dbg.process_loaded && dbg.step(StepMode.e_over) ) |
914 { | 1048 { |
915 debug foreach ( bp; dbg.temp_breakpoints ) | 1049 debug foreach ( bp; dbg.temp_breakpoints ) |
916 DbgIO.writeln(bp.value.toString); | 1050 DbgIO.writeln(bp.value.toString); |
926 // step into | 1060 // step into |
927 case "in": | 1061 case "in": |
928 if ( dbg.miniDump !is null ) { | 1062 if ( dbg.miniDump !is null ) { |
929 DbgIO.println("Command not valid in post-mortem mode"); | 1063 DbgIO.println("Command not valid in post-mortem mode"); |
930 break; | 1064 break; |
1065 } | |
1066 if ( lastcmd.length ==2 ) { | |
1067 repeat=cast(uint)atoi(lastcmd[1]); | |
1068 repeat--; | |
1069 lastcmd.length = 1; | |
931 } | 1070 } |
932 if ( dbg.process_loaded && dbg.step(StepMode.e_in) ) | 1071 if ( dbg.process_loaded && dbg.step(StepMode.e_in) ) |
933 { | 1072 { |
934 debug foreach ( bp; dbg.temp_breakpoints ) | 1073 debug foreach ( bp; dbg.temp_breakpoints ) |
935 DbgIO.writeln(bp.value.toString); | 1074 DbgIO.writeln(bp.value.toString); |
1392 Read command and call CLI supplied parser function. | 1531 Read command and call CLI supplied parser function. |
1393 Gets called when debuggee is suspended. | 1532 Gets called when debuggee is suspended. |
1394 **********************************************************************************************/ | 1533 **********************************************************************************************/ |
1395 bool readCommand() | 1534 bool readCommand() |
1396 { | 1535 { |
1536 | |
1537 if (repeat>0) | |
1538 { | |
1539 repeat--; | |
1540 return parseCommand(""); | |
1541 } | |
1397 if ( cmdQueue.length <= 0 ) { | 1542 if ( cmdQueue.length <= 0 ) { |
1398 DbgIO.write("->"); | 1543 DbgIO.write("->"); |
1399 string input = DbgIO.readln(); | 1544 string input = DbgIO.readln(); |
1400 cmdQueue ~= input; | 1545 cmdQueue ~= input; |
1401 } | 1546 } |