Recent

Author Topic: [SOLVED] Inspect Into TStringlist  (Read 1808 times)

superc

  • Full Member
  • ***
  • Posts: 242
[SOLVED] Inspect Into TStringlist
« on: March 07, 2022, 11:44:51 am »
Hello,

I don't understand how see elements in a TstringList with debugger: if I add a watch i don't see element and if I try to use a Debug Inspector i don't see anything value... What's the correct way?
I'm using Lazarus 2.2RC2 32 bit with a FPC 3.2.3 on Windows 10 with Dwarf2 into Debug options,
thanks in advance.
« Last Edit: March 07, 2022, 03:57:24 pm by superc »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5486
  • Compiler Developer
Re: Inspect Into TStringlist
« Reply #1 on: March 07, 2022, 01:49:14 pm »
I don't understand how see elements in a TstringList with debugger: if I add a watch i don't see element and if I try to use a Debug Inspector i don't see anything value... What's the correct way?

There currently is no way for this, because both evaluating properties and executing functions from within the debugger is needed for this functionality and that simply does not yet exist.

superc

  • Full Member
  • ***
  • Posts: 242
Re: Inspect Into TStringlist
« Reply #2 on: March 07, 2022, 02:13:14 pm »
It would be one of the very important features to implement

Zvoni

  • Hero Member
  • *****
  • Posts: 2330
Re: Inspect Into TStringlist
« Reply #3 on: March 07, 2022, 02:31:08 pm »
What's the correct way?
A lot of writeln's or a TMemo-Control
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

korba812

  • Sr. Member
  • ****
  • Posts: 396
Re: Inspect Into TStringlist
« Reply #4 on: March 07, 2022, 02:34:18 pm »
You can preview contents of TStringList using "Evaluate / Modify" dialog. However, you have to build rtl with debug info.

superc

  • Full Member
  • ***
  • Posts: 242
Re: Inspect Into TStringlist
« Reply #5 on: March 07, 2022, 03:57:06 pm »
You can preview contents of TStringList using "Evaluate / Modify" dialog. However, you have to build rtl with debug info.

Ok that's what i need, thank you.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9913
  • Debugger - SynEdit - and more
    • wiki
Re: Inspect Into TStringlist
« Reply #6 on: March 07, 2022, 04:17:45 pm »
It would be one of the very important features to implement

Indeed. And it is in progress. Joost is working on it. However, it actually requires changes to the compiler itself. So the earliest this might become available would be when FPC 3.4.0 will be out (the next FPC, afaik will be 3.2.4).

Some background info:
Currently the compiler does not tell the debugger how to look into a TStringList. And the debugger (any debugger) is limited to whatever info it gets from the compiler. It's called debug-info (..g., "DWARF"). Once available, it will tell the debugger, where the compiler put the data of the string-list.

Until such time, you can use one of the following watches (the 2nd, if you have "L: TStrings" and need to typecast it):
- assuming "var L: TStringList;"
- you use FpDebug / LazDebuggerFp
- Your RTL is build with debug-info / and RTL debug-info is set to "DWARF" (any of the dwarf settings / for FpDebug your can go with DWARF-3)
Code: Text  [Select][+][-]
  1. (L.FList)^[0]
Code: Text  [Select][+][-]
  1. (TStringList(L).FList)^[0]

You can use the "Debug-inspector" (menu: Run > Inspect).
There you can inspect the variable "L", and double-click the "FList" field, then again double click the entry "L.FList" to deref the pointer.
After that you need to edit the expression yourself, and add the "[0]" (or whatever index you want).
Once you got the entry, you can press the "Add watch" button. (you can then edit the index, and add more watches)

Or you can add the following watch (may depend on your fpc version)
Code: Text  [Select][+][-]
  1. (TStringList(L).FList)^
And set a "repeat count" in the watch properties. (Without repeat count you may get a hell of a lot of entries / more than the list actually has).



If your RTL does not have debug info you can try
Code: Text  [Select][+][-]
  1. ^AnsiString(L.FList)[i*2]
where i is the index.

So if you want the string at index 5 then your watch must be "^AnsiString(L.FList)[10]".
The odd indexes are the objects stored in the TStringList. However the above type-casts anything to an AnsiString - not really meaningful for a TObject....


And: No, there is on way to get the full "StringList.Text".
Not until the new feature is ready.




About: "you use FpDebug / LazDebuggerFp"
- If you use the old "gdb based" debugger, this workaround may crash the debugger.
- The last example with the "AnsiString" type-cast may work with the "gdb based" debugger. Though intstead of "AnsiString" you may need to give "PChar" or "^Char" (note, the latter ends up as "^^Char(..)[..]")
- LazDebuggerFp is the default in Lazarus version 2.2. But if you upgraded from an older version (even if you uninstalled, since your old config is kept even then) then the setting for "gdb based" will still be active. See menu: Tools > Options > Debugger > Backend
- LazDebuggerFp is also available in Lazarus version 2.0.x. But you may need to install the package "LazDebuggerFp" first.

About "RTL is build with debug-info "
=> Actually, that is probably not required. => The compiler will generate the missing debug info for any class that you use. According to my tests, at least on Windows this works.


About: "menu: Run > Inspect"
=> Maybe in future that will move to "menu: View > Debug windows > Inspector" ... Maybe...


« Last Edit: March 07, 2022, 04:25:24 pm by Martin_fr »

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: [SOLVED] Inspect Into TStringlist
« Reply #7 on: March 07, 2022, 07:44:21 pm »
The simplest way is put it in an Application.MessageBox. I tend to make a variant that accepts a single string as argument: function Msg(ThisMessage: string; ThisTitle: string = '');

I make a method for most classes that return a TStringArray especially for this purpose.

superc

  • Full Member
  • ***
  • Posts: 242
Re: Inspect Into TStringlist
« Reply #8 on: March 08, 2022, 08:20:28 am »
It would be one of the very important features to implement

Indeed. And it is in progress. Joost is working on it. However, it actually requires changes to the compiler itself. So the earliest this might become available would be when FPC 3.4.0 will be out (the next FPC, afaik will be 3.2.4).


Thanks for the reply, I have used a lot of Delphi and at present I consider Lazarus / FPC a valid alternative;
actually the Delphi debugger works very well, it would be a dream to have it similar in Lazarus  :D


 

TinyPortal © 2005-2018