From 1b8fd4aa44d46b5c301a9a373de39f0fe61fe038 Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Thu, 12 Jul 2012 21:25:55 +0200 Subject: [PATCH] GDB for Noux With this patch the 'GNU Project Debugger' (GDB) can be built for Noux. The included run script connects GDB and GDB monitor via a cross-link terminal and allows interactive source-level debugging of the GDB monitor test application on Genode. Fixes #280. --- ports/ports/gdb.mk | 12 +- ports/run/noux_gdb.run | 233 ++++++++++++++++++ .../app/gdb_monitor/gdbserver_genode.patch | 12 - ports/src/app/gdb_monitor/target.mk | 2 + ports/src/noux-pkg/gdb/build.patch | 40 +++ ports/src/noux-pkg/gdb/target.inc | 12 + ports/src/noux-pkg/gdb_arm/target.mk | 4 + ports/src/noux-pkg/gdb_x86/target.mk | 4 + tool/tool_chain | 26 +- tool/tool_chain_gdb_patches.inc | 23 ++ 10 files changed, 331 insertions(+), 37 deletions(-) create mode 100644 ports/run/noux_gdb.run create mode 100644 ports/src/noux-pkg/gdb/build.patch create mode 100644 ports/src/noux-pkg/gdb/target.inc create mode 100644 ports/src/noux-pkg/gdb_arm/target.mk create mode 100644 ports/src/noux-pkg/gdb_x86/target.mk create mode 100755 tool/tool_chain_gdb_patches.inc diff --git a/ports/ports/gdb.mk b/ports/ports/gdb.mk index db4fba11e..97f1b934f 100644 --- a/ports/ports/gdb.mk +++ b/ports/ports/gdb.mk @@ -43,7 +43,7 @@ GDB_CONTENT := gdb/regformats/regdat.sh \ # PORTS += $(GDB) -prepare:: $(CONTRIB_DIR)/$(GDB) generated_files +prepare:: $(CONTRIB_DIR)/$(GDB)/configure generated_files # # Port-specific local rules @@ -53,8 +53,16 @@ $(DOWNLOAD_DIR)/$(GDB_TBZ2): $(VERBOSE)wget -c -P $(DOWNLOAD_DIR) $(GDB_URL)/$(GDB_TBZ2) && touch $@ $(CONTRIB_DIR)/$(GDB): $(DOWNLOAD_DIR)/$(GDB_TBZ2) - $(VERBOSE)tar xfj $< -C $(CONTRIB_DIR) $(addprefix $(GDB)/,$(GDB_CONTENT)) + $(VERBOSE)tar xfj $< -C $(CONTRIB_DIR) + +include ../tool/tool_chain_gdb_patches.inc + +$(CONTRIB_DIR)/$(GDB)/configure:: $(CONTRIB_DIR)/$(GDB) + @# + @# Genode-specific changes + @# $(VERBOSE)patch -N -p1 -d $(CONTRIB_DIR)/$(GDB) < src/app/gdb_monitor/gdbserver_genode.patch + $(VERBOSE)patch -N -p1 -d $(CONTRIB_DIR)/$(GDB) < src/noux-pkg/gdb/build.patch GENERATED_DIR := src/lib/gdbserver_platform/generated diff --git a/ports/run/noux_gdb.run b/ports/run/noux_gdb.run new file mode 100644 index 000000000..cb29e18c1 --- /dev/null +++ b/ports/run/noux_gdb.run @@ -0,0 +1,233 @@ +if {![have_spec foc] || ![have_spec 32bit]} { + puts "\nThe Noux GDB scenario is supported on 32-bit Fiasco.OC only\n" + exit 0 +} + +if {[have_spec arm]} { + set gdb "gdb_arm" + set tool_prefix "genode-arm-" +} + +if {[have_spec x86]} { + set gdb "gdb_x86" + set tool_prefix "genode-x86-" +} + +# +# Uncomment the following line when working on the GDB source code. Otherwise, +# the package may get recompiled, yet it does not get reinstalled into 'bin/'. +# +#exec rm -rf noux-pkg/$gdb/ bin/$gdb/ + +set build_components { + core init drivers/timer noux lib/libc_noux + drivers/framebuffer drivers/pci drivers/input + server/terminal server/terminal_crosslink + server/ram_fs app/gdb_monitor + test/gdb_monitor +} +lappend build_components noux-pkg/$gdb + +build $build_components + +# tar archive for GDB + +exec sh -c "find bin/$gdb/ -type f | (xargs [cross_dev_prefix]strip || true) 2>/dev/null" +exec tar cfhv bin/gdb.tar -C bin/$gdb . + +# names of the binaries needed for the GDB monitor test + +set test_binaries { + test-gdb_monitor + ld.lib.so + libc.lib.so + libc_log.lib.so +} + +# tar archive for the unstripped binaries of the GDB monitor test + +foreach test_binary $test_binaries { + exec tar ufv bin/test-gdb_monitor.tar -h -C bin $test_binary +} + +# tar archive for the source code of the GDB monitor test + +foreach test_binary $test_binaries { + set source_files [ exec [cross_dev_prefix]objdump -dl bin/$test_binary | grep "^/.*:.*" | sed -e "s/:.*//" | uniq ] + foreach source_file $source_files { + if [file exists $source_file] { exec tar ufvhP bin/test-gdb_monitor-src.tar $source_file } + } +} + +create_boot_directory + +append config { + + + + + + + + + + + + + + + + + + + + + } + +append_if [have_spec sdl] config { + + + + + + + } + +append_if [have_spec pci] config { + + + + } + +append_if [have_spec vesa] config { + + + + } + +append_if [have_spec pl11x] config { + + + + } + +append_if [have_spec ps2] config { + + + + } + +append config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + set interactive-mode off + directory /gdb/src + target remote /dev/gdb + symbol-file /gdb/ld.lib.so + b call_main + c + delete 1 + symbol-file /gdb/test-gdb_monitor + b main + set solib-search-path /gdb + sharedlibrary + c + delete 2 + set interactive-mode auto + + + + + + + + + + + + + + + + + + + + + + + + + + + + } +append config " + " +append config { + + + + + + +} + +install_config $config + + +# +# Boot modules +# + +# generic modules +set boot_modules { + core init timer ld.lib.so noux terminal terminal_crosslink + libc.lib.so libm.lib.so libc_noux.lib.so ncurses.lib.so expat.lib.so + libc_lock_pipe.lib.so libc_log.lib.so libc_terminal.lib.so + ram_fs gdb_monitor test-gdb_monitor + gdb.tar test-gdb_monitor.tar test-gdb_monitor-src.tar +} + +# platform-specific modules +lappend_if [have_spec linux] boot_modules fb_sdl +lappend_if [have_spec pci] boot_modules pci_drv +lappend_if [have_spec vesa] boot_modules vesa_drv +lappend_if [have_spec ps2] boot_modules ps2_drv +lappend_if [have_spec pl11x] boot_modules pl11x_drv + +build_boot_image $boot_modules + +run_genode_until forever + +exec rm bin/gdb.tar diff --git a/ports/src/app/gdb_monitor/gdbserver_genode.patch b/ports/src/app/gdb_monitor/gdbserver_genode.patch index 8c3d9d764..adc00a314 100644 --- a/ports/src/app/gdb_monitor/gdbserver_genode.patch +++ b/ports/src/app/gdb_monitor/gdbserver_genode.patch @@ -1,17 +1,5 @@ - Genode-specific changes of gdbserver files -diff --git a/gdb/common/signals.c b/gdb/common/signals.c ---- a/gdb/common/signals.c -+++ b/gdb/common/signals.c -@@ -19,6 +19,8 @@ - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -+#define GDBSERVER -+ - #ifdef GDBSERVER - #include "server.h" - #else diff --git a/gdb/gdbserver/linux-arm-low.c b/gdb/gdbserver/linux-arm-low.c --- a/gdb/gdbserver/linux-arm-low.c +++ b/gdb/gdbserver/linux-arm-low.c diff --git a/ports/src/app/gdb_monitor/target.mk b/ports/src/app/gdb_monitor/target.mk index e39ca06a0..de5128f74 100644 --- a/ports/src/app/gdb_monitor/target.mk +++ b/ports/src/app/gdb_monitor/target.mk @@ -27,6 +27,8 @@ SRC_C = event-loop.c \ SRC_C += linux-low.c +CC_OPT += -DGDBSERVER + CC_OPT_linux-low += -Wno-unused-function SRC_CC = genode-low.cc \ diff --git a/ports/src/noux-pkg/gdb/build.patch b/ports/src/noux-pkg/gdb/build.patch new file mode 100644 index 000000000..4018c734c --- /dev/null +++ b/ports/src/noux-pkg/gdb/build.patch @@ -0,0 +1,40 @@ +diff --git a/gdb/configure b/gdb/configure +--- a/gdb/configure ++++ b/gdb/configure +@@ -7917,11 +7917,11 @@ + # configuration. + gdb_host_obs=posix-hdep.o + +-if test "${target}" = "${host}"; then +- gdb_native=yes +-else ++#if test "${target}" = "${host}"; then ++# gdb_native=yes ++#else + gdb_native=no +-fi ++#fi + + . $srcdir/configure.host + +@@ -12919,7 +12919,7 @@ + return 0; + } + _ACEOF +-if ac_fn_c_try_compile "$LINENO"; then : ++if ac_fn_c_try_link "$LINENO"; then : + gdb_cv_func_sigsetjmp=yes + else + gdb_cv_func_sigsetjmp=no +diff --git a/missing b/missing +--- a/missing ++++ b/missing +@@ -314,7 +314,7 @@ + fi + # If the file does not exist, the user really needs makeinfo; + # let's fail without touching anything. +- test -f $file || exit 1 ++ #test -f $file || exit 1 + touch $file + ;; + diff --git a/ports/src/noux-pkg/gdb/target.inc b/ports/src/noux-pkg/gdb/target.inc new file mode 100644 index 000000000..df48362e0 --- /dev/null +++ b/ports/src/noux-pkg/gdb/target.inc @@ -0,0 +1,12 @@ +NOUX_CONFIGURE_ARGS += --program-prefix=$(PROGRAM_PREFIX) \ + --target=$(GDB_TARGET) + +# the configure script calls the linker with "-lexpat", which fails +NOUX_CONFIGURE_ARGS += --without-expat +NOUX_CFLAGS += -DHAVE_LIBEXPAT=1 + +LIBS += ncurses expat + +NOUX_PKG_DIR = $(wildcard $(REP_DIR)/contrib/gdb-*) + +include $(REP_DIR)/mk/noux.mk diff --git a/ports/src/noux-pkg/gdb_arm/target.mk b/ports/src/noux-pkg/gdb_arm/target.mk new file mode 100644 index 000000000..8a6be5e24 --- /dev/null +++ b/ports/src/noux-pkg/gdb_arm/target.mk @@ -0,0 +1,4 @@ +PROGRAM_PREFIX = genode-arm- +GDB_TARGET = arm-elf-eabi + +include $(PRG_DIR)/../gdb/target.inc diff --git a/ports/src/noux-pkg/gdb_x86/target.mk b/ports/src/noux-pkg/gdb_x86/target.mk new file mode 100644 index 000000000..2bc6b2859 --- /dev/null +++ b/ports/src/noux-pkg/gdb_x86/target.mk @@ -0,0 +1,4 @@ +PROGRAM_PREFIX = genode-x86- +GDB_TARGET = x86_64-elf + +include $(PRG_DIR)/../gdb/target.inc diff --git a/tool/tool_chain b/tool/tool_chain index bf0b7e053..e6a6a6436 100755 --- a/tool/tool_chain +++ b/tool/tool_chain @@ -440,32 +440,12 @@ $(DOWNLOAD_DIR)/gdb-$(GDB_VERSION).tar.bz2: $(DOWNLOAD_DIR) $(ECHO) "$(BRIGHT_COL)downloading gdb...$(DEFAULT_COL)" $(VERBOSE)wget -c -P $(DOWNLOAD_DIR) $(GDB_DOWNLOAD_URL)/gdb-$(GDB_VERSION).tar.bz2 && touch $@ -$(CONTRIB_DIR)/gdb-$(GDB_VERSION)/configure: $(DOWNLOAD_DIR)/gdb-$(GDB_VERSION).tar.bz2 +$(CONTRIB_DIR)/gdb-$(GDB_VERSION): $(DOWNLOAD_DIR)/gdb-$(GDB_VERSION).tar.bz2 $(ECHO) "$(BRIGHT_COL)unpacking gdb...$(DEFAULT_COL)" $(VERBOSE)mkdir -p $(CONTRIB_DIR) $(VERBOSE)tar xfj $^ -C $(CONTRIB_DIR) && touch $@ - $(ECHO) "$(BRIGHT_COL)patching gdb...$(DEFAULT_COL)" - @# - @# Include 'solib.o' and 'solib-svr4.o' in arm*-*-* (non-OS) target configuration for shared library support - @# - $(VERBOSE)sed -i "s/gdb_target_obs=\"arm-tdep\.o\"$$/gdb_target_obs=\"arm-tdep.o solib.o solib-svr4.o\"/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/configure.tgt - @# - @# Add an x86_64-*-* (non-OS) target with shared library support - @# - $(VERBOSE)sed -i "/^xtensa\*-\*-linux\*/ s/^/x86_64-*-*)\n\tgdb_target_obs=\"amd64-tdep.o i386-tdep.o i387-tdep.o solib.o solib-svr4.o\"\n\t;;\n/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/configure.tgt - @# - @# Enable shared library support - @# - $(VERBOSE)sed -i "/^#include \"features\/i386\/amd64-avx\.c\"$$/ s/$$/\n\n#include \"solib-svr4\.h\"/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/amd64-tdep.c - $(VERBOSE)sed -i "/AMD64 generally uses/ s/^/ set_solib_svr4_fetch_link_map_offsets(gdbarch, svr4_lp64_fetch_link_map_offsets);\n\n/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/amd64-tdep.c - $(VERBOSE)sed -i "/^#include \"features\/arm-with-m\.c\"$$/ s/$$/\n\n#include \"solib-svr4\.h\"/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/arm-tdep.c - $(VERBOSE)sed -i "/gdbarch = gdbarch_alloc (&info, tdep);/ s/$$/\n\n set_solib_svr4_fetch_link_map_offsets(gdbarch, svr4_ilp32_fetch_link_map_offsets);/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/arm-tdep.c - $(VERBOSE)sed -i "/^#include \"features\/i386\/i386-mmx\.c\"$$/ s/$$/\n\n#include \"solib-svr4\.h\"/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/i386-tdep.c - $(VERBOSE)sed -i "/gdbarch = gdbarch_alloc (&info, tdep);/ s/$$/\n\n set_solib_svr4_fetch_link_map_offsets(gdbarch, svr4_ilp32_fetch_link_map_offsets);/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/i386-tdep.c - @# - @# Enable software single-stepping on ARM - @# - $(VERBOSE)sed -i "/gdbarch = gdbarch_alloc (&info, tdep);/ s/$$/\n\n set_gdbarch_software_single_step(gdbarch, arm_software_single_step);/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/arm-tdep.c + +include $(GENODE_DIR)/tool/tool_chain_gdb_patches.inc build/$(PLATFORM)/gdb/Makefile: $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/configure $(ECHO) "$(BRIGHT_COL)configuring gdb...$(DEFAULT_COL)" diff --git a/tool/tool_chain_gdb_patches.inc b/tool/tool_chain_gdb_patches.inc new file mode 100755 index 000000000..d17f47fb7 --- /dev/null +++ b/tool/tool_chain_gdb_patches.inc @@ -0,0 +1,23 @@ +$(CONTRIB_DIR)/gdb-$(GDB_VERSION)/configure:: $(CONTRIB_DIR)/gdb-$(GDB_VERSION) + $(ECHO) "$(BRIGHT_COL)patching gdb...$(DEFAULT_COL)" + @# + @# Include 'solib.o' and 'solib-svr4.o' in arm*-*-* (non-OS) target configuration for shared library support + @# + $(VERBOSE)sed -i "s/gdb_target_obs=\"arm-tdep\.o\"$$/gdb_target_obs=\"arm-tdep.o solib.o solib-svr4.o\"/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/configure.tgt + @# + @# Add an x86_64-*-* (non-OS) target with shared library support + @# + $(VERBOSE)sed -i "/^xtensa\*-\*-linux\*/ s/^/x86_64-*-*)\n\tgdb_target_obs=\"amd64-tdep.o i386-tdep.o i387-tdep.o solib.o solib-svr4.o\"\n\t;;\n/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/configure.tgt + @# + @# Enable shared library support + @# + $(VERBOSE)sed -i "/^#include \"features\/i386\/amd64-avx\.c\"$$/ s/$$/\n\n#include \"solib-svr4\.h\"/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/amd64-tdep.c + $(VERBOSE)sed -i "/AMD64 generally uses/ s/^/ set_solib_svr4_fetch_link_map_offsets(gdbarch, svr4_lp64_fetch_link_map_offsets);\n\n/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/amd64-tdep.c + $(VERBOSE)sed -i "/^#include \"features\/arm-with-m\.c\"$$/ s/$$/\n\n#include \"solib-svr4\.h\"/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/arm-tdep.c + $(VERBOSE)sed -i "/gdbarch = gdbarch_alloc (&info, tdep);/ s/$$/\n\n set_solib_svr4_fetch_link_map_offsets(gdbarch, svr4_ilp32_fetch_link_map_offsets);/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/arm-tdep.c + $(VERBOSE)sed -i "/^#include \"features\/i386\/i386-mmx\.c\"$$/ s/$$/\n\n#include \"solib-svr4\.h\"/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/i386-tdep.c + $(VERBOSE)sed -i "/gdbarch = gdbarch_alloc (&info, tdep);/ s/$$/\n\n set_solib_svr4_fetch_link_map_offsets(gdbarch, svr4_ilp32_fetch_link_map_offsets);/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/i386-tdep.c + @# + @# Enable software single-stepping on ARM + @# + $(VERBOSE)sed -i "/gdbarch = gdbarch_alloc (&info, tdep);/ s/$$/\n\n set_gdbarch_software_single_step(gdbarch, arm_software_single_step);/" $(CONTRIB_DIR)/gdb-$(GDB_VERSION)/gdb/arm-tdep.c