diff options
author | Tijl Coosemans <tijl@FreeBSD.org> | 2016-03-14 16:19:34 +0000 |
---|---|---|
committer | Tijl Coosemans <tijl@FreeBSD.org> | 2016-03-14 16:19:34 +0000 |
commit | 466938cba9d5fb98603b58408cab635225aa647c (patch) | |
tree | 4d0fee219e4b7518a07ca33406e04cf215054502 /devel/gdb | |
parent | 4d54b1cf38cb4e6dc06dae7e5961580830e0f4ba (diff) | |
download | ports-466938cba9d5fb98603b58408cab635225aa647c.tar.gz ports-466938cba9d5fb98603b58408cab635225aa647c.zip |
Notes
Diffstat (limited to 'devel/gdb')
-rw-r--r-- | devel/gdb/Makefile | 25 | ||||
-rw-r--r-- | devel/gdb/distinfo | 4 | ||||
-rw-r--r-- | devel/gdb/files/extrapatch-kgdb | 59 | ||||
-rw-r--r-- | devel/gdb/files/extrapatch-kgdb-configure.tgt-plain | 50 | ||||
-rw-r--r-- | devel/gdb/files/extrapatch-kgdb-configure.tgt-threads | 50 | ||||
-rw-r--r-- | devel/gdb/files/extrapatch-threads | 712 | ||||
-rw-r--r-- | devel/gdb/files/fbsd-threads.c | 1619 | ||||
-rw-r--r-- | devel/gdb/files/kgdb/fbsd-kvm.c | 2 | ||||
-rw-r--r-- | devel/gdb/files/patch-armfbsd | 15 | ||||
-rw-r--r-- | devel/gdb/files/patch-gdb-amd64bsd-nat.c | 29 | ||||
-rw-r--r-- | devel/gdb/files/patch-gdb-configure | 32 | ||||
-rw-r--r-- | devel/gdb/files/patch-gdb-fbsd-nat.c | 17 | ||||
-rw-r--r-- | devel/gdb/files/patch-gdb_common_common-defs.h | 12 |
13 files changed, 118 insertions, 2508 deletions
diff --git a/devel/gdb/Makefile b/devel/gdb/Makefile index 118f39ab394c..9abc999612b2 100644 --- a/devel/gdb/Makefile +++ b/devel/gdb/Makefile @@ -2,8 +2,8 @@ # $FreeBSD$ PORTNAME= gdb -PORTVERSION= 7.10 -PORTREVISION= 5 +PORTVERSION= 7.11 +#PORTREVISION= CATEGORIES= devel MASTER_SITES= GNU @@ -36,9 +36,9 @@ PLIST_SUB= VER=${VER} ONLY_FOR_ARCHS= i386 amd64 powerpc powerpc64 armv6 # untested elsewhere, might work -OPTIONS_DEFINE= DEBUG EXPAT GDB_LINK GUILE KGDB PYTHON THREADS TUI +OPTIONS_DEFINE= DEBUG EXPAT GDB_LINK GUILE KGDB PYTHON TUI -OPTIONS_DEFAULT= GDB_LINK KGDB THREADS TUI PORT_READLINE +OPTIONS_DEFAULT= GDB_LINK KGDB TUI PORT_READLINE OPTIONS_SINGLE= READLINE OPTIONS_SINGLE_READLINE= BASE_READLINE BUNDLED_READLINE PORT_READLINE @@ -80,21 +80,10 @@ CONFIGURE_TARGET= x86_64-portbld-freebsd${OSREL} post-patch: @${REINPLACE_CMD} -e 's|$$| [GDB v${PORTVERSION} for FreeBSD]|' \ ${WRKSRC}/gdb/version.in -.if ${PORT_OPTIONS:MTHREADS} - @${CP} ${FILESDIR}/fbsd-threads.c ${WRKSRC}/gdb/ - @${PATCH} ${PATCH_ARGS} < ${FILESDIR}/extrapatch-threads -.endif -.if ${PORT_OPTIONS:MKGDB} + +post-patch-KGDB-on: @${CP} -r ${FILESDIR}/kgdb/*.[ch] ${WRKSRC}/gdb/ @${PATCH} ${PATCH_ARGS} < ${FILESDIR}/extrapatch-kgdb -.if ${PORT_OPTIONS:MTHREADS} - @${PATCH} ${PATCH_ARGS} < \ - ${FILESDIR}/extrapatch-kgdb-configure.tgt-threads -.else - @${PATCH} ${PATCH_ARGS} < \ - ${FILESDIR}/extrapatch-kgdb-configure.tgt-plain -.endif -.endif do-install: ${INSTALL_PROGRAM} ${WRKSRC}/gdb/gdb \ @@ -119,7 +108,7 @@ do-install-PYTHON-on: (cd ${WRKSRC}/gdb; ${SETENV} ${MAKE_ENV} ${MAKE_CMD} ${MAKE_ARGS} install-python ) (cd ${WRKSRC}/gdb/data-directory ; \ ${SETENV} ${MAKE_ENV} ${MAKE_CMD} ${MAKE_ARGS} install-python ) -. for f in gdb gdb/command gdb/function +. for f in gdb gdb/command gdb/function gdb/printer @(cd ${STAGEDIR}${PREFIX}/share/gdb${VER}/python/${f} ; ${CHMOD} 644 *.py* ) . endfor diff --git a/devel/gdb/distinfo b/devel/gdb/distinfo index 7640812397e3..3a0903295e99 100644 --- a/devel/gdb/distinfo +++ b/devel/gdb/distinfo @@ -1,2 +1,2 @@ -SHA256 (gdb-7.10.tar.xz) = 7ebdaa44f9786ce0c142da4e36797d2020c55fa091905ac5af1846b5756208a8 -SIZE (gdb-7.10.tar.xz) = 18540820 +SHA256 (gdb-7.11.tar.xz) = 7a434116cb630d77bb40776e8f5d3937bed11dea56bafebb4d2bc5dd389fe5c1 +SIZE (gdb-7.11.tar.xz) = 18934392 diff --git a/devel/gdb/files/extrapatch-kgdb b/devel/gdb/files/extrapatch-kgdb index 33a623bf8590..1eb68a050ad4 100644 --- a/devel/gdb/files/extrapatch-kgdb +++ b/devel/gdb/files/extrapatch-kgdb @@ -71,6 +71,15 @@ index dfaa8a3..182d875 100644 fbsd-nat.c \ fbsd-tdep.c \ fork-child.c \ +@@ -2740,7 +2752,7 @@ + + # A list of all the objects we might care about in this build, for + # dependency tracking. +-all_object_files = gdb.o $(LIBGDB_OBS) gdbtk-main.o \ ++all_object_files = kgdb-main.o gdb.o $(LIBGDB_OBS) gdbtk-main.o \ + test-cp-name-parser.o + + # Ensure that generated files are created early. Use order-only diff --git gdb/config.in gdb/config.in index 9ef53b3..c55c01b 100644 --- gdb/config.in @@ -234,3 +243,53 @@ index a9fb44b..a156918 100644 extern void regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf); +diff --git gdb/configure.tgt gdb/configure.tgt +index 4e4d6a9..57e4b3a 100644 +--- gdb/configure.tgt ++++ gdb/configure.tgt +@@ -185,7 +185,13 @@ i[34567]86-*-dicos*) + i[34567]86-*-freebsd* | i[34567]86-*-kfreebsd*-gnu) + # Target: FreeBSD/i386 + gdb_target_obs="i386-tdep.o i387-tdep.o i386bsd-tdep.o i386fbsd-tdep.o \ +- bsd-uthread.o fbsd-tdep.o solib-svr4.o" ++ bsd-uthread.o fbsd-tdep.o solib-svr4.o \ ++ fbsd-kld.o fbsd-kthr.o fbsd-kvm.o i386fbsd-kern.o" ++ if test "x$enable_64_bit_bfd" = "xyes"; then ++ # Target: FreeBSD amd64 ++ gdb_target_obs="amd64-tdep.o amd64fbsd-tdep.o amd64fbsd-kern.o \ ++ ${gdb_target_obs}" ++ fi + ;; + i[34567]86-*-netbsd* | i[34567]86-*-knetbsd*-gnu) + # Target: NetBSD/i386 +@@ -405,7 +411,8 @@ powerpc*-*-freebsd*) + # Target: FreeBSD/powerpc + gdb_target_obs="rs6000-tdep.o ppc-sysv-tdep.o ppc64-tdep.o \ + ppcfbsd-tdep.o fbsd-tdep.o solib-svr4.o \ +- ravenscar-thread.o ppc-ravenscar-thread.o" ++ ravenscar-thread.o ppc-ravenscar-thread.o \ ++ fbsd-kld.o fbsd-kthr.o fbsd-kvm.o ppcfbsd-kern.o" + ;; + + powerpc-*-netbsd* | powerpc-*-knetbsd*-gnu) +@@ -534,7 +541,8 @@ sparc*-*-freebsd* | sparc*-*-kfreebsd*-gnu) + # Target: FreeBSD/sparc64 + gdb_target_obs="sparc-tdep.o sparc64-tdep.o sparc64fbsd-tdep.o \ + fbsd-tdep.o solib-svr4.o \ +- ravenscar-thread.o sparc-ravenscar-thread.o" ++ ravenscar-thread.o sparc-ravenscar-thread.o \ ++ fbsd-kld.o fbsd-kthr.o fbsd-kvm.o sparc64fbsd-kern.o" + ;; + sparc-*-netbsd* | sparc-*-knetbsd*-gnu) + # Target: NetBSD/sparc +@@ -662,7 +670,9 @@ x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu) + # Target: FreeBSD/amd64 + gdb_target_obs="amd64-tdep.o amd64fbsd-tdep.o i386-tdep.o \ + i387-tdep.o i386bsd-tdep.o i386fbsd-tdep.o \ +- bsd-uthread.o fbsd-tdep.o solib-svr4.o" ++ bsd-uthread.o fbsd-tdep.o solib-svr4.o \ ++ fbsd-kld.o fbsd-kthr.o fbsd-kvm.o amd64fbsd-kern.o \ ++ i386fbsd-kern.o" + ;; + x86_64-*-mingw* | x86_64-*-cygwin*) + # Target: MingW/amd64 diff --git a/devel/gdb/files/extrapatch-kgdb-configure.tgt-plain b/devel/gdb/files/extrapatch-kgdb-configure.tgt-plain deleted file mode 100644 index 72d1ac657419..000000000000 --- a/devel/gdb/files/extrapatch-kgdb-configure.tgt-plain +++ /dev/null @@ -1,50 +0,0 @@ -diff --git gdb/configure.tgt gdb/configure.tgt -index 4e4d6a9..57e4b3a 100644 ---- gdb/configure.tgt -+++ gdb/configure.tgt -@@ -185,7 +185,13 @@ i[34567]86-*-dicos*) - i[34567]86-*-freebsd* | i[34567]86-*-kfreebsd*-gnu) - # Target: FreeBSD/i386 - gdb_target_obs="i386-tdep.o i387-tdep.o i386bsd-tdep.o i386fbsd-tdep.o \ -- bsd-uthread.o fbsd-tdep.o solib-svr4.o" -+ bsd-uthread.o fbsd-tdep.o solib-svr4.o \ -+ fbsd-kld.o fbsd-kthr.o fbsd-kvm.o i386fbsd-kern.o" -+ if test "x$enable_64_bit_bfd" = "xyes"; then -+ # Target: FreeBSD amd64 -+ gdb_target_obs="amd64-tdep.o amd64fbsd-tdep.o amd64fbsd-kern.o \ -+ ${gdb_target_obs}" -+ fi - ;; - i[34567]86-*-netbsd* | i[34567]86-*-knetbsd*-gnu) - # Target: NetBSD/i386 -@@ -405,7 +411,8 @@ powerpc*-*-freebsd*) - # Target: FreeBSD/powerpc - gdb_target_obs="rs6000-tdep.o ppc-sysv-tdep.o ppc64-tdep.o \ - ppcfbsd-tdep.o fbsd-tdep.o solib-svr4.o \ -- ravenscar-thread.o ppc-ravenscar-thread.o" -+ ravenscar-thread.o ppc-ravenscar-thread.o \ -+ fbsd-kld.o fbsd-kthr.o fbsd-kvm.o ppcfbsd-kern.o" - ;; - - powerpc-*-netbsd* | powerpc-*-knetbsd*-gnu) -@@ -534,7 +541,8 @@ sparc*-*-freebsd* | sparc*-*-kfreebsd*-gnu) - # Target: FreeBSD/sparc64 - gdb_target_obs="sparc-tdep.o sparc64-tdep.o sparc64fbsd-tdep.o \ - fbsd-tdep.o solib-svr4.o \ -- ravenscar-thread.o sparc-ravenscar-thread.o" -+ ravenscar-thread.o sparc-ravenscar-thread.o \ -+ fbsd-kld.o fbsd-kthr.o fbsd-kvm.o sparc64fbsd-kern.o" - ;; - sparc-*-netbsd* | sparc-*-knetbsd*-gnu) - # Target: NetBSD/sparc -@@ -662,7 +670,9 @@ x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu) - # Target: FreeBSD/amd64 - gdb_target_obs="amd64-tdep.o amd64fbsd-tdep.o i386-tdep.o \ - i387-tdep.o i386bsd-tdep.o i386fbsd-tdep.o \ -- bsd-uthread.o fbsd-tdep.o solib-svr4.o" -+ bsd-uthread.o fbsd-tdep.o solib-svr4.o \ -+ fbsd-kld.o fbsd-kthr.o fbsd-kvm.o amd64fbsd-kern.o \ -+ i386fbsd-kern.o" - ;; - x86_64-*-mingw* | x86_64-*-cygwin*) - # Target: MingW/amd64 diff --git a/devel/gdb/files/extrapatch-kgdb-configure.tgt-threads b/devel/gdb/files/extrapatch-kgdb-configure.tgt-threads deleted file mode 100644 index f0f541889a1a..000000000000 --- a/devel/gdb/files/extrapatch-kgdb-configure.tgt-threads +++ /dev/null @@ -1,50 +0,0 @@ -diff --git gdb/configure.tgt gdb/configure.tgt -index 4e4d6a9..57e4b3a 100644 ---- gdb/configure.tgt -+++ gdb/configure.tgt -@@ -185,7 +185,13 @@ i[34567]86-*-dicos*) - i[34567]86-*-freebsd* | i[34567]86-*-kfreebsd*-gnu) - # Target: FreeBSD/i386 - gdb_target_obs="i386-tdep.o i387-tdep.o i386bsd-tdep.o i386fbsd-tdep.o \ -- fbsd-threads.o fbsd-tdep.o solib-svr4.o" -+ fbsd-threads.o fbsd-tdep.o solib-svr4.o \ -+ fbsd-kld.o fbsd-kthr.o fbsd-kvm.o i386fbsd-kern.o" -+ if test "x$enable_64_bit_bfd" = "xyes"; then -+ # Target: FreeBSD amd64 -+ gdb_target_obs="amd64-tdep.o amd64fbsd-tdep.o amd64fbsd-kern.o \ -+ ${gdb_target_obs}" -+ fi - ;; - i[34567]86-*-netbsd* | i[34567]86-*-knetbsd*-gnu) - # Target: NetBSD/i386 -@@ -405,7 +411,8 @@ powerpc*-*-freebsd*) - # Target: FreeBSD/powerpc - gdb_target_obs="rs6000-tdep.o ppc-sysv-tdep.o ppc64-tdep.o \ - ppcfbsd-tdep.o fbsd-threads.o fbsd-tdep.o solib-svr4.o \ -- ravenscar-thread.o ppc-ravenscar-thread.o" -+ ravenscar-thread.o ppc-ravenscar-thread.o \ -+ fbsd-kld.o fbsd-kthr.o fbsd-kvm.o ppcfbsd-kern.o" - ;; - - powerpc-*-netbsd* | powerpc-*-knetbsd*-gnu) -@@ -534,7 +541,8 @@ sparc*-*-freebsd* | sparc*-*-kfreebsd*-gnu) - # Target: FreeBSD/sparc64 - gdb_target_obs="sparc-tdep.o sparc64-tdep.o sparc64fbsd-tdep.o \ - fbsd-tdep.o solib-svr4.o \ -- ravenscar-thread.o sparc-ravenscar-thread.o" -+ ravenscar-thread.o sparc-ravenscar-thread.o \ -+ fbsd-kld.o fbsd-kthr.o fbsd-kvm.o sparc64fbsd-kern.o" - ;; - sparc-*-netbsd* | sparc-*-knetbsd*-gnu) - # Target: NetBSD/sparc -@@ -662,7 +670,9 @@ x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu) - # Target: FreeBSD/amd64 - gdb_target_obs="amd64-tdep.o amd64fbsd-tdep.o i386-tdep.o \ - i387-tdep.o i386bsd-tdep.o i386fbsd-tdep.o \ -- fbsd-threads.o fbsd-tdep.o solib-svr4.o" -+ fbsd-threads.o fbsd-tdep.o solib-svr4.o \ -+ fbsd-kld.o fbsd-kthr.o fbsd-kvm.o amd64fbsd-kern.o \ -+ i386fbsd-kern.o" - ;; - x86_64-*-mingw* | x86_64-*-cygwin*) - # Target: MingW/amd64 diff --git a/devel/gdb/files/extrapatch-threads b/devel/gdb/files/extrapatch-threads deleted file mode 100644 index 67f30c9dcdd2..000000000000 --- a/devel/gdb/files/extrapatch-threads +++ /dev/null @@ -1,712 +0,0 @@ -diff --git gdb/Makefile.in gdb/Makefile.in -index 7937801..6122f16 100644 ---- gdb/Makefile.in -+++ gdb/Makefile.in -@@ -691,6 +691,7 @@ ALL_TARGET_OBS = \ - xtensa-config.o xtensa-tdep.o xtensa-linux-tdep.o \ - glibc-tdep.o \ - bsd-uthread.o \ -+ fbsd-threads.o \ - nbsd-tdep.o obsd-tdep.o \ - sol2-tdep.o \ - solib-frv.o solib-svr4.o \ -@@ -1366,7 +1367,7 @@ libgdb.a: $(LIBGDB_OBS) - # Removing the old gdb first works better if it is running, at least on SunOS. - gdb$(EXEEXT): gdb.o $(LIBGDB_OBS) $(ADD_DEPS) $(CDEPS) $(TDEPLIBS) - rm -f gdb$(EXEEXT) -- $(CC_LD) $(INTERNAL_LDFLAGS) $(WIN32LDAPP) \ -+ $(CC_LD) $(INTERNAL_LDFLAGS) $(WIN32LDAPP) -Wl,-E \ - -o gdb$(EXEEXT) gdb.o $(LIBGDB_OBS) \ - $(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES) - -@@ -1639,7 +1640,7 @@ ALLDEPFILES = \ - armnbsd-nat.c armbsd-tdep.c armnbsd-tdep.c armobsd-tdep.c \ - avr-tdep.c \ - bfin-linux-tdep.c bfin-tdep.c \ -- bsd-uthread.c bsd-kvm.c \ -+ bsd-uthread.c fbsd-threads.c bsd-kvm.c \ - core-regset.c \ - dcache.c dicos-tdep.c darwin-nat.c \ - exec.c \ -diff --git gdb/amd64bsd-nat.c gdb/amd64bsd-nat.c -index b1d4a0e..7f189f6 100644 ---- gdb/amd64bsd-nat.c -+++ gdb/amd64bsd-nat.c -@@ -40,6 +40,19 @@ - size_t amd64bsd_xsave_len; - #endif - -+static pid_t -+ptrace_pid (ptid_t ptid) -+{ -+ pid_t pid; -+ -+#ifdef __FreeBSD__ -+ pid = ptid_get_lwp (ptid); -+ if (pid == 0) -+#endif -+ pid = ptid_get_pid (ptid); -+ return pid; -+} -+ - /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this - for all registers (including the floating-point registers). */ - -@@ -53,7 +66,7 @@ amd64bsd_fetch_inferior_registers (struct target_ops *ops, - { - struct reg regs; - -- if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) ®s, 0) == -1) - perror_with_name (_("Couldn't get registers")); - -@@ -71,7 +84,7 @@ amd64bsd_fetch_inferior_registers (struct target_ops *ops, - if (amd64bsd_xsave_len != 0) - { - xstateregs = alloca (amd64bsd_xsave_len); -- if (ptrace (PT_GETXSTATE, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETXSTATE, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) xstateregs, 0) == -1) - perror_with_name (_("Couldn't get extended state status")); - -@@ -80,7 +93,7 @@ amd64bsd_fetch_inferior_registers (struct target_ops *ops, - } - #endif - -- if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETFPREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) - perror_with_name (_("Couldn't get floating point status")); - -@@ -103,11 +116,11 @@ amd64bsd_store_inferior_registers (struct target_ops *ops, - - memset( ®s, 0, sizeof(struct reg)); - memset( &oldregs, 0, sizeof(struct reg)); -- if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) ®s, 0) == -1) - perror_with_name (_("Couldn't get registers")); - -- ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid), -+ ptrace (PT_GETREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &oldregs, 0); - amd64_collect_native_gregset (regcache, ®s, regnum); - -@@ -117,7 +130,7 @@ amd64bsd_store_inferior_registers (struct target_ops *ops, - regs.r_rflags ^= (regs.r_rflags ^ oldregs.r_rflags ) & ~PSL_USERCHANGE; - //printf(" allowed regs.r_rflags = 0x%8.8X\n", regs.r_rflags ); - } -- if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_SETREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) ®s, 0) == -1) - perror_with_name (_("Couldn't write registers")); - -@@ -134,26 +147,26 @@ amd64bsd_store_inferior_registers (struct target_ops *ops, - if (amd64bsd_xsave_len != 0) - { - xstateregs = alloca (amd64bsd_xsave_len); -- if (ptrace (PT_GETXSTATE, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETXSTATE, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) xstateregs, 0) == -1) - perror_with_name (_("Couldn't get extended state status")); - - amd64_collect_xsave (regcache, regnum, xstateregs, 0); - -- if (ptrace (PT_SETXSTATE, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_SETXSTATE, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) xstateregs, amd64bsd_xsave_len) == -1) - perror_with_name (_("Couldn't write extended state status")); - return; - } - #endif - -- if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETFPREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) - perror_with_name (_("Couldn't get floating point status")); - - amd64_collect_fxsave (regcache, regnum, &fpregs); - -- if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_SETFPREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) - perror_with_name (_("Couldn't write floating point status")); - } -@@ -183,7 +196,7 @@ amd64bsd_dr_get (ptid_t ptid, int regnum) - { - struct dbreg dbregs; - -- if (ptrace (PT_GETDBREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETDBREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &dbregs, 0) == -1) - perror_with_name (_("Couldn't read debug registers")); - -@@ -195,7 +208,7 @@ amd64bsd_dr_set (int regnum, unsigned long value) - { - struct dbreg dbregs; - -- if (ptrace (PT_GETDBREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETDBREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &dbregs, 0) == -1) - perror_with_name (_("Couldn't get debug registers")); - -@@ -206,7 +219,7 @@ amd64bsd_dr_set (int regnum, unsigned long value) - - DBREG_DRX ((&dbregs), regnum) = value; - -- if (ptrace (PT_SETDBREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_SETDBREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &dbregs, 0) == -1) - perror_with_name (_("Couldn't write debug registers")); - } -diff --git gdb/amd64fbsd-nat.c gdb/amd64fbsd-nat.c -index a721f48..2534360 100644 ---- gdb/amd64fbsd-nat.c -+++ gdb/amd64fbsd-nat.c -@@ -18,6 +18,7 @@ - along with this program. If not, see <http://www.gnu.org/licenses/>. */ - - #include "defs.h" -+#include "gregset.h" - #include "inferior.h" - #include "regcache.h" - #include "target.h" -@@ -92,6 +93,46 @@ static int amd64fbsd32_r_reg_offset[I386_NUM_GREGS] = - }; - - -+/* Transfering the registers between GDB, inferiors and core files. */ -+ -+/* Fill GDB's register array with the general-purpose register values -+ in *GREGSETP. */ -+ -+void -+supply_gregset (struct regcache *regcache, const gregset_t *gregsetp) -+{ -+ amd64_supply_native_gregset (regcache, gregsetp, -1); -+} -+ -+/* Fill register REGNUM (if it is a general-purpose register) in -+ *GREGSETPS with the value in GDB's register array. If REGNUM is -1, -+ do this for all registers. */ -+ -+void -+fill_gregset (const struct regcache *regcache, gdb_gregset_t *gregsetp, int regnum) -+{ -+ amd64_collect_native_gregset (regcache, gregsetp, regnum); -+} -+ -+/* Fill GDB's register array with the floating-point register values -+ in *FPREGSETP. */ -+ -+void -+supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp) -+{ -+ amd64_supply_fxsave (regcache, -1, fpregsetp); -+} -+ -+/* Fill register REGNUM (if it is a floating-point register) in -+ *FPREGSETP with the value in GDB's register array. If REGNUM is -1, -+ do this for all registers. */ -+ -+void -+fill_fpregset (const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regnum) -+{ -+ amd64_collect_fxsave (regcache, regnum, fpregsetp); -+} -+ - /* Support for debugging kernel virtual memory images. */ - - #include <machine/pcb.h> -diff --git gdb/amd64fbsd-tdep.c gdb/amd64fbsd-tdep.c -index 52705d9..6d48d8f 100644 ---- gdb/amd64fbsd-tdep.c -+++ gdb/amd64fbsd-tdep.c -@@ -28,7 +28,6 @@ - #include "x86-xstate.h" - - #include "amd64-tdep.h" --#include "bsd-uthread.h" - #include "fbsd-tdep.h" - #include "solib-svr4.h" - -@@ -226,46 +225,6 @@ amd64fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch, - } - - static void --amd64fbsd_supply_uthread (struct regcache *regcache, -- int regnum, CORE_ADDR addr) --{ -- gdb_byte buf[8]; -- int i; -- -- gdb_assert (regnum >= -1); -- -- for (i = 0; i < ARRAY_SIZE (amd64fbsd_jmp_buf_reg_offset); i++) -- { -- if (amd64fbsd_jmp_buf_reg_offset[i] != -1 -- && (regnum == -1 || regnum == i)) -- { -- read_memory (addr + amd64fbsd_jmp_buf_reg_offset[i], buf, 8); -- regcache_raw_supply (regcache, i, buf); -- } -- } --} -- --static void --amd64fbsd_collect_uthread (const struct regcache *regcache, -- int regnum, CORE_ADDR addr) --{ -- gdb_byte buf[8]; -- int i; -- -- gdb_assert (regnum >= -1); -- -- for (i = 0; i < ARRAY_SIZE (amd64fbsd_jmp_buf_reg_offset); i++) -- { -- if (amd64fbsd_jmp_buf_reg_offset[i] != -1 -- && (regnum == -1 || regnum == i)) -- { -- regcache_raw_collect (regcache, i, buf); -- write_memory (addr + amd64fbsd_jmp_buf_reg_offset[i], buf, 8); -- } -- } --} -- --static void - amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) - { - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); -@@ -298,10 +257,6 @@ amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) - set_gdbarch_core_read_description (gdbarch, - amd64fbsd_core_read_description); - -- /* FreeBSD provides a user-level threads implementation. */ -- bsd_uthread_set_supply_uthread (gdbarch, amd64fbsd_supply_uthread); -- bsd_uthread_set_collect_uthread (gdbarch, amd64fbsd_collect_uthread); -- - /* FreeBSD uses SVR4-style shared libraries. */ - set_solib_svr4_fetch_link_map_offsets - (gdbarch, svr4_lp64_fetch_link_map_offsets); -diff --git gdb/configure.tgt gdb/configure.tgt -index 7fdd34e..64afacf 100644 ---- gdb/configure.tgt -+++ gdb/configure.tgt -@@ -187,7 +187,7 @@ i[34567]86-*-dicos*) - i[34567]86-*-freebsd* | i[34567]86-*-kfreebsd*-gnu) - # Target: FreeBSD/i386 - gdb_target_obs="i386-tdep.o i387-tdep.o i386bsd-tdep.o i386fbsd-tdep.o \ -- bsd-uthread.o fbsd-tdep.o solib-svr4.o" -+ fbsd-threads.o fbsd-tdep.o solib-svr4.o" - ;; - i[34567]86-*-netbsd* | i[34567]86-*-knetbsd*-gnu) - # Target: NetBSD/i386 -@@ -410,7 +410,7 @@ nios2*-*-*) - powerpc*-*-freebsd*) - # Target: FreeBSD/powerpc - gdb_target_obs="rs6000-tdep.o ppc-sysv-tdep.o ppc64-tdep.o \ -- ppcfbsd-tdep.o fbsd-tdep.o solib-svr4.o \ -+ ppcfbsd-tdep.o fbsd-threads.o fbsd-tdep.o solib-svr4.o \ - ravenscar-thread.o ppc-ravenscar-thread.o" - ;; - -@@ -663,7 +663,7 @@ x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu) - # Target: FreeBSD/amd64 - gdb_target_obs="amd64-tdep.o amd64fbsd-tdep.o i386-tdep.o \ - i387-tdep.o i386bsd-tdep.o i386fbsd-tdep.o \ -- bsd-uthread.o fbsd-tdep.o solib-svr4.o" -+ fbsd-threads.o fbsd-tdep.o solib-svr4.o" - ;; - x86_64-*-mingw* | x86_64-*-cygwin*) - # Target: MingW/amd64 -diff --git gdb/i386bsd-nat.c gdb/i386bsd-nat.c -index ac8a19b..cb2d50e 100644 ---- gdb/i386bsd-nat.c -+++ gdb/i386bsd-nat.c -@@ -87,9 +87,22 @@ size_t i386bsd_xsave_len; - #endif - - -+static pid_t -+ptrace_pid (ptid_t ptid) -+{ -+ pid_t pid; -+ -+#ifdef __FreeBSD__ -+ pid = ptid_get_lwp (ptid); -+ if (pid == 0) -+#endif -+ pid = ptid_get_pid (ptid); -+ return pid; -+} -+ - /* Supply the general-purpose registers in GREGS, to REGCACHE. */ - --static void -+void - i386bsd_supply_gregset (struct regcache *regcache, const void *gregs) - { - const char *regs = gregs; -@@ -108,7 +121,7 @@ i386bsd_supply_gregset (struct regcache *regcache, const void *gregs) - GREGS. If REGNUM is -1, collect and store all appropriate - registers. */ - --static void -+void - i386bsd_collect_gregset (const struct regcache *regcache, - void *gregs, int regnum) - { -@@ -138,7 +151,7 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops, - { - struct reg regs; - -- if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) ®s, 0) == -1) - perror_with_name (_("Couldn't get registers")); - -@@ -160,7 +173,7 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops, - char *xstateregs; - - xstateregs = alloca (i386bsd_xsave_len); -- if (ptrace (PT_GETXSTATE, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETXSTATE, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) xstateregs, 0) == -1) - perror_with_name (_("Couldn't get extended state status")); - -@@ -171,7 +184,7 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops, - - #ifdef HAVE_PT_GETXMMREGS - if (have_ptrace_xmmregs != 0 -- && ptrace(PT_GETXMMREGS, ptid_get_pid (inferior_ptid), -+ && ptrace(PT_GETXMMREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) xmmregs, 0) == 0) - { - have_ptrace_xmmregs = 1; -@@ -181,7 +194,7 @@ i386bsd_fetch_inferior_registers (struct target_ops *ops, - { - have_ptrace_xmmregs = 0; - #endif -- if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETFPREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) - perror_with_name (_("Couldn't get floating point status")); - -@@ -203,13 +216,13 @@ i386bsd_store_inferior_registers (struct target_ops *ops, - { - struct reg regs; - -- if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) ®s, 0) == -1) - perror_with_name (_("Couldn't get registers")); - - i386bsd_collect_gregset (regcache, ®s, regnum); - -- if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_SETREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) ®s, 0) == -1) - perror_with_name (_("Couldn't write registers")); - -@@ -230,13 +243,13 @@ i386bsd_store_inferior_registers (struct target_ops *ops, - char *xstateregs; - - xstateregs = alloca (i386bsd_xsave_len); -- if (ptrace (PT_GETXSTATE, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETXSTATE, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) xstateregs, 0) == -1) - perror_with_name (_("Couldn't get extended state status")); - - i387_collect_xsave (regcache, -1, xstateregs, 0); - -- if (ptrace (PT_SETXSTATE, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_SETXSTATE, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) xstateregs, i386bsd_xsave_len) == -1) - perror_with_name (_("Couldn't write extended state status")); - return; -@@ -245,14 +258,14 @@ i386bsd_store_inferior_registers (struct target_ops *ops, - - #ifdef HAVE_PT_GETXMMREGS - if (have_ptrace_xmmregs != 0 -- && ptrace(PT_GETXMMREGS, ptid_get_pid (inferior_ptid), -+ && ptrace(PT_GETXMMREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) xmmregs, 0) == 0) - { - have_ptrace_xmmregs = 1; - - i387_collect_fxsave (regcache, regnum, xmmregs); - -- if (ptrace (PT_SETXMMREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_SETXMMREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) xmmregs, 0) == -1) - perror_with_name (_("Couldn't write XMM registers")); - } -@@ -260,13 +273,13 @@ i386bsd_store_inferior_registers (struct target_ops *ops, - { - have_ptrace_xmmregs = 0; - #endif -- if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETFPREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) - perror_with_name (_("Couldn't get floating point status")); - - i387_collect_fsave (regcache, regnum, &fpregs); - -- if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_SETFPREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) - perror_with_name (_("Couldn't write floating point status")); - #ifdef HAVE_PT_GETXMMREGS -@@ -305,7 +318,7 @@ i386bsd_dr_get (ptid_t ptid, int regnum) - { - struct dbreg dbregs; - -- if (ptrace (PT_GETDBREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETDBREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &dbregs, 0) == -1) - perror_with_name (_("Couldn't read debug registers")); - -@@ -317,7 +330,7 @@ i386bsd_dr_set (int regnum, unsigned int value) - { - struct dbreg dbregs; - -- if (ptrace (PT_GETDBREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETDBREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &dbregs, 0) == -1) - perror_with_name (_("Couldn't get debug registers")); - -@@ -328,7 +341,7 @@ i386bsd_dr_set (int regnum, unsigned int value) - - DBREG_DRX ((&dbregs), regnum) = value; - -- if (ptrace (PT_SETDBREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_SETDBREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &dbregs, 0) == -1) - perror_with_name (_("Couldn't write debug registers")); - } -diff --git gdb/i386bsd-nat.h gdb/i386bsd-nat.h -index 2f50c32..bf7f2ff 100644 ---- gdb/i386bsd-nat.h -+++ gdb/i386bsd-nat.h -@@ -38,6 +38,14 @@ extern CORE_ADDR i386bsd_dr_get_addr (int regnum); - - extern unsigned long i386bsd_dr_get_status (void); - -+/* low level i386 register functions used in i386fbsd-nat.c. */ -+ -+extern void i386bsd_supply_gregset (struct regcache *regcache, -+ const void *gregs); -+ -+extern void i386bsd_collect_gregset (const struct regcache *regcache, -+ void *gregs, int regnum); -+ - extern unsigned long i386bsd_dr_get_control (void); - - #endif /* i386bsd-nat.h */ -diff --git gdb/i386fbsd-nat.c gdb/i386fbsd-nat.c -index a205a26..29b9444 100644 ---- gdb/i386fbsd-nat.c -+++ gdb/i386fbsd-nat.c -@@ -21,6 +21,7 @@ - #include "inferior.h" - #include "regcache.h" - #include "target.h" -+#include "gregset.h" - - #include <sys/types.h> - #include <sys/ptrace.h> -@@ -81,6 +82,49 @@ i386fbsd_resume (struct target_ops *ops, - } - - -+/* Transfering the registers between GDB, inferiors and core files. */ -+ -+/* Fill GDB's register array with the general-purpose register values -+ in *GREGSETP. */ -+ -+void -+supply_gregset (struct regcache *regcache, const gregset_t *gregsetp) -+{ -+ i386bsd_supply_gregset (regcache, gregsetp); -+} -+ -+/* Fill register REGNUM (if it is a general-purpose register) in -+ *GREGSETPS with the value in GDB's register array. If REGNUM is -1, -+ do this for all registers. */ -+ -+void -+fill_gregset (const struct regcache *regcache, gdb_gregset_t *gregsetp, int regnum) -+{ -+ i386bsd_collect_gregset (regcache, gregsetp, regnum); -+} -+ -+#include "i387-tdep.h" -+ -+/* Fill GDB's register array with the floating-point register values -+ in *FPREGSETP. */ -+ -+void -+supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp) -+{ -+ i387_supply_fsave (regcache, -1, fpregsetp); -+} -+ -+/* Fill register REGNUM (if it is a floating-point register) in -+ *FPREGSETP with the value in GDB's register array. If REGNUM is -1, -+ do this for all registers. */ -+ -+void -+fill_fpregset (const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regnum) -+{ -+ i387_collect_fsave (regcache, regnum, fpregsetp); -+} -+ -+ - /* Support for debugging kernel virtual memory images. */ - - #include <machine/pcb.h> -diff --git gdb/i386fbsd-tdep.c gdb/i386fbsd-tdep.c -index 99e08cb..5bb15f6 100644 ---- gdb/i386fbsd-tdep.c -+++ gdb/i386fbsd-tdep.c -@@ -28,7 +28,6 @@ - - #include "i386-tdep.h" - #include "i387-tdep.h" --#include "bsd-uthread.h" - #include "fbsd-tdep.h" - #include "solib-svr4.h" - -@@ -333,46 +332,6 @@ i386fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch, - } - - static void --i386fbsd_supply_uthread (struct regcache *regcache, -- int regnum, CORE_ADDR addr) --{ -- gdb_byte buf[4]; -- int i; -- -- gdb_assert (regnum >= -1); -- -- for (i = 0; i < ARRAY_SIZE (i386fbsd_jmp_buf_reg_offset); i++) -- { -- if (i386fbsd_jmp_buf_reg_offset[i] != -1 -- && (regnum == -1 || regnum == i)) -- { -- read_memory (addr + i386fbsd_jmp_buf_reg_offset[i], buf, 4); -- regcache_raw_supply (regcache, i, buf); -- } -- } --} -- --static void --i386fbsd_collect_uthread (const struct regcache *regcache, -- int regnum, CORE_ADDR addr) --{ -- gdb_byte buf[4]; -- int i; -- -- gdb_assert (regnum >= -1); -- -- for (i = 0; i < ARRAY_SIZE (i386fbsd_jmp_buf_reg_offset); i++) -- { -- if (i386fbsd_jmp_buf_reg_offset[i] != -1 -- && (regnum == -1 || regnum == i)) -- { -- regcache_raw_collect (regcache, i, buf); -- write_memory (addr + i386fbsd_jmp_buf_reg_offset[i], buf, 4); -- } -- } --} -- --static void - i386fbsdaout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) - { - struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); -@@ -399,10 +358,6 @@ i386fbsdaout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) - /* FreeBSD has a more complete `struct sigcontext'. */ - tdep->sc_reg_offset = i386fbsd_sc_reg_offset; - tdep->sc_num_regs = ARRAY_SIZE (i386fbsd_sc_reg_offset); -- -- /* FreeBSD provides a user-level threads implementation. */ -- bsd_uthread_set_supply_uthread (gdbarch, i386fbsd_supply_uthread); -- bsd_uthread_set_collect_uthread (gdbarch, i386fbsd_collect_uthread); - } - - static void -diff --git gdb/ppcfbsd-nat.c gdb/ppcfbsd-nat.c -index 778b4bb..fa9285f 100644 ---- gdb/ppcfbsd-nat.c -+++ gdb/ppcfbsd-nat.c -@@ -37,6 +37,19 @@ - #include "inf-ptrace.h" - #include "bsd-kvm.h" - -+static pid_t -+ptrace_pid (ptid_t ptid) -+{ -+ pid_t pid; -+ -+#ifdef __FreeBSD__ -+ pid = ptid_get_lwp (ptid); -+ if (pid == 0) -+#endif -+ pid = ptid_get_pid (ptid); -+ return pid; -+} -+ - /* Fill GDB's register array with the general-purpose register values - in *GREGSETP. */ - -@@ -121,7 +134,7 @@ ppcfbsd_fetch_inferior_registers (struct target_ops *ops, - { - gdb_gregset_t regs; - -- if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) ®s, 0) == -1) - perror_with_name (_("Couldn't get registers")); - -@@ -132,7 +145,7 @@ ppcfbsd_fetch_inferior_registers (struct target_ops *ops, - const struct regset *fpregset = ppc_fbsd_fpregset (); - gdb_fpregset_t fpregs; - -- if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETFPREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) - perror_with_name (_("Couldn't get FP registers")); - -@@ -149,13 +162,13 @@ ppcfbsd_store_inferior_registers (struct target_ops *ops, - { - gdb_gregset_t regs; - -- if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) ®s, 0) == -1) - perror_with_name (_("Couldn't get registers")); - - fill_gregset (regcache, ®s, regno); - -- if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_SETREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) ®s, 0) == -1) - perror_with_name (_("Couldn't write registers")); - -@@ -163,13 +176,13 @@ ppcfbsd_store_inferior_registers (struct target_ops *ops, - { - gdb_fpregset_t fpregs; - -- if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_GETFPREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) - perror_with_name (_("Couldn't get FP registers")); - - fill_fpregset (regcache, &fpregs, regno); - -- if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid), -+ if (ptrace (PT_SETFPREGS, ptrace_pid (inferior_ptid), - (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) - perror_with_name (_("Couldn't set FP registers")); - } diff --git a/devel/gdb/files/fbsd-threads.c b/devel/gdb/files/fbsd-threads.c deleted file mode 100644 index 689128bb3e3f..000000000000 --- a/devel/gdb/files/fbsd-threads.c +++ /dev/null @@ -1,1619 +0,0 @@ -/* $FreeBSD$ */ -/* FreeBSD libthread_db assisted debugging support. - Copyright 1999, 2000, 2001 Free Software Foundation, Inc. - - This file is part of GDB. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ -#include <sys/param.h> -#include <sys/sysctl.h> -#include <sys/user.h> -#include <libutil.h> - -#include <dlfcn.h> -#include <sys/types.h> -#include <sys/ptrace.h> -#include <signal.h> - -#include "proc_service.h" -#include "thread_db.h" - -#include "defs.h" -#include "bfd.h" -#include "elf-bfd.h" -#include "gdb_assert.h" -#include "gdbcore.h" -#include "gdbthread.h" -#include "inferior.h" -#include "objfiles.h" -#include "regcache.h" -#include "symfile.h" -#include "symtab.h" -#include "target.h" -#include "observer.h" -#include "gdbcmd.h" -#include "gregset.h" -#ifdef PT_GETXMMREGS -#include "i387-tdep.h" -#endif - -#define LIBTHREAD_DB_SO "libthread_db.so" - -struct private_thread_info -{ - char *lwp_name; -}; - -struct ps_prochandle -{ - pid_t pid; -}; - -/* Defining the prototype of _initialize_thread_db to remove warning */ -extern initialize_file_ftype _initialize_thread_db; - -/* This module's target vectors. */ -static struct target_ops fbsd_thread_ops; - -/* Non-zero if there is a thread module */ -static int fbsd_thread_present; - -/* Non-zero if we're using this module's target vector. */ -static int fbsd_thread_active; - -/* Non-zero if we have to keep this module's target vector active - across re-runs. */ -static int keep_thread_db; - -/* Structure that identifies the child process for the - <proc_service.h> interface. */ -static struct ps_prochandle proc_handle; - -/* Connection to the libthread_db library. */ -static td_thragent_t *thread_agent; - -/* The last thread we are single stepping */ -static ptid_t last_single_step_thread; - - -/* Pointers to the libthread_db functions. */ -static td_err_e (*td_init_p) (void); - -static td_err_e (*td_ta_new_p) (struct ps_prochandle *ps, td_thragent_t **ta); -static td_err_e (*td_ta_delete_p) (td_thragent_t *); -static td_err_e (*td_ta_map_id2thr_p) (const td_thragent_t *ta, thread_t pt, - td_thrhandle_t *__th); -static td_err_e (*td_ta_map_lwp2thr_p) (const td_thragent_t *ta, lwpid_t lwpid, - td_thrhandle_t *th); -static td_err_e (*td_ta_thr_iter_p) (const td_thragent_t *ta, - td_thr_iter_f *callback, - void *cbdata_p, td_thr_state_e state, - int ti_pri, sigset_t *ti_sigmask_p, - unsigned int ti_user_flags); -static td_err_e (*td_ta_event_addr_p) (const td_thragent_t *ta, - td_event_e event, td_notify_t *ptr); -static td_err_e (*td_ta_set_event_p) (const td_thragent_t *ta, - td_thr_events_t *event); -static td_err_e (*td_ta_event_getmsg_p) (const td_thragent_t *ta, - td_event_msg_t *msg); -static td_err_e (*td_thr_get_info_p) (const td_thrhandle_t *th, - td_thrinfo_t *infop); -#ifdef PT_GETXMMREGS -static td_err_e (*td_thr_getxmmregs_p) (const td_thrhandle_t *th, - char *regset); -#endif -static td_err_e (*td_thr_getfpregs_p) (const td_thrhandle_t *th, - prfpregset_t *regset); -static td_err_e (*td_thr_getgregs_p) (const td_thrhandle_t *th, - prgregset_t gregs); -#ifdef PT_GETXMMREGS -static td_err_e (*td_thr_setxmmregs_p) (const td_thrhandle_t *th, - const char *fpregs); -#endif -static td_err_e (*td_thr_setfpregs_p) (const td_thrhandle_t *th, - const prfpregset_t *fpregs); -static td_err_e (*td_thr_setgregs_p) (const td_thrhandle_t *th, - prgregset_t gregs); -static td_err_e (*td_thr_event_enable_p) (const td_thrhandle_t *th, int event); - -static td_err_e (*td_thr_sstep_p) (td_thrhandle_t *th, int step); - -static td_err_e (*td_ta_tsd_iter_p) (const td_thragent_t *ta, - td_key_iter_f *func, void *data); -static td_err_e (*td_thr_tls_get_addr_p) (const td_thrhandle_t *th, - void *map_address, - size_t offset, void **address); -static td_err_e (*td_thr_dbsuspend_p) (const td_thrhandle_t *); -static td_err_e (*td_thr_dbresume_p) (const td_thrhandle_t *); - -static CORE_ADDR td_create_bp_addr; - -/* Location of the thread death event breakpoint. */ -static CORE_ADDR td_death_bp_addr; - -/* Prototypes for local functions. */ -static void fbsd_find_lwp_name(long lwpid, struct private_thread_info *info); -static void fbsd_thread_update_thread_list (struct target_ops *ops); -static int fbsd_thread_alive (struct target_ops *ops, ptid_t ptid); -static void attach_thread (ptid_t ptid, const td_thrhandle_t *th_p, - const td_thrinfo_t *ti_p, int verbose); -static void fbsd_thread_detach (struct target_ops *ops, const char *args, - int from_tty); - -CORE_ADDR fbsd_thread_get_local_address(struct target_ops *ops, - ptid_t ptid, CORE_ADDR lm, CORE_ADDR offset); - -/* Building process ids. */ - -#define GET_PID(ptid) ptid_get_pid (ptid) -#define GET_LWP(ptid) ptid_get_lwp (ptid) -#define GET_THREAD(ptid) ptid_get_tid (ptid) - -#define IS_LWP(ptid) (GET_LWP (ptid) != 0) -#define IS_THREAD(ptid) (GET_THREAD (ptid) != 0) - -#define BUILD_LWP(lwp, pid) ptid_build (pid, lwp, 0) -#define BUILD_THREAD(tid, pid) ptid_build (pid, 0, tid) - -static void -free_private_thread_info(struct private_thread_info *info) -{ - xfree(info->lwp_name); - xfree(info); -} - -static char * -thread_db_err_str (td_err_e err) -{ - static char buf[64]; - - switch (err) - { - case TD_OK: - return "generic 'call succeeded'"; - case TD_ERR: - return "generic error"; - case TD_NOTHR: - return "no thread to satisfy query"; - case TD_NOSV: - return "no sync handle to satisfy query"; - case TD_NOLWP: - return "no LWP to satisfy query"; - case TD_BADPH: - return "invalid process handle"; - case TD_BADTH: - return "invalid thread handle"; - case TD_BADSH: - return "invalid synchronization handle"; - case TD_BADTA: - return "invalid thread agent"; - case TD_BADKEY: - return "invalid key"; - case TD_NOMSG: - return "no event message for getmsg"; - case TD_NOFPREGS: - return "FPU register set not available"; - case TD_NOLIBTHREAD: - return "application not linked with libthread"; - case TD_NOEVENT: - return "requested event is not supported"; - case TD_NOCAPAB: - return "capability not available"; - case TD_DBERR: - return "debugger service failed"; - case TD_NOAPLIC: - return "operation not applicable to"; - case TD_NOTSD: - return "no thread-specific data for this thread"; - case TD_MALLOC: - return "malloc failed"; - case TD_PARTIALREG: - return "only part of register set was written/read"; - case TD_NOXREGS: - return "X register set not available for this thread"; - default: - snprintf (buf, sizeof (buf), "unknown thread_db error '%d'", err); - return buf; - } -} - -static char * -thread_db_state_str (td_thr_state_e state) -{ - static char buf[64]; - - switch (state) - { - case TD_THR_STOPPED: - return "stopped by debugger"; - case TD_THR_RUN: - return "runnable"; - case TD_THR_ACTIVE: - return "active"; - case TD_THR_ZOMBIE: - return "zombie"; - case TD_THR_SLEEP: - return "sleeping"; - case TD_THR_STOPPED_ASLEEP: - return "stopped by debugger AND blocked"; - default: - snprintf (buf, sizeof (buf), "unknown thread_db state %d", state); - return buf; - } -} - -/* Convert LWP to user-level thread id. */ -static ptid_t -thread_from_lwp (ptid_t ptid, td_thrhandle_t *th, td_thrinfo_t *ti) -{ - td_err_e err; - - gdb_assert (IS_LWP (ptid)); - - if (fbsd_thread_active) - { - err = td_ta_map_lwp2thr_p (thread_agent, GET_LWP (ptid), th); - if (err == TD_OK) - { - err = td_thr_get_info_p (th, ti); - if (err != TD_OK) - error ("Cannot get thread info: %s", thread_db_err_str (err)); - return BUILD_THREAD (ti->ti_tid, GET_PID (ptid)); - } - } - - /* the LWP is not mapped to user thread */ - return BUILD_LWP (GET_LWP (ptid), GET_PID (ptid)); -} - -static void -fbsd_core_get_first_lwp (bfd *abfd, asection *asect, void *obj) -{ - if (strncmp (bfd_section_name (abfd, asect), ".reg/", 5) != 0) - return; - - if (*(lwpid_t *)obj != 0) - return; - - *(lwpid_t *)obj = atoi (bfd_section_name (abfd, asect) + 5); -} - -static long -get_current_lwp (int pid) -{ - struct ptrace_lwpinfo pl; - lwpid_t lwpid; - - if (!target_has_execution) - { - lwpid = 0; - bfd_map_over_sections (core_bfd, fbsd_core_get_first_lwp, &lwpid); - return lwpid; - } - if (ptrace (PT_LWPINFO, pid, (caddr_t)&pl, sizeof(pl))) - perror_with_name("PT_LWPINFO"); - - return (long)pl.pl_lwpid; -} - -static void -get_current_thread (void) -{ - td_thrhandle_t th; - td_thrinfo_t ti; - long lwp; - ptid_t tmp, ptid; - - lwp = get_current_lwp (proc_handle.pid); - tmp = BUILD_LWP (lwp, proc_handle.pid); - ptid = thread_from_lwp (tmp, &th, &ti); - if (in_thread_list (inferior_ptid) ) - { - struct thread_info * ti_inf = inferior_thread(); - ti_inf->ptid = ptid; - } - if (!in_thread_list (ptid)) - { - attach_thread (ptid, &th, &ti, 1); - } - inferior_ptid = ptid; -} - -static CORE_ADDR -extract_func_ptr(void *value) -{ - - return (extract_typed_address - ((gdb_byte *)value, - builtin_type (target_gdbarch ())->builtin_func_ptr)); -} - -static CORE_ADDR -extract_data_ptr(void *value) -{ - - return (extract_typed_address - ((gdb_byte *)value, - builtin_type (target_gdbarch ())->builtin_data_ptr)); -} - -static td_err_e -enable_thread_event (td_thragent_t *thread_agent, int event, CORE_ADDR *bp) -{ - td_notify_t notify; - td_err_e err; - - /* Get the breakpoint address for thread EVENT. */ - err = td_ta_event_addr_p (thread_agent, event, ¬ify); - if (err != TD_OK) - return err; - - /* Set up the breakpoint. */ - (*bp) = (gdbarch_convert_from_func_ptr_addr - (target_gdbarch (), - extract_func_ptr(¬ify.u.bptaddr), - ¤t_target)); - create_thread_event_breakpoint (target_gdbarch (), (*bp)); - - return TD_OK; -} - -static void -enable_thread_event_reporting (void) -{ - td_thr_events_t events; - td_notify_t notify; - td_err_e err; - - /* We cannot use the thread event reporting facility if these - functions aren't available. */ - if (td_ta_event_addr_p == NULL || td_ta_set_event_p == NULL - || td_ta_event_getmsg_p == NULL || td_thr_event_enable_p == NULL) - return; - - /* Set the process wide mask saying which events we're interested in. */ - td_event_emptyset (&events); - td_event_addset (&events, TD_CREATE); - td_event_addset (&events, TD_DEATH); - - err = td_ta_set_event_p (thread_agent, &events); - if (err != TD_OK) - { - warning ("Unable to set global thread event mask: %s", - thread_db_err_str (err)); - return; - } - - /* Delete previous thread event breakpoints, if any. */ - remove_thread_event_breakpoints (); - td_create_bp_addr = 0; - td_death_bp_addr = 0; - - /* Set up the thread creation event. */ - err = enable_thread_event (thread_agent, TD_CREATE, &td_create_bp_addr); - if (err != TD_OK) - { - warning ("Unable to get location for thread creation breakpoint: %s", - thread_db_err_str (err)); - return; - } - - /* Set up the thread death event. */ - err = enable_thread_event (thread_agent, TD_DEATH, &td_death_bp_addr); - if (err != TD_OK) - { - warning ("Unable to get location for thread death breakpoint: %s", - thread_db_err_str (err)); - return; - } -} - -static void -disable_thread_event_reporting (void) -{ - td_thr_events_t events; - - /* Set the process wide mask saying we aren't interested in any - events anymore. */ - td_event_emptyset (&events); - td_ta_set_event_p (thread_agent, &events); - - td_create_bp_addr = 0; - td_death_bp_addr = 0; -} - -static void -fbsd_thread_activate (void) -{ - fbsd_thread_active = 1; - if (target_has_execution) - enable_thread_event_reporting (); - else - init_thread_list (); - fbsd_thread_update_thread_list (NULL); - get_current_thread (); -} - -static void -fbsd_thread_deactivate (void) -{ - if (target_has_execution) - disable_thread_event_reporting(); - td_ta_delete_p (thread_agent); - - inferior_ptid = pid_to_ptid (proc_handle.pid); - proc_handle.pid = 0; - fbsd_thread_active = 0; - fbsd_thread_present = 0; -} - -static void -check_for_thread_db (void) -{ - td_err_e err; - - if (td_ta_new_p == NULL) - return; - - /* Don't try to attach to a dead target if there is no core file. */ - if (!target_has_execution && core_bfd == NULL) - return; - - /* Nothing to do. The thread library was already detected and the - target vector was already activated. */ - if (fbsd_thread_active) - return; - - /* Now, initialize libthread_db. This needs to be done after the - shared libraries are located because it needs information from - the user's thread library. */ - - err = td_init_p (); - if (err != TD_OK) - { - warning ("Cannot initialize libthread_db: %s", thread_db_err_str (err)); - return; - } - - /* Initialize the structure that identifies the child process. Note - that at this point there is no guarantee that we actually have a - child process. */ - proc_handle.pid = GET_PID (inferior_ptid); - - /* Now attempt to open a connection to the thread library. */ - err = td_ta_new_p (&proc_handle, &thread_agent); - switch (err) - { - case TD_NOLIBTHREAD: - /* No thread library was detected. */ - break; - - case TD_OK: - /* The thread library was detected. Activate the thread_db target. */ - push_target(&fbsd_thread_ops); - fbsd_thread_present = 1; - fbsd_thread_activate(); - - break; - - default: - warning ("Cannot initialize thread debugging library: %s", - thread_db_err_str (err)); - break; - } -} - -static void -fbsd_thread_new_objfile (struct objfile *objfile) -{ - if (objfile != NULL) - check_for_thread_db (); -} - -static void -fbsd_thread_detach (struct target_ops *ops, const char *args, int from_tty) -{ - struct target_ops *beneath = find_target_beneath (ops); - - fbsd_thread_deactivate (); - - /* Delete thread event breakpoints, if any. */ - remove_thread_event_breakpoints (); - - unpush_target (&fbsd_thread_ops); - - beneath->to_detach (beneath, args, from_tty); -} - -static int -suspend_thread_callback (const td_thrhandle_t *th_p, void *data) -{ - int err = td_thr_dbsuspend_p (th_p); - if (err != 0) - fprintf_filtered(gdb_stderr, "%s %s\n", __func__, thread_db_err_str (err)); - return (err); -} - -static int -resume_thread_callback (const td_thrhandle_t *th_p, void *data) -{ - int err = td_thr_dbresume_p (th_p); - if (err != 0) - fprintf_filtered(gdb_stderr, "%s %s\n", __func__, thread_db_err_str (err)); - return (err); -} - -static void -fbsd_thread_resume (struct target_ops *ops, - ptid_t ptid, int step, enum gdb_signal signo) -{ - struct target_ops *beneath = find_target_beneath (ops); - td_thrhandle_t th; - td_thrinfo_t ti; - ptid_t work_ptid; - int resume_all, ret; - long lwp, thvalid = 0; - - if (!fbsd_thread_active) - { - // XXX: I don't think this can happen - printf_unfiltered ("%s: called without active threads\n", __func__); - beneath->to_resume (beneath, ptid, step, signo); - return; - } - - if (GET_PID(ptid) != -1 && step != 0) - { - resume_all = 0; - work_ptid = ptid; - } - else - { - resume_all = 1; - work_ptid = inferior_ptid; - } - - lwp = GET_LWP (work_ptid); - if (lwp == 0) - { - /* check user thread */ - ret = td_ta_map_id2thr_p (thread_agent, GET_THREAD(work_ptid), &th); - if (ret) - error ("%s: %s", __func__, thread_db_err_str (ret)); - - /* For M:N thread, we need to tell UTS to set/unset single step - flag at context switch time, the flag will be written into - thread mailbox. This becauses some architecture may not have - machine single step flag in ucontext, so we put the flag in mailbox, - when the thread switches back, kse_switchin restores the single step - state. */ - ret = td_thr_sstep_p (&th, step); - if (ret) - error ("%s: %s", __func__, thread_db_err_str (ret)); - ret = td_thr_get_info_p (&th, &ti); - if (ret) - error ("%s: %s", __func__, thread_db_err_str (ret)); - thvalid = 1; - lwp = ti.ti_lid; - } - - if (lwp) - { - int req = step ? PT_SETSTEP : PT_CLEARSTEP; - if (ptrace (req, (pid_t) lwp, (caddr_t) 1, gdb_signal_to_host(signo))) - perror_with_name ("PT_SETSTEP/PT_CLEARSTEP"); - } - - if (!ptid_equal (last_single_step_thread, null_ptid)) - { - ret = td_ta_thr_iter_p (thread_agent, resume_thread_callback, NULL, - TD_THR_ANY_STATE, TD_THR_LOWEST_PRIORITY, - TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS); - if (ret != TD_OK) - error ("resume error: %s", thread_db_err_str (ret)); - } - - if (!resume_all) - { - ret = td_ta_thr_iter_p (thread_agent, suspend_thread_callback, NULL, - TD_THR_ANY_STATE, TD_THR_LOWEST_PRIORITY, - TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS); - if (ret != TD_OK) - error ("suspend error: %s", thread_db_err_str (ret)); - last_single_step_thread = work_ptid; - } - else - last_single_step_thread = null_ptid; - - if (thvalid) - { - ret = td_thr_dbresume_p (&th); - if (ret != TD_OK) - error ("resume error: %s", thread_db_err_str (ret)); - } - else - { - /* it is not necessary, put it here for completness */ - ret = ptrace(PT_RESUME, lwp, 0, 0); - } - - /* now continue the process, suspended thread wont run */ - if (ptrace (PT_CONTINUE, proc_handle.pid , (caddr_t)1, - gdb_signal_to_host(signo))) - perror_with_name ("PT_CONTINUE"); -} - -static void -attach_thread (ptid_t ptid, const td_thrhandle_t *th_p, - const td_thrinfo_t *ti_p, int verbose) -{ - struct private_thread_info *private; - struct thread_info *tp = NULL; - char *lwpstr = NULL; - td_err_e err; - - /* Add the thread to GDB's thread list. */ - if (!in_thread_list (ptid)) - { - /* Add thread with info */ - private = xmalloc(sizeof(struct private_thread_info)); - gdb_assert(private != NULL); - // Thread name is assigned when printed - memset(private, 0, sizeof(struct private_thread_info)); - - tp = add_thread_with_info(ptid, private); - tp->priv = private; - tp->private_dtor = free_private_thread_info; - } - - if (ti_p->ti_state == TD_THR_UNKNOWN || ti_p->ti_state == TD_THR_ZOMBIE) - return; /* A zombie thread -- do not attach. */ - - if (! IS_THREAD(ptid)) - return; - if (!target_has_execution) - return; - /* Enable thread event reporting for this thread. */ - err = td_thr_event_enable_p (th_p, 1); - if (err != TD_OK) - error ("Cannot enable thread event reporting for %s: %s", - target_pid_to_str (ptid), thread_db_err_str (err)); -} - -static void -detach_thread (ptid_t ptid, int verbose) -{ - if (verbose) - printf_unfiltered ("[%s exited]\n", target_pid_to_str (ptid)); -} - -static void -check_event (ptid_t ptid) -{ - struct regcache *regcache = get_thread_regcache (ptid); - struct gdbarch *gdbarch = get_regcache_arch (regcache); - td_event_msg_t msg; - td_thrinfo_t ti; - td_err_e err; - CORE_ADDR stop_pc; - int loop = 0; - - /* Bail out early if we're not at a thread event breakpoint. */ - stop_pc = regcache_read_pc (regcache) - - gdbarch_decr_pc_after_break (gdbarch); - if (stop_pc != td_create_bp_addr && stop_pc != td_death_bp_addr) - return; - loop = 1; - - do - { - err = td_ta_event_getmsg_p (thread_agent, &msg); - if (err != TD_OK) - { - if (err == TD_NOMSG) - return; - error ("Cannot get thread event message: %s", - thread_db_err_str (err)); - } - err = td_thr_get_info_p ((void *)(uintptr_t)msg.th_p, &ti); - if (err != TD_OK) - error ("Cannot get thread info: %s", thread_db_err_str (err)); - ptid = BUILD_THREAD (ti.ti_tid, GET_PID (ptid)); - switch (msg.event) - { - case TD_CREATE: - /* We may already know about this thread, for instance when the - user has issued the `info threads' command before the SIGTRAP - for hitting the thread creation breakpoint was reported. */ - attach_thread (ptid, (void *)(uintptr_t)msg.th_p, &ti, 1); - break; - case TD_DEATH: - if (!in_thread_list (ptid)) - error ("Spurious thread death event."); - detach_thread (ptid, 1); - break; - default: - error ("Spurious thread event."); - } - } - while (loop); -} - -static ptid_t -fbsd_thread_wait (struct target_ops *ops, - ptid_t ptid, struct target_waitstatus *ourstatus, int options) -{ - struct target_ops *beneath = find_target_beneath (ops); - ptid_t ret; - long lwp; - CORE_ADDR stop_pc; - td_thrhandle_t th; - td_thrinfo_t ti; - - ret = beneath->to_wait (beneath, ptid, ourstatus, options); - if (GET_PID(ret) >= 0 && - ( ourstatus->kind == TARGET_WAITKIND_STOPPED || - ourstatus->kind == TARGET_WAITKIND_VFORKED || - ourstatus->kind == TARGET_WAITKIND_FORKED ) ) - { - lwp = get_current_lwp (GET_PID(ret)); - ret = thread_from_lwp (BUILD_LWP(lwp, GET_PID(ret)), - &th, &ti); - if (!in_thread_list(ret)) { - /* - * We have to enable event reporting for initial thread - * which was not mapped before. - */ - attach_thread(ret, &th, &ti, 1); - } - if (ourstatus->value.sig == GDB_SIGNAL_TRAP) - check_event(ret); - /* this is a hack, if an event won't cause gdb to stop, for example, - SIGALRM, gdb resumes the process immediatly without setting - inferior_ptid to the new thread returned here, this is a bug - because inferior_ptid may already not exist there, and passing - a non-existing thread to fbsd_thread_resume causes error. However, - if the exiting thread is the currently selected thread, - then that is handled later in handle_inferior_event(), and we must - not delete the currently selected thread. - */ - if (!fbsd_thread_alive (ops, inferior_ptid) && !ptid_equal(inferior_ptid, ret)) - { - ptid_t save_ptid; - save_ptid = inferior_ptid; - inferior_ptid = ret; - delete_thread (save_ptid); - } - } - - return (ret); -} - -static void -fbsd_thread_fetch_registers (struct target_ops *ops, - struct regcache *regcache, int regnum) -{ - prgregset_t gregset; - prfpregset_t fpregset; - td_thrhandle_t th; - td_thrinfo_t ti; - td_err_e err; -#ifdef PT_GETXMMREGS - char xmmregs[512]; -#endif - - if (!IS_THREAD (inferior_ptid)) - { - struct target_ops *beneath = find_target_beneath (ops); - - beneath->to_fetch_registers (ops, regcache, regnum); - return; - } - - err = td_ta_map_id2thr_p (thread_agent, GET_THREAD (inferior_ptid), &th); - if (err != TD_OK) - error ("Cannot find thread %d: Thread ID=%ld, %s", - pid_to_thread_id (inferior_ptid), - GET_THREAD (inferior_ptid), thread_db_err_str (err)); - - err = td_thr_get_info_p (&th, &ti); - if (err != TD_OK) - error ("Cannot get thread info, Thread ID=%ld, %s", - GET_THREAD (inferior_ptid), thread_db_err_str (err)); - - if (ti.ti_lid != 0) - { - struct target_ops *beneath = find_target_beneath (ops); - struct cleanup *old_chain; - - old_chain = save_inferior_ptid (); - - inferior_ptid = BUILD_LWP (ti.ti_lid, GET_PID (inferior_ptid)); - beneath->to_fetch_registers (ops, regcache, regnum); - - do_cleanups (old_chain); - return; - } - - err = td_thr_getgregs_p (&th, gregset); - if (err != TD_OK) - error ("Cannot fetch general-purpose registers for thread %d: Thread ID=%ld, %s", - pid_to_thread_id (inferior_ptid), - GET_THREAD (inferior_ptid), thread_db_err_str (err)); -#ifdef PT_GETXMMREGS - err = td_thr_getxmmregs_p (&th, xmmregs); - if (err == TD_OK) - { - i387_supply_fxsave (regcache, -1, xmmregs); - } - else - { -#endif - err = td_thr_getfpregs_p (&th, &fpregset); - if (err != TD_OK) - error ("Cannot get floating-point registers for thread %d: Thread ID=%ld, %s", - pid_to_thread_id (inferior_ptid), - GET_THREAD (inferior_ptid), thread_db_err_str (err)); - supply_fpregset (regcache, &fpregset); -#ifdef PT_GETXMMREGS - } -#endif - - supply_gregset (regcache, gregset); -} - -static void -fbsd_thread_store_registers (struct target_ops *ops, - struct regcache *regcache, int regnum) -{ - prgregset_t gregset; - prfpregset_t fpregset; - td_thrhandle_t th; - td_thrinfo_t ti; - td_err_e err; -#ifdef PT_GETXMMREGS - char xmmregs[512]; -#endif - - if (!IS_THREAD (inferior_ptid)) - { - struct target_ops *beneath = find_target_beneath (ops); - - beneath->to_store_registers (ops, regcache, regnum); - return; - } - - err = td_ta_map_id2thr_p (thread_agent, GET_THREAD (inferior_ptid), &th); - if (err != TD_OK) - error ("Cannot find thread %d: Thread ID=%ld, %s", - pid_to_thread_id (inferior_ptid), - GET_THREAD (inferior_ptid), - thread_db_err_str (err)); - - err = td_thr_get_info_p (&th, &ti); - if (err != TD_OK) - error ("Cannot get thread info, Thread ID=%ld, %s", - GET_THREAD (inferior_ptid), thread_db_err_str (err)); - - if (ti.ti_lid != 0) - { - struct target_ops *beneath = find_target_beneath (ops); - struct cleanup *old_chain; - - old_chain = save_inferior_ptid (); - - inferior_ptid = BUILD_LWP (ti.ti_lid, GET_PID (inferior_ptid)); - beneath->to_store_registers (ops, regcache, regnum); - - do_cleanups (old_chain); - return; - } - - if (regnum != -1) - { - char old_value[MAX_REGISTER_SIZE]; - - regcache_raw_collect (regcache, regnum, old_value); - err = td_thr_getgregs_p (&th, gregset); - if (err != TD_OK) - error ("%s: td_thr_getgregs %s", __func__, thread_db_err_str (err)); -#ifdef PT_GETXMMREGS - err = td_thr_getxmmregs_p (&th, xmmregs); - if (err != TD_OK) - { -#endif - err = td_thr_getfpregs_p (&th, &fpregset); - if (err != TD_OK) - error ("%s: td_thr_getfpgregs %s", __func__, thread_db_err_str (err)); -#ifdef PT_GETXMMREGS - } -#endif - regcache_raw_supply (regcache, regnum, old_value); - } - - fill_gregset (regcache, gregset, regnum); - err = td_thr_setgregs_p (&th, gregset); - if (err != TD_OK) - error ("Cannot store general-purpose registers for thread %d: Thread ID=%ld, %s", - pid_to_thread_id (inferior_ptid), GET_THREAD (inferior_ptid), - thread_db_err_str (err)); - -#ifdef PT_GETXMMREGS - i387_collect_fxsave (regcache, regnum, xmmregs); - err = td_thr_setxmmregs_p (&th, xmmregs); - if (err == TD_OK) - return; -#endif - - fill_fpregset (regcache, &fpregset, regnum); - err = td_thr_setfpregs_p (&th, &fpregset); - if (err != TD_OK) - error ("Cannot store floating-point registers for thread %d: Thread ID=%ld, %s", - pid_to_thread_id (inferior_ptid), GET_THREAD (inferior_ptid), - thread_db_err_str (err)); -} - -static void -fbsd_thread_mourn_inferior (struct target_ops *ops) -{ - struct target_ops *beneath = find_target_beneath (ops); - - fbsd_thread_deactivate (); - - beneath->to_mourn_inferior (beneath); - - /* Delete thread event breakpoints, if any. */ - remove_thread_event_breakpoints (); - - unpush_target (ops); -} - -static void -fbsd_core_check_lwp (bfd *abfd, asection *asect, void *obj) -{ - lwpid_t lwp; - - if (strncmp (bfd_section_name (abfd, asect), ".reg/", 5) != 0) - return; - - /* already found */ - if (*(lwpid_t *)obj == 0) - return; - - lwp = atoi (bfd_section_name (abfd, asect) + 5); - if (*(lwpid_t *)obj == lwp) - *(lwpid_t *)obj = 0; -} - -static int -fbsd_thread_alive (struct target_ops *ops, ptid_t ptid) -{ - td_thrhandle_t th; - td_thrinfo_t ti; - td_err_e err; - gregset_t gregs; - lwpid_t lwp; - - if (IS_THREAD (ptid)) - { - err = td_ta_map_id2thr_p (thread_agent, GET_THREAD (ptid), &th); - if (err != TD_OK) - return 0; - - err = td_thr_get_info_p (&th, &ti); - if (err != TD_OK) - return 0; - - /* A zombie thread. */ - if (ti.ti_state == TD_THR_UNKNOWN || ti.ti_state == TD_THR_ZOMBIE) - return 0; - - return 1; - } - else if (GET_LWP (ptid) == 0) - { - /* we sometimes are called with lwp == 0 */ - return 1; - } - - if (fbsd_thread_active) - { - err = td_ta_map_lwp2thr_p (thread_agent, GET_LWP (ptid), &th); - - /* - * if the lwp was already mapped to user thread, don't use it - * directly, please use user thread id instead. - */ - if (err == TD_OK) - return 0; - } - - if (!target_has_execution) - { - lwp = GET_LWP (ptid); - bfd_map_over_sections (core_bfd, fbsd_core_check_lwp, &lwp); - return (lwp == 0); - } - - /* check lwp in kernel */ - return ptrace (PT_GETREGS, GET_LWP (ptid), (caddr_t)&gregs, 0) == 0; -} - -static int -update_thread_list_callback (const td_thrhandle_t *th_p, void *data) -{ - td_thrinfo_t ti; - td_err_e err; - ptid_t ptid; - - err = td_thr_get_info_p (th_p, &ti); - if (err != TD_OK) - error ("Cannot get thread info: %s", thread_db_err_str (err)); - - /* Ignore zombie */ - if (ti.ti_state == TD_THR_UNKNOWN || ti.ti_state == TD_THR_ZOMBIE) - return 0; - - ptid = BUILD_THREAD (ti.ti_tid, proc_handle.pid); - attach_thread (ptid, th_p, &ti, 1); - return 0; -} - -static void -fbsd_thread_update_thread_list (struct target_ops *ops) -{ - td_err_e err; - - /* Delete dead threads. */ - prune_threads(); - - /* Iterate over all user-space threads to discover new threads. */ - err = td_ta_thr_iter_p (thread_agent, update_thread_list_callback, NULL, - TD_THR_ANY_STATE, TD_THR_LOWEST_PRIORITY, - TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS); - if (err != TD_OK) - error ("Cannot find new threads: %s", thread_db_err_str (err)); -} - -static void -fbsd_find_lwp_name(long lwpid, struct private_thread_info *info) -{ - struct cleanup *old_chain; - int error, name[4]; - unsigned int i; - struct kinfo_proc *kipp, *kip; - char *lwpstr = info->lwp_name; - int pid = inferior_ptid.pid; - size_t len = 0; - - if (!target_has_execution) - return; - - name[0] = CTL_KERN; - name[1] = KERN_PROC; - name[2] = KERN_PROC_PID | KERN_PROC_INC_THREAD; - name[3] = pid; - - error = sysctl(name, 4, NULL, &len, NULL, 0); - if (error < 0) { - if (errno != ESRCH) - warning (_("sysctl: kern.proc.pid: %d: %s"), pid, - safe_strerror (errno)); - return; - } - - kip = xmalloc(len); - if (kip == NULL) - return; - old_chain = make_cleanup(xfree, kip); - - if (sysctl(name, 4, kip, &len, NULL, 0) < 0) { - warning (_("sysctl: kern.proc.pid: %d: %s"), pid, safe_strerror(errno)); - do_cleanups(old_chain); - return; - } - - for (i = 0; i < len / sizeof(*kipp); i++) { - kipp = &kip[i]; - if ((kipp->ki_tid == lwpid) && strlen(kipp->ki_ocomm) && - (strcmp(kipp->ki_comm, kipp->ki_ocomm) != 0)) - { - // Found the LWP, update the name field - if (lwpstr != NULL) - { - if (strcmp(lwpstr, kipp->ki_ocomm) != 0) - { - xfree(lwpstr); - } - else - { - // Name hasn't changed, just return - break; - } - } - - lwpstr = xstrdup(kipp->ki_ocomm); - info->lwp_name = lwpstr; - break; - } - } - - do_cleanups(old_chain); -} - -static char * -fbsd_thread_pid_to_str (struct target_ops *ops, ptid_t ptid) -{ - static char buf[64]; - struct thread_info *tinfo = NULL; - - if (IS_THREAD (ptid)) - { - td_thrhandle_t th; - td_thrinfo_t ti; - td_err_e err; - - err = td_ta_map_id2thr_p (thread_agent, GET_THREAD (ptid), &th); - if (err != TD_OK) - error ("Cannot find thread, Thread ID=%ld, %s", - GET_THREAD (ptid), thread_db_err_str (err)); - - err = td_thr_get_info_p (&th, &ti); - if (err != TD_OK) - error ("Cannot get thread info, Thread ID=%ld, %s", - GET_THREAD (ptid), thread_db_err_str (err)); - - tinfo = find_thread_ptid(ptid); - gdb_assert(tinfo != NULL); - - if (ti.ti_lid != 0) - { - // Need to find the name of this LWP, even though it shouldn't change - fbsd_find_lwp_name(ti.ti_lid, tinfo->priv); - - if (tinfo->priv->lwp_name == NULL) - { - snprintf(buf, sizeof (buf), "Thread %llx (LWP %d)", - (unsigned long long)th.th_thread, ti.ti_lid); - } - else - { - snprintf(buf, sizeof (buf), "Thread %llx (LWP %d %s)", - (unsigned long long)th.th_thread, ti.ti_lid, - tinfo->priv->lwp_name); - } - } - else - { - snprintf (buf, sizeof (buf), "Thread %llx (%s)", - (unsigned long long)th.th_thread, - thread_db_state_str (ti.ti_state)); - } - - return buf; - } - else if (IS_LWP (ptid)) - { - snprintf (buf, sizeof (buf), "LWP %d", (int) GET_LWP (ptid)); - return buf; - } - return normal_pid_to_str (ptid); -} - -CORE_ADDR -fbsd_thread_get_local_address(struct target_ops *ops, - ptid_t ptid, - CORE_ADDR lm, - CORE_ADDR offset) -{ - td_thrhandle_t th; - void *address; - int ret; - - if (IS_THREAD (ptid)) - { - if (!td_thr_tls_get_addr_p) - error ("Cannot find thread-local interface in thread_db library."); - - ret = td_ta_map_id2thr_p (thread_agent, GET_THREAD(ptid), &th); - - /* get the address of the variable. */ - ret = td_thr_tls_get_addr_p (&th, (void *)lm, offset, &address); - - if (ret != TD_OK) - { - error ("Cannot find thread-local storage for thread %ld\n%s", - (long) GET_THREAD (ptid), thread_db_err_str (ret)); - } - - /* Cast assuming host == target. */ - return extract_data_ptr (&address); - } - return (0); -} - -static int -tsd_cb (thread_key_t key, void (*destructor)(void *), void *ignore) -{ - struct bound_minimal_symbol bms; - const char *name; - - bms = lookup_minimal_symbol_by_pc (extract_func_ptr (&destructor)); - if (!bms.minsym) - name = "???"; - else - name = MSYMBOL_PRINT_NAME (bms.minsym); - - printf_filtered ("Key %d, destructor %p <%s>\n", key, destructor, name); - return 0; -} - -static void -fbsd_thread_tsd_cmd (char *exp, int from_tty) -{ - if (fbsd_thread_active) - td_ta_tsd_iter_p (thread_agent, tsd_cb, NULL); -} - -static void -fbsd_print_sigset (sigset_t *set) -{ - int i; - - for (i = 1; i <= _SIG_MAXSIG; ++i) { - if (sigismember(set, i)) { - if (i < sizeof(sys_signame)/sizeof(sys_signame[0])) - printf_filtered("%s ", sys_signame[i]); - else - printf_filtered("sig%d ", i); - } - } - printf_filtered("\n"); -} - -static void -fbsd_thread_signal_cmd (char *exp, int from_tty) -{ - td_thrhandle_t th; - td_thrinfo_t ti; - td_err_e err; -#ifdef PL_FLAG_SI - const char *code; -#endif - - if (!fbsd_thread_active || !IS_THREAD(inferior_ptid)) - return; - - err = td_ta_map_id2thr_p (thread_agent, GET_THREAD (inferior_ptid), &th); - if (err != TD_OK) - return; - - err = td_thr_get_info_p (&th, &ti); - if (err != TD_OK) - return; - - printf_filtered("signal mask:\n"); - fbsd_print_sigset(&ti.ti_sigmask); - printf_filtered("signal pending:\n"); - fbsd_print_sigset(&ti.ti_pending); -#ifdef PL_FLAG_SI - if (ti.ti_siginfo.si_signo != 0) { - printf_filtered("si_signo %d si_errno %d", ti.ti_siginfo.si_signo, - ti.ti_siginfo.si_errno); - if (ti.ti_siginfo.si_errno != 0) - printf_filtered(" (%s)", strerror(ti.ti_siginfo.si_errno)); - printf_filtered("\n"); - switch (ti.ti_siginfo.si_code) { - case SI_NOINFO: - code = "NOINFO"; - break; - case SI_USER: - code = "USER"; - break; - case SI_QUEUE: - code = "QUEUE"; - break; - case SI_TIMER: - code = "TIMER"; - break; - case SI_ASYNCIO: - code = "ASYNCIO"; - break; - case SI_MESGQ: - code = "MESGQ"; - break; - case SI_KERNEL: - code = "KERNEL"; - break; - default: - code = "UNKNOWN"; - break; - } - printf_filtered("si_code %s si_pid %d si_uid %d si_status %x si_addr %p\n", - code, ti.ti_siginfo.si_pid, ti.ti_siginfo.si_uid, ti.ti_siginfo.si_status, - ti.ti_siginfo.si_addr); - } -#endif -} - -static void -init_fbsd_thread_ops (void) -{ - fbsd_thread_ops.to_shortname = "freebsd-threads"; - fbsd_thread_ops.to_longname = "FreeBSD multithreaded child process."; - fbsd_thread_ops.to_doc = "FreeBSD threads support."; - fbsd_thread_ops.to_detach = fbsd_thread_detach; - fbsd_thread_ops.to_resume = fbsd_thread_resume; - fbsd_thread_ops.to_wait = fbsd_thread_wait; - fbsd_thread_ops.to_fetch_registers = fbsd_thread_fetch_registers; - fbsd_thread_ops.to_store_registers = fbsd_thread_store_registers; - fbsd_thread_ops.to_mourn_inferior = fbsd_thread_mourn_inferior; - fbsd_thread_ops.to_thread_alive = fbsd_thread_alive; - fbsd_thread_ops.to_update_thread_list = fbsd_thread_update_thread_list; - fbsd_thread_ops.to_pid_to_str = fbsd_thread_pid_to_str; - fbsd_thread_ops.to_stratum = thread_stratum; - fbsd_thread_ops.to_get_thread_local_address = fbsd_thread_get_local_address; - fbsd_thread_ops.to_magic = OPS_MAGIC; -} - -static int -thread_db_load (void) -{ - void *handle; - td_err_e err; - - handle = dlopen (LIBTHREAD_DB_SO, RTLD_NOW); - if (handle == NULL) - return 0; - -#define resolve(X) \ - if (!(X##_p = dlsym (handle, #X))) \ - return 0; - - resolve(td_init); - resolve(td_ta_new); - resolve(td_ta_delete); - resolve(td_ta_map_id2thr); - resolve(td_ta_map_lwp2thr); - resolve(td_ta_thr_iter); - resolve(td_thr_get_info); -#ifdef PT_GETXMMREGS - resolve(td_thr_getxmmregs); -#endif - resolve(td_thr_getfpregs); - resolve(td_thr_getgregs); -#ifdef PT_GETXMMREGS - resolve(td_thr_setxmmregs); -#endif - resolve(td_thr_setfpregs); - resolve(td_thr_setgregs); - resolve(td_thr_sstep); - resolve(td_ta_tsd_iter); - resolve(td_thr_dbsuspend); - resolve(td_thr_dbresume); - resolve(td_thr_tls_get_addr); - - /* These are not essential. */ - td_ta_event_addr_p = dlsym (handle, "td_ta_event_addr"); - td_ta_set_event_p = dlsym (handle, "td_ta_set_event"); - td_ta_event_getmsg_p = dlsym (handle, "td_ta_event_getmsg"); - td_thr_event_enable_p = dlsym (handle, "td_thr_event_enable"); - td_thr_tls_get_addr_p = dlsym (handle, "td_thr_tls_get_addr"); - - return 1; -} - -void -_initialize_thread_db (void) -{ - - init_fbsd_thread_ops (); - - if (thread_db_load ()) - { - add_target (&fbsd_thread_ops); - - /* "thread tsd" command */ - add_cmd ("tsd", class_run, fbsd_thread_tsd_cmd, - "Show the thread-specific data keys and destructors " - "for the process.\n", - &thread_cmd_list); - - add_cmd ("signal", class_run, fbsd_thread_signal_cmd, - "Show the thread signal info.\n", - &thread_cmd_list); - - /* Hook into new_objfile notification. */ - observer_attach_new_objfile (fbsd_thread_new_objfile); - } - else - { - fprintf_unfiltered (gdb_stderr, - "[GDB will not be able to debug user-mode threads: %s]\n", dlerror()); - } -} - -/* proc service functions */ -void -ps_plog (const char *fmt, ...) -{ - va_list args; - - va_start (args, fmt); - vfprintf_filtered (gdb_stderr, fmt, args); - va_end (args); -} - -ps_err_e -ps_pglobal_lookup (struct ps_prochandle *ph, const char *obj, - const char *name, psaddr_t *sym_addr) -{ - struct bound_minimal_symbol ms; - CORE_ADDR addr; - - ms = lookup_minimal_symbol (name, NULL, NULL); - if (!ms.minsym) - return PS_NOSYM; - - *sym_addr = BMSYMBOL_VALUE_ADDRESS (ms); - return PS_OK; -} - -ps_err_e -ps_pread (struct ps_prochandle *ph, psaddr_t addr, void *buf, size_t len) -{ - int err = target_read_memory (extract_data_ptr (&addr), buf, len); - return (err == 0 ? PS_OK : PS_ERR); -} - -ps_err_e -ps_pwrite (struct ps_prochandle *ph, psaddr_t addr, const void *buf, - size_t len) -{ - int err = target_write_memory (extract_data_ptr (&addr), (void *)buf, len); - return (err == 0 ? PS_OK : PS_ERR); -} - -ps_err_e -ps_lgetregs (struct ps_prochandle *ph, lwpid_t lwpid, prgregset_t gregset) -{ - struct cleanup *old_chain; - struct regcache *regcache; - - old_chain = save_inferior_ptid (); - - inferior_ptid = BUILD_LWP (lwpid, ph->pid); - regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ()); - - target_fetch_registers (regcache, -1); - fill_gregset (regcache, gregset, -1); - do_cleanups (old_chain); - return PS_OK; -} - -ps_err_e -ps_lsetregs (struct ps_prochandle *ph, lwpid_t lwpid, const prgregset_t gregset) -{ - struct cleanup *old_chain; - struct regcache *regcache; - - old_chain = save_inferior_ptid (); - inferior_ptid = BUILD_LWP (lwpid, ph->pid); - regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ()); - - supply_gregset (regcache, gregset); - target_store_registers (regcache, -1); - do_cleanups (old_chain); - return PS_OK; -} - -ps_err_e -ps_lgetfpregs (struct ps_prochandle *ph, lwpid_t lwpid, prfpregset_t *fpregset) -{ - struct cleanup *old_chain; - struct regcache *regcache; - - old_chain = save_inferior_ptid (); - inferior_ptid = BUILD_LWP (lwpid, ph->pid); - regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ()); - - target_fetch_registers (regcache, -1); - fill_fpregset (regcache, fpregset, -1); - do_cleanups (old_chain); - return PS_OK; -} - -ps_err_e -ps_lsetfpregs (struct ps_prochandle *ph, lwpid_t lwpid, - const prfpregset_t *fpregset) -{ - struct cleanup *old_chain; - struct regcache *regcache; - - old_chain = save_inferior_ptid (); - inferior_ptid = BUILD_LWP (lwpid, ph->pid); - regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ()); - - supply_fpregset (regcache, fpregset); - target_store_registers (regcache, -1); - do_cleanups (old_chain); - return PS_OK; -} - -#ifdef PT_GETXMMREGS -ps_err_e -ps_lgetxmmregs (struct ps_prochandle *ph, lwpid_t lwpid, char *xmmregs) -{ - struct cleanup *old_chain; - struct regcache *regcache; - - old_chain = save_inferior_ptid (); - inferior_ptid = BUILD_LWP (lwpid, ph->pid); - regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ()); - - target_fetch_registers (regcache, -1); - i387_collect_fxsave (regcache, -1, xmmregs); - do_cleanups (old_chain); - return PS_OK; -} - -ps_err_e -ps_lsetxmmregs (struct ps_prochandle *ph, lwpid_t lwpid, - const char *xmmregs) -{ - struct cleanup *old_chain; - struct regcache *regcache; - - old_chain = save_inferior_ptid (); - inferior_ptid = BUILD_LWP (lwpid, ph->pid); - regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ()); - - i387_supply_fxsave (regcache, -1, xmmregs); - target_store_registers (regcache, -1); - do_cleanups (old_chain); - return PS_OK; -} -#endif - -ps_err_e -ps_lstop(struct ps_prochandle *ph, lwpid_t lwpid) -{ - if (ptrace (PT_SUSPEND, lwpid, 0, 0) == -1) - return PS_ERR; - return PS_OK; -} - -ps_err_e -ps_lcontinue(struct ps_prochandle *ph, lwpid_t lwpid) -{ - if (ptrace (PT_RESUME, lwpid, 0, 0) == -1) - return PS_ERR; - return PS_OK; -} - -ps_err_e -ps_linfo(struct ps_prochandle *ph, lwpid_t lwpid, void *info) -{ - if (!target_has_execution) { - /* XXX should verify lwpid and make a pseudo lwp info */ - memset(info, 0, sizeof(struct ptrace_lwpinfo)); - return PS_OK; - } - - if (ptrace (PT_LWPINFO, lwpid, info, sizeof(struct ptrace_lwpinfo)) == -1) - return PS_ERR; - return PS_OK; -} diff --git a/devel/gdb/files/kgdb/fbsd-kvm.c b/devel/gdb/files/kgdb/fbsd-kvm.c index 1be599b87d0e..3ef3f9c78919 100644 --- a/devel/gdb/files/kgdb/fbsd-kvm.c +++ b/devel/gdb/files/kgdb/fbsd-kvm.c @@ -478,7 +478,7 @@ kgdb_switch_to_thread(int tid) char buf[16]; int thread_id; - thread_id = pid_to_thread_id(fbsd_vmcore_ptid(tid)); + thread_id = ptid_to_global_thread_id(fbsd_vmcore_ptid(tid)); if (thread_id == 0) error ("invalid tid"); snprintf(buf, sizeof(buf), "%d", thread_id); diff --git a/devel/gdb/files/patch-armfbsd b/devel/gdb/files/patch-armfbsd index 0be9fb6cc191..4223d2da0858 100644 --- a/devel/gdb/files/patch-armfbsd +++ b/devel/gdb/files/patch-armfbsd @@ -347,20 +347,21 @@ diff --git gdb/Makefile.in gdb/Makefile.in index dfaa8a3..ddad28d 100644 --- gdb/Makefile.in +++ gdb/Makefile.in -@@ -655,7 +655,7 @@ ALL_64_TARGET_OBS = \ - # All other target-dependent objects files (used with --enable-targets=all). +@@ -659,7 +659,7 @@ ALL_TARGET_OBS = \ - armbsd-tdep.o arm-linux-tdep.o arm-symbian-tdep.o \ + armbsd-tdep.o arm.o arm-linux.o arm-linux-tdep.o \ + arm-get-next-pcs.o arm-symbian-tdep.o \ - armnbsd-tdep.o armobsd-tdep.o \ + armnbsd-tdep.o armobsd-tdep.o armfbsd-tdep.o \ arm-tdep.o arm-wince-tdep.o \ avr-tdep.o \ bfin-linux-tdep.o bfin-tdep.o \ -@@ -1660,6 +1660,6 @@ ALLDEPFILES = \ - amd64-linux-nat.c amd64-linux-tdep.c \ - amd64-sol2-tdep.c \ - arm-linux-nat.c arm-linux-tdep.c arm-symbian-tdep.c arm-tdep.c \ +@@ -1666,7 +1666,7 @@ + arm.c arm-get-next-pcs.c \ + arm-linux.c arm-linux-nat.c arm-linux-tdep.c \ + arm-symbian-tdep.c arm-tdep.c \ - armnbsd-nat.c armbsd-tdep.c armnbsd-tdep.c armobsd-tdep.c \ + armnbsd-nat.c armbsd-tdep.c armnbsd-tdep.c armobsd-tdep.c armfbsd-tdep.c \ avr-tdep.c \ bfin-linux-tdep.c bfin-tdep.c \ + bsd-uthread.c bsd-kvm.c \ diff --git a/devel/gdb/files/patch-gdb-amd64bsd-nat.c b/devel/gdb/files/patch-gdb-amd64bsd-nat.c index 4ec19126faa1..7787a495e69c 100644 --- a/devel/gdb/files/patch-gdb-amd64bsd-nat.c +++ b/devel/gdb/files/patch-gdb-amd64bsd-nat.c @@ -1,7 +1,5 @@ -diff --git gdb/amd64bsd-nat.c gdb/amd64bsd-nat.c -index 66d4289..b1d4a0e 100644 ---- gdb/amd64bsd-nat.c -+++ gdb/amd64bsd-nat.c +--- gdb/amd64bsd-nat.c.orig 2016-02-10 04:19:39.000000000 +0100 ++++ gdb/amd64bsd-nat.c 2016-03-04 11:17:58.581638025 +0100 @@ -28,6 +28,7 @@ #include <sys/types.h> #include <sys/ptrace.h> @@ -10,7 +8,7 @@ index 66d4289..b1d4a0e 100644 #include "amd64-tdep.h" #include "amd64-nat.h" -@@ -98,14 +99,24 @@ amd64bsd_store_inferior_registers (struct target_ops *ops, +@@ -98,14 +99,25 @@ if (regnum == -1 || amd64_native_gregset_supplies_p (gdbarch, regnum)) { @@ -19,20 +17,21 @@ index 66d4289..b1d4a0e 100644 + memset( ®s, 0, sizeof(struct reg)); + memset( &oldregs, 0, sizeof(struct reg)); - if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid), + if (ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid), (PTRACE_TYPE_ARG3) ®s, 0) == -1) perror_with_name (_("Couldn't get registers")); -+ ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid), -+ (PTRACE_TYPE_ARG3) &oldregs, 0); ++ ptrace (PT_GETREGS, get_ptrace_pid (inferior_ptid), ++ (PTRACE_TYPE_ARG3) &oldregs, 0); amd64_collect_native_gregset (regcache, ®s, regnum); -+ if( (regs.r_rflags ^ oldregs.r_rflags ) & ~PSL_USERCHANGE) { -+ //printf("regs.r_rflags = 0x%8.8lX\n", regs.r_rflags ); -+ //printf("oldregs.r_rflags = 0x%8.8lX\n", oldregs.r_rflags ); -+ regs.r_rflags ^= (regs.r_rflags ^ oldregs.r_rflags ) & ~PSL_USERCHANGE; -+ //printf(" allowed regs.r_rflags = 0x%8.8X\n", regs.r_rflags ); -+ } - if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid), ++ if( (regs.r_rflags ^ oldregs.r_rflags ) & ~PSL_USERCHANGE) ++ { ++ //printf("regs.r_rflags = 0x%8.8lX\n", regs.r_rflags ); ++ //printf("oldregs.r_rflags = 0x%8.8lX\n", oldregs.r_rflags ); ++ regs.r_rflags ^= (regs.r_rflags ^ oldregs.r_rflags ) & ~PSL_USERCHANGE; ++ //printf(" allowed regs.r_rflags = 0x%8.8X\n", regs.r_rflags ); ++ } + if (ptrace (PT_SETREGS, get_ptrace_pid (inferior_ptid), (PTRACE_TYPE_ARG3) ®s, 0) == -1) perror_with_name (_("Couldn't write registers")); diff --git a/devel/gdb/files/patch-gdb-configure b/devel/gdb/files/patch-gdb-configure index d51e112d4f68..85e0aea32401 100644 --- a/devel/gdb/files/patch-gdb-configure +++ b/devel/gdb/files/patch-gdb-configure @@ -1,24 +1,12 @@ -diff --git gdb/configure gdb/configure -index 355f190..9c60e01 100755 ---- gdb/configure -+++ gdb/configure -@@ -11423,7 +11423,8 @@ fi - - # See if <machine/reg.h> supports the %fs and %gs i386 segment registers. - # Older i386 BSD's don't have the r_fs and r_gs members of `struct reg'. --ac_fn_c_check_member "$LINENO" "struct reg" "r_fs" "ac_cv_member_struct_reg_r_fs" "#include <machine/reg.h> -+ac_fn_c_check_member "$LINENO" "struct reg" "r_fs" "ac_cv_member_struct_reg_r_fs" "#include <sys/types.h> -+#include <machine/reg.h> - " - if test "x$ac_cv_member_struct_reg_r_fs" = x""yes; then : - -@@ -11433,7 +11434,8 @@ _ACEOF - - +--- gdb/configure.orig 2016-03-07 10:33:02.757803766 +0100 ++++ gdb/configure 2016-03-07 10:32:39.480804873 +0100 +@@ -14297,8 +14297,7 @@ + -Wno-narrowing" + else + build_warnings="$build_warnings -Wpointer-sign -Wmissing-prototypes \ +--Wdeclaration-after-statement -Wmissing-parameter-type \ +--Wold-style-declaration -Wold-style-definition" ++-Wdeclaration-after-statement -Wold-style-definition" fi --ac_fn_c_check_member "$LINENO" "struct reg" "r_gs" "ac_cv_member_struct_reg_r_gs" "#include <machine/reg.h> -+ac_fn_c_check_member "$LINENO" "struct reg" "r_gs" "ac_cv_member_struct_reg_r_gs" "#include <sys/types.h> -+#include <machine/reg.h> - " - if test "x$ac_cv_member_struct_reg_r_gs" = x""yes; then : + # Enable -Wno-format by default when using gcc on mingw since many diff --git a/devel/gdb/files/patch-gdb-fbsd-nat.c b/devel/gdb/files/patch-gdb-fbsd-nat.c new file mode 100644 index 000000000000..07a224e09d09 --- /dev/null +++ b/devel/gdb/files/patch-gdb-fbsd-nat.c @@ -0,0 +1,17 @@ +--- gdb/fbsd-nat.c.orig 2016-03-14 00:00:11.831889802 +0100 ++++ gdb/fbsd-nat.c 2016-03-14 00:04:35.906871361 +0100 +@@ -471,6 +471,14 @@ + ptid_get_tid (ptid)); + if (ptid_lwp_p (ptid)) + { ++#ifndef PT_LWP_EVENTS ++ /* When LWP events are not supported, a new thread might already be ++ running that has not yet reported an event when GDB wishes to ++ only run a single thread. Force an update of the thread list ++ to ensure that any such threads are suspended before the process ++ is resumed. */ ++ fbsd_add_threads (ptid_get_pid (ptid)); ++#endif + /* If ptid is a specific LWP, suspend all other LWPs in the process. */ + iterate_over_threads (resume_one_thread_cb, &ptid); + } diff --git a/devel/gdb/files/patch-gdb_common_common-defs.h b/devel/gdb/files/patch-gdb_common_common-defs.h deleted file mode 100644 index 71e1795a9dd1..000000000000 --- a/devel/gdb/files/patch-gdb_common_common-defs.h +++ /dev/null @@ -1,12 +0,0 @@ ---- gdb/common/common-defs.h.orig 2015-07-06 19:57:46 UTC -+++ gdb/common/common-defs.h -@@ -34,7 +34,9 @@ - #include <stdint.h> - #include <string.h> - #include <errno.h> -+#ifndef __FreeBSD__ - #include <alloca.h> -+#endif - #include "ansidecl.h" - #include "libiberty.h" - #include "pathmax.h" |