Kernel Debugging: Difference between revisions

Jump to navigation Jump to search
m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
m (Fixed spelling mistake: bellow -> below)
m (Bot: Replace deprecated source tag with syntaxhighlight)
Line 25:
 
IMPORTANT NOTE #2: gcc thinks it is smarter than the programmer, so if you use "while(1);", then it will falsely assume that everything after that loop is not needed, and it will REMOVE all those code from the binary. You MUST use inline assembly so that gcc will keep your code as-is.
<sourcesyntaxhighlight lang="C">
asm volatile ("1: jmp 1b");
</syntaxhighlight>
</source>
 
== Use a virtual machine ==
Line 128:
 
Alternatively you can force a breakpoint in your code without knowing the name of the function or the address. Place an endless loop pseudo-breakpoint somewhere in your code
<sourcesyntaxhighlight lang="C">
asm volatile ("1: jmp 1b");
</syntaxhighlight>
</source>
 
Then on the terminal that's running gdb, when your VM hangs press Ctrl^C to stop execution and drop you at the debugger prompt. There
Line 174:
 
The easiest way to trigger a breakpoint in bochs is to place "xchg bx, bx" into your code. For example
<sourcesyntaxhighlight lang="C">
asm volatile ("xchg %bx, %bx");
</syntaxhighlight>
</source>
 
Then when you run the virtual machine, it will stop execution and drop you at debugger prompt. To single step from there, use
Line 186:
Unfortunately VirtualBox developers have removed the "--start-dbg" command line option, so there's no way to set up breakpoints before your VM starts execution.
But you can do a similar trick as with GDB, which is to place an endless loop pseudo-breakpoint in your code somewhere:
<sourcesyntaxhighlight lang="C">
asm volatile ("1: jmp 1b");
</syntaxhighlight>
</source>
 
Then when the execution hangs, access "Command line..." under "Debug" menu (if you don't have a Debug menu in the Machine window, you'll have to enable the debugger see below). In the debugger command line, the first thing to do is that you MUST stop the VM from running:
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu