Index: head/devel/gdb/Makefile =================================================================== --- head/devel/gdb/Makefile (revision 440446) +++ head/devel/gdb/Makefile (revision 440447) @@ -1,124 +1,127 @@ # Created by: Steven Kreuzer # $FreeBSD$ PORTNAME= gdb PORTVERSION= 7.12.1 +PORTREVISION= 1 CATEGORIES= devel MASTER_SITES= GNU MAINTAINER= luca.pizzamiglio@gmail.com COMMENT= GNU GDB of newer version than comes with the system LICENSE= GPLv3 TEST_DEPENDS= runtest:misc/dejagnu TEST_TARGET= check USES= compiler:env cpe iconv 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 CFLAGS:= ${CFLAGS:C/ +$//} # blanks at EOL creep in sometimes CFLAGS+= -DRL_NO_COMPAT -Wno-unused-function -Wno-unused-variable EXCLUDE= dejagnu expect sim texinfo intl EXTRACT_AFTER_ARGS= ${EXCLUDE:S/^/--exclude /} EXTRA_PATCHES= ${FILESDIR}/commit-387360daf9 \ ${FILESDIR}/commit-b268007c68 LIB_DEPENDS+= libexpat.so:textproc/expat2 VER= ${PORTVERSION:S/.//g} PLIST_SUB= VER=${VER} ONLY_FOR_ARCHS= i386 amd64 powerpc powerpc64 armv6 mips # untested elsewhere, might work OPTIONS_DEFINE= DEBUG GDB_LINK GUILE KGDB PYTHON TUI OPTIONS_DEFAULT= GDB_LINK KGDB PYTHON TUI PORT_READLINE OPTIONS_SINGLE= READLINE OPTIONS_SINGLE_READLINE= BUNDLED_READLINE PORT_READLINE GDB_LINK_DESC= Create ${PREFIX}/bin/gdb symlink KGDB_DESC= Kernel Debugging Support BUNDLED_READLINE_DESC= from gdb distfile PORT_READLINE_DESC= from devel/readline port 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 PYTHON_CONFIGURE_ON= --with-python=${PYTHON_CMD} PYTHON_CONFIGURE_OFF= --without-python PYTHON_USES= python:2 TUI_CONFIGURE_ENABLE= tui .include .if ! ${PORT_OPTIONS:MBUNDLED_READLINE} EXCLUDE+= readline .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/files/extrapatch-kgdb =================================================================== --- head/devel/gdb/files/extrapatch-kgdb (revision 440446) +++ head/devel/gdb/files/extrapatch-kgdb (revision 440447) @@ -1,306 +1,316 @@ diff --git gdb/Makefile.in gdb/Makefile.in index 5b6ccea764..f501cf29d1 100644 --- gdb/Makefile.in +++ gdb/Makefile.in @@ -212,7 +212,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 @@ -653,7 +654,8 @@ ALL_64_TARGET_OBS = \ ia64-linux-tdep.o ia64-vms-tdep.o ia64-tdep.o \ mips64obsd-tdep.o \ sparc64fbsd-tdep.o sparc64-linux-tdep.o sparc64nbsd-tdep.o \ - sparc64obsd-tdep.o sparc64-sol2-tdep.o sparc64-tdep.o + sparc64obsd-tdep.o sparc64-sol2-tdep.o sparc64-tdep.o \ + amd64fbsd-kern.o sparc64fbsd-kern.o # All other target-dependent objects files (used with --enable-targets=all). ALL_TARGET_OBS = \ @@ -676,6 +678,8 @@ ALL_TARGET_OBS = \ i386-sol2-tdep.o i386-tdep.o i387-tdep.o \ i386-dicos-tdep.o i386-darwin-tdep.o \ iq2000-tdep.o \ + fbsd-kld.o fbsd-kthr.o fbsd-kvm.o i386fbsd-kern.o ppcfbsd-kern.o \ + mipsfbsd-kern.o \ linux-tdep.o \ lm32-tdep.o \ m32c-tdep.o \ @@ -1133,7 +1137,7 @@ generated_files = config.h observer.h observer.inc ada-lex.c jit-reader.h \ $(COMPILE) $< $(POSTCOMPILE) -all: gdb$(EXEEXT) $(CONFIG_ALL) +all: gdb$(EXEEXT) kgdb$(EXEEXT) $(CONFIG_ALL) @$(MAKE) $(FLAGS_TO_PASS) DO=all "DODIRS=`echo $(SUBDIRS) | sed 's/testsuite//'`" subdir_do installcheck: @@ -1412,6 +1416,12 @@ gdb$(EXEEXT): gdb.o $(LIBGDB_OBS) $(ADD_DEPS) $(CDEPS) $(TDEPLIBS) -o gdb$(EXEEXT) gdb.o $(LIBGDB_OBS) \ $(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES) +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 @@ -1456,7 +1466,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 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 @@ -1688,6 +1698,9 @@ ALLDEPFILES = \ core-regset.c \ dcache.c dicos-tdep.c darwin-nat.c \ exec.c \ + fbsd-kld.c fbsd-kthr.c fbsd-kvm.c \ + amd64fbsd-kern.c i386fbsd-kern.c mipsfbsd-kern.c ppcfbsd-kern.c \ + sparc64fbsd-kern.c \ fbsd-nat.c \ fbsd-tdep.c \ fork-child.c \ @@ -2761,7 +2774,7 @@ py-varobj.o: $(srcdir)/python/py-varobj.c # A list of all the objects we might care about in this build, for # dependency tracking. -all_object_files = gdb.o $(LIBGDB_OBS) gdbtk-main.o \ +all_object_files = kgdb-main.o gdb.o $(LIBGDB_OBS) gdbtk-main.o \ test-cp-name-parser.o # Ensure that generated files are created early. Use order-only diff --git gdb/config.in gdb/config.in index c82a5b4bac..34140b2d59 100644 --- gdb/config.in +++ gdb/config.in @@ -219,6 +219,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/config/mips/fbsd.mh gdb/config/mips/fbsd.mh +index f433347a20..5470795612 100644 +--- gdb/config/mips/fbsd.mh ++++ gdb/config/mips/fbsd.mh +@@ -1,3 +1,5 @@ + # Host: FreeBSD/mips + NATDEPFILES= fork-child.o inf-ptrace.o fbsd-nat.o mips-fbsd-nat.o + HAVE_NATIVE_GCORE_HOST = 1 ++ ++LOADLIBES= -lkvm diff --git gdb/configure gdb/configure index b5c045cf10..68299ff16c 100755 --- gdb/configure +++ gdb/configure @@ -7112,6 +7112,66 @@ $as_echo "#define HAVE_KINFO_GETVMMAP 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 f774db7ea6..efccdd3fb1 100644 --- gdb/configure.ac +++ gdb/configure.ac @@ -540,6 +540,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. ])]) +# 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.tgt gdb/configure.tgt index 9ee9f7a799..fb14b19405 100644 --- gdb/configure.tgt +++ gdb/configure.tgt @@ -190,7 +190,13 @@ i[34567]86-*-dicos*) i[34567]86-*-freebsd* | i[34567]86-*-kfreebsd*-gnu) # Target: FreeBSD/i386 gdb_target_obs="i386-tdep.o i387-tdep.o i386bsd-tdep.o i386fbsd-tdep.o \ - bsd-uthread.o fbsd-tdep.o solib-svr4.o" + bsd-uthread.o fbsd-tdep.o solib-svr4.o \ + fbsd-kld.o fbsd-kthr.o fbsd-kvm.o i386fbsd-kern.o" + if test "x$enable_64_bit_bfd" = "xyes"; then + # Target: FreeBSD amd64 + gdb_target_obs="amd64-tdep.o amd64fbsd-tdep.o amd64fbsd-kern.o \ + ${gdb_target_obs}" + fi ;; i[34567]86-*-netbsd* | i[34567]86-*-knetbsd*-gnu) # Target: NetBSD/i386 @@ -360,7 +366,8 @@ mips*-*-netbsd* | mips*-*-knetbsd*-gnu) ;; mips*-*-freebsd*) # Target: MIPS running FreeBSD - gdb_target_obs="mips-tdep.o mips-fbsd-tdep.o solib-svr4.o fbsd-tdep.o" + gdb_target_obs="mips-tdep.o mips-fbsd-tdep.o solib-svr4.o fbsd-tdep.o \ + fbsd-kld.o fbsd-kthr.o fbsd-kvm.o mipsfbsd-kern.o" gdb_sim=../sim/mips/libsim.a ;; mips64*-*-openbsd*) @@ -419,7 +426,8 @@ powerpc*-*-freebsd*) # Target: FreeBSD/powerpc gdb_target_obs="rs6000-tdep.o ppc-sysv-tdep.o ppc64-tdep.o \ ppcfbsd-tdep.o fbsd-tdep.o solib-svr4.o \ - ravenscar-thread.o ppc-ravenscar-thread.o" + ravenscar-thread.o ppc-ravenscar-thread.o \ + fbsd-kld.o fbsd-kthr.o fbsd-kvm.o ppcfbsd-kern.o" ;; powerpc-*-netbsd* | powerpc-*-knetbsd*-gnu) @@ -543,7 +551,8 @@ sparc*-*-freebsd* | sparc*-*-kfreebsd*-gnu) # Target: FreeBSD/sparc64 gdb_target_obs="sparc-tdep.o sparc64-tdep.o sparc64fbsd-tdep.o \ fbsd-tdep.o solib-svr4.o \ - ravenscar-thread.o sparc-ravenscar-thread.o" + ravenscar-thread.o sparc-ravenscar-thread.o \ + fbsd-kld.o fbsd-kthr.o fbsd-kvm.o sparc64fbsd-kern.o" ;; sparc-*-netbsd* | sparc-*-knetbsd*-gnu) # Target: NetBSD/sparc @@ -674,7 +683,9 @@ x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu) # Target: FreeBSD/amd64 gdb_target_obs="amd64-tdep.o amd64fbsd-tdep.o i386-tdep.o \ i387-tdep.o i386bsd-tdep.o i386fbsd-tdep.o \ - bsd-uthread.o fbsd-tdep.o solib-svr4.o" + bsd-uthread.o fbsd-tdep.o solib-svr4.o \ + fbsd-kld.o fbsd-kthr.o fbsd-kvm.o amd64fbsd-kern.o \ + i386fbsd-kern.o" ;; x86_64-*-mingw* | x86_64-*-cygwin*) # Target: MingW/amd64 diff --git gdb/defs.h gdb/defs.h index 9b44f44349..f176be1108 100644 --- gdb/defs.h +++ gdb/defs.h @@ -598,6 +598,7 @@ enum gdb_osabi GDB_OSABI_LINUX, GDB_OSABI_FREEBSD_AOUT, GDB_OSABI_FREEBSD_ELF, + GDB_OSABI_FREEBSD_ELF_KERNEL, GDB_OSABI_NETBSD_AOUT, GDB_OSABI_NETBSD_ELF, GDB_OSABI_OPENBSD_ELF, diff --git gdb/osabi.c gdb/osabi.c index f7d4e74239..130ffef37e 100644 --- gdb/osabi.c +++ gdb/osabi.c @@ -66,6 +66,7 @@ static const struct osabi_names gdb_osabi_names[] = { "GNU/Linux", "linux(-gnu)?" }, { "FreeBSD/a.out", NULL }, { "FreeBSD/ELF", NULL }, + { "FreeBSD/kernel", NULL }, { "NetBSD/a.out", NULL }, { "NetBSD/ELF", NULL }, { "OpenBSD/ELF", NULL }, diff --git gdb/regcache.c gdb/regcache.c index a5c90a6314..05044e5293 100644 --- gdb/regcache.c +++ gdb/regcache.c @@ -1083,6 +1083,20 @@ regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf) } } +void +regcache_raw_supply_unsigned (struct regcache *regcache, int regnum, + ULONGEST val) +{ + gdb_byte *buf; + + gdb_assert (regcache != NULL); + gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers); + buf = (gdb_byte *)alloca (regcache->descr->sizeof_register[regnum]); + store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], + gdbarch_byte_order (regcache->descr->gdbarch), val); + regcache_raw_supply (regcache, regnum, buf); +} + /* Collect register REGNUM from REGCACHE and store its contents in BUF. */ void diff --git gdb/regcache.h gdb/regcache.h index 1bb0ce0ec8..65783b6355 100644 --- gdb/regcache.h +++ gdb/regcache.h @@ -135,6 +135,8 @@ extern void regcache_write_pc (struct regcache *regcache, CORE_ADDR pc); extern void regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf); +extern void regcache_raw_supply_unsigned (struct regcache *regcache, + int regnum, ULONGEST val); extern void regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf); Index: head/devel/gdb/files/kgdb/fbsd-kld.c =================================================================== --- head/devel/gdb/files/kgdb/fbsd-kld.c (revision 440446) +++ head/devel/gdb/files/kgdb/fbsd-kld.c (revision 440447) @@ -1,588 +1,592 @@ /* * 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 #include #include "solib.h" #include #include "kgdb.h" struct lm_info { 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 (char *filename, char *path, size_t path_size) { struct kld_info *info; struct cleanup *cleanup; char *module_path; char *kernel_dir, *module_dir, *cp; int error; info = get_kld_info(); if (exec_bfd) { - kernel_dir = dirname(bfd_get_filename(exec_bfd)); + kernel_dir = ldirname(bfd_get_filename(exec_bfd)); if (kernel_dir != NULL) { + cleanup = make_cleanup(xfree, kernel_dir); snprintf(path, path_size, "%s/%s", kernel_dir, filename); - if (check_kld_path(path, path_size)) + if (check_kld_path(path, path_size)) { + do_cleanups(cleanup); return (1); + } + do_cleanups(cleanup); } } 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; 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); 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 (char *arg, CORE_ADDR *address) { struct kld_info *info; CORE_ADDR kld; char *kld_filename; - char *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 = basename(arg); + 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); 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; bfd *bfd; CORE_ADDR curr_addr; int add_flags, i; /* Open the kld. */ bfd = bfd_openr(path, gnutarget); if (bfd == NULL) error("\"%s\": can't open: %s", path, bfd_errmsg(bfd_get_error())); cleanup = make_cleanup_bfd_unref(bfd); if (!bfd_check_format(bfd, bfd_object)) error("\%s\": not an object file", path); /* Make sure we have a .text section. */ if (bfd_get_section_by_name (bfd, ".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, §ions, §ions_end)) error("\"%s\": can't find file sections", path); 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); 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)); if (from_tty && (!query("%s", ""))) error("Not confirmed."); add_flags = 0; if (from_tty) add_flags |= SYMFILE_VERBOSE; symbol_file_add(path, add_flags, sap, OBJF_USERLOADED); do_cleanups(cleanup); } static void kgdb_add_kld_cmd (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) { static CORE_ADDR curr_addr; if (sec == so->sections) curr_addr = so->lm_info->base_address; adjust_section_address(sec, &curr_addr); } static void kld_free_so (struct so_list *so) { xfree(so->lm_info); } static void kld_clear_so (struct so_list *so) { if (so->lm_info != NULL) so->lm_info->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, 1, ¤t_target, auto_solib_add); } static void kld_special_symbol_handling (void) { } static struct so_list * kld_current_sos (void) { struct so_list *head, **prev, *newobj; struct kld_info *info; CORE_ADDR kld, kernel; char *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); newobj->lm_info = XNEW (struct lm_info); newobj->lm_info->base_address = 0; /* 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, 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, 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. */ newobj->lm_info->base_address = read_pointer(kld + info->off_address); if (newobj->lm_info->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 (void *from_ttyp) { return (0); } static int kld_in_dynsym_resolve_code (CORE_ADDR pc) { return (0); } static int kld_find_and_open_solib (char *solib, unsigned o_flags, char **temp_pathname) { char path[PATH_MAX]; int fd; *temp_pathname = 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); return (fd); } void _initialize_kld_target(void); 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.special_symbol_handling = kld_special_symbol_handling; 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/kgdb.1 =================================================================== --- head/devel/gdb/files/kgdb/kgdb.1 (nonexistent) +++ head/devel/gdb/files/kgdb/kgdb.1 (revision 440447) @@ -0,0 +1,140 @@ +.\" 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$ +.\" +.Dd October 11, 2006 +.Dt KGDB 1 +.Os +.Sh NAME +.Nm kgdb +.Nd "kernel debugger" +.Sh SYNOPSIS +.Nm +.Op Fl a | Fl f | Fl fullname +.Op Fl b Ar rate +.Op Fl q | Fl quiet +.Op Fl v +.Op Fl w +.Op Fl d Ar crashdir +.Op Fl c Ar core | Fl n Ar dumpnr | Fl r Ar device +.Op Ar kernel Op Ar core +.Sh DESCRIPTION +The +.Nm +utility is a debugger based on +.Xr gdb 1 +that allows debugging of kernel core files. +.Pp +The options are as follows: +.Bl -tag -width ".Fl d Ar crashdir" +.It Fl a +Increase the annotation level. +An annotation level of 1 features the historical +.Fl fullname +option of +.Xr gdb 1 . +This is useful when running +.Nm +in Emacs. +The +.Fl f +or +.Fl fullname +options are supported for backward compatibility as well. +.It Fl b Ar rate +Set the baudrate to +.Ar rate . +.It Fl q +Suppress printing of the banner when the debugger starts. +The +.Fl quiet +form is supported for compatibility as well. +.It Fl v +Increase verbosity. +.It Fl w +Opens kmem-based targets in read-write mode. +(This is identical to what +.Fl -wcore +used to do in previous +gdb versions for +.Fx . ) +.It Fl d Ar crashdir +Use +.Ar crashdir +instead of the default, +.Pa /var/crash +to locate kernel core dump files in. +The name +.Pa vmcore. +plus the dump number will be appended to determine +the actual dump file name. +.It Fl c Ar core +Explicitly use +.Ar core +as the core dump file. +.It Fl n Ar dumpnr +Use the kernel core dump file numbered +.Ar dumpnr +for debugging. +.It Fl r Ar device +Use +.Ar device +to connect +.Nm +to for a remote debugging session. +.El +.Pp +The +.Fl c , n , +and +.Fl r +options are mutually exclusive. +.Pp +Optionally, the name of the kernel symbol file and +the name of the core dump file can be supplied on the +command-line as positional arguments. +If no kernel symbol file name has been given, the +symbol file of the currently running kernel will be +used. +If no core dump file has been specified through either +of the options or the last command-line argument, +.Pa /dev/mem +will be opened to allow debugging the currently running +kernel. +.Sh FILES +.Bl -tag -width ".Pa /var/crash" +.It Pa /dev/mem +Default memory image to open if no core dump file +has been specified. +.It Pa /var/crash +Default directory to locate kernel core dump files. +.El +.Sh SEE ALSO +.Xr gdb 1 +.Sh HISTORY +The +.Nm +utility first appeared in its current form in +.Fx 5.3 . Property changes on: head/devel/gdb/files/kgdb/kgdb.1 ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ 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/pkg-plist =================================================================== --- head/devel/gdb/pkg-plist (revision 440446) +++ head/devel/gdb/pkg-plist (revision 440447) @@ -1,58 +1,59 @@ %%GDB_LINK%%bin/gdb %%GDB_LINK%%%%KGDB%%bin/kgdb bin/gdb%%VER%% %%TUI%%bin/gdbtui%%VER%% %%KGDB%%bin/kgdb%%VER%% man/man1/gdb%%VER%%.1.gz +%%KGDB%%man/man1/kgdb%%VER%%.1.gz %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/__init__.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/FrameDecorator.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/FrameIterator.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/frames.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/printing.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/prompt.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/types.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/unwinder.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/xmethod.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/command/__init__.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/command/explore.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/command/frame_filters.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/command/pretty_printers.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/command/prompt.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/command/type_printers.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/command/unwinders.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/command/xmethods.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/function/__init__.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/function/as_string.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/function/caller_is.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/function/strfns.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/printer/__init__.py %%PYTHON%%%%DATADIR%%%%VER%%/python/gdb/printer/bound_registers.py %%GUILE%%%%DATADIR%%%%VER%%/guile/gdb.go %%GUILE%%%%DATADIR%%%%VER%%/guile/gdb.scm %%GUILE%%%%DATADIR%%%%VER%%/guile/gdb/boot.scm %%GUILE%%%%DATADIR%%%%VER%%/guile/gdb/experimental.go %%GUILE%%%%DATADIR%%%%VER%%/guile/gdb/experimental.scm %%GUILE%%%%DATADIR%%%%VER%%/guile/gdb/init.scm %%GUILE%%%%DATADIR%%%%VER%%/guile/gdb/iterator.go %%GUILE%%%%DATADIR%%%%VER%%/guile/gdb/iterator.scm %%GUILE%%%%DATADIR%%%%VER%%/guile/gdb/printing.go %%GUILE%%%%DATADIR%%%%VER%%/guile/gdb/printing.scm %%GUILE%%%%DATADIR%%%%VER%%/guile/gdb/support.go %%GUILE%%%%DATADIR%%%%VER%%/guile/gdb/support.scm %%GUILE%%%%DATADIR%%%%VER%%/guile/gdb/types.go %%GUILE%%%%DATADIR%%%%VER%%/guile/gdb/types.scm %%DATADIR%%%%VER%%/syscalls/aarch64-linux.xml %%DATADIR%%%%VER%%/syscalls/amd64-linux.xml %%DATADIR%%%%VER%%/syscalls/arm-linux.xml %%DATADIR%%%%VER%%/syscalls/freebsd.xml %%DATADIR%%%%VER%%/syscalls/gdb-syscalls.dtd %%DATADIR%%%%VER%%/syscalls/i386-linux.xml %%DATADIR%%%%VER%%/syscalls/mips-n32-linux.xml %%DATADIR%%%%VER%%/syscalls/mips-n64-linux.xml %%DATADIR%%%%VER%%/syscalls/mips-o32-linux.xml %%DATADIR%%%%VER%%/syscalls/ppc-linux.xml %%DATADIR%%%%VER%%/syscalls/ppc64-linux.xml %%DATADIR%%%%VER%%/syscalls/s390-linux.xml %%DATADIR%%%%VER%%/syscalls/s390x-linux.xml %%DATADIR%%%%VER%%/syscalls/sparc-linux.xml %%DATADIR%%%%VER%%/syscalls/sparc64-linux.xml