symbols.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <bio.h>
  12. #include <mach.h>
  13. #include "arm.h"
  14. #define STRINGSZ 128
  15. /*
  16. * print the value of dot as file:line
  17. */
  18. void
  19. printsource(int32_t dot)
  20. {
  21. char str[STRINGSZ];
  22. if (fileline(str, STRINGSZ, dot))
  23. Bprint(bioout, "%s", str);
  24. }
  25. void
  26. printlocals(Symbol *fn, uint32_t fp)
  27. {
  28. int i;
  29. Symbol s;
  30. s = *fn;
  31. for (i = 0; localsym(&s, i); i++) {
  32. if (s.class != CAUTO)
  33. continue;
  34. Bprint(bioout, "\t%s=#%lux\n", s.name, getmem_4(fp-s.value));
  35. }
  36. }
  37. void
  38. printparams(Symbol *fn, uint32_t fp)
  39. {
  40. int i;
  41. Symbol s;
  42. int first;
  43. fp += mach->szreg; /* skip saved pc */
  44. s = *fn;
  45. for (first = i = 0; localsym(&s, i); i++) {
  46. if (s.class != CPARAM)
  47. continue;
  48. if (first++)
  49. Bprint(bioout, ", ");
  50. Bprint(bioout, "%s=#%lux", s.name, getmem_4(fp+s.value));
  51. }
  52. Bprint(bioout, ") ");
  53. }
  54. #define STARTSYM "_main"
  55. #define FRAMENAME ".frame"
  56. void
  57. stktrace(int modif)
  58. {
  59. uint32_t pc, sp;
  60. Symbol s, f;
  61. int i;
  62. char buf[512];
  63. pc = reg.r[15];
  64. sp = reg.r[13];
  65. i = 0;
  66. while (findsym(pc, CTEXT, &s)) {
  67. if(strcmp(STARTSYM, s.name) == 0) {
  68. Bprint(bioout, "%s() at #%llux\n", s.name, s.value);
  69. break;
  70. }
  71. if (pc == s.value) /* at first instruction */
  72. f.value = 0;
  73. else if (findlocal(&s, FRAMENAME, &f) == 0)
  74. break;
  75. if (s.type == 'L' || s.type == 'l' || pc <= s.value+4)
  76. pc = reg.r[14];
  77. else pc = getmem_4(sp);
  78. sp += f.value;
  79. Bprint(bioout, "%s(", s.name);
  80. printparams(&s, sp);
  81. printsource(s.value);
  82. Bprint(bioout, " called from ");
  83. symoff(buf, sizeof(buf), pc-8, CTEXT);
  84. Bprint(bioout, buf);
  85. printsource(pc-8);
  86. Bprint(bioout, "\n");
  87. if(modif == 'C')
  88. printlocals(&s, sp);
  89. if(++i > 40){
  90. Bprint(bioout, "(trace truncated)\n");
  91. break;
  92. }
  93. }
  94. }