Forum > Debugger

How: to see last line number of own code before error?

(1/1)

OH1KH:
Not being a nerd, just old man who started using Pascal in 1982 I have always had problem with debugger.

How can I see the last line number executed of own program code before error when debugging?

When debugger is active and error happens it always stops showing to some lazarus/fpc unit line where the error happens.
Ok, it really happens there, but reason for it is error in my code. Not in fpc unit.

When program is very large (132 *.pas files) it is very annoying to start writing "writeln('now at point #1')" lines inside the program to pinpoint the area where error starts in own code.
Jumping with F8 is not good idea as program has several threads and reads UDP and TCP datas from external sources.

Can someone advice me how to see the last line of own code executed before error starts? (from where the jump to fpc unit caused error)

FPC 3.2.2
Laz 2.26
Fedora 38

cdbc:
Hi
How about 'Menu' -> 'View' -> 'Debug windows' -> 'Call Stack'.
It may not be a line of code, but the history of function-calls leading up to the error.
I dunno if it's what you're after?
Regards Benny

Martin_fr:
That last line of code should be on the callstack.

Actually what will be there is the line into which it would have returned, if there had not been an error. That may either be the line that made the call, or it will be the next line. (Depending on any code still un-executed in the calling line / like a "result :=")

With older versions the line was sometimes missing, if the LCL/RTL was compiled with certain optimization (*). This may occasionally still happen with 3.2, but should be fine trunk.

(*)

Missing here means that the line you called is there. And the line that called your code is there. But not your code.

There is another missing, in that the stack doesn't show enough lines. Even if you click the button to show more. => That can happen if the error is a corrupt stack. The the error destroyed the info on that last calling line...

wp:

--- Quote from: cdbc on May 01, 2024, 09:22:53 am --- 'Menu' -> 'View' -> 'Debug windows' -> 'Call Stack'.

--- End quote ---
When you see this for the first time, it may be a bit hard to understand... The call stack must be read from the top downwards. The uppermost line is the line which finally coded the exception, usually in a system unit. The next line is the line which called the first one, and so on. So, going down the stack you will eventually find the lines in your program. The first one of these usually is the one with the error, or at least very close it it. Simply click on the lines to see them in context in the editor. Sometimes, when erroenous application line is called from several procedures it may be advantageous to look also at the following line(s). Note that debugger information must be available to see line numbers and line information.

cdbc:
Hi
@wp: Thanks mate, I didn't think that far....  :) Martin too, thanks.
Regards Benny

Navigation

[0] Message Index

Go to full version