Index: head/devel/gdb/Makefile =================================================================== --- head/devel/gdb/Makefile (revision 480612) +++ head/devel/gdb/Makefile (revision 480613) @@ -1,155 +1,146 @@ # Created by: Steven Kreuzer # $FreeBSD$ PORTNAME= gdb -PORTVERSION= 8.1.1 +PORTVERSION= 8.2 CATEGORIES= devel MASTER_SITES= GNU MAINTAINER= pizzamig@FreeBSD.org COMMENT= GNU GDB of newer version than comes with the system LICENSE= GPLv3 LICENSE_FILE= ${WRKSRC}/COPYING3 # untested on sparc64, might work ONLY_FOR_ARCHS= aarch64 amd64 armv6 armv7 i386 mips powerpc powerpc64 LIB_DEPENDS= libmpfr.so:math/mpfr TEST_DEPENDS= runtest:misc/dejagnu TEST_TARGET= check # XXX: This should be compiler:c++11-lib as GDB doesn't really require # C++14. However, clang in 10.3 crashes while building this port. # Requiring C++14 forces 10.3 to use an external version of clang while # still using the base system clang on 11.0 and later. -USES= compiler:c++14-lang cpe gmake libtool tar:xz +USES= compiler:c++14-lang cpe gettext-runtime gmake libtool tar:xz USE_CSTD= gnu89 CPE_VENDOR= gnu GNU_CONFIGURE= yes CONFIGURE_ENV= CONFIGURED_M4=m4 CONFIGURED_BISON=byacc CONFIGURE_ARGS= --program-suffix=${PORTVERSION:S/.//g} \ --enable-targets=all --enable-64-bit-bfd \ --with-gdb-datadir=${PREFIX}/share/gdb${PORTVERSION:S/.//g} \ --with-separate-debug-dir=/usr/lib/debug \ ${ICONV_CONFIGURE_ARG} \ --with-expat=yes --with-libexpat-prefix=${LOCALBASE} \ --without-libunwind-ia64 --with-system-zlib CFLAGS:= ${CFLAGS:C/ +$//} # blanks at EOL creep in sometimes CFLAGS+= -DRL_NO_COMPAT -Wno-unused-function -Wno-unused-variable CFLAGS+= -Wno-unknown-warning-option EXCLUDE= dejagnu expect sim texinfo intl EXTRACT_AFTER_ARGS= ${EXCLUDE:S/^/--exclude /} -EXTRA_PATCHES= ${FILESDIR}/commit-d2176225dc \ - ${FILESDIR}/commit-b999e2038d \ - ${FILESDIR}/commit-262f62f57d \ - ${FILESDIR}/commit-92fce24de2 \ - ${FILESDIR}/commit-2d97a5d9d3 \ - ${FILESDIR}/commit-906b4aac4c \ - ${FILESDIR}/commit-f169cfdc08 \ - ${FILESDIR}/commit-12279366d7 \ - ${FILESDIR}/commit-386a867618 \ - ${FILESDIR}/commit-7efba073e2 +EXTRA_PATCHES= ${FILESDIR}/commit-8aa0243d54 LIB_DEPENDS+= libexpat.so:textproc/expat2 VER= ${PORTVERSION:S/.//g} PLIST_SUB= VER=${VER} OPTIONS_DEFINE= DEBUG GDB_LINK GUILE KGDB PYTHON TUI OPTIONS_DEFAULT= GDB_LINK KGDB PYTHON TUI PORT_READLINE PORT_ICONV SYSTEM_ZLIB OPTIONS_SINGLE= READLINE ICONV ZLIB OPTIONS_SINGLE_READLINE= BUNDLED_READLINE PORT_READLINE OPTIONS_SINGLE_ICONV= PORT_ICONV SYSTEM_ICONV OPTIONS_SINGLE_ZLIB= BUNDLED_ZLIB SYSTEM_ZLIB GDB_LINK_DESC= Create ${PREFIX}/bin/gdb symlink KGDB_DESC= Kernel Debugging Support 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 SYSTEM_ICONV_DESC= use libc iconv, with no wchar support SYSTEM_ZLIB_DESC= use system zlib TUI_DESC= Text User Interface enabled OPTIONS_SUB= yes BUNDLED_READLINE_CONFIGURE_OFF= --with-system-readline DEBUG_CFLAGS= -g GUILE_CONFIGURE_WITH= guile GUILE_USES= pkgconfig GUILE_LIB_DEPENDS= libguile-2.0.so:lang/guile2 PORT_READLINE_USES= readline:port PORT_ICONV_USES= iconv:wchar_t PYTHON_CONFIGURE_ON= --with-python=${PYTHON_CMD} PYTHON_CONFIGURE_OFF= --without-python PYTHON_USES= python SYSTEM_ICONV_USES= iconv SYSTEM_ZLIB_WITH= system-zlib TUI_CONFIGURE_ENABLE= tui .include .if ! ${PORT_OPTIONS:MBUNDLED_READLINE} EXCLUDE+= readline .endif .if ! ${PORT_OPTIONS:MBUNDLED_ZLIB} EXCLUDE+= zlib .endif .if ${ARCH} == "amd64" CONFIGURE_TARGET= x86_64-portbld-freebsd${OSREL} .endif .if ${COMPILER_TYPE} == "clang" CFLAGS+= -Wno-extended-offsetof .endif post-patch: @${REINPLACE_CMD} -e 's|$$| [GDB v${PORTVERSION} for FreeBSD]|' \ ${WRKSRC}/gdb/version.in post-patch-KGDB-on: @${CP} -r ${FILESDIR}/kgdb/*.[ch] ${WRKSRC}/gdb/ @${PATCH} -d ${PATCH_WRKSRC} ${PATCH_ARGS} < ${FILESDIR}/extrapatch-kgdb do-install: ${INSTALL_PROGRAM} ${WRKSRC}/gdb/gdb \ ${STAGEDIR}${PREFIX}/bin/gdb${VER} ${INSTALL_MAN} ${WRKSRC}/gdb/doc/gdb.1 \ ${STAGEDIR}${MAN1PREFIX}/man/man1/gdb${VER}.1 (cd ${WRKSRC}/gdb/data-directory ; \ ${SETENV} ${MAKE_ENV} ${MAKE_CMD} ${MAKE_ARGS} install-syscalls ) do-install-KGDB-on: ${INSTALL_PROGRAM} ${WRKSRC}/gdb/kgdb \ ${STAGEDIR}${PREFIX}/bin/kgdb${VER} ${INSTALL_MAN} ${FILESDIR}/kgdb/kgdb.1 \ ${STAGEDIR}${MAN1PREFIX}/man/man1/kgdb${VER}.1 do-install-TUI-on: ${LN} -sf gdb${VER} ${STAGEDIR}${PREFIX}/bin/gdbtui${VER} do-install-GDB_LINK-on: ${LN} -sf gdb${VER} ${STAGEDIR}${PREFIX}/bin/gdb .if ${PORT_OPTIONS:MKGDB} ${LN} -sf kgdb${VER} ${STAGEDIR}${PREFIX}/bin/kgdb .endif 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 gdb/printer @(cd ${STAGEDIR}${PREFIX}/share/gdb${VER}/python/${f} ; ${CHMOD} 644 *.py* ) . endfor do-install-GUILE-on: (cd ${WRKSRC}/gdb; ${SETENV} ${MAKE_ENV} ${MAKE_CMD} ${MAKE_ARGS} install-guile ) (cd ${WRKSRC}/gdb/data-directory ; \ ${SETENV} ${MAKE_ENV} ${MAKE_CMD} ${MAKE_ARGS} install-guile ) .include Index: head/devel/gdb/distinfo =================================================================== --- head/devel/gdb/distinfo (revision 480612) +++ head/devel/gdb/distinfo (revision 480613) @@ -1,3 +1,3 @@ -TIMESTAMP = 1533926440 -SHA256 (gdb-8.1.1.tar.xz) = 97dcc3169bd430270fc29adb65145846a58c1b55cdbb73382a4a89307bdad03c -SIZE (gdb-8.1.1.tar.xz) = 20064728 +TIMESTAMP = 1536418789 +SHA256 (gdb-8.2.tar.xz) = c3a441a29c7c89720b734e5a9c6289c0a06be7e0c76ef538f7bbcef389347c39 +SIZE (gdb-8.2.tar.xz) = 20173112 Index: head/devel/gdb/files/patch-gdb_corelow.c =================================================================== --- head/devel/gdb/files/patch-gdb_corelow.c (revision 480612) +++ head/devel/gdb/files/patch-gdb_corelow.c (nonexistent) @@ -1,11 +0,0 @@ ---- gdb/corelow.c.orig 2017-07-29 11:06:52 UTC -+++ gdb/corelow.c -@@ -517,7 +517,7 @@ get_core_register_section (struct regcache *regcache, - bool variable_size_section = (regset != NULL - && regset->flags & REGSET_VARIABLE_SIZE); - -- thread_section_name section_name (name, regcache->ptid ()); -+ thread_section_name section_name (name, regcache_get_ptid (regcache)); - - section = bfd_get_section_by_name (core_bfd, section_name.c_str ()); - if (! section) Property changes on: head/devel/gdb/files/patch-gdb_corelow.c ___________________________________________________________________ Deleted: fbsd:nokeywords ## -1 +0,0 ## -yes \ No newline at end of property Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/devel/gdb/files/commit-7efba073e2 =================================================================== --- head/devel/gdb/files/commit-7efba073e2 (revision 480612) +++ head/devel/gdb/files/commit-7efba073e2 (nonexistent) @@ -1,184 +0,0 @@ -commit 7efba073e2b83803a47fd89e701fe60b98f2debc -Author: John Baldwin -Date: Sat Mar 3 21:25:33 2018 -0800 - - Use signal information to determine SIGTRAP type for FreeBSD. - - Use the signal code from siginfo_t to distinguish SIGTRAP events due - to trace traps (TRAP_TRACE) and software breakpoints (TRAP_BRKPT). - For software breakpoints, adjust the PC when the event is reported as - part of the API when supplying "stopped_by_sw_breakpoint". Currently - FreeBSD only supports hardware watchpoints and breakpoints on x86 - which are reported as trace traps. Signal information is not used on - MIPS and sparc64 kernels which do not reliably report TRAP_BRKPT for - software breakpoints. - - gdb/ChangeLog: - - * fbsd-nat.c: Include "inf-ptrace.h". - (USE_SIGTRAP_SIGINFO): Conditionally define. - [USE_SIGTRAP_SIGINFO] (fbsd_handle_debug_trap): New function. - (fbsd_wait) [USE_SIGTRAP_SIGINFO]: Call "fbsd_handle_debug_trap". - [USE_SIGTRAP_SIGINFO] (fbsd_stopped_by_sw_breakpoint): New - function. - [USE_SIGTRAP_SIGINFO] (fbsd_supports_stopped_by_sw_breakpoint): - Likewise. - [USE_SIGTRAP_SIGINFO] (fbsd_supports_stopped_by_hw_breakpoint): - Likewise. - (fbsd_nat_add_target) [USE_SIGTRAP_SIGINFO]: Set - "stopped_by_sw_breakpoint", "supports_stopped_by_sw_breakpoint", - "supports_stopped_by_hw_breakpoint" target methods. - -diff --git gdb/fbsd-nat.c gdb/fbsd-nat.c -index 2516ac5552..bea7f42c7e 100644 ---- gdb/fbsd-nat.c -+++ gdb/fbsd-nat.c -@@ -26,6 +26,7 @@ - #include "gdbcmd.h" - #include "gdbthread.h" - #include "gdb_wait.h" -+#include "inf-ptrace.h" - #include - #include - #include -@@ -45,6 +46,14 @@ - - #include - -+#ifdef TRAP_BRKPT -+/* MIPS does not set si_code for SIGTRAP. sparc64 reports -+ non-standard values in si_code for SIGTRAP. */ -+# if !defined(__mips__) && !defined(__sparc64__) -+# define USE_SIGTRAP_SIGINFO -+# endif -+#endif -+ - /* Return the name of a file that can be opened to get the symbols for - the child process identified by PID. */ - -@@ -1187,6 +1196,56 @@ fbsd_resume (struct target_ops *ops, - super_resume (ops, ptid, step, signo); - } - -+#ifdef USE_SIGTRAP_SIGINFO -+/* Handle breakpoint and trace traps reported via SIGTRAP. If the -+ trap was a breakpoint or trace trap that should be reported to the -+ core, return true. */ -+ -+static bool -+fbsd_handle_debug_trap (struct target_ops *ops, ptid_t ptid, -+ const struct ptrace_lwpinfo &pl) -+{ -+ -+ /* Ignore traps without valid siginfo or for signals other than -+ SIGTRAP. */ -+ if (! (pl.pl_flags & PL_FLAG_SI) || pl.pl_siginfo.si_signo != SIGTRAP) -+ return false; -+ -+ /* Trace traps are either a single step or a hardware watchpoint or -+ breakpoint. */ -+ if (pl.pl_siginfo.si_code == TRAP_TRACE) -+ { -+ if (debug_fbsd_nat) -+ fprintf_unfiltered (gdb_stdlog, -+ "FNAT: trace trap for LWP %ld\n", ptid.lwp ()); -+ return true; -+ } -+ -+ if (pl.pl_siginfo.si_code == TRAP_BRKPT) -+ { -+ /* Fixup PC for the software breakpoint. */ -+ struct regcache *regcache = get_thread_regcache (ptid); -+ struct gdbarch *gdbarch = regcache->arch (); -+ int decr_pc = gdbarch_decr_pc_after_break (gdbarch); -+ -+ if (debug_fbsd_nat) -+ fprintf_unfiltered (gdb_stdlog, -+ "FNAT: sw breakpoint trap for LWP %ld\n", -+ ptid.lwp ()); -+ if (decr_pc != 0) -+ { -+ CORE_ADDR pc; -+ -+ pc = regcache_read_pc (regcache); -+ regcache_write_pc (regcache, pc - decr_pc); -+ } -+ return true; -+ } -+ -+ return false; -+} -+#endif -+ - /* Wait for the child specified by PTID to do something. Return the - process ID of the child, or MINUS_ONE_PTID in case of error; store - the status in *OURSTATUS. */ -@@ -1372,6 +1431,11 @@ fbsd_wait (struct target_ops *ops, - } - #endif - -+#ifdef USE_SIGTRAP_SIGINFO -+ if (fbsd_handle_debug_trap (ops, wptid, pl)) -+ return wptid; -+#endif -+ - /* Note that PL_FLAG_SCE is set for any event reported while - a thread is executing a system call in the kernel. In - particular, signals that interrupt a sleep in a system -@@ -1410,6 +1474,42 @@ fbsd_wait (struct target_ops *ops, - } - } - -+#ifdef USE_SIGTRAP_SIGINFO -+/* Implement the "to_stopped_by_sw_breakpoint" target_ops method. */ -+ -+static int -+fbsd_stopped_by_sw_breakpoint (struct target_ops *ops) -+{ -+ struct ptrace_lwpinfo pl; -+ -+ if (ptrace (PT_LWPINFO, get_ptrace_pid (inferior_ptid), (caddr_t) &pl, -+ sizeof pl) == -1) -+ return 0; -+ -+ return ((pl.pl_flags & PL_FLAG_SI) -+ && pl.pl_siginfo.si_signo == SIGTRAP -+ && pl.pl_siginfo.si_code == TRAP_BRKPT); -+} -+ -+/* Implement the "to_supports_stopped_by_sw_breakpoint" target_ops -+ method. */ -+ -+static int -+fbsd_supports_stopped_by_sw_breakpoint (struct target_ops *ops) -+{ -+ return 1; -+} -+ -+/* Implement the "to_supports_stopped_by_hw_breakpoint" target_ops -+ method. */ -+ -+static int -+fbsd_supports_stopped_by_hw_breakpoint (struct target_ops *ops) -+{ -+ return ops->to_stopped_by_hw_breakpoint != NULL; -+} -+#endif -+ - #ifdef TDP_RFPPWAIT - /* Target hook for follow_fork. On entry and at return inferior_ptid is - the ptid of the followed inferior. */ -@@ -1560,6 +1660,13 @@ fbsd_nat_add_target (struct target_ops *t) - t->to_wait = fbsd_wait; - t->to_post_startup_inferior = fbsd_post_startup_inferior; - t->to_post_attach = fbsd_post_attach; -+#ifdef USE_SIGTRAP_SIGINFO -+ t->to_stopped_by_sw_breakpoint = fbsd_stopped_by_sw_breakpoint; -+ t->to_supports_stopped_by_sw_breakpoint -+ = fbsd_supports_stopped_by_sw_breakpoint; -+ t->to_supports_stopped_by_hw_breakpoint -+ = fbsd_supports_stopped_by_hw_breakpoint; -+#endif - #ifdef TDP_RFPPWAIT - t->to_follow_fork = fbsd_follow_fork; - t->to_insert_fork_catchpoint = fbsd_insert_fork_catchpoint; Property changes on: head/devel/gdb/files/commit-7efba073e2 ___________________________________________________________________ Deleted: fbsd:nokeywords ## -1 +0,0 ## -yes \ No newline at end of property Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/devel/gdb/files/commit-12279366d7 =================================================================== --- head/devel/gdb/files/commit-12279366d7 (revision 480612) +++ head/devel/gdb/files/commit-12279366d7 (nonexistent) @@ -1,121 +0,0 @@ -commit 12279366d71627bfbdd74d1a6675dca825d8feca -Author: John Baldwin -Date: Sat Mar 3 21:25:33 2018 -0800 - - Implement "to_stopped_by_hw_breakpoint" for x86 debug registers. - - Report that a thread is stopped by a hardware breakpoint if a non-data - watchpoint is set in DR6. This change should be a no-op since a target - still needs to implement the "to_supports_stopped_by_hw_breakpoint" - method before this function is used. - - gdb/ChangeLog: - - * nat/x86-dregs.c (x86_dr_stopped_by_hw_breakpoint): New function. - * nat/x86-dregs.h (x86_dr_stopped_by_hw_breakpoint): New - prototype. - * x86-nat.c (x86_stopped_by_hw_breakpoint): New function. - (x86_use_watchpoints): Set "stopped_by_hw_breakpoint" target - method. - -diff --git gdb/nat/x86-dregs.c gdb/nat/x86-dregs.c -index c816473628..f11a708e27 100644 ---- gdb/nat/x86-dregs.c -+++ gdb/nat/x86-dregs.c -@@ -649,3 +649,48 @@ x86_dr_stopped_by_watchpoint (struct x86_debug_reg_state *state) - CORE_ADDR addr = 0; - return x86_dr_stopped_data_address (state, &addr); - } -+ -+/* Return non-zero if the inferior has some hardware breakpoint that -+ triggered. Otherwise return zero. */ -+ -+int -+x86_dr_stopped_by_hw_breakpoint (struct x86_debug_reg_state *state) -+{ -+ CORE_ADDR addr = 0; -+ int i; -+ int rc = 0; -+ /* The current thread's DR_STATUS. We always need to read this to -+ check whether some watchpoint caused the trap. */ -+ unsigned status; -+ /* We need DR_CONTROL as well, but only iff DR_STATUS indicates a -+ breakpoint trap. Only fetch it when necessary, to avoid an -+ unnecessary extra syscall when no watchpoint triggered. */ -+ int control_p = 0; -+ unsigned control = 0; -+ -+ /* As above, always read the current thread's debug registers rather -+ than trusting dr_mirror. */ -+ status = x86_dr_low_get_status (); -+ -+ ALL_DEBUG_ADDRESS_REGISTERS (i) -+ { -+ if (!X86_DR_WATCH_HIT (status, i)) -+ continue; -+ -+ if (!control_p) -+ { -+ control = x86_dr_low_get_control (); -+ control_p = 1; -+ } -+ -+ if (X86_DR_GET_RW_LEN (control, i) == 0) -+ { -+ addr = x86_dr_low_get_addr (i); -+ rc = 1; -+ if (show_debug_regs) -+ x86_show_dr (state, "watchpoint_hit", addr, -1, hw_execute); -+ } -+ } -+ -+ return rc; -+} -diff --git gdb/nat/x86-dregs.h gdb/nat/x86-dregs.h -index dd6242eda9..e86e83aea0 100644 ---- gdb/nat/x86-dregs.h -+++ gdb/nat/x86-dregs.h -@@ -128,4 +128,8 @@ extern int x86_dr_stopped_data_address (struct x86_debug_reg_state *state, - Otherwise return false. */ - extern int x86_dr_stopped_by_watchpoint (struct x86_debug_reg_state *state); - -+/* Return true if the inferior has some hardware breakpoint that -+ triggered. Otherwise return false. */ -+extern int x86_dr_stopped_by_hw_breakpoint (struct x86_debug_reg_state *state); -+ - #endif /* X86_DREGS_H */ -diff --git gdb/x86-nat.c gdb/x86-nat.c -index b126c47c94..bec51373a6 100644 ---- gdb/x86-nat.c -+++ gdb/x86-nat.c -@@ -260,6 +260,18 @@ x86_can_use_hw_breakpoint (struct target_ops *self, - return 1; - } - -+/* Return non-zero if the inferior has some breakpoint that triggered. -+ Otherwise return zero. */ -+ -+static int -+x86_stopped_by_hw_breakpoint (struct target_ops *ops) -+{ -+ struct x86_debug_reg_state *state -+ = x86_debug_reg_state (ptid_get_pid (inferior_ptid)); -+ -+ return x86_dr_stopped_by_hw_breakpoint (state); -+} -+ - static void - add_show_debug_regs_command (void) - { -@@ -297,6 +309,11 @@ x86_use_watchpoints (struct target_ops *t) - t->to_remove_watchpoint = x86_remove_watchpoint; - t->to_insert_hw_breakpoint = x86_insert_hw_breakpoint; - t->to_remove_hw_breakpoint = x86_remove_hw_breakpoint; -+ -+ /* A target must provide an implementation of the -+ "to_supports_stopped_by_hw_breakpoint" target method before this -+ callback will be used. */ -+ t->to_stopped_by_hw_breakpoint = x86_stopped_by_hw_breakpoint; - } - - void Property changes on: head/devel/gdb/files/commit-12279366d7 ___________________________________________________________________ Deleted: fbsd:nokeywords ## -1 +0,0 ## -yes \ No newline at end of property Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/devel/gdb/files/commit-906b4aac4c =================================================================== --- head/devel/gdb/files/commit-906b4aac4c (revision 480612) +++ head/devel/gdb/files/commit-906b4aac4c (nonexistent) @@ -1,29 +0,0 @@ -commit 906b4aac4c1d3cdb2b1ea7105133cfbe25e04e14 -Author: John Baldwin -Date: Fri Jan 12 12:05:50 2018 -0800 - - Use the correct value for the offset of 'kve_protection'. - - I had forgotten to convert the decimal output of 'ptype /o' to hex - (but still used a 0x prefix) for the KVE_PROTECTION constant defining - the offset of the 'kve_protection' field in the 'kinfo_vmentry' - structure. This resulted in garbage permissions for entries in 'info - proc mappings' for FreeBSD core dumps. - - gdb/ChangeLog: - - * fbsd-tdep.c (KVE_PROTECTION): Correct value. - -diff --git gdb/fbsd-tdep.c gdb/fbsd-tdep.c -index 8aa0243d54..e49a9aff09 100644 ---- gdb/fbsd-tdep.c -+++ gdb/fbsd-tdep.c -@@ -62,7 +62,7 @@ - #define KVE_END 0x10 - #define KVE_OFFSET 0x18 - #define KVE_FLAGS 0x2c --#define KVE_PROTECTION 0x56 -+#define KVE_PROTECTION 0x38 - #define KVE_PATH 0x88 - - /* Flags in the 'kve_protection' field in struct kinfo_vmentry. These Property changes on: head/devel/gdb/files/commit-906b4aac4c ___________________________________________________________________ Deleted: fbsd:nokeywords ## -1 +0,0 ## -yes \ No newline at end of property Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/devel/gdb/files/commit-262f62f57d =================================================================== --- head/devel/gdb/files/commit-262f62f57d (revision 480612) +++ head/devel/gdb/files/commit-262f62f57d (nonexistent) @@ -1,43 +0,0 @@ -commit 262f62f57d987269152412a55c458a03adc6ddd6 -Author: John Baldwin -Date: Tue Jan 9 13:35:17 2018 -0800 - - Use gdb::unique_xmalloc_ptr<> instead of a deleter that invokes free(). - - Since xfree() always wraps free(), it is safe to use the xfree deleter - for buffers allocated by library routines such as kinfo_getvmmap() that - must be released via free(). - - gdb/ChangeLog: - - * fbsd-nat.c (struct free_deleter): Remove. - (fbsd_find_memory_regions): Use gdb::unique_xmalloc_ptr<>. - -diff --git gdb/fbsd-nat.c gdb/fbsd-nat.c -index d0aaf89145..81f8e27a2d 100644 ---- gdb/fbsd-nat.c -+++ gdb/fbsd-nat.c -@@ -81,14 +81,6 @@ fbsd_pid_to_exec_file (struct target_ops *self, int pid) - } - - #ifdef HAVE_KINFO_GETVMMAP --/* Deleter for std::unique_ptr that invokes free. */ -- --template --struct free_deleter --{ -- void operator() (T *ptr) const { free (ptr); } --}; -- - /* Iterate over all the memory regions in the current inferior, - calling FUNC for each memory region. OBFD is passed as the last - argument to FUNC. */ -@@ -102,7 +94,7 @@ fbsd_find_memory_regions (struct target_ops *self, - uint64_t size; - int i, nitems; - -- std::unique_ptr> -+ gdb::unique_xmalloc_ptr - vmentl (kinfo_getvmmap (pid, &nitems)); - if (vmentl == NULL) - perror_with_name (_("Couldn't fetch VM map entries.")); Property changes on: head/devel/gdb/files/commit-262f62f57d ___________________________________________________________________ Deleted: fbsd:nokeywords ## -1 +0,0 ## -yes \ No newline at end of property Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/devel/gdb/files/commit-2d97a5d9d3 =================================================================== --- head/devel/gdb/files/commit-2d97a5d9d3 (revision 480612) +++ head/devel/gdb/files/commit-2d97a5d9d3 (nonexistent) @@ -1,169 +0,0 @@ -commit 2d97a5d9d33aea87c3bd02fd1fa417f5d4e1fa05 -Author: John Baldwin -Date: Tue Jan 9 13:35:17 2018 -0800 - - Document support for 'info proc' on FreeBSD. - - Since the 'info proc' support on FreeBSD does not use /proc, reword - the documentation for 'info proc' to not assume /proc. This includes - renaming the node to 'Process Information' and suggesting that - additional process information can be queried via different - OS-specific interfaces. This is also cleans up the description of - 'info proc' support for core files a bit as /proc is not used for core - file support on any current platform. - - gdb/ChangeLog: - - * NEWS: Document that 'info proc' now works on FreeBSD. - - gdb/doc/ChangeLog: - - * gdb.texinfo (pwd): Update cross-reference for Process Information - node and remove explicit /proc reference. - (Native): Rename subsection from SVR4 Process Information to - Process Information. - (Process Information): Reword introduction to be less /proc - centric. Document support for "info proc" on FreeBSD. - -diff --git gdb/NEWS gdb/NEWS -index 2f834c6ff4..f69173a245 100644 ---- gdb/NEWS -+++ gdb/NEWS -@@ -3,6 +3,9 @@ - - *** Changes since GDB 8.1 - -+* 'info proc' now works on running processes on FreeBSD systems and core -+ files created on FreeBSD systems. -+ - *** Changes in GDB 8.1 - - * GDB now supports dynamically creating arbitrary register groups specified -diff --git gdb/doc/gdb.texinfo gdb/doc/gdb.texinfo -index 8bdafb0ba4..096c82cc82 100644 ---- gdb/doc/gdb.texinfo -+++ gdb/doc/gdb.texinfo -@@ -2523,9 +2523,9 @@ Print the @value{GDBN} working directory. - - It is generally impossible to find the current working directory of - the process being debugged (since a program can change its directory --during its run). If you work on a system where @value{GDBN} is --configured with the @file{/proc} support, you can use the @code{info --proc} command (@pxref{SVR4 Process Information}) to find out the -+during its run). If you work on a system where @value{GDBN} supports -+the @code {info proc} command (@pxref{Process Information}), you can -+use the @code{info proc} command to find out the - current working directory of the debuggee. - - @node Input/Output -@@ -21712,7 +21712,7 @@ configurations. - - @menu - * BSD libkvm Interface:: Debugging BSD kernel memory images --* SVR4 Process Information:: SVR4 process information -+* Process Information:: Process information - * DJGPP Native:: Features specific to the DJGPP port - * Cygwin Native:: Features specific to the Cygwin port - * Hurd Native:: Features specific to @sc{gnu} Hurd -@@ -21759,24 +21759,32 @@ Set current context from proc address. This command isn't available on - modern FreeBSD systems. - @end table - --@node SVR4 Process Information --@subsection SVR4 Process Information -+@node Process Information -+@subsection Process Information - @cindex /proc - @cindex examine process image - @cindex process info via @file{/proc} - --Many versions of SVR4 and compatible systems provide a facility called --@samp{/proc} that can be used to examine the image of a running --process using file-system subroutines. -+Some operating systems provide interfaces to fetch additional -+information about running processes beyond memory and per-thread -+register state. If @value{GDBN} is configured for an operating system -+with a supported interface, the command @code{info proc} is available -+to report information about the process running your program, or about -+any process running on your system. - --If @value{GDBN} is configured for an operating system with this --facility, the command @code{info proc} is available to report --information about the process running your program, or about any --process running on your system. This includes, as of this writing, --@sc{gnu}/Linux and Solaris, for example. -+One supported interface is a facility called @samp{/proc} that can be -+used to examine the image of a running process using file-system -+subroutines. This facility is supported on @sc{gnu}/Linux and Solaris -+systems. - --This command may also work on core files that were created on a system --that has the @samp{/proc} facility. -+On FreeBSD systems, system control nodes are used to query process -+information. -+ -+In addition, some systems may provide additional process information -+in core files. Note that a core file may include a subset of the -+information available from a live process. Process information is -+currently avaiable from cores created on @sc{gnu}/Linux and FreeBSD -+systems. - - @table @code - @kindex info proc -@@ -21800,36 +21808,40 @@ a process ID rather than a thread ID). - @item info proc cmdline - @cindex info proc cmdline - Show the original command line of the process. This command is --specific to @sc{gnu}/Linux. -+supported on @sc{gnu}/Linux and FreeBSD. - - @item info proc cwd - @cindex info proc cwd - Show the current working directory of the process. This command is --specific to @sc{gnu}/Linux. -+supported on @sc{gnu}/Linux and FreeBSD. - - @item info proc exe - @cindex info proc exe --Show the name of executable of the process. This command is specific --to @sc{gnu}/Linux. -+Show the name of executable of the process. This command is supported -+on @sc{gnu}/Linux and FreeBSD. - - @item info proc mappings - @cindex memory address space mappings --Report the memory address space ranges accessible in the program, with --information on whether the process has read, write, or execute access --rights to each range. On @sc{gnu}/Linux systems, each memory range --includes the object file which is mapped to that range, instead of the --memory access rights to that range. -+Report the memory address space ranges accessible in the program. On -+Solaris and FreeBSD systems, each memory range includes information on -+whether the process has read, write, or execute access rights to each -+range. On @sc{gnu}/Linux and FreeBSD systems, each memory range -+includes the object file which is mapped to that range. - - @item info proc stat - @itemx info proc status - @cindex process detailed status information --These subcommands are specific to @sc{gnu}/Linux systems. They show --the process-related information, including the user ID and group ID; --how many threads are there in the process; its virtual memory usage; --the signals that are pending, blocked, and ignored; its TTY; its --consumption of system and user time; its stack size; its @samp{nice} --value; etc. For more information, see the @samp{proc} man page --(type @kbd{man 5 proc} from your shell prompt). -+Show additional process-related information, including the user ID and -+group ID; virtual memory usage; the signals that are pending, blocked, -+and ignored; its TTY; its consumption of system and user time; its -+stack size; its @samp{nice} value; etc. These commands are supported -+on @sc{gnu}/Linux and FreeBSD. -+ -+For @sc{gnu}/Linux systems, see the @samp{proc} man page for more -+information (type @kbd{man 5 proc} from your shell prompt). -+ -+For FreeBSD systems, @code{info proc stat} is an alias for @code{info -+proc status}. - - @item info proc all - Show all the information about the process described under all of the Property changes on: head/devel/gdb/files/commit-2d97a5d9d3 ___________________________________________________________________ Deleted: fbsd:nokeywords ## -1 +0,0 ## -yes \ No newline at end of property Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/devel/gdb/files/commit-b999e2038d =================================================================== --- head/devel/gdb/files/commit-b999e2038d (revision 480612) +++ head/devel/gdb/files/commit-b999e2038d (nonexistent) @@ -1,32 +0,0 @@ -commit b999e2038dbc54e2c8b1c390f8b8fe50d0f1d10a -Author: John Baldwin -Date: Tue Jan 9 13:35:17 2018 -0800 - - Don't return stale data from fbsd_pid_to_exec_file for kernel processes. - - For processes without an associated executable (such as kernel processes), - the kern.proc.pathname. system control node returns a length of zero - without modifying the user's buffer. Detect this case and return NULL - rather than the previous contents of the static buffer 'buf'. - - gdb/ChangeLog: - - * fbsd-nat.c (fbsd_pid_to_exec_file) [KERN_PROC_PATHNAME]: Return - NULL for an empty pathname. - -diff --git gdb/fbsd-nat.c gdb/fbsd-nat.c -index ec4eed9abe..d0aaf89145 100644 ---- gdb/fbsd-nat.c -+++ gdb/fbsd-nat.c -@@ -63,7 +63,10 @@ fbsd_pid_to_exec_file (struct target_ops *self, int pid) - mib[3] = pid; - buflen = sizeof buf; - if (sysctl (mib, 4, buf, &buflen, NULL, 0) == 0) -- return buf; -+ /* The kern.proc.pathname. sysctl returns a length of zero -+ for processes without an associated executable such as kernel -+ processes. */ -+ return buflen == 0 ? NULL : buf; - #endif - - xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid); Property changes on: head/devel/gdb/files/commit-b999e2038d ___________________________________________________________________ Deleted: fbsd:nokeywords ## -1 +0,0 ## -yes \ No newline at end of property Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/devel/gdb/files/commit-386a867618 =================================================================== --- head/devel/gdb/files/commit-386a867618 (revision 480612) +++ head/devel/gdb/files/commit-386a867618 (nonexistent) @@ -1,115 +0,0 @@ -commit 386a86761838df16c1459275d465ed21a1c35d9f -Author: John Baldwin -Date: Sat Mar 3 21:25:33 2018 -0800 - - Add a new debug knob for the FreeBSD native target. - - For now this just logs information about the state of the current LWP - for each STOPPED event in fbsd_wait(). - - gdb/ChangeLog: - - * NEWS (Changes since GDB 8.1): Add "set/show debug fbsd-nat". - * fbsd-nat.c (debug_fbsd_nat): New variable. - (show_fbsd_nat_debug): New function. - (fbsd_wait): Log LWP info if "debug_fbsd_nat" is enabled. - (_initialize_fbsd_nat): Add "fbsd-nat" debug boolean command. - - gdb/doc/ChangeLog: - - * gdb.texinfo (Debugging Output): Document "set/show debug - fbsd-nat". - -diff --git gdb/NEWS gdb/NEWS -index 1767cef920..867e268a2a 100644 ---- gdb/NEWS -+++ gdb/NEWS -@@ -6,6 +6,12 @@ - * 'info proc' now works on running processes on FreeBSD systems and core - files created on FreeBSD systems. - -+* New commands -+ -+set debug fbsd-nat -+show debug fbsd-nat -+ Control display of debugging info regarding the FreeBSD native target. -+ - *** Changes in GDB 8.1 - - * GDB now supports dynamically creating arbitrary register groups specified -diff --git gdb/doc/gdb.texinfo gdb/doc/gdb.texinfo -index ee7adc8df2..74e0fdb4a4 100644 ---- gdb/doc/gdb.texinfo -+++ gdb/doc/gdb.texinfo -@@ -24554,6 +24554,11 @@ Displays the current state of displaying debugging info about - Turns on or off debugging messages from the FreeBSD LWP debug support. - @item show debug fbsd-lwp - Show the current state of FreeBSD LWP debugging messages. -+@item set debug fbsd-nat -+@cindex FreeBSD native target debug messages -+Turns on or off debugging messages from the FreeBSD native target. -+@item show debug fbsd-nat -+Show the current state of FreeBSD native target debugging messages. - @item set debug frame - @cindex frame debugging info - Turns on or off display of @value{GDBN} frame debugging info. The -diff --git gdb/fbsd-nat.c gdb/fbsd-nat.c -index 3a216abf18..2516ac5552 100644 ---- gdb/fbsd-nat.c -+++ gdb/fbsd-nat.c -@@ -765,6 +765,7 @@ fbsd_xfer_partial (struct target_ops *ops, enum target_object object, - - #ifdef PT_LWPINFO - static int debug_fbsd_lwp; -+static int debug_fbsd_nat; - - static void (*super_resume) (struct target_ops *, - ptid_t, -@@ -782,6 +783,14 @@ show_fbsd_lwp_debug (struct ui_file *file, int from_tty, - fprintf_filtered (file, _("Debugging of FreeBSD lwp module is %s.\n"), value); - } - -+static void -+show_fbsd_nat_debug (struct ui_file *file, int from_tty, -+ struct cmd_list_element *c, const char *value) -+{ -+ fprintf_filtered (file, _("Debugging of FreeBSD native target is %s.\n"), -+ value); -+} -+ - /* - FreeBSD's first thread support was via a "reentrant" version of libc - (libc_r) that first shipped in 2.2.7. This library multiplexed all -@@ -1212,6 +1221,18 @@ fbsd_wait (struct target_ops *ops, - - wptid = ptid_build (pid, pl.pl_lwpid, 0); - -+ if (debug_fbsd_nat) -+ { -+ fprintf_unfiltered (gdb_stdlog, -+ "FNAT: stop for LWP %u event %d flags %#x\n", -+ pl.pl_lwpid, pl.pl_event, pl.pl_flags); -+ if (pl.pl_flags & PL_FLAG_SI) -+ fprintf_unfiltered (gdb_stdlog, -+ "FNAT: si_signo %u si_code %u\n", -+ pl.pl_siginfo.si_signo, -+ pl.pl_siginfo.si_code); -+ } -+ - #ifdef PT_LWP_EVENTS - if (pl.pl_flags & PL_FLAG_EXITED) - { -@@ -1569,5 +1590,13 @@ Enables printf debugging output."), - NULL, - &show_fbsd_lwp_debug, - &setdebuglist, &showdebuglist); -+ add_setshow_boolean_cmd ("fbsd-nat", class_maintenance, -+ &debug_fbsd_nat, _("\ -+Set debugging of FreeBSD native target."), _("\ -+Show debugging of FreeBSD native target."), _("\ -+Enables printf debugging output."), -+ NULL, -+ &show_fbsd_nat_debug, -+ &setdebuglist, &showdebuglist); - #endif - } Property changes on: head/devel/gdb/files/commit-386a867618 ___________________________________________________________________ Deleted: fbsd:nokeywords ## -1 +0,0 ## -yes \ No newline at end of property Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/devel/gdb/files/commit-92fce24de2 =================================================================== --- head/devel/gdb/files/commit-92fce24de2 (revision 480612) +++ head/devel/gdb/files/commit-92fce24de2 (nonexistent) @@ -1,548 +0,0 @@ -commit 92fce24de299a8b9a9a1c0c6b98e0e9c1656f99c -Author: John Baldwin -Date: Tue Jan 9 13:35:17 2018 -0800 - - Support 'info proc' for native FreeBSD processes. - - - Command line arguments are fetched via the kern.proc.args. - sysctl. - - The 'cwd' and 'exe' values are obtained from the per-process - file descriptor table returned by kinfo_getfile() from libutil. - - 'mappings' is implemented by walking the array of VM map entries - returned by kinfo_getvmmap() from libutil. - - 'status' output is generated by outputting fields from the structure - returned by the kern.proc.pid. sysctl. - - 'stat' is aliased to 'status'. - - gdb/ChangeLog: - - * configure.ac: Check for kinfo_getfile in libutil. - * configure: Regenerate. - * config.in: Regenerate. - * fbsd-nat.c: Include "fbsd-tdep.h". - (fbsd_fetch_cmdline): New. - (fbsd_fetch_kinfo_proc): Move earlier and change to return a bool - rather than calling error. - (fbsd_info_proc): New. - (fbsd_thread_name): Report error if fbsd_fetch_kinfo_proc fails. - (fbsd_wait): Report warning if fbsd_fetch_kinfo_proc fails. - (fbsd_nat_add_target): Set "to_info_proc" to "fbsd_info_proc". - -diff --git gdb/config.in gdb/config.in -index 1d11a97080..ad2cc1754e 100644 ---- gdb/config.in -+++ gdb/config.in -@@ -219,6 +219,9 @@ - /* Define to 1 if you have the header file. */ - #undef HAVE_INTTYPES_H - -+/* Define to 1 if your system has the kinfo_getfile function. */ -+#undef HAVE_KINFO_GETFILE -+ - /* Define to 1 if your system has the kinfo_getvmmap function. */ - #undef HAVE_KINFO_GETVMMAP - -diff --git gdb/configure gdb/configure -index db610f32fc..68b9aad02d 100755 ---- gdb/configure -+++ gdb/configure -@@ -7927,6 +7927,66 @@ $as_echo "#define HAVE_KINFO_GETVMMAP 1" >>confdefs.h - fi - - -+# fbsd-nat.c can also use kinfo_getfile. -+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing kinfo_getfile" >&5 -+$as_echo_n "checking for library containing kinfo_getfile... " >&6; } -+if test "${ac_cv_search_kinfo_getfile+set}" = set; then : -+ $as_echo_n "(cached) " >&6 -+else -+ ac_func_search_save_LIBS=$LIBS -+cat confdefs.h - <<_ACEOF >conftest.$ac_ext -+/* end confdefs.h. */ -+ -+/* Override any GCC internal prototype to avoid an error. -+ Use char because int might match the return type of a GCC -+ builtin and then its argument prototype would still apply. */ -+#ifdef __cplusplus -+extern "C" -+#endif -+char kinfo_getfile (); -+int -+main () -+{ -+return kinfo_getfile (); -+ ; -+ return 0; -+} -+_ACEOF -+for ac_lib in '' util util-freebsd; do -+ if test -z "$ac_lib"; then -+ ac_res="none required" -+ else -+ ac_res=-l$ac_lib -+ LIBS="-l$ac_lib $ac_func_search_save_LIBS" -+ fi -+ if ac_fn_c_try_link "$LINENO"; then : -+ ac_cv_search_kinfo_getfile=$ac_res -+fi -+rm -f core conftest.err conftest.$ac_objext \ -+ conftest$ac_exeext -+ if test "${ac_cv_search_kinfo_getfile+set}" = set; then : -+ break -+fi -+done -+if test "${ac_cv_search_kinfo_getfile+set}" = set; then : -+ -+else -+ ac_cv_search_kinfo_getfile=no -+fi -+rm conftest.$ac_ext -+LIBS=$ac_func_search_save_LIBS -+fi -+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_kinfo_getfile" >&5 -+$as_echo "$ac_cv_search_kinfo_getfile" >&6; } -+ac_res=$ac_cv_search_kinfo_getfile -+if test "$ac_res" != no; then : -+ test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" -+ -+$as_echo "#define HAVE_KINFO_GETFILE 1" >>confdefs.h -+ -+fi -+ -+ - - if test "X$prefix" = "XNONE"; then - acl_final_prefix="$ac_default_prefix" -diff --git gdb/configure.ac gdb/configure.ac -index 3db44ae758..551afc727e 100644 ---- gdb/configure.ac -+++ gdb/configure.ac -@@ -523,6 +523,11 @@ AC_SEARCH_LIBS(kinfo_getvmmap, util util-freebsd, - [AC_DEFINE(HAVE_KINFO_GETVMMAP, 1, - [Define to 1 if your system has the kinfo_getvmmap function. ])]) - -+# fbsd-nat.c can also use kinfo_getfile. -+AC_SEARCH_LIBS(kinfo_getfile, util util-freebsd, -+ [AC_DEFINE(HAVE_KINFO_GETFILE, 1, -+ [Define to 1 if your system has the kinfo_getfile function. ])]) -+ - AM_ICONV - - # GDB may fork/exec the iconv program to get the list of supported character -diff --git gdb/fbsd-nat.c gdb/fbsd-nat.c -index 81f8e27a2d..b352418813 100644 ---- gdb/fbsd-nat.c -+++ gdb/fbsd-nat.c -@@ -32,14 +32,16 @@ - #include - #include - #include --#ifdef HAVE_KINFO_GETVMMAP -+#if defined(HAVE_KINFO_GETFILE) || defined(HAVE_KINFO_GETVMMAP) - #include --#else -+#endif -+#if !defined(HAVE_KINFO_GETVMMAP) - #include "filestuff.h" - #endif - - #include "elf-bfd.h" - #include "fbsd-nat.h" -+#include "fbsd-tdep.h" - - #include - -@@ -205,6 +207,331 @@ fbsd_find_memory_regions (struct target_ops *self, - } - #endif - -+/* Fetch the command line for a running process. */ -+ -+static gdb::unique_xmalloc_ptr -+fbsd_fetch_cmdline (pid_t pid) -+{ -+ size_t len; -+ int mib[4]; -+ -+ len = 0; -+ mib[0] = CTL_KERN; -+ mib[1] = KERN_PROC; -+ mib[2] = KERN_PROC_ARGS; -+ mib[3] = pid; -+ if (sysctl (mib, 4, NULL, &len, NULL, 0) == -1) -+ return nullptr; -+ -+ if (len == 0) -+ return nullptr; -+ -+ gdb::unique_xmalloc_ptr cmdline ((char *) xmalloc (len)); -+ if (sysctl (mib, 4, cmdline.get (), &len, NULL, 0) == -1) -+ return nullptr; -+ -+ return cmdline; -+} -+ -+/* Fetch the external variant of the kernel's internal process -+ structure for the process PID into KP. */ -+ -+static bool -+fbsd_fetch_kinfo_proc (pid_t pid, struct kinfo_proc *kp) -+{ -+ size_t len; -+ int mib[4]; -+ -+ len = sizeof *kp; -+ mib[0] = CTL_KERN; -+ mib[1] = KERN_PROC; -+ mib[2] = KERN_PROC_PID; -+ mib[3] = pid; -+ return (sysctl (mib, 4, kp, &len, NULL, 0) == 0); -+} -+ -+/* Implement the "to_info_proc target_ops" method. */ -+ -+static void -+fbsd_info_proc (struct target_ops *ops, const char *args, -+ enum info_proc_what what) -+{ -+#ifdef HAVE_KINFO_GETFILE -+ gdb::unique_xmalloc_ptr fdtbl; -+ int nfd = 0; -+#endif -+ struct kinfo_proc kp; -+ char *tmp; -+ pid_t pid; -+ bool do_cmdline = false; -+ bool do_cwd = false; -+ bool do_exe = false; -+#ifdef HAVE_KINFO_GETVMMAP -+ bool do_mappings = false; -+#endif -+ bool do_status = false; -+ -+ switch (what) -+ { -+ case IP_MINIMAL: -+ do_cmdline = true; -+ do_cwd = true; -+ do_exe = true; -+ break; -+#ifdef HAVE_KINFO_GETVMMAP -+ case IP_MAPPINGS: -+ do_mappings = true; -+ break; -+#endif -+ case IP_STATUS: -+ case IP_STAT: -+ do_status = true; -+ break; -+ case IP_CMDLINE: -+ do_cmdline = true; -+ break; -+ case IP_EXE: -+ do_exe = true; -+ break; -+ case IP_CWD: -+ do_cwd = true; -+ break; -+ case IP_ALL: -+ do_cmdline = true; -+ do_cwd = true; -+ do_exe = true; -+#ifdef HAVE_KINFO_GETVMMAP -+ do_mappings = true; -+#endif -+ do_status = true; -+ break; -+ default: -+ error (_("Not supported on this target.")); -+ } -+ -+ gdb_argv built_argv (args); -+ if (built_argv.count () == 0) -+ { -+ pid = ptid_get_pid (inferior_ptid); -+ if (pid == 0) -+ error (_("No current process: you must name one.")); -+ } -+ else if (built_argv.count () == 1 && isdigit (built_argv[0][0])) -+ pid = strtol (built_argv[0], NULL, 10); -+ else -+ error (_("Invalid arguments.")); -+ -+ printf_filtered (_("process %d\n"), pid); -+#ifdef HAVE_KINFO_GETFILE -+ if (do_cwd || do_exe) -+ fdtbl.reset (kinfo_getfile (pid, &nfd)); -+#endif -+ -+ if (do_cmdline) -+ { -+ gdb::unique_xmalloc_ptr cmdline = fbsd_fetch_cmdline (pid); -+ if (cmdline != nullptr) -+ printf_filtered ("cmdline = '%s'\n", cmdline.get ()); -+ else -+ warning (_("unable to fetch command line")); -+ } -+ if (do_cwd) -+ { -+ const char *cwd = NULL; -+#ifdef HAVE_KINFO_GETFILE -+ struct kinfo_file *kf = fdtbl.get (); -+ for (int i = 0; i < nfd; i++, kf++) -+ { -+ if (kf->kf_type == KF_TYPE_VNODE && kf->kf_fd == KF_FD_TYPE_CWD) -+ { -+ cwd = kf->kf_path; -+ break; -+ } -+ } -+#endif -+ if (cwd != NULL) -+ printf_filtered ("cwd = '%s'\n", cwd); -+ else -+ warning (_("unable to fetch current working directory")); -+ } -+ if (do_exe) -+ { -+ const char *exe = NULL; -+#ifdef HAVE_KINFO_GETFILE -+ struct kinfo_file *kf = fdtbl.get (); -+ for (int i = 0; i < nfd; i++, kf++) -+ { -+ if (kf->kf_type == KF_TYPE_VNODE && kf->kf_fd == KF_FD_TYPE_TEXT) -+ { -+ exe = kf->kf_path; -+ break; -+ } -+ } -+#endif -+ if (exe == NULL) -+ exe = fbsd_pid_to_exec_file (ops, pid); -+ if (exe != NULL) -+ printf_filtered ("exe = '%s'\n", exe); -+ else -+ warning (_("unable to fetch executable path name")); -+ } -+#ifdef HAVE_KINFO_GETVMMAP -+ if (do_mappings) -+ { -+ int nvment; -+ gdb::unique_xmalloc_ptr -+ vmentl (kinfo_getvmmap (pid, &nvment)); -+ -+ if (vmentl != nullptr) -+ { -+ printf_filtered (_("Mapped address spaces:\n\n")); -+#ifdef __LP64__ -+ printf_filtered (" %18s %18s %10s %10s %9s %s\n", -+ "Start Addr", -+ " End Addr", -+ " Size", " Offset", "Flags ", "File"); -+#else -+ printf_filtered ("\t%10s %10s %10s %10s %9s %s\n", -+ "Start Addr", -+ " End Addr", -+ " Size", " Offset", "Flags ", "File"); -+#endif -+ -+ struct kinfo_vmentry *kve = vmentl.get (); -+ for (int i = 0; i < nvment; i++, kve++) -+ { -+ ULONGEST start, end; -+ -+ start = kve->kve_start; -+ end = kve->kve_end; -+#ifdef __LP64__ -+ printf_filtered (" %18s %18s %10s %10s %9s %s\n", -+ hex_string (start), -+ hex_string (end), -+ hex_string (end - start), -+ hex_string (kve->kve_offset), -+ fbsd_vm_map_entry_flags (kve->kve_flags, -+ kve->kve_protection), -+ kve->kve_path); -+#else -+ printf_filtered ("\t%10s %10s %10s %10s %9s %s\n", -+ hex_string (start), -+ hex_string (end), -+ hex_string (end - start), -+ hex_string (kve->kve_offset), -+ fbsd_vm_map_entry_flags (kve->kve_flags, -+ kve->kve_protection), -+ kve->kve_path); -+#endif -+ } -+ } -+ else -+ warning (_("unable to fetch virtual memory map")); -+ } -+#endif -+ if (do_status) -+ { -+ if (!fbsd_fetch_kinfo_proc (pid, &kp)) -+ warning (_("Failed to fetch process information")); -+ else -+ { -+ const char *state; -+ int pgtok; -+ -+ printf_filtered ("Name: %s\n", kp.ki_comm); -+ switch (kp.ki_stat) -+ { -+ case SIDL: -+ state = "I (idle)"; -+ break; -+ case SRUN: -+ state = "R (running)"; -+ break; -+ case SSTOP: -+ state = "T (stopped)"; -+ break; -+ case SZOMB: -+ state = "Z (zombie)"; -+ break; -+ case SSLEEP: -+ state = "S (sleeping)"; -+ break; -+ case SWAIT: -+ state = "W (interrupt wait)"; -+ break; -+ case SLOCK: -+ state = "L (blocked on lock)"; -+ break; -+ default: -+ state = "? (unknown)"; -+ break; -+ } -+ printf_filtered ("State: %s\n", state); -+ printf_filtered ("Parent process: %d\n", kp.ki_ppid); -+ printf_filtered ("Process group: %d\n", kp.ki_pgid); -+ printf_filtered ("Session id: %d\n", kp.ki_sid); -+ printf_filtered ("TTY: %ju\n", (uintmax_t) kp.ki_tdev); -+ printf_filtered ("TTY owner process group: %d\n", kp.ki_tpgid); -+ printf_filtered ("User IDs (real, effective, saved): %d %d %d\n", -+ kp.ki_ruid, kp.ki_uid, kp.ki_svuid); -+ printf_filtered ("Group IDs (real, effective, saved): %d %d %d\n", -+ kp.ki_rgid, kp.ki_groups[0], kp.ki_svgid); -+ printf_filtered ("Groups: "); -+ for (int i = 0; i < kp.ki_ngroups; i++) -+ printf_filtered ("%d ", kp.ki_groups[i]); -+ printf_filtered ("\n"); -+ printf_filtered ("Minor faults (no memory page): %ld\n", -+ kp.ki_rusage.ru_minflt); -+ printf_filtered ("Minor faults, children: %ld\n", -+ kp.ki_rusage_ch.ru_minflt); -+ printf_filtered ("Major faults (memory page faults): %ld\n", -+ kp.ki_rusage.ru_majflt); -+ printf_filtered ("Major faults, children: %ld\n", -+ kp.ki_rusage_ch.ru_majflt); -+ printf_filtered ("utime: %jd.%06ld\n", -+ (intmax_t) kp.ki_rusage.ru_utime.tv_sec, -+ kp.ki_rusage.ru_utime.tv_usec); -+ printf_filtered ("stime: %jd.%06ld\n", -+ (intmax_t) kp.ki_rusage.ru_stime.tv_sec, -+ kp.ki_rusage.ru_stime.tv_usec); -+ printf_filtered ("utime, children: %jd.%06ld\n", -+ (intmax_t) kp.ki_rusage_ch.ru_utime.tv_sec, -+ kp.ki_rusage_ch.ru_utime.tv_usec); -+ printf_filtered ("stime, children: %jd.%06ld\n", -+ (intmax_t) kp.ki_rusage_ch.ru_stime.tv_sec, -+ kp.ki_rusage_ch.ru_stime.tv_usec); -+ printf_filtered ("'nice' value: %d\n", kp.ki_nice); -+ printf_filtered ("Start time: %jd.%06ld\n", kp.ki_start.tv_sec, -+ kp.ki_start.tv_usec); -+ pgtok = getpagesize () / 1024; -+ printf_filtered ("Virtual memory size: %ju kB\n", -+ (uintmax_t) kp.ki_size / 1024); -+ printf_filtered ("Data size: %ju kB\n", -+ (uintmax_t) kp.ki_dsize * pgtok); -+ printf_filtered ("Stack size: %ju kB\n", -+ (uintmax_t) kp.ki_ssize * pgtok); -+ printf_filtered ("Text size: %ju kB\n", -+ (uintmax_t) kp.ki_tsize * pgtok); -+ printf_filtered ("Resident set size: %ju kB\n", -+ (uintmax_t) kp.ki_rssize * pgtok); -+ printf_filtered ("Maximum RSS: %ju kB\n", -+ (uintmax_t) kp.ki_rusage.ru_maxrss); -+ printf_filtered ("Pending Signals: "); -+ for (int i = 0; i < _SIG_WORDS; i++) -+ printf_filtered ("%08x ", kp.ki_siglist.__bits[i]); -+ printf_filtered ("\n"); -+ printf_filtered ("Ignored Signals: "); -+ for (int i = 0; i < _SIG_WORDS; i++) -+ printf_filtered ("%08x ", kp.ki_sigignore.__bits[i]); -+ printf_filtered ("\n"); -+ printf_filtered ("Caught Signals: "); -+ for (int i = 0; i < _SIG_WORDS; i++) -+ printf_filtered ("%08x ", kp.ki_sigcatch.__bits[i]); -+ printf_filtered ("\n"); -+ } -+ } -+} -+ - #ifdef KERN_PROC_AUXV - static enum target_xfer_status (*super_xfer_partial) (struct target_ops *ops, - enum target_object object, -@@ -455,26 +782,6 @@ show_fbsd_lwp_debug (struct ui_file *file, int from_tty, - fprintf_filtered (file, _("Debugging of FreeBSD lwp module is %s.\n"), value); - } - --#if defined(TDP_RFPPWAIT) || defined(HAVE_STRUCT_PTRACE_LWPINFO_PL_TDNAME) --/* Fetch the external variant of the kernel's internal process -- structure for the process PID into KP. */ -- --static void --fbsd_fetch_kinfo_proc (pid_t pid, struct kinfo_proc *kp) --{ -- size_t len; -- int mib[4]; -- -- len = sizeof *kp; -- mib[0] = CTL_KERN; -- mib[1] = KERN_PROC; -- mib[2] = KERN_PROC_PID; -- mib[3] = pid; -- if (sysctl (mib, 4, kp, &len, NULL, 0) == -1) -- perror_with_name (("sysctl")); --} --#endif -- - /* - FreeBSD's first thread support was via a "reentrant" version of libc - (libc_r) that first shipped in 2.2.7. This library multiplexed all -@@ -560,7 +867,8 @@ fbsd_thread_name (struct target_ops *self, struct thread_info *thr) - /* Note that ptrace_lwpinfo returns the process command in pl_tdname - if a name has not been set explicitly. Return a NULL name in - that case. */ -- fbsd_fetch_kinfo_proc (pid, &kp); -+ if (!fbsd_fetch_kinfo_proc (pid, &kp)) -+ perror_with_name (_("Failed to fetch process information")); - if (ptrace (PT_LWPINFO, lwp, (caddr_t) &pl, sizeof pl) == -1) - perror_with_name (("ptrace")); - if (strcmp (kp.ki_comm, pl.pl_tdname) == 0) -@@ -970,9 +1278,13 @@ fbsd_wait (struct target_ops *ops, - #ifndef PTRACE_VFORK - /* For vfork, the child process will have the P_PPWAIT - flag set. */ -- fbsd_fetch_kinfo_proc (child, &kp); -- if (kp.ki_flag & P_PPWAIT) -- ourstatus->kind = TARGET_WAITKIND_VFORKED; -+ if (fbsd_fetch_kinfo_proc (child, &kp)) -+ { -+ if (kp.ki_flag & P_PPWAIT) -+ ourstatus->kind = TARGET_WAITKIND_VFORKED; -+ } -+ else -+ warning (_("Failed to fetch process information")); - #endif - ourstatus->value.related_pid = child_ptid; - -@@ -1176,6 +1488,7 @@ fbsd_nat_add_target (struct target_ops *t) - { - t->to_pid_to_exec_file = fbsd_pid_to_exec_file; - t->to_find_memory_regions = fbsd_find_memory_regions; -+ t->to_info_proc = fbsd_info_proc; - #ifdef KERN_PROC_AUXV - super_xfer_partial = t->to_xfer_partial; - t->to_xfer_partial = fbsd_xfer_partial; Property changes on: head/devel/gdb/files/commit-92fce24de2 ___________________________________________________________________ Deleted: fbsd:nokeywords ## -1 +0,0 ## -yes \ No newline at end of property Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/devel/gdb/files/commit-d2176225dc =================================================================== --- head/devel/gdb/files/commit-d2176225dc (revision 480612) +++ head/devel/gdb/files/commit-d2176225dc (nonexistent) @@ -1,725 +0,0 @@ -commit d2176225dc982c22640215a0e611e997e8eeb030 -Author: John Baldwin -Date: Tue Jan 9 13:35:17 2018 -0800 - - Support 'info proc' for FreeBSD process core dumps. - - - Command line arguments are obtained from the pr_psargs[] array - saved in the NT_PRPSINFO note. - - The 'cwd' and 'exe' values are obtained from the per-process file - descriptor table stored in the NT_PROCSTAT_FILES core note. - - 'mappings' is implemented by walking the array of VM map entries - stored in the NT_PROCSTAT_VMMAP core note. - - 'status' output is generated by outputting fields from - the first structure stored in the NT_PROCSTAT_PROC core note. - - 'stat' is aliased to 'status'. - - gdb/ChangeLog: - - * fbsd-tdep.c (KVE_STRUCTSIZE, KVE_START, KVE_END, KVE_OFFSET) - (KVE_FLAGS, KVE_PROTECTION, KVE_PATH, KINFO_VME_PROT_READ) - (KINFO_VME_PROT_WRITE, KINFO_VME_PROT_EXEC, KINFO_VME_FLAG_COW) - (KINFO_VME_FLAG_NEEDS_COPY, KINFO_VME_FLAG_NOCOREDUMP) - (KINFO_VME_FLAG_SUPER, KINFO_VME_FLAG_GROWS_UP) - (KINFO_VME_FLAG_GROWS_DOWN, KF_STRUCTSIZE, KF_TYPE, KF_FD) - (KF_PATH, KINFO_FILE_TYPE_VNODE, KINFO_FILE_FD_TYPE_CWD) - (KINFO_FILE_FD_TYPE_TEXT, SIG_WORDS, struct kinfo_proc_layout) - (kinfo_proc_layout_32, kinfo_proc_layout_i386) - (kinfo_proc_layout_64, fbsd_vm_map_entry_flags) - (fbsd_core_info_proc_mappings, fbsd_core_vnode_path) - (fbsd_core_fetch_timeval, fbsd_print_sigset) - (fbsd_core_info_proc_status, fbsd_core_info_proc): New. - (fbsd_init_abi): Install gdbarch "core_info_proc" method. - * fbsd-tdep.h (fbsd_vm_map_entry_flags): New. - -diff --git gdb/fbsd-tdep.c gdb/fbsd-tdep.c -index ce17c672d9..8aa0243d54 100644 ---- gdb/fbsd-tdep.c -+++ gdb/fbsd-tdep.c -@@ -52,6 +52,228 @@ - #define SIZE64_SIGINFO_T 80 - #define SIZE32_SIGINFO_T 64 - -+/* Offsets in data structure used in NT_FREEBSD_PROCSTAT_VMMAP core -+ dump notes. See for the definition of struct -+ kinfo_vmentry. This data structure should have the same layout on -+ all architectures. */ -+ -+#define KVE_STRUCTSIZE 0x0 -+#define KVE_START 0x8 -+#define KVE_END 0x10 -+#define KVE_OFFSET 0x18 -+#define KVE_FLAGS 0x2c -+#define KVE_PROTECTION 0x56 -+#define KVE_PATH 0x88 -+ -+/* Flags in the 'kve_protection' field in struct kinfo_vmentry. These -+ match the KVME_PROT_* constants in . */ -+ -+#define KINFO_VME_PROT_READ 0x00000001 -+#define KINFO_VME_PROT_WRITE 0x00000002 -+#define KINFO_VME_PROT_EXEC 0x00000004 -+ -+/* Flags in the 'kve_flags' field in struct kinfo_vmentry. These -+ match the KVME_FLAG_* constants in . */ -+ -+#define KINFO_VME_FLAG_COW 0x00000001 -+#define KINFO_VME_FLAG_NEEDS_COPY 0x00000002 -+#define KINFO_VME_FLAG_NOCOREDUMP 0x00000004 -+#define KINFO_VME_FLAG_SUPER 0x00000008 -+#define KINFO_VME_FLAG_GROWS_UP 0x00000010 -+#define KINFO_VME_FLAG_GROWS_DOWN 0x00000020 -+ -+/* Offsets in data structure used in NT_FREEBSD_PROCSTAT_FILES core -+ dump notes. See for the definition of struct -+ kinfo_file. This data structure should have the same layout on all -+ architectures. */ -+ -+#define KF_STRUCTSIZE 0x0 -+#define KF_TYPE 0x4 -+#define KF_FD 0x8 -+#define KF_PATH 0x170 -+ -+/* Constants for the 'kf_type' field in struct kinfo_file. These -+ match the KF_TYPE_* constants in . */ -+ -+#define KINFO_FILE_TYPE_VNODE 1 -+ -+/* Special values for the 'kf_fd' field in struct kinfo_file. These -+ match the KF_FD_TYPE_* constants in . */ -+ -+#define KINFO_FILE_FD_TYPE_CWD -1 -+#define KINFO_FILE_FD_TYPE_TEXT -5 -+ -+/* Number of 32-bit words in a signal set. This matches _SIG_WORDS in -+ and is the same value on all architectures. */ -+ -+#define SIG_WORDS 4 -+ -+/* Offsets in data structure used in NT_FREEBSD_PROCSTAT_PROC core -+ dump notes. See for the definition of struct -+ kinfo_proc. This data structure has different layouts on different -+ architectures mostly due to ILP32 vs LP64. However, FreeBSD/i386 -+ uses a 32-bit time_t while all other architectures use a 64-bit -+ time_t. -+ -+ The core dump note actually contains one kinfo_proc structure for -+ each thread, but all of the process-wide data can be obtained from -+ the first structure. One result of this note's format is that some -+ of the process-wide status available in the native target method -+ from the kern.proc.pid. sysctl such as ki_stat and ki_siglist -+ is not available from a core dump. Instead, the per-thread data -+ structures contain the value of these fields for individual -+ threads. */ -+ -+struct kinfo_proc_layout -+{ -+ /* Offsets of struct kinfo_proc members. */ -+ int ki_layout; -+ int ki_pid; -+ int ki_ppid; -+ int ki_pgid; -+ int ki_tpgid; -+ int ki_sid; -+ int ki_tdev_freebsd11; -+ int ki_sigignore; -+ int ki_sigcatch; -+ int ki_uid; -+ int ki_ruid; -+ int ki_svuid; -+ int ki_rgid; -+ int ki_svgid; -+ int ki_ngroups; -+ int ki_groups; -+ int ki_size; -+ int ki_rssize; -+ int ki_tsize; -+ int ki_dsize; -+ int ki_ssize; -+ int ki_start; -+ int ki_nice; -+ int ki_comm; -+ int ki_tdev; -+ int ki_rusage; -+ int ki_rusage_ch; -+ -+ /* Offsets of struct rusage members. */ -+ int ru_utime; -+ int ru_stime; -+ int ru_maxrss; -+ int ru_minflt; -+ int ru_majflt; -+}; -+ -+const struct kinfo_proc_layout kinfo_proc_layout_32 = -+ { -+ .ki_layout = 0x4, -+ .ki_pid = 0x28, -+ .ki_ppid = 0x2c, -+ .ki_pgid = 0x30, -+ .ki_tpgid = 0x34, -+ .ki_sid = 0x38, -+ .ki_tdev_freebsd11 = 0x44, -+ .ki_sigignore = 0x68, -+ .ki_sigcatch = 0x78, -+ .ki_uid = 0x88, -+ .ki_ruid = 0x8c, -+ .ki_svuid = 0x90, -+ .ki_rgid = 0x94, -+ .ki_svgid = 0x98, -+ .ki_ngroups = 0x9c, -+ .ki_groups = 0xa0, -+ .ki_size = 0xe0, -+ .ki_rssize = 0xe4, -+ .ki_tsize = 0xec, -+ .ki_dsize = 0xf0, -+ .ki_ssize = 0xf4, -+ .ki_start = 0x118, -+ .ki_nice = 0x145, -+ .ki_comm = 0x17f, -+ .ki_tdev = 0x1f0, -+ .ki_rusage = 0x220, -+ .ki_rusage_ch = 0x278, -+ -+ .ru_utime = 0x0, -+ .ru_stime = 0x10, -+ .ru_maxrss = 0x20, -+ .ru_minflt = 0x30, -+ .ru_majflt = 0x34, -+ }; -+ -+const struct kinfo_proc_layout kinfo_proc_layout_i386 = -+ { -+ .ki_layout = 0x4, -+ .ki_pid = 0x28, -+ .ki_ppid = 0x2c, -+ .ki_pgid = 0x30, -+ .ki_tpgid = 0x34, -+ .ki_sid = 0x38, -+ .ki_tdev_freebsd11 = 0x44, -+ .ki_sigignore = 0x68, -+ .ki_sigcatch = 0x78, -+ .ki_uid = 0x88, -+ .ki_ruid = 0x8c, -+ .ki_svuid = 0x90, -+ .ki_rgid = 0x94, -+ .ki_svgid = 0x98, -+ .ki_ngroups = 0x9c, -+ .ki_groups = 0xa0, -+ .ki_size = 0xe0, -+ .ki_rssize = 0xe4, -+ .ki_tsize = 0xec, -+ .ki_dsize = 0xf0, -+ .ki_ssize = 0xf4, -+ .ki_start = 0x118, -+ .ki_nice = 0x135, -+ .ki_comm = 0x16f, -+ .ki_tdev = 0x1e0, -+ .ki_rusage = 0x210, -+ .ki_rusage_ch = 0x258, -+ -+ .ru_utime = 0x0, -+ .ru_stime = 0x8, -+ .ru_maxrss = 0x10, -+ .ru_minflt = 0x20, -+ .ru_majflt = 0x24, -+ }; -+ -+const struct kinfo_proc_layout kinfo_proc_layout_64 = -+ { -+ .ki_layout = 0x4, -+ .ki_pid = 0x48, -+ .ki_ppid = 0x4c, -+ .ki_pgid = 0x50, -+ .ki_tpgid = 0x54, -+ .ki_sid = 0x58, -+ .ki_tdev_freebsd11 = 0x64, -+ .ki_sigignore = 0x88, -+ .ki_sigcatch = 0x98, -+ .ki_uid = 0xa8, -+ .ki_ruid = 0xac, -+ .ki_svuid = 0xb0, -+ .ki_rgid = 0xb4, -+ .ki_svgid = 0xb8, -+ .ki_ngroups = 0xbc, -+ .ki_groups = 0xc0, -+ .ki_size = 0x100, -+ .ki_rssize = 0x108, -+ .ki_tsize = 0x118, -+ .ki_dsize = 0x120, -+ .ki_ssize = 0x128, -+ .ki_start = 0x150, -+ .ki_nice = 0x185, -+ .ki_comm = 0x1bf, -+ .ki_tdev = 0x230, -+ .ki_rusage = 0x260, -+ .ki_rusage_ch = 0x2f0, -+ -+ .ru_utime = 0x0, -+ .ru_stime = 0x10, -+ .ru_maxrss = 0x20, -+ .ru_minflt = 0x40, -+ .ru_majflt = 0x48, -+ }; -+ - static struct gdbarch_data *fbsd_gdbarch_data_handle; - - struct fbsd_gdbarch_data -@@ -367,6 +589,433 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) - return note_data; - } - -+/* Helper function to generate mappings flags for a single VM map -+ entry in 'info proc mappings'. */ -+ -+const char * -+fbsd_vm_map_entry_flags (int kve_flags, int kve_protection) -+{ -+ static char vm_flags[9]; -+ -+ vm_flags[0] = (kve_protection & KINFO_VME_PROT_READ) ? 'r' : '-'; -+ vm_flags[1] = (kve_protection & KINFO_VME_PROT_WRITE) ? 'w' : '-'; -+ vm_flags[2] = (kve_protection & KINFO_VME_PROT_EXEC) ? 'x' : '-'; -+ vm_flags[3] = ' '; -+ vm_flags[4] = (kve_flags & KINFO_VME_FLAG_COW) ? 'C' : '-'; -+ vm_flags[5] = (kve_flags & KINFO_VME_FLAG_NEEDS_COPY) ? 'N' : '-'; -+ vm_flags[6] = (kve_flags & KINFO_VME_FLAG_SUPER) ? 'S' : '-'; -+ vm_flags[7] = (kve_flags & KINFO_VME_FLAG_GROWS_UP) ? 'U' -+ : (kve_flags & KINFO_VME_FLAG_GROWS_DOWN) ? 'D' : '-'; -+ vm_flags[8] = '\0'; -+ -+ return vm_flags; -+} -+ -+/* Implement "info proc mappings" for a corefile. */ -+ -+static void -+fbsd_core_info_proc_mappings (struct gdbarch *gdbarch) -+{ -+ asection *section; -+ unsigned char *descdata, *descend; -+ size_t note_size; -+ -+ section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.vmmap"); -+ if (section == NULL) -+ { -+ warning (_("unable to find mappings in core file")); -+ return; -+ } -+ -+ note_size = bfd_get_section_size (section); -+ if (note_size < 4) -+ error (_("malformed core note - too short for header")); -+ -+ gdb::def_vector contents (note_size); -+ if (!bfd_get_section_contents (core_bfd, section, contents.data (), -+ 0, note_size)) -+ error (_("could not get core note contents")); -+ -+ descdata = contents.data (); -+ descend = descdata + note_size; -+ -+ /* Skip over the structure size. */ -+ descdata += 4; -+ -+ printf_filtered (_("Mapped address spaces:\n\n")); -+ if (gdbarch_addr_bit (gdbarch) == 64) -+ { -+ printf_filtered (" %18s %18s %10s %10s %9s %s\n", -+ "Start Addr", -+ " End Addr", -+ " Size", " Offset", "Flags ", "File"); -+ } -+ else -+ { -+ printf_filtered ("\t%10s %10s %10s %10s %9s %s\n", -+ "Start Addr", -+ " End Addr", -+ " Size", " Offset", "Flags ", "File"); -+ } -+ -+ while (descdata + KVE_PATH < descend) -+ { -+ ULONGEST start, end, offset, flags, prot, structsize; -+ -+ structsize = bfd_get_32 (core_bfd, descdata + KVE_STRUCTSIZE); -+ if (structsize < KVE_PATH) -+ error (_("malformed core note - vmmap entry too small")); -+ -+ start = bfd_get_64 (core_bfd, descdata + KVE_START); -+ end = bfd_get_64 (core_bfd, descdata + KVE_END); -+ offset = bfd_get_64 (core_bfd, descdata + KVE_OFFSET); -+ flags = bfd_get_32 (core_bfd, descdata + KVE_FLAGS); -+ prot = bfd_get_32 (core_bfd, descdata + KVE_PROTECTION); -+ if (gdbarch_addr_bit (gdbarch) == 64) -+ { -+ printf_filtered (" %18s %18s %10s %10s %9s %s\n", -+ paddress (gdbarch, start), -+ paddress (gdbarch, end), -+ hex_string (end - start), -+ hex_string (offset), -+ fbsd_vm_map_entry_flags (flags, prot), -+ descdata + KVE_PATH); -+ } -+ else -+ { -+ printf_filtered ("\t%10s %10s %10s %10s %9s %s\n", -+ paddress (gdbarch, start), -+ paddress (gdbarch, end), -+ hex_string (end - start), -+ hex_string (offset), -+ fbsd_vm_map_entry_flags (flags, prot), -+ descdata + KVE_PATH); -+ } -+ -+ descdata += structsize; -+ } -+} -+ -+/* Fetch the pathname of a vnode for a single file descriptor from the -+ file table core note. */ -+ -+static gdb::unique_xmalloc_ptr -+fbsd_core_vnode_path (struct gdbarch *gdbarch, int fd) -+{ -+ asection *section; -+ unsigned char *descdata, *descend; -+ size_t note_size; -+ -+ section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files"); -+ if (section == NULL) -+ return nullptr; -+ -+ note_size = bfd_get_section_size (section); -+ if (note_size < 4) -+ error (_("malformed core note - too short for header")); -+ -+ gdb::def_vector contents (note_size); -+ if (!bfd_get_section_contents (core_bfd, section, contents.data (), -+ 0, note_size)) -+ error (_("could not get core note contents")); -+ -+ descdata = contents.data (); -+ descend = descdata + note_size; -+ -+ /* Skip over the structure size. */ -+ descdata += 4; -+ -+ while (descdata + KVE_PATH < descend) -+ { -+ ULONGEST structsize; -+ -+ structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE); -+ if (structsize < KVE_PATH) -+ error (_("malformed core note - vmmap entry too small")); -+ -+ if (bfd_get_32 (core_bfd, descdata + KF_TYPE) == KINFO_FILE_TYPE_VNODE -+ && bfd_get_signed_32 (core_bfd, descdata + KF_FD) == fd) -+ { -+ char *path = (char *) descdata + KF_PATH; -+ return gdb::unique_xmalloc_ptr (xstrdup (path)); -+ } -+ -+ descdata += structsize; -+ } -+ return nullptr; -+} -+ -+/* Helper function to read a struct timeval. */ -+ -+static void -+fbsd_core_fetch_timeval (struct gdbarch *gdbarch, unsigned char *data, -+ LONGEST &sec, ULONGEST &usec) -+{ -+ if (gdbarch_addr_bit (gdbarch) == 64) -+ { -+ sec = bfd_get_signed_64 (core_bfd, data); -+ usec = bfd_get_64 (core_bfd, data + 8); -+ } -+ else if (bfd_get_arch (core_bfd) == bfd_arch_i386) -+ { -+ sec = bfd_get_signed_32 (core_bfd, data); -+ usec = bfd_get_32 (core_bfd, data + 4); -+ } -+ else -+ { -+ sec = bfd_get_signed_64 (core_bfd, data); -+ usec = bfd_get_32 (core_bfd, data + 8); -+ } -+} -+ -+/* Print out the contents of a signal set. */ -+ -+static void -+fbsd_print_sigset (const char *descr, unsigned char *sigset) -+{ -+ printf_filtered ("%s: ", descr); -+ for (int i = 0; i < SIG_WORDS; i++) -+ printf_filtered ("%08x ", -+ (unsigned int) bfd_get_32 (core_bfd, sigset + i * 4)); -+ printf_filtered ("\n"); -+} -+ -+/* Implement "info proc status" for a corefile. */ -+ -+static void -+fbsd_core_info_proc_status (struct gdbarch *gdbarch) -+{ -+ const struct kinfo_proc_layout *kp; -+ asection *section; -+ const char *state; -+ unsigned char *descdata; -+ int addr_bit, long_bit; -+ size_t note_size; -+ ULONGEST value; -+ LONGEST sec; -+ -+ section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.proc"); -+ if (section == NULL) -+ { -+ warning (_("unable to find process info in core file")); -+ return; -+ } -+ -+ addr_bit = gdbarch_addr_bit (gdbarch); -+ if (addr_bit == 64) -+ kp = &kinfo_proc_layout_64; -+ else if (bfd_get_arch (core_bfd) == bfd_arch_i386) -+ kp = &kinfo_proc_layout_i386; -+ else -+ kp = &kinfo_proc_layout_32; -+ long_bit = gdbarch_long_bit (gdbarch); -+ -+ /* -+ * Ensure that the note is large enough for all of the fields fetched -+ * by this function. In particular, the note must contain the 32-bit -+ * structure size, then it must be long enough to access the last -+ * field used (ki_rusage_ch.ru_majflt) which is the size of a long. -+ */ -+ note_size = bfd_get_section_size (section); -+ if (note_size < (4 + kp->ki_rusage_ch + kp->ru_majflt -+ + long_bit / TARGET_CHAR_BIT)) -+ error (_("malformed core note - too short")); -+ -+ gdb::def_vector contents (note_size); -+ if (!bfd_get_section_contents (core_bfd, section, contents.data (), -+ 0, note_size)) -+ error (_("could not get core note contents")); -+ -+ descdata = contents.data (); -+ -+ /* Skip over the structure size. */ -+ descdata += 4; -+ -+ /* Verify 'ki_layout' is 0. */ -+ if (bfd_get_32 (core_bfd, descdata + kp->ki_layout) != 0) -+ { -+ warning (_("unsupported process information in core file")); -+ return; -+ } -+ -+ printf_filtered ("Name: %.19s\n", descdata + kp->ki_comm); -+ printf_filtered ("Process ID: %s\n", -+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pid))); -+ printf_filtered ("Parent process: %s\n", -+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ppid))); -+ printf_filtered ("Process group: %s\n", -+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pgid))); -+ printf_filtered ("Session id: %s\n", -+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_sid))); -+ -+ /* FreeBSD 12.0 and later store a 64-bit dev_t at 'ki_tdev'. Older -+ kernels store a 32-bit dev_t at 'ki_tdev_freebsd11'. In older -+ kernels the 64-bit 'ki_tdev' field is in a reserved section of -+ the structure that is cleared to zero. Assume that a zero value -+ in ki_tdev indicates a core dump from an older kernel and use the -+ value in 'ki_tdev_freebsd11' instead. */ -+ value = bfd_get_64 (core_bfd, descdata + kp->ki_tdev); -+ if (value == 0) -+ value = bfd_get_32 (core_bfd, descdata + kp->ki_tdev_freebsd11); -+ printf_filtered ("TTY: %s\n", pulongest (value)); -+ printf_filtered ("TTY owner process group: %s\n", -+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_tpgid))); -+ printf_filtered ("User IDs (real, effective, saved): %s %s %s\n", -+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ruid)), -+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_uid)), -+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svuid))); -+ printf_filtered ("Group IDs (real, effective, saved): %s %s %s\n", -+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_rgid)), -+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_groups)), -+ pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svgid))); -+ printf_filtered ("Groups: "); -+ uint16_t ngroups = bfd_get_16 (core_bfd, descdata + kp->ki_ngroups); -+ for (int i = 0; i < ngroups; i++) -+ printf_filtered ("%s ", -+ pulongest (bfd_get_32 (core_bfd, -+ descdata + kp->ki_groups + i * 4))); -+ printf_filtered ("\n"); -+ value = bfd_get (long_bit, core_bfd, -+ descdata + kp->ki_rusage + kp->ru_minflt); -+ printf_filtered ("Minor faults (no memory page): %s\n", pulongest (value)); -+ value = bfd_get (long_bit, core_bfd, -+ descdata + kp->ki_rusage_ch + kp->ru_minflt); -+ printf_filtered ("Minor faults, children: %s\n", pulongest (value)); -+ value = bfd_get (long_bit, core_bfd, -+ descdata + kp->ki_rusage + kp->ru_majflt); -+ printf_filtered ("Major faults (memory page faults): %s\n", -+ pulongest (value)); -+ value = bfd_get (long_bit, core_bfd, -+ descdata + kp->ki_rusage_ch + kp->ru_majflt); -+ printf_filtered ("Major faults, children: %s\n", pulongest (value)); -+ fbsd_core_fetch_timeval (gdbarch, -+ descdata + kp->ki_rusage + kp->ru_utime, -+ sec, value); -+ printf_filtered ("utime: %s.%06d\n", plongest (sec), (int) value); -+ fbsd_core_fetch_timeval (gdbarch, -+ descdata + kp->ki_rusage + kp->ru_stime, -+ sec, value); -+ printf_filtered ("stime: %s.%06d\n", plongest (sec), (int) value); -+ fbsd_core_fetch_timeval (gdbarch, -+ descdata + kp->ki_rusage_ch + kp->ru_utime, -+ sec, value); -+ printf_filtered ("utime, children: %s.%06d\n", plongest (sec), (int) value); -+ fbsd_core_fetch_timeval (gdbarch, -+ descdata + kp->ki_rusage_ch + kp->ru_stime, -+ sec, value); -+ printf_filtered ("stime, children: %s.%06d\n", plongest (sec), (int) value); -+ printf_filtered ("'nice' value: %d\n", -+ bfd_get_signed_8 (core_bfd, descdata + kp->ki_nice)); -+ fbsd_core_fetch_timeval (gdbarch, descdata + kp->ki_start, sec, value); -+ printf_filtered ("Start time: %s.%06d\n", plongest (sec), (int) value); -+ printf_filtered ("Virtual memory size: %s kB\n", -+ pulongest (bfd_get (addr_bit, core_bfd, -+ descdata + kp->ki_size) / 1024)); -+ printf_filtered ("Data size: %s pages\n", -+ pulongest (bfd_get (addr_bit, core_bfd, -+ descdata + kp->ki_dsize))); -+ printf_filtered ("Stack size: %s pages\n", -+ pulongest (bfd_get (addr_bit, core_bfd, -+ descdata + kp->ki_ssize))); -+ printf_filtered ("Text size: %s pages\n", -+ pulongest (bfd_get (addr_bit, core_bfd, -+ descdata + kp->ki_tsize))); -+ printf_filtered ("Resident set size: %s pages\n", -+ pulongest (bfd_get (addr_bit, core_bfd, -+ descdata + kp->ki_rssize))); -+ printf_filtered ("Maximum RSS: %s pages\n", -+ pulongest (bfd_get (long_bit, core_bfd, -+ descdata + kp->ki_rusage -+ + kp->ru_maxrss))); -+ fbsd_print_sigset ("Ignored Signals", descdata + kp->ki_sigignore); -+ fbsd_print_sigset ("Caught Signals", descdata + kp->ki_sigcatch); -+} -+ -+/* Implement the "core_info_proc" gdbarch method. */ -+ -+static void -+fbsd_core_info_proc (struct gdbarch *gdbarch, const char *args, -+ enum info_proc_what what) -+{ -+ bool do_cmdline = false; -+ bool do_cwd = false; -+ bool do_exe = false; -+ bool do_mappings = false; -+ bool do_status = false; -+ int pid; -+ -+ switch (what) -+ { -+ case IP_MINIMAL: -+ do_cmdline = true; -+ do_cwd = true; -+ do_exe = true; -+ break; -+ case IP_MAPPINGS: -+ do_mappings = true; -+ break; -+ case IP_STATUS: -+ case IP_STAT: -+ do_status = true; -+ break; -+ case IP_CMDLINE: -+ do_cmdline = true; -+ break; -+ case IP_EXE: -+ do_exe = true; -+ break; -+ case IP_CWD: -+ do_cwd = true; -+ break; -+ case IP_ALL: -+ do_cmdline = true; -+ do_cwd = true; -+ do_exe = true; -+ do_mappings = true; -+ do_status = true; -+ break; -+ default: -+ return; -+ } -+ -+ pid = bfd_core_file_pid (core_bfd); -+ if (pid != 0) -+ printf_filtered (_("process %d\n"), pid); -+ -+ if (do_cmdline) -+ { -+ const char *cmdline; -+ -+ cmdline = bfd_core_file_failing_command (core_bfd); -+ if (cmdline) -+ printf_filtered ("cmdline = '%s'\n", cmdline); -+ else -+ warning (_("Command line unavailable")); -+ } -+ if (do_cwd) -+ { -+ gdb::unique_xmalloc_ptr cwd = -+ fbsd_core_vnode_path (gdbarch, KINFO_FILE_FD_TYPE_CWD); -+ if (cwd) -+ printf_filtered ("cwd = '%s'\n", cwd.get ()); -+ else -+ warning (_("unable to read current working directory")); -+ } -+ if (do_exe) -+ { -+ gdb::unique_xmalloc_ptr exe = -+ fbsd_core_vnode_path (gdbarch, KINFO_FILE_FD_TYPE_TEXT); -+ if (exe) -+ printf_filtered ("exe = '%s'\n", exe.get ()); -+ else -+ warning (_("unable to read executable path name")); -+ } -+ if (do_mappings) -+ fbsd_core_info_proc_mappings (gdbarch); -+ if (do_status) -+ fbsd_core_info_proc_status (gdbarch); -+} -+ - /* Print descriptions of FreeBSD-specific AUXV entries to FILE. */ - - static void -@@ -519,6 +1168,7 @@ fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) - set_gdbarch_core_thread_name (gdbarch, fbsd_core_thread_name); - set_gdbarch_core_xfer_siginfo (gdbarch, fbsd_core_xfer_siginfo); - set_gdbarch_make_corefile_notes (gdbarch, fbsd_make_corefile_notes); -+ set_gdbarch_core_info_proc (gdbarch, fbsd_core_info_proc); - set_gdbarch_print_auxv_entry (gdbarch, fbsd_print_auxv_entry); - set_gdbarch_get_siginfo_type (gdbarch, fbsd_get_siginfo_type); - -diff --git gdb/fbsd-tdep.h gdb/fbsd-tdep.h -index 9769903dec..0b293e5a25 100644 ---- gdb/fbsd-tdep.h -+++ gdb/fbsd-tdep.h -@@ -22,4 +22,11 @@ - - extern void fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch); - -+/* Helper function to generate mappings flags for a single VM map -+ entry in 'info proc mappings'. The KVE_FLAGS and KVE_PROTECTION -+ parameters should contain the values of the corresponding fields in -+ a 'struct kinfo_vmentry'. */ -+ -+extern const char *fbsd_vm_map_entry_flags (int kve_flags, int kve_protection); -+ - #endif /* fbsd-tdep.h */ Property changes on: head/devel/gdb/files/commit-d2176225dc ___________________________________________________________________ Deleted: fbsd:nokeywords ## -1 +0,0 ## -yes \ No newline at end of property Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/devel/gdb/files/commit-f169cfdc08 =================================================================== --- head/devel/gdb/files/commit-f169cfdc08 (revision 480612) +++ head/devel/gdb/files/commit-f169cfdc08 (nonexistent) @@ -1,84 +0,0 @@ -commit f169cfdc08761a3d9fcd587ad8661102672403ec -Author: John Baldwin -Date: Tue Oct 24 21:06:00 2017 -0700 - - Workaround a FreeBSD ptrace() bug with clearing thread events. - - When multiple threads within a process wish to report STOPPED events - from wait(), the kernel picks one thread event as the thread event to - report. The chosen thread event is retrieved via PT_LWPINFO by - passing the process ID as the request pid. If multiple events are - pending, then the subsequent wait() after resuming a process will - report another STOPPED event after resuming the process to handle the - next thread event and so on. - - A single thread event is cleared as a side effect of resuming the - process with PT_CONTINUE, PT_STEP, etc. In older kernels, however, - the request pid was used to select which thread's event was cleared - rather than always clearing the event that was just reported. To - avoid clearing the event of the wrong LWP, always pass the process ID - instead of an LWP ID to PT_CONTINUE or PT_SYSCALL. - - In the case of stepping, the process ID cannot be used with PT_STEP - since it would step the thread that reported an event which may not be - the thread indicated by PTID. For stepping, use PT_SETSTEP to enable - stepping on the desired thread before resuming the process via - PT_CONTINUE instead of using PT_STEP. - - This manifested as a failure in the - gdb.threads/continue-pending-status.exp test. Specifically, if thread - 2 reported a breakpoint and the test thus switched to thread 3 before - continuing, thread 3's event (if any) was discarded and thread 2's - breakpoint remained pending and was reported a second time as a - duplicate event. As a result, the PC was decremented twice for the - same breakpoint resulting in an illegal instruction fault on x86. - - gdb/ChangeLog: - - * fbsd-nat.c (fbsd_resume): Use PT_SETSTEP for stepping and a - wildcard process pid for super_resume for kernels with a - specific bug. - -diff --git gdb/fbsd-nat.c gdb/fbsd-nat.c -index b352418813..3a216abf18 100644 ---- gdb/fbsd-nat.c -+++ gdb/fbsd-nat.c -@@ -1143,6 +1143,38 @@ fbsd_resume (struct target_ops *ops, - } - ptid = inferior_ptid; - } -+ -+#if __FreeBSD_version < 1200052 -+ /* When multiple threads within a process wish to report STOPPED -+ events from wait(), the kernel picks one thread event as the -+ thread event to report. The chosen thread event is retrieved via -+ PT_LWPINFO by passing the process ID as the request pid. If -+ multiple events are pending, then the subsequent wait() after -+ resuming a process will report another STOPPED event after -+ resuming the process to handle the next thread event and so on. -+ -+ A single thread event is cleared as a side effect of resuming the -+ process with PT_CONTINUE, PT_STEP, etc. In older kernels, -+ however, the request pid was used to select which thread's event -+ was cleared rather than always clearing the event that was just -+ reported. To avoid clearing the event of the wrong LWP, always -+ pass the process ID instead of an LWP ID to PT_CONTINUE or -+ PT_SYSCALL. -+ -+ In the case of stepping, the process ID cannot be used with -+ PT_STEP since it would step the thread that reported an event -+ which may not be the thread indicated by PTID. For stepping, use -+ PT_SETSTEP to enable stepping on the desired thread before -+ resuming the process via PT_CONTINUE instead of using -+ PT_STEP. */ -+ if (step) -+ { -+ if (ptrace (PT_SETSTEP, get_ptrace_pid (ptid), NULL, 0) == -1) -+ perror_with_name (("ptrace")); -+ step = 0; -+ } -+ ptid = ptid_t (ptid.pid ()); -+#endif - super_resume (ops, ptid, step, signo); - } - Property changes on: head/devel/gdb/files/commit-f169cfdc08 ___________________________________________________________________ Deleted: fbsd:nokeywords ## -1 +0,0 ## -yes \ No newline at end of property Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/devel/gdb/files/commit-8aa0243d54 =================================================================== --- head/devel/gdb/files/commit-8aa0243d54 (nonexistent) +++ head/devel/gdb/files/commit-8aa0243d54 (revision 480613) @@ -0,0 +1,197 @@ +commit 739ab2e92e1840c9285f3cfce1f1236c0fa68730 +Author: Simon Ser +Date: Thu Sep 6 15:03:19 2018 -0700 + + Generate NT_PROCSTAT_{AUXV,VMMAP,PS_STRINGS} in FreeBSD coredumps + + gcore generates NT_AUXV and NT_FILE notes for Linux targets. On + FreeBSD auxv is stored in a NT_PROCSTAT_AUXV section, virtual memory + mappings are stored in a NT_PROCSTAT_VMMAP, and both are prefixed with + the struct size. In addition, store a NT_PROCSTAT_PS_STRINGS note + saving the initial location of the argv[] and environment[] arrays. + + gdb/ChangeLog: + + PR gdb/23105 + * fbsd-nat.c (fbsd_nat_target::xfer_partial): Add support for + TARGET_OBJECT_FREEBSD_VMMAP and TARGET_OBJECT_FREEBSD_PS_STRINGS. + * fbsd-tdep.c (fbsd_make_note_desc): New. + (fbsd_make_corefile_notes): Write NT_PROCSTAT_AUXV, + NT_PROCSTAT_VMMAP and NT_PROCSTAT_PS_STRINGS notes. + * target.h (enum target_object) Add FreeBSD-specific + TARGET_OBJECT_FREEBSD_VMMAP and TARGET_OBJECT_FREEBSD_PS_STRINGS. + +diff --git gdb/ChangeLog gdb/ChangeLog +index 410fbef920..e6f44a3ac2 100644 +--- gdb/ChangeLog ++++ gdb/ChangeLog +@@ -1,3 +1,14 @@ ++2018-09-06 Simon Ser ++ ++ PR gdb/23105 ++ * fbsd-nat.c (fbsd_nat_target::xfer_partial): Add support for ++ TARGET_OBJECT_FREEBSD_VMMAP and TARGET_OBJECT_FREEBSD_PS_STRINGS. ++ * fbsd-tdep.c (fbsd_make_note_desc): New. ++ (fbsd_make_corefile_notes): Write NT_PROCSTAT_AUXV, ++ NT_PROCSTAT_VMMAP and NT_PROCSTAT_PS_STRINGS notes. ++ * target.h (enum target_object) Add FreeBSD-specific ++ TARGET_OBJECT_FREEBSD_VMMAP and TARGET_OBJECT_FREEBSD_PS_STRINGS. ++ + 2018-09-06 Simon Marchi + + * compile/compile-c.h (generate_c_for_variable_locations): +diff --git gdb/fbsd-nat.c gdb/fbsd-nat.c +index 115deac070..a255318d14 100644 +--- gdb/fbsd-nat.c ++++ gdb/fbsd-nat.c +@@ -751,6 +751,61 @@ fbsd_nat_target::xfer_partial (enum target_object object, + } + return TARGET_XFER_E_IO; + } ++ case TARGET_OBJECT_FREEBSD_VMMAP: ++ case TARGET_OBJECT_FREEBSD_PS_STRINGS: ++ { ++ gdb::byte_vector buf_storage; ++ gdb_byte *buf; ++ size_t buflen; ++ int mib[4]; ++ ++ int proc_target; ++ uint32_t struct_size; ++ switch (object) ++ { ++ case TARGET_OBJECT_FREEBSD_VMMAP: ++ proc_target = KERN_PROC_VMMAP; ++ struct_size = sizeof (struct kinfo_vmentry); ++ break; ++ case TARGET_OBJECT_FREEBSD_PS_STRINGS: ++ proc_target = KERN_PROC_PS_STRINGS; ++ struct_size = sizeof (void *); ++ break; ++ } ++ ++ if (writebuf != NULL) ++ return TARGET_XFER_E_IO; ++ ++ mib[0] = CTL_KERN; ++ mib[1] = KERN_PROC; ++ mib[2] = proc_target; ++ mib[3] = pid; ++ ++ if (sysctl (mib, 4, NULL, &buflen, NULL, 0) != 0) ++ return TARGET_XFER_E_IO; ++ buflen += sizeof (struct_size); ++ ++ if (offset >= buflen) ++ { ++ *xfered_len = 0; ++ return TARGET_XFER_EOF; ++ } ++ ++ buf_storage.resize (buflen); ++ buf = buf_storage.data (); ++ ++ memcpy (buf, &struct_size, sizeof (struct_size)); ++ buflen -= sizeof (struct_size); ++ if (sysctl (mib, 4, buf + sizeof (struct_size), &buflen, NULL, 0) != 0) ++ return TARGET_XFER_E_IO; ++ buflen += sizeof (struct_size); ++ ++ if (buflen - offset < len) ++ len = buflen - offset; ++ memcpy (readbuf, buf + offset, len); ++ *xfered_len = len; ++ return TARGET_XFER_OK; ++ } + default: + return inf_ptrace_target::xfer_partial (object, annex, + readbuf, writebuf, offset, +diff --git gdb/fbsd-tdep.c gdb/fbsd-tdep.c +index 78d0c3d830..ed43087169 100644 +--- gdb/fbsd-tdep.c ++++ gdb/fbsd-tdep.c +@@ -512,6 +512,28 @@ fbsd_corefile_thread (struct thread_info *info, + args->note_size, args->stop_signal); + } + ++/* Return a byte_vector containing the contents of a core dump note ++ for the target object of type OBJECT. If STRUCTSIZE is non-zero, ++ the data is prefixed with a 32-bit integer size to match the format ++ used in FreeBSD NT_PROCSTAT_* notes. */ ++ ++static gdb::optional ++fbsd_make_note_desc (enum target_object object, uint32_t structsize) ++{ ++ gdb::optional buf = ++ target_read_alloc (current_top_target (), object, NULL); ++ if (!buf || buf->empty ()) ++ return {}; ++ ++ if (structsize == 0) ++ return buf; ++ ++ gdb::byte_vector desc (sizeof (structsize) + buf->size ()); ++ memcpy (desc.data (), &structsize, sizeof (structsize)); ++ memcpy (desc.data () + sizeof (structsize), buf->data (), buf->size ()); ++ return desc; ++} ++ + /* Create appropriate note sections for a corefile, returning them in + allocated memory. */ + +@@ -586,6 +608,40 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) + + note_data = thread_args.note_data; + ++ /* Auxiliary vector. */ ++ uint32_t structsize = gdbarch_ptr_bit (gdbarch) / 4; /* Elf_Auxinfo */ ++ gdb::optional note_desc = ++ fbsd_make_note_desc (TARGET_OBJECT_AUXV, structsize); ++ if (note_desc && !note_desc->empty ()) ++ { ++ note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD", ++ NT_FREEBSD_PROCSTAT_AUXV, ++ note_desc->data (), note_desc->size ()); ++ if (!note_data) ++ return NULL; ++ } ++ ++ /* Virtual memory mappings. */ ++ note_desc = fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_VMMAP, 0); ++ if (note_desc && !note_desc->empty ()) ++ { ++ note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD", ++ NT_FREEBSD_PROCSTAT_VMMAP, ++ note_desc->data (), note_desc->size ()); ++ if (!note_data) ++ return NULL; ++ } ++ ++ note_desc = fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_PS_STRINGS, 0); ++ if (note_desc && !note_desc->empty ()) ++ { ++ note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD", ++ NT_FREEBSD_PROCSTAT_PSSTRINGS, ++ note_desc->data (), note_desc->size ()); ++ if (!note_data) ++ return NULL; ++ } ++ + return note_data; + } + +diff --git gdb/target.h gdb/target.h +index 229b5d0551..a3000c80c6 100644 +--- gdb/target.h ++++ gdb/target.h +@@ -202,6 +202,10 @@ enum target_object + of the process ID of the process in question, in hexadecimal + format. */ + TARGET_OBJECT_EXEC_FILE, ++ /* FreeBSD virtual memory mappings. */ ++ TARGET_OBJECT_FREEBSD_VMMAP, ++ /* FreeBSD process strings. */ ++ TARGET_OBJECT_FREEBSD_PS_STRINGS, + /* Possible future objects: TARGET_OBJECT_FILE, ... */ + }; + Property changes on: head/devel/gdb/files/commit-8aa0243d54 ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/devel/gdb/files/extrapatch-kgdb =================================================================== --- head/devel/gdb/files/extrapatch-kgdb (revision 480612) +++ head/devel/gdb/files/extrapatch-kgdb (revision 480613) @@ -1,458 +1,457 @@ diff --git gdb/Makefile.in gdb/Makefile.in -index 17b71c6e7c..95e92d08b4 100644 +index 13627e07e0..a72fd8fe0f 100644 --- gdb/Makefile.in +++ gdb/Makefile.in -@@ -230,7 +230,8 @@ INCGNU = -I$(srcdir)/gnulib/import -I$(GNULIB_BUILDDIR)/import +@@ -236,7 +236,8 @@ INCGNU = -I$(srcdir)/gnulib/import -I$(GNULIB_BUILDDIR)/import # Generated headers in the gnulib directory. These must be listed # so that they are generated before other files are compiled. -GNULIB_H = $(GNULIB_BUILDDIR)/import/string.h @GNULIB_STDINT_H@ +GNULIB_H = $(GNULIB_BUILDDIR)/import/string.h \ + $(GNULIB_BUILDDIR)/import/alloca.h @GNULIB_STDINT_H@ # # CLI sub directory definitons -@@ -629,6 +630,7 @@ TARGET_OBS = @TARGET_OBS@ +@@ -643,6 +644,7 @@ TARGET_OBS = @TARGET_OBS@ # All target-dependent objects files that require 64-bit CORE_ADDR # (used with --enable-targets=all --enable-64-bit-bfd). ALL_64_TARGET_OBS = \ + aarch64-fbsd-kern.o \ aarch64-fbsd-tdep.o \ aarch64-linux-tdep.o \ aarch64-newlib-tdep.o \ -@@ -642,6 +644,7 @@ ALL_64_TARGET_OBS = \ +@@ -656,6 +658,7 @@ ALL_64_TARGET_OBS = \ amd64-darwin-tdep.o \ amd64-dicos-tdep.o \ amd64-fbsd-tdep.o \ + amd64fbsd-kern.o \ amd64-linux-tdep.o \ amd64-nbsd-tdep.o \ amd64-obsd-tdep.o \ -@@ -656,6 +659,7 @@ ALL_64_TARGET_OBS = \ +@@ -670,6 +673,7 @@ ALL_64_TARGET_OBS = \ ia64-vms-tdep.o \ mips64-obsd-tdep.o \ sparc64-fbsd-tdep.o \ + sparc64fbsd-kern.o \ sparc64-linux-tdep.o \ sparc64-nbsd-tdep.o \ sparc64-obsd-tdep.o \ -@@ -670,6 +674,7 @@ ALL_TARGET_OBS = \ - arch/arm-linux.o \ +@@ -685,6 +689,7 @@ ALL_TARGET_OBS = \ arch/i386.o \ + arch/ppc-linux-common.o \ arm-bsd-tdep.o \ + arm-fbsd-kern.o \ arm-fbsd-tdep.o \ arm-linux-tdep.o \ arm-nbsd-tdep.o \ -@@ -684,6 +689,8 @@ ALL_TARGET_OBS = \ +@@ -699,6 +704,8 @@ ALL_TARGET_OBS = \ cris-linux-tdep.o \ cris-tdep.o \ dicos-tdep.o \ + fbsd-kld.o \ + fbsd-kthr.o \ fbsd-tdep.o \ frv-linux-tdep.o \ frv-tdep.o \ -@@ -700,6 +707,7 @@ ALL_TARGET_OBS = \ +@@ -715,6 +722,7 @@ ALL_TARGET_OBS = \ i386-darwin-tdep.o \ i386-dicos-tdep.o \ i386-fbsd-tdep.o \ + i386fbsd-kern.o \ i386-gnu-tdep.o \ i386-go32-tdep.o \ i386-linux-tdep.o \ -@@ -724,6 +732,7 @@ ALL_TARGET_OBS = \ +@@ -738,6 +746,7 @@ ALL_TARGET_OBS = \ mep-tdep.o \ microblaze-linux-tdep.o \ microblaze-tdep.o \ + mipsfbsd-kern.o \ mips-fbsd-tdep.o \ mips-linux-tdep.o \ mips-nbsd-tdep.o \ -@@ -741,6 +750,7 @@ ALL_TARGET_OBS = \ - nto-tdep.o \ +@@ -755,6 +764,7 @@ ALL_TARGET_OBS = \ obsd-tdep.o \ + or1k-tdep.o \ ppc-fbsd-tdep.o \ + ppcfbsd-kern.o \ ppc-linux-tdep.o \ ppc-nbsd-tdep.o \ ppc-obsd-tdep.o \ -@@ -1610,7 +1620,7 @@ generated_files = \ +@@ -1611,7 +1621,7 @@ generated_files = \ # Flags needed to compile Python code PYTHON_CFLAGS = @PYTHON_CFLAGS@ --all: gdb$(EXEEXT) $(CONFIG_ALL) -+all: gdb$(EXEEXT) kgdb$(EXEEXT) $(CONFIG_ALL) +-all: gdb$(EXEEXT) $(CONFIG_ALL) gdb-gdb.py gdb-gdb.gdb ++all: gdb$(EXEEXT) kgdb$(EXEEXT) $(CONFIG_ALL) gdb-gdb.py gdb-gdb.gdb @$(MAKE) $(FLAGS_TO_PASS) DO=all "DODIRS=`echo $(SUBDIRS) | sed 's/testsuite//'`" subdir_do # Rule for compiling .c files in the top-level gdb directory. -@@ -1920,6 +1930,12 @@ gdb$(EXEEXT): gdb.o $(LIBGDB_OBS) $(ADD_DEPS) $(CDEPS) $(TDEPLIBS) - -o gdb$(EXEEXT) gdb.o $(LIBGDB_OBS) \ - $(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES) +@@ -1924,6 +1934,12 @@ ifneq ($(CODESIGN_CERT),) + $(ECHO_SIGN) $(CODESIGN) -s $(CODESIGN_CERT) gdb$(EXEEXT) + endif +kgdb$(EXEEXT): kgdb-main.o $(LIBGDB_OBS) $(ADD_DEPS) $(CDEPS) $(TDEPLIBS) + rm -f kgdb$(EXEEXT) + $(CC_LD) $(INTERNAL_LDFLAGS) $(WIN32LDAPP) \ + -o kgdb$(EXEEXT) kgdb-main.o $(LIBGDB_OBS) \ + $(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES) + # Convenience rule to handle recursion. $(LIBGNU) $(GNULIB_H): all-lib all-lib: $(GNULIB_BUILDDIR)/Makefile -@@ -1964,7 +1980,7 @@ clean mostlyclean: $(CONFIG_CLEAN) +@@ -1968,7 +1984,7 @@ clean mostlyclean: $(CONFIG_CLEAN) @$(MAKE) $(FLAGS_TO_PASS) DO=clean "DODIRS=$(CLEANDIRS)" subdir_do rm -f *.o *.a $(ADD_FILES) *~ init.c-tmp init.l-tmp version.c-tmp - rm -f init.c version.c observer.h observer.inc + rm -f init.c version.c - rm -f gdb$(EXEEXT) core make.log + rm -f gdb$(EXEEXT) core make.log kgdb$(EXEEXT) rm -f gdb[0-9]$(EXEEXT) rm -f test-cp-name-parser$(EXEEXT) rm -f xml-builtin.c stamp-xml -@@ -2178,6 +2194,7 @@ MAKEOVERRIDES = +@@ -2183,6 +2199,7 @@ MAKEOVERRIDES = ALLDEPFILES = \ aarch64-fbsd-nat.c \ + aarch64-fbsd-kern.c \ aarch64-fbsd-tdep.c \ aarch64-linux-nat.c \ aarch64-linux-tdep.c \ -@@ -2195,6 +2212,7 @@ ALLDEPFILES = \ +@@ -2200,6 +2217,7 @@ ALLDEPFILES = \ amd64-bsd-nat.c \ amd64-darwin-tdep.c \ amd64-dicos-tdep.c \ + amd64fbsd-kern.c \ amd64-fbsd-nat.c \ amd64-fbsd-tdep.c \ amd64-linux-nat.c \ -@@ -2209,6 +2227,7 @@ ALLDEPFILES = \ +@@ -2214,6 +2232,7 @@ ALLDEPFILES = \ arc-tdep.c \ arm.c \ arm-bsd-tdep.c \ + arm-fbsd-kern.c \ arm-fbsd-nat.c \ arm-fbsd-tdep.c \ arm-get-next-pcs.c \ -@@ -2228,6 +2247,9 @@ ALLDEPFILES = \ +@@ -2233,6 +2252,9 @@ ALLDEPFILES = \ darwin-nat.c \ dicos-tdep.c \ exec.c \ + fbsd-kld.c \ + fbsd-kthr.c \ + fbsd-kvm.c \ fbsd-nat.c \ fbsd-tdep.c \ fork-child.c \ -@@ -2249,6 +2271,7 @@ ALLDEPFILES = \ +@@ -2254,6 +2276,7 @@ ALLDEPFILES = \ i386-darwin-nat.c \ i386-darwin-tdep.c \ i386-dicos-tdep.c \ + i386fbsd-kern.c \ i386-fbsd-nat.c \ i386-fbsd-tdep.c \ i386-gnu-nat.c \ -@@ -2290,6 +2313,7 @@ ALLDEPFILES = \ +@@ -2293,6 +2316,7 @@ ALLDEPFILES = \ mingw-hdep.c \ mips-fbsd-nat.c \ mips-fbsd-tdep.c \ + mipsfbsd-kern.c \ mips-linux-nat.c \ mips-linux-tdep.c \ mips-nbsd-nat.c \ -@@ -2307,6 +2331,7 @@ ALLDEPFILES = \ +@@ -2310,6 +2334,7 @@ ALLDEPFILES = \ obsd-nat.c \ obsd-tdep.c \ posix-hdep.c \ + ppcfbsd-kern.c \ ppc-fbsd-nat.c \ ppc-fbsd-tdep.c \ ppc-linux-nat.c \ -@@ -2351,6 +2376,7 @@ ALLDEPFILES = \ +@@ -2355,6 +2380,7 @@ ALLDEPFILES = \ sparc-sol2-nat.c \ sparc-sol2-tdep.c \ sparc-tdep.c \ + sparc64fbsd-kern.c \ sparc64-fbsd-nat.c \ sparc64-fbsd-tdep.c \ sparc64-linux-nat.c \ -@@ -2638,7 +2664,7 @@ endif +@@ -2643,7 +2669,7 @@ endif # 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 # All the .deps files to include. diff --git gdb/config.in gdb/config.in -index 1d11a97080..50a5a5b322 100644 +index 527290296e..8e0e90fd67 100644 --- gdb/config.in +++ gdb/config.in -@@ -222,6 +222,9 @@ +@@ -228,6 +228,9 @@ /* Define to 1 if your system has the kinfo_getvmmap function. */ #undef HAVE_KINFO_GETVMMAP +/* Define to 1 if your system has the kvm_open2 function. */ +#undef HAVE_KVM_OPEN2 + /* Define if you have and nl_langinfo(CODESET). */ #undef HAVE_LANGINFO_CODESET diff --git gdb/configure gdb/configure -index 84a0790c0d..f4c323d4ab 100755 +index 3849b9494f..18d2e363dc 100755 --- gdb/configure +++ gdb/configure -@@ -7927,6 +7927,66 @@ $as_echo "#define HAVE_KINFO_GETVMMAP 1" >>confdefs.h +@@ -8082,6 +8082,66 @@ $as_echo "#define HAVE_KINFO_GETFILE 1" >>confdefs.h fi +# kgdb needs kvm_open2 for cross-debugging +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing kvm_open2" >&5 +$as_echo_n "checking for library containing kvm_open2... " >&6; } +if test "${ac_cv_search_kvm_open2+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_func_search_save_LIBS=$LIBS +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char kvm_open2 (); +int +main () +{ +return kvm_open2 (); + ; + return 0; +} +_ACEOF +for ac_lib in '' kvm; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_kvm_open2=$ac_res +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext + if test "${ac_cv_search_kvm_open2+set}" = set; then : + break +fi +done +if test "${ac_cv_search_kvm_open2+set}" = set; then : + +else + ac_cv_search_kvm_open2=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_kvm_open2" >&5 +$as_echo "$ac_cv_search_kvm_open2" >&6; } +ac_res=$ac_cv_search_kvm_open2 +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + +$as_echo "#define HAVE_KVM_OPEN2 1" >>confdefs.h + +fi + + if test "X$prefix" = "XNONE"; then acl_final_prefix="$ac_default_prefix" diff --git gdb/configure.ac gdb/configure.ac -index d4133ea71e..bac85c53e0 100644 +index 4c20ea5178..df156b484f 100644 --- gdb/configure.ac +++ gdb/configure.ac -@@ -523,6 +523,11 @@ AC_SEARCH_LIBS(kinfo_getvmmap, util util-freebsd, - [AC_DEFINE(HAVE_KINFO_GETVMMAP, 1, - [Define to 1 if your system has the kinfo_getvmmap function. ])]) +@@ -534,6 +534,11 @@ AC_SEARCH_LIBS(kinfo_getfile, util util-freebsd, + [AC_DEFINE(HAVE_KINFO_GETFILE, 1, + [Define to 1 if your system has the kinfo_getfile function. ])]) +# kgdb needs kvm_open2 for cross-debugging +AC_SEARCH_LIBS(kvm_open2, kvm, + [AC_DEFINE(HAVE_KVM_OPEN2, 1, + [Define to 1 if your system has the kvm_open2 function. ])]) + AM_ICONV # GDB may fork/exec the iconv program to get the list of supported character diff --git gdb/configure.nat gdb/configure.nat -index 8e14892722..ada205f34d 100644 +index 7611266d86..8656015365 100644 --- gdb/configure.nat +++ gdb/configure.nat @@ -62,7 +62,8 @@ case ${gdb_host} in LOADLIBES='-ldl $(RDYNAMIC)' ;; fbsd*) - NATDEPFILES='fork-child.o fork-inferior.o inf-ptrace.o fbsd-nat.o' + NATDEPFILES='fork-child.o fork-inferior.o inf-ptrace.o fbsd-nat.o \ + fbsd-kvm.o' HAVE_NATIVE_GCORE_HOST=1 LOADLIBES='-lkvm' ;; diff --git gdb/configure.tgt gdb/configure.tgt -index fb8014a8e8..4bb43e366c 100644 +index f197160896..ced1140328 100644 --- gdb/configure.tgt +++ gdb/configure.tgt -@@ -92,7 +92,7 @@ esac +@@ -94,7 +94,7 @@ esac case "${targ}" in *-*-freebsd* | *-*-kfreebsd*-gnu) - os_obs="fbsd-tdep.o solib-svr4.o";; + os_obs="fbsd-tdep.o solib-svr4.o fbsd-kld.o fbsd-kthr.o";; *-*-netbsd* | *-*-knetbsd*-gnu) os_obs="nbsd-tdep.o solib-svr4.o";; *-*-openbsd*) -@@ -109,7 +109,7 @@ aarch64*-*-elf | aarch64*-*-rtems*) +@@ -111,7 +111,7 @@ aarch64*-*-elf | aarch64*-*-rtems*) aarch64*-*-freebsd*) # Target: FreeBSD/aarch64 - gdb_target_obs="aarch64-fbsd-tdep.o" + gdb_target_obs="aarch64-fbsd-tdep.o aarch64-fbsd-kern.o" ;; aarch64*-*-linux*) -@@ -162,7 +162,7 @@ arm*-*-linux*) +@@ -164,7 +164,7 @@ arm*-*-linux*) ;; arm*-*-freebsd*) # Target: FreeBSD/arm - gdb_target_obs="arm-fbsd-tdep.o" + gdb_target_obs="arm-fbsd-tdep.o arm-fbsd-kern.o" ;; arm*-*-netbsd* | arm*-*-knetbsd*-gnu) # Target: NetBSD/arm -@@ -249,7 +249,11 @@ i[34567]86-*-dicos*) +@@ -251,7 +251,11 @@ i[34567]86-*-dicos*) ;; i[34567]86-*-freebsd* | i[34567]86-*-kfreebsd*-gnu) # Target: FreeBSD/i386 - gdb_target_obs="i386-bsd-tdep.o i386-fbsd-tdep.o " + gdb_target_obs="i386-bsd-tdep.o i386-fbsd-tdep.o i386fbsd-kern.o" + if test "x$enable_64_bit_bfd" = "xyes"; then + # Target: FreeBSD amd64 + gdb_target_obs="amd64fbsd-tdep.o amd64fbsd-kern.o ${gdb_target_obs}" + fi ;; i[34567]86-*-netbsd* | i[34567]86-*-knetbsd*-gnu) # Target: NetBSD/i386 -@@ -408,7 +412,7 @@ mips*-*-netbsd* | mips*-*-knetbsd*-gnu) +@@ -405,7 +409,7 @@ mips*-*-netbsd* | mips*-*-knetbsd*-gnu) ;; mips*-*-freebsd*) # Target: MIPS running FreeBSD - gdb_target_obs="mips-tdep.o mips-fbsd-tdep.o" + gdb_target_obs="mips-tdep.o mips-fbsd-tdep.o mipsfbsd-kern.o" gdb_sim=../sim/mips/libsim.a ;; mips64*-*-openbsd*) -@@ -472,7 +476,7 @@ or1k-*-* | or1knd-*-*) +@@ -464,7 +468,7 @@ or1k-*-* | or1knd-*-*) powerpc*-*-freebsd*) # Target: FreeBSD/powerpc gdb_target_obs="rs6000-tdep.o ppc-sysv-tdep.o ppc64-tdep.o \ - ppc-fbsd-tdep.o \ + ppc-fbsd-tdep.o ppcfbsd-kern.o \ ravenscar-thread.o ppc-ravenscar-thread.o" ;; -@@ -594,6 +598,7 @@ sparc64-*-linux*) +@@ -587,6 +591,7 @@ sparc64-*-linux*) sparc*-*-freebsd* | sparc*-*-kfreebsd*-gnu) # Target: FreeBSD/sparc64 gdb_target_obs="sparc-tdep.o sparc64-tdep.o sparc64-fbsd-tdep.o \ + sparc64fbsd-kern.o \ ravenscar-thread.o sparc-ravenscar-thread.o" ;; sparc-*-netbsd* | sparc-*-knetbsd*-gnu) -@@ -716,8 +721,8 @@ x86_64-*-linux*) +@@ -709,8 +714,8 @@ x86_64-*-linux*) ;; x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu) # Target: FreeBSD/amd64 - gdb_target_obs="amd64-fbsd-tdep.o ${i386_tobjs} \ - i386-bsd-tdep.o i386-fbsd-tdep.o" + gdb_target_obs="amd64-fbsd-tdep.o amd64fbsd-kern.o ${i386_tobjs} \ + i386-bsd-tdep.o i386-fbsd-tdep.o i386fbsd-kern.o" ;; x86_64-*-mingw* | x86_64-*-cygwin*) # Target: MingW/amd64 diff --git gdb/defs.h gdb/defs.h -index 4fb2129b30..0cb0bad5c5 100644 +index fc4217005a..3d2eb6b1e9 100644 --- gdb/defs.h +++ gdb/defs.h -@@ -516,6 +516,7 @@ enum gdb_osabi +@@ -481,6 +481,7 @@ enum gdb_osabi GDB_OSABI_SOLARIS, GDB_OSABI_LINUX, GDB_OSABI_FREEBSD, + GDB_OSABI_FREEBSD_KERNEL, GDB_OSABI_NETBSD, GDB_OSABI_OPENBSD, GDB_OSABI_WINCE, diff --git gdb/gnulib/configure gdb/gnulib/configure -index 37efd06b67..a23fc0a81c 100644 +index a152abcb76..140c4ad6a8 100644 --- gdb/gnulib/configure +++ gdb/gnulib/configure -@@ -16790,6 +16790,7 @@ else +@@ -17214,6 +17214,7 @@ else case "$host_os" in # Guess all is fine on glibc systems. *-gnu*) gl_cv_func_gettimeofday_clobber="guessing no" ;; + freebsd*) gl_cv_func_gettimeofday_clobber="guessing no" ;; # If we don't know, assume the worst. *) gl_cv_func_gettimeofday_clobber="guessing yes" ;; esac diff --git gdb/osabi.c gdb/osabi.c -index 129164f51e..4eacc074a3 100644 +index 7d0540b181..c61c518652 100644 --- gdb/osabi.c +++ gdb/osabi.c -@@ -65,6 +65,7 @@ static const struct osabi_names gdb_osabi_names[] = +@@ -66,6 +66,7 @@ static const struct osabi_names gdb_osabi_names[] = { "Solaris", NULL }, - { "GNU/Linux", "linux(-gnu)?" }, + { "GNU/Linux", "linux(-gnu[^-]*)?" }, { "FreeBSD", NULL }, + { "FreeBSD/kernel", NULL }, { "NetBSD", NULL }, { "OpenBSD", NULL }, { "WindowsCE", NULL }, diff --git gdb/regcache.c gdb/regcache.c -index fb6a904dec..f9b7105b8f 100644 +index f3f845aad6..7ca007a422 100644 --- gdb/regcache.c +++ gdb/regcache.c -@@ -1079,6 +1079,23 @@ regcache::raw_supply_zeroed (int regnum) +@@ -1035,6 +1035,22 @@ reg_buffer::raw_supply_zeroed (int regnum) m_register_status[regnum] = REG_VALID; } +void -+regcache::raw_supply_unsigned (int regnum, ULONGEST val) ++reg_buffer::raw_supply_unsigned (int regnum, ULONGEST val) +{ + enum bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch); + gdb_byte *regbuf; + size_t regsize; + + assert_regnum (regnum); -+ gdb_assert (!m_readonly_p); + + regbuf = register_buffer (regnum); + regsize = m_descr->sizeof_register[regnum]; + + store_unsigned_integer (regbuf, regsize, byte_order, val); + m_register_status[regnum] = REG_VALID; +} + - /* Collect register REGNUM from REGCACHE and store its contents in BUF. */ + /* See common/common-regcache.h. */ void diff --git gdb/regcache.h gdb/regcache.h -index 9e3da8c3fc..5c65a9be1e 100644 +index 4a45f33871..94f542c087 100644 --- gdb/regcache.h +++ gdb/regcache.h -@@ -294,6 +294,8 @@ public: - void raw_supply_integer (int regnum, const gdb_byte *addr, int addr_len, - bool is_signed); +@@ -207,6 +207,8 @@ public: + only LEN, without editing the rest of the register. */ + void raw_supply_part (int regnum, int offset, int len, const gdb_byte *in); + void raw_supply_unsigned (int regnum, ULONGEST val); + - void raw_supply_zeroed (int regnum); + void invalidate (int regnum); - enum register_status get_register_status (int regnum) const; + virtual ~reg_buffer () = default; Index: head/devel/gdb/files/kgdb/amd64fbsd-kern.c =================================================================== --- head/devel/gdb/files/kgdb/amd64fbsd-kern.c (revision 480612) +++ head/devel/gdb/files/kgdb/amd64fbsd-kern.c (revision 480613) @@ -1,311 +1,311 @@ /* * Copyright (c) 2004 Marcel Moolenaar * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "defs.h" #include "frame-unwind.h" #include "gdbcore.h" #include "osabi.h" #include "regcache.h" #include "solib.h" #include "stack.h" #include "symtab.h" #include "trad-frame.h" #include "amd64-tdep.h" #include "x86-xstate.h" #ifdef __amd64__ #include #include #endif #include "kgdb.h" static const int amd64fbsd_pcb_offset[] = { -1, /* %rax */ 6 * 8, /* %rbx */ -1, /* %rcx */ -1, /* %rdx */ -1, /* %rsi */ -1, /* %rdi */ 4 * 8, /* %rbp */ 5 * 8, /* %rsp */ -1, /* %r8 ... */ -1, -1, -1, 3 * 8, 2 * 8, 1 * 8, 0 * 8, /* ... %r15 */ 7 * 8, /* %rip */ -1, /* %eflags */ -1, /* %cs */ -1, /* %ss */ -1, /* %ds */ -1, /* %es */ -1, /* %fs */ -1 /* %gs */ }; #define CODE_SEL (4 << 3) #define DATA_SEL (5 << 3) static void amd64fbsd_supply_pcb(struct regcache *regcache, CORE_ADDR pcb_addr) { gdb_byte buf[8]; int i; memset(buf, 0, sizeof(buf)); /* * XXX The PCB may have been swapped out. Supply a dummy %rip value * so as to avoid triggering an exception during stack unwinding. */ regcache->raw_supply(AMD64_RIP_REGNUM, buf); for (i = 0; i < ARRAY_SIZE (amd64fbsd_pcb_offset); i++) if (amd64fbsd_pcb_offset[i] != -1) { if (target_read_memory(pcb_addr + amd64fbsd_pcb_offset[i], buf, sizeof buf) != 0) continue; regcache->raw_supply(i, buf); } regcache->raw_supply_unsigned(AMD64_CS_REGNUM, CODE_SEL); regcache->raw_supply_unsigned(AMD64_SS_REGNUM, DATA_SEL); } static const int amd64fbsd_trapframe_offset[] = { 6 * 8, /* %rax */ 7 * 8, /* %rbx */ 3 * 8, /* %rcx */ 2 * 8, /* %rdx */ 1 * 8, /* %rsi */ 0 * 8, /* %rdi */ 8 * 8, /* %rbp */ 22 * 8, /* %rsp */ 4 * 8, /* %r8 ... */ 5 * 8, 9 * 8, 10 * 8, 11 * 8, 12 * 8, 13 * 8, 14 * 8, /* ... %r15 */ 19 * 8, /* %rip */ 21 * 8, /* %eflags */ 20 * 8, /* %cs */ 23 * 8, /* %ss */ -1, /* %ds */ -1, /* %es */ -1, /* %fs */ -1 /* %gs */ }; #define TRAPFRAME_SIZE 192 static struct trad_frame_cache * amd64fbsd_trapframe_cache (struct frame_info *this_frame, void **this_cache) { struct gdbarch *gdbarch = get_frame_arch (this_frame); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); struct trad_frame_cache *cache; CORE_ADDR addr, func, pc, sp; const char *name; int i; if (*this_cache != NULL) return ((struct trad_frame_cache *)*this_cache); cache = trad_frame_cache_zalloc (this_frame); *this_cache = cache; func = get_frame_func (this_frame); sp = get_frame_register_unsigned (this_frame, AMD64_RSP_REGNUM); find_pc_partial_function (func, &name, NULL, NULL); if (strcmp(name, "fork_trampoline") == 0 && get_frame_pc (this_frame) == func) { /* fork_exit hasn't been called (kthread has never run), so %rsp in the pcb points to the trapframe. GDB has auto-adjusted %rsp for this frame to account for the "call" into fork_trampoline, so "undo" the adjustment. */ sp += 8; } for (i = 0; i < ARRAY_SIZE (amd64fbsd_trapframe_offset); i++) if (amd64fbsd_trapframe_offset[i] != -1) trad_frame_set_reg_addr (cache, i, sp + amd64fbsd_trapframe_offset[i]); /* Read %rip from trap frame. */ addr = sp + amd64fbsd_trapframe_offset[AMD64_RIP_REGNUM]; pc = read_memory_unsigned_integer (addr, 8, byte_order); if (pc == 0 && strcmp(name, "fork_trampoline") == 0) { /* Initial frame of a kthread; terminate backtrace. */ trad_frame_set_id (cache, outer_frame_id); } else { /* Construct the frame ID using the function start. */ trad_frame_set_id (cache, frame_id_build (sp + TRAPFRAME_SIZE, func)); } return cache; } static void amd64fbsd_trapframe_this_id (struct frame_info *this_frame, void **this_cache, struct frame_id *this_id) { struct trad_frame_cache *cache = amd64fbsd_trapframe_cache (this_frame, this_cache); trad_frame_get_id (cache, this_id); } static struct value * amd64fbsd_trapframe_prev_register (struct frame_info *this_frame, void **this_cache, int regnum) { struct trad_frame_cache *cache = amd64fbsd_trapframe_cache (this_frame, this_cache); return trad_frame_get_register (cache, this_frame, regnum); } static int amd64fbsd_trapframe_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, void **this_prologue_cache) { const char *name; find_pc_partial_function (get_frame_func (this_frame), &name, NULL, NULL); return (name && ((strcmp (name, "calltrap") == 0) || (strcmp (name, "fast_syscall_common") == 0) || (strcmp (name, "fork_trampoline") == 0) || (strcmp (name, "mchk_calltrap") == 0) || (strcmp (name, "nmi_calltrap") == 0) || (name[0] == 'X' && name[1] != '_'))); } static const struct frame_unwind amd64fbsd_trapframe_unwind = { SIGTRAMP_FRAME, default_frame_unwind_stop_reason, amd64fbsd_trapframe_this_id, amd64fbsd_trapframe_prev_register, NULL, amd64fbsd_trapframe_sniffer }; static void amd64fbsd_kernel_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch) { amd64_init_abi(info, gdbarch, - amd64_target_description (X86_XSTATE_SSE_MASK)); + amd64_target_description (X86_XSTATE_SSE_MASK, true)); frame_unwind_prepend_unwinder(gdbarch, &amd64fbsd_trapframe_unwind); set_solib_ops(gdbarch, &kld_so_ops); fbsd_vmcore_set_supply_pcb(gdbarch, amd64fbsd_supply_pcb); fbsd_vmcore_set_cpu_pcb_addr(gdbarch, kgdb_trgt_stop_pcb); } void _initialize_amd64_kgdb_tdep(void) { gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64, GDB_OSABI_FREEBSD_KERNEL, amd64fbsd_kernel_init_abi); #ifdef __amd64__ gdb_assert(offsetof(struct pcb, pcb_rbx) == amd64fbsd_pcb_offset[AMD64_RBX_REGNUM]); gdb_assert(offsetof(struct pcb, pcb_rbp) == amd64fbsd_pcb_offset[AMD64_RBP_REGNUM]); gdb_assert(offsetof(struct pcb, pcb_rsp) == amd64fbsd_pcb_offset[AMD64_RSP_REGNUM]); gdb_assert(offsetof(struct pcb, pcb_r12) == amd64fbsd_pcb_offset[AMD64_R12_REGNUM]); gdb_assert(offsetof(struct pcb, pcb_r13) == amd64fbsd_pcb_offset[AMD64_R13_REGNUM]); gdb_assert(offsetof(struct pcb, pcb_r14) == amd64fbsd_pcb_offset[AMD64_R14_REGNUM]); gdb_assert(offsetof(struct pcb, pcb_r15) == amd64fbsd_pcb_offset[AMD64_R15_REGNUM]); gdb_assert(offsetof(struct pcb, pcb_rip) == amd64fbsd_pcb_offset[AMD64_RIP_REGNUM]); gdb_assert(CODE_SEL == GSEL(GCODE_SEL, SEL_KPL)); gdb_assert(DATA_SEL == GSEL(GDATA_SEL, SEL_KPL)); gdb_assert(sizeof(struct trapframe) == TRAPFRAME_SIZE); gdb_assert(offsetof(struct trapframe, tf_rax) == amd64fbsd_trapframe_offset[AMD64_RAX_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_rbx) == amd64fbsd_trapframe_offset[AMD64_RBX_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_rcx) == amd64fbsd_trapframe_offset[AMD64_RCX_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_rdx) == amd64fbsd_trapframe_offset[AMD64_RDX_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_rsi) == amd64fbsd_trapframe_offset[AMD64_RSI_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_rdi) == amd64fbsd_trapframe_offset[AMD64_RDI_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_rbp) == amd64fbsd_trapframe_offset[AMD64_RBP_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_rsp) == amd64fbsd_trapframe_offset[AMD64_RSP_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_r8) == amd64fbsd_trapframe_offset[AMD64_R8_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_r9) == amd64fbsd_trapframe_offset[AMD64_R9_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_r10) == amd64fbsd_trapframe_offset[AMD64_R10_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_r11) == amd64fbsd_trapframe_offset[AMD64_R11_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_r12) == amd64fbsd_trapframe_offset[AMD64_R12_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_r13) == amd64fbsd_trapframe_offset[AMD64_R13_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_r14) == amd64fbsd_trapframe_offset[AMD64_R14_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_r15) == amd64fbsd_trapframe_offset[AMD64_R15_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_rip) == amd64fbsd_trapframe_offset[AMD64_RIP_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_rflags) == amd64fbsd_trapframe_offset[AMD64_EFLAGS_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_cs) == amd64fbsd_trapframe_offset[AMD64_CS_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_ss) == amd64fbsd_trapframe_offset[AMD64_SS_REGNUM]); #endif } Index: head/devel/gdb/files/kgdb/fbsd-kld.c =================================================================== --- head/devel/gdb/files/kgdb/fbsd-kld.c (revision 480612) +++ head/devel/gdb/files/kgdb/fbsd-kld.c (revision 480613) @@ -1,582 +1,572 @@ /* * Copyright (c) 2004 Marcel Moolenaar * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "defs.h" #include "command.h" #include "completer.h" #include "environ.h" #include "exec.h" #include "frame-unwind.h" #include "inferior.h" #include "objfiles.h" #include "gdbcore.h" #include "language.h" #include "solib.h" #include "solist.h" #include "kgdb.h" struct lm_info_kld : public lm_info_base { CORE_ADDR base_address; }; struct kld_info { /* Offsets of fields in linker_file structure. */ CORE_ADDR off_address, off_filename, off_pathname, off_next; /* KVA of 'linker_path' which corresponds to the kern.module_path sysctl .*/ CORE_ADDR module_path_addr; CORE_ADDR linker_files_addr; CORE_ADDR kernel_file_addr; }; struct target_so_ops kld_so_ops; /* Per-program-space data key. */ static const struct program_space_data *kld_pspace_data; static void kld_pspace_data_cleanup (struct program_space *pspace, void *arg) { struct kld_info *info = (struct kld_info *)arg; xfree (info); } /* Get the current kld data. If none is found yet, add it now. This function always returns a valid object. */ static struct kld_info * get_kld_info (void) { struct kld_info *info; info = (struct kld_info *) program_space_data (current_program_space, kld_pspace_data); if (info != NULL) return info; info = XCNEW (struct kld_info); set_program_space_data (current_program_space, kld_pspace_data, info); return info; } static int kld_ok (char *path) { struct stat sb; if (stat(path, &sb) == 0 && S_ISREG(sb.st_mode)) return (1); return (0); } /* * Look for a matching file checking for debug suffixes before the raw file: * - filename + ".debug" (e.g. foo.ko.debug) * - filename (e.g. foo.ko) */ static const char *kld_suffixes[] = { ".debug", ".symbols", "", NULL }; static int check_kld_path (char *path, size_t path_size) { const char **suffix; char *ep; ep = path + strlen(path); suffix = kld_suffixes; while (*suffix != NULL) { if (strlcat(path, *suffix, path_size) < path_size) { if (kld_ok(path)) return (1); } /* Restore original path to remove suffix. */ *ep = '\0'; suffix++; } return (0); } /* * Try to find the path for a kld by looking in the kernel's directory and * in the various paths in the module path. */ static int find_kld_path (const char *filename, char *path, size_t path_size) { struct kld_info *info; struct cleanup *cleanup; - char *module_path; + gdb::unique_xmalloc_ptr module_path; char *module_dir, *cp; int error; info = get_kld_info(); if (exec_bfd) { std::string kernel_dir = ldirname(bfd_get_filename(exec_bfd)); if (!kernel_dir.empty()) { snprintf(path, path_size, "%s/%s", kernel_dir.c_str(), filename); if (check_kld_path(path, path_size)) return (1); } } if (info->module_path_addr != 0) { target_read_string(info->module_path_addr, &module_path, PATH_MAX, &error); if (error == 0) { - cleanup = make_cleanup(xfree, module_path); - cp = module_path; + cp = module_path.get(); while ((module_dir = strsep(&cp, ";")) != NULL) { snprintf(path, path_size, "%s/%s", module_dir, filename); - if (check_kld_path(path, path_size)) { - do_cleanups(cleanup); + if (check_kld_path(path, path_size)) return (1); - } } - do_cleanups(cleanup); } } return (0); } /* * Read a kernel pointer given a KVA in 'address'. */ static CORE_ADDR read_pointer (CORE_ADDR address) { struct type *ptr_type; gdb_byte ptr_buf[8]; int arch_size; arch_size = bfd_get_arch_size (exec_bfd); if (arch_size == -1) return (0); ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr; if (target_read_memory(address, ptr_buf, arch_size / 8) != 0) return (0); return (extract_typed_address (ptr_buf, ptr_type)); } /* * Try to find this kld in the kernel linker's list of linker files. */ static int find_kld_address (const char *arg, CORE_ADDR *address) { struct kld_info *info; CORE_ADDR kld; - char *kld_filename; + gdb::unique_xmalloc_ptr kld_filename; const char *filename; int error; info = get_kld_info(); if (info->linker_files_addr == 0 || info->off_address == 0 || info->off_filename == 0 || info->off_next == 0) return (0); filename = lbasename(arg); for (kld = read_pointer(info->linker_files_addr); kld != 0; kld = read_pointer(kld + info->off_next)) { /* Try to read this linker file's filename. */ target_read_string(read_pointer(kld + info->off_filename), &kld_filename, PATH_MAX, &error); if (error) continue; /* Compare this kld's filename against our passed in name. */ - if (strcmp(kld_filename, filename) != 0) { - xfree(kld_filename); + if (strcmp(kld_filename.get(), filename) != 0) continue; - } - xfree(kld_filename); /* * We found a match, use its address as the base * address if we can read it. */ *address = read_pointer(kld + info->off_address); if (*address == 0) return (0); return (1); } return (0); } static void adjust_section_address (struct target_section *sec, CORE_ADDR *curr_base) { struct bfd_section *asect = sec->the_bfd_section; bfd *abfd = asect->owner; if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0) { sec->addr += *curr_base; sec->endaddr += *curr_base; return; } *curr_base = align_power(*curr_base, bfd_get_section_alignment(abfd, asect)); sec->addr = *curr_base; sec->endaddr = sec->addr + bfd_section_size(abfd, asect); *curr_base = sec->endaddr; } static void load_kld (char *path, CORE_ADDR base_addr, int from_tty) { - struct section_addr_info *sap; struct target_section *sections = NULL, *sections_end = NULL, *s; struct cleanup *cleanup; gdb_bfd_ref_ptr bfd; CORE_ADDR curr_addr; symfile_add_flags add_flags; int i; /* Open the kld. */ bfd = gdb_bfd_openr(path, gnutarget); if (bfd == NULL) error("\"%s\": can't open: %s", path, bfd_errmsg(bfd_get_error())); if (!bfd_check_format(bfd.get(), bfd_object)) error("\%s\": not an object file", path); /* Make sure we have a .text section. */ if (bfd_get_section_by_name (bfd.get(), ".text") == NULL) error("\"%s\": can't find text section", path); /* Build a section table from the bfd and relocate the sections. */ if (build_section_table (bfd.get(), §ions, §ions_end)) error("\"%s\": can't find file sections", path); cleanup = make_cleanup(xfree, sections); curr_addr = base_addr; for (s = sections; s < sections_end; s++) adjust_section_address(s, &curr_addr); /* Build a section addr info to pass to symbol_file_add(). */ - sap = build_section_addr_info_from_section_table (sections, - sections_end); - make_cleanup((make_cleanup_ftype *)free_section_addr_info, sap); + section_addr_info sap + = build_section_addr_info_from_section_table (sections, + sections_end); printf_unfiltered("add symbol table from file \"%s\" at\n", path); - for (i = 0; i < sap->num_sections; i++) - printf_unfiltered("\t%s_addr = %s\n", sap->other[i].name, - paddress(target_gdbarch(), sap->other[i].addr)); + for (i = 0; i < sap.size(); i++) + printf_unfiltered("\t%s_addr = %s\n", sap[i].name.c_str(), + paddress(target_gdbarch(), sap[i].addr)); if (from_tty && (!query("%s", ""))) error("Not confirmed."); add_flags = 0; if (from_tty) add_flags |= SYMFILE_VERBOSE; - symbol_file_add_from_bfd(bfd.get(), path, add_flags, sap, + symbol_file_add_from_bfd(bfd.get(), path, add_flags, &sap, OBJF_USERLOADED, NULL); do_cleanups(cleanup); } static void kgdb_add_kld_cmd (const char *arg, int from_tty) { char path[PATH_MAX]; CORE_ADDR base_addr; if (!exec_bfd) error("No kernel symbol file"); /* Try to open the raw path to handle absolute paths first. */ snprintf(path, sizeof(path), "%s", arg); if (!check_kld_path(path, sizeof(path))) { /* * If that didn't work, look in the various possible * paths for the module. */ if (!find_kld_path(arg, path, sizeof(path))) { error("Unable to locate kld"); return; } } if (!find_kld_address(arg, &base_addr)) { error("Unable to find kld in kernel"); return; } load_kld(path, base_addr, from_tty); reinit_frame_cache(); } static void kld_relocate_section_addresses (struct so_list *so, struct target_section *sec) { lm_info_kld *li = (lm_info_kld *) so->lm_info; static CORE_ADDR curr_addr; if (sec == so->sections) curr_addr = li->base_address; adjust_section_address(sec, &curr_addr); } static void kld_free_so (struct so_list *so) { lm_info_kld *li = (lm_info_kld *) so->lm_info; delete li; } static void kld_clear_so (struct so_list *so) { lm_info_kld *li = (lm_info_kld *) so->lm_info; if (li != NULL) li->base_address = 0; } static void kld_clear_solib (void) { struct kld_info *info; info = get_kld_info(); memset(info, 0, sizeof(*info)); } static void kld_solib_create_inferior_hook (int from_tty) { struct kld_info *info; info = get_kld_info(); /* * Compute offsets of relevant members in struct linker_file * and the addresses of global variables. Newer kernels * include constants we can use without requiring debug * symbols. If those aren't present, fall back to using * home-grown offsetof() equivalents. */ TRY { info->off_address = parse_and_eval_long("kld_off_address"); info->off_filename = parse_and_eval_long("kld_off_filename"); info->off_pathname = parse_and_eval_long("kld_off_pathname"); info->off_next = parse_and_eval_long("kld_off_next"); } CATCH(e, RETURN_MASK_ERROR) { TRY { info->off_address = parse_and_eval_address( "&((struct linker_file *)0)->address"); info->off_filename = parse_and_eval_address( "&((struct linker_file *)0)->filename"); info->off_pathname = parse_and_eval_address( "&((struct linker_file *)0)->pathname"); info->off_next = parse_and_eval_address( "&((struct linker_file *)0)->link.tqe_next"); } CATCH(e, RETURN_MASK_ERROR) { return; } END_CATCH } END_CATCH TRY { info->module_path_addr = parse_and_eval_address("linker_path"); info->linker_files_addr = kgdb_lookup("linker_files"); info->kernel_file_addr = kgdb_lookup("linker_kernel_file"); } CATCH(e, RETURN_MASK_ERROR) { return; } END_CATCH solib_add(NULL, from_tty, auto_solib_add); } static struct so_list * kld_current_sos (void) { struct so_list *head, **prev, *newobj; struct kld_info *info; CORE_ADDR kld, kernel; - char *path; + gdb::unique_xmalloc_ptr path; int error; info = get_kld_info(); if (info->linker_files_addr == 0 || info->kernel_file_addr == 0 || info->off_address == 0 || info->off_filename == 0 || info->off_next == 0) return (NULL); head = NULL; prev = &head; /* * Walk the list of linker files creating so_list entries for * each non-kernel file. */ kernel = read_pointer(info->kernel_file_addr); for (kld = read_pointer(info->linker_files_addr); kld != 0; kld = read_pointer(kld + info->off_next)) { /* Skip the main kernel file. */ if (kld == kernel) continue; newobj = XCNEW (struct so_list); lm_info_kld *li = new lm_info_kld; li->base_address = 0; newobj->lm_info = li; /* Read the base filename and store it in so_original_name. */ target_read_string(read_pointer(kld + info->off_filename), &path, sizeof(newobj->so_original_name), &error); if (error != 0) { warning("kld_current_sos: Can't read filename: %s\n", safe_strerror(error)); free_so(newobj); continue; } - strlcpy(newobj->so_original_name, path, + strlcpy(newobj->so_original_name, path.get(), sizeof(newobj->so_original_name)); - xfree(path); /* * Try to read the pathname (if it exists) and store * it in so_name. */ if (find_kld_path(newobj->so_original_name, newobj->so_name, sizeof(newobj->so_name))) { /* we found the kld */; } else if (info->off_pathname != 0) { target_read_string(read_pointer(kld + info->off_pathname), &path, sizeof(newobj->so_name), &error); if (error != 0) { warning( "kld_current_sos: Can't read pathname for \"%s\": %s\n", newobj->so_original_name, safe_strerror(error)); strlcpy(newobj->so_name, newobj->so_original_name, sizeof(newobj->so_name)); } else { - strlcpy(newobj->so_name, path, + strlcpy(newobj->so_name, path.get(), sizeof(newobj->so_name)); - xfree(path); } } else strlcpy(newobj->so_name, newobj->so_original_name, sizeof(newobj->so_name)); /* Read this kld's base address. */ li->base_address = read_pointer(kld + info->off_address); if (li->base_address == 0) { warning( "kld_current_sos: Invalid address for kld \"%s\"", newobj->so_original_name); free_so(newobj); continue; } /* Append to the list. */ *prev = newobj; prev = &newobj->next; } return (head); } static int kld_open_symbol_file_object (int from_tty) { return (0); } static int kld_in_dynsym_resolve_code (CORE_ADDR pc) { return (0); } static int kld_find_and_open_solib (const char *solib, unsigned o_flags, - char **temp_pathname) + gdb::unique_xmalloc_ptr *temp_pathname) { char path[PATH_MAX]; int fd; - *temp_pathname = NULL; + temp_pathname->reset (NULL); if (!find_kld_path(solib, path, sizeof(path))) { errno = ENOENT; return (-1); } fd = open(path, o_flags, 0); if (fd >= 0) - *temp_pathname = xstrdup(path); + temp_pathname->reset(xstrdup(path)); return (fd); } void _initialize_kld_target(void) { struct cmd_list_element *c; kld_so_ops.relocate_section_addresses = kld_relocate_section_addresses; kld_so_ops.free_so = kld_free_so; kld_so_ops.clear_so = kld_clear_so; kld_so_ops.clear_solib = kld_clear_solib; kld_so_ops.solib_create_inferior_hook = kld_solib_create_inferior_hook; kld_so_ops.current_sos = kld_current_sos; kld_so_ops.open_symbol_file_object = kld_open_symbol_file_object; kld_so_ops.in_dynsym_resolve_code = kld_in_dynsym_resolve_code; kld_so_ops.bfd_open = solib_bfd_open; kld_so_ops.find_and_open_solib = kld_find_and_open_solib; c = add_com("add-kld", class_files, kgdb_add_kld_cmd, "Usage: add-kld FILE\n\ Load the symbols from the kernel loadable module FILE."); set_cmd_completer(c, filename_completer); kld_pspace_data = register_program_space_data_with_cleanup (NULL, kld_pspace_data_cleanup); } Index: head/devel/gdb/files/kgdb/fbsd-kvm.c =================================================================== --- head/devel/gdb/files/kgdb/fbsd-kvm.c (revision 480612) +++ head/devel/gdb/files/kgdb/fbsd-kvm.c (revision 480613) @@ -1,626 +1,628 @@ /* * Copyright (c) 2004 Marcel Moolenaar * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "defs.h" #include "command.h" #include "elf-bfd.h" #include "filenames.h" #include "gdbcore.h" #include "gdbthread.h" #include "gdb_obstack.h" #include "inferior.h" #include "objfiles.h" #include "osabi.h" #include "solib.h" #include "target.h" #include "value.h" #include "readline/tilde.h" #include #include #include #include "kgdb.h" static CORE_ADDR stoppcbs; static LONGEST pcb_size; -static void kgdb_core_cleanup(void *); - static char *vmcore; -struct target_ops kgdb_trgt_ops; /* Per-architecture data key. */ static struct gdbarch_data *fbsd_vmcore_data; struct fbsd_vmcore_ops { /* Supply registers for a pcb to a register cache. */ void (*supply_pcb)(struct regcache *, CORE_ADDR); /* Return address of pcb for thread running on a CPU. */ CORE_ADDR (*cpu_pcb_addr)(u_int); }; static void * fbsd_vmcore_init (struct obstack *obstack) { struct fbsd_vmcore_ops *ops; ops = OBSTACK_ZALLOC (obstack, struct fbsd_vmcore_ops); return ops; } /* Set the function that supplies registers from a pcb for architecture GDBARCH to SUPPLY_PCB. */ void fbsd_vmcore_set_supply_pcb (struct gdbarch *gdbarch, void (*supply_pcb) (struct regcache *, CORE_ADDR)) { struct fbsd_vmcore_ops *ops = (struct fbsd_vmcore_ops *) gdbarch_data (gdbarch, fbsd_vmcore_data); ops->supply_pcb = supply_pcb; } /* Set the function that returns the address of the pcb for a thread running on a CPU for architecture GDBARCH to CPU_PCB_ADDR. */ void fbsd_vmcore_set_cpu_pcb_addr (struct gdbarch *gdbarch, CORE_ADDR (*cpu_pcb_addr) (u_int)) { struct fbsd_vmcore_ops *ops = (struct fbsd_vmcore_ops *) gdbarch_data (gdbarch, fbsd_vmcore_data); ops->cpu_pcb_addr = cpu_pcb_addr; } static CORE_ADDR kernstart; static kvm_t *kvm; -static char kvm_err[_POSIX2_LINE_MAX]; int kgdb_quiet; static ptid_t fbsd_vmcore_ptid(int tid) { if (kvm == NULL) /* * The remote target stores the 'tid' in the lwp * field. */ - return ptid_build(ptid_get_pid(inferior_ptid), tid, 0); + return ptid_t(inferior_ptid.pid(), tid, 0); /* * This follows the model described in bsd-kvm.c except that * in kernel tids are used as the tid of the ptid instead of a * process ID. */ - return ptid_build(1, 1, tid); + return ptid_t(1, 1, tid); } #define MSGBUF_SEQ_TO_POS(size, seq) ((seq) % (size)) static void kgdb_dmesg(void) { CORE_ADDR bufp; int size, rseq, wseq; gdb_byte c; /* * Display the unread portion of the message buffer. This gives the * user a some initial data to work from. */ if (kgdb_quiet) return; TRY { bufp = parse_and_eval_address("msgbufp->msg_ptr"); size = parse_and_eval_long("msgbufp->msg_size"); rseq = parse_and_eval_long("msgbufp->msg_rseq"); wseq = parse_and_eval_long("msgbufp->msg_wseq"); } CATCH(e, RETURN_MASK_ERROR) { return; } END_CATCH rseq = MSGBUF_SEQ_TO_POS(size, rseq); wseq = MSGBUF_SEQ_TO_POS(size, wseq); if (rseq == wseq) return; printf("\nUnread portion of the kernel message buffer:\n"); while (rseq < wseq) { read_memory(bufp + rseq, &c, 1); putchar(c); rseq++; if (rseq == size) rseq = 0; } if (c != '\n') putchar('\n'); putchar('\n'); } #define KERNEL_INTERP "/red/herring" enum gdb_osabi fbsd_kernel_osabi_sniffer(bfd *abfd) { asection *s; bfd_byte buf[sizeof(KERNEL_INTERP)]; bfd_byte *bufp; /* First, determine if this is a FreeBSD/ELF binary. */ switch (elf_elfheader(abfd)->e_ident[EI_OSABI]) { case ELFOSABI_FREEBSD: break; case ELFOSABI_NONE: { enum gdb_osabi osabi = GDB_OSABI_UNKNOWN; bfd_map_over_sections (abfd, generic_elf_osabi_sniff_abi_tag_sections, &osabi); /* * aarch64 kernels don't have the right note tag for * kernels so just look for /red/herring anyway. */ if (osabi == GDB_OSABI_UNKNOWN && elf_elfheader(abfd)->e_machine == EM_AARCH64) break; if (osabi != GDB_OSABI_FREEBSD) return (GDB_OSABI_UNKNOWN); } default: return (GDB_OSABI_UNKNOWN); } /* FreeBSD ELF kernels have an interpreter path of "/red/herring". */ bufp = buf; s = bfd_get_section_by_name(abfd, ".interp"); if (s != NULL && bfd_section_size(abfd, s) == sizeof(buf) && bfd_get_full_section_contents(abfd, s, &bufp) && memcmp(buf, KERNEL_INTERP, sizeof(buf)) == 0) return (GDB_OSABI_FREEBSD_KERNEL); return (GDB_OSABI_UNKNOWN); } +/* The FreeBSD libkvm target. */ + +static const target_info fbsd_kvm_target_info = { + "vmcore", + N_("Kernel core dump file"), + N_("Use a vmcore file as a target.\n\ +If no filename is specified, /dev/mem is used to examine the running kernel.\n\ +target vmcore [-w] [filename]") +}; + +class fbsd_kvm_target final : public target_ops +{ +public: + fbsd_kvm_target () + { this->to_stratum = process_stratum; } + + const target_info &info () const override + { return fbsd_kvm_target_info; } + + void close () override; + + void fetch_registers (struct regcache *, int) override; + enum target_xfer_status xfer_partial (enum target_object object, + const char *annex, + gdb_byte *readbuf, + const gdb_byte *writebuf, + ULONGEST offset, ULONGEST len, + ULONGEST *xfered_len) override; + + void files_info () override; + bool thread_alive (ptid_t ptid) override; + void update_thread_list () override; + const char *pid_to_str (ptid_t) override; + const char *extra_thread_info (thread_info *) override; + + bool has_memory () override { return true; } + bool has_stack () override { return true; } + bool has_registers () override { return true; } +}; + +/* Target ops for libkvm interface. */ +static fbsd_kvm_target fbsd_kvm_ops; + #ifdef HAVE_KVM_OPEN2 static int kgdb_resolve_symbol(const char *name, kvaddr_t *kva) { struct bound_minimal_symbol ms; ms = lookup_minimal_symbol (name, NULL, NULL); if (ms.minsym == NULL) return (1); *kva = BMSYMBOL_VALUE_ADDRESS (ms); return (0); } #endif static void -kgdb_trgt_open(const char *args, int from_tty) +fbsd_kvm_target_open (const char *args, int from_tty) { struct fbsd_vmcore_ops *ops = (struct fbsd_vmcore_ops *) gdbarch_data (target_gdbarch(), fbsd_vmcore_data); + char kvm_err[_POSIX2_LINE_MAX]; struct inferior *inf; struct cleanup *old_chain; struct thread_info *ti; struct kthr *kt; kvm_t *nkvm; char *temp, *kernel, *filename; bool writeable; int ontop; if (ops == NULL || ops->supply_pcb == NULL || ops->cpu_pcb_addr == NULL) error ("ABI doesn't support a vmcore target"); target_preopen (from_tty); kernel = get_exec_file (1); if (kernel == NULL) error ("Can't open a vmcore without a kernel"); writeable = false; filename = NULL; if (args != NULL) { gdb_argv built_argv (args); for (char **argv = built_argv.get (); *argv != NULL; argv++) { if (**argv == '-') { if (strcmp (*argv, "-w") == 0) writeable = true; else error (_("Invalid argument")); } else { if (filename != NULL) error (_("Invalid argument")); filename = tilde_expand (*argv); if (!IS_ABSOLUTE_PATH (filename)) { temp = concat (current_directory, "/", filename, NULL); xfree(filename); filename = temp; } } } } old_chain = make_cleanup (xfree, filename); #ifdef HAVE_KVM_OPEN2 nkvm = kvm_open2(kernel, filename, writeable ? O_RDWR : O_RDONLY, kvm_err, kgdb_resolve_symbol); #else nkvm = kvm_openfiles(kernel, filename, NULL, writeable ? O_RDWR : O_RDONLY, kvm_err); #endif if (nkvm == NULL) error ("Failed to open vmcore: %s", kvm_err); /* Don't free the filename now and close any previous vmcore. */ discard_cleanups(old_chain); - unpush_target(&kgdb_trgt_ops); + unpush_target(&fbsd_kvm_ops); /* * Determine the first address in KVA. Newer kernels export * VM_MAXUSER_ADDRESS and the first kernel address can be * determined by adding one. Older kernels do not provide a * symbol that is valid on all platforms, but kernbase is close * for most platforms. */ TRY { kernstart = parse_and_eval_address("vm_maxuser_address") + 1; } CATCH(e, RETURN_MASK_ERROR) { kernstart = kgdb_lookup("kernbase"); } END_CATCH /* * Lookup symbols needed for stoppcbs[] handling, but don't * fail if they aren't present. */ stoppcbs = kgdb_lookup("stoppcbs"); TRY { pcb_size = parse_and_eval_long("pcb_size"); } CATCH(e, RETURN_MASK_ERROR) { pcb_size = 0; } END_CATCH if (pcb_size == 0) { TRY { pcb_size = parse_and_eval_long("sizeof(struct pcb)"); } CATCH(e, RETURN_MASK_ERROR) { #ifdef HAVE_KVM_OPEN2 if (kvm_native(nkvm)) pcb_size = sizeof(struct pcb); else pcb_size = 0; #else pcb_size = sizeof(struct pcb); #endif } END_CATCH } kvm = nkvm; vmcore = filename; - old_chain = make_cleanup(kgdb_core_cleanup, NULL); + push_target (&fbsd_kvm_ops); - push_target (&kgdb_trgt_ops); - discard_cleanups (old_chain); - kgdb_dmesg(); inf = current_inferior(); if (inf->pid == 0) { inferior_appeared(inf, 1); inf->fake_pid_p = 1; } solib_create_inferior_hook(0); init_thread_list(); kt = kgdb_thr_init(ops->cpu_pcb_addr); while (kt != NULL) { ti = add_thread_silent(fbsd_vmcore_ptid(kt->tid)); kt = kgdb_thr_next(kt); } if (curkthr != 0) inferior_ptid = fbsd_vmcore_ptid(curkthr->tid); target_fetch_registers (get_current_regcache (), -1); reinit_frame_cache (); print_stack_frame (get_selected_frame (NULL), 0, SRC_AND_LOC, 1); } -static void -kgdb_trgt_close(struct target_ops *self) +void +fbsd_kvm_target::close() { if (kvm != NULL) { clear_solib(); if (kvm_close(kvm) != 0) warning("cannot close \"%s\": %s", vmcore, kvm_geterr(kvm)); kvm = NULL; xfree(vmcore); vmcore = NULL; } inferior_ptid = null_ptid; } +#if 0 static void -kgdb_core_cleanup(void *arg) -{ - - kgdb_trgt_close(0); -} - -static void kgdb_trgt_detach(struct target_ops *ops, const char *args, int from_tty) { if (args) error ("Too many arguments"); unpush_target(&kgdb_trgt_ops); reinit_frame_cache(); if (from_tty) printf_filtered("No vmcore file now.\n"); } +#endif -static const char * -kgdb_trgt_extra_thread_info(struct target_ops *ops, struct thread_info *ti) +const char * +fbsd_kvm_target::extra_thread_info(thread_info *ti) { - return (kgdb_thr_extra_thread_info(ptid_get_tid(ti->ptid))); + return (kgdb_thr_extra_thread_info(ti->ptid.tid())); } -static void -kgdb_trgt_files_info(struct target_ops *target) +void +fbsd_kvm_target::files_info() { printf_filtered ("\t`%s', ", vmcore); wrap_here (" "); printf_filtered ("file type %s.\n", "FreeBSD kernel vmcore"); } -static void -kgdb_trgt_update_thread_list(struct target_ops *ops) +void +fbsd_kvm_target::update_thread_list() { /* * XXX: We should probably rescan the thread list here and update * it if there are any changes. One nit though is that we'd have * to detect exited threads. */ gdb_assert(kvm != NULL); #if 0 prune_threads(); #endif #if 0 struct target_ops *tb; if (kvm != NULL) return; tb = find_target_beneath(ops); if (tb->to_update_thread_list != NULL) tb->to_update_thread_list(tb); #endif } -static const char * -kgdb_trgt_pid_to_str(struct target_ops *ops, ptid_t ptid) +const char * +fbsd_kvm_target::pid_to_str(ptid_t ptid) { static char buf[33]; - snprintf(buf, sizeof(buf), "Thread %ld", ptid_get_tid(ptid)); + snprintf(buf, sizeof(buf), "Thread %ld", ptid.tid()); return (buf); } -static int -kgdb_trgt_thread_alive(struct target_ops *ops, ptid_t ptid) +bool +fbsd_kvm_target::thread_alive(ptid_t ptid) { - return (kgdb_thr_lookup_tid(ptid_get_tid(ptid)) != NULL); + return (kgdb_thr_lookup_tid(ptid.tid()) != NULL); } -static void -kgdb_trgt_fetch_registers(struct target_ops *tops, - struct regcache *regcache, int regnum) +void +fbsd_kvm_target::fetch_registers(struct regcache *regcache, int regnum) { struct fbsd_vmcore_ops *ops = (struct fbsd_vmcore_ops *) gdbarch_data (target_gdbarch(), fbsd_vmcore_data); struct kthr *kt; if (ops->supply_pcb == NULL) return; - kt = kgdb_thr_lookup_tid(ptid_get_tid(inferior_ptid)); + kt = kgdb_thr_lookup_tid(inferior_ptid.tid()); if (kt == NULL) return; ops->supply_pcb(regcache, kt->pcb); } -static enum target_xfer_status -kgdb_trgt_xfer_partial(struct target_ops *ops, enum target_object object, +enum target_xfer_status +fbsd_kvm_target::xfer_partial(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) { ssize_t nbytes; gdb_assert(kvm != NULL); switch (object) { case TARGET_OBJECT_MEMORY: nbytes = len; if (readbuf != NULL) #ifdef HAVE_KVM_OPEN2 nbytes = kvm_read2(kvm, offset, readbuf, len); #else nbytes = kvm_read(kvm, offset, readbuf, len); #endif if (writebuf != NULL && len > 0) nbytes = kvm_write(kvm, offset, writebuf, len); if (nbytes < 0) return TARGET_XFER_E_IO; if (nbytes == 0) return TARGET_XFER_EOF; *xfered_len = nbytes; return TARGET_XFER_OK; default: return TARGET_XFER_E_IO; } } +#if 0 static int kgdb_trgt_insert_breakpoint(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt) { return 0; } static int kgdb_trgt_remove_breakpoint(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt, enum remove_bp_reason reason) { return 0; } +#endif static void kgdb_switch_to_thread(const char *arg, int tid) { struct thread_info *tp; tp = find_thread_ptid (fbsd_vmcore_ptid (tid)); if (tp == NULL) error ("invalid tid"); thread_select (arg, tp); } static void kgdb_set_proc_cmd (const char *arg, int from_tty) { CORE_ADDR addr; struct kthr *thr; if (!arg) error_no_arg ("proc address for the new context"); if (kvm == NULL) error ("only supported for core file target"); addr = parse_and_eval_address (arg); if (addr < kernstart) { thr = kgdb_thr_lookup_pid((int)addr); if (thr == NULL) error ("invalid pid"); } else { thr = kgdb_thr_lookup_paddr(addr); if (thr == NULL) error("invalid proc address"); } kgdb_switch_to_thread(arg, thr->tid); } static void kgdb_set_tid_cmd (const char *arg, int from_tty) { CORE_ADDR addr; struct kthr *thr; if (!arg) error_no_arg ("TID or thread address for the new context"); addr = (CORE_ADDR) parse_and_eval_address (arg); if (kvm != NULL && addr >= kernstart) { thr = kgdb_thr_lookup_taddr(addr); if (thr == NULL) error("invalid thread address"); addr = thr->tid; } kgdb_switch_to_thread(arg, addr); } -static int -kgdb_trgt_return_one(struct target_ops *ops) -{ - - return 1; -} - void _initialize_kgdb_target(void) { - kgdb_trgt_ops.to_magic = OPS_MAGIC; - kgdb_trgt_ops.to_shortname = "vmcore"; - kgdb_trgt_ops.to_longname = "kernel core dump file"; - kgdb_trgt_ops.to_doc = "Use a vmcore file as a target.\n\ -If no filename is specified, /dev/mem is used to examine the running kernel.\n\ -target vmcore [-w] [filename]"; - kgdb_trgt_ops.to_stratum = process_stratum; - kgdb_trgt_ops.to_has_memory = kgdb_trgt_return_one; - kgdb_trgt_ops.to_has_registers = kgdb_trgt_return_one; - kgdb_trgt_ops.to_has_stack = kgdb_trgt_return_one; - - kgdb_trgt_ops.to_open = kgdb_trgt_open; - kgdb_trgt_ops.to_close = kgdb_trgt_close; - kgdb_trgt_ops.to_detach = kgdb_trgt_detach; - kgdb_trgt_ops.to_extra_thread_info = kgdb_trgt_extra_thread_info; - kgdb_trgt_ops.to_fetch_registers = kgdb_trgt_fetch_registers; - kgdb_trgt_ops.to_files_info = kgdb_trgt_files_info; - kgdb_trgt_ops.to_update_thread_list = kgdb_trgt_update_thread_list; - kgdb_trgt_ops.to_pid_to_str = kgdb_trgt_pid_to_str; - kgdb_trgt_ops.to_thread_alive = kgdb_trgt_thread_alive; - kgdb_trgt_ops.to_xfer_partial = kgdb_trgt_xfer_partial; - kgdb_trgt_ops.to_insert_breakpoint = kgdb_trgt_insert_breakpoint; - kgdb_trgt_ops.to_remove_breakpoint = kgdb_trgt_remove_breakpoint; - - add_target(&kgdb_trgt_ops); + add_target(fbsd_kvm_target_info, fbsd_kvm_target_open); fbsd_vmcore_data = gdbarch_data_register_pre_init(fbsd_vmcore_init); add_com ("proc", class_obscure, kgdb_set_proc_cmd, "Set current process context"); add_com ("tid", class_obscure, kgdb_set_tid_cmd, "Set current thread context"); } CORE_ADDR kgdb_trgt_stop_pcb(u_int cpuid) { if (stoppcbs == 0 || pcb_size == 0) return 0; return (stoppcbs + pcb_size * cpuid); } Index: head/devel/gdb/files/kgdb/i386fbsd-kern.c =================================================================== --- head/devel/gdb/files/kgdb/i386fbsd-kern.c (revision 480612) +++ head/devel/gdb/files/kgdb/i386fbsd-kern.c (revision 480613) @@ -1,580 +1,580 @@ /* * Copyright (c) 2004 Marcel Moolenaar * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "defs.h" #include "frame-unwind.h" #include "gdbcore.h" #include "inferior.h" #include "osabi.h" #include "regcache.h" #include "progspace.h" #include "solib.h" #include "trad-frame.h" #include "i386-tdep.h" #ifdef __i386__ #include #include #include #include #include #endif #include "kgdb.h" struct i386fbsd_info { int ofs_fix; }; /* Per-program-space data key. */ static const struct program_space_data *i386fbsd_pspace_data; static void i386fbsd_pspace_data_cleanup (struct program_space *pspace, void *arg) { struct i386fbsd_info *info = (struct i386fbsd_info *)arg; xfree (info); } /* Get the current i386fbsd data. If none is found yet, add it now. This function always returns a valid object. */ static struct i386fbsd_info * get_i386fbsd_info (void) { struct i386fbsd_info *info; info = (struct i386fbsd_info *) program_space_data (current_program_space, i386fbsd_pspace_data); if (info != NULL) return info; info = XCNEW (struct i386fbsd_info); set_program_space_data (current_program_space, i386fbsd_pspace_data, info); /* * In revision 1.117 of i386/i386/exception.S trap handlers * were changed to pass trapframes by reference rather than * by value. Detect this by seeing if the first instruction * at the 'calltrap' label is a "push %esp" which has the * opcode 0x54. */ if (parse_and_eval_long("((char *)calltrap)[0]") == 0x54) info->ofs_fix = 4; else info->ofs_fix = 0; return info; } /* * Even though the pcb contains fields for the segment selectors, only * %gs is updated on each context switch. The other selectors are * saved in stoppcbs[], but we just hardcode their known values rather * than handling that special case. */ static const int i386fbsd_pcb_offset[] = { -1, /* %eax */ -1, /* %ecx */ -1, /* %edx */ 4 * 4, /* %ebx */ 3 * 4, /* %esp */ 2 * 4, /* %ebp */ 1 * 4, /* %esi */ 0 * 4, /* %edi */ 5 * 4, /* %eip */ -1, /* %eflags */ -1, /* %cs */ -1, /* %ss */ -1, /* %ds */ -1, /* %es */ -1, /* %fs */ -1, /* %gs */ }; #define CODE_SEL (4 << 3) #define DATA_SEL (5 << 3) #define PRIV_SEL (1 << 3) static void i386fbsd_supply_pcb(struct regcache *regcache, CORE_ADDR pcb_addr) { gdb_byte buf[4]; int i; memset(buf, 0, sizeof(buf)); /* * XXX The PCB may have been swapped out. Supply a dummy %eip value * so as to avoid triggering an exception during stack unwinding. */ regcache->raw_supply(I386_EIP_REGNUM, buf); for (i = 0; i < ARRAY_SIZE (i386fbsd_pcb_offset); i++) if (i386fbsd_pcb_offset[i] != -1) { if (target_read_memory(pcb_addr + i386fbsd_pcb_offset[i], buf, sizeof buf) != 0) continue; regcache->raw_supply(i, buf); } regcache->raw_supply_unsigned(I386_CS_REGNUM, CODE_SEL); regcache->raw_supply_unsigned(I386_DS_REGNUM, DATA_SEL); regcache->raw_supply_unsigned(I386_ES_REGNUM, DATA_SEL); regcache->raw_supply_unsigned(I386_FS_REGNUM, PRIV_SEL); regcache->raw_supply_unsigned(I386_GS_REGNUM, DATA_SEL); regcache->raw_supply_unsigned(I386_SS_REGNUM, DATA_SEL); } #ifdef __i386__ /* TODO: Make this cross-debugger friendly. */ static const int i386fbsd_tss_offset[] = { 10 * 4, /* %eax */ 11 * 4, /* %ecx */ 12 * 4, /* %edx */ 13 * 4, /* %ebx */ 14 * 4, /* %esp */ 15 * 4, /* %ebp */ 16 * 4, /* %esi */ 17 * 4, /* %edi */ 8 * 4, /* %eip */ 9 * 4, /* %eflags */ 19 * 4, /* %cs */ 20 * 4, /* %ss */ 21 * 4, /* %ds */ 18 * 4, /* %es */ 22 * 4, /* %fs */ 23 * 4, /* %gs */ }; /* * If the current thread is executing on a CPU, fetch the common_tss * for that CPU. * * This is painful because 'struct pcpu' is variant sized, so we can't * use it. Instead, we lookup the GDT selector for this CPU and * extract the base of the TSS from there. */ static CORE_ADDR i386fbsd_fetch_tss(void) { struct kthr *kt; struct segment_descriptor sd; CORE_ADDR addr, cpu0prvpage, tss; - kt = kgdb_thr_lookup_tid(ptid_get_tid(inferior_ptid)); + kt = kgdb_thr_lookup_tid(inferior_ptid.tid()); if (kt == NULL || kt->cpu == NOCPU || kt->cpu < 0) return (0); addr = kgdb_lookup("gdt"); if (addr == 0) return (0); addr += (kt->cpu * NGDT + GPROC0_SEL) * sizeof(sd); if (target_read_memory(addr, (gdb_byte *)&sd, sizeof(sd)) != 0) return (0); if (sd.sd_type != SDT_SYS386BSY) { warning ("descriptor is not a busy TSS"); return (0); } tss = sd.sd_hibase << 24 | sd.sd_lobase; /* * In SMP kernels, the TSS is stored as part of the per-CPU * data. On older kernels, the CPU0's private page * is stored at an address that isn't mapped in minidumps. * However, the data is mapped at the alternate cpu0prvpage * address. Thus, if the TSS is at the invalid address, * change it to be relative to cpu0prvpage instead. */ if (trunc_page(tss) == 0xffc00000) { TRY { cpu0prvpage = parse_and_eval_address("cpu0prvpage"); } CATCH(e, RETURN_MASK_ERROR) { return (0); } END_CATCH tss = cpu0prvpage + (tss & PAGE_MASK); } return (tss); } static struct trad_frame_cache * i386fbsd_dblfault_cache (struct frame_info *this_frame, void **this_cache) { struct gdbarch *gdbarch = get_frame_arch (this_frame); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); struct trad_frame_cache *cache; CORE_ADDR addr, func, tss; int i; if (*this_cache != NULL) return (struct trad_frame_cache *)(*this_cache); cache = trad_frame_cache_zalloc (this_frame); *this_cache = cache; func = get_frame_func (this_frame); tss = i386fbsd_fetch_tss (); for (i = 0; i < ARRAY_SIZE (i386fbsd_tss_offset); i++) if (i386fbsd_tss_offset[i] != -1) trad_frame_set_reg_addr (cache, i, tss + i386fbsd_tss_offset[i]); /* Construct the frame ID using the function start. */ /* XXX: Stack address should be dbfault_stack + PAGE_SIZE. */ trad_frame_set_id (cache, frame_id_build (tss + sizeof(struct i386tss), func)); return cache; } static void i386fbsd_dblfault_this_id (struct frame_info *this_frame, void **this_cache, struct frame_id *this_id) { struct trad_frame_cache *cache = i386fbsd_dblfault_cache (this_frame, this_cache); trad_frame_get_id (cache, this_id); } static struct value * i386fbsd_dblfault_prev_register (struct frame_info *this_frame, void **this_cache, int regnum) { struct trad_frame_cache *cache = i386fbsd_dblfault_cache (this_frame, this_cache); return trad_frame_get_register (cache, this_frame, regnum); } static int i386fbsd_dblfault_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, void **this_prologue_cache) { const char *name; find_pc_partial_function (get_frame_func (this_frame), &name, NULL, NULL); return (name && strcmp (name, "dblfault_handler") == 0); } static const struct frame_unwind i386fbsd_dblfault_unwind = { SIGTRAMP_FRAME, default_frame_unwind_stop_reason, i386fbsd_dblfault_this_id, i386fbsd_dblfault_prev_register, NULL, i386fbsd_dblfault_sniffer }; #endif static const int i386fbsd_trapframe_offset[] = { 10 * 4, /* %eax */ 9 * 4, /* %ecx */ 8 * 4, /* %edx */ 7 * 4, /* %ebx */ 16 * 4, /* %esp */ 5 * 4, /* %ebp */ 4 * 4, /* %esi */ 3 * 4, /* %edi */ 13 * 4, /* %eip */ 15 * 4, /* %eflags */ 14 * 4, /* %cs */ 17 * 4, /* %ss */ 2 * 4, /* %ds */ 1 * 4, /* %es */ 0 * 4, /* %fs */ -1 /* %gs */ }; #define TRAPFRAME_SIZE 72 static struct trad_frame_cache * i386fbsd_trapframe_cache (struct frame_info *this_frame, void **this_cache) { struct gdbarch *gdbarch = get_frame_arch (this_frame); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); struct trad_frame_cache *cache; struct i386fbsd_info *info; CORE_ADDR addr, cs, func, pc, sp; const char *name; int i; if (*this_cache != NULL) return ((struct trad_frame_cache *)*this_cache); info = get_i386fbsd_info(); cache = trad_frame_cache_zalloc (this_frame); *this_cache = cache; func = get_frame_func (this_frame); sp = get_frame_register_unsigned (this_frame, I386_ESP_REGNUM); find_pc_partial_function (func, &name, NULL, NULL); if (strcmp(name, "calltrap") == 0 || strcmp(name, "Xlcall_syscall") == 0 || strcmp(name, "Xint0x80_syscall") == 0) /* Traps in later kernels pass the trap frame by reference. */ sp += info->ofs_fix; else if (strcmp(name, "Xtimerint") == 0) /* Timer interrupts also pass the trap frame by reference. */ sp += info->ofs_fix; else if (strcmp(name, "Xcpustop") == 0 || strcmp(name, "Xrendezvous") == 0 || strcmp(name, "Xipi_intr_bitmap_handler") == 0 || strcmp(name, "Xlazypmap") == 0) /* These handlers push a trap frame only. */ ; else if (strcmp(name, "fork_trampoline") == 0) if (get_frame_pc (this_frame) == func) { /* fork_exit hasn't been called (kthread has never run), so %esp in the pcb points to the word above the trapframe. */ sp += 4; } else { /* fork_exit has been called, so %esp in fork_exit's frame is &tf - 12. */ sp += 12; } else { /* Interrupt frames pass the IDT vector in addition to the trap frame. */ sp += info->ofs_fix + 4; } addr = sp + i386fbsd_trapframe_offset[I386_CS_REGNUM]; cs = read_memory_unsigned_integer (addr, 4, byte_order); for (i = 0; i < ARRAY_SIZE (i386fbsd_trapframe_offset); i++) { /* %ss/%esp are only present in the trapframe for a trap from userland. */ if ((cs & I386_SEL_RPL) == I386_SEL_KPL) { if (i == I386_SS_REGNUM) continue; if (i == I386_ESP_REGNUM) { trad_frame_set_reg_value (cache, i, sp + TRAPFRAME_SIZE - 8); continue; } } if (i386fbsd_trapframe_offset[i] != -1) trad_frame_set_reg_addr (cache, i, sp + i386fbsd_trapframe_offset[i]); } /* Read %eip from trap frame. */ addr = sp + i386fbsd_trapframe_offset[I386_EIP_REGNUM]; pc = read_memory_unsigned_integer (addr, 4, byte_order); if (pc == 0 && strcmp(name, "fork_trampoline") == 0) { /* Initial frame of a kthread; terminate backtrace. */ trad_frame_set_id (cache, outer_frame_id); } else { /* Construct the frame ID using the function start. */ sp += TRAPFRAME_SIZE; if ((cs & I386_SEL_RPL) == I386_SEL_KPL) sp -= 8; trad_frame_set_id (cache, frame_id_build (sp, func)); } return cache; } static void i386fbsd_trapframe_this_id (struct frame_info *this_frame, void **this_cache, struct frame_id *this_id) { struct trad_frame_cache *cache = i386fbsd_trapframe_cache (this_frame, this_cache); trad_frame_get_id (cache, this_id); } static struct value * i386fbsd_trapframe_prev_register (struct frame_info *this_frame, void **this_cache, int regnum) { struct trad_frame_cache *cache = i386fbsd_trapframe_cache (this_frame, this_cache); return trad_frame_get_register (cache, this_frame, regnum); } static int i386fbsd_trapframe_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, void **this_prologue_cache) { const char *name; find_pc_partial_function (get_frame_func (this_frame), &name, NULL, NULL); return (name && ((strcmp (name, "calltrap") == 0) || (strcmp (name, "fork_trampoline") == 0) || (name[0] == 'X' && name[1] != '_'))); } static const struct frame_unwind i386fbsd_trapframe_unwind = { SIGTRAMP_FRAME, default_frame_unwind_stop_reason, i386fbsd_trapframe_this_id, i386fbsd_trapframe_prev_register, NULL, i386fbsd_trapframe_sniffer }; static void i386fbsd_kernel_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch) { i386_elf_init_abi(info, gdbarch); #ifdef __i386__ frame_unwind_prepend_unwinder(gdbarch, &i386fbsd_dblfault_unwind); #endif frame_unwind_prepend_unwinder(gdbarch, &i386fbsd_trapframe_unwind); set_solib_ops(gdbarch, &kld_so_ops); fbsd_vmcore_set_supply_pcb(gdbarch, i386fbsd_supply_pcb); fbsd_vmcore_set_cpu_pcb_addr(gdbarch, kgdb_trgt_stop_pcb); } void _initialize_i386_kgdb_tdep(void) { /* This is used for both i386 and amd64, but amd64 always includes this target, so just include it here. */ gdbarch_register_osabi_sniffer(bfd_arch_i386, bfd_target_elf_flavour, fbsd_kernel_osabi_sniffer); gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_FREEBSD_KERNEL, i386fbsd_kernel_init_abi); i386fbsd_pspace_data = register_program_space_data_with_cleanup (NULL, i386fbsd_pspace_data_cleanup); #ifdef __i386__ /* * FreeBSD/i386 kernels prior to the introduction of AVX * support used a different layout for the PCB. If gdb is * compiled on these systems, these asserts will fail. The * package builders build packages on older systems which are * then run on newer systems. These binaries trip over these * assertions even when debugging user programs and even * though the running kernel is new enough. To cope, disable * the assertion checks unless gdb is built against a new * enough world. Note that this means kgdb is not going to * parse PCBs correctly on FreeBSD/i386 kernels before AVX was * merged. */ #if __FreeBSD_version >= 1001505 gdb_assert(offsetof(struct pcb, pcb_ebx) == i386fbsd_pcb_offset[I386_EBX_REGNUM]); gdb_assert(offsetof(struct pcb, pcb_esp) == i386fbsd_pcb_offset[I386_ESP_REGNUM]); gdb_assert(offsetof(struct pcb, pcb_ebp) == i386fbsd_pcb_offset[I386_EBP_REGNUM]); gdb_assert(offsetof(struct pcb, pcb_esi) == i386fbsd_pcb_offset[I386_ESI_REGNUM]); gdb_assert(offsetof(struct pcb, pcb_edi) == i386fbsd_pcb_offset[I386_EDI_REGNUM]); gdb_assert(offsetof(struct pcb, pcb_eip) == i386fbsd_pcb_offset[I386_EIP_REGNUM]); #endif gdb_assert(CODE_SEL == GSEL(GCODE_SEL, SEL_KPL)); gdb_assert(DATA_SEL == GSEL(GDATA_SEL, SEL_KPL)); gdb_assert(PRIV_SEL == GSEL(GPRIV_SEL, SEL_KPL)); gdb_assert(sizeof(struct trapframe) == TRAPFRAME_SIZE); gdb_assert(offsetof(struct trapframe, tf_eax) == i386fbsd_trapframe_offset[I386_EAX_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_ecx) == i386fbsd_trapframe_offset[I386_ECX_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_edx) == i386fbsd_trapframe_offset[I386_EDX_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_ebx) == i386fbsd_trapframe_offset[I386_EBX_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_esp) == i386fbsd_trapframe_offset[I386_ESP_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_ebp) == i386fbsd_trapframe_offset[I386_EBP_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_esi) == i386fbsd_trapframe_offset[I386_ESI_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_edi) == i386fbsd_trapframe_offset[I386_EDI_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_eip) == i386fbsd_trapframe_offset[I386_EIP_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_eflags) == i386fbsd_trapframe_offset[I386_EFLAGS_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_cs) == i386fbsd_trapframe_offset[I386_CS_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_ss) == i386fbsd_trapframe_offset[I386_SS_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_ds) == i386fbsd_trapframe_offset[I386_DS_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_es) == i386fbsd_trapframe_offset[I386_ES_REGNUM]); gdb_assert(offsetof(struct trapframe, tf_fs) == i386fbsd_trapframe_offset[I386_FS_REGNUM]); gdb_assert(offsetof(struct i386tss, tss_eax) == i386fbsd_tss_offset[I386_EAX_REGNUM]); gdb_assert(offsetof(struct i386tss, tss_ecx) == i386fbsd_tss_offset[I386_ECX_REGNUM]); gdb_assert(offsetof(struct i386tss, tss_edx) == i386fbsd_tss_offset[I386_EDX_REGNUM]); gdb_assert(offsetof(struct i386tss, tss_ebx) == i386fbsd_tss_offset[I386_EBX_REGNUM]); gdb_assert(offsetof(struct i386tss, tss_esp) == i386fbsd_tss_offset[I386_ESP_REGNUM]); gdb_assert(offsetof(struct i386tss, tss_ebp) == i386fbsd_tss_offset[I386_EBP_REGNUM]); gdb_assert(offsetof(struct i386tss, tss_esi) == i386fbsd_tss_offset[I386_ESI_REGNUM]); gdb_assert(offsetof(struct i386tss, tss_edi) == i386fbsd_tss_offset[I386_EDI_REGNUM]); gdb_assert(offsetof(struct i386tss, tss_eip) == i386fbsd_tss_offset[I386_EIP_REGNUM]); gdb_assert(offsetof(struct i386tss, tss_eflags) == i386fbsd_tss_offset[I386_EFLAGS_REGNUM]); gdb_assert(offsetof(struct i386tss, tss_cs) == i386fbsd_tss_offset[I386_CS_REGNUM]); gdb_assert(offsetof(struct i386tss, tss_ss) == i386fbsd_tss_offset[I386_SS_REGNUM]); gdb_assert(offsetof(struct i386tss, tss_ds) == i386fbsd_tss_offset[I386_DS_REGNUM]); gdb_assert(offsetof(struct i386tss, tss_es) == i386fbsd_tss_offset[I386_ES_REGNUM]); gdb_assert(offsetof(struct i386tss, tss_fs) == i386fbsd_tss_offset[I386_FS_REGNUM]); gdb_assert(offsetof(struct i386tss, tss_gs) == i386fbsd_tss_offset[I386_GS_REGNUM]); #endif } Index: head/devel/gdb/files/kgdb/kgdb-main.c =================================================================== --- head/devel/gdb/files/kgdb/kgdb-main.c (revision 480612) +++ head/devel/gdb/files/kgdb/kgdb-main.c (revision 480613) @@ -1,413 +1,412 @@ /* * Copyright (c) 2004 Marcel Moolenaar * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include /* libgdb stuff. */ #include #include #include #include #include #include #include #include -#include "observer.h" #include #include #include #include #include #include #include "kgdb.h" static int verbose; static char crashdir[PATH_MAX]; static char *dumpnr; static char *kernel; static char *remote; static char *vmcore; /* * TODO: * - test remote kgdb (see if threads and klds work) * - possibly split kthr.c out into a separate thread_stratum target that * uses new_objfile test to push itself when a FreeBSD kernel is loaded * (check for kernel osabi) (probably don't bother with this) * + test alternate kgdb_lookup() * + fix kgdb build on amd64 to include i386 cross-debug support * - propose expanded libkvm interface that supports cross-debug and moves * MD bits of kgdb into the library (examining PCB's and exporting a * stable-ABI struct of registers, similarly for trapframe handling and * stop-pcb stuff * + use tid's as lwp IDs instead of PIDs in ptid's */ static void usage(void) { fprintf(stderr, "usage: %s [-afqvw] [-b rate] [-d crashdir] [-c core | -n dumpnr | -r device]\n" "\t[kernel [core]]\n", getprogname()); exit(1); } static void kernel_from_dumpnr(const char *nr) { char line[PATH_MAX], path[PATH_MAX]; FILE *info; char *dir; struct stat st; int l; /* * If there's a kernel image right here in the crash directory, then * use it. The kernel image is either called kernel. or is in a * subdirectory kernel. and called kernel. The latter allows us * to collect the modules in the same place. */ snprintf(path, sizeof(path), "%s/kernel.%s", crashdir, nr); if (stat(path, &st) == 0) { if (S_ISREG(st.st_mode)) { kernel = strdup(path); return; } if (S_ISDIR(st.st_mode)) { snprintf(path, sizeof(path), "%s/kernel.%s/kernel", crashdir, nr); if (stat(path, &st) == 0 && S_ISREG(st.st_mode)) { kernel = strdup(path); return; } } } /* * No kernel image here. Parse the dump header. The kernel object * directory can be found there and we probably have the kernel * image still in it. The object directory may also have a kernel * with debugging info (called either kernel.full or kernel.debug). * If we have a debug kernel, use it. */ snprintf(path, sizeof(path), "%s/info.%s", crashdir, nr); info = fopen(path, "r"); if (info == NULL) { warn("%s", path); return; } while (fgets(line, sizeof(line), info) != NULL) { l = strlen(line); if (l > 0 && line[l - 1] == '\n') line[--l] = '\0'; if (strncmp(line, " ", 4) == 0) { fclose(info); dir = strchr(line, ':'); dir = (dir == NULL) ? line + 4 : dir + 1; /* * Check for kernel.full first as if it exists * kernel.debug will also exist, but will only * contain debug symbols and not be recognized * as a valid kernel by the osabi sniffer. */ snprintf(path, sizeof(path), "%s/kernel.full", dir); if (stat(path, &st) == 0 && S_ISREG(st.st_mode)) { kernel = strdup(path); return; } snprintf(path, sizeof(path), "%s/kernel.debug", dir); if (stat(path, &st) == 0 && S_ISREG(st.st_mode)) { kernel = strdup(path); return; } snprintf(path, sizeof(path), "%s/kernel", dir); if (stat(path, &st) == 0 && S_ISREG(st.st_mode)) { kernel = strdup(path); return; } return; } } fclose(info); } /* * Remote targets can support any number of syntaxes and we want to * support them all with one addition: we support specifying a device * node for a serial device without the "/dev/" prefix. * * What we do is to stat(2) the existing remote target first. If that * fails, we try it with "/dev/" prepended. If that succeeds we use * the resulting path, otherwise we use the original target. If * either stat(2) succeeds make sure the file is either a character * device or a FIFO. */ static void verify_remote(void) { char path[PATH_MAX]; struct stat st; if (stat(remote, &st) != 0) { snprintf(path, sizeof(path), "/dev/%s", remote); if (stat(path, &st) != 0) return; free(remote); remote = strdup(path); } if (!S_ISCHR(st.st_mode) && !S_ISFIFO(st.st_mode)) errx(1, "%s: not a special file, FIFO or socket", remote); } static void add_arg(struct captured_main_args *args, char const *arg) { args->argc++; args->argv = (char **)reallocf(args->argv, (args->argc + 1) * sizeof(char *)); if (args->argv == NULL) err(1, "Out of memory building argument list"); args->argv[args->argc] = (char *)arg; } int main(int argc, char *argv[]) { char path[PATH_MAX]; struct stat st; struct captured_main_args args; char *s; int a, ch, writeable; dumpnr = NULL; writeable = 0; strlcpy(crashdir, "/var/crash", sizeof(crashdir)); s = getenv("KGDB_CRASH_DIR"); if (s != NULL) strlcpy(crashdir, s, sizeof(crashdir)); /* Convert long options into short options. */ for (a = 1; a < argc; a++) { s = argv[a]; if (s[0] == '-') { s++; /* Long options take either 1 or 2 dashes. */ if (s[0] == '-') s++; if (strcmp(s, "quiet") == 0) argv[a] = (char *)"-q"; else if (strcmp(s, "fullname") == 0) argv[a] = (char *)"-f"; } } kgdb_quiet = 0; memset (&args, 0, sizeof args); args.interpreter_p = INTERP_CONSOLE; args.argv = (char **)xmalloc(sizeof(char *)); args.argv[0] = argv[0]; while ((ch = getopt(argc, argv, "ab:c:d:fn:qr:vw")) != -1) { switch (ch) { case 'a': annotation_level++; break; case 'b': { int i; char *p; i = strtol(optarg, &p, 0); if (*p != '\0' || p == optarg) warnx("warning: could not set baud rate to `%s'.\n", optarg); else baud_rate = i; break; } case 'c': /* use given core file. */ if (vmcore != NULL) { warnx("option %c: can only be specified once", optopt); usage(); /* NOTREACHED */ } vmcore = strdup(optarg); break; case 'd': /* lookup dumps in given directory. */ strlcpy(crashdir, optarg, sizeof(crashdir)); break; case 'f': annotation_level = 1; break; case 'n': /* use dump with given number. */ dumpnr = optarg; break; case 'q': kgdb_quiet = 1; add_arg(&args, "-q"); break; case 'r': /* use given device for remote session. */ if (remote != NULL) { warnx("option %c: can only be specified once", optopt); usage(); /* NOTREACHED */ } remote = strdup(optarg); break; case 'v': /* increase verbosity. */ verbose++; break; case 'w': /* core file is writeable. */ writeable = 1; break; case '?': default: usage(); } } if (((vmcore != NULL) ? 1 : 0) + ((dumpnr != NULL) ? 1 : 0) + ((remote != NULL) ? 1 : 0) > 1) { warnx("options -c, -n and -r are mutually exclusive"); usage(); /* NOTREACHED */ } if (verbose > 1) warnx("using %s as the crash directory", crashdir); if (argc > optind) kernel = strdup(argv[optind++]); if (argc > optind && (dumpnr != NULL || remote != NULL)) { warnx("options -n and -r do not take a core file. Ignored"); optind = argc; } if (dumpnr != NULL) { snprintf(path, sizeof(path), "%s/vmcore.%s", crashdir, dumpnr); if (stat(path, &st) == -1) err(1, "%s", path); if (!S_ISREG(st.st_mode)) errx(1, "%s: not a regular file", path); vmcore = strdup(path); } else if (remote != NULL) { verify_remote(); } else if (argc > optind) { if (vmcore == NULL) vmcore = strdup(argv[optind++]); if (argc > optind) warnx("multiple core files specified. Ignored"); } else if (vmcore == NULL && kernel == NULL) { vmcore = strdup(_PATH_MEM); kernel = strdup(getbootfile()); } if (verbose) { if (vmcore != NULL) warnx("core file: %s", vmcore); if (remote != NULL) warnx("device file: %s", remote); if (kernel != NULL) warnx("kernel image: %s", kernel); } /* A remote target requires an explicit kernel argument. */ if (remote != NULL && kernel == NULL) { warnx("remote debugging requires a kernel"); usage(); /* NOTREACHED */ } /* If we don't have a kernel image yet, try to find one. */ if (kernel == NULL) { if (dumpnr != NULL) kernel_from_dumpnr(dumpnr); if (kernel == NULL) errx(1, "couldn't find a suitable kernel image"); if (verbose) warnx("kernel image: %s", kernel); } /* Set an alternate prompt. */ add_arg(&args, "-iex"); add_arg(&args, "set prompt (kgdb) "); /* Change osabi to assume a FreeBSD kernel. */ add_arg(&args, "-iex"); add_arg(&args, "set osabi FreeBSD/kernel"); /* Open the vmcore if requested. */ if (vmcore != NULL) { add_arg(&args, "-ex"); if (asprintf(&s, "target vmcore %s%s", writeable ? "-w " : "", vmcore) < 0) err(1, "couldn't build command line"); add_arg(&args, s); } /* Open the remote target if requested. */ if (remote != NULL) { add_arg(&args, "-ex"); if (asprintf(&s, "target remote %s", remote) < 0) err(1, "couldn't build command line"); add_arg(&args, s); } add_arg(&args, kernel); /* The libgdb code uses optind too. Reset it... */ optind = 0; /* Terminate argv list. */ add_arg(&args, NULL); return (gdb_main(&args)); } Index: head/devel/gdb/files/kgdb/kgdb.h =================================================================== --- head/devel/gdb/files/kgdb/kgdb.h (revision 480612) +++ head/devel/gdb/files/kgdb/kgdb.h (revision 480613) @@ -1,67 +1,66 @@ /* * Copyright (c) 2004 Marcel Moolenaar * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _KGDB_H_ #define _KGDB_H_ struct kthr { struct kthr *next; CORE_ADDR paddr; CORE_ADDR kaddr; CORE_ADDR pcb; int tid; int pid; int cpu; }; extern struct kthr *curkthr; extern struct target_so_ops kld_so_ops; -extern struct target_ops kgdb_trgt_ops; extern int kgdb_quiet; CORE_ADDR kgdb_trgt_stop_pcb(u_int); struct kthr *kgdb_thr_first(void); struct kthr *kgdb_thr_init(CORE_ADDR (*cpu_pcb_addr) (u_int)); struct kthr *kgdb_thr_lookup_tid(int); struct kthr *kgdb_thr_lookup_pid(int); struct kthr *kgdb_thr_lookup_paddr(uintptr_t); struct kthr *kgdb_thr_lookup_taddr(uintptr_t); struct kthr *kgdb_thr_next(struct kthr *); const char *kgdb_thr_extra_thread_info(int); enum gdb_osabi fbsd_kernel_osabi_sniffer(bfd *abfd); void fbsd_vmcore_set_supply_pcb (struct gdbarch *gdbarch, void (*supply_pcb) (struct regcache *, CORE_ADDR)); void fbsd_vmcore_set_cpu_pcb_addr (struct gdbarch *gdbarch, CORE_ADDR (*cpu_pcb_addr) (u_int)); CORE_ADDR kgdb_lookup(const char *sym); #endif /* _KGDB_H_ */ Index: head/devel/gdb/files/patch-gdb_configure =================================================================== --- head/devel/gdb/files/patch-gdb_configure (revision 480612) +++ head/devel/gdb/files/patch-gdb_configure (revision 480613) @@ -1,19 +1,16 @@ --- gdb/configure.orig 2017-09-14 09:28:17 UTC +++ gdb/configure -@@ -15292,13 +15292,10 @@ if test "${ERROR_ON_WARNING}" = yes ; then - WERROR_CFLAGS="-Werror" - fi +@@ -15467,10 +15467,10 @@ fi --# The options we'll try to enable. -+# These options work in either C or C++ modes. + # The options we'll try to enable. build_warnings="-Wall -Wpointer-arith \ --Wno-unused -Wunused-value -Wunused-function \ ---Wno-switch -Wno-char-subscripts \ ++-Wno-unused \ + -Wno-switch -Wno-char-subscripts \ --Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable \ --Wno-sign-compare -Wno-narrowing -Wno-error=maybe-uninitialized \ ---Wno-mismatched-tags" -+-Wno-unused -Wno-switch -Wno-char-subscripts \ -+-Wempty-body -Wno-sign-compare -Wno-narrowing -Wno-mismatched-tags" - - case "${host}" in - *-*-mingw32*) ++-Wempty-body \ ++-Wno-sign-compare -Wno-narrowing \ + -Wno-mismatched-tags \ + -Wno-error=deprecated-register \ + -Wsuggest-override \ Index: head/devel/gdb/files/patch-gdb_fbsd-nat.c =================================================================== --- head/devel/gdb/files/patch-gdb_fbsd-nat.c (revision 480612) +++ head/devel/gdb/files/patch-gdb_fbsd-nat.c (revision 480613) @@ -1,17 +1,17 @@ --- gdb/fbsd-nat.c.orig 2017-09-14 09:28:17 UTC +++ gdb/fbsd-nat.c -@@ -682,6 +682,14 @@ fbsd_resume (struct target_ops *ops, +@@ -1108,6 +1108,14 @@ fbsd_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signo) struct thread_info *tp; int request; +#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 ALL_NON_EXITED_THREADS (tp) { - if (ptid_get_pid (tp->ptid) != ptid_get_pid (ptid)) + if (tp->ptid.pid () != ptid.pid ()) Index: head/devel/gdb/files/patch-gdb_i386-fbsd-nat.c =================================================================== --- head/devel/gdb/files/patch-gdb_i386-fbsd-nat.c (revision 480612) +++ head/devel/gdb/files/patch-gdb_i386-fbsd-nat.c (revision 480613) @@ -1,10 +1,27 @@ --- gdb/i386-fbsd-nat.c 2017-09-14 09:28:17 UTC +++ gdb/i386-fbsd-nat.c -@@ -163,7 +163,6 @@ _initialize_i386fbsd_nat (void) - t->to_read_description = i386fbsd_read_description; +@@ -43,8 +43,6 @@ public: + const struct target_desc *read_description () override; #endif -- t->to_resume = i386fbsd_resume; - fbsd_nat_add_target (t); +- void resume (ptid_t, int, enum gdb_signal) override; +- + #if defined(HAVE_PT_GETDBREGS) && defined(USE_SIGTRAP_SIGINFO) + bool supports_stopped_by_hw_breakpoint () override; + #endif +@@ -52,6 +50,7 @@ public: - /* Support debugging kernel virtual memory images. */ + static i386_fbsd_nat_target the_i386_fbsd_nat_target; + ++#if 0 + /* Resume execution of the inferior process. If STEP is nonzero, + single-step it. If SIGNAL is nonzero, give it that signal. */ + +@@ -98,6 +97,7 @@ i386_fbsd_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signal) + gdb_signal_to_host (signal)) == -1) + perror_with_name (("ptrace")); + } ++#endif + + + /* Support for debugging kernel virtual memory images. */ Index: head/devel/gdb/files/patch-gdb_python_python-config.py =================================================================== --- head/devel/gdb/files/patch-gdb_python_python-config.py (revision 480612) +++ head/devel/gdb/files/patch-gdb_python_python-config.py (revision 480613) @@ -1,11 +1,11 @@ --- gdb/python/python-config.py 2017-09-14 09:28:17 UTC +++ gdb/python/python-config.py @@ -59,6 +59,8 @@ for opt in opt_flags: elif opt in ('--libs', '--ldflags'): - libs = [] + libs = ['-lpython' + pyver + abiflags] + if getvar('LDFLAGS') is not None: + libs.extend(getvar('LDFLAGS').split()) if getvar('LIBS') is not None: libs.extend(getvar('LIBS').split()) if getvar('SYSLIBS') is not None: