![](/img/trans.png)
[英]How to properly copy contents of one char array into another when passed to function, WITHOUT using STL?
[英]how to see array contents in gdb when passed from a function
我希望看到通過gdb作為參數傳遞給函數的數組的內容。
說,我有一些代碼看起來像
#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;
}
在gdb中,a []看起來如下
(gdb) disp a
1: a = {1, 2, 3, 4, 5}
但是,如果我嘗試打印b [],因為它是一個指針(數組作為指針傳遞),所以內容看起來像這樣
fun (b=0x7fffffffdf90, len=5) at main.c:14
(gdb) disp b
2: b = (int *) 0x7fffffffdf90
我希望能夠看到b []的內容,就像看到a []一樣,因此它有助於調試。
我怎樣才能做到這一點?
您可以使用人工數組顯示如下:
*b@len
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.