Page 2 of 2

Re: Debugging unhandled exception.

Posted: Thu Mar 16, 2017 2:56 pm
by duststorm
Sorry to be digging up an old thread, but I'm having trouble debugging unhandled exceptions and perhaps someone can help.

Observation: as soon as I change any of the aliases (that all point to the same _unhandled_exception function) then the program no longer works. It gets stuck in the _unhandled_exception trap as soon as I continue from the ResetHandler using the debugger. I have not been able to find an instruction that is executed before it goes into error mode.

What I did was the following modifications to vectors.c:

Code: Select all

/**
 * @brief   Unhandled exceptions handler.
 * @details Any undefined exception vector points to this function by default.
 *          This function simply stops the system into an infinite loop.
 *
 * @notapi
 */
/*lint -save -e9075 [8.4] All symbols are invoked from asm context.*/
void _unhandled_exception(void) {
/*lint -restore*/

  while (true) {
  }
}

/*lint -save -e9075 [8.4] All symbols are invoked from asm context.*/
void _hard_fault(void) {
/*lint -restore*/

  while (true) {
  }
}

void Reset_Handler(void) __attribute__((weak, alias("_unhandled_exception")));
void NMI_Handler(void) __attribute__((weak, alias("_unhandled_exception")));
//void HardFault_Handler(void) __attribute__((weak, alias("_unhandled_exception")));
void HardFault_Handler(void) __attribute__((weak, alias("_hard_fault")));
void MemManage_Handler(void) __attribute__((weak, alias("_unhandled_exception")));
void BusFault_Handler(void) __attribute__((weak, alias("_unhandled_exception")));
void UsageFault_Handler(void) __attribute__((weak, alias("_unhandled_exception")));



If I try defining some of the error functions, instead of using the alias declarations, like ulikoehler suggested, I get a different but similar issue. The debugger gets stuck in the __DSB(); function of NVIC_SystemReset() and blocks indefinitely.

Using ChibiOS 3.0.2

Does someone have an idea what might be going wrong?

Re: Debugging unhandled exception.

Posted: Thu Mar 16, 2017 4:56 pm
by duststorm
This is probably a false alarm. Perhaps using the debugger too intensively for longer times somehow brought chaos.
I backed of the changesets, hard powered down the development board, made sure all gdb and stm link processes were exited. Then after reapplying my changesets one by one and testing it seems my code came back to life.

Re: Debugging unhandled exception.

Posted: Thu Mar 16, 2017 7:18 pm
by steved
If your problems recur, there's a version of vectors.c in this thread which I found very useful, since the debugger breaks as soon as the exception is encountered, with various useful information stored.

Re: Debugging unhandled exception.

Posted: Mon Sep 23, 2019 2:29 am
by russian
BRILLIANT! Thank you very much! This should be in ChibiOS by default, this improves my HardFault comfort so much!