Fix null pointer dereference in process_debug_info()
[binutils-gdb.git] / gdb / riscv-ravenscar-thread.c
blob291b1db8d9e4ce674b4ca6e073d02f7857eed560
1 /* Ravenscar RISC-V target support.
3 Copyright (C) 2019-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "gdbarch.h"
21 #include "gdbcore.h"
22 #include "regcache.h"
23 #include "riscv-tdep.h"
24 #include "inferior.h"
25 #include "ravenscar-thread.h"
26 #include "riscv-ravenscar-thread.h"
28 #define LAST_REGISTER (RISCV_FIRST_FP_REGNUM + 14)
30 struct riscv_ravenscar_ops : public ravenscar_arch_ops
32 int reg_offsets[LAST_REGISTER + 1];
34 riscv_ravenscar_ops (struct gdbarch *arch);
37 riscv_ravenscar_ops::riscv_ravenscar_ops (struct gdbarch *arch)
38 : ravenscar_arch_ops (gdb::make_array_view (reg_offsets, LAST_REGISTER + 1))
40 int reg_size = riscv_isa_xlen (arch);
42 for (int regnum = 0; regnum <= LAST_REGISTER; ++regnum)
44 int offset;
45 if (regnum == RISCV_RA_REGNUM || regnum == RISCV_PC_REGNUM)
46 offset = 0;
47 else if (regnum == RISCV_SP_REGNUM)
48 offset = 1;
49 else if (regnum == RISCV_ZERO_REGNUM + 8) /* S0 */
50 offset = 2;
51 else if (regnum == RISCV_ZERO_REGNUM + 9) /* S1 */
52 offset = 3;
53 else if (regnum >= RISCV_ZERO_REGNUM + 19
54 && regnum <= RISCV_ZERO_REGNUM + 27) /* S2..S11 */
55 offset = regnum - (RISCV_ZERO_REGNUM + 19) + 4;
56 else if (regnum >= RISCV_FIRST_FP_REGNUM
57 && regnum <= RISCV_FIRST_FP_REGNUM + 11)
58 offset = regnum - RISCV_FIRST_FP_REGNUM + 14; /* FS0..FS11 */
59 else
60 offset = -1;
62 if (offset != -1)
63 offset *= reg_size;
65 reg_offsets[regnum] = offset;
69 /* Register riscv_ravenscar_ops in GDBARCH. */
71 void
72 register_riscv_ravenscar_ops (struct gdbarch *gdbarch)
74 set_gdbarch_ravenscar_ops (gdbarch, new riscv_ravenscar_ops (gdbarch));