]> sourceware.org Git - systemtap.git/commitdiff
PR11811 prep: save full mmpath for found vmas
authorFrank Ch. Eigler <fche@elastic.org>
Sun, 7 Nov 2010 22:09:57 +0000 (17:09 -0500)
committerFrank Ch. Eigler <fche@elastic.org>
Mon, 8 Nov 2010 16:35:16 +0000 (11:35 -0500)
Extend the print_*backtrace symbol names with the full path
of the user-space ELF module, not just the basename.  This
requires saving a char[] copy in the __stp_tf_vma_entry
structure instead of a char* pointing into a dentry.d_name.
-DTASK_FINDER_VMA_ENTRY_PATHLEN governs copy length.

* runtime/task_finder_vma.c (__stp_tf_vma_entry): Change
  char*name -> char[]path field.  Update manipulating
  functions accordingly.
* runtime/vma.c (_stp_vma_mmap_cb): Pass mmpath to tf-vma table
  if available.
* testsuite/systemtap.context/usymbols.exp: Update for expected
  full path in output string.
* NEWS: Mention change.
* runtime/sym.h (_STP_SYM_MODULE_BASENAME): New flag.
  (_STP_SYM_SIMPLE): Include it.
* runtime/sym.c (_stp_snprint_addr): Process it.

NEWS
runtime/sym.c
runtime/sym.h
runtime/task_finder_vma.c
runtime/vma.c
testsuite/systemtap.context/usymbols.exp

diff --git a/NEWS b/NEWS
index 0e5e863599be9e4c40a915d75c5dbede87578ff5..819d8f0388bb7ae2db09e042426b8e56d471b199 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,10 @@
 * What's new in version 1.4
 
+- The print_ubacktrace and usym* functions attempt to print the full
+  path of the user-space binaries' paths, instead of just the basename.
+  The maximum saved path length is set by -DTASK_FINDER_VMA_ENTRY_PATHLEN,
+  default 64.
+
 - The new tz_ctime() tapset function prints times in the local time zone.
 
 - More kernel tracepoints are accessible to the kernel.trace("...") mechanism,
index 0fc050044f95a9f8c932f1e6d1f69298fdaeff44..e11f6d14e3c14b6f21c4b61e610bee7873d563ba 100644 (file)
@@ -392,6 +392,10 @@ static int _stp_snprint_addr(char *str, size_t len, unsigned long address,
   if (flags & (_STP_SYM_SYMBOL | _STP_SYM_MODULE))
     name = _stp_kallsyms_lookup(address, &size, &offset, &modname, task);
 
+  if (modname && (flags & _STP_SYM_MODULE_BASENAME)) {
+     modname = strrchr (modname, '/') ?: modname;
+  }
+
   if (name && (flags & _STP_SYM_SYMBOL)) {
     if ((flags & _STP_SYM_MODULE) && modname && *modname) {
       if (flags & _STP_SYM_OFFSET) {
index 55d02d5c6a1536fc58fc49bff0019dba420fb840..a16ca022dd5113d8f660bef884e0ee166803e55e 100644 (file)
@@ -33,6 +33,8 @@
 #define _STP_SYM_POST_SPACE 128
 /* Adds a newline character, doesn't combine with _STP_SYM_POST_SPACE. */
 #define _STP_SYM_NEWLINE    256
+/* Adds only module " [`basename name`]" if found, use with _STP_SYM_MODULE. */
+#define _STP_SYM_MODULE_BASENAME 512
 
 /* Used for backtraces in hex string form. */
 #define _STP_SYM_NONE  (_STP_SYM_HEXSTR | _STP_SYM_POST_SPACE)
@@ -44,7 +46,7 @@
                         | _STP_SYM_SIZE | _STP_SYM_PRE_SPACE \
                         | _STP_SYM_NEWLINE)
 /* Simple symbol format, as used in backtraces for strings. */
-#define _STP_SYM_SIMPLE (_STP_SYM_SYMBOL | _STP_SYM_MODULE \
+#define _STP_SYM_SIMPLE (_STP_SYM_SYMBOL | _STP_SYM_MODULE | _STP_SYM_MODULE_BASENAME \
                         | _STP_SYM_OFFSET | _STP_SYM_NEWLINE)
 /* All symbol information (as used by [u]symdata). */
 #define _STP_SYM_DATA   (_STP_SYM_SYMBOL | _STP_SYM_MODULE \
index d57ec5d815b22d00f439ec2bb84840064b763181..7ea695570ccbd4cdb792f69085d0aea327af55e8 100644 (file)
@@ -28,13 +28,20 @@ static DEFINE_RWLOCK(__stp_tf_vma_lock);
 #define TASK_FINDER_VMA_ENTRY_ITEMS 1536
 #endif
 
+#ifndef TASK_FINDER_VMA_ENTRY_PATHLEN
+#define TASK_FINDER_VMA_ENTRY_PATHLEN 64
+#elif TASK_FINDER_VMA_ENTRY_PATHLEN < 8
+#error "gimme a little more TASK_FINDER_VMA_ENTRY_PATHLEN"
+#endif
+
+
 struct __stp_tf_vma_entry {
        struct hlist_node hlist;
 
        pid_t pid;
        unsigned long vm_start;
        unsigned long vm_end;
-       const char *name;
+        char path[TASK_FINDER_VMA_ENTRY_PATHLEN]; /* mmpath name, if known */
 
        // User data (possibly stp_module)
        void *user;
@@ -130,7 +137,7 @@ __stp_tf_get_vma_map_entry_internal(struct task_struct *tsk,
 static int
 stap_add_vma_map_info(struct task_struct *tsk,
                      unsigned long vm_start, unsigned long vm_end,
-                     const char *name, void *user)
+                     const char *path, void *user)
 {
        struct hlist_head *head;
        struct hlist_node *node;
@@ -162,7 +169,16 @@ stap_add_vma_map_info(struct task_struct *tsk,
        entry->pid = tsk->pid;
        entry->vm_start = vm_start;
        entry->vm_end = vm_end;
-       entry->name = name;
+        if (strlen(path) >= TASK_FINDER_VMA_ENTRY_PATHLEN-3)
+          {
+            strncpy (entry->path, "...", TASK_FINDER_VMA_ENTRY_PATHLEN);
+            strlcpy (entry->path+3, &path[strlen(path)-TASK_FINDER_VMA_ENTRY_PATHLEN+4],
+                     TASK_FINDER_VMA_ENTRY_PATHLEN-3);
+          }
+        else
+          {
+            strlcpy (entry->path, path, TASK_FINDER_VMA_ENTRY_PATHLEN);
+          }
        entry->user = user;
 
        head = &__stp_tf_vma_map[__stp_tf_vma_map_hash(tsk)];
@@ -203,7 +219,7 @@ stap_remove_vma_map_info(struct task_struct *tsk, unsigned long vm_start)
 static int
 stap_find_vma_map_info(struct task_struct *tsk, unsigned long addr,
                       unsigned long *vm_start, unsigned long *vm_end,
-                      const char **name, void **user)
+                      const char **path, void **user)
 {
        struct hlist_head *head;
        struct hlist_node *node;
@@ -227,8 +243,8 @@ stap_find_vma_map_info(struct task_struct *tsk, unsigned long addr,
                        *vm_start = found_entry->vm_start;
                if (vm_end != NULL)
                        *vm_end = found_entry->vm_end;
-               if (name != NULL)
-                       *name = found_entry->name;
+               if (path != NULL)
+                       *path = found_entry->path;
                if (user != NULL)
                        *user = found_entry->user;
                rc = 0;
@@ -244,7 +260,7 @@ stap_find_vma_map_info(struct task_struct *tsk, unsigned long addr,
 static int
 stap_find_vma_map_info_user(struct task_struct *tsk, void *user,
                            unsigned long *vm_start, unsigned long *vm_end,
-                           const char **name)
+                           const char **path)
 {
        struct hlist_head *head;
        struct hlist_node *node;
@@ -267,8 +283,8 @@ stap_find_vma_map_info_user(struct task_struct *tsk, void *user,
                        *vm_start = found_entry->vm_start;
                if (vm_end != NULL)
                        *vm_end = found_entry->vm_end;
-               if (name != NULL)
-                       *name = found_entry->name;
+               if (path != NULL)
+                       *path = found_entry->path;
                rc = 0;
        }
        read_unlock_irqrestore(&__stp_tf_vma_lock, flags);
index d3b4bbe65fc90dd528bcbdfc946b718c00f0547e..4c51cfcaf056de728e63cc42655ac0b7a6582c77 100644 (file)
@@ -112,6 +112,9 @@ static int _stp_vma_mmap_cb(struct stap_task_finder_target *tgt,
        int i, res;
        struct _stp_module *module = NULL;
        const char *name = (dentry != NULL) ? dentry->d_name.name : NULL;
+        
+        if (path == NULL || *path == '\0') /* unknown? */
+                path = (char *)name; /* we'll copy this soon, in ..._add_vma_... */
 
 #ifdef DEBUG_TASK_FINDER_VMA
        _stp_dbug(__FUNCTION__, __LINE__,
@@ -136,7 +139,7 @@ static int _stp_vma_mmap_cb(struct stap_task_finder_target *tgt,
                             atm. */
                          res = stap_add_vma_map_info(tsk->group_leader,
                                                      addr, addr + length,
-                                                     name, module);
+                                                     path, module);
                          /* Warn, but don't error out. */
                          if (res != 0) {
                                _stp_warn ("Couldn't register module '%s' for pid %d (%d)\n", _stp_modules[i]->path, tsk->group_leader->pid, res);
@@ -156,11 +159,11 @@ static int _stp_vma_mmap_cb(struct stap_task_finder_target *tgt,
                    || _stp_target == tsk->group_leader->pid)
                  {
                    res = stap_add_vma_map_info(tsk->group_leader, addr,
-                                               addr + length, name, NULL);
+                                               addr + length, path, NULL);
 #ifdef DEBUG_TASK_FINDER_VMA
                    _stp_dbug(__FUNCTION__, __LINE__,
                              "registered '%s' for %d (res:%d)\n",
-                             name, tsk->group_leader->pid,
+                             path, tsk->group_leader->pid,
                              res);
 #endif
                  }
index b4b94d95917630ff80ddf0a9ca6f2c0a06fbffa6..c7f3bebffc2cbb5b0b0c8d8b02e36bfae831f178 100644 (file)
@@ -62,8 +62,8 @@ set testscript {
     }
 }
 
-set output "handler: main_handler ($testexename)
-handler: lib_handler (lib${testlibname}.so)"
+set output "handler: main_handler ([pwd]/$testexename)
+handler: lib_handler ([pwd]/lib${testlibname}.so)"
 
 # Used to need to run stap with both the exe and the libraries used as -d args.
 # Now use --ldd to pick up both exe and the library we just linked in.
This page took 0.040976 seconds and 5 git commands to generate.