简体   繁体   English

从函数传递时如何查看gdb中的数组内容

[英]how to see array contents in gdb when passed from a function

I would like to see the contens of my array when passed as an argument to a function, through gdb. 我希望看到通过gdb作为参数传递给函数的数组的内容。

Say, I have some code which looks like 说,我有一些代码看起来像

#include <stdio.h>

int fun(int b[], int len)
{ 
 int i = 0;

 /* how do I see the contents of array b[] in gdb */
 for(i = 0; i < len; ++i)
     printf("%d ", b[i]);
}

int main()
{
    int a[] = {1,2,3,4,5};

    fun(a, sizeof(a) / sizeof(*a));
    return 0;
}

In gdb, a[] looks as follows 在gdb中,a []看起来如下

(gdb) disp a
1: a = {1, 2, 3, 4, 5}

But If I try to print b[], since it's a pointer (as array is passed as a pointer), the contents looks like this 但是,如果我尝试打印b [],因为它是一个指针(数组作为指针传递),所以内容看起来像这样

fun (b=0x7fffffffdf90, len=5) at main.c:14
(gdb) disp b
2: b = (int *) 0x7fffffffdf90

I want to be able to see the contents of b[] just like I'm seeing a[] so it helps me debug. 我希望能够看到b []的内容,就像看到a []一样,因此它有助于调试。

How can I do this? 我怎样才能做到这一点?

您可以使用人工数组显示如下:

*b@len

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM