History log of /freebsd-11-stable/gnu/usr.bin/gdb/kgdb/
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
331323 21-Mar-2018 jhb

MFC 328158,330708: Update kgdb for PTI.

328158:
Recognize mchk_calltrap as a trapframe generator.

Should have been included in r328157.

330708:
Use the trapframe unwinder for "fast_syscall_common".

320824 09-Jul-2017 jhb

MFC 320675: Add deprecation notices for gdb and kgdb.

Even though gdb and kgdb may not be removed for 12.0 on some architectures,
the notice is unconditional as these tools will likely be removed at some
point in the future when adequate replacements are available (gdb in ports
or lldb in base).

302408 08-Jul-2016 gjb

Copy head@r302406 to stable/11 as part of the 11.0-RELEASE cycle.
Prune svn:mergeinfo from the new branch, as nothing has been merged
here.

Additional commits post-branch will follow.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation


/freebsd-11-stable/MAINTAINERS
/freebsd-11-stable/cddl
/freebsd-11-stable/cddl/contrib/opensolaris
/freebsd-11-stable/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/print
/freebsd-11-stable/cddl/contrib/opensolaris/cmd/zfs
/freebsd-11-stable/cddl/contrib/opensolaris/lib/libzfs
/freebsd-11-stable/contrib/amd
/freebsd-11-stable/contrib/apr
/freebsd-11-stable/contrib/apr-util
/freebsd-11-stable/contrib/atf
/freebsd-11-stable/contrib/binutils
/freebsd-11-stable/contrib/bmake
/freebsd-11-stable/contrib/byacc
/freebsd-11-stable/contrib/bzip2
/freebsd-11-stable/contrib/com_err
/freebsd-11-stable/contrib/compiler-rt
/freebsd-11-stable/contrib/dialog
/freebsd-11-stable/contrib/dma
/freebsd-11-stable/contrib/dtc
/freebsd-11-stable/contrib/ee
/freebsd-11-stable/contrib/elftoolchain
/freebsd-11-stable/contrib/elftoolchain/ar
/freebsd-11-stable/contrib/elftoolchain/brandelf
/freebsd-11-stable/contrib/elftoolchain/elfdump
/freebsd-11-stable/contrib/expat
/freebsd-11-stable/contrib/file
/freebsd-11-stable/contrib/gcc
/freebsd-11-stable/contrib/gcclibs/libgomp
/freebsd-11-stable/contrib/gdb
/freebsd-11-stable/contrib/gdtoa
/freebsd-11-stable/contrib/groff
/freebsd-11-stable/contrib/ipfilter
/freebsd-11-stable/contrib/ldns
/freebsd-11-stable/contrib/ldns-host
/freebsd-11-stable/contrib/less
/freebsd-11-stable/contrib/libarchive
/freebsd-11-stable/contrib/libarchive/cpio
/freebsd-11-stable/contrib/libarchive/libarchive
/freebsd-11-stable/contrib/libarchive/libarchive_fe
/freebsd-11-stable/contrib/libarchive/tar
/freebsd-11-stable/contrib/libc++
/freebsd-11-stable/contrib/libc-vis
/freebsd-11-stable/contrib/libcxxrt
/freebsd-11-stable/contrib/libexecinfo
/freebsd-11-stable/contrib/libpcap
/freebsd-11-stable/contrib/libstdc++
/freebsd-11-stable/contrib/libucl
/freebsd-11-stable/contrib/libxo
/freebsd-11-stable/contrib/llvm
/freebsd-11-stable/contrib/llvm/projects/libunwind
/freebsd-11-stable/contrib/llvm/tools/clang
/freebsd-11-stable/contrib/llvm/tools/lldb
/freebsd-11-stable/contrib/llvm/tools/llvm-dwarfdump
/freebsd-11-stable/contrib/llvm/tools/llvm-lto
/freebsd-11-stable/contrib/mdocml
/freebsd-11-stable/contrib/mtree
/freebsd-11-stable/contrib/ncurses
/freebsd-11-stable/contrib/netcat
/freebsd-11-stable/contrib/ntp
/freebsd-11-stable/contrib/nvi
/freebsd-11-stable/contrib/one-true-awk
/freebsd-11-stable/contrib/openbsm
/freebsd-11-stable/contrib/openpam
/freebsd-11-stable/contrib/openresolv
/freebsd-11-stable/contrib/pf
/freebsd-11-stable/contrib/sendmail
/freebsd-11-stable/contrib/serf
/freebsd-11-stable/contrib/sqlite3
/freebsd-11-stable/contrib/subversion
/freebsd-11-stable/contrib/tcpdump
/freebsd-11-stable/contrib/tcsh
/freebsd-11-stable/contrib/tnftp
/freebsd-11-stable/contrib/top
/freebsd-11-stable/contrib/top/install-sh
/freebsd-11-stable/contrib/tzcode/stdtime
/freebsd-11-stable/contrib/tzcode/zic
/freebsd-11-stable/contrib/tzdata
/freebsd-11-stable/contrib/unbound
/freebsd-11-stable/contrib/vis
/freebsd-11-stable/contrib/wpa
/freebsd-11-stable/contrib/xz
/freebsd-11-stable/crypto/heimdal
/freebsd-11-stable/crypto/openssh
/freebsd-11-stable/crypto/openssl
/freebsd-11-stable/gnu/lib
/freebsd-11-stable/gnu/usr.bin/binutils
/freebsd-11-stable/gnu/usr.bin/cc/cc_tools
/freebsd-11-stable/gnu/usr.bin/gdb
/freebsd-11-stable/lib/libc/locale/ascii.c
/freebsd-11-stable/sys/cddl/contrib/opensolaris
/freebsd-11-stable/sys/contrib/dev/acpica
/freebsd-11-stable/sys/contrib/ipfilter
/freebsd-11-stable/sys/contrib/libfdt
/freebsd-11-stable/sys/contrib/octeon-sdk
/freebsd-11-stable/sys/contrib/x86emu
/freebsd-11-stable/sys/contrib/xz-embedded
/freebsd-11-stable/usr.sbin/bhyve/atkbdc.h
/freebsd-11-stable/usr.sbin/bhyve/bhyvegc.c
/freebsd-11-stable/usr.sbin/bhyve/bhyvegc.h
/freebsd-11-stable/usr.sbin/bhyve/console.c
/freebsd-11-stable/usr.sbin/bhyve/console.h
/freebsd-11-stable/usr.sbin/bhyve/pci_fbuf.c
/freebsd-11-stable/usr.sbin/bhyve/pci_xhci.c
/freebsd-11-stable/usr.sbin/bhyve/pci_xhci.h
/freebsd-11-stable/usr.sbin/bhyve/ps2kbd.c
/freebsd-11-stable/usr.sbin/bhyve/ps2kbd.h
/freebsd-11-stable/usr.sbin/bhyve/ps2mouse.c
/freebsd-11-stable/usr.sbin/bhyve/ps2mouse.h
/freebsd-11-stable/usr.sbin/bhyve/rfb.c
/freebsd-11-stable/usr.sbin/bhyve/rfb.h
/freebsd-11-stable/usr.sbin/bhyve/sockstream.c
/freebsd-11-stable/usr.sbin/bhyve/sockstream.h
/freebsd-11-stable/usr.sbin/bhyve/usb_emul.c
/freebsd-11-stable/usr.sbin/bhyve/usb_emul.h
/freebsd-11-stable/usr.sbin/bhyve/usb_mouse.c
/freebsd-11-stable/usr.sbin/bhyve/vga.c
/freebsd-11-stable/usr.sbin/bhyve/vga.h
298363 20-Apr-2016 wma

Add missing function prototypes in KGDB

This fixes the build broken by r298358


298358 20-Apr-2016 wma

Fix KGDB backtrace on ARM

Modify trapframe decoding to properly analyze trapframe.

Provide method for fixup_pc. It happens, that in some kernel
functions, the GDB stack frame decoder cannot determine both
func name and frame size. This is because these functions
either contain invalid instruction, or their format does
not match standard schema. Detect that scenarios and move
PC accordingly to jump into known function schema, which
GDB is able to parse.

Obtained from: Semihalf
Sponsored by: Juniper Networks
Reviewed by: kib, zbb
Differential Revision: https://reviews.freebsd.org/D5976


295989 24-Feb-2016 bdrewery

DIRDEPS_BUILD: Regenerate without local dependencies.

These are no longer needed after the recent 'beforebuild: depend' changes
and hooking DIRDEPS_BUILD into a subset of FAST_DEPEND which supports
skipping 'make depend'.

Sponsored by: EMC / Isilon Storage Division


291738 04-Dec-2015 bdrewery

Fix LDADD/DPADD that should be LIBADD.

Sponsored by: EMC / Isilon Storage Division


291558 01-Dec-2015 bdrewery

Update dependencies after r291406 added libelf to libkvm.

Unfortunately filemon/meta mode tracks all indirect dependencies here
since ld(1) is reading libelf when linking in libkvm. Churn would be
reduced if this was able to be limited to direct dependencies.

Sponsored by: EMC / Isilon Storage Division


291525 30-Nov-2015 jhb

Fix a double-semicolon typo in my libkvm changes.

Submitted by: jmallett


291406 27-Nov-2015 jhb

Add support to libkvm for reading vmcores from other architectures.
- Add a kvaddr_type to represent kernel virtual addresses instead of
unsigned long.
- Add a struct kvm_nlist which is a stripped down version of struct nlist
that uses kvaddr_t for n_value.
- Add a kvm_native() routine that returns true if an open kvm descriptor
is for a native kernel and memory image.
- Add a kvm_open2() function similar to kvm_openfiles(). It drops the
unused 'swapfile' argument and adds a new function pointer argument for
a symbol resolving function. Native kernels still use _fdnlist() from
libc to resolve symbols if a resolver function is not supplied, but cross
kernels require a resolver.
- Add a kvm_nlist2() function similar to kvm_nlist() except that it uses
struct kvm_nlist instead of struct nlist.
- Add a kvm_read2() function similar to kvm_read() except that it uses
kvaddr_t instead of unsigned long for the kernel virtual address.
- Add a new kvm_arch switch of routines needed by a vmcore backend.
Each backend is responsible for implementing kvm_read2() for a given
vmcore format.
- Use libelf to read headers from ELF kernels and cores (except for
powerpc cores).
- Add internal helper routines for the common page offset hash table used
by the minidump backends.
- Port all of the existing kvm backends to implement a kvm_arch switch and
to be cross-friendly by using private constants instead of ones that
vary by platform (e.g. PAGE_SIZE). Static assertions are present when
a given backend is compiled natively to ensure the private constants
match the real ones.
- Enable all of the existing vmcore backends on all platforms. This means
that libkvm on any platform should be able to perform KVA translation
and read data from a vmcore of any platform.

Tested on: amd64, i386, sparc64 (marius)
Differential Revision: https://reviews.freebsd.org/D3341


290193 30-Oct-2015 zbb

Use PCB/LR from PCB rather from stack on armv7-gdb

The kernel dump does not store these values on the stack.
Use PCB structure to resolve PC and LR properly.

Submitted by: Wojciech Macek <wma@semihalf.com>
Reviewed by: jhb, kib
Obtained from: Semihalf
Sponsored by: Juniper Networks Inc.
Differential Revision: https://reviews.freebsd.org/D4013


288371 29-Sep-2015 jhb

When XSAVE support was added on amd64, the FPU save area was moved
out of 'struct pcb' and into a variable-sized region after the
structure. The kgdb code currently only reads the pcb. It does not
read in the FPU save area but instead passes stack garbage as the
FPU's saved context. Fixing this would mean determining the proper
size of the area and fetching it. However, this state is not saved
for running CPUs in stoppcbs[], so the callback would also have to
know to ignore those pcbs. Instead, just remove the call since it is
of limited usefulness. It results in kgdb reporting the state of the
FPU/SIMD registers in userland, not their current values in the kernel.
In particular, it does not report the correct state for any code in
the kernel which does use the FPU and would report incorrect values
in that case.

Reviewed by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D3743


285041 02-Jul-2015 kib

Use single instance of the identical INKERNEL() and PMC_IN_KERNEL()
macros on amd64 and i386. Move the definition to machine/param.h.
kgdb defines INKERNEL() too, the conflict is resolved by renaming kgdb
version to PINKERNEL().

On i386, correct the lowest kernel address. After the shared page was
introduced, USRSTACK no longer points to the last user address + 1 [*]

Submitted by: Oliver Pinter [*]
Sponsored by: The FreeBSD Foundation
MFC after: 1 week


284345 13-Jun-2015 sjg

Add META_MODE support.

Off by default, build behaves normally.
WITH_META_MODE we get auto objdir creation, the ability to
start build from anywhere in the tree.

Still need to add real targets under targets/ to build packages.

Differential Revision: D2796
Reviewed by: brooks imp


276190 24-Dec-2014 ian

Cleanup up ARM *frame structures...

- Eliminate unused irqframe
- Eliminate unused saframe
- Instead of splitting r4-sp storage between the stack and switchframe,
just put all the registers in switchframe and eliminate the un_32 struct.

Submitted by: Svatopluk Kraus <onwahe@gmail.com>,
Michal Meloun <meloun@miracle.cz>


275644 09-Dec-2014 dchagin

Skip calling CPU_ISSET for NOCPU as a short period of time we can have
td_oncpu is NOCPU for thread in TDS_RUNNING state.

Differential Revision: https://reviews.freebsd.org/D1283
Reviewed by: jhb
MFC after: 1 Month


275077 25-Nov-2014 bapt

Convert to LIBADD
Reduce overlinking


274391 11-Nov-2014 dim

Change kbdb's kthr::cpu field into an int, to avoid gcc warnings about
comparing it with NOCPU, which became -1 recently. While here, avoid
using it for address calculations if it is negative.

Reviewed by: jhb, adrian
MFC after: 1 week


270168 19-Aug-2014 bdrewery

Revert r267233 for now. PIE support needs to be reworked.

1. 50+% of NO_PIE use is fixed by adding -fPIC to INTERNALLIB and other
build-only utility libraries.
2. Another 40% is fixed by generating _pic.a variants of various libraries.
3. Some of the NO_PIE use is a bit absurd as it is disabling PIE (and ASLR)
where it never would work anyhow, such as csu or loader. This suggests
there may be better ways of adding support to the tree. Many of these
cases can be fixed such that -fPIE will work but there is really no
reason to have it in those cases.
4. Some of the uses are working around hacks done to some Makefiles that are
really building libraries but have been using bsd.prog.mk because the code
is cleaner. Had they been using bsd.lib.mk then NO_PIE would not have
been needed.

We likely do want to enable PIE by default (opt-out) for non-tree consumers
(such as ports). For in-tree though we probably want to only enable PIE
(opt-in) for common attack targets such as remote service daemons and setuid
utilities. This is also a great performance compromise since ASLR is expected
to reduce performance. As such it does not make sense to enable it in all
utilities such as ls(1) that have little benefit to having it enabled.

Reported by: kib


269648 06-Aug-2014 bapt

Rework privatelib/internallib

Make sure everything linking to a privatelib and/or an internallib does it directly
from the OBJDIR rather than DESTDIR.
Add src.libnames.mk so bsd.libnames.mk is not polluted by libraries not existsing
in final installation
Introduce the LD* variable which is what ld(1) is expecting (via LDADD) to link to
internal/privatelib
Directly link to the .so in case of private library to avoid having to complexify
LDFLAGS.

Phabric: https://phabric.freebsd.org/D553
Reviewed by: imp, emaste


268804 17-Jul-2014 brooks

Replace all uses of libncurses and libtermcap with their wide character
variants. This allows usable file system images (i.e. those with both a
shell and an editor) to be created with only one copy of the curses library.

Exp-run: antoine
PR: 189842
Discussed with: bapt
Sponsored by: DARPA, AFRL


268461 09-Jul-2014 bapt

The GNU readline library is now an INTERNALLIB - that is, it is
statically linked into consumers (GDB and variants) in the base
system, and the shared library is no longer installed.

That also allows ports to be able to use a modern version of readline

PR: 162948
Reviewed by: emaste


268351 07-Jul-2014 marcel

Remove ia64.

This includes:
o All directories named *ia64*
o All files named *ia64*
o All ia64-specific code guarded by __ia64__
o All ia64-specific makefile logic
o Mention of ia64 in comments and documentation

This excludes:
o Everything under contrib/
o Everything under crypto/
o sys/xen/interface
o sys/sys/elf_common.h

Discussed at: BSDcan


267233 08-Jun-2014 bdrewery

In preparation for ASLR [1] support add WITH_PIE to support building with -fPIE.

This is currently an opt-in build flag. Once ASLR support is ready and stable
it should changed to opt-out and be enabled by default along with ASLR.

Each application Makefile uses opt-out to ensure that ASLR will be enabled by
default in new directories when the system is compiled with PIE/ASLR. [2]

Mark known build failures as NO_PIE for now.

The only known runtime failure was rtld.

[1] http://www.bsdcan.org/2014/schedule/events/452.en.html
Submitted by: Shawn Webb <lattera@gmail.com>
Discussed between: des@ and Shawn Webb [2]


261788 12-Feb-2014 jmg

add support for building a cross-gdb for ARM... This isn't hooked up
to xdev yet as I don't know how to make it work properly... It also
isn't heavily tested...

Reviewed by: silence on -arm


260601 13-Jan-2014 marcel

When building a cross-kgdb, suppress the registration of the
standard core target by declaring coreops_suppress_target with
initializer. This is also happening for non-cross kgdb, by
virtue of having fbsd-threads.c in libgdb and having it do the
exact same thing. Since fbsd-threads.c is not included in in
libgdb when building a cross debugger, we ended up with more
than 1 core file targets (the standard gdb core file target and
kgdb's libkvm based core file target) and this behaves the same
as not having a core target at all.


260027 28-Dec-2013 marcel

When building a cross kgdb, link against the appropriate cross libkvm.
Provide an implementation of ps_pglobal_lookup() for use by the cross
libkvm.


249878 25-Apr-2013 imp

Fix mips64 and mipsn32 bilds by using proper register names.


248838 28-Mar-2013 will

KGDB: Accept KLD symbol files with the ".symbols" extension.

Submitted by: gibbs
Approved by: ken (mentor)
Sponsored by: Spectra Logic
MFC after: 1 month


248836 28-Mar-2013 will

KGDB: Allow modules to be loaded from the specified kernel's directory.

When looking up the absolute path for a kld, call find_kld_path() first.
This enables locating the module in a different directory than the one
stored in kernel memory.

With this change, kgdb can now be run on a kernel & vmcore whose associated
modules are located in the same directory as the kernel. This makes
independent triaging of problems much easier.

This change also does not break the normal kgdb use case where no arguments
are specified; in that case kgdb loads the running kernel and its modules.

Reviewed by: adrian
Approved by: ken (mentor)
Sponsored by: Spectra Logic
MFC after: 1 month


246958 19-Feb-2013 adrian

kgdb enhancements!

* document the kgdb -b flag
* better verify what's valid with -b
* add more comprehensive command line help

PR: kern/175743
Submitted by: Christoph Mallon <christoph.mallon@gmx.de>


246893 17-Feb-2013 marcel

In kthr.c, obtain the address of the PCB for threads that were running
on a core, when the core was stopped, by calling kgdb_trgt_core_pcb().
This has 2 advantages:
1. We don't need to include a machine-specific header anymore and as
such kthr.c is truly machine independent. This allows the code to
be used in a cross-debugger.
2. We don't need to lookup stoppcbs in generic code when it's an
inherently target-spicific symbol. It does not exist for ia64.

Implement kgdb_trgt_core_pcb() for all architectures, except ia64, by
calling a common function called kgdb_trgt_stop_pcb(). This function
differs from kgdb_trgt_core_pcb() in that it gets the size of the PCB
structure as an argument and as such remains machine independent.

On ia64 the PCB for stopped cores is in the PCPU structure itself.
This for better scaling. The implementation of kgdb_trgt_core_pcb()
for ia64 uses the cpuid_to_pcpu[] array to to obtain the address of
the PCB structure.


245705 21-Jan-2013 adrian

Add command-line support to kgdb to allow the baudrate to be set.

This allows a remote session to be specified with '-r' as well as a
non-default baudrate setting using '-b'.

TODO: add to the kgdb manpage.

MFC after: 2 weeks


234739 27-Apr-2012 marcel

Allow building a powerpc cross-kgdb.


230427 21-Jan-2012 kib

Adopt to new layout of struct pcb.

MFC after: 1 month


229521 04-Jan-2012 rwatson

Add missing -w to kgdb(1)'s usage().

Sponsored by: Adara Networks, Inc.
MFC after: 3 days


225017 19-Aug-2011 jhb

Walk the zombproc list as well as the allproc list when enumerating threads
and processes in a kernel image. This allows examination of threads that
have exited or are in the late stages of exiting.

Tested by: avg
Approved by: re (kib)
MFC after: 1 week


222813 07-Jun-2011 attilio

etire the cpumask_t type and replace it with cpuset_t usage.

This is intended to fix the bug where cpu mask objects are
capped to 32. MAXCPU, then, can now arbitrarely bumped to whatever
value. Anyway, as long as several structures in the kernel are
statically allocated and sized as MAXCPU, it is suggested to keep it
as low as possible for the time being.

Technical notes on this commit itself:
- More functions to handle with cpuset_t objects are introduced.
The most notable are cpusetobj_ffs() (which calculates a ffs(3)
for a cpuset_t object), cpusetobj_strprint() (which prepares a string
representing a cpuset_t object) and cpusetobj_strscan() (which
creates a valid cpuset_t starting from a string representation).
- pc_cpumask and pc_other_cpus are target to be removed soon.
With the moving from cpumask_t to cpuset_t they are now inefficient
and not really useful. Anyway, for the time being, please note that
access to pcpu datas is protected by sched_pin() in order to avoid
migrating the CPU while reading more than one (possible) word
- Please note that size of cpuset_t objects may differ between kernel
and userland. While this is not directly related to the patch itself,
it is good to understand that concept and possibly use the patch
as a reference on how to deal with cpuset_t objects in userland, when
accessing kernland members.
- KTR_CPUMASK is changed and now is represented through a string, to be
set as the example reported in NOTES.

Please additively note that no MAXCPU is bumped in this patch, but
private testing has been done until to MAXCPU=128 on a real 8x8x2(htt)
machine (amd64).

Please note that the FreeBSD version is not yet bumped because of
the upcoming pcpu changes. However, note that this patch is not
targeted for MFC.

People to thank for the time spent on this patch:
- sbruno, pluknet and Nicholas Esborn (nick AT desert DOT net) tested
several revision of the patches and really helped in improving
stability of this work.
- marius fixed several bugs in the sparc64 implementation and reviewed
patches related to ktr.
- jeff and jhb discussed the basic approach followed.
- kib and marcel made targeted review on some specific part of the
patch.
- marius, art, nwhitehorn and andreast reviewed MD specific part of
the patch.
- marius, andreast, gonzo, nwhitehorn and jceel tested MD specific
implementations of the patch.
- Other people have made contributions on other patches that have been
already committed and have been listed separately.

Companies that should be mentioned for having participated at several
degrees:
- Yahoo! for having offered the machines used for testing on big
count of CPUs.
- The FreeBSD Foundation for having sponsored my devsummit attendance,
which has been instrumental.
- Sandvine for having offered offices and infrastructure during
development.

(I really hope I didn't forget anyone, if it happened I apologize in
advance).


217749 23-Jan-2011 emaste

Use string literal format strings to quiet clang warnings.


215082 10-Nov-2010 imp

Complete the integration of tbemd branch into head.

TARGET_BIG_ENDIAN is now completely dead, except where it was
originally supposed to be used (internally in the toolchain building).

TARGET_ARCH has changed in three cases:
(1) Little endian mips has changed to mipsel.
(2) Big endian mips has changed to mipseb.
(3) Big endian arm has changed to armeb.

Some additional changes are needed to make 'make universe' work on arm
and mips after this change, so those are commented out for now.

UPDATING information will be forthcoming. Any remaining rough edges
will be hammered out in -current.


214962 07-Nov-2010 gonzo

Fix cross-debugger build


214952 07-Nov-2010 gonzo

- Use proper constant for accessing PCB intead of hardcoded numbers
- Minor clean-up


213013 22-Sep-2010 emaste

Move test for zero bufp or size before rseq and wseq calculation. This
avoids spinning in an infinite loop for some (possibly corrupt?) core
files at work.


210852 04-Aug-2010 jhb

Change kgdb_lookup() to resolve symbols via GDB instead of via libkvm(3).


210778 02-Aug-2010 jkim

Give kgdb(1) a chance to take a look at FPU state.


210424 23-Jul-2010 avg

kgdb: correctly map sections to addresses in elf object modules (amd64)

Unlike for modules with dso type, in elf object modules all the sections
have virtual address of zero. So, it is insufficient to add module base
address to section virtual address (as recorded in section header) to
get section address in kernel memory.
Instead, we should apply the same calculations that are performed by
kernel loaders (in boot code and in kernel) when they lay out sections
in memory.

Discussed with: jhb, np
MFC after: 3 weeks


209867 10-Jul-2010 nwhitehorn

Teach our toolchain how to generate 64-bit PowerPC binaries. This fixes
a variety of bugs in binutils related to handling of 64-bit PPC ELF,
provides a GCC configuration for 64-bit PowerPC on FreeBSD, and
associated build systems tweaks.

Obtained from: projects/ppc64


206622 14-Apr-2010 uqs

mdoc: order prologue macros consistently by Dd/Dt/Os

Although groff_mdoc(7) gives another impression, this is the ordering
most widely used and also required by mdocml/mandoc.

Reviewed by: ru
Approved by: philip, ed (mentors)


205711 26-Mar-2010 marcel

Allow building a cross-kgdb for ia64.


204138 20-Feb-2010 rrs

These contain JC's patch to get gdb sort of working
on mips. Its not fully done yet but its a start.

Obtained from: JC - c.jayachandran@gmail.com

M gnu/usr.bin/gdb/kgdb/trgt_mips.c
M gnu/usr.bin/gdb/arch/mips/init.c
M gnu/usr.bin/gdb/arch/mips/Makefile
M gnu/usr.bin/Makefile
M contrib/gdb/gdb/mips-tdep.h


203823 13-Feb-2010 avg

kgdb: initialize n_type field of nlist entry for kvm_nlist call

kvm_nlist skips lookup for entries that have n_type != N_UNDF.
N_UNDF happens to be zero, so n_type typically has a correct
value by accident, but not always.
Note: jhb has a patch that replaces kvm_nlist use with direct
gdb parsing.

MFC after: 5 days
X-MFC-Note: unless jhb commits kvm_nlist => kgdb_parse change


183556 02-Oct-2008 jhb

Oops, initialize sections and sections_end to NULL.

Submitted by: Navdeep Parhar
MFC after: 1 week


183414 27-Sep-2008 kib

Differentiate between interrupt frames, trap interrupt frames and timer
frame in the kgdb, to allow it to properly backtrace over the interrupt
stacks.

Noted and reviewed by: tegge
Tested by: pho
MFC after: 1 week


183359 25-Sep-2008 jhb

Use existing GDB routines for parsing the section table of klds in
the 'add-kld' command instead of doing it more by hand.

MFC after: 1 week


179859 18-Jun-2008 jhb

Catch up to recentish kgdb changes:
- Use ptid_get_pid() rather than ptid_get_tid() (part of the changes to
let 'tid' work for remote kgdb).
- Add a stub kgdb_trgt_new_objfile() hook.

Silence from: obrien, mips@


179162 20-May-2008 obrien

Add Juniper's copyright.


179161 20-May-2008 obrien

MIPS arch target kgdb(1) support.

Obtained from: Juniper Networks.


178880 09-May-2008 jhb

Trim unneeded header.


178713 01-May-2008 jhb

- Change how the vmcore target maps FreeBSD thread IDs to GDB ptids. We
now only use the TID and ignore the PID and use pid_to_ptid() to build a
ptid treating the TID as a PID. The benefit of this is that the vmcore
target now uses the same scheme as GDB's remote targets. As a result,
the 'tid' command now works for remote targets (however, it only accepts
TIDs and not addresses of 'struct thread' objects).
- Use gdb_thread_select() to do the actual thread switch for the 'tid' and
'proc' commands. This now gives the same UI feedback when switching
threads as the GDB 'thread' command rather than providing no visual
output at all.

MFC after: 1 week


178670 29-Apr-2008 jhb

Rework how kgdb manages kernel and vmcore files to be a bit more gdb-ish
so that kgdb can be used more like a normal gdb:
- Load the kernel via the standard 'exec' target and allow it to be changed
via the 'file' command.
- Instead of explicitly loading the kernel file as the mail symbol file
during startup, just pass it to gdb_main() as the executable file.
- Change the kld support (via shared libraries) to cache the address of
the linker_files and linker_kernel_file variables in addition to the
offsets of various members in 'struct linker_file'.
- When a new symbol file is loaded, recompute the addresses and offsets
used by the kld support code.
- When a new symbol file is loaded, recalculate the ofs_fix variable to
account for the different ways a trapframe can be passed to trap
frame handlers in i386. This is done by adding a MD
kgdb_trgt_new_objfile() hook that is empty on all but i386.
- Don't use the directory name of the kernel specified on the command
line to find kernel modules in the kld support code. Instead,
extract the filename of the current executable via exec_bfd. Now
the 'kernel' variable is private to main.c again.
- Make the 'add-kld' command explicitly fail if no executable is loaded.
- Make the support for vmcores a real core-dump target that opens the
kernel and vmcore on open and closes the kvm connection when closed, etc.
- The 'core' command can now be used to select a vmcore to use, either
a crash dump file or /dev/mem for live debugging.
- The 'detach' command can be used to detach from a vmcore w/o attaching
to a new one.
- kgdb no longer explicitly opens a core dump during startup and no longer
has to use an atexit() hook to close the kvm connection on shutdown.
- Symbols for kld's are automatically loaded anytime a core is opened.
Also, the unread portion of dmesg is dumped just as it was done on kgdb
startup previously.
- Don't require either a remote target or core dump if a kernel is specified.
You can now just run 'kgdb kernel' similar to running gdb on an executable
and later connect to a remote target or core dump.
- Use a more relaxed way to verify remote targets specified via -r.
Instead of explicitly allowing a few non-file target specifications,
just assume that if stat() on the arg and on "/dev/" + arg both fail
that is some non-file target and pass it to gdb.
- Don't use a custom interpreter. The existing kgdb_init() hook and the
target_new_objfile() hook give us sufficient hooks during startup to
setup kgdb-specific behavior now.
- Always add the 'proc', 'tid', and 'add-kld' commands on startup and not
just if we have a core dump. Currently the 'proc' and 'tid' commands do
not work for remote targets (I will fix at least 'tid' in the next round
of changes though). However, the 'add-kld' command works fine for
loading symbols for a kernel module on a remote target.
- Always setup the 'kld' shared library target operations instead of just
if we have a core dump. Although symbols for kernel modules are not
automatically loaded when connecting to a remote target, you can do
'info sharedlibrary' after connecting to the remote target and kgdb will
find all the modules. You can then use the 'sharedlibrary' command to
load symbols from the module files.
- Change kthr_init() to free the existing list of kthr objects before
generating a new one. This allows it to be invoked multiple times
w/o leaking memory.

MFC after: 1 week


178638 28-Apr-2008 jhb

Use kgdb_parse() instead of libkvm(3) to read the first instruction from
"calltrap" to see which method is used to pass trap frames. This seg
faulted on remote gdb connections (where libkvm isn't used).

MFC after: 3 days


178634 28-Apr-2008 jhb

Remove the 'add_kld_command' arg from load_kld(). It is always true since
the auto-loading of kld's switched to hooking into gdb's shared library
support.

MFC after: 1 week


177715 29-Mar-2008 jhb

Change kgdb_parse() to use wrapped versions of parse_expression() and
evaluate_expression() so that any errors are caught and cause the function
to return to 0. Otherwise the errors posted an exception (via longjmp())
that aborted the current operation. This fixes the kld handling for
older kernels (6.x and 7.x) that don't have the full pathname stored in
the kernel linker.

MFC after: 3 days


177701 29-Mar-2008 jhb

Initialize the head pointer in kld_current_sos() to NULL to avoid returning
a junk pointer and possibly causing a seg fault if we don't have any
non-kernel klds (or are unable to walk the list due to core / kernel
mismatch).

MFC after: 1 week


176568 25-Feb-2008 jhb

Remove a stale prototype I missed when converting the kld support over to
hooking into gdb's shared library infrastructure.


175809 29-Jan-2008 jhb

- Rework the kld support to hook into GDB's shared library support.
kgdb(8) now treats kld's as shared libraries relative to the kernel
"binary". Thus, you can use 'info sharedlibrary' to list the kld's
along with 'sharedlibrary' and 'nosharedlibrary' to manage symbol
loading and unloading. Note that there isn't an easy way to force GDB
to use a specific path for a shared library. However, you can use
'nosharedlibrary' to unload all the klds and then use 'sharedlibrary'
to load specific klds where it gets the kld correct and use
'add-kld' for the kld's where the default open behavior doesn't work.
klds opened via 'sharedlibrary' (and during startup) do have their
sections listed in 'info files'.
- Change the 'add-kld' command to use filename completion to complete its
argument.


175808 29-Jan-2008 jhb

Don't close the kernel bfd object during startup. Instead, leave it open
and build a section table from the kernel file so that 'info files' output
for kgdb now matches the usage of gdb on a regular file with the exception
that we don't list sections for memory in the crash dump.


175807 29-Jan-2008 jhb

Use target_read_memory() and extract_unsigned_integer() instead of direct
KVM access to read kernel pointers.


175806 29-Jan-2008 jhb

Don't look for "foo.ko.symbols" files. GDB is smart enough to open the
".symbols" file automatically when you tell it to load "foo.ko" because of
the debug link.


175775 28-Jan-2008 jhb

Use a for loop in find_kld_address() as in kgdb_auto_load_klds() and
replace the remaining goto's with continues as a result.


175774 28-Jan-2008 jhb

Add support for automatically loading symbols for kld's on startup:
- Add a new 'kgdb_auto_load_klds()' routine which is invoked during
startup that walks the list of linker files and tries to find a matching
kld on disk for each non-kernel kld. If a kld file is found, then it
is added as if the 'add-kld' command is invoked. One change from
'add-kld' is that this method attempts to use the 'pathname' from the
linker_file structure first to try to load the file. If that fails
it then looks in the kernel directory followed by the directories in
the module path.
- Move the kld file suffix handling into a separate routine so that it
can be called standalone and to reduce duplicate code in find_kld_path().
- Cache the offsets of members of 'struct linker_file' during startup
instead of computing them for each 'add-kld'.
- Use GDB's target_read_string() instead of direct KVM access.
- Add all resident sections from a kld by using bfd_map_over_sections() to
build the section list rather than just adding symbols for ".text",
".data", ".bss", and ".rodata".
- Change the 'add-kld' command to do a y/n prompt before adding the
symbols when run interactively to match 'add-symbol-file'.

MFC after: 1 week


175771 28-Jan-2008 jhb

Remove the warnx() from kgdb_lookup() so that we don't emit a warning about
optional symbols that are missing (e.g. kgdb complains about _stoppcbs and
_stopped_cpus on UP kernels). Instead, callers that really want their
symbols to be present now do explicitly warnx() about the missing symbol.


175770 28-Jan-2008 jhb

If the quiet flag is specified (-q), don't dump the unread portion of
the message buffer on startup.


175645 24-Jan-2008 jhb

Move the code for working with kld's out into its own file.


175452 18-Jan-2008 emaste

Include the thread name (in addition to the proc name) in "info threads."


175416 17-Jan-2008 jhb

Add a new 'add-kld <kld>' command to kgdb to make it easier to analyze
crash dumps with kernel modules. The command is basically a wrapper
around add-symbol-file except that it uses the kernel linker data
structures and the ELF section headers of the kld to calculate the
section addresses add-symbol-file needs.

The 'kld' parameter may either be an absolute path or a relative path.
kgdb looks for the kld in several locations checking for variants with
".symbols" or ".debug" suffixes in each location. The first location it
tries is just opening the specified path (this handles absolute paths and
looks for the kld relative to the current directory otherwise). Next
it tries to find the module in the same directory of the kernel image
being used. If that fails it extracts the kern.module_path from the
kernel being debugged and looks in each of those paths.

The upshot is that for the common cases of debugging /boot/kernel/kernel
where the module is in either /boot/kernel or /boot/modules one can merely
do 'add-kld foo.ko'.

MFC after: 1 week


173681 16-Nov-2007 jhb

Teach kgdb how to handle double fault frames on i386:
- Save td_oncpu in 'struct kthr' so the i386 target code can see which CPU
a thread is running on.
- Add a new frame unwinder for double fault frames. This unwinder is used
when "dblfault_handler" is encountered in the stack. It uses the CPU of
the current thread to lookup the base address of the TSS used for the
double fault from the GDT. It then fetches the various registers out
of the TSS similar to how the current trapframe unwinder fetches
registers out of the trapframe.

MFC after: 3 days


171924 22-Aug-2007 jhb

NMIs now come from 'nmi_calltrap' rather than 'calltrap', so teach 'kgdb'
to treat the frame under 'nmi_calltrap' as a trapframe.

MFC after: 3 days
Approved by: re (bmah)


169714 19-May-2007 kan

Remove extern int verbose declaration. It is declared static in the
only file it is used in.


167143 01-Mar-2007 kib

Unbreak the kgdb stepping over the special frames on i386 after rev. 1.117 of
i386/i386/exception.s.

No objections from: marcel


167142 01-Mar-2007 kib

Rename lookup() to kgdb_lookup() and make it global (for use in trgt_i386.c).

No objections from: marcel


166214 25-Jan-2007 rodrigc

Try to avoid a possible infinite loop when parsing an invalid kernel dump file.

PR: 108229
Submitted by: Jessica Han <jessicah juniper net>
Reviewed by: marcel
MFC after: 1 week


163583 21-Oct-2006 ru

Bump document date for the previous change.


163440 16-Oct-2006 jhb

Trim trailing whitespace.


163439 16-Oct-2006 jhb

Restore the 'proc' and 'tid' commands which allow one to switch to the
first thread in a process or to a specific thread via PIDs and TIDs,
respectively.

Submitted by: kan
Approved by: marcel


163245 11-Oct-2006 obrien

Document '-w' from main.c rev. 1.11.


162303 14-Sep-2006 imp

Add cross debug support to arm.

Submitted by: cognet@


161621 25-Aug-2006 jhb

Use the pcb in stoppcbs[] if it is present for threads that were running
on other CPUs in system when a dump is written.

Submitted by: ups
Reviewed by: marcel
MFC after: 3 days


161589 24-Aug-2006 marcel

Add initial support for kgdb(1) on PowerPC.


161555 23-Aug-2006 jhb

Remove special handling for PC == 0. With this, kgdb can now properly
unwind across a page fault due to a null function pointer. It does a
better job than ddb now in fact.

Reviewed by: marcel
MFC after: 3 days


161548 23-Aug-2006 ru

Remove alpha-specific stuff.

Approved by: marcel


160581 22-Jul-2006 obrien

Add initial platform support.

Submitted by: cognet


154043 04-Jan-2006 kan

Add -w parameter which tells kgdb to open kmem-based targets in read-write
mode. This allows one to use kgdb on /dev/mem and be able to patch memory
on a live system. This is identical to what -wcore used to do in previous
gdb versions for FreeBSD.

Requested by: wpaul


151683 26-Oct-2005 marcel

Fix dump of the unread portion of the kernel message buffer.

PR: bin/87964
Submitted by: Frank Mayhar frank at exit dot com


150668 28-Sep-2005 peter

Unbreak - remove leftover reference to pcb_rflags.


149977 11-Sep-2005 marcel

Claim frames corresponding to tl(0|1)_intr and tl0_trap as well. I
think that's the lot, but it's hard to understand the exception code
by mere glancing at it.

MFC after: 1 week


149976 11-Sep-2005 marcel

Unwind across intrframes as well. While here, better handle bottom of
stack by claiming the frame when the IP is 0. It's a bit of a kluge,
but avoids screens full of bogus frames.

MFC after: 1 week


149975 11-Sep-2005 marcel

Unwind across intrframes as well.

MFC after: 1 week


149967 11-Sep-2005 marcel

Unwind across trap frames. Handles all entry points, except the EPC
syscall. This is an entry from userland anyway.

MFC after: 1 week


149965 10-Sep-2005 marcel

Unwind across trapframes. All kernel entries are handled.

MFC after: 1 week


149961 10-Sep-2005 marcel

Unwind across trap frames. This adds most of the meat. The sniffer
just needs to be taught about all the other entry points and the
unwinder needs to be taught about the frame variation between them.

MFC after: 1 week


149957 10-Sep-2005 marcel

Unwind across trap frames. This adds most of the meat. The sniffer
just needs to be taught about all the other entry points and the
unwinder needs to be taught about the frame variation between them.

MFC after: 1 week


149955 10-Sep-2005 marcel

Unwind across trap frames. This adds most of the meat. The sniffer
just needs to be taught about all the other entry points and the
unwinder needs to be taught about the frame variation between them.

MFC after: 1 week


149954 10-Sep-2005 marcel

Add a kluge to allow kgdb(1) to inject its own frame sniffer in the
list of frame sniffers so that trapframes can be detected. The kluge
is needed because this version of gdb only supports appending a
sniffer to the list of sniffers and the moment kgdb gets a chance to
add its own frame sniffer, the target's default frame sniffer is
already in the list. Since the default frame sniffer claims any
frame thrown at it, kgdb's frame sniffer never gets to smell (a
process much akin to tasting, but with lesser chance of hurling :-)

This commit adds dummy frame sniffers that never claim a frame and
as such don't fix anything yet. However, we now have frame sniffers
and they are being called, so it's just a matter of adding meat to
the bones and we'll be able to properly unwind across trapframes.

MFC after: 1 week


149119 16-Aug-2005 marcel

Fix backtraces. Supply registers from the register window.

MFC after: 3 days


148802 06-Aug-2005 marcel

o Remove the obscure tid command, because it does what the thread
command does, but worse.
o Remove the obscure proc command, because it does what the thread
command does, but not unambigously.
o Move the PID to the extra thread info, where it makes sense and
where it doesn't confuse users. The extra thread info holds some
process information, to which the PID belongs.
o Implement the to_find_new_threads target method by having it call
the target beneath us if we're not using KVM. This makes sure that
new threads are found when using the remote target.

o Fix various core dump scenarios:
- Implement the to_files_info target method. Previously the
'info target' command would cause a NULL pointer dereference.
- Don't assume there's a current thread. We're not initialized
in all cases. This prevents a NULL pointer dereference.
- When we're not ussing KVM, have the to_xfer_memory target
method call the target beneath us. This avoids calling into
KVM with a NULL pointer.

MFC after: 1 week


148801 06-Aug-2005 marcel

o As mentioned in the previous commit: make the KVM error buffer
static.
o Register a function with atexit(3) to close the KVM object if
we have one open.
o Show the unread portion of the kernel's message buffer before
presenting the prompt. It's bound to provide some useful info.
o Don't call kgdb_target() twice. It results in having all threads
listed twice.

MFC after: 1 week


148485 28-Jul-2005 keramida

Spell "currently" correctly.


147570 24-Jun-2005 peter

kvm_openfiles() uses the supplied buffer for storing error messages
in future calls, so we can't free it here. The right place to free the
buffer would be to be after kvm_close(), but we don't do that yet. A
static buffer would work too.

Reviewed by: marcel (who has other plans for this anyway)
Approved by: re


143046 02-Mar-2005 marcel

Implement and document the -q and -f options with their corresponding
long form (-quiet and -fullname resp.) Bump documentation date.

PR: bin/78031
MFC after: 5 days


142954 01-Mar-2005 obrien

.It the -v option.


142154 20-Feb-2005 kan

Restore r1.2 change to use TARGET_ARCH.

Submitted by: kris


142151 20-Feb-2005 kan

Attempt to make kgdb little more useful and easy to use. Properly initialize
it to recognise what ABI to use on amd64 (and possibly others) platform.
Display PID and process name as a part of the 'info threads' output, TIDs
alone are too confusing. Introduce new commmands 'tid <tid>' and 'proc <pid>'
to accompany gdb's default 'thread <thread num>' to make the task of switching
between different contexts easier.


141911 14-Feb-2005 obrien

Use the system gnuregex library vs. building GNU regex bits into libiberty
and using them.

Reviewed by: marcel,imp
Desired by: ache


140175 13-Jan-2005 ru

Markup nits.


138215 30-Nov-2004 marcel

Makefile (only) changes to allow building a cross debugger.


138213 30-Nov-2004 marcel

s/MACHINE_ARCH/TARGET_ARCH/. We use TARGET_ARCH to pick the MD files
for libgdb and should do so here as well.


137993 22-Nov-2004 joerg

[Sorry, forgot to commit my source changes in my previous commit.]
Document all options and general usage.

Implement the -a option to bump the annotation_level. This improves
the Emacs gud behaviour. You can now supply the following function

(defun gud-gdb-massage-args (file args) (cons "-a" args))

(e.g. by evaluating it from the *scratch* buffer) and get the normal
jump to the source window when browsing the stack.

We should probably eventually supply our own kgdb submode to gud.el.


137992 22-Nov-2004 joerg

Document all options and general usage.

Implement the -a option to bump the annotation_level. This improves
the Emacs gud behaviour. You can now supply the following function

(defun gud-gdb-massage-args (file args) (cons "-a" args))

(e.g. by evaluating it from the *scratch* buffer) and get the normal
jump to the source window when browsing the stack.

We should probably eventually supply our own kgdb submode to gud.el.


137990 22-Nov-2004 joerg

Fix the abuse of Ar macros for designating flag options, use Fl instead.


134686 03-Sep-2004 brooks

If the argument to the -r flag starts with a ':' or a '|', don't try to
make sure it is a device. GDB special cases these prefixes and treats
:#### as a tcp port on localhost and executes what ever follows '|'.

This allows kgdb to debug via dconschat.

Discussed with: marcel


133739 15-Aug-2004 marcel

Improve the usage. Without any arguments, kgdb(1) works on /dev/mem
with the currently running kernel image. Otherwise, one of -c, -n or
-r is expected for working on a particular core file (-c), working
on a saved dump (-n) or working remotely (-r). When working on a
saved dump, a kernel may be omitted.
For a remote debugging session (-r), kgdb(1) will use the specified
device.


132624 25-Jul-2004 marcel

Add the beginnings of kernel debugging support. the kgdb(1) tool
is basicly a shell on top of libgdb that knows about kernel threads,
kernel modules and kvm(3). As the word "beginnings" implies, not
all of the features have been implemented yet. The tool is useful
and I'd like feedback on the taken route.

The simplest way to debug a kernel core file is:
kgdb -n 0

This opens /var/crash/vmcore.0 with the corresponding kernel in
the object directory (kernel.debug is used if it exists).

Typical things that need to be added are:
o Auto loading of kernel modules,
o Handling of trapframes so that backtraces can be taken across
them,
o Some fancy commands to extract useful information out of a core
file,
o Various (probably many) other things.