changeset 4:a5fb1bc967e6

- = command does not need space after it - before using r command, ov command runs the program and stops at main - more source file lines are shown at each step
author marton@basel.hu
date Sun, 10 Apr 2011 12:15:04 +0200
parents 47dd986a534e
children 496dfd8f7342
files bin/ddbg.exe src/cli/ddbgcli.d src/codeview/codeview.d src/debugger.d
diffstat 4 files changed, 64 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
Binary file bin/ddbg.exe has changed
--- a/src/cli/ddbgcli.d	Tue Apr 05 20:56:40 2011 +0200
+++ b/src/cli/ddbgcli.d	Sun Apr 10 12:15:04 2011 +0200
@@ -190,15 +190,33 @@
         else
         {
             string[]	source = dbg.getSourceFile(bp.file);
-            string		source_line;
+            string		source_lines;
             if ( source !is null && bp.line <= source.length )
-                source_line = source[bp.line-1];
+            {
+                const showmore= 2;
+                int startfrom = bp.line- 1 - showmore;
+                int startend = bp.line- 1 + showmore;
+                if (startfrom <0)
+                   startfrom=0;
+                if (startend >=source.length)
+                   startend=source.length-1;
+                int left = showmore;
+                foreach (line;source[startfrom..startend+1])
+                {
+                  if (left==0)
+                    source_lines ~= ">>"~line ~"\n";
+                  else
+                    source_lines ~= "  "~line ~"\n";
+                  left--;
+                }
+            }
 
             if ( !bp.temporary )
                 DbgIO.print("Breakpoint %d hit at ", index);
+            debug  DbgIO.println("before printing location info");
             DbgIO.println("%s:%d 0x%x thread(%d)", bp.file, bp.line, bp.address, thread.id);
-            if ( source_line.length > 0 )
-                DbgIO.writeln(source_line);
+            if ( source_lines.length > 0 )
+                DbgIO.write(source_lines);
         }
         return true;
     }
@@ -221,11 +239,19 @@
             auto r = std.regexp.RegExp("(([^\" \\t]+)|(\"[^\"]+\"))+");
             lastcmd.length = 0;
             foreach ( m; r.search(input) )
+            {
+                //DbgIO.writeln("match:"~r.match(0));
                 lastcmd ~= r.match(0);
+            }
+            
         }
         if ( lastcmd.length <= 0 )
             return false;
-
+        if (lastcmd[0][0]=='=' && lastcmd[0].length>1)
+        {
+          DbgIO.writeln("after ="~lastcmd[0][1..$]);
+          lastcmd=["=",lastcmd[0][1..$]]~lastcmd[1..$];
+        }
         switch ( lastcmd[0] )
         {
             case "help":
@@ -823,7 +849,8 @@
                     return true;
                 }
                 else {
-                    dbg.start(command_line);
+                    dbg.breakonmain = false;
+                    dbg.start(command_line);                 
                     return true;
                 }
             // single-step
@@ -889,6 +916,12 @@
                         DbgIO.writeln(bp.value.toString);
                     return true;
                 }
+                if (!dbg.process_loaded)
+                {
+                   dbg.breakonmain = true;
+                   dbg.start(command_line);
+                   return true;
+                }
                 break;
             // step into
             case "in":
--- a/src/codeview/codeview.d	Tue Apr 05 20:56:40 2011 +0200
+++ b/src/codeview/codeview.d	Sun Apr 10 12:15:04 2011 +0200
@@ -317,7 +317,7 @@
 
 		if ( find(file, '/') >= 0 )
 			file = replace(file, "/", "\\");
-        
+                debug DbgIO.println("searching in %s", file);
 		SourceFile[] sfs = images.findSrcFiles(file);
 		if ( sfs.length == 0 )
 			sfs = images.findSrcFiles(file, source_search_paths);
--- a/src/debugger.d	Tue Apr 05 20:56:40 2011 +0200
+++ b/src/debugger.d	Sun Apr 10 12:15:04 2011 +0200
@@ -34,7 +34,7 @@
 
 const uint      VERSION_MAJOR = 0,
                 VERSION_MINOR = 13,
-                VERSION_PATCH = 1;
+                VERSION_PATCH = 2;
 const string	VERSION_STRING =    "Ddbg "~itoa(VERSION_MAJOR)~"."~itoa(VERSION_MINOR)
                                     ~(VERSION_PATCH>0?"."~itoa(VERSION_PATCH):"")~" beta",
                 WELCOME_STRING =	VERSION_STRING~" - D Debugger\n"~
@@ -69,7 +69,9 @@
     bool	            paused,
                         process_loaded,
                         abort,
-                        single_step;
+                        single_step,
+                        breakonmain =false
+;
 
     size_t			    current_address;
     uint                last_line;
@@ -96,7 +98,7 @@
 
     UserInterface	    ui;
 
-    uint                evaluationDepth = 1;
+    uint                evaluationDepth = 2;
     bool                create_new_console;
 
     //=============================================================================================
@@ -602,6 +604,21 @@
                                 int bpi=-1;
                                 Breakpoint bp = setBreakpoint(mainds.offset+main_image.getCodeBase, bpi, 0, true);
                                 bp.deactivate_d_exception_handler = true;
+                                debug DbgIO.println("set breakpoint");
+                            }
+                            {
+                                int bpi=-1;
+                                // stop on first line
+                                if (breakonmain)
+                                {
+                                 breakonmain=false;
+                                 mainds = main_image.codeView.global_pub.findDataSymbol("__Dmain");
+                                 if ( mainds !is null )
+                                 {
+                                   Breakpoint bp = setBreakpoint(mainds.offset+main_image.getCodeBase, bpi, thread_id);
+                                 }
+                                }
+  
                             }
                         }
 
@@ -835,6 +852,7 @@
     void handleBreakpoint(Breakpoint bp, uint bp_index)
     {
         CONTEXT ctx;
+        debug DbgIO.println("handling breakpoint");
         if ( !process.threads[thread_id].getContext(ctx) )
             throw new DebuggerException("Error: Couldn't GetThreadContext to reset instruction pointer: %s", lastError);
 
@@ -972,6 +990,7 @@
             return full;
         foreach ( string sp; source_search_paths )
         {
+            debug DbgIO.println("searching for source file %s",sp~filename);
             full = getFullPath(sp~filename);
             if ( exists(full) )
                 return full;
@@ -1270,6 +1289,7 @@
             debug DbgIO.println("not setting bp at current 0x%08x", address);
             return null;
         }
+        debug DbgIO.println("setting breakpoint 0x%08x", address);
         bp = new Breakpoint(loc, new_index<0, threadId, hardware);
         addBreakpoint(bp, new_index);
         return bp;
@@ -1283,6 +1303,7 @@
     void addBreakpoint(Breakpoint bp, int new_index)
     {
         // add to breakpoint list
+        debug DbgIO.println("adding breakpoint 0x%08x", bp.address);
         if ( bp.temporary )
             temp_breakpoints ~= bp;
         else