From be339f2fdb18efcfdd41e932e9d2e8dd62392bb6 Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Mon, 21 Sep 2020 11:17:02 -0700 Subject: [PATCH] gdb: additional upstream patch to aslr support. Caused an error when trying to change the program from within GDB. Fixes #7004 --- mingw-w64-gdb/PKGBUILD | 9 ++-- mingw-w64-gdb/gdb-windows-aslr-2.patch | 59 ++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 mingw-w64-gdb/gdb-windows-aslr-2.patch diff --git a/mingw-w64-gdb/PKGBUILD b/mingw-w64-gdb/PKGBUILD index 3b95e7ea11..7bb1f42f09 100644 --- a/mingw-w64-gdb/PKGBUILD +++ b/mingw-w64-gdb/PKGBUILD @@ -5,7 +5,7 @@ _realname=gdb pkgbase=mingw-w64-${_realname} pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}" pkgver=9.2 -pkgrel=2 +pkgrel=3 pkgdesc="GNU Debugger (mingw-w64)" arch=('any') url="https://www.gnu.org/software/gdb/" @@ -30,7 +30,8 @@ source=(https://ftp.gnu.org/gnu/gdb/${_realname}-${pkgver}.tar.xz{,.sig} 'gdb-fix-tui-with-pdcurses.patch' 'gdb-9.1-lib-order.patch' 'gdb-home-is-userprofile.patch' - 'gdb-windows-aslr.patch') + 'gdb-windows-aslr.patch' + 'gdb-windows-aslr-2.patch') validpgpkeys=('F40ADB902B24264AA42E50BF92EDB04BFF325CF3') sha256sums=('360cd7ae79b776988e89d8f9a01c985d0b1fa21c767a4295e5f88cb49175c555' 'SKIP' @@ -41,7 +42,8 @@ sha256sums=('360cd7ae79b776988e89d8f9a01c985d0b1fa21c767a4295e5f88cb49175c555' 'f70cc0a0633d01adf777eb57a82f8c9880f6511d55e44c1dc415ddebc7467e0b' 'dcfbfb2e3fc90a51e11202529e34c1b3dcc17e352067ffdfc58b63c1deab9523' 'a63ba094dcd9bf0c0f98c6dce5825590b2cf7014834fd3bec5f88fe25d90228a' - '7c40bd442dcd4eb32310b1b6979a96fd41253f4b3128ad0fac2f8ebff132666b') + '7c40bd442dcd4eb32310b1b6979a96fd41253f4b3128ad0fac2f8ebff132666b' + '394a041e799e9e0ac04e1a2f7455ec3567f1233059ed1432ac57174f23cc8026') prepare() { cd ${srcdir}/${_realname}-${pkgver} @@ -62,6 +64,7 @@ prepare() { # https://sourceware.org/bugzilla/show_bug.cgi?id=26037 patch -p1 -i ${srcdir}/gdb-windows-aslr.patch + patch -p1 -i ${srcdir}/gdb-windows-aslr-2.patch # hack! - libiberty configure tests for header files using "$CPP $CPPFLAGS" sed -i "/ac_cpp=/s/\$CPPFLAGS/\$CPPFLAGS -O2/" libiberty/configure diff --git a/mingw-w64-gdb/gdb-windows-aslr-2.patch b/mingw-w64-gdb/gdb-windows-aslr-2.patch new file mode 100644 index 0000000000..2191d642d3 --- /dev/null +++ b/mingw-w64-gdb/gdb-windows-aslr-2.patch @@ -0,0 +1,59 @@ +From f6a460383f213f6f42dbc534bdb0fef4ef1dc823 Mon Sep 17 00:00:00 2001 +From: Hannes Domani +Date: Wed, 4 Mar 2020 21:20:31 +0100 +Subject: [PATCH 2/2] Don't try to get the TIB address without an inferior + +The target_get_tib_address call always fails in this case, and there is an +error when changing the program with the file command: + +(gdb) file allocer64.exe +Reading symbols from allocer64.exe... +You can't do that when your target is `exec' + +Now it will skip this part, there is no need to rebase the executable without +an inferior anyways. + +gdb/ChangeLog: + +2020-03-06 Hannes Domani + + * windows-tdep.c (windows_solib_create_inferior_hook): + Check if inferior is running. +--- + gdb/ChangeLog | 5 +++++ + gdb/windows-tdep.c | 3 ++- + 2 files changed, 7 insertions(+), 1 deletion(-) + +diff --git a/gdb/ChangeLog b/gdb/ChangeLog +index ca700fbab5..4e824abcaa 100644 +--- a/gdb/ChangeLog ++++ b/gdb/ChangeLog +@@ -30,6 +30,11 @@ + PR symtab/26003 + * symfile.c (symbol_file_add_separate): Preserve OBJF_MAINLINE. + ++2020-03-06 Hannes Domani ++ ++ * windows-tdep.c (windows_solib_create_inferior_hook): ++ Check if inferior is running. ++ + 2020-03-03 Hannes Domani + + * windows-tdep.c (windows_solib_create_inferior_hook): New function. +diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c +index a07c00b2f1..887654f29d 100644 +--- a/gdb/windows-tdep.c ++++ b/gdb/windows-tdep.c +@@ -492,7 +492,8 @@ windows_solib_create_inferior_hook (int from_tty) + } + CORE_ADDR tlb; + gdb_byte buf[8]; +- if (target_get_tib_address (inferior_ptid, &tlb) ++ if (target_has_execution ++ && target_get_tib_address (inferior_ptid, &tlb) + && !target_read_memory (tlb + peb_offset, buf, ptr_bytes)) + { + CORE_ADDR peb = extract_unsigned_integer (buf, ptr_bytes, byte_order); +-- +2.28.0.windows.1 +