Re: Appending to message buffer while in ddb

From: Eric Badger <eric_at_badgerio.us>
Date: Tue, 4 Aug 2015 08:27:28 -0500
On 08/03/2015 03:21 PM, Marcel Moolenaar wrote:
>> On Aug 3, 2015, at 12:59 PM, Eric Badger <eric_badger_at_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 printing to the console while in ddb. I noticed this because a ddb script which 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 discussion about it.
> It’s a direct consequence.
>

But is it a necessary consequence? For example, would the below patch 
also be acceptable (it's perhaps not the cleanest way to do it, but 
gives the idea)? This way we'll print to the console (once) and, if 
TOLOG is also specified, append to the message buffer. If this is not 
acceptable, then I think all ddb commands not using db_printf (such as 
'show rtc') should be converted to doing so (this might be a good idea 
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
_at__at_ -463,19 +463,28 _at__at_ putchar(int c, void *arg)
     struct putchar_arg *ap = (struct putchar_arg*) arg;
     struct tty *tp = ap->tty;
     int flags = ap->flags;
+   int putbuf_done = 0;

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

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

  /*
Received on Tue Aug 04 2015 - 11:31:39 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:59 UTC