mit-pdos / xv6-riscv

Xv6 for RISC-V
Other
6.63k stars 2.4k forks source link

GDB can't step into ecall. #96

Closed lxyscls closed 2 years ago

lxyscls commented 2 years ago

The output is as below, and ecall's address in sh.asm is 0xdec.

(gdb) show step-mode
Mode of the step operation is off.
(gdb) set step-mode on
(gdb) b *0xdec
Breakpoint 1 at 0xdec
(gdb) c
Continuing.

Thread 1 hit Breakpoint 1, 0x0000000000000dec in ?? ()
=> 0x0000000000000dec:  73 00 00 00     ecall
(gdb) delete 1
(gdb) print $pc
$1 = (void (*)()) 0xdec
(gdb) x/2c $a1
0x3e9f: 36 '$'  48 '0'
(gdb) si
0x0000000000000df0 in ?? ()
=> 0x0000000000000df0:  82 80   ret
(gdb) print $pc
$2 = (void (*)()) 0xdf0
(gdb)

My system is Ubuntu 20.04 in WSL2, and GDB is gdb-multiarch.

Package: gdb-multiarch
Version: 9.2-0ubuntu1~20.04
Priority: optional
Section: universe/devel
Source: gdb
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Héctor Orón Martínez <zumbi@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 15.2 MB
Depends: gdb (= 9.2-0ubuntu1~20.04), libbabeltrace1 (>= 1.5.4), libc6 (>= 2.29), libexpat1 (>= 2.0.1), libgcc-s1 (>= 3.4), liblzma5 (>= 5.1.1alpha+20110809), libmpfr6 (>= 3.1.3), libncursesw6 (>= 6), libpython3.8 (>= 3.8.2), libreadline8 (>= 8), libstdc++6 (>= 7), libtinfo6 (>= 6), zlib1g (>= 1:1.2.0)
Homepage: http://www.gnu.org/s/gdb/
Download-Size: 3794 kB
APT-Manual-Installed: yes
APT-Sources: http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages
Description: GNU Debugger (with support for multiple architectures)
 GDB is a source-level debugger, capable of breaking programs at
 any specific line, displaying variable values, and determining
 where errors occurred. Currently, gdb supports C, C++, D,
 Objective-C, Fortran, Java, OpenCL C, Pascal, assembly, Modula-2,
 Go, and Ada. A must-have for any serious programmer.
 .
 This package contains a version of GDB which supports multiple
 target architectures.
lxyscls commented 2 years ago

"info mem" in QEMU can't show the user program's pages too.

qemu-system-riscv64 -machine virt -bios none -kernel kernel/kernel -m 128M -smp 3 -nographic -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 -S -gdb tcp::25000

xv6 kernel is booting

hart 1 starting
hart 2 starting
init: starting sh
QEMU 4.2.1 monitor - type 'help' for more information
(qemu) info mem
vaddr            paddr            size             attr
---------------- ---------------- ---------------- -------
000000000c000000 000000000c000000 0000000000001000 rw---ad
000000000c001000 000000000c001000 0000000000001000 rw-----
000000000c002000 000000000c002000 0000000000001000 rw---ad
000000000c003000 000000000c003000 00000000001fe000 rw-----
000000000c201000 000000000c201000 0000000000001000 rw---ad
000000000c202000 000000000c202000 0000000000001000 rw-----
000000000c203000 000000000c203000 0000000000001000 rw---ad
000000000c204000 000000000c204000 0000000000001000 rw-----
000000000c205000 000000000c205000 0000000000001000 rw---ad
000000000c206000 000000000c206000 00000000001fa000 rw-----
0000000010000000 0000000010000000 0000000000002000 rw---ad
0000000080000000 0000000080000000 0000000000007000 r-x--a-
0000000080007000 0000000080007000 0000000000001000 r-x----
0000000080008000 0000000080008000 0000000000005000 rw---ad
000000008000d000 000000008000d000 0000000000004000 rw-----
0000000080011000 0000000080011000 0000000000011000 rw---ad
0000000080022000 0000000080022000 0000000000001000 rw-----
0000000080023000 0000000080023000 0000000000003000 rw---ad
0000000080026000 0000000080026000 0000000007f36000 rw-----
0000000087f5c000 0000000087f5c000 000000000001c000 rw---ad
0000000087f78000 0000000087f78000 0000000000088000 rw-----
0000003ffff7f000 0000000087f78000 000000000003e000 rw-----
0000003fffffb000 0000000087fb6000 0000000000002000 rw---ad
0000003ffffff000 0000000080007000 0000000000001000 r-x--a-
GroverZhu commented 2 years ago

I have the same problem in GDB can't step into ecall. First make sure in the .gdbinit.tmpl-riscv file you have this line: set riscv use-compressed-breakpoints yes, if this also cannot step into ecall, print the stvec register value,and make a breakpointer in the stvec address. In this way, it can trap into the kernel code. Hope it can help you.

lxyscls commented 2 years ago

I have the same problem in GDB can't step into ecall. First make sure in the .gdbinit.tmpl-riscv file you have this line: set riscv use-compressed-breakpoints yes, if this also cannot step into ecall, print the stvec register value,and make a breakpointer in the stvec address. In this way, it can trap into the kernel code. Hope it can help you.

set riscv use-compressed-breakpoints yes is the default value in .gdbinit.tmpl-riscv, and I have changed to riscv64-unknown-elf-gdb, everthing is ok now.