This tests the new dwarf_getlocations, dwarf_getlocation_attr and dwarf_getlocation_die functions. But it is also an example of how to handle location expressions and which libdw functions can be used to access all information required to interpret each DW_OP.
It might make sense to extend this test/example into a program that verifies various properties of DWARF expressions.
Signed-off-by: Mark Wielaard mjw@redhat.com --- tests/ChangeLog | 23 + tests/Makefile.am | 13 +- tests/run-varlocs.sh | 128 ++++++ tests/testfile_const_type.bz2 | Bin 0 -> 3353 bytes tests/testfile_const_type.c | 14 + tests/testfile_entry_value.bz2 | Bin 0 -> 3309 bytes tests/testfile_entry_value.c | 19 + tests/testfile_implicit_pointer.bz2 | Bin 0 -> 2952 bytes tests/testfile_implicit_pointer.c | 12 + tests/testfile_implicit_value.bz2 | Bin 0 -> 2973 bytes tests/testfile_implicit_value.c | 12 + tests/testfile_parameter_ref.bz2 | Bin 0 -> 3329 bytes tests/testfile_parameter_ref.c | 20 + tests/varlocs.c | 811 ++++++++++++++++++++++++++++++++++++ 14 files changed, 1049 insertions(+), 3 deletions(-) create mode 100755 tests/run-varlocs.sh create mode 100755 tests/testfile_const_type.bz2 create mode 100644 tests/testfile_const_type.c create mode 100755 tests/testfile_entry_value.bz2 create mode 100644 tests/testfile_entry_value.c create mode 100755 tests/testfile_implicit_pointer.bz2 create mode 100644 tests/testfile_implicit_pointer.c create mode 100755 tests/testfile_implicit_value.bz2 create mode 100644 tests/testfile_implicit_value.c create mode 100755 tests/testfile_parameter_ref.bz2 create mode 100644 tests/testfile_parameter_ref.c create mode 100644 tests/varlocs.c
diff --git a/tests/ChangeLog b/tests/ChangeLog index 9808ce7..c7ba095 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,26 @@ +2013-08-30 Mark Wielaard mjw@redhat.com + + * Makefile.am (check_PROGRAMS): Add varlocs. + (TESTS): Add run-varlocs.sh. + (EXTRA_DIST): Add run-varlocs.sh, testfile_const_type.c, + testfile_const_type.bz2, testfile_implicit_pointer.c, + testfile_implicit_pointer.bz2, testfile_parameter_ref.c, + testfile_entry_value.c, testfile_entry_value.bz2, + testfile_implicit_value.c and testfile_implicit_value.bz2. + (varlocs_LDADD): New. + * run-varlocs: New test. + * testfile_const_type.c: New test source file. + * testfile_entry_value.c: Likewise. + * testfile_implicit_pointer.c: Likewise. + * testfile_implicit_value.c: Likewise. + * testfile_parameter_ref.c: Likewise. + * testfile_const_type.bz2: New test file. + * testfile_entry_value.bz2: Likewise. + * testfile_implicit_pointer.bz2: Likewise. + * testfile_implicit_value.bz2: Likewise. + * testfile_parameter_ref.bz2: Likewise. + * varlocs.c: New test source. + 2013-08-13 Mark Wielaard mjw@redhat.com
* run-addr2line-i-test.sh: New test. diff --git a/tests/Makefile.am b/tests/Makefile.am index 9aa06a6..2ca9ad4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -52,7 +52,7 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \ test-flag-nobits dwarf-getstring rerequest_tag \ alldts md5-sha1-test typeiter low_high_pc \ test-elf_cntl_gelf_getshdr dwflsyms dwfllines \ - dwfl-report-elf-align + dwfl-report-elf-align varlocs asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \ asm-tst6 asm-tst7 asm-tst8 asm-tst9
@@ -89,7 +89,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ run-test-archive64.sh run-readelf-vmcoreinfo.sh \ run-readelf-mixed-corenote.sh run-dwfllines.sh \ run-dwfl-report-elf-align.sh run-addr2line-test.sh \ - run-addr2line-i-test.sh + run-addr2line-i-test.sh run-varlocs.sh
if !STANDALONE check_PROGRAMS += msg_tst md5-sha1-test @@ -202,7 +202,13 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ testfile-dwfl-report-elf-align-shlib.so.bz2 \ testfilenolines.bz2 test-core-lib.so.bz2 test-core.core.bz2 \ test-core.exec.bz2 run-addr2line-test.sh \ - run-addr2line-i-test.sh testfile-inlines.bz2 + run-addr2line-i-test.sh testfile-inlines.bz2 \ + run-varlocs.sh \ + testfile_const_type.c testfile_const_type.bz2 \ + testfile_implicit_pointer.c testfile_implicit_pointer.bz2 \ + testfile_parameter_ref.c testfile_parameter_ref.bz2 \ + testfile_entry_value.c testfile_entry_value.bz2 \ + testfile_implicit_value.c testfile_implicit_value.bz2
if USE_VALGRIND valgrind_cmd='valgrind -q --trace-children=yes --error-exitcode=1 --run-libc-freeres=no' @@ -327,6 +333,7 @@ test_elf_cntl_gelf_getshdr_LDADD = $(libelf) $(libmudflap) dwflsyms_LDADD = $(libdw) $(libelf) $(libmudflap) dwfllines_LDADD = $(libdw) $(libelf) $(libmudflap) dwfl_report_elf_align_LDADD = $(libdw) $(libmudflap) +varlocs_LDADD = $(libdw) $(libelf) $(libmudflap)
if GCOV check: check-am coverage diff --git a/tests/run-varlocs.sh b/tests/run-varlocs.sh new file mode 100755 index 0000000..9c4b313 --- /dev/null +++ b/tests/run-varlocs.sh @@ -0,0 +1,128 @@ +#! /bin/sh +# Copyright (C) 2013 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. + +. $srcdir/test-subr.sh + +# See the source files testfile_const_type.c testfile_implicit_value.c +# testfile_entry_value.c testfile_parameter_ref.c testfile_implicit_pointer.c +# how to regenerate the test files (needs GCC 4.8+). + +testfiles testfile_const_type testfile_implicit_value testfile_entry_value +testfiles testfile_parameter_ref testfile_implicit_pointer + +testrun_compare ${abs_top_builddir}/tests/varlocs -e testfile_const_type <<\EOF +module 'testfile_const_type' +[b] CU 'const_type.c'@0 + [33] function 'f1'@80483f0 + frame_base: {call_frame_cfa {bregx(4,4)}} + [4b] parameter 'd' + [80483f0,804841b) {fbreg(0)} + [57] variable 'w' + [80483f0,804841b) {fbreg(0), GNU_deref_type(8){long long int,signed,64@[25]}, GNU_const_type{long long int,signed,64@[25]}(8)[0000806745230100], div, GNU_convert{long long unsigned int,unsigned,64@[2c]}, stack_value} + [7d] function 'main'@80482f0 + frame_base: {call_frame_cfa {bregx(4,4)}} +EOF + +testrun_compare ${abs_top_builddir}/tests/varlocs -e testfile_implicit_value <<\EOF +module 'testfile_implicit_value' +[b] CU 'implicit_value.c'@0 + [25] function 'foo'@80483f0 + frame_base: {call_frame_cfa {bregx(4,4)}} + [3e] variable 'a' + [80483f0,80483f6) {implicit_value(8){0200000000000000}, piece(8), implicit_value(8){1500000000000000}, piece(8)} + [86] function 'main'@80482f0 + frame_base: {call_frame_cfa {bregx(4,4)}} +EOF + +testrun_compare ${abs_top_builddir}/tests/varlocs -e testfile_entry_value <<\EOF +module 'testfile_entry_value' +[b] CU 'entry_value.c'@0 + [29] function 'foo'@400500 + frame_base: {call_frame_cfa {bregx(7,8)}} + [4a] parameter 'x' + [400500,400504) {reg5} + [55] parameter 'y' + [400500,400504) {reg4} + [68] function 'bar'@400510 + frame_base: {call_frame_cfa {bregx(7,8)}} + [89] parameter 'x' + [400510,40051c) {reg5} + [40051c,40052b) {reg6} + [40052b,400531) {GNU_entry_value(1) {reg5}, stack_value} + [96] parameter 'y' + [400510,40051c) {reg4} + [40051c,40052a) {reg3} + [40052a,400531) {GNU_entry_value(1) {reg4}, stack_value} + [a3] variable 'z' + [400524,400528) {reg0} + [400528,400529) {reg12} + [400529,40052e) {breg0(0), breg12(0), plus, stack_value} + [40052e,400531) {reg0} + [e9] function 'main'@400400 + frame_base: {call_frame_cfa {bregx(7,8)}} + [10a] parameter 'argc' + [400400,400406) {reg5} + [400406,40040a) {breg5(-1), stack_value} + [40040a,40040b) {GNU_entry_value(1) {reg5}, stack_value} + [119] parameter 'argv' + [400400,400403) {reg4} + [400403,40040b) {GNU_entry_value(1) {reg4}, stack_value} +EOF + +testrun_compare ${abs_top_builddir}/tests/varlocs -e testfile_parameter_ref <<\EOF +module 'testfile_parameter_ref' +[b] CU 'parameter_ref.c'@0 + [77] function 'foo'@400510 + frame_base: {call_frame_cfa {bregx(7,8)}} + [92] parameter 'x' + [400510,400523) {reg5} + [99] parameter 'y' + [400510,400523) {GNU_parameter_ref[42], stack_value} + [a5] variable 'a' + [400510,400523) {breg5(0), lit1, shl, stack_value} + [b0] variable 'b' + [400510,400523) {GNU_parameter_ref[42], lit1, shl, stack_value} + [be] variable 'c' + <constant value> + [c4] parameter 'z' + <constant value> + [cb] function 'main'@400400 + frame_base: {call_frame_cfa {bregx(7,8)}} + [ec] parameter 'x' + [400400,400408) {reg5} + [400408,400421) {reg3} + [400421,400423) {GNU_entry_value(1) {reg5}, stack_value} + [f9] parameter 'argv' + [400400,400408) {reg4} + [400408,400423) {GNU_entry_value(1) {reg4}, stack_value} +EOF + +testrun_compare ${abs_top_builddir}/tests/varlocs -e testfile_implicit_pointer <<\EOF +module 'testfile_implicit_pointer' +[b] CU 'implicit_pointer.c'@0 + [29] function 'foo'@400500 + frame_base: {call_frame_cfa {bregx(7,8)}} + [4a] parameter 'i' + [400500,400503) {reg5} + [55] variable 'p' + [400500,400503) {GNU_implicit_pointer([4a],0) {reg5}} + [73] function 'main'@400400 + frame_base: {call_frame_cfa {bregx(7,8)}} +EOF + + +exit 0 diff --git a/tests/testfile_const_type.bz2 b/tests/testfile_const_type.bz2 new file mode 100755 index 0000000000000000000000000000000000000000..fea4a9cbdd3348714686f43c207fc4440f65e0a4 GIT binary patch literal 3353 zcmV+!4d(JfT4*^jL0KkKSvV2J%K!=VfB*mg|NsC0|NsC0|L_0*-}L|f|NZTE9e;oR zd;kA`|L@=nG88^}QfGH{sS?QTn%YwVimGo-%S~+!2!a|+YGl(ull4z2o<z~K)YH_| z@C2Wz%4w&lJxmGcnFB$gh|tlH(WXGt$*5_g)WUi|^oOE)o}d8JPf%!RVg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uhO1X?^6HPO{k;#yAWH6eVq-l7EIQuLV^G z<q25`5?6#NMG+9HK+##KA)*;$YsF3_z0aHU#SIDd9FOI-W?XZe6eMpSfZ^oeFak5S zv3dzPyXFWF?2I%Pf)s31uQ7>&fKWOIL6Y?;byQ`%a1F7+YS|Ov7Vuve)f_t)n%Uv2 zH5BxlEQ#*Iu;a<m=3Snt%5c&X&S)eZfkp)xWbEqaYSXl-2(geb?{*Lgv;N*D8JgB$ z!q&LVpI>c-vA)GgeFcm2^f6!nAOivnA%YK(3le}aLkSBoB)mZhI3Yj+IVdnb`9Uom z^^eTd%{=lJf#b<C4c+XPNn#*rN;~5m%G4LJb+tMAMd+AhC?h1cOjXGd<v?}*2r;xh z>zh7d<F$*+;MPaFx*SR-R2-cYnmzP)vAb<(9$hZko)d-SCQG&x0yTMztJxN>k_;um zm9<uLm%wzN5>djX;GEiKS9;GDN&rZsV*HGsm#eXp8at;Jcumo<>}$ltTr0i3rOg;7 zW_v19W@1$+IhmSG;|*{LcEs(h!nti}(5g|IXtjI+iG1WzI8PQi4Y@SR0}+;xSvDtA z{H9r)`$_{m=Zu&&phA($ztzPt0K;=G)I1@5@r${c6tu=X^P#2u1SwvJ0w7OR*I$wn zEUYRXaR64Sr~gD#V^&PTxWaUiu-i$Xx&gSi0lGb&6Fm;er@5dQdVoqfG$&&lo7!-7 z>UXZm)wTmsn!*G-lP|}PqN3HTjOF_QjSPb&Jled-25pTblv}~d_Y&;N<?bdszX8@< zQwvCnU5P%eBmv5ZMKBw($d7f}G_md~6`ss%>~MHNck;~&bUDcu41tkQwrr}pbEV|H z!g0Ue<#lVsh41rO&gY>D05|4w6reXU(x|}-LnHI8$b)5GSD`fpodY>-sTeFA>!?tu jhN3@%c9nNZblcKxyUWcNH+Lhm|Ha&qP81{#1aWe}#c>8y
literal 0 HcmV?d00001
diff --git a/tests/testfile_const_type.c b/tests/testfile_const_type.c new file mode 100644 index 0000000..259007d --- /dev/null +++ b/tests/testfile_const_type.c @@ -0,0 +1,14 @@ +// gcc -m32 -g -O2 -o const_type const_type.c + +__attribute__((noinline, noclone)) int +f1 (long long d) +{ + long long w = d / 0x1234567800000LL; + return w; +} + +int +main () +{ + return f1 (4LL) - f1 (4LL); +} diff --git a/tests/testfile_entry_value.bz2 b/tests/testfile_entry_value.bz2 new file mode 100755 index 0000000000000000000000000000000000000000..fde86c6186cac0d7154366faaf2f0c786706b365 GIT binary patch literal 3309 zcmV<J3=;D~T4*^jL0KkKS!pm4{{RdnfB*mg|Ns8~|NsC0|G)qL-~Hde@7%}8O;G>M zckbVRZ+qYiPp~!}0B1d}HRktp?rt}9+nhUfFen|?Zt&2PLTR9ARQ6Ler?O3?$n@0F zrlZ1-Q%9(NsA>9)k+nTT)csROq%veZOpKdQHjvFg8favGnkkx|kOBITGH3vLnhexv z4FsA1hMEk4GyzSbdSx*^LFF)-XaE2VgCV0qpa1|G00E((Gynhq007Vc&`gmj<a$zh zJdvbn>VA~;83brCG{`g>dP5qR0i)FoG7T6IG-6_81Jrs(L)0|Mgcu`D85o$20iZGz z)KD4#000004FCWD000000000000000000002AUvfXaEfj0BB?~0MU@h28{+lV1Q%| zGyn!hhJa`Q4FDPdXaE7A05k>(5+unJ5@SzMFw;q<o{6-KOw`EG2cl`C5YtRR^$jp4 zO*Cj}v_Jr88USga8U~Dj4FCWD8*D{(qfs?tZZEPpo+{61^aplYXmkh#9wP_=D9FPJ z7|0Fd3a{(tpqpcCZ8Xr>DjIY^C~|4U5bT+P4%F-{91^#&eH1v+NEwybTxL1xTt>Cz ztZFfy#}%Q8`tGR8FgGEL_4lK#!h@GZ4kj-XPDf$OfIhV08pN*KIdqlT&{i_Zne4_$ zphV!&7`_g`Wa677kta5rnTXJ-m19O>L<pOjwxkmv&X%Ne!>Em-R%AqP=`);ioh51G zkVwq|g9b)sO(qy$OPAVSWzUZ{3H+RF{5(uKh21^^6*xdQ5E`PID-8_5G5>hxW-+Re z0?7c*RPN@>e=0?|Xcda2b7*aET75%lQ^JJ)%+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cxR{M#!7SNLR-*rQBY%EoE$KX<-L2d8PsplhF-?@pRJe2%`CAf zn9|A{?mqVW)>I&}?;GytEl?SiUkF6LnJBg^ip=cIOx236X{3SMH?tpUxq}=*-KR3g ztI0|lPqDDgwOww@aHUgaKCcUXr?tV@Ov~mweN2*W9GI=%o!ha0kU01VVyH0Sj4lO^ zomqp<S*sDl9+fIkvQSTsmi<424V7Mo3a^6?Z=GpfF#Q37!=;{N#%wS|Ape^7S~3-g rn`PuEfxz2)Xn?mML;!^eV1N8u0W93TN<9H{Kk;`YQ-uizlK~&_s=3tC
literal 0 HcmV?d00001
diff --git a/tests/testfile_entry_value.c b/tests/testfile_entry_value.c new file mode 100644 index 0000000..d2f232b --- /dev/null +++ b/tests/testfile_entry_value.c @@ -0,0 +1,19 @@ +// gcc -g -O2 -o entry_value entry_value.c +int __attribute__((noinline, noclone)) foo (int x, int y) +{ + return x + y; +} + +int __attribute__((noinline, noclone)) bar (int x, int y) +{ + int z; + z = foo (x, y); + z += foo (y, x); + return z; +} + +int +main (int argc, char **argv) +{ + return bar (argc + 1, argc - 1); +} diff --git a/tests/testfile_implicit_pointer.bz2 b/tests/testfile_implicit_pointer.bz2 new file mode 100755 index 0000000000000000000000000000000000000000..72f6a69447db5dab525ccfe2fc666b23e67fc6d8 GIT binary patch literal 2952 zcmV;33wQKFT4*^jL0KkKS)>T2FaQd`fB*mg|Ns8~|NsB@|L_0*-~a#r<kV)^K~(+Z z^6p>$|J&dR@369Vz+AfFsFtg8UC113g$H&v8fpkl1jLO`(kJ3Hr>4_MwNDCuskJsx z+J~t19;4KHk5d!H2kMX2JrhTwJwr#R(?Ina4^Ri8JtwB4N2#XLG#;jblgc)sqta=R zG$LqdBM8cRXo&Pl=*n$0^+%){88HlohCnoEX`lvxXblYmLqkJAGynhtKmY(T0BNBF zr9F~<N}r^e>Y6sDm}+_^OeReLGBjiv3=;{U3=xTt0iYTH&|)x}Vi`2kO*2r?0BMM1 zAY{pq44D81m?5AI003xW8fXS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<GSUUjl;dMYmUWj$iE^TudmJ6@@jTZqV49kq2TauHj1;iw{~Y zf0U#oAb8cMW>61qbnJ1VgtK>H(0R??mds+%S*izL{%{$al|&pPb+X%*{6cGz_xA-M zuj>s@T8;~7^bz)#Ig?vpb`Yb58tWsUY2dSy*zXikY&F_G<_&HAB;vEgY7MTEIQNj1 zcd)6#^j?Gx#bHBIE~bHThj&d}mJ#6Q8_^~)5y!eLY~FtpH(z<&@?%5l{tkE%szO~j y6qKq0kw4;zTv`ZWwp3LiN$}NAqEr%@en#Vy%v)2ex&NjAi@744C`eKSQy2iHMmZq>
literal 0 HcmV?d00001
diff --git a/tests/testfile_implicit_pointer.c b/tests/testfile_implicit_pointer.c new file mode 100644 index 0000000..d7e28a0 --- /dev/null +++ b/tests/testfile_implicit_pointer.c @@ -0,0 +1,12 @@ +// gcc -g -O2 -o implicit_pointer implicit_pointer.c + +static __attribute__((noinline, noclone)) int foo (int i) +{ + int *p = &i; + return *p; +} + +int main (void) +{ + return foo (23) - 23; +} diff --git a/tests/testfile_implicit_value.bz2 b/tests/testfile_implicit_value.bz2 new file mode 100755 index 0000000000000000000000000000000000000000..c365a99de0a23bcfc9c5b6721cca7c3d19c26356 GIT binary patch literal 2973 zcmV;O3u5#_T4*^jL0KkKSs}grV*m+ofB*mg|NsB@|NH;{|L_0*|NZ~&eDD2-4PAfs zeQxjnfA8Q55(clHBzLn8X0>NZQCnSspy#O7?iy+%LIDjl(^UNg^h^>xq{z)v!B0&S zO{C2s>NH@RBSgr^%}oK2XvEV-nqx_m$)YhBnKUsp85un$KxhL;sp+URA{izE4Gm9I z6!g&`Gz|fxL)0__)X|}l>UxHOpa3!f>Hq*}(?)<A2dFdv8UO$Q4Lv|=X^^IbO+7<3 z9+9D@Y8alAKn9HfWHbQK00000XaE2J0iXZ?0000000T7<Ay3rMrqtSiJs>?yfCC`W zpa1{>001-rk&tKr0MGyf5C8xg0000114BWe0MHD8&;V!*gG~SfKr%7_4FCWQG62v3 zGz@^y0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+`~~m za}tn|79|Kd)UuB%;RyVLWG^fNGe~tJAb=MZ3N_!@9S|V2cYh4yTC!t7)Bim+uQcKa z;r2R(BA?5ixmaT2=Cx8p<hDU}-OE$O2_kV%P~+y<9tdTU%U{anKBtC_&?F$VF4;u$ z5CULiyh9(TuavE_J@SV*ioTNwA}nKxLV65pfoY-`Pt{(q=rzqZ_@$5-lK2W)g)tsW z*{|`l`22fDZcc5Gy5)yttx(1iUjUNI3gyQTHBZ(EP|e$ii39)ueCD944<&hxf0N(# TE+o`rf8y>)rwS4TH@}Qv-n9nq
literal 0 HcmV?d00001
diff --git a/tests/testfile_implicit_value.c b/tests/testfile_implicit_value.c new file mode 100644 index 0000000..8885bbf --- /dev/null +++ b/tests/testfile_implicit_value.c @@ -0,0 +1,12 @@ +// gcc -m32 -g -O2 -o implicit_value implicit_value.c + +static __attribute__((noinline, noclone)) int foo () +{ + unsigned long long a[] = { 2, 21 }; + return a[0] * a[1]; +} + +int main (void) +{ + return foo () - 42; +} diff --git a/tests/testfile_parameter_ref.bz2 b/tests/testfile_parameter_ref.bz2 new file mode 100755 index 0000000000000000000000000000000000000000..8ff900de1422fa029cc52353439e5a17fc234842 GIT binary patch literal 3329 zcmV+c4gT^%T4*^jL0KkKSzX{*2mlN1|NsC0|NsC0|NsC0|L_0*-~0dn?9|jk#Zmv< zbKci~@B82jPrI)-k9%jK8_e9jt8Tg7cAEFDz3v@*y}jESH1{^V8W93CDf(#{Q%}lz zjZZXWlhaevMyI6on@OW(Jxq@fH9bd)c@xxV^){NGkQ+(rXbk|#>6F2Uh9R{EAoV>! z^#jUi^wi0qG$J)H)XAo%$vp{)Jt@6W`XqZ)^HlVKlR$ca27m(~0iXcT05kvq8UO&$ z000^QG|*|Oh$to`Z8B4Om?V0Ek?J0x(?OsEL8gr~#2NrSK+{0cpa1{>0iXZ?JwO9M z006>C5#=T|PbkyTlhDyel=MSQ8hV*Lr|O1488pyokQgA-OhZ640LTH5XaEmT(?)@& zfY2Hm06h?B$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^{IkT!d&0%T$YuB?KvvacZp>8qqM^uTN8K7#&_^QWI1N_^=>&VVqDH9)c_8 zRtyBNDTIBFg(?)NRSMY@S~y}AfdMUrh*u<30vkvVdks?(@Oi>oDlg6;6+?h35bVO3 z$QtY!yZTo`%HW@>;8az^Rt_mr)fnIjr2#~<XeFY6apQblaYn0ZP$+@~ARrAf@-G2G zgtL)#;ttz4+OT3uF4PXy1QtSsJ2aw>K;r+zwD;R`y0n`fCKlV~9E@G6w3LG+hF|9| zP;%+iGVq!)9QASM7~#?mgM{J!<kNR`ah?K@qR0Xejk{Tgv%jBM;pOWM80{4sb2_RV zP;~;aWFuU5F=ol3A=eXt*I^pl*T*dmUbs}NPGWkKByz_x4abkKaKH>3r4@B6A*;WL zy2$bSPUXzQv<{&TB~GJ<(%P|Vl<4^Q@O54xu1`0e8cd+|v8JNkMI!}9msZ`FcyA{+ zVss25suVqpThVxymw$g4h^AXqzRTFvtFNn2lUBn1Y2gfVzf?W4dw58RWwmW3oAO?S zO{eVY@%YIv`&dLJT0fl|W=*E)789@?_x&w%HE?Pkc-}?zWZ`jFb-L=Po~wT!XGh&V z)(0@dp6<cbXFgg>7kTAZw^sA?!6+szSYoL;Ofj#nH6sI@{mZj-P7yK(^}7n2Uw?J3 z$mn%8)_LBu91DDr9Kxg!=T*2s56uI?Oc{h0<tEZeY#Uw@X&olx8@2wb(U_}`Pkb)q Lig2MIyTGszUUcY{
literal 0 HcmV?d00001
diff --git a/tests/testfile_parameter_ref.c b/tests/testfile_parameter_ref.c new file mode 100644 index 0000000..7fe985f --- /dev/null +++ b/tests/testfile_parameter_ref.c @@ -0,0 +1,20 @@ +// gcc -g -O2 -o parameter_ref parameter_ref.c + +volatile int vv; + +/* Don't inline, but do allow clone to create specialized versions. */ +static __attribute__((noinline)) int +foo (int x, int y, int z) +{ + int a = x * 2; + int b = y * 2; + int c = z * 2; + vv++; + return x + z; +} + +int +main (int x, char **argv) +{ + return foo (x, 2, 3) + foo (x, 4, 3) + foo (x + 6, x, 3) + x; +} diff --git a/tests/varlocs.c b/tests/varlocs.c new file mode 100644 index 0000000..cda18b6 --- /dev/null +++ b/tests/varlocs.c @@ -0,0 +1,811 @@ +/* Test program for dwarf location functions. + Copyright (C) 2013 Red Hat, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see http://www.gnu.org/licenses/. */ + +#include <config.h> +#include <assert.h> +#include <argp.h> +#include <inttypes.h> +#include <errno.h> +#include ELFUTILS_HEADER(dw) +#include ELFUTILS_HEADER(dwfl) +#include <dwarf.h> +#include <stdio.h> +#include <stdlib.h> +#include <error.h> +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + +#include "../libdw/known-dwarf.h" + +// The Dwarf, Dwarf_CFIs and address bias of +// cfi table to adjust DWARF addresses against. +// Needed for DW_OP_call_frame_cfa. +static Dwarf *dw; +Dwarf_CFI *cfi_debug; +Dwarf_CFI *cfi_eh; +Dwarf_Addr cfi_eh_bias; + +// Whether the current function has a DW_AT_frame_base defined. +// Needed for DW_OP_fbreg. +bool has_frame_base; + +static void +print_die (Dwarf_Die *die, const char *what, int indent) +{ + Dwarf_Addr entrypc; + const char *name = dwarf_diename (die) ?: "<unknown>"; + if (dwarf_entrypc (die, &entrypc) == 0) + printf ("%*s[%" PRIx64 "] %s '%s'@%" PRIx64 "\n", indent * 2, "", + dwarf_dieoffset (die), what, name, entrypc); + else + printf ("%*s[%" PRIx64 "] %s '%s'\n", indent * 2, "", + dwarf_dieoffset (die), what, name); +} + +static const char * +dwarf_encoding_string (unsigned int code) +{ + static const char *const known[] = + { +#define ONE_KNOWN_DW_ATE(NAME, CODE) [CODE] = #NAME, + ALL_KNOWN_DW_ATE +#undef ONE_KNOWN_DW_ATE + }; + + if (likely (code < sizeof (known) / sizeof (known[0]))) + return known[code]; + + return NULL; +} + +/* BASE must be a base type DIE referenced by a typed DWARF expression op. */ +static void +print_base_type (Dwarf_Die *base) +{ + assert (dwarf_tag (base) == DW_TAG_base_type); + + Dwarf_Attribute encoding; + Dwarf_Word enctype; + if (dwarf_attr (base, DW_AT_encoding, &encoding) == NULL + || dwarf_formudata (&encoding, &enctype) != 0) + error (EXIT_FAILURE, 0, "base type without encoding"); + + Dwarf_Attribute bsize; + Dwarf_Word bits; + if (dwarf_attr (base, DW_AT_byte_size, &bsize) != NULL + && dwarf_formudata (&bsize, &bits) == 0) + bits *= 8; + else if (dwarf_attr (base, DW_AT_bit_size, &bsize) == NULL + || dwarf_formudata (&bsize, &bits) != 0) + error (EXIT_FAILURE, 0, "base type without byte or bit size"); + + printf ("{%s,%s,%" PRIu64 "@[%" PRIx64 "]}", + dwarf_diename (base), + dwarf_encoding_string (enctype), + bits, + dwarf_dieoffset (base)); +} + +static const char * +dwarf_opcode_string (unsigned int code) +{ + static const char *const known[] = + { +#define ONE_KNOWN_DW_OP_DESC(NAME, CODE, DESC) ONE_KNOWN_DW_OP (NAME, CODE) +#define ONE_KNOWN_DW_OP(NAME, CODE) [CODE] = #NAME, + ALL_KNOWN_DW_OP +#undef ONE_KNOWN_DW_OP +#undef ONE_KNOWN_DW_OP_DESC + }; + + if (likely (code < sizeof (known) / sizeof (known[0]))) + return known[code]; + + return NULL; +} + +// Forward reference for print_expr_block. +static void print_expr (Dwarf_Attribute *, Dwarf_Op *, Dwarf_Addr); + +static void +print_expr_block (Dwarf_Attribute *attr, Dwarf_Op *exprs, int len, + Dwarf_Addr addr) +{ + printf ("{"); + for (int i = 0; i < len; i++) + { + print_expr (attr, &exprs[i], addr); + printf ("%s", (i + 1 < len ? ", " : "")); + } + printf ("}"); +} + +static void +print_expr_block_addrs (Dwarf_Attribute *attr, + Dwarf_Addr begin, Dwarf_Addr end, + Dwarf_Op *exprs, int len) +{ + printf (" [%" PRIx64 ",%" PRIx64 ") ", begin, end); + print_expr_block (attr, exprs, len, begin); + printf ("\n"); +} + +static void +print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr) +{ + uint8_t atom = expr->atom; + const char *opname = dwarf_opcode_string (atom); + assert (opname != NULL); + + switch (atom) + { + case DW_OP_deref: + case DW_OP_dup: + case DW_OP_drop: + case DW_OP_over: + case DW_OP_swap: + case DW_OP_rot: + case DW_OP_xderef: + case DW_OP_abs: + case DW_OP_and: + case DW_OP_div: + case DW_OP_minus: + case DW_OP_mod: + case DW_OP_mul: + case DW_OP_neg: + case DW_OP_not: + case DW_OP_or: + case DW_OP_plus: + case DW_OP_shl: + case DW_OP_shr: + case DW_OP_shra: + case DW_OP_xor: + case DW_OP_eq: + case DW_OP_ge: + case DW_OP_gt: + case DW_OP_le: + case DW_OP_lt: + case DW_OP_ne: + case DW_OP_lit0 ... DW_OP_lit31: + case DW_OP_reg0 ... DW_OP_reg31: + case DW_OP_nop: + case DW_OP_stack_value: + /* No arguments. */ + printf ("%s", opname); + break; + + case DW_OP_form_tls_address: + /* No arguments. Special. Pops and address and pushes the + corresponding address in the current thread local + storage. Uses the thread local storage block of the defining + module (executable, shared library). */ + printf ("%s", opname); + break; + + case DW_OP_GNU_push_tls_address: + /* No arguments. Special. Not the same as DW_OP_form_tls_address. + Pops an offset into the current thread local strorage and + pushes back the actual address. */ + printf ("%s", opname); + break; + + case DW_OP_call_frame_cfa: + /* No arguments. Special. Pushes Call Frame Address as computed + by CFI data (dwarf_cfi_addrframe will fetch that info (either from + the .eh_frame or .debug_frame CFI) and dwarf_frame_cfa translatesr + the CFI instructions into a plain DWARF expression. + Never used in CFI itself. */ + + if (attr == NULL) + error (EXIT_FAILURE, 0, "%s used in CFI", opname); + + printf ("%s ", opname); + if (cfi_eh == NULL && cfi_debug == NULL) + error (EXIT_FAILURE, 0, "DW_OP_call_frame_cfa used but no cfi found."); + + Dwarf_Frame *frame; + if (dwarf_cfi_addrframe (cfi_eh, addr + cfi_eh_bias, &frame) != 0 + && dwarf_cfi_addrframe (cfi_debug, addr, &frame) != 0) + error (EXIT_FAILURE, 0, "dwarf_cfi_addrframe 0x%" PRIx64 ": %s", + addr, dwarf_errmsg (-1)); + + Dwarf_Op *cfa_ops; + size_t cfa_nops; + if (dwarf_frame_cfa (frame, &cfa_ops, &cfa_nops) != 0) + error (EXIT_FAILURE, 0, "dwarf_frame_cfa 0x%" PRIx64 ": %s", + addr, dwarf_errmsg (-1)); + if (cfa_nops < 1) + error (EXIT_FAILURE, 0, "dwarf_frame_cfa no ops"); + print_expr_block (NULL, cfa_ops, cfa_nops, 0); + free (frame); + break; + + case DW_OP_push_object_address: + /* No arguments. Special. Pushes object address explicitly. + Normally only done implicitly by DW_AT_data_member_location. + Never used in CFI. */ + if (attr == NULL) + error (EXIT_FAILURE, 0, "%s used in CFI", opname); + printf ("%s", opname); + break; + + case DW_OP_addr: + /* 1 address argument. */ + printf ("%s(0x%" PRIx64 ")", opname, (Dwarf_Addr) expr->number); + break; + + case DW_OP_const1u: + case DW_OP_const2u: + case DW_OP_const4u: + case DW_OP_const8u: + case DW_OP_constu: + case DW_OP_pick: + case DW_OP_plus_uconst: + case DW_OP_regx: + case DW_OP_piece: + case DW_OP_deref_size: + case DW_OP_xderef_size: + /* 1 numeric unsigned argument. */ + printf ("%s(%" PRIu64 ")", opname, expr->number); + break; + + case DW_OP_call2: + case DW_OP_call4: + case DW_OP_call_ref: + /* 1 DIE offset argument for more ops in location attribute of DIE. + Never used in CFI. */ + { + if (attr == NULL) + error (EXIT_FAILURE, 0, "%s used in CFI", opname); + + Dwarf_Attribute call_attr; + if (dwarf_getlocation_attr (attr, expr, &call_attr) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_attr for %s error %s", + opname, dwarf_errmsg (-1)); + + Dwarf_Die call_die; + if (dwarf_getlocation_die (attr, expr, &call_die) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_die for %s error %s", + opname, dwarf_errmsg (-1)); + + Dwarf_Op *call_ops; + size_t call_len; + if (dwarf_getlocation (&call_attr, &call_ops, &call_len) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation for entry: %s", + dwarf_errmsg (-1)); + + printf ("%s([%" PRIx64 "]) ", opname, dwarf_dieoffset (&call_die)); + print_expr_block (&call_attr, call_ops, call_len, addr); + } + break; + + case DW_OP_const1s: + case DW_OP_const2s: + case DW_OP_const4s: + case DW_OP_const8s: + case DW_OP_consts: + case DW_OP_skip: + case DW_OP_bra: + case DW_OP_breg0 ... DW_OP_breg31: + /* 1 numeric signed argument. */ + printf ("%s(%" PRId64 ")", opname, (Dwarf_Sword) expr->number); + break; + + case DW_OP_fbreg: + /* 1 numeric signed argument. Offset from frame base. */ + if (attr == NULL) + error (EXIT_FAILURE, 0, "%s used in CFI", opname); + + if (! has_frame_base) + error (EXIT_FAILURE, 0, "DW_OP_fbreg used without a frame base"); + + printf ("%s(%" PRId64 ")", opname, (Dwarf_Sword) expr->number); + break; + + case DW_OP_bregx: + /* 2 arguments, unsigned register number, signed offset. */ + printf ("%s(%" PRIu64 ",%" PRId64 ")", opname, + expr->number, (Dwarf_Sword) expr->number2); + break; + + case DW_OP_bit_piece: + /* 2 arguments, unsigned size, unsigned offset. */ + printf ("%s(%" PRIu64 ",%" PRIu64 ")", opname, + expr->number, expr->number2); + break; + + case DW_OP_implicit_value: + /* Special, unsigned size plus block. */ + { + Dwarf_Attribute const_attr; + Dwarf_Block block; + if (dwarf_getlocation_attr (attr, expr, &const_attr) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_attr: %s", + dwarf_errmsg (-1)); + + if (dwarf_formblock (&const_attr, &block) != 0) + error (EXIT_FAILURE, 0, "dwarf_formblock: %s", + dwarf_errmsg (-1)); + + /* This is the "old" way. Check they result in the same. */ + Dwarf_Block block_impl; + if (dwarf_getlocation_implicit_value (attr, expr, &block_impl) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_implicit_value: %s", + dwarf_errmsg (-1)); + + assert (expr->number == block.length); + assert (block.length == block_impl.length); + printf ("%s(%" PRIu64 "){", opname, block.length); + for (size_t i = 0; i < block.length; i++) + { + printf ("%02x", block.data[i]); + assert (block.data[i] == block_impl.data[i]); + } + printf("}"); + } + break; + + case DW_OP_GNU_implicit_pointer: + /* Special, DIE offset, signed offset. Referenced DIE has a + location or const_value attribute. */ + { + if (attr == NULL) + error (EXIT_FAILURE, 0, "%s used in CFI", opname); + + Dwarf_Attribute attrval; + if (dwarf_getlocation_implicit_pointer (attr, expr, &attrval) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_implicit_pointer: %s", + dwarf_errmsg (-1)); + + // Sanity check, results should be the same. + Dwarf_Attribute attrval2; + if (dwarf_getlocation_attr (attr, expr, &attrval2) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_attr: %s", + dwarf_errmsg (-1)); + + assert (dwarf_whatattr (&attrval) == dwarf_whatattr (&attrval2)); + assert (dwarf_whatform (&attrval) == dwarf_whatform (&attrval2)); + // In theory two different valp pointers could point to the same + // value. But here we really expect them to be the equal. + assert (attrval.valp == attrval2.valp); + + Dwarf_Die impl_die; + if (dwarf_getlocation_die (attr, expr, &impl_die) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_due: %s", + dwarf_errmsg (-1)); + + printf ("%s([%" PRIx64 "],%" PRId64 ") ", opname, + dwarf_dieoffset (&impl_die), expr->number2); + + if (dwarf_whatattr (&attrval) == DW_AT_const_value) + printf ("<constant value>"); // Lookup type... + else + { + // Lookup the location description at the current address. + Dwarf_Op *exprval; + size_t exprval_len; + int locs = dwarf_getlocation_addr (&attrval, addr, + &exprval, &exprval_len, 1); + if (locs == 0) + printf ("<no location>"); // XXX should that be flagged? + else if (locs == 1) + print_expr_block (&attrval, exprval, exprval_len, addr); + else + error (EXIT_FAILURE, 0, + "dwarf_getlocation_addr attrval at addr 0x%" PRIx64 + ", locs (%d): %s", addr, locs, dwarf_errmsg (-1)); + } + } + break; + + case DW_OP_GNU_entry_value: + /* Special, unsigned size plus expression block. All registers + inside the block should be interpreted as they had on + entering the function. dwarf_getlocation_attr will return an + attribute containing the block as locexpr which can be + retrieved with dwarf_getlocation. */ + { + Dwarf_Attribute entry_attr; + if (dwarf_getlocation_attr (attr, expr, &entry_attr) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_attr: %s", + dwarf_errmsg (-1)); + + Dwarf_Op *entry_ops; + size_t entry_len; + if (dwarf_getlocation (&entry_attr, &entry_ops, &entry_len) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation for entry: %s", + dwarf_errmsg (-1)); + + printf ("%s(%zd) ", opname, entry_len); + print_expr_block (attr, entry_ops, entry_len, addr); + } + break; + + case DW_OP_GNU_parameter_ref: + /* Special, unsigned CU relative DIE offset pointing to a + DW_TAG_formal_parameter. The value that parameter had at the + call site of the current function will be put on the DWARF + stack. The value can be retrieved by finding the + DW_TAG_GNU_call_site_parameter which has as + DW_AT_abstract_origin the same formal parameter DIE. */ + { + Dwarf_Die param; + if (dwarf_getlocation_die (attr, expr, ¶m) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_die: %s", + dwarf_errmsg (-1)); + // XXX actually lookup DW_TAG_GNU_call_site_parameter + printf ("%s[%" PRIx64 "]", opname, dwarf_dieoffset (¶m)); + assert (expr->number == dwarf_cuoffset (¶m)); + assert (dwarf_tag (¶m) == DW_TAG_formal_parameter); + } + break; + + case DW_OP_GNU_convert: + case DW_OP_GNU_reinterpret: + /* Special, unsigned CU relative DIE offset pointing to a + DW_TAG_base_type. Pops a value, converts or reinterprets the + value to the given type. When the argument is zero the value + becomes untyped again. */ + { + Dwarf_Die type; + Dwarf_Off off = expr->number; + if (off != 0) + { + if (dwarf_getlocation_die (attr, expr, &type) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_die: %s", + dwarf_errmsg (-1)); + off = dwarf_dieoffset (&type); + assert (expr->number == dwarf_cuoffset (&type)); + printf ("%s", opname); + print_base_type (&type); + } + else + printf ("%s[%" PRIu64 "]", opname, off); + + } + break; + + case DW_OP_GNU_regval_type: + /* Special, unsigned register number plus unsigned CU relative + DIE offset pointing to a DW_TAG_base_type. */ + { + Dwarf_Die type; + if (dwarf_getlocation_die (attr, expr, &type) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_die: %s", + dwarf_errmsg (-1)); + assert (expr->number2 == dwarf_cuoffset (&type)); + // XXX check size against base_type size? + printf ("%s(reg%" PRIu64 ")", opname, expr->number); + print_base_type (&type); + } + break; + + case DW_OP_GNU_deref_type: + /* Special, unsigned size plus unsigned CU relative DIE offset + pointing to a DW_TAG_base_type. */ + { + Dwarf_Die type; + if (dwarf_getlocation_die (attr, expr, &type) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_die: %s", + dwarf_errmsg (-1)); + assert (expr->number2 == dwarf_cuoffset (&type)); + // XXX check size against base_type size? + printf ("%s(%" PRIu64 ")", opname, expr->number); + print_base_type (&type); + } + break; + + case DW_OP_GNU_const_type: + /* Special, unsigned CU relative DIE offset pointing to a + DW_TAG_base_type, an unsigned size length plus a block with + the constant value. */ + { + Dwarf_Die type; + if (dwarf_getlocation_die (attr, expr, &type) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_die: %s", + dwarf_errmsg (-1)); + assert (expr->number == dwarf_cuoffset (&type)); + + Dwarf_Attribute const_attr; + if (dwarf_getlocation_attr (attr, expr, &const_attr) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_attr for type: %s", + dwarf_errmsg (-1)); + + Dwarf_Block block; + if (dwarf_formblock (&const_attr, &block) != 0) + error (EXIT_FAILURE, 0, "dwarf_formblock for type: %s", + dwarf_errmsg (-1)); + + printf ("%s", opname); + print_base_type (&type); + printf ("(%" PRIu64 ")[", block.length); + for (size_t i = 0; i < block.length; i++) + printf ("%02x", block.data[i]); + printf("]"); + } + break; + + default: + error (EXIT_FAILURE, 0, "unhandled opcode: DW_OP_%s (0x%x)", + opname, atom); + } +} + +/* Get all variables and print their value expressions. */ +static void +print_varlocs (Dwarf_Die *funcdie) +{ + // Display frame base for function if it exists. + // Should be used for DW_OP_fbreg. + has_frame_base = dwarf_hasattr (funcdie, DW_AT_frame_base); + if (has_frame_base) + { + Dwarf_Attribute fb_attr; + if (dwarf_attr (funcdie, DW_AT_frame_base, &fb_attr) == NULL) + error (EXIT_FAILURE, 0, "dwarf_attr fb: %s", dwarf_errmsg (-1)); + + Dwarf_Op *fb_expr; + size_t fb_exprlen; + if (dwarf_getlocation (&fb_attr, &fb_expr, &fb_exprlen) == 0) + { + // Covers all of function. + Dwarf_Addr entrypc; + if (dwarf_entrypc (funcdie, &entrypc) != 0) + error (EXIT_FAILURE, 0, "dwarf_entrypc: %s", dwarf_errmsg (-1)); + + printf (" frame_base: "); + if (entrypc == 0) + printf ("XXX zero address"); // XXX bad DWARF? + else + print_expr_block (&fb_attr, fb_expr, fb_exprlen, entrypc); + printf ("\n"); + } + else + { + Dwarf_Addr base, start, end; + ptrdiff_t off = 0; + printf (" frame_base:\n"); + while ((off = dwarf_getlocations (&fb_attr, off, &base, + &start, &end, + &fb_expr, &fb_exprlen)) > 0) + { + printf (" (%" PRIx64 ",%" PRIx64 ") ", start, end); + print_expr_block (&fb_attr, fb_expr, fb_exprlen, start); + printf ("\n"); + } + + if (off < 0) + error (EXIT_FAILURE, 0, "dwarf_getlocations fb: %s", + dwarf_errmsg (-1)); + } + } + else if (dwarf_tag (funcdie) == DW_TAG_inlined_subroutine) + { + // See whether the subprogram we are inlined into has a frame + // base we should use. + Dwarf_Die *scopes; + int n = dwarf_getscopes_die (funcdie, &scopes); + if (n <= 0) + error (EXIT_FAILURE, 0, "dwarf_getscopes_die: %s", dwarf_errmsg (-1)); + + while (n-- > 0) + if (dwarf_tag (&scopes[n]) == DW_TAG_subprogram + && dwarf_hasattr (&scopes[n], DW_AT_frame_base)) + { + has_frame_base = true; + break; + } + free (scopes); + } + + if (! dwarf_haschildren (funcdie)) + return; + + Dwarf_Die child; + int res = dwarf_child (funcdie, &child); + if (res < 0) + error (EXIT_FAILURE, 0, "dwarf_child: %s", dwarf_errmsg (-1)); + + /* We thought there was a child, but the child list was actually + empty. This isn't technically an error in the DWARF, but it is + certainly non-optimimal. */ + if (res == 1) + return; + + do + { + int tag = dwarf_tag (&child); + if (tag == DW_TAG_variable || tag == DW_TAG_formal_parameter) + { + const char *what = tag == DW_TAG_variable ? "variable" : "parameter"; + print_die (&child, what, 2); + + if (dwarf_hasattr (&child, DW_AT_location)) + { + Dwarf_Attribute attr; + if (dwarf_attr (&child, DW_AT_location, &attr) == NULL) + error (EXIT_FAILURE, 0, "dwarf_attr: %s", dwarf_errmsg (-1)); + + Dwarf_Op *expr; + size_t exprlen; + if (dwarf_getlocation (&attr, &expr, &exprlen) == 0) + { + // Covers all ranges of the function. + // Evaluate the expression block for each range. + ptrdiff_t offset = 0; + Dwarf_Addr base, begin, end; + do + { + offset = dwarf_ranges (funcdie, offset, &base, + &begin, &end); + if (offset < 0) + error (EXIT_FAILURE, 0, "dwarf_ranges: %s", + dwarf_errmsg (-1)); + + if (offset > 0) + { + if (exprlen == 0) + printf (" (%" + PRIx64 ",%" PRIx64 + ") <empty expression>\n", begin, end); + else + print_expr_block_addrs (&attr, begin, end, + expr, exprlen); + } + } + while (offset > 0); + + if (offset < 0) + error (EXIT_FAILURE, 0, "dwarf_ranges: %s", + dwarf_errmsg (-1)); + } + else + { + Dwarf_Addr base, begin, end; + ptrdiff_t offset = 0; + while ((offset = dwarf_getlocations (&attr, offset, + &base, &begin, &end, + &expr, &exprlen)) > 0) + if (begin >= end) + printf (" (%" PRIx64 ",%" PRIx64 + ") <empty range>\n", begin, end); // XXX report? + else + print_expr_block_addrs (&attr, begin, end, + expr, exprlen); + + if (offset < 0) + error (EXIT_FAILURE, 0, "dwarf_getlocations: %s", + dwarf_errmsg (-1)); + } + } + else if (dwarf_hasattr (&child, DW_AT_const_value)) + { + printf (" <constant value>\n"); // Lookup type and print. + } + else + { + printf (" <no value>\n"); + } + } + } + while (dwarf_siblingof (&child, &child) == 0); +} + +static int +handle_instance (Dwarf_Die *funcdie, void *arg __attribute__ ((unused))) +{ + print_die (funcdie, "inlined function", 1); + print_varlocs (funcdie); + + return DWARF_CB_OK; +} + +static int +handle_function (Dwarf_Die *funcdie, void *arg __attribute__((unused))) +{ + if (dwarf_func_inline (funcdie) > 0) + { + // abstract inline definition, find all inlined instances. + + // Note this is convenient for listing all instances together + // so you can easily compare the location expressions describing + // the variables and parameters, but it isn't very efficient + // since it will walk the DIE tree multiple times. + if (dwarf_func_inline_instances (funcdie, &handle_instance, NULL) != 0) + error (EXIT_FAILURE, 0, "dwarf_func_inline_instances: %s", + dwarf_errmsg (-1)); + } + else + { + // Contains actual code, not just a declaration? + Dwarf_Addr entrypc; + if (dwarf_entrypc (funcdie, &entrypc) == 0) + { + print_die (funcdie, "function", 1); + print_varlocs (funcdie); + } + } + + return DWARF_CB_OK; +} + +int +main (int argc, char *argv[]) +{ + int remaining; + Dwfl *dwfl; + (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &remaining, + &dwfl); + assert (dwfl != NULL); + + Dwarf_Die *cu = NULL; + Dwarf_Addr dwbias; + while ((cu = dwfl_nextcu (dwfl, cu, &dwbias)) != NULL) + { + /* Only walk actual compile units (not partial units) that + contain code. */ + Dwarf_Addr cubase; + if (dwarf_tag (cu) == DW_TAG_compile_unit + && dwarf_lowpc (cu, &cubase) == 0) + { + Dwfl_Module *mod = dwfl_cumodule (cu); + Dwarf_Addr modbias; + dw = dwfl_module_getdwarf (mod, &modbias); + assert (dwbias == modbias); + + const char *mainfile; + const char *modname = dwfl_module_info (mod, NULL, + NULL, NULL, + NULL, NULL, + &mainfile, + NULL); + if (modname == NULL) + error (EXIT_FAILURE, 0, "dwfl_module_info: %s", dwarf_errmsg (-1)); + + const char *name = (modname[0] != '\0' + ? modname + : basename (mainfile)); + printf ("module '%s'\n", name); + print_die (cu, "CU", 0); + + Dwarf_Addr elfbias; + Elf *elf = dwfl_module_getelf (mod, &elfbias); + + // CFI. We need both since sometimes neither is complete. + cfi_debug = dwarf_getcfi (dw); // No bias needed, same file. + cfi_eh = dwarf_getcfi_elf (elf); + cfi_eh_bias = dwbias - elfbias; + + // Get the actual CU DIE and walk all functions inside it. + Dwarf_Die cudie; + uint8_t offsize; + uint8_t addrsize; + if (dwarf_diecu (cu, &cudie, &addrsize, &offsize) == NULL) + error (EXIT_FAILURE, 0, "dwarf_diecu %s", dwarf_errmsg (-1)); + + if (dwarf_getfuncs (cu, handle_function, NULL, 0) != 0) + error (EXIT_FAILURE, 0, "dwarf_getfuncs %s", + dwarf_errmsg (-1)); + } + } + + dwfl_end (dwfl); + return 0; +}
elfutils-devel@lists.fedorahosted.org