Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:12

0001 /*
0002  * Copyright (c) 2016-2019 Chris Johns <chrisj@rtems.org>.
0003  * All rights reserved.
0004  *
0005  * Redistribution and use in source and binary forms, with or without
0006  * modification, are permitted provided that the following conditions
0007  * are met:
0008  * 1. Redistributions of source code must retain the above copyright
0009  *    notice, this list of conditions and the following disclaimer.
0010  * 2. Redistributions in binary form must reproduce the above copyright
0011  *    notice, this list of conditions and the following disclaimer in the
0012  *    documentation and/or other materials provided with the distribution.
0013  *
0014  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
0015  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0016  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0017  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
0018  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0019  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0020  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0021  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0022  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0023  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0024  * SUCH DAMAGE.
0025  */
0026 
0027 /*
0028  * Debugger for RTEMS.
0029  */
0030 
0031 #ifndef _RTEMS_DEBUGGER_SERVER_h
0032 #define _RTEMS_DEBUGGER_SERVER_h
0033 
0034 #include <rtems.h>
0035 #include <rtems/printer.h>
0036 
0037 #include <rtems/rtems-debugger.h>
0038 
0039 #ifdef __cplusplus
0040 extern "C" {
0041 #endif /* __cplusplus */
0042 
0043 /**
0044  * Debugger NUMOF macro.
0045  */
0046 #define RTEMS_DEBUGGER_NUMOF(_d) (sizeof(_d) / sizeof(_d[0]))
0047 
0048 /**
0049  * Machine specific size. Here for 64bit support.
0050  */
0051 #define DB_UINT uint32_t
0052 
0053 /*
0054  * Debugger signals.
0055  */
0056 #define RTEMS_DEBUGGER_SIGNAL_HUP   1     /* Hangup */
0057 #define RTEMS_DEBUGGER_SIGNAL_INT   2     /* Interrupt */
0058 #define RTEMS_DEBUGGER_SIGNAL_QUIT  3     /* Quit */
0059 #define RTEMS_DEBUGGER_SIGNAL_ILL   4     /* Illegal instruction */
0060 #define RTEMS_DEBUGGER_SIGNAL_TRAP  5     /* Trace/breakpoint trap */
0061 #define RTEMS_DEBUGGER_SIGNAL_ABRT  6     /* Aborted */
0062 #define RTEMS_DEBUGGER_SIGNAL_EMT   7     /* Emulation trap */
0063 #define RTEMS_DEBUGGER_SIGNAL_FPE   8     /* Arithmetic exception */
0064 #define RTEMS_DEBUGGER_SIGNAL_KILL  9     /* Killed */
0065 #define RTEMS_DEBUGGER_SIGNAL_BUS   10    /* Bus error */
0066 #define RTEMS_DEBUGGER_SIGNAL_SEGV  11    /* Segmentation fault */
0067 #define RTEMS_DEBUGGER_SIGNAL_SYS   12    /* Bad system call */
0068 #define RTEMS_DEBUGGER_SIGNAL_PIPE  13    /* Broken pipe */
0069 #define RTEMS_DEBUGGER_SIGNAL_ALRM  14    /* Alarm clock */
0070 #define RTEMS_DEBUGGER_SIGNAL_TERM  15    /* Terminated */
0071 #define RTEMS_DEBUGGER_SIGNAL_URG   16    /* Urgent I/O condition */
0072 #define RTEMS_DEBUGGER_SIGNAL_STOP  17    /* Stopped (signal) */
0073 #define RTEMS_DEBUGGER_SIGNAL_TSTP  18    /* Stopped (user) */
0074 #define RTEMS_DEBUGGER_SIGNAL_CONT  19    /* Continued */
0075 
0076 /**
0077  * Timeout period for the Debugger task to stop in usecs.
0078  */
0079 #define RTEMS_DEBUGGER_TIMEOUT_STOP (5 * 1000 * 1000)
0080 
0081 /**
0082  * Debugger poll wait timeout in usecs.
0083  */
0084 #define RTEMS_DEBUGGER_POLL_WAIT (10000)
0085 
0086 /**
0087  * Debugger task stack size.
0088  */
0089 #define RTEMS_DEBUGGER_STACKSIZE (16 * 1024)
0090 
0091 /**
0092  * Debugger output buffer size.
0093  */
0094 #define RTEMS_DEBUGGER_BUFFER_SIZE (4 * 1024)
0095 
0096 /**
0097  * Debugger flags.
0098  */
0099 #define RTEMS_DEBUGGER_FLAG_VERBOSE      (1 << 0)
0100 #define RTEMS_DEBUGGER_FLAG_RESET        (1 << 1)
0101 #define RTEMS_DEBUGGER_FLAG_NON_STOP     (1 << 2)
0102 #define RTEMS_DEBUGGER_FLAG_VCONT        (1 << 3)
0103 #define RTEMS_DEBUGGER_FLAG_MULTIPROCESS (1 << 4)
0104 #define RTEMS_DEBUGGER_FLAG_VERBOSE_LOCK (1 << 5)
0105 #define RTEMS_DEBUGGER_FLAG_VERBOSE_CMDS (1 << 6)
0106 #define RTEMS_DEBUGGER_FLAG_BREAK_WAITER (1 << 7)
0107 
0108 /**
0109  * Forward decl for the threads and targets.
0110  */
0111 typedef struct rtems_debugger_remote  rtems_debugger_remote;
0112 typedef struct rtems_debugger_threads rtems_debugger_threads;
0113 typedef struct rtems_debugger_target  rtems_debugger_target;
0114 
0115 /**
0116  * Local types for the RTEMS-X interface.
0117  */
0118 typedef struct _Condition_Control       rtems_rx_cond;
0119 typedef struct _Mutex_recursive_Control rtems_rx_mutex;
0120 
0121 /**
0122  * Debugger data.
0123  */
0124 typedef struct
0125 {
0126   int                     port;
0127   int                     timeout;
0128   rtems_task_priority     priority;
0129   rtems_rx_mutex          lock;
0130   rtems_debugger_remote*  remote;
0131   rtems_id                server_task;
0132   rtems_rx_cond           server_cond;
0133   volatile bool           server_running;
0134   volatile bool           server_finished;
0135   rtems_id                events_task;
0136   volatile bool           events_running;
0137   volatile bool           events_finished;
0138   rtems_printer           printer;
0139   uint32_t                flags;
0140   pid_t                   pid;
0141   bool                    remote_debug;
0142   bool                    ack_pending;
0143   size_t                  output_level;
0144   uint8_t                 input[RTEMS_DEBUGGER_BUFFER_SIZE];
0145   uint8_t                 output[RTEMS_DEBUGGER_BUFFER_SIZE];
0146   rtems_debugger_threads* threads;
0147   rtems_chain_control     exception_threads;
0148   int                     signal;
0149   rtems_debugger_target*  target;
0150 } rtems_debugger_server;
0151 
0152 /**
0153  * Debugger global variable.
0154  */
0155 extern rtems_debugger_server* rtems_debugger;
0156 
0157 /**
0158  * Debug server printer.
0159  */
0160 extern int rtems_debugger_printf(const char* format, ...) RTEMS_PRINTFLIKE(1, 2);
0161 extern int rtems_debugger_clean_printf(const char* format, ...) RTEMS_PRINTFLIKE(1, 2);
0162 extern void rtems_debugger_printk_lock(rtems_interrupt_lock_context* lock_context);
0163 extern void rtems_debugger_printk_unlock(rtems_interrupt_lock_context* lock_context);
0164 
0165 /**
0166  * Lock the Debugger.
0167  */
0168 extern void rtems_debugger_lock(void);
0169 
0170 /**
0171  * Unlock the Debugger.
0172  */
0173 extern void rtems_debugger_unlock(void);
0174 
0175 /**
0176  * Is the server still running?
0177  */
0178 extern bool rtems_debugger_server_running(void);
0179 
0180 /**
0181  * Signel a server crash.
0182  */
0183 extern void rtems_debugger_server_crash(void);
0184 
0185 /**
0186  * Get the remote handle from the debugger.
0187  */
0188 extern rtems_debugger_remote* rtems_debugger_remote_handle(void);
0189 
0190 /**
0191  * Is the debugger connected?
0192  */
0193 extern bool rtems_debugger_connected(void);
0194 
0195 /**
0196  * Is the debugger events thread runnins?
0197  */
0198 extern bool rtems_debugger_server_events_running(void);
0199 
0200 /**
0201  * Signal events thread in the debug server to run.
0202  */
0203 extern void rtems_debugger_server_events_signal(void);
0204 
0205 /**
0206  * Check if verbose is on.
0207  */
0208 extern bool rtems_debugger_verbose(void);
0209 
0210 /**
0211  * Check a flag.
0212  */
0213 static inline bool rtems_debugger_server_flag(uint32_t mask)
0214 {
0215   return (rtems_debugger->flags & mask) != 0;
0216 }
0217 
0218 #ifdef __cplusplus
0219 }
0220 #endif /* __cplusplus */
0221 
0222 
0223 #endif