xref: /openbmc/qemu/gdbstub/user.c (revision 21063bce)
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/gdbstub.h"
13 #include "hw/core/cpu.h"
14 #include "internals.h"
15 
16 bool gdb_supports_guest_debug(void)
17 {
18     /* user-mode == TCG == supported */
19     return true;
20 }
21 
22 int gdb_breakpoint_insert(CPUState *cs, int type, vaddr addr, vaddr len)
23 {
24     CPUState *cpu;
25     int err = 0;
26 
27     switch (type) {
28     case GDB_BREAKPOINT_SW:
29     case GDB_BREAKPOINT_HW:
30         CPU_FOREACH(cpu) {
31             err = cpu_breakpoint_insert(cpu, addr, BP_GDB, NULL);
32             if (err) {
33                 break;
34             }
35         }
36         return err;
37     default:
38         /* user-mode doesn't support watchpoints */
39         return -ENOSYS;
40     }
41 }
42 
43 int gdb_breakpoint_remove(CPUState *cs, int type, vaddr addr, vaddr len)
44 {
45     CPUState *cpu;
46     int err = 0;
47 
48     switch (type) {
49     case GDB_BREAKPOINT_SW:
50     case GDB_BREAKPOINT_HW:
51         CPU_FOREACH(cpu) {
52             err = cpu_breakpoint_remove(cpu, addr, BP_GDB);
53             if (err) {
54                 break;
55             }
56         }
57         return err;
58     default:
59         /* user-mode doesn't support watchpoints */
60         return -ENOSYS;
61     }
62 }
63 
64 void gdb_breakpoint_remove_all(CPUState *cs)
65 {
66     cpu_breakpoint_remove_all(cs, BP_GDB);
67 }
68