packetie
packetie

Reputation: 5069

Formatting on gdb examine memory

When debugging a C/C++ code, I examine memory using the following command

(gdb)x/32xub data
0x7fef824b2c6a: 8   0   39  235 101 169 0   30
0x7fef824b2c72: 73  219 25  195 8   0   69  0
0x7fef824b2c7a: 0   60  17  223 64  0   54  6
0x7fef824b2c82: 245 43  85  190 0   3   147 32

I would like have 16 bytes in a row and each byte shows in 2 hex digits. Not sure what to do. Don't see any help from reference manual. Any ideas? Thanks.

UPDATE1

Just realized that when doing it again, it shows every bytes in hexdigits. However, it's 8 bytes per row, not 16.

(gdb) x/32x prevPkt
0x7fef824b2c6a: 0x08    0x00    0x27    0xeb    0x65    0xa9    0x00    0x1e
0x7fef824b2c72: 0x49    0xdb    0x19    0xc3    0x08    0x00    0x45    0x00
0x7fef824b2c7a: 0x00    0x3c    0x11    0xdf    0x40    0x00    0x36    0x06
0x7fef824b2c82: 0xf5    0x2b    0x55    0xbe    0x00    0x03    0x93    0x20

Upvotes: 1

Views: 962

Answers (1)

Mark Plotnick
Mark Plotnick

Reputation: 10271

You can do this with a macro. (This is adapted from my answer to a similar question).

define xb16
    dont-repeat
    set $addr = (char *)($arg0)
    set $endaddr = $addr + $arg1
    while $addr < $endaddr
        printf "%p: ", $addr
        set $lineendaddr = $addr + 16
        if $lineendaddr > $endaddr
            set $lineendaddr = $endaddr
        end
        set $a = $addr
        while $a < $lineendaddr
            printf "0x%02x ", *(unsigned char *)$a
            set $a++
        end
        printf "\n"
        set $addr = $addr + 16
    end
end

document xb16
usage: xb16 address count
outputs bytes in hex, 16 per row
end

Upvotes: 4

Related Questions