TEMU  4.4
The Terma Emulator
Debugger.h
Go to the documentation of this file.
1 //===-- temu-c/Debugger.h - TEMU Debugger API -------------------*- C++ -*-===//
2 //
3 // TEMU: The Terma Emulator
4 // (c) Terma 2023
5 // Authors: Mattias Holm <maho (at) terma.com>
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef TEMU_DEBUGGER_H
10 #define TEMU_DEBUGGER_H
11 
12 #include "temu-c/Support/Objsys.h"
13 #include <stdint.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 typedef struct temu_TimeSource temu_TimeSource;
20 typedef struct temu_Object temu_Object;
21 typedef struct temu_MemTransaction temu_MemTransaction;
22 /*
23  * Debugger functions and interfaces
24  *
25  * These functions and interfaces define an interface that can be used to
26  * attach debugger servers for e.g. the GDB RSP protocol.
27  *
28  * The functions and interfaces should be seen as unstable.
29  * Note that that means the API may change, not that they are broken.
30  *
31  * These interfaces are intended to be used to interface debuggers
32  * with the scheduler.
33  */
34 
35 /*!
36  * Return current processor number
37  *
38  * Returns -1 when running, or stopped CPU number after breakpoint hit.
39  */
41 
42 /*!
43  * Stop the scheduler from a debugger
44  *
45  * This function is intended to be used by the GDB server.
46  * It stops the scheduler as soon as possible, without returning
47  * from the temu_run*() functions.
48  *
49  * The function is blocking until the core has been stopped.
50  * If the core is currently not running, this function waits
51  * until someone calls temu_run*().
52  */
53 void temu_debuggerStop();
54 
55 /*!
56  * Resume the scheduler from a debugger
57  *
58  * Resumes the scheduler after a stop or breakpoint.
59  * Note the function returns immediately.
60  * The debugger server is expected to listen for events
61  * through the debugger interface instead.
62  */
63 void temu_debuggerCont();
64 
65 /*!
66  * Step the given processor.
67  *
68  * The debugger must be attached, and the function will block until
69  * the scheduler is running using temu_run*() functions.
70  */
71 void temu_debuggerStep(temu_TimeSource *cpu, int steps);
72 
73 typedef enum {
76 } temu_BreakState;
77 
78 typedef enum {
81 } temu_BreakAction;
82 
83 // The breakpoint functions here are called as:
84 //
85 // While running, the hit function is called, this function may be called
86 // in parallel from different processors.
87 // The handler should return the action to be taken.
88 // E.g. if we want to stop at this location, or not.
89 // Subsequently, if the breakpoint results in in a teBS_Handle,
90 // the corresponding handle function will be called in a thread safe manner.
91 // Note that in the case of parallel execution, multiple breakpoint may be
92 // "hit". before handling them.
93 
94 typedef struct {
95  temu_BreakState (*breakpointHit)(void *obj, temu_TimeSource *cpu, int cpuId,
96  temu_MemTransaction *mt);
97  temu_BreakState (*watchpointReadHit)(void *obj, temu_TimeSource *cpu,
98  int cpuId, temu_MemTransaction *mt);
99  temu_BreakState (*watchpointWriteHit)(void *obj, temu_TimeSource *cpu,
100  int cpuId, temu_MemTransaction *mt);
101 
102  temu_BreakState (*ioReadHit)(void *obj, temu_TimeSource *cpu, int cpuId,
103  temu_Object *ioDevice, temu_MemTransaction *mt);
104  temu_BreakState (*ioWriteHit)(void *obj, temu_TimeSource *cpu, int cpuId,
105  temu_Object *ioDevice, temu_MemTransaction *mt);
106 
107  temu_BreakAction (*handleBreakpoint)(void *obj, temu_TimeSource *cpu,
108  int cpuId, temu_MemTransaction *mt);
109  temu_BreakAction (*handleReadWatchpoint)(void *obj, temu_TimeSource *cpu,
110  int cpuId, temu_MemTransaction *mt);
111  temu_BreakAction (*handleWriteWatchpoint)(void *obj, temu_TimeSource *cpu,
112  int cpuId, temu_MemTransaction *mt);
113 
114  temu_BreakAction (*handleIoRead)(void *obj, temu_TimeSource *cpu, int cpuId,
115  temu_Object *ioDevice,
116  temu_MemTransaction *mt);
117  temu_BreakAction (*handleIoWrite)(void *obj, temu_TimeSource *cpu, int cpuId,
118  temu_Object *ioDevice,
119  temu_MemTransaction *mt);
120 
121  void (*stopped)(void *obj);
122 } temu_DebuggerIface;
123 #define TEMU_DEBUGGER_IFACE_TYPE "temu::DebuggerIface"
124 TEMU_IFACE_REFERENCE_TYPE(temu_Debugger)
125 
126 /*!
127  * Attach a debugger to the current scheduler
128  *
129  * This attaches a debugger to the scheduler,
130  * ensuring it is notified about events such as breakpoints and watchpoints.
131  */
132 void temu_debuggerAttach(void *debugger, temu_DebuggerIface *debuggerIface);
133 
134 /*!
135  * Notify debugger infrastructure that a remote connection has been made
136  */
138 
139 /*!
140  * Detach the debugger from the current scheduler
141  *
142  * This attaches a debugger to the scheduler,
143  * ensuring it is notified about events such as breakpoints and watchpoints.
144  */
145 
146 void temu_debuggerDetach(void *debugger);
147 
148 #ifdef __cplusplus
149 }
150 #endif
151 
152 #endif // !TEMU_DEBUGGER_H
temu_MemTransaction
struct temu_MemTransaction temu_MemTransaction
Definition: Debugger.h:21
teBS_Handle
@ teBS_Handle
Definition: Debugger.h:75
temu_DebuggerIface::stopped
void(* stopped)(void *obj)
Definition: Debugger.h:121
temu_debuggerStop
void temu_debuggerStop()
temu_debuggerStep
void temu_debuggerStep(temu_TimeSource *cpu, int steps)
temu_debuggerDetach
void temu_debuggerDetach(void *debugger)
temu_debuggerGetCurrentProcessor
int temu_debuggerGetCurrentProcessor()
temu_Object
struct temu_Object temu_Object
Definition: Scheduler.h:18
temu_debuggerAttach
void temu_debuggerAttach(void *debugger, temu_DebuggerIface *debuggerIface)
teBA_Resume
@ teBA_Resume
Definition: Debugger.h:80
temu_TimeSource
struct temu_TimeSource temu_TimeSource
Definition: Scheduler.h:17
teBS_Ignore
@ teBS_Ignore
Definition: Debugger.h:74
temu_debuggerCont
void temu_debuggerCont()
teBA_Stop
@ teBA_Stop
Definition: Debugger.h:79
temu_debuggerConnected
void temu_debuggerConnected()