2011/12/19 Martin <[email protected]>:

> The patch should check that the new list has the same registers in the same
> order.

The attached patch now stores all names of registers whose format has
been changed (in SetFormat) and when initializing them again it looks
up the preferred format by the register name. This is very similar to
what I initially tried when I tried to do it from within the GUI.

Bernd
Index: debugger/gdbmidebugger.pp
===================================================================
--- debugger/gdbmidebugger.pp	(Revision 34256)
+++ debugger/gdbmidebugger.pp	(Arbeitskopie)
@@ -927,6 +927,11 @@
     function DebugText: String; override;
   end;
 
+  TGDBMIRegisterSavedFormat = record
+    RegisterName: String;
+    DisplayFormat: TRegisterDisplayFormat;
+  end;
+
   { TGDBMIRegisters }
 
   TGDBMIRegisters = class(TDBGRegisters)
@@ -935,6 +940,7 @@
     FRegValues: Array [TRegisterDisplayFormat] of TStringArray;
     FRegModified: TBoolArray;
     FFormats: Array of TRegisterDisplayFormat;
+    FSavedFormats: Array of TGDBMIRegisterSavedFormat;
 
     FGetRegisterCmdObj: TGDBMIDebuggerCommandRegisterNames;
     FRegistersReqState: TGDBMIEvaluationState;
@@ -958,6 +964,8 @@
     procedure DoGetRegValuesFinished(Sender: TObject);
     procedure DoGetRegModifiedDestroyed(Sender: TObject);
     procedure DoGetRegModifiedFinished(Sender: TObject);
+    procedure SaveFormat(AnIndex: Integer);
+    function GetSavedFormat(AName: String): TRegisterDisplayFormat;
   protected
     procedure DoStateChange(const AOldState: TDBGState); override;
     procedure Invalidate;
@@ -8302,6 +8310,7 @@
   and (AnIndex <= High(FFormats))
   then begin
     FFormats[AnIndex] := AValue;
+    SaveFormat(AnIndex);
     inherited Changed;
   end
   else inherited SetFormat(AnIndex, AValue);
@@ -8335,7 +8344,7 @@
     for f := low(TRegisterDisplayFormat) to high(TRegisterDisplayFormat) do
       FRegValues[f][n] := '';
     FRegModified[n] := False;
-    FFormats[n] := rdDefault;
+    FFormats[n] := GetSavedFormat(Cmd.Names[n]);
   end;
 
   FGetRegisterCmdObj:= nil;
@@ -8442,6 +8451,45 @@
   then inherited Changed;
 end;
 
+// If the user changed the display format then we separately store
+// this register's name and format, so we can later after a restart
+// reinitialize the same register with this same format again.
+procedure TGDBMIRegisters.SaveFormat(AnIndex: Integer);
+var
+  L, I: Integer;
+  Found : Boolean;
+begin
+  Found := False;
+  L := Length(FSavedFormats);
+  for I := 0 to Pred(L) do begin
+    if FSavedFormats[I].RegisterName = FRegNames[AnIndex] then begin
+      FSavedFormats[I].DisplayFormat := FFormats[AnIndex];
+      Found := True;
+      break;
+    end;
+  end;
+  if not Found then begin
+    SetLength(FSavedFormats, L + 1);
+    with FSavedFormats[L] do begin
+      RegisterName := FRegNames[AnIndex];
+      DisplayFormat := FFormats[AnIndex];
+    end;
+  end;
+end;
+
+function TGDBMIRegisters.GetSavedFormat(AName: String): TRegisterDisplayFormat;
+var
+  I: Integer;
+begin
+  Result := rdDefault;
+  for I := 0 to Pred(Length(FSavedFormats)) do begin
+    if FSavedFormats[I].RegisterName = AName then begin
+      Result := FSavedFormats[I].DisplayFormat;
+      break;
+    end;
+  end;
+end;
+
 procedure TGDBMIRegisters.ModifiedNeeded;
 var
   ForceQueue: Boolean;
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to