]> sourceware.org Git - systemtap.git/commitdiff
Add sprint_[u]backtrace() tapset functions.
authorMark Wielaard <mjw@redhat.com>
Mon, 5 Jul 2010 11:08:07 +0000 (13:08 +0200)
committerMark Wielaard <mjw@redhat.com>
Mon, 5 Jul 2010 11:23:57 +0000 (13:23 +0200)
* tapset/context-unwind.stp (sprint_backtrace): New tapset function.
* tapset/ucontext-unwind.stp (sprint_ubacktrace): Likewise.
* testsuite/buildok/context-unwind-embedded.stp: Add sprint_backtrace test.
* testsuite/buildok/ucontext-unwind-embedded.stp: Add sprint_ubacktrace test.

tapset/context-unwind.stp
tapset/ucontext-unwind.stp
testsuite/buildok/context-unwind-embedded.stp
testsuite/buildok/ucontext-unwind-embedded.stp

index f0eb4f4f47016e8b159904c4fe8ce86fab30499f..b810b80e31e7d9a1151e923bdf719f8d17fea33d 100644 (file)
@@ -1,5 +1,5 @@
 // context-unwind tapset
-// Copyright (C) 2005-2008 Red Hat Inc.
+// Copyright (C) 2005-2010 Red Hat Inc.
 // Copyright (C) 2006 Intel Corporation.
 //
 // This file is part of systemtap, and is free software.  You can
@@ -37,6 +37,30 @@ function print_backtrace () %{
        }
 %}
 
+/**
+ * sfunction sprint_backtrace - Return stack back trace as string. EXPERIMENTAL!
+ *
+ * Returns a simple (kernel) backtrace. One line per address.
+ * Includes the symbol name (or hex address if symbol
+ * couldn't be resolved) and module name (if found). Includes the
+ * offset from the start of the function if found, otherwise the
+ * offset will be added to the module (if found, between
+ * brackets). Returns the backtrace as string (each line terminated by
+ * a newline character).  Note that the returned stack will be
+ * truncated to MAXSTRINGLEN, to print fuller and richer stacks use
+ * print_backtrace(). Equivalent to sprint_stack(backtrace()),
+ * but more efficient (no need to translate between hex strings and
+ * final backtrace string).
+ */
+function sprint_backtrace () %{
+       if (CONTEXT->regs)
+               _stp_stack_sprint (THIS->__retvalue, MAXSTRINGLEN,
+                                  _STP_SYM_SIMPLE, CONTEXT->regs,
+                                  CONTEXT->pi, MAXTRACE, NULL, NULL);
+       else
+               strlcpy (THIS->__retvalue, "", MAXSTRINGLEN);
+%}
+
 /**
  * sfunction backtrace - Hex backtrace of current stack
  *
index ec49305fc8fd22872025d03d7c0ea5a5c5162faf..5d885c71474ca03f7a9174e34175d41b50723958 100644 (file)
@@ -1,5 +1,5 @@
 // User context unwind tapset
-// Copyright (C) 2009 Red Hat Inc.
+// Copyright (C) 2009, 2010 Red Hat Inc.
 //
 // 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
@@ -40,6 +40,41 @@ function print_ubacktrace () %{
     _stp_printf("<no ubacktrace: %s>\n", CONTEXT->probe_point);
 %}
 
+/**
+ * sfunction sprint_ubacktrace - Return stack back trace for current task as string. EXPERIMENTAL!
+ *
+ * Returns a simple backtrace for the current task. One line per
+ * address. Includes the symbol name (or hex address if symbol
+ * couldn't be resolved) and module name (if found). Includes the
+ * offset from the start of the function if found, otherwise the
+ * offset will be added to the module (if found, between
+ * brackets). Returns the backtrace as string (each line terminated by
+ * a newline character).  Note that the returned stack will be
+ * truncated to MAXSTRINGLEN, to print fuller and richer stacks use
+ * print_ubacktrace(). Equivalent to sprint_ustack(ubacktrace()),
+ * but more efficient (no need to translate between hex strings and
+ * final backtrace string).
+ */
+function sprint_ubacktrace () %{
+/* unprivileged */ /* pragma:uprobes */ /* pragma:vma */
+  assert_is_myproc();
+
+  /* use task_pt_regs, CONTEXT->regs might be kernel regs, or not set. */
+  if (current->mm)
+    {
+      struct pt_regs *uregs = task_pt_regs(current);
+      if (uregs)
+       {
+         _stp_stack_sprint (THIS->__retvalue, MAXSTRINGLEN, _STP_SYM_SIMPLE,
+                            uregs, CONTEXT->pi, MAXTRACE,
+                            current, CONTEXT->ri);
+         return;
+       }
+    }
+
+    strlcpy (THIS->__retvalue, "", MAXSTRINGLEN);
+%}
+
 /**
  * sfunction print_ubacktrace_brief- Print stack back trace for current task. EXPERIMENTAL!
  *
index 68038c0be1b1417dc70220ba290dac5430a81f00..4e20441bf3a41aa80eed55f00d75328007efb35a 100755 (executable)
@@ -3,6 +3,7 @@
 probe begin {
        print_backtrace()
        printf("%s\n", backtrace())
+       printf("%s\n", sprint_backtrace())
        printf("%s\n", task_backtrace(0))
        printf("%s\n", caller())
        printf("%d\n", caller_addr())
index eac0254d41bf7b9758ff88f7889fd17c94096537..9661e126fa7cfbc21d6c6bee1bcbe4cbc7431474 100755 (executable)
@@ -9,6 +9,7 @@ probe begin {
        print_ubacktrace()
        print_ubacktrace_brief()
        printf("%s\n", ubacktrace())
+       printf("%s\n", sprint_ubacktrace())
 %:
        printf("\n")
 %)
This page took 0.029416 seconds and 5 git commands to generate.