Clean up handling of lost targets using new exceptions mechanism.
This commit is contained in:
parent
588bad34ba
commit
5ab8564ff6
|
@ -37,6 +37,7 @@
|
|||
#include "command.h"
|
||||
#include "gdb_packet.h"
|
||||
#include "cortexm.h"
|
||||
#include "morse.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -57,6 +58,7 @@ const struct command_s cortexm_cmd_list[] = {
|
|||
#define SIGINT 2
|
||||
#define SIGTRAP 5
|
||||
#define SIGSEGV 11
|
||||
#define SIGLOST 29
|
||||
|
||||
static int cortexm_regs_read(struct target_s *target, void *data);
|
||||
static int cortexm_regs_write(struct target_s *target, const void *data);
|
||||
|
@ -487,12 +489,23 @@ cortexm_halt_wait(struct target_s *target)
|
|||
|
||||
uint32_t dhcsr = 0;
|
||||
volatile struct exception e;
|
||||
TRY_CATCH (e, EXCEPTION_TIMEOUT) {
|
||||
TRY_CATCH (e, EXCEPTION_ALL) {
|
||||
/* If this times out because the target is in WFI then
|
||||
* the target is still running. */
|
||||
dhcsr = target_mem_read32(target, CORTEXM_DHCSR);
|
||||
}
|
||||
if (e.type || !(dhcsr & CORTEXM_DHCSR_S_HALT))
|
||||
switch (e.type) {
|
||||
case EXCEPTION_ERROR:
|
||||
/* Oh crap, there's no recovery from this... */
|
||||
target_list_free();
|
||||
morse("TARGET LOST.", 1);
|
||||
return SIGLOST;
|
||||
case EXCEPTION_TIMEOUT:
|
||||
/* Timeout isn't a problem, target could be in WFI */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(dhcsr & CORTEXM_DHCSR_S_HALT))
|
||||
return 0;
|
||||
|
||||
/* We've halted. Let's find out why. */
|
||||
|
|
|
@ -34,6 +34,6 @@ void raise_exception(uint32_t type, const char *msg)
|
|||
longjmp(e->jmpbuf, type);
|
||||
}
|
||||
}
|
||||
PLATFORM_FATAL_ERROR(type);
|
||||
abort();
|
||||
}
|
||||
|
||||
|
|
|
@ -158,6 +158,12 @@ gdb_main(void)
|
|||
if (sig < 0)
|
||||
break;
|
||||
|
||||
/* Target disappeared */
|
||||
if (cur_target == NULL) {
|
||||
gdb_putpacket_f("X%02X", sig);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Report reason for halt */
|
||||
if(target_check_hw_wp(cur_target, &watch_addr)) {
|
||||
/* Watchpoint hit */
|
||||
|
|
16
src/main.c
16
src/main.c
|
@ -28,6 +28,9 @@
|
|||
#include "jtagtap.h"
|
||||
#include "jtag_scan.h"
|
||||
#include "target.h"
|
||||
#include "exception.h"
|
||||
#include "gdb_packet.h"
|
||||
#include "morse.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
|
@ -39,9 +42,18 @@ main(int argc, char **argv)
|
|||
(void) argv;
|
||||
platform_init();
|
||||
#endif
|
||||
PLATFORM_SET_FATAL_ERROR_RECOVERY();
|
||||
|
||||
gdb_main();
|
||||
while (true) {
|
||||
volatile struct exception e;
|
||||
TRY_CATCH(e, EXCEPTION_ALL) {
|
||||
gdb_main();
|
||||
}
|
||||
if (e.type == EXCEPTION_ERROR) {
|
||||
gdb_putpacketz("EFF");
|
||||
target_list_free();
|
||||
morse("TARGET LOST.", 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Should never get here */
|
||||
return 0;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "general.h"
|
||||
#include "morse.h"
|
||||
|
||||
#include <libopencm3/cm3/systick.h>
|
||||
#include <libopencm3/cm3/scb.h>
|
||||
|
|
Loading…
Reference in New Issue