Commit Graph

329 Commits

Author SHA1 Message Date
Pedro F. Giffuni
8c6a0d07a6 Revert r298938: Change x/a to work similar to gdb.
This badly breaks x/ia: ddb and gdb syntax are quite different and it is
unclear if they can be reconciled.
2016-05-06 20:28:28 +00:00
Pedro F. Giffuni
dd40d6d5e0 Enhance the ddb examine (x) command.
* Change x/a to work similar to gdb.  The content of the memory is
  treated as an address, printed symbolically and the address is advanced.
  This way you can x/a <stack_address> and then just hit return a bunch
  of times to locate useful data on the stack.

* Add x/p.  The content of the memory is treated as an address and
  printed as hex.

This is based on the similar commit from DragonFlyBSD without the
cosmetic changes.

Relnotes:	yes
Obtained from:	DragonflyBSD (Matthew Dillon)
Reference:	0624d20e86affcd708609cbf9014207537537a72
2016-05-02 19:32:06 +00:00
Pedro F. Giffuni
4ed3c0e713 sys: Make use of our rounddown() macro when sys/param.h is available.
No functional change.
2016-04-30 14:41:18 +00:00
Pedro F. Giffuni
ad29e12e0c sys/ddb: spelling fixes in comments.
No functional change.
2016-04-29 20:53:39 +00:00
Pedro F. Giffuni
fc891c1907 ddb: Make use of our roundup() macro when available. 2016-04-26 01:52:35 +00:00
Pedro F. Giffuni
63b6b7a74a Indentation issues.
Contract some lines leftover from r298310.

Mea culpa.
2016-04-20 16:19:44 +00:00
Pedro F. Giffuni
02abd40029 kernel: use our nitems() macro when it is available through param.h.
No functional change, only trivial cases are done in this sweep,

Discussed in:	freebsd-current
2016-04-19 23:48:27 +00:00
Pedro F. Giffuni
9f915a92c7 ddb: for pointers replace 0 with NULL.
Mostly cosmetical, no functional change.

Found with devel/coccinelle.
2016-04-15 17:27:20 +00:00
Konstantin Belousov
16952e289f Avoid NULL pointer dereference, for a process which is not (yet) a
member of a process group, e.g. during the system bootstrap.

Submitted by:	Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
MFC after:	1 week
2016-04-15 09:13:01 +00:00
Conrad Meyer
c975a5d359 Add td_swinvoltick to track last involuntary context switch
Expose in DDB via "show thread."

Reviewed by:	markj
Sponsored by:	EMC / Isilon Storage Division
2016-03-25 19:35:29 +00:00
Zbigniew Bodek
cdf23c193a Add helper to catch single step debug event and distinguish it from bkpt
Some architectures (including ARMv6/v7) do not have separate single step
events and cannot see difference between breakpoint and single step.
Add db_pc_is_singlestep() to avoid skipping instruction we stepped on
to trigger debug event.
This commit does not change the existing functionality but adds possibility
to implement custom db_pc_is_singlestep().

Reviewed by:   imp
Submitted by:  Zbigniew Bodek <zbb@semihalf.com>
Obtained from: Semihalf
Sponsored by:  Juniper Networks Inc.
Differential Revision: https://reviews.freebsd.org/D4036
2015-11-27 19:03:59 +00:00
Konstantin Belousov
edc8222303 Make kstack_pages a tunable on arm, x86, and powepc. On i386, the
initial thread stack is not adjusted by the tunable, the stack is
allocated too early to get access to the kernel environment. See
TD0_KSTACK_PAGES for the thread0 stack sizing on i386.

The tunable was tested on x86 only.  From the visual inspection, it
seems that it might work on arm and powerpc.  The arm
USPACE_SVC_STACK_TOP and powerpc USPACE macros seems to be already
incorrect for the threads with non-default kstack size.  I only
changed the macros to use variable instead of constant, since I cannot
test.

On arm64, mips and sparc64, some static data structures are sized by
KSTACK_PAGES, so the tunable is disabled.

Sponsored by:	The FreeBSD Foundation
MFC after:	2 week
2015-08-10 17:18:21 +00:00
John Baldwin
9a2d6ab990 Various changes to the registers displayed in DDB for x86.
- Fix segment registers to only display the low 16 bits.
- Remove unused handlers and entries for the debug registers.
- Display xcr0 (if valid) in 'show sysregs'.
- Add '0x' prefix to MSR values to match other values in 'show sysregs'.
- MFamd64: Display various MSRs in 'show sysregs'.
- Add a 'show dbregs' to display the value of debug registers.
- Dynamically size the column width for register values to properly
  align columns on 64-bit platforms.
- Display %gs for i386 in 'show registers'.

Differential Revision:	https://reviews.freebsd.org/D2784
Reviewed by:	kib, markj
MFC after:	2 weeks
2015-07-22 01:09:02 +00:00
Mark Johnston
e31a60b486 Don't return undefined symbols to a DDB symbol lookup.
Undefined symbols have a value of zero, so it makes no sense to return
such a symbol when performing a lookup by value. This occurs for example
when unwinding the stack after calling a NULL function pointer, and we
confusingly report the faulting function as uart_sab82532_class() on
amd64.

Convert db_print_loc_and_inst() to only attempt disassembly if we managed
to find a symbol corresponding to the IP. Otherwise we may fault and
re-enter the debugger.

Reviewed by:	jhb
Sponsored by:	EMC / Isilon Storage Division
Differential Revision:	https://reviews.freebsd.org/D2858
2015-07-21 23:07:55 +00:00
Zbigniew Bodek
721555e7ee Fix KSTACK_PAGES issue when the default value was changed in KERNCONF
If KSTACK_PAGES was changed to anything alse than the default,
the value from param.h was taken instead in some places and
the value from KENRCONF in some others. This resulted in
inconsistency which caused corruption in SMP envorinment.

Ensure all places where KSTACK_PAGES are used the opt_kstack_pages.h
is included.

The file opt_kstack_pages.h could not be included in param.h
because was breaking the toolchain compilation.

Reviewed by:   kib
Obtained from: Semihalf
Sponsored by:  The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D3094
2015-07-16 10:46:52 +00:00
Bjoern A. Zeeb
8fe344fa48 Correct the function name in catch-all error handling case.
MFC after:	1 week
2015-06-17 10:20:59 +00:00
Pedro F. Giffuni
0a95ab74df ddb: de-register 2015-05-23 14:59:27 +00:00
Pedro F. Giffuni
7fb888588c ddb: Use NULL for pointers
Hinted by:	DragonflyBSD
2015-05-22 19:04:06 +00:00
Pedro F. Giffuni
cd508278c1 ddb: finish converting boolean values.
The replacement started at r283088 was necessarily incomplete without
replacing boolean_t with bool.  This also involved cleaning some type
mismatches and ansifying old C function declarations.

Pointed out by:	bde
Discussed with:	bde, ian, jhb
2015-05-21 15:16:18 +00:00
Pedro F. Giffuni
2b490bc747 ddb: stop boolean screaming.
TRUE --> true
FALSE--> false

Hinted by:	NetBSD
2015-05-18 22:27:46 +00:00
Pedro F. Giffuni
a41dd0319c ddb: ANSI-fy function declarations.
MFC after:	5 days
2014-10-12 18:01:52 +00:00
Pedro F. Giffuni
1549fb22e6 ddb: space/tab fixes.
No functional change.

MFC after:	3 days
2014-10-11 20:25:19 +00:00
Roger Pau Monné
c98a2727cc ddb: allow specifying the exact address of the symtab and strtab
When the FreeBSD kernel is loaded from Xen the symtab and strtab are
not loaded the same way as the native boot loader. This patch adds
three new global variables to ddb that can be used to specify the
exact position and size of those tables, so they can be directly used
as parameters to db_add_symbol_table. A new helper is introduced, so callers
that used to set ksym_start and ksym_end can use this helper to set the new
variables.

It also adds support for loading them from the Xen PVH port, that was
previously missing those tables.

Sponsored by: Citrix Systems R&D
Reviewed by:	kib

ddb/db_main.c:
 - Add three new global variables: ksymtab, kstrtab, ksymtab_size that
   can be used to specify the position and size of the symtab and
   strtab.
 - Use those new variables in db_init in order to call db_add_symbol_table.
 - Move the logic in db_init to db_fetch_symtab in order to set ksymtab,
   kstrtab, ksymtab_size from ksym_start and ksym_end.

ddb/ddb.h:
 - Add prototype for db_fetch_ksymtab.
 - Declate the extern variables ksymtab, kstrtab and ksymtab_size.

x86/xen/pv.c:
 - Add support for finding the symtab and strtab when booted as a Xen
   PVH guest. Since Xen loads the symtab and strtab as NetBSD expects
   to find them we have to adapt and use the same method.

amd64/amd64/machdep.c:
arm/arm/machdep.c:
i386/i386/machdep.c:
mips/mips/machdep.c:
pc98/pc98/machdep.c:
powerpc/aim/machdep.c:
powerpc/booke/machdep.c:
sparc64/sparc64/machdep.c:
 - Use the newly introduced db_fetch_ksymtab in order to set ksymtab,
   kstrtab and ksymtab_size.
2014-09-25 08:28:10 +00:00
Warner Losh
c6cb86cc6a ins is only set and unused, but only when we're not doing software
single stepping. Only set it when we're doing that by bending
style(9) rules a little to avoid even worse #ifdef soup.
2014-08-14 16:01:51 +00:00
John-Mark Gurney
527be4f229 handle longer commands so that lines don't overflow... people who added
commands forgot to check this...
2014-06-02 23:50:19 +00:00
Pedro F. Giffuni
1285b2d147 ddb: Minor style cleanups.
#define should be followed by tab.

MFC after:	1 week
2014-03-31 16:37:41 +00:00
Alfred Perlstein
21d748a957 Small textdump enhancements.
Allow textdumps to be called explicitly from DDB.

If "dump" is called in DDB and textdumps are enabled then abort the
dump and tell the user to turn off textdumps.

Add options TEXTDUMP_PREFERRED to turn textdumps on by default.
Add options TEXTDUMP_VERBOSE to be a bit more verbose while textdumping.

Reviewed by: rwatson

MFC after:	2 weeks
2012-11-01 04:07:08 +00:00
John Baldwin
28926c5766 Update the ddb and gdb backends for the new 'trace_thread' hook.
It is implemented via db_trace_thread() for DDB and not implemented
for GDB.  This should have been part of r234190.

Pointy hat to:	jhb
Reported by:	jkim
MFC after:	1 week
2012-04-12 21:34:58 +00:00
Ed Schouten
dc15eac046 Use strchr() and strrchr().
It seems strchr() and strrchr() are used more often than index() and
rindex(). Therefore, simply migrate all kernel code to use it.

For the XFS code, remove an empty line to make the code identical to
the code in the Linux kernel.
2012-01-02 12:12:10 +00:00
Sergey Kandaurov
148ddfed15 Use FOREACH_PROC_IN_SYSTEM instead of using its unrolled form.
Reviewed by:	kib
2011-12-18 15:36:21 +00:00
Konstantin Belousov
9ab83ecbcb Add 'findstack' ddb command to search either the thread kernel stack
or cached stack containing the specified kernel virtual address.

Discussed with:	pho
MFC after:	1 week
2011-12-16 11:44:20 +00:00
Konstantin Belousov
38474ef299 Show the thread kernel stack base address for 'show threads'.
Discussed with:	pho
MFC after:	1 week
2011-12-16 11:42:50 +00:00
Konstantin Belousov
40bd3bef47 Typo.
MFC after:	3 days
2011-12-09 20:41:54 +00:00
Robert Watson
e5a0927394 Follow up to r225203 refining break-to-debugger run-time configuration
improvements:

(1) Implement new model in previously missed at91 UART driver
(2) Move BREAK_TO_DEBUGGER and ALT_BREAK_TO_DEBUGGER from opt_comconsole.h
    to opt_kdb.h (spotted by np)
(3) Garbage collect now-unused opt_comconsole.h

MFC after:	3 weeks
Approved by:	re (bz)
2011-08-27 14:24:27 +00:00
Marcel Moolenaar
299cceef03 Fix making kernel dumps from the debugger by creating a command
for it. Do not not expect a developer to call doadump(). Calling
doadump does not necessarily work when it's declared static. Nor
does it necessarily do what was intended in the context of text
dumps. The dump command always creates a core dump.

Move printing of error messages from doadump to the dump command,
now that we don't have to worry about being called from DDB.
2011-06-07 01:28:12 +00:00
John Baldwin
41b1c25960 Trim some additional unnecessary <linker_set.h> includes.
MFC after:	1 week
2011-04-28 17:59:33 +00:00
Attilio Rao
7126ba42f6 - Add the possibility to reuse the already last used timeout when patting
the watchdog, via the watchdog(9) interface.
  For that, the WD_LASTVAL bitwise operation is used. It is mutually
  exclusive with any explicit timout passing to the watchdogs.
  The last timeout can be returned via the wdog_kern_last_timeout()
  KPI.
- Add the possibility to pat the watchdogs installed via the watchdog(9)
  interface from the kernel.
  In order to do that the new KPI wdog_kern_pat() is offered and it does
  accept normalized nanoseconds or WD_LASTVAL.
- Avoid to pass WD_ACTIVE down in the watchdog handlers. All the control
  bit processing should over to the upper layer functions and not passed
  down to the handlers at all.

These changes are intended to be used in order to fix up the watchdog
tripping in situation when the userland is busted, but protection is still
wanted (examples: shutdown syncing / disk dumping).

Sponsored by:	Sandvine Incorporated
Reviewed by:	emaste, des, cognet
MFC after:	2 weeks
2011-04-27 16:43:03 +00:00
Attilio Rao
8b927d7b7e Extend the DDB command "watchdog" with the ability to specify a timeout
value.

The timeout is expressed in the form T(N) = (2^N * nanoseconds) and can
be easilly extracted from the watchdog interface as a WD_TO_* macro.
That new functionality is supposed to fix re-entering the kernel from DDB
re-enabling the watchdog again (previously disabled) and also offer the
possibility to break for deadlocked DDB commands.

Please note that retro-compatibility is retained.

Sponsored by:	Sandvine Incorporated
Approved by:	des
MFC after:	10 days
2011-04-05 14:15:58 +00:00
Matthew D Fleming
3a5d36716f Modify kdb_trap() so that it re-calls the dbbe_trap function as long as
the debugger back-end has changed.  This means that switching from ddb
to gdb no longer requires a "step" which can be dangerous on an
already-crashed kernel.

Also add a capability to get from the gdb back-end back to ddb, by
typing ^C in the console window.

While here, simplify kdb_sysctl_available() by using
sbuf_new_for_sysctl(), and use strlcpy() instead of strncpy() since the
strlcpy semantic is desired.

MFC after:	1 month
2011-02-18 22:25:11 +00:00
Matthew D Fleming
fbbb13f962 sysctl(9) cleanup checkpoint: amd64 GENERIC builds cleanly.
Commit the kernel changes.
2011-01-12 19:54:19 +00:00
Konstantin Belousov
a29af74b70 One more use for _SIG_VALID.
Submitted by:	Garrett Cooper <yanegomi gmail com>
MFC after:	1 week
2010-07-12 10:18:10 +00:00
Bjoern A. Zeeb
0f59fbc3d6 MFp4 @178364:
Implement an optional delay to the ddb reset/reboot command.

This allows textdumps to be run automatically with unattended reboots
after a resonable timeout, while still permitting an administrator to
break into debugger if attached to the console at the time of the
event for further debugging.  Cap the maximum delay at 1 week to avoid
highly accidental results, and default to 15s in case of problems
parsing the timeout value.

Move hex2dec helper function from db_thread.c to db_command.c to make
it generally available and prefix it with a "db_" to avoid namespace
collisions.

Reviewed by:	rwatson
MFC after:	4 weeks
2010-05-24 16:41:05 +00:00
Attilio Rao
3caaaae046 There is not a good reason to have a different prototype for db_printf()
when compared to printf().
Unify it by returning the number of characters displayed for db_printf()
as well.

MFC after:	7 days
2010-05-11 17:01:14 +00:00
Julian Elischer
7a90b21212 Move two copies of the same definition to a common include file.
MFC after: 3 weeks
2010-04-14 23:06:07 +00:00
Rui Paulo
cc01b2698a Add a space before printing 'thread pid ...' to match the space before
']'.
2010-02-12 19:52:51 +00:00
Edward Tomasz Napierala
3745cc73d0 Replace several instances of 'if (!a & b)' with 'if (!(a &b))' in order
to silence newer GCC versions.
2010-01-08 15:44:49 +00:00
Konstantin Belousov
a3de221dbe Among signal generation syscalls, only sigqueue(2) is allowed by POSIX
to fail due to lack of resources to queue siginfo. Add KSI_SIGQ flag
that allows sigqueue_add() to fail while trying to allocate memory for
new siginfo. When the flag is not set, behaviour is the same as for
KSI_TRAP: if memory cannot be allocated, set bit in sq_kill. KSI_TRAP is
kept to preserve KBI.

Add SI_KERNEL si_code, to be used in siginfo.si_code when signal is
generated by kernel. Deliver siginfo when signal is generated by kill(2)
family of syscalls (SI_USER with properly filled si_uid and si_pid), or
by kernel (SI_KERNEL, mostly job control or SIGIO). Since KSI_SIGQ flag
is not set for the ksi, low memory condition cause old behaviour.

Keep psignal(9) KBI intact, but modify it to generate SI_KERNEL
si_code. Pgsignal(9) and gsignal(9) now take ksi explicitely. Add
pksignal(9) that behaves like psignal but takes ksi, and ddb kill
command implemented as pksignal(..., ksi = NULL) to not do allocation
while in debugger.

While there, remove some register specifiers and use ANSI C prototypes.

Reviewed by:	davidxu
MFC after:	1 month
2009-11-17 11:39:15 +00:00
John Baldwin
3538cf0cbe Put square backets ([]) around process names for system processes to patch
the behavior of ps(1).
2009-10-01 19:12:14 +00:00
Robert Watson
530c006014 Merge the remainder of kern_vimage.c and vimage.h into vnet.c and
vnet.h, we now use jails (rather than vimages) as the abstraction
for virtualization management, and what remained was specific to
virtual network stacks.  Minor cleanups are done in the process,
and comments updated to reflect these changes.

Reviewed by:	bz
Approved by:	re (vimage blanket)
2009-08-01 19:26:27 +00:00
Robert Watson
eddfbb763d Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator.  Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...).  This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.

Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack.  Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory.  Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.

Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy.  Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address.  When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.

This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.

Bump __FreeBSD_version and update UPDATING.

Portions submitted by:  bz
Reviewed by:            bz, zec
Discussed with:         gnn, jamie, jeff, jhb, julian, sam
Suggested by:           peter
Approved by:            re (kensmith)
2009-07-14 22:48:30 +00:00