gdb: fix shellcheck warnings SC2034 (unused variable) in gdbarch.sh
[deliverable/binutils-gdb.git] / gdb / gdbarch.sh
1 #!/bin/sh -u
2
3 # Architecture commands for GDB, the GNU debugger.
4 #
5 # Copyright (C) 1998-2020 Free Software Foundation, Inc.
6 #
7 # This file is part of GDB.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22 # Make certain that the script is not running in an internationalized
23 # environment.
24 LANG=C ; export LANG
25 LC_ALL=C ; export LC_ALL
26
27
28 compare_new ()
29 {
30 file=$1
31 if test ! -r "${file}"
32 then
33 echo "${file} missing? cp new-${file} ${file}" 1>&2
34 elif diff -u "${file}" "new-${file}"
35 then
36 echo "${file} unchanged" 1>&2
37 else
38 echo "${file} has changed? cp new-${file} ${file}" 1>&2
39 fi
40 }
41
42
43 # Format of the input table
44 read="class returntype function formal actual staticdefault predefault postdefault invalid_p print garbage_at_eol"
45
46 do_read ()
47 {
48 comment=""
49 class=""
50 # On some SH's, 'read' trims leading and trailing whitespace by
51 # default (e.g., bash), while on others (e.g., dash), it doesn't.
52 # Set IFS to empty to disable the trimming everywhere.
53 while IFS='' read line
54 do
55 if test "${line}" = ""
56 then
57 continue
58 elif test "${line}" = "#" -a "${comment}" = ""
59 then
60 continue
61 elif expr "${line}" : "#" > /dev/null
62 then
63 comment="${comment}
64 ${line}"
65 else
66
67 # The semantics of IFS varies between different SH's. Some
68 # treat ``;;' as three fields while some treat it as just two.
69 # Work around this by eliminating ``;;'' ....
70 line="$(echo "${line}" | sed -e 's/;;/; ;/g' -e 's/;;/; ;/g')"
71
72 OFS="${IFS}" ; IFS="[;]"
73 eval read "${read}" <<EOF
74 ${line}
75 EOF
76 IFS="${OFS}"
77
78 if test -n "${garbage_at_eol}"
79 then
80 echo "Garbage at end-of-line in ${line}" 1>&2
81 kill $$
82 exit 1
83 fi
84
85 # .... and then going back through each field and strip out those
86 # that ended up with just that space character.
87 for r in ${read}
88 do
89 if eval test "\"\${${r}}\" = ' '"
90 then
91 eval "${r}="
92 fi
93 done
94
95 case "${class}" in
96 m ) staticdefault="${predefault}" ;;
97 M ) staticdefault="0" ;;
98 * ) test "${staticdefault}" || staticdefault=0 ;;
99 esac
100
101 case "${class}" in
102 F | V | M )
103 case "${invalid_p}" in
104 "" )
105 if test -n "${predefault}"
106 then
107 #invalid_p="gdbarch->${function} == ${predefault}"
108 predicate="gdbarch->${function} != ${predefault}"
109 elif class_is_variable_p
110 then
111 predicate="gdbarch->${function} != 0"
112 elif class_is_function_p
113 then
114 predicate="gdbarch->${function} != NULL"
115 fi
116 ;;
117 * )
118 echo "Predicate function ${function} with invalid_p." 1>&2
119 kill $$
120 exit 1
121 ;;
122 esac
123 esac
124
125 #NOT YET: See gdbarch.log for basic verification of
126 # database
127
128 break
129 fi
130 done
131 if [ -n "${class}" ]
132 then
133 true
134 else
135 false
136 fi
137 }
138
139
140 fallback_default_p ()
141 {
142 { [ -n "${postdefault}" ] && [ "x${invalid_p}" != "x0" ]; } \
143 || { [ -n "${predefault}" ] && [ "x${invalid_p}" = "x0" ]; }
144 }
145
146 class_is_variable_p ()
147 {
148 case "${class}" in
149 *v* | *V* ) true ;;
150 * ) false ;;
151 esac
152 }
153
154 class_is_function_p ()
155 {
156 case "${class}" in
157 *f* | *F* | *m* | *M* ) true ;;
158 * ) false ;;
159 esac
160 }
161
162 class_is_multiarch_p ()
163 {
164 case "${class}" in
165 *m* | *M* ) true ;;
166 * ) false ;;
167 esac
168 }
169
170 class_is_predicate_p ()
171 {
172 case "${class}" in
173 *F* | *V* | *M* ) true ;;
174 * ) false ;;
175 esac
176 }
177
178 class_is_info_p ()
179 {
180 case "${class}" in
181 *i* ) true ;;
182 * ) false ;;
183 esac
184 }
185
186
187 # dump out/verify the doco
188 for field in ${read}
189 do
190 case ${field} in
191
192 class ) : ;;
193
194 # # -> line disable
195 # f -> function
196 # hiding a function
197 # F -> function + predicate
198 # hiding a function + predicate to test function validity
199 # v -> variable
200 # hiding a variable
201 # V -> variable + predicate
202 # hiding a variable + predicate to test variables validity
203 # i -> set from info
204 # hiding something from the ``struct info'' object
205 # m -> multi-arch function
206 # hiding a multi-arch function (parameterised with the architecture)
207 # M -> multi-arch function + predicate
208 # hiding a multi-arch function + predicate to test function validity
209
210 returntype ) : ;;
211
212 # For functions, the return type; for variables, the data type
213
214 function ) : ;;
215
216 # For functions, the member function name; for variables, the
217 # variable name. Member function names are always prefixed with
218 # ``gdbarch_'' for name-space purity.
219
220 formal ) : ;;
221
222 # The formal argument list. It is assumed that the formal
223 # argument list includes the actual name of each list element.
224 # A function with no arguments shall have ``void'' as the
225 # formal argument list.
226
227 actual ) : ;;
228
229 # The list of actual arguments. The arguments specified shall
230 # match the FORMAL list given above. Functions with out
231 # arguments leave this blank.
232
233 staticdefault ) : ;;
234
235 # To help with the GDB startup a static gdbarch object is
236 # created. STATICDEFAULT is the value to insert into that
237 # static gdbarch object. Since this a static object only
238 # simple expressions can be used.
239
240 # If STATICDEFAULT is empty, zero is used.
241
242 predefault ) : ;;
243
244 # An initial value to assign to MEMBER of the freshly
245 # malloc()ed gdbarch object. After initialization, the
246 # freshly malloc()ed object is passed to the target
247 # architecture code for further updates.
248
249 # If PREDEFAULT is empty, zero is used.
250
251 # A non-empty PREDEFAULT, an empty POSTDEFAULT and a zero
252 # INVALID_P are specified, PREDEFAULT will be used as the
253 # default for the non- multi-arch target.
254
255 # A zero PREDEFAULT function will force the fallback to call
256 # internal_error().
257
258 # Variable declarations can refer to ``gdbarch'' which will
259 # contain the current architecture. Care should be taken.
260
261 postdefault ) : ;;
262
263 # A value to assign to MEMBER of the new gdbarch object should
264 # the target architecture code fail to change the PREDEFAULT
265 # value.
266
267 # If POSTDEFAULT is empty, no post update is performed.
268
269 # If both INVALID_P and POSTDEFAULT are non-empty then
270 # INVALID_P will be used to determine if MEMBER should be
271 # changed to POSTDEFAULT.
272
273 # If a non-empty POSTDEFAULT and a zero INVALID_P are
274 # specified, POSTDEFAULT will be used as the default for the
275 # non- multi-arch target (regardless of the value of
276 # PREDEFAULT).
277
278 # You cannot specify both a zero INVALID_P and a POSTDEFAULT.
279
280 # Variable declarations can refer to ``gdbarch'' which
281 # will contain the current architecture. Care should be
282 # taken.
283
284 invalid_p ) : ;;
285
286 # A predicate equation that validates MEMBER. Non-zero is
287 # returned if the code creating the new architecture failed to
288 # initialize MEMBER or the initialized the member is invalid.
289 # If POSTDEFAULT is non-empty then MEMBER will be updated to
290 # that value. If POSTDEFAULT is empty then internal_error()
291 # is called.
292
293 # If INVALID_P is empty, a check that MEMBER is no longer
294 # equal to PREDEFAULT is used.
295
296 # The expression ``0'' disables the INVALID_P check making
297 # PREDEFAULT a legitimate value.
298
299 # See also PREDEFAULT and POSTDEFAULT.
300
301 print ) : ;;
302
303 # An optional expression that convers MEMBER to a value
304 # suitable for formatting using %s.
305
306 # If PRINT is empty, core_addr_to_string_nz (for CORE_ADDR)
307 # or plongest (anything else) is used.
308
309 garbage_at_eol ) : ;;
310
311 # Catches stray fields.
312
313 *)
314 echo "Bad field ${field}"
315 exit 1;;
316 esac
317 done
318
319
320 function_list ()
321 {
322 # See below (DOCO) for description of each field
323 cat <<EOF
324 i;const struct bfd_arch_info *;bfd_arch_info;;;&bfd_default_arch_struct;;;;gdbarch_bfd_arch_info (gdbarch)->printable_name
325 #
326 i;enum bfd_endian;byte_order;;;BFD_ENDIAN_BIG
327 i;enum bfd_endian;byte_order_for_code;;;BFD_ENDIAN_BIG
328 #
329 i;enum gdb_osabi;osabi;;;GDB_OSABI_UNKNOWN
330 #
331 i;const struct target_desc *;target_desc;;;;;;;host_address_to_string (gdbarch->target_desc)
332
333 # Number of bits in a short or unsigned short for the target machine.
334 v;int;short_bit;;;8 * sizeof (short);2*TARGET_CHAR_BIT;;0
335 # Number of bits in an int or unsigned int for the target machine.
336 v;int;int_bit;;;8 * sizeof (int);4*TARGET_CHAR_BIT;;0
337 # Number of bits in a long or unsigned long for the target machine.
338 v;int;long_bit;;;8 * sizeof (long);4*TARGET_CHAR_BIT;;0
339 # Number of bits in a long long or unsigned long long for the target
340 # machine.
341 v;int;long_long_bit;;;8 * sizeof (LONGEST);2*gdbarch->long_bit;;0
342
343 # The ABI default bit-size and format for "half", "float", "double", and
344 # "long double". These bit/format pairs should eventually be combined
345 # into a single object. For the moment, just initialize them as a pair.
346 # Each format describes both the big and little endian layouts (if
347 # useful).
348
349 v;int;half_bit;;;16;2*TARGET_CHAR_BIT;;0
350 v;const struct floatformat **;half_format;;;;;floatformats_ieee_half;;pformat (gdbarch->half_format)
351 v;int;float_bit;;;8 * sizeof (float);4*TARGET_CHAR_BIT;;0
352 v;const struct floatformat **;float_format;;;;;floatformats_ieee_single;;pformat (gdbarch->float_format)
353 v;int;double_bit;;;8 * sizeof (double);8*TARGET_CHAR_BIT;;0
354 v;const struct floatformat **;double_format;;;;;floatformats_ieee_double;;pformat (gdbarch->double_format)
355 v;int;long_double_bit;;;8 * sizeof (long double);8*TARGET_CHAR_BIT;;0
356 v;const struct floatformat **;long_double_format;;;;;floatformats_ieee_double;;pformat (gdbarch->long_double_format)
357
358 # The ABI default bit-size for "wchar_t". wchar_t is a built-in type
359 # starting with C++11.
360 v;int;wchar_bit;;;8 * sizeof (wchar_t);4*TARGET_CHAR_BIT;;0
361 # One if \`wchar_t' is signed, zero if unsigned.
362 v;int;wchar_signed;;;1;-1;1
363
364 # Returns the floating-point format to be used for values of length LENGTH.
365 # NAME, if non-NULL, is the type name, which may be used to distinguish
366 # different target formats of the same length.
367 m;const struct floatformat **;floatformat_for_type;const char *name, int length;name, length;0;default_floatformat_for_type;;0
368
369 # For most targets, a pointer on the target and its representation as an
370 # address in GDB have the same size and "look the same". For such a
371 # target, you need only set gdbarch_ptr_bit and gdbarch_addr_bit
372 # / addr_bit will be set from it.
373 #
374 # If gdbarch_ptr_bit and gdbarch_addr_bit are different, you'll probably
375 # also need to set gdbarch_dwarf2_addr_size, gdbarch_pointer_to_address and
376 # gdbarch_address_to_pointer as well.
377 #
378 # ptr_bit is the size of a pointer on the target
379 v;int;ptr_bit;;;8 * sizeof (void*);gdbarch->int_bit;;0
380 # addr_bit is the size of a target address as represented in gdb
381 v;int;addr_bit;;;8 * sizeof (void*);0;gdbarch_ptr_bit (gdbarch);
382 #
383 # dwarf2_addr_size is the target address size as used in the Dwarf debug
384 # info. For .debug_frame FDEs, this is supposed to be the target address
385 # size from the associated CU header, and which is equivalent to the
386 # DWARF2_ADDR_SIZE as defined by the target specific GCC back-end.
387 # Unfortunately there is no good way to determine this value. Therefore
388 # dwarf2_addr_size simply defaults to the target pointer size.
389 #
390 # dwarf2_addr_size is not used for .eh_frame FDEs, which are generally
391 # defined using the target's pointer size so far.
392 #
393 # Note that dwarf2_addr_size only needs to be redefined by a target if the
394 # GCC back-end defines a DWARF2_ADDR_SIZE other than the target pointer size,
395 # and if Dwarf versions < 4 need to be supported.
396 v;int;dwarf2_addr_size;;;sizeof (void*);0;gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
397 #
398 # One if \`char' acts like \`signed char', zero if \`unsigned char'.
399 v;int;char_signed;;;1;-1;1
400 #
401 F;CORE_ADDR;read_pc;readable_regcache *regcache;regcache
402 F;void;write_pc;struct regcache *regcache, CORE_ADDR val;regcache, val
403 # Function for getting target's idea of a frame pointer. FIXME: GDB's
404 # whole scheme for dealing with "frames" and "frame pointers" needs a
405 # serious shakedown.
406 m;void;virtual_frame_pointer;CORE_ADDR pc, int *frame_regnum, LONGEST *frame_offset;pc, frame_regnum, frame_offset;0;legacy_virtual_frame_pointer;;0
407 #
408 M;enum register_status;pseudo_register_read;readable_regcache *regcache, int cookednum, gdb_byte *buf;regcache, cookednum, buf
409 # Read a register into a new struct value. If the register is wholly
410 # or partly unavailable, this should call mark_value_bytes_unavailable
411 # as appropriate. If this is defined, then pseudo_register_read will
412 # never be called.
413 M;struct value *;pseudo_register_read_value;readable_regcache *regcache, int cookednum;regcache, cookednum
414 M;void;pseudo_register_write;struct regcache *regcache, int cookednum, const gdb_byte *buf;regcache, cookednum, buf
415 #
416 v;int;num_regs;;;0;-1
417 # This macro gives the number of pseudo-registers that live in the
418 # register namespace but do not get fetched or stored on the target.
419 # These pseudo-registers may be aliases for other registers,
420 # combinations of other registers, or they may be computed by GDB.
421 v;int;num_pseudo_regs;;;0;0;;0
422
423 # Assemble agent expression bytecode to collect pseudo-register REG.
424 # Return -1 if something goes wrong, 0 otherwise.
425 M;int;ax_pseudo_register_collect;struct agent_expr *ax, int reg;ax, reg
426
427 # Assemble agent expression bytecode to push the value of pseudo-register
428 # REG on the interpreter stack.
429 # Return -1 if something goes wrong, 0 otherwise.
430 M;int;ax_pseudo_register_push_stack;struct agent_expr *ax, int reg;ax, reg
431
432 # Some targets/architectures can do extra processing/display of
433 # segmentation faults. E.g., Intel MPX boundary faults.
434 # Call the architecture dependent function to handle the fault.
435 # UIOUT is the output stream where the handler will place information.
436 M;void;handle_segmentation_fault;struct ui_out *uiout;uiout
437
438 # GDB's standard (or well known) register numbers. These can map onto
439 # a real register or a pseudo (computed) register or not be defined at
440 # all (-1).
441 # gdbarch_sp_regnum will hopefully be replaced by UNWIND_SP.
442 v;int;sp_regnum;;;-1;-1;;0
443 v;int;pc_regnum;;;-1;-1;;0
444 v;int;ps_regnum;;;-1;-1;;0
445 v;int;fp0_regnum;;;0;-1;;0
446 # Convert stab register number (from \`r\' declaration) to a gdb REGNUM.
447 m;int;stab_reg_to_regnum;int stab_regnr;stab_regnr;;no_op_reg_to_regnum;;0
448 # Provide a default mapping from a ecoff register number to a gdb REGNUM.
449 m;int;ecoff_reg_to_regnum;int ecoff_regnr;ecoff_regnr;;no_op_reg_to_regnum;;0
450 # Convert from an sdb register number to an internal gdb register number.
451 m;int;sdb_reg_to_regnum;int sdb_regnr;sdb_regnr;;no_op_reg_to_regnum;;0
452 # Provide a default mapping from a DWARF2 register number to a gdb REGNUM.
453 # Return -1 for bad REGNUM. Note: Several targets get this wrong.
454 m;int;dwarf2_reg_to_regnum;int dwarf2_regnr;dwarf2_regnr;;no_op_reg_to_regnum;;0
455 m;const char *;register_name;int regnr;regnr;;0
456
457 # Return the type of a register specified by the architecture. Only
458 # the register cache should call this function directly; others should
459 # use "register_type".
460 M;struct type *;register_type;int reg_nr;reg_nr
461
462 # Generate a dummy frame_id for THIS_FRAME assuming that the frame is
463 # a dummy frame. A dummy frame is created before an inferior call,
464 # the frame_id returned here must match the frame_id that was built
465 # for the inferior call. Usually this means the returned frame_id's
466 # stack address should match the address returned by
467 # gdbarch_push_dummy_call, and the returned frame_id's code address
468 # should match the address at which the breakpoint was set in the dummy
469 # frame.
470 m;struct frame_id;dummy_id;struct frame_info *this_frame;this_frame;;default_dummy_id;;0
471 # Implement DUMMY_ID and PUSH_DUMMY_CALL, then delete
472 # deprecated_fp_regnum.
473 v;int;deprecated_fp_regnum;;;-1;-1;;0
474
475 M;CORE_ADDR;push_dummy_call;struct value *function, struct regcache *regcache, CORE_ADDR bp_addr, int nargs, struct value **args, CORE_ADDR sp, function_call_return_method return_method, CORE_ADDR struct_addr;function, regcache, bp_addr, nargs, args, sp, return_method, struct_addr
476 v;int;call_dummy_location;;;;AT_ENTRY_POINT;;0
477 M;CORE_ADDR;push_dummy_code;CORE_ADDR sp, CORE_ADDR funaddr, struct value **args, int nargs, struct type *value_type, CORE_ADDR *real_pc, CORE_ADDR *bp_addr, struct regcache *regcache;sp, funaddr, args, nargs, value_type, real_pc, bp_addr, regcache
478
479 # Return true if the code of FRAME is writable.
480 m;int;code_of_frame_writable;struct frame_info *frame;frame;;default_code_of_frame_writable;;0
481
482 m;void;print_registers_info;struct ui_file *file, struct frame_info *frame, int regnum, int all;file, frame, regnum, all;;default_print_registers_info;;0
483 m;void;print_float_info;struct ui_file *file, struct frame_info *frame, const char *args;file, frame, args;;default_print_float_info;;0
484 M;void;print_vector_info;struct ui_file *file, struct frame_info *frame, const char *args;file, frame, args
485 # MAP a GDB RAW register number onto a simulator register number. See
486 # also include/...-sim.h.
487 m;int;register_sim_regno;int reg_nr;reg_nr;;legacy_register_sim_regno;;0
488 m;int;cannot_fetch_register;int regnum;regnum;;cannot_register_not;;0
489 m;int;cannot_store_register;int regnum;regnum;;cannot_register_not;;0
490
491 # Determine the address where a longjmp will land and save this address
492 # in PC. Return nonzero on success.
493 #
494 # FRAME corresponds to the longjmp frame.
495 F;int;get_longjmp_target;struct frame_info *frame, CORE_ADDR *pc;frame, pc
496
497 #
498 v;int;believe_pcc_promotion;;;;;;;
499 #
500 m;int;convert_register_p;int regnum, struct type *type;regnum, type;0;generic_convert_register_p;;0
501 f;int;register_to_value;struct frame_info *frame, int regnum, struct type *type, gdb_byte *buf, int *optimizedp, int *unavailablep;frame, regnum, type, buf, optimizedp, unavailablep;0
502 f;void;value_to_register;struct frame_info *frame, int regnum, struct type *type, const gdb_byte *buf;frame, regnum, type, buf;0
503 # Construct a value representing the contents of register REGNUM in
504 # frame FRAME_ID, interpreted as type TYPE. The routine needs to
505 # allocate and return a struct value with all value attributes
506 # (but not the value contents) filled in.
507 m;struct value *;value_from_register;struct type *type, int regnum, struct frame_id frame_id;type, regnum, frame_id;;default_value_from_register;;0
508 #
509 m;CORE_ADDR;pointer_to_address;struct type *type, const gdb_byte *buf;type, buf;;unsigned_pointer_to_address;;0
510 m;void;address_to_pointer;struct type *type, gdb_byte *buf, CORE_ADDR addr;type, buf, addr;;unsigned_address_to_pointer;;0
511 M;CORE_ADDR;integer_to_address;struct type *type, const gdb_byte *buf;type, buf
512
513 # Return the return-value convention that will be used by FUNCTION
514 # to return a value of type VALTYPE. FUNCTION may be NULL in which
515 # case the return convention is computed based only on VALTYPE.
516 #
517 # If READBUF is not NULL, extract the return value and save it in this buffer.
518 #
519 # If WRITEBUF is not NULL, it contains a return value which will be
520 # stored into the appropriate register. This can be used when we want
521 # to force the value returned by a function (see the "return" command
522 # for instance).
523 M;enum return_value_convention;return_value;struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf;function, valtype, regcache, readbuf, writebuf
524
525 # Return true if the return value of function is stored in the first hidden
526 # parameter. In theory, this feature should be language-dependent, specified
527 # by language and its ABI, such as C++. Unfortunately, compiler may
528 # implement it to a target-dependent feature. So that we need such hook here
529 # to be aware of this in GDB.
530 m;int;return_in_first_hidden_param_p;struct type *type;type;;default_return_in_first_hidden_param_p;;0
531
532 m;CORE_ADDR;skip_prologue;CORE_ADDR ip;ip;0;0
533 M;CORE_ADDR;skip_main_prologue;CORE_ADDR ip;ip
534 # On some platforms, a single function may provide multiple entry points,
535 # e.g. one that is used for function-pointer calls and a different one
536 # that is used for direct function calls.
537 # In order to ensure that breakpoints set on the function will trigger
538 # no matter via which entry point the function is entered, a platform
539 # may provide the skip_entrypoint callback. It is called with IP set
540 # to the main entry point of a function (as determined by the symbol table),
541 # and should return the address of the innermost entry point, where the
542 # actual breakpoint needs to be set. Note that skip_entrypoint is used
543 # by GDB common code even when debugging optimized code, where skip_prologue
544 # is not used.
545 M;CORE_ADDR;skip_entrypoint;CORE_ADDR ip;ip
546
547 f;int;inner_than;CORE_ADDR lhs, CORE_ADDR rhs;lhs, rhs;0;0
548 m;const gdb_byte *;breakpoint_from_pc;CORE_ADDR *pcptr, int *lenptr;pcptr, lenptr;0;default_breakpoint_from_pc;;0
549
550 # Return the breakpoint kind for this target based on *PCPTR.
551 m;int;breakpoint_kind_from_pc;CORE_ADDR *pcptr;pcptr;;0;
552
553 # Return the software breakpoint from KIND. KIND can have target
554 # specific meaning like the Z0 kind parameter.
555 # SIZE is set to the software breakpoint's length in memory.
556 m;const gdb_byte *;sw_breakpoint_from_kind;int kind, int *size;kind, size;;NULL;;0
557
558 # Return the breakpoint kind for this target based on the current
559 # processor state (e.g. the current instruction mode on ARM) and the
560 # *PCPTR. In default, it is gdbarch->breakpoint_kind_from_pc.
561 m;int;breakpoint_kind_from_current_state;struct regcache *regcache, CORE_ADDR *pcptr;regcache, pcptr;0;default_breakpoint_kind_from_current_state;;0
562
563 M;CORE_ADDR;adjust_breakpoint_address;CORE_ADDR bpaddr;bpaddr
564 m;int;memory_insert_breakpoint;struct bp_target_info *bp_tgt;bp_tgt;0;default_memory_insert_breakpoint;;0
565 m;int;memory_remove_breakpoint;struct bp_target_info *bp_tgt;bp_tgt;0;default_memory_remove_breakpoint;;0
566 v;CORE_ADDR;decr_pc_after_break;;;0;;;0
567
568 # A function can be addressed by either it's "pointer" (possibly a
569 # descriptor address) or "entry point" (first executable instruction).
570 # The method "convert_from_func_ptr_addr" converting the former to the
571 # latter. gdbarch_deprecated_function_start_offset is being used to implement
572 # a simplified subset of that functionality - the function's address
573 # corresponds to the "function pointer" and the function's start
574 # corresponds to the "function entry point" - and hence is redundant.
575
576 v;CORE_ADDR;deprecated_function_start_offset;;;0;;;0
577
578 # Return the remote protocol register number associated with this
579 # register. Normally the identity mapping.
580 m;int;remote_register_number;int regno;regno;;default_remote_register_number;;0
581
582 # Fetch the target specific address used to represent a load module.
583 F;CORE_ADDR;fetch_tls_load_module_address;struct objfile *objfile;objfile
584
585 # Return the thread-local address at OFFSET in the thread-local
586 # storage for the thread PTID and the shared library or executable
587 # file given by LM_ADDR. If that block of thread-local storage hasn't
588 # been allocated yet, this function may throw an error. LM_ADDR may
589 # be zero for statically linked multithreaded inferiors.
590
591 M;CORE_ADDR;get_thread_local_address;ptid_t ptid, CORE_ADDR lm_addr, CORE_ADDR offset;ptid, lm_addr, offset
592 #
593 v;CORE_ADDR;frame_args_skip;;;0;;;0
594 m;CORE_ADDR;unwind_pc;struct frame_info *next_frame;next_frame;;default_unwind_pc;;0
595 m;CORE_ADDR;unwind_sp;struct frame_info *next_frame;next_frame;;default_unwind_sp;;0
596 # DEPRECATED_FRAME_LOCALS_ADDRESS as been replaced by the per-frame
597 # frame-base. Enable frame-base before frame-unwind.
598 F;int;frame_num_args;struct frame_info *frame;frame
599 #
600 M;CORE_ADDR;frame_align;CORE_ADDR address;address
601 m;int;stabs_argument_has_addr;struct type *type;type;;default_stabs_argument_has_addr;;0
602 v;int;frame_red_zone_size
603 #
604 m;CORE_ADDR;convert_from_func_ptr_addr;CORE_ADDR addr, struct target_ops *targ;addr, targ;;convert_from_func_ptr_addr_identity;;0
605 # On some machines there are bits in addresses which are not really
606 # part of the address, but are used by the kernel, the hardware, etc.
607 # for special purposes. gdbarch_addr_bits_remove takes out any such bits so
608 # we get a "real" address such as one would find in a symbol table.
609 # This is used only for addresses of instructions, and even then I'm
610 # not sure it's used in all contexts. It exists to deal with there
611 # being a few stray bits in the PC which would mislead us, not as some
612 # sort of generic thing to handle alignment or segmentation (it's
613 # possible it should be in TARGET_READ_PC instead).
614 m;CORE_ADDR;addr_bits_remove;CORE_ADDR addr;addr;;core_addr_identity;;0
615
616 # On some machines, not all bits of an address word are significant.
617 # For example, on AArch64, the top bits of an address known as the "tag"
618 # are ignored by the kernel, the hardware, etc. and can be regarded as
619 # additional data associated with the address.
620 v;int;significant_addr_bit;;;;;;0
621
622 # FIXME/cagney/2001-01-18: This should be split in two. A target method that
623 # indicates if the target needs software single step. An ISA method to
624 # implement it.
625 #
626 # FIXME/cagney/2001-01-18: The logic is backwards. It should be asking if the
627 # target can single step. If not, then implement single step using breakpoints.
628 #
629 # Return a vector of addresses on which the software single step
630 # breakpoints should be inserted. NULL means software single step is
631 # not used.
632 # Multiple breakpoints may be inserted for some instructions such as
633 # conditional branch. However, each implementation must always evaluate
634 # the condition and only put the breakpoint at the branch destination if
635 # the condition is true, so that we ensure forward progress when stepping
636 # past a conditional branch to self.
637 F;std::vector<CORE_ADDR>;software_single_step;struct regcache *regcache;regcache
638
639 # Return non-zero if the processor is executing a delay slot and a
640 # further single-step is needed before the instruction finishes.
641 M;int;single_step_through_delay;struct frame_info *frame;frame
642 # FIXME: cagney/2003-08-28: Need to find a better way of selecting the
643 # disassembler. Perhaps objdump can handle it?
644 f;int;print_insn;bfd_vma vma, struct disassemble_info *info;vma, info;;default_print_insn;;0
645 f;CORE_ADDR;skip_trampoline_code;struct frame_info *frame, CORE_ADDR pc;frame, pc;;generic_skip_trampoline_code;;0
646
647
648 # If in_solib_dynsym_resolve_code() returns true, and SKIP_SOLIB_RESOLVER
649 # evaluates non-zero, this is the address where the debugger will place
650 # a step-resume breakpoint to get us past the dynamic linker.
651 m;CORE_ADDR;skip_solib_resolver;CORE_ADDR pc;pc;;generic_skip_solib_resolver;;0
652 # Some systems also have trampoline code for returning from shared libs.
653 m;int;in_solib_return_trampoline;CORE_ADDR pc, const char *name;pc, name;;generic_in_solib_return_trampoline;;0
654
655 # Return true if PC lies inside an indirect branch thunk.
656 m;bool;in_indirect_branch_thunk;CORE_ADDR pc;pc;;default_in_indirect_branch_thunk;;0
657
658 # A target might have problems with watchpoints as soon as the stack
659 # frame of the current function has been destroyed. This mostly happens
660 # as the first action in a function's epilogue. stack_frame_destroyed_p()
661 # is defined to return a non-zero value if either the given addr is one
662 # instruction after the stack destroying instruction up to the trailing
663 # return instruction or if we can figure out that the stack frame has
664 # already been invalidated regardless of the value of addr. Targets
665 # which don't suffer from that problem could just let this functionality
666 # untouched.
667 m;int;stack_frame_destroyed_p;CORE_ADDR addr;addr;0;generic_stack_frame_destroyed_p;;0
668 # Process an ELF symbol in the minimal symbol table in a backend-specific
669 # way. Normally this hook is supposed to do nothing, however if required,
670 # then this hook can be used to apply tranformations to symbols that are
671 # considered special in some way. For example the MIPS backend uses it
672 # to interpret \`st_other' information to mark compressed code symbols so
673 # that they can be treated in the appropriate manner in the processing of
674 # the main symbol table and DWARF-2 records.
675 F;void;elf_make_msymbol_special;asymbol *sym, struct minimal_symbol *msym;sym, msym
676 f;void;coff_make_msymbol_special;int val, struct minimal_symbol *msym;val, msym;;default_coff_make_msymbol_special;;0
677 # Process a symbol in the main symbol table in a backend-specific way.
678 # Normally this hook is supposed to do nothing, however if required,
679 # then this hook can be used to apply tranformations to symbols that
680 # are considered special in some way. This is currently used by the
681 # MIPS backend to make sure compressed code symbols have the ISA bit
682 # set. This in turn is needed for symbol values seen in GDB to match
683 # the values used at the runtime by the program itself, for function
684 # and label references.
685 f;void;make_symbol_special;struct symbol *sym, struct objfile *objfile;sym, objfile;;default_make_symbol_special;;0
686 # Adjust the address retrieved from a DWARF-2 record other than a line
687 # entry in a backend-specific way. Normally this hook is supposed to
688 # return the address passed unchanged, however if that is incorrect for
689 # any reason, then this hook can be used to fix the address up in the
690 # required manner. This is currently used by the MIPS backend to make
691 # sure addresses in FDE, range records, etc. referring to compressed
692 # code have the ISA bit set, matching line information and the symbol
693 # table.
694 f;CORE_ADDR;adjust_dwarf2_addr;CORE_ADDR pc;pc;;default_adjust_dwarf2_addr;;0
695 # Adjust the address updated by a line entry in a backend-specific way.
696 # Normally this hook is supposed to return the address passed unchanged,
697 # however in the case of inconsistencies in these records, this hook can
698 # be used to fix them up in the required manner. This is currently used
699 # by the MIPS backend to make sure all line addresses in compressed code
700 # are presented with the ISA bit set, which is not always the case. This
701 # in turn ensures breakpoint addresses are correctly matched against the
702 # stop PC.
703 f;CORE_ADDR;adjust_dwarf2_line;CORE_ADDR addr, int rel;addr, rel;;default_adjust_dwarf2_line;;0
704 v;int;cannot_step_breakpoint;;;0;0;;0
705 # See comment in target.h about continuable, steppable and
706 # non-steppable watchpoints.
707 v;int;have_nonsteppable_watchpoint;;;0;0;;0
708 F;int;address_class_type_flags;int byte_size, int dwarf2_addr_class;byte_size, dwarf2_addr_class
709 M;const char *;address_class_type_flags_to_name;int type_flags;type_flags
710 # Execute vendor-specific DWARF Call Frame Instruction. OP is the instruction.
711 # FS are passed from the generic execute_cfa_program function.
712 m;bool;execute_dwarf_cfa_vendor_op;gdb_byte op, struct dwarf2_frame_state *fs;op, fs;;default_execute_dwarf_cfa_vendor_op;;0
713
714 # Return the appropriate type_flags for the supplied address class.
715 # This function should return 1 if the address class was recognized and
716 # type_flags was set, zero otherwise.
717 M;int;address_class_name_to_type_flags;const char *name, int *type_flags_ptr;name, type_flags_ptr
718 # Is a register in a group
719 m;int;register_reggroup_p;int regnum, struct reggroup *reggroup;regnum, reggroup;;default_register_reggroup_p;;0
720 # Fetch the pointer to the ith function argument.
721 F;CORE_ADDR;fetch_pointer_argument;struct frame_info *frame, int argi, struct type *type;frame, argi, type
722
723 # Iterate over all supported register notes in a core file. For each
724 # supported register note section, the iterator must call CB and pass
725 # CB_DATA unchanged. If REGCACHE is not NULL, the iterator can limit
726 # the supported register note sections based on the current register
727 # values. Otherwise it should enumerate all supported register note
728 # sections.
729 M;void;iterate_over_regset_sections;iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache;cb, cb_data, regcache
730
731 # Create core file notes
732 M;char *;make_corefile_notes;bfd *obfd, int *note_size;obfd, note_size
733
734 # Find core file memory regions
735 M;int;find_memory_regions;find_memory_region_ftype func, void *data;func, data
736
737 # Read offset OFFSET of TARGET_OBJECT_LIBRARIES formatted shared libraries list from
738 # core file into buffer READBUF with length LEN. Return the number of bytes read
739 # (zero indicates failure).
740 # failed, otherwise, return the red length of READBUF.
741 M;ULONGEST;core_xfer_shared_libraries;gdb_byte *readbuf, ULONGEST offset, ULONGEST len;readbuf, offset, len
742
743 # Read offset OFFSET of TARGET_OBJECT_LIBRARIES_AIX formatted shared
744 # libraries list from core file into buffer READBUF with length LEN.
745 # Return the number of bytes read (zero indicates failure).
746 M;ULONGEST;core_xfer_shared_libraries_aix;gdb_byte *readbuf, ULONGEST offset, ULONGEST len;readbuf, offset, len
747
748 # How the core target converts a PTID from a core file to a string.
749 M;std::string;core_pid_to_str;ptid_t ptid;ptid
750
751 # How the core target extracts the name of a thread from a core file.
752 M;const char *;core_thread_name;struct thread_info *thr;thr
753
754 # Read offset OFFSET of TARGET_OBJECT_SIGNAL_INFO signal information
755 # from core file into buffer READBUF with length LEN. Return the number
756 # of bytes read (zero indicates EOF, a negative value indicates failure).
757 M;LONGEST;core_xfer_siginfo;gdb_byte *readbuf, ULONGEST offset, ULONGEST len; readbuf, offset, len
758
759 # BFD target to use when generating a core file.
760 V;const char *;gcore_bfd_target;;;0;0;;;pstring (gdbarch->gcore_bfd_target)
761
762 # If the elements of C++ vtables are in-place function descriptors rather
763 # than normal function pointers (which may point to code or a descriptor),
764 # set this to one.
765 v;int;vtable_function_descriptors;;;0;0;;0
766
767 # Set if the least significant bit of the delta is used instead of the least
768 # significant bit of the pfn for pointers to virtual member functions.
769 v;int;vbit_in_delta;;;0;0;;0
770
771 # Advance PC to next instruction in order to skip a permanent breakpoint.
772 f;void;skip_permanent_breakpoint;struct regcache *regcache;regcache;default_skip_permanent_breakpoint;default_skip_permanent_breakpoint;;0
773
774 # The maximum length of an instruction on this architecture in bytes.
775 V;ULONGEST;max_insn_length;;;0;0
776
777 # Copy the instruction at FROM to TO, and make any adjustments
778 # necessary to single-step it at that address.
779 #
780 # REGS holds the state the thread's registers will have before
781 # executing the copied instruction; the PC in REGS will refer to FROM,
782 # not the copy at TO. The caller should update it to point at TO later.
783 #
784 # Return a pointer to data of the architecture's choice to be passed
785 # to gdbarch_displaced_step_fixup. Or, return NULL to indicate that
786 # the instruction's effects have been completely simulated, with the
787 # resulting state written back to REGS.
788 #
789 # For a general explanation of displaced stepping and how GDB uses it,
790 # see the comments in infrun.c.
791 #
792 # The TO area is only guaranteed to have space for
793 # gdbarch_max_insn_length (arch) bytes, so this function must not
794 # write more bytes than that to that area.
795 #
796 # If you do not provide this function, GDB assumes that the
797 # architecture does not support displaced stepping.
798 #
799 # If the instruction cannot execute out of line, return NULL. The
800 # core falls back to stepping past the instruction in-line instead in
801 # that case.
802 M;displaced_step_closure_up;displaced_step_copy_insn;CORE_ADDR from, CORE_ADDR to, struct regcache *regs;from, to, regs
803
804 # Return true if GDB should use hardware single-stepping to execute
805 # the displaced instruction identified by CLOSURE. If false,
806 # GDB will simply restart execution at the displaced instruction
807 # location, and it is up to the target to ensure GDB will receive
808 # control again (e.g. by placing a software breakpoint instruction
809 # into the displaced instruction buffer).
810 #
811 # The default implementation returns false on all targets that
812 # provide a gdbarch_software_single_step routine, and true otherwise.
813 m;int;displaced_step_hw_singlestep;struct displaced_step_closure *closure;closure;;default_displaced_step_hw_singlestep;;0
814
815 # Fix up the state resulting from successfully single-stepping a
816 # displaced instruction, to give the result we would have gotten from
817 # stepping the instruction in its original location.
818 #
819 # REGS is the register state resulting from single-stepping the
820 # displaced instruction.
821 #
822 # CLOSURE is the result from the matching call to
823 # gdbarch_displaced_step_copy_insn.
824 #
825 # If you provide gdbarch_displaced_step_copy_insn.but not this
826 # function, then GDB assumes that no fixup is needed after
827 # single-stepping the instruction.
828 #
829 # For a general explanation of displaced stepping and how GDB uses it,
830 # see the comments in infrun.c.
831 M;void;displaced_step_fixup;struct displaced_step_closure *closure, CORE_ADDR from, CORE_ADDR to, struct regcache *regs;closure, from, to, regs;;NULL
832
833 # Return the address of an appropriate place to put displaced
834 # instructions while we step over them. There need only be one such
835 # place, since we're only stepping one thread over a breakpoint at a
836 # time.
837 #
838 # For a general explanation of displaced stepping and how GDB uses it,
839 # see the comments in infrun.c.
840 m;CORE_ADDR;displaced_step_location;void;;;NULL;;(! gdbarch->displaced_step_location) != (! gdbarch->displaced_step_copy_insn)
841
842 # Relocate an instruction to execute at a different address. OLDLOC
843 # is the address in the inferior memory where the instruction to
844 # relocate is currently at. On input, TO points to the destination
845 # where we want the instruction to be copied (and possibly adjusted)
846 # to. On output, it points to one past the end of the resulting
847 # instruction(s). The effect of executing the instruction at TO shall
848 # be the same as if executing it at FROM. For example, call
849 # instructions that implicitly push the return address on the stack
850 # should be adjusted to return to the instruction after OLDLOC;
851 # relative branches, and other PC-relative instructions need the
852 # offset adjusted; etc.
853 M;void;relocate_instruction;CORE_ADDR *to, CORE_ADDR from;to, from;;NULL
854
855 # Refresh overlay mapped state for section OSECT.
856 F;void;overlay_update;struct obj_section *osect;osect
857
858 M;const struct target_desc *;core_read_description;struct target_ops *target, bfd *abfd;target, abfd
859
860 # Handle special encoding of static variables in stabs debug info.
861 F;const char *;static_transform_name;const char *name;name
862 # Set if the address in N_SO or N_FUN stabs may be zero.
863 v;int;sofun_address_maybe_missing;;;0;0;;0
864
865 # Parse the instruction at ADDR storing in the record execution log
866 # the registers REGCACHE and memory ranges that will be affected when
867 # the instruction executes, along with their current values.
868 # Return -1 if something goes wrong, 0 otherwise.
869 M;int;process_record;struct regcache *regcache, CORE_ADDR addr;regcache, addr
870
871 # Save process state after a signal.
872 # Return -1 if something goes wrong, 0 otherwise.
873 M;int;process_record_signal;struct regcache *regcache, enum gdb_signal signal;regcache, signal
874
875 # Signal translation: translate inferior's signal (target's) number
876 # into GDB's representation. The implementation of this method must
877 # be host independent. IOW, don't rely on symbols of the NAT_FILE
878 # header (the nm-*.h files), the host <signal.h> header, or similar
879 # headers. This is mainly used when cross-debugging core files ---
880 # "Live" targets hide the translation behind the target interface
881 # (target_wait, target_resume, etc.).
882 M;enum gdb_signal;gdb_signal_from_target;int signo;signo
883
884 # Signal translation: translate the GDB's internal signal number into
885 # the inferior's signal (target's) representation. The implementation
886 # of this method must be host independent. IOW, don't rely on symbols
887 # of the NAT_FILE header (the nm-*.h files), the host <signal.h>
888 # header, or similar headers.
889 # Return the target signal number if found, or -1 if the GDB internal
890 # signal number is invalid.
891 M;int;gdb_signal_to_target;enum gdb_signal signal;signal
892
893 # Extra signal info inspection.
894 #
895 # Return a type suitable to inspect extra signal information.
896 M;struct type *;get_siginfo_type;void;
897
898 # Record architecture-specific information from the symbol table.
899 M;void;record_special_symbol;struct objfile *objfile, asymbol *sym;objfile, sym
900
901 # Function for the 'catch syscall' feature.
902
903 # Get architecture-specific system calls information from registers.
904 M;LONGEST;get_syscall_number;thread_info *thread;thread
905
906 # The filename of the XML syscall for this architecture.
907 v;const char *;xml_syscall_file;;;0;0;;0;pstring (gdbarch->xml_syscall_file)
908
909 # Information about system calls from this architecture
910 v;struct syscalls_info *;syscalls_info;;;0;0;;0;host_address_to_string (gdbarch->syscalls_info)
911
912 # SystemTap related fields and functions.
913
914 # A NULL-terminated array of prefixes used to mark an integer constant
915 # on the architecture's assembly.
916 # For example, on x86 integer constants are written as:
917 #
918 # \$10 ;; integer constant 10
919 #
920 # in this case, this prefix would be the character \`\$\'.
921 v;const char *const *;stap_integer_prefixes;;;0;0;;0;pstring_list (gdbarch->stap_integer_prefixes)
922
923 # A NULL-terminated array of suffixes used to mark an integer constant
924 # on the architecture's assembly.
925 v;const char *const *;stap_integer_suffixes;;;0;0;;0;pstring_list (gdbarch->stap_integer_suffixes)
926
927 # A NULL-terminated array of prefixes used to mark a register name on
928 # the architecture's assembly.
929 # For example, on x86 the register name is written as:
930 #
931 # \%eax ;; register eax
932 #
933 # in this case, this prefix would be the character \`\%\'.
934 v;const char *const *;stap_register_prefixes;;;0;0;;0;pstring_list (gdbarch->stap_register_prefixes)
935
936 # A NULL-terminated array of suffixes used to mark a register name on
937 # the architecture's assembly.
938 v;const char *const *;stap_register_suffixes;;;0;0;;0;pstring_list (gdbarch->stap_register_suffixes)
939
940 # A NULL-terminated array of prefixes used to mark a register
941 # indirection on the architecture's assembly.
942 # For example, on x86 the register indirection is written as:
943 #
944 # \(\%eax\) ;; indirecting eax
945 #
946 # in this case, this prefix would be the charater \`\(\'.
947 #
948 # Please note that we use the indirection prefix also for register
949 # displacement, e.g., \`4\(\%eax\)\' on x86.
950 v;const char *const *;stap_register_indirection_prefixes;;;0;0;;0;pstring_list (gdbarch->stap_register_indirection_prefixes)
951
952 # A NULL-terminated array of suffixes used to mark a register
953 # indirection on the architecture's assembly.
954 # For example, on x86 the register indirection is written as:
955 #
956 # \(\%eax\) ;; indirecting eax
957 #
958 # in this case, this prefix would be the charater \`\)\'.
959 #
960 # Please note that we use the indirection suffix also for register
961 # displacement, e.g., \`4\(\%eax\)\' on x86.
962 v;const char *const *;stap_register_indirection_suffixes;;;0;0;;0;pstring_list (gdbarch->stap_register_indirection_suffixes)
963
964 # Prefix(es) used to name a register using GDB's nomenclature.
965 #
966 # For example, on PPC a register is represented by a number in the assembly
967 # language (e.g., \`10\' is the 10th general-purpose register). However,
968 # inside GDB this same register has an \`r\' appended to its name, so the 10th
969 # register would be represented as \`r10\' internally.
970 v;const char *;stap_gdb_register_prefix;;;0;0;;0;pstring (gdbarch->stap_gdb_register_prefix)
971
972 # Suffix used to name a register using GDB's nomenclature.
973 v;const char *;stap_gdb_register_suffix;;;0;0;;0;pstring (gdbarch->stap_gdb_register_suffix)
974
975 # Check if S is a single operand.
976 #
977 # Single operands can be:
978 # \- Literal integers, e.g. \`\$10\' on x86
979 # \- Register access, e.g. \`\%eax\' on x86
980 # \- Register indirection, e.g. \`\(\%eax\)\' on x86
981 # \- Register displacement, e.g. \`4\(\%eax\)\' on x86
982 #
983 # This function should check for these patterns on the string
984 # and return 1 if some were found, or zero otherwise. Please try to match
985 # as much info as you can from the string, i.e., if you have to match
986 # something like \`\(\%\', do not match just the \`\(\'.
987 M;int;stap_is_single_operand;const char *s;s
988
989 # Function used to handle a "special case" in the parser.
990 #
991 # A "special case" is considered to be an unknown token, i.e., a token
992 # that the parser does not know how to parse. A good example of special
993 # case would be ARM's register displacement syntax:
994 #
995 # [R0, #4] ;; displacing R0 by 4
996 #
997 # Since the parser assumes that a register displacement is of the form:
998 #
999 # <number> <indirection_prefix> <register_name> <indirection_suffix>
1000 #
1001 # it means that it will not be able to recognize and parse this odd syntax.
1002 # Therefore, we should add a special case function that will handle this token.
1003 #
1004 # This function should generate the proper expression form of the expression
1005 # using GDB\'s internal expression mechanism (e.g., \`write_exp_elt_opcode\'
1006 # and so on). It should also return 1 if the parsing was successful, or zero
1007 # if the token was not recognized as a special token (in this case, returning
1008 # zero means that the special parser is deferring the parsing to the generic
1009 # parser), and should advance the buffer pointer (p->arg).
1010 M;int;stap_parse_special_token;struct stap_parse_info *p;p
1011
1012 # Perform arch-dependent adjustments to a register name.
1013 #
1014 # In very specific situations, it may be necessary for the register
1015 # name present in a SystemTap probe's argument to be handled in a
1016 # special way. For example, on i386, GCC may over-optimize the
1017 # register allocation and use smaller registers than necessary. In
1018 # such cases, the client that is reading and evaluating the SystemTap
1019 # probe (ourselves) will need to actually fetch values from the wider
1020 # version of the register in question.
1021 #
1022 # To illustrate the example, consider the following probe argument
1023 # (i386):
1024 #
1025 # 4@%ax
1026 #
1027 # This argument says that its value can be found at the %ax register,
1028 # which is a 16-bit register. However, the argument's prefix says
1029 # that its type is "uint32_t", which is 32-bit in size. Therefore, in
1030 # this case, GDB should actually fetch the probe's value from register
1031 # %eax, not %ax. In this scenario, this function would actually
1032 # replace the register name from %ax to %eax.
1033 #
1034 # The rationale for this can be found at PR breakpoints/24541.
1035 M;std::string;stap_adjust_register;struct stap_parse_info *p, const std::string \&regname, int regnum;p, regname, regnum
1036
1037 # DTrace related functions.
1038
1039 # The expression to compute the NARTGth+1 argument to a DTrace USDT probe.
1040 # NARG must be >= 0.
1041 M;void;dtrace_parse_probe_argument;struct expr_builder *builder, int narg;builder, narg
1042
1043 # True if the given ADDR does not contain the instruction sequence
1044 # corresponding to a disabled DTrace is-enabled probe.
1045 M;int;dtrace_probe_is_enabled;CORE_ADDR addr;addr
1046
1047 # Enable a DTrace is-enabled probe at ADDR.
1048 M;void;dtrace_enable_probe;CORE_ADDR addr;addr
1049
1050 # Disable a DTrace is-enabled probe at ADDR.
1051 M;void;dtrace_disable_probe;CORE_ADDR addr;addr
1052
1053 # True if the list of shared libraries is one and only for all
1054 # processes, as opposed to a list of shared libraries per inferior.
1055 # This usually means that all processes, although may or may not share
1056 # an address space, will see the same set of symbols at the same
1057 # addresses.
1058 v;int;has_global_solist;;;0;0;;0
1059
1060 # On some targets, even though each inferior has its own private
1061 # address space, the debug interface takes care of making breakpoints
1062 # visible to all address spaces automatically. For such cases,
1063 # this property should be set to true.
1064 v;int;has_global_breakpoints;;;0;0;;0
1065
1066 # True if inferiors share an address space (e.g., uClinux).
1067 m;int;has_shared_address_space;void;;;default_has_shared_address_space;;0
1068
1069 # True if a fast tracepoint can be set at an address.
1070 m;int;fast_tracepoint_valid_at;CORE_ADDR addr, std::string *msg;addr, msg;;default_fast_tracepoint_valid_at;;0
1071
1072 # Guess register state based on tracepoint location. Used for tracepoints
1073 # where no registers have been collected, but there's only one location,
1074 # allowing us to guess the PC value, and perhaps some other registers.
1075 # On entry, regcache has all registers marked as unavailable.
1076 m;void;guess_tracepoint_registers;struct regcache *regcache, CORE_ADDR addr;regcache, addr;;default_guess_tracepoint_registers;;0
1077
1078 # Return the "auto" target charset.
1079 f;const char *;auto_charset;void;;default_auto_charset;default_auto_charset;;0
1080 # Return the "auto" target wide charset.
1081 f;const char *;auto_wide_charset;void;;default_auto_wide_charset;default_auto_wide_charset;;0
1082
1083 # If non-empty, this is a file extension that will be opened in place
1084 # of the file extension reported by the shared library list.
1085 #
1086 # This is most useful for toolchains that use a post-linker tool,
1087 # where the names of the files run on the target differ in extension
1088 # compared to the names of the files GDB should load for debug info.
1089 v;const char *;solib_symbols_extension;;;;;;;pstring (gdbarch->solib_symbols_extension)
1090
1091 # If true, the target OS has DOS-based file system semantics. That
1092 # is, absolute paths include a drive name, and the backslash is
1093 # considered a directory separator.
1094 v;int;has_dos_based_file_system;;;0;0;;0
1095
1096 # Generate bytecodes to collect the return address in a frame.
1097 # Since the bytecodes run on the target, possibly with GDB not even
1098 # connected, the full unwinding machinery is not available, and
1099 # typically this function will issue bytecodes for one or more likely
1100 # places that the return address may be found.
1101 m;void;gen_return_address;struct agent_expr *ax, struct axs_value *value, CORE_ADDR scope;ax, value, scope;;default_gen_return_address;;0
1102
1103 # Implement the "info proc" command.
1104 M;void;info_proc;const char *args, enum info_proc_what what;args, what
1105
1106 # Implement the "info proc" command for core files. Noe that there
1107 # are two "info_proc"-like methods on gdbarch -- one for core files,
1108 # one for live targets.
1109 M;void;core_info_proc;const char *args, enum info_proc_what what;args, what
1110
1111 # Iterate over all objfiles in the order that makes the most sense
1112 # for the architecture to make global symbol searches.
1113 #
1114 # CB is a callback function where OBJFILE is the objfile to be searched,
1115 # and CB_DATA a pointer to user-defined data (the same data that is passed
1116 # when calling this gdbarch method). The iteration stops if this function
1117 # returns nonzero.
1118 #
1119 # CB_DATA is a pointer to some user-defined data to be passed to
1120 # the callback.
1121 #
1122 # If not NULL, CURRENT_OBJFILE corresponds to the objfile being
1123 # inspected when the symbol search was requested.
1124 m;void;iterate_over_objfiles_in_search_order;iterate_over_objfiles_in_search_order_cb_ftype *cb, void *cb_data, struct objfile *current_objfile;cb, cb_data, current_objfile;0;default_iterate_over_objfiles_in_search_order;;0
1125
1126 # Ravenscar arch-dependent ops.
1127 v;struct ravenscar_arch_ops *;ravenscar_ops;;;NULL;NULL;;0;host_address_to_string (gdbarch->ravenscar_ops)
1128
1129 # Return non-zero if the instruction at ADDR is a call; zero otherwise.
1130 m;int;insn_is_call;CORE_ADDR addr;addr;;default_insn_is_call;;0
1131
1132 # Return non-zero if the instruction at ADDR is a return; zero otherwise.
1133 m;int;insn_is_ret;CORE_ADDR addr;addr;;default_insn_is_ret;;0
1134
1135 # Return non-zero if the instruction at ADDR is a jump; zero otherwise.
1136 m;int;insn_is_jump;CORE_ADDR addr;addr;;default_insn_is_jump;;0
1137
1138 # Return true if there's a program/permanent breakpoint planted in
1139 # memory at ADDRESS, return false otherwise.
1140 m;bool;program_breakpoint_here_p;CORE_ADDR address;address;;default_program_breakpoint_here_p;;0
1141
1142 # Read one auxv entry from *READPTR, not reading locations >= ENDPTR.
1143 # Return 0 if *READPTR is already at the end of the buffer.
1144 # Return -1 if there is insufficient buffer for a whole entry.
1145 # Return 1 if an entry was read into *TYPEP and *VALP.
1146 M;int;auxv_parse;gdb_byte **readptr, gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp;readptr, endptr, typep, valp
1147
1148 # Print the description of a single auxv entry described by TYPE and VAL
1149 # to FILE.
1150 m;void;print_auxv_entry;struct ui_file *file, CORE_ADDR type, CORE_ADDR val;file, type, val;;default_print_auxv_entry;;0
1151
1152 # Find the address range of the current inferior's vsyscall/vDSO, and
1153 # write it to *RANGE. If the vsyscall's length can't be determined, a
1154 # range with zero length is returned. Returns true if the vsyscall is
1155 # found, false otherwise.
1156 m;int;vsyscall_range;struct mem_range *range;range;;default_vsyscall_range;;0
1157
1158 # Allocate SIZE bytes of PROT protected page aligned memory in inferior.
1159 # PROT has GDB_MMAP_PROT_* bitmask format.
1160 # Throw an error if it is not possible. Returned address is always valid.
1161 f;CORE_ADDR;infcall_mmap;CORE_ADDR size, unsigned prot;size, prot;;default_infcall_mmap;;0
1162
1163 # Deallocate SIZE bytes of memory at ADDR in inferior from gdbarch_infcall_mmap.
1164 # Print a warning if it is not possible.
1165 f;void;infcall_munmap;CORE_ADDR addr, CORE_ADDR size;addr, size;;default_infcall_munmap;;0
1166
1167 # Return string (caller has to use xfree for it) with options for GCC
1168 # to produce code for this target, typically "-m64", "-m32" or "-m31".
1169 # These options are put before CU's DW_AT_producer compilation options so that
1170 # they can override it.
1171 m;std::string;gcc_target_options;void;;;default_gcc_target_options;;0
1172
1173 # Return a regular expression that matches names used by this
1174 # architecture in GNU configury triplets. The result is statically
1175 # allocated and must not be freed. The default implementation simply
1176 # returns the BFD architecture name, which is correct in nearly every
1177 # case.
1178 m;const char *;gnu_triplet_regexp;void;;;default_gnu_triplet_regexp;;0
1179
1180 # Return the size in 8-bit bytes of an addressable memory unit on this
1181 # architecture. This corresponds to the number of 8-bit bytes associated to
1182 # each address in memory.
1183 m;int;addressable_memory_unit_size;void;;;default_addressable_memory_unit_size;;0
1184
1185 # Functions for allowing a target to modify its disassembler options.
1186 v;const char *;disassembler_options_implicit;;;0;0;;0;pstring (gdbarch->disassembler_options_implicit)
1187 v;char **;disassembler_options;;;0;0;;0;pstring_ptr (gdbarch->disassembler_options)
1188 v;const disasm_options_and_args_t *;valid_disassembler_options;;;0;0;;0;host_address_to_string (gdbarch->valid_disassembler_options)
1189
1190 # Type alignment override method. Return the architecture specific
1191 # alignment required for TYPE. If there is no special handling
1192 # required for TYPE then return the value 0, GDB will then apply the
1193 # default rules as laid out in gdbtypes.c:type_align.
1194 m;ULONGEST;type_align;struct type *type;type;;default_type_align;;0
1195
1196 # Return a string containing any flags for the given PC in the given FRAME.
1197 f;std::string;get_pc_address_flags;frame_info *frame, CORE_ADDR pc;frame, pc;;default_get_pc_address_flags;;0
1198
1199 EOF
1200 }
1201
1202 #
1203 # The .log file
1204 #
1205 exec > new-gdbarch.log
1206 function_list | while do_read
1207 do
1208 cat <<EOF
1209 ${class} ${returntype} ${function} ($formal)
1210 EOF
1211 for r in ${read}
1212 do
1213 eval echo "\" ${r}=\${${r}}\""
1214 done
1215 if class_is_predicate_p && fallback_default_p
1216 then
1217 echo "Error: predicate function ${function} can not have a non- multi-arch default" 1>&2
1218 kill $$
1219 exit 1
1220 fi
1221 if [ "x${invalid_p}" = "x0" ] && [ -n "${postdefault}" ]
1222 then
1223 echo "Error: postdefault is useless when invalid_p=0" 1>&2
1224 kill $$
1225 exit 1
1226 fi
1227 if class_is_multiarch_p
1228 then
1229 if class_is_predicate_p ; then :
1230 elif test "x${predefault}" = "x"
1231 then
1232 echo "Error: pure multi-arch function ${function} must have a predefault" 1>&2
1233 kill $$
1234 exit 1
1235 fi
1236 fi
1237 echo ""
1238 done
1239
1240 exec 1>&2
1241 compare_new gdbarch.log
1242
1243
1244 copyright ()
1245 {
1246 cat <<EOF
1247 /* *INDENT-OFF* */ /* THIS FILE IS GENERATED -*- buffer-read-only: t -*- */
1248 /* vi:set ro: */
1249
1250 /* Dynamic architecture support for GDB, the GNU debugger.
1251
1252 Copyright (C) 1998-2020 Free Software Foundation, Inc.
1253
1254 This file is part of GDB.
1255
1256 This program is free software; you can redistribute it and/or modify
1257 it under the terms of the GNU General Public License as published by
1258 the Free Software Foundation; either version 3 of the License, or
1259 (at your option) any later version.
1260
1261 This program is distributed in the hope that it will be useful,
1262 but WITHOUT ANY WARRANTY; without even the implied warranty of
1263 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1264 GNU General Public License for more details.
1265
1266 You should have received a copy of the GNU General Public License
1267 along with this program. If not, see <http://www.gnu.org/licenses/>. */
1268
1269 /* This file was created with the aid of \`\`gdbarch.sh''.
1270
1271 The Bourne shell script \`\`gdbarch.sh'' creates the files
1272 \`\`new-gdbarch.c'' and \`\`new-gdbarch.h and then compares them
1273 against the existing \`\`gdbarch.[hc]''. Any differences found
1274 being reported.
1275
1276 If editing this file, please also run gdbarch.sh and merge any
1277 changes into that script. Conversely, when making sweeping changes
1278 to this file, modifying gdbarch.sh and using its output may prove
1279 easier. */
1280
1281 EOF
1282 }
1283
1284 #
1285 # The .h file
1286 #
1287
1288 exec > new-gdbarch.h
1289 copyright
1290 cat <<EOF
1291 #ifndef GDBARCH_H
1292 #define GDBARCH_H
1293
1294 #include <vector>
1295 #include "frame.h"
1296 #include "dis-asm.h"
1297 #include "gdb_obstack.h"
1298 #include "infrun.h"
1299 #include "osabi.h"
1300
1301 struct floatformat;
1302 struct ui_file;
1303 struct value;
1304 struct objfile;
1305 struct obj_section;
1306 struct minimal_symbol;
1307 struct regcache;
1308 struct reggroup;
1309 struct regset;
1310 struct disassemble_info;
1311 struct target_ops;
1312 struct obstack;
1313 struct bp_target_info;
1314 struct target_desc;
1315 struct symbol;
1316 struct syscall;
1317 struct agent_expr;
1318 struct axs_value;
1319 struct stap_parse_info;
1320 struct expr_builder;
1321 struct ravenscar_arch_ops;
1322 struct mem_range;
1323 struct syscalls_info;
1324 struct thread_info;
1325 struct ui_out;
1326
1327 #include "regcache.h"
1328
1329 /* The architecture associated with the inferior through the
1330 connection to the target.
1331
1332 The architecture vector provides some information that is really a
1333 property of the inferior, accessed through a particular target:
1334 ptrace operations; the layout of certain RSP packets; the solib_ops
1335 vector; etc. To differentiate architecture accesses to
1336 per-inferior/target properties from
1337 per-thread/per-frame/per-objfile properties, accesses to
1338 per-inferior/target properties should be made through this
1339 gdbarch. */
1340
1341 /* This is a convenience wrapper for 'current_inferior ()->gdbarch'. */
1342 extern struct gdbarch *target_gdbarch (void);
1343
1344 /* Callback type for the 'iterate_over_objfiles_in_search_order'
1345 gdbarch method. */
1346
1347 typedef int (iterate_over_objfiles_in_search_order_cb_ftype)
1348 (struct objfile *objfile, void *cb_data);
1349
1350 /* Callback type for regset section iterators. The callback usually
1351 invokes the REGSET's supply or collect method, to which it must
1352 pass a buffer - for collects this buffer will need to be created using
1353 COLLECT_SIZE, for supply the existing buffer being read from should
1354 be at least SUPPLY_SIZE. SECT_NAME is a BFD section name, and HUMAN_NAME
1355 is used for diagnostic messages. CB_DATA should have been passed
1356 unchanged through the iterator. */
1357
1358 typedef void (iterate_over_regset_sections_cb)
1359 (const char *sect_name, int supply_size, int collect_size,
1360 const struct regset *regset, const char *human_name, void *cb_data);
1361
1362 /* For a function call, does the function return a value using a
1363 normal value return or a structure return - passing a hidden
1364 argument pointing to storage. For the latter, there are two
1365 cases: language-mandated structure return and target ABI
1366 structure return. */
1367
1368 enum function_call_return_method
1369 {
1370 /* Standard value return. */
1371 return_method_normal = 0,
1372
1373 /* Language ABI structure return. This is handled
1374 by passing the return location as the first parameter to
1375 the function, even preceding "this". */
1376 return_method_hidden_param,
1377
1378 /* Target ABI struct return. This is target-specific; for instance,
1379 on ia64 the first argument is passed in out0 but the hidden
1380 structure return pointer would normally be passed in r8. */
1381 return_method_struct,
1382 };
1383
1384 EOF
1385
1386 # function typedef's
1387 printf "\n"
1388 printf "\n"
1389 printf "/* The following are pre-initialized by GDBARCH. */\n"
1390 function_list | while do_read
1391 do
1392 if class_is_info_p
1393 then
1394 printf "\n"
1395 printf "extern %s gdbarch_%s (struct gdbarch *gdbarch);\n" "$returntype" "$function"
1396 printf "/* set_gdbarch_%s() - not applicable - pre-initialized. */\n" "$function"
1397 fi
1398 done
1399
1400 # function typedef's
1401 printf "\n"
1402 printf "\n"
1403 printf "/* The following are initialized by the target dependent code. */\n"
1404 function_list | while do_read
1405 do
1406 if [ -n "${comment}" ]
1407 then
1408 echo "${comment}" | sed \
1409 -e '2 s,#,/*,' \
1410 -e '3,$ s,#, ,' \
1411 -e '$ s,$, */,'
1412 fi
1413
1414 if class_is_predicate_p
1415 then
1416 printf "\n"
1417 printf "extern int gdbarch_%s_p (struct gdbarch *gdbarch);\n" "$function"
1418 fi
1419 if class_is_variable_p
1420 then
1421 printf "\n"
1422 printf "extern %s gdbarch_%s (struct gdbarch *gdbarch);\n" "$returntype" "$function"
1423 printf "extern void set_gdbarch_%s (struct gdbarch *gdbarch, %s %s);\n" "$function" "$returntype" "$function"
1424 fi
1425 if class_is_function_p
1426 then
1427 printf "\n"
1428 if [ "x${formal}" = "xvoid" ] && class_is_multiarch_p
1429 then
1430 printf "typedef %s (gdbarch_%s_ftype) (struct gdbarch *gdbarch);\n" "$returntype" "$function"
1431 elif class_is_multiarch_p
1432 then
1433 printf "typedef %s (gdbarch_%s_ftype) (struct gdbarch *gdbarch, %s);\n" "$returntype" "$function" "$formal"
1434 else
1435 printf "typedef %s (gdbarch_%s_ftype) (%s);\n" "$returntype" "$function" "$formal"
1436 fi
1437 if [ "x${formal}" = "xvoid" ]
1438 then
1439 printf "extern %s gdbarch_%s (struct gdbarch *gdbarch);\n" "$returntype" "$function"
1440 else
1441 printf "extern %s gdbarch_%s (struct gdbarch *gdbarch, %s);\n" "$returntype" "$function" "$formal"
1442 fi
1443 printf "extern void set_gdbarch_%s (struct gdbarch *gdbarch, gdbarch_%s_ftype *%s);\n" "$function" "$function" "$function"
1444 fi
1445 done
1446
1447 # close it off
1448 cat <<EOF
1449
1450 extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);
1451
1452
1453 /* Mechanism for co-ordinating the selection of a specific
1454 architecture.
1455
1456 GDB targets (*-tdep.c) can register an interest in a specific
1457 architecture. Other GDB components can register a need to maintain
1458 per-architecture data.
1459
1460 The mechanisms below ensures that there is only a loose connection
1461 between the set-architecture command and the various GDB
1462 components. Each component can independently register their need
1463 to maintain architecture specific data with gdbarch.
1464
1465 Pragmatics:
1466
1467 Previously, a single TARGET_ARCHITECTURE_HOOK was provided. It
1468 didn't scale.
1469
1470 The more traditional mega-struct containing architecture specific
1471 data for all the various GDB components was also considered. Since
1472 GDB is built from a variable number of (fairly independent)
1473 components it was determined that the global aproach was not
1474 applicable. */
1475
1476
1477 /* Register a new architectural family with GDB.
1478
1479 Register support for the specified ARCHITECTURE with GDB. When
1480 gdbarch determines that the specified architecture has been
1481 selected, the corresponding INIT function is called.
1482
1483 --
1484
1485 The INIT function takes two parameters: INFO which contains the
1486 information available to gdbarch about the (possibly new)
1487 architecture; ARCHES which is a list of the previously created
1488 \`\`struct gdbarch'' for this architecture.
1489
1490 The INFO parameter is, as far as possible, be pre-initialized with
1491 information obtained from INFO.ABFD or the global defaults.
1492
1493 The ARCHES parameter is a linked list (sorted most recently used)
1494 of all the previously created architures for this architecture
1495 family. The (possibly NULL) ARCHES->gdbarch can used to access
1496 values from the previously selected architecture for this
1497 architecture family.
1498
1499 The INIT function shall return any of: NULL - indicating that it
1500 doesn't recognize the selected architecture; an existing \`\`struct
1501 gdbarch'' from the ARCHES list - indicating that the new
1502 architecture is just a synonym for an earlier architecture (see
1503 gdbarch_list_lookup_by_info()); a newly created \`\`struct gdbarch''
1504 - that describes the selected architecture (see gdbarch_alloc()).
1505
1506 The DUMP_TDEP function shall print out all target specific values.
1507 Care should be taken to ensure that the function works in both the
1508 multi-arch and non- multi-arch cases. */
1509
1510 struct gdbarch_list
1511 {
1512 struct gdbarch *gdbarch;
1513 struct gdbarch_list *next;
1514 };
1515
1516 struct gdbarch_info
1517 {
1518 /* Use default: NULL (ZERO). */
1519 const struct bfd_arch_info *bfd_arch_info;
1520
1521 /* Use default: BFD_ENDIAN_UNKNOWN (NB: is not ZERO). */
1522 enum bfd_endian byte_order;
1523
1524 enum bfd_endian byte_order_for_code;
1525
1526 /* Use default: NULL (ZERO). */
1527 bfd *abfd;
1528
1529 /* Use default: NULL (ZERO). */
1530 union
1531 {
1532 /* Architecture-specific information. The generic form for targets
1533 that have extra requirements. */
1534 struct gdbarch_tdep_info *tdep_info;
1535
1536 /* Architecture-specific target description data. Numerous targets
1537 need only this, so give them an easy way to hold it. */
1538 struct tdesc_arch_data *tdesc_data;
1539
1540 /* SPU file system ID. This is a single integer, so using the
1541 generic form would only complicate code. Other targets may
1542 reuse this member if suitable. */
1543 int *id;
1544 };
1545
1546 /* Use default: GDB_OSABI_UNINITIALIZED (-1). */
1547 enum gdb_osabi osabi;
1548
1549 /* Use default: NULL (ZERO). */
1550 const struct target_desc *target_desc;
1551 };
1552
1553 typedef struct gdbarch *(gdbarch_init_ftype) (struct gdbarch_info info, struct gdbarch_list *arches);
1554 typedef void (gdbarch_dump_tdep_ftype) (struct gdbarch *gdbarch, struct ui_file *file);
1555
1556 /* DEPRECATED - use gdbarch_register() */
1557 extern void register_gdbarch_init (enum bfd_architecture architecture, gdbarch_init_ftype *);
1558
1559 extern void gdbarch_register (enum bfd_architecture architecture,
1560 gdbarch_init_ftype *,
1561 gdbarch_dump_tdep_ftype *);
1562
1563
1564 /* Return a freshly allocated, NULL terminated, array of the valid
1565 architecture names. Since architectures are registered during the
1566 _initialize phase this function only returns useful information
1567 once initialization has been completed. */
1568
1569 extern const char **gdbarch_printable_names (void);
1570
1571
1572 /* Helper function. Search the list of ARCHES for a GDBARCH that
1573 matches the information provided by INFO. */
1574
1575 extern struct gdbarch_list *gdbarch_list_lookup_by_info (struct gdbarch_list *arches, const struct gdbarch_info *info);
1576
1577
1578 /* Helper function. Create a preliminary \`\`struct gdbarch''. Perform
1579 basic initialization using values obtained from the INFO and TDEP
1580 parameters. set_gdbarch_*() functions are called to complete the
1581 initialization of the object. */
1582
1583 extern struct gdbarch *gdbarch_alloc (const struct gdbarch_info *info, struct gdbarch_tdep *tdep);
1584
1585
1586 /* Helper function. Free a partially-constructed \`\`struct gdbarch''.
1587 It is assumed that the caller freeds the \`\`struct
1588 gdbarch_tdep''. */
1589
1590 extern void gdbarch_free (struct gdbarch *);
1591
1592 /* Get the obstack owned by ARCH. */
1593
1594 extern obstack *gdbarch_obstack (gdbarch *arch);
1595
1596 /* Helper function. Allocate memory from the \`\`struct gdbarch''
1597 obstack. The memory is freed when the corresponding architecture
1598 is also freed. */
1599
1600 #define GDBARCH_OBSTACK_CALLOC(GDBARCH, NR, TYPE) \
1601 obstack_calloc<TYPE> (gdbarch_obstack ((GDBARCH)), (NR))
1602
1603 #define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE) \
1604 obstack_zalloc<TYPE> (gdbarch_obstack ((GDBARCH)))
1605
1606 /* Duplicate STRING, returning an equivalent string that's allocated on the
1607 obstack associated with GDBARCH. The string is freed when the corresponding
1608 architecture is also freed. */
1609
1610 extern char *gdbarch_obstack_strdup (struct gdbarch *arch, const char *string);
1611
1612 /* Helper function. Force an update of the current architecture.
1613
1614 The actual architecture selected is determined by INFO, \`\`(gdb) set
1615 architecture'' et.al., the existing architecture and BFD's default
1616 architecture. INFO should be initialized to zero and then selected
1617 fields should be updated.
1618
1619 Returns non-zero if the update succeeds. */
1620
1621 extern int gdbarch_update_p (struct gdbarch_info info);
1622
1623
1624 /* Helper function. Find an architecture matching info.
1625
1626 INFO should be initialized using gdbarch_info_init, relevant fields
1627 set, and then finished using gdbarch_info_fill.
1628
1629 Returns the corresponding architecture, or NULL if no matching
1630 architecture was found. */
1631
1632 extern struct gdbarch *gdbarch_find_by_info (struct gdbarch_info info);
1633
1634
1635 /* Helper function. Set the target gdbarch to "gdbarch". */
1636
1637 extern void set_target_gdbarch (struct gdbarch *gdbarch);
1638
1639
1640 /* Register per-architecture data-pointer.
1641
1642 Reserve space for a per-architecture data-pointer. An identifier
1643 for the reserved data-pointer is returned. That identifer should
1644 be saved in a local static variable.
1645
1646 Memory for the per-architecture data shall be allocated using
1647 gdbarch_obstack_zalloc. That memory will be deleted when the
1648 corresponding architecture object is deleted.
1649
1650 When a previously created architecture is re-selected, the
1651 per-architecture data-pointer for that previous architecture is
1652 restored. INIT() is not re-called.
1653
1654 Multiple registrarants for any architecture are allowed (and
1655 strongly encouraged). */
1656
1657 struct gdbarch_data;
1658
1659 typedef void *(gdbarch_data_pre_init_ftype) (struct obstack *obstack);
1660 extern struct gdbarch_data *gdbarch_data_register_pre_init (gdbarch_data_pre_init_ftype *init);
1661 typedef void *(gdbarch_data_post_init_ftype) (struct gdbarch *gdbarch);
1662 extern struct gdbarch_data *gdbarch_data_register_post_init (gdbarch_data_post_init_ftype *init);
1663 extern void deprecated_set_gdbarch_data (struct gdbarch *gdbarch,
1664 struct gdbarch_data *data,
1665 void *pointer);
1666
1667 extern void *gdbarch_data (struct gdbarch *gdbarch, struct gdbarch_data *);
1668
1669
1670 /* Set the dynamic target-system-dependent parameters (architecture,
1671 byte-order, ...) using information found in the BFD. */
1672
1673 extern void set_gdbarch_from_file (bfd *);
1674
1675
1676 /* Initialize the current architecture to the "first" one we find on
1677 our list. */
1678
1679 extern void initialize_current_architecture (void);
1680
1681 /* gdbarch trace variable */
1682 extern unsigned int gdbarch_debug;
1683
1684 extern void gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file);
1685
1686 /* Return the number of cooked registers (raw + pseudo) for ARCH. */
1687
1688 static inline int
1689 gdbarch_num_cooked_regs (gdbarch *arch)
1690 {
1691 return gdbarch_num_regs (arch) + gdbarch_num_pseudo_regs (arch);
1692 }
1693
1694 #endif
1695 EOF
1696 exec 1>&2
1697 #../move-if-change new-gdbarch.h gdbarch.h
1698 compare_new gdbarch.h
1699
1700
1701 #
1702 # C file
1703 #
1704
1705 exec > new-gdbarch.c
1706 copyright
1707 cat <<EOF
1708
1709 #include "defs.h"
1710 #include "arch-utils.h"
1711
1712 #include "gdbcmd.h"
1713 #include "inferior.h"
1714 #include "symcat.h"
1715
1716 #include "floatformat.h"
1717 #include "reggroups.h"
1718 #include "osabi.h"
1719 #include "gdb_obstack.h"
1720 #include "observable.h"
1721 #include "regcache.h"
1722 #include "objfiles.h"
1723 #include "auxv.h"
1724 #include "frame-unwind.h"
1725 #include "dummy-frame.h"
1726
1727 /* Static function declarations */
1728
1729 static void alloc_gdbarch_data (struct gdbarch *);
1730
1731 /* Non-zero if we want to trace architecture code. */
1732
1733 #ifndef GDBARCH_DEBUG
1734 #define GDBARCH_DEBUG 0
1735 #endif
1736 unsigned int gdbarch_debug = GDBARCH_DEBUG;
1737 static void
1738 show_gdbarch_debug (struct ui_file *file, int from_tty,
1739 struct cmd_list_element *c, const char *value)
1740 {
1741 fprintf_filtered (file, _("Architecture debugging is %s.\\n"), value);
1742 }
1743
1744 static const char *
1745 pformat (const struct floatformat **format)
1746 {
1747 if (format == NULL)
1748 return "(null)";
1749 else
1750 /* Just print out one of them - this is only for diagnostics. */
1751 return format[0]->name;
1752 }
1753
1754 static const char *
1755 pstring (const char *string)
1756 {
1757 if (string == NULL)
1758 return "(null)";
1759 return string;
1760 }
1761
1762 static const char *
1763 pstring_ptr (char **string)
1764 {
1765 if (string == NULL || *string == NULL)
1766 return "(null)";
1767 return *string;
1768 }
1769
1770 /* Helper function to print a list of strings, represented as "const
1771 char *const *". The list is printed comma-separated. */
1772
1773 static const char *
1774 pstring_list (const char *const *list)
1775 {
1776 static char ret[100];
1777 const char *const *p;
1778 size_t offset = 0;
1779
1780 if (list == NULL)
1781 return "(null)";
1782
1783 ret[0] = '\0';
1784 for (p = list; *p != NULL && offset < sizeof (ret); ++p)
1785 {
1786 size_t s = xsnprintf (ret + offset, sizeof (ret) - offset, "%s, ", *p);
1787 offset += 2 + s;
1788 }
1789
1790 if (offset > 0)
1791 {
1792 gdb_assert (offset - 2 < sizeof (ret));
1793 ret[offset - 2] = '\0';
1794 }
1795
1796 return ret;
1797 }
1798
1799 EOF
1800
1801 # gdbarch open the gdbarch object
1802 printf "\n"
1803 printf "/* Maintain the struct gdbarch object. */\n"
1804 printf "\n"
1805 printf "struct gdbarch\n"
1806 printf "{\n"
1807 printf " /* Has this architecture been fully initialized? */\n"
1808 printf " int initialized_p;\n"
1809 printf "\n"
1810 printf " /* An obstack bound to the lifetime of the architecture. */\n"
1811 printf " struct obstack *obstack;\n"
1812 printf "\n"
1813 printf " /* basic architectural information. */\n"
1814 function_list | while do_read
1815 do
1816 if class_is_info_p
1817 then
1818 printf " %s %s;\n" "$returntype" "$function"
1819 fi
1820 done
1821 printf "\n"
1822 printf " /* target specific vector. */\n"
1823 printf " struct gdbarch_tdep *tdep;\n"
1824 printf " gdbarch_dump_tdep_ftype *dump_tdep;\n"
1825 printf "\n"
1826 printf " /* per-architecture data-pointers. */\n"
1827 printf " unsigned nr_data;\n"
1828 printf " void **data;\n"
1829 printf "\n"
1830 cat <<EOF
1831 /* Multi-arch values.
1832
1833 When extending this structure you must:
1834
1835 Add the field below.
1836
1837 Declare set/get functions and define the corresponding
1838 macro in gdbarch.h.
1839
1840 gdbarch_alloc(): If zero/NULL is not a suitable default,
1841 initialize the new field.
1842
1843 verify_gdbarch(): Confirm that the target updated the field
1844 correctly.
1845
1846 gdbarch_dump(): Add a fprintf_unfiltered call so that the new
1847 field is dumped out
1848
1849 get_gdbarch(): Implement the set/get functions (probably using
1850 the macro's as shortcuts).
1851
1852 */
1853
1854 EOF
1855 function_list | while do_read
1856 do
1857 if class_is_variable_p
1858 then
1859 printf " %s %s;\n" "$returntype" "$function"
1860 elif class_is_function_p
1861 then
1862 printf " gdbarch_%s_ftype *%s;\n" "$function" "$function"
1863 fi
1864 done
1865 printf "};\n"
1866
1867 # Create a new gdbarch struct
1868 cat <<EOF
1869
1870 /* Create a new \`\`struct gdbarch'' based on information provided by
1871 \`\`struct gdbarch_info''. */
1872 EOF
1873 printf "\n"
1874 cat <<EOF
1875 struct gdbarch *
1876 gdbarch_alloc (const struct gdbarch_info *info,
1877 struct gdbarch_tdep *tdep)
1878 {
1879 struct gdbarch *gdbarch;
1880
1881 /* Create an obstack for allocating all the per-architecture memory,
1882 then use that to allocate the architecture vector. */
1883 struct obstack *obstack = XNEW (struct obstack);
1884 obstack_init (obstack);
1885 gdbarch = XOBNEW (obstack, struct gdbarch);
1886 memset (gdbarch, 0, sizeof (*gdbarch));
1887 gdbarch->obstack = obstack;
1888
1889 alloc_gdbarch_data (gdbarch);
1890
1891 gdbarch->tdep = tdep;
1892 EOF
1893 printf "\n"
1894 function_list | while do_read
1895 do
1896 if class_is_info_p
1897 then
1898 printf " gdbarch->%s = info->%s;\n" "$function" "$function"
1899 fi
1900 done
1901 printf "\n"
1902 printf " /* Force the explicit initialization of these. */\n"
1903 function_list | while do_read
1904 do
1905 if class_is_function_p || class_is_variable_p
1906 then
1907 if [ -n "${predefault}" ] && [ "x${predefault}" != "x0" ]
1908 then
1909 printf " gdbarch->%s = %s;\n" "$function" "$predefault"
1910 fi
1911 fi
1912 done
1913 cat <<EOF
1914 /* gdbarch_alloc() */
1915
1916 return gdbarch;
1917 }
1918 EOF
1919
1920 # Free a gdbarch struct.
1921 printf "\n"
1922 printf "\n"
1923 cat <<EOF
1924
1925 obstack *gdbarch_obstack (gdbarch *arch)
1926 {
1927 return arch->obstack;
1928 }
1929
1930 /* See gdbarch.h. */
1931
1932 char *
1933 gdbarch_obstack_strdup (struct gdbarch *arch, const char *string)
1934 {
1935 return obstack_strdup (arch->obstack, string);
1936 }
1937
1938
1939 /* Free a gdbarch struct. This should never happen in normal
1940 operation --- once you've created a gdbarch, you keep it around.
1941 However, if an architecture's init function encounters an error
1942 building the structure, it may need to clean up a partially
1943 constructed gdbarch. */
1944
1945 void
1946 gdbarch_free (struct gdbarch *arch)
1947 {
1948 struct obstack *obstack;
1949
1950 gdb_assert (arch != NULL);
1951 gdb_assert (!arch->initialized_p);
1952 obstack = arch->obstack;
1953 obstack_free (obstack, 0); /* Includes the ARCH. */
1954 xfree (obstack);
1955 }
1956 EOF
1957
1958 # verify a new architecture
1959 cat <<EOF
1960
1961
1962 /* Ensure that all values in a GDBARCH are reasonable. */
1963
1964 static void
1965 verify_gdbarch (struct gdbarch *gdbarch)
1966 {
1967 string_file log;
1968
1969 /* fundamental */
1970 if (gdbarch->byte_order == BFD_ENDIAN_UNKNOWN)
1971 log.puts ("\n\tbyte-order");
1972 if (gdbarch->bfd_arch_info == NULL)
1973 log.puts ("\n\tbfd_arch_info");
1974 /* Check those that need to be defined for the given multi-arch level. */
1975 EOF
1976 function_list | while do_read
1977 do
1978 if class_is_function_p || class_is_variable_p
1979 then
1980 if [ "x${invalid_p}" = "x0" ]
1981 then
1982 printf " /* Skip verify of %s, invalid_p == 0 */\n" "$function"
1983 elif class_is_predicate_p
1984 then
1985 printf " /* Skip verify of %s, has predicate. */\n" "$function"
1986 # FIXME: See do_read for potential simplification
1987 elif [ -n "${invalid_p}" ] && [ -n "${postdefault}" ]
1988 then
1989 printf " if (%s)\n" "$invalid_p"
1990 printf " gdbarch->%s = %s;\n" "$function" "$postdefault"
1991 elif [ -n "${predefault}" ] && [ -n "${postdefault}" ]
1992 then
1993 printf " if (gdbarch->%s == %s)\n" "$function" "$predefault"
1994 printf " gdbarch->%s = %s;\n" "$function" "$postdefault"
1995 elif [ -n "${postdefault}" ]
1996 then
1997 printf " if (gdbarch->%s == 0)\n" "$function"
1998 printf " gdbarch->%s = %s;\n" "$function" "$postdefault"
1999 elif [ -n "${invalid_p}" ]
2000 then
2001 printf " if (%s)\n" "$invalid_p"
2002 printf " log.puts (\"\\\\n\\\\t%s\");\n" "$function"
2003 elif [ -n "${predefault}" ]
2004 then
2005 printf " if (gdbarch->%s == %s)\n" "$function" "$predefault"
2006 printf " log.puts (\"\\\\n\\\\t%s\");\n" "$function"
2007 fi
2008 fi
2009 done
2010 cat <<EOF
2011 if (!log.empty ())
2012 internal_error (__FILE__, __LINE__,
2013 _("verify_gdbarch: the following are invalid ...%s"),
2014 log.c_str ());
2015 }
2016 EOF
2017
2018 # dump the structure
2019 printf "\n"
2020 printf "\n"
2021 cat <<EOF
2022 /* Print out the details of the current architecture. */
2023
2024 void
2025 gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
2026 {
2027 const char *gdb_nm_file = "<not-defined>";
2028
2029 #if defined (GDB_NM_FILE)
2030 gdb_nm_file = GDB_NM_FILE;
2031 #endif
2032 fprintf_unfiltered (file,
2033 "gdbarch_dump: GDB_NM_FILE = %s\\n",
2034 gdb_nm_file);
2035 EOF
2036 function_list | sort '-t;' -k 3 | while do_read
2037 do
2038 # First the predicate
2039 if class_is_predicate_p
2040 then
2041 printf " fprintf_unfiltered (file,\n"
2042 printf " \"gdbarch_dump: gdbarch_%s_p() = %%d\\\\n\",\n" "$function"
2043 printf " gdbarch_%s_p (gdbarch));\n" "$function"
2044 fi
2045 # Print the corresponding value.
2046 if class_is_function_p
2047 then
2048 printf " fprintf_unfiltered (file,\n"
2049 printf " \"gdbarch_dump: %s = <%%s>\\\\n\",\n" "$function"
2050 printf " host_address_to_string (gdbarch->%s));\n" "$function"
2051 else
2052 # It is a variable
2053 case "${print}:${returntype}" in
2054 :CORE_ADDR )
2055 fmt="%s"
2056 print="core_addr_to_string_nz (gdbarch->${function})"
2057 ;;
2058 :* )
2059 fmt="%s"
2060 print="plongest (gdbarch->${function})"
2061 ;;
2062 * )
2063 fmt="%s"
2064 ;;
2065 esac
2066 printf " fprintf_unfiltered (file,\n"
2067 printf " \"gdbarch_dump: %s = %s\\\\n\",\n" "$function" "$fmt"
2068 printf " %s);\n" "$print"
2069 fi
2070 done
2071 cat <<EOF
2072 if (gdbarch->dump_tdep != NULL)
2073 gdbarch->dump_tdep (gdbarch, file);
2074 }
2075 EOF
2076
2077
2078 # GET/SET
2079 printf "\n"
2080 cat <<EOF
2081 struct gdbarch_tdep *
2082 gdbarch_tdep (struct gdbarch *gdbarch)
2083 {
2084 if (gdbarch_debug >= 2)
2085 fprintf_unfiltered (gdb_stdlog, "gdbarch_tdep called\\n");
2086 return gdbarch->tdep;
2087 }
2088 EOF
2089 printf "\n"
2090 function_list | while do_read
2091 do
2092 if class_is_predicate_p
2093 then
2094 printf "\n"
2095 printf "int\n"
2096 printf "gdbarch_%s_p (struct gdbarch *gdbarch)\n" "$function"
2097 printf "{\n"
2098 printf " gdb_assert (gdbarch != NULL);\n"
2099 printf " return %s;\n" "$predicate"
2100 printf "}\n"
2101 fi
2102 if class_is_function_p
2103 then
2104 printf "\n"
2105 printf "%s\n" "$returntype"
2106 if [ "x${formal}" = "xvoid" ]
2107 then
2108 printf "gdbarch_%s (struct gdbarch *gdbarch)\n" "$function"
2109 else
2110 printf "gdbarch_%s (struct gdbarch *gdbarch, %s)\n" "$function" "$formal"
2111 fi
2112 printf "{\n"
2113 printf " gdb_assert (gdbarch != NULL);\n"
2114 printf " gdb_assert (gdbarch->%s != NULL);\n" "$function"
2115 if class_is_predicate_p && test -n "${predefault}"
2116 then
2117 # Allow a call to a function with a predicate.
2118 printf " /* Do not check predicate: %s, allow call. */\n" "$predicate"
2119 fi
2120 printf " if (gdbarch_debug >= 2)\n"
2121 printf " fprintf_unfiltered (gdb_stdlog, \"gdbarch_%s called\\\\n\");\n" "$function"
2122 if [ "x${actual}" = "x-" ] || [ "x${actual}" = "x" ]
2123 then
2124 if class_is_multiarch_p
2125 then
2126 params="gdbarch"
2127 else
2128 params=""
2129 fi
2130 else
2131 if class_is_multiarch_p
2132 then
2133 params="gdbarch, ${actual}"
2134 else
2135 params="${actual}"
2136 fi
2137 fi
2138 if [ "x${returntype}" = "xvoid" ]
2139 then
2140 printf " gdbarch->%s (%s);\n" "$function" "$params"
2141 else
2142 printf " return gdbarch->%s (%s);\n" "$function" "$params"
2143 fi
2144 printf "}\n"
2145 printf "\n"
2146 printf "void\n"
2147 printf "set_gdbarch_%s (struct gdbarch *gdbarch,\n" "$function"
2148 printf " %s gdbarch_%s_ftype %s)\n" "$(echo "$function" | sed -e 's/./ /g')" "$function" "$function"
2149 printf "{\n"
2150 printf " gdbarch->%s = %s;\n" "$function" "$function"
2151 printf "}\n"
2152 elif class_is_variable_p
2153 then
2154 printf "\n"
2155 printf "%s\n" "$returntype"
2156 printf "gdbarch_%s (struct gdbarch *gdbarch)\n" "$function"
2157 printf "{\n"
2158 printf " gdb_assert (gdbarch != NULL);\n"
2159 if [ "x${invalid_p}" = "x0" ]
2160 then
2161 printf " /* Skip verify of %s, invalid_p == 0 */\n" "$function"
2162 elif [ -n "${invalid_p}" ]
2163 then
2164 printf " /* Check variable is valid. */\n"
2165 printf " gdb_assert (!(%s));\n" "$invalid_p"
2166 elif [ -n "${predefault}" ]
2167 then
2168 printf " /* Check variable changed from pre-default. */\n"
2169 printf " gdb_assert (gdbarch->%s != %s);\n" "$function" "$predefault"
2170 fi
2171 printf " if (gdbarch_debug >= 2)\n"
2172 printf " fprintf_unfiltered (gdb_stdlog, \"gdbarch_%s called\\\\n\");\n" "$function"
2173 printf " return gdbarch->%s;\n" "$function"
2174 printf "}\n"
2175 printf "\n"
2176 printf "void\n"
2177 printf "set_gdbarch_%s (struct gdbarch *gdbarch,\n" "$function"
2178 printf " %s %s %s)\n" "$(echo "$function" | sed -e 's/./ /g')" "$returntype" "$function"
2179 printf "{\n"
2180 printf " gdbarch->%s = %s;\n" "$function" "$function"
2181 printf "}\n"
2182 elif class_is_info_p
2183 then
2184 printf "\n"
2185 printf "%s\n" "$returntype"
2186 printf "gdbarch_%s (struct gdbarch *gdbarch)\n" "$function"
2187 printf "{\n"
2188 printf " gdb_assert (gdbarch != NULL);\n"
2189 printf " if (gdbarch_debug >= 2)\n"
2190 printf " fprintf_unfiltered (gdb_stdlog, \"gdbarch_%s called\\\\n\");\n" "$function"
2191 printf " return gdbarch->%s;\n" "$function"
2192 printf "}\n"
2193 fi
2194 done
2195
2196 # All the trailing guff
2197 cat <<EOF
2198
2199
2200 /* Keep a registry of per-architecture data-pointers required by GDB
2201 modules. */
2202
2203 struct gdbarch_data
2204 {
2205 unsigned index;
2206 int init_p;
2207 gdbarch_data_pre_init_ftype *pre_init;
2208 gdbarch_data_post_init_ftype *post_init;
2209 };
2210
2211 struct gdbarch_data_registration
2212 {
2213 struct gdbarch_data *data;
2214 struct gdbarch_data_registration *next;
2215 };
2216
2217 struct gdbarch_data_registry
2218 {
2219 unsigned nr;
2220 struct gdbarch_data_registration *registrations;
2221 };
2222
2223 struct gdbarch_data_registry gdbarch_data_registry =
2224 {
2225 0, NULL,
2226 };
2227
2228 static struct gdbarch_data *
2229 gdbarch_data_register (gdbarch_data_pre_init_ftype *pre_init,
2230 gdbarch_data_post_init_ftype *post_init)
2231 {
2232 struct gdbarch_data_registration **curr;
2233
2234 /* Append the new registration. */
2235 for (curr = &gdbarch_data_registry.registrations;
2236 (*curr) != NULL;
2237 curr = &(*curr)->next);
2238 (*curr) = XNEW (struct gdbarch_data_registration);
2239 (*curr)->next = NULL;
2240 (*curr)->data = XNEW (struct gdbarch_data);
2241 (*curr)->data->index = gdbarch_data_registry.nr++;
2242 (*curr)->data->pre_init = pre_init;
2243 (*curr)->data->post_init = post_init;
2244 (*curr)->data->init_p = 1;
2245 return (*curr)->data;
2246 }
2247
2248 struct gdbarch_data *
2249 gdbarch_data_register_pre_init (gdbarch_data_pre_init_ftype *pre_init)
2250 {
2251 return gdbarch_data_register (pre_init, NULL);
2252 }
2253
2254 struct gdbarch_data *
2255 gdbarch_data_register_post_init (gdbarch_data_post_init_ftype *post_init)
2256 {
2257 return gdbarch_data_register (NULL, post_init);
2258 }
2259
2260 /* Create/delete the gdbarch data vector. */
2261
2262 static void
2263 alloc_gdbarch_data (struct gdbarch *gdbarch)
2264 {
2265 gdb_assert (gdbarch->data == NULL);
2266 gdbarch->nr_data = gdbarch_data_registry.nr;
2267 gdbarch->data = GDBARCH_OBSTACK_CALLOC (gdbarch, gdbarch->nr_data, void *);
2268 }
2269
2270 /* Initialize the current value of the specified per-architecture
2271 data-pointer. */
2272
2273 void
2274 deprecated_set_gdbarch_data (struct gdbarch *gdbarch,
2275 struct gdbarch_data *data,
2276 void *pointer)
2277 {
2278 gdb_assert (data->index < gdbarch->nr_data);
2279 gdb_assert (gdbarch->data[data->index] == NULL);
2280 gdb_assert (data->pre_init == NULL);
2281 gdbarch->data[data->index] = pointer;
2282 }
2283
2284 /* Return the current value of the specified per-architecture
2285 data-pointer. */
2286
2287 void *
2288 gdbarch_data (struct gdbarch *gdbarch, struct gdbarch_data *data)
2289 {
2290 gdb_assert (data->index < gdbarch->nr_data);
2291 if (gdbarch->data[data->index] == NULL)
2292 {
2293 /* The data-pointer isn't initialized, call init() to get a
2294 value. */
2295 if (data->pre_init != NULL)
2296 /* Mid architecture creation: pass just the obstack, and not
2297 the entire architecture, as that way it isn't possible for
2298 pre-init code to refer to undefined architecture
2299 fields. */
2300 gdbarch->data[data->index] = data->pre_init (gdbarch->obstack);
2301 else if (gdbarch->initialized_p
2302 && data->post_init != NULL)
2303 /* Post architecture creation: pass the entire architecture
2304 (as all fields are valid), but be careful to also detect
2305 recursive references. */
2306 {
2307 gdb_assert (data->init_p);
2308 data->init_p = 0;
2309 gdbarch->data[data->index] = data->post_init (gdbarch);
2310 data->init_p = 1;
2311 }
2312 else
2313 /* The architecture initialization hasn't completed - punt -
2314 hope that the caller knows what they are doing. Once
2315 deprecated_set_gdbarch_data has been initialized, this can be
2316 changed to an internal error. */
2317 return NULL;
2318 gdb_assert (gdbarch->data[data->index] != NULL);
2319 }
2320 return gdbarch->data[data->index];
2321 }
2322
2323
2324 /* Keep a registry of the architectures known by GDB. */
2325
2326 struct gdbarch_registration
2327 {
2328 enum bfd_architecture bfd_architecture;
2329 gdbarch_init_ftype *init;
2330 gdbarch_dump_tdep_ftype *dump_tdep;
2331 struct gdbarch_list *arches;
2332 struct gdbarch_registration *next;
2333 };
2334
2335 static struct gdbarch_registration *gdbarch_registry = NULL;
2336
2337 static void
2338 append_name (const char ***buf, int *nr, const char *name)
2339 {
2340 *buf = XRESIZEVEC (const char *, *buf, *nr + 1);
2341 (*buf)[*nr] = name;
2342 *nr += 1;
2343 }
2344
2345 const char **
2346 gdbarch_printable_names (void)
2347 {
2348 /* Accumulate a list of names based on the registed list of
2349 architectures. */
2350 int nr_arches = 0;
2351 const char **arches = NULL;
2352 struct gdbarch_registration *rego;
2353
2354 for (rego = gdbarch_registry;
2355 rego != NULL;
2356 rego = rego->next)
2357 {
2358 const struct bfd_arch_info *ap;
2359 ap = bfd_lookup_arch (rego->bfd_architecture, 0);
2360 if (ap == NULL)
2361 internal_error (__FILE__, __LINE__,
2362 _("gdbarch_architecture_names: multi-arch unknown"));
2363 do
2364 {
2365 append_name (&arches, &nr_arches, ap->printable_name);
2366 ap = ap->next;
2367 }
2368 while (ap != NULL);
2369 }
2370 append_name (&arches, &nr_arches, NULL);
2371 return arches;
2372 }
2373
2374
2375 void
2376 gdbarch_register (enum bfd_architecture bfd_architecture,
2377 gdbarch_init_ftype *init,
2378 gdbarch_dump_tdep_ftype *dump_tdep)
2379 {
2380 struct gdbarch_registration **curr;
2381 const struct bfd_arch_info *bfd_arch_info;
2382
2383 /* Check that BFD recognizes this architecture */
2384 bfd_arch_info = bfd_lookup_arch (bfd_architecture, 0);
2385 if (bfd_arch_info == NULL)
2386 {
2387 internal_error (__FILE__, __LINE__,
2388 _("gdbarch: Attempt to register "
2389 "unknown architecture (%d)"),
2390 bfd_architecture);
2391 }
2392 /* Check that we haven't seen this architecture before. */
2393 for (curr = &gdbarch_registry;
2394 (*curr) != NULL;
2395 curr = &(*curr)->next)
2396 {
2397 if (bfd_architecture == (*curr)->bfd_architecture)
2398 internal_error (__FILE__, __LINE__,
2399 _("gdbarch: Duplicate registration "
2400 "of architecture (%s)"),
2401 bfd_arch_info->printable_name);
2402 }
2403 /* log it */
2404 if (gdbarch_debug)
2405 fprintf_unfiltered (gdb_stdlog, "register_gdbarch_init (%s, %s)\n",
2406 bfd_arch_info->printable_name,
2407 host_address_to_string (init));
2408 /* Append it */
2409 (*curr) = XNEW (struct gdbarch_registration);
2410 (*curr)->bfd_architecture = bfd_architecture;
2411 (*curr)->init = init;
2412 (*curr)->dump_tdep = dump_tdep;
2413 (*curr)->arches = NULL;
2414 (*curr)->next = NULL;
2415 }
2416
2417 void
2418 register_gdbarch_init (enum bfd_architecture bfd_architecture,
2419 gdbarch_init_ftype *init)
2420 {
2421 gdbarch_register (bfd_architecture, init, NULL);
2422 }
2423
2424
2425 /* Look for an architecture using gdbarch_info. */
2426
2427 struct gdbarch_list *
2428 gdbarch_list_lookup_by_info (struct gdbarch_list *arches,
2429 const struct gdbarch_info *info)
2430 {
2431 for (; arches != NULL; arches = arches->next)
2432 {
2433 if (info->bfd_arch_info != arches->gdbarch->bfd_arch_info)
2434 continue;
2435 if (info->byte_order != arches->gdbarch->byte_order)
2436 continue;
2437 if (info->osabi != arches->gdbarch->osabi)
2438 continue;
2439 if (info->target_desc != arches->gdbarch->target_desc)
2440 continue;
2441 return arches;
2442 }
2443 return NULL;
2444 }
2445
2446
2447 /* Find an architecture that matches the specified INFO. Create a new
2448 architecture if needed. Return that new architecture. */
2449
2450 struct gdbarch *
2451 gdbarch_find_by_info (struct gdbarch_info info)
2452 {
2453 struct gdbarch *new_gdbarch;
2454 struct gdbarch_registration *rego;
2455
2456 /* Fill in missing parts of the INFO struct using a number of
2457 sources: "set ..."; INFOabfd supplied; and the global
2458 defaults. */
2459 gdbarch_info_fill (&info);
2460
2461 /* Must have found some sort of architecture. */
2462 gdb_assert (info.bfd_arch_info != NULL);
2463
2464 if (gdbarch_debug)
2465 {
2466 fprintf_unfiltered (gdb_stdlog,
2467 "gdbarch_find_by_info: info.bfd_arch_info %s\n",
2468 (info.bfd_arch_info != NULL
2469 ? info.bfd_arch_info->printable_name
2470 : "(null)"));
2471 fprintf_unfiltered (gdb_stdlog,
2472 "gdbarch_find_by_info: info.byte_order %d (%s)\n",
2473 info.byte_order,
2474 (info.byte_order == BFD_ENDIAN_BIG ? "big"
2475 : info.byte_order == BFD_ENDIAN_LITTLE ? "little"
2476 : "default"));
2477 fprintf_unfiltered (gdb_stdlog,
2478 "gdbarch_find_by_info: info.osabi %d (%s)\n",
2479 info.osabi, gdbarch_osabi_name (info.osabi));
2480 fprintf_unfiltered (gdb_stdlog,
2481 "gdbarch_find_by_info: info.abfd %s\n",
2482 host_address_to_string (info.abfd));
2483 fprintf_unfiltered (gdb_stdlog,
2484 "gdbarch_find_by_info: info.tdep_info %s\n",
2485 host_address_to_string (info.tdep_info));
2486 }
2487
2488 /* Find the tdep code that knows about this architecture. */
2489 for (rego = gdbarch_registry;
2490 rego != NULL;
2491 rego = rego->next)
2492 if (rego->bfd_architecture == info.bfd_arch_info->arch)
2493 break;
2494 if (rego == NULL)
2495 {
2496 if (gdbarch_debug)
2497 fprintf_unfiltered (gdb_stdlog, "gdbarch_find_by_info: "
2498 "No matching architecture\n");
2499 return 0;
2500 }
2501
2502 /* Ask the tdep code for an architecture that matches "info". */
2503 new_gdbarch = rego->init (info, rego->arches);
2504
2505 /* Did the tdep code like it? No. Reject the change and revert to
2506 the old architecture. */
2507 if (new_gdbarch == NULL)
2508 {
2509 if (gdbarch_debug)
2510 fprintf_unfiltered (gdb_stdlog, "gdbarch_find_by_info: "
2511 "Target rejected architecture\n");
2512 return NULL;
2513 }
2514
2515 /* Is this a pre-existing architecture (as determined by already
2516 being initialized)? Move it to the front of the architecture
2517 list (keeping the list sorted Most Recently Used). */
2518 if (new_gdbarch->initialized_p)
2519 {
2520 struct gdbarch_list **list;
2521 struct gdbarch_list *self;
2522 if (gdbarch_debug)
2523 fprintf_unfiltered (gdb_stdlog, "gdbarch_find_by_info: "
2524 "Previous architecture %s (%s) selected\n",
2525 host_address_to_string (new_gdbarch),
2526 new_gdbarch->bfd_arch_info->printable_name);
2527 /* Find the existing arch in the list. */
2528 for (list = &rego->arches;
2529 (*list) != NULL && (*list)->gdbarch != new_gdbarch;
2530 list = &(*list)->next);
2531 /* It had better be in the list of architectures. */
2532 gdb_assert ((*list) != NULL && (*list)->gdbarch == new_gdbarch);
2533 /* Unlink SELF. */
2534 self = (*list);
2535 (*list) = self->next;
2536 /* Insert SELF at the front. */
2537 self->next = rego->arches;
2538 rego->arches = self;
2539 /* Return it. */
2540 return new_gdbarch;
2541 }
2542
2543 /* It's a new architecture. */
2544 if (gdbarch_debug)
2545 fprintf_unfiltered (gdb_stdlog, "gdbarch_find_by_info: "
2546 "New architecture %s (%s) selected\n",
2547 host_address_to_string (new_gdbarch),
2548 new_gdbarch->bfd_arch_info->printable_name);
2549
2550 /* Insert the new architecture into the front of the architecture
2551 list (keep the list sorted Most Recently Used). */
2552 {
2553 struct gdbarch_list *self = XNEW (struct gdbarch_list);
2554 self->next = rego->arches;
2555 self->gdbarch = new_gdbarch;
2556 rego->arches = self;
2557 }
2558
2559 /* Check that the newly installed architecture is valid. Plug in
2560 any post init values. */
2561 new_gdbarch->dump_tdep = rego->dump_tdep;
2562 verify_gdbarch (new_gdbarch);
2563 new_gdbarch->initialized_p = 1;
2564
2565 if (gdbarch_debug)
2566 gdbarch_dump (new_gdbarch, gdb_stdlog);
2567
2568 return new_gdbarch;
2569 }
2570
2571 /* Make the specified architecture current. */
2572
2573 void
2574 set_target_gdbarch (struct gdbarch *new_gdbarch)
2575 {
2576 gdb_assert (new_gdbarch != NULL);
2577 gdb_assert (new_gdbarch->initialized_p);
2578 current_inferior ()->gdbarch = new_gdbarch;
2579 gdb::observers::architecture_changed.notify (new_gdbarch);
2580 registers_changed ();
2581 }
2582
2583 /* Return the current inferior's arch. */
2584
2585 struct gdbarch *
2586 target_gdbarch (void)
2587 {
2588 return current_inferior ()->gdbarch;
2589 }
2590
2591 void _initialize_gdbarch ();
2592 void
2593 _initialize_gdbarch ()
2594 {
2595 add_setshow_zuinteger_cmd ("arch", class_maintenance, &gdbarch_debug, _("\\
2596 Set architecture debugging."), _("\\
2597 Show architecture debugging."), _("\\
2598 When non-zero, architecture debugging is enabled."),
2599 NULL,
2600 show_gdbarch_debug,
2601 &setdebuglist, &showdebuglist);
2602 }
2603 EOF
2604
2605 # close things off
2606 exec 1>&2
2607 #../move-if-change new-gdbarch.c gdbarch.c
2608 compare_new gdbarch.c
This page took 0.131489 seconds and 4 git commands to generate.