Compile gdb for aarch64 target to use with MX-Linux. Later compile to use with FreeBSD or GhostBSD-Arm64

Compile gdb for aarch64 target

REMOTE Debugging with EmCraft
 
Here I found a forum post at forums.raspberrypi.com and a shell script file
See my post 2nd about aarch64 

The first forum post has many useful links and notes.
Target Descriptions,  need to setup something like aarch64-freebsd-gnu
Need to include expat, the XML reading utility.  Used by aarch64 ARM64
 
su -
password: 
cd expat-2.6.1
./configure
make
 
sudo make install
 
pwd
cd ../../gdb/gdb-14.2/build*
pwd
 
 ../configure --host=x86_64-pc-linux-gnu --target=aarch64-elf-freebsd --with-expat --with-libexpat-prefix=/usr/local/
make
sudo make install
whereis aarch64-gdb
aarch64-gdb --configuration
 
openocd -f interface/ftdi/tigard-jtag.cfg -f target/bcm2711.cfg
aarch64-gdb
(gdb)  target remote :3336
(gdb)  target extended-remote 3336

 
 
 

 
 
http://www.kegel.com/linux/gdbserver.html  Remote Debugging by Dan Kegel
Example of how to configure building GDB  with a  --target=aarch64-freebsd for my needs of a Linux Host and a aarch64-FreeBSD target  Use line 4
  1. cd gdb-14.2
  2. ./configure --target=aarch64-linux-android && make -j8 && sudo make install
  3. $ ../configure --target=aarch64-freebsd --program-prefix=aarch64-
  4. ../configure --target=aarch64-elf-freebsd  --program-prefix=aarch64-  --with-expat --with-libexpat-prefix=/usr/local/
 
 


 
I see from the follow gdb configuration dump that I did not set the
 configuration up very well.
mxme@mx16-Klik:/media/mxme/Linux1/RaspberryPi4B/src/gdb/gdb-14.2/build-aarch64-gdb/gdb
$ gdb --configuration
Python Exception <class 'ModuleNotFoundError'> No module named 'gdb':
gdb: warning:
Could not load the Python gdb module from `/usr/local/share/gdb/python'.
Limited Python support is available from the _gdb module.
Suggest passing --data-directory=/path/to/gdb/data-directory.
This GDB was configured as follows:
   configure --host=x86_64-linux-gnu --target=x86_64-linux-gnu
             --with-auto-load-dir=$debugdir:$datadir/auto-load
             --with-auto-load-safe-path=$debugdir:$datadir/auto-load
             --with-expat
             --with-gdb-datadir=/usr/share/gdb (relocatable)
             --with-jit-reader-dir=/usr/lib/gdb (relocatable)
             --without-libunwind-ia64
             --with-lzma
             --with-babeltrace
             --with-intel-pt
             --with-mpfr
             --with-xxhash
             --with-python=/usr (relocatable)
             --with-python-libdir=/usr/lib (relocatable)
             --with-debuginfod
             --without-guile
             --enable-source-highlight
             --with-separate-debug-dir=/usr/lib/debug (relocatable)
             --with-system-gdbinit=/etc/gdb/gdbinit
             --with-system-gdbinit-dir=/etc/gdb/gdbinit.d

("Relocatable" means the directory can be moved with the GDB installation
tree, and GDB will still find it.)

 
 

Here is a Stack Overflow post to read and understand about configuring targets


Can change directory to the base of gdb-14.2 source code and read through config.guess text file with the "less config.guess"  using search function ' /aarch64'  to see what is available or  '/freebsd' to look for the operating system functions.   Remember I am building my first version of GDB to function on a host X86_64 MX Linux system box and debug target code of aarch64 on the Raspberry Pi 4B.  So GDB source code trying to use 'uname -m' command to guess at the proccesser and the host operating system is not much useful.


It seems below does the job.

./configure --host=aarch64-linux-gnu

./configure --target=aarch64-unknown-freebsd  --program-prefix=aarch64-  --with-expat --with-libexpat-prefix=/usr/local/
 

  • Have you tried CC=aarch64-linux-gnu- ?
    – Gluttton
    Aug 9, 2017 at 13:15
  • I tried this now. But it didn't work (seems configure needs the compiler option). Below is the error in config.log 70 configure:4201: aarch64-linux-gnu- --version >&5 71 ./configure: line 4203: aarch64-linux-gnu-: command not found
    – MS.
    Aug 9, 2017 at 13:27

  • Have you installed cross-compiler package (something line gcc-XXX-aarch64-linux-gnu-YYY)?
    – Gluttton
    Aug 9, 2017 at 13:31
  • Yep. Installed the packages for Ubuntu. And the same are available in /usr/bin/ as well..
    – MS.
    Aug 9, 2017 
     

     
     
GDB commands description and usage



$ cd build*
mxme@mx16-Klik:/media/mxme/Linux1/RaspberryPi4B/src/gdb/gdb-14.2/build-aarch64-gdb
$ ../configure --target=aarch64-freebsd --program-prefix=aarch64-  
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... aarch64-unknown-freebsd
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /usr/bin/sed
checking for gawk... gawk
checking for gdbserver support... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for gcc option to accept ISO C99... none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking whether g++ accepts -static-libstdc++ -static-libgcc... yes
checking for gnatbind... no
checking for gnatmake... no
checking whether compiler driver understands Ada and is recent enough... no
checking for gdc... no
checking whether the D compiler works... no
checking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2
checking for objdir... .libs
checking for the correct version of gmp.h... yes
checking for the correct version of mpfr.h... yes
checking for the correct version of the gmp/mpfr libraries... yes
checking for isl 0.15 or later... no
required isl version is 0.15 or later
*** This configuration is not supported in the following subdirectories:
     gdbserver
    (Any other directories should still work fine.)
checking for default BUILD_CONFIG...
checking for --enable-vtable-verify... no
checking for bison... no
checking for byacc... no
checking for yacc... no
checking for bison... no
checking for gm4... no
checking for gnum4... no
checking for m4... m4
checking for flex... no
checking for lex... no
checking for flex... no
checking for makeinfo... makeinfo
checking for expect... no
checking for runtest... no
checking for ar... ar
checking for as... as
checking for dlltool... no
checking for dsymutil... no
checking for ld... ld
checking for lipo... no
checking for nm... nm
checking for ranlib... ranlib
checking for strip... strip
checking for windres... no
checking for windmc... no
checking for objcopy... objcopy
checking for objdump... objdump
checking for otool... no
checking for readelf... readelf
checking for -plugin option... --plugin /usr/lib/gcc/x86_64-linux-gnu/10/liblto_plugin.so
checking for aarch64-freebsd-cc... no
checking for aarch64-freebsd-gcc... no
checking for aarch64-freebsd-c++... no
checking for aarch64-freebsd-g++... no
checking for aarch64-freebsd-cxx... no
checking for aarch64-freebsd-gxx... no
checking for aarch64-freebsd-gcc... no
checking for aarch64-freebsd-gfortran... no
checking for aarch64-freebsd-gccgo... no
checking for aarch64-freebsd-gdc... no
checking for aarch64-freebsd-gm2... no
checking for aarch64-freebsd-ar... no
checking for aarch64-freebsd-as... no
checking for aarch64-freebsd-dlltool... no
checking for aarch64-freebsd-dsymutil... no
checking for aarch64-freebsd-ld... no
checking for aarch64-freebsd-lipo... no
checking for aarch64-freebsd-nm... no
checking for aarch64-freebsd-objcopy... no
checking for aarch64-freebsd-objdump... no
checking for aarch64-freebsd-otool... no
checking for aarch64-freebsd-ranlib... no
checking for aarch64-freebsd-readelf... no
checking for aarch64-freebsd-strip... no
checking for aarch64-freebsd-windres... no
checking for aarch64-freebsd-windmc... no
checking where to find the target ar... pre-installed
checking where to find the target as... pre-installed
checking where to find the target cc... pre-installed
checking where to find the target c++... pre-installed
checking where to find the target c++ for libstdc++... pre-installed
checking where to find the target dlltool... pre-installed
checking where to find the target dsymutil... pre-installed
checking where to find the target gcc... pre-installed
checking where to find the target gfortran... pre-installed
checking where to find the target gccgo... pre-installed
checking where to find the target gdc... pre-installed
checking where to find the target gm2... pre-installed
checking where to find the target ld... pre-installed
checking where to find the target lipo... pre-installed
checking where to find the target nm... pre-installed
checking where to find the target objcopy... pre-installed
checking where to find the target objdump... pre-installed
checking where to find the target otool... pre-installed
checking where to find the target ranlib... pre-installed
checking where to find the target readelf... pre-installed
checking where to find the target strip... pre-installed
checking where to find the target windres... pre-installed
checking where to find the target windmc... pre-installed
checking whether to enable maintainer-specific portions of Makefiles... no
configure: creating ./config.status
config.status: creating Makefile

 

make  all-recursive
make[3]: Entering directory '/media/mxme/Linux1/RaspberryPi4B/src/gdb/gdb-14.2/build-aarch64-gdb/sim'
make[4]: Entering directory '/media/mxme/Linux1/RaspberryPi4B/src/gdb/gdb-14.2/build-aarch64-gdb/sim'
  CCLD     aarch64/run
/usr/bin/ld: ../opcodes/.libs/libopcodes.a(disassemble.o): in function `disassembler':
/media/mxme/Linux1/RaspberryPi4B/src/gdb/gdb-14.2/build-aarch64-gdb/opcodes/../../opcodes/disassemble.c:547: undefined reference to `print_insn_i386'
/usr/bin/ld: ../opcodes/.libs/libopcodes.a(disassemble.o): in function `disassembler_usage':
/media/mxme/Linux1/RaspberryPi4B/src/gdb/gdb-14.2/build-aarch64-gdb/opcodes/../../opcodes/disassemble.c:575: undefined reference to `print_i386_disassembler_options'
collect2: error: ld returned 1 exit status
make[4]: *** [Makefile:3635: aarch64/run] Error 1
make[4]: Leaving directory '/media/mxme/Linux1/RaspberryPi4B/src/gdb/gdb-14.2/build-aarch64-gdb/sim'
make[3]: *** [Makefile:4208: all-recursive] Error 1
make[3]: Leaving directory '/media/mxme/Linux1/RaspberryPi4B/src/gdb/gdb-14.2/build-aarch64-gdb/sim'
make[2]: *** [Makefile:3021: all] Error 2
make[2]: Leaving directory '/media/mxme/Linux1/RaspberryPi4B/src/gdb/gdb-14.2/build-aarch64-gdb/sim'
make[1]: *** [Makefile:9791: all-sim] Error 2
make[1]: Leaving directory '/media/mxme/Linux1/RaspberryPi4B/src/gdb/gdb-14.2/build-aarch64-gdb'
make: *** [Makefile:1020: all] Error 2
mxme@mx16-Klik:/media/mxme/Linux1/RaspberryPi4B/src/gdb/gdb-14.2/build-aarch64-gdb

Now to fix 2 errors:  referencing i386 disassembly links missing.  Maybe add  a target  i386  ?


 root@mx16-Klik:/media/mxme/Linux1/RaspberryPi4B/src/gdb/gdb-14.2/build-aarch64-gdb# aarch64-gdb --configuration
This GDB was configured as follows:
   configure --host=x86_64-pc-linux-gnu --target=aarch64-elf-freebsd
         --with-auto-load-dir=$debugdir:$datadir/auto-load
         --with-auto-load-safe-path=$debugdir:$datadir/auto-load
         --with-expat
         --with-gdb-datadir=/usr/local/share/gdb (relocatable)
         --with-jit-reader-dir=/usr/local/lib/gdb (relocatable)
         --without-libunwind-ia64
         --without-lzma
         --without-babeltrace
         --without-intel-pt
         --without-xxhash
         --without-python
         --without-python-libdir
         --without-debuginfod
         --without-curses
         --without-guile
         --without-amd-dbgapi
         --disable-source-highlight
         --enable-threading
         --disable-tui
         --without-system-readline
         --with-separate-debug-dir=/usr/local/lib/debug (relocatable)

("Relocatable" means the directory can be moved with the GDB installation
tree, and GDB will still find it.)

root@mx16-Klik:/media/mxme/Linux1/RaspberryPi4B/src/gdb/gdb-14.2/build-aarch64-gdb#

# In a different Terminal Window start up OpenOCD with the following line first, then start  aarch64-gdb

# openocd -f interface/ftdi/tigard-jtag.cfg -f target/bcm2711.cfg
 

 

 

 aarch64-gdb


 

Comments

Popular posts from this blog

HDMI Audio sound patches into GhostBSD source code /usr/ghost14/ghostbsd-src SOLVED Jan20 2024

How to install GhostBSD-Arm64 into a USB Flash Drive stick April 24, 2024 update edition.

January 19, 2024 Howto Download a Raspberry Pi 4B bootable image from http://ghostbsdarm64.hopto.org/packages/