jserv / rv32jit

JIT-accelerated RISC-V instruction set simulator
MIT License
30 stars 7 forks source link

Cannot find debug info with gdb using debug build `-g` #6

Closed EagleTw closed 10 months ago

EagleTw commented 11 months ago

Reproducing steps:

  1. Add debugging option in Makefile vim Makefile add -g option in CXXFLAGS
  2. Recompile cpp code run make clean and make
  3. Run gdb gdb --args ./build/rv32jit build/aes.elf

Error message shown as follows:

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.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./build/rv32jit...
Dwarf Error: DW_FORM_strx1 found in non-DWO CU [in module /home/livlig/ypaskellPlayground/rv32jit/build/rv32jit]
(No debugging symbols found in ./build/rv32jit)
(gdb) 
visitorckw commented 11 months ago

Hi @ypaskell ,

Based on the error message you provided and the version of gdb you're using, it seems that this issue may be caused by gdb versions older than 10.1 not supporting DWARFv5. I suggest trying to update your gdb to a newer version to see if that resolves the problem. Here are some references for your information: GDB < 10.1 can't read clang's DWARF v5

EagleTw commented 11 months ago

Thank you @visitorckw. It worked.

EagleTw commented 11 months ago

GDB got stuck when I set any break points and when I run start commands

GNU gdb (Ubuntu 10.2-0ubuntu1~20.04~1) 10.2
Copyright (C) 2021 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.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./build/rv32jit...
(gdb) break Execute
^C^C^C
<system got hang here>

Tried solution:

jserv commented 10 months ago

Before proceeding, it is necessary to disable link-time optimization (LTO) and ensure a debug build. Refer to the changes below:

--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 include mk/common.mk

-CXXFLAGS := -O2 -flto -Wall -Wextra -Wno-c99-designator
+CXXFLAGS := -Og -g -Wall -Wextra -Wno-c99-designator
 CXXFLAGS += -I src
 CXXFLAGS += -std=gnu++20 -fno-rtti -fexceptions
 LDFLAGS :=

Tested with GDB 14.0.50.20230907-0ubuntu1.

$ gdb -q --args build/rv32jit build/aes.elf 
Reading symbols from build/rv32jit...
(gdb) b main
Breakpoint 1 at 0x2bf5d: file src/main.cpp, line 9.
(gdb) r
Starting program: /home/jserv/compiler/rv32jit/build/rv32jit build/aes.elf
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, main (argc=2, argv=0x7fffffffe198) at src/main.cpp:9
9       if (argc < 2) {