Просмотр исходного кода

+ Disassembly window made public

pierre 24 лет назад
Родитель
Сommit
beb0234acb
6 измененных файлов с 225 добавлено и 63 удалено
  1. 5 1
      ide/fpconst.pas
  2. 67 10
      ide/fpdebug.pas
  3. 14 2
      ide/fpide.pas
  4. 94 24
      ide/fpmrun.inc
  5. 5 1
      ide/fpstre.inc
  6. 40 25
      ide/fpviews.pas

+ 5 - 1
ide/fpconst.pas

@@ -233,6 +233,7 @@ const
      cmRedoAll           = 2502;
 
      cmDebuggerStopped   = 2600;
+     cmDisassemble       = 2601;
 
      cmSymBrowse         = 2700;
      cmSymGotoSource     = 2701;
@@ -433,7 +434,10 @@ implementation
 END.
 {
   $Log$
-  Revision 1.2  2001-08-05 02:01:47  peter
+  Revision 1.3  2001-11-07 00:28:52  pierre
+   + Disassembly window made public
+
+  Revision 1.2  2001/08/05 02:01:47  peter
     * FVISION define to compile with fvision units
 
   Revision 1.1  2001/08/04 11:30:23  peter

+ 67 - 10
ide/fpdebug.pas

@@ -68,7 +68,8 @@ type
     function  GetPointerAt(addr : CORE_ADDR) : CORE_ADDR;
   end;
 
-  BreakpointType = (bt_function,bt_file_line,bt_watch,bt_awatch,bt_rwatch,bt_invalid);
+  BreakpointType = (bt_function,bt_file_line,bt_watch,
+                    bt_awatch,bt_rwatch,bt_address,bt_invalid);
   BreakpointState = (bs_enabled,bs_disabled,bs_deleted);
 
   PBreakpointCollection=^TBreakpointCollection;
@@ -88,6 +89,7 @@ type
      GDBIndex : longint;
      GDBState : BreakpointState;
      constructor Init_function(Const AFunc : String);
+     constructor Init_Address(Const AAddress : String);
      constructor Init_Empty;
      constructor Init_file_line(AFile : String; ALine : longint);
      constructor Init_type(atyp : BreakpointType;Const AnExpr : String);
@@ -108,7 +110,7 @@ type
       function  GetType(typ : BreakpointType;Const s : String) : PBreakpoint;
       function  ToggleFileLine(FileName: String;LineNr : Longint) : boolean;
       procedure Update;
-      procedure ShowBreakpoints(W : PSourceWindow);
+      procedure ShowBreakpoints(W : PFPWindow);
       procedure ShowAllBreakpoints;
     end;
 
@@ -338,7 +340,7 @@ type
 
 const
      BreakpointTypeStr : Array[BreakpointType] of String[9]
-       = ( 'function','file-line','watch','awatch','rwatch','invalid' );
+       = ( 'function','file-line','watch','awatch','rwatch','address','invalid');
      BreakpointStateStr : Array[BreakpointState] of String[8]
        = ( 'enabled','disabled','invalid' );
 
@@ -1074,7 +1076,8 @@ begin
         end
       { For watch we should get old and new value !! }
       else if (Not assigned(GDBWindow) or not GDBWindow^.GetState(sfActive)) and
-         (PB^.typ<>bt_file_line) and (PB^.typ<>bt_function) then
+         (PB^.typ<>bt_file_line) and (PB^.typ<>bt_function) and
+         (PB^.typ<>bt_address) then
         begin
            Command('p '+GetStr(PB^.Name));
            S:=GetPChar(GetOutput);
@@ -1181,6 +1184,21 @@ begin
   CurrentValue:=nil;
 end;
 
+constructor TBreakpoint.Init_Address(Const AAddress : String);
+begin
+  typ:=bt_address;
+  state:=bs_enabled;
+  GDBState:=bs_deleted;
+  Name:=NewStr(AAddress);
+  FileName:=nil;
+  Line:=0;
+  IgnoreCount:=0;
+  Commands:=nil;
+  Conditions:=nil;
+  OldValue:=nil;
+  CurrentValue:=nil;
+end;
+
 constructor TBreakpoint.Init_Empty;
 begin
   typ:=bt_function;
@@ -1294,6 +1312,8 @@ begin
         Debugger^.Command('break '+NameAndExtOf(FileName^)+':'+IntToStr(Line))
       else if (typ=bt_function) and assigned(name) then
         Debugger^.Command('break '+name^)
+      else if (typ=bt_address) and assigned(name) then
+        Debugger^.Command('break *0x'+name^)
       else if (typ=bt_watch) and assigned(name) then
         Debugger^.Command('watch '+name^)
       else if (typ=bt_awatch) and assigned(name) then
@@ -1459,17 +1479,49 @@ begin
     GetGDB:=FirstThat(@IsNum);
 end;
 
-procedure TBreakpointCollection.ShowBreakpoints(W : PSourceWindow);
+procedure TBreakpointCollection.ShowBreakpoints(W : PFPWindow);
 
   procedure SetInSource(P : PBreakpoint);{$ifndef FPC}far;{$endif}
   begin
     If assigned(P^.FileName) and
-      (GDBFileName(FExpand(P^.FileName^))=GDBFileName(FExpand(W^.Editor^.FileName))) then
-      W^.Editor^.SetLineFlagState(P^.Line-1,lfBreakpoint,P^.state=bs_enabled);
+      (GDBFileName(FExpand(P^.FileName^))=GDBFileName(FExpand(PSourceWindow(W)^.Editor^.FileName))) then
+      PSourceWindow(W)^.Editor^.SetLineFlagState(P^.Line-1,lfBreakpoint,P^.state=bs_enabled);
+  end;
+
+  procedure SetInDisassembly(P : PBreakpoint);{$ifndef FPC}far;{$endif}
+    var
+      PDL : PDisasLine;
+      S : string;
+      ps,qs,i : longint;
+  begin
+    for i:=0 to PDisassemblyWindow(W)^.Editor^.GetLineCount-1 do
+      begin
+        PDL:=PDisasLine(PDisassemblyWindow(W)^.Editor^.GetLine(i));
+        if PDL^.Address=0 then
+          begin
+            if (P^.typ=bt_file_line) then
+              begin
+                S:=PDisassemblyWindow(W)^.Editor^.GetDisplayText(i);
+                ps:=pos(':',S);
+                qs:=pos(' ',copy(S,ps+1,High(S)));
+                if (GDBFileName(FExpand(P^.FileName^))=GDBFileName(FExpand(Copy(S,1,ps-1)))) and
+                   (StrToInt(copy(S,ps+1,qs-1))=P^.line) then
+                  PDisassemblyWindow(W)^.Editor^.SetLineFlagState(i,lfBreakpoint,P^.state=bs_enabled);
+              end;
+          end
+        else
+          begin
+            If (P^.typ=bt_address) and (PDL^.Address=HexToInt(P^.Name^)) then
+              PDisassemblyWindow(W)^.Editor^.SetLineFlagState(i,lfBreakpoint,P^.state=bs_enabled);
+          end;
+      end;
   end;
 
 begin
-  ForEach(@SetInSource);
+  if W=PFPWindow(DisassemblyWindow) then
+    ForEach(@SetInDisassembly)
+  else
+    ForEach(@SetInSource);
 end;
 
 procedure TBreakpointCollection.ShowAllBreakpoints;
@@ -3565,13 +3617,15 @@ end;
       { goto source/assembly mixture }
       InitDisassemblyWindow;
       DisassemblyWindow^.LoadFunction('');
+      DisassemblyWindow^.SetCurAddress(Debugger^.frames[Focused]^.address);
       DisassemblyWindow^.SelectInDebugSession;
     end;
 
 
   procedure   TFramesListBox.HandleEvent(var Event: TEvent);
     begin
-      if (Event.What=EvKeyDown) and (Event.CharCode='i') then
+      if ((Event.What=EvKeyDown) and (Event.CharCode='i')) or
+         ((Event.What=EvCommand) and (Event.Command=cmDisassemble)) then
         GotoAssembly;
       inherited HandleEvent(Event);
     end;
@@ -3900,7 +3954,10 @@ end.
 
 {
   $Log$
-  Revision 1.6  2001-10-14 14:16:06  peter
+  Revision 1.7  2001-11-07 00:28:52  pierre
+   + Disassembly window made public
+
+  Revision 1.6  2001/10/14 14:16:06  peter
     * fixed typo for linux
 
   Revision 1.5  2001/10/11 11:39:35  pierre

+ 14 - 2
ide/fpide.pas

@@ -472,6 +472,15 @@ begin
       NewStatusKey('~'#17+'ÄŮ~ Done', kbNoKey, 65535,
       NewStatusKey('~Esc~ Cancel', kbNoKey, 65535,
       nil)))))),
+    NewStatusDef(hcStackWindow, hcStackWindow,
+      NewStatusKey(status_help, kbF1, cmHelp,
+      NewStatusKey(status_disassemble, kbAltI, cmDisassemble,
+      NewStatusKey('', kbAltF3, cmClose,
+      NewStatusKey('', kbF5, cmZoom,
+      NewStatusKey('', kbCtrlF5, cmResize,
+      NewStatusKey('', kbF6, cmNext,
+      NewStatusKey('', kbShiftF6, cmPrev,
+      nil))))))),
     NewStatusDef(hcFirstCommand, hcLastCommand,
       NewStatusKey(status_help, kbF1, cmHelp,
       NewStatusKey('', kbF10, cmMenu,
@@ -524,7 +533,7 @@ begin
       NewStatusKey(status_localmenu, kbAltF10, cmLocalMenu,
       StdStatusKeys(
       nil)))))),
-    nil))))))))));
+    nil)))))))))));
 end;
 
 procedure TIDEApp.Idle;
@@ -1167,7 +1176,10 @@ end;
 END.
 {
   $Log$
-  Revision 1.6  2001-10-24 14:17:27  pierre
+  Revision 1.7  2001-11-07 00:28:53  pierre
+   + Disassembly window made public
+
+  Revision 1.6  2001/10/24 14:17:27  pierre
    * try to fix the Win2000 mouse problem
 
   Revision 1.5  2001/10/02 23:56:30  pierre

+ 94 - 24
ide/fpmrun.inc

@@ -299,35 +299,68 @@ end;
 procedure TIDEApp.DoContToCursor;
 {$ifndef NODEBUG}
 var
-  W : PSourceWindow;
-  FileName : string;
-  LineNr : longint;
+  W : PFPWindow;
+  PDL : PDisasLine;
+  S,FileName : string;
+  P,CurY,LineNr : longint;
 {$endif}
 begin
 {$ifndef NODEBUG}
   if (DeskTop^.Current=nil) or
-     (TypeOf(DeskTop^.Current^)<>TypeOf(TSourceWindow)) then
+     ((TypeOf(DeskTop^.Current^)<>TypeOf(TSourceWindow)) and
+      (TypeOf(DeskTop^.Current^)<>TypeOf(TDisassemblyWindow))) then
     Begin
        ErrorBox(msg_impossibletoreachcursor,nil);
        Exit;
     End;
 
-  W:=PSourceWindow(DeskTop^.Current);
+  If not assigned(Debugger) or Not Debugger^.HasExe then
+    begin
+      InitDebugger;
+      if not assigned(Debugger) then
+        begin
+          NoDebugger;
+          exit;
+        end;
+    end;
+
+  W:=PFPWindow(DeskTop^.Current);
   If assigned(W) then
     begin
-      FileName:=W^.Editor^.FileName;
-      LineNr:=W^.Editor^.CurPos.Y+1;
-      If not assigned(Debugger) or Not Debugger^.HasExe then
+      If TypeOf(W^)=TypeOf(TSourceWindow) then
+        begin
+          FileName:=PSourceWindow(W)^.Editor^.FileName;
+          LineNr:=PSourceWindow(W)^.Editor^.CurPos.Y+1;
+          Debugger^.Command('tbreak '+GDBFileName(NameAndExtOf(FileName))+':'+IntToStr(LineNr));
+          Debugger^.Continue;
+        end
+      else
         begin
-          InitDebugger;
-          if not assigned(Debugger) then
+          CurY:=PDisassemblyWindow(W)^.Editor^.CurPos.Y;
+          if CurY<PDisassemblyWindow(W)^.Editor^.GetLineCount then
+            PDL:=PDisasLine(PDisassemblyWindow(W)^.Editor^.GetLine(CurY))
+          else
+            PDL:=nil;
+          if assigned(PDL) then
             begin
-              NoDebugger;
-              exit;
+              if PDL^.Address<>0 then
+                begin
+                  Debugger^.Command('tbreak *0x'+IntToHex(PDL^.Address,8));
+                end
+              else
+                begin
+                  S:=PDisassemblyWindow(W)^.Editor^.GetDisplayText(PDisassemblyWindow(W)^.Editor^.CurPos.Y);
+                  p:=pos(':',S);
+                  FileName:=Copy(S,1,p-1);
+                  S:=Copy(S,p+1,high(S));
+                  p:=pos(' ',S);
+                  S:=Copy(S,1,p-1);
+                  LineNr:=StrToInt(S);
+                  Debugger^.Command('tbreak '+GDBFileName(NameAndExtOf(FileName))+':'+IntToStr(LineNr));
+                end;
+              Debugger^.Continue;
             end;
         end;
-      Debugger^.Command('tbreak '+GDBFileName(NameAndExtOf(FileName))+':'+IntToStr(LineNr));
-      Debugger^.Continue;
     end;
 {$else NODEBUG}
   NoDebugger;
@@ -355,27 +388,61 @@ procedure TIDEApp.DoToggleBreak;
 {$ifndef NODEBUG}
 var
   W : PSourceWindow;
-  FileName : string;
-{  b : boolean;}
-  LineNr : longint;
+  WD : PDisassemblyWindow;
+  PDL : PDisasLine;
+  PB : PBreakpoint;
+  S,FileName : string;
+  b : boolean;
+  CurY,P,LineNr : longint;
 {$endif}
 begin
 {$ifndef NODEBUG}
   if (DeskTop^.Current=nil) or
-     (TypeOf(DeskTop^.Current^)<>TypeOf(TSourceWindow)) then
+     (TypeOf(DeskTop^.Current^)<>TypeOf(TSourceWindow)) and
+     (TypeOf(DeskTop^.Current^)<>TypeOf(TDisassemblyWindow)) then
     Begin
        ErrorBox(msg_impossibletosetbreakpoint,nil);
        Exit;
     End;
 
-  W:=PSourceWindow(DeskTop^.Current);
-  If assigned(W) then
+  if assigned (DeskTop^.Current) and
+     (TypeOf(DeskTop^.Current^)=TypeOf(TSourceWindow)) then
     begin
+      W:=PSourceWindow(DeskTop^.Current);
       FileName:=W^.Editor^.FileName;
       LineNr:=W^.Editor^.CurPos.Y+1;
-{      b:=}BreakpointsCollection^.ToggleFileLine(FileName,LineNr);
-      {W^.Editor^.SetLineBreakState(LineNr,b);
-        already done PM }
+      BreakpointsCollection^.ToggleFileLine(FileName,LineNr);
+    end
+  else if assigned (DeskTop^.Current) and
+     (TypeOf(DeskTop^.Current^)=TypeOf(TDisassemblyWindow)) then
+    begin
+      WD:=PDisassemblyWindow(DeskTop^.Current);
+      CurY:=WD^.Editor^.CurPos.Y;
+      if CurY<WD^.Editor^.GetLineCount then
+        PDL:=PDisasLine(WD^.Editor^.GetLine(CurY))
+      else
+        PDL:=nil;
+      if assigned(PDL) then
+        begin
+          if PDL^.Address<>0 then
+            begin
+              PB:=New(PBreakpoint,init_address(IntToHex(PDL^.Address,8)));
+              BreakpointsCollection^.Insert(PB);
+              WD^.Editor^.SetLineFlagState(CurY,lfBreakpoint,true);
+            end
+          else
+            begin
+              S:=WD^.Editor^.GetDisplayText(WD^.Editor^.CurPos.Y);
+              p:=pos(':',S);
+              FileName:=Copy(S,1,p-1);
+              S:=Copy(S,p+1,high(S));
+              p:=pos(' ',S);
+              S:=Copy(S,1,p-1);
+              LineNr:=StrToInt(S);
+              b:=BreakpointsCollection^.ToggleFileLine(FileName,LineNr);
+              WD^.Editor^.SetLineFlagState(CurY,lfBreakpoint,b);
+            end;
+        end;
     end;
 {$else NODEBUG}
   NoDebugger;
@@ -384,7 +451,10 @@ end;
 
 {
   $Log$
-  Revision 1.1  2001-08-04 11:30:23  peter
+  Revision 1.2  2001-11-07 00:28:53  pierre
+   + Disassembly window made public
+
+  Revision 1.1  2001/08/04 11:30:23  peter
     * ide works now with both compiler versions
 
   Revision 1.1.2.13  2001/03/12 17:34:55  pierre

+ 5 - 1
ide/fpstre.inc

@@ -889,6 +889,7 @@ const
       status_msgtracksource  = '~Space~ Track source';
       status_close           = '~Esc~ Close';
       status_calculatorpaste = '~Ctrl+Enter~ Transfer result';
+      status_disassemble     = '~Alt+I~ Disassemble';
 
       { Menu hints }
       hint_systemmenu        = 'System menu';
@@ -1012,7 +1013,10 @@ const
 
 {
   $Log$
-  Revision 1.4  2001-10-24 21:49:56  pierre
+  Revision 1.5  2001-11-07 00:28:53  pierre
+   + Disassembly window made public
+
+  Revision 1.4  2001/10/24 21:49:56  pierre
    + FindProcedure implemented
 
   Revision 1.3  2001/10/12 14:21:47  pierre

+ 40 - 25
ide/fpviews.pas

@@ -63,10 +63,12 @@ type
       function    GetPalette: PPalette; virtual;
     end;
 
+    PFPWindow = ^TFPWindow;
     TFPWindow = object(TWindow)
       AutoNumber: boolean;
       procedure   HandleEvent(var Event: TEvent); virtual;
       procedure   SetState(AState: Word; Enable: Boolean); virtual;
+      procedure   UpdateCommands; virtual;
       constructor Load(var S: TStream);
       procedure   Store(var S: TStream);
       procedure   Update; virtual;
@@ -172,7 +174,6 @@ type
       procedure   SetTitle(ATitle: string); virtual;
       procedure   UpdateTitle; virtual;
       procedure   HandleEvent(var Event: TEvent); virtual;
-      procedure   SetState(AState: Word; Enable: Boolean); virtual;
       procedure   Update; virtual;
       procedure   UpdateCommands; virtual;
       function    GetPalette: PPalette; virtual;
@@ -211,7 +212,6 @@ type
       function    GetPalette: PPalette;virtual;
       constructor Load(var S: TStream);
       procedure   Store(var S: TStream);
-      procedure   SetState(AState: Word; Enable: Boolean); virtual;
       procedure   UpdateCommands; virtual;
       destructor  Done; virtual;
     end;
@@ -257,6 +257,7 @@ type
       procedure   WriteSourceString(Const S : string;line : longint);
       procedure   WriteDisassemblyString(Const S : string;address : cardinal);
       procedure   SetCurAddress(address : cardinal);
+      procedure   UpdateCommands; virtual;
       function    GetPalette: PPalette;virtual;
       destructor  Done; virtual;
     end;
@@ -1498,7 +1499,9 @@ begin
 end;
 
 procedure TFPWindow.SetState(AState: Word; Enable: Boolean);
+var OldState: word;
 begin
+  OldState:=State;
   inherited SetState(AState,Enable);
   if AutoNumber then
     if (AState and (sfVisible+sfExposed))<>0 then
@@ -1510,6 +1513,12 @@ begin
         end
       else
         Number:=0;
+  if ((AState and sfActive)<>0) and (((OldState xor State) and sfActive)<>0) then
+    UpdateCommands;
+end;
+
+procedure TFPWindow.UpdateCommands;
+begin
 end;
 
 procedure TFPWindow.Update;
@@ -1771,15 +1780,6 @@ begin
   inherited HandleEvent(Event);
 end;
 
-procedure TSourceWindow.SetState(AState: Word; Enable: Boolean);
-var OldState: word;
-begin
-  OldState:=State;
-  inherited SetState(AState,Enable);
-  if ((AState and sfActive)<>0) and (((OldState xor State) and sfActive)<>0) then
-    UpdateCommands;
-end;
-
 procedure TSourceWindow.UpdateCommands;
 var Active: boolean;
 begin
@@ -2070,20 +2070,11 @@ begin
   Editor^.Draw;
 end;
 
-procedure TGDBWindow.SetState(AState: Word; Enable: Boolean);
-var OldState: word;
-begin
-  OldState:=State;
-  inherited SetState(AState,Enable);
-  if ((AState and sfActive)<>0) and (((OldState xor State) and sfActive)<>0) then
-    UpdateCommands;
-end;
-
 procedure TGDBWindow.UpdateCommands;
 var Active: boolean;
 begin
   Active:=GetState(sfActive);
-  SetCmdState([cmSaveAs,cmHide],Active);
+  SetCmdState([cmSaveAs,cmHide,cmRun],Active);
   SetCmdState(EditorCmds,Active);
   SetCmdState(ToClipCmds+FromClipCmds+NulClipCmds+UndoCmd+RedoCmd,Active);
   Message(Application,evBroadcast,cmCommandSetChanged,nil);
@@ -2100,7 +2091,7 @@ constructor TDisassemblyEditor.Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
 begin
   Inherited Init(Bounds,AHScrollBar,AVScrollBar,AIndicator,AFileName);
   GrowMode:=gfGrowHiX+gfGrowHiY;
-  SetFlags(efInsertMode+efSyntaxHighlight+efNoIndent+efExpandAllTabs+efHighlightRow);
+  SetFlags(efInsertMode+efSyntaxHighlight+efNoIndent+efExpandAllTabs{+efHighlightRow});
   New(DisasLines,Init(500,1000));
   Core^.ChangeLinesTo(DisasLines);
   { do not allow to write into that window }
@@ -2338,6 +2329,8 @@ begin
   StrDispose(p1);
   Editor^.ReleaseSource;
   Editor^.UpdateAttrs(0,attrForceFull);
+  If assigned(BreakpointsCollection) then
+    BreakpointsCollection^.ShowBreakpoints(@Self);
   Unlock;
   ReDraw;
 end;
@@ -2364,6 +2357,17 @@ begin
   Editor^.GetCurrentLine(address);
 end;
 
+procedure TDisassemblyWindow.UpdateCommands;
+var Active: boolean;
+begin
+  Active:=GetState(sfActive);
+  SetCmdState(SourceCmds+CompileCmds,Active);
+  SetCmdState(EditorCmds,Active);
+  SetCmdState(ToClipCmds+FromClipCmds+NulClipCmds+UndoCmd+RedoCmd,false);
+  Message(Application,evBroadcast,cmCommandSetChanged,nil);
+end;
+
+
 function    TDisassemblyWindow.GetPalette: PPalette;
 const P: string[length(CSourceWindow)] = CSourceWindow;
 begin
@@ -2477,7 +2481,11 @@ begin
         DontClear:=false;
         case Event.KeyCode of
           kbEnter :
-            Message(@Self,evCommand,cmMsgGotoSource,nil);
+            begin
+              Message(@Self,evCommand,cmMsgGotoSource,nil);
+              ClearEvent(Event);
+              exit;
+            end;
         else
           DontClear:=true;
         end;
@@ -2496,7 +2504,11 @@ begin
         case Event.Command of
           cmMsgGotoSource :
             if Range>0 then
-              GotoSource;
+              begin
+                GotoSource;
+                ClearEvent(Event);
+                exit;
+              end;
           cmMsgTrackSource :
             if Range>0 then
               TrackSource;
@@ -4187,7 +4199,10 @@ end;
 END.
 {
   $Log$
-  Revision 1.9  2001-10-11 23:45:28  pierre
+  Revision 1.10  2001-11-07 00:28:53  pierre
+   + Disassembly window made public
+
+  Revision 1.9  2001/10/11 23:45:28  pierre
    + some preliminary code for graph use
 
   Revision 1.8  2001/10/11 11:36:30  pierre