gdb/regformats/regdat.sh - gdb

Functions defined

Source code

  1. #!/bin/sh -u

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

  19. # Format of the input files
  20. read="type entry"

  21. do_read ()
  22. {
  23.     type=""
  24.     entry=""
  25.     while read line
  26.     do
  27.         if test "${line}" = ""
  28.         then
  29.             continue
  30.         elif test "${line}" = "#" -a "${comment}" = ""
  31.         then
  32.             continue
  33.         elif expr "${line}" : "#" > /dev/null
  34.         then
  35.             comment="${comment}
  36. ${line}"
  37.         else

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

  42.             OFS="${IFS}" ; IFS="[:]"
  43.             eval read ${read} <<EOF
  44. ${line}
  45. EOF
  46.             IFS="${OFS}"

  47.             # .... and then going back through each field and strip out those
  48.             # that ended up with just that space character.
  49.             for r in ${read}
  50.             do
  51.                 if eval test \"\${${r}}\" = \"\ \"
  52.                 then
  53.                     eval ${r}=""
  54.                 fi
  55.             done

  56.             break
  57.         fi
  58.     done
  59.     if [ -n "${type}" ]
  60.     then
  61.         true
  62.     else
  63.         false
  64.     fi
  65. }

  66. if test ! -r $1; then
  67.   echo "$0: Could not open $1." 1>&2
  68.   exit 1
  69. fi

  70. copyright ()
  71. {
  72. cat <<EOF
  73. /* *INDENT-OFF* */ /* THIS FILE IS GENERATED */

  74. /* A register protocol for GDB, the GNU debugger.
  75.    Copyright (C) 2001-2013 Free Software Foundation, Inc.

  76.    This file is part of GDB.

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

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

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

  87. /* This file was created with the aid of \`\`regdat.sh'' and \`\`$1''.  */

  88. EOF
  89. }


  90. exec > new-$2
  91. copyright $1
  92. echo '#include "server.h"'
  93. echo '#include "regdef.h"'
  94. echo '#include "tdesc.h"'
  95. echo
  96. offset=0
  97. i=0
  98. name=x
  99. xmltarget=x
  100. xmlarch=x
  101. xmlosabi=x
  102. expedite=x
  103. exec < $1
  104. while do_read
  105. do
  106.   if test "${type}" = "name"; then
  107.     name="${entry}"
  108.     echo "static struct reg regs_${name}[] = {"
  109.     continue
  110.   elif test "${type}" = "xmltarget"; then
  111.     xmltarget="${entry}"
  112.     continue
  113.   elif test "${type}" = "xmlarch"; then
  114.     xmlarch="${entry}"
  115.     continue
  116.   elif test "${type}" = "osabi"; then
  117.     xmlosabi="${entry}"
  118.     continue
  119.   elif test "${type}" = "expedite"; then
  120.     expedite="${entry}"
  121.     continue
  122.   elif test "${name}" = x; then
  123.     echo "$0: $1 does not specify \`\`name''." 1>&2
  124.     exit 1
  125.   else
  126.     echo "  { \"${entry}\", ${offset}, ${type} },"
  127.     offset=`expr ${offset} + ${type}`
  128.     i=`expr $i + 1`
  129.   fi
  130. done

  131. echo "};"
  132. echo
  133. echo "static const char *expedite_regs_${name}[] = { \"`echo ${expedite} | sed 's/,/", "/g'`\", 0 };"
  134. if test "${xmltarget}" = x; then
  135.   if test "${xmlarch}" = x && test "${xmlosabi}" = x; then
  136.     echo "static const char *xmltarget_${name} = 0;"
  137.   else
  138.     echo "static const char *xmltarget_${name} = \"@<target>\\"
  139.     if test "${xmlarch}" != x; then
  140.       echo "<architecture>${xmlarch}</architecture>\\"
  141.     fi
  142.     if test "${xmlosabi}" != x; then
  143.       echo "<osabi>${xmlosabi}</osabi>\\"
  144.     fi
  145.     echo "</target>\";"
  146.   fi
  147. else
  148.   echo "static const char *xmltarget_${name} = \"${xmltarget}\";"
  149. fi
  150. echo

  151. cat <<EOF
  152. const struct target_desc *tdesc_${name};

  153. void
  154. init_registers_${name} (void)
  155. {
  156.   static struct target_desc tdesc_${name}_s;
  157.   struct target_desc *result = &tdesc_${name}_s;

  158.   result->reg_defs = regs_${name};
  159.   result->num_registers = sizeof (regs_${name}) / sizeof (regs_${name}[0]);
  160.   result->expedite_regs = expedite_regs_${name};
  161.   result->xmltarget = xmltarget_${name};

  162.   init_target_desc (result);

  163.   tdesc_${name} = result;
  164. }
  165. EOF

  166. # close things off
  167. exec 1>&2
  168. mv -- "new-$2" "$2"