Skip to content

Commit 4251e26

Browse files
authored
Revise Debugging documentation structure and content
Reorganized and expanded the debugging documentation, adding sections for GDB instructions and QEMU monitor usage.
1 parent 81a67fa commit 4251e26

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

doc/Debugging.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
# Debugging with GDB and QEMU
1+
# Debugging
22

3-
This document deals with debugging in [GDB](https://www.gnu.org/software/gdb/).
43

54
## Prerequisites
65

76
This document expects the reader to understand some basic fundamentals about x86-64 assembly instructions and hexadecimal notation.
87

98
This document was written while using an Ubuntu 25.04 virtual machine within VirtualBox.
109

11-
This document is based on using BareMetal-OS and its script.
1210

1311
## Debugging with GDB
1412

13+
This section deals with debugging in [GDB](https://www.gnu.org/software/gdb/).
14+
15+
1516
### Terminal 1
1617

1718
Set a 'jmp $' somewhere in the source code.
@@ -20,6 +21,7 @@ Start a minimal QEMU BareMetal instance
2021

2122
qemu-system-x86-64 -s -drive format=raw,file=baremetal_os.img
2223

24+
2325
### Terminal 2
2426

2527
Start the GNU debugger
@@ -44,18 +46,25 @@ Execution will be stopped where you put the 'jmp $' in the code. Take a look at
4446
QEMU will now be running the code directly after the `jmp $` you had inserted. After the first `stepi` command is executed you can hit enter to repeat the action and want the CPU step through the assembly code.
4547

4648

47-
## Debugging with QEMU (at a known address)
49+
### GDB instructions
50+
51+
Dump some memory
52+
53+
x 0xXXXXX
54+
55+
56+
## Debugging with QEMU
4857

4958
When the kernel is compiled a file called `kernel-debug.txt` is generated. This file can be used as a reference for opcode addresses within the kernel. Add `0x100000` to any address in the text file for the actual in-memory address.
5059

5160
Start QEMU with the `-S` switch to start the virtual machine in a paused mode if you need to add a breakpoint somewhere in the kernel startup code. You can un-pause the execution by typing `c` into GDB after you create the breakpoint.
5261

5362

54-
## The QEMU monitor
63+
### The QEMU monitor
5564

56-
QEMU has a built in monitor to allow you to query the state of the VM.
65+
QEMU has a built in monitor to allow you to query the state of the VM. Running BareMetal via `./baremetal.sh run` in `BareMetal-OS` enables the monitor telnet port.
5766

58-
`Escape+2` will switch to the QEMU monitor console and `Escape+1` will switch back to the VM. Enter `quit` on the QEMU monitor console to stop the VM.
67+
telnet localhost 8086
5968

6069

6170
### Debugging via QEMU monitor
@@ -86,13 +95,6 @@ The "format" can be x (hex), d (signed decimal), u (unsigned decimal), o (octal)
8695
The "size" parameter can be b (8 bits), h (16 bits), w (32 bits) or g (64 bits).
8796

8897

89-
## GDB instructions
90-
91-
Dump some memory
92-
93-
x 0xXXXXX
94-
95-
9698
## Capturing QEMU network traffic
9799

98100
Add the following to the network definition

0 commit comments

Comments
 (0)