Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 02 Feb 1998 18:31:43 +0100
From:      "Helmut F. Wirth" <hfwirth@eunet.at>
To:        emulation@FreeBSD.ORG
Subject:   Cross debugging Linux binaries under FreeBSD, instructions
Message-ID:  <34D602FF.167EB0E7@eunet.at>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.

--------------794BDF32446B9B3D2781E494
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello!

I promised detailed instructions to build gdb for ELF and for Linux.
Here we go:

1) Get binutils-2.8.1 and install them, where it is convinient for you.
   You also need the ports linux-devel and linux-libs. Both are
   binary only and are easy to install. You should now have
   /compat/linux/... containing libraries, include files and cross
   development tools.
2) We use the original FreeBSD-current sources of gdb:
   cd to binutils-2.8.1; there are some subdirectories (binutils, bfd,
   gas, ...). Make two new directories:
   mkdir gdb buildgdb.
   Now copy parts the systems gdb sources into these directories:
   (cd /usr/src/contrib/gdb; tar cf -)|(cd
<wherever>/bintuils-2.8.1;      	                                                             
tar xf -)
   This copies the basic sources to binutils-2.8.1/gdb. You need only
   the subdirectory gdb from /usr/src/contrib/gdb! This leaves behind
   the old bfd library and the rest. Important: After the copy
   go to binutils-2.8.1/gdb and delete the configuration files:
   configure, configure.in config.status config.log and config.cache.
   *Do not remove* config.h and the subdir config. This step is
   neccessary, because configure of the entire binutils tree would
   generate some files in the subdirectory gdb (tm.h, nm.h and xm.h)
   and this is unwanted. These files are in buildgdb and are the
   original native files from FreeBSD.
   Next step: Copy the native files and the Makefile, again we only
   need the gdb subdirectory !
   (cd /usr/src/gnu/usr.bin/gdb/gdb; tar cf - *) |
                       (cd<wherever>/binutils-2.8.1/buildgdb;tar xf -)
   This brings the Makefile and the native sources to buildgdb.
3) Install patches to the following files in binutils-2.8.1/gdb (All
   patches are included at the end of this mail as shell archive):
   solib.c: -> patch with solib-patch
   utils.c: -> patch with utils-patch
4) Install patches to the following files in binutils-2.8.1/buildgdb:
   Makefile: -> patch with Makefile-patch
   nm.h:     -> patch with nm-patch
5) Now configure the binutils: 
   configure
    -host=-host=i386-unknown-freebsd3.0-target=i386-unknown-freebsdelf
   If you want to use them for the elfkit too, add the option
    -prefix /usr/local/elf (See John Poltra's elfkit and the
   instructions there. It is not neccessary to have the elfkit.
   The configure configures the package for elf binaries. 
6) In binutils-2.8.1 do a make. This should build the libraries, the
   assembler, the linker and the tools. The assembler supports MMX, btw.
   I am using it instead of the older assembler in the linux_devel, but
   I am not sure if this works in all cases. This is more a cross tool,
   not the old Linux assembler of the linux_devel port. I don't think
   the linker will work in this configuration. 
7) Now you have to build gdb, manually: cd to buildgdb. Have a look at
   the Makefile. After the patch you will find a line:
   #CFLAGS+=-DLINUX_CROSS_GDB
   If you do not enable the line, gdb will build and it will even debug
   Linux binaries, but only if they are statically linked. This version
   of gdb is useful for elfkit: It is configured to debug FreeBSD native
   programs, but as ELF binaries (I have not tested this well, yet).
   If you enable the line, gdb is built for Linux cross debugging:
   It should work with statically and dynamically linked Linux programs.
   Don't forget branding the binaries using brandelf -t Linux xxx!!
   If the Linux emulator is not loaded or you try to use an unbranded
   binary, gdb won't recognize it as an executable!
8) Manually install gdb as linux-gdb into the /compat/linux tree.
9) If you want to try it, build without LINUX_CROSS_GDB and install this
   as elf-gdb into the elfkit.
  
If somebody points me to a ftp server I will put the binary for gdb
onto it.

Helmut
-- 
Helmut F. Wirth
Email: hfwirth@ping.at

--------------794BDF32446B9B3D2781E494
Content-Type: application/x-shar; name="gdbpatch.shar"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="gdbpatch.shar"

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	Makefile-patch
#	nm-patch
#	solib-patch
#	utils-patch
#
echo x - Makefile-patch
sed 's/^X//' >Makefile-patch << 'END-of-Makefile-patch'
Xdiff -c --recursive /usr/src/gnu/usr.bin/gdb/gdb/Makefile ./Makefile
X*** /usr/src/gnu/usr.bin/gdb/gdb/Makefile	Sun Feb  1 23:41:10 1998
X--- ./Makefile	Mon Feb  2 17:09:48 1998
X***************
X*** 2,10 ****
X  
X  PROG = gdb
X  
X! GDBDIR=	${.CURDIR}/../../../../contrib/gdb
X! .PATH:	${GDBDIR}/gdb
X! .PATH:	${GDBDIR}/opcodes
X  
X  BINDIR= /usr/bin
X  XSRCS = annotate.c blockframe.c breakpoint.c buildsym.c c-lang.c \
X--- 2,10 ----
X  
X  PROG = gdb
X  
X! GDBDIR=	${.CURDIR}/../gdb
X! .PATH:	${GDBDIR}
X! .PATH:	${.CURDIR}/../opcodes
X  
X  BINDIR= /usr/bin
X  XSRCS = annotate.c blockframe.c breakpoint.c buildsym.c c-lang.c \
X***************
X*** 32,42 ****
X  XSRCS+= i386-dis.c dis-buf.c disassemble.c
X  SRCS=	init.c ${XSRCS}
X  
X! CFLAGS+= -g -I$(.CURDIR) -I${DESTDIR}/usr/include/readline -I$(.CURDIR)/../bfd
X  # use phkmalloc
X  CFLAGS+= -DNO_MMALLOC
X  # uncomment the next line if you want to debug gdb
X  #CFLAGS+= -g
X  
X  CLEANFILES+=	c-exp.c f-exp.c m2-exp.c init.c y.tab.h init.c-tmp
X  #beforedepend:	c-exp.c f-exp.c m2-exp.c init.c
X--- 32,44 ----
X  XSRCS+= i386-dis.c dis-buf.c disassemble.c
X  SRCS=	init.c ${XSRCS}
X  
X! CFLAGS+= -I$(GDBDIR) -I${DESTDIR}/usr/include/readline -I$(.CURDIR)/../bfd
X! CFLAGS+= -I$(.CURDIR)/../include -I$(GDBDIR)/config -I$(.CURDIR)
X  # use phkmalloc
X  CFLAGS+= -DNO_MMALLOC
X  # uncomment the next line if you want to debug gdb
X  #CFLAGS+= -g
X+ #CFLAGS+= -DLINUX_CROSS_GDB
X  
X  CLEANFILES+=	c-exp.c f-exp.c m2-exp.c init.c y.tab.h init.c-tmp
X  #beforedepend:	c-exp.c f-exp.c m2-exp.c init.c
END-of-Makefile-patch
echo x - nm-patch
sed 's/^X//' >nm-patch << 'END-of-nm-patch'
Xdiff -c --recursive /usr/src/gnu/usr.bin/gdb/gdb/nm.h ./nm.h
X*** /usr/src/gnu/usr.bin/gdb/gdb/nm.h	Fri Aug 22 20:16:01 1997
X--- ./nm.h	Mon Feb  2 16:32:59 1998
X***************
X*** 23,29 ****
X--- 23,33 ----
X  #define	ATTACH_DETACH
X  
X  /* Be shared lib aware */
X+ /* For Linux debugging under FreeBSD we use SVR4 shared libs */
X  #include "solib.h"
X+ #ifdef LINUX_CROSS_GDB
X+ #define SVR4_SHARED_LIBS
X+ #endif
X  
X  /* This is the amount to subtract from u.u_ar0
X     to get the offset in the core file of the register values.  */
X***************
X*** 42,47 ****
X--- 46,52 ----
X  
X  #define PTRACE_ARG3_TYPE char*
X  
X+ #ifndef LINUX_CROSS_GDB
X  /* make structure definitions match up with those expected in solib.c */
X  #define link_object	sod
X  #define lo_name		sod_name
X***************
X*** 94,99 ****
X--- 99,105 ----
X  #define ldd		d_debug
X  #define ld_un		d_un
X  #define ld_2		d_sdt
X+ #endif /* ! LINUX_CROSS_GDB */
X  
X  /* Return sizeof user struct to callers in less machine dependent routines */
X  
END-of-nm-patch
echo x - solib-patch
sed 's/^X//' >solib-patch << 'END-of-solib-patch'
Xdiff -c --recursive /usr/src/contrib/gdb/gdb/solib.c ./solib.c
X*** /usr/src/contrib/gdb/gdb/solib.c	Fri Aug 22 20:13:12 1997
X--- ./solib.c	Mon Feb  2 16:35:11 1998
X***************
X*** 39,45 ****
X--- 39,49 ----
X  #include "elf/external.h"
X  #endif
X  
X+ #ifdef LINUX_CROSS_GDB
X+ #include "/compat/linux/usr/include/link.h"
X+ #else
X  #include <link.h>
X+ #endif
X  
X  #include "symtab.h"
X  #include "bfd.h"
X***************
X*** 70,75 ****
X--- 74,80 ----
X    "r_debug_state",
X    "_r_debug_state",
X    "_dl_debug_state",
X+   "_dl_debug_addr",
X    NULL
X  };
X  #endif
X
END-of-solib-patch
echo x - utils-patch
sed 's/^X//' >utils-patch << 'END-of-utils-patch'
Xdiff -c --recursive /usr/src/contrib/gdb/gdb/utils.c ./utils.c
X*** /usr/src/contrib/gdb/gdb/utils.c	Fri Aug 22 20:13:12 1997
X--- ./utils.c	Sun Feb  1 23:50:57 1998
X***************
X*** 772,778 ****
X  
X  PTR
X  xmalloc (size)
X!      long size;
X  {
X    return (xmmalloc ((PTR) NULL, size));
X  }
X--- 772,778 ----
X  
X  PTR
X  xmalloc (size)
X!      size_t size;
X  {
X    return (xmmalloc ((PTR) NULL, size));
X  }
X***************
X*** 782,788 ****
X  PTR
X  xrealloc (ptr, size)
X       PTR ptr;
X!      long size;
X  {
X    return (xmrealloc ((PTR) NULL, ptr, size));
X  }
X--- 782,788 ----
X  PTR
X  xrealloc (ptr, size)
X       PTR ptr;
X!      size_t size;
X  {
X    return (xmrealloc ((PTR) NULL, ptr, size));
X  }
END-of-utils-patch
exit


--------------794BDF32446B9B3D2781E494--




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?34D602FF.167EB0E7>