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.
This commit is contained in:
Christian Prochaska 2012-07-12 21:25:55 +02:00 committed by Norman Feske
parent dbd1c425bf
commit 1b8fd4aa44
10 changed files with 331 additions and 37 deletions

View File

@ -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

233
ports/run/noux_gdb.run Normal file
View File

@ -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 {
<config verbose="yes">
<parent-provides>
<service name="ROM"/>
<service name="LOG"/>
<service name="CAP"/>
<service name="RAM"/>
<service name="RM"/>
<service name="CPU"/>
<service name="PD"/>
<service name="IRQ"/>
<service name="IO_PORT"/>
<service name="IO_MEM"/>
<service name="SIGNAL"/>
</parent-provides>
<default-route>
<any-service> <any-child/> <parent/> </any-service>
</default-route>
<start name="timer">
<resource name="RAM" quantum="1M"/>
<provides><service name="Timer"/></provides>
</start> }
append_if [have_spec sdl] config {
<start name="fb_sdl">
<resource name="RAM" quantum="4M"/>
<provides>
<service name="Input"/>
<service name="Framebuffer"/>
</provides>
</start>}
append_if [have_spec pci] config {
<start name="pci_drv">
<resource name="RAM" quantum="1M"/>
<provides><service name="PCI"/></provides>
</start>}
append_if [have_spec vesa] config {
<start name="vesa_drv">
<resource name="RAM" quantum="1M"/>
<provides><service name="Framebuffer"/></provides>
</start>}
append_if [have_spec pl11x] config {
<start name="pl11x_drv">
<resource name="RAM" quantum="2M"/>
<provides><service name="Framebuffer"/></provides>
</start>}
append_if [have_spec ps2] config {
<start name="ps2_drv">
<resource name="RAM" quantum="1M"/>
<provides><service name="Input"/></provides>
</start> }
append config {
<start name="terminal_noux">
<binary name="terminal"/>
<resource name="RAM" quantum="2M"/>
<provides><service name="Terminal"/></provides>
<config>
<keyboard layout="de"/>
</config>
</start>
<start name="terminal_gdb">
<binary name="terminal_crosslink"/>
<resource name="RAM" quantum="1M"/>
<provides> <service name="Terminal"/> </provides>
</start>
<start name="gdb_monitor">
<resource name="RAM" quantum="10M"/>
<route>
<service name="Terminal"><child name="terminal_gdb"/></service>
<any-service><parent/><any-child/></any-service>
</route>
<config>
<target name="test-gdb_monitor"/>
<preserve name="RAM" quantum="5M"/>
</config>
</start>
<start name="ram_fs">
<resource name="RAM" quantum="10M"/>
<provides><service name="File_system"/></provides>
<config>
<content>
<dir name="gdb">
<inline name="commands">
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
</inline>
</dir>
</content>
<!-- constrain sessions according to their labels -->
<policy label="noux -> gdb" root="/gdb" />
</config>
</start>
<start name="noux">
<resource name="RAM" quantum="1G"/>
<route>
<service name="Terminal">
<if-arg key="label" value="noux"/><child name="terminal_noux"/>
</service>
<service name="Terminal">
<if-arg key="label" value="noux -> noux(terminal_fs)"/><child name="terminal_gdb"/>
</service>
<any-service><parent/><any-child/></any-service>
</route>
<config>
<fstab>
<tar name="gdb.tar" at="/"/>
<dir name="dev"><terminal name="gdb"/></dir>
<dir name="gdb">
<tar name="test-gdb_monitor.tar"/>
<fs label="gdb"/>
<dir name="src"> <tar name="test-gdb_monitor-src.tar"/> </dir>
</dir>
</fstab> }
append config "
<start name=\"/bin/${tool_prefix}gdb\"> "
append config {
<arg value="/gdb/test-gdb_monitor"/>
<arg value="-x" /><arg value="/gdb/commands" />
</start>
</config>
</start>
</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

View File

@ -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 <http://www.gnu.org/licenses/>. */
+#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

View File

@ -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 \

View File

@ -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
;;

View File

@ -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

View File

@ -0,0 +1,4 @@
PROGRAM_PREFIX = genode-arm-
GDB_TARGET = arm-elf-eabi
include $(PRG_DIR)/../gdb/target.inc

View File

@ -0,0 +1,4 @@
PROGRAM_PREFIX = genode-x86-
GDB_TARGET = x86_64-elf
include $(PRG_DIR)/../gdb/target.inc

View File

@ -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)"

23
tool/tool_chain_gdb_patches.inc Executable file
View File

@ -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