Recent

Author Topic: how to debug RTL routines in lazarus?  (Read 733 times)

alexraynepe196

  • New Member
  • *
  • Posts: 26
how to debug RTL routines in lazarus?
« on: November 11, 2022, 03:27:04 pm »
Hallow.
have instaled lazarus 2.2.5 on win10.
my lazarus application crashes invoking setlength( soe_dinamic_array, len ) - rises exception access violation on $ffffffffffffffffffff adreess.
debuger cant traverse into it -  looks  have no debug info.

how to prepare RTL for debug in lazarus?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9904
  • Debugger - SynEdit - and more
    • wiki
Re: how to debug RTL routines in lazarus?
« Reply #1 on: November 11, 2022, 03:39:36 pm »
To debug the RTL, you will need to build FPC from sources.  But I don't think you need to debug the RTL.

Does the stack window (menu View > Debug Windows > Stack)  show the calling code?

If yes, select the calling code as "current" and check the value of the string/array passed to setlength. More important, check the "hidden pointer" of the string/array => add a watch "Pointer(my_array_var)"

Very likely this variable contains trash.



If you do not see entries in the stack window, go to Tools > Options > Debugger Backend
and change between FpDebug and GDB, and then try again.

(When done, change to FpDebug, which should be used by default)

alexraynepe196

  • New Member
  • *
  • Posts: 26
Re: how to debug RTL routines in lazarus?
« Reply #2 on: November 11, 2022, 03:45:53 pm »
> Does the stack window (menu View > Debug Windows > Stack)  show the calling code?
i see calling code - and it is assembler. and no any sources attached on it

I wanna debug an RTL sources on my problem dynamic array

alexraynepe196

  • New Member
  • *
  • Posts: 26
Re: how to debug RTL routines in lazarus?
« Reply #3 on: November 11, 2022, 03:47:53 pm »
Quote
If yes, select the calling code as "current" and check the value of the string/array passed to setlength. More important, check the "hidden pointer" of the string/array => add a watch "Pointer(my_array_var)"

Very likely this variable contains trash.
i have Nil pointer, and setlength(var, 168) with it rises exception

alexraynepe196

  • New Member
  • *
  • Posts: 26
Re: how to debug RTL routines in lazarus?
« Reply #4 on: November 11, 2022, 03:56:44 pm »
i overwrited memory by some prevous dinamic-array operation. and looks that corrupted heap-memory allocator structures

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9904
  • Debugger - SynEdit - and more
    • wiki
Re: how to debug RTL routines in lazarus?
« Reply #5 on: November 11, 2022, 08:51:14 pm »
i overwrited memory by some prevous dinamic-array operation. and looks that corrupted heap-memory allocator structures
If by any chance you can test your code an Linux (e.g. Virtualbox), then there is a tool called valgrind / memcheck. It is excellent for finding incorrect memory accesses.

But to start with, make sure you test with all of the FPC options
- range checks, and all -Criot
- heaptrc  -gh
  and set the environment HEAPTRC=keepreleased
  (though the latter will increase the mem usage of your app, if it runs for longer)


I wanna debug an RTL sources on my problem dynamic array
Then you must build FPC yourself.

The easiest is likely to use fpcupdeluxe (though I have no experience of my own with this).
The wiki should have content explaining how to build fpc (and there may be older posts on the forum).

Before you do, you may want to check that the LCL and other Lazarus packages are all build with debug info.
- Most of them will include the options from "tools > configure build lazarus"
- But the best way is probably to add debug info via "Additions and Overrides" in the "project settings" (there is a very good page an this on the wiki)


PascalDragon

  • Hero Member
  • *****
  • Posts: 5486
  • Compiler Developer
Re: how to debug RTL routines in lazarus?
« Reply #6 on: November 13, 2022, 02:50:28 pm »
my lazarus application crashes invoking setlength( soe_dinamic_array, len ) - rises exception access violation on $ffffffffffffffffffff adreess.

The issue will almost assuredly not be inside the corresponding RTL helper routine, instead the issue is your own code. Is soe_dinamic_array by any chance part of a class or record? Did you ensure that the class or record has been allocated correctly? Are you sure that soe_dinamic_array is Nil and not some garbage value?

 

TinyPortal © 2005-2018