debugsymbols.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <precomp.h>
  2. #include "debugsymbols.h"
  3. #include <api/script/debugger/disasm.h>
  4. #include <api/script/scriptmgr.h>
  5. #include <api/script/debugger/sourcecodeline.h>
  6. #include <api/script/vcpu.h>
  7. DebugSymbols::DebugSymbols(int _vcpuid) : disasm(_vcpuid)
  8. {
  9. gotsymbols = 0;
  10. SystemObject *so = SOM::getSystemObjectByScriptId(_vcpuid);
  11. if (so != NULL)
  12. binaryfilename = so->getFilename();
  13. VCPUcodeBlock *cb = VCPU::getCodeBlockEntry(_vcpuid);
  14. if (cb->debugsize != 0) {
  15. gotsymbols = 1;
  16. char *p = cb->debugsymbols;
  17. int n = *(int *)p; p += 4;
  18. while (n--) {
  19. int s = *(int *)p; p += 4;
  20. wchar_t *m = WMALLOC(s+1);
  21. MEMCPY(m, p, s*sizeof(wchar_t));
  22. m[s] = 0;
  23. StringW *temp = new StringW;
  24. temp->own(m);
  25. //files.addItem(new String(m));
  26. files.addItem(temp);
  27. //FREE(m);
  28. p+=s;
  29. }
  30. n = *(int *)p; p += 4;
  31. while (n--) {
  32. SourceCodeLineI *l = new SourceCodeLineI();
  33. l->setPointer(*(int *)p); p += 4;
  34. l->setSourceFile(files[*(int *)p]->getValue()); p += 4;
  35. l->setSourceFileLine(*(int *)p); p += 4;
  36. SourceCodeLineI *last = lines.getLast();
  37. if (last != NULL) last->setLength(l->getPointer()-last->getPointer());
  38. lines.addItem(l);
  39. }
  40. SourceCodeLineI *last = lines.getLast();
  41. if (last != NULL) last->setLength(cb->size - last->getPointer());
  42. }
  43. }
  44. DebugSymbols::~DebugSymbols()
  45. {
  46. files.deleteAll();
  47. lines.deleteAll();
  48. }
  49. int DebugSymbols::getNumLines() {
  50. if (!gotsymbols) return disasm.getNumLines();
  51. return lines.getNumItems();
  52. }
  53. int DebugSymbols::findLine(int pointer) {
  54. if (!gotsymbols) return disasm.findLine(pointer);
  55. int i;
  56. for (i=0;i<lines.getNumItems();i++) {
  57. SourceCodeLine *l = lines.enumItem(i);
  58. int ip = l->getPointer();
  59. int il = l->getLength();
  60. if (pointer >= ip && pointer < ip+il) {
  61. return i;
  62. }
  63. }
  64. return -1;
  65. }
  66. SourceCodeLine *DebugSymbols::enumLine(int n) {
  67. if (!gotsymbols) return disasm.enumLine(n);
  68. return lines.enumItem(n);
  69. }