Advertisement
yichun

Untitled

Dec 19th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.47 KB | None | 0 0
  1. diff --git a/runtime/linux/debug.h b/runtime/linux/debug.h
  2. index e23ee96e7..02921de0d 100644
  3. --- a/runtime/linux/debug.h
  4. +++ b/runtime/linux/debug.h
  5. @@ -73,6 +73,16 @@
  6.  #define dbug_unwind(level, args...) ;
  7.  #endif
  8.  
  9. +
  10. +#ifdef DEBUG_TASK_FINDER
  11. +#define dbug_task(args...) do {                                     \
  12. +       _stp_dbug(__FUNCTION__, __LINE__, args);        \
  13. +   } while (0)
  14. +#else
  15. +#define dbug_task(level, args...) ;
  16. +#endif
  17. +
  18. +
  19.  #if defined(DEBUG_TASK_FINDER_VMA)
  20.  #define dbug_task_vma(level, args...) do {                                     \
  21.                 if ((level) <= DEBUG_TASK_FINDER_VMA)                               \
  22. diff --git a/runtime/linux/task_finder2.c b/runtime/linux/task_finder2.c
  23. index 6f5d637da..77a8dc615 100644
  24. --- a/runtime/linux/task_finder2.c
  25. +++ b/runtime/linux/task_finder2.c
  26. @@ -36,9 +36,9 @@ static atomic_t __stp_attach_count = ATOMIC_INIT (0);
  27.  #define debug_task_finder_attach() (atomic_inc(&__stp_attach_count))
  28.  #define debug_task_finder_detach() (atomic_dec(&__stp_attach_count))
  29.  #define debug_task_finder_report()                 \
  30. -    (printk(KERN_ERR "%s:%d - attach count: %d, inuse count: %d\n",    \
  31. -       __FUNCTION__, __LINE__, atomic_read(&__stp_attach_count),   \
  32. -       atomic_read(&__stp_inuse_count)))
  33. +    dbug_task("attach count: %d, inuse count: %d\n",   \
  34. +       atomic_read(&__stp_attach_count),   \
  35. +       atomic_read(&__stp_inuse_count))
  36.  #else
  37.  #define debug_task_finder_attach() /* empty */
  38.  #define debug_task_finder_detach() /* empty */
  39. @@ -248,6 +248,8 @@ stap_register_task_finder_target(struct stap_task_finder_target *new_tgt)
  40.     else
  41.         new_tgt->pathlen = 0;
  42.  
  43. +   dbug_task("find target");
  44. +
  45.     // Make sure everything is initialized properly.
  46.     new_tgt->engine_attached = 0;
  47.     new_tgt->mmap_events = 0;
  48. @@ -518,7 +520,9 @@ __stp_utrace_attach(struct task_struct *tsk,
  49.  
  50.     engine = utrace_attach_task(tsk, UTRACE_ATTACH_CREATE, ops, data);
  51.     if (IS_ERR(engine)) {
  52. -       int error = -PTR_ERR(engine);
  53. +       int error;
  54. +       dbug_task("utrace_attach_task returned error");
  55. +       error = -PTR_ERR(engine);
  56.         if (error != ESRCH && error != ENOENT) {
  57.             _stp_error("utrace_attach returned error %d on pid %d",
  58.                    error, (int)tsk->pid);
  59. @@ -526,12 +530,15 @@ __stp_utrace_attach(struct task_struct *tsk,
  60.         }
  61.     }
  62.     else if (unlikely(engine == NULL)) {
  63. +       dbug_task("utrace_attach_task returned NULL");
  64.         _stp_error("utrace_attach returned NULL on pid %d",
  65.                (int)tsk->pid);
  66.         rc = EFAULT;
  67.     }
  68.     else {
  69. +       dbug_task("utrace_attach_task returned success");
  70.         rc = utrace_set_events(tsk, engine, event_flags);
  71. +       dbug_task("utrace_set_events returned %d", rc);
  72.         if (rc == -EINPROGRESS) {
  73.             /*
  74.              * It's running our callback, so we have to
  75. @@ -553,6 +560,7 @@ __stp_utrace_attach(struct task_struct *tsk,
  76.  
  77.             if (action != UTRACE_RESUME) {
  78.                 rc = utrace_control(tsk, engine, action);
  79. +               dbug_task("utrace_control returned %d", rc);
  80.                 /* If utrace_control() returns
  81.                  * EINPROGRESS when we're trying to
  82.                  * stop/interrupt, that means the task
  83. @@ -834,8 +842,10 @@ __stp_utrace_attach_match_filename(struct task_struct *tsk,
  84.             continue;
  85.         else if (tgt->pathlen > 0
  86.              && (tgt->pathlen != filelen
  87. -                || strcmp(tgt->procname, filename) != 0))
  88. +                || strcmp(tgt->procname, filename) != 0)) {
  89. +           dbug_task("path NOT equal: [%s] != [%s]", tgt->procname, filename);
  90.             continue;
  91. +       }
  92.         /* Ignore pid-based target, they were handled at startup. */
  93.         else if (tgt->pid != 0)
  94.             continue;
  95. @@ -854,6 +864,7 @@ __stp_utrace_attach_match_filename(struct task_struct *tsk,
  96.         }
  97.  #endif
  98.  
  99. +       dbug_task("utrace attach to %d", tsk->tgid);
  100.  
  101.         // Set up events we need for attached tasks. We won't
  102.         // actually call the callbacks here - we'll call them
  103. @@ -1657,9 +1668,14 @@ stap_start_task_finder(void)
  104.         if (_stp_target && tsk->tgid != _stp_target)
  105.             continue;
  106.  
  107. +       dbug_task("utrace attaching pid %d", tsk->tgid);
  108. +
  109.         rc = __stp_utrace_attach(tsk, &__stp_utrace_task_finder_ops, 0,
  110.                      __STP_TASK_FINDER_EVENTS,
  111.                      UTRACE_RESUME);
  112. +
  113. +       dbug_task("utrace attach returned %d", rc);
  114. +
  115.         if (rc == EPERM) {
  116.             /* Ignore EPERM errors, which mean this wasn't
  117.              * a thread we can attach to. */
  118. @@ -1724,13 +1740,20 @@ stap_start_task_finder(void)
  119.             else if (tgt->pathlen > 0
  120.                  && (tgt->pathlen != mmpathlen
  121.                      || strcmp(tgt->procname, mmpath) != 0))
  122. +           {
  123. +               dbug_task("path not equal: [%s] != [%s]", tgt->procname, mmpath);
  124.                 continue;
  125. +           }
  126.             /* pid-based target */
  127.             else if (tgt->pid != 0 && tgt->pid != tsk->pid)
  128.                 continue;
  129.             /* Notice that "pid == 0" (which means to
  130.              * probe all threads) falls through. */
  131.  
  132. +           if (tgt->pathlen > 0) {
  133. +               dbug_task("path equal: [%s] == [%s]", tgt->procname, mmpath);
  134. +           }
  135. +
  136.  #if ! STP_PRIVILEGE_CONTAINS (STP_PRIVILEGE, STP_PR_STAPDEV) && \
  137.      ! STP_PRIVILEGE_CONTAINS (STP_PRIVILEGE, STP_PR_STAPSYS)
  138.             /* Make sure unprivileged users only probe their own threads.  */
  139. @@ -1739,14 +1762,20 @@ stap_start_task_finder(void)
  140.                     _stp_warn("Process %d does not belong to unprivileged user %d",
  141.                           tsk->pid, _stp_uid);
  142.                 }
  143. +               dbug_task("uid != euid: %d != %d", _stp_uid, tsk_euid);
  144.                 continue;
  145.             }
  146.  #endif
  147.  
  148. +           dbug_task("setting up events for %d", tsk->tgid);
  149. +
  150.             // Set up events we need for attached tasks.
  151.             rc = __stp_utrace_attach(tsk, &tgt->ops, tgt,
  152.                          __STP_ATTACHED_TASK_EVENTS,
  153.                          UTRACE_STOP);
  154. +
  155. +           dbug_task("utrace attach returned %d", rc);
  156. +
  157.             if (rc != 0 && rc != EPERM)
  158.                 goto stf_err;
  159.             rc = 0;     /* ignore EPERM */
  160. @@ -1771,18 +1800,13 @@ stap_task_finder_post_init(void)
  161.         return;
  162.     }
  163.  
  164. -#ifdef DEBUG_TASK_FINDER
  165. -   printk(KERN_ERR "%s:%d - entry.\n", __FUNCTION__, __LINE__);
  166. -#endif
  167. +   dbug_task("entry.");
  168.     rcu_read_lock();
  169.     do_each_thread(grp, tsk) {
  170.         struct list_head *tgt_node;
  171.  
  172.         if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING) {
  173. -#ifdef DEBUG_TASK_FINDER
  174. -           printk(KERN_ERR "%s:%d - exiting early...\n",
  175. -                  __FUNCTION__, __LINE__);
  176. -#endif
  177. +           dbug_task("exiting early...");
  178.             break;
  179.         }
  180.  
  181. @@ -1794,6 +1818,8 @@ stap_task_finder_post_init(void)
  182.         if (tsk->tgid != tsk->pid)
  183.             continue;
  184.  
  185. +       dbug_task("checking task %d:%d", tsk->pid, tsk->tgid);
  186. +
  187.         /* See if we need to "poke" this thread. */
  188.         list_for_each(tgt_node, &__stp_task_finder_list) {
  189.             struct stap_task_finder_target *tgt;
  190. @@ -1804,14 +1830,19 @@ stap_task_finder_post_init(void)
  191.             if (tgt == NULL || !tgt->engine_attached)
  192.                 continue;
  193.  
  194. +           dbug_task("attaching to task %d", tsk->tgid);
  195. +
  196.             // If we found an "interesting" task earlier,
  197.             // stop it.
  198.             engine = utrace_attach_task(tsk,
  199.                             UTRACE_ATTACH_MATCH_OPS,
  200.                             &tgt->ops, tgt);
  201.             if (engine != NULL && !IS_ERR(engine)) {
  202. +               int rc;
  203. +               dbug_task("found the target task %d, stopping it...", tsk->tgid);
  204. +
  205.                 /* We found a target task. Stop it. */
  206. -               int rc = utrace_control(tsk, engine,
  207. +               rc = utrace_control(tsk, engine,
  208.                             UTRACE_INTERRUPT);
  209.                 /* If utrace_control() returns
  210.                  * EINPROGRESS when we're
  211. @@ -1824,6 +1855,9 @@ stap_task_finder_post_init(void)
  212.                     _stp_error("utrace_control returned error %d on pid %d",
  213.                            rc, (int)tsk->pid);
  214.                 }
  215. +
  216. +               dbug_task("interrupting task returned %d (%d)", rc, -EINPROGRESS);
  217. +
  218.                 utrace_engine_put(engine);
  219.  
  220.                 /* Since we only need to interrupt
  221. @@ -1835,9 +1869,7 @@ stap_task_finder_post_init(void)
  222.     } while_each_thread(grp, tsk);
  223.     rcu_read_unlock();
  224.     atomic_set(&__stp_task_finder_complete, 1);
  225. -#ifdef DEBUG_TASK_FINDER
  226. -   printk(KERN_ERR "%s:%d - exit.\n", __FUNCTION__, __LINE__);
  227. -#endif
  228. +   dbug_task("exit.");
  229.     return;
  230.  }
  231.  
  232. @@ -1858,7 +1890,7 @@ stap_stop_task_finder(void)
  233.  #ifdef DEBUG_TASK_FINDER
  234.     int i = 0;
  235.  
  236. -   printk(KERN_ERR "%s:%d - entry\n", __FUNCTION__, __LINE__);
  237. +   dbug_task("entry");
  238.  #endif
  239.     if (atomic_read(&__stp_task_finder_state) == __STP_TF_UNITIALIZED)
  240.         return;
  241. @@ -1886,7 +1918,7 @@ stap_stop_task_finder(void)
  242.     }
  243.  #ifdef DEBUG_TASK_FINDER
  244.     if (i > 0)
  245. -       printk(KERN_ERR "it took %d polling loops to quit.\n", i);
  246. +       dbug_task("it took %d polling loops to quit.", i);
  247.  #endif
  248.     debug_task_finder_report();
  249.  
  250. @@ -1903,9 +1935,7 @@ stap_stop_task_finder(void)
  251.      * everything. */
  252.     __stp_tf_free_all_task_work();
  253.  
  254. -#ifdef DEBUG_TASK_FINDER
  255. -   printk(KERN_ERR "%s:%d - exit\n", __FUNCTION__, __LINE__);
  256. -#endif
  257. +   dbug_task("exit");
  258.  }
  259.  
  260.  #endif /* TASK_FINDER2_C */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement