Skip to content

Commit 3d70683

Browse files
committed
test(callgrind): smoke-test VG_(find_DebugInfo) attribution
Add a tiny C program with hot_fn in .text plus warm_fn/cold_fn in orphan executable sections (warm_code/cold_code) that sit in the same R-E LOAD but outside text_avma..text_avma+text_size. The .vgtest compares the resolved ob= basenames against an expected list, verifying callgrind attributes events to the test binary even when execution leaves .text.
1 parent e90c7d0 commit 3d70683

5 files changed

Lines changed: 41 additions & 1 deletion

File tree

callgrind/tests/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ EXTRA_DIST = \
1010
ann1.post.exp ann1.stderr.exp ann1.vgtest \
1111
ann2.post.exp ann2.stderr.exp ann2.vgtest \
1212
clreq.vgtest clreq.stderr.exp \
13+
find_debuginfo.vgtest find_debuginfo.stderr.exp find_debuginfo.post.exp \
1314
runtime_obj_skip_py.vgtest runtime_obj_skip_py.stderr.exp runtime_obj_skip_py.post.exp \
1415
runtime_obj_skip_py.py runtime_obj_skip_py_shim.c \
1516
bug497723.stderr.exp bug497723.post.exp bug497723.vgtest \
@@ -30,7 +31,7 @@ EXTRA_DIST = \
3031
inline-crossfile.vgtest inline-crossfile.stderr.exp inline-crossfile.stdout.exp inline-crossfile.post.exp \
3132
inline-crossfile-helper1.h inline-crossfile-helper2.h filter_inline
3233

33-
check_PROGRAMS = clreq simwork threads inline-samefile inline-crossfile
34+
check_PROGRAMS = clreq find_debuginfo simwork threads inline-samefile inline-crossfile
3435

3536
AM_CFLAGS += $(AM_FLAG_M3264_PRI)
3637
AM_CXXFLAGS += $(AM_FLAG_M3264_PRI)

callgrind/tests/find_debuginfo.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* Exercise VG_(find_DebugInfo) including the filename fallback for
2+
executable code that lives outside the section named ".text".
3+
4+
Functions placed in orphan sections "warm_code" and "cold_code" end up
5+
in their own ELF sections (PROGBITS, AX) inside the same R-E LOAD as
6+
.text but *outside* di->text_avma/text_size. Calls into them force
7+
VG_(find_DebugInfo) past the primary text-range check and into the
8+
am_find_nsegment + filename match path added in commit 938e424b1. */
9+
10+
static int hot_fn(int x) { return x + 1; }
11+
12+
__attribute__((noinline, section("warm_code")))
13+
static int warm_fn(int x) { return x * 3 + 7; }
14+
15+
__attribute__((noinline, section("cold_code")))
16+
static int cold_fn(int x) { return x ^ 0x5a; }
17+
18+
int main(void)
19+
{
20+
int y = 0;
21+
for (int i = 0; i < 1000; i++)
22+
y = hot_fn(y);
23+
y = warm_fn(y);
24+
y = cold_fn(y);
25+
return y & 0xff;
26+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
find_debuginfo
2+
ld-linux-x86-64.so.2
3+
libc.so.6
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
3+
Events : Ir
4+
Collected :
5+
6+
I refs:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
prog: find_debuginfo
2+
vgopts: --compress-strings=no --callgrind-out-file=callgrind.out.find_debuginfo
3+
post: sh -c 'sed -n "s|^ob=.*/||p" callgrind.out.find_debuginfo | grep -v "^vgpreload" | sort -u'
4+
cleanup: rm -f callgrind.out.find_debuginfo

0 commit comments

Comments
 (0)