Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Aug 2015 08:27:28 -0500
From:      Eric Badger <eric@badgerio.us>
To:        Marcel Moolenaar <marcel@xcllnt.net>
Cc:        FreeBSD Current <freebsd-current@freebsd.org>
Subject:   Re: Appending to message buffer while in ddb
Message-ID:  <55C0BDC0.7010109@badgerio.us>
In-Reply-To: <16785483-7FD3-4475-9958-168528AFB2D9@xcllnt.net>
References:  <55BFC80B.2000005@dell.com> <16785483-7FD3-4475-9958-168528AFB2D9@xcllnt.net>

next in thread | previous in thread | raw e-mail | index | archive | help

On 08/03/2015 03:21 PM, Marcel Moolenaar wrote:
>> On Aug 3, 2015, at 12:59 PM, Eric Badger <eric_badger@dell.com> wrote:
>>
>> Hi there,
>>
>> Since r226435, output from kernel printf/log functions is not appended=
 to the message buffer when in ddb. The commit message doesn't call this =
out specifically; instead it appears to have been to address double print=
ing to the console while in ddb. I noticed this because a ddb script whic=
h previously resulted in some things ending up in a textdump's msgbuf.txt=
 no longer does so. It may be that the answer is "use db_printf in ddb", =
which is ok, but I thought I'd check anyway to see if the aforementioned =
change was indeed intentional, since I wasn't able to dig up any discussi=
on about it.
> It=E2=80=99s a direct consequence.
>

But is it a necessary consequence? For example, would the below patch=20
also be acceptable (it's perhaps not the cleanest way to do it, but=20
gives the idea)? This way we'll print to the console (once) and, if=20
TOLOG is also specified, append to the message buffer. If this is not=20
acceptable, then I think all ddb commands not using db_printf (such as=20
'show rtc') should be converted to doing so (this might be a good idea=20
either way), since their output cannot currently be captured in textdumps=
.

Thanks,
Eric

diff --git sys/kern/subr_prf.c sys/kern/subr_prf.c
index 4f35838..4739331 100644
--- sys/kern/subr_prf.c
+++ sys/kern/subr_prf.c
@@ -463,19 +463,28 @@ putchar(int c, void *arg)
     struct putchar_arg *ap =3D (struct putchar_arg*) arg;
     struct tty *tp =3D ap->tty;
     int flags =3D ap->flags;
+   int putbuf_done =3D 0;

     /* Don't use the tty code after a panic or while in ddb. */
     if (kdb_active) {
         if (c !=3D '\0')
             cnputc(c);
-       return;
-   }
-
-   if ((flags & TOTTY) && tp !=3D NULL && panicstr =3D=3D NULL)
-       tty_putchar(tp, c);
+       /* Prevent double printing. */
+       ap->flags &=3D ~(TOCONS);
+       flags =3D ap->flags;
+   } else {
+       if ((panicstr =3D=3D NULL) && (flags & TOTTY) && (tp !=3D NULL))
+           tty_putchar(tp, c);

-   if ((flags & (TOCONS | TOLOG)) && c !=3D '\0')
-       putbuf(c, ap);
+       if (flags & TOCONS) {
+           putbuf(c, ap);
+           putbuf_done =3D 1;
+       }
+   }
+   if ((flags & TOLOG) && (putbuf_done =3D=3D 0)) {
+       if (c !=3D '\0')
+           putbuf(c, ap);
+   }
  }

  /*




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?55C0BDC0.7010109>