gdb/reggroups.c - gdb

Global variables defined

Data types defined

Functions defined

Source code

  1. /* Register groupings for GDB, the GNU debugger.

  2.    Copyright (C) 2002-2015 Free Software Foundation, Inc.

  3.    Contributed by Red Hat.

  4.    This file is part of GDB.

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

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

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

  15. #include "defs.h"
  16. #include "arch-utils.h"
  17. #include "reggroups.h"
  18. #include "gdbtypes.h"
  19. #include "regcache.h"
  20. #include "command.h"
  21. #include "gdbcmd.h"                /* For maintenanceprintlist.  */

  22. /* Individual register groups.  */

  23. struct reggroup
  24. {
  25.   const char *name;
  26.   enum reggroup_type type;
  27. };

  28. struct reggroup *
  29. reggroup_new (const char *name, enum reggroup_type type)
  30. {
  31.   struct reggroup *group = XNEW (struct reggroup);

  32.   group->name = name;
  33.   group->type = type;
  34.   return group;
  35. }

  36. /* Register group attributes.  */

  37. const char *
  38. reggroup_name (struct reggroup *group)
  39. {
  40.   return group->name;
  41. }

  42. enum reggroup_type
  43. reggroup_type (struct reggroup *group)
  44. {
  45.   return group->type;
  46. }

  47. /* A linked list of groups for the given architecture.  */

  48. struct reggroup_el
  49. {
  50.   struct reggroup *group;
  51.   struct reggroup_el *next;
  52. };

  53. struct reggroups
  54. {
  55.   struct reggroup_el *first;
  56.   struct reggroup_el **last;
  57. };

  58. static struct gdbarch_data *reggroups_data;

  59. static void *
  60. reggroups_init (struct gdbarch *gdbarch)
  61. {
  62.   struct reggroups *groups = GDBARCH_OBSTACK_ZALLOC (gdbarch,
  63.                                                      struct reggroups);

  64.   groups->last = &groups->first;
  65.   return groups;
  66. }

  67. /* Add a register group (with attribute values) to the pre-defined
  68.    list.  */

  69. static void
  70. add_group (struct reggroups *groups, struct reggroup *group,
  71.            struct reggroup_el *el)
  72. {
  73.   gdb_assert (group != NULL);
  74.   el->group = group;
  75.   el->next = NULL;
  76.   (*groups->last) = el;
  77.   groups->last = &el->next;
  78. }

  79. void
  80. reggroup_add (struct gdbarch *gdbarch, struct reggroup *group)
  81. {
  82.   struct reggroups *groups = gdbarch_data (gdbarch, reggroups_data);

  83.   if (groups == NULL)
  84.     {
  85.       /* ULGH, called during architecture initialization.  Patch
  86.          things up.  */
  87.       groups = reggroups_init (gdbarch);
  88.       deprecated_set_gdbarch_data (gdbarch, reggroups_data, groups);
  89.     }
  90.   add_group (groups, group,
  91.              GDBARCH_OBSTACK_ZALLOC (gdbarch, struct reggroup_el));
  92. }

  93. /* The default register groups for an architecture.  */

  94. static struct reggroups default_groups = { NULL, &default_groups.first };

  95. /* A register group iterator.  */

  96. struct reggroup *
  97. reggroup_next (struct gdbarch *gdbarch, struct reggroup *last)
  98. {
  99.   struct reggroups *groups;
  100.   struct reggroup_el *el;

  101.   /* Don't allow this function to be called during architecture
  102.      creation.  If there are no groups, use the default groups list.  */
  103.   groups = gdbarch_data (gdbarch, reggroups_data);
  104.   gdb_assert (groups != NULL);
  105.   if (groups->first == NULL)
  106.     groups = &default_groups;

  107.   /* Return the first/next reggroup.  */
  108.   if (last == NULL)
  109.     return groups->first->group;
  110.   for (el = groups->first; el != NULL; el = el->next)
  111.     {
  112.       if (el->group == last)
  113.         {
  114.           if (el->next != NULL)
  115.             return el->next->group;
  116.           else
  117.             return NULL;
  118.         }
  119.     }
  120.   return NULL;
  121. }

  122. /* Is REGNUM a member of REGGROUP?  */
  123. int
  124. default_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
  125.                              struct reggroup *group)
  126. {
  127.   int vector_p;
  128.   int float_p;
  129.   int raw_p;

  130.   if (gdbarch_register_name (gdbarch, regnum) == NULL
  131.       || *gdbarch_register_name (gdbarch, regnum) == '\0')
  132.     return 0;
  133.   if (group == all_reggroup)
  134.     return 1;
  135.   vector_p = TYPE_VECTOR (register_type (gdbarch, regnum));
  136.   float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT;
  137.   raw_p = regnum < gdbarch_num_regs (gdbarch);
  138.   if (group == float_reggroup)
  139.     return float_p;
  140.   if (group == vector_reggroup)
  141.     return vector_p;
  142.   if (group == general_reggroup)
  143.     return (!vector_p && !float_p);
  144.   if (group == save_reggroup || group == restore_reggroup)
  145.     return raw_p;
  146.   return 0;
  147. }

  148. /* Dump out a table of register groups for the current architecture.  */

  149. static void
  150. reggroups_dump (struct gdbarch *gdbarch, struct ui_file *file)
  151. {
  152.   struct reggroup *group = NULL;

  153.   do
  154.     {
  155.       /* Group name.  */
  156.       {
  157.         const char *name;

  158.         if (group == NULL)
  159.           name = "Group";
  160.         else
  161.           name = reggroup_name (group);
  162.         fprintf_unfiltered (file, " %-10s", name);
  163.       }

  164.       /* Group type.  */
  165.       {
  166.         const char *type;

  167.         if (group == NULL)
  168.           type = "Type";
  169.         else
  170.           {
  171.             switch (reggroup_type (group))
  172.               {
  173.               case USER_REGGROUP:
  174.                 type = "user";
  175.                 break;
  176.               case INTERNAL_REGGROUP:
  177.                 type = "internal";
  178.                 break;
  179.               default:
  180.                 internal_error (__FILE__, __LINE__, _("bad switch"));
  181.               }
  182.           }
  183.         fprintf_unfiltered (file, " %-10s", type);
  184.       }

  185.       /* Note: If you change this, be sure to also update the
  186.          documentation.  */

  187.       fprintf_unfiltered (file, "\n");

  188.       group = reggroup_next (gdbarch, group);
  189.     }
  190.   while (group != NULL);
  191. }

  192. static void
  193. maintenance_print_reggroups (char *args, int from_tty)
  194. {
  195.   struct gdbarch *gdbarch = get_current_arch ();

  196.   if (args == NULL)
  197.     reggroups_dump (gdbarch, gdb_stdout);
  198.   else
  199.     {
  200.       struct cleanup *cleanups;
  201.       struct ui_file *file = gdb_fopen (args, "w");

  202.       if (file == NULL)
  203.         perror_with_name (_("maintenance print reggroups"));
  204.       cleanups = make_cleanup_ui_file_delete (file);
  205.       reggroups_dump (gdbarch, file);
  206.       do_cleanups (cleanups);
  207.     }
  208. }

  209. /* Pre-defined register groups.  */
  210. static struct reggroup general_group = { "general", USER_REGGROUP };
  211. static struct reggroup float_group = { "float", USER_REGGROUP };
  212. static struct reggroup system_group = { "system", USER_REGGROUP };
  213. static struct reggroup vector_group = { "vector", USER_REGGROUP };
  214. static struct reggroup all_group = { "all", USER_REGGROUP };
  215. static struct reggroup save_group = { "save", INTERNAL_REGGROUP };
  216. static struct reggroup restore_group = { "restore", INTERNAL_REGGROUP };

  217. struct reggroup *const general_reggroup = &general_group;
  218. struct reggroup *const float_reggroup = &float_group;
  219. struct reggroup *const system_reggroup = &system_group;
  220. struct reggroup *const vector_reggroup = &vector_group;
  221. struct reggroup *const all_reggroup = &all_group;
  222. struct reggroup *const save_reggroup = &save_group;
  223. struct reggroup *const restore_reggroup = &restore_group;

  224. extern initialize_file_ftype _initialize_reggroup; /* -Wmissing-prototypes */

  225. void
  226. _initialize_reggroup (void)
  227. {
  228.   reggroups_data = gdbarch_data_register_post_init (reggroups_init);

  229.   /* The pre-defined list of groups.  */
  230.   add_group (&default_groups, general_reggroup, XNEW (struct reggroup_el));
  231.   add_group (&default_groups, float_reggroup, XNEW (struct reggroup_el));
  232.   add_group (&default_groups, system_reggroup, XNEW (struct reggroup_el));
  233.   add_group (&default_groups, vector_reggroup, XNEW (struct reggroup_el));
  234.   add_group (&default_groups, all_reggroup, XNEW (struct reggroup_el));
  235.   add_group (&default_groups, save_reggroup, XNEW (struct reggroup_el));
  236.   add_group (&default_groups, restore_reggroup, XNEW (struct reggroup_el));

  237.   add_cmd ("reggroups", class_maintenance,
  238.            maintenance_print_reggroups, _("\
  239. Print the internal register group names.\n\
  240. Takes an optional file parameter."),
  241.            &maintenanceprintlist);

  242. }