From: Mark Wielaard Date: Sat, 27 Dec 2014 15:16:29 +0000 (+0100) Subject: libdwfl: dwfl_module_getsrc should never match end_sequence line. X-Git-Tag: elfutils-0.162~129 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f8198f2322b93dea4efbcf491b073a89e8aab1bf;p=thirdparty%2Felfutils.git libdwfl: dwfl_module_getsrc should never match end_sequence line. The line with end_sequence set has an address outside the current line sequence. An end_sequence line has no other useful information except marking the address as out of range. Two tests, addrscopes and funcscopes, depended on matching the end_sequence line. But that was because they included the high_pc address in the scope. However the high_pc attributes has as address the first location past the range associated with a given DIE. Adjust the tests to use high_pc - 1 as end of the scope. Signed-off-by: Mark Wielaard --- diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 4dda62af3..5a9757817 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,8 @@ +2014-12-27 Mark Wielaard + + * dwfl_module_getsrc.c (dwfl_module_getsrc): Never match a line that + has end_sequence set. + 2015-01-04 Mark Wielaard * cu.c (intern_cu): Store result and return directly when finding diff --git a/libdwfl/dwfl_module_getsrc.c b/libdwfl/dwfl_module_getsrc.c index f6d883903..f7e340bc6 100644 --- a/libdwfl/dwfl_module_getsrc.c +++ b/libdwfl/dwfl_module_getsrc.c @@ -64,11 +64,11 @@ dwfl_module_getsrc (Dwfl_Module *mod, Dwarf_Addr addr) l = idx; } - /* The last line which is less than or equal to addr is what we want, - except with an end_sequence which can only be strictly equal. */ + /* The last line which is less than or equal to addr is what + we want, unless it is the end_sequence which is after the + current line sequence. */ Dwarf_Line *line = &lines->info[l]; - if (line->addr == addr - || (! line->end_sequence && line->addr < addr)) + if (! line->end_sequence && line->addr <= addr) return &cu->lines->idx[l]; } diff --git a/tests/ChangeLog b/tests/ChangeLog index c05e80793..b81e83c1a 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,10 @@ +2014-12-27 Mark Wielaard + + * addrscopes.c (handle_address): Last address in scope is highpc - 1. + * funcscopes.c (handle_function): Likewise. + * run-addrscopes.sh: Adjust last address in scope. + * run-funcscopes.sh: Likewise. + 2015-01-07 Mark Wielaard * run-addrcfi.sh: Add test for ppc32 eh_frame_hdr address search. diff --git a/tests/addrscopes.c b/tests/addrscopes.c index fca61d33d..2285d2ca9 100644 --- a/tests/addrscopes.c +++ b/tests/addrscopes.c @@ -1,5 +1,5 @@ /* Test program for dwarf_getscopes. - Copyright (C) 2005 Red Hat, Inc. + Copyright (C) 2005, 2014 Red Hat, Inc. This file is part of elfutils. This file is free software; you can redistribute it and/or modify @@ -125,10 +125,10 @@ handle_address (GElf_Addr pc, Dwfl *dwfl) lowpc += cubias; highpc += cubias; Dwfl_Line *loline = dwfl_getsrc (dwfl, lowpc); - Dwfl_Line *hiline = dwfl_getsrc (dwfl, highpc); + Dwfl_Line *hiline = dwfl_getsrc (dwfl, highpc - 1); paddr (": ", lowpc, loline); if (highpc != lowpc) - paddr (" .. ", lowpc, hiline == loline ? NULL : hiline); + paddr (" .. ", highpc - 1, hiline == loline ? NULL : hiline); } puts (""); diff --git a/tests/funcscopes.c b/tests/funcscopes.c index 720ff3b98..55cb4facd 100644 --- a/tests/funcscopes.c +++ b/tests/funcscopes.c @@ -1,5 +1,5 @@ /* Test program for dwarf_getscopes. - Copyright (C) 2005 Red Hat, Inc. + Copyright (C) 2005, 2014 Red Hat, Inc. This file is part of elfutils. This file is free software; you can redistribute it and/or modify @@ -153,10 +153,10 @@ handle_function (Dwarf_Die *funcdie, void *arg) lowpc += a->dwbias; highpc += a->dwbias; Dwfl_Line *loline = dwfl_getsrc (a->dwfl, lowpc); - Dwfl_Line *hiline = dwfl_getsrc (a->dwfl, highpc); + Dwfl_Line *hiline = dwfl_getsrc (a->dwfl, highpc - 1); paddr (": ", lowpc, loline); if (highpc != lowpc) - paddr (" .. ", lowpc, hiline == loline ? NULL : hiline); + paddr (" .. ", highpc - 1, hiline == loline ? NULL : hiline); } puts (""); diff --git a/tests/run-addrscopes.sh b/tests/run-addrscopes.sh index 4f5c9d7fc..8f1bf0e36 100755 --- a/tests/run-addrscopes.sh +++ b/tests/run-addrscopes.sh @@ -1,5 +1,5 @@ #! /bin/sh -# Copyright (C) 2005 Red Hat, Inc. +# Copyright (C) 2005, 2014 Red Hat, Inc. # This file is part of elfutils. # # This file is free software; you can redistribute it and/or modify @@ -21,9 +21,9 @@ testfiles testfile22 testrun_compare ${abs_builddir}/addrscopes -e testfile22 0x8048353 <<\EOF 0x8048353: - tests/foo.c (0x11): 0x8048348 (tests/foo.c:5) .. 0x804837e (tests/foo.c:16) + tests/foo.c (0x11): 0x8048348 (tests/foo.c:5) .. 0x804837c (tests/foo.c:16) global [ be] - function (0x2e): 0x8048348 (tests/foo.c:5) .. 0x804835b (tests/foo.c:14) + function (0x2e): 0x8048348 (tests/foo.c:5) .. 0x8048359 (tests/foo.c:11) local [ 8f] EOF @@ -32,8 +32,8 @@ test_cleanup testfiles testfile24 testrun_compare ${abs_builddir}/addrscopes -e testfile24 0x804834e <<\EOF 0x804834e: - inline-test.c (0x11): 0x8048348 (/home/roland/build/stock-elfutils/inline-test.c:7) .. 0x8048364 (/home/roland/build/stock-elfutils/inline-test.c:16) - add (0x1d): 0x804834e (/home/roland/build/stock-elfutils/inline-test.c:3) .. 0x8048350 (/home/roland/build/stock-elfutils/inline-test.c:9) + inline-test.c (0x11): 0x8048348 (/home/roland/build/stock-elfutils/inline-test.c:7) .. 0x8048360 (/home/roland/build/stock-elfutils/inline-test.c:16) + add (0x1d): 0x804834e (/home/roland/build/stock-elfutils/inline-test.c:3) .. 0x804834f y [ 9d] x [ a2] x (abstract) diff --git a/tests/run-funcscopes.sh b/tests/run-funcscopes.sh index d236f5c3b..367729a70 100755 --- a/tests/run-funcscopes.sh +++ b/tests/run-funcscopes.sh @@ -1,5 +1,5 @@ #! /bin/sh -# Copyright (C) 2005 Red Hat, Inc. +# Copyright (C) 2005, 2014 Red Hat, Inc. # This file is part of elfutils. # # This file is free software; you can redistribute it and/or modify @@ -21,8 +21,8 @@ testfiles testfile25 testrun_compare ${abs_builddir}/funcscopes -e testfile25 incr <<\EOF testfile25: 0x8048000 .. 0x8049528 - inline-test.c (0x11): 0x8048348 (/home/roland/build/stock-elfutils/inline-test.c:7) .. 0x804834f (/home/roland/build/stock-elfutils/inline-test.c:9) - incr (0x2e): 0x8048348 (/home/roland/build/stock-elfutils/inline-test.c:7) .. 0x804834f (/home/roland/build/stock-elfutils/inline-test.c:9) + inline-test.c (0x11): 0x8048348 (/home/roland/build/stock-elfutils/inline-test.c:7) .. 0x804834e (/home/roland/build/stock-elfutils/inline-test.c:9) + incr (0x2e): 0x8048348 (/home/roland/build/stock-elfutils/inline-test.c:7) .. 0x804834e (/home/roland/build/stock-elfutils/inline-test.c:9) x [ 66] EOF