Package: gdb
Version: 6.3-6
Severity: wishlist
This patch against 6.3-6 allow to debug cross-compiled applications
using GDB. To create a cross-gdb please apply this patch and set
the TARGET environment variable to your desired architecture. In this
example we create a powerpc-linux-gdb application:
$ apt-get source gdb
$ cd gdb-6.3
$ patch -p1 < ../gdb-6.3-6.cross-patch-20050613.diff
$ TARGET=powerpc dpkg-buildpackage -rfakeroot -uc -us
After the successful build you get a package called
gdb-powerpc-linux_6.3-6_i386.deb on i386. Install it first:
# dpkg -i gdb-powerpc-linux_6.3-6_i386.deb
Now we can start the new debugger:
$ GNU gdb 6.3-debian
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "--host=i386-linux --target=powerpc-linux".
(gdb)
A new configuration variable is introduced with this patch called
"solib-crossdir":
(gdb) show solib-crossdir
The base directory for cross libraries is "/usr/powerpc-linux".
(gdb)
This configuration variable is set by default to the dpkg-cross's
default directory where cross files are found. For libraries it is
/usr/powerpc-linux/lib for PowerPC cross-debugger.
--
Raphael Bossek
diff -Nru gdb-6.3/debian/control.in gdb-6.3.cross/debian/control.in
--- gdb-6.3/debian/control.in 2005-06-13 08:54:58.505776632 +0200
+++ gdb-6.3.cross/debian/control.in 2005-06-13 08:54:32.970658560 +0200
@@ -1,17 +1,17 @@
Source: gdb
-Maintainer: Daniel Jacobowitz <[EMAIL PROTECTED]>
+Maintainer: @MAINTAINER@
Section: devel
Priority: standard
Standards-Version: 3.5.3
Build-Depends: autoconf, libtool, texinfo (>= 4.7-2.2), tetex-bin, libncurses5-dev, libreadline4-dev (>= 4.2a-1), bison, gettext, debhelper (>= 4.1.46), dejagnu, gcj [!mips !mipsel], gobjc, mig [EMAIL PROTECTED]@], cdbs (>= 0.4.17), quilt (>= 0.30-1), libkvm-dev [EMAIL PROTECTED]@], type-handling (>= 0.2.1), libunwind7-dev [ia64], flex | flex-old
-Package: gdb
+Package: [EMAIL PROTECTED]@
Architecture: any
Section: devel
Depends: ${shlibs:Depends}
Conflicts: gdb-arm
-Replaces: gdb-arm, insight (<< 6.1+cvs.2004.04.07-1)
-Description: The GNU Debugger
+Replaces: gdb-arm, [EMAIL PROTECTED]@ (<< 6.1+cvs.2004.04.07-1)
+Description: The GNU [EMAIL PROTECTED]@
GDB is a source-level debugger, capable of breaking programs at
any specific line, displaying variable values, and determining
where errors occurred. Currently, it works for C, C++, Fortran
diff -Nru gdb-6.3/debian/gdb.menu.in gdb-6.3.cross/debian/gdb.menu.in
--- gdb-6.3/debian/gdb.menu.in 1970-01-01 01:00:00.000000000 +0100
+++ gdb-6.3.cross/debian/gdb.menu.in 2005-06-13 08:54:33.685549880 +0200
@@ -0,0 +1,3 @@
+?package(gdb):needs="text" title="[EMAIL PROTECTED]@" section="Apps/Programming"\
+ hints="Debuggers" command="/usr/bin/@[EMAIL PROTECTED]"
+
diff -Nru gdb-6.3/debian/rules gdb-6.3.cross/debian/rules
--- gdb-6.3/debian/rules 2005-06-13 08:54:58.505776632 +0200
+++ gdb-6.3.cross/debian/rules 2005-06-13 08:54:33.687549576 +0200
@@ -22,8 +22,39 @@
DEB_HOST_GNU_CPU := $(shell dpkg-architecture -qDEB_HOST_GNU_CPU)
DEB_HOST_GNU_TYPE := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
-run_tests := yes
-run_thread_tests := yes
+DEB_TARGET_ARCH := $(shell dpkg-architecture -f \
+ -a$(TARGET) -qDEB_HOST_ARCH 2>/dev/null)
+DEB_TARGET_GNU_CPU := $(shell dpkg-architecture -f \
+ -a$(DEB_TARGET_ARCH) -qDEB_HOST_GNU_CPU 2>/dev/null)
+DEB_TARGET_GNU_SYSTEM := $(shell dpkg-architecture -f \
+ -a$(DEB_TARGET_ARCH) -qDEB_HOST_GNU_SYSTEM 2>/dev/null)
+DEB_TARGET_GNU_TYPE := $(shell dpkg-architecture -f \
+ -a$(DEB_TARGET_ARCH) -qDEB_HOST_GNU_TYPE 2>/dev/null)
+
+ifneq ($(DEB_HOST_ARCH),$(DEB_TARGET_ARCH))
+ DEB_CROSS = yes
+ # TP: Target Prefix. Used primarily as a prefix for cross tool
+ # names (e.g. powerpc-linux-gcc).
+ # TS: Target Suffix. Used primarily at the end of cross compiler
+ # package names (e.g. gcc-powerpc).
+ # LS: Library Suffix. Used primarily at the end of cross compiler
+ # library package names (e.g. libgcc-powerpc-cross).
+ DEB_TARGET_ALIAS ?= $(DEB_TARGET_GNU_TYPE)
+ TP = $(DEB_TARGET_GNU_TYPE)-
+ TS = -$(DEB_TARGET_ALIAS)
+ LS = -$(DEB_TARGET_ARCH)-cross
+ MAINTAINER = Raphael Bossek <[EMAIL PROTECTED]>
+else
+ MAINTAINER = Daniel Jacobowitz <[EMAIL PROTECTED]>
+endif
+
+ifneq ($(DEB_CROSS),yes)
+ run_tests := yes
+ run_thread_tests := yes
+else
+ run_tests := no
+ run_thread_tests := no
+endif
ifneq ($(DEB_HOST_GNU_SYSTEM),linux)
run_tests := no
@@ -33,22 +64,33 @@
run_tests := no
endif
-ifeq ($(DEB_HOST_GNU_CPU),ia64)
+ifeq ($(DEB_TARGET_GNU_CPU),ia64)
arch_config_args := --with-libunwind
endif
INSTALL = $(install)
export INSTALL
+ifeq ($(DEB_CROSS),yes)
+LIBDIR = /usr/$(DEB_TARGET_ALIAS)/lib
+else
+LIBDIR = /usr/lib
+endif
+
# We pass srcdir explicitly to avoid an extra '/.' at the end of it. That
# causes a harmless, but ugly, testsuite failure in maint.exp.
-DEB_CONFIGURE_EXTRA_FLAGS := $(DEB_HOST_GNU_TYPE) --disable-gdbtk \
+DEB_CONFIGURE_EXTRA_FLAGS := --disable-gdbtk \
--disable-shared --enable-tui --srcdir=$(shell pwd) \
- $(arch_config_args)
+ --target=$(DEB_TARGET_GNU_TYPE) --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_HOST_GNU_TYPE) \
+ --libdir=$(LIBDIR) $(arch_config_args)
+ifneq ($(DEB_CROSS),yes)
DEB_MAKE_BUILD_TARGET = all info
+else
+DEB_MAKE_BUILD_TARGET = all
+endif
-post-patches::
+post-patches:: debian/gdb$(TS).menu
if ! test -f gdb/version.in.backup; then \
mv -f gdb/version.in gdb/version.in.backup; \
sed -e 's/$$/-debian/' < gdb/version.in.backup > gdb/version.in; \
@@ -56,7 +98,7 @@
# This should probably be common-post-build-arch, but that runs during
# install, under fakeroot, in CDBS 0.4.21.
-build/gdb:: check-stamp
+build/gdb$(TS):: check-stamp
$(MAKE) -C objdir/gdb/doc refcard.dvi refcard.ps
check-stamp:
@@ -80,39 +122,52 @@
mv -f gdb/version.in.backup gdb/version.in; \
fi
+ rm -f debian/gdb$(TS).menu
+
# # For snapshots this is appropriate; careful of release tarballs
# # which include .gmo files.
# find -type f -name '*.gmo' | xargs rm -f
rm -f check-stamp
+ cat debian/control.in \
+ | sed "s/@kfreebsd@/`type-handling any kfreebsd-gnu`/g" \
+ | sed "s/@gnu@/`type-handling any gnu`/g" \
+ | sed "s/@TP@/$(TP)/g;s/@TS@/$(TS)/g;s/@TA@/ ($(DEB_TARGET_ALIAS))/g" \
+ | sed "s/ ()//g" \
+ | sed "s/@MAINTAINER@/$(MAINTAINER)/g" \
+ > debian/control
-binary-post-install/gdb ::
- if [ -x debian/gdb/usr/bin/run ]; then \
- mv debian/gdb/usr/bin/run \
- debian/gdb/usr/bin/$(DEB_HOST_GNU_TYPE)-run; \
- mv debian/gdb/usr/share/man/man1/run.1 \
- debian/gdb/usr/share/man/man1/$(DEB_HOST_GNU_TYPE)-run.1; \
+binary-post-install/gdb$(TS) ::
+ if [ -x debian/gdb$(TS)/usr/bin/run ]; then \
+ mv debian/gdb$(TS)/usr/bin/run \
+ debian/gdb$(TS)/usr/bin/$(DEB_TARGET_GNU_TYPE)-run; \
+ mv debian/gdb$(TS)/usr/share/man/man1/run.1 \
+ debian/gdb$(TS)/usr/share/man/man1/$(DEB_TARGET_GNU_TYPE)-run.1; \
fi
ifeq ($(run_tests),yes)
- install -d debian/gdb/usr/share/doc/gdb
+ install -d debian/gdb$(TS)/usr/share/doc/gdb$(TS)
install -m 644 objdir/check.log \
- debian/gdb/usr/share/doc/gdb/check.log
+ debian/gdb$(TS)/usr/share/doc/gdb$(TS)/check.log
endif
- rm -rf debian/gdb/usr/include \
- debian/gdb/usr/lib/lib*.* \
- debian/gdb/usr/share/info/annotate.info* \
- debian/gdb/usr/share/info/bfd.info* \
- debian/gdb/usr/share/info/configure.info* \
- debian/gdb/usr/share/info/mmalloc.info* \
- debian/gdb/usr/share/info/standards.info* \
- debian/gdb/usr/share/locale
-
-debian/control:: debian/control.in
- cat debian/control.in \
- | sed "s/@kfreebsd@/`type-handling any kfreebsd-gnu`/g" \
- | sed "s/@gnu@/`type-handling any gnu`/g" \
- > debian/control
+ rm -rf debian/gdb$(TS)/usr/include \
+ debian/gdb$(TS)$(LIBDIR)/lib*.* \
+ debian/gdb$(TS)/usr/share/info/annotate.info* \
+ debian/gdb$(TS)/usr/share/info/bfd.info* \
+ debian/gdb$(TS)/usr/share/info/configure.info* \
+ debian/gdb$(TS)/usr/share/info/mmalloc.info* \
+ debian/gdb$(TS)/usr/share/info/standards.info* \
+ debian/gdb$(TS)/usr/share/locale
+
+ifeq ($(DEB_CROSS),yes)
+ rm -rf debian/gdb$(TS)/usr/share/info
+ rm -rf debian/gdb$(TS)/usr/share/locale
+endif
+
+debian/gdb$(TS).menu:: debian/gdb.menu.in
+ cat debian/gdb.menu.in \
+ | sed "s/@TP@/$(TP)/g;s/@TS@/$(TS)/g;s/@TA@/ ($(DEB_TARGET_ALIAS))/g" \
+ > debian/gdb$(TS).menu
DEB_INSTALL_DOCS_gdb = gdb/NEWS gdb/README gdb/doc/refcard.tex \
objdir/gdb/doc/refcard.dvi objdir/gdb/doc/refcard.ps
diff -Nru gdb-6.3/gdb/solib.c gdb-6.3.cross/gdb/solib.c
--- gdb-6.3/gdb/solib.c 2004-09-11 12:24:50.000000000 +0200
+++ gdb-6.3.cross/gdb/solib.c 2005-06-13 08:56:50.660726488 +0200
@@ -44,6 +44,7 @@
#include "solist.h"
#include "observer.h"
#include "readline/readline.h"
+#include "version.h"
/* external data declarations */
@@ -69,6 +70,10 @@
and LD_LIBRARY_PATH. */
static char *solib_search_path = NULL;
+/* Directory which should be used as replacement for /usr while searching
+ for cross libraries. */
+static char *solib_crossdir = NULL;
+
/*
GLOBAL FUNCTION
@@ -173,19 +178,23 @@
found_file = TARGET_SO_FIND_AND_OPEN_SOLIB
(in_pathname, O_RDONLY, &temp_pathname);
- /* If not found, next search the inferior's $PATH environment variable. */
- if (found_file < 0 && solib_absolute_prefix == NULL)
- found_file = openp (get_in_environ (inferior_environ, "PATH"),
- OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY, 0,
- &temp_pathname);
-
- /* If not found, next search the inferior's $LD_LIBRARY_PATH
- environment variable. */
- if (found_file < 0 && solib_absolute_prefix == NULL)
- found_file = openp (get_in_environ (inferior_environ, "LD_LIBRARY_PATH"),
- OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY, 0,
- &temp_pathname);
-
+ /* Search PATH and LD_LIBRARY_PATH only for native GDB. */
+ if (strcmp (host_name, target_name) != 0)
+ {
+ /* If not found, next search the inferior's $PATH environment variable. */
+ if (found_file < 0 && solib_absolute_prefix == NULL)
+ found_file = openp (get_in_environ (inferior_environ, "PATH"),
+ OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY, 0,
+ &temp_pathname);
+
+ /* If not found, next search the inferior's $LD_LIBRARY_PATH
+ environment variable. */
+ if (found_file < 0 && solib_absolute_prefix == NULL)
+ found_file = openp (get_in_environ (inferior_environ, "LD_LIBRARY_PATH"),
+ OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY, 0,
+ &temp_pathname);
+ }
+
/* Done. If not found, tough luck. Return found_file and
(optionally) found_pathname. */
if (found_pathname != NULL && temp_pathname != NULL)
@@ -233,7 +242,18 @@
bfd *abfd;
filename = tilde_expand (so->so_name);
-
+ /* Cross development environment. */
+ if (strcmp (host_name, target_name) != 0)
+ {
+ char *libpart_path = NULL;
+ if (IS_ABSOLUTE_PATH (filename) && strncmp (filename, solib_crossdir, strlen (solib_crossdir)) != 0 \
+ && (libpart_path = strstr (filename, "/lib/")))
+ {
+ char *temp_filename = concat (solib_crossdir, libpart_path, NULL);
+ xfree (filename);
+ filename = temp_filename;
+ }
+ }
old_chain = make_cleanup (xfree, filename);
scratch_chan = solib_open (filename, &scratch_pathname);
@@ -917,4 +937,16 @@
deprecated_add_show_from_set (c, &showlist);
set_cmd_cfunc (c, reload_shared_libraries);
set_cmd_completer (c, filename_completer);
+
+ c = add_set_cmd ("solib-crossdir", class_support, var_string,
+ (char *) &solib_crossdir,
+ "Set the base directory for cross libraries. This variable is only active\n\
+if GDB was compiled for debugging foreign architectures.",
+ &setlist);
+ deprecated_add_show_from_set (c, &showlist);
+
+ if (!solib_crossdir && strcmp (host_name, target_name) != 0)
+ {
+ solib_crossdir = concat ("/usr/", target_name, NULL);
+ }
}