riscv-collab / riscv-gnu-toolchain

GNU toolchain for RISC-V, including GCC
Other
3.47k stars 1.14k forks source link

Use gef in riscv-gdb #636

Closed Phantom1003 closed 4 years ago

Phantom1003 commented 4 years ago

I run riscv64-unknown-linux-gnu-gdb with gef, got the following info:

GNU gdb (GDB) 8.3.0.20190516-git
Copyright (C) 2019 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 "--host=x86_64-pc-linux-gnu --target=riscv64-unknown-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".
/home/phantom/.gdbinit:1: Error in sourced command file:
/home/phantom/.gdbinit-gef.py:58: Error in sourced command file:
Undefined command: "from".  Try "help".

And the result of configuration show that python is closed

(gdb) show configuration
This GDB was configured as follows:
   configure --host=x86_64-pc-linux-gnu --target=riscv64-unknown-linux-gnu
             --with-auto-load-dir=$debugdir:$datadir/auto-load
             --with-auto-load-safe-path=$debugdir:$datadir/auto-load
             --with-expat
             --with-gdb-datadir=.../toolchain/share/gdb (relocatable)
             --with-jit-reader-dir=.../toolchain/lib/gdb (relocatable)
             --without-libunwind-ia64
             --without-lzma
             --without-babeltrace
             --without-intel-pt
             --disable-libmcheck
             --with-mpfr
             --without-python       <-
             --without-guile
             --disable-source-highlight
             --with-separate-debug-dir=.../toolchain/lib/debug (relocatable)
             --with-sysroot=.../toolchain/sysroot (relocatable)

I think the reason is because of my environment, my desktop got the python support with same code Desktop

Linux Pavilion 4.15.0-99-generic #100-Ubuntu SMP Wed Apr 22 20:32:56 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Python 2.7.17

vm in laptop

Linux ubuntu-phantom 5.3.0-51-generic #44~18.04.2-Ubuntu SMP Thu Apr 23 14:27:18 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Python 2.7.17

Could you give me some suggestion? Thanks

jim-wilson commented 4 years ago

You probably don't have the necessary OS packages installed to support python. If you look at the build-gdb-linux/gdb/config.log file you will see checks for python support, and probably one of them failed. Note that you may need to have a python development package installed in order for gdb to find python header files and libraries. That is the part most likely missing. You probably have the pythoin package installed but not the python developer package. This varies from one distro to the next.

Phantom1003 commented 4 years ago

I find info in build-gdb-linux/gdb/config.log:

configure:10550: checking for python2.7
configure:10568: gcc -o conftest -g -O2  -I/usr/include/python2.7 -I/usr/include/python2.7 -static-libstdc++ -static-libgcc  conftest.c -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions -lm -ldl  >&5
conftest.c:53:10: fatal error: Python.h: No such file or directory
 #include "Python.h"
          ^~~~~~~~~~
compilation terminated.

And I run the command

sudo apt-get install python-dev  

Although I am still compiling, I think this should work, thanks

Phantom1003 commented 4 years ago

By the way, you should also use a python2 version gef. https://github.com/hugsy/gef-legacy Hope riscv-gdb upgrade py3 as soon as possible