Discussion:
[fpc-pascal] Logging full runtime-error/exception backtrace
leledumbo
2012-02-20 14:58:11 UTC
Permalink
I want to log the full runtime-error/exception backtrace to a file. I've
tried all methods explained
http://wiki.lazarus.freepascal.org/Logging_exceptions here but none seems
to give the full backtrace. i.e. when compiled with -gl, instead of just the
address, I could also get "line NN of file XX.pas". How could I do it?

--
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Logging-full-runtime-error-exception-backtrace-tp5499290p5499290.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
Everton Vieira
2012-02-20 15:08:30 UTC
Permalink
I use this units to do that. Was someone with the nickname crhonos who made.
Post by leledumbo
I want to log the full runtime-error/exception backtrace to a file. I've
tried all methods explained
http://wiki.lazarus.freepascal.org/Logging_exceptions here but none seems
to give the full backtrace. i.e. when compiled with -gl, instead of just the
address, I could also get "line NN of file XX.pas". How could I do it?
--
http://free-pascal-general.1045716.n5.nabble.com/Logging-full-runtime-error-exception-backtrace-tp5499290p5499290.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
_______________________________________________
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
--
Everton Vieira.
Sven Barth
2012-02-20 15:36:43 UTC
Permalink
Post by Everton Vieira
I use this units to do that. Was someone with the nickname crhonos who made.
These units will only work if the debug format is Stabs and not DWARF.

Regards,
Sven
leledumbo
2012-02-20 22:33:22 UTC
Permalink
Post by Everton Vieira
I use this units to do that. Was someone with the nickname crhonos who made.
Thanks, I'll try it :)

--
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Logging-full-runtime-error-exception-backtrace-tp5499290p5500483.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
Sven Barth
2012-02-20 15:15:14 UTC
Permalink
Post by leledumbo
I want to log the full runtime-error/exception backtrace to a file. I've
tried all methods explained
http://wiki.lazarus.freepascal.org/Logging_exceptions here but none seems
to give the full backtrace. i.e. when compiled with -gl, instead of just the
address, I could also get "line NN of file XX.pas". How could I do it?
The resolution of file and address can only be done if your code is a)
compiled with debug info and b) some code is available that can
translate the debug info to the output. The first is done by "-g", while
the second is done by adding the "l" option. The latter adds the unit
lineinfo or lnfodwrf depending on the debug format used by the compiler.

So in summary: if you want to have full output of the backtrace, then it
is wisest to use "-gl" and then one of the approaches mentioned on the
wiki page (e.g. DumpExceptionBackTrace(SomeFile) ).

If you don't want to include the debug information with your application
(e.g. space reasons) then compile your application using "-Xg" which
will create a file "appname.dbg" which will contain the debug info (you
don't need to redistribute this file). On an exception you simply log
the addresses and then you can convert these addresses to line/file by
using gdb and the created ".dbg" file (more details on this if you want
to follow that approach).

Regards,
Sven
leledumbo
2012-02-20 22:37:11 UTC
Permalink
Post by Sven Barth
The resolution of file and address can only be done if your code is a)
compiled with debug info and b) some code is available that can
translate the debug info to the output. The first is done by "-g", while
the second is done by adding the "l" option. The latter adds the unit
lineinfo or lnfodwrf depending on the debug format used by the compiler.

I'm aware of a) and my thought for b) is that BackTraceStrFunc would do it.
But I got the same thing happened with Everton, the function doesn't
translate debug info so all I get is simply addresses, without line
information.

--
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Logging-full-runtime-error-exception-backtrace-tp5499290p5500488.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
Sven Barth
2012-02-21 09:18:21 UTC
Permalink
Post by Sven Barth
Post by Sven Barth
The resolution of file and address can only be done if your code is a)
compiled with debug info and b) some code is available that can
translate the debug info to the output. The first is done by "-g", while
the second is done by adding the "l" option. The latter adds the unit
lineinfo or lnfodwrf depending on the debug format used by the compiler.
I'm aware of a) and my thought for b) is that BackTraceStrFunc would do it.
But I got the same thing happened with Everton, the function doesn't
translate debug info so all I get is simply addresses, without line
information.
The BackTraceStrFunc by default points to SysBackTraceStr which just
converts addresses to strings. If you use "-gl" then one of the two
lineinfo units is included depending on the chosen format of the debug
info. This units in turn set BackTraceStrFunc to their own function, so
that line and file info is now part of the returned string. So the savest
way to ensure that BackTraceStrFunc returns more than just the address us
to use "-gl".

Regards,
Sven
leledumbo
2012-02-21 16:14:39 UTC
Permalink
So the savest way to ensure that BackTraceStrFunc returns more than just
the address us to use "-gl"

I think I'm not clear enough to say that I have used -gl for this, and I
don't get the line information. I've tried this on 2 places: ExceptProc and
TApplication.OnException.

--
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Logging-full-runtime-error-exception-backtrace-tp5499290p5502650.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
Martin
2012-02-21 16:20:41 UTC
Permalink
Post by leledumbo
So the savest way to ensure that BackTraceStrFunc returns more than just
the address us to use "-gl"
I think I'm not clear enough to say that I have used -gl for this, and I
don't get the line information. I've tried this on 2 places: ExceptProc and
TApplication.OnException.
It should be noted, that afaik if the BackTraceStrFunc encounters an
error, it is reset to the system one (without line info). So once
backtrace failed (maybe problems reading a particular part of the debug
info, it switches itself off... (for all further calls)

If you don't get results: then you should mention if that was using
stabs, or dwarf. And 32bit 64 bit.

Also start testing outside an exception, to see if that works.
Everton Vieira
2012-02-21 20:28:05 UTC
Permalink
Post by leledumbo
So the savest way to ensure that BackTraceStrFunc returns more than just
the address us to use "-gl"
I think I'm not clear enough to say that I have used -gl for this, and I
don't get the line information. I've tried this on 2 places: ExceptProc and
TApplication.OnException.
It should be noted, that afaik if the BackTraceStrFunc encounters an error, it is reset to the system one (without line info). So once backtrace failed (maybe problems reading a particular part of the debug info, it switches itself off... (for all further calls)
If you don't get results: then you should mention if that was using stabs, or dwarf. And 32bit 64 bit.
Did you have looked at the example i send? It also is not working. I`m on 32b mac osx lion with svn version instaled. And with none of the available options have worked: automatic, stabs, dwarf, dwarf2, dwarf3 beta.
Also start testing outside an exception, to see if that works.
_______________________________________________
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Martin
2012-02-21 20:35:38 UTC
Permalink
Post by Everton Vieira
Post by leledumbo
So the savest way to ensure that BackTraceStrFunc returns more than just
the address us to use "-gl"
I think I'm not clear enough to say that I have used -gl for this, and I
don't get the line information. I've tried this on 2 places: ExceptProc and
TApplication.OnException.
It should be noted, that afaik if the BackTraceStrFunc encounters an error, it is reset to the system one (without line info). So once backtrace failed (maybe problems reading a particular part of the debug info, it switches itself off... (for all further calls)
If you don't get results: then you should mention if that was using stabs, or dwarf. And 32bit 64 bit.
Did you have looked at the example i send? It also is not working. I`m on 32b mac osx lion with svn version instaled. And with none of the available options have worked: automatic, stabs, dwarf, dwarf2, dwarf3 beta.
Well then maybe there is a bug on Mac.

It does work for me on windows (and IIRC I also had success on Linux)
both 32 bit.
Everton Vieira
2012-02-21 20:38:14 UTC
Permalink
Post by Martin
Post by Everton Vieira
Post by leledumbo
So the savest way to ensure that BackTraceStrFunc returns more than just
the address us to use "-gl"
I think I'm not clear enough to say that I have used -gl for this, and I
don't get the line information. I've tried this on 2 places: ExceptProc and
TApplication.OnException.
It should be noted, that afaik if the BackTraceStrFunc encounters an error, it is reset to the system one (without line info). So once backtrace failed (maybe problems reading a particular part of the debug info, it switches itself off... (for all further calls)
If you don't get results: then you should mention if that was using stabs, or dwarf. And 32bit 64 bit.
Did you have looked at the example i send? It also is not working. I`m on 32b mac osx lion with svn version instaled. And with none of the available options have worked: automatic, stabs, dwarf, dwarf2, dwarf3 beta.
Well then maybe there is a bug on Mac.
It does work for me on windows (and IIRC I also had success on Linux) both 32 bit.
I have a virtualized windows xp here. I`ll try there.
Post by Martin
_______________________________________________
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Everton Vieira
2012-02-21 20:47:18 UTC
Permalink
Post by Everton Vieira
Post by Martin
Post by Everton Vieira
Post by leledumbo
So the savest way to ensure that BackTraceStrFunc returns more than just
the address us to use "-gl"
I think I'm not clear enough to say that I have used -gl for this, and I
don't get the line information. I've tried this on 2 places: ExceptProc and
TApplication.OnException.
It should be noted, that afaik if the BackTraceStrFunc encounters an error, it is reset to the system one (without line info). So once backtrace failed (maybe problems reading a particular part of the debug info, it switches itself off... (for all further calls)
If you don't get results: then you should mention if that was using stabs, or dwarf. And 32bit 64 bit.
Did you have looked at the example i send? It also is not working. I`m on 32b mac osx lion with svn version instaled. And with none of the available options have worked: automatic, stabs, dwarf, dwarf2, dwarf3 beta.
Well then maybe there is a bug on Mac.
It does work for me on windows (and IIRC I also had success on Linux) both 32 bit.
I have a virtualized windows xp here. I`ll try there.
Also not worked, not with stabs or dwarf. Tomorrow i`ll test a host windows machine. But i can advance that some time ago i did this tests and didn`t worked until i`ve used that units that i send some mails ago.
Post by Everton Vieira
Post by Martin
_______________________________________________
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Everton Vieira
2012-02-21 12:07:50 UTC
Permalink
Done the test, attached project , with -gl and the BackTraceStrFunc, i got the example in the wiki, here doesn`t show the info only the address, i`m on a mac osx lion with the svn version installed.
Post by Sven Barth
Post by Sven Barth
The resolution of file and address can only be done if your code is a)
compiled with debug info and b) some code is available that can
translate the debug info to the output. The first is done by "-g", while
the second is done by adding the "l" option. The latter adds the unit
lineinfo or lnfodwrf depending on the debug format used by the compiler.
I'm aware of a) and my thought for b) is that BackTraceStrFunc would do it.
But I got the same thing happened with Everton, the function doesn't
translate debug info so all I get is simply addresses, without line
information.
The BackTraceStrFunc by default points to SysBackTraceStr which just converts addresses to strings. If you use "-gl" then one of the two lineinfo units is included depending on the chosen format of the debug info. This units in turn set BackTraceStrFunc to their own function, so that line and file info is now part of the returned string. So the savest way to ensure that BackTraceStrFunc returns more than just the address us to use "-gl".
Regards,
Sven
_______________________________________________
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Martin
2012-02-20 15:34:32 UTC
Permalink
Post by leledumbo
I want to log the full runtime-error/exception backtrace to a file. I've
tried all methods explained
http://wiki.lazarus.freepascal.org/Logging_exceptions here but none seems
to give the full backtrace. i.e. when compiled with -gl, instead of just the
address, I could also get "line NN of file XX.pas". How could I do it?
If you ship with debug info, then see gdbmidebugger.pp
function TGDBMIDebuggerCommand.Execute: Boolean;

Report := BackTraceStrFunc(ExceptAddr);
Report2 := Report;
Frames := ExceptFrames;
for I := 0 to ExceptFrameCount - 1 do begin
Report := Report + LineEnding + BackTraceStrFunc(Frames[I]);
if i < 5
then Report2 := Report;
end;

-------

If you do not want to ship with debug info:

- compile with debug info
- keep a copy of the file with debug info
- use strip[.exe] to remove the debug info from shipping version
- dump addresses

when you get the addresses, you can use gdb and the copy with debug info
that you kept (must match 100% the shipped version)

you will need a smass script calling gdb for each address


gdb.exe -i mi project1.exe --eval-command="info line *0x428f60"
--eval-command=q
Everton Vieira
2012-02-20 15:42:32 UTC
Permalink
I've tried sometimes to do directly with the -gl and the BackTraceStrFunc
and i never was able to get the info of the error, maybe my fault. With
this units that i've passed i was able to get the info of the error with
the line number and everything else within the app.
Post by Martin
Post by leledumbo
I want to log the full runtime-error/exception backtrace to a file. I've
tried all methods explained
http://wiki.lazarus.**freepascal.org/Logging_**exceptions<http://wiki.lazarus.freepascal.org/Logging_exceptions>here but none seems
to give the full backtrace. i.e. when compiled with -gl, instead of just the
address, I could also get "line NN of file XX.pas". How could I do it?
If you ship with debug info, then see gdbmidebugger.pp
function TGDBMIDebuggerCommand.Execute: Boolean;
Report := BackTraceStrFunc(ExceptAddr);
Report2 := Report;
Frames := ExceptFrames;
for I := 0 to ExceptFrameCount - 1 do begin
Report := Report + LineEnding + BackTraceStrFunc(Frames[I]);
if i < 5
then Report2 := Report;
end;
-------
- compile with debug info
- keep a copy of the file with debug info
- use strip[.exe] to remove the debug info from shipping version
- dump addresses
when you get the addresses, you can use gdb and the copy with debug info
that you kept (must match 100% the shipped version)
you will need a smass script calling gdb for each address
gdb.exe -i mi project1.exe --eval-command="info line *0x428f60"
--eval-command=q
______________________________**_________________
http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>
--
Everton Vieira.
Sven Barth
2012-02-20 15:41:53 UTC
Permalink
Post by Martin
- compile with debug info
- keep a copy of the file with debug info
- use strip[.exe] to remove the debug info from shipping version
- dump addresses
when you get the addresses, you can use gdb and the copy with debug info
that you kept (must match 100% the shipped version)
you will need a smass script calling gdb for each address
gdb.exe -i mi project1.exe --eval-command="info line *0x428f60"
--eval-command=q
Alternatively - as I already wrote:

- compile with "-Xg"
- keep the appname.dbg file
- dump addresses

command to use:

gdb.exe -i mi project1.exe --symbols=project1.dbg --eval-command="info
line *0x428f60" --eval-command=q

Regards,
Sven
Everton Vieira
2012-02-20 15:52:09 UTC
Permalink
Is supposed that with the -gl and the BackTraceStrFunc would get all the
info with the line number as well? Because if is true i've seen not work
and could test again.
Post by Sven Barth
Post by Martin
- compile with debug info
- keep a copy of the file with debug info
- use strip[.exe] to remove the debug info from shipping version
- dump addresses
when you get the addresses, you can use gdb and the copy with debug info
that you kept (must match 100% the shipped version)
you will need a smass script calling gdb for each address
gdb.exe -i mi project1.exe --eval-command="info line *0x428f60"
--eval-command=q
- compile with "-Xg"
- keep the appname.dbg file
- dump addresses
gdb.exe -i mi project1.exe --symbols=project1.dbg --eval-command="info
line *0x428f60" --eval-command=q
Regards,
Sven
______________________________**_________________
http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>
--
Everton Vieira.
Sven Barth
2012-02-20 15:59:33 UTC
Permalink
Post by Everton Vieira
Is supposed that with the -gl and the BackTraceStrFunc would get all the
info with the line number as well? Because if is true i've seen not work
and could test again.
This only works if you do not strip the debug info from the executable
(either by using the strip command - as Martin wrote - or by using -Xg -
as I wrote). Some people do not won't to include the debug information,
because they increase the file size of the executable quite a bit
(especially if you use the LCL).

Example of Lazarus.exe:

* executable size: ~14MB
* debug info size: ~145MB

Regards,
Sven
Everton Vieira
2012-02-20 16:07:23 UTC
Permalink
Post by Everton Vieira
Is supposed that with the -gl and the BackTraceStrFunc would get all the
Post by Everton Vieira
info with the line number as well? Because if is true i've seen not work
and could test again.
This only works if you do not strip the debug info from the executable
(either by using the strip command - as Martin wrote - or by using -Xg - as
I wrote). Some people do not won't to include the debug information,
because they increase the file size of the executable quite a bit
(especially if you use the LCL).
I know, wasn't with the strip.
Post by Everton Vieira
* executable size: ~14MB
* debug info size: ~145MB
Regards,
Sven
______________________________**_________________
http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>
--
Everton Vieira.
Martin
2012-02-20 16:01:04 UTC
Permalink
Post by Everton Vieira
Is supposed that with the -gl and the BackTraceStrFunc would get all
the info with the line number as well? Because if is true i've seen
not work and could test again.
It is supposed, yes.
And it does for me.

However I read something, someone said that it was broken at some point
for stabs or dwarf (not sure which, but only one of them.

Your units seem to contain a reader for that info. it may differ from
the one shipped with fpc.... So if indeed it is true, and the one in fpc
is indeed not working (which I do not know), then that probably needs to
be bug reported ...
Post by Everton Vieira
- compile with debug info
- keep a copy of the file with debug info
- use strip[.exe] to remove the debug info from shipping version
- dump addresses
when you get the addresses, you can use gdb and the copy with debug info
that you kept (must match 100% the shipped version)
you will need a smass script calling gdb for each address
gdb.exe -i mi project1.exe --eval-command="info line *0x428f60"
--eval-command=q
- compile with "-Xg"
- keep the appname.dbg file
- dump addresses
gdb.exe -i mi project1.exe --symbols=project1.dbg
--eval-command="info line *0x428f60" --eval-command=q
Regards,
Sven
_______________________________________________
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
--
Everton Vieira.
_______________________________________________
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Everton Vieira
2012-02-20 16:10:56 UTC
Permalink
Post by Everton Vieira
Is supposed that with the -gl and the BackTraceStrFunc would get all the
info with the line number as well? Because if is true i've seen not work
and could test again.
It is supposed, yes.
And it does for me.
However I read something, someone said that it was broken at some point
for stabs or dwarf (not sure which, but only one of them.
Your units seem to contain a reader for that info. it may differ from the
one shipped with fpc.... So if indeed it is true, and the one in fpc is
indeed not working (which I do not know), then that probably needs to be
bug reported ...
Well, i have to finish a project here that i'm on, since i get finish i'll
do some tests.
Post by Everton Vieira
_______________________________________________
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
--
Everton Vieira.
Loading...