C语言 如何在GDB中查看像数组一样的指针?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14502236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to view a pointer like an array in GDB?
提问by CDT
Suppose defined: int a[100]Type print athen gdb will automatically display it as an array:1, 2, 3, 4.... However, if ais passed to a function as a parameter, then gdb will treat it as a normal int pointer, type print awill display:(int *)0x7fffffffdaa0. What should I do if I want to view aas an array?
假设定义:int a[100]键入print a然后 gdb 将自动将其显示为数组:1, 2, 3, 4...。但是,如果a作为参数传递给函数,则 gdb 会将其视为普通的 int 指针,typeprint a将显示:(int *)0x7fffffffdaa0。如果我想以a数组形式查看该怎么办?
回答by R.. GitHub STOP HELPING ICE
*(T (*)[N])pwhere T is the type, N is the number of elements and p is the pointer.
*(T (*)[N])p其中 T 是类型,N 是元素数,p 是指针。
回答by aschepler
Use the xcommand.
使用x命令。
(gdb) x/100w a

