Author: cem
Date: Fri Aug 26 02:46:47 2016
New Revision: 304828
URL: https://svnweb.freebsd.org/changeset/base/304828

Log:
  ddb: Add 'show active trace' command
  
  'show active trace', or 'acttrace' for short, prints backtraces from running
  threads only.
  
  Reviewed by:  mjg
  Differential Revision:        https://reviews.freebsd.org/D7646

Modified:
  head/sys/ddb/db_command.c

Modified: head/sys/ddb/db_command.c
==============================================================================
--- head/sys/ddb/db_command.c   Fri Aug 26 01:28:31 2016        (r304827)
+++ head/sys/ddb/db_command.c   Fri Aug 26 02:46:47 2016        (r304828)
@@ -72,6 +72,7 @@ static db_cmdfcn_t    db_halt;
 static db_cmdfcn_t     db_kill;
 static db_cmdfcn_t     db_reset;
 static db_cmdfcn_t     db_stack_trace;
+static db_cmdfcn_t     db_stack_trace_active;
 static db_cmdfcn_t     db_stack_trace_all;
 static db_cmdfcn_t     db_watchdog;
 
@@ -79,6 +80,12 @@ static db_cmdfcn_t   db_watchdog;
  * 'show' commands
  */
 
+static struct command db_show_active_cmds[] = {
+       { "trace",      db_stack_trace_active,  0,      NULL },
+};
+struct command_table db_show_active_table =
+    LIST_HEAD_INITIALIZER(db_show_active_table);
+
 static struct command db_show_all_cmds[] = {
        { "trace",      db_stack_trace_all,     0,      NULL },
 };
@@ -86,6 +93,7 @@ struct command_table db_show_all_table =
     LIST_HEAD_INITIALIZER(db_show_all_table);
 
 static struct command db_show_cmds[] = {
+       { "active",     0,                      0,      &db_show_active_table },
        { "all",        0,                      0,      &db_show_all_table },
        { "registers",  db_show_regs,           0,      NULL },
        { "breaks",     db_listbreak_cmd,       0,      NULL },
@@ -120,6 +128,8 @@ static struct command db_cmds[] = {
        { "match",      db_trace_until_matching_cmd,0,  NULL },
        { "trace",      db_stack_trace,         CS_OWN, NULL },
        { "t",          db_stack_trace,         CS_OWN, NULL },
+       /* XXX alias for active trace */
+       { "acttrace",   db_stack_trace_active,  0,      NULL },
        /* XXX alias for all trace */
        { "alltrace",   db_stack_trace_all,     0,      NULL },
        { "where",      db_stack_trace,         CS_OWN, NULL },
@@ -195,6 +205,9 @@ db_command_init(void)
                db_command_register(&db_cmd_table, &db_cmds[i]);
        for (i = 0; i < N(db_show_cmds); i++)
                db_command_register(&db_show_table, &db_show_cmds[i]);
+       for (i = 0; i < N(db_show_active_cmds); i++)
+               db_command_register(&db_show_active_table,
+                   &db_show_active_cmds[i]);
        for (i = 0; i < N(db_show_all_cmds); i++)
                db_command_register(&db_show_all_table, &db_show_all_cmds[i]);
 #undef N
@@ -799,8 +812,7 @@ db_stack_trace(db_expr_t tid, bool hasti
 }
 
 static void
-db_stack_trace_all(db_expr_t dummy, bool dummy2, db_expr_t dummy3,
-    char *dummy4)
+_db_stack_trace_all(bool active_only)
 {
        struct proc *p;
        struct thread *td;
@@ -811,8 +823,18 @@ db_stack_trace_all(db_expr_t dummy, bool
                prev_jb = kdb_jmpbuf(jb);
                if (setjmp(jb) == 0) {
                        FOREACH_THREAD_IN_PROC(p, td) {
-                               db_printf("\nTracing command %s pid %d tid %ld 
td %p\n",
-                                         p->p_comm, p->p_pid, 
(long)td->td_tid, td);
+                               if (td->td_state == TDS_RUNNING)
+                                       db_printf("\nTracing command %s pid %d"
+                                           " tid %ld td %p (CPU %d)\n",
+                                           p->p_comm, p->p_pid,
+                                           (long)td->td_tid, td,
+                                           td->td_oncpu);
+                               else if (active_only)
+                                       continue;
+                               else
+                                       db_printf("\nTracing command %s pid %d"
+                                           " tid %ld td %p\n", p->p_comm,
+                                           p->p_pid, (long)td->td_tid, td);
                                db_trace_thread(td, -1);
                                if (db_pager_quit) {
                                        kdb_jmpbuf(prev_jb);
@@ -824,6 +846,22 @@ db_stack_trace_all(db_expr_t dummy, bool
        }
 }
 
+static void
+db_stack_trace_active(db_expr_t dummy, bool dummy2, db_expr_t dummy3,
+    char *dummy4)
+{
+
+       _db_stack_trace_all(true);
+}
+
+static void
+db_stack_trace_all(db_expr_t dummy, bool dummy2, db_expr_t dummy3,
+    char *dummy4)
+{
+
+       _db_stack_trace_all(false);
+}
+
 /*
  * Take the parsed expression value from the command line that was parsed
  * as a hexadecimal value and convert it as if the expression was parsed
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to