Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2025-12

interfaces and fpdebug

6 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luca Olivetti

Hello,

I seldom use interfaces myself, though some components I need use them extensively, and I find them difficult to debug.
I thought it was because gdb doesn't understand them, but I switched to fpdebug a long time ago and it still find them problematic:

if I hover on an interface variable, the hint shows only the address. The same happens if I put the variable in a watch or in evaluate/modify. If I try "intfvariable as TRealClass" (in case I know the real class) I get an error

Unexpected at xx: "as"

If I try TRealClass(intfvariable) I see bogus data.

Is this a known limitation or it's me doing it wrong?

Bye

Luca Olivetti Tel. +34 935883004 Ext. 3010 https://wetron.es https://wecobots.com

Reply by email

Michael Van Canneyt
to Luca Olivetti
Luca Olivetti wrote 15 lines
Hello, I seldom use interfaces myself, though some components I need use them extensively, and I find them difficult to debug. I thought it was because gdb doesn't understand them, but I switched to fpdebug a long time ago and it still find them problematic: if I hover on an interface variable, the hint shows only the address. The same happens if I put the variable in a watch or in evaluate/modify. If I try "intfvariable as TRealClass" (in case I know the real class) I get an error Unexpected at xx: "as" If I try TRealClass(intfvariable) I see bogus data.

That is correct, since this is not a valid typecast.

I think neither gdb nor fpdebug can retrieve the original object.

But it is known that interfaces are a problem to debug, also in Delphi.

Michael.

Reply by email

Martin Frb
to Luca Olivetti: I seldom use interfaces myself, though some components I need use them extensively, and I…
Luca Olivetti wrote 11 lines
Hello, I seldom use interfaces myself, though some components I need use them extensively, and I find them difficult to debug. I thought it was because gdb doesn't understand them, but I switched to fpdebug a long time ago and it still find them problematic: if I hover on an interface variable, the hint shows only the address. The same happens if I put the variable in a watch or in evaluate/modify. If I try "intfvariable as TRealClass" (in case I know the real class) I get an error

https://wiki.freepascal.org/FpDebug-Watches-Intrinsic-Functions#I2O(interface)_{show_object_behind_an_interface} At least Lazarus 4.99 / not sure if the 4-fixes branch has it...

? :i2o(the_intf)

There is no debug info from the compiler.
FpDebug actually disassembles the code from the first function in the interface, retrieves the address of the object, and (IIRC) gets the class for that from RTTI.

I might add an optional automatic mode for this... But not currently high on my todo.

Reply by email

Michael Van Canneyt
to Martin Frb: https://wiki.freepascal.org/FpDebug-Watches-Intrinsic-Functions#I2O(interface)_{show_objec…
Martin Frb wrote 17 lines
On 18/12/2025 16:19, Luca Olivetti via lazarus wrote: > Hello, > > I seldom use interfaces myself, though some components I need use them > extensively, and I find them difficult to debug. > I thought it was because gdb doesn't understand them, but I switched > to fpdebug a long time ago and it still find them problematic: > > if I hover on an interface variable, the hint shows only the address. > The same happens if I put the variable in a watch or in evaluate/modify. > If I try "intfvariable as TRealClass" (in case I know the real class) > I get an error https://wiki.freepascal.org/FpDebug-Watches-Intrinsic-Functions#I2O(interface)_{show_object_behind_an_interface} At least Lazarus 4.99 / not sure if the 4-fixes branch has it... ? :i2o(the_intf)

Nice one, I learn every day!

Michael.

Reply by email

Sven Barth
to Luca Olivetti: I seldom use interfaces myself, though some components I need use them extensively, and I…
Luca Olivetti wrote 17 lines
Hello, I seldom use interfaces myself, though some components I need use them extensively, and I find them difficult to debug. I thought it was because gdb doesn't understand them, but I switched to fpdebug a long time ago and it still find them problematic: if I hover on an interface variable, the hint shows only the address. The same happens if I put the variable in a watch or in evaluate/modify. If I try "intfvariable as TRealClass" (in case I know the real class) I get an error Unexpected at xx: "as" If I try TRealClass(intfvariable) I see bogus data. Is this a known limitation or it's me doing it wrong?

The problem is that there is no formal way to get an object instance from any interface, because the compiler can not know what the interface might point to and even then it might not be an Object Pascal class instance, but instead e.g. a C++ instance or some static implementation like is used in rtl-generics or even multiple object instances if "implements" is involved.

Even "as" only works, because it internally uses
IInterface.QueryInterface with a special GUID that's handled by TInterfacedObject.QueryInterface thus it does not work with raw interfaces or types that provide their own QueryInterface implementation.

Regards,
Sven

Reply by email