From owner-svn-src-all@freebsd.org Fri Aug 26 02:46:48 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 94F08BC6AA8; Fri, 26 Aug 2016 02:46:48 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6C44D18C9; Fri, 26 Aug 2016 02:46:48 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u7Q2klCe083022; Fri, 26 Aug 2016 02:46:47 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u7Q2klPe083021; Fri, 26 Aug 2016 02:46:47 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201608260246.u7Q2klPe083021@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: "Conrad E. Meyer" Date: Fri, 26 Aug 2016 02:46:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r304828 - head/sys/ddb X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Aug 2016 02:46:48 -0000 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