Reputation: 1629
Here is my g++:
$ /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
generate 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
I use qemu-i386 to load my toy OS, then my bootloader will parse kernel.bin
, puts segments into memory. Then I start gdb in my host OS (OS X 10.11), execute:
file ./generated/kernel.bin
target remote localhost:1234
b initMemory
c
I can successfully stop at function initMemory
which is in memoryManage.o
.
8: x/i 0x100000 + $eip
0x100010 <initMemory()>: push %ebp
However when I execute n
or s
or p
it doesn't work. I can only use si
ni
(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.
How can I fix this problem? Is it caused by mismatch of i586 g++ and i386 gdb, or mismatch of gcc 4.8.1 and gdb 7.7.1?
Upvotes: 1
Views: 490
Reputation: 1629
Finally I find out the problem. gdb use %eip
to find instructions, however in my kernel it should use %cs:%eip
. After setting %cs
to 0
, gdb works as expected.
Upvotes: 1