root@os1:/mnt/gdb-14.2/build-riscv64# ./bin/riscv64-unknown-elf-gdb --version GNU gdb (GDB) 14.2 Copyright (C) 2023 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. root@os1:/mnt/gdb-14.2/build-riscv64# ll ./bin/ total 238428 drwxr-xr-x 1 root root 4096 May 13 03:10 ./ drwxr-xr-x 1 root root 4096 May 13 03:10 ../ -rwxr-xr-x 1 root root 232530576 May 13 03:10 riscv64-unknown-elf-gdb* -rwxr-xr-x 1 root root 4627 May 13 03:10 riscv64-unknown-elf-gdb-add-index* -rwxr-xr-x 1 root root 11605272 May 13 03:10 riscv64-unknown-elf-run*
root@os1:/mnt/2024s-rcore-xuejianxinokok/os/target/riscv64gc-unknown-none-elf/debug# file os os: ELF 64-bit LSB executable, UCB RISC-V, version 1 (SYSV), statically linked,
with debug_info, not stripped <<<<<<< 注意是这行
# 或者直接读取section 信息,发现有debug_info 这些section root@os1:/mnt/2024s-rcore-xuejianxinokok/os/target/riscv64gc-unknown-none-elf/debug# readelf -SW os There are 18 section headers, starting at offset 0x2952a8:
Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 0000000080200000 001000 00a340 00 AX 0 0 4 [ 2] .rodata PROGBITS 000000008020b000 00c000 0334ab 00 AM 0 0 4096 [ 3] .data PROGBITS 000000008023f000 040000 028920 00 WA 0 0 8 [ 4] .bss NOBITS 0000000080268000 068920 038660 00 WA 0 0 8 [ 5] .debug_abbrev PROGBITS 0000000000000000 068920 006a82 00 0 0 1 [ 6] .debug_info PROGBITS 0000000000000000 06f3a2 073718 00 0 0 1 [ 7] .debug_aranges PROGBITS 0000000000000000 0e2aba 0061b0 00 0 0 1 [ 8] .debug_str PROGBITS 0000000000000000 0e8c6a 08d4ab 01 MS 0 0 1 [ 9] .comment PROGBITS 0000000000000000 176115 000048 01 MS 0 0 1 [10] .riscv.attributes RISCV_ATTRIBUTES 0000000000000000 17615d 00003e 00 0 0 1 [11] .debug_frame PROGBITS 0000000000000000 1761a0 007f08 00 0 0 8 [12] .debug_line PROGBITS 0000000000000000 17e0a8 040627 00 0 0 1 [13] .debug_ranges PROGBITS 0000000000000000 1be6cf 033b00 00 0 0 1 [14] .debug_loc PROGBITS 0000000000000000 1f21cf 000b72 00 0 0 1 [15] .symtab SYMTAB 0000000000000000 1f2d48 096048 18 17 25465 8 [16] .shstrtab STRTAB 0000000000000000 288d90 0000b5 00 0 0 1 [17] .strtab STRTAB 0000000000000000 288e45 00c462 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), p (processor specific)
这时我们就可以在 容器内的命令行进行调试了,但这样还是不太方便
进入gbd 后
先回车后 ,然后再输入 b rust_main
1 2
b rust_main Breakpoint 1 at 0x8020618a: file src/main.rs, line 98.