stack_dump.inc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright (C) 2012 Zeex
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a
  4. // copy of this software and associated documentation files (the "Software"),
  5. // to deal in the Software without restriction, including without limitation
  6. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  7. // and/or sell copies of the Software, and to permit persons to whom the
  8. // Software is furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  14. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  18. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  19. // DEALINGS IN THE SOFTWARE.
  20. #if defined STACK_DUMP_INC
  21. #endinput
  22. #endif
  23. #define STACK_DUMP_INC
  24. #tryinclude <console>
  25. /////////////////////////////////////////////////
  26. // Stack layout
  27. /////////////////////////////////////////////////
  28. // what | stack pointer (STK)
  29. //-----------------------------------------------
  30. // <STACK TOP> | STP
  31. // ... | STP - 4
  32. // ... | STP - 8
  33. // ... | ...
  34. // argument_N | FRM + 4*(N+3)
  35. // ... | ...
  36. // argument_2 | FRM + 16
  37. // argument_1 | FRM + 12
  38. // 4*N | FRM + 8
  39. // RET address | FRM + 4
  40. // old FRM | FRM
  41. // |
  42. //-------------- N E W F R A M E ---------------
  43. // |
  44. // local_var_1 | FRM - 4
  45. // local_var_2 | FRM - 8
  46. // ... | ...
  47. // local_var_M | FRM - 4*M
  48. // ... | ...
  49. // ... | 8
  50. // ... | 4
  51. // <BOTTOM> | 0
  52. //-----------------------------------------------
  53. #include "amx_memory"
  54. stock DumpStack()
  55. {
  56. new stp, stk;
  57. #emit lctrl 3
  58. #emit stor.s.pri stp
  59. #emit lctrl 4
  60. #emit stor.s.pri stk
  61. print("------------------------");
  62. print("Stack dump:");
  63. print("------------------------");
  64. // Skip locals + FRM + RETN address + paramcount.
  65. stk += 20;
  66. // Don't print above the top of the stack.
  67. new i = stp;
  68. printf("[0x%08x]: TOP", i);
  69. i -= 4;
  70. for ( ; i >= stk; i -= 4) {
  71. printf("[0x%08x]: 0x%08x", i, ReadAmxMemory(i));
  72. }
  73. print("------------------------");
  74. }