public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: Cong Wu <congwu@alauda.io>
To: "systemtap@sourceware.org" <systemtap@sourceware.org>
Subject: a idea about probe proc path like /proc/pid/root/xxx
Date: Wed, 13 Jul 2022 05:18:52 +0000	[thread overview]
Message-ID: <HK0PR01MB34916D6B6B1BD921A62CCA64C9899@HK0PR01MB3491.apcprd01.prod.exchangelabs.com> (raw)

hi all. currently, I'm use stap to probe user process like `probe process("/proc/xx/root/xxx").function("a")`, what I really want is to probe a process running in docker, I make a small patch.
here is what i did. https://github.com/woodgear/systemtap-wg/commit/0872dc3f5594be520afd83fc5075fff8c6bec955.
basically if solib_pathname start with /proc/$(task->tgid)/root then i just compare the rest part of it.
```
--- a/runtime/linux/uprobes-inode.c
+++ b/runtime/linux/uprobes-inode.c
@@ -813,6 +813,8 @@ stapiu_mmap_found(struct stap_task_finder_target *tf_target,
   struct stapiu_process* p;
   int known_mapping_p;
   unsigned long flags;
+  char proc_path_buff[100];
+  char *proc_path="/proc/";

   dbug_uprobes("wg: in mmap_found pid %d inode %ld\n",task->tgid,dentry->d_inode->i_ino);

@@ -876,18 +878,33 @@ stapiu_mmap_found(struct stap_task_finder_target *tf_target,

   if (! known_mapping_p) {

     /* The file path or build-id must match. The build-id address
      * is calculated using start address of this vma, the file
      * offset of the vma start address and the file offset of
      * the build-id. */
-    if (c->solib_pathname && path && strcmp (path, c->solib_pathname))
-      return 0;
+    if (c->solib_pathname && path) {
+        if (strncmp(proc_path, c->solib_pathname, strlen(proc_path)) == 0) {
+            sprintf(proc_path_buff,"/proc/%d/root%s",task->tgid,path);
+            if (strcmp (proc_path_buff, c->solib_pathname)) {
+                return 0;
+            }
+        }else {
+            // not proc path just compare
+            if (strcmp (path, c->solib_pathname)) {
+                return 0;
+            }
+        }
+    }
     if (c->solib_build_id_len > 0 && !__verify_build_id(task,
                                                        addr - offset + c->solib_build_id_vaddr,
                                                        c->solib_build_id,
-                                                       c->solib_build_id_len))
+                                                       c->solib_build_id_len)) {
+
       return 0;
+    }
   }

   // If we made it this far, we have an interesting solib.
@@ -923,7 +940,7 @@ stapiu_mmap_found(struct stap_task_finder_target *tf_target,
       spin_lock_irqsave (&c->process_list_lock, flags);
       list_add(&p->process_list, &c->process_list_head);
       spin_unlock_irqrestore (&c->process_list_lock, flags);
     } else
       _stp_warn("out of memory tracking solib %s in process %ld\n",
                 path, (long) task->tgid);
```
this is just a draft code to show what I want to change.
is this way work?
A further idea is that we can add an option like --use-proc-path to find the uprobe file path at a given pid.


             reply	other threads:[~2022-07-13  5:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-13  5:18 Cong Wu [this message]
2022-08-18 17:35 ` Frank Ch. Eigler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=HK0PR01MB34916D6B6B1BD921A62CCA64C9899@HK0PR01MB3491.apcprd01.prod.exchangelabs.com \
    --to=congwu@alauda.io \
    --cc=systemtap@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).