Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-02

Logging full runtime-error/exception backtrace

22 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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?

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 .

Reply by email

Everton Vieira
to leledumbo

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 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 . _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Everton Vieira.

Reply by email

Sven Barth
to leledumbo: I want to log the full runtime-error/exception backtrace to a file. I've tried all…
leledumbo wrote 5 lines
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

Reply by email

Martin
to leledumbo: I want to log the full runtime-error/exception backtrace to a file. I've tried all…
leledumbo wrote 6 lines
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

Reply by email

Sven Barth
to Martin: If you ship with debug info, then see gdbmidebugger.pp function…
Martin wrote 15 lines
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

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

Reply by email

Everton Vieira
to Martin: 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
On 20/02/2012 14:58, leledumbo wrote: > 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; ------- 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 ______________________________**_________________ fpc-pascal maillist - http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>
Everton Vieira.

Reply by email

Everton Vieira
to Sven Barth: - 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
Am 20.02.2012 16:34, schrieb Martin: 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 > 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 ______________________________**_________________ fpc-pascal maillist - http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>
Everton Vieira.

Reply by email

Sven Barth
to Everton Vieira
Everton Vieira wrote
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

Reply by email

Martin
to Everton Vieira: Is supposed that with the -gl and the BackTraceStrFunc would get all the info with the…
Everton Vieira wrote
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 ...

Show quoted text 52 lines
2012/2/20 Sven Barth < > Am 20.02.2012 16:34, schrieb Martin: 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 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 _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal -- Everton Vieira. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Everton Vieira
to Sven Barth: 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
Am 20.02.2012 16:52, schrieb 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).

I know, wasn't with the strip.

Show quoted text 13 lines
Example of Lazarus.exe: * executable size: ~14MB * debug info size: ~145MB Regards, Sven ______________________________**_________________ fpc-pascal maillist - http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>
Everton Vieira.

Reply by email

Everton Vieira
to Martin: 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
On 20/02/2012 15:52, Everton Vieira wrote: 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.

Show quoted text 6 lines
_______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Everton Vieira.

Reply by email

leledumbo
to Sven Barth: 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.

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 .

Reply by email

Sven Barth
to leledumbo
"leledumbo" wrote 8 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. 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

Reply by email

Everton Vieira
to Sven Barth

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
Am 20.02.2012 23:37 schrieb "leledumbo" : > > > 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 _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

leledumbo
to Sven Barth: 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.

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 .

Reply by email

Martin
to leledumbo
leledumbo wrote 7 lines
> 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.

Reply by email

Everton Vieira
to Martin
Martin wrote 12 lines
On 21/02/2012 16:14, leledumbo wrote: >> 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.

Show quoted text 5 lines
Also start testing outside an exception, to see if that works. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Martin
to Everton Vieira
Everton Vieira wrote 15 lines
Em 21/02/2012, às 14:20, Martin escreveu: > On 21/02/2012 16:14, leledumbo wrote: >>> 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.

Reply by email

Everton Vieira
to Martin
Martin wrote 19 lines
On 21/02/2012 20:28, Everton Vieira wrote: > Em 21/02/2012, às 14:20, Martin escreveu: > >> On 21/02/2012 16:14, leledumbo wrote: >>>> 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.

Show quoted text 6 lines
_______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Everton Vieira
to Everton Vieira
Everton Vieira wrote 24 lines
Em 21/02/2012, às 18:35, Martin escreveu: > On 21/02/2012 20:28, Everton Vieira wrote: >> Em 21/02/2012, às 14:20, Martin escreveu: >> >>> On 21/02/2012 16:14, leledumbo wrote: >>>>> 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.

Show quoted text 8 lines
> > > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email