Project

General

Profile

Bug #12364

mdb trips assertion related to autowrap

Added by John Levon 8 months ago. Updated 8 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
-
Start date:
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

Description

People are regularly hitting an assertion inside mdb_iob_nputs().

History

#1

Updated by John Levon 8 months ago

This issue stems from:

commit c8a3ee0e3658c32402e6bd505596d4fa45bfe17c
Author: Bryan Cantrill <bryan@joyent.com>
Date:   Thu Jun 6 15:00:37 2019 +0000

    11208 add mdb format character for jazzed-up binary output
    11206 mdb output autowrapping still subtly wrong

In mdb_fmt_print(), we set autowrap in the mdb.m_flags. This is done so that
we get things like:

$ mdb -e '-1,6=J'
                ffffffffffffffff ffffffffffffffff ffffffffffffffff
                ffffffffffffffff ffffffffffffffff ffffffffffffffff

in preference to

> -1,6=J
                ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffff
ffff ffffffffffffffff ffffffffffffffff 

However, when switching on autowrap, it's possible that "iob->iob_nbytes"
(the number of bytes currently in the iob buffer) is already larger than
"iob->iob_cols". Thus, when we next reach mdb_iob_nputs(), we'll hit the ASSERT.

For a specific example:

    6cb234 char [32] vsc_linkname = [ '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', ...
                                                                                ^
                                                           iob_cols  -----------|

::print has this code:

 974         if (IS_CHAR(*ep)) {                                                      
 975                 mdb_printf("'");                                                 
 976                 if (mdb_fmt_print(pap->pa_tgt, pap->pa_as,                       
 977                     addr, 1, 'C') == addr)                                       
 978                         return (1);                                              
 979                 mdb_printf("'");                                                 
 980                 return (0);                                                      
 981         }                                                                        

So, if that first single quote happens to fall at the cols line, as shown above,
then when we call into mdb_fmt_print(), we'll set autowrap, then hit the assertion when we try to print "\\0".

To fix this, we'll make a couple of changes:

- when mdb_fmt_print() sets autowrap, it will check for this condition, and force a newline if found
- in the unlikely case that we're some other iob that hasn't yet been handled, we'll handle it last minute in mdb_iob_fill() / mdb_iob_nputs()
- for ::print of a char specifically, we'll disable auto-wrapping
#2

Updated by John Levon 8 months ago

Note: one peculiarity of autowrapping is that when we don't read from the terminal, we never pick up the real number of columns:

jlevon:mdb $ tput cols 
211
jlevon:mdb $ mdb -e '-1,6=J'
                ffffffffffffffff ffffffffffffffff ffffffffffffffff 
                ffffffffffffffff ffffffffffffffff ffffffffffffffff 

This is a separate bug.

#3

Updated by John Levon 8 months ago

I tested this with a dump that previously asserted and verified that it looked OK and wrapped correctly with ::set- o autowrap. I also tested the wrapping cases from the previous bugs filed in this area, and output large ::print cpu_t (large) on both mdb -k and kmdb.

#4

Updated by Electric Monk 8 months ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100

git commit f11c6b604a17df4ddc8c4987e50f5b8d8a945516

commit  f11c6b604a17df4ddc8c4987e50f5b8d8a945516
Author: John Levon <john.levon@joyent.com>
Date:   2020-03-07T17:03:10.000Z

    12364 mdb trips assertion related to autowrap
    Reviewed by: Dan McDonald <danmcd@joyent.com>
    Approved by: Robert Mustacchi <rm@fingolfin.org>

Also available in: Atom PDF