gdb: Modify PC in case of invalid PC

Signed-off-by: Sachin Parekh <sachin.parekh@espressif.com>
This commit is contained in:
Sachin Parekh 2020-04-17 19:06:26 +05:30
parent e30185c166
commit 46d914ff45
4 changed files with 28 additions and 3 deletions

View file

@ -142,6 +142,7 @@ SECTIONS
. = 0x3C0;
KEEP(*(.DoubleExceptionVector.text));
. = 0x400;
_invalid_pc_placeholder = ABSOLUTE(.);
*(.*Vector.literal)
*(.UserEnter.literal);

View file

@ -142,6 +142,7 @@ SECTIONS
. = 0x3C0;
KEEP(*(.DoubleExceptionVector.text));
. = 0x400;
_invalid_pc_placeholder = ABSOLUTE(.);
*(.*Vector.literal)
*(.UserEnter.literal);

View file

@ -24,6 +24,8 @@
#warning "gdbstub_xtensa: revisit the implementation for Call0 ABI"
#endif
extern int _invalid_pc_placeholder;
static void init_regfile(esp_gdbstub_gdb_regfile_t *dst)
{
memset(dst, 0, sizeof(*dst));
@ -47,7 +49,15 @@ void esp_gdbstub_frame_to_regfile(const esp_gdbstub_frame_t *frame, esp_gdbstub_
{
init_regfile(dst);
const uint32_t *a_regs = (const uint32_t *) &frame->a0;
dst->pc = (frame->pc & 0x3fffffffU) | 0x40000000U;
if (!(esp_ptr_executable((frame->pc & 0x3fffffffU) | 0x40000000U) && (frame->pc & 0xC0000000U))) {
/* Xtensa ABI sets the 2 MSBs of the PC according to the windowed call size
* Incase the PC is invalid, GDB will fail to translate addresses to function names
* Hence replacing the PC to a placeholder address in case of invalid PC
*/
dst->pc = (uint32_t)&_invalid_pc_placeholder;
} else {
dst->pc = (frame->pc & 0x3fffffffU) | 0x40000000U;
}
for (int i = 0; i < 16; i++) {
dst->a[i] = a_regs[i];
@ -73,7 +83,11 @@ static void solicited_frame_to_regfile(const XtSolFrame *frame, esp_gdbstub_gdb_
{
init_regfile(dst);
const uint32_t *a_regs = (const uint32_t *) &frame->a0;
dst->pc = (frame->pc & 0x3fffffffU) | 0x40000000U;
if (!(esp_ptr_executable((frame->pc & 0x3fffffffU) | 0x40000000U) && (frame->pc & 0xC0000000U))) {
dst->pc = (uint32_t)&_invalid_pc_placeholder;
} else {
dst->pc = (frame->pc & 0x3fffffffU) | 0x40000000U;
}
/* only 4 registers saved in the solicited frame */
for (int i = 0; i < 4; i++) {

View file

@ -51,7 +51,9 @@
#include "panic_internal.h"
extern void esp_panic_handler(panic_info_t *);
extern int _invalid_pc_placeholder;
extern void esp_panic_handler(panic_info_t*);
static wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
@ -512,6 +514,13 @@ static void panic_handler(XtExcFrame *frame, bool pseudo_excause)
#endif
if (esp_cpu_in_ocd_debug_mode()) {
if (!(esp_ptr_executable(cpu_ll_pc_to_ptr(frame->pc)) && (frame->pc & 0xC0000000U))) {
/* Xtensa ABI sets the 2 MSBs of the PC according to the windowed call size
* Incase the PC is invalid, GDB will fail to translate addresses to function names
* Hence replacing the PC to a placeholder address in case of invalid PC
*/
frame->pc = (uint32_t)&_invalid_pc_placeholder;
}
if (frame->exccause == PANIC_RSN_INTWDT_CPU0 ||
frame->exccause == PANIC_RSN_INTWDT_CPU1) {
wdt_hal_write_protect_disable(&wdt0_context);