Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view a pointer like an array in GDB?

Tags:

c

gdb

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?

like image 375
CDT Avatar asked Jan 24 '13 13:01

CDT


People also ask

What does P do in gdb?

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).

How do I list breakpoints in gdb?

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.

Which command in gdb is used to find the type of variable?

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.


2 Answers

See here. In short you should do:

p *array@len 
like image 85
Ivaylo Strandjev Avatar answered Sep 20 '22 01:09

Ivaylo Strandjev


*(T (*)[N])p where T is the type, N is the number of elements and p is the pointer.

like image 43
R.. GitHub STOP HELPING ICE Avatar answered Sep 22 '22 01:09

R.. GitHub STOP HELPING ICE