1994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath/* Enumerate DWARF register numbers and their names.
2c373d850ec9ca342f4c71d5e287c8d8bf0723cd6Roland McGrath   Copyright (C) 2005, 2006 Red Hat, Inc.
3de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   This file is part of elfutils.
4994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath
5de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   This file is free software; you can redistribute it and/or modify
6de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   it under the terms of either
7994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath
8de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard     * the GNU Lesser General Public License as published by the Free
9de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       Software Foundation; either version 3 of the License, or (at
10de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       your option) any later version
11de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
12de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   or
13de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
14de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard     * the GNU General Public License as published by the Free
15de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       Software Foundation; either version 2 of the License, or (at
16de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       your option) any later version
17de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
18de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   or both in parallel, as here.
19de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
20de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   elfutils is distributed in the hope that it will be useful, but
21361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   WITHOUT ANY WARRANTY; without even the implied warranty of
22361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   General Public License for more details.
24361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper
25de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   You should have received copies of the GNU General Public License and
26de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   the GNU Lesser General Public License along with this program.  If
27de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   not, see <http://www.gnu.org/licenses/>.  */
28994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath
29994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath#include "libdwflP.h"
30994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath
31994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath
32994b4899278199fc4d307780dac0ea50b238bc74Roland McGrathint
331ccdfb683ad6c7e59793136c3a657ddf131cafd1Mark Wielaarddwfl_module_register_names (Dwfl_Module *mod,
341ccdfb683ad6c7e59793136c3a657ddf131cafd1Mark Wielaard			    int (*func) (void *, int, const char *,
351ccdfb683ad6c7e59793136c3a657ddf131cafd1Mark Wielaard					 const char *, const char *,
361ccdfb683ad6c7e59793136c3a657ddf131cafd1Mark Wielaard					 int, int),
371ccdfb683ad6c7e59793136c3a657ddf131cafd1Mark Wielaard			    void *arg)
38994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath{
39994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath  if (unlikely (mod == NULL))
40994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath    return -1;
41994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath
42994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath  if (unlikely (mod->ebl == NULL))
43994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath    {
44994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath      Dwfl_Error error = __libdwfl_module_getebl (mod);
45994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath      if (error != DWFL_E_NOERROR)
46994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath	{
47994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath	  __libdwfl_seterrno (error);
48994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath	  return -1;
49994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath	}
50994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath    }
51994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath
52c373d850ec9ca342f4c71d5e287c8d8bf0723cd6Roland McGrath  int nregs = ebl_register_info (mod->ebl, -1, NULL, 0,
53c373d850ec9ca342f4c71d5e287c8d8bf0723cd6Roland McGrath				 NULL, NULL, NULL, NULL);
54994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath  int result = 0;
55994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath  for (int regno = 0; regno < nregs && likely (result == 0); ++regno)
56994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath    {
57994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath      char name[32];
58994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath      const char *setname = NULL;
59994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath      const char *prefix = NULL;
60c373d850ec9ca342f4c71d5e287c8d8bf0723cd6Roland McGrath      int bits = -1;
61c373d850ec9ca342f4c71d5e287c8d8bf0723cd6Roland McGrath      int type = -1;
62c373d850ec9ca342f4c71d5e287c8d8bf0723cd6Roland McGrath      ssize_t len = ebl_register_info (mod->ebl, regno, name, sizeof name,
63c373d850ec9ca342f4c71d5e287c8d8bf0723cd6Roland McGrath				       &prefix, &setname, &bits, &type);
64994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath      if (unlikely (len < 0))
65994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath	{
66994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath	  __libdwfl_seterrno (DWFL_E_LIBEBL);
67994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath	  result = -1;
68994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath	  break;
69994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath	}
70994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath      if (likely (len > 0))
71994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath	{
72994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath	  assert (len > 1);	/* Backend should never yield "".  */
73c373d850ec9ca342f4c71d5e287c8d8bf0723cd6Roland McGrath	  result = (*func) (arg, regno, setname, prefix, name, bits, type);
74994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath	}
75994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath    }
76994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath
77994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath  return result;
78994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath}
79