Recent

Author Topic: FPDebug: value of a Variant  (Read 1545 times)

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
FPDebug: value of a Variant
« on: November 30, 2022, 11:11:04 am »
How can I see the value of a Variant?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: FPDebug: value of a Variant
« Reply #1 on: November 30, 2022, 11:51:54 am »
Use Lazarus 2.3.

It is not implemented in 2.2.x

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: FPDebug: value of a Variant
« Reply #2 on: November 30, 2022, 02:51:30 pm »
1. How can I see the value of a Variant in Lazarus 2.3?

If I can see what's inside at all, it's a long list, among which are the type and a pointer to the value. But I cannot cast that pointer to, for example, a string, if that is the type. So all it tells me, is: it is some value of this type.

2. Sometimes it just shows: "()". That's it.


When I posted the previous post, it did show what's inside. At the moment, it only shows "()". Restarting Lazarus doesn't fix it.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: FPDebug: value of a Variant
« Reply #3 on: November 30, 2022, 05:02:27 pm »
Ok, I missed out a point....

Tested with:
- FPC 3.2.3 (but I believe 3.2.2 should work too)
- Lazarus 2.3

So, by default you will see something like: vtype 123; vstring $0001234546
For int and bool, you get vshortint and vboolean.

That is what actually is in the variant. the declaration contains "vstring : pointer". So FPC tells the debugger this is an address, and nothing else.


But...

You can get better results. For that however you need to tell (and allow) the debugger to execute "SysVarToLStr" in you paused app  (the debugger will call that function, this will run. It can (but in this case should not) have sideeffects)

https://wiki.freepascal.org/IDE_Window:_Ide_Options_-_Backend_Value_Converter#CallSysVarToLStr

- Create a new entry (any name)
- set checkbox
- select SysVarToLStr
- enter "variant" (without quotes) in "Match type name"


See image, what I get to see for variants.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: FPDebug: value of a Variant
« Reply #4 on: November 30, 2022, 05:08:16 pm »
And I can typecast
Code: Pascal  [Select][+][-]
  1. ansistring(a.vstring)
  2. ^char(a.vstring)

But only if the types (char or ansistring) are used in the app. You need a variable of that type, and it needs to be used (so it's not left out by fpc/linker)
« Last Edit: November 30, 2022, 05:10:55 pm by Martin_fr »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: FPDebug: value of a Variant
« Reply #5 on: November 30, 2022, 05:14:22 pm »
Casting to "pchar" gives the full string... I have to dig down why ^char does not.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: FPDebug: value of a Variant
« Reply #6 on: December 05, 2022, 02:22:32 pm »
Thanks! Casting vstring to a PChar in the inspector works.

I tried adding the value converter, but that doesn't seems to work, so I probably did it wrong (see attachments).

Btw, removing an option gave an error that the list was out of bounds.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: FPDebug: value of a Variant
« Reply #7 on: December 05, 2022, 03:07:53 pm »
The setup looks correct.
It's not the latest version of Lazarus, but it should still work.

Which version of dwarf to you use?
And which version of FPC?
OS and bitness?

Also can you just test, if you enter the variant directly? like "myvar.fitems[11].myvalue" ?
(it should work in the structure too, but just narrowing things down)

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: FPDebug: value of a Variant
« Reply #8 on: December 07, 2022, 10:52:53 am »
I use Dwarf with sets. I tend to select Dwarf 3 for new projects. Dwarf 3 gives an error: The function stopped unexpectedly.

Lazarus is version 2.3.0, FPC is 3.3.1. Windows 10, 64-bit.

« Last Edit: December 07, 2022, 10:57:24 am by SymbolicFrank »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: FPDebug: value of a Variant
« Reply #9 on: December 07, 2022, 02:50:11 pm »
I use Dwarf with sets. I tend to select Dwarf 3 for new projects. Dwarf 3 gives an error: The function stopped unexpectedly.

This is odd. The Dwarf version shouldn't affect that.

I am myself on Win10 64bit. And I just tested (with 3.3.1 updated yesterday) with both (Dwarf3 and 2+sets) and it worked.

Btw, with which options was your FPC build?
- optimization level?
- debug info?


Btw, did you update your Lazarus since your post on December 05, 2022, 02:22:32 pm?
Because in that image, the option dialog is missing the "Run all threads while evaluating" checkbox. Which if you have it defaults to off, and should be off. But if you don't, it will be on.
And it's not just the running off threads. The entire function eval had lots of work done. So you do want to test with the latest 2.3 Lazarus.

If you have that checkbox, and the "function stopped unexpectedly"  error still happen:
Please run Lazarus with the following option, and when the error arises provide the log file. (Clear the logfile between runs of Lazarus, or it grows very large)
Code: Text  [Select][+][-]
  1. --debug-log=somelogfile.txt  --debug-enable=DBGMI_QUEUE_DEBUG,DBG_VERBOSE,DBG_WARNINGS,DBG_ERRORS,DBG_VERBOSE_BRKPOINT,DBG_STATE,DBG_EVENTS,DBG_BREAKPOINTS,DBG_FPDEBUG_VERBOSE,FPDBG_BREAKPOINT_ERRORS,FPDBG_BREAKPOINTS,FPDBG_COMMANDS,FPDBG_THREADS,FPDBG_QUEUE,FPDBG_FUNCCALL,FPDBG_WINDOWS


SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: FPDebug: value of a Variant
« Reply #10 on: December 07, 2022, 04:01:36 pm »
Ok, thanks.

On my develop laptop, I use the fpc + Lazarus fork I made for the merge requests. You had explained how I could sync all repos and update them to the latest versions. I'll do that and make a new build + install. That might take a while.

I'll post an update when that is done.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: FPDebug: value of a Variant
« Reply #11 on: March 12, 2023, 10:58:33 pm »
With the very latest main branch you can also try https://wiki.freepascal.org/IDE_Window:_Ide_Options_-_Backend_Value_Converter#.22Convert_variant_to_value_type.22

This does not relay on calling a function in your debugged app.
But it may still need some testing for coverage of values. Also the display format may be different for some values.

 

TinyPortal © 2005-2018