project-navigation
Personal tools

Author Topic: translating executable addresses to file:line in backtrace - addr2line  (Read 7221 times)

Offline jerikojerk

  • Squad Leader
  • ****
  • Posts: 149
    • View Profile
i made a script to pipe ufo output to replace object addresses to file/line/function

example:
Code: [Select]
./ufo(CL_ReadSinglePlayerData+0x15d)[0x80c2fa5]
./ufo(GAME_CP_InitStartup+0x137)[0x8070671]
./ufo(GAME_SetMode+0x100)[0x806e634]
./ufo(GAME_ReloadMode+0x34)[0x806e396]
./ufo[0x80eff36]
./ufo[0x80f0cae]

by something more human readable

Code: [Select]
./ufo(CL_ReadSinglePlayerData+0x15d)[./src/client/campaign/cp_parse.c:728 CP_ItemsSanityCheck()]
./ufo(GAME_CP_InitStartup+0x137)[./src/client/cl_game_campaign.c:491 GAME_CP_InitStartup()]
./ufo(GAME_SetMode+0x100)[./src/client/cl_game.c:308 GAME_SetMode()]
./ufo(GAME_ReloadMode+0x34)[./src/client/cl_game.c:117 GAME_GenerateTeam()]
./ufo[./src/client/campaign/cp_save.c:158 SAV_GameLoad()]
./ufo[./src/client/campaign/cp_save.c:390 SAV_GameReadGameComment()]

now the bad new is that's a php5 shell script, i provided in attached file.

if you are still interested, you have to use it like this

  • you have to put the script addr2line.php in the same directory as your ufo binary. I mean, if you're running from trunk, you just have to copy it in trunk directory.
  • you run ufo binary from shell using ./ufo 2>&1 |  php addr2line.php
  • you can enjoy the game as usual.

as ufo writes both on stderr and stdout the pipe may mix the two streams from time to time. i don't think you care a lot about it.

the script assume addr2line is available in /usr/bin/addr2line. if not just edit line 29. It will not try to install addr2line if you don't have it.

feel free to improve it or to port it into what you want.

Offline jerikojerk

  • Squad Leader
  • ****
  • Posts: 149
    • View Profile
an other way to use it, if you already have a backtrace. You copy it in a file (backtrace_file) and then:

cat backtrace_file | php addr2line.php

it should work fine on window with any php.exe in CLI version, but i don't know how to pipe stdin and stdout on windows, sorry boys.


Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
on windows is no backtrace anyway ;)

Offline mikeg

  • Rookie
  • ***
  • Posts: 24
    • View Profile
Re: translating executable addresses to file:line in backtrace - addr2line
« Reply #3 on: October 12, 2010, 11:12:18 pm »
on windows is no backtrace anyway ;)

Well, I found this: http://code.google.com/p/backtrace-mingw/

Maybe an option for the debug build?

Offline mikeg

  • Rookie
  • ***
  • Posts: 24
    • View Profile
Re: translating executable addresses to file:line in backtrace - addr2line
« Reply #4 on: October 14, 2010, 08:36:42 pm »
Here is an initial draft version of the backtrace in windows for an unhandled exception (segfault, e.g.).

Please apply patch in ascending order (0001, 0002)

Tested by adding following lines somewhere in code:

Code: [Select]
int *i = NULL;
*i = 4;

This caused the following backtrace in ufoconsole.log:

Code: [Select]
2010/10/14 20:19:48
----- network initialization -------
2010/10/14 20:19:48libcurl/7.21.1 zlib/1.2.3 initialized.
2010/10/14 20:19:48
------ server initialization -------
2010/10/14 20:19:48mapcycle add: '+africa small' type '1on1'
2010/10/14 20:19:48mapcycle add: '+frozen small' type '1on1'
2010/10/14 20:19:48mapcycle add: '+italy default' type '1on1'
2010/10/14 20:19:48mapcycle add: 'farm' type '1on1'
2010/10/14 20:19:48mapcycle add: 'estate' type '1on1'
2010/10/14 20:19:48mapcycle add: '+japan default' type '1on1'
2010/10/14 20:19:48mapcycle add: 'tower' type '1on1'
2010/10/14 20:19:48added 7 maps to the mapcycle
2010/10/14 20:19:48Stack trace:

0x41064f : E:\cpp\ufoai\ufo.exe : e:\cpp\ufoai/src/client/cl_main.c (1260) : in function (CL_Init)
0x4dc28a : E:\cpp\ufoai\ufo.exe : e:\cpp\ufoai/src/common/common.c (1105) : in function (Qcommon_Init)
0x53b433 : E:\cpp\ufoai\ufo.exe : e:\cpp\ufoai/src/ports/windows/win_main.c (149) : in function (WinMain@16)
0x53c676 : E:\cpp\ufoai\ufo.exe : main.c
0x4010db : E:\cpp\ufoai\ufo.exe : crt1.c
0x401158 : E:\cpp\ufoai\ufo.exe : crt1.c
Failed to init bfd from (C:\Windows\system32\kernel32.dll)
0x76d61194 : C:\Windows\system32\kernel32.dll : BaseThreadInitThunk
Failed to init bfd from (C:\Windows\SYSTEM32\ntdll.dll)
0x773ab495 : C:\Windows\SYSTEM32\ntdll.dll : RtlInitializeExceptionChain
Failed to init bfd from (C:\Windows\SYSTEM32\ntdll.dll)
0x773ab468 : C:\Windows\SYSTEM32\ntdll.dll : RtlInitializeExceptionChain

May it is helpful.

Regards

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: translating executable addresses to file:line in backtrace - addr2line
« Reply #5 on: October 15, 2010, 07:35:55 am »
also see http://sourceforge.net/tracker/?func=detail&aid=3086573&group_id=157793&atid=805244

i've done the same - the problem is that bfd is missing in our mingw installation - so we can't provide cross-compiled binaries. that's why i haven't applied this yet. that must be fixed in mingw-cross-env first

Offline Muton

  • Sergeant
  • *****
  • Posts: 496
    • View Profile
Re: translating executable addresses to file:line in backtrace - addr2line
« Reply #6 on: October 15, 2010, 02:29:31 pm »
I've included this lib in my new mingw
build it using this
http://ufoai.ninex.info/forum/index.php?action=dlattach;topic=5425.0;attach=5653

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: translating executable addresses to file:line in backtrace - addr2line
« Reply #7 on: October 15, 2010, 05:04:48 pm »
what was needed to build it? where did you get it? any special configure/make flags needed? tell me about this and i might be able to add this to mingw-cross-env to be able to provide cross-compile support for libfd