diff options
author | Dave Brolley <brolley@redhat.com> | 2008-09-10 12:24:44 -0400 |
---|---|---|
committer | Dave Brolley <brolley@redhat.com> | 2008-09-10 12:24:44 -0400 |
commit | 4efa91dd26956c961b2999470ced965a448ed31b (patch) | |
tree | b27b7b323eefbe3303e630809776b626987aa421 | |
parent | bb997bd81d90b94e734c8c93402353eddd0bc408 (diff) | |
parent | 675fb1ddeec8cd22e17ab989f8a813a375ae6226 (diff) | |
download | systemtap-steved-4efa91dd26956c961b2999470ced965a448ed31b.tar.gz systemtap-steved-4efa91dd26956c961b2999470ced965a448ed31b.tar.xz systemtap-steved-4efa91dd26956c961b2999470ced965a448ed31b.zip |
Merge branch 'master' of ssh://sources.redhat.com/git/systemtap
33 files changed, 713 insertions, 103 deletions
@@ -1,3 +1,51 @@ +2008-09-10 Mark Wielaard <mjw@redhat.com> + + * translate.cxx (dump_unwindsyms): Rename module_base output to + dwarf_module_base. + +2008-09-10 Mark Wielaard <mjw@redhat.com> + + * translate.cxx (dump_unwindsyms): Output module_base. + +2008-09-10 Mark Wielaard <mjw@redhat.com> + + * translate.cxx (get_unwind_data): New function. + (dump_unwindsyms): Output unwind data. + +2008-09-09 Masami Hiramatsu <mhiramat@redhat.com> + + * stapprobes.5.in: Added a description about $return. + * NEWS: Ditto. + * tapsets.cxx (utrace_var_expanding_copy_visitor): Change + visit_target_symbol_syscall() to visit_target_symbol_context(). + (utrace_var_expanding_copy_visitor::visit_target_symbol_context): + Handle not only $syscall but also $return. + (utrace_var_expanding_copy_visitor::visit_target_symbol): Ditto. + +2008-09-09 Masami Hiramatsu <mhiramat@redhat.com> + + * stapprobes.5.in: Added a description about $argN. + * NEWS: Ditto. + * tapsets.cxx (utrace_var_expanding_copy_visitor): Added + visit_target_symbol_arg() and visit_target_symbol_syscall(). + (visit_target_symbol_arg): New function for handling $argN. + (visit_target_symbol_syscall): New function for handling $syscall. + (visit_target_symbol): Use visit_target_symbol_arg() and + visit_target_symbol_syscall(). + +2008-09-09 Masami Hiramatsu <mhiramat@redhat.com> + + * stapprobes.5.in : Added a line for $name context variable. + * translate.cxx (c_unparser::emit_common_header): Add marker_name and + marker_format fields to context. + * tapsets.cxx (common_probe_entryfn_prologue) : Ditto. + (mark_derived_probe_group::emit_module_decls) : Ditto. + (mark_var_expanding_copy_visitor) : change visit_target_symbol_format + to visit_target_symbol_context. + (mark_var_expanding_copy_visitor::visit_target_symbol_context): handle + not only $format but also $name. + (mark_var_expanding_copy_visitor::visit_target_symbol): Ditto. + 2008-09-07 Frank Ch. Eigler <fche@elastic.org> * tapsets.cxx (build_blacklist): Add some x86 raw port-io spots. @@ -1,5 +1,11 @@ * What's new +- Additional context variables are available on user-space syscall probes. + - $argN ($arg1, $arg2, ... $arg6) in process(PATH_OR_PID).syscall + gives you the argument of the system call. + - $return in process(PATH_OR_PID).syscall.return gives you the return + value of the system call. + - Target process mode (stap -c CMD or -x PID) now implicitly restricts all "process.*" probes to the given child process. (It does not affect kernel.* or other probe types.) The CMD string is now executed directly, diff --git a/doc/SystemTap_Beginners_Guide/en-US/Book_Info.xml b/doc/SystemTap_Beginners_Guide/en-US/Book_Info.xml index 0058f768..09530ccc 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Book_Info.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Book_Info.xml @@ -5,10 +5,9 @@ <bookinfo id="SystemTap_Beginners_Guide"> <title>SystemTap Beginners Guide</title> <subtitle>For use with Red Hat Enterprise Linux 5</subtitle> - <issuenum>0.1</issuenum> <edition>1.0</edition> <productname>Red Hat Enterprise Linux</productname> - <productnumber>5</productnumber> + <productnumber>5.3</productnumber> <pubsnumber>1</pubsnumber> <abstract><para>This guide provides basic instructions on how to use SystemTap to monitor different subsystems of &PRODUCT; in finer detail. The <citetitle>SystemTap Beginners Guide</citetitle> is recommended for users who have taken <ulink url="https://www.redhat.com/courses/rh133_red_hat_linux_system_administration_and_rhct_exam/">RHCT</ulink> or have a similar level of expertise in &PRODUCT;.</para></abstract> <corpauthor> diff --git a/doc/SystemTap_Beginners_Guide/en-US/Introduction.xml b/doc/SystemTap_Beginners_Guide/en-US/Introduction.xml index f60ab2f3..6f1b2a0a 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Introduction.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Introduction.xml @@ -19,13 +19,13 @@ --> <section id="goals"> <title>Goals</title> - <para>The goal of SystemTap is to provide infrastructure to monitor the running Linux kernel for detailed analysis. This can assist in identifying the underlying cause of a performance or functional problem.</para> + <para>SystemTap provides the infrastructure to monitor the running Linux kernel for detailed analysis. This can assist in identifying the underlying cause of a performance or functional problem.</para> - <para>Without SystemTap, monitoring the activity of a running kernel would require a tedious instrument, recompile, install, and reboot sequence. SystemTap is designed to eliminate this, allowing you to gather the same information by simply running its suite of tools against specific <firstterm>tapsets</firstterm> or SystemTap scripts.</para> + <para>Without SystemTap, monitoring the activity of a running kernel would require a tedious instrument, recompile, install, and reboot sequence. SystemTap is designed to eliminate this, allowing users to gather the same information by simply running its suite of tools against specific <firstterm>tapsets</firstterm> or SystemTap scripts.</para> <para>However, SystemTap was initially designed for users with intermediate to advanced knowledge of the kernel. This could present a steep learning curve for administrators or developers whose knowledge of the Linux kernel is little to none.</para> - <para>In line with that, the main goal of the <citetitle>SystemTap Beginner's Guide</citetitle> is two-fold:</para> + <para>In line with that, the main goals of the <citetitle>SystemTap Beginner's Guide</citetitle> are as follows:</para> <itemizedlist> <listitem><para>To introduce users to SystemTap, familiarize them with its architecture, and provide setup instructions for all kernel types.</para></listitem> @@ -34,15 +34,16 @@ </itemizedlist> <!-- </formalpara> --> <remark>above, Short description on the underlying goals of SystemTap_Beginners_Guide, what we want to teach users.</remark> -</section> +</section> +<!-- <section id="intro-usage"> <title>Usage</title> <remark> This section describes the practical uses of SystemTap, at a conceptual level. What a beginner can use SystemTap for, and what an advanced user can use SystemTap for. </remark> </section> - + --> <section id="intro-systemtap-vs-others"> <title>SystemTap Versus Other Monitoring Tools</title> <remark> diff --git a/doc/SystemTap_Beginners_Guide/en-US/Scripts.xml b/doc/SystemTap_Beginners_Guide/en-US/Scripts.xml index abb087bc..24ab8a83 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Scripts.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Scripts.xml @@ -6,7 +6,7 @@ <title>SystemTap Scripts</title> <para> - For the most part, SystemTap scripts are the foundation of each SystemTap session. The SystemTap scripts you use or write yourself instruct SystemTap on what type of information to trap, and what to do once that information is trapped. + For the most part, SystemTap scripts are the foundation of each SystemTap session. SystemTap scripts instruct SystemTap on what type of information to trap, and what to do once that information is trapped. </para> <para> @@ -15,7 +15,7 @@ <note> <title>Note</title> - <para>An event and its corresponding handler is collectively called a <emphasis>probe</emphasis>. A SystemTap script can have multiple probes, in the same manner that each event can have multiple corresponding handlers.</para> + <para>An event and its corresponding handler is collectively called a <emphasis>probe</emphasis>. A SystemTap script can have multiple probes.</para> </note> <para> @@ -26,13 +26,105 @@ SystemTap scripts go one step further by allowing you more flexibility with regard to handlers. Events serve as the triggers for handlers to run; handlers can be specified to trap specified data and print it in a certain manner. </para> +<formalpara id="scriptformats"> + <title>Format</title> + <para> + SystemTap scripts use the file extension <filename>.stp</filename>, and are written in the following format: + </para> +</formalpara> +<screen> +probe <replaceable>[event]</replaceable>, +<replaceable>[another event]</replaceable> + +{ + <replaceable>[handler]</replaceable> + + exit() +} +</screen> + <para>The <replaceable>exit()</replaceable> condition is optional, but it is recommended since it safely terminates the session once the script successfully traps the required information.</para> +<important> + <title>Important</title> + <para> + <xref linkend="scripts"/> is designed to introduce readers to the basics of SystemTap scripts. To understand SystemTap scripts better, it is advisable that you refer to <xref linkend="useful-systemtap-scripts"/>; each section therein provides a detailed explanation of the script, its events, handlers, and expected output. + </para> +</important> + <section id="systemtapscript-events"> + <title>Events</title> + +<para> + SystemTap supports multiple events per probe; as shown in <xref linkend="scriptformats"/>, multiple events are delimited by a comma (<command>,</command>). Sample <replaceable>[event]</replaceable>s include:</para> + +<variablelist> + +<varlistentry> + <term>begin</term> + <listitem> + <para>The startup of a SystemTap session; i.e. as soon as the SystemTap script is run.</para> + </listitem> +</varlistentry> + +<varlistentry> + <term>end</term> + <listitem> + <para>The end of a SystemTap session.</para> + </listitem> +</varlistentry> + +<varlistentry> + <term>kernel.function("<replaceable>[function]</replaceable>")</term> + <listitem> + <para>The entry to the kernel function <replaceable>function</replaceable>. For example, <command>kernel.function("sys_open")</command> refers to the "event" that the kernel function <command>sys_open</command> is used. To specify the <emphasis>return</emphasis> of the kernel function <command>sys_open</command>, append the <command>return</command> string to the event statement; i.e. <command>kernel.function("sys_open").return</command>.</para> + + <para>When defining functions, you can use asterisk (<command>*</command>) for wildcards. You can also trace the entry/exit of a function in a kernel source file. Consider the following example:</para> +<example id="wildcards"><title>Wildcards and Kernel Source Files in an Event</title> +<programlisting> +probe kernel.function("*@net/socket.c") { } +probe kernel.function("*@net/socket.c").return { } +</programlisting> +</example> + +<para>In the previous example, the first probe's event specifies the entry of ALL functions in the kernel source file <filename>net/socket.c</filename>. The second probe specifies the exit of all those functions. Note that in this example, no handler was specified; as such, no information will be displayed.</para> + </listitem> +</varlistentry> + +<varlistentry> + <term>syscall.<replaceable>[system_call]</replaceable></term> + <listitem> + <para>The entry to the system call <replaceable>[system_call]</replaceable>. Similar to <command>kerne.function</command>, appending a <command>return</command> to the statement specifies the exit of the system call. For example, to specify the entry of the system call <command>close</command>, use <command>syscall.close.return</command>.</para> + + <para>To identify what system calls are made by a specific program/command, use <command>strace <replaceable>command</replaceable></command>.</para> + </listitem> +</varlistentry> +<!-- +<varlistentry> + <term></term> + <listitem> + <para></para> + </listitem> +</varlistentry> +--> + +</variablelist> + + + </section> + + <section id="systemtapscript-handlers"> + <title>Handlers</title> + +<para> + SystemTap supports a wide variety of functions that can trap data when triggered by events. One way to display these functions is to use the <command>print()</command> +</para> + +<!-- +<para> + <xref linkend="wildcards"/> illustrates an example of a SystemTap script that contains no handlers. SystemTap will still be able to run the script, but no information will be displayed. +</para> +--> + - <section id="systemtapscript-format"> - <title>Format</title> - <para> - SystemTap scripts use the following format: - </para> </section> <!-- <section id="SystemTap_Beginners_Guide-Test-Section_2_Test"> diff --git a/runtime/ChangeLog b/runtime/ChangeLog index 71cd97e4..2438ee5e 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,48 @@ +2008-09-10 Mark Wielaard <mjw@redhat.com> + + * sym.h (_stp_module): Rename module_base to dwarf_module_base. + * unwind.c (adjustStartLoc): Document and use dwarf_module_base. + +2008-09-10 Mark Wielaard <mjw@redhat.com> + + * runtime.h (CONFIG_FRAME_POINTER): Don't enable when + STP_USE_DWARF_UNWINDER is already defined. + +2008-09-10 Mark Wielaard <mjw@redhat.com> + + * sym.h (_stp_module): Add module_base field. + * unwind.c (adjustStartLoc): New function. + (_stp_search_unwind_hdr): Use adjustStartLoc. + (unwind): Likewise. + +2008-09-10 Mark Wielaard <mjw@redhat.com> + + * unwind.c (unwind): Use _stp_mod_sec_lookup to get module and + unwind tables. + * runtime.h (STP_USE_FRAME_BUFFER): Disable by default for now. + * stack-x86_64.c (__stp_stack_print): Add levels to + _stp_stack_print_fallback call. + +2008-09-09 Masami Hiramatsu <mhiramat@redhat.com> + + * regs-ia64.c (__ia64_fetch_register): Return the address of the + register. + (ia64_fetch_register): Use __ia64_fetch_register. + * syscall.h (____stp_user_syscall_arg): Use __ia64_fetch_register. + (__stp_user_syscall_arg): Wrapping ____stp_user_syscall_arg to pass the + unwind address cache. + * task_finder.c (__stp_utrace_task_finder_target_syscall_): Added dummy + unwind address cache. + +2008-09-09 Masami Hiramatsu <mhiramat@redhat.com> + + * syscall.h: Added ia64 support. + +2008-09-09 Mark Wielaard <mwielaard@redhat.com> + + * sym.c (_stp_mod_sec_lookup): New function, extracted from + _stp_kallsyms_lookup. + 2008-09-09 Mark Wielaard <mwielaard@redhat.com> * sym.c (_stp_kallsyms_lookup): Correct this_section_offset diff --git a/runtime/regs-ia64.c b/runtime/regs-ia64.c index fd8d8ca8..8ce3e4c3 100644 --- a/runtime/regs-ia64.c +++ b/runtime/regs-ia64.c @@ -61,27 +61,36 @@ static void ia64_stap_get_arbsp(struct unw_frame_info *info, void *arg) -(__offset + (regs->cr_ifs & 127)));\ } -static long ia64_fetch_register(int regno, struct pt_regs *pt_regs, unsigned long **cache) +static long * +__ia64_fetch_register(int regno, struct pt_regs *pt_regs, unsigned long **cache) { struct ia64_stap_get_arbsp_param pa; if (regno == 12) - return pt_regs->r12; + return &pt_regs->r12; if (regno >= 8 && regno <= 11) - return *(unsigned long *)(&pt_regs->r8 + regno - 8); + return (long *)(&pt_regs->r8 + regno - 8); else if (regno < 32 || regno > 127) - return 0; + return NULL; if (!*cache) { pa.ip = pt_regs->cr_iip; unw_init_running(ia64_stap_get_arbsp, &pa); if (pa.address == 0) - return 0; + return NULL; *cache = pa.address; } - return *ia64_rse_skip_regs(*cache, regno-32); + return ia64_rse_skip_regs(*cache, regno-32); +} + +static long +ia64_fetch_register(int regno, struct pt_regs *pt_regs, unsigned long **cache) +{ + long *reg; + reg = __ia64_fetch_register(regno, pt_regs, cache); + return (reg != NULL)? *reg : 0; } static void ia64_store_register(int regno, diff --git a/runtime/runtime.h b/runtime/runtime.h index fd0cac9e..db793aa5 100644 --- a/runtime/runtime.h +++ b/runtime/runtime.h @@ -68,13 +68,17 @@ static struct #ifdef CONFIG_FRAME_POINTER /* Just because frame pointers are available does not mean we can trust them. */ +#ifndef STP_USE_DWARF_UNWINDER #if defined (__i386__) || defined (__arm__) #define STP_USE_FRAME_POINTER #endif #endif +#endif -/* dwarf unwinder only tested so far on i386 and x86_64 */ -#if !defined(STP_USE_FRAME_BUFFER) && (defined(__i386__) || defined(__x86_64__)) +/* dwarf unwinder only tested so far on i386 and x86_64, + but globally disabled for now */ +#if 0 +// !defined(STP_USE_FRAME_BUFFER) && (defined(__i386__) || defined(__x86_64__)) #define STP_USE_DWARF_UNWINDER #endif diff --git a/runtime/stack-x86_64.c b/runtime/stack-x86_64.c index 783e72bd..d3ec91cf 100644 --- a/runtime/stack-x86_64.c +++ b/runtime/stack-x86_64.c @@ -45,6 +45,6 @@ static void __stp_stack_print(struct pt_regs *regs, int verbose, int levels) break; } #else /* ! STP_USE_DWARF_UNWINDER */ - _stp_stack_print_fallback(REG_SP(regs), verbose); + _stp_stack_print_fallback(REG_SP(regs), verbose, levels); #endif } diff --git a/runtime/sym.c b/runtime/sym.c index b594d9c2..1a9e26b2 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -73,6 +73,37 @@ unsigned long _stp_module_relocate(const char *module, const char *section, unsi } +/* Return module owner and fills in closest section of the address + if found, return NULL otherwise. + XXX: needs to be address-space-specific. */ +static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, + struct _stp_section **sec) +{ + struct _stp_module *m = NULL; + unsigned midx = 0; + unsigned long closest_section_offset = ~0; + for (midx = 0; midx < _stp_num_modules; midx++) + { + unsigned secidx; + for (secidx = 0; secidx < _stp_modules[midx]->num_sections; secidx++) + { + unsigned long this_section_addr; + unsigned long this_section_offset; + this_section_addr = _stp_modules[midx]->sections[secidx].addr; + if (addr < this_section_addr) continue; + this_section_offset = addr - this_section_addr; + if (this_section_offset < closest_section_offset) + { + closest_section_offset = this_section_offset; + m = _stp_modules[midx]; + *sec = & m->sections[secidx]; + } + } + } + return m; +} + + /* XXX: needs to be address-space-specific. */ static const char *_stp_kallsyms_lookup(unsigned long addr, unsigned long *symbolsize, unsigned long *offset, @@ -86,29 +117,7 @@ static const char *_stp_kallsyms_lookup(unsigned long addr, unsigned long *symbo unsigned long flags; unsigned end, begin = 0; - /* Find the closest section (and its owner module); fill in m & sec. */ - { - unsigned midx = 0; - unsigned long closest_section_offset = ~0; - for (midx = 0; midx < _stp_num_modules; midx++) - { - unsigned secidx; - for (secidx = 0; secidx < _stp_modules[midx]->num_sections; secidx++) - { - unsigned long this_section_addr = _stp_modules[midx]->sections[secidx].addr; - unsigned long this_section_offset; - if (addr < this_section_addr) continue; - this_section_offset = addr - this_section_addr; - if (this_section_offset < closest_section_offset) - { - closest_section_offset = this_section_offset; - m = _stp_modules[midx]; - sec = & m->sections[secidx]; - } - } - } - } - + m = _stp_mod_sec_lookup(addr, &sec); if (unlikely (m == NULL || sec == NULL)) return NULL; diff --git a/runtime/sym.h b/runtime/sym.h index b2fb8ee9..5888d2c7 100644 --- a/runtime/sym.h +++ b/runtime/sym.h @@ -33,7 +33,12 @@ struct _stp_module { /* any notifier hooks that will tell us when a module */ /* is unloading. */ unsigned long module; /* XXX: why not struct module * ? */ - + + /* This is to undo .debug_frame relocation performed by elfutils, */ + /* which is done during the translate phase when we encode the */ + /* unwind data into the module. See adjustStartLoc() in unwind.c. */ + unsigned long dwarf_module_base; + /* the stack unwind data for this module */ void *unwind_data; void *unwind_hdr; diff --git a/runtime/syscall.h b/runtime/syscall.h index 24e93463..24fc7b1c 100644 --- a/runtime/syscall.h +++ b/runtime/syscall.h @@ -66,7 +66,15 @@ #define MUNMAP_SYSCALL_NO(tsk) 91 #define MREMAP_SYSCALL_NO(tsk) 163 #endif - + +#if defined(__ia64__) +#define MMAP_SYSCALL_NO(tsk) 1151 +#define MMAP2_SYSCALL_NO(tsk) 1172 +#define MPROTECT_SYSCALL_NO(tsk) 1155 +#define MUNMAP_SYSCALL_NO(tsk) 1152 +#define MREMAP_SYSCALL_NO(tsk) 1156 +#endif + #if !defined(MMAP_SYSCALL_NO) || !defined(MMAP2_SYSCALL_NO) \ || !defined(MPROTECT_SYSCALL_NO) || !defined(MUNMAP_SYSCALL_NO) \ || !defined(MREMAP_SYSCALL_NO) @@ -95,6 +103,14 @@ __stp_user_syscall_nr(struct pt_regs *regs) } #endif +#if defined(__ia64__) +static inline unsigned long +__stp_user_syscall_nr(struct pt_regs *regs) +{ + return regs->r15; +} +#endif + #if defined(__i386__) || defined(__x86_64__) static inline long * __stp_user_syscall_return_value(struct task_struct *task, struct pt_regs *regs) @@ -129,6 +145,14 @@ __stp_user_syscall_return_value(struct task_struct *task, struct pt_regs *regs) } #endif +#if defined(__ia64__) +static inline long * +__stp_user_syscall_return_value(struct task_struct *task, struct pt_regs *regs) +{ + return ®s->r8; +} +#endif + #if defined(__i386__) || defined(__x86_64__) static inline long * __stp_user_syscall_arg(struct task_struct *task, struct pt_regs *regs, @@ -211,4 +235,20 @@ __stp_user_syscall_arg(struct task_struct *task, struct pt_regs *regs, } #endif +#if defined(__ia64__) +#define __stp_user_syscall_arg(task, regs, n) \ + ____stp_user_syscall_arg(task, regs, n, &c->unwaddr) + +static inline long * +____stp_user_syscall_arg(struct task_struct *task, struct pt_regs *regs, + unsigned int n, unsigned long **cache) +{ + if (n > 5) { + _stp_error("syscall arg > 5"); + return NULL; + } + return __ia64_fetch_register(n + 32, regs, cache); +} +#endif + #endif /* _SYSCALL_H_ */ diff --git a/runtime/task_finder.c b/runtime/task_finder.c index 2d4eed15..cbb10d35 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -843,6 +843,9 @@ __stp_utrace_task_finder_target_syscall_entry(enum utrace_resume_action action, struct vm_area_struct *vma; unsigned long *arg0_addr, arg0; int rc; +#if defined(__ia64__) + struct { unsigned long *unwaddr; } _c = {.unwaddr = NULL}, *c = &_c; +#endif if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING) { debug_task_finder_detach(); @@ -950,6 +953,9 @@ __stp_utrace_task_finder_target_syscall_exit(enum utrace_resume_action action, struct mm_struct *mm; struct vm_area_struct *vma; struct __stp_tf_vma_entry *entry = NULL; +#if defined(__ia64__) + struct { unsigned long *unwaddr; } _c = {.unwaddr = NULL}, *c = &_c; +#endif if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING) { debug_task_finder_detach(); diff --git a/runtime/unwind.c b/runtime/unwind.c index 21ea4559..bc8a93dc 100644 --- a/runtime/unwind.c +++ b/runtime/unwind.c @@ -550,10 +550,29 @@ static int processCFI(const u8 *start, const u8 *end, unsigned long targetLoc, s return result && ptr.p8 == end && (targetLoc == 0 || state->label == NULL); } +// If this is an address inside a module, adjust for section relocation +// and the elfutils base relocation done during loading of the .dwarf_frame +// in translate.cxx. +static unsigned long +adjustStartLoc (unsigned long startLoc, + struct _stp_module *m, + struct _stp_section *s) +{ + if (startLoc && (strcmp (m->name, "kernel") != 0)) + { + startLoc = _stp_module_relocate (m->name, s->name, + startLoc); + startLoc -= m->dwarf_module_base; + } + return startLoc; +} + /* If we previously created an unwind header, then use it now to binary search */ /* for the FDE corresponding to pc. */ -static u32 *_stp_search_unwind_hdr(unsigned long pc, struct _stp_module *m) +static u32 *_stp_search_unwind_hdr(unsigned long pc, + struct _stp_module *m, + struct _stp_section *s) { const u8 *ptr, *end, *hdr = m->unwind_hdr; unsigned long startLoc; @@ -600,6 +619,7 @@ static u32 *_stp_search_unwind_hdr(unsigned long pc, struct _stp_module *m) do { const u8 *cur = ptr + (num / 2) * (2 * tableSize); startLoc = read_pointer(&cur, cur + tableSize, hdr[3]); + startLoc = adjustStartLoc(startLoc, m, s); if (pc < startLoc) num /= 2; else { @@ -608,7 +628,7 @@ static u32 *_stp_search_unwind_hdr(unsigned long pc, struct _stp_module *m) } } while (startLoc && num > 1); - if (num == 1 && (startLoc = read_pointer(&ptr, ptr + tableSize, hdr[3])) != 0 && pc >= startLoc) + if (num == 1 && (startLoc = adjustStartLoc(read_pointer(&ptr, ptr + tableSize, hdr[3]), m, s)) != 0 && pc >= startLoc) fde = (void *)read_pointer(&ptr, ptr + tableSize, hdr[3]); dbug_unwind(1, "returning fde=%lx startLoc=%lx", fde, startLoc); @@ -676,6 +696,7 @@ int unwind(struct unwind_frame_info *frame) signed ptrType = -1; uleb128_t retAddrReg = 0; struct _stp_module *m; + struct _stp_section *s = NULL; struct unwind_state state; dbug_unwind(1, "pc=%lx, %lx", pc, UNW_PC(frame)); @@ -683,7 +704,7 @@ int unwind(struct unwind_frame_info *frame) if (UNW_PC(frame) == 0) return -EINVAL; - m = NULL /*_stp_get_unwind_info(pc) */; + m = _stp_mod_sec_lookup (pc, &s); if (unlikely(m == NULL)) { dbug_unwind(1, "No module found for pc=%lx", pc); return -EINVAL; @@ -694,7 +715,7 @@ int unwind(struct unwind_frame_info *frame) goto err; } - fde = _stp_search_unwind_hdr(pc, m); + fde = _stp_search_unwind_hdr(pc, m, s); dbug_unwind(1, "%s: fde=%lx\n", m->name, fde); /* found the fde, now set startLoc and endLoc */ @@ -704,6 +725,8 @@ int unwind(struct unwind_frame_info *frame) ptr = (const u8 *)(fde + 2); ptrType = fde_pointer_type(cie); startLoc = read_pointer(&ptr, (const u8 *)(fde + 1) + *fde, ptrType); + startLoc = adjustStartLoc(startLoc, m, s); + dbug_unwind(2, "startLoc=%lx, ptrType=%s", startLoc, _stp_eh_enc_name(ptrType)); if (!(ptrType & DW_EH_PE_indirect)) ptrType &= DW_EH_PE_FORM | DW_EH_PE_signed; @@ -733,6 +756,7 @@ int unwind(struct unwind_frame_info *frame) ptr = (const u8 *)(fde + 2); startLoc = read_pointer(&ptr, (const u8 *)(fde + 1) + *fde, ptrType); + startLoc = adjustStartLoc(startLoc, m, s); dbug_unwind(2, "startLoc=%lx, ptrType=%s", startLoc, _stp_eh_enc_name(ptrType)); if (!startLoc) continue; diff --git a/stapprobes.5.in b/stapprobes.5.in index 5281c40e..36b36156 100644 --- a/stapprobes.5.in +++ b/stapprobes.5.in @@ -421,12 +421,20 @@ probe gets called when a thread described by PID or PATH dies. A .B .syscall probe gets called when a thread described by PID or PATH makes a -system call. The system call number is available in the "$syscall" -context variable. +system call. The system call number is available in the +.BR $syscall +context variable, and the first 6 arguments of the system call +are available in the +.BR $argN +(ex. $arg1, $arg2, ...) context variable. A .B .syscall.return probe gets called when a thread described by PID or PATH returns from a -system call. The system call number is available in the "$syscall" +system call. The system call number is available in the +.BR $syscall +context variable, and the return value of the system call is available +in the +.BR $return context variable. A .B .itrace @@ -520,6 +528,8 @@ and string parameters are passed in a type-safe manner. The marker format string associated with a marker is available in .BR $format . +And also the marker name string is avalable in +.BR $name . .SS PERFORMANCE MONITORING HARDWARE diff --git a/tapset/ChangeLog b/tapset/ChangeLog index 39b6b93b..3e2ebaf7 100644 --- a/tapset/ChangeLog +++ b/tapset/ChangeLog @@ -1,3 +1,15 @@ +2008-09-09 Masami Hiramatsu <mhiramat@redhat.com> + + * utrace.stp: Added _utrace_syscall_return(). + +2008-09-09 Masami Hiramatsu <mhiramat@redhat.com> + + * utrace.stp: Added _utrace_syscall_arg(). + +2008-09-09 Masami Hiramatsu <mhiramat@redhat.com> + + * marker.stp : New file, including marker context variable accessors. + 2008-09-01 Frank Ch. Eigler <fche@elastic.org> PR4225 merge. diff --git a/tapset/marker.stp b/tapset/marker.stp new file mode 100644 index 00000000..593ffaea --- /dev/null +++ b/tapset/marker.stp @@ -0,0 +1,22 @@ +// +// kernel marker tapset +// +// This file is part of systemtap, and is free software. You can +// redistribute it and/or modify it under the terms of the GNU General +// Public License (GPL); either version 2, or (at your option) any +// later version. + +/* marker-only context accessors */ + + +function _mark_name_get:string () %{ + strlcpy (THIS->__retvalue, + (CONTEXT->marker_name)?CONTEXT->marker_name:"", + MAXSTRINGLEN); /* pure */ +%} + +function _mark_format_get:string () %{ + strlcpy (THIS->__retvalue, + (CONTEXT->marker_format)?CONTEXT->marker_format:"", + MAXSTRINGLEN); /* pure */ +%} diff --git a/tapset/utrace.stp b/tapset/utrace.stp index 3831ca3c..34cb32c5 100644 --- a/tapset/utrace.stp +++ b/tapset/utrace.stp @@ -5,7 +5,14 @@ #include "syscall.h" %} - function _utrace_syscall_nr:long () %{ THIS->__retvalue = __stp_user_syscall_nr(CONTEXT->regs); /* pure */ %} + +function _utrace_syscall_arg:long (n:long) %{ + THIS->__retvalue = *__stp_user_syscall_arg(current, CONTEXT->regs, (int)THIS->n); /* pure */ +%} + +function _utrace_syscall_return:long () %{ + THIS->__retvalue = *__stp_user_syscall_return_value(current, CONTEXT->regs); /* pure */ +%} diff --git a/tapsets.cxx b/tapsets.cxx index 64fa9d34..28f945fe 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -221,6 +221,8 @@ common_probe_entryfn_prologue (translator_output* o, string statestr, // reset unwound address cache o->newline() << "c->pi = 0;"; o->newline() << "c->regparm = 0;"; + o->newline() << "c->marker_name = NULL;"; + o->newline() << "c->marker_format = NULL;"; o->newline() << "c->probe_point = 0;"; if (! interruptible) o->newline() << "c->actionremaining = MAXACTION;"; @@ -5844,6 +5846,8 @@ struct utrace_var_expanding_copy_visitor: public var_expanding_copy_visitor enum utrace_derived_probe_flags flags; bool target_symbol_seen; + void visit_target_symbol_arg (target_symbol* e); + void visit_target_symbol_context (target_symbol* e); void visit_target_symbol (target_symbol* e); }; @@ -5921,32 +5925,77 @@ utrace_derived_probe::join_group (systemtap_session& s) void -utrace_var_expanding_copy_visitor::visit_target_symbol (target_symbol* e) +utrace_var_expanding_copy_visitor::visit_target_symbol_arg (target_symbol* e) { - assert(e->base_name.size() > 0 && e->base_name[0] == '$'); + string argnum_s = e->base_name.substr(4,e->base_name.length()-4); + int argnum = atoi (argnum_s.c_str()); - if (flags != UDPF_SYSCALL && flags != UDPF_SYSCALL_RETURN) - throw semantic_error ("only \"process(PATH_OR_PID).syscall\" and \"process(PATH_OR_PID).syscall.return\" probes support target symbols", - e->tok); + if (flags != UDPF_SYSCALL) + throw semantic_error ("only \"process(PATH_OR_PID).syscall\" support $argN.", e->tok); - if (e->base_name != "$syscall") - throw semantic_error ("invalid target symbol for utrace probe, $syscall expected", - e->tok); + if (e->components.size() > 0) + { + switch (e->components[0].first) + { + case target_symbol::comp_literal_array_index: + throw semantic_error("utrace target variable '$argN' may not be used as array", + e->tok); + break; + case target_symbol::comp_struct_member: + throw semantic_error("utrace target variable '$argN' may not be used as a structure", + e->tok); + break; + default: + throw semantic_error ("invalid use of utrace target variable '$argN'", + e->tok); + break; + } + } + + // FIXME: max argnument number should not be hardcoded. + if (argnum < 1 || argnum > 6) + throw semantic_error ("invalid syscall argument number (1-6)", e->tok); + + bool lvalue = is_active_lvalue(e); + if (lvalue) + throw semantic_error("utrace '$argN' variable is read-only", e->tok); + + // Remember that we've seen a target variable. + target_symbol_seen = true; + + // We're going to substitute a synthesized '_utrace_syscall_arg' + // function call for the '$argN' reference. + functioncall* n = new functioncall; + n->tok = e->tok; + n->function = "_utrace_syscall_arg"; + n->referent = 0; // NB: must not resolve yet, to ensure inclusion in session + + literal_number *num = new literal_number(argnum - 1); + num->tok = e->tok; + n->args.push_back(num); + + provide <functioncall*> (this, n); +} + +void +utrace_var_expanding_copy_visitor::visit_target_symbol_context (target_symbol* e) +{ + string sname = e->base_name; if (e->components.size() > 0) { switch (e->components[0].first) { case target_symbol::comp_literal_array_index: - throw semantic_error("utrace target variable '$syscall' may not be used as array", + throw semantic_error("utrace target variable '" + sname + "' may not be used as array", e->tok); break; case target_symbol::comp_struct_member: - throw semantic_error("utrace target variable '$syscall' may not be used as a structure", + throw semantic_error("utrace target variable '" + sname + "' may not be used as a structure", e->tok); break; default: - throw semantic_error ("invalid use of utrace target variable '$syscall'", + throw semantic_error ("invalid use of utrace target variable '" + sname + "'", e->tok); break; } @@ -5954,21 +6003,49 @@ utrace_var_expanding_copy_visitor::visit_target_symbol (target_symbol* e) bool lvalue = is_active_lvalue(e); if (lvalue) - throw semantic_error("utrace $syscall variable is read-only", e->tok); + throw semantic_error("utrace '" + sname + "' variable is read-only", e->tok); + + string fname; + if (sname == "$return") + { + if (flags != UDPF_SYSCALL_RETURN) + throw semantic_error ("only \"process(PATH_OR_PID).syscall.return\" support $return.", e->tok); + fname = "_utrace_syscall_return"; + } + else + fname = "_utrace_syscall_nr"; // Remember that we've seen a target variable. target_symbol_seen = true; - // We're going to substitute a synthesized '_syscall_nr_get' + // We're going to substitute a synthesized '_utrace_syscall_nr' // function call for the '$syscall' reference. functioncall* n = new functioncall; n->tok = e->tok; - n->function = "_utrace_syscall_nr"; + n->function = fname; n->referent = 0; // NB: must not resolve yet, to ensure inclusion in session provide <functioncall*> (this, n); } +void +utrace_var_expanding_copy_visitor::visit_target_symbol (target_symbol* e) +{ + assert(e->base_name.size() > 0 && e->base_name[0] == '$'); + + if (flags != UDPF_SYSCALL && flags != UDPF_SYSCALL_RETURN) + throw semantic_error ("only \"process(PATH_OR_PID).syscall\" and \"process(PATH_OR_PID).syscall.return\" probes support target symbols", + e->tok); + + if (e->base_name.substr(0,4) == "$arg") + visit_target_symbol_arg(e); + else if (e->base_name == "$syscall" || e->base_name == "$return") + visit_target_symbol_context(e); + else + throw semantic_error ("invalid target symbol for utrace probe, $syscall, $return or $argN expected", + e->tok); +} + struct utrace_builder: public derived_probe_builder { @@ -7758,7 +7835,7 @@ struct mark_var_expanding_copy_visitor: public var_expanding_copy_visitor void visit_target_symbol (target_symbol* e); void visit_target_symbol_arg (target_symbol* e); - void visit_target_symbol_format (target_symbol* e); + void visit_target_symbol_context (target_symbol* e); }; @@ -7865,48 +7942,37 @@ mark_var_expanding_copy_visitor::visit_target_symbol_arg (target_symbol* e) void -mark_var_expanding_copy_visitor::visit_target_symbol_format (target_symbol* e) +mark_var_expanding_copy_visitor::visit_target_symbol_context (target_symbol* e) { - static bool function_synthesized = false; + string sname = e->base_name; if (is_active_lvalue (e)) - throw semantic_error("write to marker format not permitted", e->tok); + throw semantic_error("write to marker '" + sname + "' not permitted", e->tok); if (e->components.size() > 0) { switch (e->components[0].first) { case target_symbol::comp_literal_array_index: - throw semantic_error("marker format may not be used as array", + throw semantic_error("marker '" + sname + "' may not be used as array", e->tok); break; case target_symbol::comp_struct_member: - throw semantic_error("marker format may not be used as a structure", + throw semantic_error("marker '" + sname + "' may not be used as a structure", e->tok); break; default: - throw semantic_error ("invalid marker format use", e->tok); + throw semantic_error ("invalid marker '" + sname + "' use", e->tok); break; } } - string fname = string("_mark_format_get"); - - // Synthesize a function (if not already synthesized). - if (! function_synthesized) - { - function_synthesized = true; - functiondecl *fdecl = new functiondecl; - fdecl->tok = e->tok; - embeddedcode *ec = new embeddedcode; - ec->tok = e->tok; - - ec->code = string("strlcpy (THIS->__retvalue, CONTEXT->data, MAXSTRINGLEN); /* pure */"); - fdecl->name = fname; - fdecl->body = ec; - fdecl->type = pe_string; - sess.functions.push_back(fdecl); - } + string fname; + if (e->base_name == "$format") { + fname = string("_mark_format_get"); + } else { + fname = string("_mark_name_get"); + } // Synthesize a functioncall. functioncall* n = new functioncall; @@ -7923,10 +7989,10 @@ mark_var_expanding_copy_visitor::visit_target_symbol (target_symbol* e) if (e->base_name.substr(0,4) == "$arg") visit_target_symbol_arg (e); - else if (e->base_name == "$format") - visit_target_symbol_format (e); + else if (e->base_name == "$format" || e->base_name == "$name") + visit_target_symbol_context (e); else - throw semantic_error ("invalid target symbol for marker, $argN or $format expected", + throw semantic_error ("invalid target symbol for marker, $argN, $name or $format expected", e->tok); } @@ -8225,8 +8291,8 @@ mark_derived_probe_group::emit_module_decls (systemtap_session& s) s.op->newline(1) << "struct stap_marker_probe *smp = (struct stap_marker_probe *)probe_data;"; common_probe_entryfn_prologue (s.op, "STAP_SESSION_RUNNING"); s.op->newline() << "c->probe_point = smp->pp;"; - s.op->newline() << "c->data = (char *)smp->format;"; - + s.op->newline() << "c->marker_name = smp->name;"; + s.op->newline() << "c->marker_format = smp->format;"; s.op->newline() << "c->mark_va_list = args;"; s.op->newline() << "(*smp->ph) (c);"; s.op->newline() << "c->mark_va_list = NULL;"; diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog index 045772a3..3effc92f 100644 --- a/testsuite/ChangeLog +++ b/testsuite/ChangeLog @@ -1,3 +1,24 @@ +2008-09-09 Frank Ch. Eigler <fche@elastic.org> + + * systemtap.base/uprobes.*: Tweak regexps for read-only src tree + tolerance. + +2008-09-09 Masami Hiramatsu <mhiramat@redhat.com> + + * buildok/per-process-syscall.stp: New test, for process.syscall test. + * semko/utrace15.stp: Ditto. + * semko/utrace16.stp: Ditto. + * semko/utrace17.stp: Ditto. + * semko/utrace18.stp: Ditto. + * semko/utrace19.stp: Ditto. + * semko/utrace20.stp: Ditto. + * semko/utrace21.stp: Ditto. + * semko/utrace22.stp: Ditto. + +2008-09-09 Masami Hiramatsu <mhiramat@redhat.com> + + * systemtap.base/marker.exp : Added testcases of $name. + 2008-09-06 Frank Ch. Eigler <fche@elastic.org> * systemtap.base/cmd_parse.exp: Adapt to sh-c-less "stap -c" diff --git a/testsuite/buildok/per-process-syscall.stp b/testsuite/buildok/per-process-syscall.stp new file mode 100755 index 00000000..c2c41c0b --- /dev/null +++ b/testsuite/buildok/per-process-syscall.stp @@ -0,0 +1,18 @@ +#! stap -p4 +# +# per-process syscall trace test + +probe process.syscall { +print($syscall) +print($arg1) +print($arg2) +print($arg3) +print($arg4) +print($arg5) +print($arg6) +} + +probe process.syscall.return { +print($syscall) +print($return) +} diff --git a/testsuite/semko/utrace15.stp b/testsuite/semko/utrace15.stp new file mode 100755 index 00000000..56d91e89 --- /dev/null +++ b/testsuite/semko/utrace15.stp @@ -0,0 +1,4 @@ +#! stap -p2 + +# write to $argN +probe process("/bin/cat").syscall { $arg1 = 1 } diff --git a/testsuite/semko/utrace16.stp b/testsuite/semko/utrace16.stp new file mode 100755 index 00000000..f88923d6 --- /dev/null +++ b/testsuite/semko/utrace16.stp @@ -0,0 +1,4 @@ +#! stap -p2 + +# treat $argN as a pointer +probe process("/bin/cat").syscall { print($arg1->foo) } diff --git a/testsuite/semko/utrace17.stp b/testsuite/semko/utrace17.stp new file mode 100755 index 00000000..3a296dff --- /dev/null +++ b/testsuite/semko/utrace17.stp @@ -0,0 +1,4 @@ +#! stap -p2 + +# treat $argN as an array +probe process("/bin/cat").syscall { print($arg1[0]) } diff --git a/testsuite/semko/utrace18.stp b/testsuite/semko/utrace18.stp new file mode 100755 index 00000000..5d4960db --- /dev/null +++ b/testsuite/semko/utrace18.stp @@ -0,0 +1,4 @@ +#! stap -p2 + +# write to $return +probe process("/bin/cat").syscall.return { $return = 1 } diff --git a/testsuite/semko/utrace19.stp b/testsuite/semko/utrace19.stp new file mode 100755 index 00000000..3d30dc5e --- /dev/null +++ b/testsuite/semko/utrace19.stp @@ -0,0 +1,4 @@ +#! stap -p2 + +# access to $return from syscall entry +probe process("/bin/cat").syscall { print($return) } diff --git a/testsuite/semko/utrace20.stp b/testsuite/semko/utrace20.stp new file mode 100755 index 00000000..15fdc4c5 --- /dev/null +++ b/testsuite/semko/utrace20.stp @@ -0,0 +1,4 @@ +#! stap -p2 + +# treat $return as an array +probe process("/bin/cat").syscall { print($return[0]) } diff --git a/testsuite/semko/utrace21.stp b/testsuite/semko/utrace21.stp new file mode 100755 index 00000000..aa29ec59 --- /dev/null +++ b/testsuite/semko/utrace21.stp @@ -0,0 +1,4 @@ +#! stap -p2 + +# treat $return as a pointer/structure +probe process("/bin/cat").syscall.return { print($return->foo) } diff --git a/testsuite/semko/utrace22.stp b/testsuite/semko/utrace22.stp new file mode 100755 index 00000000..710810f6 --- /dev/null +++ b/testsuite/semko/utrace22.stp @@ -0,0 +1,4 @@ +#! stap -p2 + +# access to $argN from syscall return +probe process("/bin/cat").syscall.return { print($arg1) } diff --git a/testsuite/systemtap.base/marker.exp b/testsuite/systemtap.base/marker.exp index 89c0b8c3..0cacf60d 100644 --- a/testsuite/systemtap.base/marker.exp +++ b/testsuite/systemtap.base/marker.exp @@ -230,3 +230,48 @@ if {$kernel_markers_found == 0} { [lindex $kernel_marker_names 0] "foo"] stap_compile $TEST_NAME 0 $script } + +set TEST_NAME "K_MARKER18" +if {$kernel_markers_found == 0} { + untested "$TEST_NAME : no kernel markers present" +} else { + # Try compiling a script that prints the name string of a + # marker. + set script [format $kernel_script_arg \ + [lindex $kernel_marker_names 0] {\$name}] + stap_compile $TEST_NAME 1 $script +} + +set TEST_NAME "K_MARKER19" +if {$kernel_markers_found == 0} { + untested "$TEST_NAME : no kernel markers present" +} else { + # Try compiling a script that writes to a marker name string + # (which isn't allowed). + set script [format $kernel_script_arg2 \ + [lindex $kernel_marker_names 0] {\$name}] + stap_compile $TEST_NAME 0 $script +} + +set TEST_NAME "K_MARKER20" +if {$kernel_markers_found == 0} { + untested "$TEST_NAME : no kernel markers present" +} else { + # Try compiling a script that treats the marker name string as a + # structure (which isn't allowed). + set script [format $kernel_script_arg \ + [lindex $kernel_marker_names 0] {\$name->foo}] + stap_compile $TEST_NAME 0 $script +} + +set TEST_NAME "K_MARKER21" +if {$kernel_markers_found == 0} { + untested "$TEST_NAME : no kernel markers present" +} else { + # Try compiling a script that treats the marker name string like + # an array (which isn't allowed). + set script [format $kernel_script_arg \ + [lindex $kernel_marker_names 0] {\$name\[0\]}] + stap_compile $TEST_NAME 0 $script +} + diff --git a/testsuite/systemtap.base/uprobes.exp b/testsuite/systemtap.base/uprobes.exp index a0ae3e76..8fbe6da6 100644 --- a/testsuite/systemtap.base/uprobes.exp +++ b/testsuite/systemtap.base/uprobes.exp @@ -26,8 +26,12 @@ spawn sudo stap -v $srcdir/$subdir/uprobes.stp -c "./jennie 1 2 3 4" set ok 0 expect { -re {^Pass[^\r\n]*\r\n} { exp_continue } - -re {^process[^\r\n]*jennie[^\r\n]*main[^\r\n]*call[^\r\n]*\r\n} { incr ok; exp_continue } - -re {^process[^\r\n]*jennie[^\r\n]*main[^\r\n]*return[^\r\n]*\r\n} { incr ok; exp_continue } + -re {^Warning[^\r\n]*\r\n} { exp_continue } + -re {^Disabling[^\r\n]*\r\n} { exp_continue } + -re {^Uprobes[^\r\n]*\r\n} { exp_continue } + -re {^Cache[^\r\n]*\r\n} { exp_continue } + -re {^process[^\r\n]*jennie[^\r\n]*main[^\r\n]*call\r\n} { incr ok; exp_continue } + -re {^process[^\r\n]*jennie[^\r\n]*main[^\r\n]*return\r\n} { incr ok; exp_continue } -timeout 30 timeout { } eof { } diff --git a/testsuite/systemtap.base/uprobes.stp b/testsuite/systemtap.base/uprobes.stp index d7efb586..8e7dbe9d 100755 --- a/testsuite/systemtap.base/uprobes.stp +++ b/testsuite/systemtap.base/uprobes.stp @@ -1,3 +1,3 @@ #! stap -p4 -probe process("./jennie").function("main").call { log(pp()." "/*.$$parms*/) } -probe process("./jennie").function("main").return { log(pp()." "/*.$$return*/) } +probe process("./jennie").function("main").call { log(pp()/*." ".$$parms*/) } +probe process("./jennie").function("main").return { log(pp()/*." ".$$return*/) } diff --git a/translate.cxx b/translate.cxx index 2fe33314..4620f76f 100644 --- a/translate.cxx +++ b/translate.cxx @@ -881,6 +881,8 @@ c_unparser::emit_common_header () o->newline() << "struct kretprobe_instance *pi;"; o->newline() << "int regparm;"; o->newline() << "va_list *mark_va_list;"; + o->newline() << "const char * marker_name;"; + o->newline() << "const char * marker_format;"; o->newline() << "void *data;"; o->newline() << "#ifdef STP_TIMING"; o->newline() << "Stat *statp;"; @@ -4338,6 +4340,43 @@ struct unwindsym_dump_context }; +// Get the .debug_frame section for the given module. +// l will be set to the length of the size of the unwind data if found. +static void *get_unwind_data (Dwfl_Module *m, size_t *l) +{ + Dwarf_Addr bias = 0; + Dwarf *dw; + GElf_Ehdr *ehdr, ehdr_mem; + GElf_Shdr *shdr, shdr_mem; + Elf_Scn *scn = NULL; + Elf_Data *data = NULL; + + dw = dwfl_module_getdwarf(m, &bias); + if (dw != NULL) + { + Elf *elf = dwarf_getelf(dw); + ehdr = gelf_getehdr(elf, &ehdr_mem); + while ((scn = elf_nextscn(elf, scn))) + { + shdr = gelf_getshdr(scn, &shdr_mem); + if (strcmp(elf_strptr(elf, ehdr->e_shstrndx, shdr->sh_name), + ".debug_frame") == 0) + { + data = elf_rawdata(scn, NULL); + break; + } + } + } + + if (data != NULL) + { + *l = data->d_size; + return data->d_buf; + } + + return NULL; +} + static int dump_unwindsyms (Dwfl_Module *m, void **userdata __attribute__ ((unused)), @@ -4457,6 +4496,31 @@ dump_unwindsyms (Dwfl_Module *m, } } + // Add unwind data to be included if it exists for this module. + size_t len = 0; + void *unwind = get_unwind_data (m, &len); + if (unwind != NULL) + { + c->output << "#ifdef STP_USE_DWARF_UNWINDER" << endl; + c->output << "static uint8_t _stp_module_" << stpmod_idx + << "_unwind_data[] = " << endl; + c->output << " {"; + for (size_t i = 0; i < len; i++) + { + int h = ((uint8_t *)unwind)[i]; + c->output << "0x" << hex << h << dec << ","; + if ((i + 1) % 16 == 0) + c->output << endl << " "; + } + c->output << "};" << endl; + c->output << "#endif /* STP_USE_DWARF_UNWINDER */" << endl; + } + else + { + c->session.print_warning ("No unwind data for " + modname + + ", " + dwfl_errmsg (-1)); + } + for (unsigned secidx = 0; secidx < seclist.size(); secidx++) { c->output << "struct _stp_symbol " @@ -4487,6 +4551,27 @@ dump_unwindsyms (Dwfl_Module *m, c->output << "struct _stp_module _stp_module_" << stpmod_idx << " = {" << endl; c->output << ".name = " << lex_cast_qstring (modname) << ", " << endl; + c->output << ".dwarf_module_base = 0x" << hex << base << dec << ", " << endl; + + if (unwind != NULL) + { + c->output << "#ifdef STP_USE_DWARF_UNWINDER" << endl; + c->output << ".unwind_data = " + << "_stp_module_" << stpmod_idx << "_unwind_data, " << endl; + c->output << ".unwind_data_len = " << len << ", " << endl; + c->output << "#else" << endl; + } + + c->output << ".unwind_data = NULL, " << endl; + c->output << ".unwind_data_len = 0, " << endl; + + if (unwind != NULL) + c->output << "#endif /* STP_USE_DWARF_UNWINDER */" << endl; + + c->output << ".unwind_hdr = NULL, " << endl; + c->output << ".unwind_hdr_len = 0, " << endl; + c->output << ".unwind_is_ehframe = 0, " << endl; + c->output << ".sections = _stp_module_" << stpmod_idx << "_sections" << ", " << endl; c->output << ".num_sections = sizeof(_stp_module_" << stpmod_idx << "_sections)/" << "sizeof(struct _stp_section), " << endl; |