利用backtrace的地址信息和addr2line命令定位so出错的行数

2016年01月28日 Android 9条评论 阅读21515次

利用backtrace的地址信息和addr2line命令定位so出错的行数

Linux开发中,底层经常会用到静态链接库(*.a)或动态链接库(*.so)来实现某一功能。

在应用层调用so文件时,也会经常遇到因为so内部的问题导致应用crash的现象。

crash发生后,系统会产生一个日志。日志大体内容如下:


I/DEBUG(349): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG(349): Build fingerprint: 
'Android/jileniao.net/jileniao:5.0.1/LRX22G/root03231947:userdebug/test-keys'
I/DEBUG(349): Revision: '33696'
I/DEBUG(349): ABI: 'arm'
I/DEBUG(349): pid: 2686, tid: 3065, name: gps_proc  >>> /system/bin/gpsserver <<<
I/DEBUG(349): signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0xb170a219
W/NativeCrashListener(856): Couldn't find ProcessRecord for pid 2686
I/DEBUG(349):     r0 000fde18  r1 ae3f4248  r2 0007ef0c  r3 00008000
E/DEBUG(349): AM write failure (32 / Broken pipe) I/DEBUG(349):     r4 001fb799  r5 ffffa7e4  r6 ae4d00c0  r7 0001c5a2
I/DEBUG(349):     r8 00000081  r9 00000001  sl b160c400  fp 00000001
I/DEBUG(349):     ip ae4d00c0  sp af0bb8a0  lr b160c401  pc b5d08680  cpsr 280b0010
I/DEBUG(349): backtrace:
I/DEBUG(349):     #00 pc 0011d680  /system/lib/gps_ma87.so (Method0+984)
I/DEBUG(349):     #01 pc 0007694c  /system/lib/gps_ma87.so (Method1+724)
I/DEBUG(349):     #02 pc 00069c2c  /system/lib/gps_ma87.so (Method2+1116)
I/DEBUG(349):     #03 pc 000676f4  /system/lib/gps_ma87.so (Method3+224)
I/DEBUG(349):     #04 pc 00066bef  /system/lib/gps_ma87.so (GPSCPPClassName::Method4(char*, int)+390)
I/DEBUG(349):     #05 pc 000438bf  /system/lib/gps_ma87.so (gps::Method5(void)+134)
I/DEBUG(349):     #06 pc 00042fe1  /system/lib/gps_ma87.so (gps::Method6(void*)+40)
I/DEBUG(349):     #07 pc 00042429  /system/lib/gps_ma87.so (gps::Method7(void*)+172)
I/DEBUG(349):     #08 pc 000162e3  /system/lib/libc.so (__pthread_start(void*)+30)
I/DEBUG(349):     #09 pc 000142d3  /system/lib/libc.so (__start_thread+6) 


看到这些log之后,直接找最有用的backtrace信息。 backtrace描述了crash发生时函数的调用关系及其它地址信息等,可谓是真实地还原了crash的现场。接下来就看下现场的具体情况是怎么样的。

backtrace中,从#00到#09 共十行信息代表是crash时函数调用关系,从下往上倒着看,#09行的方法调用了#08行的方法;#08行的方法调用了#07行的方法;向上类推,最后就是#01行的方法调用了#00行的方法。而最终出现的crash就是在#00行中。

通过上面我们知道了crash发生时是哪个方法的问题了。但具体某一个方法还是范围有些大,对于排查问题来说,我们还希望能得到更细的结果。

在backtrace信息中,#00到#09每行标注的方法后面还有个+XXX的字样,最初我对此的理解,认为这就是行号了。但回到源代码中却发现不是这样子的。

要想知道确切的行号,就要用到每行的pc 后面的地址。

Linux为我们提供了addr2line的命令。通过这个命令可以根据地址得到行号。

先看addr2line命令的具体用法。

这里我们主要指定两个选项就可以达到看函数以及行号的目的。


  • -e 后面加上so的文件名
  • -f 同时输出函数名称


例子: addr2line -e test gps_ma87.so 0x0011d680 -f

这样即可得到函数名称以及具体哪个文件的多少行了。

addr2line得到的行号确定不可能出错

如果使用addr2line命令得到的行号对应的源代码中就是一句很简单的赋值语句这样的情况,也就是我们非常确定这行代码不可能出什么错误异常的。此时就要看调用该方法的地方是否有错,很有可能是调用该方法的地方就出错了,所以系统报错时候就定位到这一行了。

addr2line得到行号为??:?或??:0的原因

如果遇到addr2line得到??:?或??:0的情况,原因就是编译得到的so文件没有附加上符号表(symbolic)信息。

如果在android源码环境下,android编译环境会自动生成附带有符号表(symbolic)的so文件。标准android5.0中,附带有符号表(symbolic)的so文件在下面路径:

out/target/product/[productname]/symbols/system/lib/****.so

如果是非android环境,需要在makefile中指定生成附带有符号表(symbolic)的so文件的选项,具体关于动态链接库以及符号表等,请参阅如下网站: http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

分享本文至:

WRITTEN BY

avatar
本文标签:backtraceaddr2line
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

9 条评论

  1. avatar hdwi748u

    <a href="http://www.ehbnzb84.com/air-jordan-11-retro-medium-gris-blanc-cool-gris-kurpesa">air jordan 11 retro medium gris blanc cool gris</a> <a href="http://www.n1jvmtjv.com/air-max-95-infrar%C3%B8d-unit-butyc">air max 95 infrar酶d unit</a> <a href="http://www.r2g427lp.com/air-jordan-retro-14-blanc-vert-jaune-butyd">air jordan retro 14 blanc vert jaune</a> <a href="http://www.cv9uzx13.com/nike-lebron-soldier-10-all-svart-download-kurpesc">nike lebron soldier 10 all svart download</a> <a href="http://www.pqphql39.com/nike-tiempo-legend-iv-wei%C3%9F-wei%C3%9F-schwarz-schuhea">nike tiempo legend iv wei脽 wei脽 schwarz</a> <a href="http://www.8z1143o9.com/nike-foamposite-yeezy-for-venta-michigan-kurpesf">nike foamposite yeezy for venta michigan</a>
    hdwi748u http://www.hdwi748u.com/

  2. avatar rentalloka

    <a href="http://www.hotelfuat.com/red-white-mens-nike-kobe-10-elite-shoes-sneakere">red white mens nike kobe 10 elite shoes</a> <a href="http://www.pmisaltriver.com/adidas-zx-750-r%C3%B8d-guld-kurpesa">adidas zx 750 r酶d guld</a> <a href="http://www.ductambag.com/nike-flynit-air-max-grey-multicolor-sneakerb">nike flynit air max grey multicolor</a> <a href="http://www.priverussia.com/nike-roshe-mens-new-shoesg">nike roshe mens new</a> <a href="http://www.coatsfrance.com/new-york-yankees-camouflage-hat-hats">new york yankees camouflage hat</a> <a href="http://www.intoloo.com/adidas-ultra-boost-hypebeast-instagram-sneakerf">adidas ultra boost hypebeast instagram</a>
    rentalloka http://www.rentalloka.com/

  3. avatar pistaclic

    <a href="http://www.opelbeyinleri.com/nike-air-max-bw-gul-bl%C3%A5-scarpeg">nike air max bw gul bl氓</a> <a href="http://www.pazoga.com/adidas-originals-herren-zx-750-trainer-blau-obuvc">adidas originals herren zx 750 trainer blau</a> <a href="http://www.rahwindsor.com/jordan-6-rojo-varsity-scarpea">jordan 6 rojo varsity</a> <a href="http://www.salessteelbar.com/nike-kobe-10-poison-gr%C3%B8nn-grass-schuheb">nike kobe 10 poison gr酶nn grass</a> <a href="http://www.harpiabd.com/mens-nike-indianapolis-colts-78-ryan-kelly-royal-blue-team-color-vapor-untouchable-limited-player-nfl-jersey-nflr">mens nike indianapolis colts 78 ryan kelly royal blue team color vapor untouchable limited player nfl jersey</a> <a href="http://www.katiagrinkov.com/adidas-avalanche-64-nail-yakupov-burgundy-home-authentic-usa-flag-stitched-nhl-jersey-nflx">adidas avalanche 64 nail yakupov burgundy home authentic usa flag stitched nhl jersey</a>
    pistaclic http://www.pistaclic.com/

  4. avatar mengenmetal

    <a href="http://www.daddeaze.com/jordan-11-low-blau-snake-scarpec">jordan 11 low blau snake</a> <a href="http://www.debracousins.com/lunarglide-7-bl%C3%A5-ridge-kurpesc">lunarglide 7 bl氓 ridge</a> <a href="http://www.yankaripark.com/discount-ray-ban-metal-effect-sunglassesf">discount ray ban metal effect</a> <a href="http://www.yicailottery.com/womens-nike-jacksonville-jaguars-44-myles-jack-white-vapor-untouchable-limited-player-nfl-jersey-nflr">womens nike jacksonville jaguars 44 myles jack white vapor untouchable limited player nfl jersey</a> <a href="http://www.calebcraw.com/bon-march%C3%A9-nike-free-trail-hommes-bleu-skoa">bon march茅 nike free trail hommes bleu</a> <a href="http://www.liquidputter.com/nike-hypervenom-phelon-fg-junior-football-boots-silver-sneakerf">nike hypervenom phelon fg junior football boots silver</a>
    mengenmetal http://www.mengenmetal.com/

  5. avatar medieneinsatz

    <a href="http://www.freizeittrend.com/white-green-mens-nike-zoom-speed-shoes-sneakere">white green mens nike zoom speed shoes</a> <a href="http://www.instanalo.com/nike-lunar-negro-p%C3%BArpura-kurpesa">nike lunar negro p煤rpura</a> <a href="http://www.olafhuth.com/nike-free-womens-black-5-black-sneakerb">nike free womens black 5 black</a> <a href="http://www.pecanfirewood.com/air-jordan-7-female-turquoise-purple-shoesg">air jordan 7 female turquoise purple</a> <a href="http://www.ezzolawaz.com/syracuse-snapback-hats">syracuse snapback</a> <a href="http://www.suchmeldungen.com/when-do-the-curry-1-low-come-out-last-night-sneakerf">when do the curry 1 low come out last night</a>
    medieneinsatz http://www.medieneinsatz.com/

  6. avatar soulmateunlimited

    <a href="http://www.lifetimekiawarranty.net/air-jordan-retro-1-barn-rosa-lilla-butye">air jordan retro 1 barn rosa lilla</a> <a href="http://www.llensa.net/nike-hyperdunk-on-vendita-yarn-obuvd">nike hyperdunk on vendita yarn</a> <a href="http://www.lockip.net/new-blance-barn-sko-lilla-gr%C3%A5-obuvg">new blance barn sko lilla gr氓</a> <a href="http://www.lockseventeen.net/air-max-90-negro-and-gris-schuhef">air max 90 negro and gris</a> <a href="http://www.logicaldrift.net/nike-zoom-winflo-3-femmes-bleu-ciel-rouge-obuve">nike zoom winflo 3 femmes bleu ciel rouge</a> <a href="http://www.longevitysa.net/air-yeezy-ii-2-sp-max-90-bl%C3%A5-butye">air yeezy ii 2 sp max 90 bl氓</a>
    soulmateunlimited http://www.soulmateunlimited.net/

  7. avatar ankaralokanta

    <a href="http://www.eworklife.com/nike-blazer-mid-metric-royal-blue-kaufen-sneakerb">nike blazer mid metric royal blue kaufen</a> <a href="http://www.fullcountkbo.com/nike-air-max-damen-in-pink-shoesf">nike air max damen in pink</a> <a href="http://www.shackofstones.com/new-england-patriots-snapback-hats">new england patriots snapback</a> <a href="http://www.tamworthbacon.com/billig-air-jordan-8-kvinders-orange-sneakere">billig air jordan 8 kvinders orange</a> <a href="http://www.dvmengineers.com/adidas-tubular-runner-west-gr%C3%B8n-gr%C3%A5-obuvd">adidas tubular runner west gr酶n gr氓</a> <a href="http://www.questoffine.com/nike-baltimore-ravens-womens-legend-logo-drifit-nfl-t-shirt-purple-nflx">nike baltimore ravens womens legend logo drifit nfl t shirt purple</a>
    ankaralokanta http://www.ankaralokanta.com/

  8. avatar kokismith

    <a href="http://www.carlosbartolo.com/nike-zoom-vomero-r%C3%B8d-bl%C3%A5-kurpesf">nike zoom vomero r酶d bl氓</a> <a href="http://www.chiragsblog.com/nike-jarran-reed-jersey-90-nfl-seattle-seahawks-pullover-hoodie-one-color-ash-nflr">nike jarran reed jersey 90 nfl seattle seahawks pullover hoodie one color ash</a> <a href="http://www.eventyrshop.com/nike-air-max-tailwind-6-mujeres-negro-verde-kurpesf">nike air max tailwind 6 mujeres negro verde</a> <a href="http://www.firmayoga.com/maschio-nike-free-flyknit-3.0-rosso-grigio-schuhef">maschio nike free flyknit 3.0 rosso grigio</a> <a href="http://www.keiservices.com/nike-air-huarache-nm-rosa-gr%C3%B8nn-obuvg">nike air huarache nm rosa gr酶nn</a> <a href="http://www.kmkonka.com/nike-flyknit-lunar-1-femmes-rouge-violet-chaussuresa">nike flyknit lunar 1 femmes rouge violet</a>
    [url=http://www.kokismith.com/]kokismith[/url]

  9. avatar 0o345dwi

    <a href="http://www.19mhn34f.com/asics-gel-kayano-21-rosa-up-kurpesb">asics gel kayano 21 rosa up</a> <a href="http://www.4hwik75b.com/nike-kobe-9-elite-low-gr%C3%BCn-rot-kurpesa">nike kobe 9 elite low gr眉n rot</a> <a href="http://www.p64crdmr.com/kd-7-orange-and-vert-obuvb">kd 7 orange and vert</a> <a href="http://www.g8291ttv.com/nike-free-inneva-woven-poison-verde-kurpesa">nike free inneva woven poison verde</a> <a href="http://www.xq2wj553.com/nike-free-5.0-v4-leopard-grigio-butyd">nike free 5.0 v4 leopard grigio</a> <a href="http://www.hwgcf43f.com/nike-sb-dunk-lila-pigeon-butye">nike sb dunk lila pigeon</a>
    0o345dwi http://www.0o345dwi.com/

欢迎留言




用户登录

sitemap