Here is a guide on how to enable GDB debugger in Bochs environment. Also, for a specific project (TAMU CSCE 410/611 OS System, Machine Problem) with a provided system image, I included how to output kernel message in linux terminal. Special thanks to Min Qin who provided me with his GDB guideline, and Dr. Bettati’s notes.
Enable GDB debugger in Bochs environment
- Download bochs source files with gdb from https://sourceforge.net/projects/bochs/files/bochs/2.6.8/
- In the folder containing the downloaded file:
tar xvzf bochs-2.6.8.tar.gz
cd bochs-2.6.8
sudo apt-get install libx11-dev
sudo apt-get install libxrandr-dev
sudo ./configure --enable-gdb-stub --with-x11
sudo make
sudo make install
- Add
-g
and-O0
options to the end ofCPP_OPTIONs
inmakefile
- Remove the first line of
linker.ld
- add gdb configuration to the bochs configuration file
bochsrc.bxrc
gdbstub: enabled=1, port=1234, text_base=0, data_base=0, bss_base=0
- write a
.gdbinit
file in the MP source directoryfile kernel.bin
target remote:1234
Use GDB
- In the project folder, type
bochs -f bochsrc.bxrc
- It may ask for options,
6
is what we need
- It may ask for options,
- Open a new terminal
cd
to the project folder, entergdb
- If you just want to continue without any breakpoint, just type
c
- To exit,
kill
thenquit
Here is two very brief tutorial on how to use GDB: UMich GDB tutorial and CMU GDB tutorial
Terminal output
Steps to do linux terminal output are as below. It is better to add our Console::myPuts()
method in Console::puts()
, so every console output will be printed in linux terminal as well.
- Add
port_e9_hack: enabled=1
inbochsrc.bxrc
- Add following methods in
console.H/C
. Use them for terminal output
void Console::myPuts(const char * _s)
{
for (int i = 0; i < strlen(_s); i++) {
Machine::outportb(0xe9, _s[i]);
}
}
void Console::myPuti(const int _n)
{
char foostr[15];
int2str(_n, foostr);
myPuts(foostr);
}