gdb-extract-def 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. # Invocation: gdb -x gdb-extract-def
  2. # extract-state /path/to/foo.bin /path/to/foo.fixture
  3. define extract-state
  4. file $arg0
  5. # Disables logging to stdout - only log to file
  6. set logging redirect on
  7. set logging file $arg1
  8. set logging overwrite on
  9. set logging on
  10. run
  11. printf "---BEGIN JSON---\n"
  12. printf "[\n"
  13. printf " %d,\n", $eax
  14. printf " %d,\n", $ecx
  15. printf " %d,\n", $edx
  16. printf " %d,\n", $ebx
  17. printf " %d,\n", $esp
  18. printf " %d,\n", $ebp
  19. printf " %d,\n", $esi
  20. printf " %d,\n", $edi
  21. printf "\n"
  22. printf " %d,\n", $eip
  23. printf "\n"
  24. # For fpu registers, check the tag register first. If the tag index is
  25. # invalid and you try to access to corresponding register, gdb exits with an
  26. # error.
  27. set $top = $fstat >> 11 & 7
  28. if ($ftag >> (2 * (($top + 0) & 7)) & 3) != 2
  29. printf " %.100e,\n", $st0
  30. else
  31. printf " \"invalid\",\n"
  32. end
  33. if ($ftag >> (2 * (($top + 1) & 7)) & 3) != 2
  34. printf " %.100e,\n", $st1
  35. else
  36. printf " \"invalid\",\n"
  37. end
  38. if ($ftag >> (2 * (($top + 2) & 7)) & 3) != 2
  39. printf " %.100e,\n", $st2
  40. else
  41. printf " \"invalid\",\n"
  42. end
  43. if ($ftag >> (2 * (($top + 3) & 7)) & 3) != 2
  44. printf " %.100e,\n", $st3
  45. else
  46. printf " \"invalid\",\n"
  47. end
  48. if ($ftag >> (2 * (($top + 4) & 7)) & 3) != 2
  49. printf " %.100e,\n", $st4
  50. else
  51. printf " \"invalid\",\n"
  52. end
  53. if ($ftag >> (2 * (($top + 5) & 7)) & 3) != 2
  54. printf " %.100e,\n", $st5
  55. else
  56. printf " \"invalid\",\n"
  57. end
  58. if ($ftag >> (2 * (($top + 6) & 7)) & 3) != 2
  59. printf " %.100e,\n", $st6
  60. else
  61. printf " \"invalid\",\n"
  62. end
  63. if ($ftag >> (2 * (($top + 7) & 7)) & 3) != 2
  64. printf " %.100e,\n", $st7
  65. else
  66. printf " \"invalid\",\n"
  67. end
  68. printf "\n"
  69. printf " %d,\n", $mm0.v2_int32[0]
  70. printf " %d,\n", $mm0.v2_int32[1]
  71. printf " %d,\n", $mm1.v2_int32[0]
  72. printf " %d,\n", $mm1.v2_int32[1]
  73. printf " %d,\n", $mm2.v2_int32[0]
  74. printf " %d,\n", $mm2.v2_int32[1]
  75. printf " %d,\n", $mm3.v2_int32[0]
  76. printf " %d,\n", $mm3.v2_int32[1]
  77. printf " %d,\n", $mm4.v2_int32[0]
  78. printf " %d,\n", $mm4.v2_int32[1]
  79. printf " %d,\n", $mm5.v2_int32[0]
  80. printf " %d,\n", $mm5.v2_int32[1]
  81. printf " %d,\n", $mm6.v2_int32[0]
  82. printf " %d,\n", $mm6.v2_int32[1]
  83. printf " %d,\n", $mm7.v2_int32[0]
  84. printf " %d,\n", $mm7.v2_int32[1]
  85. printf "\n"
  86. printf " %d,\n", $xmm0.v4_int32[0]
  87. printf " %d,\n", $xmm0.v4_int32[1]
  88. printf " %d,\n", $xmm0.v4_int32[2]
  89. printf " %d,\n", $xmm0.v4_int32[3]
  90. printf " %d,\n", $xmm1.v4_int32[0]
  91. printf " %d,\n", $xmm1.v4_int32[1]
  92. printf " %d,\n", $xmm1.v4_int32[2]
  93. printf " %d,\n", $xmm1.v4_int32[3]
  94. printf " %d,\n", $xmm2.v4_int32[0]
  95. printf " %d,\n", $xmm2.v4_int32[1]
  96. printf " %d,\n", $xmm2.v4_int32[2]
  97. printf " %d,\n", $xmm2.v4_int32[3]
  98. printf " %d,\n", $xmm3.v4_int32[0]
  99. printf " %d,\n", $xmm3.v4_int32[1]
  100. printf " %d,\n", $xmm3.v4_int32[2]
  101. printf " %d,\n", $xmm3.v4_int32[3]
  102. printf " %d,\n", $xmm4.v4_int32[0]
  103. printf " %d,\n", $xmm4.v4_int32[1]
  104. printf " %d,\n", $xmm4.v4_int32[2]
  105. printf " %d,\n", $xmm4.v4_int32[3]
  106. printf " %d,\n", $xmm5.v4_int32[0]
  107. printf " %d,\n", $xmm5.v4_int32[1]
  108. printf " %d,\n", $xmm5.v4_int32[2]
  109. printf " %d,\n", $xmm5.v4_int32[3]
  110. printf " %d,\n", $xmm6.v4_int32[0]
  111. printf " %d,\n", $xmm6.v4_int32[1]
  112. printf " %d,\n", $xmm6.v4_int32[2]
  113. printf " %d,\n", $xmm6.v4_int32[3]
  114. printf " %d,\n", $xmm7.v4_int32[0]
  115. printf " %d,\n", $xmm7.v4_int32[1]
  116. printf " %d,\n", $xmm7.v4_int32[2]
  117. printf " %d,\n", $xmm7.v4_int32[3]
  118. printf "\n"
  119. set $addr=0x100000
  120. while($addr < 0x102000)
  121. printf " %d, %d, %d, %d, %d, %d, %d, %d,\n", *(int*)($addr+0), *(int*)($addr+4), *(int*)($addr+8), *(int*)($addr+12), *(int*)($addr+16), *(int*)($addr+20), *(int*)($addr+24), *(int*)($addr+28)
  122. set $addr=$addr+32
  123. end
  124. printf "\n"
  125. printf " %d,\n", $eflags
  126. printf " %d,\n", $ftag
  127. printf " %d\n", $fstat
  128. printf "]\n"
  129. printf "---END JSON---\n"
  130. set logging off
  131. end