Bochs GDB stub

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Crazed123

Bochs GDB stub

Post by Crazed123 »

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.
Kim

Re:Bochs GDB stub

Post by Kim »

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.

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
This is what gdb gives me when testing some basic kernel:

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>
Crazed123

Re:Bochs GDB stub

Post by Crazed123 »

What's the support directory you're adding? And that command thing?

Yes, I compiled with -g.
Kim

Re:Bochs GDB stub

Post by Kim »

That command thing is used to execute gdb commands at start.
Support dir is an other source code dir.

debug.gdb:

Code: Select all

target remote localhost:8383
Crazed123

Re:Bochs GDB stub

Post by Crazed123 »

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.
Kim

Re:Bochs GDB stub

Post by Kim »

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.
Crazed123

Re:Bochs GDB stub

Post by Crazed123 »

It hangs for you? For me it just acts as though I'd pressed "continue".
Kim

Re:Bochs GDB stub

Post by Kim »

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.
Crazed123

Re:Bochs GDB stub

Post by Crazed123 »

GDB 6.0
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.
That's from the GDB manual, "Debugging with GDB". WTF?
Kim

Re:Bochs GDB stub

Post by Kim »

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...
Crazed123

Re:Bochs GDB stub

Post by Crazed123 »

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.
Kim

Re:Bochs GDB stub

Post by Kim »

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.
Crazed123

Re:Bochs GDB stub

Post by Crazed123 »

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
Kim

Re:Bochs GDB stub

Post by Kim »

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.
Crazed123

Re:Bochs GDB stub

Post by Crazed123 »

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.
Post Reply