* fixed environment handling to debuggee

git-svn-id: trunk@4445 -
This commit is contained in:
marc 2003-08-02 00:20:20 +00:00
parent 9338a6c4f2
commit c4e8a6b79e
3 changed files with 136 additions and 20 deletions

View File

@ -153,6 +153,15 @@ begin
Result := 0; Result := 0;
{$ENDIF} {$ENDIF}
end; end;
procedure SetPGid(APID, APGID: Integer);
var
sr: SyscallRegs;
begin
sr.reg2 := APID;
sr.reg3 := APGID;
SysCall(Syscall_nr_setpgid, sr);
end;
////////////////////////////////////////////////// //////////////////////////////////////////////////
@ -175,9 +184,9 @@ begin
then begin then begin
FDbgProcess := TProcess.Create(nil); FDbgProcess := TProcess.Create(nil);
FDbgProcess.CommandLine := ExternalDebugger + ' ' + AOptions; FDbgProcess.CommandLine := ExternalDebugger + ' ' + AOptions;
FDbgProcess.Options:= [poUsePipes, {poNoConsole,} poStdErrToOutPut]; FDbgProcess.Options:= [poUsePipes, {poNoConsole,} poStdErrToOutPut, poNewProcessGroup];
FDbgProcess.ShowWindow := swoNone; FDbgProcess.ShowWindow := swoNone;
FDbgProcess.Environment:=Environment; FDbgProcess.Environment := DebuggerEnvironment;
end; end;
if not FDbgProcess.Running if not FDbgProcess.Running
then begin then begin
@ -366,9 +375,15 @@ begin
SendCmdLn(ACommand); SendCmdLn(ACommand);
end; end;
initialization
// setpgid(0, 0);
end. end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.18 2003/08/02 00:20:20 marc
* fixed environment handling to debuggee
Revision 1.17 2003/07/24 08:47:37 marc Revision 1.17 2003/07/24 08:47:37 marc
+ Added SSHGDB debugger + Added SSHGDB debugger

View File

@ -59,7 +59,8 @@ type
dcWatch, dcWatch,
dcLocal, dcLocal,
dcEvaluate, dcEvaluate,
dcModify dcModify,
dcEnvironment
); );
TDBGCommands = set of TDBGCommand; TDBGCommands = set of TDBGCommand;
@ -796,6 +797,8 @@ type
private private
FArguments: String; FArguments: String;
FBreakPoints: TDBGBreakPoints; FBreakPoints: TDBGBreakPoints;
FDebuggerEnvironment: TStrings;
FCurEnvironment: TStrings;
FEnvironment: TStrings; FEnvironment: TStrings;
FExceptions: TDBGExceptions; FExceptions: TDBGExceptions;
FExitCode: Integer; FExitCode: Integer;
@ -813,9 +816,12 @@ type
FOnDbgOutput: TDBGOutputEvent; FOnDbgOutput: TDBGOutputEvent;
FOnState: TDebuggerStateChangedEvent; FOnState: TDebuggerStateChangedEvent;
FWorkingDir: String; FWorkingDir: String;
procedure DebuggerEnvironmentChanged(Sender: TObject);
procedure EnvironmentChanged(Sender: TObject);
function GetState: TDBGState; function GetState: TDBGState;
function ReqCmd(const ACommand: TDBGCommand; function ReqCmd(const ACommand: TDBGCommand;
const AParams: array of const): Boolean; const AParams: array of const): Boolean;
procedure SetDebuggerEnvironment (const AValue: TStrings );
procedure SetEnvironment(const AValue: TStrings); procedure SetEnvironment(const AValue: TStrings);
procedure SetFileName(const AValue: String); procedure SetFileName(const AValue: String);
protected protected
@ -857,8 +863,8 @@ type
procedure Stop; // quit debugging procedure Stop; // quit debugging
procedure StepOver; procedure StepOver;
procedure StepInto; procedure StepInto;
procedure RunTo(const ASource: String; const ALine: Integer); virtual; // Executes til a certain point procedure RunTo(const ASource: String; const ALine: Integer); // Executes til a certain point
procedure JumpTo(const ASource: String; const ALine: Integer); virtual; // No execute, only set exec point procedure JumpTo(const ASource: String; const ALine: Integer); // No execute, only set exec point
function Evaluate(const AExpression: String; var AResult: String): Boolean; // Evaluates the given expression, returns true if valid function Evaluate(const AExpression: String; var AResult: String): Boolean; // Evaluates the given expression, returns true if valid
function Modify(const AExpression, AValue: String): Boolean; // Modifies the given expression, returns true if valid function Modify(const AExpression, AValue: String): Boolean; // Modifies the given expression, returns true if valid
@ -869,10 +875,12 @@ type
property BreakPoints: TDBGBreakPoints read FBreakPoints; // list of all breakpoints property BreakPoints: TDBGBreakPoints read FBreakPoints; // list of all breakpoints
property CallStack: TDBGCallStack read FCallStack; property CallStack: TDBGCallStack read FCallStack;
property Commands: TDBGCommands read GetCommands; // All current available commands of the debugger property Commands: TDBGCommands read GetCommands; // All current available commands of the debugger
property Environment: TStrings read FEnvironment write SetEnvironment; property DebuggerEnvironment: TStrings read FDebuggerEnvironment
write SetDebuggerEnvironment; // The environment passed to the debugger process
property Environment: TStrings read FEnvironment write SetEnvironment; // The environment passed to the debuggee
property Exceptions: TDBGExceptions read FExceptions; // A list of exceptions we should ignore property Exceptions: TDBGExceptions read FExceptions; // A list of exceptions we should ignore
property ExitCode: Integer read FExitCode; property ExitCode: Integer read FExitCode;
property ExternalDebugger: String read FExternalDebugger; property ExternalDebugger: String read FExternalDebugger; // The name of the debugger executable
property FileName: String read FFileName write SetFileName; // The name of the exe to be debugged property FileName: String read FFileName write SetFileName; // The name of the exe to be debugged
property Locals: TDBGLocals read FLocals; property Locals: TDBGLocals read FLocals;
property Signals: TDBGSignals read FSignals; // A list of actions for signals we know property Signals: TDBGSignals read FSignals; // A list of actions for signals we know
@ -902,7 +910,8 @@ const
'Watch', 'Watch',
'Local', 'Local',
'Evaluate', 'Evaluate',
'Modify' 'Modify',
'Environment'
); );
DBGStateNames: array[TDBGState] of string = ( DBGStateNames: array[TDBGState] of string = (
@ -934,12 +943,12 @@ implementation
const const
COMMANDMAP: array[TDBGState] of TDBGCommands = ( COMMANDMAP: array[TDBGState] of TDBGCommands = (
{dsNone } [], {dsNone } [],
{dsIdle } [], {dsIdle } [dcEnvironment],
{dsStop } [dcRun, dcStepOver, dcStepInto, dcRunTo, dcJumpto, dcBreak, dcWatch, {dsStop } [dcRun, dcStepOver, dcStepInto, dcRunTo, dcJumpto, dcBreak, dcWatch,
dcEvaluate], dcEvaluate, dcEnvironment],
{dsPause} [dcRun, dcStop, dcStepOver, dcStepInto, dcRunTo, dcJumpto, dcBreak, {dsPause} [dcRun, dcStop, dcStepOver, dcStepInto, dcRunTo, dcJumpto, dcBreak,
dcWatch, dcLocal, dcEvaluate, dcModify], dcWatch, dcLocal, dcEvaluate, dcModify, dcEnvironment],
{dsRun } [dcPause, dcStop, dcBreak, dcWatch], {dsRun } [dcPause, dcStop, dcBreak, dcWatch, dcEnvironment],
{dsError} [dcStop] {dsError} [dcStop]
); );
@ -1016,6 +1025,8 @@ begin
end; end;
constructor TDebugger.Create(const AExternalDebugger: String); constructor TDebugger.Create(const AExternalDebugger: String);
var
list: TStringList;
begin begin
inherited Create; inherited Create;
FOnState := nil; FOnState := nil;
@ -1026,7 +1037,20 @@ begin
FArguments := ''; FArguments := '';
FFilename := ''; FFilename := '';
FExternalDebugger := AExternalDebugger; FExternalDebugger := AExternalDebugger;
FEnvironment := TStringList.Create;
list := TStringList.Create;
list.Sorted := True;
list.Duplicates := dupIgnore;
list.OnChange := @DebuggerEnvironmentChanged;
FDebuggerEnvironment := list;
list := TStringList.Create;
list.Sorted := True;
list.Duplicates := dupIgnore;
list.OnChange := @EnvironmentChanged;
FEnvironment := list;
FCurEnvironment := TStringList.Create;
FBreakPoints := CreateBreakPoints; FBreakPoints := CreateBreakPoints;
FLocals := CreateLocals; FLocals := CreateLocals;
FCallStack := CreateCallStack; FCallStack := CreateCallStack;
@ -1066,6 +1090,10 @@ begin
Result := TDBGWatches.Create(Self, TDBGWatch); Result := TDBGWatches.Create(Self, TDBGWatch);
end; end;
procedure TDebugger.DebuggerEnvironmentChanged (Sender: TObject );
begin
end;
destructor TDebugger.Destroy; destructor TDebugger.Destroy;
begin begin
// don't call events // don't call events
@ -1086,13 +1114,17 @@ begin
FreeAndNil(FLocals); FreeAndNil(FLocals);
FreeAndNil(FCallStack); FreeAndNil(FCallStack);
FreeAndNil(FWatches); FreeAndNil(FWatches);
FreeAndNil(FDebuggerEnvironment);
FreeAndNil(FEnvironment); FreeAndNil(FEnvironment);
FreeAndNil(FCurEnvironment);
FreeAndNil(FSignals); FreeAndNil(FSignals);
inherited; inherited;
end; end;
procedure TDebugger.Done; procedure TDebugger.Done;
begin begin
FEnvironment.Clear;
FCurEnvironment.Clear;
SetState(dsNone); SetState(dsNone);
end; end;
@ -1124,6 +1156,41 @@ begin
if Assigned(FOnState) then FOnState(Self,OldState); if Assigned(FOnState) then FOnState(Self,OldState);
end; end;
procedure TDebugger.EnvironmentChanged(Sender: TObject);
var
n, idx: integer;
S: String;
Env: TStringList;
begin
// Createe local copy
Env := TStringList.Create;
try
Env.Assign(Environment);
// Check for nonexisting and unchanged vars
for n := 0 to FCurEnvironment.Count - 1 do
begin
S := FCurEnvironment[n];
idx := Env.IndexOfName(GetPart([], ['='], S, False, False));
if idx = -1
then ReqCmd(dcEnvironment, [S, False])
else begin
if Env[idx] = S
then Env.Delete(idx);
end;
end;
// Set the remaining
for n := 0 to Env.Count - 1 do
begin
ReqCmd(dcEnvironment, [Env[n], True]);
end;
finally
Env.Free;
end;
FCurEnvironment.Assign(FEnvironment);
end;
function TDebugger.Evaluate(const AExpression: String; function TDebugger.Evaluate(const AExpression: String;
var AResult: String): Boolean; var AResult: String): Boolean;
begin begin
@ -1188,11 +1255,6 @@ begin
else Result := False; else Result := False;
end; end;
procedure TDebugger.SetEnvironment(const AValue: TStrings);
begin
FEnvironment.Assign(AValue);
end;
procedure TDebugger.Run; procedure TDebugger.Run;
begin begin
ReqCmd(dcRun, []); ReqCmd(dcRun, []);
@ -1203,6 +1265,16 @@ begin
ReqCmd(dcRunTo, [ASource, ALine]); ReqCmd(dcRunTo, [ASource, ALine]);
end; end;
procedure TDebugger.SetDebuggerEnvironment (const AValue: TStrings );
begin
FDebuggerEnvironment.Assign(AValue);
end;
procedure TDebugger.SetEnvironment(const AValue: TStrings);
begin
FEnvironment.Assign(AValue);
end;
procedure TDebugger.SetExitCode(const AValue: Integer); procedure TDebugger.SetExitCode(const AValue: Integer);
begin begin
FExitCode := AValue; FExitCode := AValue;
@ -3027,6 +3099,9 @@ end;
end. end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.49 2003/08/02 00:20:20 marc
* fixed environment handling to debuggee
Revision 1.48 2003/07/30 23:15:39 marc Revision 1.48 2003/07/30 23:15:39 marc
* Added RegisterDebugger * Added RegisterDebugger

View File

@ -48,7 +48,12 @@ type
SignalText: String; // Signal text if we hit one SignalText: String; // Signal text if we hit one
end; end;
TGDBMICmdFlags = set of (cfNoMiCommand, cfIgnoreState, cfIgnoreError, cfExternal); TGDBMICmdFlags = set of (
cfNoMiCommand, // the command is not a MI command
cfIgnoreState, // ignore the result state of the command
cfIgnoreError, // ignore errors
cfExternal // the command is a result from a user action
);
TGDBMICallback = procedure(var AResultState: TDBGState; var AResultValues: String; const ATag: Integer) of object; TGDBMICallback = procedure(var AResultState: TDBGState; var AResultValues: String; const ATag: Integer) of object;
TGDBMIPauseWaitState = (pwsNone, pwsInternal, pwsExternal); TGDBMIPauseWaitState = (pwsNone, pwsInternal, pwsExternal);
@ -65,6 +70,7 @@ type
FPauseWaitState: TGDBMIPauseWaitState; FPauseWaitState: TGDBMIPauseWaitState;
FInExecuteCount: Integer; FInExecuteCount: Integer;
// Implementation of external functions // Implementation of external functions
function GDBEnvironment(const AVariable: String; const ASet: Boolean): Boolean;
function GDBEvaluate(const AExpression: String; var AResult: String): Boolean; function GDBEvaluate(const AExpression: String; var AResult: String): Boolean;
function GDBRun: Boolean; function GDBRun: Boolean;
function GDBPause(const AInternal: Boolean): Boolean; function GDBPause(const AInternal: Boolean): Boolean;
@ -565,6 +571,22 @@ begin
Result := nil; Result := nil;
end; end;
function TGDBMIDebugger.GDBEnvironment(const AVariable: String; const ASet: Boolean): Boolean;
var
S: String;
begin
Result := True;
if State = dsRun
then GDBPause(True);
if ASet
then ExecuteCommand('-gdb-set env %s', [AVariable], [cfIgnoreState, cfExternal])
else begin
S := AVariable;
ExecuteCommand('unset env %s', [GetPart([], ['='], S, False, False)], [cfNoMiCommand, cfIgnoreState, cfExternal]);
end;
end;
function TGDBMIDebugger.GDBEvaluate(const AExpression: String; function TGDBMIDebugger.GDBEvaluate(const AExpression: String;
var AResult: String): Boolean; var AResult: String): Boolean;
var var
@ -789,7 +811,7 @@ end;
function TGDBMIDebugger.GetSupportedCommands: TDBGCommands; function TGDBMIDebugger.GetSupportedCommands: TDBGCommands;
begin begin
Result := [dcRun, dcPause, dcStop, dcStepOver, dcStepInto, dcRunTo, dcJumpto, Result := [dcRun, dcPause, dcStop, dcStepOver, dcStepInto, dcRunTo, dcJumpto,
dcBreak{, dcWatch}, dcLocal, dcEvaluate, dcModify] dcBreak{, dcWatch}, dcLocal, dcEvaluate, dcModify, dcEnvironment]
end; end;
procedure TGDBMIDebugger.Init; procedure TGDBMIDebugger.Init;
@ -1256,6 +1278,7 @@ begin
dcRunTo: Result := GDBRunTo(String(APArams[0].VAnsiString), APArams[1].VInteger); dcRunTo: Result := GDBRunTo(String(APArams[0].VAnsiString), APArams[1].VInteger);
dcJumpto: Result := GDBJumpTo(String(APArams[0].VAnsiString), APArams[1].VInteger); dcJumpto: Result := GDBJumpTo(String(APArams[0].VAnsiString), APArams[1].VInteger);
dcEvaluate: Result := GDBEvaluate(String(APArams[0].VAnsiString), String(APArams[1].VPointer^)); dcEvaluate: Result := GDBEvaluate(String(APArams[0].VAnsiString), String(APArams[1].VPointer^));
dcEnvironment: Result := GDBEnvironment(String(APArams[0].VAnsiString), AParams[1].VBoolean);
end; end;
end; end;
@ -2025,6 +2048,9 @@ initialization
end. end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.35 2003/08/02 00:20:20 marc
* fixed environment handling to debuggee
Revision 1.34 2003/07/30 23:15:39 marc Revision 1.34 2003/07/30 23:15:39 marc
* Added RegisterDebugger * Added RegisterDebugger