Back to home page

LXR

 
 

    


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

0001 /*
0002  * Copyright (c) 2016-2017 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_THREADS_h
0032 #define _RTEMS_DEBUGGER_THREADS_h
0033 
0034 #include <rtems/debugger/rtems-debugger-server.h>
0035 
0036 #include <rtems/score/thread.h>
0037 
0038 #include "rtems-debugger-block.h"
0039 
0040 #ifdef __cplusplus
0041 extern "C" {
0042 #endif /* __cplusplus */
0043 
0044 /**
0045  * Debugger thread name size, fixed size. ASCIIZ format.
0046  */
0047 #define RTEMS_DEBUGGER_THREAD_NAME_SIZE (5)
0048 
0049 /**
0050  * Debugger thread allocation block size.
0051  */
0052 #define RTEMS_DEBUGGER_THREAD_BLOCK_SIZE (32)
0053 
0054 /**
0055  * Debugger thread flags.
0056  */
0057 #define RTEMS_DEBUGGER_THREAD_FLAG_EXCEPTION      (1 << 0)
0058 #define RTEMS_DEBUGGER_THREAD_FLAG_REG_VALID      (1 << 1)
0059 #define RTEMS_DEBUGGER_THREAD_FLAG_REG_DIRTY      (1 << 2)
0060 #define RTEMS_DEBUGGER_THREAD_FLAG_CONTINUE       (1 << 3)
0061 #define RTEMS_DEBUGGER_THREAD_FLAG_STEP           (1 << 4)
0062 #define RTEMS_DEBUGGER_THREAD_FLAG_STEPPING       (1 << 5)
0063 #define RTEMS_DEBUGGER_THREAD_FLAG_INTS_DISABLED  (1 << 6)
0064 /* Target specific flags for use by the target backend. */
0065 #define RTEMS_DEBUGGER_THREAD_FLAG_TARGET_BASE    (24)
0066 #define RTEMS_DEBUGGER_THREAD_FLAG_TARGET_MASK    (0xff << RTEMS_DEBUGGER_THREAD_FLAG_TARGET_BASE)
0067 
0068 /**
0069  * Resume this thread.
0070  */
0071 #define RTEMS_DEBUGGER_THREAD_FLAG_RESUME \
0072   (RTEMS_DEBUGGER_THREAD_FLAG_CONTINUE | \
0073    RTEMS_DEBUGGER_THREAD_FLAG_STEP | \
0074    RTEMS_DEBUGGER_THREAD_FLAG_STEPPING)
0075 
0076 /**
0077  * Step an instruction.
0078  */
0079 #define RTEMS_DEBUGGER_THREAD_FLAG_STEP_INSTR \
0080   (RTEMS_DEBUGGER_THREAD_FLAG_STEP | \
0081    RTEMS_DEBUGGER_THREAD_FLAG_STEPPING)
0082 
0083 /**
0084  * Debugger thread.
0085  */
0086 typedef struct rtems_debugger_thread
0087 {
0088   uint32_t        flags;
0089   const char      name[RTEMS_DEBUGGER_THREAD_NAME_SIZE];
0090   Thread_Control* tcb;
0091   rtems_id        id;
0092   int             cpu;
0093   uint8_t*        registers;
0094   int             signal;
0095   void*           frame;
0096 } rtems_debugger_thread;
0097 
0098 /**
0099  * Debugger stepping thread. This is a thread that steps while inside an
0100  * address range.
0101  */
0102 typedef struct rtems_debugger_thread_stepper
0103 {
0104   rtems_debugger_thread* thread;
0105   uintptr_t              start;
0106   uintptr_t              end;
0107 } rtems_debugger_thread_stepper;
0108 
0109 /**
0110  * Debugger thread control.
0111  */
0112 struct rtems_debugger_threads
0113 {
0114   rtems_debugger_block current;       /**< The threads currently available. */
0115   rtems_debugger_block registers;     /**< The threads that have stopped. */
0116   rtems_debugger_block excludes;      /**< The threads we cannot touch. */
0117   rtems_debugger_block stopped;       /**< The threads that have stopped. */
0118   rtems_debugger_block steppers;      /**< The threads that are stepping. */
0119   size_t               next;          /**< An iterator. */
0120   int                  selector_gen;  /**< General thread selector. */
0121   int                  selector_cont; /**< Continue thread selector. */
0122 };
0123 
0124 /**
0125  * Create the thread support.
0126  */
0127 extern int rtems_debugger_thread_create(void);
0128 
0129 /**
0130  * Destroy the thread support.
0131  */
0132 extern int rtems_debugger_thread_destroy(void);
0133 
0134 /**
0135  * Find the index in the thread table for the ID.
0136  */
0137 extern int rtems_debugger_thread_find_index(rtems_id id);
0138 
0139 /**
0140  * Suspend the system.
0141  */
0142 extern int rtems_debugger_thread_system_suspend(void);
0143 
0144 /**
0145  * Resume the system.
0146  */
0147 extern int rtems_debugger_thread_system_resume(bool detaching);
0148 
0149 /**
0150  * Continue all threads.
0151  */
0152 extern int rtems_debugger_thread_continue_all(void);
0153 
0154 /**
0155  * Continue a thread.
0156  */
0157 extern int rtems_debugger_thread_continue(rtems_debugger_thread* thread);
0158 
0159 /**
0160  * Step a thread.
0161  */
0162 extern int rtems_debugger_thread_step(rtems_debugger_thread* thread);
0163 
0164 /**
0165  * Thread is stepping so record the details.
0166  */
0167 extern int rtems_debugger_thread_stepping(rtems_debugger_thread* thread,
0168                                           uintptr_t              start,
0169                                           uintptr_t              end);
0170 
0171 /**
0172  * Thread's PC in the stepping range? Returns the stepper is in range else
0173  * NULL.
0174  */
0175 extern const rtems_debugger_thread_stepper*
0176 rtems_debugger_thread_is_stepping(rtems_id id, uintptr_t pc);
0177 
0178 /**
0179  * Return the thread's current priority/
0180  */
0181 extern int rtems_debugger_thread_current_priority(rtems_debugger_thread* thread);
0182 
0183 /**
0184  * Return the thread's real priority.
0185  */
0186 extern int rtems_debugger_thread_real_priority(rtems_debugger_thread* thread);
0187 
0188 /**
0189  * Return the thread's state.
0190  */
0191 extern int rtems_debugger_thread_state(rtems_debugger_thread* thread);
0192 
0193 /**
0194  * Return the thread's state.
0195  */
0196 //extern bool rtems_debugger_thread_state_debugger(rtems_debugger_thread* thread);
0197 
0198 /**
0199  * Return a string of the thread's state.
0200  */
0201 extern int rtems_debugger_thread_state_str(rtems_debugger_thread* thread,
0202                                            char*                  buffer,
0203                                            size_t                 size);
0204 
0205 /**
0206  * Return the thread's stack size.
0207  */
0208 extern unsigned long rtems_debugger_thread_stack_size(rtems_debugger_thread* thread);
0209 
0210 /**
0211  * Return the thread's stack area address.
0212  */
0213 extern void* rtems_debugger_thread_stack_area(rtems_debugger_thread* thread);
0214 
0215 /**
0216  * Check a thread's flag and return true if any of the bits in the mask are
0217  * set.
0218  */
0219 static inline bool
0220 rtems_debugger_thread_flag(rtems_debugger_thread* thread, uint32_t mask)
0221 {
0222   return (thread->flags & mask) != 0;
0223 }
0224 
0225 /**
0226  * Get the current threads.
0227  */
0228 static inline rtems_debugger_thread*
0229 rtems_debugger_thread_current(rtems_debugger_threads* threads)
0230 {
0231   return threads->current.block;
0232 }
0233 
0234 /**
0235  * Get the registers.
0236  */
0237 static inline uint8_t*
0238 rtems_debugger_thread_registers(rtems_debugger_threads* threads)
0239 {
0240   return threads->registers.block;
0241 }
0242 
0243 /**
0244  * Get the excludes.
0245  */
0246 static inline rtems_id*
0247 rtems_debugger_thread_excludes(rtems_debugger_threads* threads)
0248 {
0249   return threads->excludes.block;
0250 }
0251 
0252 /**
0253  * Get the stopped.
0254  */
0255 static inline rtems_id*
0256 rtems_debugger_thread_stopped(rtems_debugger_threads* threads)
0257 {
0258   return threads->stopped.block;
0259 }
0260 
0261 /**
0262  * Get the steppers.
0263  */
0264 static inline rtems_debugger_thread_stepper*
0265 rtems_debugger_thread_steppers(rtems_debugger_threads* threads)
0266 {
0267   return threads->steppers.block;
0268 }
0269 
0270 #ifdef __cplusplus
0271 }
0272 #endif /* __cplusplus */
0273 
0274 #endif