Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/runtime/linux/debug.h b/runtime/linux/debug.h
- index e23ee96e7..02921de0d 100644
- --- a/runtime/linux/debug.h
- +++ b/runtime/linux/debug.h
- @@ -73,6 +73,16 @@
- #define dbug_unwind(level, args...) ;
- #endif
- +
- +#ifdef DEBUG_TASK_FINDER
- +#define dbug_task(args...) do { \
- + _stp_dbug(__FUNCTION__, __LINE__, args); \
- + } while (0)
- +#else
- +#define dbug_task(level, args...) ;
- +#endif
- +
- +
- #if defined(DEBUG_TASK_FINDER_VMA)
- #define dbug_task_vma(level, args...) do { \
- if ((level) <= DEBUG_TASK_FINDER_VMA) \
- diff --git a/runtime/linux/task_finder2.c b/runtime/linux/task_finder2.c
- index 6f5d637da..77a8dc615 100644
- --- a/runtime/linux/task_finder2.c
- +++ b/runtime/linux/task_finder2.c
- @@ -36,9 +36,9 @@ static atomic_t __stp_attach_count = ATOMIC_INIT (0);
- #define debug_task_finder_attach() (atomic_inc(&__stp_attach_count))
- #define debug_task_finder_detach() (atomic_dec(&__stp_attach_count))
- #define debug_task_finder_report() \
- - (printk(KERN_ERR "%s:%d - attach count: %d, inuse count: %d\n", \
- - __FUNCTION__, __LINE__, atomic_read(&__stp_attach_count), \
- - atomic_read(&__stp_inuse_count)))
- + dbug_task("attach count: %d, inuse count: %d\n", \
- + atomic_read(&__stp_attach_count), \
- + atomic_read(&__stp_inuse_count))
- #else
- #define debug_task_finder_attach() /* empty */
- #define debug_task_finder_detach() /* empty */
- @@ -248,6 +248,8 @@ stap_register_task_finder_target(struct stap_task_finder_target *new_tgt)
- else
- new_tgt->pathlen = 0;
- + dbug_task("find target");
- +
- // Make sure everything is initialized properly.
- new_tgt->engine_attached = 0;
- new_tgt->mmap_events = 0;
- @@ -518,7 +520,9 @@ __stp_utrace_attach(struct task_struct *tsk,
- engine = utrace_attach_task(tsk, UTRACE_ATTACH_CREATE, ops, data);
- if (IS_ERR(engine)) {
- - int error = -PTR_ERR(engine);
- + int error;
- + dbug_task("utrace_attach_task returned error");
- + error = -PTR_ERR(engine);
- if (error != ESRCH && error != ENOENT) {
- _stp_error("utrace_attach returned error %d on pid %d",
- error, (int)tsk->pid);
- @@ -526,12 +530,15 @@ __stp_utrace_attach(struct task_struct *tsk,
- }
- }
- else if (unlikely(engine == NULL)) {
- + dbug_task("utrace_attach_task returned NULL");
- _stp_error("utrace_attach returned NULL on pid %d",
- (int)tsk->pid);
- rc = EFAULT;
- }
- else {
- + dbug_task("utrace_attach_task returned success");
- rc = utrace_set_events(tsk, engine, event_flags);
- + dbug_task("utrace_set_events returned %d", rc);
- if (rc == -EINPROGRESS) {
- /*
- * It's running our callback, so we have to
- @@ -553,6 +560,7 @@ __stp_utrace_attach(struct task_struct *tsk,
- if (action != UTRACE_RESUME) {
- rc = utrace_control(tsk, engine, action);
- + dbug_task("utrace_control returned %d", rc);
- /* If utrace_control() returns
- * EINPROGRESS when we're trying to
- * stop/interrupt, that means the task
- @@ -834,8 +842,10 @@ __stp_utrace_attach_match_filename(struct task_struct *tsk,
- continue;
- else if (tgt->pathlen > 0
- && (tgt->pathlen != filelen
- - || strcmp(tgt->procname, filename) != 0))
- + || strcmp(tgt->procname, filename) != 0)) {
- + dbug_task("path NOT equal: [%s] != [%s]", tgt->procname, filename);
- continue;
- + }
- /* Ignore pid-based target, they were handled at startup. */
- else if (tgt->pid != 0)
- continue;
- @@ -854,6 +864,7 @@ __stp_utrace_attach_match_filename(struct task_struct *tsk,
- }
- #endif
- + dbug_task("utrace attach to %d", tsk->tgid);
- // Set up events we need for attached tasks. We won't
- // actually call the callbacks here - we'll call them
- @@ -1657,9 +1668,14 @@ stap_start_task_finder(void)
- if (_stp_target && tsk->tgid != _stp_target)
- continue;
- + dbug_task("utrace attaching pid %d", tsk->tgid);
- +
- rc = __stp_utrace_attach(tsk, &__stp_utrace_task_finder_ops, 0,
- __STP_TASK_FINDER_EVENTS,
- UTRACE_RESUME);
- +
- + dbug_task("utrace attach returned %d", rc);
- +
- if (rc == EPERM) {
- /* Ignore EPERM errors, which mean this wasn't
- * a thread we can attach to. */
- @@ -1724,13 +1740,20 @@ stap_start_task_finder(void)
- else if (tgt->pathlen > 0
- && (tgt->pathlen != mmpathlen
- || strcmp(tgt->procname, mmpath) != 0))
- + {
- + dbug_task("path not equal: [%s] != [%s]", tgt->procname, mmpath);
- continue;
- + }
- /* pid-based target */
- else if (tgt->pid != 0 && tgt->pid != tsk->pid)
- continue;
- /* Notice that "pid == 0" (which means to
- * probe all threads) falls through. */
- + if (tgt->pathlen > 0) {
- + dbug_task("path equal: [%s] == [%s]", tgt->procname, mmpath);
- + }
- +
- #if ! STP_PRIVILEGE_CONTAINS (STP_PRIVILEGE, STP_PR_STAPDEV) && \
- ! STP_PRIVILEGE_CONTAINS (STP_PRIVILEGE, STP_PR_STAPSYS)
- /* Make sure unprivileged users only probe their own threads. */
- @@ -1739,14 +1762,20 @@ stap_start_task_finder(void)
- _stp_warn("Process %d does not belong to unprivileged user %d",
- tsk->pid, _stp_uid);
- }
- + dbug_task("uid != euid: %d != %d", _stp_uid, tsk_euid);
- continue;
- }
- #endif
- + dbug_task("setting up events for %d", tsk->tgid);
- +
- // Set up events we need for attached tasks.
- rc = __stp_utrace_attach(tsk, &tgt->ops, tgt,
- __STP_ATTACHED_TASK_EVENTS,
- UTRACE_STOP);
- +
- + dbug_task("utrace attach returned %d", rc);
- +
- if (rc != 0 && rc != EPERM)
- goto stf_err;
- rc = 0; /* ignore EPERM */
- @@ -1771,18 +1800,13 @@ stap_task_finder_post_init(void)
- return;
- }
- -#ifdef DEBUG_TASK_FINDER
- - printk(KERN_ERR "%s:%d - entry.\n", __FUNCTION__, __LINE__);
- -#endif
- + dbug_task("entry.");
- rcu_read_lock();
- do_each_thread(grp, tsk) {
- struct list_head *tgt_node;
- if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING) {
- -#ifdef DEBUG_TASK_FINDER
- - printk(KERN_ERR "%s:%d - exiting early...\n",
- - __FUNCTION__, __LINE__);
- -#endif
- + dbug_task("exiting early...");
- break;
- }
- @@ -1794,6 +1818,8 @@ stap_task_finder_post_init(void)
- if (tsk->tgid != tsk->pid)
- continue;
- + dbug_task("checking task %d:%d", tsk->pid, tsk->tgid);
- +
- /* See if we need to "poke" this thread. */
- list_for_each(tgt_node, &__stp_task_finder_list) {
- struct stap_task_finder_target *tgt;
- @@ -1804,14 +1830,19 @@ stap_task_finder_post_init(void)
- if (tgt == NULL || !tgt->engine_attached)
- continue;
- + dbug_task("attaching to task %d", tsk->tgid);
- +
- // If we found an "interesting" task earlier,
- // stop it.
- engine = utrace_attach_task(tsk,
- UTRACE_ATTACH_MATCH_OPS,
- &tgt->ops, tgt);
- if (engine != NULL && !IS_ERR(engine)) {
- + int rc;
- + dbug_task("found the target task %d, stopping it...", tsk->tgid);
- +
- /* We found a target task. Stop it. */
- - int rc = utrace_control(tsk, engine,
- + rc = utrace_control(tsk, engine,
- UTRACE_INTERRUPT);
- /* If utrace_control() returns
- * EINPROGRESS when we're
- @@ -1824,6 +1855,9 @@ stap_task_finder_post_init(void)
- _stp_error("utrace_control returned error %d on pid %d",
- rc, (int)tsk->pid);
- }
- +
- + dbug_task("interrupting task returned %d (%d)", rc, -EINPROGRESS);
- +
- utrace_engine_put(engine);
- /* Since we only need to interrupt
- @@ -1835,9 +1869,7 @@ stap_task_finder_post_init(void)
- } while_each_thread(grp, tsk);
- rcu_read_unlock();
- atomic_set(&__stp_task_finder_complete, 1);
- -#ifdef DEBUG_TASK_FINDER
- - printk(KERN_ERR "%s:%d - exit.\n", __FUNCTION__, __LINE__);
- -#endif
- + dbug_task("exit.");
- return;
- }
- @@ -1858,7 +1890,7 @@ stap_stop_task_finder(void)
- #ifdef DEBUG_TASK_FINDER
- int i = 0;
- - printk(KERN_ERR "%s:%d - entry\n", __FUNCTION__, __LINE__);
- + dbug_task("entry");
- #endif
- if (atomic_read(&__stp_task_finder_state) == __STP_TF_UNITIALIZED)
- return;
- @@ -1886,7 +1918,7 @@ stap_stop_task_finder(void)
- }
- #ifdef DEBUG_TASK_FINDER
- if (i > 0)
- - printk(KERN_ERR "it took %d polling loops to quit.\n", i);
- + dbug_task("it took %d polling loops to quit.", i);
- #endif
- debug_task_finder_report();
- @@ -1903,9 +1935,7 @@ stap_stop_task_finder(void)
- * everything. */
- __stp_tf_free_all_task_work();
- -#ifdef DEBUG_TASK_FINDER
- - printk(KERN_ERR "%s:%d - exit\n", __FUNCTION__, __LINE__);
- -#endif
- + dbug_task("exit");
- }
- #endif /* TASK_FINDER2_C */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement