xref: /openbmc/qemu/gdbstub/user.c (revision a95570e3)
1 /*
2  * gdbstub user-mode helper routines.
3  *
4  * We know for user-mode we are using TCG so we can call stuff directly.
5  *
6  * Copyright (c) 2022 Linaro Ltd
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10 
11 #include "qemu/osdep.h"
12 #include "exec/hwaddr.h"
13 #include "exec/gdbstub.h"
14 #include "hw/core/cpu.h"
15 #include "internals.h"
16 
17 bool gdb_supports_guest_debug(void)
18 {
19     /* user-mode == TCG == supported */
20     return true;
21 }
22 
23 int gdb_breakpoint_insert(CPUState *cs, int type, hwaddr addr, hwaddr len)
24 {
25     CPUState *cpu;
26     int err = 0;
27 
28     switch (type) {
29     case GDB_BREAKPOINT_SW:
30     case GDB_BREAKPOINT_HW:
31         CPU_FOREACH(cpu) {
32             err = cpu_breakpoint_insert(cpu, addr, BP_GDB, NULL);
33             if (err) {
34                 break;
35             }
36         }
37         return err;
38     default:
39         /* user-mode doesn't support watchpoints */
40         return -ENOSYS;
41     }
42 }
43 
44 int gdb_breakpoint_remove(CPUState *cs, int type, hwaddr addr, hwaddr len)
45 {
46     CPUState *cpu;
47     int err = 0;
48 
49     switch (type) {
50     case GDB_BREAKPOINT_SW:
51     case GDB_BREAKPOINT_HW:
52         CPU_FOREACH(cpu) {
53             err = cpu_breakpoint_remove(cpu, addr, BP_GDB);
54             if (err) {
55                 break;
56             }
57         }
58         return err;
59     default:
60         /* user-mode doesn't support watchpoints */
61         return -ENOSYS;
62     }
63 }
64 
65 void gdb_breakpoint_remove_all(CPUState *cs)
66 {
67     cpu_breakpoint_remove_all(cs, BP_GDB);
68 }
69