os-tutorial icon indicating copy to clipboard operation
os-tutorial copied to clipboard

14-checkpoint: Program received signal SIGTRAP, Trace/breakpoint trap

Open MyCodeMyMoney opened this issue 3 years ago • 4 comments

When I set a breakpoint and continue, I get an error like the following,can anyone help me? image

MyCodeMyMoney avatar May 23 '22 02:05 MyCodeMyMoney

Having the exact same issue.

Are you using WSL2 on Windows? The problem only exists when trying to add breakpoint...

aea5 avatar Jun 20 '22 20:06 aea5

The test environment I use is ubuntu20.04

MyCodeMyMoney avatar Jun 21 '22 01:06 MyCodeMyMoney

In my case, I solved the problem by using the new GDB.

  1. Issue Description: My setup: WSL2 Ubuntu on Windows 11, with GUI support The kernel itself can run and print 'X'. But when adding breakpoint b main using i386-system-gdb, it will stop at SIGTRAP and showing 0x00000000 in ?? (), as shown by the previous image. My i386-system-gdb is a patched version trying to solve the Remote 'g' packet reply is too long issue. It is built different from the one provided in this repo; https://wiki.osdev.org/QEMU_and_GDB_in_long_mode I used solution 2.

  2. Analysis: This problem only occurs when adding breakpoint. Dumped memory shows memory data are correct. However GDB's registers info reg are not showing helpful values when having the SIGTRAP (and I cannot even change them using gdb). I assume this is because the GDB is broken ( or broken by the OSDev patch).

  3. Solution: Using Ubuntu's default gdb sudo apt install gdb instead of the i386-system-gdb in the makefile.

❯ gdb --version
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

And change make debug in Makefile:

# Open the connection to qemu and load our kernel-object file with symbols
debug: os-image.bin kernel.elf
	qemu-system-i386 -s -fda os-image.bin -S &
#	${GDB} -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
	gdb -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"

which replaced ${GDB} with the new default gdb. Also added -S to halt the QEMU before booting. You can also change gdb=gdb, it's the same.

aea5 avatar Jun 21 '22 07:06 aea5

Thanks, @aea5, for your answer. I have the same problem on ubuntu 22.04 as @MyCodeMyMoney has. Add '-S' it is enough to resolve that

andishgar avatar Nov 03 '22 17:11 andishgar