Advertisement
yichun

Untitled

Dec 20th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 25.55 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..66b884917 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. @@ -519,6 +521,7 @@ __stp_utrace_attach(struct task_struct *tsk,
  49.     engine = utrace_attach_task(tsk, UTRACE_ATTACH_CREATE, ops, data);
  50.     if (IS_ERR(engine)) {
  51.         int error = -PTR_ERR(engine);
  52. +       dbug_task("utrace_attach_task returned an error: %d", error);
  53.         if (error != ESRCH && error != ENOENT) {
  54.             _stp_error("utrace_attach returned error %d on pid %d",
  55.                    error, (int)tsk->pid);
  56. @@ -526,12 +529,15 @@ __stp_utrace_attach(struct task_struct *tsk,
  57.         }
  58.     }
  59.     else if (unlikely(engine == NULL)) {
  60. +       dbug_task("utrace_attach_task returned NULL");
  61.         _stp_error("utrace_attach returned NULL on pid %d",
  62.                (int)tsk->pid);
  63.         rc = EFAULT;
  64.     }
  65.     else {
  66. +       dbug_task("utrace_attach_task returned successfully");
  67.         rc = utrace_set_events(tsk, engine, event_flags);
  68. +       dbug_task("utrace_set_events returned %d", rc);
  69.         if (rc == -EINPROGRESS) {
  70.             /*
  71.              * It's running our callback, so we have to
  72. @@ -553,6 +559,7 @@ __stp_utrace_attach(struct task_struct *tsk,
  73.  
  74.             if (action != UTRACE_RESUME) {
  75.                 rc = utrace_control(tsk, engine, action);
  76. +               dbug_task("utrace_control returned %d", rc);
  77.                 /* If utrace_control() returns
  78.                  * EINPROGRESS when we're trying to
  79.                  * stop/interrupt, that means the task
  80. @@ -588,9 +595,13 @@ __stp_call_callbacks(struct stap_task_finder_target *tgt,
  81.     struct list_head *cb_node;
  82.     int rc;
  83.  
  84. +   dbug_task("entering tgt=%p tsk=%p pid=%d", tgt, tsk, tsk ? tsk->tgid : -1);
  85. +
  86.     if (tgt == NULL || tsk == NULL)
  87.         return;
  88.  
  89. +   dbug_task("pid: %d", tsk->tgid);
  90. +
  91.     list_for_each(cb_node, &tgt->callback_list_head) {
  92.         struct stap_task_finder_target *cb_tgt;
  93.  
  94. @@ -599,7 +610,15 @@ __stp_call_callbacks(struct stap_task_finder_target *tgt,
  95.         if (cb_tgt == NULL || cb_tgt->callback == NULL)
  96.             continue;
  97.  
  98. +       dbug_task("calling %s callback %p (proc=%s pid=%d, pathlen=%d, "
  99. +             "engine-attached=%d)",
  100. +             (cb_tgt->purpose?:""), cb_tgt->callback, cb_tgt->procname, cb_tgt->pid,
  101. +             (int) cb_tgt->pathlen, cb_tgt->engine_attached);
  102. +
  103.         rc = cb_tgt->callback(cb_tgt, tsk, register_p, process_p);
  104. +
  105. +       dbug_task("callback returned %d", rc);
  106. +
  107.         if (rc != 0) {
  108.             _stp_warn("task_finder %s%scallback for task %d failed: %d",
  109.                                    (cb_tgt->purpose?:""), (cb_tgt->purpose?" ":""),
  110. @@ -834,8 +853,10 @@ __stp_utrace_attach_match_filename(struct task_struct *tsk,
  111.             continue;
  112.         else if (tgt->pathlen > 0
  113.              && (tgt->pathlen != filelen
  114. -                || strcmp(tgt->procname, filename) != 0))
  115. +                || strcmp(tgt->procname, filename) != 0)) {
  116. +           dbug_task("path NOT equal: [%s] != [%s]", tgt->procname, filename);
  117.             continue;
  118. +       }
  119.         /* Ignore pid-based target, they were handled at startup. */
  120.         else if (tgt->pid != 0)
  121.             continue;
  122. @@ -854,6 +875,7 @@ __stp_utrace_attach_match_filename(struct task_struct *tsk,
  123.         }
  124.  #endif
  125.  
  126. +       dbug_task("utrace attach to %d", tsk->tgid);
  127.  
  128.         // Set up events we need for attached tasks. We won't
  129.         // actually call the callbacks here - we'll call them
  130. @@ -1657,9 +1679,14 @@ stap_start_task_finder(void)
  131.         if (_stp_target && tsk->tgid != _stp_target)
  132.             continue;
  133.  
  134. +       dbug_task("utrace attaching pid %d", tsk->tgid);
  135. +
  136.         rc = __stp_utrace_attach(tsk, &__stp_utrace_task_finder_ops, 0,
  137.                      __STP_TASK_FINDER_EVENTS,
  138.                      UTRACE_RESUME);
  139. +
  140. +       dbug_task("utrace attach returned %d", rc);
  141. +
  142.         if (rc == EPERM) {
  143.             /* Ignore EPERM errors, which mean this wasn't
  144.              * a thread we can attach to. */
  145. @@ -1724,13 +1751,20 @@ stap_start_task_finder(void)
  146.             else if (tgt->pathlen > 0
  147.                  && (tgt->pathlen != mmpathlen
  148.                      || strcmp(tgt->procname, mmpath) != 0))
  149. +           {
  150. +               dbug_task("path not equal: [%s] != [%s]", tgt->procname, mmpath);
  151.                 continue;
  152. +           }
  153.             /* pid-based target */
  154.             else if (tgt->pid != 0 && tgt->pid != tsk->pid)
  155.                 continue;
  156.             /* Notice that "pid == 0" (which means to
  157.              * probe all threads) falls through. */
  158.  
  159. +           if (tgt->pathlen > 0) {
  160. +               dbug_task("path equal: [%s] == [%s]", tgt->procname, mmpath);
  161. +           }
  162. +
  163.  #if ! STP_PRIVILEGE_CONTAINS (STP_PRIVILEGE, STP_PR_STAPDEV) && \
  164.      ! STP_PRIVILEGE_CONTAINS (STP_PRIVILEGE, STP_PR_STAPSYS)
  165.             /* Make sure unprivileged users only probe their own threads.  */
  166. @@ -1739,14 +1773,20 @@ stap_start_task_finder(void)
  167.                     _stp_warn("Process %d does not belong to unprivileged user %d",
  168.                           tsk->pid, _stp_uid);
  169.                 }
  170. +               dbug_task("uid != euid: %d != %d", _stp_uid, tsk_euid);
  171.                 continue;
  172.             }
  173.  #endif
  174.  
  175. +           dbug_task("setting up events for %d", tsk->tgid);
  176. +
  177.             // Set up events we need for attached tasks.
  178.             rc = __stp_utrace_attach(tsk, &tgt->ops, tgt,
  179.                          __STP_ATTACHED_TASK_EVENTS,
  180.                          UTRACE_STOP);
  181. +
  182. +           dbug_task("utrace attach returned %d", rc);
  183. +
  184.             if (rc != 0 && rc != EPERM)
  185.                 goto stf_err;
  186.             rc = 0;     /* ignore EPERM */
  187. @@ -1771,18 +1811,13 @@ stap_task_finder_post_init(void)
  188.         return;
  189.     }
  190.  
  191. -#ifdef DEBUG_TASK_FINDER
  192. -   printk(KERN_ERR "%s:%d - entry.\n", __FUNCTION__, __LINE__);
  193. -#endif
  194. +   dbug_task("entry.");
  195.     rcu_read_lock();
  196.     do_each_thread(grp, tsk) {
  197.         struct list_head *tgt_node;
  198.  
  199.         if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING) {
  200. -#ifdef DEBUG_TASK_FINDER
  201. -           printk(KERN_ERR "%s:%d - exiting early...\n",
  202. -                  __FUNCTION__, __LINE__);
  203. -#endif
  204. +           dbug_task("exiting early...");
  205.             break;
  206.         }
  207.  
  208. @@ -1794,6 +1829,8 @@ stap_task_finder_post_init(void)
  209.         if (tsk->tgid != tsk->pid)
  210.             continue;
  211.  
  212. +       dbug_task("checking task %d:%d", tsk->pid, tsk->tgid);
  213. +
  214.         /* See if we need to "poke" this thread. */
  215.         list_for_each(tgt_node, &__stp_task_finder_list) {
  216.             struct stap_task_finder_target *tgt;
  217. @@ -1804,14 +1841,19 @@ stap_task_finder_post_init(void)
  218.             if (tgt == NULL || !tgt->engine_attached)
  219.                 continue;
  220.  
  221. +           dbug_task("attaching to task %d", tsk->tgid);
  222. +
  223.             // If we found an "interesting" task earlier,
  224.             // stop it.
  225.             engine = utrace_attach_task(tsk,
  226.                             UTRACE_ATTACH_MATCH_OPS,
  227.                             &tgt->ops, tgt);
  228.             if (engine != NULL && !IS_ERR(engine)) {
  229. +               int rc;
  230. +               dbug_task("found the target task %d, stopping it...", tsk->tgid);
  231. +
  232.                 /* We found a target task. Stop it. */
  233. -               int rc = utrace_control(tsk, engine,
  234. +               rc = utrace_control(tsk, engine,
  235.                             UTRACE_INTERRUPT);
  236.                 /* If utrace_control() returns
  237.                  * EINPROGRESS when we're
  238. @@ -1824,6 +1866,9 @@ stap_task_finder_post_init(void)
  239.                     _stp_error("utrace_control returned error %d on pid %d",
  240.                            rc, (int)tsk->pid);
  241.                 }
  242. +
  243. +               dbug_task("interrupting task returned %d (%d)", rc, -EINPROGRESS);
  244. +
  245.                 utrace_engine_put(engine);
  246.  
  247.                 /* Since we only need to interrupt
  248. @@ -1835,9 +1880,7 @@ stap_task_finder_post_init(void)
  249.     } while_each_thread(grp, tsk);
  250.     rcu_read_unlock();
  251.     atomic_set(&__stp_task_finder_complete, 1);
  252. -#ifdef DEBUG_TASK_FINDER
  253. -   printk(KERN_ERR "%s:%d - exit.\n", __FUNCTION__, __LINE__);
  254. -#endif
  255. +   dbug_task("exit.");
  256.     return;
  257.  }
  258.  
  259. @@ -1858,7 +1901,7 @@ stap_stop_task_finder(void)
  260.  #ifdef DEBUG_TASK_FINDER
  261.     int i = 0;
  262.  
  263. -   printk(KERN_ERR "%s:%d - entry\n", __FUNCTION__, __LINE__);
  264. +   dbug_task("entry");
  265.  #endif
  266.     if (atomic_read(&__stp_task_finder_state) == __STP_TF_UNITIALIZED)
  267.         return;
  268. @@ -1886,7 +1929,7 @@ stap_stop_task_finder(void)
  269.     }
  270.  #ifdef DEBUG_TASK_FINDER
  271.     if (i > 0)
  272. -       printk(KERN_ERR "it took %d polling loops to quit.\n", i);
  273. +       dbug_task("it took %d polling loops to quit.", i);
  274.  #endif
  275.     debug_task_finder_report();
  276.  
  277. @@ -1903,9 +1946,7 @@ stap_stop_task_finder(void)
  278.      * everything. */
  279.     __stp_tf_free_all_task_work();
  280.  
  281. -#ifdef DEBUG_TASK_FINDER
  282. -   printk(KERN_ERR "%s:%d - exit\n", __FUNCTION__, __LINE__);
  283. -#endif
  284. +   dbug_task("exit");
  285.  }
  286.  
  287.  #endif /* TASK_FINDER2_C */
  288. diff --git a/tapset-been.cxx b/tapset-been.cxx
  289. index 61b3b18a3..1107d3e76 100644
  290. --- a/tapset-been.cxx
  291. +++ b/tapset-been.cxx
  292. @@ -149,7 +149,7 @@ be_derived_probe_group::emit_module_decls (systemtap_session& s)
  293.  
  294.    s.op->newline() << "static void enter_be_probe (struct stap_be_probe *stp) {";
  295.    s.op->indent(1);
  296. -  common_probe_entryfn_prologue (s, "stp->state", "stp->probe",
  297. +  common_probe_entryfn_prologue (s, "stp->state", "", "stp->probe",
  298.                  "stp_probe_type_been", false);
  299.    s.op->newline() << "(*stp->probe->ph) (c);";
  300.    common_probe_entryfn_epilogue (s, false, otf_safe_context(s));
  301. diff --git a/tapset-itrace.cxx b/tapset-itrace.cxx
  302. index 4682e7674..0a262076c 100644
  303. --- a/tapset-itrace.cxx
  304. +++ b/tapset-itrace.cxx
  305. @@ -199,7 +199,7 @@ itrace_derived_probe_group::emit_module_decls (systemtap_session& s)
  306.    s.op->newline() << "static void enter_itrace_probe(struct stap_itrace_probe *p, struct pt_regs *regs, void *data) {";
  307.    s.op->indent(1);
  308.  
  309. -  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "p->probe",
  310. +  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "", "p->probe",
  311.                  "stp_probe_type_itrace");
  312.    s.op->newline() << "c->uregs = regs;";
  313.    s.op->newline() << "c->user_mode_p = 1;";
  314. diff --git a/tapset-mark.cxx b/tapset-mark.cxx
  315. index 2dec501c8..5a48eaa76 100644
  316. --- a/tapset-mark.cxx
  317. +++ b/tapset-mark.cxx
  318. @@ -509,7 +509,7 @@ mark_derived_probe_group::emit_module_decls (systemtap_session& s)
  319.    s.op->newline();
  320.    s.op->newline() << "static void enter_marker_probe (void *probe_data, void *call_data, const char *fmt, va_list *args) {";
  321.    s.op->newline(1) << "struct stap_marker_probe *smp = (struct stap_marker_probe *)probe_data;";
  322. -  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "smp->probe",
  323. +  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "", "smp->probe",
  324.                  "stp_probe_type_marker");
  325.    s.op->newline() << "c->ips.kmark.marker_name = smp->name;";
  326.    s.op->newline() << "c->ips.kmark.marker_format = smp->format;";
  327. diff --git a/tapset-netfilter.cxx b/tapset-netfilter.cxx
  328. index 1c6952e1f..a6ae5909d 100644
  329. --- a/tapset-netfilter.cxx
  330. +++ b/tapset-netfilter.cxx
  331. @@ -313,7 +313,7 @@ netfilter_derived_probe_group::emit_module_decls (systemtap_session& s)
  332.        s.op->newline() << "#elif defined(STAPCONF_NETFILTER_V41)";
  333.        s.op->newline() << "int (*nf_okfn)(struct sock *, struct sk_buff *) = nf_state->okfn;";
  334.        s.op->newline() << "#endif";
  335. -      common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "stp",
  336. +      common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "", "stp",
  337.                                       "stp_probe_type_netfilter",
  338.                                       false);
  339.  
  340. diff --git a/tapset-perfmon.cxx b/tapset-perfmon.cxx
  341. index 11dbbd32b..2b9f5ad42 100644
  342. --- a/tapset-perfmon.cxx
  343. +++ b/tapset-perfmon.cxx
  344. @@ -235,7 +235,7 @@ perf_derived_probe_group::emit_module_decls (systemtap_session& s)
  345.    s.op->newline() << "static void handle_perf_probe (unsigned i, struct pt_regs *regs)";
  346.    s.op->newline() << "{";
  347.    s.op->newline(1) << "struct stap_perf_probe* stp = & stap_perf_probes [i];";
  348. -  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "stp->probe",
  349. +  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "", "stp->probe",
  350.                  "stp_probe_type_perf");
  351.    s.op->newline() << "if (user_mode(regs)) {";
  352.    s.op->newline(1)<< "c->user_mode_p = 1;";
  353. diff --git a/tapset-procfs.cxx b/tapset-procfs.cxx
  354. index c39f20fcb..c5087afcb 100644
  355. --- a/tapset-procfs.cxx
  356. +++ b/tapset-procfs.cxx
  357. @@ -366,7 +366,7 @@ procfs_derived_probe_group::emit_module_decls (systemtap_session& s)
  358.      {
  359.        s.op->newline() << "struct _stp_procfs_data pdata;";
  360.  
  361. -      common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING",
  362. +      common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "",
  363.                      "spp->read_probe",
  364.                      "stp_probe_type_procfs");
  365.  
  366. @@ -412,7 +412,7 @@ procfs_derived_probe_group::emit_module_decls (systemtap_session& s)
  367.      {
  368.        s.op->newline() << "struct _stp_procfs_data pdata;";
  369.  
  370. -      common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING",
  371. +      common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "",
  372.                      "spp->write_probes[0]",
  373.                      "stp_probe_type_procfs");
  374.  
  375. diff --git a/tapset-timers.cxx b/tapset-timers.cxx
  376. index 8dd00a1b9..4949b6e14 100644
  377. --- a/tapset-timers.cxx
  378. +++ b/tapset-timers.cxx
  379. @@ -136,7 +136,7 @@ timer_derived_probe_group::emit_module_decls (systemtap_session& s)
  380.    s.op->line() << ");";
  381.    s.op->newline(-1) << "{";
  382.    s.op->indent(1);
  383. -  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "stp->probe",
  384. +  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "", "stp->probe",
  385.                  "stp_probe_type_timer");
  386.    s.op->newline() << "(*stp->probe->ph) (c);";
  387.    common_probe_entryfn_epilogue (s, true, otf_safe_context(s));
  388. @@ -293,7 +293,7 @@ hrtimer_derived_probe_group::emit_module_decls (systemtap_session& s)
  389.  
  390.        s.op->newline() << "{";
  391.        s.op->indent(1);
  392. -      common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "stp->probe",
  393. +      common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "", "stp->probe",
  394.                      "stp_probe_type_hrtimer");
  395.        s.op->newline() << "(*stp->probe->ph) (c);";
  396.        common_probe_entryfn_epilogue (s, true, otf_safe_context(s));
  397. @@ -315,7 +315,8 @@ hrtimer_derived_probe_group::emit_module_decls (systemtap_session& s)
  398.  
  399.        s.op->newline() << "{";
  400.        s.op->indent(1);
  401. -      common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "stp->probe",
  402. +      common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "",
  403. +                                     "stp->probe",
  404.                      "stp_probe_type_hrtimer");
  405.        s.op->newline() << "(*stp->probe->ph) (c);";
  406.        common_probe_entryfn_epilogue (s, true, otf_safe_context(s));
  407. @@ -483,7 +484,7 @@ profile_derived_probe_group::emit_module_decls (systemtap_session& s)
  408.    s.op->newline() << "static void enter_all_profile_probes (struct pt_regs *regs) {";
  409.    s.op->newline(1) << "const struct stap_probe * probe = "
  410.                     << common_probe_init (probes[0]) << ";";
  411. -  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "probe",
  412. +  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "", "probe",
  413.                  "stp_probe_type_profile_timer");
  414.    // Timer interrupts save all registers, so if the interrupt happened
  415.    // in user space we can rely on it being the full user pt_regs.
  416. diff --git a/tapset-utrace.cxx b/tapset-utrace.cxx
  417. index 2b644843a..2214e3010 100644
  418. --- a/tapset-utrace.cxx
  419. +++ b/tapset-utrace.cxx
  420. @@ -862,10 +862,13 @@ utrace_derived_probe_group::emit_module_linux_decls (systemtap_session& s)
  421.        s.op->newline() << "static void stap_utrace_probe_handler(struct task_struct *tsk, struct stap_utrace_probe *p) {";
  422.        s.op->indent(1);
  423.  
  424. -      common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "p->probe",
  425. +      common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING",
  426. +                                     "STAP_SESSION_STARTING",
  427. +                                     "p->probe",
  428.                      "stp_probe_type_utrace");
  429.  
  430.        // call probe function
  431. +      s.op->newline() << "dbug_task(\"calling UDPF probe function\");";
  432.        s.op->newline() << "(*p->probe->ph) (c);";
  433.        common_probe_entryfn_epilogue (s, true, otf_safe_context(s));
  434.  
  435. @@ -889,7 +892,7 @@ utrace_derived_probe_group::emit_module_linux_decls (systemtap_session& s)
  436.        s.op->indent(1);
  437.        s.op->newline() << "struct stap_utrace_probe *p = (struct stap_utrace_probe *)engine->data;";
  438.  
  439. -      common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "p->probe",
  440. +      common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "", "p->probe",
  441.                      "stp_probe_type_utrace_syscall");
  442.        s.op->newline() << "c->uregs = regs;";
  443.        s.op->newline() << "c->user_mode_p = 1;";
  444. @@ -914,6 +917,7 @@ utrace_derived_probe_group::emit_module_linux_decls (systemtap_session& s)
  445.    s.op->newline() << "int rc = 0;";
  446.    s.op->newline() << "struct stap_utrace_probe *p = container_of(tgt, struct stap_utrace_probe, tgt);";
  447.    s.op->newline() << "struct utrace_engine *engine;";
  448. +  s.op->newline() << "dbug_task(\"utrace probe cb: register_p=%d process_p=%d, p->flags=%x (begin: %d, thr begin: %d)\", register_p, process_p, (unsigned) p->flags, UDPF_BEGIN, UDPF_THREAD_BEGIN);";
  449.  
  450.    s.op->newline() << "if (register_p) {";
  451.    s.op->indent(1);
  452. @@ -1176,7 +1180,7 @@ utrace_derived_probe_group::emit_module_dyninst_decls (systemtap_session& s)
  453.                    << "(uint64_t index, struct pt_regs *regs) {";
  454.    s.op->newline(1) << "struct stapdu_probe *sup = &stapdu_probes[index];";
  455.  
  456. -  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "sup->probe",
  457. +  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "", "sup->probe",
  458.                                   "stp_probe_type_utrace");
  459.    s.op->newline() << "c->uregs = regs ?: &stapdu_dummy_uregs;";
  460.    s.op->newline() << "c->user_mode_p = 1;";
  461. diff --git a/tapsets.cxx b/tapsets.cxx
  462. index b83960a2e..24b4e264d 100644
  463. --- a/tapsets.cxx
  464. +++ b/tapsets.cxx
  465. @@ -91,7 +91,7 @@ common_probe_init (derived_probe* p)
  466.  
  467.  void
  468.  common_probe_entryfn_prologue (systemtap_session& s,
  469. -                  string statestr, string probe,
  470. +                  string statestr, string statestr2, string probe,
  471.                    string probe_type, bool overload_processing,
  472.                    void (*declaration_callback)(systemtap_session& s, void *data),
  473.                    void (*pre_context_callback)(systemtap_session& s, void *data),
  474. @@ -159,9 +159,25 @@ common_probe_entryfn_prologue (systemtap_session& s,
  475.        s.op->newline(-1) << "}";
  476.      }
  477.  
  478. -  s.op->newline() << "if (atomic_read (session_state()) != " << statestr << ")";
  479. -  s.op->newline(1) << "goto probe_epilogue;";
  480. -  s.op->indent(-1);
  481. +  s.op->newline() << "{";
  482. +  s.op->newline(1) << "unsigned sess_state = atomic_read (session_state());";
  483. +  s.op->newline() << "#ifdef DEBUG_PROBES";
  484. +  s.op->newline() << "_stp_dbug(__FUNCTION__, __LINE__, \"session state: %d\", "
  485. +    "sess_state);";
  486. +  s.op->newline() << "#endif";
  487. +  s.op->newline() << "if (sess_state != " << statestr
  488. +    << (statestr2.empty() ? "" : string(" && sess_state != ") + statestr2)
  489. +    << ") {";
  490. +  s.op->newline(1) << "#ifdef DEBUG_PROBES";
  491. +  s.op->newline() << "_stp_dbug(__FUNCTION__, __LINE__, \"session state %d != "
  492. +    << statestr << " (%d)" << (statestr2.empty() ? "" : string(" or ")
  493. +                               + statestr2 + " (%d)")
  494. +    << "\", sess_state, " << statestr
  495. +    << (statestr2.empty() ? "" : string(", ") + statestr2)  << ");";
  496. +  s.op->newline() << "#endif";
  497. +  s.op->newline() << "goto probe_epilogue;";
  498. +  s.op->newline(-1) << "}";
  499. +  s.op->newline(-1) << "}";
  500.  
  501.    if (pre_context_callback)
  502.      {
  503. @@ -6079,7 +6095,7 @@ generic_kprobe_derived_probe_group::emit_module_decls (systemtap_session& s)
  504.    s.op->line() << "kprobe_idx:0)"; // NB: at least we avoid memory corruption
  505.    // XXX: it would be nice to give a more verbose error though; BUG_ON later?
  506.    s.op->line() << "];";
  507. -  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "skp->probe",
  508. +  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "", "skp->probe",
  509.                  "stp_probe_type_kprobe");
  510.    s.op->newline() << "c->kregs = regs;";
  511.  
  512. @@ -6116,7 +6132,7 @@ generic_kprobe_derived_probe_group::emit_module_decls (systemtap_session& s)
  513.    s.op->newline() << "const struct stap_probe *sp = entry ? skp->entry_probe : skp->probe;";
  514.    s.op->newline() << "if (sp) {";
  515.    s.op->indent(1);
  516. -  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "sp",
  517. +  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "", "sp",
  518.                  "stp_probe_type_kretprobe");
  519.    s.op->newline() << "c->kregs = regs;";
  520.  
  521. @@ -9465,7 +9481,7 @@ uprobe_derived_probe_group::emit_module_utrace_decls (systemtap_session& s)
  522.    s.op->newline() << "static void enter_uprobe_probe (struct uprobe *inst, struct pt_regs *regs) {";
  523.    s.op->newline(1) << "struct stap_uprobe *sup = container_of(inst, struct stap_uprobe, up);";
  524.    s.op->newline() << "const struct stap_uprobe_spec *sups = &stap_uprobe_specs [sup->spec_index];";
  525. -  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "sups->probe",
  526. +  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "", "sups->probe",
  527.                  "stp_probe_type_uprobe", true,
  528.                  udpg_entryfn_prologue_declaration_callback,
  529.                  udpg_entryfn_prologue_pre_context_callback,
  530. @@ -9500,7 +9516,7 @@ uprobe_derived_probe_group::emit_module_utrace_decls (systemtap_session& s)
  531.    s.op->newline() << "static void enter_uretprobe_probe (struct uretprobe_instance *inst, struct pt_regs *regs) {";
  532.    s.op->newline(1) << "struct stap_uprobe *sup = container_of(inst->rp, struct stap_uprobe, urp);";
  533.    s.op->newline() << "const struct stap_uprobe_spec *sups = &stap_uprobe_specs [sup->spec_index];";
  534. -  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "sups->probe",
  535. +  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "", "sups->probe",
  536.                  "stp_probe_type_uretprobe", true,
  537.                  udpg_entryfn_prologue_declaration_callback,
  538.                  udpg_entryfn_prologue_pre_context_callback,
  539. @@ -9664,7 +9680,7 @@ uprobe_derived_probe_group::emit_module_inode_decls (systemtap_session& s)
  540.  
  541.    // Since we're sharing the entry function, we have to dynamically choose the probe_type
  542.    string probe_type = "(sup->return_p ? stp_probe_type_uretprobe : stp_probe_type_uprobe)";
  543. -  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "sup->probe",
  544. +  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "", "sup->probe",
  545.                                   probe_type, true,
  546.                  udpg_entryfn_prologue_declaration_callback,
  547.                  udpg_entryfn_prologue_pre_context_callback,
  548. @@ -9857,7 +9873,7 @@ uprobe_derived_probe_group::emit_module_dyninst_decls (systemtap_session& s)
  549.    // Since we're sharing the entry function, we have to dynamically choose the probe_type
  550.    string probe_type = "((sup->flags & STAPDYN_PROBE_FLAG_RETURN) ?"
  551.                        " stp_probe_type_uretprobe : stp_probe_type_uprobe)";
  552. -  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "sup->probe",
  553. +  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "", "sup->probe",
  554.                                   probe_type);
  555.  
  556.    s.op->newline() << "c->uregs = regs ?: &stapdu_dummy_uregs;";
  557. @@ -10546,7 +10562,7 @@ hwbkpt_derived_probe_group::emit_module_decls (systemtap_session& s)
  558.    // XXX: why not match stap_hwbkpt_ret_array[i] against bp instead?
  559.    s.op->newline() << "if (bp->attr.bp_addr==hp->bp_addr && bp->attr.bp_type==hp->bp_type && bp->attr.bp_len==hp->bp_len) {";
  560.    s.op->newline(1) << "struct stap_hwbkpt_probe *skp = &stap_hwbkpt_probes[i];";
  561. -  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "skp->probe",
  562. +  common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "", "skp->probe",
  563.                  "stp_probe_type_hwbkpt");
  564.    s.op->newline() << "if (user_mode(regs)) {";
  565.    s.op->newline(1)<< "c->user_mode_p = 1;";
  566. @@ -11866,7 +11882,7 @@ tracepoint_derived_probe_group::emit_module_decls (systemtap_session& s)
  567.        s.op->newline() << "{";
  568.        s.op->newline(1) << "const struct stap_probe * const probe = "
  569.                         << common_probe_init (p) << ";";
  570. -      common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "probe",
  571. +      common_probe_entryfn_prologue (s, "STAP_SESSION_RUNNING", "", "probe",
  572.                      "stp_probe_type_tracepoint");
  573.        s.op->newline() << "c->ips.tp.tracepoint_system = "
  574.                        << lex_cast_qstring (p->tracepoint_system)
  575. diff --git a/tapsets.h b/tapsets.h
  576. index b52c35c21..2a11ebd6f 100644
  577. --- a/tapsets.h
  578. +++ b/tapsets.h
  579. @@ -21,6 +21,7 @@ void register_standard_tapsets(systemtap_session& sess);
  580.  std::vector<derived_probe_group*> all_session_groups(systemtap_session& s);
  581.  std::string common_probe_init (derived_probe* p);
  582.  void common_probe_entryfn_prologue (systemtap_session& s, std::string statestr,
  583. +                                    std::string statestr2,
  584.                     std::string probe, std::string probe_type,
  585.                     bool overload_processing = true,
  586.                     void (*declaration_callback)(systemtap_session& s, void* data) = NULL,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement