Page 1 of 1

How to use gdbstub and bochs to debug kernel file

Posted: Sat Feb 23, 2013 8:49 pm
by MarkZar
Hello everyone, I'm new to os development, and now I am very confused with something about debugging. My os is started with boot.bin, which loads the loader.bin, and loader.bin starts the kernel.bin. In kernel.bin I used a function init_prot that is defined in protect.c. Also there is one line in init_prot:

Code: Select all

init_descriptor(&gdt[INDEX_LDT_FIRST],
			vir2phys(seg2phys(SELECTOR_KERNEL_DS), proc_table[0].ldts),
			LDT_SIZE * sizeof(DESCRIPTOR) - 1,
			DA_LDT);
Just as you can see, I only want to set a breakpoint in function seg2phys, which is defined here(also in protect.c):

Code: Select all

PUBLIC t_32 seg2phys(t_16 seg)
{
	DESCRIPTOR* p_dest = &gdt[seg >> 3];

	return (p_dest->base_high << 24) | (p_dest->base_mid << 16) | (p_dest->base_low);
}
I have some questions:
1. Should I use gdb protect.o(executable file compiled with protect.c) or gdb boot.bin(boot file which is loaded in 0x7c00h) to start the gdb at first?
2. I have run the command gdb protect.o to start the gdb and connected to bochs successfully using target remote localhost:1234. Then I set a breakpoint(b seg2phys) successfully, but when I continue the os with command continue, gdb didn't stop at that breakpoint and bochs continued to run without any stop. I'm quite sure that the function will be executed in os running. But why didn't it stop? Is there any place that I go wrong?
3. Is there any website that illustrates how to use bochs with gdbstub in detail? I have searched the Internet for a long time, but only found some simple tutorials.

Thanks

MarkZar

Re: How to use gdbstub and bochs to debug kernel file

Posted: Sat Feb 23, 2013 10:07 pm
by Owen
1. "gdb kernel.bin"
2. Probably because the addresses in protect.o (as an unlinked object) are completely different from those in the linked kernel
3. No idea. Most people use the Bochs builtin debugger.

Re: How to use gdbstub and bochs to debug kernel file

Posted: Mon Feb 25, 2013 3:15 am
by MarkZar
Owen wrote:1. "gdb kernel.bin"
2. Probably because the addresses in protect.o (as an unlinked object) are completely different from those in the linked kernel
3. No idea. Most people use the Bochs builtin debugger.
Thanks a lot!