source: rtems/cpukit/libdebugger/rtems-debugger-target.h @ a0d4e99

Last change on this file since a0d4e99 was a0d4e99, checked in by Chris Johns <chrisj@…>, on Nov 25, 2016 at 4:13:36 AM

cpukit: Add libdebugger, a remote debugger agent for GDB.

  • Property mode set to 100644
File size: 6.9 KB
Line 
1/*
2 * Copyright (c) 2016 Chris Johns <chrisj@rtems.org>.  All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26/*
27 * Debugger for RTEMS.
28 */
29
30#ifndef _RTEMS_DEBUGGER_TARGET_h
31#define _RTEMS_DEBUGGER_TARGET_h
32
33#include <setjmp.h>
34
35#include <rtems/rtems-debugger.h>
36
37#include "rtems-debugger-threads.h"
38
39#ifdef __cplusplus
40extern "C" {
41#endif /* __cplusplus */
42
43/*
44 * Software breakpoint block size.
45 */
46#define RTEMS_DEBUGGER_TARGET_SWBREAK_NUM 64
47
48/**
49 * Target capabilities mask.
50 */
51#define RTEMS_DEBUGGER_TARGET_CAP_SWBREAK   (1 << 0)
52#define RTEMS_DEBUGGER_TARGET_CAP_HWBREAK   (1 << 1)
53#define RTEMS_DEBUGGER_TARGET_CAP_HWWATCH   (1 << 2)
54
55/**
56 * Types of hardware breakpoints.
57 */
58typedef enum rtems_debugger_target_watchpoint
59{
60  rtems_debugger_target_hw_read,
61  rtems_debugger_target_hw_write,
62  rtems_debugger_target_hw_read_write,
63  rtems_debugger_target_hw_execute
64} rtems_debugger_target_watchpoint;
65
66/**
67 * Target exception actions.
68 */
69typedef enum rtems_debugger_target_exc_action
70{
71  rtems_debugger_target_exc_consumed, /*<< The exception has been consumed. */
72  rtems_debugger_target_exc_cascade,  /*<< Cascade to a previous handler. */
73  rtems_debugger_target_exc_step,     /*<< Step an instruction. */
74} rtems_debugger_target_exc_action;
75
76/**
77 * Memory breakpoint. We use thumb mode BKPT which is 2 bytes.
78 */
79#define RTEMS_DEBUGGER_TARGET_SWBREAK_MAX_SIZE (4)
80typedef struct rtems_debugger_target_swbreak {
81  void*   address;
82  uint8_t contents[RTEMS_DEBUGGER_TARGET_SWBREAK_MAX_SIZE];
83} rtems_debugger_target_swbreak;
84
85/**
86 * The target data.
87 */
88typedef struct rtems_debugger_target {
89  int                  capabilities;     /*<< The capabilities to report. */
90  size_t               reg_num;          /*<< The number of registers. */
91  size_t               reg_size;         /*<< The size of a register. */
92  const uint8_t*       breakpoint;       /*<< The breakpoint instruction(s). */
93  size_t               breakpoint_size;  /*<< The breakpoint size. */
94  rtems_debugger_block swbreaks;         /*<< The software breakpoint block. */
95  bool                 memory_access;    /*<< Accessing target memory. */
96  jmp_buf              access_return;    /*<< Return from an access fault. */
97} rtems_debugger_target;
98
99/**
100 * Create the target.
101 */
102extern int rtems_debugger_target_create(void);
103
104/**
105 * Destroy the target.
106 */
107extern int rtems_debugger_target_destroy(void);
108
109/**
110 * Configure the target. This is architecture specific.
111 */
112extern int rtems_debugger_target_configure(rtems_debugger_target* target);
113
114/**
115 * Enable the target.
116 */
117extern int rtems_debugger_target_enable(void);
118
119/**
120 * Disable the target.
121 */
122extern int rtems_debugger_target_disable(void);
123
124/**
125 * Return the capabilities mask for the target.
126 */
127extern uint32_t rtems_debugger_target_capabilities(void);
128
129/**
130 * Return the number of regisers.
131 */
132extern size_t rtems_debugger_target_reg_num(void);
133
134/**
135 * Return the size of the regisers in bytes.
136 */
137extern size_t rtems_debugger_target_reg_size(void);
138
139/**
140 * Read the regosters.
141 */
142extern int rtems_debugger_target_read_regs(rtems_debugger_thread* thread);
143
144/**
145 * Write the regosters.
146 */
147extern int rtems_debugger_target_write_regs(rtems_debugger_thread* thread);
148
149/**
150 * Return the thread's program counter (PC).
151 */
152extern DB_UINT rtems_debugger_target_reg_pc(rtems_debugger_thread* thread);
153
154/**
155 * Return the frame's program counter (PC).
156 */
157extern DB_UINT rtems_debugger_target_frame_pc(CPU_Exception_frame* frame);
158
159/**
160 * Return the thread's stack pointer (SP).
161 */
162extern DB_UINT rtems_debugger_target_reg_sp(rtems_debugger_thread* thread);
163
164/**
165 * Return the thread's TCB stack pointer (SP).
166 */
167extern DB_UINT rtems_debugger_target_tcb_sp(rtems_debugger_thread* thread);
168
169/**
170 * The thread is stepping. Setup the thread to step an instruction.
171 */
172extern int rtems_debugger_target_thread_stepping(rtems_debugger_thread* thread);
173
174/**
175 * Return the signal for the exception.
176 */
177extern int rtems_debugger_target_exception_to_signal(CPU_Exception_frame* frame);
178
179/**
180 * Software breakpoints. These are also referred to as memory breakpoints.
181 */
182extern int rtems_debugger_target_swbreak_control(bool    insert,
183                                                 DB_UINT addr,
184                                                 DB_UINT kind);
185
186/**
187 * Insert software breakpoints into the memory.
188 */
189extern int rtems_debugger_target_swbreak_insert(void);
190
191/**
192 * Remove software breakpoints from the memory.
193 */
194extern int rtems_debugger_target_swbreak_remove(void);
195
196/**
197 * Hardware breakpoints.
198 */
199extern int rtems_debugger_target_hwbreak_control(rtems_debugger_target_watchpoint type,
200                                                 bool                             insert,
201                                                 DB_UINT                          addr,
202                                                 DB_UINT                          kind);
203
204/**
205 * Target exception processor.
206 */
207extern rtems_debugger_target_exc_action
208rtems_debugger_target_exception(CPU_Exception_frame* frame);
209
210/**
211 * Set the thread's exception stack frame pointer.
212 */
213extern int rtems_debugger_target_set_exception_frame(rtems_debugger_thread* thread);
214
215/**
216 * Target instruction cache sync. This depends on the target but it normally
217 * means a data cache flush and an instruction cache invalidate.
218 */
219extern int rtems_debugger_target_cache_sync(rtems_debugger_target_swbreak* swbreak);
220
221/**
222 * Start a target memory access. If 0 is return the access can proceed and if
223 * -1 is return the access has failed.
224 */
225extern int rtems_debugger_target_start_memory_access(void);
226
227/**
228 * End a target memory access.
229 */
230extern void rtems_debugger_target_end_memory_access(void);
231
232#ifdef __cplusplus
233}
234#endif /* __cplusplus */
235
236
237#endif
Note: See TracBrowser for help on using the repository browser.