125b3c049e70834cf33790a28643ab058b507b35cBen Cheng/* Enumerate DWARF register numbers and their names.
225b3c049e70834cf33790a28643ab058b507b35cBen Cheng   Copyright (C) 2005, 2006 Red Hat, Inc.
303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   This file is part of elfutils.
425b3c049e70834cf33790a28643ab058b507b35cBen Cheng
503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   This file is free software; you can redistribute it and/or modify
603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   it under the terms of either
725b3c049e70834cf33790a28643ab058b507b35cBen Cheng
803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes     * the GNU Lesser General Public License as published by the Free
903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes       Software Foundation; either version 3 of the License, or (at
1003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes       your option) any later version
1103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
1203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   or
1303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
1403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes     * the GNU General Public License as published by the Free
1503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes       Software Foundation; either version 2 of the License, or (at
1603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes       your option) any later version
1703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
1803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   or both in parallel, as here.
1903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
2003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   elfutils is distributed in the hope that it will be useful, but
2125b3c049e70834cf33790a28643ab058b507b35cBen Cheng   WITHOUT ANY WARRANTY; without even the implied warranty of
2225b3c049e70834cf33790a28643ab058b507b35cBen Cheng   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2325b3c049e70834cf33790a28643ab058b507b35cBen Cheng   General Public License for more details.
2425b3c049e70834cf33790a28643ab058b507b35cBen Cheng
2503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   You should have received copies of the GNU General Public License and
2603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   the GNU Lesser General Public License along with this program.  If
2703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes   not, see <http://www.gnu.org/licenses/>.  */
2825b3c049e70834cf33790a28643ab058b507b35cBen Cheng
2925b3c049e70834cf33790a28643ab058b507b35cBen Cheng#include "libdwflP.h"
3025b3c049e70834cf33790a28643ab058b507b35cBen Cheng
3125b3c049e70834cf33790a28643ab058b507b35cBen Cheng
3225b3c049e70834cf33790a28643ab058b507b35cBen Chengint
3325b3c049e70834cf33790a28643ab058b507b35cBen Chengdwfl_module_register_names (mod, func, arg)
3425b3c049e70834cf33790a28643ab058b507b35cBen Cheng     Dwfl_Module *mod;
3525b3c049e70834cf33790a28643ab058b507b35cBen Cheng     int (*func) (void *, int regno, const char *setname,
3625b3c049e70834cf33790a28643ab058b507b35cBen Cheng		  const char *prefix, const char *regname,
3725b3c049e70834cf33790a28643ab058b507b35cBen Cheng		  int bits, int type);
3825b3c049e70834cf33790a28643ab058b507b35cBen Cheng     void *arg;
3925b3c049e70834cf33790a28643ab058b507b35cBen Cheng{
4025b3c049e70834cf33790a28643ab058b507b35cBen Cheng  if (unlikely (mod == NULL))
4125b3c049e70834cf33790a28643ab058b507b35cBen Cheng    return -1;
4225b3c049e70834cf33790a28643ab058b507b35cBen Cheng
4325b3c049e70834cf33790a28643ab058b507b35cBen Cheng  if (unlikely (mod->ebl == NULL))
4425b3c049e70834cf33790a28643ab058b507b35cBen Cheng    {
4525b3c049e70834cf33790a28643ab058b507b35cBen Cheng      Dwfl_Error error = __libdwfl_module_getebl (mod);
4625b3c049e70834cf33790a28643ab058b507b35cBen Cheng      if (error != DWFL_E_NOERROR)
4725b3c049e70834cf33790a28643ab058b507b35cBen Cheng	{
4825b3c049e70834cf33790a28643ab058b507b35cBen Cheng	  __libdwfl_seterrno (error);
4925b3c049e70834cf33790a28643ab058b507b35cBen Cheng	  return -1;
5025b3c049e70834cf33790a28643ab058b507b35cBen Cheng	}
5125b3c049e70834cf33790a28643ab058b507b35cBen Cheng    }
5225b3c049e70834cf33790a28643ab058b507b35cBen Cheng
5325b3c049e70834cf33790a28643ab058b507b35cBen Cheng  int nregs = ebl_register_info (mod->ebl, -1, NULL, 0,
5425b3c049e70834cf33790a28643ab058b507b35cBen Cheng				 NULL, NULL, NULL, NULL);
5525b3c049e70834cf33790a28643ab058b507b35cBen Cheng  int result = 0;
5625b3c049e70834cf33790a28643ab058b507b35cBen Cheng  for (int regno = 0; regno < nregs && likely (result == 0); ++regno)
5725b3c049e70834cf33790a28643ab058b507b35cBen Cheng    {
5825b3c049e70834cf33790a28643ab058b507b35cBen Cheng      char name[32];
5925b3c049e70834cf33790a28643ab058b507b35cBen Cheng      const char *setname = NULL;
6025b3c049e70834cf33790a28643ab058b507b35cBen Cheng      const char *prefix = NULL;
6125b3c049e70834cf33790a28643ab058b507b35cBen Cheng      int bits = -1;
6225b3c049e70834cf33790a28643ab058b507b35cBen Cheng      int type = -1;
6325b3c049e70834cf33790a28643ab058b507b35cBen Cheng      ssize_t len = ebl_register_info (mod->ebl, regno, name, sizeof name,
6425b3c049e70834cf33790a28643ab058b507b35cBen Cheng				       &prefix, &setname, &bits, &type);
6525b3c049e70834cf33790a28643ab058b507b35cBen Cheng      if (unlikely (len < 0))
6625b3c049e70834cf33790a28643ab058b507b35cBen Cheng	{
6725b3c049e70834cf33790a28643ab058b507b35cBen Cheng	  __libdwfl_seterrno (DWFL_E_LIBEBL);
6825b3c049e70834cf33790a28643ab058b507b35cBen Cheng	  result = -1;
6925b3c049e70834cf33790a28643ab058b507b35cBen Cheng	  break;
7025b3c049e70834cf33790a28643ab058b507b35cBen Cheng	}
7125b3c049e70834cf33790a28643ab058b507b35cBen Cheng      if (likely (len > 0))
7225b3c049e70834cf33790a28643ab058b507b35cBen Cheng	{
7325b3c049e70834cf33790a28643ab058b507b35cBen Cheng	  assert (len > 1);	/* Backend should never yield "".  */
7425b3c049e70834cf33790a28643ab058b507b35cBen Cheng	  result = (*func) (arg, regno, setname, prefix, name, bits, type);
7525b3c049e70834cf33790a28643ab058b507b35cBen Cheng	}
7625b3c049e70834cf33790a28643ab058b507b35cBen Cheng    }
7725b3c049e70834cf33790a28643ab058b507b35cBen Cheng
7825b3c049e70834cf33790a28643ab058b507b35cBen Cheng  return result;
7925b3c049e70834cf33790a28643ab058b507b35cBen Cheng}
80