我分享如何看debug information。
下面有幾個檔案
a.c
Code:
#include "common.h"
void
foo ()
{
LALA lala;
}
int
main ()
{
return 0;
}
b.c
Code:
#define HELLO
#include "common.h"
void
bar ()
{
LALA lala;
}
common.h
Code:
typedef struct
{
int f1;
#ifdef HELLO
int f2;
#endif
int f3;
} LALA;
Makefile
Code:
all:
nds32le-elf-gcc a.c b.c -g -O0 -o case1.out
nds32le-elf-gcc b.c a.c -g -O0 -o case2.out
因為這裡的structure用條件式編譯的緣故,
相同的structure LALA,內容不相同。
我們可以從debug information中看到的element。
command為
Code:
$ nds32le-elf-readelf.exe -w case1.out >> out.txt
打開out.txt檔。
看到資訊如下圖,可知a.c中,LALA define的structure有2個int變數f1及f3,size為8 bytes
Attachment:
p1.gif [ 39.02 KiB | Viewed 7309 times ]
我們看b.c的debug information,可以看到LALA define的structure有3個變數,f1 f2 f3。
size為12 bytes
Attachment:
p2.gif [ 34.05 KiB | Viewed 7309 times ]
gdb用當時所指向的pc值去抓debug information,
所以不會抓錯變數。
最後,附上我測試用的檔案。
Attachment:
debug_info.zip [6.04 KiB]
Downloaded 865 times