From eb0b07f4fc63fec057f1b59cce8cb308110a4552 Mon Sep 17 00:00:00 2001 From: Aaron Merey Date: Wed, 20 Sep 2023 13:00:02 -0400 Subject: [PATCH] debuginfo.c: Add more hooks for lazy loading debuginfo Add calls to di_load_di in search_one_{symtab,loctab,cfitab} to ensure that debuginfo is always loaded before searching these tables. This fixes a bug introduced in commit 60f7e89ba32 that results in callgrind failing to read source filenames from debuginfo. Also add a test which checks that callgrind successfully finds a filename from debuginfo. Co-Authored-By: Philippe Waroquiers --- callgrind/tests/Makefile.am | 3 ++- callgrind/tests/find-source.post.exp | 0 callgrind/tests/find-source.stderr.exp | 6 ++++++ callgrind/tests/find-source.vgtest | 6 ++++++ coregrind/m_debuginfo/priv_storage.h | 6 +++--- coregrind/m_debuginfo/storage.c | 9 ++++++--- 6 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 callgrind/tests/find-source.post.exp create mode 100644 callgrind/tests/find-source.stderr.exp create mode 100644 callgrind/tests/find-source.vgtest diff --git a/callgrind/tests/Makefile.am b/callgrind/tests/Makefile.am index d6b0937f46..9b68679908 100644 --- a/callgrind/tests/Makefile.am +++ b/callgrind/tests/Makefile.am @@ -21,7 +21,8 @@ EXTRA_DIST = \ notpower2-hwpref.vgtest notpower2-hwpref.stderr.exp \ notpower2-use.vgtest notpower2-use.stderr.exp \ threads.vgtest threads.stderr.exp \ - threads-use.vgtest threads-use.stderr.exp + threads-use.vgtest threads-use.stderr.exp \ + find-source.vgtest find-source.stderr.exp find-source.post.exp check_PROGRAMS = clreq simwork threads diff --git a/callgrind/tests/find-source.post.exp b/callgrind/tests/find-source.post.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/callgrind/tests/find-source.stderr.exp b/callgrind/tests/find-source.stderr.exp new file mode 100644 index 0000000000..d0b7820ae3 --- /dev/null +++ b/callgrind/tests/find-source.stderr.exp @@ -0,0 +1,6 @@ + + +Events : Ir +Collected : + +I refs: diff --git a/callgrind/tests/find-source.vgtest b/callgrind/tests/find-source.vgtest new file mode 100644 index 0000000000..cf1db463ab --- /dev/null +++ b/callgrind/tests/find-source.vgtest @@ -0,0 +1,6 @@ +# The 'prog' doesn't matter because we don't use its output. Instead we test +# the post-processing of the cgout-test file. +prog: ../../tests/true +vgopts: --callgrind-out-file=callgrind.out +post: grep -q 'tests/true\.c' callgrind.out +cleanup: rm callgrind.out diff --git a/coregrind/m_debuginfo/priv_storage.h b/coregrind/m_debuginfo/priv_storage.h index b959873ab8..912edd435a 100644 --- a/coregrind/m_debuginfo/priv_storage.h +++ b/coregrind/m_debuginfo/priv_storage.h @@ -1162,16 +1162,16 @@ extern void ML_(finish_CFSI_arrays) ( struct _DebugInfo* di ); /* Find a symbol-table index containing the specified pointer, or -1 if not found. Binary search. */ -extern Word ML_(search_one_symtab) ( const DebugInfo* di, Addr ptr, +extern Word ML_(search_one_symtab) ( DebugInfo* di, Addr ptr, Bool findText ); /* Find a location-table index containing the specified pointer, or -1 if not found. Binary search. */ -extern Word ML_(search_one_loctab) ( const DebugInfo* di, Addr ptr ); +extern Word ML_(search_one_loctab) ( DebugInfo* di, Addr ptr ); /* Find a CFI-table index containing the specified pointer, or -1 if not found. Binary search. */ -extern Word ML_(search_one_cfitab) ( const DebugInfo* di, Addr ptr ); +extern Word ML_(search_one_cfitab) ( DebugInfo* di, Addr ptr ); /* Find a FPO-table index containing the specified pointer, or -1 if not found. Binary search. */ diff --git a/coregrind/m_debuginfo/storage.c b/coregrind/m_debuginfo/storage.c index 3ad114607b..80c4b77bb5 100644 --- a/coregrind/m_debuginfo/storage.c +++ b/coregrind/m_debuginfo/storage.c @@ -2420,9 +2420,10 @@ void ML_(canonicaliseTables) ( struct _DebugInfo* di ) /* Find a symbol-table index containing the specified pointer, or -1 if not found. Binary search. */ -Word ML_(search_one_symtab) ( const DebugInfo* di, Addr ptr, +Word ML_(search_one_symtab) ( DebugInfo* di, Addr ptr, Bool findText ) { + VG_(di_load_di)(di); Addr a_mid_lo, a_mid_hi; Word mid, lo = 0, @@ -2449,8 +2450,9 @@ Word ML_(search_one_symtab) ( const DebugInfo* di, Addr ptr, /* Find a location-table index containing the specified pointer, or -1 if not found. Binary search. */ -Word ML_(search_one_loctab) ( const DebugInfo* di, Addr ptr ) +Word ML_(search_one_loctab) ( DebugInfo* di, Addr ptr ) { + VG_(di_load_di)(di); Addr a_mid_lo, a_mid_hi; Word mid, lo = 0, @@ -2473,8 +2475,9 @@ Word ML_(search_one_loctab) ( const DebugInfo* di, Addr ptr ) /* Find a CFI-table index containing the specified pointer, or -1 if not found. Binary search. */ -Word ML_(search_one_cfitab) ( const DebugInfo* di, Addr ptr ) +Word ML_(search_one_cfitab) ( DebugInfo* di, Addr ptr ) { + VG_(di_load_di)(di); Word mid, lo = 0, hi = di->cfsi_used-1; -- 2.43.5