Project

General

Profile

Actions

Bug #6461

closed

mdb incorrectly prints byte-sized things at a bit-offset

Added by Hans Rosenfeld over 6 years ago. Updated 7 months ago.

Status:
Closed
Priority:
Normal
Category:
mdb - modular debugger
Start date:
2015-11-18
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage
Gerrit CR:

Description

While debugging a nvme-related core dump I saw this in mdb:

> ffffff07481cad00::print -ta nvme_cmd_t nc_cqe.cqe_sf
ffffff07481cad4e nvme_cqe_sf_t nc_cqe.cqe_sf = {
    ffffff07481cad4e unsigned short nc_cqe.cqe_sf.sf_p :1 = 0x1
    ffffff07481cad4e.1 unsigned short nc_cqe.cqe_sf.sf_sc :8 = 0x5
    ffffff07481cad4f.1 unsigned short nc_cqe.cqe_sf.sf_sct :3 = 0
    ffffff07481cad4f.4 unsigned short nc_cqe.cqe_sf.sf_rsvd2 :2 = 0
    ffffff07481cad4f.6 unsigned short nc_cqe.cqe_sf.sf_m :1 = 0x1
    ffffff07481cad4f.7 unsigned short nc_cqe.cqe_sf.sf_dnr :1 = 0
}
> ffffff07481cad4e/x
0xffffff07481cad4e:             4005    

The value of sf_sc should be 2, not 5. This is a 8-bit chunk of a bitfield starting at bit 1.

Actions #1

Updated by Robert Mustacchi 7 months ago

  • Subject changed from mdb printing of bitfields broken to mdb incorrectly prints byte-sized things at a bit-offset
  • Category set to mdb - modular debugger
  • Assignee set to Robert Mustacchi

The problem here is that when mdb tries to print this it does not look at the offset of a member when determining whether or not it is a bitfield. So what happens here is that mdb sees that it has a byte sized object and doesn't fall into its bitfield printing routine and then incorrectly prints the int at offset 0, resulting in the value of 0x5 rather than 0x2.

The fix is simple. When we are printing and considering an integer to print as a bitfield, we need to check if it's bit-wise offset mod NBBY is zero. If it is not, we should print it as a bitfield.

Actions #2

Updated by Electric Monk 7 months ago

  • Gerrit CR set to 1913
Actions #3

Updated by Robert Mustacchi 7 months ago

This was tested with updated additions to the mdb bitfields tests that are discussed in #14317.

Actions #4

Updated by Electric Monk 7 months ago

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

git commit 7a58f53801acca2cd594b9ecb75bf926e4fb3eda

commit  7a58f53801acca2cd594b9ecb75bf926e4fb3eda
Author: Robert Mustacchi <rm@fingolfin.org>
Date:   2022-01-15T00:41:16.000Z

    14317 mdb misprints certain bitfields
    6461 mdb incorrectly prints byte-sized things at a bit-offset
    14316 want means to leverage ctfconvert in one go in the build
    Reviewed by: Yuri Pankov <ypankov@tintri.com>
    Reviewed by: Andy Fiddaman <andy@omnios.org>
    Reviewed by: Toomas Soome <tsoome@me.com>
    Approved by: Rich Lowe <richlowe@richlowe.net>

Actions

Also available in: Atom PDF