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.8sudo apt-get install libx11-devsudo apt-get install libxrandr-devsudo ./configure --enable-gdb-stub --with-x11sudo makesudo make install- Add
-gand-O0options to the end ofCPP_OPTIONsinmakefile - Remove the first line of
linker.ld - add gdb configuration to the bochs configuration file
bochsrc.bxrcgdbstub: enabled=1, port=1234, text_base=0, data_base=0, bss_base=0
- write a
.gdbinitfile in the MP source directoryfile kernel.bintarget remote:1234
Use GDB
- In the project folder, type
bochs -f bochsrc.bxrc- It may ask for options,
6is what we need
- It may ask for options,
- Open a new terminal
cdto the project folder, entergdb - If you just want to continue without any breakpoint, just type
c - To exit,
killthenquit
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=1inbochsrc.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);
}
