Page 1 of 1

How do you debug the Intel assembly?

Posted: Sun Oct 03, 2021 1:26 pm
by benjixu
Hello, everyone. I am an OS development beginner. Debugging is a very useful approach to help us find mistakes. I know how to debug the C language in the kernel. But kernel not only includes C language but also including a lot of assembly language. The interesting things are I can use the gdb to debug the C language parts of the kernel, instead of assembly. When I put the breakpoint in assembly, the gdb wouldn't go there, so that I can't see any debug information in it. I make sure I added the -g option in nasm and GCC. The more detail you can see in my makefile. My OS project is https://github.com/xubenji/DolphinOS.
You can download the project and enter the DolphinOS directory to run it.
Running this project in qemu with debug model is:
root@benji:~/make s
Then open gdb, make sure attached the symbol file: kelf.
: symbol-file kelf
You end up connecting to the qemu with this instruction:
target remote localhost:1234
When you set the breakpoint in handler_ASM.asm, io_ASM.asm and switch_ASM.asm, you will find that the gdb wouldn't go to those files. It is pretty strange. Do you know how to solve this problem? I appreciate you very much.

Re: How do you debug the Intel assembly?

Posted: Sun Oct 03, 2021 3:28 pm
by nexos
Try using Bochs. It has an amazing integrated ASM debugger. Note that AFAIK Bochs can't display symbol information (although you might be able to load one in, I'm not sure), but it still is great.

Try looking at the Bochs wiki page.

Re: How do you debug the Intel assembly?

Posted: Sun Oct 03, 2021 6:54 pm
by benjixu
nexos wrote:Try using Bochs. It has an amazing integrated ASM debugger. Note that AFAIK Bochs can't display symbol information (although you might be able to load one in, I'm not sure), but it still is great.

Try looking at the Bochs wiki page.
Thanks for your response. Now I use the VScode to conduct the gdb running in the Linux server. Building this framework would take me a long time. Do you know how the Bochs and gdb co-work with each other? Do you know how to set the Bochs and gdb?

Re: How do you debug the Intel assembly?

Posted: Mon Oct 04, 2021 2:01 am
by iansjack
You can set breakpoints at individual addresses in gdb with the command

Code: Select all

break *0x1234
.

Re: How do you debug the Intel assembly?

Posted: Mon Oct 04, 2021 10:15 am
by benjixu
iansjack wrote:You can set breakpoints at individual addresses in gdb with the command

Code: Select all

break *0x1234
.
Yes, but the problem is that I don’t know the address. Hahahahaha

Re: How do you debug the Intel assembly?

Posted: Mon Oct 04, 2021 10:22 am
by iansjack
Then produce a linker map file. Or use objdump to inspect your executable.