How to use gdbstub and bochs to debug kernel file

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.
Post Reply
MarkZar
Posts: 13
Joined: Thu Feb 07, 2013 11:53 pm

How to use gdbstub and bochs to debug kernel file

Post 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
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

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

Post 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.
MarkZar
Posts: 13
Joined: Thu Feb 07, 2013 11:53 pm

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

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