Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print characters from a void* in gdb

Tags:

gdb

I have a void* and I think there's a string nearby, somewhere within the next few bytes, but I'm not sure where. I don't know have any other knowledge of the what's nearby in memory, including whether there are 0s, so casting to char* isn't what I want. How can I print the next 20 bytes from this pointer as characters?

like image 851
pythonic metaphor Avatar asked Feb 16 '11 19:02

pythonic metaphor


1 Answers

Use the “x“ command to display the memory contents at a given address using the specified format.

Syntax:

    x [Address expression]
    x /[Format] [Address expression]
    x /[Length][Format] [Address expression]

Dumps 20 bytes as characters:

    x/20c voidptr

Dumps 20 bytes as hex:

    x/20x voidptr

See GDB command reference for x command

like image 57
Erik Avatar answered Sep 23 '22 21:09

Erik