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