changeset 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
files bin/ddbg.exe src/cli/ddbg_help.txt src/cli/ddbgcli.d src/cli/userinterface.d src/codeview/codeview.d src/debugger.d
diffstat 6 files changed, 217 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
Binary file bin/ddbg.exe has changed
--- a/src/cli/ddbg_help.txt	Sun Apr 10 12:15:04 2011 +0200
+++ b/src/cli/ddbg_help.txt	Sun Apr 17 11:05:31 2011 +0200
@@ -1,14 +1,23 @@
                 Running
 -----------------------------------------------------------------------------
-in                                 step into at source level
-ov                                 step over at source level
+in [repeat]                        step into at source level
+                                   optionally step into repeat times
+ov/n [repeat]                      step over at source level
+                                   optionally step over repeat times
 out                                step out at source level
 r                                  run/continue the program
+r <file>:<line>[#<thrd>]           run until location
+                                   optionally only for the given thread id
+rf funcname[#<thrd>]               run until the given function
+                                   optionally only for the given thread id
                 Breakpoints
 -----------------------------------------------------------------------------
 bp [<file>:<line>[#<thrd>]] [ind]  set breakpoint #index at given file:line
                                    optionally only for the given thread id
                                    optionally with the given breakpoint index
+bpf funcname[#<thrd>] [ind]        set breakpoint for given (substring)function name
+                                   optionally only for the given thread id
+                                   optionally with the given breakpoint index
 dbp [<file>:<line>|#index|*]       delete breakpoint by index, line or all
 lbp                                list breakpoints
 ltbp                               list temporary breakpoints
--- a/src/cli/ddbgcli.d	Sun Apr 10 12:15:04 2011 +0200
+++ b/src/cli/ddbgcli.d	Sun Apr 17 11:05:31 2011 +0200
@@ -57,6 +57,8 @@
 
     bool        auto_find_scope_frame, /// find frame of last active scope if current frame has no source/symbols
                 jump_to_last_known_location_on_exception = true;
+                
+    uint        repeat = 0;
 
     /**********************************************************************************************
 
@@ -108,6 +110,7 @@
     void exitProcess()
     {
         DbgIO.println("Process terminated");
+        repeat = 0;
         cmdQueue ~= ontermCommands;
     }
 
@@ -228,6 +231,75 @@
     {
         printf("OUTPUT DEBUG STRING:\n%s\n", toStringz(str));
     }
+    bool setBreakpointByFunctionname(char[][] lastcmd,uint threadId, int index)
+    {
+        DataSymbol[] ds;
+        size_t codebase;
+       // int index;
+       
+                 foreach ( img; dbg.images.images )
+                {
+                    if ( img.codeView is null )
+                        continue;
+                    DataSymbol[] tds;
+                    ds ~= img.codeView.global_pub.findDataSymbolBySubstring(lastcmd[1]);
+                    ds ~=  img.codeView.global_sym.findDataSymbolBySubstring(lastcmd[1]);
+                    ds ~= img.codeView.static_sym.findDataSymbolBySubstring(lastcmd[1]);
+               
+                    foreach ( m; img.codeView.modulesByIndex )
+                        ds ~= m.symbols.findDataSymbolBySubstring(lastcmd[1]);
+                    if (ds.length>0)
+                      codebase=img.getCodeBase;
+                  
+                }
+                debug DbgIO.println("Found candidates:%d",ds.length);
+                if (ds.length==1)
+                {
+                //Location loc = new Location(lastcmd[1]);
+                //loc.bind(dbg.images, dbg.source_search_paths);
+                if (index>=0)
+                if ( lastcmd.length > 2 )
+                    index = cast(int)atoi(lastcmd[2]);
+
+                Breakpoint bp;
+                if (index>=0) // not temporary
+                {if ( index <= 0 && dbg.breakpoints.length > 0 )
+                    index = dbg.breakpoints.keys.dup.sort[$-1]+1;
+                }
+                else
+                  index=-1;
+                bp = dbg.setBreakpoint(ds[0].offset+codebase, index, threadId);
+        
+                DbgIO.println("Breakpoint set: %s", bp.toString);
+                }
+                else
+                if (ds.length==0)
+                {
+                  DbgIO.println("Breakpoint is not set:no matching functions are found!");
+                  return false;
+                }
+                else
+                {
+                  DbgIO.println("Breakpoint is not set:too many matching functions are found!");
+                  int maxi=ds.length;
+                  if (maxi>20)
+                  {
+                    DbgIO.println("There are more than 20 possibilities, first twenty is snown:");
+                    maxi=20;
+                  }
+                  else
+                  {
+                    DbgIO.println("These are the matched function names:");
+                  }
+                  foreach (s;ds[0..maxi])
+                  {
+                   //DbgIO.println(s.name_notype);
+                   printSymbol(s);
+                  }
+                   return false;
+                }
+       return true;
+    }
 
     /**********************************************************************************************
         Command line parser. Gets called when debuggee is suspended.
@@ -282,7 +354,7 @@
                     DbgIO.println("invalid syntax - see help for details");
                     break;
                 }
-
+           
                 int pos = find(lastcmd[1], '#');
                 uint threadId;
                 if ( pos > 0 )
@@ -301,6 +373,27 @@
                 bp = dbg.setBreakpoint(loc, index, threadId);
                 DbgIO.println("Breakpoint set: %s", bp.toString);
                 break;
+            case "bpf":
+                int index;
+                if ( lastcmd.length < 2 ) {
+                    DbgIO.println("invalid syntax - see help for details");
+                    break;
+                }
+           
+                int pos = find(lastcmd[1], '#');
+                uint threadId;
+                if ( pos > 0 )
+                {
+                    threadId = cast(uint)atoi(lastcmd[1][pos+1..$]);
+                    lastcmd[1] = lastcmd[1][0..pos];
+                }
+               if (lastcmd.length>1)
+                 setBreakpointByFunctionname(lastcmd,threadId,0);
+                  break;
+                
+                
+  
+                break;
             // delete breakpoint
             case "dbp":
                 if ( lastcmd.length > 1 )
@@ -839,11 +932,47 @@
                 quit = true;
                 return true;
             // run/continue
-            case "r":
+            case "r": case "rf":
                 if ( dbg.miniDump !is null ) {
                     DbgIO.println("Command not valid in post-mortem mode");
                     break;
                 }
+                int index;
+                if ( lastcmd[0]=="r" && lastcmd.length == 2 ) {
+                   
+           
+                int pos = find(lastcmd[1], '#');
+                uint threadId;
+                if ( pos > 0 )
+                {
+                    threadId = cast(uint)atoi(lastcmd[1][pos+1..$]);
+                    lastcmd[1] = lastcmd[1][0..pos];
+                }
+                Location loc = new Location(lastcmd[1]);
+                if (!loc.bind(dbg.images, dbg.source_search_paths))
+                   break;
+                //if ( lastcmd.length > 2 )
+                //    index = cast(int)atoi(lastcmd[2]);
+                index=-1;
+                Breakpoint bp;
+                if ( index <= 0 && dbg.breakpoints.length > 0 )
+                    index = dbg.breakpoints.keys.dup.sort[$-1]+1;
+                bp = dbg.setBreakpoint(loc, index, threadId);
+                DbgIO.println("Breakpoint set: %s", bp.toString);
+                }
+                if ( lastcmd[0]=="rf" && lastcmd.length == 2 ) {
+                 int pos = find(lastcmd[1], '#');
+                uint threadId;
+                if ( pos > 0 )
+                {
+                    threadId = cast(uint)atoi(lastcmd[1][pos+1..$]);
+                    lastcmd[1] = lastcmd[1][0..pos];
+                }
+                 if (!setBreakpointByFunctionname(lastcmd,threadId,-1))
+                   break;
+                
+                
+                }
                 if ( dbg.process_loaded ) {
                     dbg.resume;
                     return true;
@@ -905,11 +1034,16 @@
                 }
                 break;
             // step over
-            case "ov":
+            case "n": case "ov":
                 if ( dbg.miniDump !is null ) {
                     DbgIO.println("Command not valid in post-mortem mode");
                     break;
                 }
+                if ( lastcmd.length ==2 ) {
+                   repeat=cast(uint)atoi(lastcmd[1]);
+                   repeat--;
+                   lastcmd.length = 1;
+                }
                 if ( dbg.process_loaded && dbg.step(StepMode.e_over) )
                 {
                     debug foreach ( bp; dbg.temp_breakpoints )
@@ -929,6 +1063,11 @@
                     DbgIO.println("Command not valid in post-mortem mode");
                     break;
                 }
+                if ( lastcmd.length ==2 ) {
+                   repeat=cast(uint)atoi(lastcmd[1]);
+                   repeat--;
+                   lastcmd.length = 1;
+                }
                 if ( dbg.process_loaded && dbg.step(StepMode.e_in) )
                 {
                     debug foreach ( bp; dbg.temp_breakpoints )
@@ -1394,6 +1533,12 @@
     **********************************************************************************************/
     bool readCommand()
     {
+  
+        if (repeat>0)
+        {
+          repeat--;
+          return parseCommand("");
+        }
         if ( cmdQueue.length <= 0 ) {
             DbgIO.write("->");
             string input = DbgIO.readln();
--- a/src/cli/userinterface.d	Sun Apr 10 12:15:04 2011 +0200
+++ b/src/cli/userinterface.d	Sun Apr 17 11:05:31 2011 +0200
@@ -238,8 +238,49 @@
 		return true;
 	}
 
+     /**********************************************************************************************
+      prints information about symbol (not recursive)
+    **********************************************************************************************/
+
+        void printSymbol( NamedSymbol ns, uint indent=0)
+	{
+		
+		{
+			
+
+			char[] indent_str;
+			indent_str.length = indent*2;
+			indent_str[0..indent*2] = ' ';
+			ClassInfo cs = ns.classinfo;
+			if ( cs == ProcedureSymbol.classinfo )
+			{
+			    ProcedureSymbol ps = cast(ProcedureSymbol)ns;
+			   
+				DbgIO.println("%s%s %d arguments",
+                    indent_str, ps.name_type, ps.arguments.symbols.length
+                );
+			}
+			else if ( cs == StackSymbol.classinfo ) {
+				StackSymbol ss = cast(StackSymbol)ns;
+				DbgIO.println("%s%s stack (%s) %x ebp%s%d", indent_str, ns.name_type, ns.mangled_name, ss.cvtype, ss.offset>=0?"+":"", ss.offset);
+			}
+			else if ( cs == DataSymbol.classinfo )
+            {
+				DataSymbol ds = cast(DataSymbol)ns;
+				DbgIO.println("%s%s (%s) data offset: 0x%x size: 0x%x segment: 0x%x type: 0x%x (%s)", indent_str, ds.name_type, ds.name_notype,
+					ds.offset, ds.size, ds.cvdata.segment, ds.cvdata.type, dbg.images.mangleCVtype(ds.cvdata.type)
+				);
+			}
+			else
+				DbgIO.println("%s%s %s", indent_str, ns.name_type, cs.name);
+			ScopeSymbol scs = cast(ScopeSymbol)ns;
+			//if ( scs !is null )
+			//	printSymbols(cv, scs.symbols.named_symbols, indent+1);
+		}
+	}
+
     /**********************************************************************************************
-
+      prints symbols that contain substring with indentation indent
     **********************************************************************************************/
 	void printSymbols(CodeView cv, NamedSymbol[] syms, string substring=null, uint indent=0)
 	{
--- a/src/codeview/codeview.d	Sun Apr 10 12:15:04 2011 +0200
+++ b/src/codeview/codeview.d	Sun Apr 17 11:05:31 2011 +0200
@@ -212,6 +212,20 @@
 		return null;
 	}
 
+        /**********************************************************************************************
+        Find matching data symbols by a substring in its name.
+    **********************************************************************************************/
+	DataSymbol[] findDataSymbolBySubstring(string name)
+	{
+                DataSymbol[] found;
+		foreach ( ds; data_symbols )
+		{
+			if ( find(ds.name_notype,name)>=0 )
+				found~=ds;
+		}
+		return found;
+	}
+
 	/**********************************************************************************************
         Find nearest data symbol to the given address.
     **********************************************************************************************/
--- a/src/debugger.d	Sun Apr 10 12:15:04 2011 +0200
+++ b/src/debugger.d	Sun Apr 17 11:05:31 2011 +0200
@@ -34,7 +34,7 @@
 
 const uint      VERSION_MAJOR = 0,
                 VERSION_MINOR = 13,
-                VERSION_PATCH = 2;
+                VERSION_PATCH = 3;
 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"~
@@ -75,7 +75,7 @@
 
     size_t			    current_address;
     uint                last_line;
-
+   // uint                repeat=0;
     string[][string]	source_files;
     string[]			source_search_paths;