gdb-extract-def 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. set $STACK_TOP=0x120000
  6. # Disables logging to stdout - only log to file
  7. set logging redirect on
  8. set logging file $arg1
  9. set logging overwrite on
  10. set logging on
  11. run
  12. printf "---BEGIN JSON---\n"
  13. printf "[\n"
  14. printf " %d,\n", $eax
  15. printf " %d,\n", $ecx
  16. printf " %d,\n", $edx
  17. printf " %d,\n", $ebx
  18. printf " %d,\n", $esp
  19. printf " %d,\n", $ebp
  20. printf " %d,\n", $esi
  21. printf " %d,\n", $edi
  22. printf " \n"
  23. printf " %d,\n", $eip
  24. printf " \n"
  25. # For fpu registers, check the tag register first. If the tag index is
  26. # invalid and you try to access to corresponding register, gdb exits with an
  27. # error.
  28. if ($ftag & (3 << 0)) != (2 << 0)
  29. printf " %.100e,\n", $st0
  30. else
  31. printf " \"invalid\",\n"
  32. end
  33. if ($ftag & (3 << 2)) != (2 << 2)
  34. printf " %.100e,\n", $st1
  35. else
  36. printf " \"invalid\",\n"
  37. end
  38. if ($ftag & (3 << 4)) != (2 << 4)
  39. printf " %.100e,\n", $st2
  40. else
  41. printf " \"invalid\",\n"
  42. end
  43. if ($ftag & (3 << 6)) != (2 << 6)
  44. printf " %.100e,\n", $st3
  45. else
  46. printf " \"invalid\",\n"
  47. end
  48. if ($ftag & (3 << 8)) != (2 << 8)
  49. printf " %.100e,\n", $st4
  50. else
  51. printf " \"invalid\",\n"
  52. end
  53. if ($ftag & (3 << 10)) != (2 << 10)
  54. printf " %.100e,\n", $st5
  55. else
  56. printf " \"invalid\",\n"
  57. end
  58. if ($ftag & (3 << 12)) != (2 << 12)
  59. printf " %.100e,\n", $st6
  60. else
  61. printf " \"invalid\",\n"
  62. end
  63. if ($ftag & (3 << 14)) != (2 << 14)
  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. printf " %d,\n", *(int*)($STACK_TOP-64)
  120. printf " %d,\n", *(int*)($STACK_TOP-60)
  121. printf " %d,\n", *(int*)($STACK_TOP-56)
  122. printf " %d,\n", *(int*)($STACK_TOP-52)
  123. printf " %d,\n", *(int*)($STACK_TOP-48)
  124. printf " %d,\n", *(int*)($STACK_TOP-44)
  125. printf " %d,\n", *(int*)($STACK_TOP-40)
  126. printf " %d,\n", *(int*)($STACK_TOP-36)
  127. printf " %d,\n", *(int*)($STACK_TOP-32)
  128. printf " %d,\n", *(int*)($STACK_TOP-28)
  129. printf " %d,\n", *(int*)($STACK_TOP-24)
  130. printf " %d,\n", *(int*)($STACK_TOP-20)
  131. printf " %d,\n", *(int*)($STACK_TOP-16)
  132. printf " %d,\n", *(int*)($STACK_TOP-12)
  133. printf " %d,\n", *(int*)($STACK_TOP-8)
  134. printf " %d,\n", *(int*)($STACK_TOP-4)
  135. printf " \n"
  136. printf " %d,\n", $eflags
  137. printf " %d,\n", $ftag
  138. printf " %d\n", $fstat
  139. printf "]\n"
  140. printf "---END JSON---\n"
  141. set logging off
  142. end