[a0d4e99] | 1 | /* |
---|
[b2353ed9] | 2 | * Copyright (c) 2016-2017 Chris Johns <chrisj@rtems.org>. |
---|
| 3 | * All rights reserved. |
---|
[a0d4e99] | 4 | * |
---|
| 5 | * Redistribution and use in source and binary forms, with or without |
---|
| 6 | * modification, are permitted provided that the following conditions |
---|
| 7 | * are met: |
---|
| 8 | * 1. Redistributions of source code must retain the above copyright |
---|
| 9 | * notice, this list of conditions and the following disclaimer. |
---|
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
| 11 | * notice, this list of conditions and the following disclaimer in the |
---|
| 12 | * documentation and/or other materials provided with the distribution. |
---|
| 13 | * |
---|
| 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
---|
| 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
| 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
| 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
| 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
| 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
| 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
| 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
| 24 | * SUCH DAMAGE. |
---|
| 25 | */ |
---|
| 26 | |
---|
| 27 | /* |
---|
| 28 | * Debugger for RTEMS. |
---|
| 29 | */ |
---|
| 30 | |
---|
| 31 | #ifndef _RTEMS_DEBUGGER_SERVER_h |
---|
| 32 | #define _RTEMS_DEBUGGER_SERVER_h |
---|
| 33 | |
---|
| 34 | #include <rtems.h> |
---|
| 35 | #include <rtems/printer.h> |
---|
| 36 | |
---|
| 37 | #include <rtems/rtems-debugger.h> |
---|
| 38 | |
---|
| 39 | #ifdef __cplusplus |
---|
| 40 | extern "C" { |
---|
| 41 | #endif /* __cplusplus */ |
---|
| 42 | |
---|
| 43 | /** |
---|
| 44 | * Debugger NUMOF macro. |
---|
| 45 | */ |
---|
| 46 | #define RTEMS_DEBUGGER_NUMOF(_d) (sizeof(_d) / sizeof(_d[0])) |
---|
| 47 | |
---|
| 48 | /** |
---|
| 49 | * Machine specific size. Here for 64bit support. |
---|
| 50 | */ |
---|
| 51 | #define DB_UINT uint32_t |
---|
| 52 | |
---|
| 53 | /* |
---|
| 54 | * Debugger signals. |
---|
| 55 | */ |
---|
| 56 | #define RTEMS_DEBUGGER_SIGNAL_HUP 1 /* Hangup */ |
---|
| 57 | #define RTEMS_DEBUGGER_SIGNAL_INT 2 /* Interrupt */ |
---|
| 58 | #define RTEMS_DEBUGGER_SIGNAL_QUIT 3 /* Quit */ |
---|
| 59 | #define RTEMS_DEBUGGER_SIGNAL_ILL 4 /* Illegal instruction */ |
---|
| 60 | #define RTEMS_DEBUGGER_SIGNAL_TRAP 5 /* Trace/breakpoint trap */ |
---|
| 61 | #define RTEMS_DEBUGGER_SIGNAL_ABRT 6 /* Aborted */ |
---|
| 62 | #define RTEMS_DEBUGGER_SIGNAL_EMT 7 /* Emulation trap */ |
---|
| 63 | #define RTEMS_DEBUGGER_SIGNAL_FPE 8 /* Arithmetic exception */ |
---|
| 64 | #define RTEMS_DEBUGGER_SIGNAL_KILL 9 /* Killed */ |
---|
| 65 | #define RTEMS_DEBUGGER_SIGNAL_BUS 10 /* Bus error */ |
---|
| 66 | #define RTEMS_DEBUGGER_SIGNAL_SEGV 11 /* Segmentation fault */ |
---|
| 67 | #define RTEMS_DEBUGGER_SIGNAL_SYS 12 /* Bad system call */ |
---|
| 68 | #define RTEMS_DEBUGGER_SIGNAL_PIPE 13 /* Broken pipe */ |
---|
| 69 | #define RTEMS_DEBUGGER_SIGNAL_ALRM 14 /* Alarm clock */ |
---|
| 70 | #define RTEMS_DEBUGGER_SIGNAL_TERM 15 /* Terminated */ |
---|
| 71 | #define RTEMS_DEBUGGER_SIGNAL_URG 16 /* Urgent I/O condition */ |
---|
| 72 | #define RTEMS_DEBUGGER_SIGNAL_STOP 17 /* Stopped (signal) */ |
---|
| 73 | #define RTEMS_DEBUGGER_SIGNAL_TSTP 18 /* Stopped (user) */ |
---|
| 74 | #define RTEMS_DEBUGGER_SIGNAL_CONT 19 /* Continued */ |
---|
| 75 | |
---|
| 76 | /** |
---|
| 77 | * Timeout period for the Debugger task to stop in usecs. |
---|
| 78 | */ |
---|
| 79 | #define RTEMS_DEBUGGER_TIMEOUT_STOP (5 * 1000 * 1000) |
---|
| 80 | |
---|
| 81 | /** |
---|
| 82 | * Debugger poll wait timeout in usecs. |
---|
| 83 | */ |
---|
| 84 | #define RTEMS_DEBUGGER_POLL_WAIT (10000) |
---|
| 85 | |
---|
| 86 | /** |
---|
| 87 | * Debugger task stack size. |
---|
| 88 | */ |
---|
| 89 | #define RTEMS_DEBUGGER_STACKSIZE (16 * 1024) |
---|
| 90 | |
---|
| 91 | /** |
---|
| 92 | * Debugger output buffer size. |
---|
| 93 | */ |
---|
| 94 | #define RTEMS_DEBUGGER_BUFFER_SIZE (4 * 1024) |
---|
| 95 | |
---|
| 96 | /** |
---|
| 97 | * Debugger flags. |
---|
| 98 | */ |
---|
| 99 | #define RTEMS_DEBUGGER_FLAG_VERBOSE (1 << 0) |
---|
| 100 | #define RTEMS_DEBUGGER_FLAG_RESET (1 << 1) |
---|
| 101 | #define RTEMS_DEBUGGER_FLAG_NON_STOP (1 << 2) |
---|
| 102 | #define RTEMS_DEBUGGER_FLAG_VCONT (1 << 3) |
---|
| 103 | #define RTEMS_DEBUGGER_FLAG_MULTIPROCESS (1 << 4) |
---|
[b2353ed9] | 104 | #define RTEMS_DEBUGGER_FLAG_VERBOSE_LOCK (1 << 5) |
---|
| 105 | #define RTEMS_DEBUGGER_FLAG_VERBOSE_CMDS (1 << 6) |
---|
[a0d4e99] | 106 | |
---|
| 107 | /** |
---|
| 108 | * Forward decl for the threads and targets. |
---|
| 109 | */ |
---|
| 110 | typedef struct rtems_debugger_remote rtems_debugger_remote; |
---|
| 111 | typedef struct rtems_debugger_threads rtems_debugger_threads; |
---|
| 112 | typedef struct rtems_debugger_target rtems_debugger_target; |
---|
| 113 | |
---|
[b2353ed9] | 114 | /** |
---|
| 115 | * Local types for the RTEMS-X interface. |
---|
| 116 | */ |
---|
| 117 | typedef struct _Condition_Control rtems_rx_cond; |
---|
| 118 | typedef struct _Mutex_recursive_Control rtems_rx_mutex; |
---|
| 119 | |
---|
[a0d4e99] | 120 | /** |
---|
| 121 | * Debugger data. |
---|
| 122 | */ |
---|
| 123 | typedef struct |
---|
| 124 | { |
---|
| 125 | int port; |
---|
| 126 | int timeout; |
---|
| 127 | rtems_task_priority priority; |
---|
[b2353ed9] | 128 | rtems_rx_mutex lock; |
---|
[a0d4e99] | 129 | rtems_debugger_remote* remote; |
---|
| 130 | rtems_id server_task; |
---|
[b2353ed9] | 131 | rtems_rx_cond server_cond; |
---|
[a0d4e99] | 132 | volatile bool server_running; |
---|
| 133 | volatile bool server_finished; |
---|
| 134 | rtems_id events_task; |
---|
| 135 | volatile bool events_running; |
---|
| 136 | volatile bool events_finished; |
---|
| 137 | rtems_printer printer; |
---|
| 138 | uint32_t flags; |
---|
| 139 | pid_t pid; |
---|
| 140 | bool remote_debug; |
---|
| 141 | bool ack_pending; |
---|
| 142 | size_t output_level; |
---|
| 143 | uint8_t input[RTEMS_DEBUGGER_BUFFER_SIZE]; |
---|
| 144 | uint8_t output[RTEMS_DEBUGGER_BUFFER_SIZE]; |
---|
| 145 | rtems_debugger_threads* threads; |
---|
[b2353ed9] | 146 | rtems_chain_control exception_threads; |
---|
[a0d4e99] | 147 | int signal; |
---|
| 148 | rtems_debugger_target* target; |
---|
| 149 | } rtems_debugger_server; |
---|
| 150 | |
---|
| 151 | /** |
---|
| 152 | * Debugger global variable. |
---|
| 153 | */ |
---|
| 154 | extern rtems_debugger_server* rtems_debugger; |
---|
| 155 | |
---|
| 156 | /** |
---|
| 157 | * Debug server printer. |
---|
| 158 | */ |
---|
| 159 | extern int rtems_debugger_printf(const char* format, ...) RTEMS_PRINTFLIKE(1, 2); |
---|
[b2353ed9] | 160 | extern int rtems_debugger_clean_printf(const char* format, ...) RTEMS_PRINTFLIKE(1, 2); |
---|
| 161 | extern void rtems_debugger_printk_lock(rtems_interrupt_lock_context* lock_context); |
---|
| 162 | extern void rtems_debugger_printk_unlock(rtems_interrupt_lock_context* lock_context); |
---|
[a0d4e99] | 163 | |
---|
| 164 | /** |
---|
| 165 | * Lock the Debugger. |
---|
| 166 | */ |
---|
[b2353ed9] | 167 | extern void rtems_debugger_lock(void); |
---|
[a0d4e99] | 168 | |
---|
| 169 | /** |
---|
| 170 | * Unlock the Debugger. |
---|
| 171 | */ |
---|
[b2353ed9] | 172 | extern void rtems_debugger_unlock(void); |
---|
[a0d4e99] | 173 | |
---|
| 174 | /** |
---|
| 175 | * Is the server still running? |
---|
| 176 | */ |
---|
[b2353ed9] | 177 | extern bool rtems_debugger_server_running(void); |
---|
[a0d4e99] | 178 | |
---|
| 179 | /** |
---|
| 180 | * Get the remote handle from the debugger. |
---|
| 181 | */ |
---|
[b2353ed9] | 182 | extern rtems_debugger_remote* rtems_debugger_remote_handle(void); |
---|
[a0d4e99] | 183 | |
---|
| 184 | /** |
---|
| 185 | * Is the debugger connected? |
---|
| 186 | */ |
---|
[b2353ed9] | 187 | extern bool rtems_debugger_connected(void); |
---|
[a0d4e99] | 188 | |
---|
| 189 | /** |
---|
| 190 | * Is the debugger events thread runnins? |
---|
| 191 | */ |
---|
[b2353ed9] | 192 | extern bool rtems_debugger_server_events_running(void); |
---|
[a0d4e99] | 193 | |
---|
| 194 | /** |
---|
[b2353ed9] | 195 | * Signal events thread in the debug server to run. |
---|
[a0d4e99] | 196 | */ |
---|
[b2353ed9] | 197 | extern void rtems_debugger_server_events_signal(void); |
---|
[a0d4e99] | 198 | |
---|
| 199 | /** |
---|
| 200 | * Check if verbose is on. |
---|
| 201 | */ |
---|
| 202 | extern bool rtems_debugger_verbose(void); |
---|
| 203 | |
---|
| 204 | /** |
---|
| 205 | * Check a flag. |
---|
| 206 | */ |
---|
| 207 | static inline bool rtems_debugger_server_flag(uint32_t mask) |
---|
| 208 | { |
---|
| 209 | return (rtems_debugger->flags & mask) != 0; |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | #ifdef __cplusplus |
---|
| 213 | } |
---|
| 214 | #endif /* __cplusplus */ |
---|
| 215 | |
---|
| 216 | |
---|
| 217 | #endif |
---|