2016-07-15 55 views
1

這裏是我的G ++:爲什麼gdb不能顯示調試信息?

$ /usr/local/gcc-4.8.1-for-linux32/bin/i586-pc-linux-g++ -v 
Using built-in specs. 
COLLECT_GCC=/usr/local/gcc-4.8.1-for-linux32/bin/i586-pc-linux-g++ 
COLLECT_LTO_WRAPPER=/usr/local/gcc-4.8.1-for-linux32/libexec/gcc/i586-pc-linux/4.8.1/lto-wrapper 
Target: i586-pc-linux 
Configured with: ../gcc-4.8.1/configure --target=i586-pc-linux --build=i686-apple-darwin11 --prefix=/usr/local/gcc-4.8.1-for-linux32 --disable-multilib --enable-languages=c,c++ --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --disable-bootstrap 
Thread model: posix 
gcc version 4.8.1 (GCC) 

GDB:

$ i386-linux-gdb -v 
GNU gdb (GDB) 7.7.1 
This GDB was configured as "--host=x86_64-apple-darwin15.5.0 --target=i386-linux". 

CXX_FLAGS:

-ffreestanding -O0 -Wall -Wextra -fno-exceptions -fno-rtti -ggdb -nostdlib -std=c++11 -m32 

產生kernel.bin

/usr/local/gcc-4.8.1-for-linux32/bin/i586-pc-linux-g++ -I. -Iinclude -Ikernel -ffreestanding -O0 -Wall -Wextra -fno-exceptions -fno-rtti -ggdb -nostdlib -std=c++11 -m32 -e main -Ttext 0x100000 -o generated/kernel.bin generated/kernel/init/kernelMain.o generated/kernel/memoryManage/memoryManage.o 
/usr/local/gcc-4.8.1-for-linux32/bin/i586-pc-linux-objdump -S -D generated/kernel.bin > generated/kernel.dump 

我用QEMU-I 386加載我的玩具操作系統,然後我的引導程序將解析kernel.bin,將分段放入內存。然後我在主機操作系統(OS X 10.11)啓動gdb,執行:

file ./generated/kernel.bin 
target remote localhost:1234 
b initMemory 
c 

我可以成功地停在功能initMemory這是memoryManage.o

8: x/i 0x100000 + $eip 
    0x100010 <initMemory()>: push %ebp 

然而,當我執行nsp這是行不通的。我只能用sini

(gdb) n 
Cannot find bounds of current function 
(gdb) s 
Cannot find bounds of current function 
(gdb) p memoryInfoAddr 
No symbol "memoryInfoAddr" in current context. 

我怎樣才能解決這個問題呢?它是由i586 g ++和i386 gdb的不匹配,還是gcc 4.8.1和gdb 7.7.1的不匹配造成的?

+0

請檢查您的命令行以驗證您是否正在告訴*編譯器*生成調試信息。對於一些編譯器,選項是「-g」。 –

+0

@ThomasMatthews我有-ggdb,kernel.bin中的轉儲文件有許多調試部分,比如debug_info,debug_line ... –

回答

1

最後我找出問題所在。 gdb使用%eip來查找指令,但是在我的內核中它應該使用%cs:%eip。將%cs設置爲0後,gdb按預期工作。

+0

設置'%cs'以糾正gdt選擇器 –