diff options
author | Stan Cox <scox@redhat.com> | 2008-11-26 22:41:48 -0500 |
---|---|---|
committer | Stan Cox <scox@redhat.com> | 2008-11-26 22:41:48 -0500 |
commit | 349dc70e4967d0ae1fd7d504bd2c5c13f7b30fd8 (patch) | |
tree | bf8fda0988b1eab045dfdc33a0c757d8e84fb944 | |
parent | d0f2eabd2bf318502edddc50f60635df5d16c744 (diff) | |
download | systemtap-steved-349dc70e4967d0ae1fd7d504bd2c5c13f7b30fd8.tar.gz systemtap-steved-349dc70e4967d0ae1fd7d504bd2c5c13f7b30fd8.tar.xz systemtap-steved-349dc70e4967d0ae1fd7d504bd2c5c13f7b30fd8.zip |
Support debuginfo static uprobes.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | runtime/ChangeLog | 4 | ||||
-rw-r--r-- | runtime/sduprobes.h | 144 | ||||
-rw-r--r-- | tapsets.cxx | 227 | ||||
-rw-r--r-- | testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | testsuite/systemtap.base/static_uprobes.exp | 39 | ||||
-rw-r--r-- | testsuite/systemtap.base/static_uprobes.stp | 15 |
7 files changed, 306 insertions, 132 deletions
@@ -1,3 +1,7 @@ +2008-11-26 Stan Cox <scox@redhat.com> + + * tapsets.cxx (dwarf_builder::build): Support debuginfo static uprobes. + 2008-11-26 Frank Ch. Eigler <fche@elastic.org> * translate.cxx (emit_module_exit): Add another synchronize_sched. diff --git a/runtime/ChangeLog b/runtime/ChangeLog index 93ee18d2..51d8d933 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,7 @@ +2008-11-26 Stan Cox <scox@redhat.com> + + * sduprobes.h (STAP_PROBE1): Add USE_STAP_DEBUGINFO_PROBE. + 2008-11-26 Frank Ch. Eigler <fche@elastic.org> PR 4886. diff --git a/runtime/sduprobes.h b/runtime/sduprobes.h index b2c32e43..934f19e0 100644 --- a/runtime/sduprobes.h +++ b/runtime/sduprobes.h @@ -6,51 +6,137 @@ // Public License (GPL); either version 2, or (at your option) any // later version. -#include <stdlib.h> #include <string.h> extern int _stap_probe_sentinel; -#define STAP_PROBE_START() \ - char *stap_sdt = getenv("SYSTEMTAP_SDT"); \ - if (stap_sdt != NULL) \ +#define STAP_PROBE_START() \ + char *stap_sdt = getenv("SYSTEMTAP_SDT"); \ + if (stap_sdt != NULL) \ _stap_probe_start () -#define STAP_PROBE_STRUCT(probe,argc) \ -struct _probe_ ## probe \ -{ \ - char probe_name [strlen(#probe)+1]; \ - int arg_count; \ -}; \ -static volatile struct _probe_ ## probe _probe_ ## probe __attribute__ ((section (".probes"))) = {#probe,argc}; -#define STAP_PROBE(provider,probe) \ -STAP_PROBE_STRUCT(probe,0) \ - if (__builtin_expect(_stap_probe_sentinel, 0)) \ - _stap_probe_0 (_probe_ ## probe.probe_name); +#if _LP64 +#define STAP_PROBE_STRUCT_ARG \ + __uint64_t probe_arg; +#else +#define STAP_PROBE_STRUCT_ARG \ + long probe_arg __attribute__ ((aligned(8))); +#endif +#define STAP_PROBE_STRUCT(probe,type,argc) \ +struct _probe_ ## probe \ +{ \ + char probe_name [strlen(#probe)+1]; \ + int probe_type; \ + STAP_PROBE_STRUCT_ARG \ +}; \ + static volatile struct _probe_ ## probe _probe_ ## probe __attribute__ ((section (".probes"))) = {#probe,type,argc}; + +#ifndef USE_STAP_DEBUGINFO_PROBE +#define STAP_PROBE(provider,probe) \ + STAP_PROBE_STRUCT(probe,0,0) \ + if (__builtin_expect(_stap_probe_sentinel, 0))\ + _stap_probe_0 (_probe_ ## probe.probe_name); +#else +#define STAP_PROBE(provider,probe) \ +_probe_ ## probe: \ + asm volatile ("nop"); \ + STAP_PROBE_STRUCT(probe,1,(size_t)&& _probe_ ## probe) +#endif -#define STAP_PROBE1(provider,probe,arg1) \ -STAP_PROBE_STRUCT(probe,1) \ - if (__builtin_expect(_stap_probe_sentinel, 0)) \ - _stap_probe_1 (_probe_ ## probe.probe_name,(size_t)arg1); +#ifndef USE_STAP_DEBUGINFO_PROBE +#define STAP_PROBE1(provider,probe,arg1) \ + STAP_PROBE_STRUCT(probe,0,1) \ + if (__builtin_expect(_stap_probe_sentinel, 0))\ + _stap_probe_1 (_probe_ ## probe.probe_name,(size_t)arg1); +#else +#define STAP_PROBE1(provider,probe,parm1) \ +_probe_ ## probe: \ + asm volatile ("nop"); \ + volatile typeof(parm1) arg1 = parm1; \ + STAP_PROBE_STRUCT(probe,1,(size_t)&& _probe_ ## probe) \ + asm volatile ("# %0" :: "r"(arg1)); \ + asm volatile ("# %0" :: "m" ((_probe_ ## probe.probe_type))); +#endif -#define STAP_PROBE2(provider,probe,arg1,arg2) \ -STAP_PROBE_STRUCT(probe,2) \ + +#ifndef USE_STAP_DEBUGINFO_PROBE +#define STAP_PROBE2(provider,probe,arg1,arg2) \ + STAP_PROBE_STRUCT(probe,0,2) \ if (__builtin_expect(_stap_probe_sentinel, 0)) \ - _stap_probe_2 (_probe_ ## probe.probe_name,(size_t)arg1,(size_t)arg2); + _stap_probe_2 (_probe_ ## probe.probe_name,(size_t)arg1,(size_t)arg2); +#else +#define STAP_PROBE2(provider,probe,parm1,parm2) \ +_probe_ ## probe: \ + asm volatile ("nop"); \ + volatile typeof(parm1) arg1 = parm1; \ + volatile typeof(parm2) arg2 = parm2; \ + STAP_PROBE_STRUCT(probe,1,(size_t)&& _probe_ ## probe)\ + asm volatile ("# %0" :: "r"(arg1)); \ + asm volatile ("# %0" :: "r"(arg2)); \ + asm volatile ("# %0" :: "m" ((_probe_ ## probe.probe_type))); +#endif +#ifndef USE_STAP_DEBUGINFO_PROBE #define STAP_PROBE3(provider,probe,arg1,arg2,arg3) \ -STAP_PROBE_STRUCT(probe,3) \ + STAP_PROBE_STRUCT(probe,0,3) \ if (__builtin_expect(_stap_probe_sentinel, 0)) \ - _stap_probe_3 (_probe_ ## probe.probe_name,(size_t)arg1,(size_t)arg2,(size_t)arg3); + _stap_probe_3 (_probe_ ## probe.probe_name,(size_t)arg1,(size_t)arg2,(size_t)arg3); +#else +#define STAP_PROBE3(provider,probe,parm1,parm2,parm3) \ +_probe_ ## probe: \ + asm volatile ("nop"); \ + volatile typeof(parm1) arg1 = parm1; \ + volatile typeof(parm2) arg2 = parm2; \ + volatile typeof(parm3) arg3 = parm3; \ + STAP_PROBE_STRUCT(probe,1,(size_t)&& _probe_ ## probe) \ + asm volatile ("# %0" :: "r"(arg1)); \ + asm volatile ("# %0" :: "r"(arg2)); \ + asm volatile ("# %0" :: "r"(arg3)); \ + asm volatile ("# %0" :: "m" ((_probe_ ## probe.probe_type))); +#endif +#ifndef USE_STAP_DEBUGINFO_PROBE #define STAP_PROBE4(provider,probe,arg1,arg2,arg3,arg4) \ -STAP_PROBE_STRUCT(probe,4) \ + STAP_PROBE_STRUCT(probe,0,4) \ if (__builtin_expect(_stap_probe_sentinel, 0)) \ - _stap_probe_4 (_probe_ ## probe.probe_name,(size_t)arg1,(size_t)arg2,(size_t)arg3,(size_t)arg4); + _stap_probe_4 (_probe_ ## probe.probe_name,(size_t)arg1,(size_t)arg2,(size_t)arg3,(size_t)arg4); +#else +#define STAP_PROBE4(provider,probe,parm1,parm2,parm3) \ +_probe_ ## probe: \ + asm volatile ("nop"); \ + volatile typeof(parm1) arg1 = parm1; \ + volatile typeof(parm2) arg2 = parm2; \ + volatile typeof(parm3) arg3 = parm3; \ + volatile typeof(parm4) arg4 = parm4; \ + STAP_PROBE_STRUCT(probe,1,(size_t)&& _probe_ ## probe) \ + asm volatile ("# %0" :: "r"(arg1)); \ + asm volatile ("# %0" :: "r"(arg2)); \ + asm volatile ("# %0" :: "r"(arg3)); \ + asm volatile ("# %0" :: "r"(arg4)); \ + asm volatile ("# %0" :: "m" ((_probe_ ## probe.probe_type))); +#endif +#ifndef USE_STAP_DEBUGINFO_PROBE #define STAP_PROBE5(provider,probe,arg1,arg2,arg3,arg4,arg5) \ -STAP_PROBE_STRUCT(probe,5) \ - if (__builtin_expect(_stap_probe_sentinel, 0)) \ - _stap_probe_5 (_probe_ ## probe.probe_name,(size_t)arg1,(size_t)arg2,(size_t)arg3,(size_t)arg4,(size_t)arg5); + STAP_PROBE_STRUCT(probe,0,5) \ + if (__builtin_expect(_stap_probe_sentinel, 0))\ + _stap_probe_5 (_probe_ ## probe.probe_name,(size_t)arg1,(size_t)arg2,(size_t)arg3,(size_t)arg4,(size_t)arg5); +#else +#define STAP_PROBE5(provider,probe,parm1,parm2,parm3,parm4,parm5) \ +_probe_ ## probe: \ + asm volatile ("nop"); \ + volatile typeof(parm1) arg1 = parm1; \ + volatile typeof(parm2) arg2 = parm2; \ + volatile typeof(parm3) arg3 = parm3; \ + volatile typeof(parm4) arg4 = parm4; \ + volatile typeof(parm5) arg5 = parm5; \ + STAP_PROBE_STRUCT(probe,1,(size_t)&& _probe_ ## probe) \ + asm volatile ("# %0" :: "r"(arg1)); \ + asm volatile ("# %0" :: "r"(arg2)); \ + asm volatile ("# %0" :: "r"(arg3)); \ + asm volatile ("# %0" :: "r"(arg4)); \ + asm volatile ("# %0" :: "r"(arg5)); \ + asm volatile ("# %0" :: "m" ((_probe_ ## probe.probe_type))); +#endif diff --git a/tapsets.cxx b/tapsets.cxx index 82d5b81f..d6be0c2d 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -49,6 +49,7 @@ extern "C" { #include <glob.h> #include <fnmatch.h> #include <stdio.h> +#include <sys/types.h> #include "loc2c.h" #define __STDC_FORMAT_MACROS @@ -5214,46 +5215,6 @@ dwarf_builder::build(systemtap_session & sess, if (! sess.module_cache) sess.module_cache = new module_cache (); - if (((probe_point::component*)(location->components[1]))->functor == TOK_MARK) - { - // Generate: _probe_string = user_string($probe); - block *b = ((block*)(base->body)); - assignment *as = new assignment; - symbol* lsym = new symbol; - lsym->type = pe_string; - lsym->name = "_probe_string"; - lsym->tok = base->body->tok; - as->left = lsym; - as->op = "="; - functioncall *fc = new functioncall; - fc->function = "user_string"; - fc->tok = base->body->tok; - target_symbol* rsym = new target_symbol; - rsym->base_name = "$probe"; - rsym->tok = base->body->tok; - fc->args.push_back(rsym); - as->right = fc; - expr_statement* es = new expr_statement; - es->value = as; - - // Generate: if (_probe_string != mark("label")) next; - if_statement *is = new if_statement; - is->thenblock = new next_statement; - is->elseblock = NULL; - is->tok = base->body->tok; - comparison *be = new comparison; - be->op = "!="; - be->tok = base->body->tok; - be->left = lsym; - be->right = new literal_string(location->components[1]->arg->tok->content);; - is->condition = be; - - b->statements.insert(b->statements.begin(),(statement*) is); - b->statements.insert(b->statements.begin(),(statement*) es); - - location->components[0]->arg = new literal_string(sess.cmd); - ((literal_map_t&)parameters)[location->components[0]->functor] = location->components[0]->arg; - } string module_name; if (has_null_param (parameters, TOK_KERNEL) @@ -5286,62 +5247,144 @@ dwarf_builder::build(systemtap_session & sess, } if (((probe_point::component*)(location->components[1]))->functor == TOK_MARK) + { + enum probe_types { - Dwarf_Addr bias; - Elf* elf = (dwarf_getelf (dwfl_module_getdwarf (dw->module, &bias)) - ?: dwfl_module_getelf (dw->module, &bias)); - size_t shstrndx; + no_debuginfo = 0, + use_debuginfo = 1 + }; - Elf_Scn *probe_scn = NULL; - dwfl_assert ("getshstrndx", elf_getshstrndx (elf, &shstrndx)); - int argc = 0; - // Find the .probes section where the static probe label and arg count are stored - while ((probe_scn = elf_nextscn (elf, probe_scn))) - { - GElf_Shdr shdr_mem; - GElf_Shdr *shdr = gelf_getshdr (probe_scn, &shdr_mem); - assert (shdr != NULL); - - if (strcmp (elf_strptr (elf, shstrndx, shdr->sh_name), ".probes") != 0) - continue; - Elf_Data *pdata = elf_getdata (probe_scn, NULL); - assert (pdata != NULL); - size_t probe_scn_offset = 0; - while (probe_scn_offset < pdata->d_size) - { - char *probe_name = (char*)pdata->d_buf + probe_scn_offset; - probe_scn_offset += strlen(probe_name); - probe_scn_offset += 4 - (probe_scn_offset % 4); - argc = *(((char*)pdata->d_buf + probe_scn_offset)); - probe_scn_offset += sizeof(int); - if (strcmp (location->components[1]->arg->tok->content.c_str(), probe_name) == 0) - break; - } - } + location->components[0]->arg = new literal_string(sess.cmd); + ((literal_map_t&)parameters)[location->components[0]->functor] = location->components[0]->arg; + Dwarf_Addr bias; + Elf* elf = (dwarf_getelf (dwfl_module_getdwarf (dw->module, &bias)) + ?: dwfl_module_getelf (dw->module, &bias)); + size_t shstrndx; + + Elf_Scn *probe_scn = NULL; + dwfl_assert ("getshstrndx", elf_getshstrndx (elf, &shstrndx)); + __uint64_t probe_arg = 0; + int probe_type = no_debuginfo; + // Find the .probes section where the static probe label and arg are stored + while ((probe_scn = elf_nextscn (elf, probe_scn))) + { + GElf_Shdr shdr_mem; + GElf_Shdr *shdr = gelf_getshdr (probe_scn, &shdr_mem); + assert (shdr != NULL); - Dwarf *dwarf = dwfl_module_getdwarf(dw->module, &dw->module_bias); - Dwarf_Off off; - size_t cuhl; - Dwarf_Off noff = 0; - const char *probe_cudie = ""; - // Find where the probe instrumentation landing points are defined - while (dwarf_nextcu (dwarf, off = noff, &noff, &cuhl, NULL, NULL, NULL) == 0) - { - Dwarf_Die cudie_mem; - Dwarf_Die *cudie = dwarf_offdie (dwarf, off + cuhl, &cudie_mem); - if (cudie == NULL) - continue; - if (strncmp (dwarf_diename(&cudie_mem), "sduprobes", 9) == 0) - probe_cudie = dwarf_diename(&cudie_mem); - } - location->components[1]->functor = TOK_STATEMENT; - string argc_str = string(1,'0' + argc); - location->components[1]->arg = new literal_string("_stap_probe_" + (argc_str) - + "@sduprobes.c+1"); - ((literal_map_t&)parameters)[TOK_STATEMENT] = location->components[1]->arg; - dw->module = 0; - } + if (strcmp (elf_strptr (elf, shstrndx, shdr->sh_name), ".probes") != 0) + continue; + Elf_Data *pdata = elf_getdata (probe_scn, NULL); + assert (pdata != NULL); + size_t probe_scn_offset = 0; + while (probe_scn_offset < pdata->d_size) + { + char *probe_name = (char*)pdata->d_buf + probe_scn_offset; + probe_scn_offset += strlen(probe_name); + probe_scn_offset += sizeof(int) - (probe_scn_offset % sizeof(int)); + probe_type = *(((char*)pdata->d_buf + probe_scn_offset)); + probe_scn_offset += sizeof(int); + probe_arg = *((__uint32_t*)((char*)pdata->d_buf + probe_scn_offset)); + probe_arg <<= 32; + probe_arg |= *((__uint32_t*)((char*)pdata->d_buf + probe_scn_offset + 4)); + if (strcmp (location->components[1]->arg->tok->content.c_str(), probe_name) == 0) + break; + probe_scn_offset += sizeof(__uint64_t); + probe_scn_offset += sizeof(__uint64_t)*2 - (probe_scn_offset % (sizeof(__uint64_t)*2)); + } + } + if (probe_type == no_debuginfo) + { + // Many probe labels correspond to _stap_probe_N + // Generate: _probe_string = user_string($probe); + block *b = ((block*)(base->body)); + assignment *as = new assignment; + symbol* lsym = new symbol; + lsym->type = pe_string; + lsym->name = "_probe_string"; + lsym->tok = base->body->tok; + as->left = lsym; + as->op = "="; + functioncall *fc = new functioncall; + fc->function = "user_string"; + fc->tok = base->body->tok; + target_symbol* rsym = new target_symbol; + rsym->base_name = "$probe"; + rsym->tok = base->body->tok; + fc->args.push_back(rsym); + as->right = fc; + expr_statement* es = new expr_statement; + es->value = as; + + // Generate: if (_probe_string != mark("label")) next; + if_statement *is = new if_statement; + is->thenblock = new next_statement; + is->elseblock = NULL; + is->tok = base->body->tok; + comparison *be = new comparison; + be->op = "!="; + be->tok = base->body->tok; + be->left = lsym; + be->right = new literal_string(location->components[1]->arg->tok->content);; + is->condition = be; + + b->statements.insert(b->statements.begin(),(statement*) is); + b->statements.insert(b->statements.begin(),(statement*) es); + } + + Dwarf *dwarf = dwfl_module_getdwarf(dw->module, &dw->module_bias); + Dwarf_Off off; + size_t cuhl; + Dwarf_Off noff = 0; + const char *probe_cudie = ""; + const char *probe_file = "@sduprobes.c"; + int probe_line; + // Find where the probe instrumentation landing points are defined + while (dwarf_nextcu (dwarf, off = noff, &noff, &cuhl, NULL, NULL, NULL) == 0) + { + Dwarf_Die cudie_mem; + Dwarf_Die *cudie = dwarf_offdie (dwarf, off + cuhl, &cudie_mem); + if (cudie == NULL) + continue; + if (probe_type == no_debuginfo) + { + if (strncmp (dwarf_diename(&cudie_mem), "sduprobes", 9) == 0) + { + probe_cudie = dwarf_diename(&cudie_mem); + break; + } + } + else + { + Dwarf_Line *dwarf_line = dwarf_getsrc_die (cudie, probe_arg); + if (dwarf_line == NULL) + continue; + dwarf_lineno (dwarf_line, &probe_line); + probe_file = dwarf_diename(&cudie_mem); + break; + } + } + location->components[1]->functor = TOK_STATEMENT; + if (probe_type == no_debuginfo) + { + string probe_arg_str = string(1,'0' + probe_arg); + location->components[1]->arg + = new literal_string("_stap_probe_" + + (probe_arg_str) + + probe_file + "+1"); + } + else + { + char *pline; + if (asprintf (&pline, "*@%s:%d", probe_file, probe_line + 1) < 0) + return; + location->components[1]->arg = new literal_string(pline); + } + ((literal_map_t&)parameters)[TOK_STATEMENT] = location->components[1]->arg; + dw->module = 0; + } + dwarf_query q(sess, base, location, *dw, parameters, finished_results); diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog index 24f0cbdd..df7a24f9 100644 --- a/testsuite/ChangeLog +++ b/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-11-26 Stan Cox <scox@redhat.com> + + * systemtap.base/static_uprobes.exp: Check debuginfo static uprobes. + * systemtap.base/static_uprobes.stp: Check debuginfo static uprobes. + 2008-11-21 Frank Ch. Eigler <fche@elastic.org> PR5689. diff --git a/testsuite/systemtap.base/static_uprobes.exp b/testsuite/systemtap.base/static_uprobes.exp index 75e8fd21..2e1c41e1 100644 --- a/testsuite/systemtap.base/static_uprobes.exp +++ b/testsuite/systemtap.base/static_uprobes.exp @@ -55,7 +55,6 @@ if { $res != "" } { } set ok 0 -set env(SYSTEMTAP_SDT) 1 spawn stap -c $sup_exepath $srcdir/$subdir/static_uprobes.stp expect { -timeout 180 @@ -65,6 +64,42 @@ expect { timeout { fail "$test (timeout)" } eof { } } + +# Now do a debuginfo style probe of the above test + +set fp [open "[pwd]/static_uprobes.sh" "w"] +puts $fp " +ed $sup_srcpath <<HERE +1a +#define USE_STAP_DEBUGINFO_PROBE 1 +. +w +q +HERE +" +close $fp +spawn sh [pwd]/static_uprobes.sh + +set sup_flags "additional_flags=-iquote$env(SYSTEMTAP_RUNTIME) additional_flags=-g additional_flags=$env(SYSTEMTAP_RUNTIME)/sduprobes.c" +set res [target_compile $sup_srcpath $sup_exepath executable $sup_flags] +if { $res != "" } { + verbose "target_compile failed: $res" 2 + fail "unable to compile $sup_srcpath" + return +} else { + pass "compiling $sup_srcpath" +} + +spawn stap -c $sup_exepath $srcdir/$subdir/static_uprobes.stp +expect { + -timeout 180 + -re {In label1 probe} { incr ok; exp_continue } + -re {In label2 probe 0x2} { incr ok; exp_continue } + -re {In label3 probe 0x3 0x[0-9a-f][0-9a-f]} { incr ok; exp_continue } + timeout { fail "$test (timeout)" } + eof { } +} + wait -if {$ok == 3} { pass "$test" } { fail "$test (Got $ok Expected 3)" } +if {$ok == 6} { pass "$test" } { fail "$test (Got $ok Expected 3)" } diff --git a/testsuite/systemtap.base/static_uprobes.stp b/testsuite/systemtap.base/static_uprobes.stp index 25e64a37..b9de197e 100644 --- a/testsuite/systemtap.base/static_uprobes.stp +++ b/testsuite/systemtap.base/static_uprobes.stp @@ -1,17 +1,14 @@ -probe process("tstlabel.x").mark("label1") +probe process("static_uprobes.x").mark("label1") { - probe_str=user_string($probe) - printf("In %s probe\n", probe_str) + printf("In label1 probe\n") } -probe process("tstlabel.x").mark("label2") +probe process("static_uprobes.x").mark("label2") { - probe_str=user_string($probe) - printf("In %s probe %#x\n", probe_str, $arg1) + printf("In label2 probe %#x\n", $arg1) } -probe process("tstlabel.x").mark("label3") +probe process("static_uprobes.x").mark("label3") { - probe_str=user_string($probe) - printf("In %s probe %#x %#x\n", probe_str, $arg1, $arg2) + printf("In label3 probe %#x %#x\n", $arg1, $arg2) } |