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?
Mailing lists / fpc-pascal / 2012-02
Logging full runtime-error/exception backtrace
22 messages · 4 people · –
- EEverton Vieira 9
- SSven Barth 5
- Lleledumbo 4
- MMartin 4
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
I use this units to do that. Was someone with the nickname crhonos who made. 2012/2/20 leledumbo
Show quoted text 15 lines
I want to log the full runtime-error/exception backtrace to a file. I've tried all…
leledumbo wrote 5 lines
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
I want to log the full runtime-error/exception backtrace to a file. I've tried all…
leledumbo wrote 6 lines
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
I use this units to do that. Was someone with the nickname crhonos who made. 2012/2/20…
Everton Vieira wroteI 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
If you ship with debug info, then see gdbmidebugger.pp function…
Martin wrote 15 lines
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
If you ship with debug info, then see gdbmidebugger.pp function…
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.
2012/2/20 Martin
Show quoted text 46 lines
- compile with "-Xg" - keep the appname.dbg file - dump addresses command to use: gdb.exe…
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.
2012/2/20 Sven Barth
Show quoted text 37 lines
Everton Vieira wroteIs 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
Is supposed that with the -gl and the BackTraceStrFunc would get all the info with the…
Everton Vieira wroteIs 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 ...
Show quoted text 52 lines
This only works if you do not strip the debug info from the executable (either by using…
2012/2/20 Sven Barth
Show quoted text 13 lines
I know, wasn't with the strip.
Show quoted text 13 lines
It is supposed, yes. And it does for me. However I read something, someone said that it…
2012/2/20 Martin
Show quoted text 18 lines
Well, i have to finish a project here that i'm on, since i get finish i'll do some tests.
Show quoted text 6 lines
I use this units to do that. Was someone with the nickname crhonos who made. 2012/2/20…
I use this units to do that. Was someone with the nickname crhonos who
made.
Thanks, I'll try it :)
The resolution of file and address can only be done if your code is a) compiled with…
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.
"leledumbo" wrote 8 lines
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
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.
Sven Barth wrote 20 lines
it. The BackTraceStrFunc by default points to SysBackTraceStr which just converts…
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.
leledumbo wrote 7 lines
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.
Martin wrote 12 lines
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.
Show quoted text 5 lines
Everton Vieira wrote 15 lines
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.
Martin wrote 19 lines
I have a virtualized windows xp here. I`ll try there.
Show quoted text 6 lines
Everton Vieira wrote 24 lines
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.
