Bochs GDB stub
Bochs GDB stub
I've compiled and set up Bochs correctly to run its GDB stub and have remotely attached GDB to Bochs running my kernel successfully. The issue comes when I try to debug the kernel. GDB only seems to understand certain source code lines as being such, when I break at the beginning of PASCALMAIN I can stepi as far as a I want, but if I enter "next" to go to the next source line or "step" GDB just runs the kernel as though I'd said "continue". Also, whenever I look up the value of a variable it reports a value of $ffffffff.
What's going on with this thing? It reports being able to read the symbols from my kernel correctly!
If anybody's had experience with making Bochs and GDB work together on kernels, it isn't in the FAQ, on Bonafide, on osdev.org, or in the QuickLinkz. There is also little to no Bochs documentation about it.
What's going on with this thing? It reports being able to read the symbols from my kernel correctly!
If anybody's had experience with making Bochs and GDB work together on kernels, it isn't in the FAQ, on Bonafide, on osdev.org, or in the QuickLinkz. There is also little to no Bochs documentation about it.
Re:Bochs GDB stub
Works fine for me. I compiled on freepascal using -g option to compile with debug information. And when kernel is running i could do print ktickcount and gdb printed the correct value (same as printed onscreen by kernel). Please note when debugging you must be sure that the value is valid at the time when you ask gdb to print it. When you invoke gdb you have to give some info.
The debugger has to be able to find the image with information, and your source code.
This is what gdb gives me when testing some basic kernel:
The debugger has to be able to find the image with information, and your source code.
Code: Select all
.\bin\gdb.exe .\output\kernel\kernel.elf -d .\src\kernel -d .\src\kernel\include -d .\src\kernel\support -command .\src\kernel\debug.gdb
Code: Select all
Program received signal 0, Signal 0.
KMAIN (MBINFO=$2bd40, MBMAGIC=732803074, SCREEN_OFFSET=640) at kernel.pas:84
84 jmp @idle
Current language: auto; currently pascal
(gdb) print ktickcount
$3 = 2745
(gdb) list
79
80 kwritestr('KERNEL::STATUS::kernel up and running.');
81
82 asm
83 @idle:
84 jmp @idle
85 end;
86
87 kernelhalt:
88 asm
(gdb) print kmain
$4 = {procedure (PMULTIBOOT_INFO_T, LONGWORD, LONGINT)} $c0000cb0 <KMAIN>
Re:Bochs GDB stub
What's the support directory you're adding? And that command thing?
Yes, I compiled with -g.
Yes, I compiled with -g.
Re:Bochs GDB stub
That command thing is used to execute gdb commands at start.
Support dir is an other source code dir.
debug.gdb:
Support dir is an other source code dir.
debug.gdb:
Code: Select all
target remote localhost:8383
Re:Bochs GDB stub
It still happens, once I hit line 16 of my main source file I can't get it to next to the next source line, even though my RTL is compiled with debug information, also.
Also, I still can't correctly read the values of parameters and local variables.
Also, I still can't correctly read the values of parameters and local variables.
Re:Bochs GDB stub
I just checked some stuff, when you break into the debugger with ctrl+c it looks like it works but when I use step or next it just hangs... looks like something is going rong.
Re:Bochs GDB stub
It hangs for you? For me it just acts as though I'd pressed "continue".
Re:Bochs GDB stub
Iam using gdb thats bundled with freepascal 2.0 release.
GNU gdb 6.2.1
What version are you using?
EDIT: i tested some older version with no luck, tried compiling newer one on cygwin but at the last step its saying it can't find the rule to build the gnu int lib, even if it doesn't have to build it, its prebuild in my lib dir.
GNU gdb 6.2.1
What version are you using?
EDIT: i tested some older version with no luck, tried compiling newer one on cygwin but at the last step its saying it can't find the rule to build the gnu int lib, even if it doesn't have to build it, its prebuild in my lib dir.
Re:Bochs GDB stub
GDB 6.0
That's from the GDB manual, "Debugging with GDB". WTF?12.4.4 Pascal
Debugging Pascal programs which use sets, subranges, file variables, or nested functions does not currently work. GDB does not support entering expressions, printing values, or similar features using Pascal syntax.
Re:Bochs GDB stub
http://www.freepascal.org/docs-html/user/userse55.html#x164-16200010.3
next works sometimes, but most of the time it looks like bochs or gdb hang. Very strange...
next works sometimes, but most of the time it looks like bochs or gdb hang. Very strange...
Re:Bochs GDB stub
Well, stepping seems to work after I've installed GDB 6.3... However, parameter and local variable values still show up as $F'd out.
And I've figured out why. Apparently the segmentation performed by Bochs doesn't affect where GDB looks for things.
And I've figured out why. Apparently the segmentation performed by Bochs doesn't affect where GDB looks for things.
Re:Bochs GDB stub
Thats why it worked for me, i used flat segments and paging.
But still step, next are not working. Could you upload that version of gdb that you said step works with.
EDIT:
It looks like bochs hangs when you make gdb cont.
But still step, next are not working. Could you upload that version of gdb that you said step works with.
EDIT:
It looks like bochs hangs when you make gdb cont.
Re:Bochs GDB stub
GDB 6.3? It's on the official website: http://www.gnu.org/software/gdb/gdb.html
And by "flat segments and paging" do you mean that you used flat segments and identity paging so that virtual=physical? Or does GDB work correctly for paging?
See here: http://bochs.sourceforge.net/cgi-bin/topper.pl?name=Bochs+Discussion+Boards&url=http://sourceforge.net/forum/qmrkgroup_ideq12580
And by "flat segments and paging" do you mean that you used flat segments and identity paging so that virtual=physical? Or does GDB work correctly for paging?
See here: http://bochs.sourceforge.net/cgi-bin/topper.pl?name=Bochs+Discussion+Boards&url=http://sourceforge.net/forum/qmrkgroup_ideq12580
Re:Bochs GDB stub
Damn it, I feel stupid now
Next/step didn't work because i tried it on a loop that never gets to the next source line.
@loop:
jmp @loop
This makes the debugger wait forever, because the source line never increases
Anyway everything is working, its great to debug your kernel following the execution flow inside your source code. And that insight gui frontend for dbg is realy easy to use.
Next/step didn't work because i tried it on a loop that never gets to the next source line.
@loop:
jmp @loop
This makes the debugger wait forever, because the source line never increases
Anyway everything is working, its great to debug your kernel following the execution flow inside your source code. And that insight gui frontend for dbg is realy easy to use.
Re:Bochs GDB stub
What about the paging/segmentation thing? Also, GDB misreads the addresses of local variables more than it does global. That is, global variables I just do a virtual->physical transformation to make gdb look at the correct address, but some local variables won't work even then.