System Administration Commands adbgen(1M)
NAME
adbgen - generate adb script
SYNOPSIS
/usr/lib/adb/adbgen [-m model] filename.adb ...
DESCRIPTION
adbgen makes it possible to write adb(1) scripts that do not
contain hard-coded dependencies on structure member offsets.
The input to adbgen is a file named filename.adb that con-
tains header information, then a null line, then the name ofa structure, and finally an adb script. adbgen only deals
with one structure per file; all member names are assumed tobe in this structure. The output of adbgen is an adb script
in filename. adbgen operates by generating a C program which
determines structure member offsets and sizes, which in turn generate the adb script. The header lines, up to the null line, are copied verbatiminto the generated C program. Typically, these are #include
statements, which include the headers containing the relevant structure declarations. The adb script part may contain any valid adb commands (seeadb(1)), and may also contain adbgen requests, each enclosed
in braces ({}). Request types are: o Print a structure member. The request form is {member,format}. member is a member name of the structure given earlier, and format is any validadb format request or any of the adbgen format
specifiers (such as {POINTER}) listed below. Forexample, to print the p_pid field of the proc
structure as a decimal number, you would write{p_pid,d}.
o Print the appropriate adb format character for thegiven adbgen format specifier. This action takes
the data model into consideration. The request formis {format specifier}. The valid adbgen format
specifiers are: {POINTER} pointer value in hexadecimal {LONGDEC} long value in decimalSunOS 5.11 Last change: 20 Feb 1998 1
System Administration Commands adbgen(1M)
{ULONGDEC} unsigned long value in decimal {ULONGHEX} unsigned long value in hexadecimal {LONGOCT} long value in octal {ULONGOCT} unsigned long value in octal o Reference a structure member. The request form is {*member,base}. member is the member name whose value is desired, and base is an adb register name which contains the base address of the structure.For example, to get the p_pid field of the proc
structure, you would get the proc structure address in an adb register, for example{*p_pid,
o Tell adbgen that the offset is valid. The request
form is {OFFSETOK}. This is useful after invoking another adb script which moves the adb dot. o Get the size of the structure. The request form is{SIZEOF}. adbgen replaces this request with the
size of the structure. This is useful in increment-
ing a pointer to step through an array of struc-
tures. o Calculate an arbitrary C expression. The requestform is {EXPR,expression}. adbgen replaces this
request with the value of the expression. This is useful when more than one structure is involved in the script. o Get the offset to the end of the structure. The request form is {END}. This is useful at the end of the structure to get adb to align the dot for printing the next structure member.adbgen keeps track of the movement of the adb dot and gen-
erates adb code to move forward or backward as necessarybefore printing any structure member in a script. adbgen's
model of the behavior of adb's dot is simple: it is assumed that the first line of the script is of the formstruct_address/adb text and that subsequent lines are of the
form +/adb text. The adb dot then moves in a sane fashion.adbgen does not check the script to ensure that these
SunOS 5.11 Last change: 20 Feb 1998 2
System Administration Commands adbgen(1M)
limitations are met. adbgen also checks the size of the
structure member against the size of the adb format code and warns if they are not equal. OPTIONS The following option is supported:-m model Specifies the data type model to be used by
adbgen for the macro. This affects the outcome
of the {format specifier} requests describedunder DESCRIPTION and the offsets and sizes of
data types. model can be ilp32 or lp64. If the-m option is not given, the data type model
defaults to ilp32. OPERANDS The following operand is supported:filename.adb Input file that contains header informa-
tion, followed by a null line, the name of the structure, and finally an adb script.EXAMPLES
Example 1 A sample adbgen file.
For an include file x.h which contained struct x {char *x_cp;
char x_c;
int x_i;
};then , an adbgen file (call it script.adb) to print the file
x.h would be:#include "x.h"
x./"x_cp"16t"x_c"8t"x_i"n{x_cp,{POINTER}}{x_c,C}{x_i,D}
SunOS 5.11 Last change: 20 Feb 1998 3
System Administration Commands adbgen(1M)
After running adbgen as follows,
% /usr/lib/adb/adbgen script.adb
the output file script contains:./"x_cp"16t"x_c"8t"x_i"nXC3+D
For a macro generated for a 64-bit program using the lp64
data model as follows,% /usr/lib/adb/adbgen/ -m lp64 script.adb
the output file script would contain:./"x_cp"16t"x_c"8t"x_i"nJC3+D
To invoke the script, type:example% adb program
x$