aboutsummaryrefslogtreecommitdiff
path: root/sys/ddb
Commit message (Collapse)AuthorAgeFilesLines
* ddb ps: Print again the effective GID, separatelyOlivier Certner2025-09-091-6/+5
| | | | | | | | | | | | Following commit be1f7435ef218b1d ("kern: start tracking cr_gid outside of cr_groups[]"), cr_groups[] doesn't contain the effective GID anymore. Fix the 'show proc' DDB command to show it again, and make it stand out with respect to the supplementary ones. Fixes: be1f7435ef218b1d ("kern: start tracking cr_gid outside of cr_groups[]") MFC after: 9 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D52251
* machine/stdarg.h -> sys/stdarg.hBrooks Davis2025-06-112-4/+2
| | | | | | | | | | | | | Switch to using sys/stdarg.h for va_list type and va_* builtins. Make an attempt to insert the include in a sensible place. Where style(9) was followed this is easy, where it was ignored, aim for the first block of sys/*.h headers and don't get too fussy or try to fix other style bugs. Reviewed by: imp Exp-run by: antoine (PR 286274) Pull Request: https://github.com/freebsd/freebsd-src/pull/1595
* proc: Remove kernel stack swapping support, part 6Mark Johnston2024-07-293-15/+4
| | | | | | | | | | | | - Remove most checks of the P_INMEM flag. - Some uses remain since a few userspace tools, e.g., ps(1) and top(1) expect the flag to be set. These can be cleaned up but the code has most likely been copy-pasted elsewhere and while linger for a long time. Tested by: pho Reviewed by: alc, imp, kib Differential Revision: https://reviews.freebsd.org/D46117
* thread: Remove kernel stack swapping support, part 4Mark Johnston2024-07-291-8/+0
| | | | | | | | | | | - Remove the IS_SWAPPED thread inhibitor state. - Remove all uses of TD_IS_SWAPPED() in the kernel. - Remove the TDF_CANSWAP flag. - Remove the P_SWAPPINGOUT and P_SWAPPINGIN flags. Tested by: pho Reviewed by: alc, imp, kib Differential Revision: https://reviews.freebsd.org/D46115
* db_pprint: Properly handle complex pointer typesBojan Novković2024-07-211-8/+30
| | | | | | | | | The existing pretty-printing code fails to properly print complex pointer types. This commit fixes this behaviour by traversing the chain of CTF types until a base type is encountered. Approved by: markj (mentor) Fixes: c21bc6f3c242
* db_pprint: Fix offset calculation for struct membersBojan Novković2024-07-211-2/+2
| | | | | | | | | | | The struct pretty-printing code uses the ctm_offset field in struct ctf_member_v3 to calculate the address of a struct member. However, the code treats this as a byte offset rather than the offset in bits, leading to wrong values being printed. Fix this by diving with ctm_offset by NBBY. Approved by: markj (mentor) Fixes: c21bc6f3c242
* ddb: make db_error reliably no-returnRyan Libby2024-07-092-1/+2
| | | | | | | | | | | Most code assumes db_error does not return, but according to kdb_reenter_silent, there may be cases where it could. Instead, panic if kdb_reenter_silent returns and mark the routine as __dead2. This addresses gcc warnings. Reported by: GCC -Wmaybe-uninitialized Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D45918
* sys/ddb: Add hardware breakpoint support to ddbAndrew Turner2024-04-123-8/+99
| | | | | | | | | | | | As with hardware watchpoints add support for hardware breakpoints. The command is only enabled on architectures that report support for them. Currently no architectures do, however arm64 will add support in a future change. Reviewed by: jhb (earlier version) Sponsored by: Arm Ltd Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D22191
* ddb: Start to generalise breakpointsAndrew Turner2024-04-121-34/+56
| | | | | | | | | To allow for hardware breakpoints it is useful to reuse the same management code. Start to generalise the code by moving common data into a new struct and pas this to internal functions to work with. Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D44461
* ddb: Fix format string errors in db_pprint.cMark Johnston2024-04-031-2/+2
| | | | | Reported by: bapt Fixes: aada453dcbaa ("ddb: Properly pretty-print non-labeled enum values")
* ddb: Don't throw away qualifier when pretty-printing unnamed pointersBojan Novković2024-04-031-1/+1
| | | | | | Reported by: jrtc27 Fixes: c21bc6f ("ddb: Add CTF-based pretty printing") Approved by: markj (mentor)
* ddb: Properly pretty-print non-labeled enum valuesBojan Novković2024-04-031-5/+6
| | | | | | | | | | The ddb pretty-printer currently does not print out enum values that are not labeled (e.g. X | Y). The enum printer was reworked to print non-labeled values. Reported by: jrtc27 Fixes: c21bc6f ("ddb: Add CTF-based pretty printing") Approved by: markj (mentor)
* ddb: Drop obsolete -FreeBSD identifier from licenseBojan Novković2024-03-283-3/+3
| | | | | | Reported by: jrtc27 Fixes: c21bc6f3c242 ("ddb: Add CTF-based pretty printing") Approved by: markj (mentor)
* ddb: Fix format string errors in db_pprint.cMark Johnston2024-03-221-6/+6
| | | | | | | | | For some reason, db_expr_t is defined as "long" on 64-bit platforms and "int" on others. When printing values of this type, simply cast them to long to suppress compilation errors on 32-bit systems. Reviewed by: bnovkov Fixes: c21bc6f3c242 ("ddb: Add CTF-based pretty printing")
* ddb: Add CTF-based pretty printingBojan Novković2024-03-225-0/+842
| | | | | | | | | | | | | | | | | | | | Add basic CTF support and a CTF-powered pretty-printer to ddb. The db_ctf.* files expose a basic interface for fetching type data for ELF symbols, interacting with the CTF string table, and translating type identifiers to type data. The db_pprint.c file uses those interfaces to implement a pretty-printer for all kernel ELF symbols. The pretty-printer works with symbol names and arbitrary addresses: pprint struct thread 0xffffffff8194ad90 Pretty-printing currently only works after the root filesystem gets mounted because the CTF info is not available during early boot. Differential Revision: https://reviews.freebsd.org/D37899 Approved by: markj (mentor)
* ddb: Fix typo (triple S)Jose Luis Duran2023-12-281-1/+1
| | | | | Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/955
* sys: Automated cleanup of cdefs and other formattingWarner Losh2023-11-2715-15/+0
| | | | | | | | | | | | | | | | Apply the following automated changes to try to eliminate no-longer-needed sys/cdefs.h includes as well as now-empty blank lines in a row. Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/ Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/ Remove /\n+#if.*\n#endif.*\n+/ Remove /^#if.*\n#endif.*\n/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/ Sponsored by: Netflix
* ddb: Add sysctl flag CTLFLAG_TUN to loader tunableZhenlei Huang2023-10-091-2/+2
| | | | | | | | | | | | The sysctl variable 'debug.ddb.capture.bufsize' is actually a loader tunable. Add sysctl flag CTLFLAG_TUN to it so that `sysctl -T` will report it correctly. No functional change intended. Reviewed by: kib, imp MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D42113
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-1620-40/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-169-18/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* ddb: Rework macros to make it easier to add new command tables.John Baldwin2023-07-051-36/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | - Add new DB_DEFINE_TABLE and DB_DECLARE_TABLE macros to define new command tables. DB_DECLARE_TABLE is intended for use in headers similar to MALLOC_DECLARE and SYSCTL_DECL. DB_DEFINE_TABLE takes three arguments, the name of the parent table, the command name, and the name of the table itself, e.g. DB_DEFINE_TABLE(show, foo, show_foo) defines a new "show foo" table. - DB_TABLE_COMMAND, DB_TABLE_COMMAND_FLAGS, DB_TABLE_ALIAS, and DB_ALIAS_FLAGS allow new commands and aliases to be defined. These are similar to the existing DB_COMMAND, etc. except that they take an initial argument giving the name of the parent table, e.g.: DB_TABLE_COMMAND(show_foo, bar, db_show_foo_bar) defines a new "show foo bar" command. This provides a cleaner interface than the ad-hoc use of internal macros like _DB_SET that was required previously (e.g. in cxgbe(4)). This retires DB_FUNC macro as well as the internal _DB_FUNC macro. Reviewed by: melifaro, kib, markj Differential Revision: https://reviews.freebsd.org/D40819
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-124-4/+4
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* ddb: ansifyMateusz Guzik2023-02-081-14/+5
| | | | | Reported by: clang 15 Sponsored by: Rubicon Communications, LLC ("Netgate")
* Move kstack_contains() and GET_STACK_USAGE() to MD machine/stack.hKonstantin Belousov2023-02-011-0/+2
| | | | | | | Reviewed by: jhb Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D38320
* ddb: have 'reset' command use normal reboot pathMitchell Horne2023-01-231-1/+13
| | | | | | | | | | | | | | | | | | This conditionally gives all registered shutdown handlers a chance to perform the reboot, with cpu_reset() being the fallback. The '\s' modifier can be used with the command to get the previous behaviour. The motivation is that some platforms may not be able do anything meaningful via cpu_reset(), due to a lack of standardized reset mechanism and/or firmware shortcomings. However, they may have a separate device driver attached that normally performs the reboot. Such is the case for some versions of the Raspberry Pi, where reset via PSCI fails, but the BCM2835 watchdog driver has a shutdown hook. Reported by: bz Reviewed by: markj (slightly earlier version) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D37981
* ddb: Don't flag breakpoint/watchpoint commands as MEMSAFEMark Johnston2022-11-021-8/+8
| | | | | | | | | | | They could potentially be abused to overwrite kernel memory, so shouldn't be accessible when mac_ddb is loaded. Reviewed by: mhorne Fixes: bc4ea61d55cb ("ddb: tag core commands with DB_CMD_MEMSAFE") Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D37105
* ddb: print the actual syscall nameMitchell Horne2022-10-282-14/+6
| | | | | | | | | | | | | | | | | | | | | Some architectures will pretty-print a system call trap in the backtrace. Rather than printing the symbol, use the syscallname() function to pull the string from the sv_syscallnames array corresponding to the process. This simplifies the function somewhat. Mostly, this will result in dropping the "sys" prefix, e.g. "sys_exit" will now be printed simply as "exit". Make two minor tweaks to the function signature: use a u_int for the syscall number since this is a more correct type (see the 'code' member of struct syscall_args), and make the thread pointer the first argument. The latter is more natural and conventional. Suggested by: jrtc27 Reviewed by: jrtc27, markj, jhb MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D37200
* Fix kernel build after 754cb545b68ba0a1643792763d000018ffe2afec .Hans Petter Selasky2022-10-041-0/+1
| | | | | | | | By adding missing include file for powerpc64, QORIQ64. Differential Revision: https://reviews.freebsd.org/D36565 MFC after: 1 week Sponsored by: NVIDIA Networking
* db_sym.c: restore sys/systm.h includeMitchell Horne2022-10-031-0/+1
| | | | | | | This was erroneously dropped in the previous commit. Reported by: Jenkins Fixes: 754cb545b68b ("ddb: de-duplicate decode_syscall()")
* ddb: de-duplicate decode_syscall()Mitchell Horne2022-10-032-1/+25
| | | | | | | | | | Only i386 and amd64 print the decoded syscall name in the backtrace. This de-duplication facilitates further changes and adoption by other platforms. Reviewed by: jrtc27, markj, jhb MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D36565
* Adjust db_flush_line() definition to avoid clang 15 warningDimitry Andric2022-07-191-1/+1
| | | | | | | | | | | | | | | With clang 15, the following -Werror warnings is produced: sys/ddb/db_lex.c:94:14: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes] db_flush_line() ^ void This is because db_flush_line() is declared with a (void) argument list, but defined with an empty argument list. Make the definition match the declaration. MFC after: 3 days
* mac: add new mac_ddb(4) policyMitchell Horne2022-07-181-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Generally, access to the kernel debugger is considered to be unsafe from a security perspective since it presents an unrestricted interface to inspect or modify the system state, including sensitive data such as signing keys. However, having some access to debugger functionality on production systems may be useful in determining the cause of a panic or hang. Therefore, it is desirable to have an optional policy which allows limited use of ddb(4) while disabling the functionality which could reveal system secrets. This loadable MAC module allows for the use of some ddb(4) commands while preventing the execution of others. The commands have been broadly grouped into three categories: - Those which are 'safe' and will not emit sensitive data (e.g. trace). Generally, these commands are deterministic and don't accept arguments. - Those which are definitively unsafe (e.g. examine <addr>, search <addr> <value>) - Commands which may be safe to execute depending on the arguments provided (e.g. show thread <addr>). Safe commands have been flagged as such with the DB_CMD_MEMSAFE flag. Commands requiring extra validation can provide a function to do so. For example, 'show thread <addr>' can be used as long as addr can be checked against the system's list of process structures. The policy also prevents debugger backends other than ddb(4) from executing, for example gdb(4). Reviewed by: markj, pauamma_gundo.com (manpages) Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D35371
* mac: kdb/ddb framework hooksMitchell Horne2022-07-182-0/+19
| | | | | | | | | | | | | | | | Add three simple hooks to the debugger allowing for a loaded MAC policy to intervene if desired: 1. Before invoking the kdb backend 2. Before ddb command registration 3. Before ddb command execution We extend struct db_command with a private pointer and two flag bits reserved for policy use. Reviewed by: markj Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D35370
* ddb: tag core commands with DB_CMD_MEMSAFEMitchell Horne2022-07-181-39/+39
| | | | | | | | Those which are statically defined in db_command.c. Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D35584
* ddb: annotate some commands with DB_CMD_MEMSAFEMitchell Horne2022-07-182-2/+2
| | | | | | | | | | This is not completely exhaustive, but covers a large majority of commands in the tree. Reviewed by: markj Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D35583
* ddb: add the DB_CMD_MEMSAFE flag for commandsMitchell Horne2022-07-181-6/+10
| | | | | | | | | | | | | | | | | | This flag value can be used to indicate if a command has the property of being "memory safe". In this instance, memory safe means that the command does not allow/enable reads or writes of arbitrary memory, regardless of the arguments passed to it. For example, 'backtrace' is considered a memory-safe command since its output is deterministic, while 'show vnode' is not, since it requires a memory address as an argument and will print the contents beginning at that location. Apply the flag to the "show all" command macros. It is expected that commands added to this table will always exhibit this property. Reviewed by: markj Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D35581
* ddb: add _FLAGS command variantsMitchell Horne2022-07-051-4/+12
| | | | | | | | | | | | Provide _FLAGS variants of the various command definition macros, in anticipation of adding a new flag. This can also be used for some existing commands which require special flag values. Reviewed by: markj MFC after: 3 days Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D35581
* db_command.c: use designated initializersMitchell Horne2022-07-051-57/+70
| | | | | | | | | | | | | Provide separate helper macros for regular commands and next-level table commands as they are mutually exclusive. This ensures proper initialization of each element and allows us to exclude some redundant fields, such as specifying .more = NULL for every regular command. Reviewed by: markj, jhb MFC after: 3 days Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D35580
* db_command.c: styleMitchell Horne2022-07-051-153/+141
| | | | | | | | Reviewed by: jhb MFC after: 3 days Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D35368
* ddb: namespacing of struct commandMitchell Horne2022-06-142-39/+42
| | | | | | | | | | | | 'command' is too generic for something specific to the kernel debugger; change this so it is less likely to collide with local variable names. Also rename struct command_table to struct db_command_table. Reviewed by: markj MFC after: 1 week Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D35367
* kerneldump: remove physical from dump routinesMitchell Horne2022-05-131-2/+2
| | | | | | | | | It is unused, especially now that the underlying d_dumper methods do not accept the argument. Reviewed by: markj MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D35174
* ddb: Remove SOFTWARE_SSTEP supportWarner Losh2022-01-073-149/+0
| | | | | | | It was needed for mips only, and only kinda sorta worked for mips. It can be brought back if we grow another architecture that need it. Sponsored by: Netflix
* sys/ddb: Use C99 fixed-width integer types.John Baldwin2021-12-281-1/+1
| | | | | | | No functional change. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D33634
* Create sys/reg.h for the common code previously in machine/reg.hAndrew Turner2021-08-301-0/+1
| | | | | | | | | | Move the common kernel function signatures from machine/reg.h to a new sys/reg.h. This is in preperation for adding PT_GETREGSET to ptrace(2). Reviewed by: imp, markj Sponsored by: DARPA, AFRL (original work) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D19830
* fix style nit: space after ifWarner Losh2021-05-051-2/+2
|
* ddb: replace watchpoint set/clear functionsMitchell Horne2021-03-292-16/+41
| | | | | | | | | | Use the new kdb variants. Print more specific error messages. Reviewed by: jhb, markj MFC after: 3 weeks Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D29156
* ddb: enable the use of ^C and ^S/^QRyan Libby2021-03-143-22/+103
| | | | | | | | | | | | | | | | | | | | | | | | This lets one interrupt DDB's output, which is useful if paging is disabled and the output device is slow. This follows a previous implementation in svn r311952 / git 5fddef79998678d256ba30316353393b4d8ebb32 which was reverted because it broke DDB type-ahead. Now, try this again, but with a 512-byte type-ahead buffer. While there is buffer space, control input is handled and non-control input is buffered. When the buffer is exhausted, the default is to print a warning and drop further non-control input in order to continue handling control input. sysctl debug.ddb.prioritize_control_input can be set to 0 to instead preserve all input but lose immediate handling of control input. This could for example effect pasting of a large script into the ddb console. Suggested by: Anton Rang <rang@acm.org> Reviewed by: markj Discussed with: imp Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D28676
* ddb: just move cursor when the lexer backs upRyan Libby2021-02-241-11/+16
| | | | | | | | | | | | | | | Get rid of db_look_char because it's not compatible with db_get_line(). This fixes the following issue: db> script lockinfo=show alllocks db> run lockinfo db:0:lockinfo> how alllocks No such command; use "help" to list available commands Reported by: markj Reviewed by: markj Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D28725
* ddb: reliably fail with ambiguous commandsRyan Libby2021-02-241-1/+1
| | | | | | | | | | | | db_cmd_match had an even/odd bug, where if a third command was partially matched (or any odd number greater than one) the search result would be set back from CMD_AMBIGUOUS to CMD_FOUND, causing the last command in the list to be executed instead of failing the match. Reported by: mlaier Reviewed by: markj, mlaier, vangyzen Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D28659
* Use atomic loads/stores when updating td->td_stateAlex Richardson2021-02-182-7/+7
| | | | | | | | | | | | | | | KCSAN complains about racy accesses in the locking code. Those races are fine since they are inside a TD_SET_RUNNING() loop that expects the value to be changed by another CPU. Use relaxed atomic stores/loads to indicate that this variable can be written/read by multiple CPUs at the same time. This will also prevent the compiler from doing unexpected re-ordering. Reported by: GENERIC-KCSAN Test Plan: KCSAN no longer complains, kernel still runs fine. Reviewed By: markj, mjg (earlier version) Differential Revision: https://reviews.freebsd.org/D28569