gdb/gdbarch.sh - gdb

Functions defined

Source code

  1. #!/bin/sh -u

  2. # Architecture commands for GDB, the GNU debugger.
  3. #
  4. # Copyright (C) 1998-2015 Free Software Foundation, Inc.
  5. #
  6. # This file is part of GDB.
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program.  If not, see <http://www.gnu.org/licenses/>.

  20. # Make certain that the script is not running in an internationalized
  21. # environment.
  22. LANG=C ; export LANG
  23. LC_ALL=C ; export LC_ALL


  24. compare_new ()
  25. {
  26.     file=$1
  27.     if test ! -r ${file}
  28.     then
  29.         echo "${file} missing? cp new-${file} ${file}" 1>&2
  30.     elif diff -u ${file} new-${file}
  31.     then
  32.         echo "${file} unchanged" 1>&2
  33.     else
  34.         echo "${file} has changed? cp new-${file} ${file}" 1>&2
  35.     fi
  36. }


  37. # Format of the input table
  38. read="class returntype function formal actual staticdefault predefault postdefault invalid_p print garbage_at_eol"

  39. do_read ()
  40. {
  41.     comment=""
  42.     class=""
  43.     # On some SH's, 'read' trims leading and trailing whitespace by
  44.     # default (e.g., bash), while on others (e.g., dash), it doesn't.
  45.     # Set IFS to empty to disable the trimming everywhere.
  46.     while IFS='' read line
  47.     do
  48.         if test "${line}" = ""
  49.         then
  50.             continue
  51.         elif test "${line}" = "#" -a "${comment}" = ""
  52.         then
  53.             continue
  54.         elif expr "${line}" : "#" > /dev/null
  55.         then
  56.             comment="${comment}
  57. ${line}"
  58.         else

  59.             # The semantics of IFS varies between different SH's.  Some
  60.             # treat ``::' as three fields while some treat it as just too.
  61.             # Work around this by eliminating ``::'' ....
  62.             line="`echo "${line}" | sed -e 's/::/: :/g' -e 's/::/: :/g'`"

  63.             OFS="${IFS}" ; IFS="[:]"
  64.             eval read ${read} <<EOF
  65. ${line}
  66. EOF
  67.             IFS="${OFS}"

  68.             if test -n "${garbage_at_eol}"
  69.             then
  70.                 echo "Garbage at end-of-line in ${line}" 1>&2
  71.                 kill $$
  72.                 exit 1
  73.             fi

  74.             # .... and then going back through each field and strip out those
  75.             # that ended up with just that space character.
  76.             for r in ${read}
  77.             do
  78.                 if eval test \"\${${r}}\" = \"\ \"
  79.                 then
  80.                     eval ${r}=""
  81.                 fi
  82.             done

  83.             case "${class}" in
  84.                 m ) staticdefault="${predefault}" ;;
  85.                 M ) staticdefault="0" ;;
  86.                 * ) test "${staticdefault}" || staticdefault=0 ;;
  87.             esac

  88.             case "${class}" in
  89.             F | V | M )
  90.                 case "${invalid_p}" in
  91.                 "" )
  92.                     if test -n "${predefault}"
  93.                     then
  94.                         #invalid_p="gdbarch->${function} == ${predefault}"
  95.                         predicate="gdbarch->${function} != ${predefault}"
  96.                     elif class_is_variable_p
  97.                     then
  98.                         predicate="gdbarch->${function} != 0"
  99.                     elif class_is_function_p
  100.                     then
  101.                         predicate="gdbarch->${function} != NULL"
  102.                     fi
  103.                     ;;
  104.                 * )
  105.                     echo "Predicate function ${function} with invalid_p." 1>&2
  106.                     kill $$
  107.                     exit 1
  108.                     ;;
  109.                 esac
  110.             esac

  111.             # PREDEFAULT is a valid fallback definition of MEMBER when
  112.             # multi-arch is not enabled.  This ensures that the
  113.             # default value, when multi-arch is the same as the
  114.             # default value when not multi-arch.  POSTDEFAULT is
  115.             # always a valid definition of MEMBER as this again
  116.             # ensures consistency.

  117.             if [ -n "${postdefault}" ]
  118.             then
  119.                 fallbackdefault="${postdefault}"
  120.             elif [ -n "${predefault}" ]
  121.             then
  122.                 fallbackdefault="${predefault}"
  123.             else
  124.                 fallbackdefault="0"
  125.             fi

  126.             #NOT YET: See gdbarch.log for basic verification of
  127.             # database

  128.             break
  129.         fi
  130.     done
  131.     if [ -n "${class}" ]
  132.     then
  133.         true
  134.     else
  135.         false
  136.     fi
  137. }


  138. fallback_default_p ()
  139. {
  140.     [ -n "${postdefault}" -a "x${invalid_p}" != "x0" ] \
  141.         || [ -n "${predefault}" -a "x${invalid_p}" = "x0" ]
  142. }

  143. class_is_variable_p ()
  144. {
  145.     case "${class}" in
  146.         *v* | *V* ) true ;;
  147.         * ) false ;;
  148.     esac
  149. }

  150. class_is_function_p ()
  151. {
  152.     case "${class}" in
  153.         *f* | *F* | *m* | *M* ) true ;;
  154.         * ) false ;;
  155.     esac
  156. }

  157. class_is_multiarch_p ()
  158. {
  159.     case "${class}" in
  160.         *m* | *M* ) true ;;
  161.         * ) false ;;
  162.     esac
  163. }

  164. class_is_predicate_p ()
  165. {
  166.     case "${class}" in
  167.         *F* | *V* | *M* ) true ;;
  168.         * ) false ;;
  169.     esac
  170. }

  171. class_is_info_p ()
  172. {
  173.     case "${class}" in
  174.         *i* ) true ;;
  175.         * ) false ;;
  176.     esac
  177. }


  178. # dump out/verify the doco
  179. for field in ${read}
  180. do
  181.   case ${field} in

  182.     class ) : ;;

  183.         # # -> line disable
  184.         # f -> function
  185.         #   hiding a function
  186.         # F -> function + predicate
  187.         #   hiding a function + predicate to test function validity
  188.         # v -> variable
  189.         #   hiding a variable
  190.         # V -> variable + predicate
  191.         #   hiding a variable + predicate to test variables validity
  192.         # i -> set from info
  193.         #   hiding something from the ``struct info'' object
  194.         # m -> multi-arch function
  195.         #   hiding a multi-arch function (parameterised with the architecture)
  196.         # M -> multi-arch function + predicate
  197.         #   hiding a multi-arch function + predicate to test function validity

  198.     returntype ) : ;;

  199.         # For functions, the return type; for variables, the data type

  200.     function ) : ;;

  201.         # For functions, the member function name; for variables, the
  202.         # variable name.  Member function names are always prefixed with
  203.         # ``gdbarch_'' for name-space purity.

  204.     formal ) : ;;

  205.         # The formal argument list.  It is assumed that the formal
  206.         # argument list includes the actual name of each list element.
  207.         # A function with no arguments shall have ``void'' as the
  208.         # formal argument list.

  209.     actual ) : ;;

  210.         # The list of actual arguments.  The arguments specified shall
  211.         # match the FORMAL list given above.  Functions with out
  212.         # arguments leave this blank.

  213.     staticdefault ) : ;;

  214.         # To help with the GDB startup a static gdbarch object is
  215.         # created.  STATICDEFAULT is the value to insert into that
  216.         # static gdbarch object.  Since this a static object only
  217.         # simple expressions can be used.

  218.         # If STATICDEFAULT is empty, zero is used.

  219.     predefault ) : ;;

  220.         # An initial value to assign to MEMBER of the freshly
  221.         # malloc()ed gdbarch object.  After initialization, the
  222.         # freshly malloc()ed object is passed to the target
  223.         # architecture code for further updates.

  224.         # If PREDEFAULT is empty, zero is used.

  225.         # A non-empty PREDEFAULT, an empty POSTDEFAULT and a zero
  226.         # INVALID_P are specified, PREDEFAULT will be used as the
  227.         # default for the non- multi-arch target.

  228.         # A zero PREDEFAULT function will force the fallback to call
  229.         # internal_error().

  230.         # Variable declarations can refer to ``gdbarch'' which will
  231.         # contain the current architecture.  Care should be taken.

  232.     postdefault ) : ;;

  233.         # A value to assign to MEMBER of the new gdbarch object should
  234.         # the target architecture code fail to change the PREDEFAULT
  235.         # value.

  236.         # If POSTDEFAULT is empty, no post update is performed.

  237.         # If both INVALID_P and POSTDEFAULT are non-empty then
  238.         # INVALID_P will be used to determine if MEMBER should be
  239.         # changed to POSTDEFAULT.

  240.         # If a non-empty POSTDEFAULT and a zero INVALID_P are
  241.         # specified, POSTDEFAULT will be used as the default for the
  242.         # non- multi-arch target (regardless of the value of
  243.         # PREDEFAULT).

  244.         # You cannot specify both a zero INVALID_P and a POSTDEFAULT.

  245.         # Variable declarations can refer to ``gdbarch'' which
  246.         # will contain the current architecture.  Care should be
  247.         # taken.

  248.     invalid_p ) : ;;

  249.         # A predicate equation that validates MEMBER.  Non-zero is
  250.         # returned if the code creating the new architecture failed to
  251.         # initialize MEMBER or the initialized the member is invalid.
  252.         # If POSTDEFAULT is non-empty then MEMBER will be updated to
  253.         # that value.  If POSTDEFAULT is empty then internal_error()
  254.         # is called.

  255.         # If INVALID_P is empty, a check that MEMBER is no longer
  256.         # equal to PREDEFAULT is used.

  257.         # The expression ``0'' disables the INVALID_P check making
  258.         # PREDEFAULT a legitimate value.

  259.         # See also PREDEFAULT and POSTDEFAULT.

  260.     print ) : ;;

  261.         # An optional expression that convers MEMBER to a value
  262.         # suitable for formatting using %s.

  263.         # If PRINT is empty, core_addr_to_string_nz (for CORE_ADDR)
  264.         # or plongest (anything else) is used.

  265.     garbage_at_eol ) : ;;

  266.         # Catches stray fields.

  267.     *)
  268.         echo "Bad field ${field}"
  269.         exit 1;;
  270.   esac
  271. done


  272. function_list ()
  273. {
  274.   # See below (DOCO) for description of each field
  275.   cat <<EOF
  276. i:const struct bfd_arch_info *:bfd_arch_info:::&bfd_default_arch_struct::::gdbarch_bfd_arch_info (gdbarch)->printable_name
  277. #
  278. i:enum bfd_endian:byte_order:::BFD_ENDIAN_BIG
  279. i:enum bfd_endian:byte_order_for_code:::BFD_ENDIAN_BIG
  280. #
  281. i:enum gdb_osabi:osabi:::GDB_OSABI_UNKNOWN
  282. #
  283. i:const struct target_desc *:target_desc:::::::host_address_to_string (gdbarch->target_desc)

  284. # The bit byte-order has to do just with numbering of bits in debugging symbols
  285. # and such.  Conceptually, it's quite separate from byte/word byte order.
  286. v:int:bits_big_endian:::1:(gdbarch->byte_order == BFD_ENDIAN_BIG)::0

  287. # Number of bits in a char or unsigned char for the target machine.
  288. # Just like CHAR_BIT in <limits.h> but describes the target machine.
  289. # v:TARGET_CHAR_BIT:int:char_bit::::8 * sizeof (char):8::0:
  290. #
  291. # Number of bits in a short or unsigned short for the target machine.
  292. v:int:short_bit:::8 * sizeof (short):2*TARGET_CHAR_BIT::0
  293. # Number of bits in an int or unsigned int for the target machine.
  294. v:int:int_bit:::8 * sizeof (int):4*TARGET_CHAR_BIT::0
  295. # Number of bits in a long or unsigned long for the target machine.
  296. v:int:long_bit:::8 * sizeof (long):4*TARGET_CHAR_BIT::0
  297. # Number of bits in a long long or unsigned long long for the target
  298. # machine.
  299. v:int:long_long_bit:::8 * sizeof (LONGEST):2*gdbarch->long_bit::0
  300. # Alignment of a long long or unsigned long long for the target
  301. # machine.
  302. v:int:long_long_align_bit:::8 * sizeof (LONGEST):2*gdbarch->long_bit::0

  303. # The ABI default bit-size and format for "half", "float", "double", and
  304. # "long double".  These bit/format pairs should eventually be combined
  305. # into a single object.  For the moment, just initialize them as a pair.
  306. # Each format describes both the big and little endian layouts (if
  307. # useful).

  308. v:int:half_bit:::16:2*TARGET_CHAR_BIT::0
  309. v:const struct floatformat **:half_format:::::floatformats_ieee_half::pformat (gdbarch->half_format)
  310. v:int:float_bit:::8 * sizeof (float):4*TARGET_CHAR_BIT::0
  311. v:const struct floatformat **:float_format:::::floatformats_ieee_single::pformat (gdbarch->float_format)
  312. v:int:double_bit:::8 * sizeof (double):8*TARGET_CHAR_BIT::0
  313. v:const struct floatformat **:double_format:::::floatformats_ieee_double::pformat (gdbarch->double_format)
  314. v:int:long_double_bit:::8 * sizeof (long double):8*TARGET_CHAR_BIT::0
  315. v:const struct floatformat **:long_double_format:::::floatformats_ieee_double::pformat (gdbarch->long_double_format)

  316. # For most targets, a pointer on the target and its representation as an
  317. # address in GDB have the same size and "look the same".  For such a
  318. # target, you need only set gdbarch_ptr_bit and gdbarch_addr_bit
  319. # / addr_bit will be set from it.
  320. #
  321. # If gdbarch_ptr_bit and gdbarch_addr_bit are different, you'll probably
  322. # also need to set gdbarch_dwarf2_addr_size, gdbarch_pointer_to_address and
  323. # gdbarch_address_to_pointer as well.
  324. #
  325. # ptr_bit is the size of a pointer on the target
  326. v:int:ptr_bit:::8 * sizeof (void*):gdbarch->int_bit::0
  327. # addr_bit is the size of a target address as represented in gdb
  328. v:int:addr_bit:::8 * sizeof (void*):0:gdbarch_ptr_bit (gdbarch):
  329. #
  330. # dwarf2_addr_size is the target address size as used in the Dwarf debug
  331. # info.  For .debug_frame FDEs, this is supposed to be the target address
  332. # size from the associated CU header, and which is equivalent to the
  333. # DWARF2_ADDR_SIZE as defined by the target specific GCC back-end.
  334. # Unfortunately there is no good way to determine this value.  Therefore
  335. # dwarf2_addr_size simply defaults to the target pointer size.
  336. #
  337. # dwarf2_addr_size is not used for .eh_frame FDEs, which are generally
  338. # defined using the target's pointer size so far.
  339. #
  340. # Note that dwarf2_addr_size only needs to be redefined by a target if the
  341. # GCC back-end defines a DWARF2_ADDR_SIZE other than the target pointer size,
  342. # and if Dwarf versions < 4 need to be supported.
  343. v:int:dwarf2_addr_size:::sizeof (void*):0:gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT:
  344. #
  345. # One if \`char' acts like \`signed char', zero if \`unsigned char'.
  346. v:int:char_signed:::1:-1:1
  347. #
  348. F:CORE_ADDR:read_pc:struct regcache *regcache:regcache
  349. F:void:write_pc:struct regcache *regcache, CORE_ADDR val:regcache, val
  350. # Function for getting target's idea of a frame pointer.  FIXME: GDB's
  351. # whole scheme for dealing with "frames" and "frame pointers" needs a
  352. # serious shakedown.
  353. 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
  354. #
  355. M:enum register_status:pseudo_register_read:struct regcache *regcache, int cookednum, gdb_byte *buf:regcache, cookednum, buf
  356. # Read a register into a new struct value.  If the register is wholly
  357. # or partly unavailable, this should call mark_value_bytes_unavailable
  358. # as appropriate.  If this is defined, then pseudo_register_read will
  359. # never be called.
  360. M:struct value *:pseudo_register_read_value:struct regcache *regcache, int cookednum:regcache, cookednum
  361. M:void:pseudo_register_write:struct regcache *regcache, int cookednum, const gdb_byte *buf:regcache, cookednum, buf
  362. #
  363. v:int:num_regs:::0:-1
  364. # This macro gives the number of pseudo-registers that live in the
  365. # register namespace but do not get fetched or stored on the target.
  366. # These pseudo-registers may be aliases for other registers,
  367. # combinations of other registers, or they may be computed by GDB.
  368. v:int:num_pseudo_regs:::0:0::0

  369. # Assemble agent expression bytecode to collect pseudo-register REG.
  370. # Return -1 if something goes wrong, 0 otherwise.
  371. M:int:ax_pseudo_register_collect:struct agent_expr *ax, int reg:ax, reg

  372. # Assemble agent expression bytecode to push the value of pseudo-register
  373. # REG on the interpreter stack.
  374. # Return -1 if something goes wrong, 0 otherwise.
  375. M:int:ax_pseudo_register_push_stack:struct agent_expr *ax, int reg:ax, reg

  376. # GDB's standard (or well known) register numbers.  These can map onto
  377. # a real register or a pseudo (computed) register or not be defined at
  378. # all (-1).
  379. # gdbarch_sp_regnum will hopefully be replaced by UNWIND_SP.
  380. v:int:sp_regnum:::-1:-1::0
  381. v:int:pc_regnum:::-1:-1::0
  382. v:int:ps_regnum:::-1:-1::0
  383. v:int:fp0_regnum:::0:-1::0
  384. # Convert stab register number (from \`r\' declaration) to a gdb REGNUM.
  385. m:int:stab_reg_to_regnum:int stab_regnr:stab_regnr::no_op_reg_to_regnum::0
  386. # Provide a default mapping from a ecoff register number to a gdb REGNUM.
  387. m:int:ecoff_reg_to_regnum:int ecoff_regnr:ecoff_regnr::no_op_reg_to_regnum::0
  388. # Convert from an sdb register number to an internal gdb register number.
  389. m:int:sdb_reg_to_regnum:int sdb_regnr:sdb_regnr::no_op_reg_to_regnum::0
  390. # Provide a default mapping from a DWARF2 register number to a gdb REGNUM.
  391. m:int:dwarf2_reg_to_regnum:int dwarf2_regnr:dwarf2_regnr::no_op_reg_to_regnum::0
  392. m:const char *:register_name:int regnr:regnr::0

  393. # Return the type of a register specified by the architecture.  Only
  394. # the register cache should call this function directly; others should
  395. # use "register_type".
  396. M:struct type *:register_type:int reg_nr:reg_nr

  397. M:struct frame_id:dummy_id:struct frame_info *this_frame:this_frame
  398. # Implement DUMMY_ID and PUSH_DUMMY_CALL, then delete
  399. # deprecated_fp_regnum.
  400. v:int:deprecated_fp_regnum:::-1:-1::0

  401. M:CORE_ADDR:push_dummy_call:struct value *function, struct regcache *regcache, CORE_ADDR bp_addr, int nargs, struct value **args, CORE_ADDR sp, int struct_return, CORE_ADDR struct_addr:function, regcache, bp_addr, nargs, args, sp, struct_return, struct_addr
  402. v:int:call_dummy_location::::AT_ENTRY_POINT::0
  403. 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

  404. 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
  405. m:void:print_float_info:struct ui_file *file, struct frame_info *frame, const char *args:file, frame, args::default_print_float_info::0
  406. M:void:print_vector_info:struct ui_file *file, struct frame_info *frame, const char *args:file, frame, args
  407. # MAP a GDB RAW register number onto a simulator register number.  See
  408. # also include/...-sim.h.
  409. m:int:register_sim_regno:int reg_nr:reg_nr::legacy_register_sim_regno::0
  410. m:int:cannot_fetch_register:int regnum:regnum::cannot_register_not::0
  411. m:int:cannot_store_register:int regnum:regnum::cannot_register_not::0

  412. # Determine the address where a longjmp will land and save this address
  413. # in PC.  Return nonzero on success.
  414. #
  415. # FRAME corresponds to the longjmp frame.
  416. F:int:get_longjmp_target:struct frame_info *frame, CORE_ADDR *pc:frame, pc

  417. #
  418. v:int:believe_pcc_promotion:::::::
  419. #
  420. m:int:convert_register_p:int regnum, struct type *type:regnum, type:0:generic_convert_register_p::0
  421. 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
  422. f:void:value_to_register:struct frame_info *frame, int regnum, struct type *type, const gdb_byte *buf:frame, regnum, type, buf:0
  423. # Construct a value representing the contents of register REGNUM in
  424. # frame FRAME_ID, interpreted as type TYPE.  The routine needs to
  425. # allocate and return a struct value with all value attributes
  426. # (but not the value contents) filled in.
  427. 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
  428. #
  429. m:CORE_ADDR:pointer_to_address:struct type *type, const gdb_byte *buf:type, buf::unsigned_pointer_to_address::0
  430. m:void:address_to_pointer:struct type *type, gdb_byte *buf, CORE_ADDR addr:type, buf, addr::unsigned_address_to_pointer::0
  431. M:CORE_ADDR:integer_to_address:struct type *type, const gdb_byte *buf:type, buf

  432. # Return the return-value convention that will be used by FUNCTION
  433. # to return a value of type VALTYPE.  FUNCTION may be NULL in which
  434. # case the return convention is computed based only on VALTYPE.
  435. #
  436. # If READBUF is not NULL, extract the return value and save it in this buffer.
  437. #
  438. # If WRITEBUF is not NULL, it contains a return value which will be
  439. # stored into the appropriate register.  This can be used when we want
  440. # to force the value returned by a function (see the "return" command
  441. # for instance).
  442. 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

  443. # Return true if the return value of function is stored in the first hidden
  444. # parameter.  In theory, this feature should be language-dependent, specified
  445. # by language and its ABI, such as C++.  Unfortunately, compiler may
  446. # implement it to a target-dependent feature.  So that we need such hook here
  447. # to be aware of this in GDB.
  448. m:int:return_in_first_hidden_param_p:struct type *type:type::default_return_in_first_hidden_param_p::0

  449. m:CORE_ADDR:skip_prologue:CORE_ADDR ip:ip:0:0
  450. M:CORE_ADDR:skip_main_prologue:CORE_ADDR ip:ip
  451. # On some platforms, a single function may provide multiple entry points,
  452. # e.g. one that is used for function-pointer calls and a different one
  453. # that is used for direct function calls.
  454. # In order to ensure that breakpoints set on the function will trigger
  455. # no matter via which entry point the function is entered, a platform
  456. # may provide the skip_entrypoint callback.  It is called with IP set
  457. # to the main entry point of a function (as determined by the symbol table),
  458. # and should return the address of the innermost entry point, where the
  459. # actual breakpoint needs to be set.  Note that skip_entrypoint is used
  460. # by GDB common code even when debugging optimized code, where skip_prologue
  461. # is not used.
  462. M:CORE_ADDR:skip_entrypoint:CORE_ADDR ip:ip

  463. f:int:inner_than:CORE_ADDR lhs, CORE_ADDR rhs:lhs, rhs:0:0
  464. m:const gdb_byte *:breakpoint_from_pc:CORE_ADDR *pcptr, int *lenptr:pcptr, lenptr::0:
  465. # Return the adjusted address and kind to use for Z0/Z1 packets.
  466. # KIND is usually the memory length of the breakpoint, but may have a
  467. # different target-specific meaning.
  468. m:void:remote_breakpoint_from_pc:CORE_ADDR *pcptr, int *kindptr:pcptr, kindptr:0:default_remote_breakpoint_from_pc::0
  469. M:CORE_ADDR:adjust_breakpoint_address:CORE_ADDR bpaddr:bpaddr
  470. m:int:memory_insert_breakpoint:struct bp_target_info *bp_tgt:bp_tgt:0:default_memory_insert_breakpoint::0
  471. m:int:memory_remove_breakpoint:struct bp_target_info *bp_tgt:bp_tgt:0:default_memory_remove_breakpoint::0
  472. v:CORE_ADDR:decr_pc_after_break:::0:::0

  473. # A function can be addressed by either it's "pointer" (possibly a
  474. # descriptor address) or "entry point" (first executable instruction).
  475. # The method "convert_from_func_ptr_addr" converting the former to the
  476. # latter.  gdbarch_deprecated_function_start_offset is being used to implement
  477. # a simplified subset of that functionality - the function's address
  478. # corresponds to the "function pointer" and the function's start
  479. # corresponds to the "function entry point" - and hence is redundant.

  480. v:CORE_ADDR:deprecated_function_start_offset:::0:::0

  481. # Return the remote protocol register number associated with this
  482. # register.  Normally the identity mapping.
  483. m:int:remote_register_number:int regno:regno::default_remote_register_number::0

  484. # Fetch the target specific address used to represent a load module.
  485. F:CORE_ADDR:fetch_tls_load_module_address:struct objfile *objfile:objfile
  486. #
  487. v:CORE_ADDR:frame_args_skip:::0:::0
  488. M:CORE_ADDR:unwind_pc:struct frame_info *next_frame:next_frame
  489. M:CORE_ADDR:unwind_sp:struct frame_info *next_frame:next_frame
  490. # DEPRECATED_FRAME_LOCALS_ADDRESS as been replaced by the per-frame
  491. # frame-base.  Enable frame-base before frame-unwind.
  492. F:int:frame_num_args:struct frame_info *frame:frame
  493. #
  494. M:CORE_ADDR:frame_align:CORE_ADDR address:address
  495. m:int:stabs_argument_has_addr:struct type *type:type::default_stabs_argument_has_addr::0
  496. v:int:frame_red_zone_size
  497. #
  498. m:CORE_ADDR:convert_from_func_ptr_addr:CORE_ADDR addr, struct target_ops *targ:addr, targ::convert_from_func_ptr_addr_identity::0
  499. # On some machines there are bits in addresses which are not really
  500. # part of the address, but are used by the kernel, the hardware, etc.
  501. # for special purposes.  gdbarch_addr_bits_remove takes out any such bits so
  502. # we get a "real" address such as one would find in a symbol table.
  503. # This is used only for addresses of instructions, and even then I'm
  504. # not sure it's used in all contexts.  It exists to deal with there
  505. # being a few stray bits in the PC which would mislead us, not as some
  506. # sort of generic thing to handle alignment or segmentation (it's
  507. # possible it should be in TARGET_READ_PC instead).
  508. m:CORE_ADDR:addr_bits_remove:CORE_ADDR addr:addr::core_addr_identity::0

  509. # FIXME/cagney/2001-01-18: This should be split in two.  A target method that
  510. # indicates if the target needs software single step.  An ISA method to
  511. # implement it.
  512. #
  513. # FIXME/cagney/2001-01-18: This should be replaced with something that inserts
  514. # breakpoints using the breakpoint system instead of blatting memory directly
  515. # (as with rs6000).
  516. #
  517. # FIXME/cagney/2001-01-18: The logic is backwards.  It should be asking if the
  518. # target can single step.  If not, then implement single step using breakpoints.
  519. #
  520. # A return value of 1 means that the software_single_step breakpoints
  521. # were inserted; 0 means they were not.
  522. F:int:software_single_step:struct frame_info *frame:frame

  523. # Return non-zero if the processor is executing a delay slot and a
  524. # further single-step is needed before the instruction finishes.
  525. M:int:single_step_through_delay:struct frame_info *frame:frame
  526. # FIXME: cagney/2003-08-28: Need to find a better way of selecting the
  527. # disassembler.  Perhaps objdump can handle it?
  528. f:int:print_insn:bfd_vma vma, struct disassemble_info *info:vma, info::0:
  529. f:CORE_ADDR:skip_trampoline_code:struct frame_info *frame, CORE_ADDR pc:frame, pc::generic_skip_trampoline_code::0


  530. # If in_solib_dynsym_resolve_code() returns true, and SKIP_SOLIB_RESOLVER
  531. # evaluates non-zero, this is the address where the debugger will place
  532. # a step-resume breakpoint to get us past the dynamic linker.
  533. m:CORE_ADDR:skip_solib_resolver:CORE_ADDR pc:pc::generic_skip_solib_resolver::0
  534. # Some systems also have trampoline code for returning from shared libs.
  535. m:int:in_solib_return_trampoline:CORE_ADDR pc, const char *name:pc, name::generic_in_solib_return_trampoline::0

  536. # A target might have problems with watchpoints as soon as the stack
  537. # frame of the current function has been destroyed.  This mostly happens
  538. # as the first action in a funtion's epilogue.  in_function_epilogue_p()
  539. # is defined to return a non-zero value if either the given addr is one
  540. # instruction after the stack destroying instruction up to the trailing
  541. # return instruction or if we can figure out that the stack frame has
  542. # already been invalidated regardless of the value of addr.  Targets
  543. # which don't suffer from that problem could just let this functionality
  544. # untouched.
  545. m:int:in_function_epilogue_p:CORE_ADDR addr:addr:0:generic_in_function_epilogue_p::0
  546. # Process an ELF symbol in the minimal symbol table in a backend-specific
  547. # way.  Normally this hook is supposed to do nothing, however if required,
  548. # then this hook can be used to apply tranformations to symbols that are
  549. # considered special in some way.  For example the MIPS backend uses it
  550. # to interpret \`st_other' information to mark compressed code symbols so
  551. # that they can be treated in the appropriate manner in the processing of
  552. # the main symbol table and DWARF-2 records.
  553. F:void:elf_make_msymbol_special:asymbol *sym, struct minimal_symbol *msym:sym, msym
  554. f:void:coff_make_msymbol_special:int val, struct minimal_symbol *msym:val, msym::default_coff_make_msymbol_special::0
  555. # Process a symbol in the main symbol table in a backend-specific way.
  556. # Normally this hook is supposed to do nothing, however if required,
  557. # then this hook can be used to apply tranformations to symbols that
  558. # are considered special in some way.  This is currently used by the
  559. # MIPS backend to make sure compressed code symbols have the ISA bit
  560. # set.  This in turn is needed for symbol values seen in GDB to match
  561. # the values used at the runtime by the program itself, for function
  562. # and label references.
  563. f:void:make_symbol_special:struct symbol *sym, struct objfile *objfile:sym, objfile::default_make_symbol_special::0
  564. # Adjust the address retrieved from a DWARF-2 record other than a line
  565. # entry in a backend-specific way.  Normally this hook is supposed to
  566. # return the address passed unchanged, however if that is incorrect for
  567. # any reason, then this hook can be used to fix the address up in the
  568. # required manner.  This is currently used by the MIPS backend to make
  569. # sure addresses in FDE, range records, etc. referring to compressed
  570. # code have the ISA bit set, matching line information and the symbol
  571. # table.
  572. f:CORE_ADDR:adjust_dwarf2_addr:CORE_ADDR pc:pc::default_adjust_dwarf2_addr::0
  573. # Adjust the address updated by a line entry in a backend-specific way.
  574. # Normally this hook is supposed to return the address passed unchanged,
  575. # however in the case of inconsistencies in these records, this hook can
  576. # be used to fix them up in the required manner.  This is currently used
  577. # by the MIPS backend to make sure all line addresses in compressed code
  578. # are presented with the ISA bit set, which is not always the case.  This
  579. # in turn ensures breakpoint addresses are correctly matched against the
  580. # stop PC.
  581. f:CORE_ADDR:adjust_dwarf2_line:CORE_ADDR addr, int rel:addr, rel::default_adjust_dwarf2_line::0
  582. v:int:cannot_step_breakpoint:::0:0::0
  583. v:int:have_nonsteppable_watchpoint:::0:0::0
  584. F:int:address_class_type_flags:int byte_size, int dwarf2_addr_class:byte_size, dwarf2_addr_class
  585. M:const char *:address_class_type_flags_to_name:int type_flags:type_flags

  586. # Return the appropriate type_flags for the supplied address class.
  587. # This function should return 1 if the address class was recognized and
  588. # type_flags was set, zero otherwise.
  589. M:int:address_class_name_to_type_flags:const char *name, int *type_flags_ptr:name, type_flags_ptr
  590. # Is a register in a group
  591. m:int:register_reggroup_p:int regnum, struct reggroup *reggroup:regnum, reggroup::default_register_reggroup_p::0
  592. # Fetch the pointer to the ith function argument.
  593. F:CORE_ADDR:fetch_pointer_argument:struct frame_info *frame, int argi, struct type *type:frame, argi, type

  594. # Iterate over all supported register notes in a core file.  For each
  595. # supported register note section, the iterator must call CB and pass
  596. # CB_DATA unchanged.  If REGCACHE is not NULL, the iterator can limit
  597. # the supported register note sections based on the current register
  598. # values.  Otherwise it should enumerate all supported register note
  599. # sections.
  600. M:void:iterate_over_regset_sections:iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache:cb, cb_data, regcache

  601. # Create core file notes
  602. M:char *:make_corefile_notes:bfd *obfd, int *note_size:obfd, note_size

  603. # The elfcore writer hook to use to write Linux prpsinfo notes to core
  604. # files.  Most Linux architectures use the same prpsinfo32 or
  605. # prpsinfo64 layouts, and so won't need to provide this hook, as we
  606. # call the Linux generic routines in bfd to write prpsinfo notes by
  607. # default.
  608. F:char *:elfcore_write_linux_prpsinfo:bfd *obfd, char *note_data, int *note_size, const struct elf_internal_linux_prpsinfo *info:obfd, note_data, note_size, info

  609. # Find core file memory regions
  610. M:int:find_memory_regions:find_memory_region_ftype func, void *data:func, data

  611. # Read offset OFFSET of TARGET_OBJECT_LIBRARIES formatted shared libraries list from
  612. # core file into buffer READBUF with length LEN.  Return the number of bytes read
  613. # (zero indicates failure).
  614. # failed, otherwise, return the red length of READBUF.
  615. M:ULONGEST:core_xfer_shared_libraries:gdb_byte *readbuf, ULONGEST offset, ULONGEST len:readbuf, offset, len

  616. # Read offset OFFSET of TARGET_OBJECT_LIBRARIES_AIX formatted shared
  617. # libraries list from core file into buffer READBUF with length LEN.
  618. # Return the number of bytes read (zero indicates failure).
  619. M:ULONGEST:core_xfer_shared_libraries_aix:gdb_byte *readbuf, ULONGEST offset, ULONGEST len:readbuf, offset, len

  620. # How the core target converts a PTID from a core file to a string.
  621. M:char *:core_pid_to_str:ptid_t ptid:ptid

  622. # BFD target to use when generating a core file.
  623. V:const char *:gcore_bfd_target:::0:0:::pstring (gdbarch->gcore_bfd_target)

  624. # If the elements of C++ vtables are in-place function descriptors rather
  625. # than normal function pointers (which may point to code or a descriptor),
  626. # set this to one.
  627. v:int:vtable_function_descriptors:::0:0::0

  628. # Set if the least significant bit of the delta is used instead of the least
  629. # significant bit of the pfn for pointers to virtual member functions.
  630. v:int:vbit_in_delta:::0:0::0

  631. # Advance PC to next instruction in order to skip a permanent breakpoint.
  632. f:void:skip_permanent_breakpoint:struct regcache *regcache:regcache:default_skip_permanent_breakpoint:default_skip_permanent_breakpoint::0

  633. # The maximum length of an instruction on this architecture in bytes.
  634. V:ULONGEST:max_insn_length:::0:0

  635. # Copy the instruction at FROM to TO, and make any adjustments
  636. # necessary to single-step it at that address.
  637. #
  638. # REGS holds the state the thread's registers will have before
  639. # executing the copied instruction; the PC in REGS will refer to FROM,
  640. # not the copy at TO.  The caller should update it to point at TO later.
  641. #
  642. # Return a pointer to data of the architecture's choice to be passed
  643. # to gdbarch_displaced_step_fixup.  Or, return NULL to indicate that
  644. # the instruction's effects have been completely simulated, with the
  645. # resulting state written back to REGS.
  646. #
  647. # For a general explanation of displaced stepping and how GDB uses it,
  648. # see the comments in infrun.c.
  649. #
  650. # The TO area is only guaranteed to have space for
  651. # gdbarch_max_insn_length (arch) bytes, so this function must not
  652. # write more bytes than that to that area.
  653. #
  654. # If you do not provide this function, GDB assumes that the
  655. # architecture does not support displaced stepping.
  656. #
  657. # If your architecture doesn't need to adjust instructions before
  658. # single-stepping them, consider using simple_displaced_step_copy_insn
  659. # here.
  660. M:struct displaced_step_closure *:displaced_step_copy_insn:CORE_ADDR from, CORE_ADDR to, struct regcache *regs:from, to, regs

  661. # Return true if GDB should use hardware single-stepping to execute
  662. # the displaced instruction identified by CLOSURE.  If false,
  663. # GDB will simply restart execution at the displaced instruction
  664. # location, and it is up to the target to ensure GDB will receive
  665. # control again (e.g. by placing a software breakpoint instruction
  666. # into the displaced instruction buffer).
  667. #
  668. # The default implementation returns false on all targets that
  669. # provide a gdbarch_software_single_step routine, and true otherwise.
  670. m:int:displaced_step_hw_singlestep:struct displaced_step_closure *closure:closure::default_displaced_step_hw_singlestep::0

  671. # Fix up the state resulting from successfully single-stepping a
  672. # displaced instruction, to give the result we would have gotten from
  673. # stepping the instruction in its original location.
  674. #
  675. # REGS is the register state resulting from single-stepping the
  676. # displaced instruction.
  677. #
  678. # CLOSURE is the result from the matching call to
  679. # gdbarch_displaced_step_copy_insn.
  680. #
  681. # If you provide gdbarch_displaced_step_copy_insn.but not this
  682. # function, then GDB assumes that no fixup is needed after
  683. # single-stepping the instruction.
  684. #
  685. # For a general explanation of displaced stepping and how GDB uses it,
  686. # see the comments in infrun.c.
  687. M:void:displaced_step_fixup:struct displaced_step_closure *closure, CORE_ADDR from, CORE_ADDR to, struct regcache *regs:closure, from, to, regs::NULL

  688. # Free a closure returned by gdbarch_displaced_step_copy_insn.
  689. #
  690. # If you provide gdbarch_displaced_step_copy_insn, you must provide
  691. # this function as well.
  692. #
  693. # If your architecture uses closures that don't need to be freed, then
  694. # you can use simple_displaced_step_free_closure here.
  695. #
  696. # For a general explanation of displaced stepping and how GDB uses it,
  697. # see the comments in infrun.c.
  698. m:void:displaced_step_free_closure:struct displaced_step_closure *closure:closure::NULL::(! gdbarch->displaced_step_free_closure) != (! gdbarch->displaced_step_copy_insn)

  699. # Return the address of an appropriate place to put displaced
  700. # instructions while we step over them.  There need only be one such
  701. # place, since we're only stepping one thread over a breakpoint at a
  702. # time.
  703. #
  704. # For a general explanation of displaced stepping and how GDB uses it,
  705. # see the comments in infrun.c.
  706. m:CORE_ADDR:displaced_step_location:void:::NULL::(! gdbarch->displaced_step_location) != (! gdbarch->displaced_step_copy_insn)

  707. # Relocate an instruction to execute at a different address.  OLDLOC
  708. # is the address in the inferior memory where the instruction to
  709. # relocate is currently at.  On input, TO points to the destination
  710. # where we want the instruction to be copied (and possibly adjusted)
  711. # to.  On output, it points to one past the end of the resulting
  712. # instruction(s).  The effect of executing the instruction at TO shall
  713. # be the same as if executing it at FROM.  For example, call
  714. # instructions that implicitly push the return address on the stack
  715. # should be adjusted to return to the instruction after OLDLOC;
  716. # relative branches, and other PC-relative instructions need the
  717. # offset adjusted; etc.
  718. M:void:relocate_instruction:CORE_ADDR *to, CORE_ADDR from:to, from::NULL

  719. # Refresh overlay mapped state for section OSECT.
  720. F:void:overlay_update:struct obj_section *osect:osect

  721. M:const struct target_desc *:core_read_description:struct target_ops *target, bfd *abfd:target, abfd

  722. # Handle special encoding of static variables in stabs debug info.
  723. F:const char *:static_transform_name:const char *name:name
  724. # Set if the address in N_SO or N_FUN stabs may be zero.
  725. v:int:sofun_address_maybe_missing:::0:0::0

  726. # Parse the instruction at ADDR storing in the record execution log
  727. # the registers REGCACHE and memory ranges that will be affected when
  728. # the instruction executes, along with their current values.
  729. # Return -1 if something goes wrong, 0 otherwise.
  730. M:int:process_record:struct regcache *regcache, CORE_ADDR addr:regcache, addr

  731. # Save process state after a signal.
  732. # Return -1 if something goes wrong, 0 otherwise.
  733. M:int:process_record_signal:struct regcache *regcache, enum gdb_signal signal:regcache, signal

  734. # Signal translation: translate inferior's signal (target's) number
  735. # into GDB's representation.  The implementation of this method must
  736. # be host independent.  IOW, don't rely on symbols of the NAT_FILE
  737. # header (the nm-*.h files), the host <signal.h> header, or similar
  738. # headers.  This is mainly used when cross-debugging core files ---
  739. # "Live" targets hide the translation behind the target interface
  740. # (target_wait, target_resume, etc.).
  741. M:enum gdb_signal:gdb_signal_from_target:int signo:signo

  742. # Signal translation: translate the GDB's internal signal number into
  743. # the inferior's signal (target's) representation.  The implementation
  744. # of this method must be host independent.  IOW, don't rely on symbols
  745. # of the NAT_FILE header (the nm-*.h files), the host <signal.h>
  746. # header, or similar headers.
  747. # Return the target signal number if found, or -1 if the GDB internal
  748. # signal number is invalid.
  749. M:int:gdb_signal_to_target:enum gdb_signal signal:signal

  750. # Extra signal info inspection.
  751. #
  752. # Return a type suitable to inspect extra signal information.
  753. M:struct type *:get_siginfo_type:void:

  754. # Record architecture-specific information from the symbol table.
  755. M:void:record_special_symbol:struct objfile *objfile, asymbol *sym:objfile, sym

  756. # Function for the 'catch syscall' feature.

  757. # Get architecture-specific system calls information from registers.
  758. M:LONGEST:get_syscall_number:ptid_t ptid:ptid

  759. # The filename of the XML syscall for this architecture.
  760. v:const char *:xml_syscall_file:::0:0::0:pstring (gdbarch->xml_syscall_file)

  761. # Information about system calls from this architecture
  762. v:struct syscalls_info *:syscalls_info:::0:0::0:host_address_to_string (gdbarch->syscalls_info)

  763. # SystemTap related fields and functions.

  764. # A NULL-terminated array of prefixes used to mark an integer constant
  765. # on the architecture's assembly.
  766. # For example, on x86 integer constants are written as:
  767. #
  768. \$10 ;; integer constant 10
  769. #
  770. # in this case, this prefix would be the character \`\$\'.
  771. v:const char *const *:stap_integer_prefixes:::0:0::0:pstring_list (gdbarch->stap_integer_prefixes)

  772. # A NULL-terminated array of suffixes used to mark an integer constant
  773. # on the architecture's assembly.
  774. v:const char *const *:stap_integer_suffixes:::0:0::0:pstring_list (gdbarch->stap_integer_suffixes)

  775. # A NULL-terminated array of prefixes used to mark a register name on
  776. # the architecture's assembly.
  777. # For example, on x86 the register name is written as:
  778. #
  779. \%eax ;; register eax
  780. #
  781. # in this case, this prefix would be the character \`\%\'.
  782. v:const char *const *:stap_register_prefixes:::0:0::0:pstring_list (gdbarch->stap_register_prefixes)

  783. # A NULL-terminated array of suffixes used to mark a register name on
  784. # the architecture's assembly.
  785. v:const char *const *:stap_register_suffixes:::0:0::0:pstring_list (gdbarch->stap_register_suffixes)

  786. # A NULL-terminated array of prefixes used to mark a register
  787. # indirection on the architecture's assembly.
  788. # For example, on x86 the register indirection is written as:
  789. #
  790. \(\%eax\) ;; indirecting eax
  791. #
  792. # in this case, this prefix would be the charater \`\(\'.
  793. #
  794. # Please note that we use the indirection prefix also for register
  795. # displacement, e.g., \`4\(\%eax\)\' on x86.
  796. v:const char *const *:stap_register_indirection_prefixes:::0:0::0:pstring_list (gdbarch->stap_register_indirection_prefixes)

  797. # A NULL-terminated array of suffixes used to mark a register
  798. # indirection on the architecture's assembly.
  799. # For example, on x86 the register indirection is written as:
  800. #
  801. \(\%eax\) ;; indirecting eax
  802. #
  803. # in this case, this prefix would be the charater \`\)\'.
  804. #
  805. # Please note that we use the indirection suffix also for register
  806. # displacement, e.g., \`4\(\%eax\)\' on x86.
  807. v:const char *const *:stap_register_indirection_suffixes:::0:0::0:pstring_list (gdbarch->stap_register_indirection_suffixes)

  808. # Prefix(es) used to name a register using GDB's nomenclature.
  809. #
  810. # For example, on PPC a register is represented by a number in the assembly
  811. # language (e.g., \`10\' is the 10th general-purpose register).  However,
  812. # inside GDB this same register has an \`r\' appended to its name, so the 10th
  813. # register would be represented as \`r10\' internally.
  814. v:const char *:stap_gdb_register_prefix:::0:0::0:pstring (gdbarch->stap_gdb_register_prefix)

  815. # Suffix used to name a register using GDB's nomenclature.
  816. v:const char *:stap_gdb_register_suffix:::0:0::0:pstring (gdbarch->stap_gdb_register_suffix)

  817. # Check if S is a single operand.
  818. #
  819. # Single operands can be:
  820. \- Literal integers, e.g. \`\$10\' on x86
  821. \- Register access, e.g. \`\%eax\' on x86
  822. \- Register indirection, e.g. \`\(\%eax\)\' on x86
  823. \- Register displacement, e.g. \`4\(\%eax\)\' on x86
  824. #
  825. # This function should check for these patterns on the string
  826. # and return 1 if some were found, or zero otherwise.  Please try to match
  827. # as much info as you can from the string, i.e., if you have to match
  828. # something like \`\(\%\', do not match just the \`\(\'.
  829. M:int:stap_is_single_operand:const char *s:s

  830. # Function used to handle a "special case" in the parser.
  831. #
  832. # A "special case" is considered to be an unknown token, i.e., a token
  833. # that the parser does not know how to parse.  A good example of special
  834. # case would be ARM's register displacement syntax:
  835. #
  836. #  [R0, #4]  ;; displacing R0 by 4
  837. #
  838. # Since the parser assumes that a register displacement is of the form:
  839. #
  840. #  <number> <indirection_prefix> <register_name> <indirection_suffix>
  841. #
  842. # it means that it will not be able to recognize and parse this odd syntax.
  843. # Therefore, we should add a special case function that will handle this token.
  844. #
  845. # This function should generate the proper expression form of the expression
  846. # using GDB\'s internal expression mechanism (e.g., \`write_exp_elt_opcode\'
  847. # and so on).  It should also return 1 if the parsing was successful, or zero
  848. # if the token was not recognized as a special token (in this case, returning
  849. # zero means that the special parser is deferring the parsing to the generic
  850. # parser), and should advance the buffer pointer (p->arg).
  851. M:int:stap_parse_special_token:struct stap_parse_info *p:p


  852. # True if the list of shared libraries is one and only for all
  853. # processes, as opposed to a list of shared libraries per inferior.
  854. # This usually means that all processes, although may or may not share
  855. # an address space, will see the same set of symbols at the same
  856. # addresses.
  857. v:int:has_global_solist:::0:0::0

  858. # On some targets, even though each inferior has its own private
  859. # address space, the debug interface takes care of making breakpoints
  860. # visible to all address spaces automatically.  For such cases,
  861. # this property should be set to true.
  862. v:int:has_global_breakpoints:::0:0::0

  863. # True if inferiors share an address space (e.g., uClinux).
  864. m:int:has_shared_address_space:void:::default_has_shared_address_space::0

  865. # True if a fast tracepoint can be set at an address.
  866. m:int:fast_tracepoint_valid_at:CORE_ADDR addr, int *isize, char **msg:addr, isize, msg::default_fast_tracepoint_valid_at::0

  867. # Return the "auto" target charset.
  868. f:const char *:auto_charset:void::default_auto_charset:default_auto_charset::0
  869. # Return the "auto" target wide charset.
  870. f:const char *:auto_wide_charset:void::default_auto_wide_charset:default_auto_wide_charset::0

  871. # If non-empty, this is a file extension that will be opened in place
  872. # of the file extension reported by the shared library list.
  873. #
  874. # This is most useful for toolchains that use a post-linker tool,
  875. # where the names of the files run on the target differ in extension
  876. # compared to the names of the files GDB should load for debug info.
  877. v:const char *:solib_symbols_extension:::::::pstring (gdbarch->solib_symbols_extension)

  878. # If true, the target OS has DOS-based file system semantics.  That
  879. # is, absolute paths include a drive name, and the backslash is
  880. # considered a directory separator.
  881. v:int:has_dos_based_file_system:::0:0::0

  882. # Generate bytecodes to collect the return address in a frame.
  883. # Since the bytecodes run on the target, possibly with GDB not even
  884. # connected, the full unwinding machinery is not available, and
  885. # typically this function will issue bytecodes for one or more likely
  886. # places that the return address may be found.
  887. m:void:gen_return_address:struct agent_expr *ax, struct axs_value *value, CORE_ADDR scope:ax, value, scope::default_gen_return_address::0

  888. # Implement the "info proc" command.
  889. M:void:info_proc:const char *args, enum info_proc_what what:args, what

  890. # Implement the "info proc" command for core files.  Noe that there
  891. # are two "info_proc"-like methods on gdbarch -- one for core files,
  892. # one for live targets.
  893. M:void:core_info_proc:const char *args, enum info_proc_what what:args, what

  894. # Iterate over all objfiles in the order that makes the most sense
  895. # for the architecture to make global symbol searches.
  896. #
  897. # CB is a callback function where OBJFILE is the objfile to be searched,
  898. # and CB_DATA a pointer to user-defined data (the same data that is passed
  899. # when calling this gdbarch method).  The iteration stops if this function
  900. # returns nonzero.
  901. #
  902. # CB_DATA is a pointer to some user-defined data to be passed to
  903. # the callback.
  904. #
  905. # If not NULL, CURRENT_OBJFILE corresponds to the objfile being
  906. # inspected when the symbol search was requested.
  907. 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

  908. # Ravenscar arch-dependent ops.
  909. v:struct ravenscar_arch_ops *:ravenscar_ops:::NULL:NULL::0:host_address_to_string (gdbarch->ravenscar_ops)

  910. # Return non-zero if the instruction at ADDR is a call; zero otherwise.
  911. m:int:insn_is_call:CORE_ADDR addr:addr::default_insn_is_call::0

  912. # Return non-zero if the instruction at ADDR is a return; zero otherwise.
  913. m:int:insn_is_ret:CORE_ADDR addr:addr::default_insn_is_ret::0

  914. # Return non-zero if the instruction at ADDR is a jump; zero otherwise.
  915. m:int:insn_is_jump:CORE_ADDR addr:addr::default_insn_is_jump::0

  916. # Read one auxv entry from *READPTR, not reading locations >= ENDPTR.
  917. # Return 0 if *READPTR is already at the end of the buffer.
  918. # Return -1 if there is insufficient buffer for a whole entry.
  919. # Return 1 if an entry was read into *TYPEP and *VALP.
  920. M:int:auxv_parse:gdb_byte **readptr, gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp:readptr, endptr, typep, valp

  921. # Find the address range of the current inferior's vsyscall/vDSO, and
  922. # write it to *RANGE.  If the vsyscall's length can't be determined, a
  923. # range with zero length is returned.  Returns true if the vsyscall is
  924. # found, false otherwise.
  925. m:int:vsyscall_range:struct mem_range *range:range::default_vsyscall_range::0

  926. # Allocate SIZE bytes of PROT protected page aligned memory in inferior.
  927. # PROT has GDB_MMAP_PROT_* bitmask format.
  928. # Throw an error if it is not possible.  Returned address is always valid.
  929. f:CORE_ADDR:infcall_mmap:CORE_ADDR size, unsigned prot:size, prot::default_infcall_mmap::0

  930. # Return string (caller has to use xfree for it) with options for GCC
  931. # to produce code for this target, typically "-m64", "-m32" or "-m31".
  932. # These options are put before CU's DW_AT_producer compilation options so that
  933. # they can override it.  Method may also return NULL.
  934. m:char *:gcc_target_options:void:::default_gcc_target_options::0

  935. # Return a regular expression that matches names used by this
  936. # architecture in GNU configury triplets.  The result is statically
  937. # allocated and must not be freed.  The default implementation simply
  938. # returns the BFD architecture name, which is correct in nearly every
  939. # case.
  940. m:const char *:gnu_triplet_regexp:void:::default_gnu_triplet_regexp::0
  941. EOF
  942. }

  943. #
  944. # The .log file
  945. #
  946. exec > new-gdbarch.log
  947. function_list | while do_read
  948. do
  949.     cat <<EOF
  950. ${class} ${returntype} ${function} ($formal)
  951. EOF
  952.     for r in ${read}
  953.     do
  954.         eval echo \"\ \ \ \ ${r}=\${${r}}\"
  955.     done
  956.     if class_is_predicate_p && fallback_default_p
  957.     then
  958.         echo "Error: predicate function ${function} can not have a non- multi-arch default" 1>&2
  959.         kill $$
  960.         exit 1
  961.     fi
  962.     if [ "x${invalid_p}" = "x0" -a -n "${postdefault}" ]
  963.     then
  964.         echo "Error: postdefault is useless when invalid_p=0" 1>&2
  965.         kill $$
  966.         exit 1
  967.     fi
  968.     if class_is_multiarch_p
  969.     then
  970.         if class_is_predicate_p ; then :
  971.         elif test "x${predefault}" = "x"
  972.         then
  973.             echo "Error: pure multi-arch function ${function} must have a predefault" 1>&2
  974.             kill $$
  975.             exit 1
  976.         fi
  977.     fi
  978.     echo ""
  979. done

  980. exec 1>&2
  981. compare_new gdbarch.log


  982. copyright ()
  983. {
  984. cat <<EOF
  985. /* *INDENT-OFF* */ /* THIS FILE IS GENERATED -*- buffer-read-only: t -*- */
  986. /* vi:set ro: */

  987. /* Dynamic architecture support for GDB, the GNU debugger.

  988.    Copyright (C) 1998-2015 Free Software Foundation, Inc.

  989.    This file is part of GDB.

  990.    This program is free software; you can redistribute it and/or modify
  991.    it under the terms of the GNU General Public License as published by
  992.    the Free Software Foundation; either version 3 of the License, or
  993.    (at your option) any later version.

  994.    This program is distributed in the hope that it will be useful,
  995.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  996.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  997.    GNU General Public License for more details.

  998.    You should have received a copy of the GNU General Public License
  999.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  1000. /* This file was created with the aid of \`\`gdbarch.sh''.

  1001.    The Bourne shell script \`\`gdbarch.sh'' creates the files
  1002.    \`\`new-gdbarch.c'' and \`\`new-gdbarch.h and then compares them
  1003.    against the existing \`\`gdbarch.[hc]''.  Any differences found
  1004.    being reported.

  1005.    If editing this file, please also run gdbarch.sh and merge any
  1006.    changes into that script. Conversely, when making sweeping changes
  1007.    to this file, modifying gdbarch.sh and using its output may prove
  1008.    easier.  */

  1009. EOF
  1010. }

  1011. #
  1012. # The .h file
  1013. #

  1014. exec > new-gdbarch.h
  1015. copyright
  1016. cat <<EOF
  1017. #ifndef GDBARCH_H
  1018. #define GDBARCH_H

  1019. #include "frame.h"

  1020. struct floatformat;
  1021. struct ui_file;
  1022. struct value;
  1023. struct objfile;
  1024. struct obj_section;
  1025. struct minimal_symbol;
  1026. struct regcache;
  1027. struct reggroup;
  1028. struct regset;
  1029. struct disassemble_info;
  1030. struct target_ops;
  1031. struct obstack;
  1032. struct bp_target_info;
  1033. struct target_desc;
  1034. struct objfile;
  1035. struct symbol;
  1036. struct displaced_step_closure;
  1037. struct core_regset_section;
  1038. struct syscall;
  1039. struct agent_expr;
  1040. struct axs_value;
  1041. struct stap_parse_info;
  1042. struct ravenscar_arch_ops;
  1043. struct elf_internal_linux_prpsinfo;
  1044. struct mem_range;
  1045. struct syscalls_info;

  1046. /* The architecture associated with the inferior through the
  1047.    connection to the target.

  1048.    The architecture vector provides some information that is really a
  1049.    property of the inferior, accessed through a particular target:
  1050.    ptrace operations; the layout of certain RSP packets; the solib_ops
  1051.    vector; etc.  To differentiate architecture accesses to
  1052.    per-inferior/target properties from
  1053.    per-thread/per-frame/per-objfile properties, accesses to
  1054.    per-inferior/target properties should be made through this
  1055.    gdbarch.  */

  1056. /* This is a convenience wrapper for 'current_inferior ()->gdbarch'.  */
  1057. extern struct gdbarch *target_gdbarch (void);

  1058. /* Callback type for the 'iterate_over_objfiles_in_search_order'
  1059.    gdbarch  method.  */

  1060. typedef int (iterate_over_objfiles_in_search_order_cb_ftype)
  1061.   (struct objfile *objfile, void *cb_data);

  1062. typedef void (iterate_over_regset_sections_cb)
  1063.   (const char *sect_name, int size, const struct regset *regset,
  1064.    const char *human_name, void *cb_data);
  1065. EOF

  1066. # function typedef's
  1067. printf "\n"
  1068. printf "\n"
  1069. printf "/* The following are pre-initialized by GDBARCH.  */\n"
  1070. function_list | while do_read
  1071. do
  1072.     if class_is_info_p
  1073.     then
  1074.         printf "\n"
  1075.         printf "extern ${returntype} gdbarch_${function} (struct gdbarch *gdbarch);\n"
  1076.         printf "/* set_gdbarch_${function}() - not applicable - pre-initialized.  */\n"
  1077.     fi
  1078. done

  1079. # function typedef's
  1080. printf "\n"
  1081. printf "\n"
  1082. printf "/* The following are initialized by the target dependent code.  */\n"
  1083. function_list | while do_read
  1084. do
  1085.     if [ -n "${comment}" ]
  1086.     then
  1087.         echo "${comment}" | sed \
  1088.             -e '2 s,#,/*,' \
  1089.             -e '3,$ s,#,  ,' \
  1090.             -e '$ s,$, */,'
  1091.     fi

  1092.     if class_is_predicate_p
  1093.     then
  1094.         printf "\n"
  1095.         printf "extern int gdbarch_${function}_p (struct gdbarch *gdbarch);\n"
  1096.     fi
  1097.     if class_is_variable_p
  1098.     then
  1099.         printf "\n"
  1100.         printf "extern ${returntype} gdbarch_${function} (struct gdbarch *gdbarch);\n"
  1101.         printf "extern void set_gdbarch_${function} (struct gdbarch *gdbarch, ${returntype} ${function});\n"
  1102.     fi
  1103.     if class_is_function_p
  1104.     then
  1105.         printf "\n"
  1106.         if [ "x${formal}" = "xvoid" ] && class_is_multiarch_p
  1107.         then
  1108.             printf "typedef ${returntype} (gdbarch_${function}_ftype) (struct gdbarch *gdbarch);\n"
  1109.         elif class_is_multiarch_p
  1110.         then
  1111.             printf "typedef ${returntype} (gdbarch_${function}_ftype) (struct gdbarch *gdbarch, ${formal});\n"
  1112.         else
  1113.             printf "typedef ${returntype} (gdbarch_${function}_ftype) (${formal});\n"
  1114.         fi
  1115.         if [ "x${formal}" = "xvoid" ]
  1116.         then
  1117.           printf "extern ${returntype} gdbarch_${function} (struct gdbarch *gdbarch);\n"
  1118.         else
  1119.           printf "extern ${returntype} gdbarch_${function} (struct gdbarch *gdbarch, ${formal});\n"
  1120.         fi
  1121.         printf "extern void set_gdbarch_${function} (struct gdbarch *gdbarch, gdbarch_${function}_ftype *${function});\n"
  1122.     fi
  1123. done

  1124. # close it off
  1125. cat <<EOF

  1126. /* Definition for an unknown syscall, used basically in error-cases.  */
  1127. #define UNKNOWN_SYSCALL (-1)

  1128. extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);


  1129. /* Mechanism for co-ordinating the selection of a specific
  1130.    architecture.

  1131.    GDB targets (*-tdep.c) can register an interest in a specific
  1132.    architecture.  Other GDB components can register a need to maintain
  1133.    per-architecture data.

  1134.    The mechanisms below ensures that there is only a loose connection
  1135.    between the set-architecture command and the various GDB
  1136.    components.  Each component can independently register their need
  1137.    to maintain architecture specific data with gdbarch.

  1138.    Pragmatics:

  1139.    Previously, a single TARGET_ARCHITECTURE_HOOK was provided.  It
  1140.    didn't scale.

  1141.    The more traditional mega-struct containing architecture specific
  1142.    data for all the various GDB components was also considered.  Since
  1143.    GDB is built from a variable number of (fairly independent)
  1144.    components it was determined that the global aproach was not
  1145.    applicable.  */


  1146. /* Register a new architectural family with GDB.

  1147.    Register support for the specified ARCHITECTURE with GDB.  When
  1148.    gdbarch determines that the specified architecture has been
  1149.    selected, the corresponding INIT function is called.

  1150.    --

  1151.    The INIT function takes two parameters: INFO which contains the
  1152.    information available to gdbarch about the (possibly new)
  1153.    architecture; ARCHES which is a list of the previously created
  1154.    \`\`struct gdbarch'' for this architecture.

  1155.    The INFO parameter is, as far as possible, be pre-initialized with
  1156.    information obtained from INFO.ABFD or the global defaults.

  1157.    The ARCHES parameter is a linked list (sorted most recently used)
  1158.    of all the previously created architures for this architecture
  1159.    family.  The (possibly NULL) ARCHES->gdbarch can used to access
  1160.    values from the previously selected architecture for this
  1161.    architecture family.

  1162.    The INIT function shall return any of: NULL - indicating that it
  1163.    doesn't recognize the selected architecture; an existing \`\`struct
  1164.    gdbarch'' from the ARCHES list - indicating that the new
  1165.    architecture is just a synonym for an earlier architecture (see
  1166.    gdbarch_list_lookup_by_info()); a newly created \`\`struct gdbarch''
  1167.    - that describes the selected architecture (see gdbarch_alloc()).

  1168.    The DUMP_TDEP function shall print out all target specific values.
  1169.    Care should be taken to ensure that the function works in both the
  1170.    multi-arch and non- multi-arch cases.  */

  1171. struct gdbarch_list
  1172. {
  1173.   struct gdbarch *gdbarch;
  1174.   struct gdbarch_list *next;
  1175. };

  1176. struct gdbarch_info
  1177. {
  1178.   /* Use default: NULL (ZERO).  */
  1179.   const struct bfd_arch_info *bfd_arch_info;

  1180.   /* Use default: BFD_ENDIAN_UNKNOWN (NB: is not ZERO).  */
  1181.   enum bfd_endian byte_order;

  1182.   enum bfd_endian byte_order_for_code;

  1183.   /* Use default: NULL (ZERO).  */
  1184.   bfd *abfd;

  1185.   /* Use default: NULL (ZERO).  */
  1186.   struct gdbarch_tdep_info *tdep_info;

  1187.   /* Use default: GDB_OSABI_UNINITIALIZED (-1).  */
  1188.   enum gdb_osabi osabi;

  1189.   /* Use default: NULL (ZERO).  */
  1190.   const struct target_desc *target_desc;
  1191. };

  1192. typedef struct gdbarch *(gdbarch_init_ftype) (struct gdbarch_info info, struct gdbarch_list *arches);
  1193. typedef void (gdbarch_dump_tdep_ftype) (struct gdbarch *gdbarch, struct ui_file *file);

  1194. /* DEPRECATED - use gdbarch_register() */
  1195. extern void register_gdbarch_init (enum bfd_architecture architecture, gdbarch_init_ftype *);

  1196. extern void gdbarch_register (enum bfd_architecture architecture,
  1197.                               gdbarch_init_ftype *,
  1198.                               gdbarch_dump_tdep_ftype *);


  1199. /* Return a freshly allocated, NULL terminated, array of the valid
  1200.    architecture names.  Since architectures are registered during the
  1201.    _initialize phase this function only returns useful information
  1202.    once initialization has been completed.  */

  1203. extern const char **gdbarch_printable_names (void);


  1204. /* Helper function.  Search the list of ARCHES for a GDBARCH that
  1205.    matches the information provided by INFO.  */

  1206. extern struct gdbarch_list *gdbarch_list_lookup_by_info (struct gdbarch_list *arches, const struct gdbarch_info *info);


  1207. /* Helper function.  Create a preliminary \`\`struct gdbarch''.  Perform
  1208.    basic initialization using values obtained from the INFO and TDEP
  1209.    parameters.  set_gdbarch_*() functions are called to complete the
  1210.    initialization of the object.  */

  1211. extern struct gdbarch *gdbarch_alloc (const struct gdbarch_info *info, struct gdbarch_tdep *tdep);


  1212. /* Helper function.  Free a partially-constructed \`\`struct gdbarch''.
  1213.    It is assumed that the caller freeds the \`\`struct
  1214.    gdbarch_tdep''.  */

  1215. extern void gdbarch_free (struct gdbarch *);


  1216. /* Helper function.  Allocate memory from the \`\`struct gdbarch''
  1217.    obstack.  The memory is freed when the corresponding architecture
  1218.    is also freed.  */

  1219. extern void *gdbarch_obstack_zalloc (struct gdbarch *gdbarch, long size);
  1220. #define GDBARCH_OBSTACK_CALLOC(GDBARCH, NR, TYPE) ((TYPE *) gdbarch_obstack_zalloc ((GDBARCH), (NR) * sizeof (TYPE)))
  1221. #define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE) ((TYPE *) gdbarch_obstack_zalloc ((GDBARCH), sizeof (TYPE)))


  1222. /* Helper function.  Force an update of the current architecture.

  1223.    The actual architecture selected is determined by INFO, \`\`(gdb) set
  1224.    architecture'' et.al., the existing architecture and BFD's default
  1225.    architecture.  INFO should be initialized to zero and then selected
  1226.    fields should be updated.

  1227.    Returns non-zero if the update succeeds.  */

  1228. extern int gdbarch_update_p (struct gdbarch_info info);


  1229. /* Helper function.  Find an architecture matching info.

  1230.    INFO should be initialized using gdbarch_info_init, relevant fields
  1231.    set, and then finished using gdbarch_info_fill.

  1232.    Returns the corresponding architecture, or NULL if no matching
  1233.    architecture was found.  */

  1234. extern struct gdbarch *gdbarch_find_by_info (struct gdbarch_info info);


  1235. /* Helper function.  Set the target gdbarch to "gdbarch".  */

  1236. extern void set_target_gdbarch (struct gdbarch *gdbarch);


  1237. /* Register per-architecture data-pointer.

  1238.    Reserve space for a per-architecture data-pointer.  An identifier
  1239.    for the reserved data-pointer is returned.  That identifer should
  1240.    be saved in a local static variable.

  1241.    Memory for the per-architecture data shall be allocated using
  1242.    gdbarch_obstack_zalloc.  That memory will be deleted when the
  1243.    corresponding architecture object is deleted.

  1244.    When a previously created architecture is re-selected, the
  1245.    per-architecture data-pointer for that previous architecture is
  1246.    restored.  INIT() is not re-called.

  1247.    Multiple registrarants for any architecture are allowed (and
  1248.    strongly encouraged).  */

  1249. struct gdbarch_data;

  1250. typedef void *(gdbarch_data_pre_init_ftype) (struct obstack *obstack);
  1251. extern struct gdbarch_data *gdbarch_data_register_pre_init (gdbarch_data_pre_init_ftype *init);
  1252. typedef void *(gdbarch_data_post_init_ftype) (struct gdbarch *gdbarch);
  1253. extern struct gdbarch_data *gdbarch_data_register_post_init (gdbarch_data_post_init_ftype *init);
  1254. extern void deprecated_set_gdbarch_data (struct gdbarch *gdbarch,
  1255.                                          struct gdbarch_data *data,
  1256.                                          void *pointer);

  1257. extern void *gdbarch_data (struct gdbarch *gdbarch, struct gdbarch_data *);


  1258. /* Set the dynamic target-system-dependent parameters (architecture,
  1259.    byte-order, ...) using information found in the BFD.  */

  1260. extern void set_gdbarch_from_file (bfd *);


  1261. /* Initialize the current architecture to the "first" one we find on
  1262.    our list.  */

  1263. extern void initialize_current_architecture (void);

  1264. /* gdbarch trace variable */
  1265. extern unsigned int gdbarch_debug;

  1266. extern void gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file);

  1267. #endif
  1268. EOF
  1269. exec 1>&2
  1270. #../move-if-change new-gdbarch.h gdbarch.h
  1271. compare_new gdbarch.h


  1272. #
  1273. # C file
  1274. #

  1275. exec > new-gdbarch.c
  1276. copyright
  1277. cat <<EOF

  1278. #include "defs.h"
  1279. #include "arch-utils.h"

  1280. #include "gdbcmd.h"
  1281. #include "inferior.h"
  1282. #include "symcat.h"

  1283. #include "floatformat.h"
  1284. #include "reggroups.h"
  1285. #include "osabi.h"
  1286. #include "gdb_obstack.h"
  1287. #include "observer.h"
  1288. #include "regcache.h"
  1289. #include "objfiles.h"

  1290. /* Static function declarations */

  1291. static void alloc_gdbarch_data (struct gdbarch *);

  1292. /* Non-zero if we want to trace architecture code.  */

  1293. #ifndef GDBARCH_DEBUG
  1294. #define GDBARCH_DEBUG 0
  1295. #endif
  1296. unsigned int gdbarch_debug = GDBARCH_DEBUG;
  1297. static void
  1298. show_gdbarch_debug (struct ui_file *file, int from_tty,
  1299.                     struct cmd_list_element *c, const char *value)
  1300. {
  1301.   fprintf_filtered (file, _("Architecture debugging is %s.\\n"), value);
  1302. }

  1303. static const char *
  1304. pformat (const struct floatformat **format)
  1305. {
  1306.   if (format == NULL)
  1307.     return "(null)";
  1308.   else
  1309.     /* Just print out one of them - this is only for diagnostics.  */
  1310.     return format[0]->name;
  1311. }

  1312. static const char *
  1313. pstring (const char *string)
  1314. {
  1315.   if (string == NULL)
  1316.     return "(null)";
  1317.   return string;
  1318. }

  1319. /* Helper function to print a list of strings, represented as "const
  1320.    char *const *".  The list is printed comma-separated.  */

  1321. static char *
  1322. pstring_list (const char *const *list)
  1323. {
  1324.   static char ret[100];
  1325.   const char *const *p;
  1326.   size_t offset = 0;

  1327.   if (list == NULL)
  1328.     return "(null)";

  1329.   ret[0] = '\0';
  1330.   for (p = list; *p != NULL && offset < sizeof (ret); ++p)
  1331.     {
  1332.       size_t s = xsnprintf (ret + offset, sizeof (ret) - offset, "%s, ", *p);
  1333.       offset += 2 + s;
  1334.     }

  1335.   if (offset > 0)
  1336.     {
  1337.       gdb_assert (offset - 2 < sizeof (ret));
  1338.       ret[offset - 2] = '\0';
  1339.     }

  1340.   return ret;
  1341. }

  1342. EOF

  1343. # gdbarch open the gdbarch object
  1344. printf "\n"
  1345. printf "/* Maintain the struct gdbarch object.  */\n"
  1346. printf "\n"
  1347. printf "struct gdbarch\n"
  1348. printf "{\n"
  1349. printf "  /* Has this architecture been fully initialized?  */\n"
  1350. printf "  int initialized_p;\n"
  1351. printf "\n"
  1352. printf "  /* An obstack bound to the lifetime of the architecture.  */\n"
  1353. printf "  struct obstack *obstack;\n"
  1354. printf "\n"
  1355. printf "  /* basic architectural information.  */\n"
  1356. function_list | while do_read
  1357. do
  1358.     if class_is_info_p
  1359.     then
  1360.         printf "  ${returntype} ${function};\n"
  1361.     fi
  1362. done
  1363. printf "\n"
  1364. printf "  /* target specific vector.  */\n"
  1365. printf "  struct gdbarch_tdep *tdep;\n"
  1366. printf "  gdbarch_dump_tdep_ftype *dump_tdep;\n"
  1367. printf "\n"
  1368. printf "  /* per-architecture data-pointers.  */\n"
  1369. printf "  unsigned nr_data;\n"
  1370. printf "  void **data;\n"
  1371. printf "\n"
  1372. cat <<EOF
  1373.   /* Multi-arch values.

  1374.      When extending this structure you must:

  1375.      Add the field below.

  1376.      Declare set/get functions and define the corresponding
  1377.      macro in gdbarch.h.

  1378.      gdbarch_alloc(): If zero/NULL is not a suitable default,
  1379.      initialize the new field.

  1380.      verify_gdbarch(): Confirm that the target updated the field
  1381.      correctly.

  1382.      gdbarch_dump(): Add a fprintf_unfiltered call so that the new
  1383.      field is dumped out

  1384.      get_gdbarch(): Implement the set/get functions (probably using
  1385.      the macro's as shortcuts).

  1386.      */

  1387. EOF
  1388. function_list | while do_read
  1389. do
  1390.     if class_is_variable_p
  1391.     then
  1392.         printf "  ${returntype} ${function};\n"
  1393.     elif class_is_function_p
  1394.     then
  1395.         printf "  gdbarch_${function}_ftype *${function};\n"
  1396.     fi
  1397. done
  1398. printf "};\n"

  1399. # Create a new gdbarch struct
  1400. cat <<EOF

  1401. /* Create a new \`\`struct gdbarch'' based on information provided by
  1402.    \`\`struct gdbarch_info''.  */
  1403. EOF
  1404. printf "\n"
  1405. cat <<EOF
  1406. struct gdbarch *
  1407. gdbarch_alloc (const struct gdbarch_info *info,
  1408.                struct gdbarch_tdep *tdep)
  1409. {
  1410.   struct gdbarch *gdbarch;

  1411.   /* Create an obstack for allocating all the per-architecture memory,
  1412.      then use that to allocate the architecture vector.  */
  1413.   struct obstack *obstack = XNEW (struct obstack);
  1414.   obstack_init (obstack);
  1415.   gdbarch = obstack_alloc (obstack, sizeof (*gdbarch));
  1416.   memset (gdbarch, 0, sizeof (*gdbarch));
  1417.   gdbarch->obstack = obstack;

  1418.   alloc_gdbarch_data (gdbarch);

  1419.   gdbarch->tdep = tdep;
  1420. EOF
  1421. printf "\n"
  1422. function_list | while do_read
  1423. do
  1424.     if class_is_info_p
  1425.     then
  1426.         printf "  gdbarch->${function} = info->${function};\n"
  1427.     fi
  1428. done
  1429. printf "\n"
  1430. printf "  /* Force the explicit initialization of these.  */\n"
  1431. function_list | while do_read
  1432. do
  1433.     if class_is_function_p || class_is_variable_p
  1434.     then
  1435.         if [ -n "${predefault}" -a "x${predefault}" != "x0" ]
  1436.         then
  1437.           printf "  gdbarch->${function} = ${predefault};\n"
  1438.         fi
  1439.     fi
  1440. done
  1441. cat <<EOF
  1442.   /* gdbarch_alloc() */

  1443.   return gdbarch;
  1444. }
  1445. EOF

  1446. # Free a gdbarch struct.
  1447. printf "\n"
  1448. printf "\n"
  1449. cat <<EOF
  1450. /* Allocate extra space using the per-architecture obstack.  */

  1451. void *
  1452. gdbarch_obstack_zalloc (struct gdbarch *arch, long size)
  1453. {
  1454.   void *data = obstack_alloc (arch->obstack, size);

  1455.   memset (data, 0, size);
  1456.   return data;
  1457. }


  1458. /* Free a gdbarch struct.  This should never happen in normal
  1459.    operation --- once you've created a gdbarch, you keep it around.
  1460.    However, if an architecture's init function encounters an error
  1461.    building the structure, it may need to clean up a partially
  1462.    constructed gdbarch.  */

  1463. void
  1464. gdbarch_free (struct gdbarch *arch)
  1465. {
  1466.   struct obstack *obstack;

  1467.   gdb_assert (arch != NULL);
  1468.   gdb_assert (!arch->initialized_p);
  1469.   obstack = arch->obstack;
  1470.   obstack_free (obstack, 0); /* Includes the ARCH.  */
  1471.   xfree (obstack);
  1472. }
  1473. EOF

  1474. # verify a new architecture
  1475. cat <<EOF


  1476. /* Ensure that all values in a GDBARCH are reasonable.  */

  1477. static void
  1478. verify_gdbarch (struct gdbarch *gdbarch)
  1479. {
  1480.   struct ui_file *log;
  1481.   struct cleanup *cleanups;
  1482.   long length;
  1483.   char *buf;

  1484.   log = mem_fileopen ();
  1485.   cleanups = make_cleanup_ui_file_delete (log);
  1486.   /* fundamental */
  1487.   if (gdbarch->byte_order == BFD_ENDIAN_UNKNOWN)
  1488.     fprintf_unfiltered (log, "\n\tbyte-order");
  1489.   if (gdbarch->bfd_arch_info == NULL)
  1490.     fprintf_unfiltered (log, "\n\tbfd_arch_info");
  1491.   /* Check those that need to be defined for the given multi-arch level.  */
  1492. EOF
  1493. function_list | while do_read
  1494. do
  1495.     if class_is_function_p || class_is_variable_p
  1496.     then
  1497.         if [ "x${invalid_p}" = "x0" ]
  1498.         then
  1499.             printf "  /* Skip verify of ${function}, invalid_p == 0 */\n"
  1500.         elif class_is_predicate_p
  1501.         then
  1502.             printf "  /* Skip verify of ${function}, has predicate.  */\n"
  1503.         # FIXME: See do_read for potential simplification
  1504.          elif [ -n "${invalid_p}" -a -n "${postdefault}" ]
  1505.         then
  1506.             printf "  if (${invalid_p})\n"
  1507.             printf "    gdbarch->${function} = ${postdefault};\n"
  1508.         elif [ -n "${predefault}" -a -n "${postdefault}" ]
  1509.         then
  1510.             printf "  if (gdbarch->${function} == ${predefault})\n"
  1511.             printf "    gdbarch->${function} = ${postdefault};\n"
  1512.         elif [ -n "${postdefault}" ]
  1513.         then
  1514.             printf "  if (gdbarch->${function} == 0)\n"
  1515.             printf "    gdbarch->${function} = ${postdefault};\n"
  1516.         elif [ -n "${invalid_p}" ]
  1517.         then
  1518.             printf "  if (${invalid_p})\n"
  1519.             printf "    fprintf_unfiltered (log, \"\\\\n\\\\t${function}\");\n"
  1520.         elif [ -n "${predefault}" ]
  1521.         then
  1522.             printf "  if (gdbarch->${function} == ${predefault})\n"
  1523.             printf "    fprintf_unfiltered (log, \"\\\\n\\\\t${function}\");\n"
  1524.         fi
  1525.     fi
  1526. done
  1527. cat <<EOF
  1528.   buf = ui_file_xstrdup (log, &length);
  1529.   make_cleanup (xfree, buf);
  1530.   if (length > 0)
  1531.     internal_error (__FILE__, __LINE__,
  1532.                     _("verify_gdbarch: the following are invalid ...%s"),
  1533.                     buf);
  1534.   do_cleanups (cleanups);
  1535. }
  1536. EOF

  1537. # dump the structure
  1538. printf "\n"
  1539. printf "\n"
  1540. cat <<EOF
  1541. /* Print out the details of the current architecture.  */

  1542. void
  1543. gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
  1544. {
  1545.   const char *gdb_nm_file = "<not-defined>";

  1546. #if defined (GDB_NM_FILE)
  1547.   gdb_nm_file = GDB_NM_FILE;
  1548. #endif
  1549.   fprintf_unfiltered (file,
  1550.                       "gdbarch_dump: GDB_NM_FILE = %s\\n",
  1551.                       gdb_nm_file);
  1552. EOF
  1553. function_list | sort -t: -k 3 | while do_read
  1554. do
  1555.     # First the predicate
  1556.     if class_is_predicate_p
  1557.     then
  1558.         printf "  fprintf_unfiltered (file,\n"
  1559.         printf "                      \"gdbarch_dump: gdbarch_${function}_p() = %%d\\\\n\",\n"
  1560.         printf "                      gdbarch_${function}_p (gdbarch));\n"
  1561.     fi
  1562.     # Print the corresponding value.
  1563.     if class_is_function_p
  1564.     then
  1565.         printf "  fprintf_unfiltered (file,\n"
  1566.         printf "                      \"gdbarch_dump: ${function} = <%%s>\\\\n\",\n"
  1567.         printf "                      host_address_to_string (gdbarch->${function}));\n"
  1568.     else
  1569.         # It is a variable
  1570.         case "${print}:${returntype}" in
  1571.             :CORE_ADDR )
  1572.                 fmt="%s"
  1573.                 print="core_addr_to_string_nz (gdbarch->${function})"
  1574.                 ;;
  1575.             :* )
  1576.                 fmt="%s"
  1577.                 print="plongest (gdbarch->${function})"
  1578.                 ;;
  1579.             * )
  1580.                 fmt="%s"
  1581.                 ;;
  1582.         esac
  1583.         printf "  fprintf_unfiltered (file,\n"
  1584.         printf "                      \"gdbarch_dump: ${function} = %s\\\\n\",\n" "${fmt}"
  1585.         printf "                      ${print});\n"
  1586.     fi
  1587. done
  1588. cat <<EOF
  1589.   if (gdbarch->dump_tdep != NULL)
  1590.     gdbarch->dump_tdep (gdbarch, file);
  1591. }
  1592. EOF


  1593. # GET/SET
  1594. printf "\n"
  1595. cat <<EOF
  1596. struct gdbarch_tdep *
  1597. gdbarch_tdep (struct gdbarch *gdbarch)
  1598. {
  1599.   if (gdbarch_debug >= 2)
  1600.     fprintf_unfiltered (gdb_stdlog, "gdbarch_tdep called\\n");
  1601.   return gdbarch->tdep;
  1602. }
  1603. EOF
  1604. printf "\n"
  1605. function_list | while do_read
  1606. do
  1607.     if class_is_predicate_p
  1608.     then
  1609.         printf "\n"
  1610.         printf "int\n"
  1611.         printf "gdbarch_${function}_p (struct gdbarch *gdbarch)\n"
  1612.         printf "{\n"
  1613.         printf "  gdb_assert (gdbarch != NULL);\n"
  1614.         printf "  return ${predicate};\n"
  1615.         printf "}\n"
  1616.     fi
  1617.     if class_is_function_p
  1618.     then
  1619.         printf "\n"
  1620.         printf "${returntype}\n"
  1621.         if [ "x${formal}" = "xvoid" ]
  1622.         then
  1623.           printf "gdbarch_${function} (struct gdbarch *gdbarch)\n"
  1624.         else
  1625.           printf "gdbarch_${function} (struct gdbarch *gdbarch, ${formal})\n"
  1626.         fi
  1627.         printf "{\n"
  1628.         printf "  gdb_assert (gdbarch != NULL);\n"
  1629.         printf "  gdb_assert (gdbarch->${function} != NULL);\n"
  1630.         if class_is_predicate_p && test -n "${predefault}"
  1631.         then
  1632.             # Allow a call to a function with a predicate.
  1633.             printf "  /* Do not check predicate: ${predicate}, allow call.  */\n"
  1634.         fi
  1635.         printf "  if (gdbarch_debug >= 2)\n"
  1636.         printf "    fprintf_unfiltered (gdb_stdlog, \"gdbarch_${function} called\\\\n\");\n"
  1637.         if [ "x${actual}" = "x-" -o "x${actual}" = "x" ]
  1638.         then
  1639.             if class_is_multiarch_p
  1640.             then
  1641.                 params="gdbarch"
  1642.             else
  1643.                 params=""
  1644.             fi
  1645.         else
  1646.             if class_is_multiarch_p
  1647.             then
  1648.                 params="gdbarch, ${actual}"
  1649.             else
  1650.                 params="${actual}"
  1651.             fi
  1652.         fi
  1653.                if [ "x${returntype}" = "xvoid" ]
  1654.         then
  1655.           printf "  gdbarch->${function} (${params});\n"
  1656.         else
  1657.           printf "  return gdbarch->${function} (${params});\n"
  1658.         fi
  1659.         printf "}\n"
  1660.         printf "\n"
  1661.         printf "void\n"
  1662.         printf "set_gdbarch_${function} (struct gdbarch *gdbarch,\n"
  1663.         printf "            `echo ${function} | sed -e 's/./ /g'`  gdbarch_${function}_ftype ${function})\n"
  1664.         printf "{\n"
  1665.         printf "  gdbarch->${function} = ${function};\n"
  1666.         printf "}\n"
  1667.     elif class_is_variable_p
  1668.     then
  1669.         printf "\n"
  1670.         printf "${returntype}\n"
  1671.         printf "gdbarch_${function} (struct gdbarch *gdbarch)\n"
  1672.         printf "{\n"
  1673.         printf "  gdb_assert (gdbarch != NULL);\n"
  1674.         if [ "x${invalid_p}" = "x0" ]
  1675.         then
  1676.             printf "  /* Skip verify of ${function}, invalid_p == 0 */\n"
  1677.         elif [ -n "${invalid_p}" ]
  1678.         then
  1679.             printf "  /* Check variable is valid.  */\n"
  1680.             printf "  gdb_assert (!(${invalid_p}));\n"
  1681.         elif [ -n "${predefault}" ]
  1682.         then
  1683.             printf "  /* Check variable changed from pre-default.  */\n"
  1684.             printf "  gdb_assert (gdbarch->${function} != ${predefault});\n"
  1685.         fi
  1686.         printf "  if (gdbarch_debug >= 2)\n"
  1687.         printf "    fprintf_unfiltered (gdb_stdlog, \"gdbarch_${function} called\\\\n\");\n"
  1688.         printf "  return gdbarch->${function};\n"
  1689.         printf "}\n"
  1690.         printf "\n"
  1691.         printf "void\n"
  1692.         printf "set_gdbarch_${function} (struct gdbarch *gdbarch,\n"
  1693.         printf "            `echo ${function} | sed -e 's/./ /g'`  ${returntype} ${function})\n"
  1694.         printf "{\n"
  1695.         printf "  gdbarch->${function} = ${function};\n"
  1696.         printf "}\n"
  1697.     elif class_is_info_p
  1698.     then
  1699.         printf "\n"
  1700.         printf "${returntype}\n"
  1701.         printf "gdbarch_${function} (struct gdbarch *gdbarch)\n"
  1702.         printf "{\n"
  1703.         printf "  gdb_assert (gdbarch != NULL);\n"
  1704.         printf "  if (gdbarch_debug >= 2)\n"
  1705.         printf "    fprintf_unfiltered (gdb_stdlog, \"gdbarch_${function} called\\\\n\");\n"
  1706.         printf "  return gdbarch->${function};\n"
  1707.         printf "}\n"
  1708.     fi
  1709. done

  1710. # All the trailing guff
  1711. cat <<EOF


  1712. /* Keep a registry of per-architecture data-pointers required by GDB
  1713.    modules.  */

  1714. struct gdbarch_data
  1715. {
  1716.   unsigned index;
  1717.   int init_p;
  1718.   gdbarch_data_pre_init_ftype *pre_init;
  1719.   gdbarch_data_post_init_ftype *post_init;
  1720. };

  1721. struct gdbarch_data_registration
  1722. {
  1723.   struct gdbarch_data *data;
  1724.   struct gdbarch_data_registration *next;
  1725. };

  1726. struct gdbarch_data_registry
  1727. {
  1728.   unsigned nr;
  1729.   struct gdbarch_data_registration *registrations;
  1730. };

  1731. struct gdbarch_data_registry gdbarch_data_registry =
  1732. {
  1733.   0, NULL,
  1734. };

  1735. static struct gdbarch_data *
  1736. gdbarch_data_register (gdbarch_data_pre_init_ftype *pre_init,
  1737.                        gdbarch_data_post_init_ftype *post_init)
  1738. {
  1739.   struct gdbarch_data_registration **curr;

  1740.   /* Append the new registration.  */
  1741.   for (curr = &gdbarch_data_registry.registrations;
  1742.        (*curr) != NULL;
  1743.        curr = &(*curr)->next);
  1744.   (*curr) = XNEW (struct gdbarch_data_registration);
  1745.   (*curr)->next = NULL;
  1746.   (*curr)->data = XNEW (struct gdbarch_data);
  1747.   (*curr)->data->index = gdbarch_data_registry.nr++;
  1748.   (*curr)->data->pre_init = pre_init;
  1749.   (*curr)->data->post_init = post_init;
  1750.   (*curr)->data->init_p = 1;
  1751.   return (*curr)->data;
  1752. }

  1753. struct gdbarch_data *
  1754. gdbarch_data_register_pre_init (gdbarch_data_pre_init_ftype *pre_init)
  1755. {
  1756.   return gdbarch_data_register (pre_init, NULL);
  1757. }

  1758. struct gdbarch_data *
  1759. gdbarch_data_register_post_init (gdbarch_data_post_init_ftype *post_init)
  1760. {
  1761.   return gdbarch_data_register (NULL, post_init);
  1762. }

  1763. /* Create/delete the gdbarch data vector.  */

  1764. static void
  1765. alloc_gdbarch_data (struct gdbarch *gdbarch)
  1766. {
  1767.   gdb_assert (gdbarch->data == NULL);
  1768.   gdbarch->nr_data = gdbarch_data_registry.nr;
  1769.   gdbarch->data = GDBARCH_OBSTACK_CALLOC (gdbarch, gdbarch->nr_data, void *);
  1770. }

  1771. /* Initialize the current value of the specified per-architecture
  1772.    data-pointer.  */

  1773. void
  1774. deprecated_set_gdbarch_data (struct gdbarch *gdbarch,
  1775.                              struct gdbarch_data *data,
  1776.                              void *pointer)
  1777. {
  1778.   gdb_assert (data->index < gdbarch->nr_data);
  1779.   gdb_assert (gdbarch->data[data->index] == NULL);
  1780.   gdb_assert (data->pre_init == NULL);
  1781.   gdbarch->data[data->index] = pointer;
  1782. }

  1783. /* Return the current value of the specified per-architecture
  1784.    data-pointer.  */

  1785. void *
  1786. gdbarch_data (struct gdbarch *gdbarch, struct gdbarch_data *data)
  1787. {
  1788.   gdb_assert (data->index < gdbarch->nr_data);
  1789.   if (gdbarch->data[data->index] == NULL)
  1790.     {
  1791.       /* The data-pointer isn't initialized, call init() to get a
  1792.          value.  */
  1793.       if (data->pre_init != NULL)
  1794.         /* Mid architecture creation: pass just the obstack, and not
  1795.            the entire architecture, as that way it isn't possible for
  1796.            pre-init code to refer to undefined architecture
  1797.            fields.  */
  1798.         gdbarch->data[data->index] = data->pre_init (gdbarch->obstack);
  1799.       else if (gdbarch->initialized_p
  1800.                && data->post_init != NULL)
  1801.         /* Post architecture creation: pass the entire architecture
  1802.            (as all fields are valid), but be careful to also detect
  1803.            recursive references.  */
  1804.         {
  1805.           gdb_assert (data->init_p);
  1806.           data->init_p = 0;
  1807.           gdbarch->data[data->index] = data->post_init (gdbarch);
  1808.           data->init_p = 1;
  1809.         }
  1810.       else
  1811.         /* The architecture initialization hasn't completed - punt -
  1812.          hope that the caller knows what they are doing.  Once
  1813.          deprecated_set_gdbarch_data has been initialized, this can be
  1814.          changed to an internal error.  */
  1815.         return NULL;
  1816.       gdb_assert (gdbarch->data[data->index] != NULL);
  1817.     }
  1818.   return gdbarch->data[data->index];
  1819. }


  1820. /* Keep a registry of the architectures known by GDB.  */

  1821. struct gdbarch_registration
  1822. {
  1823.   enum bfd_architecture bfd_architecture;
  1824.   gdbarch_init_ftype *init;
  1825.   gdbarch_dump_tdep_ftype *dump_tdep;
  1826.   struct gdbarch_list *arches;
  1827.   struct gdbarch_registration *next;
  1828. };

  1829. static struct gdbarch_registration *gdbarch_registry = NULL;

  1830. static void
  1831. append_name (const char ***buf, int *nr, const char *name)
  1832. {
  1833.   *buf = xrealloc (*buf, sizeof (char**) * (*nr + 1));
  1834.   (*buf)[*nr] = name;
  1835.   *nr += 1;
  1836. }

  1837. const char **
  1838. gdbarch_printable_names (void)
  1839. {
  1840.   /* Accumulate a list of names based on the registed list of
  1841.      architectures.  */
  1842.   int nr_arches = 0;
  1843.   const char **arches = NULL;
  1844.   struct gdbarch_registration *rego;

  1845.   for (rego = gdbarch_registry;
  1846.        rego != NULL;
  1847.        rego = rego->next)
  1848.     {
  1849.       const struct bfd_arch_info *ap;
  1850.       ap = bfd_lookup_arch (rego->bfd_architecture, 0);
  1851.       if (ap == NULL)
  1852.         internal_error (__FILE__, __LINE__,
  1853.                         _("gdbarch_architecture_names: multi-arch unknown"));
  1854.       do
  1855.         {
  1856.           append_name (&arches, &nr_arches, ap->printable_name);
  1857.           ap = ap->next;
  1858.         }
  1859.       while (ap != NULL);
  1860.     }
  1861.   append_name (&arches, &nr_arches, NULL);
  1862.   return arches;
  1863. }


  1864. void
  1865. gdbarch_register (enum bfd_architecture bfd_architecture,
  1866.                   gdbarch_init_ftype *init,
  1867.                   gdbarch_dump_tdep_ftype *dump_tdep)
  1868. {
  1869.   struct gdbarch_registration **curr;
  1870.   const struct bfd_arch_info *bfd_arch_info;

  1871.   /* Check that BFD recognizes this architecture */
  1872.   bfd_arch_info = bfd_lookup_arch (bfd_architecture, 0);
  1873.   if (bfd_arch_info == NULL)
  1874.     {
  1875.       internal_error (__FILE__, __LINE__,
  1876.                       _("gdbarch: Attempt to register "
  1877.                         "unknown architecture (%d)"),
  1878.                       bfd_architecture);
  1879.     }
  1880.   /* Check that we haven't seen this architecture before.  */
  1881.   for (curr = &gdbarch_registry;
  1882.        (*curr) != NULL;
  1883.        curr = &(*curr)->next)
  1884.     {
  1885.       if (bfd_architecture == (*curr)->bfd_architecture)
  1886.         internal_error (__FILE__, __LINE__,
  1887.                         _("gdbarch: Duplicate registration "
  1888.                           "of architecture (%s)"),
  1889.                         bfd_arch_info->printable_name);
  1890.     }
  1891.   /* log it */
  1892.   if (gdbarch_debug)
  1893.     fprintf_unfiltered (gdb_stdlog, "register_gdbarch_init (%s, %s)\n",
  1894.                         bfd_arch_info->printable_name,
  1895.                         host_address_to_string (init));
  1896.   /* Append it */
  1897.   (*curr) = XNEW (struct gdbarch_registration);
  1898.   (*curr)->bfd_architecture = bfd_architecture;
  1899.   (*curr)->init = init;
  1900.   (*curr)->dump_tdep = dump_tdep;
  1901.   (*curr)->arches = NULL;
  1902.   (*curr)->next = NULL;
  1903. }

  1904. void
  1905. register_gdbarch_init (enum bfd_architecture bfd_architecture,
  1906.                        gdbarch_init_ftype *init)
  1907. {
  1908.   gdbarch_register (bfd_architecture, init, NULL);
  1909. }


  1910. /* Look for an architecture using gdbarch_info.  */

  1911. struct gdbarch_list *
  1912. gdbarch_list_lookup_by_info (struct gdbarch_list *arches,
  1913.                              const struct gdbarch_info *info)
  1914. {
  1915.   for (; arches != NULL; arches = arches->next)
  1916.     {
  1917.       if (info->bfd_arch_info != arches->gdbarch->bfd_arch_info)
  1918.         continue;
  1919.       if (info->byte_order != arches->gdbarch->byte_order)
  1920.         continue;
  1921.       if (info->osabi != arches->gdbarch->osabi)
  1922.         continue;
  1923.       if (info->target_desc != arches->gdbarch->target_desc)
  1924.         continue;
  1925.       return arches;
  1926.     }
  1927.   return NULL;
  1928. }


  1929. /* Find an architecture that matches the specified INFO.  Create a new
  1930.    architecture if needed.  Return that new architecture.  */

  1931. struct gdbarch *
  1932. gdbarch_find_by_info (struct gdbarch_info info)
  1933. {
  1934.   struct gdbarch *new_gdbarch;
  1935.   struct gdbarch_registration *rego;

  1936.   /* Fill in missing parts of the INFO struct using a number of
  1937.      sources: "set ..."; INFOabfd supplied; and the global
  1938.      defaults.  */
  1939.   gdbarch_info_fill (&info);

  1940.   /* Must have found some sort of architecture.  */
  1941.   gdb_assert (info.bfd_arch_info != NULL);

  1942.   if (gdbarch_debug)
  1943.     {
  1944.       fprintf_unfiltered (gdb_stdlog,
  1945.                           "gdbarch_find_by_info: info.bfd_arch_info %s\n",
  1946.                           (info.bfd_arch_info != NULL
  1947.                            ? info.bfd_arch_info->printable_name
  1948.                            : "(null)"));
  1949.       fprintf_unfiltered (gdb_stdlog,
  1950.                           "gdbarch_find_by_info: info.byte_order %d (%s)\n",
  1951.                           info.byte_order,
  1952.                           (info.byte_order == BFD_ENDIAN_BIG ? "big"
  1953.                            : info.byte_order == BFD_ENDIAN_LITTLE ? "little"
  1954.                            : "default"));
  1955.       fprintf_unfiltered (gdb_stdlog,
  1956.                           "gdbarch_find_by_info: info.osabi %d (%s)\n",
  1957.                           info.osabi, gdbarch_osabi_name (info.osabi));
  1958.       fprintf_unfiltered (gdb_stdlog,
  1959.                           "gdbarch_find_by_info: info.abfd %s\n",
  1960.                           host_address_to_string (info.abfd));
  1961.       fprintf_unfiltered (gdb_stdlog,
  1962.                           "gdbarch_find_by_info: info.tdep_info %s\n",
  1963.                           host_address_to_string (info.tdep_info));
  1964.     }

  1965.   /* Find the tdep code that knows about this architecture.  */
  1966.   for (rego = gdbarch_registry;
  1967.        rego != NULL;
  1968.        rego = rego->next)
  1969.     if (rego->bfd_architecture == info.bfd_arch_info->arch)
  1970.       break;
  1971.   if (rego == NULL)
  1972.     {
  1973.       if (gdbarch_debug)
  1974.         fprintf_unfiltered (gdb_stdlog, "gdbarch_find_by_info: "
  1975.                             "No matching architecture\n");
  1976.       return 0;
  1977.     }

  1978.   /* Ask the tdep code for an architecture that matches "info".  */
  1979.   new_gdbarch = rego->init (info, rego->arches);

  1980.   /* Did the tdep code like it?  No.  Reject the change and revert to
  1981.      the old architecture.  */
  1982.   if (new_gdbarch == NULL)
  1983.     {
  1984.       if (gdbarch_debug)
  1985.         fprintf_unfiltered (gdb_stdlog, "gdbarch_find_by_info: "
  1986.                             "Target rejected architecture\n");
  1987.       return NULL;
  1988.     }

  1989.   /* Is this a pre-existing architecture (as determined by already
  1990.      being initialized)?  Move it to the front of the architecture
  1991.      list (keeping the list sorted Most Recently Used).  */
  1992.   if (new_gdbarch->initialized_p)
  1993.     {
  1994.       struct gdbarch_list **list;
  1995.       struct gdbarch_list *this;
  1996.       if (gdbarch_debug)
  1997.         fprintf_unfiltered (gdb_stdlog, "gdbarch_find_by_info: "
  1998.                             "Previous architecture %s (%s) selected\n",
  1999.                             host_address_to_string (new_gdbarch),
  2000.                             new_gdbarch->bfd_arch_info->printable_name);
  2001.       /* Find the existing arch in the list.  */
  2002.       for (list = &rego->arches;
  2003.            (*list) != NULL && (*list)->gdbarch != new_gdbarch;
  2004.            list = &(*list)->next);
  2005.       /* It had better be in the list of architectures.  */
  2006.       gdb_assert ((*list) != NULL && (*list)->gdbarch == new_gdbarch);
  2007.       /* Unlink THIS.  */
  2008.       this = (*list);
  2009.       (*list) = this->next;
  2010.       /* Insert THIS at the front.  */
  2011.       this->next = rego->arches;
  2012.       rego->arches = this;
  2013.       /* Return it.  */
  2014.       return new_gdbarch;
  2015.     }

  2016.   /* It's a new architecture.  */
  2017.   if (gdbarch_debug)
  2018.     fprintf_unfiltered (gdb_stdlog, "gdbarch_find_by_info: "
  2019.                         "New architecture %s (%s) selected\n",
  2020.                         host_address_to_string (new_gdbarch),
  2021.                         new_gdbarch->bfd_arch_info->printable_name);

  2022.   /* Insert the new architecture into the front of the architecture
  2023.      list (keep the list sorted Most Recently Used).  */
  2024.   {
  2025.     struct gdbarch_list *this = XNEW (struct gdbarch_list);
  2026.     this->next = rego->arches;
  2027.     this->gdbarch = new_gdbarch;
  2028.     rego->arches = this;
  2029.   }

  2030.   /* Check that the newly installed architecture is valid.  Plug in
  2031.      any post init values.  */
  2032.   new_gdbarch->dump_tdep = rego->dump_tdep;
  2033.   verify_gdbarch (new_gdbarch);
  2034.   new_gdbarch->initialized_p = 1;

  2035.   if (gdbarch_debug)
  2036.     gdbarch_dump (new_gdbarch, gdb_stdlog);

  2037.   return new_gdbarch;
  2038. }

  2039. /* Make the specified architecture current.  */

  2040. void
  2041. set_target_gdbarch (struct gdbarch *new_gdbarch)
  2042. {
  2043.   gdb_assert (new_gdbarch != NULL);
  2044.   gdb_assert (new_gdbarch->initialized_p);
  2045.   current_inferior ()->gdbarch = new_gdbarch;
  2046.   observer_notify_architecture_changed (new_gdbarch);
  2047.   registers_changed ();
  2048. }

  2049. /* Return the current inferior's arch.  */

  2050. struct gdbarch *
  2051. target_gdbarch (void)
  2052. {
  2053.   return current_inferior ()->gdbarch;
  2054. }

  2055. extern void _initialize_gdbarch (void);

  2056. void
  2057. _initialize_gdbarch (void)
  2058. {
  2059.   add_setshow_zuinteger_cmd ("arch", class_maintenance, &gdbarch_debug, _("\\
  2060. Set architecture debugging."), _("\\
  2061. Show architecture debugging."), _("\\
  2062. When non-zero, architecture debugging is enabled."),
  2063.                             NULL,
  2064.                             show_gdbarch_debug,
  2065.                             &setdebuglist, &showdebuglist);
  2066. }
  2067. EOF

  2068. # close things off
  2069. exec 1>&2
  2070. #../move-if-change new-gdbarch.c gdbarch.c
  2071. compare_new gdbarch.c