Board logo

Subject: How to get live object from IDE with OTA [Print This Page]

Author: AntonioBakula    Time: 2009-9-19 21:54     Subject: How to get live object from IDE with OTA

This question is not related to cnPack, so I apologise in advance for that, but I was thinking that maybe some of you know the answer

I am trying to make debugger Visualizer for Dataset classes for Delphi 2010, using build in StringListVisualizer as a reference, but I can't get
viewed object with IOTAThread.Evaluate, btw. StringListVisualizer gets content with eval as string.

I tried casting  value returned from Evaluate in ResultAddr to TDataset but that is not working, in variable Exppresion is dataset variable
name and EvalRes is returne as erOK, but when I try to use Result access violation occures.

Here is the code (this is a slightly modified code from StringList visualizer) :

function TDatasetViewerFrame.GetDataset(Expression: string): TDataset;
var
  CurProcess: IOTAProcess;
  CurThread: IOTAThread;
  ResultStr: array[0..4095] of Char;
  CanModify: Boolean;
  ResultAddr, ResultSize, ResultVal: LongWord;
  EvalRes: TOTAEvaluateResult;
  DebugSvcs: IOTADebuggerServices;
begin
  begin
    Result := nil;
    if Supports(BorlandIDEServices, IOTADebuggerServices, DebugSvcs) then
      CurProcess := DebugSvcs.CurrentProcess;

    if CurProcess <> nil then
    begin
      CurThread := CurProcess.CurrentThread;
      if CurThread <> nil then
      begin
        EvalRes := CurThread.Evaluate(Expression, @ResultStr, Length(ResultStr), CanModify, eseAll, '', ResultAddr, ResultSize, ResultVal,
'', 0);

        case EvalRes of
          erOK:
            Result := TDataset(ResultAddr);  // Result is shown as Inaccessible value in debugger
Author: Passion    Time: 2009-9-20 10:29

Could you check the hex value of returned ResultAddr?

Or just check its classname using TObject(ResultAddr).ClassName,
If AV occured, indicate it's not an object, and not a Dataset object.

I'm afraid it's a string such as "([csInheritable])", like shown in Evaluation/Modify window when evaluating an object var in it.
Author: AntonioBakula    Time: 2009-9-21 17:01

Hi Passion !

In Expression variable i have name of an live object (eg. "AdoDataset1") not "([csInheritable])"

Hex value of ResultAddr is $13A46AC

I tried to chek class name of casted pointer but AV occurred, in embarcadero.public.delphi.opentoolsapi I've got an answer that this is not possible because the object's address is in a different virtual address space, to bad

So it seems that is not possible to make visualizer for TDataset classes, anyway thanks for your time
Author: AntonioBakula    Time: 2009-9-21 18:05

I find workaround, but unfortunatly it will work only for dataset that have SaveToFile method, I will evaluate expression (here is the name of dataset variable) + 'SaveToFile('sometempfile')'

this works for TClientDataset
Author: Passion    Time: 2009-9-21 19:47

Oh yes. They're not in same process. We can only obtain needed values using whole expression with properties, such as StringList1.Text to get the simple value. Not the object itself.
Author: AntonioBakula    Time: 2009-9-22 15:52

This makes Debug Visualizers pretty limited, I hope that next OTA version will have this possibility




Welcome to CnPack Forum (http://bbs.cnpack.org/) Powered by Discuz! 5.0.0