1 /* Copyright (C) 2005, 2006 Red Hat, Inc.
2 This file is part of elfutils.
4 This file is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 elfutils is distributed in the hope that it will be useful, but
10 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.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 #include ELFUTILS_HEADER(dwfl)
31 #include "../libdw/known-dwarf.h"
34 dwarf_encoding_string (unsigned int code)
36 static const char *const known[] =
38 #define ONE_KNOWN_DW_ATE(NAME, CODE) [CODE] = #NAME,
40 #undef ONE_KNOWN_DW_ATE
43 if (likely (code < sizeof (known) / sizeof (known[0])))
51 first_module (Dwfl_Module *mod,
52 void **userdatap __attribute__ ((unused)),
53 const char *name __attribute__ ((unused)),
54 Dwarf_Addr low_addr __attribute__ ((unused)),
58 if (dwfl_module_getelf (mod, &bias) == NULL) /* Not really a module. */
61 *(Dwfl_Module **) arg = mod;
62 return DWARF_CB_ABORT;
74 const char *set, *pfx;
82 compare (const void *r1, const void *r2)
84 const struct reginfo *a = r1, *b = r2;
86 return a->regno - b->regno;
91 if (!strcmp (a->set, "integer"))
93 if (!strcmp (b->set, "integer"))
95 return strcmp (a->set, b->set);
99 one_register (void *arg,
106 struct state *state = arg;
108 if (regno >= state->nregs)
110 state->info = realloc (state->info, (regno + 1) * sizeof state->info[0]);
111 memset (&state->info[state->nregs], 0,
112 ((void *) &state->info[regno + 1]
113 - (void *) &state->info[state->nregs]));
114 state->nregs = regno + 1;
117 state->info[regno].regno = regno;
118 state->info[regno].set = setname;
119 state->info[regno].pfx = prefix;
120 state->info[regno].bits = bits;
121 state->info[regno].type = type;
122 assert (strlen (regname) < sizeof state->info[regno].name);
123 strcpy (state->info[regno].name, regname);
130 match_register (void *arg,
137 if (regno == *(int *) arg)
138 printf ("%5d => %s register %s%s %s %d bits\n",
139 regno, setname, prefix, regname,
140 dwarf_encoding_string (type), bits);
142 return DWARF_CB_ABORT;
147 main (int argc, char **argv)
152 (void) setlocale (LC_ALL, "");
155 (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &remaining, &dwfl);
156 assert (dwfl != NULL);
158 Dwfl_Module *mod = NULL;
159 if (dwfl_getmodules (dwfl, &first_module, &mod, 0) < 0)
160 error (EXIT_FAILURE, 0, "dwfl_getmodules: %s", dwfl_errmsg (-1));
162 if (remaining == argc)
164 struct state state = { NULL, 0 };
165 int result = dwfl_module_register_names (mod, &one_register, &state);
166 if (result != 0 || state.nregs == 0)
167 error (EXIT_FAILURE, 0, "dwfl_module_register_names: %s",
168 result ? dwfl_errmsg (-1) : "no backend registers known");
170 qsort (state.info, state.nregs, sizeof state.info[0], &compare);
172 const char *set = NULL;
173 for (int i = 0; i < state.nregs; ++i)
174 if (state.info[i].set != NULL)
176 if (set != state.info[i].set)
177 printf ("%s registers:\n", state.info[i].set);
178 set = state.info[i].set;
180 printf ("\t%3d: %s%s (%s), %s %d bits\n",
182 state.info[i].pfx ?: "", state.info[i].name,
184 dwarf_encoding_string (state.info[i].type),
191 const char *arg = argv[remaining++];
192 int regno = atoi (arg);
193 int result = dwfl_module_register_names (mod, &match_register, ®no);
194 if (result != DWARF_CB_ABORT)
195 error (EXIT_FAILURE, 0, "dwfl_module_register_names: %s",
196 result ? dwfl_errmsg (-1) : "no backend registers known");
198 while (remaining < argc);