From 22ac61865162e74823c869e011760805d46cfb32 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Wed, 18 Aug 2010 15:37:22 -0700 Subject: [PATCH] Test case for DW_OP_GNU_implicit_pointer support * testsuite/systemtap.base/implicitptr.c: New file. * testsuite/systemtap.base/implicitptr.stp: New file. * testsuite/systemtap.base/implicitptr.exp: New file. --- testsuite/systemtap.base/implicitptr.c | 63 +++++++++++++++++++ testsuite/systemtap.base/implicitptr.exp | 78 ++++++++++++++++++++++++ testsuite/systemtap.base/implicitptr.stp | 21 +++++++ 3 files changed, 162 insertions(+) create mode 100644 testsuite/systemtap.base/implicitptr.c create mode 100644 testsuite/systemtap.base/implicitptr.exp create mode 100644 testsuite/systemtap.base/implicitptr.stp diff --git a/testsuite/systemtap.base/implicitptr.c b/testsuite/systemtap.base/implicitptr.c new file mode 100644 index 000000000..057450cb9 --- /dev/null +++ b/testsuite/systemtap.base/implicitptr.c @@ -0,0 +1,63 @@ +#include + +#define MARK(name) STAP_PROBE(implicitptr, name) + +int z; + +static int +foo (int i) +{ + int *j = &i; + int **k = &j; + int ***l = &k; + l1: MARK (foo_l1); + z++; /* side effect helps the probe placement hit right */ + i++; + return i; +} + +struct S +{ + int *x, y; +}; + +int u[6]; + +static inline void +add (struct S *a, struct S *b, int c) +{ + *a->x += *b->x; + a->y += b->y; + l1: MARK (add_l1); + u[c + 0]++; + a = (struct S *) 0; + u[c + 1]++; + a = b; + l2: MARK (add_l2); + u[c + 2]++; +} + +static int +bar (int i) +{ + int j = i; + struct S p[2] = { { &i, i * 2 }, { &j, j * 2 } }; + l1: MARK (bar_l1); + add (&p[0], &p[1], 0); + l2: MARK (bar_l2); + p[0].x = &j; + p[1].x = &i; + add (&p[0], &p[1], 3); + l3: MARK (bar_l3); + return i + j; +} + +int x = 22; + +int +main (void) +{ + x = foo (x); + x = bar (x); + return 0; +} diff --git a/testsuite/systemtap.base/implicitptr.exp b/testsuite/systemtap.base/implicitptr.exp new file mode 100644 index 000000000..c2c60f034 --- /dev/null +++ b/testsuite/systemtap.base/implicitptr.exp @@ -0,0 +1,78 @@ +set test "implicitptr" +set ::result_string {foo: 22 22 22 22 +changed foo (99): 99 99 99 99 +p = { { &100, 200 }, { &100, 200 } } +*a->x=200, a->y=400, *b->x=100, b->y=200 +*a->x=100, a->y=200, *b->x=100, b->y=200 +p = { { &200, 400 }, { &100, 200 } } +*a->x=300, a->y=600, *b->x=200, b->y=200 +*a->x=200, a->y=200, *b->x=200, b->y=200 +p = { { &300, 600 }, { &200, 200 } }} + +set listspec "process(\"$test.exe\").statement(\"foo@*:7\")" + +proc exe_uses_implicit_ptr {exe} { + if {[catch {exec readelf --debug-dump=info,loc $exe | \ + egrep -q {implicit_pointer| f2 .*User defined location op}} \ + results options]} { + verbose -log "exe_uses_implicit_ptr caught: $results" + return 0 + } else { + verbose -log "exe_uses_implicit_ptr ran: {$results}" + if {$results == ""} { + return 1 + } else { + return 0 + } + } +} + +set opt_flags {{-O0} {-O1} {-O2} {-O3}} +foreach opt $opt_flags { + set test_flags "additional_flags=-g additional_flags=$opt" + + set res [target_compile $srcdir/$subdir/$test.c $test.exe executable "$test_flags"] + if {$res != ""} { + verbose -log "target_compile failed: $res" 2 + fail "$test.c compile $opt" + untested "probe listing $test$opt" + untested "$test$opt" + continue + } else { + pass "$test.c compile $opt" + exec cp $test.exe /tmp/$test$opt + } + + set listing "" + catch {set listing [exec stap -L $listspec 2>@1]} + verbose -log "stap -L $listspec reports: $listing" + set listing [lsort [lrange [split $listing] 1 end]] + if {$listing == {{$i:int}}} { + set avail 0 + pass "probe listing $test$opt (i)" + } elseif {$listing == {{$i:int} {$j:int*} {$k:int**} {$l:int***}}} { + set avail 1 + pass "probe listing $test$opt (ijkl)" + } else { + verbose -log "listified: $listing" + fail "probe listing $test$opt" + set avail -1 + } + + if {$avail} { + if {[installtest_p] && [uprobes_p]} { + stap_run3 "$test$opt" $srcdir/$subdir/$test.stp \ + -g -c ./$test.exe $test.exe + } else { + untested "$test$opt" + } + } elseif {[exe_uses_implicit_ptr $test.exe]} { + verbose -log "$test$opt uses implicit_ptr but -L missed it" + fail "$test$opt" + } else { + verbose -log "$test$opt did not use implicit_ptr, skipping" + untested "$test$opt" + } + + catch {exec rm -f $test.exe} +} diff --git a/testsuite/systemtap.base/implicitptr.stp b/testsuite/systemtap.base/implicitptr.stp new file mode 100644 index 000000000..cbba91632 --- /dev/null +++ b/testsuite/systemtap.base/implicitptr.stp @@ -0,0 +1,21 @@ +probe process(@1).mark("foo_*") +{ + printf("foo: %d %d %d %d\n", + $i, $j[0], $k[0][0], $l[0][0][0]); + newval = 99; + $i = newval; + printf("changed foo (%d): %d %d %d %d\n", newval, + $i, $j[0], $k[0][0], $l[0][0][0]); +} + +probe process(@1).mark("bar_*") +{ + printf("p = { { &%d, %d }, { &%d, %d } }\n", + $p[0]->x[0], $p[0]->y, $p[1]->x[0], $p[1]->y); +} + +probe process(@1).mark("add_*") +{ + printf("*a->x=%d, a->y=%d, *b->x=%d, b->y=%d\n", + $a->x[0], $a->y, $b->x[0], $b->y); +} -- 2.43.5