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 <[email protected]>
---
 libdwfl/ChangeLog            |  5 +++++
 libdwfl/dwfl_module_getsrc.c |  8 ++++----
 tests/ChangeLog              |  7 +++++++
 tests/addrscopes.c           |  6 +++---
 tests/funcscopes.c           |  6 +++---
 tests/run-addrscopes.sh      | 10 +++++-----
 tests/run-funcscopes.sh      |  6 +++---
 7 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 69e59a6..6b51880 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,8 @@
+2014-12-27  Mark Wielaard  <[email protected]>
+
+       * dwfl_module_getsrc.c (dwfl_module_getsrc): Never match a line that
+       has end_sequence set.
+
 2014-12-19  Mark Wielaard  <[email protected]>
 
        * dwfl_module_getdwarf.c (find_symtab): Always try find_dynsym last.
diff --git a/libdwfl/dwfl_module_getsrc.c b/libdwfl/dwfl_module_getsrc.c
index f6d8839..f7e340b 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 6dd553b..b749899 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,10 @@
+2014-12-27  Mark Wielaard  <[email protected]>
+
+       * 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.
+
 2014-12-26  Mark Wielaard  <[email protected]>
 
        * run-test-archive64.sh: Add nm test.
diff --git a/tests/addrscopes.c b/tests/addrscopes.c
index fca61d3..2285d2c 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 720ff3b..55cb4fa 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 4f5c9d7..8f1bf0e 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 d236f5c..367729a 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
 
-- 
2.1.0

Reply via email to