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 #define gdb_do_break() cpu_hal_break()
62 #elif defined(ARCH_RP2040)
63 #define gdb_do_break() __asm__("bkpt #0")
64 #endif
65 #else
66 #define gdb_do_break() \
67  do { \
68  } while(0)
69 #endif
70 
71 typedef enum {
75 } GdbState;
76 
80 GdbState gdb_present(void);
81 
86 void gdb_on_attach(bool attached);
87 
92 void gdb_detach();
93 
94 /*
95  * @brief Called by framework on unexpected system reset
96  */
97 void debug_crash_callback(const struct rst_info* rst_info, uint32_t stack, uint32_t stack_end);
98 
104 void debug_print_stack(uint32_t start, uint32_t end);
105 
106 #ifdef __cplusplus
107 } // extern "C"
108 #endif
109 
void gdb_init(void)
Initialise GDB stub, if present.
void gdb_enable(bool state)
Dynamically enable/disable GDB stub.
void gdb_on_attach(bool attached)
Called from task queue when GDB attachment status changes.
void debug_print_stack(uint32_t start, uint32_t end)
Send a stack dump to debug output.
void gdb_detach()
Detach from GDB, if attached.
@ eGDB_Attached
Definition: gdb_hooks.h:74
GdbState
Definition: gdb_hooks.h:71
GdbState gdb_present(void)
Check if GDB stub is present.
void debug_crash_callback(const struct rst_info *rst_info, uint32_t stack, uint32_t stack_end)
@ eGDB_Detached
Definition: gdb_hooks.h:73
@ eGDB_NotPresent
Definition: gdb_hooks.h:72