@@ -191,6 +191,45 @@ static void esf_dump(const z_arch_esf_t *esf)
191191 LOG_ERR ("x16: 0x%016llx x17: 0x%016llx" , esf -> x16 , esf -> x17 );
192192 LOG_ERR ("x18: 0x%016llx lr: 0x%016llx" , esf -> x18 , esf -> lr );
193193}
194+
195+ #ifdef CONFIG_ARM64_ENABLE_FRAME_POINTER
196+ static void esf_unwind (const z_arch_esf_t * esf )
197+ {
198+ /*
199+ * For GCC:
200+ *
201+ * ^ +-----------------+
202+ * | | |
203+ * | | |
204+ * | | |
205+ * | | |
206+ * | | function stack |
207+ * | | |
208+ * | | |
209+ * | | |
210+ * | | |
211+ * | +-----------------+
212+ * | | LR |
213+ * | +-----------------+
214+ * | | previous FP | <---+ FP
215+ * + +-----------------+
216+ */
217+
218+ uint64_t * fp = (uint64_t * ) esf -> fp ;
219+ unsigned int count = 0 ;
220+ uint64_t lr ;
221+
222+ LOG_ERR ("" );
223+ while (fp != NULL ) {
224+ lr = fp [1 ];
225+ LOG_ERR ("backtrace %2d: fp: 0x%016llx lr: 0x%016llx" ,
226+ count ++ , (uint64_t ) fp , lr );
227+ fp = (uint64_t * ) fp [0 ];
228+ }
229+ LOG_ERR ("" );
230+ }
231+ #endif
232+
194233#endif /* CONFIG_EXCEPTION_DEBUG */
195234
196235static bool is_recoverable (z_arch_esf_t * esf , uint64_t esr , uint64_t far ,
@@ -261,6 +300,10 @@ void z_arm64_fatal_error(unsigned int reason, z_arch_esf_t *esf)
261300 if (esf != NULL ) {
262301 esf_dump (esf );
263302 }
303+
304+ #ifdef CONFIG_ARM64_ENABLE_FRAME_POINTER
305+ esf_unwind (esf );
306+ #endif /* CONFIG_ARM64_ENABLE_FRAME_POINTER */
264307#endif /* CONFIG_EXCEPTION_DEBUG */
265308
266309 z_fatal_error (reason , esf );
0 commit comments