gdb_hooks.h
Go to the documentation of this file.
1 /*
2  gdb_hooks.h - Hooks for GDB Stub library
3  Copyright (c) 2018 Ivan Grokhotkov. All right reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 #pragma once
21 
22 #include <esp_systemapi.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
36 void gdb_init(void);
37 
50 void gdb_enable(bool state);
51 
55 #ifdef ENABLE_GDB
56 #ifdef ARCH_HOST
57 #if defined(__arm__) || defined(__aarch64__)
58 #define gdb_do_break() __builtin_debugtrap()
59 #else
60 #define gdb_do_break() __asm__("int $0x03")
61 #endif
62 #elif defined(ARCH_ESP8266)
63 #define gdb_do_break() __asm__("break 0,0")
64 #elif defined(ARCH_ESP32)
65 #if ESP_IDF_VERSION_MAJOR < 5
66 #define gdb_do_break() cpu_hal_break()
67 #else
68 #define gdb_do_break() esp_cpu_dbgr_break()
69 #endif
70 #elif defined(ARCH_RP2040)
71 #define gdb_do_break() __asm__("bkpt #0")
72 #endif
73 #else
74 #define gdb_do_break() \
75  do { \
76  } while(0)
77 #endif
78 
79 typedef enum {
83 } GdbState;
84 
89 
94 void gdb_on_attach(bool attached);
95 
100 void gdb_detach();
101 
102 /*
103  * @brief Called by framework on unexpected system reset
104  */
105 void debug_crash_callback(const struct rst_info* rst_info, uint32_t stack, uint32_t stack_end);
106 
112 void debug_print_stack(uint32_t start, uint32_t end);
113 
114 #ifdef __cplusplus
115 } // extern "C"
116 #endif
117 
void gdb_enable(bool state)
Dynamically enable/disable GDB stub.
void debug_crash_callback(const struct rst_info *rst_info, uint32_t stack, uint32_t stack_end)
void debug_print_stack(uint32_t start, uint32_t end)
Send a stack dump to debug output.
void gdb_init(void)
Initialise GDB stub, if present.
void gdb_detach()
Detach from GDB, if attached.
GdbState
Definition: gdb_hooks.h:79
void gdb_on_attach(bool attached)
Called from task queue when GDB attachment status changes.
GdbState gdb_present(void)
Check if GDB stub is present.
@ eGDB_Detached
Definition: gdb_hooks.h:81
@ eGDB_Attached
Definition: gdb_hooks.h:82
@ eGDB_NotPresent
Definition: gdb_hooks.h:80
void end()
Stop USB operation.