[02/14] libdw: Handle split DWARF in dwarf_entrypc

Message ID 4d980efe1a90d50a4aae2758bbed21c05b664ee4.1695837512.git.osandov@fb.com
State Committed
Headers
Series elfutils: DWARF package (.dwp) file support |

Commit Message

Omar Sandoval Sept. 27, 2023, 6:20 p.m. UTC
  From: Omar Sandoval <osandov@fb.com>

If a DIE has no DW_AT_entry_pc attribute, dwarf_entrypc looks for
DW_AT_low_pc in that DIE.  But for a split compilation unit DIE,
DW_AT_low_pc is in the corresponding skeleton DIE, so this fails.
dwarf_lowpc already handles this fallback, so use it instead.

Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 libdw/ChangeLog       |  1 +
 libdw/dwarf_entrypc.c | 12 +++++-------
 tests/ChangeLog       |  4 ++++
 tests/run-varlocs.sh  | 14 +++++++-------
 4 files changed, 17 insertions(+), 14 deletions(-)
  

Comments

Mark Wielaard Oct. 3, 2023, 4:10 p.m. UTC | #1
Hi Omar,

On Wed, 2023-09-27 at 11:20 -0700, Omar Sandoval wrote:
> From: Omar Sandoval <osandov@fb.com>
> 
> If a DIE has no DW_AT_entry_pc attribute, dwarf_entrypc looks for
> DW_AT_low_pc in that DIE.  But for a split compilation unit DIE,
> DW_AT_low_pc is in the corresponding skeleton DIE, so this fails.
> dwarf_lowpc already handles this fallback, so use it instead.

Nice find. Also interesting varlocs already "tested" for that and we
hadn't noticed before. Applied.

Thanks,

Mark
  

Patch

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 0014aeb1..af74ce0d 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,6 +1,7 @@ 
 2023-09-27  Omar Sandoval  <osandov@fb.com>
 
 	* libdw_find_split_unit.c (try_split_file): Make static.
+	* dwarf_entrypc.c (dwarf_entrypc): Call dwarf_lowpc.
 
 2023-02-22  Mark Wielaard  <mark@klomp.org>
 
diff --git a/libdw/dwarf_entrypc.c b/libdw/dwarf_entrypc.c
index 0ef3b0ea..543567d4 100644
--- a/libdw/dwarf_entrypc.c
+++ b/libdw/dwarf_entrypc.c
@@ -37,12 +37,10 @@ 
 int
 dwarf_entrypc (Dwarf_Die *die, Dwarf_Addr *return_addr)
 {
-  Dwarf_Attribute attr_mem;
-
-  return INTUSE(dwarf_formaddr) (INTUSE(dwarf_attr) (die, DW_AT_entry_pc,
-						     &attr_mem)
-				 ?: INTUSE(dwarf_attr) (die, DW_AT_low_pc,
-							&attr_mem),
-				 return_addr);
+  Dwarf_Attribute attr_mem, *attr;
+  if ((attr = INTUSE(dwarf_attr) (die, DW_AT_entry_pc, &attr_mem)) != NULL)
+    return INTUSE(dwarf_formaddr) (attr, return_addr);
+  else
+    return INTUSE(dwarf_lowpc) (die, return_addr);
 }
 INTDEF(dwarf_entrypc)
diff --git a/tests/ChangeLog b/tests/ChangeLog
index d816873c..f934c114 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,7 @@ 
+2023-09-27  Omar Sandoval  <osandov@fb.com>
+
+	* run-varlocs.sh: Add entry PC to split units.
+
 2023-04-21  Frank Ch. Eigler <fche@redhat.com>
 
 	* run-debuginfod-IXr.sh: New test.
diff --git a/tests/run-varlocs.sh b/tests/run-varlocs.sh
index b2621776..cbbcf6c7 100755
--- a/tests/run-varlocs.sh
+++ b/tests/run-varlocs.sh
@@ -206,7 +206,7 @@  testfiles testfilesplitranges5.debug
 testfiles testfile-ranges-hello5.dwo testfile-ranges-world5.dwo
 testrun_compare ${abs_top_builddir}/tests/varlocs --debug -e testfilesplitranges5.debug <<\EOF
 module 'testfilesplitranges5.debug'
-[14] CU 'hello.c'
+[14] CU 'hello.c'@0
   [1d] function 'no_say'@401160
     frame_base: {call_frame_cfa {...}}
     [33] parameter 'prefix'
@@ -236,7 +236,7 @@  module 'testfilesplitranges5.debug'
     [111] parameter 'count'
       [401150,401160) {reg4}
 module 'testfilesplitranges5.debug'
-[14] CU 'world.c'
+[14] CU 'world.c'@401180
   [1d] function 'no_main'@4011d0
     frame_base: {call_frame_cfa {...}}
     [35] parameter 'argc'
@@ -282,7 +282,7 @@  testfiles testfilesplitranges4.debug
 testfiles testfile-ranges-hello.dwo testfile-ranges-world.dwo
 testrun_compare ${abs_top_builddir}/tests/varlocs --debug -e testfilesplitranges4.debug <<\EOF
 module 'testfilesplitranges4.debug'
-[b] CU 'hello.c'
+[b] CU 'hello.c'@0
   [18] function 'no_say'@4004f0
     frame_base: {call_frame_cfa {...}}
     [2f] parameter 'prefix'
@@ -310,7 +310,7 @@  module 'testfilesplitranges4.debug'
     [102] parameter 'count'
       [4004e0,4004f0) {reg4}
 module 'testfilesplitranges4.debug'
-[b] CU 'world.c'
+[b] CU 'world.c'@400500
   [18] function 'no_main'@400550
     frame_base: {call_frame_cfa {...}}
     [2f] parameter 'argc'
@@ -373,7 +373,7 @@  EOF
 testfiles testfile-addrx_constx-5 addrx_constx-5.dwo
 testrun_compare ${abs_top_builddir}/tests/varlocs --exprlocs -e testfile-addrx_constx-5 <<\EOF
 module 'testfile-addrx_constx-5'
-[14] CU 'addrx_constx.c'
+[14] CU 'addrx_constx.c'@0
   producer (strx)
   language (data1)
   name (strx)
@@ -467,7 +467,7 @@  EOF
 testfiles testfile-addrx_constx-4 addrx_constx-4.dwo
 testrun_compare ${abs_top_builddir}/tests/varlocs --exprlocs -e testfile-addrx_constx-4 <<\EOF
 module 'testfile-addrx_constx-4'
-[b] CU 'addrx_constx.c'
+[b] CU 'addrx_constx.c'@0
   producer (GNU_str_index)
   language (data1)
   name (GNU_str_index)
@@ -565,7 +565,7 @@  testfiles splitdwarf4-not-split4.dwo
 
 testrun_compare ${abs_top_builddir}/tests/varlocs --debug -e testfile-splitdwarf4-not-split4.debug <<\EOF
 module 'testfile-splitdwarf4-not-split4.debug'
-[b] CU 'splitdwarf4-not-split4.c'
+[b] CU 'splitdwarf4-not-split4.c'@0
   [18] function 'main'@401050
     frame_base: {call_frame_cfa {...}}
     [30] parameter 'argc'