Page 1 of 1

Wait for debugger

Posted: Wed Aug 19, 2020 8:16 am
by ojoj42
Hi,

Is it somehow possible to generate a break point in code and than wait for the debugger (jtag) to connect to target and start debugging at that point?

Kind Regards
Daniel Moberg

Re: Wait for debugger

Posted: Wed Aug 19, 2020 8:21 pm
by ESP_igrr
Hi Daniel, first you can use cpu_hal_is_debugger_attached function to check whether OpenOCD has connected to the chip. If not connected, print some message, delay, repeat the check.
Once OpenOCD is connected, cpu_hal_is_debugger_attached returns 'true'.
Then call cpu_hal_set_breakpoint function to set a breakpoint at the point where you would like the program to stop.

Something along these lines:

Code: Select all

while(!cpu_hal_is_debugger_attached()) {
  printf("waiting for debugger\n");
  usleep(1000000);
}
cpu_hal_set_breakpoint(0, &next);

next: // label used to get the address of the next line of code

some_other_func();