backtrace.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * File : backtrace.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, 2008 RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2008-07-29 Bernard first version from QiuYi implementation
  13. */
  14. #include <rtthread.h>
  15. #ifdef __GNUC__
  16. /*
  17. -->High Address,Stack Top
  18. PC<-----|
  19. LR |
  20. IP |
  21. FP |
  22. ...... |
  23. PC<-| |
  24. LR | |
  25. IP | |
  26. FP---|-- |
  27. ...... |
  28. PC |
  29. LR |
  30. IP |
  31. FP---
  32. -->Low Address,Stack Bottom
  33. */
  34. void rt_hw_backtrace(rt_uint32_t *fp, rt_uint32_t thread_entry)
  35. {
  36. rt_uint32_t i, pc, func_entry;
  37. pc = *fp;
  38. rt_kprintf("[0x%x]\n", pc-0xC);
  39. for(i=0; i<10; i++)
  40. {
  41. fp = (rt_uint32_t *)*(fp - 3);
  42. pc = *fp ;
  43. func_entry = pc - 0xC;
  44. if(func_entry <= 0x30000000) break;
  45. if((func_entry == thread_entry))
  46. {
  47. rt_kprintf("EntryPoint:0x%x\n", func_entry);
  48. break;
  49. }
  50. rt_kprintf("[0x%x]\n", func_entry);
  51. }
  52. }
  53. #else
  54. void rt_hw_backtrace(rt_uint32_t *fp, rt_uint32_t thread_entry)
  55. {
  56. /* old compiler implementation */
  57. }
  58. #endif