==>'
1033 |
|
|
`
|
1034 |
|
|
|
1035 |
|
|
`
|
1036 |
|
|
`{ }'
|
1037 |
|
|
|
1038 |
|
|
` ==>'
|
1039 |
|
|
` '
|
1040 |
|
|
|
1041 |
|
|
` ==>'
|
1042 |
|
|
`{}'
|
1043 |
|
|
|
1044 |
|
|
4.2.2 General Conventions
|
1045 |
|
|
-------------------------
|
1046 |
|
|
|
1047 |
|
|
Most `ui_out' routines are of type `void', the exceptions are
|
1048 |
|
|
`ui_out_stream_new' (which returns a pointer to the newly created
|
1049 |
|
|
object) and the `make_cleanup' routines.
|
1050 |
|
|
|
1051 |
|
|
The first parameter is always the `ui_out' vector object, a pointer
|
1052 |
|
|
to a `struct ui_out'.
|
1053 |
|
|
|
1054 |
|
|
The FORMAT parameter is like in `printf' family of functions. When
|
1055 |
|
|
it is present, there must also be a variable list of arguments
|
1056 |
|
|
sufficient used to satisfy the `%' specifiers in the supplied format.
|
1057 |
|
|
|
1058 |
|
|
When a character string argument is not used in a `ui_out' function
|
1059 |
|
|
call, a `NULL' pointer has to be supplied instead.
|
1060 |
|
|
|
1061 |
|
|
4.2.3 Table, Tuple and List Functions
|
1062 |
|
|
-------------------------------------
|
1063 |
|
|
|
1064 |
|
|
This section introduces `ui_out' routines for building lists, tuples
|
1065 |
|
|
and tables. The routines to output the actual data items (fields) are
|
1066 |
|
|
presented in the next section.
|
1067 |
|
|
|
1068 |
|
|
To recap: A "tuple" is a sequence of "fields", each field containing
|
1069 |
|
|
information about an object; a "list" is a sequence of fields where
|
1070 |
|
|
each field describes an identical object.
|
1071 |
|
|
|
1072 |
|
|
Use the "table" functions when your output consists of a list of
|
1073 |
|
|
rows (tuples) and the console output should include a heading. Use this
|
1074 |
|
|
even when you are listing just one object but you still want the header.
|
1075 |
|
|
|
1076 |
|
|
Tables can not be nested. Tuples and lists can be nested up to a
|
1077 |
|
|
maximum of five levels.
|
1078 |
|
|
|
1079 |
|
|
The overall structure of the table output code is something like
|
1080 |
|
|
this:
|
1081 |
|
|
|
1082 |
|
|
ui_out_table_begin
|
1083 |
|
|
ui_out_table_header
|
1084 |
|
|
...
|
1085 |
|
|
ui_out_table_body
|
1086 |
|
|
ui_out_tuple_begin
|
1087 |
|
|
ui_out_field_*
|
1088 |
|
|
...
|
1089 |
|
|
ui_out_tuple_end
|
1090 |
|
|
...
|
1091 |
|
|
ui_out_table_end
|
1092 |
|
|
|
1093 |
|
|
Here is the description of table-, tuple- and list-related `ui_out'
|
1094 |
|
|
functions:
|
1095 |
|
|
|
1096 |
|
|
-- Function: void ui_out_table_begin (struct ui_out *UIOUT, int
|
1097 |
|
|
NBROFCOLS, int NR_ROWS, const char *TBLID)
|
1098 |
|
|
The function `ui_out_table_begin' marks the beginning of the output
|
1099 |
|
|
of a table. It should always be called before any other `ui_out'
|
1100 |
|
|
function for a given table. NBROFCOLS is the number of columns in
|
1101 |
|
|
the table. NR_ROWS is the number of rows in the table. TBLID is
|
1102 |
|
|
an optional string identifying the table. The string pointed to
|
1103 |
|
|
by TBLID is copied by the implementation of `ui_out_table_begin',
|
1104 |
|
|
so the application can free the string if it was `malloc'ed.
|
1105 |
|
|
|
1106 |
|
|
The companion function `ui_out_table_end', described below, marks
|
1107 |
|
|
the end of the table's output.
|
1108 |
|
|
|
1109 |
|
|
-- Function: void ui_out_table_header (struct ui_out *UIOUT, int
|
1110 |
|
|
WIDTH, enum ui_align ALIGNMENT, const char *COLHDR)
|
1111 |
|
|
`ui_out_table_header' provides the header information for a single
|
1112 |
|
|
table column. You call this function several times, one each for
|
1113 |
|
|
every column of the table, after `ui_out_table_begin', but before
|
1114 |
|
|
`ui_out_table_body'.
|
1115 |
|
|
|
1116 |
|
|
The value of WIDTH gives the column width in characters. The
|
1117 |
|
|
value of ALIGNMENT is one of `left', `center', and `right', and it
|
1118 |
|
|
specifies how to align the header: left-justify, center, or
|
1119 |
|
|
right-justify it. COLHDR points to a string that specifies the
|
1120 |
|
|
column header; the implementation copies that string, so column
|
1121 |
|
|
header strings in `malloc'ed storage can be freed after the call.
|
1122 |
|
|
|
1123 |
|
|
-- Function: void ui_out_table_body (struct ui_out *UIOUT)
|
1124 |
|
|
This function delimits the table header from the table body.
|
1125 |
|
|
|
1126 |
|
|
-- Function: void ui_out_table_end (struct ui_out *UIOUT)
|
1127 |
|
|
This function signals the end of a table's output. It should be
|
1128 |
|
|
called after the table body has been produced by the list and
|
1129 |
|
|
field output functions.
|
1130 |
|
|
|
1131 |
|
|
There should be exactly one call to `ui_out_table_end' for each
|
1132 |
|
|
call to `ui_out_table_begin', otherwise the `ui_out' functions
|
1133 |
|
|
will signal an internal error.
|
1134 |
|
|
|
1135 |
|
|
The output of the tuples that represent the table rows must follow
|
1136 |
|
|
the call to `ui_out_table_body' and precede the call to
|
1137 |
|
|
`ui_out_table_end'. You build a tuple by calling `ui_out_tuple_begin'
|
1138 |
|
|
and `ui_out_tuple_end', with suitable calls to functions which actually
|
1139 |
|
|
output fields between them.
|
1140 |
|
|
|
1141 |
|
|
-- Function: void ui_out_tuple_begin (struct ui_out *UIOUT, const char
|
1142 |
|
|
*ID)
|
1143 |
|
|
This function marks the beginning of a tuple output. ID points to
|
1144 |
|
|
an optional string that identifies the tuple; it is copied by the
|
1145 |
|
|
implementation, and so strings in `malloc'ed storage can be freed
|
1146 |
|
|
after the call.
|
1147 |
|
|
|
1148 |
|
|
-- Function: void ui_out_tuple_end (struct ui_out *UIOUT)
|
1149 |
|
|
This function signals an end of a tuple output. There should be
|
1150 |
|
|
exactly one call to `ui_out_tuple_end' for each call to
|
1151 |
|
|
`ui_out_tuple_begin', otherwise an internal GDB error will be
|
1152 |
|
|
signaled.
|
1153 |
|
|
|
1154 |
|
|
-- Function: struct cleanup * make_cleanup_ui_out_tuple_begin_end
|
1155 |
|
|
(struct ui_out *UIOUT, const char *ID)
|
1156 |
|
|
This function first opens the tuple and then establishes a cleanup
|
1157 |
|
|
(*note Cleanups: Coding.) to close the tuple. It provides a
|
1158 |
|
|
convenient and correct implementation of the non-portable(1) code
|
1159 |
|
|
sequence:
|
1160 |
|
|
struct cleanup *old_cleanup;
|
1161 |
|
|
ui_out_tuple_begin (uiout, "...");
|
1162 |
|
|
old_cleanup = make_cleanup ((void(*)(void *)) ui_out_tuple_end,
|
1163 |
|
|
uiout);
|
1164 |
|
|
|
1165 |
|
|
-- Function: void ui_out_list_begin (struct ui_out *UIOUT, const char
|
1166 |
|
|
*ID)
|
1167 |
|
|
This function marks the beginning of a list output. ID points to
|
1168 |
|
|
an optional string that identifies the list; it is copied by the
|
1169 |
|
|
implementation, and so strings in `malloc'ed storage can be freed
|
1170 |
|
|
after the call.
|
1171 |
|
|
|
1172 |
|
|
-- Function: void ui_out_list_end (struct ui_out *UIOUT)
|
1173 |
|
|
This function signals an end of a list output. There should be
|
1174 |
|
|
exactly one call to `ui_out_list_end' for each call to
|
1175 |
|
|
`ui_out_list_begin', otherwise an internal GDB error will be
|
1176 |
|
|
signaled.
|
1177 |
|
|
|
1178 |
|
|
-- Function: struct cleanup * make_cleanup_ui_out_list_begin_end
|
1179 |
|
|
(struct ui_out *UIOUT, const char *ID)
|
1180 |
|
|
Similar to `make_cleanup_ui_out_tuple_begin_end', this function
|
1181 |
|
|
opens a list and then establishes cleanup (*note Cleanups: Coding.)
|
1182 |
|
|
that will close the list.
|
1183 |
|
|
|
1184 |
|
|
4.2.4 Item Output Functions
|
1185 |
|
|
---------------------------
|
1186 |
|
|
|
1187 |
|
|
The functions described below produce output for the actual data items,
|
1188 |
|
|
or fields, which contain information about the object.
|
1189 |
|
|
|
1190 |
|
|
Choose the appropriate function accordingly to your particular needs.
|
1191 |
|
|
|
1192 |
|
|
-- Function: void ui_out_field_fmt (struct ui_out *UIOUT, char
|
1193 |
|
|
*FLDNAME, char *FORMAT, ...)
|
1194 |
|
|
This is the most general output function. It produces the
|
1195 |
|
|
representation of the data in the variable-length argument list
|
1196 |
|
|
according to formatting specifications in FORMAT, a `printf'-like
|
1197 |
|
|
format string. The optional argument FLDNAME supplies the name of
|
1198 |
|
|
the field. The data items themselves are supplied as additional
|
1199 |
|
|
arguments after FORMAT.
|
1200 |
|
|
|
1201 |
|
|
This generic function should be used only when it is not possible
|
1202 |
|
|
to use one of the specialized versions (see below).
|
1203 |
|
|
|
1204 |
|
|
-- Function: void ui_out_field_int (struct ui_out *UIOUT, const char
|
1205 |
|
|
*FLDNAME, int VALUE)
|
1206 |
|
|
This function outputs a value of an `int' variable. It uses the
|
1207 |
|
|
`"%d"' output conversion specification. FLDNAME specifies the
|
1208 |
|
|
name of the field.
|
1209 |
|
|
|
1210 |
|
|
-- Function: void ui_out_field_fmt_int (struct ui_out *UIOUT, int
|
1211 |
|
|
WIDTH, enum ui_align ALIGNMENT, const char *FLDNAME, int
|
1212 |
|
|
VALUE)
|
1213 |
|
|
This function outputs a value of an `int' variable. It differs
|
1214 |
|
|
from `ui_out_field_int' in that the caller specifies the desired
|
1215 |
|
|
WIDTH and ALIGNMENT of the output. FLDNAME specifies the name of
|
1216 |
|
|
the field.
|
1217 |
|
|
|
1218 |
|
|
-- Function: void ui_out_field_core_addr (struct ui_out *UIOUT, const
|
1219 |
|
|
char *FLDNAME, struct gdbarch *GDBARCH, CORE_ADDR ADDRESS)
|
1220 |
|
|
This function outputs an address as appropriate for GDBARCH.
|
1221 |
|
|
|
1222 |
|
|
-- Function: void ui_out_field_string (struct ui_out *UIOUT, const
|
1223 |
|
|
char *FLDNAME, const char *STRING)
|
1224 |
|
|
This function outputs a string using the `"%s"' conversion
|
1225 |
|
|
specification.
|
1226 |
|
|
|
1227 |
|
|
Sometimes, there's a need to compose your output piece by piece using
|
1228 |
|
|
functions that operate on a stream, such as `value_print' or
|
1229 |
|
|
`fprintf_symbol_filtered'. These functions accept an argument of the
|
1230 |
|
|
type `struct ui_file *', a pointer to a `ui_file' object used to store
|
1231 |
|
|
the data stream used for the output. When you use one of these
|
1232 |
|
|
functions, you need a way to pass their results stored in a `ui_file'
|
1233 |
|
|
object to the `ui_out' functions. To this end, you first create a
|
1234 |
|
|
`ui_stream' object by calling `ui_out_stream_new', pass the `stream'
|
1235 |
|
|
member of that `ui_stream' object to `value_print' and similar
|
1236 |
|
|
functions, and finally call `ui_out_field_stream' to output the field
|
1237 |
|
|
you constructed. When the `ui_stream' object is no longer needed, you
|
1238 |
|
|
should destroy it and free its memory by calling `ui_out_stream_delete'.
|
1239 |
|
|
|
1240 |
|
|
-- Function: struct ui_stream * ui_out_stream_new (struct ui_out
|
1241 |
|
|
*UIOUT)
|
1242 |
|
|
This function creates a new `ui_stream' object which uses the same
|
1243 |
|
|
output methods as the `ui_out' object whose pointer is passed in
|
1244 |
|
|
UIOUT. It returns a pointer to the newly created `ui_stream'
|
1245 |
|
|
object.
|
1246 |
|
|
|
1247 |
|
|
-- Function: void ui_out_stream_delete (struct ui_stream *STREAMBUF)
|
1248 |
|
|
This functions destroys a `ui_stream' object specified by
|
1249 |
|
|
STREAMBUF.
|
1250 |
|
|
|
1251 |
|
|
-- Function: void ui_out_field_stream (struct ui_out *UIOUT, const
|
1252 |
|
|
char *FIELDNAME, struct ui_stream *STREAMBUF)
|
1253 |
|
|
This function consumes all the data accumulated in
|
1254 |
|
|
`streambuf->stream' and outputs it like `ui_out_field_string'
|
1255 |
|
|
does. After a call to `ui_out_field_stream', the accumulated data
|
1256 |
|
|
no longer exists, but the stream is still valid and may be used
|
1257 |
|
|
for producing more fields.
|
1258 |
|
|
|
1259 |
|
|
*Important:* If there is any chance that your code could bail out
|
1260 |
|
|
before completing output generation and reaching the point where
|
1261 |
|
|
`ui_out_stream_delete' is called, it is necessary to set up a cleanup,
|
1262 |
|
|
to avoid leaking memory and other resources. Here's a skeleton code to
|
1263 |
|
|
do that:
|
1264 |
|
|
|
1265 |
|
|
struct ui_stream *mybuf = ui_out_stream_new (uiout);
|
1266 |
|
|
struct cleanup *old = make_cleanup (ui_out_stream_delete, mybuf);
|
1267 |
|
|
...
|
1268 |
|
|
do_cleanups (old);
|
1269 |
|
|
|
1270 |
|
|
If the function already has the old cleanup chain set (for other
|
1271 |
|
|
kinds of cleanups), you just have to add your cleanup to it:
|
1272 |
|
|
|
1273 |
|
|
mybuf = ui_out_stream_new (uiout);
|
1274 |
|
|
make_cleanup (ui_out_stream_delete, mybuf);
|
1275 |
|
|
|
1276 |
|
|
Note that with cleanups in place, you should not call
|
1277 |
|
|
`ui_out_stream_delete' directly, or you would attempt to free the same
|
1278 |
|
|
buffer twice.
|
1279 |
|
|
|
1280 |
|
|
4.2.5 Utility Output Functions
|
1281 |
|
|
------------------------------
|
1282 |
|
|
|
1283 |
|
|
-- Function: void ui_out_field_skip (struct ui_out *UIOUT, const char
|
1284 |
|
|
*FLDNAME)
|
1285 |
|
|
This function skips a field in a table. Use it if you have to
|
1286 |
|
|
leave an empty field without disrupting the table alignment. The
|
1287 |
|
|
argument FLDNAME specifies a name for the (missing) filed.
|
1288 |
|
|
|
1289 |
|
|
-- Function: void ui_out_text (struct ui_out *UIOUT, const char
|
1290 |
|
|
*STRING)
|
1291 |
|
|
This function outputs the text in STRING in a way that makes it
|
1292 |
|
|
easy to be read by humans. For example, the console
|
1293 |
|
|
implementation of this method filters the text through a built-in
|
1294 |
|
|
pager, to prevent it from scrolling off the visible portion of the
|
1295 |
|
|
screen.
|
1296 |
|
|
|
1297 |
|
|
Use this function for printing relatively long chunks of text
|
1298 |
|
|
around the actual field data: the text it produces is not aligned
|
1299 |
|
|
according to the table's format. Use `ui_out_field_string' to
|
1300 |
|
|
output a string field, and use `ui_out_message', described below,
|
1301 |
|
|
to output short messages.
|
1302 |
|
|
|
1303 |
|
|
-- Function: void ui_out_spaces (struct ui_out *UIOUT, int NSPACES)
|
1304 |
|
|
This function outputs NSPACES spaces. It is handy to align the
|
1305 |
|
|
text produced by `ui_out_text' with the rest of the table or list.
|
1306 |
|
|
|
1307 |
|
|
-- Function: void ui_out_message (struct ui_out *UIOUT, int VERBOSITY,
|
1308 |
|
|
const char *FORMAT, ...)
|
1309 |
|
|
This function produces a formatted message, provided that the
|
1310 |
|
|
current verbosity level is at least as large as given by
|
1311 |
|
|
VERBOSITY. The current verbosity level is specified by the user
|
1312 |
|
|
with the `set verbositylevel' command.(2)
|
1313 |
|
|
|
1314 |
|
|
-- Function: void ui_out_wrap_hint (struct ui_out *UIOUT, char *INDENT)
|
1315 |
|
|
This function gives the console output filter (a paging filter) a
|
1316 |
|
|
hint of where to break lines which are too long. Ignored for all
|
1317 |
|
|
other output consumers. INDENT, if non-`NULL', is the string to
|
1318 |
|
|
be printed to indent the wrapped text on the next line; it must
|
1319 |
|
|
remain accessible until the next call to `ui_out_wrap_hint', or
|
1320 |
|
|
until an explicit newline is produced by one of the other
|
1321 |
|
|
functions. If INDENT is `NULL', the wrapped text will not be
|
1322 |
|
|
indented.
|
1323 |
|
|
|
1324 |
|
|
-- Function: void ui_out_flush (struct ui_out *UIOUT)
|
1325 |
|
|
This function flushes whatever output has been accumulated so far,
|
1326 |
|
|
if the UI buffers output.
|
1327 |
|
|
|
1328 |
|
|
4.2.6 Examples of Use of `ui_out' functions
|
1329 |
|
|
-------------------------------------------
|
1330 |
|
|
|
1331 |
|
|
This section gives some practical examples of using the `ui_out'
|
1332 |
|
|
functions to generalize the old console-oriented code in GDB. The
|
1333 |
|
|
examples all come from functions defined on the `breakpoints.c' file.
|
1334 |
|
|
|
1335 |
|
|
This example, from the `breakpoint_1' function, shows how to produce
|
1336 |
|
|
a table.
|
1337 |
|
|
|
1338 |
|
|
The original code was:
|
1339 |
|
|
|
1340 |
|
|
if (!found_a_breakpoint++)
|
1341 |
|
|
{
|
1342 |
|
|
annotate_breakpoints_headers ();
|
1343 |
|
|
|
1344 |
|
|
annotate_field (0);
|
1345 |
|
|
printf_filtered ("Num ");
|
1346 |
|
|
annotate_field (1);
|
1347 |
|
|
printf_filtered ("Type ");
|
1348 |
|
|
annotate_field (2);
|
1349 |
|
|
printf_filtered ("Disp ");
|
1350 |
|
|
annotate_field (3);
|
1351 |
|
|
printf_filtered ("Enb ");
|
1352 |
|
|
if (addressprint)
|
1353 |
|
|
{
|
1354 |
|
|
annotate_field (4);
|
1355 |
|
|
printf_filtered ("Address ");
|
1356 |
|
|
}
|
1357 |
|
|
annotate_field (5);
|
1358 |
|
|
printf_filtered ("What\n");
|
1359 |
|
|
|
1360 |
|
|
annotate_breakpoints_table ();
|
1361 |
|
|
}
|
1362 |
|
|
|
1363 |
|
|
Here's the new version:
|
1364 |
|
|
|
1365 |
|
|
nr_printable_breakpoints = ...;
|
1366 |
|
|
|
1367 |
|
|
if (addressprint)
|
1368 |
|
|
ui_out_table_begin (ui, 6, nr_printable_breakpoints, "BreakpointTable");
|
1369 |
|
|
else
|
1370 |
|
|
ui_out_table_begin (ui, 5, nr_printable_breakpoints, "BreakpointTable");
|
1371 |
|
|
|
1372 |
|
|
if (nr_printable_breakpoints > 0)
|
1373 |
|
|
annotate_breakpoints_headers ();
|
1374 |
|
|
if (nr_printable_breakpoints > 0)
|
1375 |
|
|
annotate_field (0);
|
1376 |
|
|
ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */
|
1377 |
|
|
if (nr_printable_breakpoints > 0)
|
1378 |
|
|
annotate_field (1);
|
1379 |
|
|
ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
|
1380 |
|
|
if (nr_printable_breakpoints > 0)
|
1381 |
|
|
annotate_field (2);
|
1382 |
|
|
ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
|
1383 |
|
|
if (nr_printable_breakpoints > 0)
|
1384 |
|
|
annotate_field (3);
|
1385 |
|
|
ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
|
1386 |
|
|
if (addressprint)
|
1387 |
|
|
{
|
1388 |
|
|
if (nr_printable_breakpoints > 0)
|
1389 |
|
|
annotate_field (4);
|
1390 |
|
|
if (print_address_bits <= 32)
|
1391 |
|
|
ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
|
1392 |
|
|
else
|
1393 |
|
|
ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
|
1394 |
|
|
}
|
1395 |
|
|
if (nr_printable_breakpoints > 0)
|
1396 |
|
|
annotate_field (5);
|
1397 |
|
|
ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
|
1398 |
|
|
ui_out_table_body (uiout);
|
1399 |
|
|
if (nr_printable_breakpoints > 0)
|
1400 |
|
|
annotate_breakpoints_table ();
|
1401 |
|
|
|
1402 |
|
|
This example, from the `print_one_breakpoint' function, shows how to
|
1403 |
|
|
produce the actual data for the table whose structure was defined in
|
1404 |
|
|
the above example. The original code was:
|
1405 |
|
|
|
1406 |
|
|
annotate_record ();
|
1407 |
|
|
annotate_field (0);
|
1408 |
|
|
printf_filtered ("%-3d ", b->number);
|
1409 |
|
|
annotate_field (1);
|
1410 |
|
|
if ((int)b->type > (sizeof(bptypes)/sizeof(bptypes[0]))
|
1411 |
|
|
|| ((int) b->type != bptypes[(int) b->type].type))
|
1412 |
|
|
internal_error ("bptypes table does not describe type #%d.",
|
1413 |
|
|
(int)b->type);
|
1414 |
|
|
printf_filtered ("%-14s ", bptypes[(int)b->type].description);
|
1415 |
|
|
annotate_field (2);
|
1416 |
|
|
printf_filtered ("%-4s ", bpdisps[(int)b->disposition]);
|
1417 |
|
|
annotate_field (3);
|
1418 |
|
|
printf_filtered ("%-3c ", bpenables[(int)b->enable]);
|
1419 |
|
|
...
|
1420 |
|
|
|
1421 |
|
|
This is the new version:
|
1422 |
|
|
|
1423 |
|
|
annotate_record ();
|
1424 |
|
|
ui_out_tuple_begin (uiout, "bkpt");
|
1425 |
|
|
annotate_field (0);
|
1426 |
|
|
ui_out_field_int (uiout, "number", b->number);
|
1427 |
|
|
annotate_field (1);
|
1428 |
|
|
if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
|
1429 |
|
|
|| ((int) b->type != bptypes[(int) b->type].type))
|
1430 |
|
|
internal_error ("bptypes table does not describe type #%d.",
|
1431 |
|
|
(int) b->type);
|
1432 |
|
|
ui_out_field_string (uiout, "type", bptypes[(int)b->type].description);
|
1433 |
|
|
annotate_field (2);
|
1434 |
|
|
ui_out_field_string (uiout, "disp", bpdisps[(int)b->disposition]);
|
1435 |
|
|
annotate_field (3);
|
1436 |
|
|
ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int)b->enable]);
|
1437 |
|
|
...
|
1438 |
|
|
|
1439 |
|
|
This example, also from `print_one_breakpoint', shows how to produce
|
1440 |
|
|
a complicated output field using the `print_expression' functions which
|
1441 |
|
|
requires a stream to be passed. It also shows how to automate stream
|
1442 |
|
|
destruction with cleanups. The original code was:
|
1443 |
|
|
|
1444 |
|
|
annotate_field (5);
|
1445 |
|
|
print_expression (b->exp, gdb_stdout);
|
1446 |
|
|
|
1447 |
|
|
The new version is:
|
1448 |
|
|
|
1449 |
|
|
struct ui_stream *stb = ui_out_stream_new (uiout);
|
1450 |
|
|
struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
|
1451 |
|
|
...
|
1452 |
|
|
annotate_field (5);
|
1453 |
|
|
print_expression (b->exp, stb->stream);
|
1454 |
|
|
ui_out_field_stream (uiout, "what", local_stream);
|
1455 |
|
|
|
1456 |
|
|
This example, also from `print_one_breakpoint', shows how to use
|
1457 |
|
|
`ui_out_text' and `ui_out_field_string'. The original code was:
|
1458 |
|
|
|
1459 |
|
|
annotate_field (5);
|
1460 |
|
|
if (b->dll_pathname == NULL)
|
1461 |
|
|
printf_filtered (" ");
|
1462 |
|
|
else
|
1463 |
|
|
printf_filtered ("library \"%s\" ", b->dll_pathname);
|
1464 |
|
|
|
1465 |
|
|
It became:
|
1466 |
|
|
|
1467 |
|
|
annotate_field (5);
|
1468 |
|
|
if (b->dll_pathname == NULL)
|
1469 |
|
|
{
|
1470 |
|
|
ui_out_field_string (uiout, "what", "");
|
1471 |
|
|
ui_out_spaces (uiout, 1);
|
1472 |
|
|
}
|
1473 |
|
|
else
|
1474 |
|
|
{
|
1475 |
|
|
ui_out_text (uiout, "library \"");
|
1476 |
|
|
ui_out_field_string (uiout, "what", b->dll_pathname);
|
1477 |
|
|
ui_out_text (uiout, "\" ");
|
1478 |
|
|
}
|
1479 |
|
|
|
1480 |
|
|
The following example from `print_one_breakpoint' shows how to use
|
1481 |
|
|
`ui_out_field_int' and `ui_out_spaces'. The original code was:
|
1482 |
|
|
|
1483 |
|
|
annotate_field (5);
|
1484 |
|
|
if (b->forked_inferior_pid != 0)
|
1485 |
|
|
printf_filtered ("process %d ", b->forked_inferior_pid);
|
1486 |
|
|
|
1487 |
|
|
It became:
|
1488 |
|
|
|
1489 |
|
|
annotate_field (5);
|
1490 |
|
|
if (b->forked_inferior_pid != 0)
|
1491 |
|
|
{
|
1492 |
|
|
ui_out_text (uiout, "process ");
|
1493 |
|
|
ui_out_field_int (uiout, "what", b->forked_inferior_pid);
|
1494 |
|
|
ui_out_spaces (uiout, 1);
|
1495 |
|
|
}
|
1496 |
|
|
|
1497 |
|
|
Here's an example of using `ui_out_field_string'. The original code
|
1498 |
|
|
was:
|
1499 |
|
|
|
1500 |
|
|
annotate_field (5);
|
1501 |
|
|
if (b->exec_pathname != NULL)
|
1502 |
|
|
printf_filtered ("program \"%s\" ", b->exec_pathname);
|
1503 |
|
|
|
1504 |
|
|
It became:
|
1505 |
|
|
|
1506 |
|
|
annotate_field (5);
|
1507 |
|
|
if (b->exec_pathname != NULL)
|
1508 |
|
|
{
|
1509 |
|
|
ui_out_text (uiout, "program \"");
|
1510 |
|
|
ui_out_field_string (uiout, "what", b->exec_pathname);
|
1511 |
|
|
ui_out_text (uiout, "\" ");
|
1512 |
|
|
}
|
1513 |
|
|
|
1514 |
|
|
Finally, here's an example of printing an address. The original
|
1515 |
|
|
code:
|
1516 |
|
|
|
1517 |
|
|
annotate_field (4);
|
1518 |
|
|
printf_filtered ("%s ",
|
1519 |
|
|
hex_string_custom ((unsigned long) b->address, 8));
|
1520 |
|
|
|
1521 |
|
|
It became:
|
1522 |
|
|
|
1523 |
|
|
annotate_field (4);
|
1524 |
|
|
ui_out_field_core_addr (uiout, "Address", b->address);
|
1525 |
|
|
|
1526 |
|
|
4.3 Console Printing
|
1527 |
|
|
====================
|
1528 |
|
|
|
1529 |
|
|
4.4 TUI
|
1530 |
|
|
=======
|
1531 |
|
|
|
1532 |
|
|
---------- Footnotes ----------
|
1533 |
|
|
|
1534 |
|
|
(1) The function cast is not portable ISO C.
|
1535 |
|
|
|
1536 |
|
|
(2) As of this writing (April 2001), setting verbosity level is not
|
1537 |
|
|
yet implemented, and is always returned as zero. So calling
|
1538 |
|
|
`ui_out_message' with a VERBOSITY argument more than zero will cause
|
1539 |
|
|
the message to never be printed.
|
1540 |
|
|
|
1541 |
|
|
|
1542 |
|
|
File: gdbint.info, Node: libgdb, Next: Values, Prev: User Interface, Up: Top
|
1543 |
|
|
|
1544 |
|
|
5 libgdb
|
1545 |
|
|
********
|
1546 |
|
|
|
1547 |
|
|
5.1 libgdb 1.0
|
1548 |
|
|
==============
|
1549 |
|
|
|
1550 |
|
|
`libgdb' 1.0 was an abortive project of years ago. The theory was to
|
1551 |
|
|
provide an API to GDB's functionality.
|
1552 |
|
|
|
1553 |
|
|
5.2 libgdb 2.0
|
1554 |
|
|
==============
|
1555 |
|
|
|
1556 |
|
|
`libgdb' 2.0 is an ongoing effort to update GDB so that is better able
|
1557 |
|
|
to support graphical and other environments.
|
1558 |
|
|
|
1559 |
|
|
Since `libgdb' development is on-going, its architecture is still
|
1560 |
|
|
evolving. The following components have so far been identified:
|
1561 |
|
|
|
1562 |
|
|
* Observer - `gdb-events.h'.
|
1563 |
|
|
|
1564 |
|
|
* Builder - `ui-out.h'
|
1565 |
|
|
|
1566 |
|
|
* Event Loop - `event-loop.h'
|
1567 |
|
|
|
1568 |
|
|
* Library - `gdb.h'
|
1569 |
|
|
|
1570 |
|
|
The model that ties these components together is described below.
|
1571 |
|
|
|
1572 |
|
|
5.3 The `libgdb' Model
|
1573 |
|
|
======================
|
1574 |
|
|
|
1575 |
|
|
A client of `libgdb' interacts with the library in two ways.
|
1576 |
|
|
|
1577 |
|
|
* As an observer (using `gdb-events') receiving notifications from
|
1578 |
|
|
`libgdb' of any internal state changes (break point changes, run
|
1579 |
|
|
state, etc).
|
1580 |
|
|
|
1581 |
|
|
* As a client querying `libgdb' (using the `ui-out' builder) to
|
1582 |
|
|
obtain various status values from GDB.
|
1583 |
|
|
|
1584 |
|
|
Since `libgdb' could have multiple clients (e.g., a GUI supporting
|
1585 |
|
|
the existing GDB CLI), those clients must co-operate when controlling
|
1586 |
|
|
`libgdb'. In particular, a client must ensure that `libgdb' is idle
|
1587 |
|
|
(i.e. no other client is using `libgdb') before responding to a
|
1588 |
|
|
`gdb-event' by making a query.
|
1589 |
|
|
|
1590 |
|
|
5.4 CLI support
|
1591 |
|
|
===============
|
1592 |
|
|
|
1593 |
|
|
At present GDB's CLI is very much entangled in with the core of
|
1594 |
|
|
`libgdb'. Consequently, a client wishing to include the CLI in their
|
1595 |
|
|
interface needs to carefully co-ordinate its own and the CLI's
|
1596 |
|
|
requirements.
|
1597 |
|
|
|
1598 |
|
|
It is suggested that the client set `libgdb' up to be bi-modal
|
1599 |
|
|
(alternate between CLI and client query modes). The notes below sketch
|
1600 |
|
|
out the theory:
|
1601 |
|
|
|
1602 |
|
|
* The client registers itself as an observer of `libgdb'.
|
1603 |
|
|
|
1604 |
|
|
* The client create and install `cli-out' builder using its own
|
1605 |
|
|
versions of the `ui-file' `gdb_stderr', `gdb_stdtarg' and
|
1606 |
|
|
`gdb_stdout' streams.
|
1607 |
|
|
|
1608 |
|
|
* The client creates a separate custom `ui-out' builder that is only
|
1609 |
|
|
used while making direct queries to `libgdb'.
|
1610 |
|
|
|
1611 |
|
|
When the client receives input intended for the CLI, it simply
|
1612 |
|
|
passes it along. Since the `cli-out' builder is installed by default,
|
1613 |
|
|
all the CLI output in response to that command is routed (pronounced
|
1614 |
|
|
rooted) through to the client controlled `gdb_stdout' et. al. streams.
|
1615 |
|
|
At the same time, the client is kept abreast of internal changes by
|
1616 |
|
|
virtue of being a `libgdb' observer.
|
1617 |
|
|
|
1618 |
|
|
The only restriction on the client is that it must wait until
|
1619 |
|
|
`libgdb' becomes idle before initiating any queries (using the client's
|
1620 |
|
|
custom builder).
|
1621 |
|
|
|
1622 |
|
|
5.5 `libgdb' components
|
1623 |
|
|
=======================
|
1624 |
|
|
|
1625 |
|
|
Observer - `gdb-events.h'
|
1626 |
|
|
-------------------------
|
1627 |
|
|
|
1628 |
|
|
`gdb-events' provides the client with a very raw mechanism that can be
|
1629 |
|
|
used to implement an observer. At present it only allows for one
|
1630 |
|
|
observer and that observer must, internally, handle the need to delay
|
1631 |
|
|
the processing of any event notifications until after `libgdb' has
|
1632 |
|
|
finished the current command.
|
1633 |
|
|
|
1634 |
|
|
Builder - `ui-out.h'
|
1635 |
|
|
--------------------
|
1636 |
|
|
|
1637 |
|
|
`ui-out' provides the infrastructure necessary for a client to create a
|
1638 |
|
|
builder. That builder is then passed down to `libgdb' when doing any
|
1639 |
|
|
queries.
|
1640 |
|
|
|
1641 |
|
|
Event Loop - `event-loop.h'
|
1642 |
|
|
---------------------------
|
1643 |
|
|
|
1644 |
|
|
`event-loop', currently non-re-entrant, provides a simple event loop.
|
1645 |
|
|
A client would need to either plug its self into this loop or,
|
1646 |
|
|
implement a new event-loop that GDB would use.
|
1647 |
|
|
|
1648 |
|
|
The event-loop will eventually be made re-entrant. This is so that
|
1649 |
|
|
GDB can better handle the problem of some commands blocking instead of
|
1650 |
|
|
returning.
|
1651 |
|
|
|
1652 |
|
|
Library - `gdb.h'
|
1653 |
|
|
-----------------
|
1654 |
|
|
|
1655 |
|
|
`libgdb' is the most obvious component of this system. It provides the
|
1656 |
|
|
query interface. Each function is parameterized by a `ui-out' builder.
|
1657 |
|
|
The result of the query is constructed using that builder before the
|
1658 |
|
|
query function returns.
|
1659 |
|
|
|
1660 |
|
|
|
1661 |
|
|
File: gdbint.info, Node: Values, Next: Stack Frames, Prev: libgdb, Up: Top
|
1662 |
|
|
|
1663 |
|
|
6 Values
|
1664 |
|
|
********
|
1665 |
|
|
|
1666 |
|
|
6.1 Values
|
1667 |
|
|
==========
|
1668 |
|
|
|
1669 |
|
|
GDB uses `struct value', or "values", as an internal abstraction for
|
1670 |
|
|
the representation of a variety of inferior objects and GDB convenience
|
1671 |
|
|
objects.
|
1672 |
|
|
|
1673 |
|
|
Values have an associated `struct type', that describes a virtual
|
1674 |
|
|
view of the raw data or object stored in or accessed through the value.
|
1675 |
|
|
|
1676 |
|
|
A value is in addition discriminated by its lvalue-ness, given its
|
1677 |
|
|
`enum lval_type' enumeration type:
|
1678 |
|
|
|
1679 |
|
|
``not_lval''
|
1680 |
|
|
This value is not an lval. It can't be assigned to.
|
1681 |
|
|
|
1682 |
|
|
``lval_memory''
|
1683 |
|
|
This value represents an object in memory.
|
1684 |
|
|
|
1685 |
|
|
``lval_register''
|
1686 |
|
|
This value represents an object that lives in a register.
|
1687 |
|
|
|
1688 |
|
|
``lval_internalvar''
|
1689 |
|
|
Represents the value of an internal variable.
|
1690 |
|
|
|
1691 |
|
|
``lval_internalvar_component''
|
1692 |
|
|
Represents part of a GDB internal variable. E.g., a structure
|
1693 |
|
|
field.
|
1694 |
|
|
|
1695 |
|
|
``lval_computed''
|
1696 |
|
|
These are "computed" values. They allow creating specialized value
|
1697 |
|
|
objects for specific purposes, all abstracted away from the core
|
1698 |
|
|
value support code. The creator of such a value writes specialized
|
1699 |
|
|
functions to handle the reading and writing to/from the value's
|
1700 |
|
|
backend data, and optionally, a "copy operator" and a "destructor".
|
1701 |
|
|
|
1702 |
|
|
Pointers to these functions are stored in a `struct lval_funcs'
|
1703 |
|
|
instance (declared in `value.h'), and passed to the
|
1704 |
|
|
`allocate_computed_value' function, as in the example below.
|
1705 |
|
|
|
1706 |
|
|
static void
|
1707 |
|
|
nil_value_read (struct value *v)
|
1708 |
|
|
{
|
1709 |
|
|
/* This callback reads data from some backend, and stores it in V.
|
1710 |
|
|
In this case, we always read null data. You'll want to fill in
|
1711 |
|
|
something more interesting. */
|
1712 |
|
|
|
1713 |
|
|
memset (value_contents_all_raw (v),
|
1714 |
|
|
value_offset (v),
|
1715 |
|
|
TYPE_LENGTH (value_type (v)));
|
1716 |
|
|
}
|
1717 |
|
|
|
1718 |
|
|
static void
|
1719 |
|
|
nil_value_write (struct value *v, struct value *fromval)
|
1720 |
|
|
{
|
1721 |
|
|
/* Takes the data from FROMVAL and stores it in the backend of V. */
|
1722 |
|
|
|
1723 |
|
|
to_oblivion (value_contents_all_raw (fromval),
|
1724 |
|
|
value_offset (v),
|
1725 |
|
|
TYPE_LENGTH (value_type (fromval)));
|
1726 |
|
|
}
|
1727 |
|
|
|
1728 |
|
|
static struct lval_funcs nil_value_funcs =
|
1729 |
|
|
{
|
1730 |
|
|
nil_value_read,
|
1731 |
|
|
nil_value_write
|
1732 |
|
|
};
|
1733 |
|
|
|
1734 |
|
|
struct value *
|
1735 |
|
|
make_nil_value (void)
|
1736 |
|
|
{
|
1737 |
|
|
struct type *type;
|
1738 |
|
|
struct value *v;
|
1739 |
|
|
|
1740 |
|
|
type = make_nils_type ();
|
1741 |
|
|
v = allocate_computed_value (type, &nil_value_funcs, NULL);
|
1742 |
|
|
|
1743 |
|
|
return v;
|
1744 |
|
|
}
|
1745 |
|
|
|
1746 |
|
|
See the implementation of the `$_siginfo' convenience variable in
|
1747 |
|
|
`infrun.c' as a real example use of lval_computed.
|
1748 |
|
|
|
1749 |
|
|
|
1750 |
|
|
|
1751 |
|
|
File: gdbint.info, Node: Stack Frames, Next: Symbol Handling, Prev: Values, Up: Top
|
1752 |
|
|
|
1753 |
|
|
7 Stack Frames
|
1754 |
|
|
**************
|
1755 |
|
|
|
1756 |
|
|
A frame is a construct that GDB uses to keep track of calling and
|
1757 |
|
|
called functions.
|
1758 |
|
|
|
1759 |
|
|
GDB's frame model, a fresh design, was implemented with the need to
|
1760 |
|
|
support DWARF's Call Frame Information in mind. In fact, the term
|
1761 |
|
|
"unwind" is taken directly from that specification. Developers wishing
|
1762 |
|
|
to learn more about unwinders, are encouraged to read the DWARF
|
1763 |
|
|
specification, available from `http://www.dwarfstd.org'.
|
1764 |
|
|
|
1765 |
|
|
GDB's model is that you find a frame's registers by "unwinding" them
|
1766 |
|
|
from the next younger frame. That is, `get_frame_register' which
|
1767 |
|
|
returns the value of a register in frame #1 (the next-to-youngest
|
1768 |
|
|
frame), is implemented by calling frame #0's `frame_register_unwind'
|
1769 |
|
|
(the youngest frame). But then the obvious question is: how do you
|
1770 |
|
|
access the registers of the youngest frame itself?
|
1771 |
|
|
|
1772 |
|
|
To answer this question, GDB has the "sentinel" frame, the "-1st"
|
1773 |
|
|
frame. Unwinding registers from the sentinel frame gives you the
|
1774 |
|
|
current values of the youngest real frame's registers. If F is a
|
1775 |
|
|
sentinel frame, then `get_frame_type (F) == SENTINEL_FRAME'.
|
1776 |
|
|
|
1777 |
|
|
7.1 Selecting an Unwinder
|
1778 |
|
|
=========================
|
1779 |
|
|
|
1780 |
|
|
The architecture registers a list of frame unwinders (`struct
|
1781 |
|
|
frame_unwind'), using the functions `frame_unwind_prepend_unwinder' and
|
1782 |
|
|
`frame_unwind_append_unwinder'. Each unwinder includes a sniffer.
|
1783 |
|
|
Whenever GDB needs to unwind a frame (to fetch the previous frame's
|
1784 |
|
|
registers or the current frame's ID), it calls registered sniffers in
|
1785 |
|
|
order to find one which recognizes the frame. The first time a sniffer
|
1786 |
|
|
returns non-zero, the corresponding unwinder is assigned to the frame.
|
1787 |
|
|
|
1788 |
|
|
7.2 Unwinding the Frame ID
|
1789 |
|
|
==========================
|
1790 |
|
|
|
1791 |
|
|
Every frame has an associated ID, of type `struct frame_id'. The ID
|
1792 |
|
|
includes the stack base and function start address for the frame. The
|
1793 |
|
|
ID persists through the entire life of the frame, including while other
|
1794 |
|
|
called frames are running; it is used to locate an appropriate `struct
|
1795 |
|
|
frame_info' from the cache.
|
1796 |
|
|
|
1797 |
|
|
Every time the inferior stops, and at various other times, the frame
|
1798 |
|
|
cache is flushed. Because of this, parts of GDB which need to keep
|
1799 |
|
|
track of individual frames cannot use pointers to `struct frame_info'.
|
1800 |
|
|
A frame ID provides a stable reference to a frame, even when the
|
1801 |
|
|
unwinder must be run again to generate a new `struct frame_info' for
|
1802 |
|
|
the same frame.
|
1803 |
|
|
|
1804 |
|
|
The frame's unwinder's `this_id' method is called to find the ID.
|
1805 |
|
|
Note that this is different from register unwinding, where the next
|
1806 |
|
|
frame's `prev_register' is called to unwind this frame's registers.
|
1807 |
|
|
|
1808 |
|
|
Both stack base and function address are required to identify the
|
1809 |
|
|
frame, because a recursive function has the same function address for
|
1810 |
|
|
two consecutive frames and a leaf function may have the same stack
|
1811 |
|
|
address as its caller. On some platforms, a third address is part of
|
1812 |
|
|
the ID to further disambiguate frames--for instance, on IA-64 the
|
1813 |
|
|
separate register stack address is included in the ID.
|
1814 |
|
|
|
1815 |
|
|
An invalid frame ID (`outer_frame_id') returned from the `this_id'
|
1816 |
|
|
method means to stop unwinding after this frame.
|
1817 |
|
|
|
1818 |
|
|
`null_frame_id' is another invalid frame ID which should be used
|
1819 |
|
|
when there is no frame. For instance, certain breakpoints are attached
|
1820 |
|
|
to a specific frame, and that frame is identified through its frame ID
|
1821 |
|
|
(we use this to implement the "finish" command). Using `null_frame_id'
|
1822 |
|
|
as the frame ID for a given breakpoint means that the breakpoint is not
|
1823 |
|
|
specific to any frame. The `this_id' method should never return
|
1824 |
|
|
`null_frame_id'.
|
1825 |
|
|
|
1826 |
|
|
7.3 Unwinding Registers
|
1827 |
|
|
=======================
|
1828 |
|
|
|
1829 |
|
|
Each unwinder includes a `prev_register' method. This method takes a
|
1830 |
|
|
frame, an associated cache pointer, and a register number. It returns
|
1831 |
|
|
a `struct value *' describing the requested register, as saved by this
|
1832 |
|
|
frame. This is the value of the register that is current in this
|
1833 |
|
|
frame's caller.
|
1834 |
|
|
|
1835 |
|
|
The returned value must have the same type as the register. It may
|
1836 |
|
|
have any lvalue type. In most circumstances one of these routines will
|
1837 |
|
|
generate the appropriate value:
|
1838 |
|
|
|
1839 |
|
|
`frame_unwind_got_optimized'
|
1840 |
|
|
This register was not saved.
|
1841 |
|
|
|
1842 |
|
|
`frame_unwind_got_register'
|
1843 |
|
|
This register was copied into another register in this frame. This
|
1844 |
|
|
is also used for unchanged registers; they are "copied" into the
|
1845 |
|
|
same register.
|
1846 |
|
|
|
1847 |
|
|
`frame_unwind_got_memory'
|
1848 |
|
|
This register was saved in memory.
|
1849 |
|
|
|
1850 |
|
|
`frame_unwind_got_constant'
|
1851 |
|
|
This register was not saved, but the unwinder can compute the
|
1852 |
|
|
previous value some other way.
|
1853 |
|
|
|
1854 |
|
|
`frame_unwind_got_address'
|
1855 |
|
|
Same as `frame_unwind_got_constant', except that the value is a
|
1856 |
|
|
target address. This is frequently used for the stack pointer,
|
1857 |
|
|
which is not explicitly saved but has a known offset from this
|
1858 |
|
|
frame's stack pointer. For architectures with a flat unified
|
1859 |
|
|
address space, this is generally the same as
|
1860 |
|
|
`frame_unwind_got_constant'.
|
1861 |
|
|
|
1862 |
|
|
|
1863 |
|
|
File: gdbint.info, Node: Symbol Handling, Next: Language Support, Prev: Stack Frames, Up: Top
|
1864 |
|
|
|
1865 |
|
|
8 Symbol Handling
|
1866 |
|
|
*****************
|
1867 |
|
|
|
1868 |
|
|
Symbols are a key part of GDB's operation. Symbols include variables,
|
1869 |
|
|
functions, and types.
|
1870 |
|
|
|
1871 |
|
|
Symbol information for a large program can be truly massive, and
|
1872 |
|
|
reading of symbol information is one of the major performance
|
1873 |
|
|
bottlenecks in GDB; it can take many minutes to process it all.
|
1874 |
|
|
Studies have shown that nearly all the time spent is computational,
|
1875 |
|
|
rather than file reading.
|
1876 |
|
|
|
1877 |
|
|
One of the ways for GDB to provide a good user experience is to
|
1878 |
|
|
start up quickly, taking no more than a few seconds. It is simply not
|
1879 |
|
|
possible to process all of a program's debugging info in that time, and
|
1880 |
|
|
so we attempt to handle symbols incrementally. For instance, we create
|
1881 |
|
|
"partial symbol tables" consisting of only selected symbols, and only
|
1882 |
|
|
expand them to full symbol tables when necessary.
|
1883 |
|
|
|
1884 |
|
|
8.1 Symbol Reading
|
1885 |
|
|
==================
|
1886 |
|
|
|
1887 |
|
|
GDB reads symbols from "symbol files". The usual symbol file is the
|
1888 |
|
|
file containing the program which GDB is debugging. GDB can be
|
1889 |
|
|
directed to use a different file for symbols (with the `symbol-file'
|
1890 |
|
|
command), and it can also read more symbols via the `add-file' and
|
1891 |
|
|
`load' commands. In addition, it may bring in more symbols while
|
1892 |
|
|
loading shared libraries.
|
1893 |
|
|
|
1894 |
|
|
Symbol files are initially opened by code in `symfile.c' using the
|
1895 |
|
|
BFD library (*note Support Libraries::). BFD identifies the type of
|
1896 |
|
|
the file by examining its header. `find_sym_fns' then uses this
|
1897 |
|
|
identification to locate a set of symbol-reading functions.
|
1898 |
|
|
|
1899 |
|
|
Symbol-reading modules identify themselves to GDB by calling
|
1900 |
|
|
`add_symtab_fns' during their module initialization. The argument to
|
1901 |
|
|
`add_symtab_fns' is a `struct sym_fns' which contains the name (or name
|
1902 |
|
|
prefix) of the symbol format, the length of the prefix, and pointers to
|
1903 |
|
|
four functions. These functions are called at various times to process
|
1904 |
|
|
symbol files whose identification matches the specified prefix.
|
1905 |
|
|
|
1906 |
|
|
The functions supplied by each module are:
|
1907 |
|
|
|
1908 |
|
|
`XYZ_symfile_init(struct sym_fns *sf)'
|
1909 |
|
|
Called from `symbol_file_add' when we are about to read a new
|
1910 |
|
|
symbol file. This function should clean up any internal state
|
1911 |
|
|
(possibly resulting from half-read previous files, for example)
|
1912 |
|
|
and prepare to read a new symbol file. Note that the symbol file
|
1913 |
|
|
which we are reading might be a new "main" symbol file, or might
|
1914 |
|
|
be a secondary symbol file whose symbols are being added to the
|
1915 |
|
|
existing symbol table.
|
1916 |
|
|
|
1917 |
|
|
The argument to `XYZ_symfile_init' is a newly allocated `struct
|
1918 |
|
|
sym_fns' whose `bfd' field contains the BFD for the new symbol
|
1919 |
|
|
file being read. Its `private' field has been zeroed, and can be
|
1920 |
|
|
modified as desired. Typically, a struct of private information
|
1921 |
|
|
will be `malloc''d, and a pointer to it will be placed in the
|
1922 |
|
|
`private' field.
|
1923 |
|
|
|
1924 |
|
|
There is no result from `XYZ_symfile_init', but it can call
|
1925 |
|
|
`error' if it detects an unavoidable problem.
|
1926 |
|
|
|
1927 |
|
|
`XYZ_new_init()'
|
1928 |
|
|
Called from `symbol_file_add' when discarding existing symbols.
|
1929 |
|
|
This function needs only handle the symbol-reading module's
|
1930 |
|
|
internal state; the symbol table data structures visible to the
|
1931 |
|
|
rest of GDB will be discarded by `symbol_file_add'. It has no
|
1932 |
|
|
arguments and no result. It may be called after
|
1933 |
|
|
`XYZ_symfile_init', if a new symbol table is being read, or may be
|
1934 |
|
|
called alone if all symbols are simply being discarded.
|
1935 |
|
|
|
1936 |
|
|
`XYZ_symfile_read(struct sym_fns *sf, CORE_ADDR addr, int mainline)'
|
1937 |
|
|
Called from `symbol_file_add' to actually read the symbols from a
|
1938 |
|
|
symbol-file into a set of psymtabs or symtabs.
|
1939 |
|
|
|
1940 |
|
|
`sf' points to the `struct sym_fns' originally passed to
|
1941 |
|
|
`XYZ_sym_init' for possible initialization. `addr' is the offset
|
1942 |
|
|
between the file's specified start address and its true address in
|
1943 |
|
|
memory. `mainline' is 1 if this is the main symbol table being
|
1944 |
|
|
read, and 0 if a secondary symbol file (e.g., shared library or
|
1945 |
|
|
dynamically loaded file) is being read.
|
1946 |
|
|
|
1947 |
|
|
In addition, if a symbol-reading module creates psymtabs when
|
1948 |
|
|
XYZ_symfile_read is called, these psymtabs will contain a pointer to a
|
1949 |
|
|
function `XYZ_psymtab_to_symtab', which can be called from any point in
|
1950 |
|
|
the GDB symbol-handling code.
|
1951 |
|
|
|
1952 |
|
|
`XYZ_psymtab_to_symtab (struct partial_symtab *pst)'
|
1953 |
|
|
Called from `psymtab_to_symtab' (or the `PSYMTAB_TO_SYMTAB' macro)
|
1954 |
|
|
if the psymtab has not already been read in and had its
|
1955 |
|
|
`pst->symtab' pointer set. The argument is the psymtab to be
|
1956 |
|
|
fleshed-out into a symtab. Upon return, `pst->readin' should have
|
1957 |
|
|
been set to 1, and `pst->symtab' should contain a pointer to the
|
1958 |
|
|
new corresponding symtab, or zero if there were no symbols in that
|
1959 |
|
|
part of the symbol file.
|
1960 |
|
|
|
1961 |
|
|
8.2 Partial Symbol Tables
|
1962 |
|
|
=========================
|
1963 |
|
|
|
1964 |
|
|
GDB has three types of symbol tables:
|
1965 |
|
|
|
1966 |
|
|
* Full symbol tables ("symtabs"). These contain the main
|
1967 |
|
|
information about symbols and addresses.
|
1968 |
|
|
|
1969 |
|
|
* Partial symbol tables ("psymtabs"). These contain enough
|
1970 |
|
|
information to know when to read the corresponding part of the full
|
1971 |
|
|
symbol table.
|
1972 |
|
|
|
1973 |
|
|
* Minimal symbol tables ("msymtabs"). These contain information
|
1974 |
|
|
gleaned from non-debugging symbols.
|
1975 |
|
|
|
1976 |
|
|
This section describes partial symbol tables.
|
1977 |
|
|
|
1978 |
|
|
A psymtab is constructed by doing a very quick pass over an
|
1979 |
|
|
executable file's debugging information. Small amounts of information
|
1980 |
|
|
are extracted--enough to identify which parts of the symbol table will
|
1981 |
|
|
need to be re-read and fully digested later, when the user needs the
|
1982 |
|
|
information. The speed of this pass causes GDB to start up very
|
1983 |
|
|
quickly. Later, as the detailed rereading occurs, it occurs in small
|
1984 |
|
|
pieces, at various times, and the delay therefrom is mostly invisible to
|
1985 |
|
|
the user.
|
1986 |
|
|
|
1987 |
|
|
The symbols that show up in a file's psymtab should be, roughly,
|
1988 |
|
|
those visible to the debugger's user when the program is not running
|
1989 |
|
|
code from that file. These include external symbols and types, static
|
1990 |
|
|
symbols and types, and `enum' values declared at file scope.
|
1991 |
|
|
|
1992 |
|
|
The psymtab also contains the range of instruction addresses that the
|
1993 |
|
|
full symbol table would represent.
|
1994 |
|
|
|
1995 |
|
|
The idea is that there are only two ways for the user (or much of the
|
1996 |
|
|
code in the debugger) to reference a symbol:
|
1997 |
|
|
|
1998 |
|
|
* By its address (e.g., execution stops at some address which is
|
1999 |
|
|
inside a function in this file). The address will be noticed to
|
2000 |
|
|
be in the range of this psymtab, and the full symtab will be read
|
2001 |
|
|
in. `find_pc_function', `find_pc_line', and other `find_pc_...'
|
2002 |
|
|
functions handle this.
|
2003 |
|
|
|
2004 |
|
|
* By its name (e.g., the user asks to print a variable, or set a
|
2005 |
|
|
breakpoint on a function). Global names and file-scope names will
|
2006 |
|
|
be found in the psymtab, which will cause the symtab to be pulled
|
2007 |
|
|
in. Local names will have to be qualified by a global name, or a
|
2008 |
|
|
file-scope name, in which case we will have already read in the
|
2009 |
|
|
symtab as we evaluated the qualifier. Or, a local symbol can be
|
2010 |
|
|
referenced when we are "in" a local scope, in which case the first
|
2011 |
|
|
case applies. `lookup_symbol' does most of the work here.
|
2012 |
|
|
|
2013 |
|
|
The only reason that psymtabs exist is to cause a symtab to be read
|
2014 |
|
|
in at the right moment. Any symbol that can be elided from a psymtab,
|
2015 |
|
|
while still causing that to happen, should not appear in it. Since
|
2016 |
|
|
psymtabs don't have the idea of scope, you can't put local symbols in
|
2017 |
|
|
them anyway. Psymtabs don't have the idea of the type of a symbol,
|
2018 |
|
|
either, so types need not appear, unless they will be referenced by
|
2019 |
|
|
name.
|
2020 |
|
|
|
2021 |
|
|
It is a bug for GDB to behave one way when only a psymtab has been
|
2022 |
|
|
read, and another way if the corresponding symtab has been read in.
|
2023 |
|
|
Such bugs are typically caused by a psymtab that does not contain all
|
2024 |
|
|
the visible symbols, or which has the wrong instruction address ranges.
|
2025 |
|
|
|
2026 |
|
|
The psymtab for a particular section of a symbol file (objfile)
|
2027 |
|
|
could be thrown away after the symtab has been read in. The symtab
|
2028 |
|
|
should always be searched before the psymtab, so the psymtab will never
|
2029 |
|
|
be used (in a bug-free environment). Currently, psymtabs are allocated
|
2030 |
|
|
on an obstack, and all the psymbols themselves are allocated in a pair
|
2031 |
|
|
of large arrays on an obstack, so there is little to be gained by
|
2032 |
|
|
trying to free them unless you want to do a lot more work.
|
2033 |
|
|
|
2034 |
|
|
Whether or not psymtabs are created depends on the objfile's symbol
|
2035 |
|
|
reader. The core of GDB hides the details of partial symbols and
|
2036 |
|
|
partial symbol tables behind a set of function pointers known as the
|
2037 |
|
|
"quick symbol functions". These are documented in `symfile.h'.
|
2038 |
|
|
|
2039 |
|
|
8.3 Types
|
2040 |
|
|
=========
|
2041 |
|
|
|
2042 |
|
|
Fundamental Types (e.g., `FT_VOID', `FT_BOOLEAN').
|
2043 |
|
|
--------------------------------------------------
|
2044 |
|
|
|
2045 |
|
|
These are the fundamental types that GDB uses internally. Fundamental
|
2046 |
|
|
types from the various debugging formats (stabs, ELF, etc) are mapped
|
2047 |
|
|
into one of these. They are basically a union of all fundamental types
|
2048 |
|
|
that GDB knows about for all the languages that GDB knows about.
|
2049 |
|
|
|
2050 |
|
|
Type Codes (e.g., `TYPE_CODE_PTR', `TYPE_CODE_ARRAY').
|
2051 |
|
|
------------------------------------------------------
|
2052 |
|
|
|
2053 |
|
|
Each time GDB builds an internal type, it marks it with one of these
|
2054 |
|
|
types. The type may be a fundamental type, such as `TYPE_CODE_INT', or
|
2055 |
|
|
a derived type, such as `TYPE_CODE_PTR' which is a pointer to another
|
2056 |
|
|
type. Typically, several `FT_*' types map to one `TYPE_CODE_*' type,
|
2057 |
|
|
and are distinguished by other members of the type struct, such as
|
2058 |
|
|
whether the type is signed or unsigned, and how many bits it uses.
|
2059 |
|
|
|
2060 |
|
|
Builtin Types (e.g., `builtin_type_void', `builtin_type_char').
|
2061 |
|
|
---------------------------------------------------------------
|
2062 |
|
|
|
2063 |
|
|
These are instances of type structs that roughly correspond to
|
2064 |
|
|
fundamental types and are created as global types for GDB to use for
|
2065 |
|
|
various ugly historical reasons. We eventually want to eliminate
|
2066 |
|
|
these. Note for example that `builtin_type_int' initialized in
|
2067 |
|
|
`gdbtypes.c' is basically the same as a `TYPE_CODE_INT' type that is
|
2068 |
|
|
initialized in `c-lang.c' for an `FT_INTEGER' fundamental type. The
|
2069 |
|
|
difference is that the `builtin_type' is not associated with any
|
2070 |
|
|
particular objfile, and only one instance exists, while `c-lang.c'
|
2071 |
|
|
builds as many `TYPE_CODE_INT' types as needed, with each one
|
2072 |
|
|
associated with some particular objfile.
|
2073 |
|
|
|
2074 |
|
|
8.4 Object File Formats
|
2075 |
|
|
=======================
|
2076 |
|
|
|
2077 |
|
|
8.4.1 a.out
|
2078 |
|
|
-----------
|
2079 |
|
|
|
2080 |
|
|
The `a.out' format is the original file format for Unix. It consists
|
2081 |
|
|
of three sections: `text', `data', and `bss', which are for program
|
2082 |
|
|
code, initialized data, and uninitialized data, respectively.
|
2083 |
|
|
|
2084 |
|
|
The `a.out' format is so simple that it doesn't have any reserved
|
2085 |
|
|
place for debugging information. (Hey, the original Unix hackers used
|
2086 |
|
|
`adb', which is a machine-language debugger!) The only debugging
|
2087 |
|
|
format for `a.out' is stabs, which is encoded as a set of normal
|
2088 |
|
|
symbols with distinctive attributes.
|
2089 |
|
|
|
2090 |
|
|
The basic `a.out' reader is in `dbxread.c'.
|
2091 |
|
|
|
2092 |
|
|
8.4.2 COFF
|
2093 |
|
|
----------
|
2094 |
|
|
|
2095 |
|
|
The COFF format was introduced with System V Release 3 (SVR3) Unix.
|
2096 |
|
|
COFF files may have multiple sections, each prefixed by a header. The
|
2097 |
|
|
number of sections is limited.
|
2098 |
|
|
|
2099 |
|
|
The COFF specification includes support for debugging. Although this
|
2100 |
|
|
was a step forward, the debugging information was woefully limited.
|
2101 |
|
|
For instance, it was not possible to represent code that came from an
|
2102 |
|
|
included file. GNU's COFF-using configs often use stabs-type info,
|
2103 |
|
|
encapsulated in special sections.
|
2104 |
|
|
|
2105 |
|
|
The COFF reader is in `coffread.c'.
|
2106 |
|
|
|
2107 |
|
|
8.4.3 ECOFF
|
2108 |
|
|
-----------
|
2109 |
|
|
|
2110 |
|
|
ECOFF is an extended COFF originally introduced for Mips and Alpha
|
2111 |
|
|
workstations.
|
2112 |
|
|
|
2113 |
|
|
The basic ECOFF reader is in `mipsread.c'.
|
2114 |
|
|
|
2115 |
|
|
8.4.4 XCOFF
|
2116 |
|
|
-----------
|
2117 |
|
|
|
2118 |
|
|
The IBM RS/6000 running AIX uses an object file format called XCOFF.
|
2119 |
|
|
The COFF sections, symbols, and line numbers are used, but debugging
|
2120 |
|
|
symbols are `dbx'-style stabs whose strings are located in the `.debug'
|
2121 |
|
|
section (rather than the string table). For more information, see
|
2122 |
342 |
jeremybenn |
*note Top: (stabs)Top.
|
2123 |
330 |
jeremybenn |
|
2124 |
|
|
The shared library scheme has a clean interface for figuring out what
|
2125 |
|
|
shared libraries are in use, but the catch is that everything which
|
2126 |
|
|
refers to addresses (symbol tables and breakpoints at least) needs to be
|
2127 |
|
|
relocated for both shared libraries and the main executable. At least
|
2128 |
|
|
using the standard mechanism this can only be done once the program has
|
2129 |
|
|
been run (or the core file has been read).
|
2130 |
|
|
|
2131 |
|
|
8.4.5 PE
|
2132 |
|
|
--------
|
2133 |
|
|
|
2134 |
|
|
Windows 95 and NT use the PE ("Portable Executable") format for their
|
2135 |
|
|
executables. PE is basically COFF with additional headers.
|
2136 |
|
|
|
2137 |
|
|
While BFD includes special PE support, GDB needs only the basic COFF
|
2138 |
|
|
reader.
|
2139 |
|
|
|
2140 |
|
|
8.4.6 ELF
|
2141 |
|
|
---------
|
2142 |
|
|
|
2143 |
|
|
The ELF format came with System V Release 4 (SVR4) Unix. ELF is
|
2144 |
|
|
similar to COFF in being organized into a number of sections, but it
|
2145 |
|
|
removes many of COFF's limitations. Debugging info may be either stabs
|
2146 |
|
|
encapsulated in ELF sections, or more commonly these days, DWARF.
|
2147 |
|
|
|
2148 |
|
|
The basic ELF reader is in `elfread.c'.
|
2149 |
|
|
|
2150 |
|
|
8.4.7 SOM
|
2151 |
|
|
---------
|
2152 |
|
|
|
2153 |
|
|
SOM is HP's object file and debug format (not to be confused with IBM's
|
2154 |
|
|
SOM, which is a cross-language ABI).
|
2155 |
|
|
|
2156 |
|
|
The SOM reader is in `somread.c'.
|
2157 |
|
|
|
2158 |
|
|
8.5 Debugging File Formats
|
2159 |
|
|
==========================
|
2160 |
|
|
|
2161 |
|
|
This section describes characteristics of debugging information that
|
2162 |
|
|
are independent of the object file format.
|
2163 |
|
|
|
2164 |
|
|
8.5.1 stabs
|
2165 |
|
|
-----------
|
2166 |
|
|
|
2167 |
|
|
`stabs' started out as special symbols within the `a.out' format.
|
2168 |
|
|
Since then, it has been encapsulated into other file formats, such as
|
2169 |
|
|
COFF and ELF.
|
2170 |
|
|
|
2171 |
|
|
While `dbxread.c' does some of the basic stab processing, including
|
2172 |
|
|
for encapsulated versions, `stabsread.c' does the real work.
|
2173 |
|
|
|
2174 |
|
|
8.5.2 COFF
|
2175 |
|
|
----------
|
2176 |
|
|
|
2177 |
|
|
The basic COFF definition includes debugging information. The level of
|
2178 |
|
|
support is minimal and non-extensible, and is not often used.
|
2179 |
|
|
|
2180 |
|
|
8.5.3 Mips debug (Third Eye)
|
2181 |
|
|
----------------------------
|
2182 |
|
|
|
2183 |
|
|
ECOFF includes a definition of a special debug format.
|
2184 |
|
|
|
2185 |
|
|
The file `mdebugread.c' implements reading for this format.
|
2186 |
|
|
|
2187 |
|
|
8.5.4 DWARF 2
|
2188 |
|
|
-------------
|
2189 |
|
|
|
2190 |
|
|
DWARF 2 is an improved but incompatible version of DWARF 1.
|
2191 |
|
|
|
2192 |
|
|
The DWARF 2 reader is in `dwarf2read.c'.
|
2193 |
|
|
|
2194 |
|
|
8.5.5 Compressed DWARF 2
|
2195 |
|
|
------------------------
|
2196 |
|
|
|
2197 |
|
|
Compressed DWARF 2 is not technically a separate debugging format, but
|
2198 |
|
|
merely DWARF 2 debug information that has been compressed. In this
|
2199 |
|
|
format, every object-file section holding DWARF 2 debugging information
|
2200 |
|
|
is compressed and prepended with a header. (The section is also
|
2201 |
|
|
typically renamed, so a section called `.debug_info' in a DWARF 2
|
2202 |
|
|
binary would be called `.zdebug_info' in a compressed DWARF 2 binary.)
|
2203 |
|
|
The header is 12 bytes long:
|
2204 |
|
|
|
2205 |
|
|
* 4 bytes: the literal string "ZLIB"
|
2206 |
|
|
|
2207 |
|
|
* 8 bytes: the uncompressed size of the section, in big-endian byte
|
2208 |
|
|
order.
|
2209 |
|
|
|
2210 |
|
|
The same reader is used for both compressed an normal DWARF 2 info.
|
2211 |
|
|
Section decompression is done in `zlib_decompress_section' in
|
2212 |
|
|
`dwarf2read.c'.
|
2213 |
|
|
|
2214 |
|
|
8.5.6 DWARF 3
|
2215 |
|
|
-------------
|
2216 |
|
|
|
2217 |
|
|
DWARF 3 is an improved version of DWARF 2.
|
2218 |
|
|
|
2219 |
|
|
8.5.7 SOM
|
2220 |
|
|
---------
|
2221 |
|
|
|
2222 |
|
|
Like COFF, the SOM definition includes debugging information.
|
2223 |
|
|
|
2224 |
|
|
8.6 Adding a New Symbol Reader to GDB
|
2225 |
|
|
=====================================
|
2226 |
|
|
|
2227 |
|
|
If you are using an existing object file format (`a.out', COFF, ELF,
|
2228 |
|
|
etc), there is probably little to be done.
|
2229 |
|
|
|
2230 |
|
|
If you need to add a new object file format, you must first add it to
|
2231 |
|
|
BFD. This is beyond the scope of this document.
|
2232 |
|
|
|
2233 |
|
|
You must then arrange for the BFD code to provide access to the
|
2234 |
|
|
debugging symbols. Generally GDB will have to call swapping routines
|
2235 |
|
|
from BFD and a few other BFD internal routines to locate the debugging
|
2236 |
|
|
information. As much as possible, GDB should not depend on the BFD
|
2237 |
|
|
internal data structures.
|
2238 |
|
|
|
2239 |
|
|
For some targets (e.g., COFF), there is a special transfer vector
|
2240 |
|
|
used to call swapping routines, since the external data structures on
|
2241 |
|
|
various platforms have different sizes and layouts. Specialized
|
2242 |
|
|
routines that will only ever be implemented by one object file format
|
2243 |
|
|
may be called directly. This interface should be described in a file
|
2244 |
|
|
`bfd/libXYZ.h', which is included by GDB.
|
2245 |
|
|
|
2246 |
|
|
8.7 Memory Management for Symbol Files
|
2247 |
|
|
======================================
|
2248 |
|
|
|
2249 |
|
|
Most memory associated with a loaded symbol file is stored on its
|
2250 |
|
|
`objfile_obstack'. This includes symbols, types, namespace data, and
|
2251 |
|
|
other information produced by the symbol readers.
|
2252 |
|
|
|
2253 |
|
|
Because this data lives on the objfile's obstack, it is automatically
|
2254 |
|
|
released when the objfile is unloaded or reloaded. Therefore one
|
2255 |
|
|
objfile must not reference symbol or type data from another objfile;
|
2256 |
|
|
they could be unloaded at different times.
|
2257 |
|
|
|
2258 |
|
|
User convenience variables, et cetera, have associated types.
|
2259 |
|
|
Normally these types live in the associated objfile. However, when the
|
2260 |
|
|
objfile is unloaded, those types are deep copied to global memory, so
|
2261 |
|
|
that the values of the user variables and history items are not lost.
|
2262 |
|
|
|
2263 |
|
|
|
2264 |
|
|
File: gdbint.info, Node: Language Support, Next: Host Definition, Prev: Symbol Handling, Up: Top
|
2265 |
|
|
|
2266 |
|
|
9 Language Support
|
2267 |
|
|
******************
|
2268 |
|
|
|
2269 |
|
|
GDB's language support is mainly driven by the symbol reader, although
|
2270 |
|
|
it is possible for the user to set the source language manually.
|
2271 |
|
|
|
2272 |
|
|
GDB chooses the source language by looking at the extension of the
|
2273 |
|
|
file recorded in the debug info; `.c' means C, `.f' means Fortran, etc.
|
2274 |
|
|
It may also use a special-purpose language identifier if the debug
|
2275 |
|
|
format supports it, like with DWARF.
|
2276 |
|
|
|
2277 |
|
|
9.1 Adding a Source Language to GDB
|
2278 |
|
|
===================================
|
2279 |
|
|
|
2280 |
|
|
To add other languages to GDB's expression parser, follow the following
|
2281 |
|
|
steps:
|
2282 |
|
|
|
2283 |
|
|
_Create the expression parser._
|
2284 |
|
|
This should reside in a file `LANG-exp.y'. Routines for building
|
2285 |
|
|
parsed expressions into a `union exp_element' list are in
|
2286 |
|
|
`parse.c'.
|
2287 |
|
|
|
2288 |
|
|
Since we can't depend upon everyone having Bison, and YACC produces
|
2289 |
|
|
parsers that define a bunch of global names, the following lines
|
2290 |
|
|
*must* be included at the top of the YACC parser, to prevent the
|
2291 |
|
|
various parsers from defining the same global names:
|
2292 |
|
|
|
2293 |
|
|
#define yyparse LANG_parse
|
2294 |
|
|
#define yylex LANG_lex
|
2295 |
|
|
#define yyerror LANG_error
|
2296 |
|
|
#define yylval LANG_lval
|
2297 |
|
|
#define yychar LANG_char
|
2298 |
|
|
#define yydebug LANG_debug
|
2299 |
|
|
#define yypact LANG_pact
|
2300 |
|
|
#define yyr1 LANG_r1
|
2301 |
|
|
#define yyr2 LANG_r2
|
2302 |
|
|
#define yydef LANG_def
|
2303 |
|
|
#define yychk LANG_chk
|
2304 |
|
|
#define yypgo LANG_pgo
|
2305 |
|
|
#define yyact LANG_act
|
2306 |
|
|
#define yyexca LANG_exca
|
2307 |
|
|
#define yyerrflag LANG_errflag
|
2308 |
|
|
#define yynerrs LANG_nerrs
|
2309 |
|
|
|
2310 |
|
|
At the bottom of your parser, define a `struct language_defn' and
|
2311 |
|
|
initialize it with the right values for your language. Define an
|
2312 |
|
|
`initialize_LANG' routine and have it call
|
2313 |
|
|
`add_language(LANG_language_defn)' to tell the rest of GDB that
|
2314 |
|
|
your language exists. You'll need some other supporting variables
|
2315 |
|
|
and functions, which will be used via pointers from your
|
2316 |
|
|
`LANG_language_defn'. See the declaration of `struct
|
2317 |
|
|
language_defn' in `language.h', and the other `*-exp.y' files, for
|
2318 |
|
|
more information.
|
2319 |
|
|
|
2320 |
|
|
_Add any evaluation routines, if necessary_
|
2321 |
|
|
If you need new opcodes (that represent the operations of the
|
2322 |
|
|
language), add them to the enumerated type in `expression.h'. Add
|
2323 |
|
|
support code for these operations in the `evaluate_subexp' function
|
2324 |
|
|
defined in the file `eval.c'. Add cases for new opcodes in two
|
2325 |
|
|
functions from `parse.c': `prefixify_subexp' and
|
2326 |
|
|
`length_of_subexp'. These compute the number of `exp_element's
|
2327 |
|
|
that a given operation takes up.
|
2328 |
|
|
|
2329 |
|
|
_Update some existing code_
|
2330 |
|
|
Add an enumerated identifier for your language to the enumerated
|
2331 |
|
|
type `enum language' in `defs.h'.
|
2332 |
|
|
|
2333 |
|
|
Update the routines in `language.c' so your language is included.
|
2334 |
|
|
These routines include type predicates and such, which (in some
|
2335 |
|
|
cases) are language dependent. If your language does not appear
|
2336 |
|
|
in the switch statement, an error is reported.
|
2337 |
|
|
|
2338 |
|
|
Also included in `language.c' is the code that updates the variable
|
2339 |
|
|
`current_language', and the routines that translate the
|
2340 |
|
|
`language_LANG' enumerated identifier into a printable string.
|
2341 |
|
|
|
2342 |
|
|
Update the function `_initialize_language' to include your
|
2343 |
|
|
language. This function picks the default language upon startup,
|
2344 |
|
|
so is dependent upon which languages that GDB is built for.
|
2345 |
|
|
|
2346 |
|
|
Update `allocate_symtab' in `symfile.c' and/or symbol-reading code
|
2347 |
|
|
so that the language of each symtab (source file) is set properly.
|
2348 |
|
|
This is used to determine the language to use at each stack frame
|
2349 |
|
|
level. Currently, the language is set based upon the extension of
|
2350 |
|
|
the source file. If the language can be better inferred from the
|
2351 |
|
|
symbol information, please set the language of the symtab in the
|
2352 |
|
|
symbol-reading code.
|
2353 |
|
|
|
2354 |
|
|
Add helper code to `print_subexp' (in `expprint.c') to handle any
|
2355 |
|
|
new expression opcodes you have added to `expression.h'. Also,
|
2356 |
|
|
add the printed representations of your operators to
|
2357 |
|
|
`op_print_tab'.
|
2358 |
|
|
|
2359 |
|
|
_Add a place of call_
|
2360 |
|
|
Add a call to `LANG_parse()' and `LANG_error' in `parse_exp_1'
|
2361 |
|
|
(defined in `parse.c').
|
2362 |
|
|
|
2363 |
|
|
_Edit `Makefile.in'_
|
2364 |
|
|
Add dependencies in `Makefile.in'. Make sure you update the macro
|
2365 |
|
|
variables such as `HFILES' and `OBJS', otherwise your code may not
|
2366 |
|
|
get linked in, or, worse yet, it may not get `tar'red into the
|
2367 |
|
|
distribution!
|
2368 |
|
|
|
2369 |
|
|
|
2370 |
|
|
File: gdbint.info, Node: Host Definition, Next: Target Architecture Definition, Prev: Language Support, Up: Top
|
2371 |
|
|
|
2372 |
|
|
10 Host Definition
|
2373 |
|
|
******************
|
2374 |
|
|
|
2375 |
|
|
With the advent of Autoconf, it's rarely necessary to have host
|
2376 |
|
|
definition machinery anymore. The following information is provided,
|
2377 |
|
|
mainly, as an historical reference.
|
2378 |
|
|
|
2379 |
|
|
10.1 Adding a New Host
|
2380 |
|
|
======================
|
2381 |
|
|
|
2382 |
|
|
GDB's host configuration support normally happens via Autoconf. New
|
2383 |
|
|
host-specific definitions should not be needed. Older hosts GDB still
|
2384 |
|
|
use the host-specific definitions and files listed below, but these
|
2385 |
|
|
mostly exist for historical reasons, and will eventually disappear.
|
2386 |
|
|
|
2387 |
|
|
`gdb/config/ARCH/XYZ.mh'
|
2388 |
|
|
This file is a Makefile fragment that once contained both host and
|
2389 |
|
|
native configuration information (*note Native Debugging::) for the
|
2390 |
|
|
machine XYZ. The host configuration information is now handled by
|
2391 |
|
|
Autoconf.
|
2392 |
|
|
|
2393 |
|
|
Host configuration information included definitions for `CC',
|
2394 |
|
|
`SYSV_DEFINE', `XM_CFLAGS', `XM_ADD_FILES', `XM_CLIBS',
|
2395 |
|
|
`XM_CDEPS', etc.; see `Makefile.in'.
|
2396 |
|
|
|
2397 |
|
|
New host-only configurations do not need this file.
|
2398 |
|
|
|
2399 |
|
|
|
2400 |
|
|
(Files named `gdb/config/ARCH/xm-XYZ.h' were once used to define
|
2401 |
|
|
host-specific macros, but were no longer needed and have all been
|
2402 |
|
|
removed.)
|
2403 |
|
|
|
2404 |
|
|
Generic Host Support Files
|
2405 |
|
|
--------------------------
|
2406 |
|
|
|
2407 |
|
|
There are some "generic" versions of routines that can be used by
|
2408 |
|
|
various systems.
|
2409 |
|
|
|
2410 |
|
|
`ser-unix.c'
|
2411 |
|
|
This contains serial line support for Unix systems. It is
|
2412 |
|
|
included by default on all Unix-like hosts.
|
2413 |
|
|
|
2414 |
|
|
`ser-pipe.c'
|
2415 |
|
|
This contains serial pipe support for Unix systems. It is
|
2416 |
|
|
included by default on all Unix-like hosts.
|
2417 |
|
|
|
2418 |
|
|
`ser-mingw.c'
|
2419 |
|
|
This contains serial line support for 32-bit programs running under
|
2420 |
|
|
Windows using MinGW.
|
2421 |
|
|
|
2422 |
|
|
`ser-go32.c'
|
2423 |
|
|
This contains serial line support for 32-bit programs running
|
2424 |
|
|
under DOS, using the DJGPP (a.k.a. GO32) execution environment.
|
2425 |
|
|
|
2426 |
|
|
`ser-tcp.c'
|
2427 |
|
|
This contains generic TCP support using sockets. It is included by
|
2428 |
|
|
default on all Unix-like hosts and with MinGW.
|
2429 |
|
|
|
2430 |
|
|
10.2 Host Conditionals
|
2431 |
|
|
======================
|
2432 |
|
|
|
2433 |
|
|
When GDB is configured and compiled, various macros are defined or left
|
2434 |
|
|
undefined, to control compilation based on the attributes of the host
|
2435 |
|
|
system. While formerly they could be set in host-specific header
|
2436 |
|
|
files, at present they can be changed only by setting `CFLAGS' when
|
2437 |
|
|
building, or by editing the source code.
|
2438 |
|
|
|
2439 |
|
|
These macros and their meanings (or if the meaning is not documented
|
2440 |
|
|
here, then one of the source files where they are used is indicated)
|
2441 |
|
|
are:
|
2442 |
|
|
|
2443 |
|
|
`GDBINIT_FILENAME'
|
2444 |
|
|
The default name of GDB's initialization file (normally
|
2445 |
|
|
`.gdbinit').
|
2446 |
|
|
|
2447 |
|
|
`SIGWINCH_HANDLER'
|
2448 |
|
|
If your host defines `SIGWINCH', you can define this to be the name
|
2449 |
|
|
of a function to be called if `SIGWINCH' is received.
|
2450 |
|
|
|
2451 |
|
|
`SIGWINCH_HANDLER_BODY'
|
2452 |
|
|
Define this to expand into code that will define the function
|
2453 |
|
|
named by the expansion of `SIGWINCH_HANDLER'.
|
2454 |
|
|
|
2455 |
|
|
`CRLF_SOURCE_FILES'
|
2456 |
|
|
Define this if host files use `\r\n' rather than `\n' as a line
|
2457 |
|
|
terminator. This will cause source file listings to omit `\r'
|
2458 |
|
|
characters when printing and it will allow `\r\n' line endings of
|
2459 |
|
|
files which are "sourced" by gdb. It must be possible to open
|
2460 |
|
|
files in binary mode using `O_BINARY' or, for fopen, `"rb"'.
|
2461 |
|
|
|
2462 |
|
|
`DEFAULT_PROMPT'
|
2463 |
|
|
The default value of the prompt string (normally `"(gdb) "').
|
2464 |
|
|
|
2465 |
|
|
`DEV_TTY'
|
2466 |
|
|
The name of the generic TTY device, defaults to `"/dev/tty"'.
|
2467 |
|
|
|
2468 |
|
|
`ISATTY'
|
2469 |
|
|
Substitute for isatty, if not available.
|
2470 |
|
|
|
2471 |
|
|
`FOPEN_RB'
|
2472 |
|
|
Define this if binary files are opened the same way as text files.
|
2473 |
|
|
|
2474 |
|
|
`CC_HAS_LONG_LONG'
|
2475 |
|
|
Define this if the host C compiler supports `long long'. This is
|
2476 |
|
|
set by the `configure' script.
|
2477 |
|
|
|
2478 |
|
|
`PRINTF_HAS_LONG_LONG'
|
2479 |
|
|
Define this if the host can handle printing of long long integers
|
2480 |
|
|
via the printf format conversion specifier `ll'. This is set by
|
2481 |
|
|
the `configure' script.
|
2482 |
|
|
|
2483 |
|
|
`LSEEK_NOT_LINEAR'
|
2484 |
|
|
Define this if `lseek (n)' does not necessarily move to byte number
|
2485 |
|
|
`n' in the file. This is only used when reading source files. It
|
2486 |
|
|
is normally faster to define `CRLF_SOURCE_FILES' when possible.
|
2487 |
|
|
|
2488 |
|
|
`lint'
|
2489 |
|
|
Define this to help placate `lint' in some situations.
|
2490 |
|
|
|
2491 |
|
|
`volatile'
|
2492 |
|
|
Define this to override the defaults of `__volatile__' or `/**/'.
|
2493 |
|
|
|
2494 |
|
|
|
2495 |
|
|
File: gdbint.info, Node: Target Architecture Definition, Next: Target Descriptions, Prev: Host Definition, Up: Top
|
2496 |
|
|
|
2497 |
|
|
11 Target Architecture Definition
|
2498 |
|
|
*********************************
|
2499 |
|
|
|
2500 |
|
|
GDB's target architecture defines what sort of machine-language
|
2501 |
|
|
programs GDB can work with, and how it works with them.
|
2502 |
|
|
|
2503 |
|
|
The target architecture object is implemented as the C structure
|
2504 |
|
|
`struct gdbarch *'. The structure, and its methods, are generated
|
2505 |
|
|
using the Bourne shell script `gdbarch.sh'.
|
2506 |
|
|
|
2507 |
|
|
* Menu:
|
2508 |
|
|
|
2509 |
|
|
* OS ABI Variant Handling::
|
2510 |
|
|
* Initialize New Architecture::
|
2511 |
|
|
* Registers and Memory::
|
2512 |
|
|
* Pointers and Addresses::
|
2513 |
|
|
* Address Classes::
|
2514 |
|
|
* Register Representation::
|
2515 |
|
|
* Frame Interpretation::
|
2516 |
|
|
* Inferior Call Setup::
|
2517 |
|
|
* Adding support for debugging core files::
|
2518 |
|
|
* Defining Other Architecture Features::
|
2519 |
|
|
* Adding a New Target::
|
2520 |
|
|
|
2521 |
|
|
|
2522 |
|
|
File: gdbint.info, Node: OS ABI Variant Handling, Next: Initialize New Architecture, Up: Target Architecture Definition
|
2523 |
|
|
|
2524 |
|
|
11.1 Operating System ABI Variant Handling
|
2525 |
|
|
==========================================
|
2526 |
|
|
|
2527 |
|
|
GDB provides a mechanism for handling variations in OS ABIs. An OS ABI
|
2528 |
|
|
variant may have influence over any number of variables in the target
|
2529 |
|
|
architecture definition. There are two major components in the OS ABI
|
2530 |
|
|
mechanism: sniffers and handlers.
|
2531 |
|
|
|
2532 |
|
|
A "sniffer" examines a file matching a BFD architecture/flavour pair
|
2533 |
|
|
(the architecture may be wildcarded) in an attempt to determine the OS
|
2534 |
|
|
ABI of that file. Sniffers with a wildcarded architecture are
|
2535 |
|
|
considered to be "generic", while sniffers for a specific architecture
|
2536 |
|
|
are considered to be "specific". A match from a specific sniffer
|
2537 |
|
|
overrides a match from a generic sniffer. Multiple sniffers for an
|
2538 |
|
|
architecture/flavour may exist, in order to differentiate between two
|
2539 |
|
|
different operating systems which use the same basic file format. The
|
2540 |
|
|
OS ABI framework provides a generic sniffer for ELF-format files which
|
2541 |
|
|
examines the `EI_OSABI' field of the ELF header, as well as note
|
2542 |
|
|
sections known to be used by several operating systems.
|
2543 |
|
|
|
2544 |
|
|
A "handler" is used to fine-tune the `gdbarch' structure for the
|
2545 |
|
|
selected OS ABI. There may be only one handler for a given OS ABI for
|
2546 |
|
|
each BFD architecture.
|
2547 |
|
|
|
2548 |
|
|
The following OS ABI variants are defined in `defs.h':
|
2549 |
|
|
|
2550 |
|
|
`GDB_OSABI_UNINITIALIZED'
|
2551 |
|
|
Used for struct gdbarch_info if ABI is still uninitialized.
|
2552 |
|
|
|
2553 |
|
|
`GDB_OSABI_UNKNOWN'
|
2554 |
|
|
The ABI of the inferior is unknown. The default `gdbarch'
|
2555 |
|
|
settings for the architecture will be used.
|
2556 |
|
|
|
2557 |
|
|
`GDB_OSABI_SVR4'
|
2558 |
|
|
UNIX System V Release 4.
|
2559 |
|
|
|
2560 |
|
|
`GDB_OSABI_HURD'
|
2561 |
|
|
GNU using the Hurd kernel.
|
2562 |
|
|
|
2563 |
|
|
`GDB_OSABI_SOLARIS'
|
2564 |
|
|
Sun Solaris.
|
2565 |
|
|
|
2566 |
|
|
`GDB_OSABI_OSF1'
|
2567 |
|
|
OSF/1, including Digital UNIX and Compaq Tru64 UNIX.
|
2568 |
|
|
|
2569 |
|
|
`GDB_OSABI_LINUX'
|
2570 |
|
|
GNU using the Linux kernel.
|
2571 |
|
|
|
2572 |
|
|
`GDB_OSABI_FREEBSD_AOUT'
|
2573 |
|
|
FreeBSD using the `a.out' executable format.
|
2574 |
|
|
|
2575 |
|
|
`GDB_OSABI_FREEBSD_ELF'
|
2576 |
|
|
FreeBSD using the ELF executable format.
|
2577 |
|
|
|
2578 |
|
|
`GDB_OSABI_NETBSD_AOUT'
|
2579 |
|
|
NetBSD using the `a.out' executable format.
|
2580 |
|
|
|
2581 |
|
|
`GDB_OSABI_NETBSD_ELF'
|
2582 |
|
|
NetBSD using the ELF executable format.
|
2583 |
|
|
|
2584 |
|
|
`GDB_OSABI_OPENBSD_ELF'
|
2585 |
|
|
OpenBSD using the ELF executable format.
|
2586 |
|
|
|
2587 |
|
|
`GDB_OSABI_WINCE'
|
2588 |
|
|
Windows CE.
|
2589 |
|
|
|
2590 |
|
|
`GDB_OSABI_GO32'
|
2591 |
|
|
DJGPP.
|
2592 |
|
|
|
2593 |
|
|
`GDB_OSABI_IRIX'
|
2594 |
|
|
Irix.
|
2595 |
|
|
|
2596 |
|
|
`GDB_OSABI_INTERIX'
|
2597 |
|
|
Interix (Posix layer for MS-Windows systems).
|
2598 |
|
|
|
2599 |
|
|
`GDB_OSABI_HPUX_ELF'
|
2600 |
|
|
HP/UX using the ELF executable format.
|
2601 |
|
|
|
2602 |
|
|
`GDB_OSABI_HPUX_SOM'
|
2603 |
|
|
HP/UX using the SOM executable format.
|
2604 |
|
|
|
2605 |
|
|
`GDB_OSABI_QNXNTO'
|
2606 |
|
|
QNX Neutrino.
|
2607 |
|
|
|
2608 |
|
|
`GDB_OSABI_CYGWIN'
|
2609 |
|
|
Cygwin.
|
2610 |
|
|
|
2611 |
|
|
`GDB_OSABI_AIX'
|
2612 |
|
|
AIX.
|
2613 |
|
|
|
2614 |
|
|
|
2615 |
|
|
Here are the functions that make up the OS ABI framework:
|
2616 |
|
|
|
2617 |
|
|
-- Function: const char * gdbarch_osabi_name (enum gdb_osabi OSABI)
|
2618 |
|
|
Return the name of the OS ABI corresponding to OSABI.
|
2619 |
|
|
|
2620 |
|
|
-- Function: void gdbarch_register_osabi (enum bfd_architecture ARCH,
|
2621 |
|
|
unsigned long MACHINE, enum gdb_osabi OSABI, void
|
2622 |
|
|
(*INIT_OSABI)(struct gdbarch_info INFO, struct gdbarch
|
2623 |
|
|
*GDBARCH))
|
2624 |
|
|
Register the OS ABI handler specified by INIT_OSABI for the
|
2625 |
|
|
architecture, machine type and OS ABI specified by ARCH, MACHINE
|
2626 |
|
|
and OSABI. In most cases, a value of zero for the machine type,
|
2627 |
|
|
which implies the architecture's default machine type, will
|
2628 |
|
|
suffice.
|
2629 |
|
|
|
2630 |
|
|
-- Function: void gdbarch_register_osabi_sniffer (enum
|
2631 |
|
|
bfd_architecture ARCH, enum bfd_flavour FLAVOUR, enum
|
2632 |
|
|
gdb_osabi (*SNIFFER)(bfd *ABFD))
|
2633 |
|
|
Register the OS ABI file sniffer specified by SNIFFER for the BFD
|
2634 |
|
|
architecture/flavour pair specified by ARCH and FLAVOUR. If ARCH
|
2635 |
|
|
is `bfd_arch_unknown', the sniffer is considered to be generic,
|
2636 |
|
|
and is allowed to examine FLAVOUR-flavoured files for any
|
2637 |
|
|
architecture.
|
2638 |
|
|
|
2639 |
|
|
-- Function: enum gdb_osabi gdbarch_lookup_osabi (bfd *ABFD)
|
2640 |
|
|
Examine the file described by ABFD to determine its OS ABI. The
|
2641 |
|
|
value `GDB_OSABI_UNKNOWN' is returned if the OS ABI cannot be
|
2642 |
|
|
determined.
|
2643 |
|
|
|
2644 |
|
|
-- Function: void gdbarch_init_osabi (struct gdbarch info INFO, struct
|
2645 |
|
|
gdbarch *GDBARCH, enum gdb_osabi OSABI)
|
2646 |
|
|
Invoke the OS ABI handler corresponding to OSABI to fine-tune the
|
2647 |
|
|
`gdbarch' structure specified by GDBARCH. If a handler
|
2648 |
|
|
corresponding to OSABI has not been registered for GDBARCH's
|
2649 |
|
|
architecture, a warning will be issued and the debugging session
|
2650 |
|
|
will continue with the defaults already established for GDBARCH.
|
2651 |
|
|
|
2652 |
|
|
-- Function: void generic_elf_osabi_sniff_abi_tag_sections (bfd *ABFD,
|
2653 |
|
|
asection *SECT, void *OBJ)
|
2654 |
|
|
Helper routine for ELF file sniffers. Examine the file described
|
2655 |
|
|
by ABFD and look at ABI tag note sections to determine the OS ABI
|
2656 |
|
|
from the note. This function should be called via
|
2657 |
|
|
`bfd_map_over_sections'.
|
2658 |
|
|
|
2659 |
|
|
|
2660 |
|
|
File: gdbint.info, Node: Initialize New Architecture, Next: Registers and Memory, Prev: OS ABI Variant Handling, Up: Target Architecture Definition
|
2661 |
|
|
|
2662 |
|
|
11.2 Initializing a New Architecture
|
2663 |
|
|
====================================
|
2664 |
|
|
|
2665 |
|
|
* Menu:
|
2666 |
|
|
|
2667 |
|
|
* How an Architecture is Represented::
|
2668 |
|
|
* Looking Up an Existing Architecture::
|
2669 |
|
|
* Creating a New Architecture::
|
2670 |
|
|
|
2671 |
|
|
|
2672 |
|
|
File: gdbint.info, Node: How an Architecture is Represented, Next: Looking Up an Existing Architecture, Up: Initialize New Architecture
|
2673 |
|
|
|
2674 |
|
|
11.2.1 How an Architecture is Represented
|
2675 |
|
|
-----------------------------------------
|
2676 |
|
|
|
2677 |
|
|
Each `gdbarch' is associated with a single BFD architecture, via a
|
2678 |
|
|
`bfd_arch_ARCH' in the `bfd_architecture' enumeration. The `gdbarch'
|
2679 |
|
|
is registered by a call to `register_gdbarch_init', usually from the
|
2680 |
|
|
file's `_initialize_FILENAME' routine, which will be automatically
|
2681 |
|
|
called during GDB startup. The arguments are a BFD architecture
|
2682 |
|
|
constant and an initialization function.
|
2683 |
|
|
|
2684 |
|
|
A GDB description for a new architecture, ARCH is created by
|
2685 |
|
|
defining a global function `_initialize_ARCH_tdep', by convention in
|
2686 |
|
|
the source file `ARCH-tdep.c'. For example, in the case of the
|
2687 |
|
|
OpenRISC 1000, this function is called `_initialize_or1k_tdep' and is
|
2688 |
|
|
found in the file `or1k-tdep.c'.
|
2689 |
|
|
|
2690 |
|
|
The resulting object files containing the implementation of the
|
2691 |
|
|
`_initialize_ARCH_tdep' function are specified in the GDB
|
2692 |
|
|
`configure.tgt' file, which includes a large case statement pattern
|
2693 |
|
|
matching against the `--target' option of the `configure' script. The
|
2694 |
|
|
new `struct gdbarch' is created within the `_initialize_ARCH_tdep'
|
2695 |
|
|
function by calling `gdbarch_register':
|
2696 |
|
|
|
2697 |
|
|
void gdbarch_register (enum bfd_architecture ARCHITECTURE,
|
2698 |
|
|
gdbarch_init_ftype *INIT_FUNC,
|
2699 |
|
|
gdbarch_dump_tdep_ftype *TDEP_DUMP_FUNC);
|
2700 |
|
|
|
2701 |
|
|
The ARCHITECTURE will identify the unique BFD to be associated with
|
2702 |
|
|
this `gdbarch'. The INIT_FUNC funciton is called to create and return
|
2703 |
|
|
the new `struct gdbarch'. The TDEP_DUMP_FUNC function will dump the
|
2704 |
|
|
target specific details associated with this architecture.
|
2705 |
|
|
|
2706 |
|
|
For example the function `_initialize_or1k_tdep' creates its
|
2707 |
|
|
architecture for 32-bit OpenRISC 1000 architectures by calling:
|
2708 |
|
|
|
2709 |
|
|
gdbarch_register (bfd_arch_or32, or1k_gdbarch_init, or1k_dump_tdep);
|
2710 |
|
|
|
2711 |
|
|
|
2712 |
|
|
File: gdbint.info, Node: Looking Up an Existing Architecture, Next: Creating a New Architecture, Prev: How an Architecture is Represented, Up: Initialize New Architecture
|
2713 |
|
|
|
2714 |
|
|
11.2.2 Looking Up an Existing Architecture
|
2715 |
|
|
------------------------------------------
|
2716 |
|
|
|
2717 |
|
|
The initialization function has this prototype:
|
2718 |
|
|
|
2719 |
|
|
static struct gdbarch *
|
2720 |
|
|
ARCH_gdbarch_init (struct gdbarch_info INFO,
|
2721 |
|
|
struct gdbarch_list *ARCHES)
|
2722 |
|
|
|
2723 |
|
|
The INFO argument contains parameters used to select the correct
|
2724 |
|
|
architecture, and ARCHES is a list of architectures which have already
|
2725 |
|
|
been created with the same `bfd_arch_ARCH' value.
|
2726 |
|
|
|
2727 |
|
|
The initialization function should first make sure that INFO is
|
2728 |
|
|
acceptable, and return `NULL' if it is not. Then, it should search
|
2729 |
|
|
through ARCHES for an exact match to INFO, and return one if found.
|
2730 |
|
|
Lastly, if no exact match was found, it should create a new
|
2731 |
|
|
architecture based on INFO and return it.
|
2732 |
|
|
|
2733 |
|
|
The lookup is done using `gdbarch_list_lookup_by_info'. It is
|
2734 |
|
|
passed the list of existing architectures, ARCHES, and the `struct
|
2735 |
|
|
gdbarch_info', INFO, and returns the first matching architecture it
|
2736 |
|
|
finds, or `NULL' if none are found. If an architecture is found it can
|
2737 |
|
|
be returned as the result from the initialization function, otherwise a
|
2738 |
|
|
new `struct gdbach' will need to be created.
|
2739 |
|
|
|
2740 |
|
|
The struct gdbarch_info has the following components:
|
2741 |
|
|
|
2742 |
|
|
struct gdbarch_info
|
2743 |
|
|
{
|
2744 |
|
|
const struct bfd_arch_info *bfd_arch_info;
|
2745 |
|
|
int byte_order;
|
2746 |
|
|
bfd *abfd;
|
2747 |
|
|
struct gdbarch_tdep_info *tdep_info;
|
2748 |
|
|
enum gdb_osabi osabi;
|
2749 |
|
|
const struct target_desc *target_desc;
|
2750 |
|
|
};
|
2751 |
|
|
|
2752 |
|
|
The `bfd_arch_info' member holds the key details about the
|
2753 |
|
|
architecture. The `byte_order' member is a value in an enumeration
|
2754 |
|
|
indicating the endianism. The `abfd' member is a pointer to the full
|
2755 |
|
|
BFD, the `tdep_info' member is additional custom target specific
|
2756 |
|
|
information, `osabi' identifies which (if any) of a number of operating
|
2757 |
|
|
specific ABIs are used by this architecture and the `target_desc'
|
2758 |
|
|
member is a set of name-value pairs with information about register
|
2759 |
|
|
usage in this target.
|
2760 |
|
|
|
2761 |
|
|
When the `struct gdbarch' initialization function is called, not all
|
2762 |
|
|
the fields are provided--only those which can be deduced from the BFD.
|
2763 |
|
|
The `struct gdbarch_info', INFO is used as a look-up key with the list
|
2764 |
|
|
of existing architectures, ARCHES to see if a suitable architecture
|
2765 |
|
|
already exists. The TDEP_INFO, OSABI and TARGET_DESC fields may be
|
2766 |
|
|
added before this lookup to refine the search.
|
2767 |
|
|
|
2768 |
|
|
Only information in INFO should be used to choose the new
|
2769 |
|
|
architecture. Historically, INFO could be sparse, and defaults would
|
2770 |
|
|
be collected from the first element on ARCHES. However, GDB now fills
|
2771 |
|
|
in INFO more thoroughly, so new `gdbarch' initialization functions
|
2772 |
|
|
should not take defaults from ARCHES.
|
2773 |
|
|
|
2774 |
|
|
|
2775 |
|
|
File: gdbint.info, Node: Creating a New Architecture, Prev: Looking Up an Existing Architecture, Up: Initialize New Architecture
|
2776 |
|
|
|
2777 |
|
|
11.2.3 Creating a New Architecture
|
2778 |
|
|
----------------------------------
|
2779 |
|
|
|
2780 |
|
|
If no architecture is found, then a new architecture must be created,
|
2781 |
|
|
by calling `gdbarch_alloc' using the supplied `struct gdbarch_info' and
|
2782 |
|
|
any additional custom target specific information in a `struct
|
2783 |
|
|
gdbarch_tdep'. The prototype for `gdbarch_alloc' is:
|
2784 |
|
|
|
2785 |
|
|
struct gdbarch *gdbarch_alloc (const struct gdbarch_info *INFO,
|
2786 |
|
|
struct gdbarch_tdep *TDEP);
|
2787 |
|
|
|
2788 |
|
|
The newly created struct gdbarch must then be populated. Although
|
2789 |
|
|
there are default values, in most cases they are not what is required.
|
2790 |
|
|
|
2791 |
|
|
For each element, X, there is are a pair of corresponding accessor
|
2792 |
|
|
functions, one to set the value of that element, `set_gdbarch_X', the
|
2793 |
|
|
second to either get the value of an element (if it is a variable) or
|
2794 |
|
|
to apply the element (if it is a function), `gdbarch_X'. Note that
|
2795 |
|
|
both accessor functions take a pointer to the `struct gdbarch' as first
|
2796 |
|
|
argument. Populating the new `gdbarch' should use the `set_gdbarch'
|
2797 |
|
|
functions.
|
2798 |
|
|
|
2799 |
|
|
The following sections identify the main elements that should be set
|
2800 |
|
|
in this way. This is not the complete list, but represents the
|
2801 |
|
|
functions and elements that must commonly be specified for a new
|
2802 |
|
|
architecture. Many of the functions and variables are described in the
|
2803 |
|
|
header file `gdbarch.h'.
|
2804 |
|
|
|
2805 |
|
|
This is the main work in defining a new architecture. Implementing
|
2806 |
|
|
the set of functions to populate the `struct gdbarch'.
|
2807 |
|
|
|
2808 |
|
|
`struct gdbarch_tdep' is not defined within GDB--it is up to the
|
2809 |
|
|
user to define this struct if it is needed to hold custom target
|
2810 |
|
|
information that is not covered by the standard `struct gdbarch'. For
|
2811 |
|
|
example with the OpenRISC 1000 architecture it is used to hold the
|
2812 |
|
|
number of matchpoints available in the target (along with other
|
2813 |
|
|
information).
|
2814 |
|
|
|
2815 |
|
|
If there is no additional target specific information, it can be set
|
2816 |
|
|
to `NULL'.
|
2817 |
|
|
|
2818 |
|
|
|
2819 |
|
|
File: gdbint.info, Node: Registers and Memory, Next: Pointers and Addresses, Prev: Initialize New Architecture, Up: Target Architecture Definition
|
2820 |
|
|
|
2821 |
|
|
11.3 Registers and Memory
|
2822 |
|
|
=========================
|
2823 |
|
|
|
2824 |
|
|
GDB's model of the target machine is rather simple. GDB assumes the
|
2825 |
|
|
machine includes a bank of registers and a block of memory. Each
|
2826 |
|
|
register may have a different size.
|
2827 |
|
|
|
2828 |
|
|
GDB does not have a magical way to match up with the compiler's idea
|
2829 |
|
|
of which registers are which; however, it is critical that they do
|
2830 |
|
|
match up accurately. The only way to make this work is to get accurate
|
2831 |
|
|
information about the order that the compiler uses, and to reflect that
|
2832 |
|
|
in the `gdbarch_register_name' and related functions.
|
2833 |
|
|
|
2834 |
|
|
GDB can handle big-endian, little-endian, and bi-endian
|
2835 |
|
|
architectures.
|
2836 |
|
|
|
2837 |
|
|
|
2838 |
|
|
File: gdbint.info, Node: Pointers and Addresses, Next: Address Classes, Prev: Registers and Memory, Up: Target Architecture Definition
|
2839 |
|
|
|
2840 |
|
|
11.4 Pointers Are Not Always Addresses
|
2841 |
|
|
======================================
|
2842 |
|
|
|
2843 |
|
|
On almost all 32-bit architectures, the representation of a pointer is
|
2844 |
|
|
indistinguishable from the representation of some fixed-length number
|
2845 |
|
|
whose value is the byte address of the object pointed to. On such
|
2846 |
|
|
machines, the words "pointer" and "address" can be used interchangeably.
|
2847 |
|
|
However, architectures with smaller word sizes are often cramped for
|
2848 |
|
|
address space, so they may choose a pointer representation that breaks
|
2849 |
|
|
this identity, and allows a larger code address space.
|
2850 |
|
|
|
2851 |
|
|
For example, the Renesas D10V is a 16-bit VLIW processor whose
|
2852 |
|
|
instructions are 32 bits long(1). If the D10V used ordinary byte
|
2853 |
|
|
addresses to refer to code locations, then the processor would only be
|
2854 |
|
|
able to address 64kb of instructions. However, since instructions must
|
2855 |
|
|
be aligned on four-byte boundaries, the low two bits of any valid
|
2856 |
|
|
instruction's byte address are always zero--byte addresses waste two
|
2857 |
|
|
bits. So instead of byte addresses, the D10V uses word addresses--byte
|
2858 |
|
|
addresses shifted right two bits--to refer to code. Thus, the D10V can
|
2859 |
|
|
use 16-bit words to address 256kb of code space.
|
2860 |
|
|
|
2861 |
|
|
However, this means that code pointers and data pointers have
|
2862 |
|
|
different forms on the D10V. The 16-bit word `0xC020' refers to byte
|
2863 |
|
|
address `0xC020' when used as a data address, but refers to byte address
|
2864 |
|
|
`0x30080' when used as a code address.
|
2865 |
|
|
|
2866 |
|
|
(The D10V also uses separate code and data address spaces, which also
|
2867 |
|
|
affects the correspondence between pointers and addresses, but we're
|
2868 |
|
|
going to ignore that here; this example is already too long.)
|
2869 |
|
|
|
2870 |
|
|
To cope with architectures like this--the D10V is not the only
|
2871 |
|
|
one!--GDB tries to distinguish between "addresses", which are byte
|
2872 |
|
|
numbers, and "pointers", which are the target's representation of an
|
2873 |
|
|
address of a particular type of data. In the example above, `0xC020'
|
2874 |
|
|
is the pointer, which refers to one of the addresses `0xC020' or
|
2875 |
|
|
`0x30080', depending on the type imposed upon it. GDB provides
|
2876 |
|
|
functions for turning a pointer into an address and vice versa, in the
|
2877 |
|
|
appropriate way for the current architecture.
|
2878 |
|
|
|
2879 |
|
|
Unfortunately, since addresses and pointers are identical on almost
|
2880 |
|
|
all processors, this distinction tends to bit-rot pretty quickly. Thus,
|
2881 |
|
|
each time you port GDB to an architecture which does distinguish
|
2882 |
|
|
between pointers and addresses, you'll probably need to clean up some
|
2883 |
|
|
architecture-independent code.
|
2884 |
|
|
|
2885 |
|
|
Here are functions which convert between pointers and addresses:
|
2886 |
|
|
|
2887 |
|
|
-- Function: CORE_ADDR extract_typed_address (void *BUF, struct type
|
2888 |
|
|
*TYPE)
|
2889 |
|
|
Treat the bytes at BUF as a pointer or reference of type TYPE, and
|
2890 |
|
|
return the address it represents, in a manner appropriate for the
|
2891 |
|
|
current architecture. This yields an address GDB can use to read
|
2892 |
|
|
target memory, disassemble, etc. Note that BUF refers to a buffer
|
2893 |
|
|
in GDB's memory, not the inferior's.
|
2894 |
|
|
|
2895 |
|
|
For example, if the current architecture is the Intel x86, this
|
2896 |
|
|
function extracts a little-endian integer of the appropriate
|
2897 |
|
|
length from BUF and returns it. However, if the current
|
2898 |
|
|
architecture is the D10V, this function will return a 16-bit
|
2899 |
|
|
integer extracted from BUF, multiplied by four if TYPE is a
|
2900 |
|
|
pointer to a function.
|
2901 |
|
|
|
2902 |
|
|
If TYPE is not a pointer or reference type, then this function
|
2903 |
|
|
will signal an internal error.
|
2904 |
|
|
|
2905 |
|
|
-- Function: CORE_ADDR store_typed_address (void *BUF, struct type
|
2906 |
|
|
*TYPE, CORE_ADDR ADDR)
|
2907 |
|
|
Store the address ADDR in BUF, in the proper format for a pointer
|
2908 |
|
|
of type TYPE in the current architecture. Note that BUF refers to
|
2909 |
|
|
a buffer in GDB's memory, not the inferior's.
|
2910 |
|
|
|
2911 |
|
|
For example, if the current architecture is the Intel x86, this
|
2912 |
|
|
function stores ADDR unmodified as a little-endian integer of the
|
2913 |
|
|
appropriate length in BUF. However, if the current architecture
|
2914 |
|
|
is the D10V, this function divides ADDR by four if TYPE is a
|
2915 |
|
|
pointer to a function, and then stores it in BUF.
|
2916 |
|
|
|
2917 |
|
|
If TYPE is not a pointer or reference type, then this function
|
2918 |
|
|
will signal an internal error.
|
2919 |
|
|
|
2920 |
|
|
-- Function: CORE_ADDR value_as_address (struct value *VAL)
|
2921 |
|
|
Assuming that VAL is a pointer, return the address it represents,
|
2922 |
|
|
as appropriate for the current architecture.
|
2923 |
|
|
|
2924 |
|
|
This function actually works on integral values, as well as
|
2925 |
|
|
pointers. For pointers, it performs architecture-specific
|
2926 |
|
|
conversions as described above for `extract_typed_address'.
|
2927 |
|
|
|
2928 |
|
|
-- Function: CORE_ADDR value_from_pointer (struct type *TYPE,
|
2929 |
|
|
CORE_ADDR ADDR)
|
2930 |
|
|
Create and return a value representing a pointer of type TYPE to
|
2931 |
|
|
the address ADDR, as appropriate for the current architecture.
|
2932 |
|
|
This function performs architecture-specific conversions as
|
2933 |
|
|
described above for `store_typed_address'.
|
2934 |
|
|
|
2935 |
|
|
Here are two functions which architectures can define to indicate the
|
2936 |
|
|
relationship between pointers and addresses. These have default
|
2937 |
|
|
definitions, appropriate for architectures on which all pointers are
|
2938 |
|
|
simple unsigned byte addresses.
|
2939 |
|
|
|
2940 |
|
|
-- Function: CORE_ADDR gdbarch_pointer_to_address (struct gdbarch
|
2941 |
|
|
*GDBARCH, struct type *TYPE, char *BUF)
|
2942 |
|
|
Assume that BUF holds a pointer of type TYPE, in the appropriate
|
2943 |
|
|
format for the current architecture. Return the byte address the
|
2944 |
|
|
pointer refers to.
|
2945 |
|
|
|
2946 |
|
|
This function may safely assume that TYPE is either a pointer or a
|
2947 |
|
|
C++ reference type.
|
2948 |
|
|
|
2949 |
|
|
-- Function: void gdbarch_address_to_pointer (struct gdbarch *GDBARCH,
|
2950 |
|
|
struct type *TYPE, char *BUF, CORE_ADDR ADDR)
|
2951 |
|
|
Store in BUF a pointer of type TYPE representing the address ADDR,
|
2952 |
|
|
in the appropriate format for the current architecture.
|
2953 |
|
|
|
2954 |
|
|
This function may safely assume that TYPE is either a pointer or a
|
2955 |
|
|
C++ reference type.
|
2956 |
|
|
|
2957 |
|
|
---------- Footnotes ----------
|
2958 |
|
|
|
2959 |
|
|
(1) Some D10V instructions are actually pairs of 16-bit
|
2960 |
|
|
sub-instructions. However, since you can't jump into the middle of
|
2961 |
|
|
such a pair, code addresses can only refer to full 32 bit instructions,
|
2962 |
|
|
which is what matters in this explanation.
|
2963 |
|
|
|
2964 |
|
|
|
2965 |
|
|
File: gdbint.info, Node: Address Classes, Next: Register Representation, Prev: Pointers and Addresses, Up: Target Architecture Definition
|
2966 |
|
|
|
2967 |
|
|
11.5 Address Classes
|
2968 |
|
|
====================
|
2969 |
|
|
|
2970 |
|
|
Sometimes information about different kinds of addresses is available
|
2971 |
|
|
via the debug information. For example, some programming environments
|
2972 |
|
|
define addresses of several different sizes. If the debug information
|
2973 |
|
|
distinguishes these kinds of address classes through either the size
|
2974 |
|
|
info (e.g, `DW_AT_byte_size' in DWARF 2) or through an explicit address
|
2975 |
|
|
class attribute (e.g, `DW_AT_address_class' in DWARF 2), the following
|
2976 |
|
|
macros should be defined in order to disambiguate these types within
|
2977 |
|
|
GDB as well as provide the added information to a GDB user when
|
2978 |
|
|
printing type expressions.
|
2979 |
|
|
|
2980 |
|
|
-- Function: int gdbarch_address_class_type_flags (struct gdbarch
|
2981 |
|
|
*GDBARCH, int BYTE_SIZE, int DWARF2_ADDR_CLASS)
|
2982 |
|
|
Returns the type flags needed to construct a pointer type whose
|
2983 |
|
|
size is BYTE_SIZE and whose address class is DWARF2_ADDR_CLASS.
|
2984 |
|
|
This function is normally called from within a symbol reader. See
|
2985 |
|
|
`dwarf2read.c'.
|
2986 |
|
|
|
2987 |
|
|
-- Function: char * gdbarch_address_class_type_flags_to_name (struct
|
2988 |
|
|
gdbarch *GDBARCH, int TYPE_FLAGS)
|
2989 |
|
|
Given the type flags representing an address class qualifier,
|
2990 |
|
|
return its name.
|
2991 |
|
|
|
2992 |
|
|
-- Function: int gdbarch_address_class_name_to_type_flags (struct
|
2993 |
|
|
gdbarch *GDBARCH, int NAME, int *TYPE_FLAGS_PTR)
|
2994 |
|
|
Given an address qualifier name, set the `int' referenced by
|
2995 |
|
|
TYPE_FLAGS_PTR to the type flags for that address class qualifier.
|
2996 |
|
|
|
2997 |
|
|
Since the need for address classes is rather rare, none of the
|
2998 |
|
|
address class functions are defined by default. Predicate functions
|
2999 |
|
|
are provided to detect when they are defined.
|
3000 |
|
|
|
3001 |
|
|
Consider a hypothetical architecture in which addresses are normally
|
3002 |
|
|
32-bits wide, but 16-bit addresses are also supported. Furthermore,
|
3003 |
|
|
suppose that the DWARF 2 information for this architecture simply uses
|
3004 |
|
|
a `DW_AT_byte_size' value of 2 to indicate the use of one of these
|
3005 |
|
|
"short" pointers. The following functions could be defined to
|
3006 |
|
|
implement the address class functions:
|
3007 |
|
|
|
3008 |
|
|
somearch_address_class_type_flags (int byte_size,
|
3009 |
|
|
int dwarf2_addr_class)
|
3010 |
|
|
{
|
3011 |
|
|
if (byte_size == 2)
|
3012 |
|
|
return TYPE_FLAG_ADDRESS_CLASS_1;
|
3013 |
|
|
else
|
3014 |
|
|
return 0;
|
3015 |
|
|
}
|
3016 |
|
|
|
3017 |
|
|
static char *
|
3018 |
|
|
somearch_address_class_type_flags_to_name (int type_flags)
|
3019 |
|
|
{
|
3020 |
|
|
if (type_flags & TYPE_FLAG_ADDRESS_CLASS_1)
|
3021 |
|
|
return "short";
|
3022 |
|
|
else
|
3023 |
|
|
return NULL;
|
3024 |
|
|
}
|
3025 |
|
|
|
3026 |
|
|
int
|
3027 |
|
|
somearch_address_class_name_to_type_flags (char *name,
|
3028 |
|
|
int *type_flags_ptr)
|
3029 |
|
|
{
|
3030 |
|
|
if (strcmp (name, "short") == 0)
|
3031 |
|
|
{
|
3032 |
|
|
*type_flags_ptr = TYPE_FLAG_ADDRESS_CLASS_1;
|
3033 |
|
|
return 1;
|
3034 |
|
|
}
|
3035 |
|
|
else
|
3036 |
|
|
return 0;
|
3037 |
|
|
}
|
3038 |
|
|
|
3039 |
|
|
The qualifier `@short' is used in GDB's type expressions to indicate
|
3040 |
|
|
the presence of one of these "short" pointers. For example if the
|
3041 |
|
|
debug information indicates that `short_ptr_var' is one of these short
|
3042 |
|
|
pointers, GDB might show the following behavior:
|
3043 |
|
|
|
3044 |
|
|
(gdb) ptype short_ptr_var
|
3045 |
|
|
type = int * @short
|
3046 |
|
|
|
3047 |
|
|
|
3048 |
|
|
File: gdbint.info, Node: Register Representation, Next: Frame Interpretation, Prev: Address Classes, Up: Target Architecture Definition
|
3049 |
|
|
|
3050 |
|
|
11.6 Register Representation
|
3051 |
|
|
============================
|
3052 |
|
|
|
3053 |
|
|
* Menu:
|
3054 |
|
|
|
3055 |
|
|
* Raw and Cooked Registers::
|
3056 |
|
|
* Register Architecture Functions & Variables::
|
3057 |
|
|
* Register Information Functions::
|
3058 |
|
|
* Register and Memory Data::
|
3059 |
|
|
* Register Caching::
|
3060 |
|
|
|
3061 |
|
|
|
3062 |
|
|
File: gdbint.info, Node: Raw and Cooked Registers, Next: Register Architecture Functions & Variables, Up: Register Representation
|
3063 |
|
|
|
3064 |
|
|
11.6.1 Raw and Cooked Registers
|
3065 |
|
|
-------------------------------
|
3066 |
|
|
|
3067 |
|
|
GDB considers registers to be a set with members numbered linearly from
|
3068 |
|
|
|
3069 |
|
|
registers, the second part to any "pseudo-registers". Pseudo-registers
|
3070 |
|
|
have no independent physical existence, but are useful representations
|
3071 |
|
|
of information within the architecture. For example the OpenRISC 1000
|
3072 |
|
|
architecture has up to 32 general purpose registers, which are
|
3073 |
|
|
typically represented as 32-bit (or 64-bit) integers. However the GPRs
|
3074 |
|
|
are also used as operands to the floating point operations, and it
|
3075 |
|
|
could be convenient to define a set of pseudo-registers, to show the
|
3076 |
|
|
GPRs represented as floating point values.
|
3077 |
|
|
|
3078 |
|
|
For any architecture, the implementer will decide on a mapping from
|
3079 |
|
|
hardware to GDB register numbers. The registers corresponding to real
|
3080 |
|
|
hardware are referred to as "raw" registers, the remaining registers are
|
3081 |
|
|
"pseudo-registers". The total register set (raw and pseudo) is called
|
3082 |
|
|
the "cooked" register set.
|
3083 |
|
|
|
3084 |
|
|
|
3085 |
|
|
File: gdbint.info, Node: Register Architecture Functions & Variables, Next: Register Information Functions, Prev: Raw and Cooked Registers, Up: Register Representation
|
3086 |
|
|
|
3087 |
|
|
11.6.2 Functions and Variables Specifying the Register Architecture
|
3088 |
|
|
-------------------------------------------------------------------
|
3089 |
|
|
|
3090 |
|
|
These `struct gdbarch' functions and variables specify the number and
|
3091 |
|
|
type of registers in the architecture.
|
3092 |
|
|
|
3093 |
|
|
-- Architecture Function: CORE_ADDR read_pc (struct regcache *REGCACHE)
|
3094 |
|
|
|
3095 |
|
|
-- Architecture Function: void write_pc (struct regcache *REGCACHE,
|
3096 |
|
|
CORE_ADDR VAL)
|
3097 |
|
|
Read or write the program counter. The default value of both
|
3098 |
|
|
functions is `NULL' (no function available). If the program
|
3099 |
|
|
counter is just an ordinary register, it can be specified in
|
3100 |
|
|
`struct gdbarch' instead (see `pc_regnum' below) and it will be
|
3101 |
|
|
read or written using the standard routines to access registers.
|
3102 |
|
|
This function need only be specified if the program counter is not
|
3103 |
|
|
an ordinary register.
|
3104 |
|
|
|
3105 |
|
|
Any register information can be obtained using the supplied
|
3106 |
|
|
register cache, REGCACHE. *Note Register Caching: Register
|
3107 |
|
|
Caching.
|
3108 |
|
|
|
3109 |
|
|
|
3110 |
|
|
-- Architecture Function: void pseudo_register_read (struct gdbarch
|
3111 |
|
|
*GDBARCH, struct regcache *REGCACHE, int REGNUM, const
|
3112 |
|
|
gdb_byte *BUF)
|
3113 |
|
|
|
3114 |
|
|
-- Architecture Function: void pseudo_register_write (struct gdbarch
|
3115 |
|
|
*GDBARCH, struct regcache *REGCACHE, int REGNUM, const
|
3116 |
|
|
gdb_byte *BUF)
|
3117 |
|
|
These functions should be defined if there are any
|
3118 |
|
|
pseudo-registers. The default value is `NULL'. REGNUM is the
|
3119 |
|
|
number of the register to read or write (which will be a "cooked"
|
3120 |
|
|
register number) and BUF is the buffer where the value read will be
|
3121 |
|
|
placed, or from which the value to be written will be taken. The
|
3122 |
|
|
value in the buffer may be converted to or from a signed or
|
3123 |
|
|
unsigned integral value using one of the utility functions (*note
|
3124 |
|
|
Using Different Register and Memory Data Representations: Register
|
3125 |
|
|
and Memory Data.).
|
3126 |
|
|
|
3127 |
|
|
The access should be for the specified architecture, GDBARCH. Any
|
3128 |
|
|
register information can be obtained using the supplied register
|
3129 |
|
|
cache, REGCACHE. *Note Register Caching: Register Caching.
|
3130 |
|
|
|
3131 |
|
|
|
3132 |
|
|
-- Architecture Variable: int sp_regnum
|
3133 |
|
|
This specifies the register holding the stack pointer, which may
|
3134 |
|
|
be a raw or pseudo-register. It defaults to -1 (not defined), but
|
3135 |
|
|
it is an error for it not to be defined.
|
3136 |
|
|
|
3137 |
|
|
The value of the stack pointer register can be accessed withing
|
3138 |
|
|
GDB as the variable `$sp'.
|
3139 |
|
|
|
3140 |
|
|
|
3141 |
|
|
-- Architecture Variable: int pc_regnum
|
3142 |
|
|
This specifies the register holding the program counter, which may
|
3143 |
|
|
be a raw or pseudo-register. It defaults to -1 (not defined). If
|
3144 |
|
|
`pc_regnum' is not defined, then the functions `read_pc' and
|
3145 |
|
|
`write_pc' (see above) must be defined.
|
3146 |
|
|
|
3147 |
|
|
The value of the program counter (whether defined as a register, or
|
3148 |
|
|
through `read_pc' and `write_pc') can be accessed withing GDB as
|
3149 |
|
|
the variable `$pc'.
|
3150 |
|
|
|
3151 |
|
|
|
3152 |
|
|
-- Architecture Variable: int ps_regnum
|
3153 |
|
|
This specifies the register holding the processor status (often
|
3154 |
|
|
called the status register), which may be a raw or
|
3155 |
|
|
pseudo-register. It defaults to -1 (not defined).
|
3156 |
|
|
|
3157 |
|
|
If defined, the value of this register can be accessed withing GDB
|
3158 |
|
|
as the variable `$ps'.
|
3159 |
|
|
|
3160 |
|
|
|
3161 |
|
|
-- Architecture Variable: int fp0_regnum
|
3162 |
|
|
This specifies the first floating point register. It defaults to
|
3163 |
|
|
0. `fp0_regnum' is not needed unless the target offers support
|
3164 |
|
|
for floating point.
|
3165 |
|
|
|
3166 |
|
|
|
3167 |
|
|
|
3168 |
|
|
File: gdbint.info, Node: Register Information Functions, Next: Register and Memory Data, Prev: Register Architecture Functions & Variables, Up: Register Representation
|
3169 |
|
|
|
3170 |
|
|
11.6.3 Functions Giving Register Information
|
3171 |
|
|
--------------------------------------------
|
3172 |
|
|
|
3173 |
|
|
These functions return information about registers.
|
3174 |
|
|
|
3175 |
|
|
-- Architecture Function: const char * register_name (struct gdbarch
|
3176 |
|
|
*GDBARCH, int REGNUM)
|
3177 |
|
|
This function should convert a register number (raw or pseudo) to a
|
3178 |
|
|
register name (as a C `const char *'). This is used both to
|
3179 |
|
|
determine the name of a register for output and to work out the
|
3180 |
|
|
meaning of any register names used as input. The function may
|
3181 |
|
|
also return `NULL', to indicate that REGNUM is not a valid
|
3182 |
|
|
register.
|
3183 |
|
|
|
3184 |
|
|
For example with the OpenRISC 1000, GDB registers 0-31 are the
|
3185 |
|
|
General Purpose Registers, register 32 is the program counter and
|
3186 |
|
|
register 33 is the supervision register (i.e. the processor status
|
3187 |
|
|
register), which map to the strings `"gpr00"' through `"gpr31"',
|
3188 |
|
|
`"pc"' and `"sr"' respectively. This means that the GDB command
|
3189 |
|
|
`print $gpr5' should print the value of the OR1K general purpose
|
3190 |
|
|
register 5(1).
|
3191 |
|
|
|
3192 |
|
|
The default value for this function is `NULL', meaning undefined.
|
3193 |
|
|
It should always be defined.
|
3194 |
|
|
|
3195 |
|
|
The access should be for the specified architecture, GDBARCH.
|
3196 |
|
|
|
3197 |
|
|
|
3198 |
|
|
-- Architecture Function: struct type * register_type (struct gdbarch
|
3199 |
|
|
*GDBARCH, int REGNUM)
|
3200 |
|
|
Given a register number, this function identifies the type of data
|
3201 |
|
|
it may be holding, specified as a `struct type'. GDB allows
|
3202 |
|
|
creation of arbitrary types, but a number of built in types are
|
3203 |
|
|
provided (`builtin_type_void', `builtin_type_int32' etc), together
|
3204 |
|
|
with functions to derive types from these.
|
3205 |
|
|
|
3206 |
|
|
Typically the program counter will have a type of "pointer to
|
3207 |
|
|
function" (it points to code), the frame pointer and stack pointer
|
3208 |
|
|
will have types of "pointer to void" (they point to data on the
|
3209 |
|
|
stack) and all other integer registers will have a type of 32-bit
|
3210 |
|
|
integer or 64-bit integer.
|
3211 |
|
|
|
3212 |
|
|
This information guides the formatting when displaying register
|
3213 |
|
|
information. The default value is `NULL' meaning no information is
|
3214 |
|
|
available to guide formatting when displaying registers.
|
3215 |
|
|
|
3216 |
|
|
|
3217 |
|
|
-- Architecture Function: void print_registers_info (struct gdbarch
|
3218 |
|
|
*GDBARCH, struct ui_file *FILE, struct frame_info *FRAME, int
|
3219 |
|
|
REGNUM, int ALL)
|
3220 |
|
|
Define this function to print out one or all of the registers for
|
3221 |
|
|
the GDB `info registers' command. The default value is the
|
3222 |
|
|
function `default_print_registers_info', which uses the register
|
3223 |
|
|
type information (see `register_type' above) to determine how each
|
3224 |
|
|
register should be printed. Define a custom version of this
|
3225 |
|
|
function for fuller control over how the registers are displayed.
|
3226 |
|
|
|
3227 |
|
|
The access should be for the specified architecture, GDBARCH, with
|
3228 |
|
|
output to the the file specified by the User Interface Independent
|
3229 |
|
|
Output file handle, FILE (*note UI-Independent Output--the
|
3230 |
|
|
`ui_out' Functions: UI-Independent Output.).
|
3231 |
|
|
|
3232 |
|
|
The registers should show their values in the frame specified by
|
3233 |
|
|
FRAME. If REGNUM is -1 and ALL is zero, then all the
|
3234 |
|
|
"significant" registers should be shown (the implementer should
|
3235 |
|
|
decide which registers are "significant"). Otherwise only the
|
3236 |
|
|
value of the register specified by REGNUM should be output. If
|
3237 |
|
|
REGNUM is -1 and ALL is non-zero (true), then the value of all
|
3238 |
|
|
registers should be shown.
|
3239 |
|
|
|
3240 |
|
|
By default `default_print_registers_info' prints one register per
|
3241 |
|
|
line, and if ALL is zero omits floating-point registers.
|
3242 |
|
|
|
3243 |
|
|
|
3244 |
|
|
-- Architecture Function: void print_float_info (struct gdbarch
|
3245 |
|
|
*GDBARCH, struct ui_file *FILE, struct frame_info *FRAME,
|
3246 |
|
|
const char *ARGS)
|
3247 |
|
|
Define this function to provide output about the floating point
|
3248 |
|
|
unit and registers for the GDB `info float' command respectively.
|
3249 |
|
|
The default value is `NULL' (not defined), meaning no information
|
3250 |
|
|
will be provided.
|
3251 |
|
|
|
3252 |
|
|
The GDBARCH and FILE and FRAME arguments have the same meaning as
|
3253 |
|
|
in the `print_registers_info' function above. The string ARGS
|
3254 |
|
|
contains any supplementary arguments to the `info float' command.
|
3255 |
|
|
|
3256 |
|
|
Define this function if the target supports floating point
|
3257 |
|
|
operations.
|
3258 |
|
|
|
3259 |
|
|
|
3260 |
|
|
-- Architecture Function: void print_vector_info (struct gdbarch
|
3261 |
|
|
*GDBARCH, struct ui_file *FILE, struct frame_info *FRAME,
|
3262 |
|
|
const char *ARGS)
|
3263 |
|
|
Define this function to provide output about the vector unit and
|
3264 |
|
|
registers for the GDB `info vector' command respectively. The
|
3265 |
|
|
default value is `NULL' (not defined), meaning no information will
|
3266 |
|
|
be provided.
|
3267 |
|
|
|
3268 |
|
|
The GDBARCH, FILE and FRAME arguments have the same meaning as in
|
3269 |
|
|
the `print_registers_info' function above. The string ARGS
|
3270 |
|
|
contains any supplementary arguments to the `info vector' command.
|
3271 |
|
|
|
3272 |
|
|
Define this function if the target supports vector operations.
|
3273 |
|
|
|
3274 |
|
|
|
3275 |
|
|
-- Architecture Function: int register_reggroup_p (struct gdbarch
|
3276 |
|
|
*GDBARCH, int REGNUM, struct reggroup *GROUP)
|
3277 |
|
|
GDB groups registers into different categories (general, vector,
|
3278 |
|
|
floating point etc). This function, given a register, REGNUM, and
|
3279 |
|
|
group, GROUP, returns 1 (true) if the register is in the group and
|
3280 |
|
|
|
3281 |
|
|
|
3282 |
|
|
The information should be for the specified architecture, GDBARCH
|
3283 |
|
|
|
3284 |
|
|
The default value is the function `default_register_reggroup_p'
|
3285 |
|
|
which will do a reasonable job based on the type of the register
|
3286 |
|
|
(see the function `register_type' above), with groups for general
|
3287 |
|
|
purpose registers, floating point registers, vector registers and
|
3288 |
|
|
raw (i.e not pseudo) registers.
|
3289 |
|
|
|
3290 |
|
|
|
3291 |
|
|
---------- Footnotes ----------
|
3292 |
|
|
|
3293 |
|
|
(1) Historically, GDB always had a concept of a frame pointer
|
3294 |
|
|
register, which could be accessed via the GDB variable, `$fp'. That
|
3295 |
|
|
concept is now deprecated, recognizing that not all architectures have
|
3296 |
|
|
a frame pointer. However if an architecture does have a frame pointer
|
3297 |
|
|
register, and defines a register or pseudo-register with the name
|
3298 |
|
|
`"fp"', then that register will be used as the value of the `$fp'
|
3299 |
|
|
variable.
|
3300 |
|
|
|
3301 |
|
|
|
3302 |
|
|
File: gdbint.info, Node: Register and Memory Data, Next: Register Caching, Prev: Register Information Functions, Up: Register Representation
|
3303 |
|
|
|
3304 |
|
|
11.6.4 Using Different Register and Memory Data Representations
|
3305 |
|
|
---------------------------------------------------------------
|
3306 |
|
|
|
3307 |
|
|
Some architectures have different representations of data objects,
|
3308 |
|
|
depending whether the object is held in a register or memory. For
|
3309 |
|
|
example:
|
3310 |
|
|
|
3311 |
|
|
* The Alpha architecture can represent 32 bit integer values in
|
3312 |
|
|
floating-point registers.
|
3313 |
|
|
|
3314 |
|
|
* The x86 architecture supports 80-bit floating-point registers. The
|
3315 |
|
|
`long double' data type occupies 96 bits in memory but only 80
|
3316 |
|
|
bits when stored in a register.
|
3317 |
|
|
|
3318 |
|
|
|
3319 |
|
|
In general, the register representation of a data type is determined
|
3320 |
|
|
by the architecture, or GDB's interface to the architecture, while the
|
3321 |
|
|
memory representation is determined by the Application Binary Interface.
|
3322 |
|
|
|
3323 |
|
|
For almost all data types on almost all architectures, the two
|
3324 |
|
|
representations are identical, and no special handling is needed.
|
3325 |
|
|
However, they do occasionally differ. An architecture may define the
|
3326 |
|
|
following `struct gdbarch' functions to request conversions between the
|
3327 |
|
|
register and memory representations of a data type:
|
3328 |
|
|
|
3329 |
|
|
-- Architecture Function: int gdbarch_convert_register_p (struct
|
3330 |
|
|
gdbarch *GDBARCH, int REG)
|
3331 |
|
|
Return non-zero (true) if the representation of a data value
|
3332 |
|
|
stored in this register may be different to the representation of
|
3333 |
|
|
that same data value when stored in memory. The default value is
|
3334 |
|
|
`NULL' (undefined).
|
3335 |
|
|
|
3336 |
|
|
If this function is defined and returns non-zero, the `struct
|
3337 |
|
|
gdbarch' functions `gdbarch_register_to_value' and
|
3338 |
|
|
`gdbarch_value_to_register' (see below) should be used to perform
|
3339 |
|
|
any necessary conversion.
|
3340 |
|
|
|
3341 |
|
|
If defined, this function should return zero for the register's
|
3342 |
|
|
native type, when no conversion is necessary.
|
3343 |
|
|
|
3344 |
|
|
-- Architecture Function: void gdbarch_register_to_value (struct
|
3345 |
|
|
gdbarch *GDBARCH, int REG, struct type *TYPE, char *FROM,
|
3346 |
|
|
char *TO)
|
3347 |
|
|
Convert the value of register number REG to a data object of type
|
3348 |
|
|
TYPE. The buffer at FROM holds the register's value in raw
|
3349 |
|
|
format; the converted value should be placed in the buffer at TO.
|
3350 |
|
|
|
3351 |
|
|
_Note:_ `gdbarch_register_to_value' and
|
3352 |
|
|
`gdbarch_value_to_register' take their REG and TYPE arguments
|
3353 |
|
|
in different orders.
|
3354 |
|
|
|
3355 |
|
|
`gdbarch_register_to_value' should only be used with registers for
|
3356 |
|
|
which the `gdbarch_convert_register_p' function returns a non-zero
|
3357 |
|
|
value.
|
3358 |
|
|
|
3359 |
|
|
|
3360 |
|
|
-- Architecture Function: void gdbarch_value_to_register (struct
|
3361 |
|
|
gdbarch *GDBARCH, struct type *TYPE, int REG, char *FROM,
|
3362 |
|
|
char *TO)
|
3363 |
|
|
Convert a data value of type TYPE to register number REG' raw
|
3364 |
|
|
format.
|
3365 |
|
|
|
3366 |
|
|
_Note:_ `gdbarch_register_to_value' and
|
3367 |
|
|
`gdbarch_value_to_register' take their REG and TYPE arguments
|
3368 |
|
|
in different orders.
|
3369 |
|
|
|
3370 |
|
|
`gdbarch_value_to_register' should only be used with registers for
|
3371 |
|
|
which the `gdbarch_convert_register_p' function returns a non-zero
|
3372 |
|
|
value.
|
3373 |
|
|
|
3374 |
|
|
|
3375 |
|
|
|
3376 |
|
|
File: gdbint.info, Node: Register Caching, Prev: Register and Memory Data, Up: Register Representation
|
3377 |
|
|
|
3378 |
|
|
11.6.5 Register Caching
|
3379 |
|
|
-----------------------
|
3380 |
|
|
|
3381 |
|
|
Caching of registers is used, so that the target does not need to be
|
3382 |
|
|
accessed and reanalyzed multiple times for each register in
|
3383 |
|
|
circumstances where the register value cannot have changed.
|
3384 |
|
|
|
3385 |
|
|
GDB provides `struct regcache', associated with a particular `struct
|
3386 |
|
|
gdbarch' to hold the cached values of the raw registers. A set of
|
3387 |
|
|
functions is provided to access both the raw registers (with `raw' in
|
3388 |
|
|
their name) and the full set of cooked registers (with `cooked' in
|
3389 |
|
|
their name). Functions are provided to ensure the register cache is
|
3390 |
|
|
kept synchronized with the values of the actual registers in the target.
|
3391 |
|
|
|
3392 |
|
|
Accessing registers through the `struct regcache' routines will
|
3393 |
|
|
ensure that the appropriate `struct gdbarch' functions are called when
|
3394 |
|
|
necessary to access the underlying target architecture. In general
|
3395 |
|
|
users should use the "cooked" functions, since these will map to the
|
3396 |
|
|
"raw" functions automatically as appropriate.
|
3397 |
|
|
|
3398 |
|
|
The two key functions are `regcache_cooked_read' and
|
3399 |
|
|
`regcache_cooked_write' which read or write a register from or to a
|
3400 |
|
|
byte buffer (type `gdb_byte *'). For convenience the wrapper functions
|
3401 |
|
|
`regcache_cooked_read_signed', `regcache_cooked_read_unsigned',
|
3402 |
|
|
`regcache_cooked_write_signed' and `regcache_cooked_write_unsigned' are
|
3403 |
|
|
provided, which read or write the value using the buffer and convert to
|
3404 |
|
|
or from an integral value as appropriate.
|
3405 |
|
|
|
3406 |
|
|
|
3407 |
|
|
File: gdbint.info, Node: Frame Interpretation, Next: Inferior Call Setup, Prev: Register Representation, Up: Target Architecture Definition
|
3408 |
|
|
|
3409 |
|
|
11.7 Frame Interpretation
|
3410 |
|
|
=========================
|
3411 |
|
|
|
3412 |
|
|
* Menu:
|
3413 |
|
|
|
3414 |
|
|
* All About Stack Frames::
|
3415 |
|
|
* Frame Handling Terminology::
|
3416 |
|
|
* Prologue Caches::
|
3417 |
|
|
* Functions and Variable to Analyze Frames::
|
3418 |
|
|
* Functions to Access Frame Data::
|
3419 |
|
|
* Analyzing Stacks---Frame Sniffers::
|
3420 |
|
|
|
3421 |
|
|
|
3422 |
|
|
File: gdbint.info, Node: All About Stack Frames, Next: Frame Handling Terminology, Up: Frame Interpretation
|
3423 |
|
|
|
3424 |
|
|
11.7.1 All About Stack Frames
|
3425 |
|
|
-----------------------------
|
3426 |
|
|
|
3427 |
|
|
GDB needs to understand the stack on which local (automatic) variables
|
3428 |
|
|
are stored. The area of the stack containing all the local variables
|
3429 |
|
|
for a function invocation is known as the "stack frame" for that
|
3430 |
|
|
function (or colloquially just as the "frame"). In turn the function
|
3431 |
|
|
that called the function will have its stack frame, and so on back
|
3432 |
|
|
through the chain of functions that have been called.
|
3433 |
|
|
|
3434 |
|
|
Almost all architectures have one register dedicated to point to the
|
3435 |
|
|
end of the stack (the "stack pointer"). Many have a second register
|
3436 |
|
|
which points to the start of the currently active stack frame (the
|
3437 |
|
|
"frame pointer"). The specific arrangements for an architecture are a
|
3438 |
|
|
key part of the ABI.
|
3439 |
|
|
|
3440 |
|
|
A diagram helps to explain this. Here is a simple program to compute
|
3441 |
|
|
factorials:
|
3442 |
|
|
|
3443 |
|
|
#include
|
3444 |
|
|
int fact (int n)
|
3445 |
|
|
{
|
3446 |
|
|
if (0 == n)
|
3447 |
|
|
{
|
3448 |
|
|
return 1;
|
3449 |
|
|
}
|
3450 |
|
|
else
|
3451 |
|
|
{
|
3452 |
|
|
return n * fact (n - 1);
|
3453 |
|
|
}
|
3454 |
|
|
}
|
3455 |
|
|
|
3456 |
|
|
main ()
|
3457 |
|
|
{
|
3458 |
|
|
int i;
|
3459 |
|
|
|
3460 |
|
|
for (i = 0; i < 10; i++)
|
3461 |
|
|
{
|
3462 |
|
|
int f = fact (i);
|
3463 |
|
|
printf ("%d! = %d\n", i, f);
|
3464 |
|
|
}
|
3465 |
|
|
}
|
3466 |
|
|
|
3467 |
|
|
Consider the state of the stack when the code reaches line 6 after
|
3468 |
|
|
the main program has called `fact (3)'. The chain of function calls
|
3469 |
|
|
will be `main ()', `fact (3)', `fact (2)', `fact (1)' and `fact (0)'.
|
3470 |
|
|
|
3471 |
|
|
In this illustration the stack is falling (as used for example by the
|
3472 |
|
|
OpenRISC 1000 ABI). The stack pointer (SP) is at the end of the stack
|
3473 |
|
|
(lowest address) and the frame pointer (FP) is at the highest address
|
3474 |
|
|
in the current stack frame. The following diagram shows how the stack
|
3475 |
|
|
looks.
|
3476 |
|
|
|
3477 |
|
|
|
3478 |
|
|
Frame | | | |
|
3479 |
|
|
Number - | | |============| int fact (int n)
|
3480 |
|
|
| | | | i = 3 | {
|
3481 |
|
|
| | | |------------| if (0 == n) {
|
3482 |
|
|
| | | | f = ? | return 1; <-------- PC
|
3483 |
|
|
#4 main() < | | |------------| }
|
3484 |
|
|
| | | | | else {
|
3485 |
|
|
| | -+->|------------| ---> return n * fact (n - 1);
|
3486 |
|
|
| -+-+--+-----o | | }
|
3487 |
|
|
= | | |============| | }
|
3488 |
|
|
| | | | n = 3 | |
|
3489 |
|
|
| | | |------------| | main ()
|
3490 |
|
|
#3 fact (3) < | | | o---------+- {
|
3491 |
|
|
| -+-+->|------------| | | int i;
|
3492 |
|
|
| | | --+-----o | | |
|
3493 |
|
|
= | | |============| | | for (i = 0; i < 10; i++) {
|
3494 |
|
|
| | | | n = 2 | | -> int f = fact (i);
|
3495 |
|
|
| | | |------------| | printf (\"%d! = %d\\n\", i , f);
|
3496 |
|
|
#2 fact (2) < | | | o------+--| }
|
3497 |
|
|
| | | ->|------------| | }
|
3498 |
|
|
| | -+--+-----o | |
|
3499 |
|
|
= | | |============| |
|
3500 |
|
|
| | | | n = 1 | |
|
3501 |
|
|
| | | |------------| |
|
3502 |
|
|
#1 fact (1) < | | | o------+--|
|
3503 |
|
|
| | | |------------| |
|
3504 |
|
|
| ---|--+-----o |<-+------- FP
|
3505 |
|
|
= | |============| | |
|
3506 |
|
|
| | | n = 0 | | |
|
3507 |
|
|
| | |------------| | |
|
3508 |
|
|
#0 fact (0) < | | o--------- |
|
3509 |
|
|
| | |------------| |
|
3510 |
|
|
| --+-----o |<--------- SP |
|
3511 |
|
|
= |============| |
|
3512 |
|
|
| | Red Zone | v
|
3513 |
|
|
| \\/\\/\\/\\/\\/\\/\\/ Direction of
|
3514 |
|
|
#-1 < \\/\\/\\/\\/\\/\\/\\/ stack growth
|
3515 |
|
|
| | |
|
3516 |
|
|
" ]
|
3517 |
|
|
|
3518 |
|
|
In each stack frame, offset 0 from the stack pointer is the frame
|
3519 |
|
|
pointer of the previous frame and offset 4 (this is illustrating a
|
3520 |
|
|
32-bit architecture) from the stack pointer is the return address.
|
3521 |
|
|
Local variables are indexed from the frame pointer, with negative
|
3522 |
|
|
|
3523 |
|
|
the argument N. In the `main' function, offset -4 from the frame
|
3524 |
|
|
pointer is the local variable I and offset -8 from the frame pointer is
|
3525 |
|
|
the local variable F(1).
|
3526 |
|
|
|
3527 |
|
|
It is very easy to get confused when examining stacks. GDB has
|
3528 |
|
|
terminology it uses rigorously throughout. The stack frame of the
|
3529 |
|
|
|
3530 |
|
|
zero. In this example frame #0 is the stack frame of the call to
|
3531 |
|
|
`fact (0)'. The stack frame of its calling function (`fact (1)' in
|
3532 |
|
|
this case) is numbered #1 and so on back through the chain of calls.
|
3533 |
|
|
|
3534 |
|
|
The main GDB data structure describing frames is
|
3535 |
|
|
`struct frame_info'. It is not used directly, but only via its
|
3536 |
|
|
|
3537 |
|
|
registers in the frame and a pointer to the code of the function with
|
3538 |
|
|
|
3539 |
|
|
linked list of `frame_info' structs.
|
3540 |
|
|
|
3541 |
|
|
---------- Footnotes ----------
|
3542 |
|
|
|
3543 |
|
|
|
3544 |
|
|
Good optimizing compilers would not put anything on the stack for such
|
3545 |
|
|
simple functions. Indeed they might eliminate the recursion and use of
|
3546 |
|
|
|
3547 |
|
|
|
3548 |
|
|
|
3549 |
|
|
|
3550 |
|
|
|
3551 |
|
|
11.7.2 Frame Handling Terminology
|
3552 |
|
|
|
3553 |
|
|
|
3554 |
|
|
|
3555 |
|
|
some precise terminology.
|
3556 |
|
|
|
3557 |
|
|
|
3558 |
|
|
|
3559 |
|
|
* The "NEXT" frame, also sometimes called the inner or newer frame
|
3560 |
|
|
is the frame of the function called by the function of THIS frame.
|
3561 |
|
|
|
3562 |
|
|
|
3563 |
|
|
frame is the frame of the function which called the function of
|
3564 |
|
|
THIS frame.
|
3565 |
|
|
|
3566 |
|
|
|
3567 |
|
|
|
3568 |
|
|
Frames: All About Stack Frames.), if THIS frame is #3 (the call to
|
3569 |
|
|
`fact (3)'), the NEXT frame is frame #2 (the call to `fact (2)') and
|
3570 |
|
|
the PREVIOUS frame is frame #4 (the call to `main ()').
|
3571 |
|
|
|
3572 |
|
|
The "innermost" frame is the frame of the current executing
|
3573 |
|
|
function, or where the program stopped, in this example, in the middle
|
3574 |
|
|
of the call to `fact (0))'. It is always numbered frame #0.
|
3575 |
|
|
|
3576 |
|
|
The "base" of a frame is the address immediately before the start of
|
3577 |
|
|
|
3578 |
|
|
stack) this will be the lowest address and for a stack which grows up
|
3579 |
|
|
in memory (a "rising" stack) this will be the highest address in the
|
3580 |
|
|
frame.
|
3581 |
|
|
|
3582 |
|
|
GDB functions to analyze the stack are typically given a pointer to
|
3583 |
|
|
the NEXT frame to determine information about THIS frame. Information
|
3584 |
|
|
|
3585 |
|
|
frame are stored in this stack frame. In this example the frame
|
3586 |
|
|
pointer of the PREVIOUS frame is stored at offset 0 from the stack
|
3587 |
|
|
pointer of THIS frame.
|
3588 |
|
|
|
3589 |
|
|
|
3590 |
|
|
to work out information about THIS frame is referred to as "unwinding".
|
3591 |
|
|
The GDB functions involved in this typically include unwind in their
|
3592 |
|
|
name.
|
3593 |
|
|
|
3594 |
|
|
The process of analyzing a target to determine the information that
|
3595 |
|
|
|
3596 |
|
|
that carry this out are called sniffers and typically include sniffer
|
3597 |
|
|
in their name. More than one sniffer may be required to extract all
|
3598 |
|
|
the information for a particular frame.
|
3599 |
|
|
|
3600 |
|
|
Because so many functions work using the NEXT frame, there is an
|
3601 |
|
|
issue about addressing the innermost frame--it has no NEXT frame. To
|
3602 |
|
|
|
3603 |
|
|
|
3604 |
|
|
|
3605 |
|
|
|
3606 |
|
|
|
3607 |
|
|
11.7.3 Prologue Caches
|
3608 |
|
|
----------------------
|
3609 |
|
|
|
3610 |
|
|
All the frame sniffing functions typically examine the code at the
|
3611 |
|
|
|
3612 |
|
|
registers. The ABI will save old values and set new values of key
|
3613 |
|
|
registers at the start of each function in what is known as the
|
3614 |
|
|
function "prologue".
|
3615 |
|
|
|
3616 |
|
|
For any particular stack frame this data does not change, so all the
|
3617 |
|
|
standard unwinding functions, in addition to receiving a pointer to the
|
3618 |
|
|
|
3619 |
|
|
cache" as their second argument. This can be used to store values
|
3620 |
|
|
associated with a particular frame, for reuse on subsequent calls
|
3621 |
|
|
involving the same frame.
|
3622 |
|
|
|
3623 |
|
|
It is up to the user to define the structure used (it is a `void *'
|
3624 |
|
|
pointer) and arrange allocation and deallocation of storage. However
|
3625 |
|
|
for general use, GDB provides `struct trad_frame_cache', with a set of
|
3626 |
|
|
|
3627 |
|
|
THIS frame, the base address of the frame, a pointer to the struct
|
3628 |
|
|
`frame_info' for the NEXT frame and details of where the registers of
|
3629 |
|
|
the PREVIOUS frame may be found in THIS frame.
|
3630 |
|
|
|
3631 |
|
|
Typically the first time any sniffer function is called with NEXT
|
3632 |
|
|
frame, the prologue sniffer for THIS frame will be `NULL'. The sniffer
|
3633 |
|
|
|
3634 |
|
|
populate it. Subsequent calls using the same NEXT frame will pass in
|
3635 |
|
|
this prologue cache, so the data can be returned with no additional
|
3636 |
|
|
|
3637 |
|
|
|
3638 |
|
|
|
3639 |
|
|
|
3640 |
|
|
|
3641 |
|
|
11.7.4 Functions and Variable to Analyze Frames
|
3642 |
|
|
-----------------------------------------------
|
3643 |
|
|
|
3644 |
|
|
These struct `gdbarch' functions and variable should be defined to
|
3645 |
|
|
provide analysis of the stack frame and allow it to be adjusted as
|
3646 |
|
|
required.
|
3647 |
|
|
|
3648 |
|
|
-- Architecture Function: CORE_ADDR skip_prologue (struct gdbarch
|
3649 |
|
|
*GDBARCH, CORE_ADDR PC)
|
3650 |
|
|
|
3651 |
|
|
function which sets up the stack frame, saves the return address
|
3652 |
|
|
etc. The code representing the behavior of the function starts
|
3653 |
|
|
after the prologue.
|
3654 |
|
|
|
3655 |
|
|
This function skips past the prologue of a function if the program
|
3656 |
|
|
counter, PC, is within the prologue of a function. The result is
|
3657 |
|
|
|
3658 |
|
|
optimizing compilers, this may be a far from trivial exercise.
|
3659 |
|
|
However the required information may be within the binary as
|
3660 |
|
|
DWARF2 debugging information, making the job much easier.
|
3661 |
|
|
|
3662 |
|
|
|
3663 |
|
|
always be provided, but can take advantage of DWARF2 debugging
|
3664 |
|
|
information, if that is available.
|
3665 |
|
|
|
3666 |
|
|
|
3667 |
|
|
-- Architecture Function: int inner_than (CORE_ADDR LHS, CORE_ADDR RHS)
|
3668 |
|
|
Given two frame or stack pointers, return non-zero (true) if the
|
3669 |
|
|
first represents the "inner" stack frame and 0 (false) otherwise.
|
3670 |
|
|
|
3671 |
|
|
grows up in memory (rising stack) or grows down in memory (falling
|
3672 |
|
|
stack). *Note All About Stack Frames: All About Stack Frames, for
|
3673 |
|
|
an explanation of "inner" frames.
|
3674 |
|
|
|
3675 |
|
|
The default value of this function is `NULL' and it should always
|
3676 |
|
|
|
3677 |
|
|
|
3678 |
|
|
growing down in memory) or `core_addr_greaterthan' (for stacks
|
3679 |
|
|
growing up in memory).
|
3680 |
|
|
|
3681 |
|
|
|
3682 |
|
|
-- Architecture Function: CORE_ADDR frame_align (struct gdbarch
|
3683 |
|
|
*GDBARCH, CORE_ADDR ADDRESS)
|
3684 |
|
|
The architecture may have constraints on how its frames are
|
3685 |
|
|
|
3686 |
|
|
to be double-word aligned, but 32-bit versions of the architecture
|
3687 |
|
|
allocate single-word values to the stack. Thus extra padding may
|
3688 |
|
|
|
3689 |
|
|
|
3690 |
|
|
Given a proposed address for the stack pointer, this function
|
3691 |
|
|
returns a suitably aligned address (by expanding the stack frame).
|
3692 |
|
|
|
3693 |
|
|
The default value is `NULL' (undefined). This function should be
|
3694 |
|
|
|
3695 |
|
|
|
3696 |
|
|
stacks) and `align_up' (for rising stacks) will facilitate the
|
3697 |
|
|
implementation of this function.
|
3698 |
|
|
|
3699 |
|
|
|
3700 |
|
|
|
3701 |
|
|
Some ABIs reserve space beyond the end of the stack for use by leaf
|
3702 |
|
|
functions without prologue or epilogue or by exception handlers
|
3703 |
|
|
(for example the OpenRISC 1000).
|
3704 |
|
|
|
3705 |
|
|
This is known as a "red zone" (AMD terminology). The AMD64 (nee
|
3706 |
|
|
x86-64) ABI documentation refers to the "red zone" when describing
|
3707 |
|
|
this scratch area.
|
3708 |
|
|
|
3709 |
|
|
|
3710 |
|
|
|
3711 |
|
|
(see `frame_align' above for an explanation of stack frame
|
3712 |
|
|
alignment).
|
3713 |
|
|
|
3714 |
|
|
|
3715 |
|
|
|
3716 |
|
|
|
3717 |
|
|
|
3718 |
|
|
11.7.5 Functions to Access Frame Data
|
3719 |
|
|
|
3720 |
|
|
|
3721 |
|
|
These functions provide access to key registers and arguments in the
|
3722 |
|
|
stack frame.
|
3723 |
|
|
|
3724 |
|
|
-- Architecture Function: CORE_ADDR unwind_pc (struct gdbarch
|
3725 |
|
|
*GDBARCH, struct frame_info *NEXT_FRAME)
|
3726 |
|
|
This function is given a pointer to the NEXT stack frame (*note
|
3727 |
|
|
|
3728 |
|
|
represented) and returns the value of the program counter in the
|
3729 |
|
|
PREVIOUS frame (i.e. the frame of the function that called THIS
|
3730 |
|
|
|
3731 |
|
|
|
3732 |
|
|
The implementation, which must be frame agnostic (work with any
|
3733 |
|
|
frame), is typically no more than:
|
3734 |
|
|
|
3735 |
|
|
|
3736 |
|
|
pc = frame_unwind_register_unsigned (next_frame, ARCH_PC_REGNUM);
|
3737 |
|
|
return gdbarch_addr_bits_remove (gdbarch, pc);
|
3738 |
|
|
|
3739 |
|
|
|
3740 |
|
|
-- Architecture Function: CORE_ADDR unwind_sp (struct gdbarch
|
3741 |
|
|
*GDBARCH, struct frame_info *NEXT_FRAME)
|
3742 |
|
|
This function is given a pointer to the NEXT stack frame (*note
|
3743 |
|
|
|
3744 |
|
|
represented) and returns the value of the stack pointer in the
|
3745 |
|
|
PREVIOUS frame (i.e. the frame of the function that called THIS
|
3746 |
|
|
|
3747 |
|
|
|
3748 |
|
|
The implementation, which must be frame agnostic (work with any
|
3749 |
|
|
frame), is typically no more than:
|
3750 |
|
|
|
3751 |
|
|
|
3752 |
|
|
sp = frame_unwind_register_unsigned (next_frame, ARCH_SP_REGNUM);
|
3753 |
|
|
return gdbarch_addr_bits_remove (gdbarch, sp);
|
3754 |
|
|
|
3755 |
|
|
|
3756 |
|
|
-- Architecture Function: int frame_num_args (struct gdbarch *GDBARCH,
|
3757 |
|
|
struct frame_info *THIS_FRAME)
|
3758 |
|
|
|
3759 |
|
|
About Stack Frames: All About Stack Frames. for how frames are
|
3760 |
|
|
represented), and returns the number of arguments that are being
|
3761 |
|
|
passed, or -1 if not known.
|
3762 |
|
|
|
3763 |
|
|
|
3764 |
|
|
of arguments passed on any stack frame is always unknown. For many
|
3765 |
|
|
architectures this will be a suitable default.
|
3766 |
|
|
|
3767 |
|
|
|
3768 |
|
|
|
3769 |
|
|
|
3770 |
|
|
|
3771 |
|
|
11.7.6 Analyzing Stacks--Frame Sniffers
|
3772 |
|
|
---------------------------------------
|
3773 |
|
|
|
3774 |
|
|
When a program stops, GDB needs to construct the chain of struct
|
3775 |
|
|
`frame_info' representing the state of the stack using appropriate
|
3776 |
|
|
"sniffers".
|
3777 |
|
|
|
3778 |
|
|
Each architecture requires appropriate sniffers, but they do not form
|
3779 |
|
|
|
3780 |
|
|
required and a sniffer may be suitable for more than one
|
3781 |
|
|
`struct gdbarch'. Instead sniffers are associated with architectures
|
3782 |
|
|
|
3783 |
|
|
|
3784 |
|
|
* `frame_unwind_append_sniffer' is used to add a new sniffer to
|
3785 |
|
|
|
3786 |
|
|
|
3787 |
|
|
* `frame_base_append_sniffer' is used to add a new sniffer which can
|
3788 |
|
|
|
3789 |
|
|
|
3790 |
|
|
* `frame_base_set_default' is used to specify the default base
|
3791 |
|
|
sniffer.
|
3792 |
|
|
|
3793 |
|
|
|
3794 |
|
|
These functions all take a reference to `struct gdbarch', so they
|
3795 |
|
|
|
3796 |
|
|
in the `gdbarch' initialization function, after the `gdbarch' struct
|
3797 |
|
|
has been set up. Unless a default has been set, the most recently
|
3798 |
|
|
appended sniffer will be tried first.
|
3799 |
|
|
|
3800 |
|
|
The main frame unwinding sniffer (as set by
|
3801 |
|
|
`frame_unwind_append_sniffer)' returns a structure specifying a set of
|
3802 |
|
|
sniffing functions:
|
3803 |
|
|
|
3804 |
|
|
struct frame_unwind
|
3805 |
|
|
{
|
3806 |
|
|
enum frame_type type;
|
3807 |
|
|
frame_this_id_ftype *this_id;
|
3808 |
|
|
frame_prev_register_ftype *prev_register;
|
3809 |
|
|
const struct frame_data *unwind_data;
|
3810 |
|
|
|
3811 |
|
|
frame_prev_pc_ftype *prev_pc;
|
3812 |
|
|
frame_dealloc_cache_ftype *dealloc_cache;
|
3813 |
|
|
};
|
3814 |
|
|
|
3815 |
|
|
The `type' field indicates the type of frame this sniffer can
|
3816 |
|
|
|
3817 |
|
|
Creating Dummy Frames.), signal handler or sentinel. Signal handlers
|
3818 |
|
|
sometimes have their own simplified stack structure for efficiency, so
|
3819 |
|
|
may need their own handlers.
|
3820 |
|
|
|
3821 |
|
|
The `unwind_data' field holds additional information which may be
|
3822 |
|
|
relevant to particular types of frame. For example it may hold
|
3823 |
|
|
additional information for signal handler frames.
|
3824 |
|
|
|
3825 |
|
|
|
3826 |
|
|
information when given a pointer to the NEXT stack frame. Not all
|
3827 |
|
|
functions need be provided. If an entry is `NULL', the next sniffer
|
3828 |
|
|
|
3829 |
|
|
|
3830 |
|
|
* `this_id' determines the stack pointer and function (code entry
|
3831 |
|
|
|
3832 |
|
|
|
3833 |
|
|
* `prev_register' determines where the values of registers for the
|
3834 |
|
|
|
3835 |
|
|
|
3836 |
|
|
* `sniffer' takes a look at THIS frame's registers to determine if
|
3837 |
|
|
this is the appropriate unwinder.
|
3838 |
|
|
|
3839 |
|
|
|
3840 |
|
|
needed if the program counter is not an ordinary register (*note
|
3841 |
|
|
Functions and Variables Specifying the Register Architecture:
|
3842 |
|
|
Register Architecture Functions & Variables.).
|
3843 |
|
|
|
3844 |
|
|
|
3845 |
|
|
prologue cache for this frame (*note Prologue Caches: Prologue
|
3846 |
|
|
Caches.).
|
3847 |
|
|
|
3848 |
|
|
|
3849 |
|
|
In general it is only the `this_id' and `prev_register' fields that
|
3850 |
|
|
need be defined for custom sniffers.
|
3851 |
|
|
|
3852 |
|
|
|
3853 |
|
|
`struct frame_base', which refers to the corresponding `frame_unwind'
|
3854 |
|
|
struct and whose fields refer to functions yielding various addresses
|
3855 |
|
|
within the frame.
|
3856 |
|
|
|
3857 |
|
|
struct frame_base
|
3858 |
|
|
{
|
3859 |
|
|
const struct frame_unwind *unwind;
|
3860 |
|
|
|
3861 |
|
|
frame_this_locals_ftype *this_locals;
|
3862 |
|
|
frame_this_args_ftype *this_args;
|
3863 |
|
|
};
|
3864 |
|
|
|
3865 |
|
|
All the functions referred to take a pointer to the NEXT frame as
|
3866 |
|
|
argument. The function referred to by `this_base' returns the base
|
3867 |
|
|
|
3868 |
|
|
returns the base address of local variables in THIS frame and the
|
3869 |
|
|
function referred to by `this_args' returns the base address of the
|
3870 |
|
|
function arguments in this frame.
|
3871 |
|
|
|
3872 |
|
|
As described above, the base address of a frame is the address
|
3873 |
|
|
immediately before the start of the NEXT frame. For a falling stack,
|
3874 |
|
|
|
3875 |
|
|
the highest address in the frame. For most architectures the same
|
3876 |
|
|
|
3877 |
|
|
which case the same function can be used for all three entries(1).
|
3878 |
|
|
|
3879 |
|
|
---------- Footnotes ----------
|
3880 |
|
|
|
3881 |
|
|
(1) It is worth noting that if it cannot be determined in any other
|
3882 |
|
|
way (for example by there being a register with the name `"fp"'), then
|
3883 |
|
|
the result of the `this_base' function will be used as the value of the
|
3884 |
|
|
|
3885 |
|
|
(for example with the OpenRISC 1000, this value is the stack pointer,
|
3886 |
|
|
`$sp'). In this case a register (raw or pseudo) with the name `"fp"'
|
3887 |
|
|
|
3888 |
|
|
|
3889 |
|
|
|
3890 |
|
|
|
3891 |
|
|
|
3892 |
|
|
|
3893 |
|
|
========================
|
3894 |
|
|
|
3895 |
|
|
|
3896 |
|
|
|
3897 |
|
|
* About Dummy Frames::
|
3898 |
|
|
|
3899 |
|
|
|
3900 |
|
|
|
3901 |
|
|
|
3902 |
|
|
|
3903 |
|
|
11.8.1 About Dummy Frames
|
3904 |
|
|
-------------------------
|
3905 |
|
|
|
3906 |
|
|
|
3907 |
|
|
`call' or `print' commands). These functions may be breakpointed, and
|
3908 |
|
|
it is essential that if a function does hit a breakpoint, commands like
|
3909 |
|
|
`backtrace' work correctly.
|
3910 |
|
|
|
3911 |
|
|
|
3912 |
|
|
been called from the point where GDB had previously stopped. This
|
3913 |
|
|
requires that GDB can set up stack frames appropriate for such function
|
3914 |
|
|
|
3915 |
|
|
|
3916 |
|
|
|
3917 |
|
|
|
3918 |
|
|
|
3919 |
|
|
11.8.2 Functions Creating Dummy Frames
|
3920 |
|
|
|
3921 |
|
|
|
3922 |
|
|
The following functions provide the functionality to set up such
|
3923 |
|
|
"dummy" stack frames.
|
3924 |
|
|
|
3925 |
|
|
-- Architecture Function: CORE_ADDR push_dummy_call (struct gdbarch
|
3926 |
|
|
*GDBARCH, struct value *FUNCTION, struct regcache *REGCACHE,
|
3927 |
|
|
CORE_ADDR BP_ADDR, int NARGS, struct value **ARGS, CORE_ADDR
|
3928 |
|
|
SP, int STRUCT_RETURN, CORE_ADDR STRUCT_ADDR)
|
3929 |
|
|
|
3930 |
|
|
to be called. `push_dummy_call' is given the arguments to be
|
3931 |
|
|
passed and must copy them into registers or push them on to the
|
3932 |
|
|
stack as appropriate for the ABI.
|
3933 |
|
|
|
3934 |
|
|
FUNCTION is a pointer to the function that will be called and
|
3935 |
|
|
REGCACHE the register cache from which values should be obtained.
|
3936 |
|
|
BP_ADDR is the address to which the function should return (which
|
3937 |
|
|
is breakpointed, so GDB can regain control, hence the name).
|
3938 |
|
|
|
3939 |
|
|
containing the argument values. STRUCT_RETURN is non-zero (true)
|
3940 |
|
|
if the function returns a structure, and if so STRUCT_ADDR is the
|
3941 |
|
|
address in which the structure should be returned.
|
3942 |
|
|
|
3943 |
|
|
After calling this function, GDB will pass control to the target
|
3944 |
|
|
at the address of the function, which will find the stack and
|
3945 |
|
|
registers set up just as expected.
|
3946 |
|
|
|
3947 |
|
|
|
3948 |
|
|
function is not defined, then GDB will not allow the user to call
|
3949 |
|
|
functions within the target being debugged.
|
3950 |
|
|
|
3951 |
|
|
|
3952 |
|
|
-- Architecture Function: struct frame_id unwind_dummy_id (struct
|
3953 |
|
|
gdbarch *GDBARCH, struct frame_info *NEXT_FRAME)
|
3954 |
|
|
This is the inverse of `push_dummy_call' which restores the stack
|
3955 |
|
|
|
3956 |
|
|
using a dummy stack frame. The result is a `struct frame_id',
|
3957 |
|
|
which contains the value of the stack pointer and program counter
|
3958 |
|
|
to be used.
|
3959 |
|
|
|
3960 |
|
|
|
3961 |
|
|
frame is the frame of the dummy function, which can be unwound, to
|
3962 |
|
|
yield the required stack pointer and program counter from the
|
3963 |
|
|
|
3964 |
|
|
|
3965 |
|
|
The default value is `NULL' (undefined). If `push_dummy_call' is
|
3966 |
|
|
defined, then this function should also be defined.
|
3967 |
|
|
|
3968 |
|
|
|
3969 |
|
|
-- Architecture Function: CORE_ADDR push_dummy_code (struct gdbarch
|
3970 |
|
|
*GDBARCH, CORE_ADDR SP, CORE_ADDR FUNADDR, struct value
|
3971 |
|
|
**ARGS, int NARGS, struct type *VALUE_TYPE, CORE_ADDR
|
3972 |
|
|
*REAL_PC, CORE_ADDR *BP_ADDR, struct regcache *REGCACHE)
|
3973 |
|
|
If this function is not defined (its default value is `NULL'), a
|
3974 |
|
|
|
3975 |
|
|
on the target as its return address. A temporary breakpoint will
|
3976 |
|
|
be set there, so the location must be writable and have room for a
|
3977 |
|
|
breakpoint.
|
3978 |
|
|
|
3979 |
|
|
|
3980 |
|
|
writable (in ROM possibly), or the ABI might require code to be
|
3981 |
|
|
executed on return from a call to unwind the stack before the
|
3982 |
|
|
breakpoint is encountered.
|
3983 |
|
|
|
3984 |
|
|
If either of these is the case, then push_dummy_code should be
|
3985 |
|
|
defined to push an instruction sequence onto the end of the stack
|
3986 |
|
|
to which the dummy call should return.
|
3987 |
|
|
|
3988 |
|
|
The arguments are essentially the same as those to
|
3989 |
|
|
`push_dummy_call'. However the function is provided with the type
|
3990 |
|
|
of the function result, VALUE_TYPE, BP_ADDR is used to return a
|
3991 |
|
|
|
3992 |
|
|
inserted) and REAL PC is used to specify the resume address when
|
3993 |
|
|
starting the call sequence. The function should return the
|
3994 |
|
|
|
3995 |
|
|
|
3996 |
|
|
_Note:_ This does require that code in the stack can be
|
3997 |
|
|
executed. Some Harvard architectures may not allow this.
|
3998 |
|
|
|
3999 |
|
|
|
4000 |
|
|
|
4001 |
|
|
|
4002 |
|
|
|
4003 |
|
|
11.9 Adding support for debugging core files
|
4004 |
|
|
|
4005 |
|
|
|
4006 |
|
|
The prerequisite for adding core file support in GDB is to have core
|
4007 |
|
|
file support in BFD.
|
4008 |
|
|
|
4009 |
|
|
Once BFD support is available, writing the apropriate
|
4010 |
|
|
`regset_from_core_section' architecture function should be all that is
|
4011 |
|
|
|
4012 |
|
|
|
4013 |
|
|
|
4014 |
|
|
|
4015 |
|
|
|
4016 |
|
|
11.10 Defining Other Architecture Features
|
4017 |
|
|
==========================================
|
4018 |
|
|
|
4019 |
|
|
This section describes other functions and values in `gdbarch',
|
4020 |
|
|
together with some useful macros, that you can use to define the target
|
4021 |
|
|
architecture.
|
4022 |
|
|
|
4023 |
|
|
`CORE_ADDR gdbarch_addr_bits_remove (GDBARCH, ADDR)'
|
4024 |
|
|
|
4025 |
|
|
really part of the address, then this function is used to zero
|
4026 |
|
|
those bits in ADDR. This is only used for addresses of
|
4027 |
|
|
instructions, and even then not in all contexts.
|
4028 |
|
|
|
4029 |
|
|
For example, the two low-order bits of the PC on the
|
4030 |
|
|
Hewlett-Packard PA 2.0 architecture contain the privilege level of
|
4031 |
|
|
the corresponding instruction. Since instructions must always be
|
4032 |
|
|
aligned on four-byte boundaries, the processor masks out these
|
4033 |
|
|
bits to generate the actual address of the instruction.
|
4034 |
|
|
`gdbarch_addr_bits_remove' would then for example look like that:
|
4035 |
|
|
|
4036 |
|
|
{
|
4037 |
|
|
return (addr &= ~0x3);
|
4038 |
|
|
}
|
4039 |
|
|
|
4040 |
|
|
`int address_class_name_to_type_flags (GDBARCH, NAME, TYPE_FLAGS_PTR)'
|
4041 |
|
|
|
4042 |
|
|
referenced by TYPE_FLAGS_PTR to the mask representing the qualifier
|
4043 |
|
|
and return 1. If NAME is not a valid address class qualifier name,
|
4044 |
|
|
return 0.
|
4045 |
|
|
|
4046 |
|
|
|
4047 |
|
|
`TYPE_FLAG_ADDRESS_CLASS_1', `TYPE_FLAG_ADDRESS_CLASS_2', or
|
4048 |
|
|
possibly some combination of these values or'd together. *Note
|
4049 |
|
|
Address Classes: Target Architecture Definition.
|
4050 |
|
|
|
4051 |
|
|
`int address_class_name_to_type_flags_p (GDBARCH)'
|
4052 |
|
|
Predicate which indicates whether
|
4053 |
|
|
`address_class_name_to_type_flags' has been defined.
|
4054 |
|
|
|
4055 |
|
|
`int gdbarch_address_class_type_flags (GDBARCH, BYTE_SIZE, DWARF2_ADDR_CLASS)'
|
4056 |
|
|
Given a pointers byte size (as described by the debug information)
|
4057 |
|
|
and the possible `DW_AT_address_class' value, return the type flags
|
4058 |
|
|
used by GDB to represent this address class. The value returned
|
4059 |
|
|
|
4060 |
|
|
`TYPE_FLAG_ADDRESS_CLASS_2', or possibly some combination of these
|
4061 |
|
|
values or'd together. *Note Address Classes: Target Architecture
|
4062 |
|
|
Definition.
|
4063 |
|
|
|
4064 |
|
|
`int gdbarch_address_class_type_flags_p (GDBARCH)'
|
4065 |
|
|
Predicate which indicates whether
|
4066 |
|
|
`gdbarch_address_class_type_flags_p' has been defined.
|
4067 |
|
|
|
4068 |
|
|
`const char *gdbarch_address_class_type_flags_to_name (GDBARCH, TYPE_FLAGS)'
|
4069 |
|
|
Return the name of the address class qualifier associated with the
|
4070 |
|
|
type flags given by TYPE_FLAGS.
|
4071 |
|
|
|
4072 |
|
|
|
4073 |
|
|
Predicate which indicates whether
|
4074 |
|
|
`gdbarch_address_class_type_flags_to_name' has been defined.
|
4075 |
|
|
*Note Address Classes: Target Architecture Definition.
|
4076 |
|
|
|
4077 |
|
|
`void gdbarch_address_to_pointer (GDBARCH, TYPE, BUF, ADDR)'
|
4078 |
|
|
Store in BUF a pointer of type TYPE representing the address ADDR,
|
4079 |
|
|
|
4080 |
|
|
function may safely assume that TYPE is either a pointer or a C++
|
4081 |
|
|
reference type. *Note Pointers Are Not Always Addresses: Target
|
4082 |
|
|
Architecture Definition.
|
4083 |
|
|
|
4084 |
|
|
|
4085 |
|
|
Used to notify if the compiler promotes a `short' or `char'
|
4086 |
|
|
parameter to an `int', but still reports the parameter as its
|
4087 |
|
|
original type, rather than the promoted type.
|
4088 |
|
|
|
4089 |
|
|
`gdbarch_bits_big_endian (GDBARCH)'
|
4090 |
|
|
|
4091 |
|
|
match the endianism of the target byte order. A value of 1 means
|
4092 |
|
|
that the bits are numbered in a big-endian bit order, 0 means
|
4093 |
|
|
little-endian.
|
4094 |
|
|
|
4095 |
|
|
|
4096 |
|
|
Calling set_gdbarch_bits_big_endian with a value of 1 indicates
|
4097 |
|
|
that the bits in the target are numbered in a big-endian bit
|
4098 |
|
|
order, 0 indicates little-endian.
|
4099 |
|
|
|
4100 |
|
|
`BREAKPOINT'
|
4101 |
|
|
This is the character array initializer for the bit pattern to put
|
4102 |
|
|
into memory where a breakpoint is set. Although it's common to
|
4103 |
|
|
|
4104 |
|
|
instance, the bit pattern could be an invalid instruction. The
|
4105 |
|
|
breakpoint must be no longer than the shortest instruction of the
|
4106 |
|
|
|
4107 |
|
|
|
4108 |
|
|
`BREAKPOINT' has been deprecated in favor of
|
4109 |
|
|
`gdbarch_breakpoint_from_pc'.
|
4110 |
|
|
|
4111 |
|
|
`BIG_BREAKPOINT'
|
4112 |
|
|
`LITTLE_BREAKPOINT'
|
4113 |
|
|
|
4114 |
|
|
|
4115 |
|
|
`BIG_BREAKPOINT' and `LITTLE_BREAKPOINT' have been deprecated in
|
4116 |
|
|
favor of `gdbarch_breakpoint_from_pc'.
|
4117 |
|
|
|
4118 |
|
|
`const gdb_byte *gdbarch_breakpoint_from_pc (GDBARCH, PCPTR, LENPTR)'
|
4119 |
|
|
Use the program counter to determine the contents and size of a
|
4120 |
|
|
breakpoint instruction. It returns a pointer to a static string
|
4121 |
|
|
of bytes that encode a breakpoint instruction, stores the length
|
4122 |
|
|
|
4123 |
|
|
necessary) to point to the actual memory location where the
|
4124 |
|
|
breakpoint should be inserted. May return `NULL' to indicate that
|
4125 |
|
|
software breakpoints are not supported.
|
4126 |
|
|
|
4127 |
|
|
|
4128 |
|
|
it's not required; for instance, the bit pattern could be an
|
4129 |
|
|
invalid instruction. The breakpoint must be no longer than the
|
4130 |
|
|
shortest instruction of the architecture.
|
4131 |
|
|
|
4132 |
|
|
Provided breakpoint bytes can be also used by
|
4133 |
|
|
`bp_loc_is_permanent' to detect permanent breakpoints.
|
4134 |
|
|
|
4135 |
|
|
copy if it was called for a location with permanent breakpoint as
|
4136 |
|
|
|
4137 |
|
|
arbitrary parameter value.
|
4138 |
|
|
|
4139 |
|
|
Replaces all the other BREAKPOINT macros.
|
4140 |
|
|
|
4141 |
|
|
`int gdbarch_memory_insert_breakpoint (GDBARCH, BP_TGT)'
|
4142 |
|
|
`gdbarch_memory_remove_breakpoint (GDBARCH, BP_TGT)'
|
4143 |
|
|
Insert or remove memory based breakpoints. Reasonable defaults
|
4144 |
|
|
(`default_memory_insert_breakpoint' and
|
4145 |
|
|
`default_memory_remove_breakpoint' respectively) have been
|
4146 |
|
|
provided so that it is not necessary to set these for most
|
4147 |
|
|
|
4148 |
|
|
`gdbarch_memory_insert_breakpoint' and
|
4149 |
|
|
`gdbarch_memory_remove_breakpoint' will likely have instructions
|
4150 |
|
|
that are oddly sized or are not stored in a conventional manner.
|
4151 |
|
|
|
4152 |
|
|
|
4153 |
|
|
custom breakpoint insertion and removal routines if
|
4154 |
|
|
`gdbarch_breakpoint_from_pc' needs to read the target's memory for
|
4155 |
|
|
some reason.
|
4156 |
|
|
|
4157 |
|
|
`CORE_ADDR gdbarch_adjust_breakpoint_address (GDBARCH, BPADDR)'
|
4158 |
|
|
|
4159 |
|
|
breakpoint address adjusted to account for architectural
|
4160 |
|
|
constraints on breakpoint placement. This method is not needed by
|
4161 |
|
|
most targets.
|
4162 |
|
|
|
4163 |
|
|
The FR-V target (see `frv-tdep.c') requires this method. The FR-V
|
4164 |
|
|
|
4165 |
|
|
are grouped (packed) together into an aggregate instruction or
|
4166 |
|
|
instruction bundle. When the processor executes one of these
|
4167 |
|
|
bundles, the component instructions are executed in parallel.
|
4168 |
|
|
|
4169 |
|
|
In the course of optimization, the compiler may group instructions
|
4170 |
|
|
from distinct source statements into the same bundle. The line
|
4171 |
|
|
number information associated with one of the latter statements
|
4172 |
|
|
will likely refer to some instruction other than the first one in
|
4173 |
|
|
the bundle. So, if the user attempts to place a breakpoint on one
|
4174 |
|
|
of these latter statements, GDB must be careful to _not_ place the
|
4175 |
|
|
break instruction on any instruction other than the first one in
|
4176 |
|
|
|
4177 |
|
|
bundle execute in parallel, so the _first_ instruction is the
|
4178 |
|
|
instruction at the lowest address and has nothing to do with
|
4179 |
|
|
execution order.)
|
4180 |
|
|
|
4181 |
|
|
The FR-V's `gdbarch_adjust_breakpoint_address' method will adjust a
|
4182 |
|
|
breakpoint's address by scanning backwards for the beginning of
|
4183 |
|
|
the bundle, returning the address of the bundle.
|
4184 |
|
|
|
4185 |
|
|
|
4186 |
|
|
user's expectation, GDB prints a warning when an adjusted
|
4187 |
|
|
breakpoint is initially set and each time that that breakpoint is
|
4188 |
|
|
|
4189 |
|
|
|
4190 |
|
|
`int gdbarch_call_dummy_location (GDBARCH)'
|
4191 |
|
|
|
4192 |
|
|
|
4193 |
|
|
This method has been replaced by `gdbarch_push_dummy_code' (*note
|
4194 |
|
|
gdbarch_push_dummy_code::).
|
4195 |
|
|
|
4196 |
|
|
`int gdbarch_cannot_fetch_register (GDBARCH, REGUM)'
|
4197 |
|
|
This function should return nonzero if REGNO cannot be fetched
|
4198 |
|
|
from an inferior process.
|
4199 |
|
|
|
4200 |
|
|
|
4201 |
|
|
This function should return nonzero if REGNO should not be written
|
4202 |
|
|
|
4203 |
|
|
status words, and other special registers. This function returns
|
4204 |
|
|
0 as default so that GDB will assume that all registers may be
|
4205 |
|
|
written.
|
4206 |
|
|
|
4207 |
|
|
|
4208 |
|
|
Return non-zero if register REGNUM represents data values of type
|
4209 |
|
|
TYPE in a non-standard form. *Note Using Different Register and
|
4210 |
|
|
Memory Data Representations: Target Architecture Definition.
|
4211 |
|
|
|
4212 |
|
|
|
4213 |
|
|
This function returns the number of the first floating point
|
4214 |
|
|
register, if the machine has such registers. Otherwise, it
|
4215 |
|
|
returns -1.
|
4216 |
|
|
|
4217 |
|
|
`CORE_ADDR gdbarch_decr_pc_after_break (GDBARCH)'
|
4218 |
|
|
|
4219 |
|
|
after the program encounters a breakpoint. This is often the
|
4220 |
|
|
number of bytes in `BREAKPOINT', though not always. For most
|
4221 |
|
|
targets this value will be 0.
|
4222 |
|
|
|
4223 |
|
|
|
4224 |
|
|
If defined, this should evaluate to 1 if ADDR is in a shared
|
4225 |
|
|
library in which breakpoints cannot be set and so should be
|
4226 |
|
|
disabled.
|
4227 |
|
|
|
4228 |
|
|
`int gdbarch_dwarf2_reg_to_regnum (GDBARCH, DWARF2_REGNR)'
|
4229 |
|
|
Convert DWARF2 register number DWARF2_REGNR into GDB regnum. If
|
4230 |
|
|
not defined, no conversion will be performed.
|
4231 |
|
|
|
4232 |
|
|
`int gdbarch_ecoff_reg_to_regnum (GDBARCH, ECOFF_REGNR)'
|
4233 |
|
|
Convert ECOFF register number ECOFF_REGNR into GDB regnum. If
|
4234 |
|
|
not defined, no conversion will be performed.
|
4235 |
|
|
|
4236 |
|
|
`GCC_COMPILED_FLAG_SYMBOL'
|
4237 |
|
|
`GCC2_COMPILED_FLAG_SYMBOL'
|
4238 |
|
|
|
4239 |
|
|
for to detect that GCC compiled the file. The default symbols are
|
4240 |
|
|
`gcc_compiled.' and `gcc2_compiled.', respectively. (Currently
|
4241 |
|
|
only defined for the Delta 68.)
|
4242 |
|
|
|
4243 |
|
|
`gdbarch_get_longjmp_target'
|
4244 |
|
|
This function determines the target PC address that `longjmp' will
|
4245 |
|
|
jump to, assuming that we have just stopped at a `longjmp'
|
4246 |
|
|
breakpoint. It takes a `CORE_ADDR *' as argument, and stores the
|
4247 |
|
|
target PC value through this pointer. It examines the current
|
4248 |
|
|
state of the machine as needed, typically by using a
|
4249 |
|
|
|
4250 |
|
|
like to get the offset from the target's `jmpbuf.h', that header
|
4251 |
|
|
file cannot be assumed to be available when building a
|
4252 |
|
|
cross-debugger.)
|
4253 |
|
|
|
4254 |
|
|
`DEPRECATED_IBM6000_TARGET'
|
4255 |
|
|
|
4256 |
|
|
conditional should be eliminated (FIXME) and replaced by
|
4257 |
|
|
feature-specific macros. It was introduced in haste and we are
|
4258 |
|
|
repenting at leisure.
|
4259 |
|
|
|
4260 |
|
|
|
4261 |
|
|
An x86-based target can define this to use the generic x86
|
4262 |
342 |
jeremybenn |
watchpoint support; see *note I386_USE_GENERIC_WATCHPOINTS:
|
4263 |
330 |
jeremybenn |
Algorithms.
|
4264 |
|
|
|
4265 |
|
|
`gdbarch_in_function_epilogue_p (GDBARCH, ADDR)'
|
4266 |
|
|
|
4267 |
|
|
function. The epilogue of a function is defined as the part of a
|
4268 |
|
|
function where the stack frame of the function already has been
|
4269 |
|
|
destroyed up to the final `return from function call' instruction.
|
4270 |
|
|
|
4271 |
|
|
`int gdbarch_in_solib_return_trampoline (GDBARCH, PC, NAME)'
|
4272 |
|
|
Define this function to return nonzero if the program is stopped
|
4273 |
|
|
in the trampoline that returns from a shared library.
|
4274 |
|
|
|
4275 |
|
|
`target_so_ops.in_dynsym_resolve_code (PC)'
|
4276 |
|
|
Define this to return nonzero if the program is stopped in the
|
4277 |
|
|
dynamic linker.
|
4278 |
|
|
|
4279 |
|
|
`SKIP_SOLIB_RESOLVER (PC)'
|
4280 |
|
|
Define this to evaluate to the (nonzero) address at which execution
|
4281 |
|
|
|
4282 |
|
|
function. A zero value indicates that it is not important or
|
4283 |
|
|
necessary to set a breakpoint to get through the dynamic linker
|
4284 |
|
|
and that single stepping will suffice.
|
4285 |
|
|
|
4286 |
|
|
|
4287 |
|
|
Define this when the architecture needs to handle non-pointer to
|
4288 |
|
|
address conversions specially. Converts that value to an address
|
4289 |
|
|
according to the current architectures conventions.
|
4290 |
|
|
|
4291 |
|
|
_Pragmatics: When the user copies a well defined expression from
|
4292 |
|
|
their source code and passes it, as a parameter, to GDB's `print'
|
4293 |
|
|
command, they should get the same value as would have been
|
4294 |
|
|
computed by the target program. Any deviation from this rule can
|
4295 |
|
|
cause major confusion and annoyance, and needs to be justified
|
4296 |
|
|
carefully. In other words, GDB doesn't really have the freedom to
|
4297 |
|
|
do these conversions in clever and useful ways. It has, however,
|
4298 |
|
|
been pointed out that users aren't complaining about how GDB casts
|
4299 |
|
|
|
4300 |
|
|
address from a disassembly listing and give it to `x/i'. Adding
|
4301 |
|
|
an architecture method like `gdbarch_integer_to_address' certainly
|
4302 |
|
|
|
4303 |
|
|
|
4304 |
|
|
*Note Pointers Are Not Always Addresses: Target Architecture
|
4305 |
|
|
Definition.
|
4306 |
|
|
|
4307 |
|
|
`CORE_ADDR gdbarch_pointer_to_address (GDBARCH, TYPE, BUF)'
|
4308 |
|
|
|
4309 |
|
|
format for the current architecture. Return the byte address the
|
4310 |
|
|
pointer refers to. *Note Pointers Are Not Always Addresses:
|
4311 |
|
|
Target Architecture Definition.
|
4312 |
|
|
|
4313 |
|
|
|
4314 |
|
|
Convert the raw contents of register REGNUM into a value of type
|
4315 |
|
|
TYPE. *Note Using Different Register and Memory Data
|
4316 |
|
|
Representations: Target Architecture Definition.
|
4317 |
|
|
|
4318 |
|
|
|
4319 |
|
|
Convert the value of register REG from its raw form to its virtual
|
4320 |
|
|
form. *Note Raw and Virtual Register Representations: Target
|
4321 |
|
|
Architecture Definition.
|
4322 |
|
|
|
4323 |
|
|
|
4324 |
|
|
Convert the value of register REG from its virtual form to its raw
|
4325 |
|
|
form. *Note Raw and Virtual Register Representations: Target
|
4326 |
|
|
Architecture Definition.
|
4327 |
|
|
|
4328 |
|
|
`const struct regset *regset_from_core_section (struct gdbarch * GDBARCH, const char * SECT_NAME, size_t SECT_SIZE)'
|
4329 |
|
|
Return the appropriate register set for a core file section with
|
4330 |
|
|
name SECT_NAME and size SECT_SIZE.
|
4331 |
|
|
|
4332 |
|
|
`SOFTWARE_SINGLE_STEP_P()'
|
4333 |
|
|
Define this as 1 if the target does not have a hardware single-step
|
4334 |
|
|
mechanism. The macro `SOFTWARE_SINGLE_STEP' must also be defined.
|
4335 |
|
|
|
4336 |
|
|
`SOFTWARE_SINGLE_STEP(SIGNAL, INSERT_BREAKPOINTS_P)'
|
4337 |
|
|
|
4338 |
|
|
INSERT_BREAKPOINTS_P) breakpoints at each possible destinations of
|
4339 |
|
|
the next instruction. See `sparc-tdep.c' and `rs6000-tdep.c' for
|
4340 |
|
|
examples.
|
4341 |
|
|
|
4342 |
|
|
`set_gdbarch_sofun_address_maybe_missing (GDBARCH, SET)'
|
4343 |
|
|
Somebody clever observed that, the more actual addresses you have
|
4344 |
|
|
|
4345 |
|
|
relocating them. So whenever there's some other way the debugger
|
4346 |
|
|
could find the address it needs, you should omit it from the debug
|
4347 |
|
|
info, to make linking faster.
|
4348 |
|
|
|
4349 |
|
|
Calling `set_gdbarch_sofun_address_maybe_missing' with a non-zero
|
4350 |
|
|
argument SET indicates that a particular set of hacks of this sort
|
4351 |
|
|
|
4352 |
|
|
debugging information. `N_SO' stabs mark the beginning and ending
|
4353 |
|
|
|
4354 |
|
|
mark the starts and ends of functions.
|
4355 |
|
|
|
4356 |
|
|
In this case, GDB assumes two things:
|
4357 |
|
|
|
4358 |
|
|
* `N_FUN' stabs have an address of zero. Instead of using those
|
4359 |
|
|
addresses, you should find the address where the function
|
4360 |
|
|
starts by taking the function name from the stab, and then
|
4361 |
|
|
|
4362 |
|
|
table). In other words, the stab has the name, and the
|
4363 |
|
|
linker/assembler symbol table is the only place that carries
|
4364 |
|
|
the address.
|
4365 |
|
|
|
4366 |
|
|
|
4367 |
|
|
the `N_FUN' stabs that appear before and after the `N_SO'
|
4368 |
|
|
stab, and guess the starting and ending addresses of the
|
4369 |
|
|
compilation unit from them.
|
4370 |
|
|
|
4371 |
|
|
`int gdbarch_stabs_argument_has_addr (GDBARCH, TYPE)'
|
4372 |
|
|
Define this function to return nonzero if a function argument of
|
4373 |
|
|
type TYPE is passed by reference instead of value.
|
4374 |
|
|
|
4375 |
|
|
`CORE_ADDR gdbarch_push_dummy_call (GDBARCH, FUNCTION, REGCACHE, BP_ADDR, NARGS, ARGS, SP, STRUCT_RETURN, STRUCT_ADDR)'
|
4376 |
|
|
|
4377 |
|
|
function onto the stack. In addition to pushing NARGS, the code
|
4378 |
|
|
should push STRUCT_ADDR (when STRUCT_RETURN is non-zero), and the
|
4379 |
|
|
return address (BP_ADDR).
|
4380 |
|
|
|
4381 |
|
|
FUNCTION is a pointer to a `struct value'; on architectures that
|
4382 |
|
|
|
4383 |
|
|
value.
|
4384 |
|
|
|
4385 |
|
|
Returns the updated top-of-stack pointer.
|
4386 |
|
|
|
4387 |
|
|
|
4388 |
|
|
Given a stack based call dummy, push the instruction sequence
|
4389 |
|
|
(including space for a breakpoint) to which the called function
|
4390 |
|
|
should return.
|
4391 |
|
|
|
4392 |
|
|
Set BP_ADDR to the address at which the breakpoint instruction
|
4393 |
|
|
should be inserted, REAL_PC to the resume address when starting
|
4394 |
|
|
the call sequence, and return the updated inner-most stack address.
|
4395 |
|
|
|
4396 |
|
|
By default, the stack is grown sufficient to hold a frame-aligned
|
4397 |
|
|
|
4398 |
|
|
reserved for that breakpoint, and REAL_PC set to FUNADDR.
|
4399 |
|
|
|
4400 |
|
|
This method replaces `gdbarch_call_dummy_location (GDBARCH)'.
|
4401 |
|
|
|
4402 |
|
|
`int gdbarch_sdb_reg_to_regnum (GDBARCH, SDB_REGNR)'
|
4403 |
|
|
Use this function to convert sdb register SDB_REGNR into GDB
|
4404 |
|
|
regnum. If not defined, no conversion will be done.
|
4405 |
|
|
|
4406 |
|
|
`enum return_value_convention gdbarch_return_value (struct gdbarch *GDBARCH, struct type *VALTYPE, struct regcache *REGCACHE, void *READBUF, const void *WRITEBUF)'
|
4407 |
|
|
Given a function with a return-value of type RETTYPE, return which
|
4408 |
|
|
return-value convention that function would use.
|
4409 |
|
|
|
4410 |
|
|
GDB currently recognizes two function return-value conventions:
|
4411 |
|
|
|
4412 |
|
|
in registers; and `RETURN_VALUE_STRUCT_CONVENTION' where the return
|
4413 |
|
|
value is found in memory and the address of that memory location is
|
4414 |
|
|
|
4415 |
|
|
|
4416 |
|
|
If the register convention is being used, and WRITEBUF is
|
4417 |
|
|
non-`NULL', also copy the return-value in WRITEBUF into REGCACHE.
|
4418 |
|
|
|
4419 |
|
|
|
4420 |
|
|
non-`NULL', also copy the return value from REGCACHE into READBUF
|
4421 |
|
|
(REGCACHE contains a copy of the registers from the just returned
|
4422 |
|
|
function).
|
4423 |
|
|
|
4424 |
|
|
_Maintainer note: This method replaces separate predicate, extract,
|
4425 |
|
|
store methods. By having only one method, the logic needed to
|
4426 |
|
|
|
4427 |
|
|
one place. If GDB were written in an OO language, this method
|
4428 |
|
|
would instead return an object that knew how to perform the
|
4429 |
|
|
register return-value extract and store._
|
4430 |
|
|
|
4431 |
|
|
_Maintainer note: This method does not take a GCC_P parameter, and
|
4432 |
|
|
|
4433 |
|
|
requires per-compiler or per-function information be identified,
|
4434 |
|
|
then the replacement of RETTYPE with `struct value' FUNCTION
|
4435 |
|
|
should be pursued._
|
4436 |
|
|
|
4437 |
|
|
|
4438 |
|
|
the inner most frame. While replacing REGCACHE with a `struct
|
4439 |
|
|
frame_info' FRAME parameter would remove that limitation there has
|
4440 |
|
|
yet to be a demonstrated need for such a change._
|
4441 |
|
|
|
4442 |
|
|
`void gdbarch_skip_permanent_breakpoint (GDBARCH, REGCACHE)'
|
4443 |
|
|
Advance the inferior's PC past a permanent breakpoint. GDB
|
4444 |
|
|
normally steps over a breakpoint by removing it, stepping one
|
4445 |
|
|
instruction, and re-inserting the breakpoint. However, permanent
|
4446 |
|
|
breakpoints are hardwired into the inferior, and can't be removed,
|
4447 |
|
|
so this strategy doesn't work. Calling
|
4448 |
|
|
|
4449 |
|
|
so that execution will resume just after the breakpoint. This
|
4450 |
|
|
function does the right thing even when the breakpoint is in the
|
4451 |
|
|
delay slot of a branch or jump.
|
4452 |
|
|
|
4453 |
|
|
|
4454 |
|
|
If the target machine has trampoline code that sits between
|
4455 |
|
|
callers and the functions being called, then define this function
|
4456 |
|
|
to return a new PC that is at the start of the real function.
|
4457 |
|
|
|
4458 |
|
|
`int gdbarch_deprecated_fp_regnum (GDBARCH)'
|
4459 |
|
|
If the frame pointer is in a register, use this function to return
|
4460 |
|
|
the number of that register.
|
4461 |
|
|
|
4462 |
|
|
`int gdbarch_stab_reg_to_regnum (GDBARCH, STAB_REGNR)'
|
4463 |
|
|
Use this function to convert stab register STAB_REGNR into GDB
|
4464 |
|
|
regnum. If not defined, no conversion will be done.
|
4465 |
|
|
|
4466 |
|
|
`SYMBOL_RELOADING_DEFAULT'
|
4467 |
|
|
The default value of the "symbol-reloading" variable. (Never
|
4468 |
|
|
|
4469 |
|
|
|
4470 |
|
|
`TARGET_CHAR_BIT'
|
4471 |
|
|
Number of bits in a char; defaults to 8.
|
4472 |
|
|
|
4473 |
|
|
`int gdbarch_char_signed (GDBARCH)'
|
4474 |
|
|
Non-zero if `char' is normally signed on this architecture; zero if
|
4475 |
|
|
it should be unsigned.
|
4476 |
|
|
|
4477 |
|
|
The ISO C standard requires the compiler to treat `char' as
|
4478 |
|
|
|
4479 |
|
|
character in the standard execution set is supposed to be positive.
|
4480 |
|
|
Most compilers treat `char' as signed, but `char' is unsigned on
|
4481 |
|
|
the IBM S/390, RS6000, and PowerPC targets.
|
4482 |
|
|
|
4483 |
|
|
`int gdbarch_double_bit (GDBARCH)'
|
4484 |
|
|
Number of bits in a double float; defaults to
|
4485 |
|
|
|
4486 |
|
|
|
4487 |
|
|
`int gdbarch_float_bit (GDBARCH)'
|
4488 |
|
|
|
4489 |
|
|
|
4490 |
|
|
`int gdbarch_int_bit (GDBARCH)'
|
4491 |
|
|
Number of bits in an integer; defaults to `4 * TARGET_CHAR_BIT'.
|
4492 |
|
|
|
4493 |
|
|
`int gdbarch_long_bit (GDBARCH)'
|
4494 |
|
|
Number of bits in a long integer; defaults to
|
4495 |
|
|
`4 * TARGET_CHAR_BIT'.
|
4496 |
|
|
|
4497 |
|
|
`int gdbarch_long_double_bit (GDBARCH)'
|
4498 |
|
|
Number of bits in a long double float; defaults to
|
4499 |
|
|
`2 * gdbarch_double_bit (GDBARCH)'.
|
4500 |
|
|
|
4501 |
|
|
`int gdbarch_long_long_bit (GDBARCH)'
|
4502 |
|
|
Number of bits in a long long integer; defaults to
|
4503 |
|
|
`2 * gdbarch_long_bit (GDBARCH)'.
|
4504 |
|
|
|
4505 |
|
|
`int gdbarch_ptr_bit (GDBARCH)'
|
4506 |
|
|
Number of bits in a pointer; defaults to
|
4507 |
|
|
`gdbarch_int_bit (GDBARCH)'.
|
4508 |
|
|
|
4509 |
|
|
`int gdbarch_short_bit (GDBARCH)'
|
4510 |
|
|
Number of bits in a short integer; defaults to
|
4511 |
|
|
`2 * TARGET_CHAR_BIT'.
|
4512 |
|
|
|
4513 |
|
|
`void gdbarch_virtual_frame_pointer (GDBARCH, PC, FRAME_REGNUM, FRAME_OFFSET)'
|
4514 |
|
|
Returns a `(REGISTER, OFFSET)' pair representing the virtual frame
|
4515 |
|
|
|
4516 |
|
|
are not used, a default definition simply returns
|
4517 |
|
|
`gdbarch_deprecated_fp_regnum' (or `gdbarch_sp_regnum', if no
|
4518 |
|
|
frame pointer is defined), with an offset of zero.
|
4519 |
|
|
|
4520 |
|
|
|
4521 |
|
|
If non-zero, the target has support for hardware-assisted
|
4522 |
|
|
watchpoints. *Note watchpoints: Algorithms, for more details and
|
4523 |
|
|
other related macros.
|
4524 |
|
|
|
4525 |
|
|
`int gdbarch_print_insn (GDBARCH, VMA, INFO)'
|
4526 |
|
|
This is the function used by GDB to print an assembly instruction.
|
4527 |
|
|
It prints the instruction at address VMA in debugged memory and
|
4528 |
|
|
returns the length of the instruction, in bytes. This usually
|
4529 |
|
|
points to a function in the `opcodes' library (*note Opcodes:
|
4530 |
|
|
|
4531 |
|
|
`disassemble_info') defined in the header file
|
4532 |
|
|
`include/dis-asm.h', and used to pass information to the
|
4533 |
|
|
instruction decoding routine.
|
4534 |
|
|
|
4535 |
|
|
`frame_id gdbarch_dummy_id (GDBARCH, FRAME)'
|
4536 |
|
|
|
4537 |
|
|
inferior function call's dummy frame. The value returned must
|
4538 |
|
|
match the dummy frame stack value previously saved by
|
4539 |
|
|
`call_function_by_hand'.
|
4540 |
|
|
|
4541 |
|
|
|
4542 |
|
|
|
4543 |
|
|
*Note Using Different Register and Memory Data Representations:
|
4544 |
|
|
|
4545 |
|
|
|
4546 |
|
|
|
4547 |
|
|
Motorola M68K target conditionals.
|
4548 |
|
|
|
4549 |
|
|
`BPT_VECTOR'
|
4550 |
|
|
Define this to be the 4-bit location of the breakpoint trap
|
4551 |
|
|
|
4552 |
|
|
|
4553 |
|
|
`REMOTE_BPT_VECTOR'
|
4554 |
|
|
Defaults to `1'.
|
4555 |
|
|
|
4556 |
|
|
|
4557 |
|
|
|
4558 |
|
|
|
4559 |
|
|
|
4560 |
|
|
|
4561 |
|
|
=========================
|
4562 |
|
|
|
4563 |
|
|
The following files add a target to GDB:
|
4564 |
|
|
|
4565 |
|
|
`gdb/TTT-tdep.c'
|
4566 |
|
|
Contains any miscellaneous code required for this target machine.
|
4567 |
|
|
On some machines it doesn't exist at all.
|
4568 |
|
|
|
4569 |
|
|
`gdb/ARCH-tdep.c'
|
4570 |
|
|
|
4571 |
|
|
|
4572 |
|
|
machine's processor chip (registers, stack, etc.). It can be
|
4573 |
|
|
shared among many targets that use the same processor architecture.
|
4574 |
|
|
|
4575 |
|
|
|
4576 |
|
|
(Target header files such as `gdb/config/ARCH/tm-TTT.h',
|
4577 |
|
|
`gdb/config/ARCH/tm-ARCH.h', and `config/tm-OS.h' are no longer used.)
|
4578 |
|
|
|
4579 |
|
|
A GDB description for a new architecture, arch is created by
|
4580 |
|
|
|
4581 |
|
|
the source file `ARCH-tdep.c'. For example, in the case of the
|
4582 |
|
|
OpenRISC 1000, this function is called `_initialize_or1k_tdep' and is
|
4583 |
|
|
found in the file `or1k-tdep.c'.
|
4584 |
|
|
|
4585 |
|
|
The object file resulting from compiling this source file, which will
|
4586 |
|
|
|
4587 |
|
|
specified in the GDB `configure.tgt' file, which includes a large case
|
4588 |
|
|
statement pattern matching against the `--target' option of the
|
4589 |
|
|
`configure' script.
|
4590 |
|
|
|
4591 |
|
|
_Note:_ If the architecture requires multiple source files, the
|
4592 |
|
|
|
4593 |
|
|
However if there are header files, the dependencies on these will
|
4594 |
|
|
not be picked up from the entries in `configure.tgt'. The
|
4595 |
|
|
`Makefile.in' file will need extending to show these dependencies.
|
4596 |
|
|
|
4597 |
|
|
A new struct gdbarch, defining the new architecture, is created
|
4598 |
|
|
within the `_initialize_ARCH_tdep' function by calling
|
4599 |
|
|
`gdbarch_register':
|
4600 |
|
|
|
4601 |
|
|
void gdbarch_register (enum bfd_architecture architecture,
|
4602 |
|
|
gdbarch_init_ftype *init_func,
|
4603 |
|
|
|
4604 |
|
|
|
4605 |
|
|
This function has been described fully in an earlier section. *Note
|
4606 |
|
|
How an Architecture is Represented: How an Architecture is Represented.
|
4607 |
|
|
|
4608 |
|
|
The new `struct gdbarch' should contain implementations of the
|
4609 |
|
|
|
4610 |
|
|
the basic layout of the target machine's processor chip (registers,
|
4611 |
|
|
stack, etc.). It can be shared among many targets that use the same
|
4612 |
|
|
|
4613 |
|
|
|
4614 |
|
|
|
4615 |
|
|
|
4616 |
|
|
|
4617 |
|
|
12 Target Descriptions
|
4618 |
|
|
**********************
|
4619 |
|
|
|
4620 |
|
|
The target architecture definition (*note Target Architecture
|
4621 |
|
|
Definition::) contains GDB's hard-coded knowledge about an
|
4622 |
|
|
architecture. For some platforms, it is handy to have more flexible
|
4623 |
|
|
|
4624 |
|
|
a processor or development board. "Target descriptions" provide a
|
4625 |
|
|
mechanism for the user to tell GDB more about what their target
|
4626 |
|
|
supports, or for the target to tell GDB directly.
|
4627 |
|
|
|
4628 |
|
|
|
4629 |
342 |
jeremybenn |
selecting target descriptions, see *note Target Descriptions:
|
4630 |
330 |
jeremybenn |
|
4631 |
|
|
about the GDB internals.
|
4632 |
|
|
|
4633 |
|
|
|
4634 |
|
|
|
4635 |
|
|
* Target Descriptions Implementation::
|
4636 |
|
|
|
4637 |
|
|
|
4638 |
|
|
|
4639 |
|
|
|
4640 |
|
|
|
4641 |
|
|
12.1 Target Descriptions Implementation
|
4642 |
|
|
=======================================
|
4643 |
|
|
|
4644 |
|
|
|
4645 |
|
|
existing target, it discards any existing target description and
|
4646 |
|
|
reverts to a default gdbarch. Then, after connecting, it looks for a
|
4647 |
|
|
new target description by calling `target_find_description'.
|
4648 |
|
|
|
4649 |
|
|
A description may come from a user specified file (XML), the remote
|
4650 |
|
|
|
4651 |
|
|
`to_read_description' routine in the target vector. For instance, the
|
4652 |
|
|
remote target supports guessing whether a MIPS target is 32-bit or
|
4653 |
|
|
64-bit based on the size of the `g' packet.
|
4654 |
|
|
|
4655 |
|
|
If any target description is found, GDB creates a new gdbarch
|
4656 |
|
|
incorporating the description by calling `gdbarch_update_p'. Any
|
4657 |
|
|
`' element is handled first, to determine which
|
4658 |
|
|
architecture's gdbarch initialization routine is called to create the
|
4659 |
|
|
new architecture. Then the initialization routine is called, and has a
|
4660 |
|
|
|
4661 |
|
|
the target description. For instance, it can recognize any properties
|
4662 |
342 |
jeremybenn |
set by a `to_read_description' routine. Also see *note Adding Target
|
4663 |
330 |
jeremybenn |
|
4664 |
|
|
|
4665 |
|
|
|
4666 |
|
|
|
4667 |
|
|
|
4668 |
|
|
12.2 Adding Target Described Register Support
|
4669 |
|
|
=============================================
|
4670 |
|
|
|
4671 |
|
|
Target descriptions can report additional registers specific to an
|
4672 |
|
|
instance of the target. But it takes a little work in the architecture
|
4673 |
|
|
specific routines to support this.
|
4674 |
|
|
|
4675 |
|
|
A target description must either have no registers or a complete
|
4676 |
|
|
set--this avoids complexity in trying to merge standard registers with
|
4677 |
|
|
|
4678 |
|
|
to validate that a description with registers has everything it needs.
|
4679 |
|
|
To keep architecture code simple, the same mechanism is used to assign
|
4680 |
|
|
|
4681 |
|
|
|
4682 |
|
|
If `tdesc_has_registers' returns 1, the description contains
|
4683 |
|
|
|
4684 |
|
|
|
4685 |
|
|
|
4686 |
|
|
searching for a matching gdbarch or allocating a new one.
|
4687 |
|
|
|
4688 |
|
|
|
4689 |
|
|
|
4690 |
|
|
* Use `tdesc_numbered_register' and `tdesc_numbered_register_choices'
|
4691 |
|
|
to locate the expected registers in the standard features.
|
4692 |
|
|
|
4693 |
|
|
* Return `NULL' if a required feature is missing, or if any standard
|
4694 |
|
|
feature is missing expected registers. This will produce a
|
4695 |
|
|
|
4696 |
|
|
|
4697 |
|
|
* Free the allocated data before returning, unless
|
4698 |
|
|
|
4699 |
|
|
|
4700 |
|
|
* Call `set_gdbarch_num_regs' as usual, with a number higher than any
|
4701 |
|
|
|
4702 |
|
|
|
4703 |
|
|
* Call `tdesc_use_registers' after creating a new gdbarch, before
|
4704 |
|
|
returning it.
|
4705 |
|
|
|
4706 |
|
|
|
4707 |
|
|
After `tdesc_use_registers' has been called, the architecture's
|
4708 |
|
|
|
4709 |
|
|
will not be called; that information will be taken from the target
|
4710 |
|
|
|
4711 |
|
|
registers in the description.
|
4712 |
|
|
|
4713 |
|
|
Pseudo-registers require some extra care:
|
4714 |
|
|
|
4715 |
|
|
* Using `tdesc_numbered_register' allows the architecture to give
|
4716 |
|
|
constant register numbers to standard architectural registers, e.g.
|
4717 |
|
|
|
4718 |
|
|
always numbered above `num_regs', which may be increased by the
|
4719 |
|
|
description, constant numbers can not be used for pseudos. They
|
4720 |
|
|
must be numbered relative to `num_regs' instead.
|
4721 |
|
|
|
4722 |
|
|
* The description will not describe pseudo-registers, so the
|
4723 |
|
|
architecture must call `set_tdesc_pseudo_register_name',
|
4724 |
|
|
`set_tdesc_pseudo_register_type', and
|
4725 |
|
|
|
4726 |
|
|
|
4727 |
|
|
internal register numbers, so the same routines used for the
|
4728 |
|
|
gdbarch equivalents are usually suitable.
|
4729 |
|
|
|
4730 |
|
|
|
4731 |
|
|
|
4732 |
|
|
|
4733 |
|
|
|
4734 |
|
|
13 Target Vector Definition
|
4735 |
|
|
***************************
|
4736 |
|
|
|
4737 |
|
|
The target vector defines the interface between GDB's abstract handling
|
4738 |
|
|
|
4739 |
|
|
control over a process or a serial port. GDB includes some 30-40
|
4740 |
|
|
|
4741 |
|
|
only a few of them.
|
4742 |
|
|
|
4743 |
|
|
|
4744 |
|
|
|
4745 |
|
|
* Managing Execution State::
|
4746 |
|
|
|
4747 |
|
|
|
4748 |
|
|
|
4749 |
|
|
|
4750 |
|
|
|
4751 |
|
|
13.1 Managing Execution State
|
4752 |
|
|
=============================
|
4753 |
|
|
|
4754 |
|
|
A target vector can be completely inactive (not pushed on the target
|
4755 |
|
|
stack), active but not running (pushed, but not connected to a fully
|
4756 |
|
|
|
4757 |
|
|
inferior). Most targets are only completely inactive or completely
|
4758 |
|
|
active, but some support persistent connections to a target even when
|
4759 |
|
|
the target has exited or not yet started.
|
4760 |
|
|
|
4761 |
|
|
For example, connecting to the simulator using `target sim' does not
|
4762 |
|
|
|
4763 |
|
|
until `run'. Similarly, after `kill', the program can not continue
|
4764 |
|
|
executing. But in both cases GDB remains connected to the simulator,
|
4765 |
|
|
and target-specific commands are directed to the simulator.
|
4766 |
|
|
|
4767 |
|
|
|
4768 |
|
|
onto the stack in its `to_open' routine (by calling `push_target'), and
|
4769 |
|
|
unpush itself from the stack in its `to_mourn_inferior' routine (by
|
4770 |
|
|
calling `unpush_target').
|
4771 |
|
|
|
4772 |
|
|
A target which supports both partial and complete activation should
|
4773 |
|
|
still call `push_target' in `to_open', but not call `unpush_target' in
|
4774 |
|
|
`to_mourn_inferior'. Instead, it should call either
|
4775 |
|
|
`target_mark_running' or `target_mark_exited' in its `to_open',
|
4776 |
|
|
depending on whether the target is fully active after connection. It
|
4777 |
|
|
should also call `target_mark_running' any time the inferior becomes
|
4778 |
|
|
fully active (e.g. in `to_create_inferior' and `to_attach'), and
|
4779 |
|
|
|
4780 |
|
|
`to_mourn_inferior'). The target should also make sure to call
|
4781 |
|
|
`target_mourn_inferior' from its `to_kill', to return the target to
|
4782 |
|
|
|
4783 |
|
|
|
4784 |
|
|
|
4785 |
|
|
|
4786 |
|
|
|
4787 |
|
|
13.2 Existing Targets
|
4788 |
|
|
|
4789 |
|
|
|
4790 |
|
|
|
4791 |
|
|
-------------------
|
4792 |
|
|
|
4793 |
|
|
|
4794 |
|
|
|
4795 |
|
|
13.2.2 Standard Protocol and Remote Stubs
|
4796 |
|
|
-----------------------------------------
|
4797 |
|
|
|
4798 |
|
|
GDB's file `remote.c' talks a serial protocol to code that runs in the
|
4799 |
|
|
target system. GDB provides several sample "stubs" that can be
|
4800 |
|
|
integrated into target programs or operating systems for this purpose;
|
4801 |
|
|
|
4802 |
|
|
emulators, and simulators already have a GDB stub built into them, and
|
4803 |
|
|
maintenance of the remote protocol must be careful to preserve
|
4804 |
|
|
compatibility.
|
4805 |
|
|
|
4806 |
|
|
|
4807 |
|
|
target code. What follows is a discussion of integrating the SPARC
|
4808 |
|
|
stub into a complicated operating system (rather than a simple
|
4809 |
|
|
|
4810 |
|
|
|
4811 |
|
|
The trap handling code in the stub assumes the following upon entry
|
4812 |
|
|
|
4813 |
|
|
|
4814 |
|
|
|
4815 |
|
|
trap;
|
4816 |
|
|
|
4817 |
|
|
2. traps are disabled;
|
4818 |
|
|
|
4819 |
|
|
3. you are in the correct trap window.
|
4820 |
|
|
|
4821 |
|
|
As long as your trap handler can guarantee those conditions, then
|
4822 |
|
|
there is no reason why you shouldn't be able to "share" traps with the
|
4823 |
|
|
stub. The stub has no requirement that it be jumped to directly from
|
4824 |
|
|
|
4825 |
|
|
which is provided by the external environment. For instance, this could
|
4826 |
|
|
set up the hardware traps to actually execute code which calls the stub
|
4827 |
|
|
first, and then transfers to its own trap handler.
|
4828 |
|
|
|
4829 |
|
|
For the most point, there probably won't be much of an issue with
|
4830 |
|
|
"sharing" traps, as the traps we use are usually not used by the kernel,
|
4831 |
|
|
and often indicate unrecoverable error conditions. Anyway, this is all
|
4832 |
|
|
|
4833 |
|
|
trap for us is for `ta 1'. Without that, we can't single step or do
|
4834 |
|
|
breakpoints. Everything else is unnecessary for the proper operation
|
4835 |
|
|
|
4836 |
|
|
|
4837 |
|
|
From reading the stub, it's probably not obvious how breakpoints
|
4838 |
|
|
|
4839 |
|
|
|
4840 |
|
|
13.2.3 ROM Monitor Interface
|
4841 |
|
|
|
4842 |
|
|
|
4843 |
|
|
13.2.4 Custom Protocols
|
4844 |
|
|
|
4845 |
|
|
|
4846 |
|
|
13.2.5 Transport Layer
|
4847 |
|
|
|
4848 |
|
|
|
4849 |
|
|
13.2.6 Builtin Simulator
|
4850 |
|
|
|
4851 |
|
|
|
4852 |
|
|
|
4853 |
|
|
|
4854 |
|
|
|
4855 |
|
|
|
4856 |
|
|
*******************
|
4857 |
|
|
|
4858 |
|
|
Several files control GDB's configuration for native support:
|
4859 |
|
|
|
4860 |
|
|
`gdb/config/ARCH/XYZ.mh'
|
4861 |
|
|
Specifies Makefile fragments needed by a _native_ configuration on
|
4862 |
|
|
machine XYZ. In particular, this lists the required
|
4863 |
|
|
native-dependent object files, by defining `NATDEPFILES=...'.
|
4864 |
|
|
|
4865 |
|
|
XYZ, by defining `NAT_FILE= nm-XYZ.h'. You can also define
|
4866 |
|
|
`NAT_CFLAGS', `NAT_ADD_FILES', `NAT_CLIBS', `NAT_CDEPS',
|
4867 |
|
|
`NAT_GENERATED_FILES', etc.; see `Makefile.in'.
|
4868 |
|
|
|
4869 |
|
|
_Maintainer's note: The `.mh' suffix is because this file
|
4870 |
|
|
|
4871 |
|
|
machine XYZ. While the file is no longer used for this purpose,
|
4872 |
|
|
the `.mh' suffix remains. Perhaps someone will eventually rename
|
4873 |
|
|
these fragments so that they have a `.mn' suffix._
|
4874 |
|
|
|
4875 |
|
|
|
4876 |
|
|
(`nm.h' is a link to this file, created by `configure'). Contains
|
4877 |
|
|
C macro definitions describing the native system environment, such
|
4878 |
|
|
as child process control and core file support.
|
4879 |
|
|
|
4880 |
|
|
`gdb/XYZ-nat.c'
|
4881 |
|
|
Contains any miscellaneous C code required for this native support
|
4882 |
|
|
of this machine. On some machines it doesn't exist at all.
|
4883 |
|
|
|
4884 |
|
|
There are some "generic" versions of routines that can be used by
|
4885 |
|
|
|
4886 |
|
|
defined in your `nm-XYZ.h' file. If these routines work for the XYZ
|
4887 |
|
|
host, you can just include the generic file's name (with `.o', not
|
4888 |
|
|
`.c') in `NATDEPFILES'.
|
4889 |
|
|
|
4890 |
|
|
|
4891 |
|
|
need to write routines that perform the same functions as the generic
|
4892 |
|
|
file. Put them into `XYZ-nat.c', and put `XYZ-nat.o' into
|
4893 |
|
|
`NATDEPFILES'.
|
4894 |
|
|
|
4895 |
|
|
|
4896 |
|
|
This contains the _target_ops vector_ that supports Unix child
|
4897 |
|
|
processes on systems which use ptrace and wait to control the
|
4898 |
|
|
child.
|
4899 |
|
|
|
4900 |
|
|
`procfs.c'
|
4901 |
|
|
This contains the _target_ops vector_ that supports Unix child
|
4902 |
|
|
processes on systems which use /proc to control the child.
|
4903 |
|
|
|
4904 |
|
|
`fork-child.c'
|
4905 |
|
|
This does the low-level grunge that uses Unix system calls to do a
|
4906 |
|
|
"fork and exec" to start up a child process.
|
4907 |
|
|
|
4908 |
|
|
`infptrace.c'
|
4909 |
|
|
This is the low level interface to inferior processes for systems
|
4910 |
|
|
|
4911 |
|
|
|
4912 |
|
|
14.1 ptrace
|
4913 |
|
|
|
4914 |
|
|
|
4915 |
|
|
14.2 /proc
|
4916 |
|
|
|
4917 |
|
|
|
4918 |
|
|
14.3 win32
|
4919 |
|
|
|
4920 |
|
|
|
4921 |
|
|
14.4 shared libraries
|
4922 |
|
|
|
4923 |
|
|
|
4924 |
|
|
14.5 Native Conditionals
|
4925 |
|
|
========================
|
4926 |
|
|
|
4927 |
|
|
|
4928 |
|
|
undefined, to control compilation when the host and target systems are
|
4929 |
|
|
the same. These macros should be defined (or left undefined) in
|
4930 |
|
|
`nm-SYSTEM.h'.
|
4931 |
|
|
|
4932 |
|
|
|
4933 |
|
|
An x86-based machine can define this to use the generic x86
|
4934 |
342 |
jeremybenn |
watchpoint support; see *note I386_USE_GENERIC_WATCHPOINTS:
|
4935 |
330 |
jeremybenn |
Algorithms.
|
4936 |
|
|
|
4937 |
|
|
`SOLIB_ADD (FILENAME, FROM_TTY, TARG, READSYMS)'
|
4938 |
|
|
|
4939 |
|
|
symbols in FILENAME to be added to GDB's symbol table. If
|
4940 |
|
|
READSYMS is zero symbols are not read but any necessary low level
|
4941 |
|
|
processing for FILENAME is still done.
|
4942 |
|
|
|
4943 |
|
|
`SOLIB_CREATE_INFERIOR_HOOK'
|
4944 |
|
|
Define this to expand into any shared-library-relocation code that
|
4945 |
|
|
you want to be run just after the child process has been forked.
|
4946 |
|
|
|
4947 |
|
|
`START_INFERIOR_TRAPS_EXPECTED'
|
4948 |
|
|
|
4949 |
|
|
|
4950 |
|
|
If the actual number of traps is something other than 2, then
|
4951 |
|
|
define this macro to expand into the number expected.
|
4952 |
|
|
|
4953 |
|
|
|
4954 |
|
|
|
4955 |
|
|
|
4956 |
|
|
|
4957 |
|
|
15 Support Libraries
|
4958 |
|
|
|
4959 |
|
|
|
4960 |
|
|
|
4961 |
|
|
========
|
4962 |
|
|
|
4963 |
|
|
BFD provides support for GDB in several ways:
|
4964 |
|
|
|
4965 |
|
|
|
4966 |
|
|
BFD will identify a variety of file types, including a.out, coff,
|
4967 |
|
|
and several variants thereof, as well as several kinds of core
|
4968 |
|
|
files.
|
4969 |
|
|
|
4970 |
|
|
_access to sections of files_
|
4971 |
|
|
BFD parses the file headers to determine the names, virtual
|
4972 |
|
|
|
4973 |
|
|
sections in files (such as the text section or the data section).
|
4974 |
|
|
GDB simply calls BFD to read or write section X at byte offset Y
|
4975 |
|
|
for length Z.
|
4976 |
|
|
|
4977 |
|
|
_specialized core file support_
|
4978 |
|
|
|
4979 |
|
|
in a core file, the signal with which the program failed, and
|
4980 |
|
|
whether a core file matches (i.e. could be a core dump of) a
|
4981 |
|
|
particular executable file.
|
4982 |
|
|
|
4983 |
|
|
_locating the symbol information_
|
4984 |
|
|
GDB uses an internal interface of BFD to determine where to find
|
4985 |
|
|
|
4986 |
|
|
itself handles the reading of symbols, since BFD does not
|
4987 |
|
|
"understand" debug symbols, but GDB uses BFD's cached information
|
4988 |
|
|
|
4989 |
|
|
|
4990 |
|
|
15.2 opcodes
|
4991 |
|
|
|
4992 |
|
|
|
4993 |
|
|
The opcodes library provides GDB's disassembler. (It's a separate
|
4994 |
|
|
|
4995 |
|
|
|
4996 |
|
|
15.3 readline
|
4997 |
|
|
=============
|
4998 |
|
|
|
4999 |
|
|
The `readline' library provides a set of functions for use by
|
5000 |
|
|
applications that allow users to edit command lines as they are typed
|
5001 |
|
|
|
5002 |
|
|
|
5003 |
|
|
15.4 libiberty
|
5004 |
|
|
==============
|
5005 |
|
|
|
5006 |
|
|
The `libiberty' library provides a set of functions and features that
|
5007 |
|
|
integrate and improve on functionality found in modern operating
|
5008 |
|
|
systems. Broadly speaking, such features can be divided into three
|
5009 |
|
|
groups: supplemental functions (functions that may be missing in some
|
5010 |
|
|
|
5011 |
|
|
uniform and easier to use interface for commonly used standard
|
5012 |
|
|
functions), and extensions (which provide additional functionality
|
5013 |
|
|
beyond standard functions).
|
5014 |
|
|
|
5015 |
|
|
|
5016 |
|
|
instance the C++ demangler, the IEEE floating format support functions,
|
5017 |
|
|
the input options parser `getopt', the `obstack' extension, and other
|
5018 |
|
|
|
5019 |
|
|
|
5020 |
|
|
15.4.1 `obstacks' in GDB
|
5021 |
|
|
------------------------
|
5022 |
|
|
|
5023 |
|
|
The obstack mechanism provides a convenient way to allocate and free
|
5024 |
|
|
|
5025 |
|
|
like a stack. Objects (of any nature, size and alignment) are
|
5026 |
|
|
allocated and freed in a LIFO fashion on an obstack (see `libiberty''s
|
5027 |
|
|
documentation for a more detailed explanation of `obstacks').
|
5028 |
|
|
|
5029 |
|
|
The most noticeable use of the `obstacks' in GDB is in object files.
|
5030 |
|
|
There is an obstack associated with each internal representation of an
|
5031 |
|
|
object file. Lots of things get allocated on these `obstacks':
|
5032 |
|
|
dictionary entries, blocks, blockvectors, symbols, minimal symbols,
|
5033 |
|
|
types, vectors of fundamental types, class fields of types, object
|
5034 |
|
|
files section lists, object files section offset lists, line tables,
|
5035 |
|
|
symbol tables, partial symbol tables, string tables, symbol table
|
5036 |
|
|
|
5037 |
|
|
import and export lists (som), unwind information (hppa), dwarf2
|
5038 |
|
|
location expressions data. Plus various strings such as directory
|
5039 |
|
|
names strings, debug format strings, names of types.
|
5040 |
|
|
|
5041 |
|
|
An essential and convenient property of all data on `obstacks' is
|
5042 |
|
|
that memory for it gets allocated (with `obstack_alloc') at various
|
5043 |
|
|
times during a debugging session, but it is released all at once using
|
5044 |
|
|
the `obstack_free' function. The `obstack_free' function takes a
|
5045 |
|
|
pointer to where in the stack it must start the deletion from (much
|
5046 |
|
|
like the cleanup chains have a pointer to where to start the cleanups).
|
5047 |
|
|
Because of the stack like structure of the `obstacks', this allows to
|
5048 |
|
|
free only a top portion of the obstack. There are a few instances in
|
5049 |
|
|
GDB where such thing happens. Calls to `obstack_free' are done after
|
5050 |
|
|
some local data is allocated to the obstack. Only the local data is
|
5051 |
|
|
|
5052 |
|
|
the `obstack_alloc' and the `obstack_free' allocates anything else on
|
5053 |
|
|
the same obstack. For this reason it is best and safest to use
|
5054 |
|
|
temporary `obstacks'.
|
5055 |
|
|
|
5056 |
|
|
|
5057 |
|
|
under the condition that we know the `obstacks' memory is no longer
|
5058 |
|
|
needed. In GDB we get rid of the `obstacks' only when we get rid of
|
5059 |
|
|
|
5060 |
|
|
|
5061 |
|
|
|
5062 |
|
|
==============
|
5063 |
|
|
|
5064 |
|
|
Regex conditionals.
|
5065 |
|
|
|
5066 |
|
|
`C_ALLOCA'
|
5067 |
|
|
|
5068 |
|
|
`NFAILURES'
|
5069 |
|
|
|
5070 |
|
|
`RE_NREGS'
|
5071 |
|
|
|
5072 |
|
|
`SIGN_EXTEND_CHAR'
|
5073 |
|
|
|
5074 |
|
|
`SWITCH_ENUM_BUG'
|
5075 |
|
|
|
5076 |
|
|
`SYNTAX_TABLE'
|
5077 |
|
|
|
5078 |
|
|
`Sword'
|
5079 |
|
|
|
5080 |
|
|
|
5081 |
|
|
|
5082 |
|
|
15.6 Array Containers
|
5083 |
|
|
=====================
|
5084 |
|
|
|
5085 |
|
|
Often it is necessary to manipulate a dynamic array of a set of
|
5086 |
|
|
objects. C forces some bookkeeping on this, which can get cumbersome
|
5087 |
|
|
|
5088 |
|
|
using a typesafe vector type. The functions defined will be inlined
|
5089 |
|
|
when compiling, and so the abstraction cost should be zero. Domain
|
5090 |
|
|
checks are added to detect programming errors.
|
5091 |
|
|
|
5092 |
|
|
An example use would be an array of symbols or section information.
|
5093 |
|
|
The array can be grown as symbols are read in (or preallocated), and
|
5094 |
|
|
|
5095 |
|
|
bookkeeping. Because the arrays are type safe, there is no danger of
|
5096 |
|
|
accidentally mixing up the contents. Think of these as C++ templates,
|
5097 |
|
|
but implemented in C.
|
5098 |
|
|
|
5099 |
|
|
Because of the different behavior of structure objects, scalar
|
5100 |
|
|
objects and of pointers, there are three flavors of vector, one for
|
5101 |
|
|
each of these variants. Both the structure object and pointer variants
|
5102 |
|
|
pass pointers to objects around -- in the former case the pointers are
|
5103 |
|
|
|
5104 |
|
|
dereferenced and the objects copied into the vector. The scalar object
|
5105 |
|
|
variant is suitable for `int'-like objects, and the vector elements are
|
5106 |
|
|
returned by value.
|
5107 |
|
|
|
5108 |
|
|
|
5109 |
|
|
returns a boolean iteration condition and updates the iteration
|
5110 |
|
|
variable passed by reference. Because the iterator will be inlined,
|
5111 |
|
|
the address-of can be optimized away.
|
5112 |
|
|
|
5113 |
|
|
The vectors are implemented using the trailing array idiom, thus they
|
5114 |
|
|
are not resizeable without changing the address of the vector object
|
5115 |
|
|
itself. This means you cannot have variables or fields of vector type
|
5116 |
|
|
-- always use a pointer to a vector. The one exception is the final
|
5117 |
|
|
field of a structure, which could be a vector type. You will have to
|
5118 |
|
|
use the `embedded_size' & `embedded_init' calls to create such objects,
|
5119 |
|
|
and they will probably not be resizeable (so don't use the "safe"
|
5120 |
|
|
|
5121 |
|
|
pointer to an array of data), because, if we allow `NULL' to also
|
5122 |
|
|
represent an empty vector, empty vectors occupy minimal space in the
|
5123 |
|
|
structure containing them.
|
5124 |
|
|
|
5125 |
|
|
Each operation that increases the number of active elements is
|
5126 |
|
|
available in "quick" and "safe" variants. The former presumes that
|
5127 |
|
|
there is sufficient allocated space for the operation to succeed (it
|
5128 |
|
|
dies if there is not). The latter will reallocate the vector, if
|
5129 |
|
|
needed. Reallocation causes an exponential increase in vector size.
|
5130 |
|
|
If you know you will be adding N elements, it would be more efficient
|
5131 |
|
|
to use the reserve operation before adding the elements with the
|
5132 |
|
|
"quick" operation. This will ensure there are at least as many
|
5133 |
|
|
elements as you ask for, it will exponentially increase if there are
|
5134 |
|
|
|
5135 |
|
|
but do not want the exponential increase (for instance, you know this
|
5136 |
|
|
is the last allocation), use a negative number for reservation. You
|
5137 |
|
|
can also create a vector of a specific size from the get go.
|
5138 |
|
|
|
5139 |
|
|
You should prefer the push and pop operations, as they append and
|
5140 |
|
|
remove from the end of the vector. If you need to remove several items
|
5141 |
|
|
in one go, use the truncate operation. The insert and remove
|
5142 |
|
|
operations allow you to change elements in the middle of the vector.
|
5143 |
|
|
There are two remove operations, one which preserves the element
|
5144 |
|
|
ordering `ordered_remove', and one which does not `unordered_remove'.
|
5145 |
|
|
|
5146 |
|
|
rather than invoke a memmove operation. The `lower_bound' function
|
5147 |
|
|
will determine where to place an item in the array using insert that
|
5148 |
|
|
will maintain sorted order.
|
5149 |
|
|
|
5150 |
|
|
|
5151 |
|
|
accessor will return the address of the start of the vector. Also the
|
5152 |
|
|
`space' predicate will tell you whether there is spare capacity in the
|
5153 |
|
|
vector. You will not normally need to use these two functions.
|
5154 |
|
|
|
5155 |
|
|
Vector types are defined using a `DEF_VEC_{O,P,I}(TYPENAME)' macro.
|
5156 |
|
|
Variables of vector type are declared using a `VEC(TYPENAME)' macro.
|
5157 |
|
|
The characters `O', `P' and `I' indicate whether TYPENAME is an object
|
5158 |
|
|
(`O'), pointer (`P') or integral (`I') type. Be careful to pick the
|
5159 |
|
|
|
5160 |
|
|
the wrong one. There is a check, which results in a compile-time
|
5161 |
|
|
|
5162 |
|
|
`O' versions, as that is not possible in plain C.
|
5163 |
|
|
|
5164 |
|
|
An example of their use would be,
|
5165 |
|
|
|
5166 |
|
|
DEF_VEC_P(tree); // non-managed tree vector.
|
5167 |
|
|
|
5168 |
|
|
struct my_struct {
|
5169 |
|
|
|
5170 |
|
|
};
|
5171 |
|
|
|
5172 |
|
|
struct my_struct *s;
|
5173 |
|
|
|
5174 |
|
|
|
5175 |
|
|
VEC_safe_push(tree, s->v, decl); // append some decl onto the end
|
5176 |
|
|
for (ix = 0; VEC_iterate(tree, s->v, ix, elt); ix++)
|
5177 |
|
|
|
5178 |
|
|
|
5179 |
|
|
The `vec.h' file provides details on how to invoke the various
|
5180 |
|
|
|
5181 |
|
|
|
5182 |
|
|
`VEC_length'
|
5183 |
|
|
|
5184 |
|
|
|
5185 |
|
|
`VEC_empty'
|
5186 |
|
|
Return true if the array has no elements.
|
5187 |
|
|
|
5188 |
|
|
`VEC_last'
|
5189 |
|
|
`VEC_index'
|
5190 |
|
|
Return the last or arbitrary item in the array.
|
5191 |
|
|
|
5192 |
|
|
`VEC_iterate'
|
5193 |
|
|
Access an array element and indicate whether the array has been
|
5194 |
|
|
traversed.
|
5195 |
|
|
|
5196 |
|
|
`VEC_alloc'
|
5197 |
|
|
`VEC_free'
|
5198 |
|
|
Create and destroy an array.
|
5199 |
|
|
|
5200 |
|
|
|
5201 |
|
|
`VEC_embedded_init'
|
5202 |
|
|
Helpers for embedding an array as the final element of another
|
5203 |
|
|
|
5204 |
|
|
|
5205 |
|
|
`VEC_copy'
|
5206 |
|
|
|
5207 |
|
|
|
5208 |
|
|
`VEC_space'
|
5209 |
|
|
|
5210 |
|
|
|
5211 |
|
|
`VEC_reserve'
|
5212 |
|
|
Ensure a certain amount of free space.
|
5213 |
|
|
|
5214 |
|
|
|
5215 |
|
|
`VEC_safe_push'
|
5216 |
|
|
Append to an array, either assuming the space is available, or
|
5217 |
|
|
|
5218 |
|
|
|
5219 |
|
|
`VEC_pop'
|
5220 |
|
|
|
5221 |
|
|
|
5222 |
|
|
`VEC_truncate'
|
5223 |
|
|
|
5224 |
|
|
|
5225 |
|
|
`VEC_safe_grow'
|
5226 |
|
|
|
5227 |
|
|
|
5228 |
|
|
`VEC_replace'
|
5229 |
|
|
Overwrite an item in the array.
|
5230 |
|
|
|
5231 |
|
|
|
5232 |
|
|
`VEC_safe_insert'
|
5233 |
|
|
Insert an item into the middle of the array. Either the space must
|
5234 |
|
|
already exist, or the space is created.
|
5235 |
|
|
|
5236 |
|
|
`VEC_ordered_remove'
|
5237 |
|
|
`VEC_unordered_remove'
|
5238 |
|
|
|
5239 |
|
|
|
5240 |
|
|
`VEC_block_remove'
|
5241 |
|
|
|
5242 |
|
|
|
5243 |
|
|
`VEC_address'
|
5244 |
|
|
|
5245 |
|
|
|
5246 |
|
|
`VEC_lower_bound'
|
5247 |
|
|
Binary search the array.
|
5248 |
|
|
|
5249 |
|
|
|
5250 |
|
|
15.7 include
|
5251 |
|
|
|
5252 |
|
|
|
5253 |
|
|
|
5254 |
|
|
|
5255 |
|
|
|
5256 |
|
|
16 Coding
|
5257 |
|
|
|
5258 |
|
|
|
5259 |
|
|
This chapter covers topics that are lower-level than the major
|
5260 |
|
|
|
5261 |
|
|
|
5262 |
|
|
16.1 Cleanups
|
5263 |
|
|
|
5264 |
|
|
|
5265 |
|
|
Cleanups are a structured way to deal with things that need to be done
|
5266 |
|
|
later.
|
5267 |
|
|
|
5268 |
|
|
When your code does something (e.g., `xmalloc' some memory, or
|
5269 |
|
|
`open' a file) that needs to be undone later (e.g., `xfree' the memory
|
5270 |
|
|
or `close' the file), it can make a cleanup. The cleanup will be done
|
5271 |
|
|
|
5272 |
|
|
to the top level; when an error occurs and the stack is unwound; or
|
5273 |
|
|
|
5274 |
|
|
Alternatively you can elect to discard the cleanups you created.
|
5275 |
|
|
|
5276 |
|
|
|
5277 |
|
|
|
5278 |
|
|
`struct cleanup *OLD_CHAIN;'
|
5279 |
|
|
Declare a variable which will hold a cleanup chain handle.
|
5280 |
|
|
|
5281 |
|
|
`OLD_CHAIN = make_cleanup (FUNCTION, ARG);'
|
5282 |
|
|
Make a cleanup which will cause FUNCTION to be called with ARG (a
|
5283 |
|
|
|
5284 |
|
|
later be passed to `do_cleanups' or `discard_cleanups'. Unless
|
5285 |
|
|
you are going to call `do_cleanups' or `discard_cleanups', you can
|
5286 |
|
|
ignore the result from `make_cleanup'.
|
5287 |
|
|
|
5288 |
|
|
`do_cleanups (OLD_CHAIN);'
|
5289 |
|
|
Do all cleanups added to the chain since the corresponding
|
5290 |
|
|
`make_cleanup' call was made.
|
5291 |
|
|
|
5292 |
|
|
`discard_cleanups (OLD_CHAIN);'
|
5293 |
|
|
Same as `do_cleanups' except that it just removes the cleanups from
|
5294 |
|
|
the chain and does not call the specified functions.
|
5295 |
|
|
|
5296 |
|
|
|
5297 |
|
|
`make_cleanups' includes the cleanup passed to the call and any later
|
5298 |
|
|
cleanups appended to the chain (but not yet discarded or performed).
|
5299 |
|
|
E.g.:
|
5300 |
|
|
|
5301 |
|
|
make_cleanup (a, 0);
|
5302 |
|
|
{
|
5303 |
|
|
struct cleanup *old = make_cleanup (b, 0);
|
5304 |
|
|
|
5305 |
|
|
...
|
5306 |
|
|
do_cleanups (old);
|
5307 |
|
|
}
|
5308 |
|
|
|
5309 |
|
|
will call `c()' and `b()' but will not call `a()'. The cleanup that
|
5310 |
|
|
calls `a()' will remain in the cleanup chain, and will be done later
|
5311 |
|
|
unless otherwise discarded.
|
5312 |
|
|
|
5313 |
|
|
|
5314 |
|
|
creates. Failing to do this leads to non-deterministic behavior since
|
5315 |
|
|
the caller will arbitrarily do or discard your functions cleanups.
|
5316 |
|
|
This need leads to two common cleanup styles.
|
5317 |
|
|
|
5318 |
|
|
The first style is try/finally. Before it exits, your code-block
|
5319 |
|
|
calls `do_cleanups' with the old cleanup chain and thus ensures that
|
5320 |
|
|
|
5321 |
|
|
following code-segment avoids a memory leak problem (even when `error'
|
5322 |
|
|
is called and a forced stack unwind occurs) by ensuring that the
|
5323 |
|
|
`xfree' will always be called:
|
5324 |
|
|
|
5325 |
|
|
struct cleanup *old = make_cleanup (null_cleanup, 0);
|
5326 |
|
|
|
5327 |
|
|
make_cleanup (xfree, data);
|
5328 |
|
|
... blah blah ...
|
5329 |
|
|
do_cleanups (old);
|
5330 |
|
|
|
5331 |
|
|
The second style is try/except. Before it exits, your code-block
|
5332 |
|
|
|
5333 |
|
|
that any created cleanups are not performed. For instance, the
|
5334 |
|
|
following code segment, ensures that the file will be closed but only
|
5335 |
|
|
if there is an error:
|
5336 |
|
|
|
5337 |
|
|
FILE *file = fopen ("afile", "r");
|
5338 |
|
|
|
5339 |
|
|
... blah blah ...
|
5340 |
|
|
discard_cleanups (old);
|
5341 |
|
|
return file;
|
5342 |
|
|
|
5343 |
|
|
Some functions, e.g., `fputs_filtered()' or `error()', specify that
|
5344 |
|
|
they "should not be called when cleanups are not in place". This means
|
5345 |
|
|
|
5346 |
|
|
interruption must be on the cleanup chain before you call these
|
5347 |
|
|
functions, since they might never return to your code (they `longjmp'
|
5348 |
|
|
|
5349 |
|
|
|
5350 |
|
|
16.2 Per-architecture module data
|
5351 |
|
|
=================================
|
5352 |
|
|
|
5353 |
|
|
The multi-arch framework includes a mechanism for adding module
|
5354 |
|
|
|
5355 |
|
|
architecture object.
|
5356 |
|
|
|
5357 |
|
|
A module registers one or more per-architecture data-pointers using:
|
5358 |
|
|
|
5359 |
|
|
-- Architecture Function: struct gdbarch_data *
|
5360 |
|
|
gdbarch_data_register_pre_init (gdbarch_data_pre_init_ftype *PRE_INIT)
|
5361 |
|
|
PRE_INIT is used to, on-demand, allocate an initial value for a
|
5362 |
|
|
per-architecture data-pointer using the architecture's obstack
|
5363 |
|
|
|
5364 |
|
|
architecture creation, it is not parameterized with the
|
5365 |
|
|
architecture. and must not call modules that use per-architecture
|
5366 |
|
|
data.
|
5367 |
|
|
|
5368 |
|
|
-- Architecture Function: struct gdbarch_data *
|
5369 |
|
|
gdbarch_data_register_post_init (gdbarch_data_post_init_ftype
|
5370 |
|
|
*POST_INIT)
|
5371 |
|
|
POST_INIT is used to obtain an initial value for a
|
5372 |
|
|
per-architecture data-pointer _after_. Since POST_INIT is always
|
5373 |
|
|
called after architecture creation, it both receives the fully
|
5374 |
|
|
|
5375 |
|
|
per-architecture data (care needs to be taken to ensure that those
|
5376 |
|
|
other modules do not try to call back to this module as that will
|
5377 |
|
|
|
5378 |
|
|
|
5379 |
|
|
|
5380 |
|
|
identify the per-architecture data-pointer added for that module.
|
5381 |
|
|
|
5382 |
|
|
The per-architecture data-pointer is accessed using the function:
|
5383 |
|
|
|
5384 |
|
|
-- Architecture Function: void * gdbarch_data (struct gdbarch
|
5385 |
|
|
*GDBARCH, struct gdbarch_data *DATA_HANDLE)
|
5386 |
|
|
Given the architecture ARCH and module data handle DATA_HANDLE
|
5387 |
|
|
(returned by `gdbarch_data_register_pre_init' or
|
5388 |
|
|
|
5389 |
|
|
current value of the per-architecture data-pointer. If the data
|
5390 |
|
|
|
5391 |
|
|
corresponding PRE_INIT or POST_INIT method.
|
5392 |
|
|
|
5393 |
|
|
|
5394 |
|
|
|
5395 |
|
|
struct nozel { int total; };
|
5396 |
|
|
static struct gdbarch_data *nozel_handle;
|
5397 |
|
|
|
5398 |
|
|
A module can extend the architecture vector, adding additional
|
5399 |
|
|
per-architecture data, using the PRE_INIT method. The module's
|
5400 |
|
|
per-architecture data is then initialized during architecture creation.
|
5401 |
|
|
|
5402 |
|
|
In the below, the module's per-architecture _nozel_ is added. An
|
5403 |
|
|
architecture can specify its nozel by calling `set_gdbarch_nozel' from
|
5404 |
|
|
`gdbarch_init'.
|
5405 |
|
|
|
5406 |
|
|
static void *
|
5407 |
|
|
nozel_pre_init (struct obstack *obstack)
|
5408 |
|
|
|
5409 |
|
|
struct nozel *data = OBSTACK_ZALLOC (obstack, struct nozel);
|
5410 |
|
|
return data;
|
5411 |
|
|
}
|
5412 |
|
|
|
5413 |
|
|
extern void
|
5414 |
|
|
set_gdbarch_nozel (struct gdbarch *gdbarch, int total)
|
5415 |
|
|
|
5416 |
|
|
struct nozel *data = gdbarch_data (gdbarch, nozel_handle);
|
5417 |
|
|
data->total = nozel;
|
5418 |
|
|
|
5419 |
|
|
|
5420 |
|
|
A module can on-demand create architecture dependent data structures
|
5421 |
|
|
|
5422 |
|
|
|
5423 |
|
|
In the below, the nozel's total is computed on-demand by
|
5424 |
|
|
`nozel_post_init' using information obtained from the architecture.
|
5425 |
|
|
|
5426 |
|
|
static void *
|
5427 |
|
|
nozel_post_init (struct gdbarch *gdbarch)
|
5428 |
|
|
{
|
5429 |
|
|
|
5430 |
|
|
nozel->total = gdbarch... (gdbarch);
|
5431 |
|
|
return data;
|
5432 |
|
|
}
|
5433 |
|
|
|
5434 |
|
|
extern int
|
5435 |
|
|
nozel_total (struct gdbarch *gdbarch)
|
5436 |
|
|
|
5437 |
|
|
struct nozel *data = gdbarch_data (gdbarch, nozel_handle);
|
5438 |
|
|
return data->total;
|
5439 |
|
|
|
5440 |
|
|
|
5441 |
|
|
16.3 Wrapping Output Lines
|
5442 |
|
|
==========================
|
5443 |
|
|
|
5444 |
|
|
|
5445 |
|
|
`fputs_demangled' needs only to have calls to `wrap_here' added in
|
5446 |
|
|
places that would be good breaking points. The utility routines will
|
5447 |
|
|
take care of actually wrapping if the line width is exceeded.
|
5448 |
|
|
|
5449 |
|
|
The argument to `wrap_here' is an indentation string which is
|
5450 |
|
|
|
5451 |
|
|
and used later. It must remain valid until the next call to
|
5452 |
|
|
`wrap_here' or until a newline has been printed through the
|
5453 |
|
|
`*_filtered' functions. Don't pass in a local variable and then return!
|
5454 |
|
|
|
5455 |
|
|
|
5456 |
|
|
space. If you call it before printing a space, make sure that your
|
5457 |
|
|
indentation properly accounts for the leading space that will print if
|
5458 |
|
|
the line wraps there.
|
5459 |
|
|
|
5460 |
|
|
|
5461 |
|
|
finish by printing a newline, to flush the wrap buffer, before switching
|
5462 |
|
|
to unfiltered (`printf') output. Symbol reading routines that print
|
5463 |
|
|
|
5464 |
|
|
|
5465 |
|
|
16.4 GDB Coding Standards
|
5466 |
|
|
=========================
|
5467 |
|
|
|
5468 |
|
|
GDB follows the GNU coding standards, as described in
|
5469 |
|
|
|
5470 |
|
|
from GNU archive sites. GDB takes a strict interpretation of the
|
5471 |
|
|
standard; in general, when the GNU standard recommends a practice but
|
5472 |
|
|
|
5473 |
|
|
|
5474 |
|
|
GDB follows an additional set of coding standards specific to GDB,
|
5475 |
|
|
|
5476 |
|
|
|
5477 |
|
|
|
5478 |
|
|
------------
|
5479 |
|
|
|
5480 |
|
|
GDB assumes an ISO/IEC 9899:1990 (a.k.a. ISO C90) compliant compiler.
|
5481 |
|
|
|
5482 |
|
|
|
5483 |
|
|
|
5484 |
|
|
16.4.2 Memory Management
|
5485 |
|
|
|
5486 |
|
|
|
5487 |
|
|
GDB does not use the functions `malloc', `realloc', `calloc', `free'
|
5488 |
|
|
and `asprintf'.
|
5489 |
|
|
|
5490 |
|
|
GDB uses the functions `xmalloc', `xrealloc' and `xcalloc' when
|
5491 |
|
|
|
5492 |
|
|
return when the memory pool is empty. Instead, they unwind the stack
|
5493 |
|
|
using cleanups. These functions return `NULL' when requested to
|
5494 |
|
|
allocate a chunk of memory of size zero.
|
5495 |
|
|
|
5496 |
|
|
_Pragmatics: By using these functions, the need to check every
|
5497 |
|
|
|
5498 |
|
|
behavior._
|
5499 |
|
|
|
5500 |
|
|
GDB does not use the function `free'.
|
5501 |
|
|
|
5502 |
|
|
GDB uses the function `xfree' to return memory to the memory pool.
|
5503 |
|
|
Consistent with ISO-C, this function ignores a request to free a `NULL'
|
5504 |
|
|
|
5505 |
|
|
|
5506 |
|
|
_Pragmatics: On some systems `free' fails when passed a `NULL'
|
5507 |
|
|
|
5508 |
|
|
|
5509 |
|
|
GDB can use the non-portable function `alloca' for the allocation of
|
5510 |
|
|
|
5511 |
|
|
|
5512 |
|
|
_Pragmatics: This function is very non-portable. Some systems
|
5513 |
|
|
|
5514 |
|
|
|
5515 |
|
|
GDB uses the string function `xstrdup' and the print function
|
5516 |
|
|
|
5517 |
|
|
|
5518 |
|
|
_Pragmatics: `asprintf' and `strdup' can fail. Print functions such
|
5519 |
|
|
|
5520 |
|
|
|
5521 |
|
|
16.4.3 Compiler Warnings
|
5522 |
|
|
------------------------
|
5523 |
|
|
|
5524 |
|
|
|
5525 |
|
|
`--disable-werror' when building GDB. The exceptions are listed in the
|
5526 |
|
|
file `gdb/MAINTAINERS'. The default, when building with GCC, is
|
5527 |
|
|
`--enable-werror'.
|
5528 |
|
|
|
5529 |
|
|
This option causes GDB (when built using GCC) to be compiled with a
|
5530 |
|
|
|
5531 |
|
|
those flags are treated as errors.
|
5532 |
|
|
|
5533 |
|
|
|
5534 |
|
|
|
5535 |
|
|
`-Wall'
|
5536 |
|
|
Recommended GCC warnings.
|
5537 |
|
|
|
5538 |
|
|
`-Wdeclaration-after-statement'
|
5539 |
|
|
|
5540 |
|
|
but GCC 2.x and C89 do not.
|
5541 |
|
|
|
5542 |
|
|
`-Wpointer-arith'
|
5543 |
|
|
|
5544 |
|
|
`-Wformat-nonliteral'
|
5545 |
|
|
Non-literal format strings, with a few exceptions, are bugs - they
|
5546 |
|
|
|
5547 |
|
|
GDB uses the `format printf' attribute on all `printf' like
|
5548 |
|
|
functions this checks not just `printf' calls but also calls to
|
5549 |
|
|
functions such as `fprintf_unfiltered'.
|
5550 |
|
|
|
5551 |
|
|
`-Wno-pointer-sign'
|
5552 |
|
|
In version 4.0, GCC began warning about pointer argument passing or
|
5553 |
|
|
assignment even when the source and destination differed only in
|
5554 |
|
|
|
5555 |
|
|
between `char' and `unsigned char'. In early 2006 the GDB
|
5556 |
|
|
developers decided correcting these warnings wasn't worth the time
|
5557 |
|
|
it would take.
|
5558 |
|
|
|
5559 |
|
|
`-Wno-unused-parameter'
|
5560 |
|
|
Due to the way that GDB is implemented many functions have unused
|
5561 |
|
|
|
5562 |
|
|
`ATTRIBUTE_UNUSED' is not used as it leads to false negatives --
|
5563 |
|
|
it is not an error to have `ATTRIBUTE_UNUSED' on a parameter that
|
5564 |
|
|
is being used.
|
5565 |
|
|
|
5566 |
|
|
`-Wno-unused'
|
5567 |
|
|
|
5568 |
|
|
|
5569 |
|
|
These are warnings which might be useful for GDB, but are
|
5570 |
|
|
currently too noisy to enable with `-Werror'.
|
5571 |
|
|
|
5572 |
|
|
|
5573 |
|
|
16.4.4 Formatting
|
5574 |
|
|
|
5575 |
|
|
|
5576 |
|
|
The standard GNU recommendations for formatting must be followed
|
5577 |
|
|
|
5578 |
|
|
|
5579 |
|
|
A function declaration should not have its name in column zero. A
|
5580 |
|
|
function definition should have its name in column zero.
|
5581 |
|
|
|
5582 |
|
|
/* Declaration */
|
5583 |
|
|
static void foo (void);
|
5584 |
|
|
/* Definition */
|
5585 |
|
|
|
5586 |
|
|
foo (void)
|
5587 |
|
|
{
|
5588 |
|
|
|
5589 |
|
|
|
5590 |
|
|
_Pragmatics: This simplifies scripting. Function definitions can be
|
5591 |
|
|
found using `^function-name'._
|
5592 |
|
|
|
5593 |
|
|
|
5594 |
|
|
opening parenthesis of its argument list (except for macro definitions,
|
5595 |
|
|
as required by C). There must not be a space after an open
|
5596 |
|
|
paren/bracket or before a close paren/bracket.
|
5597 |
|
|
|
5598 |
|
|
While additional whitespace is generally helpful for reading, do not
|
5599 |
|
|
|
5600 |
|
|
whitespace after the end of a program line (as of 1/99, some 600 lines
|
5601 |
|
|
|
5602 |
|
|
difficulties for `diff' and `patch' utilities.
|
5603 |
|
|
|
5604 |
|
|
Pointers are declared using the traditional K&R C style:
|
5605 |
|
|
|
5606 |
|
|
void *foo;
|
5607 |
|
|
|
5608 |
|
|
|
5609 |
|
|
|
5610 |
|
|
void * foo;
|
5611 |
|
|
|
5612 |
|
|
|
5613 |
|
|
|
5614 |
|
|
---------------
|
5615 |
|
|
|
5616 |
|
|
|
5617 |
|
|
|
5618 |
|
|
Block comments must appear in the following form, with no `/*'- or
|
5619 |
|
|
`*/'-only lines, and no leading `*':
|
5620 |
|
|
|
5621 |
|
|
/* Wait for control to return from inferior to debugger. If inferior
|
5622 |
|
|
|
5623 |
|
|
returning. That is why there is a loop in this function. When
|
5624 |
|
|
this function actually returns it means the inferior should be left
|
5625 |
|
|
stopped and GDB should read more commands. */
|
5626 |
|
|
|
5627 |
|
|
(Note that this format is encouraged by Emacs; tabbing for a
|
5628 |
|
|
multi-line comment works correctly, and `M-q' fills the block
|
5629 |
|
|
|
5630 |
|
|
|
5631 |
|
|
Put a blank line between the block comments preceding function or
|
5632 |
|
|
variable definitions, and the definition itself.
|
5633 |
|
|
|
5634 |
|
|
|
5635 |
|
|
than trying to fit them into the 20 characters left at the end of a
|
5636 |
|
|
line, since either the comment or the code will inevitably get longer
|
5637 |
|
|
|
5638 |
|
|
|
5639 |
|
|
16.4.6 C Usage
|
5640 |
|
|
--------------
|
5641 |
|
|
|
5642 |
|
|
Code must not depend on the sizes of C data types, the format of the
|
5643 |
|
|
host's floating point numbers, the alignment of anything, or the order
|
5644 |
|
|
of evaluation of expressions.
|
5645 |
|
|
|
5646 |
|
|
|
5647 |
|
|
areas in GDB that might be affected by the overhead of a function call,
|
5648 |
|
|
mainly in symbol reading. Most of GDB's performance is limited by the
|
5649 |
|
|
target interface (whether serial line or system call).
|
5650 |
|
|
|
5651 |
|
|
However, use functions with moderation. A thousand one-line
|
5652 |
|
|
functions are just as hard to understand as a single thousand-line
|
5653 |
|
|
|
5654 |
|
|
|
5655 |
|
|
_Macros are bad, M'kay._ (But if you have to use a macro, make sure
|
5656 |
|
|
|
5657 |
|
|
|
5658 |
|
|
Declarations like `struct foo *' should be used in preference to
|
5659 |
|
|
|
5660 |
|
|
|
5661 |
|
|
16.4.7 Function Prototypes
|
5662 |
|
|
--------------------------
|
5663 |
|
|
|
5664 |
|
|
|
5665 |
|
|
function. Prototypes for GDB functions must include both the argument
|
5666 |
|
|
type and name, with the name matching that used in the actual function
|
5667 |
|
|
definition.
|
5668 |
|
|
|
5669 |
|
|
|
5670 |
|
|
that callers include, except for `_initialize_*' functions, which must
|
5671 |
|
|
be external so that `init.c' construction works, but shouldn't be
|
5672 |
|
|
|
5673 |
|
|
|
5674 |
|
|
Where a source file needs a forward declaration of a static function,
|
5675 |
|
|
|
5676 |
|
|
|
5677 |
|
|
16.4.8 Internal Error Recovery
|
5678 |
|
|
------------------------------
|
5679 |
|
|
|
5680 |
|
|
During its execution, GDB can encounter two types of errors. User
|
5681 |
|
|
errors and internal errors. User errors include not only a user
|
5682 |
|
|
|
5683 |
|
|
object files and system errors when interacting with the target.
|
5684 |
|
|
Internal errors include situations where GDB has detected, at run time,
|
5685 |
|
|
|
5686 |
|
|
|
5687 |
|
|
|
5688 |
|
|
`gdb_assert'.
|
5689 |
|
|
|
5690 |
|
|
GDB must not call `abort' or `assert'.
|
5691 |
|
|
|
5692 |
|
|
|
5693 |
|
|
code detected a user error, recovered from it and issued a `warning' or
|
5694 |
|
|
the code failed to correctly recover from the user error and issued an
|
5695 |
|
|
|
5696 |
|
|
|
5697 |
|
|
|
5698 |
|
|
--------------------
|
5699 |
|
|
|
5700 |
|
|
|
5701 |
|
|
|
5702 |
|
|
16.4.10 File Names
|
5703 |
|
|
------------------
|
5704 |
|
|
|
5705 |
|
|
Any file used when building the core of GDB must be in lower case. Any
|
5706 |
|
|
file used when building the core of GDB must be 8.3 unique. These
|
5707 |
|
|
requirements apply to both source and generated files.
|
5708 |
|
|
|
5709 |
|
|
_Pragmatics: The core of GDB must be buildable on many platforms
|
5710 |
|
|
including DJGPP and MacOS/HFS. Every time an unfriendly file is
|
5711 |
|
|
|
5712 |
|
|
need to be modified accordingly. Compare the convoluted conversion
|
5713 |
|
|
process needed to transform `COPYING' into `copying.c' with the
|
5714 |
|
|
|
5715 |
|
|
|
5716 |
|
|
|
5717 |
|
|
core of GDB) must be added to `gdb/config/djgpp/fnchange.lst'.
|
5718 |
|
|
|
5719 |
|
|
_Pragmatics: This is clearly a compromise._
|
5720 |
|
|
|
5721 |
|
|
When GDB has a local version of a system header file (ex `string.h')
|
5722 |
|
|
the file name based on the POSIX header prefixed with `gdb_'
|
5723 |
|
|
(`gdb_string.h'). These headers should be relatively independent: they
|
5724 |
|
|
|
5725 |
|
|
host; they should include only system headers; they should refer only
|
5726 |
|
|
|
5727 |
|
|
GDB and GDBSERVER.
|
5728 |
|
|
|
5729 |
|
|
|
5730 |
|
|
|
5731 |
|
|
|
5732 |
|
|
---------------------
|
5733 |
|
|
|
5734 |
|
|
A `.c' file should include `defs.h' first.
|
5735 |
|
|
|
5736 |
|
|
A `.c' file should directly include the `.h' file of every
|
5737 |
|
|
declaration and/or definition it directly refers to. It cannot rely on
|
5738 |
|
|
indirect inclusion.
|
5739 |
|
|
|
5740 |
|
|
|
5741 |
|
|
declaration and/or definition it directly refers to. It cannot rely on
|
5742 |
|
|
|
5743 |
|
|
directly included.
|
5744 |
|
|
|
5745 |
|
|
An external declaration should only appear in one include file.
|
5746 |
|
|
|
5747 |
|
|
An external declaration should never appear in a `.c' file.
|
5748 |
|
|
|
5749 |
|
|
`-Wmissing-declaration'.
|
5750 |
|
|
|
5751 |
|
|
A `typedef' definition should only appear in one include file.
|
5752 |
|
|
|
5753 |
|
|
An opaque `struct' declaration can appear in multiple `.h' files.
|
5754 |
|
|
|
5755 |
|
|
instead of an include.
|
5756 |
|
|
|
5757 |
|
|
All `.h' files should be wrapped in:
|
5758 |
|
|
|
5759 |
|
|
|
5760 |
|
|
#define INCLUDE_FILE_NAME_H
|
5761 |
|
|
header body
|
5762 |
|
|
|
5763 |
|
|
|
5764 |
|
|
16.4.12 Clean Design and Portable Implementation
|
5765 |
|
|
------------------------------------------------
|
5766 |
|
|
|
5767 |
|
|
|
5768 |
|
|
semantics. Some things are done in certain ways in GDB because long
|
5769 |
|
|
experience has shown that the more obvious ways caused various kinds of
|
5770 |
|
|
trouble.
|
5771 |
|
|
|
5772 |
|
|
|
5773 |
|
|
(including VALUEs, object files, and instructions). Such things must
|
5774 |
|
|
be byte-swapped using `SWAP_TARGET_AND_HOST' in GDB, or one of the swap
|
5775 |
|
|
routines defined in `bfd.h', such as `bfd_get_32'.
|
5776 |
|
|
|
5777 |
|
|
You can't assume that you know what interface is being used to talk
|
5778 |
|
|
to the target system. All references to the target must go through the
|
5779 |
|
|
current `target_ops' vector.
|
5780 |
|
|
|
5781 |
|
|
You can't assume that the host and target machines are the same
|
5782 |
|
|
machine (except in the "native" support modules). In particular, you
|
5783 |
|
|
|
5784 |
|
|
on the host machine. Target code must bring along its own header files
|
5785 |
|
|
- written from scratch or explicitly donated by their owner, to avoid
|
5786 |
|
|
copyright problems.
|
5787 |
|
|
|
5788 |
|
|
Insertion of new `#ifdef''s will be frowned upon. It's much better
|
5789 |
|
|
to write the code portably than to conditionalize it for various
|
5790 |
|
|
systems.
|
5791 |
|
|
|
5792 |
|
|
New `#ifdef''s which test for specific compilers or manufacturers or
|
5793 |
|
|
operating systems are unacceptable. All `#ifdef''s should test for
|
5794 |
|
|
features. The information about which configurations contain which
|
5795 |
|
|
features should be segregated into the configuration files. Experience
|
5796 |
|
|
has proven far too often that a feature unique to one particular system
|
5797 |
|
|
|
5798 |
|
|
predefined macro for your current system will become worthless over
|
5799 |
|
|
time, as new versions of your system come out that behave differently
|
5800 |
|
|
|
5801 |
|
|
|
5802 |
|
|
Adding code that handles specific architectures, operating systems,
|
5803 |
|
|
target interfaces, or hosts, is not acceptable in generic code.
|
5804 |
|
|
|
5805 |
|
|
One particularly notorious area where system dependencies tend to
|
5806 |
|
|
creep in is handling of file names. The mainline GDB code assumes
|
5807 |
|
|
Posix semantics of file names: absolute file names begin with a forward
|
5808 |
|
|
slash `/', slashes are used to separate leading directories,
|
5809 |
|
|
|
5810 |
|
|
on non-Posix systems such as MS-Windows. To avoid system-dependent
|
5811 |
|
|
code where you need to take apart or construct a file name, use the
|
5812 |
|
|
following portable macros:
|
5813 |
|
|
|
5814 |
|
|
`HAVE_DOS_BASED_FILE_SYSTEM'
|
5815 |
|
|
|
5816 |
|
|
whose filesystems belong to the MS-DOS/MS-Windows family. Use this
|
5817 |
|
|
symbol to write conditional code which should only be compiled for
|
5818 |
|
|
such hosts.
|
5819 |
|
|
|
5820 |
|
|
|
5821 |
|
|
Evaluates to a non-zero value if C is a directory separator
|
5822 |
|
|
character. On Unix and GNU/Linux systems, only a slash `/' is
|
5823 |
|
|
such a character, but on Windows, both `/' and `\' will pass.
|
5824 |
|
|
|
5825 |
|
|
`IS_ABSOLUTE_PATH (FILE)'
|
5826 |
|
|
|
5827 |
|
|
For Unix and GNU/Linux hosts, a name which begins with a slash `/'
|
5828 |
|
|
is absolute. On DOS and Windows, `d:/foo' and `x:\bar' are also
|
5829 |
|
|
absolute file names.
|
5830 |
|
|
|
5831 |
|
|
`FILENAME_CMP (F1, F2)'
|
5832 |
|
|
|
5833 |
|
|
appropriate for the underlying host filesystem. For Posix systems,
|
5834 |
|
|
this simply calls `strcmp'; on case-insensitive filesystems it
|
5835 |
|
|
will call `strcasecmp' instead.
|
5836 |
|
|
|
5837 |
|
|
|
5838 |
|
|
Evaluates to a character which separates directories in
|
5839 |
|
|
`PATH'-style lists, typically held in environment variables. This
|
5840 |
|
|
character is `:' on Unix, `;' on DOS and Windows.
|
5841 |
|
|
|
5842 |
|
|
`SLASH_STRING'
|
5843 |
|
|
|
5844 |
|
|
absolute filename from leading directories and the file's basename.
|
5845 |
|
|
`SLASH_STRING' is `"/"' on most systems, but might be `"\\"' for
|
5846 |
|
|
some Windows-based ports.
|
5847 |
|
|
|
5848 |
|
|
In addition to using these macros, be sure to use portable library
|
5849 |
|
|
|
5850 |
|
|
basename part from a file name, use the `dirname' and `basename'
|
5851 |
|
|
library functions (available in `libiberty' for platforms which don't
|
5852 |
|
|
provide them), instead of searching for a slash with `strrchr'.
|
5853 |
|
|
|
5854 |
|
|
Another way to generalize GDB along a particular interface is with an
|
5855 |
|
|
attribute struct. For example, GDB has been generalized to handle
|
5856 |
|
|
multiple kinds of remote interfaces--not by `#ifdef's everywhere, but
|
5857 |
|
|
by defining the `target_ops' structure and having a current target (as
|
5858 |
|
|
well as a stack of targets below it, for memory references). Whenever
|
5859 |
|
|
something needs to be done that depends on which remote interface we are
|
5860 |
|
|
using, a flag in the current target_ops structure is tested (e.g.,
|
5861 |
|
|
`target_has_stack'), or a function is called through a pointer in the
|
5862 |
|
|
current target_ops structure. In this way, when a new remote interface
|
5863 |
|
|
|
5864 |
|
|
implements the new remote interface. Other examples of
|
5865 |
|
|
attribute-structs are BFD access to multiple kinds of object file
|
5866 |
|
|
formats, or GDB's access to multiple source languages.
|
5867 |
|
|
|
5868 |
|
|
Please avoid duplicating code. For example, in GDB 3.x all the code
|
5869 |
|
|
interfacing between `ptrace' and the rest of GDB was duplicated in
|
5870 |
|
|
`*-dep.c', and so changing something was very painful. In GDB 4.x,
|
5871 |
|
|
|
5872 |
|
|
deal with variations between systems the same way any system-independent
|
5873 |
|
|
file would (hooks, `#if defined', etc.), and machines which are
|
5874 |
|
|
radically different don't need to use `infptrace.c' at all.
|
5875 |
|
|
|
5876 |
|
|
All debugging code must be controllable using the `set debug MODULE'
|
5877 |
|
|
command. Do not use `printf' to print trace messages. Use
|
5878 |
|
|
|
5879 |
|
|
|
5880 |
|
|
|
5881 |
|
|
|
5882 |
|
|
|
5883 |
|
|
17 Porting GDB
|
5884 |
|
|
**************
|
5885 |
|
|
|
5886 |
|
|
Most of the work in making GDB compile on a new machine is in
|
5887 |
|
|
specifying the configuration of the machine. Porting a new
|
5888 |
|
|
architecture to GDB can be broken into a number of steps.
|
5889 |
|
|
|
5890 |
|
|
* Ensure a BFD exists for executables of the target architecture in
|
5891 |
|
|
the `bfd' directory. If one does not exist, create one by
|
5892 |
|
|
|
5893 |
|
|
|
5894 |
|
|
* Implement a disassembler for the target architecture in the
|
5895 |
|
|
`opcodes' directory.
|
5896 |
|
|
|
5897 |
|
|
* Define the target architecture in the `gdb' directory (*note
|
5898 |
|
|
|
5899 |
|
|
the new target to `configure.tgt' with the names of the files that
|
5900 |
|
|
contain the code. By convention the target architecture
|
5901 |
|
|
definition for an architecture ARCH is placed in `ARCH-tdep.c'.
|
5902 |
|
|
|
5903 |
|
|
Within `ARCH-tdep.c' define the function `_initialize_ARCH_tdep'
|
5904 |
|
|
which calls `gdbarch_register' to create the new `struct gdbarch'
|
5905 |
|
|
for the architecture.
|
5906 |
|
|
|
5907 |
|
|
* If a new remote target is needed, consider adding a new remote
|
5908 |
|
|
|
5909 |
|
|
if at all possible use the GDB _Remote Serial Protocol_ for this
|
5910 |
|
|
and implement the server side protocol independently with the
|
5911 |
|
|
target.
|
5912 |
|
|
|
5913 |
|
|
* If desired implement a simulator in the `sim' directory. This
|
5914 |
|
|
should create the library `libsim.a' implementing the interface in
|
5915 |
|
|
|
5916 |
|
|
|
5917 |
|
|
* Build and test. If desired, lobby the GDB steering group to have
|
5918 |
|
|
the new port included in the main distribution!
|
5919 |
|
|
|
5920 |
|
|
|
5921 |
|
|
guide (*note Configuration Specific Information:
|
5922 |
|
|
(gdb)Configuration Specific Information.).
|
5923 |
|
|
|
5924 |
|
|
|
5925 |
|
|
|
5926 |
|
|
|
5927 |
|
|
|
5928 |
|
|
18 Versions and Branches
|
5929 |
|
|
|
5930 |
|
|
|
5931 |
|
|
18.1 Versions
|
5932 |
|
|
|
5933 |
|
|
|
5934 |
|
|
GDB's version is determined by the file `gdb/version.in' and takes one
|
5935 |
|
|
of the following forms:
|
5936 |
|
|
|
5937 |
|
|
MAJOR.MINOR
|
5938 |
|
|
MAJOR.MINOR.PATCHLEVEL
|
5939 |
|
|
an official release (e.g., 6.2 or 6.2.1)
|
5940 |
|
|
|
5941 |
|
|
MAJOR.MINOR.PATCHLEVEL.YYYYMMDD
|
5942 |
|
|
a snapshot taken at YYYY-MM-DD-gmt (e.g., 6.1.50.20020302,
|
5943 |
|
|
6.1.90.20020304, or 6.1.0.20020308)
|
5944 |
|
|
|
5945 |
|
|
MAJOR.MINOR.PATCHLEVEL.YYYYMMDD-cvs
|
5946 |
|
|
a CVS check out drawn on YYYY-MM-DD (e.g., 6.1.50.20020302-cvs,
|
5947 |
|
|
6.1.90.20020304-cvs, or 6.1.0.20020308-cvs)
|
5948 |
|
|
|
5949 |
|
|
MAJOR.MINOR.PATCHLEVEL.YYYYMMDD (VENDOR)
|
5950 |
|
|
a vendor specific release of GDB, that while based on
|
5951 |
|
|
MAJOR.MINOR.PATCHLEVEL.YYYYMMDD, may include additional changes
|
5952 |
|
|
|
5953 |
|
|
|
5954 |
|
|
most recent release branch, with a PATCHLEVEL of 50. At the time each
|
5955 |
|
|
new release branch is created, the mainline's MAJOR and MINOR version
|
5956 |
|
|
numbers are updated.
|
5957 |
|
|
|
5958 |
|
|
GDB's release branch is similar. When the branch is cut, the
|
5959 |
|
|
|
5960 |
|
|
the branch, the PATCHLEVEL is incremented. Once the first release
|
5961 |
|
|
(MAJOR.MINOR) has been made, the PATCHLEVEL is set to 0 and updates
|
5962 |
|
|
|
5963 |
|
|
|
5964 |
|
|
For snapshots, and CVS check outs, it is also possible to identify
|
5965 |
|
|
|
5966 |
|
|
|
5967 |
|
|
MAJOR.MINOR.50.YYYYMMDD
|
5968 |
|
|
drawn from the HEAD of mainline CVS (e.g., 6.1.50.20020302)
|
5969 |
|
|
|
5970 |
|
|
|
5971 |
|
|
MAJOR.MINOR.91.YYYYMMDD ...
|
5972 |
|
|
drawn from a release branch prior to the release (e.g.,
|
5973 |
|
|
6.1.90.20020304)
|
5974 |
|
|
|
5975 |
|
|
|
5976 |
|
|
MAJOR.MINOR.1.YYYYMMDD ...
|
5977 |
|
|
drawn from a release branch after the release (e.g.,
|
5978 |
|
|
6.2.0.20020308)
|
5979 |
|
|
|
5980 |
|
|
If the previous GDB version is 6.1 and the current version is 6.2,
|
5981 |
|
|
then, substituting 6 for MAJOR and 1 or 2 for MINOR, here's an
|
5982 |
|
|
illustration of a typical sequence:
|
5983 |
|
|
|
5984 |
|
|
|
5985 |
|
|
|
|
5986 |
|
|
6.1.50.20020302-cvs
|
5987 |
|
|
|
|
5988 |
|
|
+--------------------------.
|
5989 |
|
|
|
|
5990 |
|
|
| |
|
5991 |
|
|
6.2.50.20020303-cvs 6.1.90 (draft #1)
|
5992 |
|
|
| |
|
5993 |
|
|
6.2.50.20020304-cvs 6.1.90.20020304-cvs
|
5994 |
|
|
| |
|
5995 |
|
|
6.2.50.20020305-cvs 6.1.91 (draft #2)
|
5996 |
|
|
| |
|
5997 |
|
|
6.2.50.20020306-cvs 6.1.91.20020306-cvs
|
5998 |
|
|
| |
|
5999 |
|
|
6.2.50.20020307-cvs 6.2 (release)
|
6000 |
|
|
| |
|
6001 |
|
|
6.2.50.20020308-cvs 6.2.0.20020308-cvs
|
6002 |
|
|
| |
|
6003 |
|
|
6.2.50.20020309-cvs 6.2.1 (update)
|
6004 |
|
|
| |
|
6005 |
|
|
6.2.50.20020310-cvs
|
6006 |
|
|
|
|
6007 |
|
|
6.2.50.20020311-cvs
|
6008 |
|
|
|
|
6009 |
|
|
+--------------------------.
|
6010 |
|
|
|
6011 |
|
|
| |
|
6012 |
|
|
6.3.50.20020312-cvs 6.2.90 (draft #1)
|
6013 |
|
|
|
6014 |
|
|
|
6015 |
|
|
18.2 Release Branches
|
6016 |
|
|
|
6017 |
|
|
|
6018 |
|
|
GDB draws a release series (6.2, 6.2.1, ...) from a single release
|
6019 |
|
|
branch, and identifies that branch using the CVS branch tags:
|
6020 |
|
|
|
6021 |
|
|
gdb_MAJOR_MINOR-YYYYMMDD-branchpoint
|
6022 |
|
|
gdb_MAJOR_MINOR-branch
|
6023 |
|
|
gdb_MAJOR_MINOR-YYYYMMDD-release
|
6024 |
|
|
|
6025 |
|
|
|
6026 |
|
|
is made, both the branchpoint and release tags include the date that
|
6027 |
|
|
they are cut (YYYYMMDD) in the tag. The branch tag, denoting the head
|
6028 |
|
|
|
6029 |
|
|
|
6030 |
|
|
18.3 Vendor Branches
|
6031 |
|
|
====================
|
6032 |
|
|
|
6033 |
|
|
|
6034 |
|
|
`gdb/version.in' to include a vendor unique alphabetic identifier (an
|
6035 |
|
|
official GDB release never uses alphabetic characters in its version
|
6036 |
|
|
|
6037 |
|
|
|
6038 |
|
|
18.4 Experimental Branches
|
6039 |
|
|
|
6040 |
|
|
|
6041 |
|
|
18.4.1 Guidelines
|
6042 |
|
|
-----------------
|
6043 |
|
|
|
6044 |
|
|
|
6045 |
|
|
experimental development. Branches make it possible for developers to
|
6046 |
|
|
|
6047 |
|
|
developments.
|
6048 |
|
|
|
6049 |
|
|
The following are a set of guidelines for creating such branches:
|
6050 |
|
|
|
6051 |
|
|
|
6052 |
|
|
The owner can set further policy for a branch, but may not change
|
6053 |
|
|
the ground rules. In particular, they can set a policy for
|
6054 |
|
|
commits (be it adding more reviewers or deciding who can commit).
|
6055 |
|
|
|
6056 |
|
|
_all commits are posted_
|
6057 |
|
|
|
6058 |
|
|
patches mailing list . While
|
6059 |
|
|
commentary on such changes are encouraged, people should remember
|
6060 |
|
|
that the changes only apply to a branch.
|
6061 |
|
|
|
6062 |
|
|
|
6063 |
|
|
This ensures that all changes belong to the Free Software
|
6064 |
|
|
Foundation, and avoids the possibility that the branch may become
|
6065 |
|
|
contaminated.
|
6066 |
|
|
|
6067 |
|
|
|
6068 |
|
|
A focused branch has a single objective or goal, and does not
|
6069 |
|
|
contain unnecessary or irrelevant changes. Cleanups, where
|
6070 |
|
|
identified, being be pushed into the mainline as soon as possible.
|
6071 |
|
|
|
6072 |
|
|
|
6073 |
|
|
This keeps the level of divergence under control. It also keeps
|
6074 |
|
|
the pressure on developers to push cleanups and other stuff into
|
6075 |
|
|
the mainline.
|
6076 |
|
|
|
6077 |
|
|
_a branch shall contain the entire GDB module_
|
6078 |
|
|
The GDB module `gdb' should be specified when creating a branch
|
6079 |
|
|
(branches of individual files should be avoided). *Note Tags::.
|
6080 |
|
|
|
6081 |
|
|
|
6082 |
|
|
|
6083 |
|
|
the branch OWNER and branch NAME, e.g.,
|
6084 |
|
|
`6.2.50.20030303_owner_name' or `6.2 (Owner Name)'.
|
6085 |
|
|
|
6086 |
|
|
|
6087 |
|
|
18.4.2 Tags
|
6088 |
|
|
|
6089 |
|
|
|
6090 |
|
|
To simplify the identification of GDB branches, the following branch
|
6091 |
|
|
tagging convention is strongly recommended:
|
6092 |
|
|
|
6093 |
|
|
`OWNER_NAME-YYYYMMDD-branchpoint'
|
6094 |
|
|
`OWNER_NAME-YYYYMMDD-branch'
|
6095 |
|
|
The branch point and corresponding branch tag. YYYYMMDD is the
|
6096 |
|
|
date that the branch was created. A branch is created using the
|
6097 |
|
|
|
6098 |
|
|
cvs rtag OWNER_NAME-YYYYMMDD-branchpoint gdb
|
6099 |
|
|
cvs rtag -b -r OWNER_NAME-YYYYMMDD-branchpoint \
|
6100 |
|
|
OWNER_NAME-YYYYMMDD-branch gdb
|
6101 |
|
|
|
6102 |
|
|
`OWNER_NAME-YYYYMMDD-mergepoint'
|
6103 |
|
|
The tagged point, on the mainline, that was used when merging the
|
6104 |
|
|
branch on YYYYMMDD. To merge in all changes since the branch was
|
6105 |
|
|
cut, use a command sequence like:
|
6106 |
|
|
cvs rtag OWNER_NAME-YYYYMMDD-mergepoint gdb
|
6107 |
|
|
cvs update \
|
6108 |
|
|
|
6109 |
|
|
|
6110 |
|
|
Similar sequences can be used to just merge in changes since the
|
6111 |
|
|
last merge.
|
6112 |
|
|
|
6113 |
|
|
|
6114 |
|
|
For further information on CVS, see Concurrent Versions System
|
6115 |
|
|
|
6116 |
|
|
|
6117 |
|
|
|
6118 |
|
|
|
6119 |
|
|
|
6120 |
|
|
19 Start of New Year Procedure
|
6121 |
|
|
|
6122 |
|
|
|
6123 |
|
|
|
6124 |
|
|
performed:
|
6125 |
|
|
|
6126 |
|
|
* Rotate the ChangeLog file
|
6127 |
|
|
|
6128 |
|
|
The current `ChangeLog' file should be renamed into
|
6129 |
|
|
`ChangeLog-YYYY' where YYYY is the year that has just passed. A
|
6130 |
|
|
new `ChangeLog' file should be created, and its contents should
|
6131 |
|
|
contain a reference to the previous ChangeLog. The following
|
6132 |
|
|
should also be preserved at the end of the new ChangeLog, in order
|
6133 |
|
|
to provide the appropriate settings when editing this file with
|
6134 |
|
|
Emacs:
|
6135 |
|
|
Local Variables:
|
6136 |
|
|
mode: change-log
|
6137 |
|
|
left-margin: 8
|
6138 |
|
|
|
6139 |
|
|
version-control: never
|
6140 |
|
|
coding: utf-8
|
6141 |
|
|
|
6142 |
|
|
|
6143 |
|
|
|
6144 |
|
|
(`ChangeLog-YYYY') in `gdb/config/djgpp/fnchange.lst'.
|
6145 |
|
|
|
6146 |
|
|
|
6147 |
|
|
|
6148 |
|
|
|
6149 |
|
|
* file `top.c', function `print_gdb_version'
|
6150 |
|
|
|
6151 |
|
|
* file `gdbserver/server.c', function `gdbserver_version'
|
6152 |
|
|
|
6153 |
|
|
* file `gdbserver/gdbreplay.c', function `gdbreplay_version'
|
6154 |
|
|
|
6155 |
|
|
* Run the `copyright.sh' script to add the new year in the copyright
|
6156 |
|
|
notices of most source files. This script requires Emacs 22 or
|
6157 |
|
|
later to be installed.
|
6158 |
|
|
|
6159 |
|
|
* The new year also needs to be added manually in all other files
|
6160 |
|
|
|
6161 |
|
|
* `*.s'
|
6162 |
|
|
|
6163 |
|
|
* `*.f'
|
6164 |
|
|
|
6165 |
|
|
* `*.f90'
|
6166 |
|
|
|
6167 |
|
|
* `*.igen'
|
6168 |
|
|
|
6169 |
|
|
* `*.ac'
|
6170 |
|
|
|
6171 |
|
|
* `*.texi'
|
6172 |
|
|
|
6173 |
|
|
* `*.texinfo'
|
6174 |
|
|
|
6175 |
|
|
* `*.tex'
|
6176 |
|
|
|
6177 |
|
|
|
6178 |
|
|
|
6179 |
|
|
* `*.1'
|
6180 |
|
|
|
6181 |
|
|
|
6182 |
|
|
|
6183 |
|
|
|
6184 |
|
|
|
6185 |
|
|
20 Releasing GDB
|
6186 |
|
|
|
6187 |
|
|
|
6188 |
|
|
20.1 Branch Commit Policy
|
6189 |
|
|
|
6190 |
|
|
|
6191 |
|
|
|
6192 |
|
|
5.2 all used the below:
|
6193 |
|
|
|
6194 |
|
|
* The `gdb/MAINTAINERS' file still holds.
|
6195 |
|
|
|
6196 |
|
|
* Don't fix something on the branch unless/until it is also fixed in
|
6197 |
|
|
the trunk. If this isn't possible, mentioning it in the
|
6198 |
|
|
`gdb/PROBLEMS' file is better than committing a hack.
|
6199 |
|
|
|
6200 |
|
|
* When considering a patch for the branch, suggested criteria
|
6201 |
|
|
include: Does it fix a build? Does it fix the sequence `break
|
6202 |
|
|
|
6203 |
|
|
|
6204 |
|
|
* The further a change is from the core of GDB, the less likely the
|
6205 |
|
|
change will worry anyone (e.g., target specific code).
|
6206 |
|
|
|
6207 |
|
|
* Only post a proposal to change the core of GDB after you've sent
|
6208 |
|
|
individual bribes to all the people listed in the `MAINTAINERS'
|
6209 |
|
|
file ;-)
|
6210 |
|
|
|
6211 |
|
|
|
6212 |
|
|
functionality there is little chance that a broken change will be fatal.
|
6213 |
|
|
This means that changes such as adding a new architectures or (within
|
6214 |
|
|
|
6215 |
|
|
|
6216 |
|
|
20.2 Obsoleting code
|
6217 |
|
|
====================
|
6218 |
|
|
|
6219 |
|
|
Before anything else, poke the other developers (and around the source
|
6220 |
|
|
code) to see if there is anything that can be removed from GDB (an old
|
6221 |
|
|
target, an unused file).
|
6222 |
|
|
|
6223 |
|
|
Obsolete code is identified by adding an `OBSOLETE' prefix to every
|
6224 |
|
|
line. Doing this means that it is easy to identify something that has
|
6225 |
|
|
been obsoleted when greping through the sources.
|
6226 |
|
|
|
6227 |
|
|
The process is done in stages -- this is mainly to ensure that the
|
6228 |
|
|
wider GDB community has a reasonable opportunity to respond. Remember,
|
6229 |
|
|
everything on the Internet takes a week.
|
6230 |
|
|
|
6231 |
|
|
1. Post the proposal on the GDB mailing list
|
6232 |
|
|
|
6233 |
|
|
recommended.
|
6234 |
|
|
|
6235 |
|
|
|
6236 |
|
|
|
6237 |
|
|
|
6238 |
|
|
.
|
6239 |
|
|
|
6240 |
|
|
|
6241 |
|
|
|
6242 |
|
|
5. Go through and edit all relevant files and lines so that they are
|
6243 |
|
|
|
6244 |
|
|
|
6245 |
|
|
|
6246 |
|
|
has been released.
|
6247 |
|
|
|
6248 |
|
|
7. Remove the obsolete code.
|
6249 |
|
|
|
6250 |
|
|
_Maintainer note: While removing old code is regrettable it is
|
6251 |
|
|
hopefully better for GDB's long term development. Firstly it helps the
|
6252 |
|
|
|
6253 |
|
|
wrong. Secondly since it removes any history associated with the file
|
6254 |
|
|
(effectively clearing the slate) the developer has a much freer hand
|
6255 |
|
|
|
6256 |
|
|
|
6257 |
|
|
20.3 Before the Branch
|
6258 |
|
|
======================
|
6259 |
|
|
|
6260 |
|
|
|
6261 |
|
|
changes that become a pain to track once the branch is created. For
|
6262 |
|
|
instance, configuration problems that stop GDB from even building. If
|
6263 |
|
|
|
6264 |
|
|
|
6265 |
|
|
Prompt for `gdb/NEWS'
|
6266 |
|
|
---------------------
|
6267 |
|
|
|
6268 |
|
|
People always forget. Send a post reminding them but also if you know
|
6269 |
|
|
something interesting happened add it yourself. The `schedule' script
|
6270 |
|
|
|
6271 |
|
|
|
6272 |
|
|
Review `gdb/README'
|
6273 |
|
|
-------------------
|
6274 |
|
|
|
6275 |
|
|
Grab one of the nightly snapshots and then walk through the
|
6276 |
|
|
`gdb/README' looking for anything that can be improved. The `schedule'
|
6277 |
|
|
|
6278 |
|
|
|
6279 |
|
|
|
6280 |
|
|
---------------------------
|
6281 |
|
|
|
6282 |
|
|
A number of files are taken from external repositories. They include:
|
6283 |
|
|
|
6284 |
|
|
* `texinfo/texinfo.tex'
|
6285 |
|
|
|
6286 |
|
|
* `config.guess' et. al. (see the top-level `MAINTAINERS' file)
|
6287 |
|
|
|
6288 |
|
|
|
6289 |
|
|
|
6290 |
|
|
Check the ARI
|
6291 |
|
|
-------------
|
6292 |
|
|
|
6293 |
|
|
|
6294 |
|
|
number of errors and coding conventions. The checks include things
|
6295 |
|
|
like using `malloc' instead of `xmalloc' and file naming problems.
|
6296 |
|
|
|
6297 |
|
|
|
6298 |
|
|
|
6299 |
|
|
-------------------------------
|
6300 |
|
|
|
6301 |
|
|
|
6302 |
|
|
|
6303 |
|
|
|
6304 |
|
|
------------------------------------
|
6305 |
|
|
|
6306 |
|
|
|
6307 |
|
|
|
6308 |
|
|
20.4 Cut the Branch
|
6309 |
|
|
|
6310 |
|
|
|
6311 |
|
|
Create the branch
|
6312 |
|
|
-----------------
|
6313 |
|
|
|
6314 |
|
|
$ u=5.1
|
6315 |
|
|
$ v=5.2
|
6316 |
|
|
$ V=`echo $v | sed 's/\./_/g'`
|
6317 |
|
|
$ D=`date -u +%Y-%m-%d`
|
6318 |
|
|
$ echo $u $V $D
|
6319 |
|
|
5.1 5_2 2002-03-03
|
6320 |
|
|
$ echo cvs -f -d :ext:sourceware.org:/cvs/src rtag \
|
6321 |
|
|
-D $D-gmt gdb_$V-$D-branchpoint insight
|
6322 |
|
|
cvs -f -d :ext:sourceware.org:/cvs/src rtag
|
6323 |
|
|
-D 2002-03-03-gmt gdb_5_2-2002-03-03-branchpoint insight
|
6324 |
|
|
$ ^echo ^^
|
6325 |
|
|
...
|
6326 |
|
|
$ echo cvs -f -d :ext:sourceware.org:/cvs/src rtag \
|
6327 |
|
|
-b -r gdb_$V-$D-branchpoint gdb_$V-branch insight
|
6328 |
|
|
cvs -f -d :ext:sourceware.org:/cvs/src rtag \
|
6329 |
|
|
|
6330 |
|
|
$ ^echo ^^
|
6331 |
|
|
...
|
6332 |
|
|
|
6333 |
|
|
|
6334 |
|
|
* By using `-D YYYY-MM-DD-gmt', the branch is forced to an exact
|
6335 |
|
|
|
6336 |
|
|
|
6337 |
|
|
|
6338 |
|
|
found.
|
6339 |
|
|
|
6340 |
|
|
* Insight, which includes GDB, is tagged at the same time.
|
6341 |
|
|
|
6342 |
|
|
* `version.in' gets bumped to avoid version number conflicts.
|
6343 |
|
|
|
6344 |
|
|
|
6345 |
|
|
|
6346 |
|
|
Update `version.in'
|
6347 |
|
|
-------------------
|
6348 |
|
|
|
6349 |
|
|
$ u=5.1
|
6350 |
|
|
$ v=5.2
|
6351 |
|
|
$ V=`echo $v | sed 's/\./_/g'`
|
6352 |
|
|
$ echo $u $v$V
|
6353 |
|
|
5.1 5_2
|
6354 |
|
|
$ cd /tmp
|
6355 |
|
|
$ echo cvs -f -d :ext:sourceware.org:/cvs/src co \
|
6356 |
|
|
-r gdb_$V-branch src/gdb/version.in
|
6357 |
|
|
cvs -f -d :ext:sourceware.org:/cvs/src co
|
6358 |
|
|
-r gdb_5_2-branch src/gdb/version.in
|
6359 |
|
|
$ ^echo ^^
|
6360 |
|
|
U src/gdb/version.in
|
6361 |
|
|
$ cd src/gdb
|
6362 |
|
|
|
6363 |
|
|
$ cat version.in
|
6364 |
|
|
5.1.90-0000-00-00-cvs
|
6365 |
|
|
|
6366 |
|
|
|
6367 |
|
|
* `0000-00-00' is used as a date to pump prime the version.in update
|
6368 |
|
|
|
6369 |
|
|
|
6370 |
|
|
* `.90' and the previous branch version are used as fairly arbitrary
|
6371 |
|
|
|
6372 |
|
|
|
6373 |
|
|
|
6374 |
|
|
-----------------------------
|
6375 |
|
|
|
6376 |
|
|
|
6377 |
|
|
|
6378 |
|
|
Tweak cron to track the new branch
|
6379 |
|
|
|
6380 |
|
|
|
6381 |
|
|
|
6382 |
|
|
file needs to be updated so that:
|
6383 |
|
|
|
6384 |
|
|
* A daily timestamp is added to the file `version.in'.
|
6385 |
|
|
|
6386 |
|
|
|
6387 |
|
|
|
6388 |
|
|
See the file `gdbadmin/cron/README' for how to install the updated cron
|
6389 |
|
|
table.
|
6390 |
|
|
|
6391 |
|
|
The file `gdbadmin/ss/README' should also be reviewed to reflect any
|
6392 |
|
|
changes. That file is copied to both the branch/ and current/ snapshot
|
6393 |
|
|
|
6394 |
|
|
|
6395 |
|
|
Update the NEWS and README files
|
6396 |
|
|
--------------------------------
|
6397 |
|
|
|
6398 |
|
|
The `NEWS' file needs to be updated so that on the branch it refers to
|
6399 |
|
|
_changes in the current release_ while on the trunk it also refers to
|
6400 |
|
|
|
6401 |
|
|
|
6402 |
|
|
The `README' file needs to be updated so that it refers to the
|
6403 |
|
|
|
6404 |
|
|
|
6405 |
|
|
|
6406 |
|
|
--------------------
|
6407 |
|
|
|
6408 |
|
|
Send an announcement to the mailing lists:
|
6409 |
|
|
|
6410 |
|
|
|
6411 |
|
|
|
6412 |
|
|
* GDB Discussion mailing list and GDB Testers
|
6413 |
|
|
mailing list
|
6414 |
|
|
|
6415 |
|
|
_Pragmatics: The branch creation is sent to the announce list to
|
6416 |
|
|
|
6417 |
|
|
list are alerted._
|
6418 |
|
|
|
6419 |
|
|
The announcement should include:
|
6420 |
|
|
|
6421 |
|
|
* The branch tag.
|
6422 |
|
|
|
6423 |
|
|
* How to check out the branch using CVS.
|
6424 |
|
|
|
6425 |
|
|
* The date/number of weeks until the release.
|
6426 |
|
|
|
6427 |
|
|
|
6428 |
|
|
|
6429 |
|
|
|
6430 |
|
|
=========================
|
6431 |
|
|
|
6432 |
|
|
|
6433 |
|
|
|
6434 |
|
|
20.6 Create a Release
|
6435 |
|
|
=====================
|
6436 |
|
|
|
6437 |
|
|
|
6438 |
|
|
down into a number of stages. The first part addresses the technical
|
6439 |
|
|
|
6440 |
|
|
process of releasing that tar ball.
|
6441 |
|
|
|
6442 |
|
|
|
6443 |
|
|
|
6444 |
|
|
20.6.1 Create a release candidate
|
6445 |
|
|
---------------------------------
|
6446 |
|
|
|
6447 |
|
|
The objective at this stage is to create a set of tar balls that can be
|
6448 |
|
|
made available as a formal release (or as a less formal release
|
6449 |
|
|
|
6450 |
|
|
|
6451 |
|
|
Freeze the branch
|
6452 |
|
|
|
6453 |
|
|
|
6454 |
|
|
Send out an e-mail notifying everyone that the branch is frozen to
|
6455 |
|
|
|
6456 |
|
|
|
6457 |
|
|
Establish a few defaults.
|
6458 |
|
|
.........................
|
6459 |
|
|
|
6460 |
|
|
$ b=gdb_5_2-branch
|
6461 |
|
|
$ v=5.2
|
6462 |
|
|
$ t=/sourceware/snapshot-tmp/gdbadmin-tmp
|
6463 |
|
|
$ echo $t/$b/$v
|
6464 |
|
|
/sourceware/snapshot-tmp/gdbadmin-tmp/gdb_5_2-branch/5.2
|
6465 |
|
|
$ mkdir -p $t/$b/$v
|
6466 |
|
|
$ cd $t/$b/$v
|
6467 |
|
|
$ pwd
|
6468 |
|
|
|
6469 |
|
|
$ which autoconf
|
6470 |
|
|
|
6471 |
|
|
$
|
6472 |
|
|
|
6473 |
|
|
Notes:
|
6474 |
|
|
|
6475 |
|
|
|
6476 |
|
|
version documented in the toplevel `README-maintainer-mode' file.
|
6477 |
|
|
It is very unlikely that the version of `autoconf' installed in
|
6478 |
|
|
|
6479 |
|
|
|
6480 |
|
|
Check out the relevant modules:
|
6481 |
|
|
...............................
|
6482 |
|
|
|
6483 |
|
|
$ for m in gdb insight
|
6484 |
|
|
|
6485 |
|
|
( mkdir -p $m && cd $m && cvs -q -f -d /cvs/src co -P -r $b $m )
|
6486 |
|
|
|
6487 |
|
|
$
|
6488 |
|
|
|
6489 |
|
|
Note:
|
6490 |
|
|
|
6491 |
|
|
* The reading of `.cvsrc' is disabled (`-f') so that there isn't any
|
6492 |
|
|
confusion between what is written here and what your local `cvs'
|
6493 |
|
|
|
6494 |
|
|
|
6495 |
|
|
Update relevant files.
|
6496 |
|
|
......................
|
6497 |
|
|
|
6498 |
|
|
|
6499 |
|
|
Major releases get their comments added as part of the mainline.
|
6500 |
|
|
|
6501 |
|
|
were fixed.
|
6502 |
|
|
|
6503 |
|
|
Don't forget to include the `ChangeLog' entry.
|
6504 |
|
|
|
6505 |
|
|
$ emacs gdb/src/gdb/NEWS
|
6506 |
|
|
...
|
6507 |
|
|
c-x 4 a
|
6508 |
|
|
|
6509 |
|
|
c-x c-s c-x c-c
|
6510 |
|
|
$ cp gdb/src/gdb/NEWS insight/src/gdb/NEWS
|
6511 |
|
|
|
6512 |
|
|
|
6513 |
|
|
|
6514 |
|
|
You'll need to update:
|
6515 |
|
|
|
6516 |
|
|
* The version.
|
6517 |
|
|
|
6518 |
|
|
* The update date.
|
6519 |
|
|
|
6520 |
|
|
* Who did it.
|
6521 |
|
|
|
6522 |
|
|
$ emacs gdb/src/gdb/README
|
6523 |
|
|
...
|
6524 |
|
|
c-x 4 a
|
6525 |
|
|
|
6526 |
|
|
c-x c-s c-x c-c
|
6527 |
|
|
$ cp gdb/src/gdb/README insight/src/gdb/README
|
6528 |
|
|
$ cp gdb/src/gdb/ChangeLog insight/src/gdb/ChangeLog
|
6529 |
|
|
|
6530 |
|
|
_Maintainer note: Hopefully the `README' file was reviewed before
|
6531 |
|
|
the initial branch was cut so just a simple substitute is needed
|
6532 |
|
|
|
6533 |
|
|
|
6534 |
|
|
_Maintainer note: Other projects generate `README' and `INSTALL'
|
6535 |
|
|
from the core documentation. This might be worth pursuing._
|
6536 |
|
|
|
6537 |
|
|
`gdb/version.in'
|
6538 |
|
|
$ echo $v > gdb/src/gdb/version.in
|
6539 |
|
|
$ cat gdb/src/gdb/version.in
|
6540 |
|
|
5.2
|
6541 |
|
|
$ emacs gdb/src/gdb/version.in
|
6542 |
|
|
...
|
6543 |
|
|
c-x 4 a
|
6544 |
|
|
|
6545 |
|
|
|
6546 |
|
|
$ cp gdb/src/gdb/version.in insight/src/gdb/version.in
|
6547 |
|
|
$ cp gdb/src/gdb/ChangeLog insight/src/gdb/ChangeLog
|
6548 |
|
|
|
6549 |
|
|
|
6550 |
|
|
|
6551 |
|
|
.................
|
6552 |
|
|
|
6553 |
|
|
This is identical to the process used to create the daily snapshot.
|
6554 |
|
|
|
6555 |
|
|
|
6556 |
|
|
do
|
6557 |
|
|
( cd $m/src && gmake -f src-release $m.tar )
|
6558 |
|
|
|
6559 |
|
|
|
6560 |
|
|
If the top level source directory does not have `src-release' (GDB
|
6561 |
|
|
version 5.3.1 or earlier), try these commands instead:
|
6562 |
|
|
|
6563 |
|
|
|
6564 |
|
|
do
|
6565 |
|
|
( cd $m/src && gmake -f Makefile.in $m.tar )
|
6566 |
|
|
|
6567 |
|
|
|
6568 |
|
|
Check the source files
|
6569 |
|
|
......................
|
6570 |
|
|
|
6571 |
|
|
You're looking for files that have mysteriously disappeared.
|
6572 |
|
|
`distclean' has the habit of deleting files it shouldn't. Watch out
|
6573 |
|
|
for the `version.in' update `cronjob'.
|
6574 |
|
|
|
6575 |
|
|
$ ( cd gdb/src && cvs -f -q -n update )
|
6576 |
|
|
M djunpack.bat
|
6577 |
|
|
? gdb-5.1.91.tar
|
6578 |
|
|
? proto-toplev
|
6579 |
|
|
... lots of generated files ...
|
6580 |
|
|
M gdb/ChangeLog
|
6581 |
|
|
M gdb/NEWS
|
6582 |
|
|
|
6583 |
|
|
M gdb/version.in
|
6584 |
|
|
... lots of generated files ...
|
6585 |
|
|
$
|
6586 |
|
|
|
6587 |
|
|
|
6588 |
|
|
generated (and yes `gdb.info-1' was also generated only something
|
6589 |
|
|
strange with CVS means that they didn't get suppressed). Fixing it
|
6590 |
|
|
|
6591 |
|
|
|
6592 |
|
|
Create compressed versions of the release
|
6593 |
|
|
.........................................
|
6594 |
|
|
|
6595 |
|
|
$ cp */src/*.tar .
|
6596 |
|
|
$ cp */src/*.bz2 .
|
6597 |
|
|
$ ls -F
|
6598 |
|
|
gdb/ gdb-5.2.tar insight/ insight-5.2.tar
|
6599 |
|
|
$ for m in gdb insight
|
6600 |
|
|
do
|
6601 |
|
|
|
6602 |
|
|
gzip -v -9 -c $m-$v.tar > $m-$v.tar.gz
|
6603 |
|
|
|
6604 |
|
|
$
|
6605 |
|
|
|
6606 |
|
|
Note:
|
6607 |
|
|
|
6608 |
|
|
|
6609 |
|
|
in that mode, `gzip' does not know the name of the file and, hence,
|
6610 |
|
|
can not include it in the compressed file. This is also why the
|
6611 |
|
|
|
6612 |
|
|
|
6613 |
|
|
|
6614 |
|
|
--------------------------------
|
6615 |
|
|
|
6616 |
|
|
Pick a popular machine (Solaris/PPC?) and try the build on that.
|
6617 |
|
|
|
6618 |
|
|
$ bunzip2 < gdb-5.2.tar.bz2 | tar xpf -
|
6619 |
|
|
$ cd gdb-5.2
|
6620 |
|
|
$ ./configure
|
6621 |
|
|
$ make
|
6622 |
|
|
...
|
6623 |
|
|
$ ./gdb/gdb ./gdb/gdb
|
6624 |
|
|
GNU gdb 5.2
|
6625 |
|
|
...
|
6626 |
|
|
|
6627 |
|
|
Breakpoint 1 at 0x80732bc: file main.c, line 734.
|
6628 |
|
|
(gdb) run
|
6629 |
|
|
Starting program: /tmp/gdb-5.2/gdb/gdb
|
6630 |
|
|
|
6631 |
|
|
Breakpoint 1, main (argc=1, argv=0xbffff8b4) at main.c:734
|
6632 |
|
|
|
6633 |
|
|
(gdb) print args
|
6634 |
|
|
$1 = {argc = 136426532, argv = 0x821b7f0}
|
6635 |
|
|
|
6636 |
|
|
|
6637 |
|
|
|
6638 |
|
|
-----------------------------------------
|
6639 |
|
|
|
6640 |
|
|
If this is a release candidate then the only remaining steps are:
|
6641 |
|
|
|
6642 |
|
|
|
6643 |
|
|
|
6644 |
|
|
2. Tweak `version.in' (and `ChangeLog' to read L.M.N-0000-00-00-cvs
|
6645 |
|
|
|
6646 |
|
|
|
6647 |
|
|
3. Make the release candidate available in
|
6648 |
|
|
|
6649 |
|
|
|
6650 |
|
|
4. Notify the relevant mailing lists ( and
|
6651 |
|
|
|
6652 |
|
|
|
6653 |
|
|
|
6654 |
|
|
--------------------------------------
|
6655 |
|
|
|
6656 |
|
|
|
6657 |
|
|
|
6658 |
|
|
|
6659 |
|
|
................
|
6660 |
|
|
|
6661 |
|
|
|
6662 |
|
|
|
6663 |
|
|
$ cp *.bz2 *.gz ~ftp/pub/gdb/old-releases/
|
6664 |
|
|
|
6665 |
|
|
|
6666 |
|
|
Clean up the releases directory so that only the most recent releases
|
6667 |
|
|
|
6668 |
|
|
|
6669 |
|
|
|
6670 |
|
|
$ rm ...
|
6671 |
|
|
|
6672 |
|
|
Update the file `README' and `.message' in the releases directory:
|
6673 |
|
|
|
6674 |
|
|
|
6675 |
|
|
...
|
6676 |
|
|
$ rm -f .message
|
6677 |
|
|
|
6678 |
|
|
|
6679 |
|
|
Update the web pages.
|
6680 |
|
|
.....................
|
6681 |
|
|
|
6682 |
|
|
`htdocs/download/ANNOUNCEMENT'
|
6683 |
|
|
This file, which is posted as the official announcement, includes:
|
6684 |
|
|
|
6685 |
|
|
|
6686 |
|
|
|
6687 |
|
|
earlier M.N release.
|
6688 |
|
|
|
6689 |
|
|
* Errata.
|
6690 |
|
|
|
6691 |
|
|
`htdocs/index.html'
|
6692 |
|
|
|
6693 |
|
|
`htdocs/download/index.html'
|
6694 |
|
|
These files include:
|
6695 |
|
|
* Announcement of the most recent release.
|
6696 |
|
|
|
6697 |
|
|
* News entry (remember to update both the top level and the
|
6698 |
|
|
news directory).
|
6699 |
|
|
These pages also need to be regenerate using `index.sh'.
|
6700 |
|
|
|
6701 |
|
|
`download/onlinedocs/'
|
6702 |
|
|
|
6703 |
|
|
online docs from the `.tar.bz2'. The best way is to look in the
|
6704 |
|
|
output from one of the nightly `cron' jobs and then just edit
|
6705 |
|
|
accordingly. Something like:
|
6706 |
|
|
|
6707 |
|
|
$ ~/ss/update-web-docs \
|
6708 |
|
|
|
6709 |
|
|
$PWD/www \
|
6710 |
|
|
/www/sourceware/htdocs/gdb/download/onlinedocs \
|
6711 |
|
|
|
6712 |
|
|
|
6713 |
|
|
`download/ari/'
|
6714 |
|
|
Just like the online documentation. Something like:
|
6715 |
|
|
|
6716 |
|
|
$ /bin/sh ~/ss/update-web-ari \
|
6717 |
|
|
|
6718 |
|
|
|
6719 |
|
|
/www/sourceware/htdocs/gdb/download/ari \
|
6720 |
|
|
gdb
|
6721 |
|
|
|
6722 |
|
|
|
6723 |
|
|
|
6724 |
|
|
.........................
|
6725 |
|
|
|
6726 |
|
|
|
6727 |
|
|
|
6728 |
|
|
Install the GDB tar ball on GNU
|
6729 |
|
|
|
6730 |
|
|
|
6731 |
|
|
At the time of writing, the GNU machine was `gnudist.gnu.org' in
|
6732 |
|
|
|
6733 |
|
|
|
6734 |
|
|
|
6735 |
|
|
.......................
|
6736 |
|
|
|
6737 |
|
|
Post the `ANNOUNCEMENT' file you created above to:
|
6738 |
|
|
|
6739 |
|
|
|
6740 |
|
|
|
6741 |
|
|
|
6742 |
|
|
day or so to let things get out)
|
6743 |
|
|
|
6744 |
|
|
|
6745 |
|
|
|
6746 |
|
|
|
6747 |
|
|
--------------
|
6748 |
|
|
|
6749 |
|
|
|
6750 |
|
|
|
6751 |
|
|
|
6752 |
|
|
..........................
|
6753 |
|
|
|
6754 |
|
|
In particular you'll need to commit any changes to:
|
6755 |
|
|
|
6756 |
|
|
* `gdb/ChangeLog'
|
6757 |
|
|
|
6758 |
|
|
* `gdb/version.in'
|
6759 |
|
|
|
6760 |
|
|
* `gdb/NEWS'
|
6761 |
|
|
|
6762 |
|
|
|
6763 |
|
|
|
6764 |
|
|
|
6765 |
|
|
...............
|
6766 |
|
|
|
6767 |
|
|
Something like:
|
6768 |
|
|
|
6769 |
|
|
$ d=`date -u +%Y-%m-%d`
|
6770 |
|
|
|
6771 |
|
|
2002-01-24
|
6772 |
|
|
|
6773 |
|
|
$ ( cd insight/src && cvs -f -q tag gdb_5_2-$d-release )
|
6774 |
|
|
|
6775 |
|
|
|
6776 |
|
|
|
6777 |
|
|
Mention the release on the trunk
|
6778 |
|
|
|
6779 |
|
|
|
6780 |
|
|
Just put something in the `ChangeLog' so that the trunk also indicates
|
6781 |
|
|
|
6782 |
|
|
|
6783 |
|
|
Restart `gdb/version.in'
|
6784 |
|
|
........................
|
6785 |
|
|
|
6786 |
|
|
If `gdb/version.in' does not contain an ISO date such as `2002-01-24'
|
6787 |
|
|
|
6788 |
|
|
release changes it can be set to `5.2.0_0000-00-00-cvs' which will
|
6789 |
|
|
|
6790 |
|
|
process).
|
6791 |
|
|
|
6792 |
|
|
|
6793 |
|
|
|
6794 |
|
|
Merge into trunk
|
6795 |
|
|
|
6796 |
|
|
|
6797 |
|
|
The files committed to the branch may also need changes merged into the
|
6798 |
|
|
|
6799 |
|
|
|
6800 |
|
|
Revise the release schedule
|
6801 |
|
|
...........................
|
6802 |
|
|
|
6803 |
|
|
Post a revised release schedule to GDB Discussion List
|
6804 |
|
|
|
6805 |
|
|
generated by running:
|
6806 |
|
|
|
6807 |
|
|
|
6808 |
|
|
|
6809 |
|
|
|
6810 |
|
|
of the most recent release.
|
6811 |
|
|
|
6812 |
|
|
|
6813 |
|
|
|
6814 |
|
|
|
6815 |
|
|
=================
|
6816 |
|
|
|
6817 |
|
|
|
6818 |
|
|
|
6819 |
|
|
|
6820 |
|
|
|
6821 |
|
|
|
6822 |
|
|
21 Testsuite
|
6823 |
|
|
************
|
6824 |
|
|
|
6825 |
|
|
The testsuite is an important component of the GDB package. While it
|
6826 |
|
|
|
6827 |
|
|
rarely sufficient; users typically use only a small subset of the
|
6828 |
|
|
available commands, and it has proven all too common for a change to
|
6829 |
|
|
cause a significant regression that went unnoticed for some time.
|
6830 |
|
|
|
6831 |
|
|
The GDB testsuite uses the DejaGNU testing framework. The tests
|
6832 |
|
|
themselves are calls to various `Tcl' procs; the framework runs all the
|
6833 |
|
|
|
6834 |
|
|
|
6835 |
|
|
21.1 Using the Testsuite
|
6836 |
|
|
========================
|
6837 |
|
|
|
6838 |
|
|
To run the testsuite, simply go to the GDB object directory (or to the
|
6839 |
|
|
testsuite's objdir) and type `make check'. This just sets up some
|
6840 |
|
|
|
6841 |
|
|
the testsuite is running, you'll get mentions of which test file is in
|
6842 |
|
|
|
6843 |
|
|
testsuite is finished, you'll get a summary that looks like this:
|
6844 |
|
|
|
6845 |
|
|
=== gdb Summary ===
|
6846 |
|
|
|
6847 |
|
|
# of expected passes 6016
|
6848 |
|
|
# of unexpected failures 58
|
6849 |
|
|
|
6850 |
|
|
# of expected failures 183
|
6851 |
|
|
# of unresolved testcases 3
|
6852 |
|
|
# of untested testcases 5
|
6853 |
|
|
|
6854 |
|
|
To run a specific test script, type:
|
6855 |
|
|
make check RUNTESTFLAGS='TESTS'
|
6856 |
|
|
where TESTS is a list of test script file names, separated by spaces.
|
6857 |
|
|
|
6858 |
|
|
If you use GNU make, you can use its `-j' option to run the
|
6859 |
|
|
testsuite in parallel. This can greatly reduce the amount of time it
|
6860 |
|
|
takes for the testsuite to run. In this case, if you set
|
6861 |
|
|
`RUNTESTFLAGS' then, by default, the tests will be run serially even
|
6862 |
|
|
under `-j'. You can override this and force a parallel run by setting
|
6863 |
|
|
|
6864 |
|
|
the parallel `make check' assumes that you want to run the entire
|
6865 |
|
|
testsuite, so it is not compatible with some dejagnu options, like
|
6866 |
|
|
`--directory'.
|
6867 |
|
|
|
6868 |
|
|
The ideal test run consists of expected passes only; however, reality
|
6869 |
|
|
conspires to keep us from this ideal. Unexpected failures indicate
|
6870 |
|
|
real problems, whether in GDB or in the testsuite. Expected failures
|
6871 |
|
|
are still failures, but ones which have been decided are too hard to
|
6872 |
|
|
deal with at the time; for instance, a test case might work everywhere
|
6873 |
|
|
except on AIX, and there is no prospect of the AIX case being fixed in
|
6874 |
|
|
the near future. Expected failures should not be added lightly, since
|
6875 |
|
|
|
6876 |
|
|
expected fails that are passing for some reason, while unresolved and
|
6877 |
|
|
untested cases often indicate some minor catastrophe, such as the
|
6878 |
|
|
compiler being unable to deal with a test program.
|
6879 |
|
|
|
6880 |
|
|
When making any significant change to GDB, you should run the
|
6881 |
|
|
testsuite before and after the change, to confirm that there are no
|
6882 |
|
|
regressions. Note that truly complete testing would require that you
|
6883 |
|
|
run the testsuite with all supported configurations and a variety of
|
6884 |
|
|
compilers; however this is more than really necessary. In many cases
|
6885 |
|
|
|
6886 |
|
|
options are to test one big-endian (Sparc) and one little-endian (x86)
|
6887 |
|
|
host, a cross config with a builtin simulator (powerpc-eabi, mips-elf),
|
6888 |
|
|
or a 64-bit host (Alpha).
|
6889 |
|
|
|
6890 |
|
|
If you add new functionality to GDB, please consider adding tests
|
6891 |
|
|
for it as well; this way future GDB hackers can detect and fix their
|
6892 |
|
|
changes that break the functionality you added. Similarly, if you fix
|
6893 |
|
|
|
6894 |
|
|
test case for it. Some cases are extremely difficult to test, such as
|
6895 |
|
|
code that handles host OS failures or bugs in particular versions of
|
6896 |
|
|
compilers, and it's OK not to try to write tests for all of those.
|
6897 |
|
|
|
6898 |
|
|
|
6899 |
|
|
some GDB test scripts do not work if the build machine and the host
|
6900 |
|
|
|
6901 |
|
|
give a result of "UNRESOLVED", like this:
|
6902 |
|
|
|
6903 |
|
|
|
6904 |
|
|
|
6905 |
|
|
|
6906 |
|
|
=========================
|
6907 |
|
|
|
6908 |
|
|
Several variables exist to modify the behavior of the testsuite.
|
6909 |
|
|
|
6910 |
|
|
* `TRANSCRIPT'
|
6911 |
|
|
|
6912 |
|
|
|
6913 |
|
|
which the testsuite sends to GDB. For example, if GDB crashes
|
6914 |
|
|
during testing, a transcript can be used to more easily
|
6915 |
|
|
reconstruct the failure when running GDB under GDB.
|
6916 |
|
|
|
6917 |
|
|
You can instruct the GDB testsuite to write transcripts by setting
|
6918 |
|
|
the DejaGNU variable `TRANSCRIPT' (to any value) before invoking
|
6919 |
|
|
`runtest' or `make check'. The transcripts will be written into
|
6920 |
|
|
DejaGNU's output directory. One transcript will be made for each
|
6921 |
|
|
|
6922 |
|
|
an integer. The first line of the transcript file will show how
|
6923 |
|
|
|
6924 |
|
|
to GDB.
|
6925 |
|
|
|
6926 |
|
|
|
6927 |
|
|
|
6928 |
|
|
|
6929 |
|
|
tests of completion can yield partial command lines.
|
6930 |
|
|
|
6931 |
|
|
* `GDB'
|
6932 |
|
|
|
6933 |
|
|
Sometimes one wishes to test a different GDB than the one in the
|
6934 |
|
|
|
6935 |
|
|
`/usr/bin/gdb'.
|
6936 |
|
|
|
6937 |
|
|
make check RUNTESTFLAGS=GDB=/usr/bin/gdb
|
6938 |
|
|
|
6939 |
|
|
|
6940 |
|
|
|
6941 |
|
|
|
6942 |
|
|
different gdbserver.
|
6943 |
|
|
|
6944 |
|
|
make check RUNTESTFLAGS="GDB=/usr/bin/gdb GDBSERVER=/usr/bin/gdbserver"
|
6945 |
|
|
|
6946 |
|
|
* `INTERNAL_GDBFLAGS'
|
6947 |
|
|
|
6948 |
|
|
When running the testsuite normally one doesn't want whatever is in
|
6949 |
|
|
|
6950 |
|
|
harness passes `-nx' to GDB. One also doesn't want any windowed
|
6951 |
|
|
|
6952 |
|
|
`INTERNAL_GDBFLAGS'.
|
6953 |
|
|
|
6954 |
|
|
set INTERNAL_GDBFLAGS "-nw -nx"
|
6955 |
|
|
|
6956 |
|
|
This is all well and good, except when testing an installed GDB
|
6957 |
|
|
that has been configured with `--with-system-gdbinit'. Here one
|
6958 |
|
|
|
6959 |
|
|
`.gdbinit' file loaded. This can be achieved by pointing `$HOME'
|
6960 |
|
|
at a directory without a `.gdbinit' and by overriding
|
6961 |
|
|
`INTERNAL_GDBFLAGS' and removing `-nx'.
|
6962 |
|
|
|
6963 |
|
|
cd testsuite
|
6964 |
|
|
|
6965 |
|
|
|
6966 |
|
|
GDBSERVER=/usr/bin/gdbserver \
|
6967 |
|
|
INTERNAL_GDBFLAGS=-nw
|
6968 |
|
|
|
6969 |
|
|
|
6970 |
|
|
There are two ways to run the testsuite and pass additional
|
6971 |
|
|
|
6972 |
|
|
the makefile variable `RUNTESTFLAGS'.
|
6973 |
|
|
|
6974 |
|
|
|
6975 |
|
|
|
6976 |
|
|
The second is to cd to the `testsuite' directory and invoke the
|
6977 |
|
|
DejaGnu `runtest' command directly.
|
6978 |
|
|
|
6979 |
|
|
cd testsuite
|
6980 |
|
|
make site.exp
|
6981 |
|
|
|
6982 |
|
|
|
6983 |
|
|
21.3 Testsuite Configuration
|
6984 |
|
|
============================
|
6985 |
|
|
|
6986 |
|
|
It is possible to adjust the behavior of the testsuite by defining the
|
6987 |
|
|
|
6988 |
|
|
board file.
|
6989 |
|
|
|
6990 |
|
|
* `gdb_test_timeout'
|
6991 |
|
|
|
6992 |
|
|
Defining this variable changes the default timeout duration used
|
6993 |
|
|
during communication with GDB. More specifically, the global
|
6994 |
|
|
|
6995 |
|
|
reset to `gdb_test_timeout' at the beginning of each testcase,
|
6996 |
|
|
making sure that any local change to `timeout' in a testcase does
|
6997 |
|
|
not affect subsequent testcases.
|
6998 |
|
|
|
6999 |
|
|
|
7000 |
|
|
than normal due to the testing environment, triggering unexpected
|
7001 |
|
|
`TIMEOUT' test failures. Examples include when testing on a
|
7002 |
|
|
remote machine, or against a system where communications are slow.
|
7003 |
|
|
|
7004 |
|
|
If not specifically defined, this variable gets automatically
|
7005 |
|
|
|
7006 |
|
|
|
7007 |
|
|
the file `gdb/testsuite/config/unix.exp' that is part of the GDB
|
7008 |
|
|
test suite(1).
|
7009 |
|
|
|
7010 |
|
|
|
7011 |
|
|
21.4 Testsuite Organization
|
7012 |
|
|
===========================
|
7013 |
|
|
|
7014 |
|
|
The testsuite is entirely contained in `gdb/testsuite'. While the
|
7015 |
|
|
testsuite includes some makefiles and configury, these are very minimal,
|
7016 |
|
|
and used for little besides cleaning up, since the tests themselves
|
7017 |
|
|
handle the compilation of the programs that GDB will run. The file
|
7018 |
|
|
|
7019 |
|
|
GDB tests, while the directory `testsuite/config' contains
|
7020 |
|
|
configuration-specific files, typically used for special-purpose
|
7021 |
|
|
definitions of procs like `gdb_load' and `gdb_start'.
|
7022 |
|
|
|
7023 |
|
|
The tests themselves are to be found in `testsuite/gdb.*' and
|
7024 |
|
|
|
7025 |
|
|
with `.exp'. DejaGNU collects the test files by wildcarding in the
|
7026 |
|
|
test directories, so both subdirectories and individual files get
|
7027 |
|
|
chosen and run in alphabetical order.
|
7028 |
|
|
|
7029 |
|
|
The following table lists the main types of subdirectories and what
|
7030 |
|
|
|
7031 |
|
|
located, and since each test file sets up its own compilation and
|
7032 |
|
|
execution environment, this organization is simply for convenience and
|
7033 |
|
|
intelligibility.
|
7034 |
|
|
|
7035 |
|
|
`gdb.base'
|
7036 |
|
|
This is the base testsuite. The tests in it should apply to all
|
7037 |
|
|
|
7038 |
|
|
here). The test programs should be in the subset of C that is
|
7039 |
|
|
valid K&R, ANSI/ISO, and C++ (`#ifdef's are allowed if necessary,
|
7040 |
|
|
for instance for prototypes).
|
7041 |
|
|
|
7042 |
|
|
`gdb.LANG'
|
7043 |
|
|
Language-specific tests for any language LANG besides C. Examples
|
7044 |
|
|
are `gdb.cp' and `gdb.java'.
|
7045 |
|
|
|
7046 |
|
|
|
7047 |
|
|
Non-portable tests. The tests are specific to a specific
|
7048 |
|
|
configuration (host or target), such as HP-UX or eCos. Example is
|
7049 |
|
|
`gdb.hp', for HP-UX.
|
7050 |
|
|
|
7051 |
|
|
`gdb.COMPILER'
|
7052 |
|
|
Tests specific to a particular compiler. As of this writing (June
|
7053 |
|
|
|
7054 |
|
|
that couldn't just as sensibly be made platform-specific, but one
|
7055 |
|
|
could imagine a `gdb.gcc', for tests of GDB's handling of GCC
|
7056 |
|
|
extensions.
|
7057 |
|
|
|
7058 |
|
|
|
7059 |
|
|
Tests that exercise a specific GDB subsystem in more depth. For
|
7060 |
|
|
instance, `gdb.disasm' exercises various disassemblers, while
|
7061 |
|
|
|
7062 |
|
|
|
7063 |
|
|
21.5 Writing Tests
|
7064 |
|
|
|
7065 |
|
|
|
7066 |
|
|
In many areas, the GDB tests are already quite comprehensive; you
|
7067 |
|
|
should be able to copy existing tests to handle new cases.
|
7068 |
|
|
|
7069 |
|
|
You should try to use `gdb_test' whenever possible, since it
|
7070 |
|
|
|
7071 |
|
|
However, it doesn't cost anything to add new test procedures; for
|
7072 |
|
|
instance, `gdb.base/exprs.exp' defines a `test_expr' that calls
|
7073 |
|
|
`gdb_test' multiple times.
|
7074 |
|
|
|
7075 |
|
|
|
7076 |
|
|
Even if GDB has several valid responses to a command, you can use
|
7077 |
|
|
`gdb_test_multiple'. Like `gdb_test', `gdb_test_multiple' recognizes
|
7078 |
|
|
internal errors and unexpected prompts.
|
7079 |
|
|
|
7080 |
|
|
Do not write tests which expect a literal tab character from GDB.
|
7081 |
|
|
On some operating systems (e.g. OpenBSD) the TTY layer expands tabs to
|
7082 |
|
|
spaces, so by the time GDB's output reaches expect the tab is gone.
|
7083 |
|
|
|
7084 |
|
|
The source language programs do _not_ need to be in a consistent
|
7085 |
|
|
style. Since GDB is used to debug programs written in many different
|
7086 |
|
|
|
7087 |
|
|
instance, some GDB bugs involving the display of source lines would
|
7088 |
|
|
|
7089 |
|
|
uniformly.
|
7090 |
|
|
|
7091 |
|
|
|
7092 |
|
|
|
7093 |
|
|
(1) If you are using a board file, it could override the test-suite
|
7094 |
|
|
|
7095 |
|
|
|
7096 |
|
|
|
7097 |
|
|
|
7098 |
|
|
|
7099 |
|
|
22 Hints
|
7100 |
|
|
|
7101 |
|
|
|
7102 |
|
|
|
7103 |
|
|
appear anywhere else in the directory.
|
7104 |
|
|
|
7105 |
|
|
|
7106 |
|
|
|
7107 |
|
|
* Getting Started:: Getting started working on GDB
|
7108 |
|
|
|
7109 |
|
|
|
7110 |
|
|
|
7111 |
|
|
|
7112 |
|
|
|
7113 |
|
|
22.1 Getting Started
|
7114 |
|
|
====================
|
7115 |
|
|
|
7116 |
|
|
GDB is a large and complicated program, and if you first starting to
|
7117 |
|
|
work on it, it can be hard to know where to start. Fortunately, if you
|
7118 |
|
|
|
7119 |
|
|
|
7120 |
|
|
This manual, the GDB Internals manual, has information which applies
|
7121 |
|
|
generally to many parts of GDB.
|
7122 |
|
|
|
7123 |
|
|
Information about particular functions or data structures are
|
7124 |
|
|
located in comments with those functions or data structures. If you
|
7125 |
|
|
run across a function or a global variable which does not have a
|
7126 |
|
|
|
7127 |
|
|
bug in GDB; feel free to submit a bug report, with a suggested comment
|
7128 |
|
|
if you can figure out what the comment should say. If you find a
|
7129 |
|
|
comment which is actually wrong, be especially sure to report that.
|
7130 |
|
|
|
7131 |
|
|
Comments explaining the function of macros defined in host, target,
|
7132 |
|
|
or native dependent files can be in several places. Sometimes they are
|
7133 |
|
|
|
7134 |
|
|
macro is used. Sometimes there is a header file which supplies a
|
7135 |
|
|
default definition of the macro, and the comment is there. This manual
|
7136 |
|
|
also documents all the available macros.
|
7137 |
|
|
|
7138 |
|
|
|
7139 |
|
|
internal symbol tables are stored (see `symtab.h', `gdbtypes.h'), you
|
7140 |
|
|
will find it much easier to understand the code which uses and creates
|
7141 |
|
|
those symbol tables.
|
7142 |
|
|
|
7143 |
|
|
You may wish to process the information you are getting somehow, to
|
7144 |
|
|
enhance your understanding of it. Summarize it, translate it to another
|
7145 |
|
|
language, add some (perhaps trivial or non-useful) feature to GDB, use
|
7146 |
|
|
|
7147 |
|
|
and verify your prediction, etc. If you are reading code and your eyes
|
7148 |
|
|
are starting to glaze over, this is a sign you need to use a more active
|
7149 |
|
|
approach.
|
7150 |
|
|
|
7151 |
|
|
Once you have a part of GDB to start with, you can find more
|
7152 |
|
|
specifically the part you are looking for by stepping through each
|
7153 |
|
|
function with the `next' command. Do not use `step' or you will
|
7154 |
|
|
quickly get distracted; when the function you are stepping through
|
7155 |
|
|
calls another function try only to get a big-picture understanding
|
7156 |
|
|
(perhaps using the comment at the beginning of the function being
|
7157 |
|
|
called) of what it does. This way you can identify which of the
|
7158 |
|
|
functions being called by the function you are stepping through is the
|
7159 |
|
|
|
7160 |
|
|
structures generated at each stage, with reference to the comments in
|
7161 |
|
|
the header files explaining what the data structures are supposed to
|
7162 |
|
|
look like.
|
7163 |
|
|
|
7164 |
|
|
Of course, this same technique can be used if you are just reading
|
7165 |
|
|
|
7166 |
|
|
principle applies--when the code you are looking at calls something
|
7167 |
|
|
else, just try to understand generally what the code being called does,
|
7168 |
|
|
rather than worrying about all its details.
|
7169 |
|
|
|
7170 |
|
|
A good place to start when tracking down some particular area is with
|
7171 |
|
|
a command which invokes that feature. Suppose you want to know how
|
7172 |
|
|
single-stepping works. As a GDB user, you know that the `step' command
|
7173 |
|
|
invokes single-stepping. The command is invoked via command tables
|
7174 |
|
|
(see `command.h'); by convention the function which actually performs
|
7175 |
|
|
the command is formed by taking the name of the command and adding
|
7176 |
|
|
`_command', or in the case of an `info' subcommand, `_info'. For
|
7177 |
|
|
|
7178 |
|
|
`info display' command invokes `display_info'. When this convention is
|
7179 |
|
|
not followed, you might have to use `grep' or `M-x tags-search' in
|
7180 |
|
|
emacs, or run GDB on itself and set a breakpoint in `execute_command'.
|
7181 |
|
|
|
7182 |
|
|
If all of the above fail, it may be appropriate to ask for
|
7183 |
|
|
|
7184 |
|
|
was wondering if anyone could give me some tips about understanding
|
7185 |
|
|
GDB"--if we had some magic secret we would put it in this manual.
|
7186 |
|
|
|
7187 |
|
|
|
7188 |
|
|
|
7189 |
|
|
|
7190 |
|
|
|
7191 |
|
|
22.2 Debugging GDB with itself
|
7192 |
|
|
==============================
|
7193 |
|
|
|
7194 |
|
|
If GDB is limping on your machine, this is the preferred way to get it
|
7195 |
|
|
fully functional. Be warned that in some ancient Unix systems, like
|
7196 |
|
|
|
7197 |
|
|
debugged in another. Rather than typing the command `./gdb ./gdb',
|
7198 |
|
|
which works on Suns and such, you can copy `gdb' to `gdb2' and then
|
7199 |
|
|
type `./gdb ./gdb2'.
|
7200 |
|
|
|
7201 |
|
|
When you run GDB in the GDB source directory, it will read a
|
7202 |
|
|
|
7203 |
|
|
easier. The `info' command, when executed without a subcommand in a
|
7204 |
|
|
GDB being debugged by gdb, will pop you back up to the top level gdb.
|
7205 |
|
|
See `.gdbinit' for details.
|
7206 |
|
|
|
7207 |
|
|
|
7208 |
|
|
you configure your distribution; this will put the machine dependent
|
7209 |
|
|
routines for your local machine where they will be accessed first by
|
7210 |
|
|
|
7211 |
|
|
|
7212 |
|
|
Also, make sure that you've either compiled GDB with your local cc,
|
7213 |
|
|
|
7214 |
|
|
|
7215 |
|
|
22.3 Submitting Patches
|
7216 |
|
|
=======================
|
7217 |
|
|
|
7218 |
|
|
|
7219 |
|
|
GDB users. In general we like to get well designed enhancements.
|
7220 |
|
|
Thanks also for checking in advance about the best way to transfer the
|
7221 |
|
|
|
7222 |
|
|
|
7223 |
|
|
The GDB maintainers will only install "cleanly designed" patches.
|
7224 |
|
|
This manual summarizes what we believe to be clean design for GDB.
|
7225 |
|
|
|
7226 |
|
|
If the maintainers don't have time to put the patch in when it
|
7227 |
|
|
arrives, or if there is any question about a patch, it goes into a
|
7228 |
|
|
large queue with everyone else's patches and bug reports.
|
7229 |
|
|
|
7230 |
|
|
The legal issue is that to incorporate substantial changes requires a
|
7231 |
|
|
copyright assignment from you and/or your employer, granting ownership
|
7232 |
|
|
of the changes to the Free Software Foundation. You can get the
|
7233 |
|
|
standard documents for doing this by sending mail to `gnu@gnu.org' and
|
7234 |
|
|
asking for it. We recommend that people write in "All programs owned
|
7235 |
|
|
by the Free Software Foundation" as "NAME OF PROGRAM", so that changes
|
7236 |
|
|
in many programs (not just GDB, but GAS, Emacs, GCC, etc) can be
|
7237 |
|
|
|
7238 |
|
|
bureaucracy and filed with the FSF. We can't start merging changes
|
7239 |
|
|
until this paperwork is received by the FSF (their rules, which we
|
7240 |
|
|
follow since we maintain it for them).
|
7241 |
|
|
|
7242 |
|
|
Technically, the easiest way to receive changes is to receive each
|
7243 |
|
|
feature as a small context diff or unidiff, suitable for `patch'. Each
|
7244 |
|
|
message sent to me should include the changes to C code and header
|
7245 |
|
|
files for a single feature, plus `ChangeLog' entries for each directory
|
7246 |
|
|
|
7247 |
|
|
manuals (`gdb/doc/gdb.texinfo' or `gdb/doc/gdbint.texinfo'). If there
|
7248 |
|
|
are a lot of changes for a single feature, they can be split down into
|
7249 |
|
|
multiple messages.
|
7250 |
|
|
|
7251 |
|
|
|
7252 |
|
|
sources with a single patch command, do some testing, and check it in.
|
7253 |
|
|
If you leave out the `ChangeLog', we have to write one. If you leave
|
7254 |
|
|
out the doc, we have to puzzle out what needs documenting. Etc., etc.
|
7255 |
|
|
|
7256 |
|
|
The reason to send each change in a separate message is that we will
|
7257 |
|
|
not install some of the changes. They'll be returned to you with
|
7258 |
|
|
questions or comments. If we're doing our job correctly, the message
|
7259 |
|
|
back to you will say what you have to fix in order to make the change
|
7260 |
|
|
acceptable. The reason to have separate messages for separate features
|
7261 |
|
|
is so that the acceptable changes can be installed while one or more
|
7262 |
|
|
|
7263 |
|
|
message, we tend to not put in the effort to sort out the acceptable
|
7264 |
|
|
changes from the unacceptable, so none of the features get installed
|
7265 |
|
|
until all are acceptable.
|
7266 |
|
|
|
7267 |
|
|
If this sounds painful or authoritarian, well, it is. But we get a
|
7268 |
|
|
lot of bug reports and a lot of patches, and many of them don't get
|
7269 |
|
|
installed because we don't have the time to finish the job that the bug
|
7270 |
|
|
reporter or the contributor could have done. Patches that arrive
|
7271 |
|
|
|
7272 |
|
|
they arrive. The others go into a queue and get installed as time
|
7273 |
|
|
permits, which, since the maintainers have many demands to meet, may not
|
7274 |
|
|
|
7275 |
|
|
|
7276 |
|
|
Please send patches directly to the GDB maintainers
|
7277 |
|
|
|
7278 |
|
|
|
7279 |
|
|
22.4 Build Script
|
7280 |
|
|
=================
|
7281 |
|
|
|
7282 |
|
|
|
7283 |
|
|
`--enable-targets=all' set. This builds GDB with all supported targets
|
7284 |
|
|
activated. This helps testing GDB when doing changes that affect more
|
7285 |
|
|
than one architecture and is much faster than using `gdb_mbuild.sh'.
|
7286 |
|
|
|
7287 |
|
|
|
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.