Date: Sat, 1 Jun 2019 00:44:08 +0000 (UTC) From: John Baldwin <jhb@FreeBSD.org> To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r503200 - in head/devel/gdb: . files files/kgdb Message-ID: <201906010044.x510i80Z087786@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jhb (src,doc committer) Date: Sat Jun 1 00:44:08 2019 New Revision: 503200 URL: https://svnweb.freebsd.org/changeset/ports/503200 Log: Update port to GDB 8.3. New features in GDB 8.3 include support for DWARF index caches and styling (colors) in the CLI and TUI. Source code styling is also available via the new SOURCE_HIGHLIGHT option (enabled by default). GDB 8.3 also adds support for FreeBSD/riscv64. In addition, kgdb has been updated for changes in 8.3 along with support for FreeBSD/riscv64 kernels. The libc++ helpers have been updated to a newer version which adds support for std::list<> and std::forward_list<>. The helpers now also support Python 3. Finally, a few post-8.3 patches have been backported which add suport for TLS (Thread Local Storage) variables on FreeBSD amd64, i386, powerpc, and riscv architectures. Note that amd64 and i386 do not support examining TLS variables in core dumps currently. This support along with support for additional architectures require kernel changes and will be added in the future once the kernel has been updated. Reviewed by: pizzamig (maintainer) Differential Revision: https://reviews.freebsd.org/D20403 Added: head/devel/gdb/files/commit-1163a4b7a3 (contents, props changed) head/devel/gdb/files/commit-36c53a0262 (contents, props changed) head/devel/gdb/files/commit-6e056c8178 (contents, props changed) head/devel/gdb/files/commit-8399425f5f (contents, props changed) head/devel/gdb/files/commit-945f3901b5 (contents, props changed) head/devel/gdb/files/commit-b0f87ed032 (contents, props changed) head/devel/gdb/files/commit-cd250a1898 (contents, props changed) head/devel/gdb/files/commit-ce25aa57a3 (contents, props changed) head/devel/gdb/files/commit-dd6876c91c (contents, props changed) head/devel/gdb/files/commit-df22c1e5d5 (contents, props changed) head/devel/gdb/files/commit-ef0bd2046f (contents, props changed) head/devel/gdb/files/commit-f5424cfa7e (contents, props changed) head/devel/gdb/files/kgdb/riscv-fbsd-kern.c (contents, props changed) Deleted: head/devel/gdb/files/commit-2861ee4fde head/devel/gdb/files/commit-8aa0243d54 head/devel/gdb/files/commit-93579f6f90 head/devel/gdb/files/patch-gdb_aarch64-fbsd-tdep.c head/devel/gdb/files/patch-gdb_aarch64-linux-tdep.c head/devel/gdb/files/patch-gdb_aarch64-tdep.c head/devel/gdb/files/patch-gdb_alpha-tdep.c head/devel/gdb/files/patch-gdb_arch_arm-get-next-pcs.c head/devel/gdb/files/patch-gdb_arm-fbsd-tdep.c head/devel/gdb/files/patch-gdb_arm-linux-tdep.c head/devel/gdb/files/patch-gdb_arm-obsd-tdep.c head/devel/gdb/files/patch-gdb_bfin-linux-tdep.c head/devel/gdb/files/patch-gdb_completer.c head/devel/gdb/files/patch-gdb_hppa-nbsd-tdep.c head/devel/gdb/files/patch-gdb_i386-nbsd-tdep.c head/devel/gdb/files/patch-gdb_linespec.c head/devel/gdb/files/patch-gdb_microblaze-linux-tdep.c head/devel/gdb/files/patch-gdb_mips-fbsd-tdep.c head/devel/gdb/files/patch-gdb_mips-linux-tdep.c head/devel/gdb/files/patch-gdb_mips-tdep.c head/devel/gdb/files/patch-gdb_mips64-obsd-tdep.c head/devel/gdb/files/patch-gdb_mn10300-linux-tdep.c head/devel/gdb/files/patch-gdb_nios2-linux-tdep.c head/devel/gdb/files/patch-gdb_ppc-linux-tdep.c head/devel/gdb/files/patch-gdb_ppc-nbsd-tdep.c head/devel/gdb/files/patch-gdb_ppc64-tdep.c head/devel/gdb/files/patch-gdb_rs6000-tdep.c head/devel/gdb/files/patch-gdb_sparc-linux-tdep.c head/devel/gdb/files/patch-gdb_sparc64-linux-tdep.c head/devel/gdb/files/patch-gdb_tick6x-linux-tdep.c head/devel/gdb/files/patch-gdb_tilegx-linux-tdep.c head/devel/gdb/files/patch-gdb_tramp-frame.h head/devel/gdb/files/patch-gdb_xtensa-tdep.h Modified: head/devel/gdb/Makefile head/devel/gdb/distinfo head/devel/gdb/files/extrapatch-kgdb head/devel/gdb/files/kgdb/aarch64-fbsd-kern.c head/devel/gdb/files/kgdb/amd64fbsd-kern.c head/devel/gdb/files/kgdb/fbsd-kld.c head/devel/gdb/files/kgdb/fbsd-kthr.c head/devel/gdb/files/kgdb/fbsd-kvm.c head/devel/gdb/files/kgdb/mipsfbsd-kern.c head/devel/gdb/files/kgdb/ppcfbsd-kern.c head/devel/gdb/files/patch-fixes head/devel/gdb/files/patch-gdb_configure head/devel/gdb/files/patch-gdb_fbsd-nat.c Modified: head/devel/gdb/Makefile ============================================================================== --- head/devel/gdb/Makefile Fri May 31 23:22:49 2019 (r503199) +++ head/devel/gdb/Makefile Sat Jun 1 00:44:08 2019 (r503200) @@ -2,8 +2,8 @@ # $FreeBSD$ PORTNAME= gdb -PORTVERSION= 8.2.1 -PORTREVISION= 3 +PORTVERSION= 8.3 +PORTREVISION= 0 CATEGORIES= devel MASTER_SITES= GNU @@ -14,12 +14,12 @@ LICENSE= GPLv3 LICENSE_FILE= ${WRKSRC}/COPYING3 # untested on sparc64, might work -ONLY_FOR_ARCHS= aarch64 amd64 armv6 armv7 i386 mips powerpc powerpc64 +NOT_FOR_ARCHS= sparc64 LIB_DEPENDS= libmpfr.so:math/mpfr TEST_DEPENDS= runtest:misc/dejagnu -USES= compiler:c++11-lang cpe gmake libtool tar:xz +USES= compiler:c++11-lang cpe gmake libtool pkgconfig tar:xz USE_PYTHON= flavors py3kplist TEST_TARGET= check @@ -39,17 +39,24 @@ CFLAGS+= -DRL_NO_COMPAT -Wno-unused-function -Wno-unus CFLAGS+= -Wno-unknown-warning-option EXCLUDE= dejagnu expect sim texinfo intl EXTRACT_AFTER_ARGS= ${EXCLUDE:S/^/--exclude /} -EXTRA_PATCHES= ${FILESDIR}/commit-8aa0243d54 \ - ${FILESDIR}/commit-93579f6f90 \ - ${FILESDIR}/commit-2861ee4fde +EXTRA_PATCHES= ${FILESDIR}/commit-1163a4b7a3 \ + ${FILESDIR}/commit-dd6876c91c \ + ${FILESDIR}/commit-6e056c8178 \ + ${FILESDIR}/commit-36c53a0262 \ + ${FILESDIR}/commit-ef0bd2046f \ + ${FILESDIR}/commit-945f3901b5 \ + ${FILESDIR}/commit-f5424cfa7e \ + ${FILESDIR}/commit-ce25aa57a3 \ + ${FILESDIR}/commit-8399425f5f LIB_DEPENDS+= libexpat.so:textproc/expat2 VER= ${PORTVERSION:S/.//g} PLIST_SUB= VER=${VER} -OPTIONS_DEFINE= DEBUG GDB_LINK GUILE KGDB NLS PYTHON TUI +OPTIONS_DEFINE= DEBUG GDB_LINK GUILE KGDB NLS PYTHON SOURCE_HIGHLIGHT TUI -OPTIONS_DEFAULT= GDB_LINK KGDB NLS PYTHON TUI PORT_READLINE PORT_ICONV SYSTEM_ZLIB +OPTIONS_DEFAULT= GDB_LINK KGDB NLS PYTHON SOURCE_HIGHLIGHT TUI +OPTIONS_DEFAULT+= PORT_READLINE PORT_ICONV SYSTEM_ZLIB OPTIONS_SINGLE= READLINE ICONV ZLIB OPTIONS_SINGLE_READLINE= BUNDLED_READLINE PORT_READLINE @@ -62,6 +69,7 @@ BUNDLED_READLINE_DESC= from gdb distfile BUNDLED_ZLIB_DESC= from gdb distfile PORT_READLINE_DESC= from devel/readline port PORT_ICONV_DESC= use libiconv, with wider charset support +SOURCE_HIGHLIGHT_DESC= Source Code Styling SYSTEM_ICONV_DESC= use libc iconv, with no wchar support SYSTEM_ZLIB_DESC= use system zlib TUI_DESC= Text User Interface enabled @@ -79,6 +87,9 @@ PORT_ICONV_USES= iconv:wchar_t PYTHON_CONFIGURE_ON= --with-python=${PYTHON_CMD} PYTHON_CONFIGURE_OFF= --without-python PYTHON_USES= python +SOURCE_HIGHLIGHT_WITH= source-highlight +SOURCE_HIGHLIGHT_LIB_DEPENDS= \ + libsource-highlight.so:textproc/source-highlight SYSTEM_ICONV_USES= iconv SYSTEM_ZLIB_WITH= system-zlib TUI_CONFIGURE_ENABLE= tui @@ -96,7 +107,7 @@ USE_GITHUB= nodefault GH_ACCOUNT= bsdjhb:libcxx GH_PROJECT= libcxx-gdbpy:libcxx -GH_TAGNAME= 99aae0c:libcxx +GH_TAGNAME= 229610a:libcxx # Workaround USE_GITHUB preventing the default DISTFILES DISTFILES= ${DISTNAME}${EXTRACT_SUFX} Modified: head/devel/gdb/distinfo ============================================================================== --- head/devel/gdb/distinfo Fri May 31 23:22:49 2019 (r503199) +++ head/devel/gdb/distinfo Sat Jun 1 00:44:08 2019 (r503200) @@ -1,5 +1,5 @@ -TIMESTAMP = 1550011043 -SHA256 (gdb-8.2.1.tar.xz) = 0a6a432907a03c5c8eaad3c3cffd50c00a40c3a5e3c4039440624bae703f2202 -SIZE (gdb-8.2.1.tar.xz) = 20170388 -SHA256 (bsdjhb-libcxx-gdbpy-99aae0c_GH0.tar.gz) = 101425f8041489e31370ddd5938b41541b88a2e1051da70fe12d37c9186aa7eb -SIZE (bsdjhb-libcxx-gdbpy-99aae0c_GH0.tar.gz) = 4607 +TIMESTAMP = 1559324758 +SHA256 (gdb-8.3.tar.xz) = 802f7ee309dcc547d65a68d61ebd6526762d26c3051f52caebe2189ac1ffd72e +SIZE (gdb-8.3.tar.xz) = 20490300 +SHA256 (bsdjhb-libcxx-gdbpy-229610a_GH0.tar.gz) = d4235f98b71c4d5e3f01744de279e64808229dd46c0f00cac6a12fdeb3a998a1 +SIZE (bsdjhb-libcxx-gdbpy-229610a_GH0.tar.gz) = 5299 Added: head/devel/gdb/files/commit-1163a4b7a3 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/devel/gdb/files/commit-1163a4b7a3 Sat Jun 1 00:44:08 2019 (r503200) @@ -0,0 +1,419 @@ +commit 1163a4b7a38a79ebd153dc5ee76ce93877d21dbd +Author: John Baldwin <jhb@FreeBSD.org> +Date: Tue Mar 12 13:39:02 2019 -0700 + + Support the fs_base and gs_base registers on i386. + + As on amd64, these registers hold the base address of the fs and gs + segments, respectively. For i386 these two registers are 32 bits. + + gdb/ChangeLog: + + * amd64-fbsd-nat.c (amd64_fbsd_nat_target::read_description): + Update calls to i386_target_description to add 'segments' + parameter. + * amd64-tdep.c (amd64_init_abi): Set tdep->fsbase_regnum. Don't + add segment base registers. + * arch/i386.c (i386_create_target_description): Add 'segments' + parameter to enable segment base registers. + * arch/i386.h (i386_create_target_description): Likewise. + * features/i386/32bit-segments.xml: New file. + * features/i386/32bit-segments.c: Generate. + * i386-fbsd-nat.c (i386_fbsd_nat_target::read_description): Update + call to i386_target_description to add 'segments' parameter. + * i386-fbsd-tdep.c (i386fbsd_core_read_description): Likewise. + * i386-go32-tdep.c (i386_go32_init_abi): Likewise. + * i386-linux-tdep.c (i386_linux_read_description): Likewise. + * i386-tdep.c (i386_validate_tdesc_p): Add segment base registers + if feature is present. + (i386_gdbarch_init): Pass I386_NUM_REGS to set_gdbarch_num_regs. + Add 'segments' parameter to call to i386_target_description. + (i386_target_description): Add 'segments' parameter to enable + segment base registers. + (_initialize_i386_tdep) [GDB_SELF_TEST]: Add 'segments' parameter + to call to i386_target_description. + * i386-tdep.h (struct gdbarch_tdep): Add 'fsbase_regnum'. + (enum i386_regnum): Add I386_FSBASE_REGNUM and I386_GSBASE_REGNUM. + Define I386_NUM_REGS. + (i386_target_description): Add 'segments' parameter to enable + segment base registers. + + gdb/gdbserver/ChangeLog: + + * linux-x86-tdesc.c (i386_linux_read_description): Update call to + i386_create_target_description for 'segments' parameter. + * lynx-i386-low.c (lynx_i386_arch_setup): Likewise. + * nto-x86-low.c (nto_x86_arch_setup): Likewise. + * win32-i386-low.c (i386_arch_setup): Likewise. + +diff --git gdb/amd64-fbsd-nat.c gdb/amd64-fbsd-nat.c +index 74ef240766..9fff763dd3 100644 +--- gdb/amd64-fbsd-nat.c ++++ gdb/amd64-fbsd-nat.c +@@ -190,13 +190,13 @@ amd64_fbsd_nat_target::read_description () + if (is64) + return amd64_target_description (xcr0, true); + else +- return i386_target_description (xcr0); ++ return i386_target_description (xcr0, false); + } + #endif + if (is64) + return amd64_target_description (X86_XSTATE_SSE_MASK, true); + else +- return i386_target_description (X86_XSTATE_SSE_MASK); ++ return i386_target_description (X86_XSTATE_SSE_MASK, false); + } + + #if defined(HAVE_PT_GETDBREGS) && defined(USE_SIGTRAP_SIGINFO) +diff --git gdb/amd64-tdep.c gdb/amd64-tdep.c +index 3f61997d66..d5892954d7 100644 +--- gdb/amd64-tdep.c ++++ gdb/amd64-tdep.c +@@ -3107,15 +3107,7 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch, + + if (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.segments") != NULL) + { +- const struct tdesc_feature *feature = +- tdesc_find_feature (tdesc, "org.gnu.gdb.i386.segments"); +- struct tdesc_arch_data *tdesc_data_segments = +- (struct tdesc_arch_data *) info.tdep_info; +- +- tdesc_numbered_register (feature, tdesc_data_segments, +- AMD64_FSBASE_REGNUM, "fs_base"); +- tdesc_numbered_register (feature, tdesc_data_segments, +- AMD64_GSBASE_REGNUM, "gs_base"); ++ tdep->fsbase_regnum = AMD64_FSBASE_REGNUM; + } + + if (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.pkeys") != NULL) +diff --git gdb/arch/i386.c gdb/arch/i386.c +index 7d2901333b..ab24cf71cb 100644 +--- gdb/arch/i386.c ++++ gdb/arch/i386.c +@@ -28,11 +28,12 @@ + #include "../features/i386/32bit-avx512.c" + #include "../features/i386/32bit-mpx.c" + #include "../features/i386/32bit-pkeys.c" ++#include "../features/i386/32bit-segments.c" + + /* Create i386 target descriptions according to XCR0. */ + + target_desc * +-i386_create_target_description (uint64_t xcr0, bool is_linux) ++i386_create_target_description (uint64_t xcr0, bool is_linux, bool segments) + { + target_desc *tdesc = allocate_target_description (); + +@@ -53,6 +54,9 @@ i386_create_target_description (uint64_t xcr0, bool is_linux) + if (is_linux) + regnum = create_feature_i386_32bit_linux (tdesc, regnum); + ++ if (segments) ++ regnum = create_feature_i386_32bit_segments (tdesc, regnum); ++ + if (xcr0 & X86_XSTATE_AVX) + regnum = create_feature_i386_32bit_avx (tdesc, regnum); + +diff --git gdb/arch/i386.h gdb/arch/i386.h +index fa85438080..9a831cea30 100644 +--- gdb/arch/i386.h ++++ gdb/arch/i386.h +@@ -21,6 +21,7 @@ + #include "common/tdesc.h" + #include <stdint.h> + +-target_desc *i386_create_target_description (uint64_t xcr0, bool is_linux); ++target_desc *i386_create_target_description (uint64_t xcr0, bool is_linux, ++ bool segments); + + #endif /* ARCH_I386_H */ +diff --git gdb/features/i386/32bit-segments.c gdb/features/i386/32bit-segments.c +new file mode 100644 +index 0000000000..c22c3dfbc3 +--- /dev/null ++++ gdb/features/i386/32bit-segments.c +@@ -0,0 +1,15 @@ ++/* THIS FILE IS GENERATED. -*- buffer-read-only: t -*- vi:set ro: ++ Original: 32bit-segments.xml */ ++ ++#include "common/tdesc.h" ++ ++static int ++create_feature_i386_32bit_segments (struct target_desc *result, long regnum) ++{ ++ struct tdesc_feature *feature; ++ ++ feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments"); ++ tdesc_create_reg (feature, "fs_base", regnum++, 1, NULL, 32, "int"); ++ tdesc_create_reg (feature, "gs_base", regnum++, 1, NULL, 32, "int"); ++ return regnum; ++} +diff --git gdb/features/i386/32bit-segments.xml gdb/features/i386/32bit-segments.xml +new file mode 100644 +index 0000000000..098948e5ec +--- /dev/null ++++ gdb/features/i386/32bit-segments.xml +@@ -0,0 +1,12 @@ ++<?xml version="1.0"?> ++<!-- Copyright (C) 2016-2018 Free Software Foundation, Inc. ++ ++ Copying and distribution of this file, with or without modification, ++ are permitted in any medium without royalty provided the copyright ++ notice and this notice are preserved. --> ++ ++<!DOCTYPE feature SYSTEM "gdb-target.dtd"> ++<feature name="org.gnu.gdb.i386.segments"> ++ <reg name="fs_base" bitsize="32" type="int"/> ++ <reg name="gs_base" bitsize="32" type="int"/> ++</feature> +diff --git gdb/gdbserver/linux-x86-tdesc.c gdb/gdbserver/linux-x86-tdesc.c +index 04bccc84ed..8f24a3d72d 100644 +--- gdb/gdbserver/linux-x86-tdesc.c ++++ gdb/gdbserver/linux-x86-tdesc.c +@@ -87,7 +87,7 @@ i386_linux_read_description (uint64_t xcr0) + + if (*tdesc == NULL) + { +- *tdesc = i386_create_target_description (xcr0, true); ++ *tdesc = i386_create_target_description (xcr0, true, false); + + init_target_desc (*tdesc, i386_expedite_regs); + } +diff --git gdb/gdbserver/lynx-i386-low.c gdb/gdbserver/lynx-i386-low.c +index bc1027dc52..e47f6b92f6 100644 +--- gdb/gdbserver/lynx-i386-low.c ++++ gdb/gdbserver/lynx-i386-low.c +@@ -331,7 +331,7 @@ static void + lynx_i386_arch_setup (void) + { + struct target_desc *tdesc +- = i386_create_target_description (X86_XSTATE_SSE_MASK, false); ++ = i386_create_target_description (X86_XSTATE_SSE_MASK, false, false); + + init_target_desc (tdesc, i386_expedite_regs); + +diff --git gdb/gdbserver/nto-x86-low.c gdb/gdbserver/nto-x86-low.c +index 1b00f7f6cc..cfbe7ba6d8 100644 +--- gdb/gdbserver/nto-x86-low.c ++++ gdb/gdbserver/nto-x86-low.c +@@ -89,7 +89,7 @@ nto_x86_arch_setup (void) + { + the_low_target.num_regs = 16; + struct target_desc *tdesc +- = i386_create_target_description (X86_XSTATE_SSE_MASK, false); ++ = i386_create_target_description (X86_XSTATE_SSE_MASK, false, false); + + init_target_desc (tdesc, i386_expedite_regs); + +diff --git gdb/gdbserver/win32-i386-low.c gdb/gdbserver/win32-i386-low.c +index 3be75d2bf2..7b187d3bea 100644 +--- gdb/gdbserver/win32-i386-low.c ++++ gdb/gdbserver/win32-i386-low.c +@@ -439,7 +439,7 @@ i386_arch_setup (void) + false, false); + const char **expedite_regs = amd64_expedite_regs; + #else +- tdesc = i386_create_target_description (X86_XSTATE_SSE_MASK, false); ++ tdesc = i386_create_target_description (X86_XSTATE_SSE_MASK, false, false); + const char **expedite_regs = i386_expedite_regs; + #endif + +diff --git gdb/i386-fbsd-nat.c gdb/i386-fbsd-nat.c +index 2309b76506..7106e90801 100644 +--- gdb/i386-fbsd-nat.c ++++ gdb/i386-fbsd-nat.c +@@ -160,7 +160,7 @@ i386_fbsd_nat_target::read_description () + if (x86bsd_xsave_len == 0) + xcr0 = X86_XSTATE_SSE_MASK; + +- return i386_target_description (xcr0); ++ return i386_target_description (xcr0, false); + } + #endif + +diff --git gdb/i386-fbsd-tdep.c gdb/i386-fbsd-tdep.c +index 236edd692a..2f28bad728 100644 +--- gdb/i386-fbsd-tdep.c ++++ gdb/i386-fbsd-tdep.c +@@ -267,7 +267,7 @@ i386fbsd_core_read_description (struct gdbarch *gdbarch, + struct target_ops *target, + bfd *abfd) + { +- return i386_target_description (i386fbsd_core_read_xcr0 (abfd)); ++ return i386_target_description (i386fbsd_core_read_xcr0 (abfd), false); + } + + /* Similar to i386_supply_fpregset, but use XSAVE extended state. */ +diff --git gdb/i386-go32-tdep.c gdb/i386-go32-tdep.c +index 06833c346c..30db72d880 100644 +--- gdb/i386-go32-tdep.c ++++ gdb/i386-go32-tdep.c +@@ -35,7 +35,7 @@ i386_go32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) + + /* DJGPP does not support the SSE registers. */ + if (!tdesc_has_registers (info.target_desc)) +- tdep->tdesc = i386_target_description (X86_XSTATE_X87_MASK); ++ tdep->tdesc = i386_target_description (X86_XSTATE_X87_MASK, false); + + /* Native compiler is GCC, which uses the SVR4 register numbering + even in COFF and STABS. See the comment in i386_gdbarch_init, +diff --git gdb/i386-linux-tdep.c gdb/i386-linux-tdep.c +index da81715061..fa6b86f1c8 100644 +--- gdb/i386-linux-tdep.c ++++ gdb/i386-linux-tdep.c +@@ -694,7 +694,7 @@ i386_linux_read_description (uint64_t xcr0) + [(xcr0 & X86_XSTATE_PKRU) ? 1 : 0]; + + if (*tdesc == NULL) +- *tdesc = i386_create_target_description (xcr0, true); ++ *tdesc = i386_create_target_description (xcr0, true, false); + + return *tdesc; + } +diff --git gdb/i386-tdep.c gdb/i386-tdep.c +index bc9ba752ed..4e63832b0e 100644 +--- gdb/i386-tdep.c ++++ gdb/i386-tdep.c +@@ -8175,7 +8175,7 @@ i386_validate_tdesc_p (struct gdbarch_tdep *tdep, + const struct tdesc_feature *feature_core; + + const struct tdesc_feature *feature_sse, *feature_avx, *feature_mpx, +- *feature_avx512, *feature_pkeys; ++ *feature_avx512, *feature_pkeys, *feature_segments; + int i, num_regs, valid_p; + + if (! tdesc_has_registers (tdesc)) +@@ -8198,6 +8198,9 @@ i386_validate_tdesc_p (struct gdbarch_tdep *tdep, + /* Try AVX512 registers. */ + feature_avx512 = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.avx512"); + ++ /* Try segment base registers. */ ++ feature_segments = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.segments"); ++ + /* Try PKEYS */ + feature_pkeys = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.pkeys"); + +@@ -8307,6 +8310,16 @@ i386_validate_tdesc_p (struct gdbarch_tdep *tdep, + tdep->mpx_register_names[i]); + } + ++ if (feature_segments) ++ { ++ if (tdep->fsbase_regnum < 0) ++ tdep->fsbase_regnum = I386_FSBASE_REGNUM; ++ valid_p &= tdesc_numbered_register (feature_segments, tdesc_data, ++ tdep->fsbase_regnum, "fs_base"); ++ valid_p &= tdesc_numbered_register (feature_segments, tdesc_data, ++ tdep->fsbase_regnum + 1, "gs_base"); ++ } ++ + if (feature_pkeys) + { + tdep->xcr0 |= X86_XSTATE_PKRU; +@@ -8543,14 +8556,14 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) + /* Even though the default ABI only includes general-purpose registers, + floating-point registers and the SSE registers, we have to leave a + gap for the upper AVX, MPX and AVX512 registers. */ +- set_gdbarch_num_regs (gdbarch, I386_PKEYS_NUM_REGS); ++ set_gdbarch_num_regs (gdbarch, I386_NUM_REGS); + + set_gdbarch_gnu_triplet_regexp (gdbarch, i386_gnu_triplet_regexp); + + /* Get the x86 target description from INFO. */ + tdesc = info.target_desc; + if (! tdesc_has_registers (tdesc)) +- tdesc = i386_target_description (X86_XSTATE_SSE_MASK); ++ tdesc = i386_target_description (X86_XSTATE_SSE_MASK, false); + tdep->tdesc = tdesc; + + tdep->num_core_regs = I386_NUM_GREGS + I387_NUM_REGS; +@@ -8592,6 +8605,9 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) + tdep->pkru_regnum = -1; + tdep->num_pkeys_regs = 0; + ++ /* No segment base registers. */ ++ tdep->fsbase_regnum = -1; ++ + tdesc_data = tdesc_data_alloc (); + + set_gdbarch_relocate_instruction (gdbarch, i386_relocate_instruction); +@@ -8717,20 +8733,21 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) + /* Return the target description for a specified XSAVE feature mask. */ + + const struct target_desc * +-i386_target_description (uint64_t xcr0) ++i386_target_description (uint64_t xcr0, bool segments) + { + static target_desc *i386_tdescs \ +- [2/*SSE*/][2/*AVX*/][2/*MPX*/][2/*AVX512*/][2/*PKRU*/] = {}; ++ [2/*SSE*/][2/*AVX*/][2/*MPX*/][2/*AVX512*/][2/*PKRU*/][2/*segments*/] = {}; + target_desc **tdesc; + + tdesc = &i386_tdescs[(xcr0 & X86_XSTATE_SSE) ? 1 : 0] + [(xcr0 & X86_XSTATE_AVX) ? 1 : 0] + [(xcr0 & X86_XSTATE_MPX) ? 1 : 0] + [(xcr0 & X86_XSTATE_AVX512) ? 1 : 0] +- [(xcr0 & X86_XSTATE_PKRU) ? 1 : 0]; ++ [(xcr0 & X86_XSTATE_PKRU) ? 1 : 0] ++ [segments ? 1 : 0]; + + if (*tdesc == NULL) +- *tdesc = i386_create_target_description (xcr0, false); ++ *tdesc = i386_create_target_description (xcr0, false, segments); + + return *tdesc; + } +@@ -9072,7 +9089,7 @@ Show Intel Memory Protection Extensions specific variables."), + + for (auto &a : xml_masks) + { +- auto tdesc = i386_target_description (a.mask); ++ auto tdesc = i386_target_description (a.mask, false); + + selftests::record_xml_tdesc (a.xml, tdesc); + } +diff --git gdb/i386-tdep.h gdb/i386-tdep.h +index 2532306e5c..c0d494824c 100644 +--- gdb/i386-tdep.h ++++ gdb/i386-tdep.h +@@ -200,6 +200,10 @@ struct gdbarch_tdep + /* PKEYS register names. */ + const char **pkeys_register_names; + ++ /* Register number for %fsbase. Set this to -1 to indicate the ++ absence of segment base registers. */ ++ int fsbase_regnum; ++ + /* Target description. */ + const struct target_desc *tdesc; + +@@ -296,7 +300,9 @@ enum i386_regnum + I386_K7_REGNUM = I386_K0_REGNUM + 7, + I386_ZMM0H_REGNUM, /* %zmm0h */ + I386_ZMM7H_REGNUM = I386_ZMM0H_REGNUM + 7, +- I386_PKRU_REGNUM ++ I386_PKRU_REGNUM, ++ I386_FSBASE_REGNUM, ++ I386_GSBASE_REGNUM + }; + + /* Register numbers of RECORD_REGMAP. */ +@@ -337,6 +343,7 @@ enum record_i386_regnum + #define I386_MPX_NUM_REGS (I386_BNDSTATUS_REGNUM + 1) + #define I386_AVX512_NUM_REGS (I386_ZMM7H_REGNUM + 1) + #define I386_PKEYS_NUM_REGS (I386_PKRU_REGNUM + 1) ++#define I386_NUM_REGS (I386_GSBASE_REGNUM + 1) + + /* Size of the largest register. */ + #define I386_MAX_REGISTER_SIZE 64 +@@ -440,7 +447,8 @@ extern int i386_svr4_reg_to_regnum (struct gdbarch *gdbarch, int reg); + + extern int i386_process_record (struct gdbarch *gdbarch, + struct regcache *regcache, CORE_ADDR addr); +-extern const struct target_desc *i386_target_description (uint64_t xcr0); ++extern const struct target_desc *i386_target_description (uint64_t xcr0, ++ bool segments); + + /* Return true iff the current target is MPX enabled. */ + extern int i386_mpx_enabled (void); Added: head/devel/gdb/files/commit-36c53a0262 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/devel/gdb/files/commit-36c53a0262 Sat Jun 1 00:44:08 2019 (r503200) @@ -0,0 +1,60 @@ +commit 36c53a0262f84ad11d738471789dadfa9c4eb320 +Author: John Baldwin <jhb@FreeBSD.org> +Date: Tue Mar 12 13:39:02 2019 -0700 + + Remove code disabled since at least 1999 from lookup_struct_elt_type. + + Update the comment above the function to reflect the code removal and + document the existing behavior. + + gdb/ChangeLog: + + * gdbtypes.c (lookup_struct_elt_type): Update comment and + remove disabled code block. + +diff --git gdb/gdbtypes.c gdb/gdbtypes.c +index 09284ef259..5924b15520 100644 +--- gdb/gdbtypes.c ++++ gdb/gdbtypes.c +@@ -1644,8 +1644,7 @@ lookup_template_type (char *name, struct type *type, + return (SYMBOL_TYPE (sym)); + } + +-/* Given a type TYPE, lookup the type of the component of type named +- NAME. ++/* Given a type TYPE, lookup the type of the component named NAME. + + TYPE can be either a struct or union, or a pointer or reference to + a struct or union. If it is a pointer or reference, its target +@@ -1653,8 +1652,8 @@ lookup_template_type (char *name, struct type *type, + as specified for the definitions of the expression element types + STRUCTOP_STRUCT and STRUCTOP_PTR. + +- If NOERR is nonzero, return zero if NAME is not suitably defined. +- If NAME is the name of a baseclass type, return that type. */ ++ If NOERR is nonzero, return NULL if there is no component named ++ NAME. */ + + struct type * + lookup_struct_elt_type (struct type *type, const char *name, int noerr) +@@ -1678,20 +1677,6 @@ lookup_struct_elt_type (struct type *type, const char *name, int noerr) + type_name.c_str ()); + } + +-#if 0 +- /* FIXME: This change put in by Michael seems incorrect for the case +- where the structure tag name is the same as the member name. +- I.e. when doing "ptype bell->bar" for "struct foo { int bar; int +- foo; } bell;" Disabled by fnf. */ +- { +- char *type_name; +- +- type_name = TYPE_NAME (type); +- if (type_name != NULL && strcmp (type_name, name) == 0) +- return type; +- } +-#endif +- + for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--) + { + const char *t_field_name = TYPE_FIELD_NAME (type, i); Added: head/devel/gdb/files/commit-6e056c8178 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/devel/gdb/files/commit-6e056c8178 Sat Jun 1 00:44:08 2019 (r503200) @@ -0,0 +1,166 @@ +commit 6e056c817845f3d736a1be6b68c69b439c6c6d25 +Author: John Baldwin <jhb@FreeBSD.org> +Date: Tue Mar 12 13:39:02 2019 -0700 + + Add a new gdbarch method to resolve the address of TLS variables. + + Permit TLS variable addresses to be resolved purely by an ABI rather + than requiring a target method. This doesn't try the target method if + the ABI function is present (even if the ABI function fails) to + simplify error handling. + + gdb/ChangeLog: + + * gdbarch.sh (get_thread_local_address): New method. + * gdbarch.h, gdbarch.c: Regenerate. + * target.c (target_translate_tls_address): Use + gdbarch_get_thread_local_address if present instead of + target::get_thread_local_address. + +diff --git gdb/gdbarch.c gdb/gdbarch.c +index 434ee3bfcf..2b3fcef004 100644 +--- gdb/gdbarch.c ++++ gdb/gdbarch.c +@@ -251,6 +251,7 @@ struct gdbarch + CORE_ADDR deprecated_function_start_offset; + gdbarch_remote_register_number_ftype *remote_register_number; + gdbarch_fetch_tls_load_module_address_ftype *fetch_tls_load_module_address; ++ gdbarch_get_thread_local_address_ftype *get_thread_local_address; + CORE_ADDR frame_args_skip; + gdbarch_unwind_pc_ftype *unwind_pc; + gdbarch_unwind_sp_ftype *unwind_sp; +@@ -613,6 +614,7 @@ verify_gdbarch (struct gdbarch *gdbarch) + /* Skip verify of deprecated_function_start_offset, invalid_p == 0 */ + /* Skip verify of remote_register_number, invalid_p == 0 */ + /* Skip verify of fetch_tls_load_module_address, has predicate. */ ++ /* Skip verify of get_thread_local_address, has predicate. */ + /* Skip verify of frame_args_skip, invalid_p == 0 */ + /* Skip verify of unwind_pc, invalid_p == 0 */ + /* Skip verify of unwind_sp, invalid_p == 0 */ +@@ -1073,6 +1075,12 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) + fprintf_unfiltered (file, + "gdbarch_dump: get_syscall_number = <%s>\n", + host_address_to_string (gdbarch->get_syscall_number)); ++ fprintf_unfiltered (file, ++ "gdbarch_dump: gdbarch_get_thread_local_address_p() = %d\n", ++ gdbarch_get_thread_local_address_p (gdbarch)); ++ fprintf_unfiltered (file, ++ "gdbarch_dump: get_thread_local_address = <%s>\n", ++ host_address_to_string (gdbarch->get_thread_local_address)); + fprintf_unfiltered (file, + "gdbarch_dump: gnu_triplet_regexp = <%s>\n", + host_address_to_string (gdbarch->gnu_triplet_regexp)); +@@ -3018,6 +3026,30 @@ set_gdbarch_fetch_tls_load_module_address (struct gdbarch *gdbarch, + gdbarch->fetch_tls_load_module_address = fetch_tls_load_module_address; + } + ++int ++gdbarch_get_thread_local_address_p (struct gdbarch *gdbarch) ++{ ++ gdb_assert (gdbarch != NULL); ++ return gdbarch->get_thread_local_address != NULL; ++} ++ ++CORE_ADDR ++gdbarch_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid, CORE_ADDR lm_addr, CORE_ADDR offset) ++{ ++ gdb_assert (gdbarch != NULL); ++ gdb_assert (gdbarch->get_thread_local_address != NULL); ++ if (gdbarch_debug >= 2) ++ fprintf_unfiltered (gdb_stdlog, "gdbarch_get_thread_local_address called\n"); ++ return gdbarch->get_thread_local_address (gdbarch, ptid, lm_addr, offset); ++} ++ ++void ++set_gdbarch_get_thread_local_address (struct gdbarch *gdbarch, ++ gdbarch_get_thread_local_address_ftype get_thread_local_address) ++{ ++ gdbarch->get_thread_local_address = get_thread_local_address; ++} ++ + CORE_ADDR + gdbarch_frame_args_skip (struct gdbarch *gdbarch) + { +diff --git gdb/gdbarch.h gdb/gdbarch.h +index 75618376ab..abb72e752b 100644 +--- gdb/gdbarch.h ++++ gdb/gdbarch.h +@@ -649,6 +649,18 @@ typedef CORE_ADDR (gdbarch_fetch_tls_load_module_address_ftype) (struct objfile + extern CORE_ADDR gdbarch_fetch_tls_load_module_address (struct gdbarch *gdbarch, struct objfile *objfile); + extern void set_gdbarch_fetch_tls_load_module_address (struct gdbarch *gdbarch, gdbarch_fetch_tls_load_module_address_ftype *fetch_tls_load_module_address); + ++/* Return the thread-local address at OFFSET in the thread-local ++ storage for the thread PTID and the shared library or executable ++ file given by LM_ADDR. If that block of thread-local storage hasn't ++ been allocated yet, this function may throw an error. LM_ADDR may ++ be zero for statically linked multithreaded inferiors. */ ++ ++extern int gdbarch_get_thread_local_address_p (struct gdbarch *gdbarch); ++ ++typedef CORE_ADDR (gdbarch_get_thread_local_address_ftype) (struct gdbarch *gdbarch, ptid_t ptid, CORE_ADDR lm_addr, CORE_ADDR offset); ++extern CORE_ADDR gdbarch_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid, CORE_ADDR lm_addr, CORE_ADDR offset); ++extern void set_gdbarch_get_thread_local_address (struct gdbarch *gdbarch, gdbarch_get_thread_local_address_ftype *get_thread_local_address); ++ + extern CORE_ADDR gdbarch_frame_args_skip (struct gdbarch *gdbarch); + extern void set_gdbarch_frame_args_skip (struct gdbarch *gdbarch, CORE_ADDR frame_args_skip); + +diff --git gdb/gdbarch.sh gdb/gdbarch.sh +index 48fcebd19a..63bfbad7d9 100755 +--- gdb/gdbarch.sh ++++ gdb/gdbarch.sh +@@ -602,6 +602,14 @@ m;int;remote_register_number;int regno;regno;;default_remote_register_number;;0 + + # Fetch the target specific address used to represent a load module. + F;CORE_ADDR;fetch_tls_load_module_address;struct objfile *objfile;objfile ++ ++# Return the thread-local address at OFFSET in the thread-local ++# storage for the thread PTID and the shared library or executable ++# file given by LM_ADDR. If that block of thread-local storage hasn't ++# been allocated yet, this function may throw an error. LM_ADDR may ++# be zero for statically linked multithreaded inferiors. ++ ++M;CORE_ADDR;get_thread_local_address;ptid_t ptid, CORE_ADDR lm_addr, CORE_ADDR offset;ptid, lm_addr, offset + # + v;CORE_ADDR;frame_args_skip;;;0;;;0 + m;CORE_ADDR;unwind_pc;struct frame_info *next_frame;next_frame;;default_unwind_pc;;0 +diff --git gdb/target.c gdb/target.c +index 8579c19d05..c27157d209 100644 +--- gdb/target.c ++++ gdb/target.c +@@ -698,8 +698,9 @@ target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset) + { + volatile CORE_ADDR addr = 0; + struct target_ops *target = current_top_target (); ++ struct gdbarch *gdbarch = target_gdbarch (); + +- if (gdbarch_fetch_tls_load_module_address_p (target_gdbarch ())) ++ if (gdbarch_fetch_tls_load_module_address_p (gdbarch)) + { + ptid_t ptid = inferior_ptid; + +@@ -708,10 +709,14 @@ target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset) + CORE_ADDR lm_addr; + + /* Fetch the load module address for this objfile. */ +- lm_addr = gdbarch_fetch_tls_load_module_address (target_gdbarch (), ++ lm_addr = gdbarch_fetch_tls_load_module_address (gdbarch, + objfile); + +- addr = target->get_thread_local_address (ptid, lm_addr, offset); ++ if (gdbarch_get_thread_local_address_p (gdbarch)) ++ addr = gdbarch_get_thread_local_address (gdbarch, ptid, lm_addr, ++ offset); ++ else ++ addr = target->get_thread_local_address (ptid, lm_addr, offset); + } + /* If an error occurred, print TLS related messages here. Otherwise, + throw the error to some higher catcher. */ +@@ -766,8 +771,6 @@ target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset) + } + END_CATCH + } +- /* It wouldn't be wrong here to try a gdbarch method, too; finding +- TLS is an ABI-specific thing. But we don't do that yet. */ + else + error (_("Cannot find thread-local variables on this target")); + Added: head/devel/gdb/files/commit-8399425f5f ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/devel/gdb/files/commit-8399425f5f Sat Jun 1 00:44:08 2019 (r503200) @@ -0,0 +1,69 @@ +commit 8399425f5f472ad8e630bb30ad2dbefeddbb68b7 +Author: John Baldwin <jhb@FreeBSD.org> +Date: Tue Mar 12 13:39:02 2019 -0700 + + Support TLS variables on FreeBSD/powerpc. + + Derive the pointer to the DTV array from the %r2 register on 32-bit + powerpc and %r13 on 64-bit powerpc. + + gdb/ChangeLog: + + * ppc-fbsd-tdep.c (ppcfbsd_get_thread_local_address): New. + (ppcfbsd_init_abi): Install gdbarch + "fetch_tls_load_module_address" and "get_thread_local_address" + methods. + +diff --git gdb/ppc-fbsd-tdep.c gdb/ppc-fbsd-tdep.c +index c21a52c898..290bd1fd88 100644 +--- gdb/ppc-fbsd-tdep.c ++++ gdb/ppc-fbsd-tdep.c +@@ -279,6 +279,39 @@ ppcfbsd_return_value (struct gdbarch *gdbarch, struct value *function, + regcache, readbuf, writebuf); + } + ++/* Implement the "get_thread_local_address" gdbarch method. */ ++ ++static CORE_ADDR ++ppcfbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid, ++ CORE_ADDR lm_addr, CORE_ADDR offset) ++{ ++ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); ++ struct regcache *regcache; ++ int tp_offset, tp_regnum; ++ ++ regcache = get_thread_arch_regcache (ptid, gdbarch); ++ ++ if (tdep->wordsize == 4) ++ { ++ tp_offset = 0x7008; ++ tp_regnum = PPC_R0_REGNUM + 2; ++ } ++ else ++ { ++ tp_offset = 0x7010; ++ tp_regnum = PPC_R0_REGNUM + 13; ++ } ++ target_fetch_registers (regcache, tp_regnum); ++ ++ ULONGEST tp; ++ if (regcache->cooked_read (tp_regnum, &tp) != REG_VALID) ++ error (_("Unable to fetch tcb pointer")); ++ ++ /* tp points to the end of the TCB block. The first member of the ++ TCB is the pointer to the DTV array. */ ++ CORE_ADDR dtv_addr = tp - tp_offset; ++ return fbsd_get_thread_local_address (gdbarch, dtv_addr, lm_addr, offset); ++} + + static void + ppcfbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) +@@ -322,6 +355,8 @@ ppcfbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) + + set_gdbarch_fetch_tls_load_module_address (gdbarch, + svr4_fetch_objfile_link_map); ++ set_gdbarch_get_thread_local_address (gdbarch, ++ ppcfbsd_get_thread_local_address); + } + + void Added: head/devel/gdb/files/commit-945f3901b5 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/devel/gdb/files/commit-945f3901b5 Sat Jun 1 00:44:08 2019 (r503200) @@ -0,0 +1,224 @@ +commit 945f3901b5889e57edf5a2ee25acb51f0078a719 +Author: John Baldwin <jhb@FreeBSD.org> +Date: Tue Mar 12 13:39:02 2019 -0700 + + Add a helper function to resolve TLS variable addresses for FreeBSD. + + The fbsd_get_thread_local_address function accepts the base address of + a thread's DTV array and the base address of an object file's link map + and uses this to compute a TLS variable's address. FreeBSD + architectures use an architecture-specific method to determine the + address of the DTV array pointer and call this helper function to + perform the rest of the address calculation. + + * fbsd-tdep.c (fbsd_pspace_data_handle): New variable. + (struct fbsd_pspace_data): New type. + (get_fbsd_pspace_data, fbsd_pspace_data_cleanup) + (fbsd_read_integer_by_name, fbsd_fetch_rtld_offsets) + (fbsd_get_tls_index, fbsd_get_thread_local_address): New function. + (_initialize_fbsd_tdep): Initialize 'fbsd_pspace_data_handle'. + * fbsd-tdep.c (fbsd_get_thread_local_address): New prototype. + +diff --git gdb/fbsd-tdep.c gdb/fbsd-tdep.c +index d971d3a653..f06836216d 100644 +--- gdb/fbsd-tdep.c ++++ gdb/fbsd-tdep.c +@@ -24,6 +24,7 @@ + #include "regcache.h" + #include "regset.h" + #include "gdbthread.h" ++#include "objfiles.h" + #include "xml-syscall.h" + #include <sys/socket.h> + #include <arpa/inet.h> +@@ -444,6 +445,41 @@ get_fbsd_gdbarch_data (struct gdbarch *gdbarch) + gdbarch_data (gdbarch, fbsd_gdbarch_data_handle)); + } + ++/* Per-program-space data for FreeBSD architectures. */ ++static const struct program_space_data *fbsd_pspace_data_handle; ++ ++struct fbsd_pspace_data ++{ ++ /* Offsets in the runtime linker's 'Obj_Entry' structure. */ ++ LONGEST off_linkmap; ++ LONGEST off_tlsindex; ++ bool rtld_offsets_valid; ++}; ++ ++static struct fbsd_pspace_data * ++get_fbsd_pspace_data (struct program_space *pspace) ++{ ++ struct fbsd_pspace_data *data; ++ ++ data = ((struct fbsd_pspace_data *) ++ program_space_data (pspace, fbsd_pspace_data_handle)); ++ if (data == NULL) ++ { ++ data = XCNEW (struct fbsd_pspace_data); ++ set_program_space_data (pspace, fbsd_pspace_data_handle, data); ++ } ++ ++ return data; ++} ++ ++/* The cleanup callback for FreeBSD architecture per-program-space data. */ ++ ++static void ++fbsd_pspace_data_cleanup (struct program_space *pspace, void *data) ++{ ++ xfree (data); ++} ++ + /* This is how we want PTIDs from core files to be printed. */ + + static const char * +@@ -1932,6 +1968,121 @@ fbsd_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread) + internal_error (__FILE__, __LINE__, _("fbsd_get_sycall_number called")); + } + ++/* Read an integer symbol value from the current target. */ ++ ++static LONGEST ++fbsd_read_integer_by_name (struct gdbarch *gdbarch, const char *name) ++{ ++ bound_minimal_symbol ms = lookup_minimal_symbol (name, NULL, NULL); ++ if (ms.minsym == NULL) ++ error (_("Unable to resolve symbol '%s'"), name); ++ ++ gdb_byte buf[4]; ++ if (target_read_memory (BMSYMBOL_VALUE_ADDRESS (ms), buf, sizeof buf) != 0) ++ error (_("Unable to read value of '%s'"), name); ++ ++ return extract_signed_integer (buf, sizeof buf, gdbarch_byte_order (gdbarch)); ++} ++ ++/* Lookup offsets of fields in the runtime linker's 'Obj_Entry' ++ structure needed to determine the TLS index of an object file. */ ++ ++static void ++fbsd_fetch_rtld_offsets (struct gdbarch *gdbarch, struct fbsd_pspace_data *data) ++{ ++ TRY ++ { ++ /* Fetch offsets from debug symbols in rtld. */ ++ struct symbol *obj_entry_sym ++ = lookup_symbol_in_language ("Struct_Obj_Entry", NULL, STRUCT_DOMAIN, ++ language_c, NULL).symbol; ++ if (obj_entry_sym == NULL) ++ error (_("Unable to find Struct_Obj_Entry symbol")); ++ data->off_linkmap = lookup_struct_elt (SYMBOL_TYPE(obj_entry_sym), ++ "linkmap", 0).offset / 8; ++ data->off_tlsindex = lookup_struct_elt (SYMBOL_TYPE(obj_entry_sym), ++ "tlsindex", 0).offset / 8; ++ data->rtld_offsets_valid = true; ++ return; ++ } ++ CATCH (e, RETURN_MASK_ERROR) ++ { ++ data->off_linkmap = -1; ++ } ++ END_CATCH ++ ++ TRY ++ { ++ /* Fetch offsets from global variables in libthr. Note that ++ this does not work for single-threaded processes that are not ++ linked against libthr. */ ++ data->off_linkmap = fbsd_read_integer_by_name (gdbarch, ++ "_thread_off_linkmap"); ++ data->off_tlsindex = fbsd_read_integer_by_name (gdbarch, ++ "_thread_off_tlsindex"); ++ data->rtld_offsets_valid = true; ++ return; ++ } ++ CATCH (e, RETURN_MASK_ERROR) ++ { ++ data->off_linkmap = -1; ++ } ++ END_CATCH ++} ++ ++/* Helper function to read the TLS index of an object file associated ++ with a link map entry at LM_ADDR. */ ++ ++static LONGEST ++fbsd_get_tls_index (struct gdbarch *gdbarch, CORE_ADDR lm_addr) ++{ ++ struct fbsd_pspace_data *data = get_fbsd_pspace_data (current_program_space); ++ ++ if (!data->rtld_offsets_valid) ++ fbsd_fetch_rtld_offsets (gdbarch, data); ++ ++ if (data->off_linkmap == -1) ++ throw_error (TLS_GENERIC_ERROR, ++ _("Cannot fetch runtime linker structure offsets")); ++ ++ /* Simulate container_of to convert from LM_ADDR to the Obj_Entry ++ pointer and then compute the offset of the tlsindex member. */ ++ CORE_ADDR tlsindex_addr = lm_addr - data->off_linkmap + data->off_tlsindex; ++ ++ gdb_byte buf[4]; ++ if (target_read_memory (tlsindex_addr, buf, sizeof buf) != 0) ++ throw_error (TLS_GENERIC_ERROR, ++ _("Cannot find thread-local variables on this target")); ++ ++ return extract_signed_integer (buf, sizeof buf, gdbarch_byte_order (gdbarch)); ++} ++ ++/* See fbsd-tdep.h. */ ++ ++CORE_ADDR ++fbsd_get_thread_local_address (struct gdbarch *gdbarch, CORE_ADDR dtv_addr, ++ CORE_ADDR lm_addr, CORE_ADDR offset) *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201906010044.x510i80Z087786>