Commit Graph

334 Commits

Author SHA1 Message Date
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
Jamie Gritton
76ca6f88da Place hostnames and similar information fully under the prison system.
The system hostname is now stored in prison0, and the global variable
"hostname" has been removed, as has the hostname_mtx mutex.  Jails may
have their own host information, or they may inherit it from the
parent/system.  The proper way to read the hostname is via
getcredhostname(), which will copy either the hostname associated with
the passed cred, or the system hostname if you pass NULL.  The system
hostname can still be accessed directly (and without locking) at
prison0.pr_host, but that should be avoided where possible.

The "similar information" referred to is domainname, hostid, and
hostuuid, which have also become prison parameters and had their
associated global variables removed.

Approved by:	bz (mentor)
2009-05-29 21:27:12 +00:00
Warner Losh
19b79af1e9 Prefer prototypes to k&r definitions. 2009-03-09 13:32:19 +00:00
Peter Wemm
e6592ee55c Collect N identical (or near identical) mkdumpheader() implementations into
one, as threatened in the comment.  Textdump magic can be passed in.
2008-10-01 22:08:53 +00:00
John Baldwin
93d4804b62 Initialize the DDB command list when initializing DDB so that the basic
commands are available from 'boot -d'.

Suggested by:	dfr
2008-09-25 19:50:14 +00:00
Sam Leffler
39297ba455 Make ddb command registration dynamic so modules can extend
the command set (only so long as the module is present):
o add db_command_register and db_command_unregister to add and remove
  commands, respectively
o replace linker sets with SYSINIT's (and SYSUINIT's) that register
  commands
o expose 3 list heads: db_cmd_table, db_show_table, and db_show_all_table
  for registering top-level commands, show operands, and show all operands,
  respectively

While here also:
o sort command lists
o add DB_ALIAS, DB_SHOW_ALIAS, and DB_SHOW_ALL_ALIAS to add aliases
  for existing commands
o add "show all trace" as an alias for "show alltrace"
o add "show all locks" as an alias for "show alllocks"

Submitted by:	Guillaume Ballet <gballet@gmail.com> (original version)
Reviewed by:	jhb
MFC after:	1 month
2008-09-15 22:45:14 +00:00
Attilio Rao
e23851c6ba Add a missing include which was erroneusly left out from the previous
commit.

Sponsored by:	Nokia
2008-08-18 16:51:44 +00:00
Attilio Rao
51b93e474d Bufferize the output for DDB printouts.
In order to CATER this, DDB buffered output can be choosen at compile
time through the option DDB_BUFR_SIZE=nbytes where nbytes choose the size
of the buffer (suggested size is 128 bytes), which should be manually
specified in any interested config file.

Sponsored by:	Nokia
2008-08-18 16:48:09 +00:00
Bjoern A. Zeeb
603724d3ab Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).

This is the first in a series of commits over the course
of the next few weeks.

Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.

We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.

Obtained from:	//depot/projects/vimage-commit2/...
Reviewed by:	brooks, des, ed, mav, julian,
		jamie, kris, rwatson, zec, ...
		(various people I forgot, different versions)
		md5 (with a bit of help)
Sponsored by:	NLnet Foundation, The FreeBSD Foundation
X-MFC after:	never
V_Commit_Message_Reviewed_By:	more people than the patch
2008-08-17 23:27:27 +00:00
Olivier Houchard
08cfba5d14 Fix software single-stepping: we need to check if the instruction is a
return instruction as well, or we'll stop single-stepping as soon as we'll
return from a function.

MFC after:	3 days
2008-08-02 12:49:43 +00:00
Attilio Rao
f15b761da5 Print out the container lock when showing the thread state in DDB.
Tested by:	benjsc
2008-06-18 20:42:01 +00:00
Robert Watson
92e6c2fd6d Rename debug.ddb.capture.bytes sysctl to debug.ddb.capture.bufoff in
order to match the internal variable name.

Add a new sysctl debug.ddb.capture.inprogress to export the inprogress
variable.

MFC after:	3 days
2008-04-25 13:23:36 +00:00
Sam Leffler
9e340a6190 enable dynamic addition of "show all" commands
MFC after:	3 weeks
2008-03-25 20:36:32 +00:00
Robert Watson
7c7b7f8e1b Add a /S mode to DDB "ex" command, which interprets and prints the
value at the requested address as a symbol.  For example, "ex /S
aio_swake" prints the name of the function currently registered in
via aio_swake hook.

The change as committed differs slightly from the patch in the PR,
as I force the size of the retrieved value (and the automatic
address increment) to be sizeof(void *).  This seems to provide
the most useful auto-increment behavior, and defaults using the
default size (4), which is not sizeof(void *) on 64-bit platforms.

MFC after:	3 days
PR:		57976
Submitted by:	Dan Strick <strick at covad.net>
2008-03-07 18:09:07 +00:00
Robert Watson
3755dbd805 When killing a user process from DDB, check that the requested signal is
> 0 rather than >= 0, or we will panic when trying to deliver the signal.

MFC after:	3 days
PR:		100802
Submitted by:	Valerio Daelli <valerio.daelli at gmail.com>
2008-03-07 14:26:30 +00:00
Robert Watson
233f8184ec Reserve two bytes at the end of the DDB input line in db_readline() to
hold the newline and nul terminator.  Otherwise, there are cases where
garbage may end up in the command history due to a lack of a nul
terminator, or input may end up without room for a newline.

MFC after:	3 days
PR:		119079
Submitted by:	Michael Plass <mfp49_freebsd@plass-family.net>
2008-03-07 13:13:17 +00:00
Robert Watson
ea1c6a394a When redrawing an input line, count backspaces to get to the beginning of
the input field from the current cursor location, rather than the end of
the input line, as the cursor may not be at the end of the line.
Otherwise, we may overshoot, overwriting a bit of the previous line and
failing to fully overwrite the current line.

MFC after:	3 days
PR:		119079
Submitted by:	Michael Plass <mfp49_freebsd@plass-family.net>
2008-03-06 10:10:43 +00:00
Robert Watson
990132f07d Use dump_write() instead of direct calls to di->dumper() in textdumps.
Textdumps already do pretty much the same sanity checking, but
abstractions and seatbelts are both useful.

MFC after:	2 months
2008-01-31 16:22:14 +00:00
Robert Watson
a384163c5e Increase maximum DDB capture buffer size to 5MB.
PR:		119993
MFC after:	2 months
Suggested by:	Scot Hetzel <swhetzel at gmail dot com>
2008-01-26 23:02:14 +00:00
Robert Watson
f33dc69dfb Allow DDB_CAPTURE_DEFAULTBUFSIZE and DDB_CAPTURE_MAXBUFSIZE to be
overridden at compile-time using kernel options of the same names.

Rather than doing a compile-time CTASSERT of buffer sizes being
even multiples of block sizes, just adjust them at boottime, as
the failure mode is more user-friendly.

MFC after:	2 months
PR:		119993
Suggested by:	Scot Hetzel <swhetzel at gmail dot com>
2008-01-26 22:32:23 +00:00
Robert Watson
8a4d372e93 Rename DB_ constants in db_capture.c to DDB_ so that when they are
exposed as kernel compile options, they have more meaningful names.

PR:		119993
MFC after:	2 months
Suggested by:	Scot Hetzel <swhetzel at gmail dot com>
2008-01-26 13:55:52 +00:00
Robert Watson
9b0fce602a Refine textdump comments slightly.
MFC after:	3 months
2008-01-10 00:26:47 +00:00
Robert Watson
618c7db30a Add textdump(4) facility, which provides an alternative form of kernel
dump using mechanically generated/extracted debugging output rather than
a simple memory dump.  Current sources of debugging output are:

- DDB output capture buffer, if there is captured output to save
- Kernel message buffer
- Kernel configuration, if included in kernel
- Kernel version string
- Panic message

Textdumps are stored in swap/dump partitions as with regular dumps, but
are laid out as ustar files in order to allow multiple parts to be stored
as a stream of sequentially written blocks.  Blocks are written out in
reverse order, as the size of a textdump isn't known a priori.  As with
regular dumps, they will be extracted using savecore(8).

One new DDB(4) command is added, "textdump", which accepts "set",
"unset", and "status" arguments.  By default, normal kernel dumps are
generated unless "textdump set" is run in order to schedule a textdump.
It can be canceled using "textdump unset" to restore generation of a
normal kernel dump.

Several sysctls exist to configure aspects of textdumps;
debug.ddb.textdump.pending can be set to check whether a textdump is
pending, or set/unset in order to control whether the next kernel dump
will be a textdump from userspace.

While textdumps don't have to be generated as a result of a DDB script
run automatically as part of a kernel panic, this is a particular useful
way to use them, as instead of generating a complete memory dump, a
simple transcript of an automated DDB session can be captured using the
DDB output capture and textdump facilities.  This can be used to
generate quite brief kernel bug reports rich in debugging information
but not dependent on kernel symbol tables or precisely synchronized
source code.  Most textdumps I generate are less than 100k including
the full message buffer.  Using textdumps with an interactive debugging
session is also useful, with capture being enabled/disabled in order to
record some but not all of the DDB session.

MFC after:	3 months
2007-12-26 11:32:33 +00:00
Robert Watson
44daa2da55 Remove duplicate $FreeBSD$ that snuck in.
MFC after:	3 months
2007-12-26 10:51:07 +00:00
Robert Watson
c9b0cc3b96 Add a simple scripting facility to DDB(4), allowing the user to
define a set of named scripts.  Each script consists of a list of DDB
commands separated by ";"s that will be executed verbatim.  No higher
level language constructs, such as branching, are provided for:
scripts are executed by sequentially injecting commands into the DDB
input buffer.

Four new commands are present in DDB: "run" to run a specific script,
"script" to define or print a script, "scripts" to list currently
defined scripts, and "unscript" to delete a script, modeled on shell
alias commands.  Scripts may also be manipulated using sysctls in the
debug.ddb.scripting MIB space, although users will prefer to use the
soon-to-be-added ddb(8) tool for usability reasons.

Scripts with certain names are automatically executed on various DDB
events, such as entering the debugger via a panic, a witness error,
watchdog, breakpoint, sysctl, serial break, etc, allowing customized
handling.

MFC after:	3 months
2007-12-26 09:33:19 +00:00
Robert Watson
086fec574e Add a new DDB(4) facility, output capture. Input and output from DDB may be
captured to a memory buffer for later inspection using sysctl(8), or in the
future, to a textdump.

A new DDB command, "capture", is added, which accepts arguments "on", "off",
"reset", and "status".

A new DDB sysctl tree, debug.ddb.capture, is added, which can be used to
resize the capture buffer and extract buffer contents.

MFC after:	3 months
2007-12-25 23:06:51 +00:00
John Baldwin
6b76a4c77a Make the examine command honor db_pager_quit so you can use 'q' or 'x'
at the pager prompt to abort an examine command that spans multiple pages.

MFC after:	1 week
2007-10-27 20:19:11 +00:00
Marcel Moolenaar
a0f4a3a63b Print the stack bounds of the thread. 2007-10-16 17:52:59 +00:00
Jeff Roberson
b61ce5b0e6 - Move all of the PS_ flags into either p_flag or td_flags.
- p_sflag was mostly protected by PROC_LOCK rather than the PROC_SLOCK or
   previously the sched_lock.  These bugs have existed for some time.
 - Allow swapout to try each thread in a process individually and then
   swapin the whole process if any of these fail.  This allows us to move
   most scheduler related swap flags into td_flags.
 - Keep ki_sflag for backwards compat but change all in source tools to
   use the new and more correct location of P_INMEM.

Reported by:	pho
Reviewed by:	attilio, kib
Approved by:	re (kensmith)
2007-09-17 05:31:39 +00:00
Xin LI
f67af5c918 Use FOREACH_PROC_IN_SYSTEM instead of using its unrolled form. 2007-01-17 15:05:52 +00:00
Julian Elischer
ad1e7d285a Threading cleanup.. part 2 of several.
Make part of John Birrell's KSE patch permanent..
Specifically, remove:
Any reference of the ksegrp structure. This feature was
never fully utilised and made things overly complicated.
All code in the scheduler that tried to make threaded programs
fair to unthreaded programs.  Libpthread processes will already
do this to some extent and libthr processes already disable it.

Also:
Since this makes such a big change to the scheduler(s), take the opportunity
to rename some structures and elements that had to be moved anyhow.
This makes the code a lot more readable.

The ULE scheduler compiles again but I have no idea if it works.

The 4bsd scheduler still reqires a little cleaning and some functions that now do
ALMOST nothing will go away, but I thought I'd do that as a separate commit.

Tested by David Xu, and Dan Eischen using libthr and libpthread.
2006-12-06 06:34:57 +00:00
John Baldwin
e6337905e5 Fix the output format of MI ddb watches in 'show watch' on 64-bit
platforms.
2006-11-17 16:41:56 +00:00
Konstantin Belousov
a0396f2797 Set up the context for the dbbe_trace callback in the ddb. Otherwise,
trap caused by backtracing would lead to panic.

Noted and reviewed by:	bde
2006-11-06 11:10:57 +00:00
Konstantin Belousov
9641e38966 On trap while inside ddb, the trap handler calls kdb_reenter(), that
longjmp to the default context. As result, "alltrace" command may
be prematurely terminated (without error message). This is happens,
for instance, when system is low on memory and referenced page in
kernel-mode thread stack is swapped out.

Protect "alltrace" against termination on trap by setting temporary
kdb_jmpbuf context.

Submitted by:	Peter Holm
2006-11-02 11:47:38 +00:00
John Birrell
8460a577a4 Make KSE a kernel option, turned on by default in all GENERIC
kernel configs except sun4v (which doesn't process signals properly
with KSE).

Reviewed by:	davidxu@
2006-10-26 21:42:22 +00:00
Bruce Evans
e4b732cff1 The powerpc and sparc64 MD `reboot' commands should never have existed
since they just duplicated the MI `reset' command.  Instead of removing
them, make `reboot' an MI alias for `reboot' since this gives a better
way of killing the `r' alias for `reset'.  Remove the `registers' command
that was used to kill the alias.

Turn the powerpc and sparc64 MD `halt' command into an MI command.

A copy of sparc64/db_interface.c grew in sun4v just after I found the
extra reboot commands.  It has not been changed, and is now not
identical.  Duplicated commands come out duplicated in ddb's online
help, but cause large problems when used (e.g., on i386's with 2 halt's
and an hwatch, typing h doesn' give the expected message about an
ambiguous command, but hangs like the halt command or a looping parseri
would).
2006-10-10 07:26:54 +00:00
Bruce Evans
c7eeb59df0 Fixed loss of whitespace suppression at ends of lines. Whitespace
suppression is only needed at ends of lines, but rev.1.32 forced it
off precisely there.

The --More-- prompt is now cleared by explicitly forcing out the
whitespace in "\r        \r".  It might be better to use the line
editor's clearing functions, but these are currently static and not
much different.
2006-10-10 06:36:01 +00:00
Bruce Evans
75149ab872 Added some aliases:
- `b' is now an official alias for `break'.  It used to be an unofficial
  alias, but this was broken by adding the `bt' alias for `trace'.
- `t' is now an official alias for `trace'.  It used to be an unofficial
  alias, but this was broken by adding the `thread' command.
- `registers' is now an alias for `show registers'.  This is a hack to
  break the unofficial `r' alias for `reset'.  `r' really means
  `registers' in some debuggers, so I sometimes type it accidentally and
  am annoyed when it resets the system.  A short command shouldn't have
  such a large effect.  Now at least `res' must be typed to disambiguate
  `reset'.
2006-10-08 18:37:00 +00:00
Bruce Evans
2481da7487 Fixed formatting of printing of command tables. WIth the default max
output width of 79, only 6 columns of width 12 each fit, but 7 columns
were printed.

The fix is to pass the width of the next output to db_end_line() and
not assume there that this width is always 1.

Related unfixed bugs:
- 1 character is wasted for a space after the last column
- suppression of trailing spaces used to limit the misformatting, but
  seems to have been lost
- in db_examine(), the width of the next output is not know and is
  still assumed to be 1.
2006-10-08 18:15:08 +00:00
John Baldwin
d25168e14e Fix two nits in the ps header that offset each other making them largely
unnoticable.
2006-08-01 22:30:55 +00:00
John Baldwin
8b6d68671b Some cosmetic tweaks:
- Right justify 'pid' label.
- Move the uid column to the right 2 columns so that the 3 process id
  columns (pid, ppid, pgrp) are grouped together.
- Expand the uid column to 5 chars.
- Don't indent the tid for multithreaded processes.

Requested by:	bde (1, 2, 4)
2006-08-01 15:29:46 +00:00
John Baldwin
15cc91d345 Disable the pager for 'panic' and 'call' to be paranoid. 2006-07-19 18:26:53 +00:00
John Baldwin
19e9205a23 Simplify the pager support in DDB. Allowing different db commands to
install custom pager functions didn't actually happen in practice (they
all just used the simple pager and passed in a local quit pointer).  So,
just hardcode the simple pager as the only pager and make it set a global
db_pager_quit flag that db commands can check when the user hits 'q' (or a
suitable variant) at the pager prompt.  Also, now that it's easy to do so,
enable paging by default for all ddb commands.  Any command that wishes to
honor the quit flag can do so by checking db_pager_quit.  Note that the
pager can also be effectively disabled by setting $lines to 0.

Other fixes:
- 'show idt' on i386 and pc98 now actually checks the quit flag and
  terminates early.
- 'show intr' now actually checks the quit flag and terminates early.
2006-07-12 21:22:44 +00:00
Konstantin Belousov
d48b6d9ad6 Never zero-out db_last_symtab. Whan backtraces are done
in parallel in several threads, one symbol lookup could
clear db_last_symtab when another one going to use it as
starting point for traversal.

Approved by:	pjd (mentor)
MFC after:	1 month
2006-06-16 16:17:52 +00:00
John Baldwin
10fd453475 Use __LP64__ rather than the PTR64 hack.
Suggested by:	ru
2006-05-11 21:59:55 +00:00
John Baldwin
a421d57149 Sort includes. 2006-04-27 22:09:18 +00:00
John Baldwin
eefcd2a1e6 A whitespace fix.
Submitted by:	bde
2006-04-27 22:02:27 +00:00
John Baldwin
60b0d00999 Drop locking comments. ddb functions should never use locking anyway and
no other ddb functions try to annotate what locking would otherwise be
appropriate in comments.

Prodded by:	bde
2006-04-27 21:59:43 +00:00
John Baldwin
c9a08d1cad - Overhaul the 'ps' command in ddb to be mostly readable again. :) It is
now back to using fixed-size columns for output and each line of output
  should fit in 80 columns on both 32-bit and 64-bit architectures.  In
  general the output is close to that of the userland ps(1) with the
  exception that the 'wmesg' field is mostly similar to the "state" field
  in top(1) in that it will show either a wmesg, a lock name (prefixed with
  an *), "CPU xx" (for a running thread), or nothing if none of those three
  conditions are true.  It also respects td_name when listing threads in
  a multithreaded process.  There is a somewhat evilly-defined PTR64 macro
  I use to make account for the change in the size of the 'wchan' column
  in the formatted output (wchan is now the only pointer in the ps output
  and is available so it can be passed to 'show sleepq', 'show turnstile',
  or 'show lock').
- Add two new commands "show proc [process]" and "show thread [thread]"
  that show details about the specified process or thread (specified
  either by pid/tid or pointer), respectively.  If an address it not
  specified, it uses the current kdb thread.
2006-04-25 20:34:04 +00:00
John Baldwin
d605beaaa8 Add two helper functions: db_lookup_thread() and db_lookup_proc(). They
take the addr value passed to a ddb command and attempt to use it to
lookup a struct thread * or struct proc *, respectively.  Each function
first reparses the passed in value as if it was an ID entered in base 10.
For threads the ID is treated as a thread ID, for proceses the ID is
treated as a PID.  If a thread or proc matching the ID is found, it is
returned.  For db_lookup_thread(), if the check_pid argument is true and
it didn't find a thread with a matching thread ID, it will treat the ID as
a PID and look for a matching process.  If it finds one it returns the
first thread in the process.  If none of the ID lookups succeeded, then
the functions assume that the passed in address is a thread or proc
pointer, respectively.  This allows one to use tids, pids, or structure
pointers interchangeably in ddb functions that want to lookup threads or
processes if desired.
2006-04-25 20:22:48 +00:00
John Baldwin
cf93bc6617 Use LIST_FOREACH(). 2006-04-21 20:39:51 +00:00
John Baldwin
e1e31c0e43 Clean up the way we handle auxiliary commands for a given ddb command
table.  Previously, the ddb code knew of each linker set of auxiliary
commands and which explicit command list they were tied to.  These changes
add a simple command_table struct that contains both the static list of
commands and the pointers for any auxiliary linker set of additional
commands.  This also makes it possible for other arbitrary command tables
to be defined in other parts of the kernel w/o having to edit ddb itself.

The DB_SET macro has also been trimmed down to just creating an entry in
a linker set.  A new DB_FUNC macro does what the old DB_SET did which is
to not only add an entry to the linker set but also to include a function
prototype for the function being added.  With these changes, it's now also
possible to create aliases for ddb functions using DB_SET() directly if
desired.
2006-03-07 22:17:06 +00:00
Ruslan Ermilov
f4e9888107 Fix -Wundef. 2005-12-04 02:12:43 +00:00
John Baldwin
3924da21a3 - Rename 'traceall' to 'alltrace' so that the 'tr' shortcut for 'trace'
still works.  Also, this is consistent with 'show pcpu' vs
  'show allpcpu'.  (And 'show allstacks' on OS X for that matter.)
- Add 'bt' as an alias for 'trace'.  We already have a 'where' alias as
  well, so this makes it easier for gdb-wired hands to work in ddb.

Ok'd by:	rwatson (1)
Requested by:	scottl (2)
MFC after:	1 day
2005-10-24 15:21:36 +00:00
Olivier Houchard
da927f93bd - Call db_setup_paging() for traceall.
- Make it so one can't call db_setup_paging() if it has already been called
before. traceall needs this, or else the db_setup_paging() call from
db_trace_thread() will reset the printed line number, and override its
argument.
This is not perfect for traceall, because even if one presses 'q' while in
the middle of printing a backtrace it will finish printing the backtrace
before exiting, as db_trace_thread() won't be notified it should stop, but
it is hard to do better without reworking the pager interface a lot more.
2005-10-02 22:57:31 +00:00
Robert Watson
a7ad956bdf Add a DDB "traceall" function, which stack traces all known process
threads.  This is quite useful if generating a debug log for post-mortem
by another developer, in which case the person at the console may not
know which threads are of interest.  The output of this can be quite
long.

Discussed with:	kris
MFC after:	3 days
2005-10-02 11:41:12 +00:00
Marcel Moolenaar
216e80c2ba Move the prototypes of db_md_set_watchpoint(), db_md_clr_watchpoint()
and db_md_list_watchpoints() to ddb/ddb.h.
2005-09-10 03:01:25 +00:00
David E. O'Brien
cec9a4bf57 Remove the need to forward declare statics by moving them around. 2005-08-10 07:08:14 +00:00
Marcel Moolenaar
a2aeb24eff Implement functions calls from within DDB on ia64. On ia64 a function
pointer doesn't point to the first instruction of that function, but
rather to a descriptor. The descriptor has the address of the first
instruction, as well as the value of the global pointer. The symbol
table doesn't know anything about descriptors, so if you lookup the
name of a function you get the address of the first instruction. The
cast from the address, which is the result of the symbol lookup, to a
function pointer as is done in db_fncall is therefore invalid.
Abstract this detail behind the DB_CALL macro. By default DB_CALL is
defined as db_fncall_generic, which yields the old behaviour. On ia64
the macro is defined as db_fncall_ia64, in which a descriptor is
constructed to yield a valid function pointer.

While here, introduce DB_MAXARGS. DB_MAXARGS replaces the existing
(local) MAXARGS. The DB_MAXARGS macro can be defined by platforms to
create a convenient maximum. By default this will be the legacy 10.
On ia64 we define this macro to be 8, for 8 is the maximum number of
arguments that can be passed in registers. This avoids having to
implement spilling of arguments on the memory stack.

Approved by: re (dwhite)
2005-07-02 23:52:37 +00:00
Paul Saab
8cb038b4b2 Don't enter the debugger if KDB_UNATTENDED is set or if
debug.debugger_on_panic=0.

MFC after:	2 weeks
2005-04-20 20:52:46 +00:00
Peter Wemm
20984f2f04 rev 1.54 of i386/include/pcb.h depended on sys/proc.h. The prerequisite
was satisified for the rest of the kernel on the i386 build except for
these two files.  Rather than adding a submarine include to pcb.h, I've
added proc.h here.

I forgot to include these with the original commit. Sorry folks.
2005-04-14 05:25:40 +00:00
Warner Losh
dd3cb56845 Start each of the license/copyright comments with /*- 2005-01-06 01:34:41 +00:00
Robert Watson
a13aca1a8e When printing a stack trace for a thread, also print the pid and tid.
When a series of traces is included in a bug report, this will make it
easier to tie the trace information back to ps or threads output,
each of which will show the pid or the tid, but usually not both.
2004-11-23 23:11:47 +00:00
Robert Watson
2afce774e7 When printing information on the current thread, such as when entering
DDB, also print the pid of the process if present.  Since much
debugging still centers around processes, having the pid is quite
helpful.
2004-11-23 23:07:12 +00:00
Olivier Houchard
75f88c7ca4 Do not attempt to skip a breakpoint that is a result of a software single step,
or bad things happen.
2004-11-21 18:11:02 +00:00
David Schultz
626ff2081f Remove the uarea column from the DDB 'ps' display, and from grog's gdb
scripts.

Reviewed by:	arch@
2004-11-20 02:32:42 +00:00
John Baldwin
d39d4a6e64 - Change the ddb paging "support" to use a variable (db_lines_per_page) to
control the number of lines per page rather than a constant.  The variable
  can be examined and changed in ddb as '$lines'.  Setting the variable to
  0 will effectively turn off paging.
- Change db_putchar() to force out pending whitespace before outputting
  newlines and carriage returns so that one can rub out content on the
  current line via '\r     \r' type strings.
- Change the simple pager to rub out the --More-- prompt explicitly when
  the routine exits.
- Add some aliases to the simple pager to make it more compatible with
  more(1): 'e' and 'j' do a single line.  'd' does half a page, and
  'f' does a full page.

MFC after:	1 month
Inspired by:	kris
2004-11-01 22:15:15 +00:00
Julian Elischer
ed062c8d66 Refactor a bunch of scheduler code to give basically the same behaviour
but with slightly cleaned up interfaces.

The KSE structure has become the same as the "per thread scheduler
private data" structure. In order to not make the diffs too great
one is #defined as the other at this time.

The KSE (or td_sched) structure is  now allocated per thread and has no
allocation code of its own.

Concurrency for a KSEGRP is now kept track of via a simple pair of counters
rather than using KSE structures as tokens.

Since the KSE structure is different in each scheduler, kern_switch.c
is now included at the end of each scheduler. Nothing outside the
scheduler knows the contents of the KSE (aka td_sched) structure.

The fields in the ksegrp structure that are to do with the scheduler's
queueing mechanisms are now moved to the kg_sched structure.
(per ksegrp scheduler private data structure). In other words how the
scheduler queues and keeps track of threads is no-one's business except
the scheduler's. This should allow people to write experimental
schedulers with completely different internal structuring.

A scheduler call sched_set_concurrency(kg, N) has been added that
notifies teh scheduler that no more than N threads from that ksegrp
should be allowed to be on concurrently scheduled. This is also
used to enforce 'fainess' at this time so that a ksegrp with
10000 threads can not swamp a the run queue and force out a process
with 1 thread, since the current code will not set the concurrency above
NCPU, and both schedulers will not allow more than that many
onto the system run queue at a time. Each scheduler should eventualy develop
their own methods to do this now that they are effectively separated.

Rejig libthr's kernel interface to follow the same code paths as
linkse for scope system threads. This has slightly hurt libthr's performance
but I will work to recover as much of it as I can.

Thread exit code has been cleaned up greatly.
exit and exec code now transitions a process back to
'standard non-threaded mode' before taking the next step.
Reviewed by:	scottl, peter
MFC after:	1 week
2004-09-05 02:09:54 +00:00
Alexander Kabaev
0171fe42f2 Damage control. Correcly advance symtab and strtab pointers, not
table length values.

Spotted by:	iedowse
2004-07-28 08:59:08 +00:00
Alexander Kabaev
eec256de79 Avoid casts as lvalues. 2004-07-28 06:21:53 +00:00
Marcel Moolenaar
026c3aaa60 Oops... Add the CS_OWN flag to the trace and where commands so that
db_stack_trace() actually has a chance to parse its own arguments.
2004-07-21 05:55:51 +00:00
Marcel Moolenaar
fd32d93b97 Unify db_stack_trace_cmd(). All it did was look up the thread given
the thread ID and call db_trace_thread().
Since arm has all the logic in db_stack_trace_cmd(), rename the
new DB_COMMAND function to db_stack_trace to avoid conflicts on
arm.
While here, have db_stack_trace parse its own arguments so that
we can use a more natural radix for IDs. If the ID is not a thread
ID, or more precisely when no thread exists with the ID, try if
there's a process with that ID and return the first thread in it.
This makes it easier to print stack traces from the ps output.

requested by: rwatson@
tested on: amd64, i386, ia64
2004-07-21 05:07:09 +00:00
Marcel Moolenaar
f3be7cb3e9 Re-add the gdb command. It was removed to be replaced by something
more generic, but that didn't actually happen. Since the feature to
switch backends (and historically this means from DDB to GDB) is
important, make sure people can do just that until such the generic
mechanism actually sees the light of day.

Suggested by: rwatson@
2004-07-12 01:38:07 +00:00
Marcel Moolenaar
412e1faf02 Remove now unused files:
db_elf.c, db_kld.c: The new KDB backend supports both at the same time.
db_sysctl.c: The functionality has been moved to sys/kern/subr_kdb.c.
db_trap.c: The DDB entry point has been moved to sys/ddb/db_main.c.
2004-07-11 01:50:09 +00:00
Marcel Moolenaar
37224cd3fc Mega update for the KDB framework: turn DDB into a KDB backend.
Most of the changes are a direct result of adding thread awareness.
Typically, DDB_REGS is gone. All registers are taken from the
trapframe and backtraces use the PCB based contexts. DDB_REGS was
defined to be a trapframe on all platforms anyway.
Thread awareness introduces the following new commands:
	thread X	switch to thread X (where X is the TID),
	show threads	list all threads.

The backtrace code has been made more flexible so that one can
create backtraces for any thread by giving the thread ID as an
argument to trace.

With this change, ia64 has support for breakpoints.
2004-07-10 23:47:20 +00:00
Bruce Evans
130ff9c31a Fixed DDB_NOKLDSYM on amd64's:
machdep.c:
Initialize the symbol table pointers, not quite like for other arches.

db_elf.c:
Don't claim to be an i486 in the fake ELF header.
2004-05-18 05:30:06 +00:00
Warner Losh
f36cfd49ad Remove advertising clause from University of California Regent's
license, per letter dated July 22, 1999 and email from Peter Wemm,
Alan Cox and Robert Watson.

Approved by: core, peter, alc, rwatson
2004-04-07 20:46:16 +00:00
Poul-Henning Kamp
74cc032b41 Give DDB a "watchdog" command which disables all watchdogs. 2004-02-29 09:55:32 +00:00
John Baldwin
44f3b09204 Switch the sleep/wakeup and condition variable implementations to use the
sleep queue interface:
- Sleep queues attempt to merge some of the benefits of both sleep queues
  and condition variables.  Having sleep qeueus in a hash table avoids
  having to allocate a queue head for each wait channel.  Thus, struct cv
  has shrunk down to just a single char * pointer now.  However, the
  hash table does not hold threads directly, but queue heads.  This means
  that once you have located a queue in the hash bucket, you no longer have
  to walk the rest of the hash chain looking for threads.  Instead, you have
  a list of all the threads sleeping on that wait channel.
- Outside of the sleepq code and the sleep/cv code the kernel no longer
  differentiates between cv's and sleep/wakeup.  For example, calls to
  abortsleep() and cv_abort() are replaced with a call to sleepq_abort().
  Thus, the TDF_CVWAITQ flag is removed.  Also, calls to unsleep() and
  cv_waitq_remove() have been replaced with calls to sleepq_remove().
- The sched_sleep() function no longer accepts a priority argument as
  sleep's no longer inherently bump the priority.  Instead, this is soley
  a propery of msleep() which explicitly calls sched_prio() before
  blocking.
- The TDF_ONSLEEPQ flag has been dropped as it was never used.  The
  associated TDF_SET_ONSLEEPQ and TDF_CLR_ON_SLEEPQ macros have also been
  dropped and replaced with a single explicit clearing of td_wchan.
  TD_SET_ONSLEEPQ() would really have only made sense if it had taken
  the wait channel and message as arguments anyway.  Now that that only
  happens in one place, a macro would be overkill.
2004-02-27 18:52:44 +00:00
Poul-Henning Kamp
9aece96fc0 Add DDB_NUMSYM option which in addition to the symbolic representation
also prints the actual numerical value of the symbol in question.

Users of addr2line(1) will be less proficient in hex arithmetic as a
consequence.

This amongst other things means that traceback lines change from:
   siointr1(c4016800,c073bda0,0,c06b699c,69f) at siointr1+0xc5
to
   siointr1(c4016800,c073bda0,0,c06b699c,69f) at 0xc062b0bd = siointr1+0xc5

I made this an option to avoid bikesheds.
~
~
~
2004-02-24 22:51:42 +00:00
Nate Lawson
5de6c5b5a5 If not in the debugger or if the user requests it with the
debug.ddb_use_printf sysctl, output kernel debugger data to both the
console and kernel message buffer via printf.  This fixes the case where
backtrace() went directly to the console and should help debugging greatly.
Thanks to Ian Dowse for the work, minor edits or any bugs are by myself.

Submitted by:	iedowse
2004-01-28 06:51:18 +00:00
Bruce Evans
f8191f94aa Reworked rev.1.14. Use the ELF symbol type again to summarily reject
some symbols in X_db_search_symbol().  Reject the same symbols that
rev.1.13 did (all except STT_OBJECT and STT_FUNC), except don't reject
typeless symbols.  This keeps the typeless symbols in non-verbosely
written assembler code visible, but makes file symbols invisible.  ELF
file symbols have type STT_FILE and value 0, so this stops small values
and offsets sometimes being displayed in terms of the first file symbol
in the kernel (usually device_if.c).  I think it rejects some other
unwanted symbols (small absolute symbols for things like struct offsets).
It may reject some wanted symbols (large absolute symbols for addresses
like PTmap).
2003-09-28 06:02:33 +00:00
Poul-Henning Kamp
71b797c176 Label the uarea address as such in DDB's ps output 2003-08-30 19:06:57 +00:00
Marcel Moolenaar
26502503e5 Further cleanup <machine/cpu.h> and <machine/md_var.h>: move the MI
prototypes of cpu_halt(), cpu_reset() and swi_vm() from md_var.h to
cpu.h. This affects db_command.c and kern_shutdown.c.

ia64: move all MD prototypes from cpu.h to md_var.h. This affects
madt.c, interrupt.c and mp_machdep.c. Remove is_physical_memory().
It's not used (vm_machdep.c).

alpha: the MD prototypes have been left in cpu.h with a comment
that they should be there. Moving them is left for later. It was
expected that the impact would be significant enough to be done in
a seperate commit.

powerpc: MD prototypes left in cpu.h. Comment added.

Suggested by: bde
Tested with: make universe (pc98 incomplete)
2003-08-16 16:57:57 +00:00
Hartmut Brandt
0ddc915c01 db_get_value uses a local buffer to first fetch all the bytes of a
integer value and then to construct the integer from it. This buffer
was sizeof(int) bytes long, which was fine until the (undocumented) 'g'
modifier for 8-byte integers was introduced. Change this to sizeof(uint64_t).
2003-08-12 13:24:21 +00:00
John Baldwin
3f2a1b0656 Update the 'ps', 'show pci', and 'show ktr' ddb commands to use the new
pager callout instead of homerolling their own paging facility.
2003-07-31 17:29:42 +00:00
John Baldwin
1e16f6098b Add a one-shot callout facility to db_printf() that executes the registered
callout when a specified number of lines have been output.  This can be
used to implement pagers for ddb commands that output a lot of text.  A
simple paging function is included that automatically rearms itself when
fired.

Reviewed by:	bde, julian
2003-07-31 17:27:52 +00:00
John Baldwin
cb075651f8 Whitespace nit. 2003-07-30 20:59:36 +00:00
David Xu
0e2a4d3aeb Rename P_THREADED to P_SA. P_SA means a process is using scheduler
activations.
2003-06-15 00:31:24 +00:00
David E. O'Brien
753960f7c4 Use __FBSDID(). 2003-06-10 22:09:23 +00:00
Julian Elischer
b410626185 Attempt to crunch down the thread state info so that it is more likely to
fit on one line. Account for threads better.

* No need to report that it is on a sleep queue if it is actually sleeping
* "Normal" state is almost ubiquitous.. only report abnormal states.
* increment the #lines count for each separate thread shown in threaded
  programs.

makes it less likely that a threaded program will make all the data
on a screen overflow off the top of the screen.
2003-06-06 20:28:11 +00:00
John Baldwin
a85b6f827b Handle the TDS_INACTIVE state by printing '[INACTIVE]' instead of
panic'ing.  Also, for unknown thread states, print out the value rather
than panic.  Panic'ing in the debugger is pointless at best.
2003-06-06 17:20:47 +00:00
John Baldwin
ac39898e7e Whitespace nits. 2003-06-06 17:19:27 +00:00
Poul-Henning Kamp
04361c8c3a Make "where" an alias for "trace" 2003-06-01 09:06:23 +00:00
Poul-Henning Kamp
bd961794c3 Add /* FALLTHROUGH */
Found by:       FlexeLint
2003-05-31 20:43:47 +00:00
Poul-Henning Kamp
9a4b535c7a Add /* FALLTHROUGH */
Found by:       FlexeLint
2003-05-31 19:00:02 +00:00