Recent

Author Topic: Lazarus debug: Show source line  (Read 4415 times)

OH1KH

  • Jr. Member
  • **
  • Posts: 63
Lazarus debug: Show source line
« on: January 22, 2019, 11:22:04 am »
Hi!
I'm sure this question is answered, but I could not find it with searh (wrong words, maybe)

How can I trace the last source line (in my own source) that was executed before execution stops to error (External: SIGSEGV)

When I press OK at that splash I get assembler window open.
I do not want that. I am a "sunday programmer" and cant see anyting from asm. (unless it is Z80 cpu code from -80's :-) )

If I set break point near the point i have pinpointed error to happen (by adding extra writelns) and then go forward with stepping it takes ages to reach the error point due to stepping walks inside lazarus units source.

I also do not want to see pascal code from lazarus units (that I see lot with steppping).
I just want to see the last succeeded line of my own code.

Maybe later I'm interested in what happens inside of lazarus units, or even at asm level.

Usually finding own error is easiest when you see just your own code.


Lazarus 1.8.4/ Fedora 28 linux
--
Saku

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Lazarus debug: Show source line
« Reply #1 on: January 22, 2019, 12:36:29 pm »
View -> Debug windows -> Call Stack
The Call Stack window lists the names and line numbers of the most recent end of the call "chain" that brought you to the point of the crash.
If there is no debug or line number info for called code, you won't get line numbers, of course. Much of the FPC code does not ship with debug info, so unless you recompile those parts to include debug info you will not be able to use to the debugger to trace meaningfully into such FPC code.
However, usually SIGSEGV faults are down to errors in your code, not to bugs in RTL or LCL libraries.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus debug: Show source line
« Reply #2 on: January 22, 2019, 01:44:39 pm »
See Howardpc's answer.
In addition also open the "thread" window, you may have to set another thread to "current".

However this only works, if the info is available.
SigSegV are errors that often indicate that your app vandalized some of its memory. If you are unlucky then it just trashed the memory that holds the info where the error has happened.


In addition compile with   -Criot -gt
and heaptrc  -gh

you may also (together with heaptrc) want to set the environment HEAPTRC="keepreleased" 

If you are on linux then as a last resort (but usually really good at tracking such issues), try valgrind --tool=memcheck

OH1KH

  • Jr. Member
  • **
  • Posts: 63
Re: Lazarus debug: Show source line
« Reply #3 on: January 24, 2019, 11:55:38 am »
OK.
Thanks for all info. I'll look what they give.

But as said:
>"However, usually SIGSEGV faults are down to errors in your code, not to bugs in RTL or LCL libraries."

And I really just wanted to know:
 >"I just want to see the last succeeded line of my own code."

As knowing that, I can rethink what I was doing.
And it was the original question, Not what SIGSEGV means.

Now this leaves me to situation where I need to add  writeln('now in line #xxx'); after each line of my code to see where it stopped. Stupid, but seems to be the only way. Unless those suggestions I got as answer do not show me the last successful point of my code.
I have to test those now.
--
Saku

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: Lazarus debug: Show source line
« Reply #4 on: January 24, 2019, 02:49:20 pm »
Now this leaves me to situation where I need to add  writeln('now in line #xxx'); after each line of my code to see where it stopped.
What I am going to suggest doesn't always work but, it often does.   Simply run your program directly from the OS (instead of from Lazarus.)  The RTL will likely catch the SIGSEV and output a stack trace including line numbers.  When it works, it's a very quick and simple way of finding out which line of code is causing the problem.  No writeln(s) needed.

HTH.

ETA: I should have mentioned that the above suggestion usually works well with console apps, I don't know if it will work with GUI apps.

« Last Edit: January 24, 2019, 02:52:45 pm by 440bx »
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018