For gdb debugger
(gdb) p &buffer
This command is used to print the content of starting of buffer (stack), or print the address?
If it is content, how to print the address?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
It depends on what type the
buffer is a pointer to the start of the buffer. The C-style declaration for it might be
struct stackElement *buffer; or something similar (note the asterisk!).
In that case:
p &bufferprints the address where the pointer itself is stored (i.e. "the address of the address of the buffer")
p buffershould print the value of the
bufferpointer variable, which is the address of the buffer.
p *buffershould print the contents of the buffer.
bufferis some structure type, and not a pointer (example C declaration might be
struct stackElement buffer; with no asterisk), then:
p &bufferprints the address where the structure is, i.e. the address of the buffer
p bufferprints the contents of this structure (= if this is a stack, probably the first stack element)
p *bufferis an error.