* Improved hint evaluation

git-svn-id: trunk@3132 -
This commit is contained in:
marc 2002-08-18 08:57:49 +00:00
parent 9edbf70bc1
commit f17cd838b1
3 changed files with 94 additions and 25 deletions

View File

@ -558,24 +558,50 @@ var
ResultState: TDBGState;
S, ResultValues: String;
ResultList: TStringList;
Expression: TGDBMIExpression;
ResultInfo: TGDBType;
addr, e: Integer;
// Expression: TGDBMIExpression;
begin
// TGDBMIExpression was an attempt to make expression evaluation on Objects possible for GDB <= 5.2
// It is not completed and buggy. Since 5.3 expression evaluation is OK, so maybe in future the
// TGDBMIExpression will be completed to support older gdb versions
(*
Expression := TGDBMIExpression.Create(Self, AExpression);
if not Expression.GetExpression(S)
then S := AExpression;
WriteLN('[GDBEval] AskExpr: ', AExpression, ' EvalExp:', S ,' Dump: ',
Expression.DumpExpression);
Expression.Free;
*)
S := AExpression;
Result := ExecuteCommand('-data-evaluate-expression %s', [S], ResultState,
ResultValues, [cfIgnoreError, cfExternal])
and (ResultState <> dsError);
ResultValues, [cfIgnoreError, cfExternal]);
ResultList := CreateMIValueList(ResultValues);
if ResultState = dsError
then AResult := ResultList.Values['msg']
else AResult := ResultList.Values['value'];
ResultList.Free;
if ResultState = dsError
then Exit;
// Check for strings
ResultInfo := GetGDBTypeInfo(S);
if (ResultInfo = nil)
or (ResultInfo.Kind <> skPointer)
then Exit;
Val(AResult, addr, e);
if e <> 0 then Exit;
if Addr = 0
then AResult := 'nil';
S := Lowercase(ResultInfo.TypeName);
if (S = 'character')
or (S = 'ansistring')
then AResult := '''' + GetText(Pointer(addr)) + '''';
end;
function TGDBMIDebugger.GDBJumpTo(const ASource: String;
@ -734,7 +760,7 @@ function TGDBMIDebugger.GetText(const AExpression: String;
var
S: String;
begin
if not ExecuteCommand('x/s ' + AExpression, AValues, S, [cfNoMICommand])
if not ExecuteCommand('x/s ' + AExpression, AValues, S, [cfNoMICommand, cfIgnoreError])
then begin
Result := '';
end
@ -1960,6 +1986,9 @@ end;
end.
{ =============================================================================
$Log$
Revision 1.31 2002/08/18 08:57:49 marc
* Improved hint evaluation
Revision 1.30 2003/06/13 19:21:31 marc
MWE: + Added initial signal and exception handling

View File

@ -8334,31 +8334,55 @@ var
ActiveSrcEdit: TSourceEditor;
ActiveUnitInfo: TUnitInfo;
Identifier, SmartHintStr: string;
DebugEval: string;
Expression, DebugEval: string;
begin
if (SrcEdit=nil) then exit;
if (ToolStatus<>itNone) and (ToolStatus<>itDebugger) then exit;
// check if there is an identifier
Identifier:=SrcEdit.GetWordFromCaret(CaretPos);
if (Identifier='') or (not IsValidIdent(Identifier)) then exit;
case ToolStatus of
itNone: begin
Identifier := SrcEdit.GetWordFromCaret(CaretPos);
if (Identifier='') or (not IsValidIdent(Identifier)) then exit;
end;
itDebugger: begin
// Identifier := SrcEdit.GetWordFromCaretEx(CaretPos,
// ['A'..'Z', 'a'..'z', '0'..'9', '(', '[', '.', ''''],
// ['A'..'Z', 'a'..'z', '0'..'9', ')', ']', '^', '''']);
Identifier := SrcEdit.GetWordFromCaret(CaretPos);
if Identifier = '' then Exit;
end;
else
Exit;
end;
SourceNotebook.SetActiveSE(SrcEdit);
if not BeginCodeTool(ActiveSrcEdit, ActiveUnitInfo,
[{ctfActivateAbortMode}]) then exit;
{$IFDEF IDE_DEBUG}
writeln('');
writeln('[TMainIDE.OnSrcNotebookShowHintForSource] ************ ',ActiveUnitInfo.Source.Filename,' X=',CaretPos.X,' Y=',CaretPos.Y);
{$ENDIF}
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.OnSrcNotebookShowHintForSource A');{$ENDIF}
SmartHintStr:=CodeToolBoss.FindSmartHint(ActiveUnitInfo.Source,
CaretPos.X,CaretPos.Y);
CodeToolBoss.Abortable:=false;
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.OnSrcNotebookShowHintForSource B');{$ENDIF}
if (ToolStatus=itDebugger)
and DebugBoss.Evaluate(Identifier,DebugEval) then begin
if (DebugEval<>'') then
SmartHintStr:=SmartHintStr+' = '+DebugEval;
case ToolStatus of
itNone: begin
{$IFDEF IDE_DEBUG}
writeln('');
writeln('[TMainIDE.OnSrcNotebookShowHintForSource] ************ ',ActiveUnitInfo.Source.Filename,' X=',CaretPos.X,' Y=',CaretPos.Y);
{$ENDIF}
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.OnSrcNotebookShowHintForSource A');{$ENDIF}
SmartHintStr:=CodeToolBoss.FindSmartHint(ActiveUnitInfo.Source,
CaretPos.X,CaretPos.Y);
CodeToolBoss.Abortable:=false;
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.OnSrcNotebookShowHintForSource B');{$ENDIF}
end;
itDebugger: begin
if SrcEdit.SelectionAvailable
and SrcEdit.CaretInSelection(CaretPos)
then Expression := SrcEdit.GetText(True)
else Expression := Identifier;
if not DebugBoss.Evaluate(Expression, DebugEval)
or (DebugEval = '')
then DebugEval := '???';
SmartHintStr := Expression + ' = ' + DebugEval;
end;
else
Exit;
end;
if SmartHintStr<>'' then
@ -9270,6 +9294,9 @@ end.
{ =============================================================================
$Log$
Revision 1.614 2002/08/18 08:57:49 marc
* Improved hint evaluation
Revision 1.613 2003/06/20 13:24:46 mattias
implemented jump to source for code explorer

View File

@ -139,8 +139,6 @@ type
Shift: TShiftState; X,Y: Integer);
Procedure EditorKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
Procedure EditorStatusChanged(Sender: TObject; Changes: TSynStatusChanges);
function GetWordFromCaretEx(const ACaretPos: TPoint;
const ALeftLimit, ARightLimit: TCharSet): String;
procedure SetCodeBuffer(NewCodeBuffer: TCodeBuffer);
Function GetSource : TStrings;
procedure SetPageName(const AValue: string);
@ -254,7 +252,11 @@ type
// used to get the word at the mouse cursor
Function GetWordAtPosition(Position : TPoint) : String;
function GetWordFromCaret(const ACaretPos: TPoint) : String;
function GetWordFromCaretEx(const ACaretPos: TPoint;
const ALeftLimit, ARightLimit: TCharSet): String;
Function GetWordAtCurrentCaret: String;
function CaretInSelection(const ACaretPos: TPoint): Boolean;
function PositionInSelection(const APosition: TPoint): Boolean;
// cursor
Function GetCaretPosFromCursorPos(CursorPos : TPoint) : TPoint;
@ -1904,6 +1906,17 @@ begin
Result:=-1;
end;
function TSourceEditor.CaretInSelection(const ACaretPos: TPoint): Boolean;
begin
Result := (CompareCaret(EditorComponent.BlockBegin, ACaretpos) >= 0)
and (CompareCaret(ACaretPos, EditorComponent.BlockEnd) >= 0);
end;
function TSourceEditor.PositionInSelection(const APosition: TPoint): Boolean;
begin
Result := CaretInSelection(GetCaretPosfromCursorPos(APosition));
end;
function TSourceEditor.IsActiveOnNoteBook: boolean;
begin
if FSourceNoteBook<>nil then