Suppose defined: int a[100]
Type print a
then gdb will automatically display it as an array:1, 2, 3, 4...
. However, if a
is passed to a function as a parameter, then gdb will treat it as a normal int pointer, type print a
will display:(int *)0x7fffffffdaa0
. What should I do if I want to view a
as an array?
The usual way to examine data in your program is with the print command (abbreviated p ), or its synonym inspect . It evaluates and prints the value of an expression of the language your program is written in (see section Using GDB with Different Languages).
You can see these breakpoints with the GDB maintenance command `maint info breakpoints' . Using the same format as `info breakpoints' , display both the breakpoints you've set explicitly, and those GDB is using for internal purposes. Internal breakpoints are shown with negative breakpoint numbers.
The ptype [ARG] command will print the type. Show activity on this post. This question may be related: vtable in polymorphic class of C++ using gdb: (gdb) help set print object Set printing of object's derived type based on vtable info.
See here. In short you should do:
p *array@len
*(T (*)[N])p
where T is the type, N is the number of elements and p is the pointer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With