2021-06-07 15:54:09 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2019-06-13 12:43:49 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2021-04-15 03:52:09 -04:00
|
|
|
#include "esp_gdbstub_arch.h"
|
2019-06-13 12:43:49 -04:00
|
|
|
#include "sdkconfig.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_ESP_GDBSTUB_SUPPORT_TASKS
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
2023-09-21 05:17:49 -04:00
|
|
|
#include "esp_private/freertos_debug.h"
|
2019-06-13 12:43:49 -04:00
|
|
|
#endif // CONFIG_ESP_GDBSTUB_SUPPORT_TASKS
|
|
|
|
|
|
|
|
/* Internal error codes used by the routines that parse the incoming gdb packet */
|
|
|
|
#define GDBSTUB_ST_ENDPACKET -1
|
|
|
|
#define GDBSTUB_ST_ERR -2
|
|
|
|
#define GDBSTUB_ST_OK -3
|
2021-04-15 03:52:09 -04:00
|
|
|
#define GDBSTUB_ST_CONT -4
|
2019-06-13 12:43:49 -04:00
|
|
|
|
|
|
|
/* Special task index values */
|
|
|
|
#define GDBSTUB_CUR_TASK_INDEX_UNKNOWN -1
|
|
|
|
|
|
|
|
#ifndef GDBSTUB_CMD_BUFLEN
|
|
|
|
#define GDBSTUB_CMD_BUFLEN 512
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_ESP_GDBSTUB_SUPPORT_TASKS
|
|
|
|
typedef enum {
|
|
|
|
GDBSTUB_NOT_STARTED,
|
|
|
|
GDBSTUB_STARTED,
|
|
|
|
GDBSTUB_TASK_SUPPORT_DISABLED
|
|
|
|
} esp_gdbstub_state_t;
|
|
|
|
|
|
|
|
#define GDBSTUB_TASKS_NUM CONFIG_ESP_GDBSTUB_MAX_TASKS
|
|
|
|
|
|
|
|
#endif // CONFIG_ESP_GDBSTUB_SUPPORT_TASKS
|
|
|
|
|
|
|
|
/* gdbstub temporary run-time data, stored in .bss to reduce stack usage */
|
|
|
|
typedef struct {
|
|
|
|
esp_gdbstub_gdb_regfile_t regfile;
|
|
|
|
int signal;
|
|
|
|
#if CONFIG_ESP_GDBSTUB_SUPPORT_TASKS
|
|
|
|
esp_gdbstub_state_t state;
|
|
|
|
int task_count;
|
|
|
|
int paniced_task_index;
|
|
|
|
int current_task_index;
|
|
|
|
int thread_info_index; //!< index of the last task passed to qsThreadInfo
|
|
|
|
esp_gdbstub_frame_t paniced_frame;
|
|
|
|
TaskSnapshot_t tasks[GDBSTUB_TASKS_NUM]; // TODO: add an API to get snapshots one by one
|
|
|
|
#endif // CONFIG_ESP_GDBSTUB_SUPPORT_TASKS
|
|
|
|
} esp_gdbstub_scratch_t;
|
|
|
|
|
2021-06-07 15:54:09 -04:00
|
|
|
extern esp_gdbstub_scratch_t s_scratch;
|
2019-06-13 12:43:49 -04:00
|
|
|
/**** Functions provided by the architecture specific part ****/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param frame exception frame pointer
|
|
|
|
* @return the appropriate "signal" number for the given exception cause
|
|
|
|
*/
|
|
|
|
int esp_gdbstub_get_signal(const esp_gdbstub_frame_t *frame);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write registers from the exception frame to the GDB register file
|
|
|
|
* @param frame exception frame to parse
|
|
|
|
* @param dst pointer to the GDB register file
|
|
|
|
*/
|
|
|
|
void esp_gdbstub_frame_to_regfile(const esp_gdbstub_frame_t *frame, esp_gdbstub_gdb_regfile_t *dst);
|
|
|
|
|
2023-04-07 12:09:22 -04:00
|
|
|
/**
|
|
|
|
* Signal handler for debugging interrupts of the application.
|
|
|
|
*/
|
|
|
|
void esp_gdbstub_int(void *frame);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signal handler for transport protocol interrupts.
|
|
|
|
*/
|
|
|
|
void gdbstub_handle_uart_int(esp_gdbstub_frame_t *regs_frame);
|
|
|
|
|
2019-06-13 12:43:49 -04:00
|
|
|
#if CONFIG_ESP_GDBSTUB_SUPPORT_TASKS
|
|
|
|
/**
|
|
|
|
* Write registers from the saved frame of a given task to the GDB register file
|
|
|
|
* @param tcb pointer to the TCB of the task
|
|
|
|
* @param dst pointer to the GDB register file
|
|
|
|
*/
|
|
|
|
void esp_gdbstub_tcb_to_regfile(TaskHandle_t tcb, esp_gdbstub_gdb_regfile_t *dst);
|
|
|
|
#endif // CONFIG_ESP_GDBSTUB_SUPPORT_TASKS
|
|
|
|
|
|
|
|
|
2023-04-02 11:29:27 -04:00
|
|
|
/**** UART related functions ****/
|
2019-06-13 12:43:49 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Receive a byte from the GDB client. Blocks until a byte is available.
|
|
|
|
* @return received byte
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
int esp_gdbstub_getchar(void);
|
2019-06-13 12:43:49 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a byte to the GDB client
|
|
|
|
* @param c byte to send
|
|
|
|
*/
|
|
|
|
void esp_gdbstub_putchar(int c);
|
|
|
|
|
2021-04-28 04:38:24 -04:00
|
|
|
/**
|
|
|
|
* Make sure all bytes sent using putchar() end up at the host.
|
|
|
|
* (Usually stubbed for UART, but can be useful for other channels)
|
|
|
|
*/
|
|
|
|
void esp_gdbstub_flush(void);
|
2019-06-13 12:43:49 -04:00
|
|
|
|
2023-04-07 12:09:22 -04:00
|
|
|
#ifdef CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME
|
2021-04-15 03:52:09 -04:00
|
|
|
/**
|
|
|
|
* Read a data from fifo and detect start symbol
|
|
|
|
* @return 1 if break symbol was detected, or 0 if not
|
|
|
|
*/
|
|
|
|
int esp_gdbstub_getfifo(void);
|
2023-04-07 12:09:22 -04:00
|
|
|
#endif // CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME
|
2021-04-15 03:52:09 -04:00
|
|
|
|
2019-06-13 12:43:49 -04:00
|
|
|
/**** GDB packet related functions ****/
|
|
|
|
|
|
|
|
/** Begin a packet */
|
2019-07-16 05:33:30 -04:00
|
|
|
void esp_gdbstub_send_start(void);
|
2019-06-13 12:43:49 -04:00
|
|
|
|
|
|
|
/** Send a character as part of the packet */
|
|
|
|
void esp_gdbstub_send_char(char c);
|
|
|
|
|
|
|
|
/** Send a string as part of the packet */
|
|
|
|
void esp_gdbstub_send_str(const char *s);
|
|
|
|
|
|
|
|
/** Send a hex value as part of the packet */
|
|
|
|
void esp_gdbstub_send_hex(int val, int bits);
|
|
|
|
|
|
|
|
/** Finish sending the packet */
|
2019-07-16 05:33:30 -04:00
|
|
|
void esp_gdbstub_send_end(void);
|
2019-06-13 12:43:49 -04:00
|
|
|
|
|
|
|
/** Send a packet with a string as content */
|
2021-04-15 03:52:09 -04:00
|
|
|
void esp_gdbstub_send_str_packet(const char *str);
|
2019-06-13 12:43:49 -04:00
|
|
|
|
|
|
|
/** Get a hex value from the gdb packet */
|
|
|
|
uint32_t esp_gdbstub_gethex(const unsigned char **ptr, int bits);
|
|
|
|
|
|
|
|
/** Read, unescape, and validate the incoming GDB command */
|
|
|
|
int esp_gdbstub_read_command(unsigned char **out_cmd, size_t *out_size);
|
|
|
|
|
|
|
|
/** Handle a command received from gdb */
|
|
|
|
int esp_gdbstub_handle_command(unsigned char *cmd, int len);
|
2021-06-07 15:54:09 -04:00
|
|
|
|
|
|
|
void esp_gdbstub_init_dports(void);
|
|
|
|
void esp_gdbstub_stall_other_cpus_start(void);
|
|
|
|
void esp_gdbstub_stall_other_cpus_end(void);
|
|
|
|
|
|
|
|
void esp_gdbstub_clear_step(void);
|
2023-04-07 12:09:22 -04:00
|
|
|
void esp_gdbstub_do_step(esp_gdbstub_frame_t *regs_frame);
|
2021-06-07 15:54:09 -04:00
|
|
|
void esp_gdbstub_trigger_cpu(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a value to register in frame
|
|
|
|
* @param frame gdbstub frame
|
|
|
|
* @param reg_index register index, depends on architecture
|
|
|
|
* @param value 32 bit data value
|
|
|
|
*/
|
|
|
|
void esp_gdbstub_set_register(esp_gdbstub_frame_t *frame, uint32_t reg_index, uint32_t value);
|