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

2016年01月28日 Android 10条评论 阅读35416次

利用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
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

10 条评论

  1. avatar gypsandco

    <a href="http://www.pulselocums.com/jordan-4-gr%C3%B8nn-glow-gr%C3%A5-chaussuresf">jordan 4 gr酶nn glow gr氓</a> <a href="http://www.eniszczarki.com/nike-air-max-womens-dark-blue-footc">nike air max womens dark blue</a> <a href="http://www.gradualdesing.com/tory-burch-black-leather-wallet-toryburchr">tory burch black leather wallet</a> <a href="http://www.sigaldavid.com/hermes-birkin-30-gold-togo-hermesr">hermes birkin 30 gold togo</a> <a href="http://www.mindteez.com/adidas-john-wtutti-3-gituttio-viola-obuva">adidas john wtutti 3 gituttio viola</a> <a href="http://www.synthcourses.com/adidas-neo-scarpe-ladies-obuvc">adidas neo scarpe ladies</a>
    gypsandco http://www.gypsandco.com/

  2. avatar auroragenri

    <a href="http://www.sohbetikiz.com/youth-san-diego-chargers-nick-dzubnar-navy-pro-line-jersey-nflh">youth san diego chargers nick dzubnar navy pro line jersey</a> <a href="http://www.akkordiki.com/kevin-durant-ut-jersey-nfli">kevin durant ut jersey</a> <a href="http://www.torrentslot.com/patriots-chandler-jones-jersey-nflh">patriots chandler jones jersey</a> <a href="http://www.familycarepc.com/nike-air-max-bw-kvinders-lyser%C3%B8d-shoese">nike air max bw kvinders lyser酶d</a> <a href="http://www.alizatrade.com/ralph-lauren-slim-fit-t-shirt-poloh">ralph lauren slim fit t shirt</a> <a href="http://www.auroragenri.com/nike-lebron-11-alle-r%C3%B8d-foota">nike lebron 11 alle r酶d</a>
    auroragenri http://www.auroragenri.com/

  3. avatar troyafolklor

    <a href="http://www.synthcourses.com/nike-sko-kvinners-roshe-run-svart-gr%C3%A5-obuvf">nike sko kvinners roshe run svart gr氓</a> <a href="http://www.talentbschool.com/jordan-retro-5-svart-and-gull-obuve">jordan retro 5 svart and gull</a> <a href="http://www.chatavalanche.com/nike-mercurial-superfly-4-fg-sort-kurpesg">nike mercurial superfly 4 fg sort</a> <a href="http://www.demuslimah.com/nike-air-pegasus-92-schwarz-wei%C3%9F-obuvc">nike air pegasus 92 schwarz wei脽</a> <a href="http://www.getbizbuilder.com/nike-air-foamposite-one-hoh-electric-gr%C3%BCn-butya">nike air foamposite one hoh electric gr眉n</a> <a href="http://www.harveenandraj.com/nike-team-usa-6-lebron-james-white-2012-usa-basketball-retro-stitched-nba-jersey-nflu">nike team usa 6 lebron james white 2012 usa basketball retro stitched nba jersey</a>
    troyafolklor http://www.troyafolklor.com/

  4. avatar mydxp

    <a href="http://www.drtruth.net/air-jordan-super-fly-iv-gul-lilla-schuhea">air jordan super fly iv gul lilla</a> <a href="http://www.drybulkintelligence.net/nike-free-3.0-dam%C3%A4nner-schwarz-himmelblau-kurpese">nike free 3.0 dam盲nner schwarz himmelblau</a> <a href="http://www.dsicomposer.net/air-jordan-3.5-braun-schwarz-chaussuresa">air jordan 3.5 braun schwarz</a> <a href="http://www.duckbeachmovie.net/nike-air-max-2016-marr%C3%B3n-amarillo-kurpesg">nike air max 2016 marr贸n amarillo</a> <a href="http://www.dynamicbook.net/nike-air-pegasus-92-bianca-arancia-peel-schuhee">nike air pegasus 92 bianca arancia peel</a> <a href="http://www.earlylearninggroup.net/nike-air-max-2016-sort-and-gr%C3%B8n-obuvg">nike air max 2016 sort and gr酶n</a>
    mydxp http://www.mydxp.net/

  5. avatar skepticmoment

    <a href="http://www.sofakolle.com/us-polo-city-mall-poloh">us polo city mall</a> <a href="http://www.tomsavagetrio.com/nike-kobe-11-em-svart-laser-crimson-wolf-gr%C3%A5-hvit-foota">nike kobe 11 em svart laser crimson wolf gr氓 hvit</a> <a href="http://www.hopeforcinema.com/jordan-retro-5-wolf-gr%C3%A5-svart-hot-lava-runninga">jordan retro 5 wolf gr氓 svart hot lava</a> <a href="http://www.pusulagelisim.com/jordan-retro-4-cool-gr%C3%A5-2015-scarpee">jordan retro 4 cool gr氓 2015</a> <a href="http://www.ndtkalashop.com/air-jordan-eclipse-gold-himmelblau-runningg">air jordan eclipse gold himmelblau</a> <a href="http://www.isgmembers.com/m%C3%A4nner-nike-internationalist-jcrd-weave-dark-blau-moonlight-schuhei">m盲nner nike internationalist jcrd weave dark blau moonlight</a>
    skepticmoment http://www.skepticmoment.com/

  6. avatar radiationism

    <a href="http://www.newinfit.com/nike-magista-opus-lila-schuhek">nike magista opus lila</a> <a href="http://www.thebedguide.com/asics-gel-noosa-tri-10-rosa-argento-scarpeg">asics gel noosa tri 10 rosa argento</a> <a href="http://www.lisastrnad.com/under-armour-curry-one-gul-lyser%C3%B8d-kurpesb">under armour curry one gul lyser酶d</a> <a href="http://www.plangivethank.com/mujer-air-jordan-retro-12-low-blanco-azul-zapatosk">mujer air jordan retro 12 low blanco azul</a> <a href="http://www.sikisfilim.com/kvinders-new-balance-577-mintgr%C3%B8n-runningc">kvinders new balance 577 mintgr酶n</a> <a href="http://www.boajewlery.com/nike-magista-opus-tpu-fg-high-tops-gris-negro-verde-zapatosj">nike magista opus tpu fg high tops gris negro verde</a>
    radiationism http://www.radiationism.com/

  7. avatar dazedkayla

    <a href="http://www.investicrypto.com/adidas-zx-flux-nero-rosa-blu-verde-scarpej">adidas zx flux nero rosa blu verde</a> <a href="http://www.nattaravnur.com/adidas-zx-flux-wei%C3%9F-and-rainbow-schuhei">adidas zx flux wei脽 and rainbow</a> <a href="http://www.uacheap.com/lilla-gr%C3%A5-herre-nike-air-force-1-high-sko-skoh">lilla gr氓 herre nike air force 1 high sko</a> <a href="http://www.sheeradiance.com/arizona-cardinals-fitzgerald-youth-jersey-nfli">arizona cardinals fitzgerald youth jersey</a> <a href="http://www.solclimasur.com/mennns-nike-air-max-90-rosa-hvit-obuvk">mennns nike air max 90 rosa hvit</a> <a href="http://www.successlms.com/coach-in-signature-large-yellow-wallets-coachh">coach in signature large yellow wallets</a>
    dazedkayla http://www.dazedkayla.com/

  8. avatar rastadread

    <a href="http://www.bowtieorg.com/nike-air-force-1-flyknit-high-black-shoesj">nike air force 1 flyknit high black</a> <a href="http://www.shaneboothmx.com/nike-free-flyknit-4.0-v2-black-white-shoesl">nike free flyknit 4.0 v2 black white</a> <a href="http://www.basarancarpet.com/ralph-lauren-blue-v-neck-poloh">ralph lauren blue v neck</a> <a href="http://www.freedhamaal.com/adidas-rose-bl%C3%A5-guld-skok">adidas rose bl氓 guld</a> <a href="http://www.borbonecoffe.com/m%C3%A4nner-nike-kobe-ix-elite-low-rot-brow-grau-schuheh">m盲nner nike kobe ix elite low rot brow grau</a> <a href="http://www.cammaara.com/air-jordan-retro-11-wine-velvet-heiress-shoesk">air jordan retro 11 wine velvet heiress</a>
    rastadread http://www.rastadread.com/

  9. avatar truthtapes

    <a href="http://www.unefinemouche.com/air-jordan-retro-14-silber-royal-blau-schuheh">air jordan retro 14 silber royal blau</a> <a href="http://www.ayuinc.com/nike-zoom-structure-20-black-white-shoesq">nike zoom structure 20 black white</a> <a href="http://www.unirlisboa.com/jordan-23-jersey-crop-top-nfli">jordan 23 jersey crop top</a> <a href="http://www.escortfeeds.com/mennns-nike-shox-deliver-gr%C3%A5-gul-obuvp">mennns nike shox deliver gr氓 gul</a> <a href="http://www.rdjanitorial.com/coach-nina-sunglasses-coachh">coach nina sunglasses</a> <a href="http://www.bookoobeats.com/nike-lebron-12-femminile-rosso-rosa-scarpei">nike lebron 12 femminile rosso rosa</a>
    [url=http://www.truthtapes.com/]truthtapes[/url]

  10. avatar buycharboleps

    <a href="http://www.goodmedusa.com/coach-in-signature-large-black-totes-coachh">coach in signature large black totes</a> <a href="http://www.murskacorp.com/adidas-zx-flux-floreale-grigio-scarpej">adidas zx flux floreale grigio</a> <a href="http://www.prajansim.com/rosso-pelle-converse-uk-scarpei">rosso pelle converse uk</a> <a href="http://www.pokersurga.com/florida-panthers-adidas-nhl-2nd-season-flex-cap-hath">florida panthers adidas nhl 2nd season flex cap</a> <a href="http://www.arkmmj.com/bon-march%C3%A9-tout-noir-cuir-converse-chaussuresh">bon march茅 tout noir cuir converse</a> <a href="http://www.butterbroad.com/nike-roshe-hommes-wool-skin-vente-noir-vert-chaussuresj">nike roshe hommes wool skin vente noir vert</a>
    buycharboleps http://www.buycharboleps.com/

欢迎留言




用户登录

sitemap