]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/sh-nbsd-nat.c
Fix buffer overrun parsing a corrupt tekhex binary.
[thirdparty/binutils-gdb.git] / gdb / sh-nbsd-nat.c
CommitLineData
bd372731
MK
1/* Native-dependent code for NetBSD/sh.
2
61baf725 3 Copyright (C) 2002-2017 Free Software Foundation, Inc.
9f8e0089 4
13a38d45
JT
5 Contributed by Wasabi Systems, Inc.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
13a38d45
JT
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
13a38d45 21
bd372731
MK
22#include "defs.h"
23#include "inferior.h"
24
13a38d45
JT
25#include <sys/types.h>
26#include <sys/ptrace.h>
27#include <machine/reg.h>
28
97a5b208 29#include "sh-tdep.h"
bd372731 30#include "inf-ptrace.h"
4e3269e3
UW
31#include "regcache.h"
32
13a38d45 33
c378eb4e 34/* Determine if PT_GETREGS fetches this register. */
40a6adc1 35#define GETREGS_SUPPLIES(gdbarch, regno) \
13a38d45 36 (((regno) >= R0_REGNUM && (regno) <= (R0_REGNUM + 15)) \
40a6adc1 37|| (regno) == gdbarch_pc_regnum (gdbarch) || (regno) == PR_REGNUM \
13a38d45
JT
38|| (regno) == MACH_REGNUM || (regno) == MACL_REGNUM \
39|| (regno) == SR_REGNUM)
40
c9ac0a72
AS
41/* Sizeof `struct reg' in <machine/reg.h>. */
42#define SHNBSD_SIZEOF_GREGS (21 * 4)
43
bd372731 44static void
28439f5e
PA
45shnbsd_fetch_inferior_registers (struct target_ops *ops,
46 struct regcache *regcache, int regno)
13a38d45 47{
bcc0c096
SM
48 pid_t pid = ptid_get_pid (regcache_get_ptid (regcache));
49
40a6adc1 50 if (regno == -1 || GETREGS_SUPPLIES (get_regcache_arch (regcache), regno))
13a38d45
JT
51 {
52 struct reg inferior_registers;
53
bcc0c096 54 if (ptrace (PT_GETREGS, pid,
dfeafa2f 55 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
e2e0b3e5 56 perror_with_name (_("Couldn't get registers"));
13a38d45 57
c9ac0a72
AS
58 sh_corefile_supply_regset (&sh_corefile_gregset, regcache, regno,
59 (char *) &inferior_registers,
60 SHNBSD_SIZEOF_GREGS);
13a38d45
JT
61
62 if (regno != -1)
63 return;
64 }
65}
66
bd372731 67static void
28439f5e
PA
68shnbsd_store_inferior_registers (struct target_ops *ops,
69 struct regcache *regcache, int regno)
13a38d45 70{
bcc0c096
SM
71 pid_t pid = ptid_get_pid (regcache_get_ptid (regcache));
72
40a6adc1 73 if (regno == -1 || GETREGS_SUPPLIES (get_regcache_arch (regcache), regno))
13a38d45
JT
74 {
75 struct reg inferior_registers;
76
bcc0c096 77 if (ptrace (PT_GETREGS, pid,
dfeafa2f 78 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
e2e0b3e5 79 perror_with_name (_("Couldn't get registers"));
13a38d45 80
c9ac0a72
AS
81 sh_corefile_collect_regset (&sh_corefile_gregset, regcache, regno,
82 (char *) &inferior_registers,
83 SHNBSD_SIZEOF_GREGS);
13a38d45 84
bcc0c096 85 if (ptrace (PT_SETREGS, pid,
dfeafa2f 86 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1)
e2e0b3e5 87 perror_with_name (_("Couldn't set registers"));
13a38d45
JT
88
89 if (regno != -1)
90 return;
91 }
92}
bd372731
MK
93
94/* Provide a prototype to silence -Wmissing-prototypes. */
95void _initialize_shnbsd_nat (void);
96
97void
98_initialize_shnbsd_nat (void)
99{
100 struct target_ops *t;
101
102 t = inf_ptrace_target ();
103 t->to_fetch_registers = shnbsd_fetch_inferior_registers;
104 t->to_store_registers = shnbsd_store_inferior_registers;
105 add_target (t);
106}