Page MenuHomeFreeBSD

D25487.id74119.diff
No OneTemporary

D25487.id74119.diff

Index: head/sys/kern/subr_stack.c
===================================================================
--- head/sys/kern/subr_stack.c
+++ head/sys/kern/subr_stack.c
@@ -170,7 +170,8 @@
* flags - M_WAITOK or M_NOWAIT (EWOULDBLOCK).
*/
int
-stack_sbuf_print_flags(struct sbuf *sb, const struct stack *st, int flags)
+stack_sbuf_print_flags(struct sbuf *sb, const struct stack *st, int flags,
+ enum stack_sbuf_fmt format)
{
char namebuf[64];
long offset;
@@ -182,9 +183,19 @@
&offset, flags);
if (error == EWOULDBLOCK)
return (error);
- sbuf_printf(sb, "#%d %p at %s+%#lx\n", i, (void *)st->pcs[i],
- namebuf, offset);
+ switch (format) {
+ case STACK_SBUF_FMT_LONG:
+ sbuf_printf(sb, "#%d %p at %s+%#lx\n", i,
+ (void *)st->pcs[i], namebuf, offset);
+ break;
+ case STACK_SBUF_FMT_COMPACT:
+ sbuf_printf(sb, "%s+%#lx ", namebuf, offset);
+ break;
+ default:
+ __assert_unreachable();
+ }
}
+ sbuf_nl_terminate(sb);
return (0);
}
@@ -192,7 +203,7 @@
stack_sbuf_print(struct sbuf *sb, const struct stack *st)
{
- (void)stack_sbuf_print_flags(sb, st, M_WAITOK);
+ (void)stack_sbuf_print_flags(sb, st, M_WAITOK, STACK_SBUF_FMT_LONG);
}
#if defined(DDB) || defined(WITNESS)
Index: head/sys/kern/tty_info.c
===================================================================
--- head/sys/kern/tty_info.c
+++ head/sys/kern/tty_info.c
@@ -239,10 +239,36 @@
}
#ifdef STACK
-static bool tty_info_kstacks = true;
-SYSCTL_BOOL(_kern, OID_AUTO, tty_info_kstacks, CTLFLAG_RWTUN,
- &tty_info_kstacks, 0,
- "Enable printing kernel stack(9) traces on ^T (tty info)");
+static int tty_info_kstacks = STACK_SBUF_FMT_LONG;
+
+static int
+sysctl_tty_info_kstacks(SYSCTL_HANDLER_ARGS)
+{
+ enum stack_sbuf_fmt val;
+ int error;
+
+ val = tty_info_kstacks;
+ error = sysctl_handle_int(oidp, &val, 0, req);
+ if (error != 0 || req->newptr == NULL)
+ return (error);
+
+ switch (val) {
+ case STACK_SBUF_FMT_NONE:
+ case STACK_SBUF_FMT_LONG:
+ case STACK_SBUF_FMT_COMPACT:
+ tty_info_kstacks = val;
+ break;
+ default:
+ error = EINVAL;
+ }
+
+ return (error);
+}
+SYSCTL_PROC(_kern, OID_AUTO, tty_info_kstacks,
+ CTLFLAG_RWTUN | CTLFLAG_MPSAFE | CTLTYPE_INT, NULL, 0,
+ sysctl_tty_info_kstacks, "I",
+ "Adjust format of kernel stack(9) traces on ^T (tty info): "
+ "0 - disabled; 1 - long; 2 - compact");
#endif
/*
@@ -254,7 +280,8 @@
struct timeval rtime, utime, stime;
#ifdef STACK
struct stack stack;
- int sterr;
+ int sterr, kstacks_val;
+ bool print_kstacks;
#endif
struct proc *p, *ppick;
struct thread *td, *tdpick;
@@ -337,7 +364,10 @@
state = "unknown";
pctcpu = (sched_pctcpu(td) * 10000 + FSCALE / 2) >> FSHIFT;
#ifdef STACK
- if (tty_info_kstacks) {
+ kstacks_val = atomic_load_int(&tty_info_kstacks);
+ print_kstacks = (kstacks_val != STACK_SBUF_FMT_NONE);
+
+ if (print_kstacks) {
if (TD_IS_SWAPPED(td))
sterr = ENOENT;
else
@@ -366,8 +396,8 @@
pctcpu / 100, rss);
#ifdef STACK
- if (tty_info_kstacks && sterr == 0)
- stack_sbuf_print_flags(&sb, &stack, M_NOWAIT);
+ if (print_kstacks && sterr == 0)
+ stack_sbuf_print_flags(&sb, &stack, M_NOWAIT, kstacks_val);
#endif
out:
Index: head/sys/sys/stack.h
===================================================================
--- head/sys/sys/stack.h
+++ head/sys/sys/stack.h
@@ -39,6 +39,12 @@
struct sbuf;
+enum stack_sbuf_fmt {
+ STACK_SBUF_FMT_NONE = 0,
+ STACK_SBUF_FMT_LONG = 1,
+ STACK_SBUF_FMT_COMPACT = 2,
+};
+
/* MI Routines. */
struct stack *stack_create(int);
void stack_destroy(struct stack *);
@@ -52,7 +58,7 @@
void stack_sbuf_print(struct sbuf *, const struct stack *);
void stack_sbuf_print_ddb(struct sbuf *, const struct stack *);
int stack_sbuf_print_flags(struct sbuf *, const struct stack *,
- int);
+ int, enum stack_sbuf_fmt);
#ifdef KTR
void stack_ktr(u_int, const char *, int, const struct stack *,
u_int);

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 19, 1:13 PM (12 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25635452
Default Alt Text
D25487.id74119.diff (3 KB)

Event Timeline