Skip to content

Commit

Permalink
target/espressif: add command to disable lazy breakpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
erhankur committed Aug 16, 2024
1 parent 994e17d commit 858373d
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 19 deletions.
48 changes: 43 additions & 5 deletions src/target/espressif/esp.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ int esp_common_init(struct target *target, struct esp_common *esp,
esp->flash_brps.brps = calloc(ESP_FLASH_BREAKPOINTS_MAX_NUM, sizeof(struct esp_flash_breakpoint));
if (!esp->flash_brps.brps)
return ERROR_FAIL;
esp->breakpoint_lazy_process = true;

if (target->coreid == 0)
target_register_event_callback(esp_callback_event_handler, esp);
Expand Down Expand Up @@ -245,7 +246,7 @@ int esp_common_flash_breakpoint_add(struct target *target, struct esp_common *es
if (ret != ERROR_OK)
return ret;

if (flash_bps->ops->breakpoint_lazy_process) {
if (esp->breakpoint_lazy_process) {
flash_bps->brps[slot].action = ESP_BP_ACT_ADD;
flash_bps->brps[slot].status = ESP_BP_STAT_PEND;
esp_common_dump_bp_slot("BP-ADD(new)", flash_bps, slot);
Expand All @@ -267,7 +268,7 @@ int esp_common_flash_breakpoint_remove(struct target *target, struct esp_common
}

if (slot == ESP_FLASH_BREAKPOINTS_MAX_NUM) {
if (esp->flash_brps.ops->breakpoint_lazy_process) {
if (esp->breakpoint_lazy_process) {
/* This is not an error since breakpoints are already removed inside qxfer-thread-read-end event */
return ERROR_OK;
}
Expand All @@ -276,7 +277,7 @@ int esp_common_flash_breakpoint_remove(struct target *target, struct esp_common
}

/* Mark that z1 package received for this slot */
if (esp->flash_brps.ops->breakpoint_lazy_process) {
if (esp->breakpoint_lazy_process) {
flash_bps[slot].action = ESP_BP_ACT_REM;
flash_bps[slot].status = ESP_BP_STAT_PEND;
esp_common_dump_bp_slot("BP-REMOVE", &esp->flash_brps, slot);
Expand Down Expand Up @@ -380,7 +381,7 @@ int esp_common_handle_gdb_detach(struct target *target)
if (ret != ERROR_OK)
return ret;

if (esp->flash_brps.ops->breakpoint_lazy_process) {
if (esp->breakpoint_lazy_process) {
esp_common_flash_breakpoints_get_ready_to_remove(esp);
ret = esp_common_process_lazy_flash_breakpoints(target);
} else {
Expand All @@ -403,7 +404,7 @@ int esp_common_handle_flash_breakpoints(struct target *target)
{
struct esp_common *esp = target_to_esp_common(target);

if (!esp->flash_brps.ops->breakpoint_lazy_process)
if (!esp->breakpoint_lazy_process)
return ERROR_OK;

if (!esp_common_any_pending_flash_breakpoint(esp))
Expand Down Expand Up @@ -515,6 +516,26 @@ int esp_common_process_flash_breakpoints_handler(struct target *target)
return esp_common_handle_flash_breakpoints(target);
}

int esp_common_disable_lazy_breakpoints_handler(struct target *target)
{
/* Before disabling, add/remove pending breakpoints */
int ret = esp_common_process_flash_breakpoints_handler(target);
if (ret != ERROR_OK)
return ret;

if (target->smp) {
struct target_list *head;
foreach_smp_target(head, target->smp_targets) {
target_to_esp_common(target)->breakpoint_lazy_process = false;
}
return ERROR_OK;
}

target_to_esp_common(target)->breakpoint_lazy_process = false;

return ERROR_OK;
}

int esp_common_process_flash_breakpoints_command(struct command_invocation *cmd)
{
if (CMD_ARGC != 0)
Expand All @@ -525,6 +546,23 @@ int esp_common_process_flash_breakpoints_command(struct command_invocation *cmd)
return esp_common_process_flash_breakpoints_handler(target);
}

int esp_common_disable_lazy_breakpoints_command(struct command_invocation *cmd)
{
if (CMD_ARGC != 0)
return ERROR_COMMAND_SYNTAX_ERROR;

struct target *target = get_current_target(CMD_CTX);

int ret = esp_common_disable_lazy_breakpoints_handler(target);

if (ret == ERROR_OK)
command_print(CMD, "disabled");
else
command_print(CMD, "failed");

return ret;
}

static int esp_callback_event_handler(struct target *target, enum target_event event, void *priv)
{
switch (event) {
Expand Down
3 changes: 2 additions & 1 deletion src/target/espressif/esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ struct esp_flash_breakpoint_ops {
int (*breakpoint_remove)(struct target *target,
struct esp_flash_breakpoint *bp,
size_t num_bps);
bool breakpoint_lazy_process;
};

struct esp_flash_breakpoints {
Expand All @@ -128,6 +127,7 @@ struct esp_common {
const struct esp_algorithm_hw *algo_hw;
struct esp_dbg_stubs dbg_stubs;
struct esp_panic_reason panic_reason;
bool breakpoint_lazy_process;
};

struct esp_ops {
Expand All @@ -151,6 +151,7 @@ bool esp_common_flash_breakpoint_exists(struct esp_common *esp,
struct breakpoint *breakpoint);
int esp_common_handle_gdb_detach(struct target *target);
int esp_common_process_flash_breakpoints_command(struct command_invocation *cmd);
int esp_common_disable_lazy_breakpoints_command(struct command_invocation *cmd);
int esp_dbgstubs_table_read(struct target *target, struct esp_dbg_stubs *dbg_stubs);

void esp_common_assist_debug_monitor_disable(struct target *target, uint32_t address, uint32_t *value);
Expand Down
1 change: 0 additions & 1 deletion src/target/espressif/esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ static const struct esp_flash_breakpoint_ops esp32_flash_brp_ops = {
.breakpoint_prepare = esp_algo_flash_breakpoint_prepare,
.breakpoint_add = esp_algo_flash_breakpoint_add,
.breakpoint_remove = esp_algo_flash_breakpoint_remove,
.breakpoint_lazy_process = true,
};

static const struct esp_xtensa_smp_chip_ops esp32_chip_ops = {
Expand Down
1 change: 0 additions & 1 deletion src/target/espressif/esp32c2.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ static const struct esp_flash_breakpoint_ops esp32c2_flash_brp_ops = {
.breakpoint_prepare = esp_algo_flash_breakpoint_prepare,
.breakpoint_add = esp_algo_flash_breakpoint_add,
.breakpoint_remove = esp_algo_flash_breakpoint_remove,
.breakpoint_lazy_process = true,
};

static int esp32c2_target_create(struct target *target, Jim_Interp *interp)
Expand Down
1 change: 0 additions & 1 deletion src/target/espressif/esp32c3.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ static const struct esp_flash_breakpoint_ops esp32c3_flash_brp_ops = {
.breakpoint_prepare = esp_algo_flash_breakpoint_prepare,
.breakpoint_add = esp_algo_flash_breakpoint_add,
.breakpoint_remove = esp_algo_flash_breakpoint_remove,
.breakpoint_lazy_process = true,
};

static int esp32c3_target_create(struct target *target, Jim_Interp *interp)
Expand Down
1 change: 0 additions & 1 deletion src/target/espressif/esp32c5.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ static const struct esp_flash_breakpoint_ops esp32c5_flash_brp_ops = {
.breakpoint_prepare = esp_algo_flash_breakpoint_prepare,
.breakpoint_add = esp_algo_flash_breakpoint_add,
.breakpoint_remove = esp_algo_flash_breakpoint_remove,
.breakpoint_lazy_process = true,
};

static const char *esp32c5_csrs[] = {
Expand Down
1 change: 0 additions & 1 deletion src/target/espressif/esp32c6.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ static const struct esp_flash_breakpoint_ops esp32c6_flash_brp_ops = {
.breakpoint_prepare = esp_algo_flash_breakpoint_prepare,
.breakpoint_add = esp_algo_flash_breakpoint_add,
.breakpoint_remove = esp_algo_flash_breakpoint_remove,
.breakpoint_lazy_process = true,
};

static const char *esp32c6_csrs[] = {
Expand Down
1 change: 0 additions & 1 deletion src/target/espressif/esp32c61.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ static const struct esp_flash_breakpoint_ops esp32c61_flash_brp_ops = {
.breakpoint_prepare = esp_algo_flash_breakpoint_prepare,
.breakpoint_add = esp_algo_flash_breakpoint_add,
.breakpoint_remove = esp_algo_flash_breakpoint_remove,
.breakpoint_lazy_process = true,
};

static const char *esp32c61_csrs[] = {
Expand Down
1 change: 0 additions & 1 deletion src/target/espressif/esp32h2.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ static const struct esp_flash_breakpoint_ops esp32h2_flash_brp_ops = {
.breakpoint_prepare = esp_algo_flash_breakpoint_prepare,
.breakpoint_add = esp_algo_flash_breakpoint_add,
.breakpoint_remove = esp_algo_flash_breakpoint_remove,
.breakpoint_lazy_process = true,
};

static const char *esp32h2_csrs[] = {
Expand Down
1 change: 0 additions & 1 deletion src/target/espressif/esp32p4.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ static const struct esp_flash_breakpoint_ops esp32p4_flash_brp_ops = {
.breakpoint_prepare = esp_algo_flash_breakpoint_prepare,
.breakpoint_add = esp_algo_flash_breakpoint_add,
.breakpoint_remove = esp_algo_flash_breakpoint_remove,
.breakpoint_lazy_process = true,
};

static const char *esp32p4_csrs[] = {
Expand Down
1 change: 0 additions & 1 deletion src/target/espressif/esp32s2.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,6 @@ static const struct esp_flash_breakpoint_ops esp32s2_spec_brp_ops = {
.breakpoint_prepare = esp_algo_flash_breakpoint_prepare,
.breakpoint_add = esp_algo_flash_breakpoint_add,
.breakpoint_remove = esp_algo_flash_breakpoint_remove,
.breakpoint_lazy_process = true,
};

static const struct esp_semihost_ops esp32s2_semihost_ops = {
Expand Down
1 change: 0 additions & 1 deletion src/target/espressif/esp32s3.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ static const struct esp_flash_breakpoint_ops esp32s3_flash_brp_ops = {
.breakpoint_prepare = esp_algo_flash_breakpoint_prepare,
.breakpoint_add = esp_algo_flash_breakpoint_add,
.breakpoint_remove = esp_algo_flash_breakpoint_remove,
.breakpoint_lazy_process = true,
};

static const struct esp_xtensa_smp_chip_ops esp32s3_chip_ops = {
Expand Down
9 changes: 8 additions & 1 deletion src/target/espressif/esp_riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,14 @@ const struct command_registration esp_riscv_command_handlers[] = {
.name = "process_lazy_breakpoints",
.handler = esp_common_process_flash_breakpoints_command,
.mode = COMMAND_ANY,
.help = "Handles resum-start and step-start events to set/clear all waiting flash breakpoints",
.help = "Set/clear all pending flash breakpoints",
.usage = "",
},
{
.name = "disable_lazy_breakpoints",
.handler = esp_common_disable_lazy_breakpoints_command,
.mode = COMMAND_ANY,
.help = "Process flash breakpoints on time",
.usage = "",
},
{
Expand Down
9 changes: 8 additions & 1 deletion src/target/espressif/esp_xtensa.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,14 @@ const struct command_registration esp_command_handlers[] = {
.name = "process_lazy_breakpoints",
.handler = esp_common_process_flash_breakpoints_command,
.mode = COMMAND_ANY,
.help = "Handles resum-start and step-start events to set/clear all waiting flash breakpoints",
.help = "Set/clear all pending flash breakpoints",
.usage = "",
},
{
.name = "disable_lazy_breakpoints",
.handler = esp_common_disable_lazy_breakpoints_command,
.mode = COMMAND_ANY,
.help = "Process flash breakpoints on time",
.usage = "",
},
COMMAND_REGISTRATION_DONE
Expand Down
9 changes: 8 additions & 1 deletion src/target/espressif/esp_xtensa_smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,14 @@ const struct command_registration esp_xtensa_smp_esp_command_handlers[] = {
.name = "process_lazy_breakpoints",
.handler = esp_common_process_flash_breakpoints_command,
.mode = COMMAND_ANY,
.help = "Handles resum-start and step-start events to set/clear all waiting flash breakpoints",
.help = "Set/clear all pending flash breakpoints",
.usage = "",
},
{
.name = "disable_lazy_breakpoints",
.handler = esp_common_disable_lazy_breakpoints_command,
.mode = COMMAND_ANY,
.help = "Process flash breakpoints on time",
.usage = "",
},
COMMAND_REGISTRATION_DONE
Expand Down
3 changes: 3 additions & 0 deletions testing/esp/py_debug_backend/debug_backend/hw_specific/esp.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def apptrace_wait_stop(self, tmo=10):
def process_lazy_bps(self):
self.cmd_exec('esp process_lazy_breakpoints')

def disable_lazy_bps(self):
self.cmd_exec('esp disable_lazy_breakpoints')

class OocdEspXtensa(OocdXtensa, OocdEspImpl):
"""
Class to communicate to OpenOCD supporting ESP Xtensa-specific features
Expand Down

0 comments on commit 858373d

Please sign in to comment.