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 #define gdb_do_break() __asm__("int $0x03")
58 #elif defined(ARCH_ESP8266)
59 #define gdb_do_break() __asm__("break 0,0")
60 #elif defined(ARCH_ESP32)
61 #if ESP_IDF_VERSION_MAJOR < 5
62 #define gdb_do_break() cpu_hal_break()
63 #else
64 #define gdb_do_break() esp_cpu_dbgr_break()
65 #endif
66 #elif defined(ARCH_RP2040)
67 #define gdb_do_break() __asm__("bkpt #0")
68 #endif
69 #else
70 #define gdb_do_break() \
71  do { \
72  } while(0)
73 #endif
74 
75 typedef enum {
79 } GdbState;
80 
85 
90 void gdb_on_attach(bool attached);
91 
96 void gdb_detach();
97 
98 /*
99  * @brief Called by framework on unexpected system reset
100  */
101 void debug_crash_callback(const struct rst_info* rst_info, uint32_t stack, uint32_t stack_end);
102 
108 void debug_print_stack(uint32_t start, uint32_t end);
109 
110 #ifdef __cplusplus
111 } // extern "C"
112 #endif
113 
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:75
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:77
@ eGDB_Attached
Definition: gdb_hooks.h:78
@ eGDB_NotPresent
Definition: gdb_hooks.h:76