Debug with QEmu and GDB
In addition to the basic set of utilities suggested by the Developers’ Starting Guide, you will also need:
Getting Started
First you have to get compile the project:
- Open a command prompt and go to your local SharpOS trunk directory
- Use “
nant dist” to compile & AOT-compile the project (note that among other files, this placesSharpOS.Kernel.binin./buildandSharpOS.imgin./build/distro/common)
Then you need to start QEmu up. (Note that we do not include a script for doing so in the repository, because QEmu has a required command line parameter that has to point to your QEmu install/extraction location.)
Assuming QEmu was extracted/installed at “C:\Program Files\QEmu\”, (but that QEmu is in your %PATH% environment variable):
qemu -L C:\Progra~1\QEmu\ -fda .\build\distro\common\SharpOS.img -s -S
Note that you you have to use care under Windows with your folder paths, and that I am assuming that you are executing this from the /trunk of your local working copy.
QEmu will start, in ‘STOPPED’ mode, waiting for the debugger to attach.
Attaching the Debugger
Now you need to get GDB up off the ground.
- Open a new command prompt and go to your local SharpOS trunk directory
- (Assuming GDB is in your
%PATH%environment variable), enter “gdb” to start gdb - Enter “
file ./build/SharpOS.Kernel.bin” to tell gdb where to load information about the kernel - Enter “
set disassembly-flavor intel” for good measure - Enter “
target remote localhost:1234” to connect gdb to what we are debugging - A number of commands are at your disposal:
* “
info functions” lists all the functions in the kernel * “b <function>” can be used to set a breakpoint at aby name or address * “ help” can get you started with the plethora of other options available… - Enter “
c” (for “continue“) to have gdb instruct QEmu to start/continue execution of SharpOS - To manually pause execution, make sure your gdb window has focus and simply enter
<CTRL>+<C>
Conclusion
There is alot that GDB will let you do, so you’ll have to do some hunting around. However, there are currently a couple limitations because of how SharpOS is compiled – so don’t be disappointed if you can’t set breakpoints in Visual Studio, or see your variable names when you are debugging.
It is also feasible that you could get GDB working with other emulators. If so, let us know, and we’ll get instructions up here for any such cases.