Blame sysdeps/unix/sysv/linux/riscv/register-dump.h

Packit 6c4009
/* Dump registers.
Packit 6c4009
   Copyright (C) 2000-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library.  If not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <unistd.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <_itoa.h>
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
hexvalue (unsigned long int value, char *buf, size_t len)
Packit 6c4009
{
Packit 6c4009
  char *cp = _itoa_word (value, buf + len, 16, 0);
Packit 6c4009
  while (cp > buf)
Packit 6c4009
    *--cp = '0';
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define REGDUMP_NREGS 32
Packit 6c4009
#define REGDUMP_PER_LINE (80 / (__WORDSIZE / 4 + 4))
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
register_dump (int fd, ucontext_t *ctx)
Packit 6c4009
{
Packit 6c4009
  int i;
Packit 6c4009
  char regvalue[__WORDSIZE / 4 + 1];
Packit 6c4009
  char str[82 * ((REGDUMP_NREGS + REGDUMP_PER_LINE - 1) / REGDUMP_PER_LINE)];
Packit 6c4009
Packit 6c4009
  static const char names[REGDUMP_NREGS][4] = {
Packit 6c4009
    "pc", "ra", "sp", "gp", "tp", "t0", "t1", "t2",
Packit 6c4009
    "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5",
Packit 6c4009
    "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7",
Packit 6c4009
    "s8", "s9", "sA", "sB", "t3", "t4", "t5", "t6"
Packit 6c4009
  };
Packit 6c4009
Packit 6c4009
  str[0] = 0;
Packit 6c4009
  for (i = 0; i < REGDUMP_NREGS; i++)
Packit 6c4009
    {
Packit 6c4009
      strcat (str, names[i]);
Packit 6c4009
      strcat (str, " ");
Packit 6c4009
      hexvalue (ctx->uc_mcontext.__gregs[i], regvalue, __WORDSIZE / 4);
Packit 6c4009
      strcat (str, regvalue);
Packit 6c4009
Packit 6c4009
      if ((i + 1) % REGDUMP_PER_LINE == 0)
Packit 6c4009
	strcat (str, "\n");
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  write (fd, str, strlen (str));
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define REGISTER_DUMP register_dump (fd, ctx)