How do you debug the Intel assembly?

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
benjixu
Posts: 11
Joined: Sat Oct 02, 2021 10:28 pm
Libera.chat IRC: Benji

How do you debug the Intel assembly?

Post 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.
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: How do you debug the Intel assembly?

Post 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.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
benjixu
Posts: 11
Joined: Sat Oct 02, 2021 10:28 pm
Libera.chat IRC: Benji

Re: How do you debug the Intel assembly?

Post 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?
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How do you debug the Intel assembly?

Post by iansjack »

You can set breakpoints at individual addresses in gdb with the command

Code: Select all

break *0x1234
.
benjixu
Posts: 11
Joined: Sat Oct 02, 2021 10:28 pm
Libera.chat IRC: Benji

Re: How do you debug the Intel assembly?

Post 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
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How do you debug the Intel assembly?

Post by iansjack »

Then produce a linker map file. Or use objdump to inspect your executable.
Post Reply