Jump to content
terran

Local variables broken when debugging .obj files?

Recommended Posts

I am debugging a Delphi application, which uses C Object files (.obj).

When enters a function, it shows correct Local variables, but when a step-in, it doesn't show correct Local variables.

Is it a bug?

 

Before entering function:

varsbeforeenterfunction.thumb.png.6f6557b80caaf1b6e58c8cf44b803eb1.png

 

After entering function:

varsafterenterfunction.thumb.png.543c71e5e0b1b19ddec90b6a380920a4.png

 

Previous function in stack:

varsinpreviousfunctioninstack.thumb.png.416aad1aeb8abdabe65e939b016d057c.png

 

Actually, ReadProc is assigned to SeekProc, WriteProc to CloseProc, and SeekProc to SizeProc.

 

Function in delphi:

type

  PTIFF = Pointer;
  TIFFReadWriteProc = function(Fd: THandle; Buffer: Pointer; Size: tmsize_t): Integer; cdecl;
  TIFFCloseProc = function(Fd: THandle): Integer; cdecl;
  TIFFSeekProc = function(Fd: THandle; Off: toff_t; Whence: Integer): toff_t; cdecl;
  TIFFSizeProc = function(Fd: THandle): toff_t; cdecl;
  TIFFMapFileProc = function(Fd: THandle; PBase: PPointer; PSize: poff_t): Integer; cdecl;
  TIFFUnmapFileProc = procedure(Fd: THandle; Base: Pointer; Size: toff_t); cdecl;


function _TIFFClientOpenExt(name: PAnsiChar;  mode: PAnsiChar;
                        clientdata: THandle; readproc: TIFFReadWriteProc;
                        writeproc: TIFFReadWriteProc; seekproc: TIFFSeekProc;
                        closeproc: TIFFCloseProc; sizeproc: TIFFSizeProc;
                        mapproc: TIFFMapFileProc; unmapproc:TIFFUnmapFileProc;
                        opts: Pointer): PTIFF; cdecl; external;

 

 

Function in C :

    typedef tmsize_t (*TIFFReadWriteProc)(thandle_t, void *, tmsize_t);
    typedef toff_t (*TIFFSeekProc)(thandle_t, toff_t, int);
    typedef int (*TIFFCloseProc)(thandle_t);
    typedef toff_t (*TIFFSizeProc)(thandle_t);
    typedef int (*TIFFMapFileProc)(thandle_t, void **base, toff_t *size);
    typedef void (*TIFFUnmapFileProc)(thandle_t, void *base, toff_t size);
////////////


TIFF *TIFFClientOpen(const char *name, const char *mode, thandle_t clientdata,
                     TIFFReadWriteProc readproc, TIFFReadWriteProc writeproc,
                     TIFFSeekProc seekproc, TIFFCloseProc closeproc,
                     TIFFSizeProc sizeproc, TIFFMapFileProc mapproc,
                     TIFFUnmapFileProc unmapproc)
{
    return TIFFClientOpenExt(name, mode, clientdata, readproc, writeproc,
                             seekproc, closeproc, sizeproc, mapproc, unmapproc,
                             NULL);
}

TIFF *TIFFClientOpenExt(const char *name, const char *mode,
                        thandle_t clientdata, TIFFReadWriteProc readproc,
                        TIFFReadWriteProc writeproc, TIFFSeekProc seekproc,
                        TIFFCloseProc closeproc, TIFFSizeProc sizeproc,
                        TIFFMapFileProc mapproc, TIFFUnmapFileProc unmapproc,
                        TIFFOpenOptions *opts)

 

Edited by terran

Share this post


Link to post

Is the function working well? I'd bet on incorrect parameters porting. 1st guess is differing calling convention but it seems valid

Share this post


Link to post
10 hours ago, terran said:

When enters a function, it shows correct Local variables, but when a step-in, it doesn't show correct Local variables.

Is it a bug?

The obj files do not contain debug information so the IDE debugger is unable to work fully while the execution is inside code from the obj file.

Share this post


Link to post

I didn't even know that Delphi debugger would step into obj files. How did you compile the .obj file? Where is Delphi getting the debug info from?

Share this post


Link to post

I compiled it with bcc32c -tM -tR -Od -v (CMake did it for me).

The object files compiled with the -v switch are twice as big, and of course contain some "debugging information". But it's not exact. 😄

 

No, the code doesn't work.

It is an old LibTiff library. It worked with a (20 years) old .OBJ files with no sources (and no debugging).

I compiled the new object files from .C sources, and with them it doesn't work.

The delphi unit to that library is not so much outdated. But it's not exact. 😄

Share this post


Link to post

What if you try to print arguments from that C function and test at runtime? I too didn't know that Delphi is able to step into OBJ. Probably this feature is buggy

Edited by Fr0sT.Brutal

Share this post


Link to post

If I were you I'd compile the code into a DLL and link to that. My experience is that works more reliably. I used to do the .obj dance back in the day but moved away from it. Very happy to have done so.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×