xref: /freebsd/share/man/man9/DB_COMMAND.9 (revision 4b9d6057)
1.\"-
2.\" Copyright (c) 2008 Guillaume Ballet
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.Dd July 5, 2023
27.Dt DB_COMMAND 9
28.Os
29.Sh NAME
30.Nm DB_COMMAND ,
31.Nm DB_COMMAND_FLAGS ,
32.Nm DB_SHOW_COMMAND ,
33.Nm DB_SHOW_COMMAND_FLAGS ,
34.Nm DB_SHOW_ALL_COMMAND ,
35.Nm DB_TABLE_COMMAND ,
36.Nm DB_TABLE_COMMAND_FLAGS ,
37.Nm DB_ALIAS ,
38.Nm DB_ALIAS_FLAGS ,
39.Nm DB_SHOW_ALIAS ,
40.Nm DB_SHOW_ALIAS_FLAGS ,
41.Nm DB_SHOW_ALL_ALIAS ,
42.Nm DB_TABLE_ALIAS ,
43.Nm DB_TABLE_ALIAS_FLAGS
44.Nm DB_DECLARE_TABLE ,
45.Nm DB_DEFINE_TABLE ,
46.Nd Extends the ddb command set
47.Sh SYNOPSIS
48.In ddb/ddb.h
49.Fn DB_COMMAND "command_name" "command_function"
50.Fn DB_COMMAND_FLAGS "command_name" "command_function" "flags"
51.Fn DB_SHOW_COMMAND "command_name" "command_function"
52.Fn DB_SHOW_COMMAND_FLAGS "command_name" "command_function" "flags"
53.Fn DB_SHOW_ALL_COMMAND "command_name" "command_function"
54.Fn DB_TABLE_COMMAND "table" "command_name" "command_function"
55.Fn DB_TABLE_COMMAND_FLAGS "table" "command_name" "command_function" "flags"
56.Fn DB_ALIAS "alias_name" "command_function"
57.Fn DB_ALIAS_FLAGS "alias_name" "command_function" "flags"
58.Fn DB_SHOW_ALIAS "alias_name" "command_function"
59.Fn DB_SHOW_ALIAS_FLAGS "alias_name" "command_function" "flags"
60.Fn DB_SHOW_ALL_ALIAS "alias_name" "command_function"
61.Fn DB_TABLE_ALIAS "table" "alias_name" "command_function"
62.Fn DB_TABLE_ALIAS_FLAGS "table" "alias_name" "command_function" "flags"
63.Fn DB_DEFINE_TABLE "parent" "name" "table"
64.Fn DB_DECLARE_TABLE "table"
65.Sh DESCRIPTION
66The
67.Fn DB_COMMAND
68macro adds
69.Fa command_name
70to the list of top-level commands.
71Invoking
72.Fa command_name
73from ddb will call
74.Fa command_function .
75.Pp
76The
77.Fn DB_SHOW_COMMAND
78and
79.Fn DB_SHOW_ALL_COMMAND
80macros are roughly equivalent to
81.Fn DB_COMMAND
82but in these cases,
83.Fa command_name
84is a sub-command of the ddb
85.Sy show
86command and
87.Sy show all
88command, respectively.
89.Pp
90The
91.Fn DB_TABLE_COMMAND
92macro is also similar to
93.Fn DB_COMMAND
94but adds the new command as a sub-command of the ddb command
95.Fa table .
96.Pp
97The
98.Fn DB_ALIAS ,
99.Fn DB_SHOW_ALIAS ,
100.Fn DB_SHOW_ALL_ALIAS ,
101and
102.Fn DB_TABLE_ALIAS
103macros register the existing
104.Fa command_function
105under the alternative command name
106.Fa alias_name .
107.Pp
108The _FLAGS variants of these commands allow the programmer to specify a value
109for the
110.Fa flag
111field of the command structure.
112The possible flag values are defined alongside
113.Ft struct db_command
114in
115.In ddb/ddb.h .
116.Pp
117The general command syntax:
118.Cm command Ns Op Li \&/ Ns Ar modifier
119.Ar address Ns Op , Ns Ar count ,
120translates into the following parameters for
121.Fa command_function :
122.Bl -tag -width Fa -offset indent
123.It Fa addr
124The address passed to the command as an argument.
125.It Fa have_addr
126A boolean value that is true if the addr field is valid.
127.It Fa count
128The number of quad words starting at offset
129.Fa addr
130that the command must process.
131.It Fa modif
132A pointer to the string of modifiers.
133That is, a series of symbols used to pass some options to the command.
134For example, the
135.Sy examine
136command will display words in decimal form if it is passed the modifier "d".
137.El
138.Pp
139The
140.Fn DB_DEFINE_TABLE
141macro adds a new command
142.Fa name
143as a sub-command of the existing command table
144.Fa parent .
145The new command defines a table named
146.Fa table
147which contains sub-commands.
148New commands and aliases can be added to this table by passing
149.Fa table
150as the first argument to one of the DB_TABLE_ macros.
151.Sh EXAMPLES
152In your module, the command is declared as:
153.Bd -literal
154DB_COMMAND(mycmd, my_cmd_func)
155{
156	if (have_addr)
157		db_printf("Calling my command with address %p\\n", addr);
158}
159.Ed
160.Pp
161An alias for this command is declared as:
162.Bd -literal
163DB_ALIAS(mycmd2, my_cmd_func);
164.Ed
165.Pp
166Then, when in ddb:
167.Bd -literal
168.Bf Sy
169db> mycmd 0x1000
170Calling my command with address 0x1000
171db> mycmd2 0x2500
172Calling my command with address 0x2500
173db>
174.Ef
175.Ed
176.Sh SEE ALSO
177.Xr ddb 4
178.Sh AUTHORS
179This manual page was written by
180.An Guillaume Ballet Aq Mt gballet@gmail.com .
181