immunio 0.15.4 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (454) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +0 -27
  3. data/ext/immunio/Rakefile +9 -0
  4. data/lib/immunio/plugins/active_record.rb +1 -1
  5. data/lib/immunio/plugins/active_record_relation.rb +1 -1
  6. data/lib/immunio/plugins/environment_reporter.rb +20 -0
  7. data/lib/immunio/rufus_lua_ext/ref.rb +1 -3
  8. data/lib/immunio/version.rb +1 -1
  9. data/lib/immunio/vm.rb +1 -2
  10. data/lua-hooks/Makefile +97 -0
  11. data/lua-hooks/ext/all.c +41 -52
  12. data/lua-hooks/ext/all.o +0 -0
  13. data/lua-hooks/ext/libinjection/libinjection_html5.o +0 -0
  14. data/lua-hooks/ext/libinjection/libinjection_sqli.o +0 -0
  15. data/lua-hooks/ext/libinjection/libinjection_xss.o +0 -0
  16. data/lua-hooks/ext/libinjection/lualib.c +2 -2
  17. data/lua-hooks/ext/lpeg/lpcap.c +2 -2
  18. data/lua-hooks/ext/lpeg/lpcap.o +0 -0
  19. data/lua-hooks/ext/lpeg/lpcode.c +2 -2
  20. data/lua-hooks/ext/lpeg/lpcode.h +1 -1
  21. data/lua-hooks/ext/lpeg/lpcode.o +0 -0
  22. data/lua-hooks/ext/lpeg/lpprint.o +0 -0
  23. data/lua-hooks/ext/lpeg/lptree.c +2 -2
  24. data/lua-hooks/ext/lpeg/lptypes.h +1 -1
  25. data/lua-hooks/ext/lpeg/lpvm.c +2 -2
  26. data/lua-hooks/ext/lpeg/lpvm.o +0 -0
  27. data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +16 -3
  28. data/lua-hooks/ext/lua-snapshot/snapshot.c +14 -7
  29. data/lua-hooks/ext/luajit/COPYRIGHT +56 -0
  30. data/lua-hooks/ext/luajit/Makefile +159 -0
  31. data/lua-hooks/ext/luajit/README +16 -0
  32. data/lua-hooks/ext/luajit/doc/bluequad-print.css +166 -0
  33. data/lua-hooks/ext/luajit/doc/bluequad.css +325 -0
  34. data/lua-hooks/ext/luajit/doc/changes.html +804 -0
  35. data/lua-hooks/ext/luajit/doc/contact.html +104 -0
  36. data/lua-hooks/ext/luajit/doc/ext_c_api.html +189 -0
  37. data/lua-hooks/ext/luajit/doc/ext_ffi.html +332 -0
  38. data/lua-hooks/ext/luajit/doc/ext_ffi_api.html +570 -0
  39. data/lua-hooks/ext/luajit/doc/ext_ffi_semantics.html +1261 -0
  40. data/lua-hooks/ext/luajit/doc/ext_ffi_tutorial.html +603 -0
  41. data/lua-hooks/ext/luajit/doc/ext_jit.html +201 -0
  42. data/lua-hooks/ext/luajit/doc/ext_profiler.html +365 -0
  43. data/lua-hooks/ext/luajit/doc/extensions.html +448 -0
  44. data/lua-hooks/ext/luajit/doc/faq.html +186 -0
  45. data/lua-hooks/ext/luajit/doc/img/contact.png +0 -0
  46. data/lua-hooks/ext/luajit/doc/install.html +659 -0
  47. data/lua-hooks/ext/luajit/doc/luajit.html +236 -0
  48. data/lua-hooks/ext/luajit/doc/running.html +309 -0
  49. data/lua-hooks/ext/luajit/doc/status.html +118 -0
  50. data/lua-hooks/ext/luajit/dynasm/dasm_arm.h +456 -0
  51. data/lua-hooks/ext/luajit/dynasm/dasm_arm.lua +1125 -0
  52. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.h +518 -0
  53. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.lua +1166 -0
  54. data/lua-hooks/ext/luajit/dynasm/dasm_mips.h +416 -0
  55. data/lua-hooks/ext/luajit/dynasm/dasm_mips.lua +953 -0
  56. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.h +419 -0
  57. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.lua +1919 -0
  58. data/lua-hooks/ext/luajit/dynasm/dasm_proto.h +83 -0
  59. data/lua-hooks/ext/luajit/dynasm/dasm_x64.lua +12 -0
  60. data/lua-hooks/ext/luajit/dynasm/dasm_x86.h +471 -0
  61. data/lua-hooks/ext/luajit/dynasm/dasm_x86.lua +1945 -0
  62. data/lua-hooks/ext/luajit/dynasm/dynasm.lua +1094 -0
  63. data/lua-hooks/ext/luajit/etc/luajit.1 +88 -0
  64. data/lua-hooks/ext/luajit/etc/luajit.pc +25 -0
  65. data/lua-hooks/ext/luajit/src/Makefile +697 -0
  66. data/lua-hooks/ext/luajit/src/Makefile.dep +244 -0
  67. data/lua-hooks/ext/luajit/src/host/README +4 -0
  68. data/lua-hooks/ext/luajit/src/host/buildvm +0 -0
  69. data/lua-hooks/ext/luajit/src/host/buildvm.c +518 -0
  70. data/lua-hooks/ext/luajit/src/host/buildvm.h +105 -0
  71. data/lua-hooks/ext/luajit/src/host/buildvm.o +0 -0
  72. data/lua-hooks/ext/luajit/src/host/buildvm_arch.h +7449 -0
  73. data/lua-hooks/ext/luajit/src/host/buildvm_asm.c +345 -0
  74. data/lua-hooks/ext/luajit/src/host/buildvm_asm.o +0 -0
  75. data/lua-hooks/ext/luajit/src/host/buildvm_fold.c +229 -0
  76. data/lua-hooks/ext/luajit/src/host/buildvm_fold.o +0 -0
  77. data/lua-hooks/ext/luajit/src/host/buildvm_lib.c +457 -0
  78. data/lua-hooks/ext/luajit/src/host/buildvm_lib.o +0 -0
  79. data/lua-hooks/ext/luajit/src/host/buildvm_libbc.h +45 -0
  80. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.c +368 -0
  81. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.o +0 -0
  82. data/lua-hooks/ext/luajit/src/host/genlibbc.lua +197 -0
  83. data/lua-hooks/ext/luajit/src/host/genminilua.lua +428 -0
  84. data/lua-hooks/ext/luajit/src/host/minilua +0 -0
  85. data/lua-hooks/ext/luajit/src/host/minilua.c +7770 -0
  86. data/lua-hooks/ext/luajit/src/host/minilua.o +0 -0
  87. data/lua-hooks/ext/luajit/src/jit/bc.lua +190 -0
  88. data/lua-hooks/ext/luajit/src/jit/bcsave.lua +661 -0
  89. data/lua-hooks/ext/luajit/src/jit/dis_arm.lua +689 -0
  90. data/lua-hooks/ext/luajit/src/jit/dis_mips.lua +428 -0
  91. data/lua-hooks/ext/luajit/src/jit/dis_mipsel.lua +17 -0
  92. data/lua-hooks/ext/luajit/src/jit/dis_ppc.lua +591 -0
  93. data/lua-hooks/ext/luajit/src/jit/dis_x64.lua +17 -0
  94. data/lua-hooks/ext/luajit/src/jit/dis_x86.lua +838 -0
  95. data/lua-hooks/ext/luajit/src/jit/dump.lua +706 -0
  96. data/lua-hooks/ext/luajit/src/jit/p.lua +310 -0
  97. data/lua-hooks/ext/luajit/src/jit/v.lua +170 -0
  98. data/lua-hooks/ext/luajit/src/jit/vmdef.lua +362 -0
  99. data/lua-hooks/ext/luajit/src/jit/zone.lua +45 -0
  100. data/lua-hooks/ext/{lua → luajit/src}/lauxlib.h +10 -17
  101. data/lua-hooks/ext/luajit/src/lib_aux.c +356 -0
  102. data/lua-hooks/ext/luajit/src/lib_aux.o +0 -0
  103. data/lua-hooks/ext/luajit/src/lib_aux_dyn.o +0 -0
  104. data/lua-hooks/ext/luajit/src/lib_base.c +664 -0
  105. data/lua-hooks/ext/luajit/src/lib_base.o +0 -0
  106. data/lua-hooks/ext/luajit/src/lib_base_dyn.o +0 -0
  107. data/lua-hooks/ext/luajit/src/lib_bit.c +180 -0
  108. data/lua-hooks/ext/luajit/src/lib_bit.o +0 -0
  109. data/lua-hooks/ext/luajit/src/lib_bit_dyn.o +0 -0
  110. data/lua-hooks/ext/luajit/src/lib_debug.c +405 -0
  111. data/lua-hooks/ext/luajit/src/lib_debug.o +0 -0
  112. data/lua-hooks/ext/luajit/src/lib_debug_dyn.o +0 -0
  113. data/lua-hooks/ext/luajit/src/lib_ffi.c +872 -0
  114. data/lua-hooks/ext/luajit/src/lib_ffi.o +0 -0
  115. data/lua-hooks/ext/luajit/src/lib_ffi_dyn.o +0 -0
  116. data/lua-hooks/ext/luajit/src/lib_init.c +55 -0
  117. data/lua-hooks/ext/luajit/src/lib_init.o +0 -0
  118. data/lua-hooks/ext/luajit/src/lib_init_dyn.o +0 -0
  119. data/lua-hooks/ext/luajit/src/lib_io.c +541 -0
  120. data/lua-hooks/ext/luajit/src/lib_io.o +0 -0
  121. data/lua-hooks/ext/luajit/src/lib_io_dyn.o +0 -0
  122. data/lua-hooks/ext/luajit/src/lib_jit.c +767 -0
  123. data/lua-hooks/ext/luajit/src/lib_jit.o +0 -0
  124. data/lua-hooks/ext/luajit/src/lib_jit_dyn.o +0 -0
  125. data/lua-hooks/ext/luajit/src/lib_math.c +230 -0
  126. data/lua-hooks/ext/luajit/src/lib_math.o +0 -0
  127. data/lua-hooks/ext/luajit/src/lib_math_dyn.o +0 -0
  128. data/lua-hooks/ext/luajit/src/lib_os.c +292 -0
  129. data/lua-hooks/ext/luajit/src/lib_os.o +0 -0
  130. data/lua-hooks/ext/luajit/src/lib_os_dyn.o +0 -0
  131. data/lua-hooks/ext/luajit/src/lib_package.c +610 -0
  132. data/lua-hooks/ext/luajit/src/lib_package.o +0 -0
  133. data/lua-hooks/ext/luajit/src/lib_package_dyn.o +0 -0
  134. data/lua-hooks/ext/luajit/src/lib_string.c +752 -0
  135. data/lua-hooks/ext/luajit/src/lib_string.o +0 -0
  136. data/lua-hooks/ext/luajit/src/lib_string_dyn.o +0 -0
  137. data/lua-hooks/ext/luajit/src/lib_table.c +307 -0
  138. data/lua-hooks/ext/luajit/src/lib_table.o +0 -0
  139. data/lua-hooks/ext/luajit/src/lib_table_dyn.o +0 -0
  140. data/lua-hooks/ext/luajit/src/libluajit.a +0 -0
  141. data/lua-hooks/ext/luajit/src/libluajit.so +0 -0
  142. data/lua-hooks/ext/luajit/src/lj.supp +26 -0
  143. data/lua-hooks/ext/luajit/src/lj_alloc.c +1398 -0
  144. data/lua-hooks/ext/luajit/src/lj_alloc.h +17 -0
  145. data/lua-hooks/ext/luajit/src/lj_alloc.o +0 -0
  146. data/lua-hooks/ext/luajit/src/lj_alloc_dyn.o +0 -0
  147. data/lua-hooks/ext/luajit/src/lj_api.c +1210 -0
  148. data/lua-hooks/ext/luajit/src/lj_api.o +0 -0
  149. data/lua-hooks/ext/luajit/src/lj_api_dyn.o +0 -0
  150. data/lua-hooks/ext/luajit/src/lj_arch.h +509 -0
  151. data/lua-hooks/ext/luajit/src/lj_asm.c +2278 -0
  152. data/lua-hooks/ext/luajit/src/lj_asm.h +17 -0
  153. data/lua-hooks/ext/luajit/src/lj_asm.o +0 -0
  154. data/lua-hooks/ext/luajit/src/lj_asm_arm.h +2217 -0
  155. data/lua-hooks/ext/luajit/src/lj_asm_dyn.o +0 -0
  156. data/lua-hooks/ext/luajit/src/lj_asm_mips.h +1833 -0
  157. data/lua-hooks/ext/luajit/src/lj_asm_ppc.h +2015 -0
  158. data/lua-hooks/ext/luajit/src/lj_asm_x86.h +2634 -0
  159. data/lua-hooks/ext/luajit/src/lj_bc.c +14 -0
  160. data/lua-hooks/ext/luajit/src/lj_bc.h +265 -0
  161. data/lua-hooks/ext/luajit/src/lj_bc.o +0 -0
  162. data/lua-hooks/ext/luajit/src/lj_bc_dyn.o +0 -0
  163. data/lua-hooks/ext/luajit/src/lj_bcdef.h +220 -0
  164. data/lua-hooks/ext/luajit/src/lj_bcdump.h +68 -0
  165. data/lua-hooks/ext/luajit/src/lj_bcread.c +457 -0
  166. data/lua-hooks/ext/luajit/src/lj_bcread.o +0 -0
  167. data/lua-hooks/ext/luajit/src/lj_bcread_dyn.o +0 -0
  168. data/lua-hooks/ext/luajit/src/lj_bcwrite.c +361 -0
  169. data/lua-hooks/ext/luajit/src/lj_bcwrite.o +0 -0
  170. data/lua-hooks/ext/luajit/src/lj_bcwrite_dyn.o +0 -0
  171. data/lua-hooks/ext/luajit/src/lj_buf.c +234 -0
  172. data/lua-hooks/ext/luajit/src/lj_buf.h +105 -0
  173. data/lua-hooks/ext/luajit/src/lj_buf.o +0 -0
  174. data/lua-hooks/ext/luajit/src/lj_buf_dyn.o +0 -0
  175. data/lua-hooks/ext/luajit/src/lj_carith.c +429 -0
  176. data/lua-hooks/ext/luajit/src/lj_carith.h +37 -0
  177. data/lua-hooks/ext/luajit/src/lj_carith.o +0 -0
  178. data/lua-hooks/ext/luajit/src/lj_carith_dyn.o +0 -0
  179. data/lua-hooks/ext/luajit/src/lj_ccall.c +984 -0
  180. data/lua-hooks/ext/luajit/src/lj_ccall.h +178 -0
  181. data/lua-hooks/ext/luajit/src/lj_ccall.o +0 -0
  182. data/lua-hooks/ext/luajit/src/lj_ccall_dyn.o +0 -0
  183. data/lua-hooks/ext/luajit/src/lj_ccallback.c +712 -0
  184. data/lua-hooks/ext/luajit/src/lj_ccallback.h +25 -0
  185. data/lua-hooks/ext/luajit/src/lj_ccallback.o +0 -0
  186. data/lua-hooks/ext/luajit/src/lj_ccallback_dyn.o +0 -0
  187. data/lua-hooks/ext/luajit/src/lj_cconv.c +752 -0
  188. data/lua-hooks/ext/luajit/src/lj_cconv.h +70 -0
  189. data/lua-hooks/ext/luajit/src/lj_cconv.o +0 -0
  190. data/lua-hooks/ext/luajit/src/lj_cconv_dyn.o +0 -0
  191. data/lua-hooks/ext/luajit/src/lj_cdata.c +288 -0
  192. data/lua-hooks/ext/luajit/src/lj_cdata.h +76 -0
  193. data/lua-hooks/ext/luajit/src/lj_cdata.o +0 -0
  194. data/lua-hooks/ext/luajit/src/lj_cdata_dyn.o +0 -0
  195. data/lua-hooks/ext/luajit/src/lj_char.c +43 -0
  196. data/lua-hooks/ext/luajit/src/lj_char.h +42 -0
  197. data/lua-hooks/ext/luajit/src/lj_char.o +0 -0
  198. data/lua-hooks/ext/luajit/src/lj_char_dyn.o +0 -0
  199. data/lua-hooks/ext/luajit/src/lj_clib.c +418 -0
  200. data/lua-hooks/ext/luajit/src/lj_clib.h +29 -0
  201. data/lua-hooks/ext/luajit/src/lj_clib.o +0 -0
  202. data/lua-hooks/ext/luajit/src/lj_clib_dyn.o +0 -0
  203. data/lua-hooks/ext/luajit/src/lj_cparse.c +1862 -0
  204. data/lua-hooks/ext/luajit/src/lj_cparse.h +65 -0
  205. data/lua-hooks/ext/luajit/src/lj_cparse.o +0 -0
  206. data/lua-hooks/ext/luajit/src/lj_cparse_dyn.o +0 -0
  207. data/lua-hooks/ext/luajit/src/lj_crecord.c +1834 -0
  208. data/lua-hooks/ext/luajit/src/lj_crecord.h +38 -0
  209. data/lua-hooks/ext/luajit/src/lj_crecord.o +0 -0
  210. data/lua-hooks/ext/luajit/src/lj_crecord_dyn.o +0 -0
  211. data/lua-hooks/ext/luajit/src/lj_ctype.c +635 -0
  212. data/lua-hooks/ext/luajit/src/lj_ctype.h +461 -0
  213. data/lua-hooks/ext/luajit/src/lj_ctype.o +0 -0
  214. data/lua-hooks/ext/luajit/src/lj_ctype_dyn.o +0 -0
  215. data/lua-hooks/ext/luajit/src/lj_debug.c +699 -0
  216. data/lua-hooks/ext/luajit/src/lj_debug.h +65 -0
  217. data/lua-hooks/ext/luajit/src/lj_debug.o +0 -0
  218. data/lua-hooks/ext/luajit/src/lj_debug_dyn.o +0 -0
  219. data/lua-hooks/ext/luajit/src/lj_def.h +365 -0
  220. data/lua-hooks/ext/luajit/src/lj_dispatch.c +557 -0
  221. data/lua-hooks/ext/luajit/src/lj_dispatch.h +138 -0
  222. data/lua-hooks/ext/luajit/src/lj_dispatch.o +0 -0
  223. data/lua-hooks/ext/luajit/src/lj_dispatch_dyn.o +0 -0
  224. data/lua-hooks/ext/luajit/src/lj_emit_arm.h +356 -0
  225. data/lua-hooks/ext/luajit/src/lj_emit_mips.h +211 -0
  226. data/lua-hooks/ext/luajit/src/lj_emit_ppc.h +238 -0
  227. data/lua-hooks/ext/luajit/src/lj_emit_x86.h +462 -0
  228. data/lua-hooks/ext/luajit/src/lj_err.c +794 -0
  229. data/lua-hooks/ext/luajit/src/lj_err.h +41 -0
  230. data/lua-hooks/ext/luajit/src/lj_err.o +0 -0
  231. data/lua-hooks/ext/luajit/src/lj_err_dyn.o +0 -0
  232. data/lua-hooks/ext/luajit/src/lj_errmsg.h +190 -0
  233. data/lua-hooks/ext/luajit/src/lj_ff.h +18 -0
  234. data/lua-hooks/ext/luajit/src/lj_ffdef.h +209 -0
  235. data/lua-hooks/ext/luajit/src/lj_ffrecord.c +1247 -0
  236. data/lua-hooks/ext/luajit/src/lj_ffrecord.h +24 -0
  237. data/lua-hooks/ext/luajit/src/lj_ffrecord.o +0 -0
  238. data/lua-hooks/ext/luajit/src/lj_ffrecord_dyn.o +0 -0
  239. data/lua-hooks/ext/luajit/src/lj_folddef.h +1138 -0
  240. data/lua-hooks/ext/luajit/src/lj_frame.h +259 -0
  241. data/lua-hooks/ext/luajit/src/lj_func.c +185 -0
  242. data/lua-hooks/ext/luajit/src/lj_func.h +24 -0
  243. data/lua-hooks/ext/luajit/src/lj_func.o +0 -0
  244. data/lua-hooks/ext/luajit/src/lj_func_dyn.o +0 -0
  245. data/lua-hooks/ext/luajit/src/lj_gc.c +845 -0
  246. data/lua-hooks/ext/luajit/src/lj_gc.h +134 -0
  247. data/lua-hooks/ext/luajit/src/lj_gc.o +0 -0
  248. data/lua-hooks/ext/luajit/src/lj_gc_dyn.o +0 -0
  249. data/lua-hooks/ext/luajit/src/lj_gdbjit.c +787 -0
  250. data/lua-hooks/ext/luajit/src/lj_gdbjit.h +22 -0
  251. data/lua-hooks/ext/luajit/src/lj_gdbjit.o +0 -0
  252. data/lua-hooks/ext/luajit/src/lj_gdbjit_dyn.o +0 -0
  253. data/lua-hooks/ext/luajit/src/lj_ir.c +505 -0
  254. data/lua-hooks/ext/luajit/src/lj_ir.h +577 -0
  255. data/lua-hooks/ext/luajit/src/lj_ir.o +0 -0
  256. data/lua-hooks/ext/luajit/src/lj_ir_dyn.o +0 -0
  257. data/lua-hooks/ext/luajit/src/lj_ircall.h +321 -0
  258. data/lua-hooks/ext/luajit/src/lj_iropt.h +161 -0
  259. data/lua-hooks/ext/luajit/src/lj_jit.h +440 -0
  260. data/lua-hooks/ext/luajit/src/lj_lex.c +482 -0
  261. data/lua-hooks/ext/luajit/src/lj_lex.h +86 -0
  262. data/lua-hooks/ext/luajit/src/lj_lex.o +0 -0
  263. data/lua-hooks/ext/luajit/src/lj_lex_dyn.o +0 -0
  264. data/lua-hooks/ext/luajit/src/lj_lib.c +303 -0
  265. data/lua-hooks/ext/luajit/src/lj_lib.h +115 -0
  266. data/lua-hooks/ext/luajit/src/lj_lib.o +0 -0
  267. data/lua-hooks/ext/luajit/src/lj_lib_dyn.o +0 -0
  268. data/lua-hooks/ext/luajit/src/lj_libdef.h +414 -0
  269. data/lua-hooks/ext/luajit/src/lj_load.c +168 -0
  270. data/lua-hooks/ext/luajit/src/lj_load.o +0 -0
  271. data/lua-hooks/ext/luajit/src/lj_load_dyn.o +0 -0
  272. data/lua-hooks/ext/luajit/src/lj_mcode.c +386 -0
  273. data/lua-hooks/ext/luajit/src/lj_mcode.h +30 -0
  274. data/lua-hooks/ext/luajit/src/lj_mcode.o +0 -0
  275. data/lua-hooks/ext/luajit/src/lj_mcode_dyn.o +0 -0
  276. data/lua-hooks/ext/luajit/src/lj_meta.c +477 -0
  277. data/lua-hooks/ext/luajit/src/lj_meta.h +38 -0
  278. data/lua-hooks/ext/luajit/src/lj_meta.o +0 -0
  279. data/lua-hooks/ext/luajit/src/lj_meta_dyn.o +0 -0
  280. data/lua-hooks/ext/luajit/src/lj_obj.c +50 -0
  281. data/lua-hooks/ext/luajit/src/lj_obj.h +976 -0
  282. data/lua-hooks/ext/luajit/src/lj_obj.o +0 -0
  283. data/lua-hooks/ext/luajit/src/lj_obj_dyn.o +0 -0
  284. data/lua-hooks/ext/luajit/src/lj_opt_dce.c +78 -0
  285. data/lua-hooks/ext/luajit/src/lj_opt_dce.o +0 -0
  286. data/lua-hooks/ext/luajit/src/lj_opt_dce_dyn.o +0 -0
  287. data/lua-hooks/ext/luajit/src/lj_opt_fold.c +2488 -0
  288. data/lua-hooks/ext/luajit/src/lj_opt_fold.o +0 -0
  289. data/lua-hooks/ext/luajit/src/lj_opt_fold_dyn.o +0 -0
  290. data/lua-hooks/ext/luajit/src/lj_opt_loop.c +449 -0
  291. data/lua-hooks/ext/luajit/src/lj_opt_loop.o +0 -0
  292. data/lua-hooks/ext/luajit/src/lj_opt_loop_dyn.o +0 -0
  293. data/lua-hooks/ext/luajit/src/lj_opt_mem.c +935 -0
  294. data/lua-hooks/ext/luajit/src/lj_opt_mem.o +0 -0
  295. data/lua-hooks/ext/luajit/src/lj_opt_mem_dyn.o +0 -0
  296. data/lua-hooks/ext/luajit/src/lj_opt_narrow.c +652 -0
  297. data/lua-hooks/ext/luajit/src/lj_opt_narrow.o +0 -0
  298. data/lua-hooks/ext/luajit/src/lj_opt_narrow_dyn.o +0 -0
  299. data/lua-hooks/ext/luajit/src/lj_opt_sink.c +245 -0
  300. data/lua-hooks/ext/luajit/src/lj_opt_sink.o +0 -0
  301. data/lua-hooks/ext/luajit/src/lj_opt_sink_dyn.o +0 -0
  302. data/lua-hooks/ext/luajit/src/lj_opt_split.c +856 -0
  303. data/lua-hooks/ext/luajit/src/lj_opt_split.o +0 -0
  304. data/lua-hooks/ext/luajit/src/lj_opt_split_dyn.o +0 -0
  305. data/lua-hooks/ext/luajit/src/lj_parse.c +2725 -0
  306. data/lua-hooks/ext/luajit/src/lj_parse.h +18 -0
  307. data/lua-hooks/ext/luajit/src/lj_parse.o +0 -0
  308. data/lua-hooks/ext/luajit/src/lj_parse_dyn.o +0 -0
  309. data/lua-hooks/ext/luajit/src/lj_profile.c +368 -0
  310. data/lua-hooks/ext/luajit/src/lj_profile.h +21 -0
  311. data/lua-hooks/ext/luajit/src/lj_profile.o +0 -0
  312. data/lua-hooks/ext/luajit/src/lj_profile_dyn.o +0 -0
  313. data/lua-hooks/ext/luajit/src/lj_recdef.h +270 -0
  314. data/lua-hooks/ext/luajit/src/lj_record.c +2554 -0
  315. data/lua-hooks/ext/luajit/src/lj_record.h +45 -0
  316. data/lua-hooks/ext/luajit/src/lj_record.o +0 -0
  317. data/lua-hooks/ext/luajit/src/lj_record_dyn.o +0 -0
  318. data/lua-hooks/ext/luajit/src/lj_snap.c +870 -0
  319. data/lua-hooks/ext/luajit/src/lj_snap.h +34 -0
  320. data/lua-hooks/ext/luajit/src/lj_snap.o +0 -0
  321. data/lua-hooks/ext/luajit/src/lj_snap_dyn.o +0 -0
  322. data/lua-hooks/ext/luajit/src/lj_state.c +300 -0
  323. data/lua-hooks/ext/luajit/src/lj_state.h +35 -0
  324. data/lua-hooks/ext/luajit/src/lj_state.o +0 -0
  325. data/lua-hooks/ext/luajit/src/lj_state_dyn.o +0 -0
  326. data/lua-hooks/ext/luajit/src/lj_str.c +197 -0
  327. data/lua-hooks/ext/luajit/src/lj_str.h +27 -0
  328. data/lua-hooks/ext/luajit/src/lj_str.o +0 -0
  329. data/lua-hooks/ext/luajit/src/lj_str_dyn.o +0 -0
  330. data/lua-hooks/ext/luajit/src/lj_strfmt.c +554 -0
  331. data/lua-hooks/ext/luajit/src/lj_strfmt.h +125 -0
  332. data/lua-hooks/ext/luajit/src/lj_strfmt.o +0 -0
  333. data/lua-hooks/ext/luajit/src/lj_strfmt_dyn.o +0 -0
  334. data/lua-hooks/ext/luajit/src/lj_strscan.c +547 -0
  335. data/lua-hooks/ext/luajit/src/lj_strscan.h +39 -0
  336. data/lua-hooks/ext/luajit/src/lj_strscan.o +0 -0
  337. data/lua-hooks/ext/luajit/src/lj_strscan_dyn.o +0 -0
  338. data/lua-hooks/ext/luajit/src/lj_tab.c +666 -0
  339. data/lua-hooks/ext/luajit/src/lj_tab.h +73 -0
  340. data/lua-hooks/ext/luajit/src/lj_tab.o +0 -0
  341. data/lua-hooks/ext/luajit/src/lj_tab_dyn.o +0 -0
  342. data/lua-hooks/ext/luajit/src/lj_target.h +164 -0
  343. data/lua-hooks/ext/luajit/src/lj_target_arm.h +270 -0
  344. data/lua-hooks/ext/luajit/src/lj_target_arm64.h +97 -0
  345. data/lua-hooks/ext/luajit/src/lj_target_mips.h +260 -0
  346. data/lua-hooks/ext/luajit/src/lj_target_ppc.h +280 -0
  347. data/lua-hooks/ext/luajit/src/lj_target_x86.h +345 -0
  348. data/lua-hooks/ext/luajit/src/lj_trace.c +859 -0
  349. data/lua-hooks/ext/luajit/src/lj_trace.h +54 -0
  350. data/lua-hooks/ext/luajit/src/lj_trace.o +0 -0
  351. data/lua-hooks/ext/luajit/src/lj_trace_dyn.o +0 -0
  352. data/lua-hooks/ext/luajit/src/lj_traceerr.h +63 -0
  353. data/lua-hooks/ext/luajit/src/lj_udata.c +34 -0
  354. data/lua-hooks/ext/luajit/src/lj_udata.h +14 -0
  355. data/lua-hooks/ext/luajit/src/lj_udata.o +0 -0
  356. data/lua-hooks/ext/luajit/src/lj_udata_dyn.o +0 -0
  357. data/lua-hooks/ext/luajit/src/lj_vm.S +2730 -0
  358. data/lua-hooks/ext/luajit/src/lj_vm.h +114 -0
  359. data/lua-hooks/ext/luajit/src/lj_vm.o +0 -0
  360. data/lua-hooks/ext/luajit/src/lj_vm_dyn.o +0 -0
  361. data/lua-hooks/ext/luajit/src/lj_vmevent.c +58 -0
  362. data/lua-hooks/ext/luajit/src/lj_vmevent.h +59 -0
  363. data/lua-hooks/ext/luajit/src/lj_vmevent.o +0 -0
  364. data/lua-hooks/ext/luajit/src/lj_vmevent_dyn.o +0 -0
  365. data/lua-hooks/ext/luajit/src/lj_vmmath.c +152 -0
  366. data/lua-hooks/ext/luajit/src/lj_vmmath.o +0 -0
  367. data/lua-hooks/ext/luajit/src/lj_vmmath_dyn.o +0 -0
  368. data/lua-hooks/ext/luajit/src/ljamalg.c +96 -0
  369. data/lua-hooks/ext/{lua → luajit/src}/lua.h +12 -7
  370. data/lua-hooks/ext/luajit/src/lua.hpp +9 -0
  371. data/lua-hooks/ext/luajit/src/luaconf.h +156 -0
  372. data/lua-hooks/ext/luajit/src/luajit +0 -0
  373. data/lua-hooks/ext/luajit/src/luajit.c +570 -0
  374. data/lua-hooks/ext/luajit/src/luajit.h +79 -0
  375. data/lua-hooks/ext/luajit/src/luajit.o +0 -0
  376. data/lua-hooks/ext/luajit/src/lualib.h +43 -0
  377. data/lua-hooks/ext/luajit/src/msvcbuild.bat +114 -0
  378. data/lua-hooks/ext/luajit/src/ps4build.bat +103 -0
  379. data/lua-hooks/ext/luajit/src/psvitabuild.bat +93 -0
  380. data/lua-hooks/ext/luajit/src/vm_arm.dasc +4585 -0
  381. data/lua-hooks/ext/luajit/src/vm_arm64.dasc +3764 -0
  382. data/lua-hooks/ext/luajit/src/vm_mips.dasc +4355 -0
  383. data/lua-hooks/ext/luajit/src/vm_ppc.dasc +5252 -0
  384. data/lua-hooks/ext/luajit/src/vm_x64.dasc +4902 -0
  385. data/lua-hooks/ext/luajit/src/vm_x86.dasc +5710 -0
  386. data/lua-hooks/ext/luajit/src/xb1build.bat +101 -0
  387. data/lua-hooks/ext/luajit/src/xedkbuild.bat +92 -0
  388. data/lua-hooks/ext/luautf8/lutf8lib.c +3 -3
  389. data/lua-hooks/lib/boot.lua +37 -2
  390. metadata +372 -69
  391. data/lua-hooks/ext/bitop/README +0 -22
  392. data/lua-hooks/ext/bitop/bit.c +0 -189
  393. data/lua-hooks/ext/extconf.rb +0 -38
  394. data/lua-hooks/ext/lua/COPYRIGHT +0 -34
  395. data/lua-hooks/ext/lua/lapi.c +0 -1087
  396. data/lua-hooks/ext/lua/lapi.h +0 -16
  397. data/lua-hooks/ext/lua/lauxlib.c +0 -652
  398. data/lua-hooks/ext/lua/lbaselib.c +0 -659
  399. data/lua-hooks/ext/lua/lcode.c +0 -831
  400. data/lua-hooks/ext/lua/lcode.h +0 -76
  401. data/lua-hooks/ext/lua/ldblib.c +0 -398
  402. data/lua-hooks/ext/lua/ldebug.c +0 -638
  403. data/lua-hooks/ext/lua/ldebug.h +0 -33
  404. data/lua-hooks/ext/lua/ldo.c +0 -519
  405. data/lua-hooks/ext/lua/ldo.h +0 -57
  406. data/lua-hooks/ext/lua/ldump.c +0 -164
  407. data/lua-hooks/ext/lua/lfunc.c +0 -174
  408. data/lua-hooks/ext/lua/lfunc.h +0 -34
  409. data/lua-hooks/ext/lua/lgc.c +0 -710
  410. data/lua-hooks/ext/lua/lgc.h +0 -110
  411. data/lua-hooks/ext/lua/linit.c +0 -38
  412. data/lua-hooks/ext/lua/liolib.c +0 -556
  413. data/lua-hooks/ext/lua/llex.c +0 -463
  414. data/lua-hooks/ext/lua/llex.h +0 -81
  415. data/lua-hooks/ext/lua/llimits.h +0 -128
  416. data/lua-hooks/ext/lua/lmathlib.c +0 -263
  417. data/lua-hooks/ext/lua/lmem.c +0 -86
  418. data/lua-hooks/ext/lua/lmem.h +0 -49
  419. data/lua-hooks/ext/lua/loadlib.c +0 -705
  420. data/lua-hooks/ext/lua/loadlib_rel.c +0 -760
  421. data/lua-hooks/ext/lua/lobject.c +0 -214
  422. data/lua-hooks/ext/lua/lobject.h +0 -381
  423. data/lua-hooks/ext/lua/lopcodes.c +0 -102
  424. data/lua-hooks/ext/lua/lopcodes.h +0 -268
  425. data/lua-hooks/ext/lua/loslib.c +0 -243
  426. data/lua-hooks/ext/lua/lparser.c +0 -1339
  427. data/lua-hooks/ext/lua/lparser.h +0 -82
  428. data/lua-hooks/ext/lua/lstate.c +0 -214
  429. data/lua-hooks/ext/lua/lstate.h +0 -169
  430. data/lua-hooks/ext/lua/lstring.c +0 -111
  431. data/lua-hooks/ext/lua/lstring.h +0 -31
  432. data/lua-hooks/ext/lua/lstrlib.c +0 -871
  433. data/lua-hooks/ext/lua/ltable.c +0 -588
  434. data/lua-hooks/ext/lua/ltable.h +0 -40
  435. data/lua-hooks/ext/lua/ltablib.c +0 -287
  436. data/lua-hooks/ext/lua/ltm.c +0 -75
  437. data/lua-hooks/ext/lua/ltm.h +0 -54
  438. data/lua-hooks/ext/lua/lua.c +0 -392
  439. data/lua-hooks/ext/lua/lua.def +0 -131
  440. data/lua-hooks/ext/lua/lua.rc +0 -28
  441. data/lua-hooks/ext/lua/lua_dll.rc +0 -26
  442. data/lua-hooks/ext/lua/luac.c +0 -200
  443. data/lua-hooks/ext/lua/luac.rc +0 -1
  444. data/lua-hooks/ext/lua/luaconf.h +0 -763
  445. data/lua-hooks/ext/lua/luaconf.h.in +0 -724
  446. data/lua-hooks/ext/lua/luaconf.h.orig +0 -763
  447. data/lua-hooks/ext/lua/lualib.h +0 -53
  448. data/lua-hooks/ext/lua/lundump.c +0 -227
  449. data/lua-hooks/ext/lua/lundump.h +0 -36
  450. data/lua-hooks/ext/lua/lvm.c +0 -767
  451. data/lua-hooks/ext/lua/lvm.h +0 -36
  452. data/lua-hooks/ext/lua/lzio.c +0 -82
  453. data/lua-hooks/ext/lua/lzio.h +0 -67
  454. data/lua-hooks/ext/lua/print.c +0 -227
@@ -0,0 +1,134 @@
1
+ /*
2
+ ** Garbage collector.
3
+ ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4
+ */
5
+
6
+ #ifndef _LJ_GC_H
7
+ #define _LJ_GC_H
8
+
9
+ #include "lj_obj.h"
10
+
11
+ /* Garbage collector states. Order matters. */
12
+ enum {
13
+ GCSpause, GCSpropagate, GCSatomic, GCSsweepstring, GCSsweep, GCSfinalize
14
+ };
15
+
16
+ /* Bitmasks for marked field of GCobj. */
17
+ #define LJ_GC_WHITE0 0x01
18
+ #define LJ_GC_WHITE1 0x02
19
+ #define LJ_GC_BLACK 0x04
20
+ #define LJ_GC_FINALIZED 0x08
21
+ #define LJ_GC_WEAKKEY 0x08
22
+ #define LJ_GC_WEAKVAL 0x10
23
+ #define LJ_GC_CDATA_FIN 0x10
24
+ #define LJ_GC_FIXED 0x20
25
+ #define LJ_GC_SFIXED 0x40
26
+
27
+ #define LJ_GC_WHITES (LJ_GC_WHITE0 | LJ_GC_WHITE1)
28
+ #define LJ_GC_COLORS (LJ_GC_WHITES | LJ_GC_BLACK)
29
+ #define LJ_GC_WEAK (LJ_GC_WEAKKEY | LJ_GC_WEAKVAL)
30
+
31
+ /* Macros to test and set GCobj colors. */
32
+ #define iswhite(x) ((x)->gch.marked & LJ_GC_WHITES)
33
+ #define isblack(x) ((x)->gch.marked & LJ_GC_BLACK)
34
+ #define isgray(x) (!((x)->gch.marked & (LJ_GC_BLACK|LJ_GC_WHITES)))
35
+ #define tviswhite(x) (tvisgcv(x) && iswhite(gcV(x)))
36
+ #define otherwhite(g) (g->gc.currentwhite ^ LJ_GC_WHITES)
37
+ #define isdead(g, v) ((v)->gch.marked & otherwhite(g) & LJ_GC_WHITES)
38
+
39
+ #define curwhite(g) ((g)->gc.currentwhite & LJ_GC_WHITES)
40
+ #define newwhite(g, x) (obj2gco(x)->gch.marked = (uint8_t)curwhite(g))
41
+ #define makewhite(g, x) \
42
+ ((x)->gch.marked = ((x)->gch.marked & (uint8_t)~LJ_GC_COLORS) | curwhite(g))
43
+ #define flipwhite(x) ((x)->gch.marked ^= LJ_GC_WHITES)
44
+ #define black2gray(x) ((x)->gch.marked &= (uint8_t)~LJ_GC_BLACK)
45
+ #define fixstring(s) ((s)->marked |= LJ_GC_FIXED)
46
+ #define markfinalized(x) ((x)->gch.marked |= LJ_GC_FINALIZED)
47
+
48
+ /* Collector. */
49
+ LJ_FUNC size_t lj_gc_separateudata(global_State *g, int all);
50
+ LJ_FUNC void lj_gc_finalize_udata(lua_State *L);
51
+ #if LJ_HASFFI
52
+ LJ_FUNC void lj_gc_finalize_cdata(lua_State *L);
53
+ #else
54
+ #define lj_gc_finalize_cdata(L) UNUSED(L)
55
+ #endif
56
+ LJ_FUNC void lj_gc_freeall(global_State *g);
57
+ LJ_FUNCA int LJ_FASTCALL lj_gc_step(lua_State *L);
58
+ LJ_FUNCA void LJ_FASTCALL lj_gc_step_fixtop(lua_State *L);
59
+ #if LJ_HASJIT
60
+ LJ_FUNC int LJ_FASTCALL lj_gc_step_jit(global_State *g, MSize steps);
61
+ #endif
62
+ LJ_FUNC void lj_gc_fullgc(lua_State *L);
63
+
64
+ /* GC check: drive collector forward if the GC threshold has been reached. */
65
+ #define lj_gc_check(L) \
66
+ { if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) \
67
+ lj_gc_step(L); }
68
+ #define lj_gc_check_fixtop(L) \
69
+ { if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) \
70
+ lj_gc_step_fixtop(L); }
71
+
72
+ /* Write barriers. */
73
+ LJ_FUNC void lj_gc_barrierf(global_State *g, GCobj *o, GCobj *v);
74
+ LJ_FUNCA void LJ_FASTCALL lj_gc_barrieruv(global_State *g, TValue *tv);
75
+ LJ_FUNC void lj_gc_closeuv(global_State *g, GCupval *uv);
76
+ #if LJ_HASJIT
77
+ LJ_FUNC void lj_gc_barriertrace(global_State *g, uint32_t traceno);
78
+ #endif
79
+
80
+ /* Move the GC propagation frontier back for tables (make it gray again). */
81
+ static LJ_AINLINE void lj_gc_barrierback(global_State *g, GCtab *t)
82
+ {
83
+ GCobj *o = obj2gco(t);
84
+ lua_assert(isblack(o) && !isdead(g, o));
85
+ lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause);
86
+ black2gray(o);
87
+ setgcrefr(t->gclist, g->gc.grayagain);
88
+ setgcref(g->gc.grayagain, o);
89
+ }
90
+
91
+ /* Barrier for stores to table objects. TValue and GCobj variant. */
92
+ #define lj_gc_anybarriert(L, t) \
93
+ { if (LJ_UNLIKELY(isblack(obj2gco(t)))) lj_gc_barrierback(G(L), (t)); }
94
+ #define lj_gc_barriert(L, t, tv) \
95
+ { if (tviswhite(tv) && isblack(obj2gco(t))) \
96
+ lj_gc_barrierback(G(L), (t)); }
97
+ #define lj_gc_objbarriert(L, t, o) \
98
+ { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) \
99
+ lj_gc_barrierback(G(L), (t)); }
100
+
101
+ /* Barrier for stores to any other object. TValue and GCobj variant. */
102
+ #define lj_gc_barrier(L, p, tv) \
103
+ { if (tviswhite(tv) && isblack(obj2gco(p))) \
104
+ lj_gc_barrierf(G(L), obj2gco(p), gcV(tv)); }
105
+ #define lj_gc_objbarrier(L, p, o) \
106
+ { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
107
+ lj_gc_barrierf(G(L), obj2gco(p), obj2gco(o)); }
108
+
109
+ /* Allocator. */
110
+ LJ_FUNC void *lj_mem_realloc(lua_State *L, void *p, GCSize osz, GCSize nsz);
111
+ LJ_FUNC void * LJ_FASTCALL lj_mem_newgco(lua_State *L, GCSize size);
112
+ LJ_FUNC void *lj_mem_grow(lua_State *L, void *p,
113
+ MSize *szp, MSize lim, MSize esz);
114
+
115
+ #define lj_mem_new(L, s) lj_mem_realloc(L, NULL, 0, (s))
116
+
117
+ static LJ_AINLINE void lj_mem_free(global_State *g, void *p, size_t osize)
118
+ {
119
+ g->gc.total -= (GCSize)osize;
120
+ g->allocf(g->allocd, p, osize, 0);
121
+ }
122
+
123
+ #define lj_mem_newvec(L, n, t) ((t *)lj_mem_new(L, (GCSize)((n)*sizeof(t))))
124
+ #define lj_mem_reallocvec(L, p, on, n, t) \
125
+ ((p) = (t *)lj_mem_realloc(L, p, (on)*sizeof(t), (GCSize)((n)*sizeof(t))))
126
+ #define lj_mem_growvec(L, p, n, m, t) \
127
+ ((p) = (t *)lj_mem_grow(L, (p), &(n), (m), (MSize)sizeof(t)))
128
+ #define lj_mem_freevec(g, p, n, t) lj_mem_free(g, (p), (n)*sizeof(t))
129
+
130
+ #define lj_mem_newobj(L, t) ((t *)lj_mem_newgco(L, sizeof(t)))
131
+ #define lj_mem_newt(L, s, t) ((t *)lj_mem_new(L, (s)))
132
+ #define lj_mem_freet(g, p) lj_mem_free(g, (p), sizeof(*(p)))
133
+
134
+ #endif
@@ -0,0 +1,787 @@
1
+ /*
2
+ ** Client for the GDB JIT API.
3
+ ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
4
+ */
5
+
6
+ #define lj_gdbjit_c
7
+ #define LUA_CORE
8
+
9
+ #include "lj_obj.h"
10
+
11
+ #if LJ_HASJIT
12
+
13
+ #include "lj_gc.h"
14
+ #include "lj_err.h"
15
+ #include "lj_debug.h"
16
+ #include "lj_frame.h"
17
+ #include "lj_buf.h"
18
+ #include "lj_strfmt.h"
19
+ #include "lj_jit.h"
20
+ #include "lj_dispatch.h"
21
+
22
+ /* This is not compiled in by default.
23
+ ** Enable with -DLUAJIT_USE_GDBJIT in the Makefile and recompile everything.
24
+ */
25
+ #ifdef LUAJIT_USE_GDBJIT
26
+
27
+ /* The GDB JIT API allows JIT compilers to pass debug information about
28
+ ** JIT-compiled code back to GDB. You need at least GDB 7.0 or higher
29
+ ** to see it in action.
30
+ **
31
+ ** This is a passive API, so it works even when not running under GDB
32
+ ** or when attaching to an already running process. Alas, this implies
33
+ ** enabling it always has a non-negligible overhead -- do not use in
34
+ ** release mode!
35
+ **
36
+ ** The LuaJIT GDB JIT client is rather minimal at the moment. It gives
37
+ ** each trace a symbol name and adds a source location and frame unwind
38
+ ** information. Obviously LuaJIT itself and any embedding C application
39
+ ** should be compiled with debug symbols, too (see the Makefile).
40
+ **
41
+ ** Traces are named TRACE_1, TRACE_2, ... these correspond to the trace
42
+ ** numbers from -jv or -jdump. Use "break TRACE_1" or "tbreak TRACE_1" etc.
43
+ ** to set breakpoints on specific traces (even ahead of their creation).
44
+ **
45
+ ** The source location for each trace allows listing the corresponding
46
+ ** source lines with the GDB command "list" (but only if the Lua source
47
+ ** has been loaded from a file). Currently this is always set to the
48
+ ** location where the trace has been started.
49
+ **
50
+ ** Frame unwind information can be inspected with the GDB command
51
+ ** "info frame". This also allows proper backtraces across JIT-compiled
52
+ ** code with the GDB command "bt".
53
+ **
54
+ ** You probably want to add the following settings to a .gdbinit file
55
+ ** (or add them to ~/.gdbinit):
56
+ ** set disassembly-flavor intel
57
+ ** set breakpoint pending on
58
+ **
59
+ ** Here's a sample GDB session:
60
+ ** ------------------------------------------------------------------------
61
+
62
+ $ cat >x.lua
63
+ for outer=1,100 do
64
+ for inner=1,100 do end
65
+ end
66
+ ^D
67
+
68
+ $ luajit -jv x.lua
69
+ [TRACE 1 x.lua:2]
70
+ [TRACE 2 (1/3) x.lua:1 -> 1]
71
+
72
+ $ gdb --quiet --args luajit x.lua
73
+ (gdb) tbreak TRACE_1
74
+ Function "TRACE_1" not defined.
75
+ Temporary breakpoint 1 (TRACE_1) pending.
76
+ (gdb) run
77
+ Starting program: luajit x.lua
78
+
79
+ Temporary breakpoint 1, TRACE_1 () at x.lua:2
80
+ 2 for inner=1,100 do end
81
+ (gdb) list
82
+ 1 for outer=1,100 do
83
+ 2 for inner=1,100 do end
84
+ 3 end
85
+ (gdb) bt
86
+ #0 TRACE_1 () at x.lua:2
87
+ #1 0x08053690 in lua_pcall [...]
88
+ [...]
89
+ #7 0x0806ff90 in main [...]
90
+ (gdb) disass TRACE_1
91
+ Dump of assembler code for function TRACE_1:
92
+ 0xf7fd9fba <TRACE_1+0>: mov DWORD PTR ds:0xf7e0e2a0,0x1
93
+ 0xf7fd9fc4 <TRACE_1+10>: movsd xmm7,QWORD PTR [edx+0x20]
94
+ [...]
95
+ 0xf7fd9ff8 <TRACE_1+62>: jmp 0xf7fd2014
96
+ End of assembler dump.
97
+ (gdb) tbreak TRACE_2
98
+ Function "TRACE_2" not defined.
99
+ Temporary breakpoint 2 (TRACE_2) pending.
100
+ (gdb) cont
101
+ Continuing.
102
+
103
+ Temporary breakpoint 2, TRACE_2 () at x.lua:1
104
+ 1 for outer=1,100 do
105
+ (gdb) info frame
106
+ Stack level 0, frame at 0xffffd7c0:
107
+ eip = 0xf7fd9f60 in TRACE_2 (x.lua:1); saved eip 0x8053690
108
+ called by frame at 0xffffd7e0
109
+ source language unknown.
110
+ Arglist at 0xffffd78c, args:
111
+ Locals at 0xffffd78c, Previous frame's sp is 0xffffd7c0
112
+ Saved registers:
113
+ ebx at 0xffffd7ac, ebp at 0xffffd7b8, esi at 0xffffd7b0, edi at 0xffffd7b4,
114
+ eip at 0xffffd7bc
115
+ (gdb)
116
+
117
+ ** ------------------------------------------------------------------------
118
+ */
119
+
120
+ /* -- GDB JIT API --------------------------------------------------------- */
121
+
122
+ /* GDB JIT actions. */
123
+ enum {
124
+ GDBJIT_NOACTION = 0,
125
+ GDBJIT_REGISTER,
126
+ GDBJIT_UNREGISTER
127
+ };
128
+
129
+ /* GDB JIT entry. */
130
+ typedef struct GDBJITentry {
131
+ struct GDBJITentry *next_entry;
132
+ struct GDBJITentry *prev_entry;
133
+ const char *symfile_addr;
134
+ uint64_t symfile_size;
135
+ } GDBJITentry;
136
+
137
+ /* GDB JIT descriptor. */
138
+ typedef struct GDBJITdesc {
139
+ uint32_t version;
140
+ uint32_t action_flag;
141
+ GDBJITentry *relevant_entry;
142
+ GDBJITentry *first_entry;
143
+ } GDBJITdesc;
144
+
145
+ GDBJITdesc __jit_debug_descriptor = {
146
+ 1, GDBJIT_NOACTION, NULL, NULL
147
+ };
148
+
149
+ /* GDB sets a breakpoint at this function. */
150
+ void LJ_NOINLINE __jit_debug_register_code()
151
+ {
152
+ __asm__ __volatile__("");
153
+ };
154
+
155
+ /* -- In-memory ELF object definitions ------------------------------------ */
156
+
157
+ /* ELF definitions. */
158
+ typedef struct ELFheader {
159
+ uint8_t emagic[4];
160
+ uint8_t eclass;
161
+ uint8_t eendian;
162
+ uint8_t eversion;
163
+ uint8_t eosabi;
164
+ uint8_t eabiversion;
165
+ uint8_t epad[7];
166
+ uint16_t type;
167
+ uint16_t machine;
168
+ uint32_t version;
169
+ uintptr_t entry;
170
+ uintptr_t phofs;
171
+ uintptr_t shofs;
172
+ uint32_t flags;
173
+ uint16_t ehsize;
174
+ uint16_t phentsize;
175
+ uint16_t phnum;
176
+ uint16_t shentsize;
177
+ uint16_t shnum;
178
+ uint16_t shstridx;
179
+ } ELFheader;
180
+
181
+ typedef struct ELFsectheader {
182
+ uint32_t name;
183
+ uint32_t type;
184
+ uintptr_t flags;
185
+ uintptr_t addr;
186
+ uintptr_t ofs;
187
+ uintptr_t size;
188
+ uint32_t link;
189
+ uint32_t info;
190
+ uintptr_t align;
191
+ uintptr_t entsize;
192
+ } ELFsectheader;
193
+
194
+ #define ELFSECT_IDX_ABS 0xfff1
195
+
196
+ enum {
197
+ ELFSECT_TYPE_PROGBITS = 1,
198
+ ELFSECT_TYPE_SYMTAB = 2,
199
+ ELFSECT_TYPE_STRTAB = 3,
200
+ ELFSECT_TYPE_NOBITS = 8
201
+ };
202
+
203
+ #define ELFSECT_FLAGS_WRITE 1
204
+ #define ELFSECT_FLAGS_ALLOC 2
205
+ #define ELFSECT_FLAGS_EXEC 4
206
+
207
+ typedef struct ELFsymbol {
208
+ #if LJ_64
209
+ uint32_t name;
210
+ uint8_t info;
211
+ uint8_t other;
212
+ uint16_t sectidx;
213
+ uintptr_t value;
214
+ uint64_t size;
215
+ #else
216
+ uint32_t name;
217
+ uintptr_t value;
218
+ uint32_t size;
219
+ uint8_t info;
220
+ uint8_t other;
221
+ uint16_t sectidx;
222
+ #endif
223
+ } ELFsymbol;
224
+
225
+ enum {
226
+ ELFSYM_TYPE_FUNC = 2,
227
+ ELFSYM_TYPE_FILE = 4,
228
+ ELFSYM_BIND_LOCAL = 0 << 4,
229
+ ELFSYM_BIND_GLOBAL = 1 << 4,
230
+ };
231
+
232
+ /* DWARF definitions. */
233
+ #define DW_CIE_VERSION 1
234
+
235
+ enum {
236
+ DW_CFA_nop = 0x0,
237
+ DW_CFA_offset_extended = 0x5,
238
+ DW_CFA_def_cfa = 0xc,
239
+ DW_CFA_def_cfa_offset = 0xe,
240
+ DW_CFA_offset_extended_sf = 0x11,
241
+ DW_CFA_advance_loc = 0x40,
242
+ DW_CFA_offset = 0x80
243
+ };
244
+
245
+ enum {
246
+ DW_EH_PE_udata4 = 3,
247
+ DW_EH_PE_textrel = 0x20
248
+ };
249
+
250
+ enum {
251
+ DW_TAG_compile_unit = 0x11
252
+ };
253
+
254
+ enum {
255
+ DW_children_no = 0,
256
+ DW_children_yes = 1
257
+ };
258
+
259
+ enum {
260
+ DW_AT_name = 0x03,
261
+ DW_AT_stmt_list = 0x10,
262
+ DW_AT_low_pc = 0x11,
263
+ DW_AT_high_pc = 0x12
264
+ };
265
+
266
+ enum {
267
+ DW_FORM_addr = 0x01,
268
+ DW_FORM_data4 = 0x06,
269
+ DW_FORM_string = 0x08
270
+ };
271
+
272
+ enum {
273
+ DW_LNS_extended_op = 0,
274
+ DW_LNS_copy = 1,
275
+ DW_LNS_advance_pc = 2,
276
+ DW_LNS_advance_line = 3
277
+ };
278
+
279
+ enum {
280
+ DW_LNE_end_sequence = 1,
281
+ DW_LNE_set_address = 2
282
+ };
283
+
284
+ enum {
285
+ #if LJ_TARGET_X86
286
+ DW_REG_AX, DW_REG_CX, DW_REG_DX, DW_REG_BX,
287
+ DW_REG_SP, DW_REG_BP, DW_REG_SI, DW_REG_DI,
288
+ DW_REG_RA,
289
+ #elif LJ_TARGET_X64
290
+ /* Yes, the order is strange, but correct. */
291
+ DW_REG_AX, DW_REG_DX, DW_REG_CX, DW_REG_BX,
292
+ DW_REG_SI, DW_REG_DI, DW_REG_BP, DW_REG_SP,
293
+ DW_REG_8, DW_REG_9, DW_REG_10, DW_REG_11,
294
+ DW_REG_12, DW_REG_13, DW_REG_14, DW_REG_15,
295
+ DW_REG_RA,
296
+ #elif LJ_TARGET_ARM
297
+ DW_REG_SP = 13,
298
+ DW_REG_RA = 14,
299
+ #elif LJ_TARGET_PPC
300
+ DW_REG_SP = 1,
301
+ DW_REG_RA = 65,
302
+ DW_REG_CR = 70,
303
+ #elif LJ_TARGET_MIPS
304
+ DW_REG_SP = 29,
305
+ DW_REG_RA = 31,
306
+ #else
307
+ #error "Unsupported target architecture"
308
+ #endif
309
+ };
310
+
311
+ /* Minimal list of sections for the in-memory ELF object. */
312
+ enum {
313
+ GDBJIT_SECT_NULL,
314
+ GDBJIT_SECT_text,
315
+ GDBJIT_SECT_eh_frame,
316
+ GDBJIT_SECT_shstrtab,
317
+ GDBJIT_SECT_strtab,
318
+ GDBJIT_SECT_symtab,
319
+ GDBJIT_SECT_debug_info,
320
+ GDBJIT_SECT_debug_abbrev,
321
+ GDBJIT_SECT_debug_line,
322
+ GDBJIT_SECT__MAX
323
+ };
324
+
325
+ enum {
326
+ GDBJIT_SYM_UNDEF,
327
+ GDBJIT_SYM_FILE,
328
+ GDBJIT_SYM_FUNC,
329
+ GDBJIT_SYM__MAX
330
+ };
331
+
332
+ /* In-memory ELF object. */
333
+ typedef struct GDBJITobj {
334
+ ELFheader hdr; /* ELF header. */
335
+ ELFsectheader sect[GDBJIT_SECT__MAX]; /* ELF sections. */
336
+ ELFsymbol sym[GDBJIT_SYM__MAX]; /* ELF symbol table. */
337
+ uint8_t space[4096]; /* Space for various section data. */
338
+ } GDBJITobj;
339
+
340
+ /* Combined structure for GDB JIT entry and ELF object. */
341
+ typedef struct GDBJITentryobj {
342
+ GDBJITentry entry;
343
+ size_t sz;
344
+ GDBJITobj obj;
345
+ } GDBJITentryobj;
346
+
347
+ /* Template for in-memory ELF header. */
348
+ static const ELFheader elfhdr_template = {
349
+ .emagic = { 0x7f, 'E', 'L', 'F' },
350
+ .eclass = LJ_64 ? 2 : 1,
351
+ .eendian = LJ_ENDIAN_SELECT(1, 2),
352
+ .eversion = 1,
353
+ #if LJ_TARGET_LINUX
354
+ .eosabi = 0, /* Nope, it's not 3. */
355
+ #elif defined(__FreeBSD__)
356
+ .eosabi = 9,
357
+ #elif defined(__NetBSD__)
358
+ .eosabi = 2,
359
+ #elif defined(__OpenBSD__)
360
+ .eosabi = 12,
361
+ #elif defined(__DragonFly__)
362
+ .eosabi = 0,
363
+ #elif (defined(__sun__) && defined(__svr4__))
364
+ .eosabi = 6,
365
+ #else
366
+ .eosabi = 0,
367
+ #endif
368
+ .eabiversion = 0,
369
+ .epad = { 0, 0, 0, 0, 0, 0, 0 },
370
+ .type = 1,
371
+ #if LJ_TARGET_X86
372
+ .machine = 3,
373
+ #elif LJ_TARGET_X64
374
+ .machine = 62,
375
+ #elif LJ_TARGET_ARM
376
+ .machine = 40,
377
+ #elif LJ_TARGET_PPC
378
+ .machine = 20,
379
+ #elif LJ_TARGET_MIPS
380
+ .machine = 8,
381
+ #else
382
+ #error "Unsupported target architecture"
383
+ #endif
384
+ .version = 1,
385
+ .entry = 0,
386
+ .phofs = 0,
387
+ .shofs = offsetof(GDBJITobj, sect),
388
+ .flags = 0,
389
+ .ehsize = sizeof(ELFheader),
390
+ .phentsize = 0,
391
+ .phnum = 0,
392
+ .shentsize = sizeof(ELFsectheader),
393
+ .shnum = GDBJIT_SECT__MAX,
394
+ .shstridx = GDBJIT_SECT_shstrtab
395
+ };
396
+
397
+ /* -- In-memory ELF object generation ------------------------------------- */
398
+
399
+ /* Context for generating the ELF object for the GDB JIT API. */
400
+ typedef struct GDBJITctx {
401
+ uint8_t *p; /* Pointer to next address in obj.space. */
402
+ uint8_t *startp; /* Pointer to start address in obj.space. */
403
+ GCtrace *T; /* Generate symbols for this trace. */
404
+ uintptr_t mcaddr; /* Machine code address. */
405
+ MSize szmcode; /* Size of machine code. */
406
+ MSize spadjp; /* Stack adjustment for parent trace or interpreter. */
407
+ MSize spadj; /* Stack adjustment for trace itself. */
408
+ BCLine lineno; /* Starting line number. */
409
+ const char *filename; /* Starting file name. */
410
+ size_t objsize; /* Final size of ELF object. */
411
+ GDBJITobj obj; /* In-memory ELF object. */
412
+ } GDBJITctx;
413
+
414
+ /* Add a zero-terminated string. */
415
+ static uint32_t gdbjit_strz(GDBJITctx *ctx, const char *str)
416
+ {
417
+ uint8_t *p = ctx->p;
418
+ uint32_t ofs = (uint32_t)(p - ctx->startp);
419
+ do {
420
+ *p++ = (uint8_t)*str;
421
+ } while (*str++);
422
+ ctx->p = p;
423
+ return ofs;
424
+ }
425
+
426
+ /* Append a decimal number. */
427
+ static void gdbjit_catnum(GDBJITctx *ctx, uint32_t n)
428
+ {
429
+ if (n >= 10) { uint32_t m = n / 10; n = n % 10; gdbjit_catnum(ctx, m); }
430
+ *ctx->p++ = '0' + n;
431
+ }
432
+
433
+ /* Add a SLEB128 value. */
434
+ static void gdbjit_sleb128(GDBJITctx *ctx, int32_t v)
435
+ {
436
+ uint8_t *p = ctx->p;
437
+ for (; (uint32_t)(v+0x40) >= 0x80; v >>= 7)
438
+ *p++ = (uint8_t)((v & 0x7f) | 0x80);
439
+ *p++ = (uint8_t)(v & 0x7f);
440
+ ctx->p = p;
441
+ }
442
+
443
+ /* Shortcuts to generate DWARF structures. */
444
+ #define DB(x) (*p++ = (x))
445
+ #define DI8(x) (*(int8_t *)p = (x), p++)
446
+ #define DU16(x) (*(uint16_t *)p = (x), p += 2)
447
+ #define DU32(x) (*(uint32_t *)p = (x), p += 4)
448
+ #define DADDR(x) (*(uintptr_t *)p = (x), p += sizeof(uintptr_t))
449
+ #define DUV(x) (p = (uint8_t *)lj_strfmt_wuleb128((char *)p, (x)))
450
+ #define DSV(x) (ctx->p = p, gdbjit_sleb128(ctx, (x)), p = ctx->p)
451
+ #define DSTR(str) (ctx->p = p, gdbjit_strz(ctx, (str)), p = ctx->p)
452
+ #define DALIGNNOP(s) while ((uintptr_t)p & ((s)-1)) *p++ = DW_CFA_nop
453
+ #define DSECT(name, stmt) \
454
+ { uint32_t *szp_##name = (uint32_t *)p; p += 4; stmt \
455
+ *szp_##name = (uint32_t)((p-(uint8_t *)szp_##name)-4); } \
456
+
457
+ /* Initialize ELF section headers. */
458
+ static void LJ_FASTCALL gdbjit_secthdr(GDBJITctx *ctx)
459
+ {
460
+ ELFsectheader *sect;
461
+
462
+ *ctx->p++ = '\0'; /* Empty string at start of string table. */
463
+
464
+ #define SECTDEF(id, tp, al) \
465
+ sect = &ctx->obj.sect[GDBJIT_SECT_##id]; \
466
+ sect->name = gdbjit_strz(ctx, "." #id); \
467
+ sect->type = ELFSECT_TYPE_##tp; \
468
+ sect->align = (al)
469
+
470
+ SECTDEF(text, NOBITS, 16);
471
+ sect->flags = ELFSECT_FLAGS_ALLOC|ELFSECT_FLAGS_EXEC;
472
+ sect->addr = ctx->mcaddr;
473
+ sect->ofs = 0;
474
+ sect->size = ctx->szmcode;
475
+
476
+ SECTDEF(eh_frame, PROGBITS, sizeof(uintptr_t));
477
+ sect->flags = ELFSECT_FLAGS_ALLOC;
478
+
479
+ SECTDEF(shstrtab, STRTAB, 1);
480
+ SECTDEF(strtab, STRTAB, 1);
481
+
482
+ SECTDEF(symtab, SYMTAB, sizeof(uintptr_t));
483
+ sect->ofs = offsetof(GDBJITobj, sym);
484
+ sect->size = sizeof(ctx->obj.sym);
485
+ sect->link = GDBJIT_SECT_strtab;
486
+ sect->entsize = sizeof(ELFsymbol);
487
+ sect->info = GDBJIT_SYM_FUNC;
488
+
489
+ SECTDEF(debug_info, PROGBITS, 1);
490
+ SECTDEF(debug_abbrev, PROGBITS, 1);
491
+ SECTDEF(debug_line, PROGBITS, 1);
492
+
493
+ #undef SECTDEF
494
+ }
495
+
496
+ /* Initialize symbol table. */
497
+ static void LJ_FASTCALL gdbjit_symtab(GDBJITctx *ctx)
498
+ {
499
+ ELFsymbol *sym;
500
+
501
+ *ctx->p++ = '\0'; /* Empty string at start of string table. */
502
+
503
+ sym = &ctx->obj.sym[GDBJIT_SYM_FILE];
504
+ sym->name = gdbjit_strz(ctx, "JIT mcode");
505
+ sym->sectidx = ELFSECT_IDX_ABS;
506
+ sym->info = ELFSYM_TYPE_FILE|ELFSYM_BIND_LOCAL;
507
+
508
+ sym = &ctx->obj.sym[GDBJIT_SYM_FUNC];
509
+ sym->name = gdbjit_strz(ctx, "TRACE_"); ctx->p--;
510
+ gdbjit_catnum(ctx, ctx->T->traceno); *ctx->p++ = '\0';
511
+ sym->sectidx = GDBJIT_SECT_text;
512
+ sym->value = 0;
513
+ sym->size = ctx->szmcode;
514
+ sym->info = ELFSYM_TYPE_FUNC|ELFSYM_BIND_GLOBAL;
515
+ }
516
+
517
+ /* Initialize .eh_frame section. */
518
+ static void LJ_FASTCALL gdbjit_ehframe(GDBJITctx *ctx)
519
+ {
520
+ uint8_t *p = ctx->p;
521
+ uint8_t *framep = p;
522
+
523
+ /* Emit DWARF EH CIE. */
524
+ DSECT(CIE,
525
+ DU32(0); /* Offset to CIE itself. */
526
+ DB(DW_CIE_VERSION);
527
+ DSTR("zR"); /* Augmentation. */
528
+ DUV(1); /* Code alignment factor. */
529
+ DSV(-(int32_t)sizeof(uintptr_t)); /* Data alignment factor. */
530
+ DB(DW_REG_RA); /* Return address register. */
531
+ DB(1); DB(DW_EH_PE_textrel|DW_EH_PE_udata4); /* Augmentation data. */
532
+ DB(DW_CFA_def_cfa); DUV(DW_REG_SP); DUV(sizeof(uintptr_t));
533
+ #if LJ_TARGET_PPC
534
+ DB(DW_CFA_offset_extended_sf); DB(DW_REG_RA); DSV(-1);
535
+ #else
536
+ DB(DW_CFA_offset|DW_REG_RA); DUV(1);
537
+ #endif
538
+ DALIGNNOP(sizeof(uintptr_t));
539
+ )
540
+
541
+ /* Emit DWARF EH FDE. */
542
+ DSECT(FDE,
543
+ DU32((uint32_t)(p-framep)); /* Offset to CIE. */
544
+ DU32(0); /* Machine code offset relative to .text. */
545
+ DU32(ctx->szmcode); /* Machine code length. */
546
+ DB(0); /* Augmentation data. */
547
+ /* Registers saved in CFRAME. */
548
+ #if LJ_TARGET_X86
549
+ DB(DW_CFA_offset|DW_REG_BP); DUV(2);
550
+ DB(DW_CFA_offset|DW_REG_DI); DUV(3);
551
+ DB(DW_CFA_offset|DW_REG_SI); DUV(4);
552
+ DB(DW_CFA_offset|DW_REG_BX); DUV(5);
553
+ #elif LJ_TARGET_X64
554
+ DB(DW_CFA_offset|DW_REG_BP); DUV(2);
555
+ DB(DW_CFA_offset|DW_REG_BX); DUV(3);
556
+ DB(DW_CFA_offset|DW_REG_15); DUV(4);
557
+ DB(DW_CFA_offset|DW_REG_14); DUV(5);
558
+ /* Extra registers saved for JIT-compiled code. */
559
+ DB(DW_CFA_offset|DW_REG_13); DUV(LJ_GC64 ? 10 : 9);
560
+ DB(DW_CFA_offset|DW_REG_12); DUV(LJ_GC64 ? 11 : 10);
561
+ #elif LJ_TARGET_ARM
562
+ {
563
+ int i;
564
+ for (i = 11; i >= 4; i--) { DB(DW_CFA_offset|i); DUV(2+(11-i)); }
565
+ }
566
+ #elif LJ_TARGET_PPC
567
+ {
568
+ int i;
569
+ DB(DW_CFA_offset_extended); DB(DW_REG_CR); DUV(55);
570
+ for (i = 14; i <= 31; i++) {
571
+ DB(DW_CFA_offset|i); DUV(37+(31-i));
572
+ DB(DW_CFA_offset|32|i); DUV(2+2*(31-i));
573
+ }
574
+ }
575
+ #elif LJ_TARGET_MIPS
576
+ {
577
+ int i;
578
+ DB(DW_CFA_offset|30); DUV(2);
579
+ for (i = 23; i >= 16; i--) { DB(DW_CFA_offset|i); DUV(26-i); }
580
+ for (i = 30; i >= 20; i -= 2) { DB(DW_CFA_offset|32|i); DUV(42-i); }
581
+ }
582
+ #else
583
+ #error "Unsupported target architecture"
584
+ #endif
585
+ if (ctx->spadjp != ctx->spadj) { /* Parent/interpreter stack frame size. */
586
+ DB(DW_CFA_def_cfa_offset); DUV(ctx->spadjp);
587
+ DB(DW_CFA_advance_loc|1); /* Only an approximation. */
588
+ }
589
+ DB(DW_CFA_def_cfa_offset); DUV(ctx->spadj); /* Trace stack frame size. */
590
+ DALIGNNOP(sizeof(uintptr_t));
591
+ )
592
+
593
+ ctx->p = p;
594
+ }
595
+
596
+ /* Initialize .debug_info section. */
597
+ static void LJ_FASTCALL gdbjit_debuginfo(GDBJITctx *ctx)
598
+ {
599
+ uint8_t *p = ctx->p;
600
+
601
+ DSECT(info,
602
+ DU16(2); /* DWARF version. */
603
+ DU32(0); /* Abbrev offset. */
604
+ DB(sizeof(uintptr_t)); /* Pointer size. */
605
+
606
+ DUV(1); /* Abbrev #1: DW_TAG_compile_unit. */
607
+ DSTR(ctx->filename); /* DW_AT_name. */
608
+ DADDR(ctx->mcaddr); /* DW_AT_low_pc. */
609
+ DADDR(ctx->mcaddr + ctx->szmcode); /* DW_AT_high_pc. */
610
+ DU32(0); /* DW_AT_stmt_list. */
611
+ )
612
+
613
+ ctx->p = p;
614
+ }
615
+
616
+ /* Initialize .debug_abbrev section. */
617
+ static void LJ_FASTCALL gdbjit_debugabbrev(GDBJITctx *ctx)
618
+ {
619
+ uint8_t *p = ctx->p;
620
+
621
+ /* Abbrev #1: DW_TAG_compile_unit. */
622
+ DUV(1); DUV(DW_TAG_compile_unit);
623
+ DB(DW_children_no);
624
+ DUV(DW_AT_name); DUV(DW_FORM_string);
625
+ DUV(DW_AT_low_pc); DUV(DW_FORM_addr);
626
+ DUV(DW_AT_high_pc); DUV(DW_FORM_addr);
627
+ DUV(DW_AT_stmt_list); DUV(DW_FORM_data4);
628
+ DB(0); DB(0);
629
+
630
+ ctx->p = p;
631
+ }
632
+
633
+ #define DLNE(op, s) (DB(DW_LNS_extended_op), DUV(1+(s)), DB((op)))
634
+
635
+ /* Initialize .debug_line section. */
636
+ static void LJ_FASTCALL gdbjit_debugline(GDBJITctx *ctx)
637
+ {
638
+ uint8_t *p = ctx->p;
639
+
640
+ DSECT(line,
641
+ DU16(2); /* DWARF version. */
642
+ DSECT(header,
643
+ DB(1); /* Minimum instruction length. */
644
+ DB(1); /* is_stmt. */
645
+ DI8(0); /* Line base for special opcodes. */
646
+ DB(2); /* Line range for special opcodes. */
647
+ DB(3+1); /* Opcode base at DW_LNS_advance_line+1. */
648
+ DB(0); DB(1); DB(1); /* Standard opcode lengths. */
649
+ /* Directory table. */
650
+ DB(0);
651
+ /* File name table. */
652
+ DSTR(ctx->filename); DUV(0); DUV(0); DUV(0);
653
+ DB(0);
654
+ )
655
+
656
+ DLNE(DW_LNE_set_address, sizeof(uintptr_t)); DADDR(ctx->mcaddr);
657
+ if (ctx->lineno) {
658
+ DB(DW_LNS_advance_line); DSV(ctx->lineno-1);
659
+ }
660
+ DB(DW_LNS_copy);
661
+ DB(DW_LNS_advance_pc); DUV(ctx->szmcode);
662
+ DLNE(DW_LNE_end_sequence, 0);
663
+ )
664
+
665
+ ctx->p = p;
666
+ }
667
+
668
+ #undef DLNE
669
+
670
+ /* Undef shortcuts. */
671
+ #undef DB
672
+ #undef DI8
673
+ #undef DU16
674
+ #undef DU32
675
+ #undef DADDR
676
+ #undef DUV
677
+ #undef DSV
678
+ #undef DSTR
679
+ #undef DALIGNNOP
680
+ #undef DSECT
681
+
682
+ /* Type of a section initializer callback. */
683
+ typedef void (LJ_FASTCALL *GDBJITinitf)(GDBJITctx *ctx);
684
+
685
+ /* Call section initializer and set the section offset and size. */
686
+ static void gdbjit_initsect(GDBJITctx *ctx, int sect, GDBJITinitf initf)
687
+ {
688
+ ctx->startp = ctx->p;
689
+ ctx->obj.sect[sect].ofs = (uintptr_t)((char *)ctx->p - (char *)&ctx->obj);
690
+ initf(ctx);
691
+ ctx->obj.sect[sect].size = (uintptr_t)(ctx->p - ctx->startp);
692
+ }
693
+
694
+ #define SECTALIGN(p, a) \
695
+ ((p) = (uint8_t *)(((uintptr_t)(p) + ((a)-1)) & ~(uintptr_t)((a)-1)))
696
+
697
+ /* Build in-memory ELF object. */
698
+ static void gdbjit_buildobj(GDBJITctx *ctx)
699
+ {
700
+ GDBJITobj *obj = &ctx->obj;
701
+ /* Fill in ELF header and clear structures. */
702
+ memcpy(&obj->hdr, &elfhdr_template, sizeof(ELFheader));
703
+ memset(&obj->sect, 0, sizeof(ELFsectheader)*GDBJIT_SECT__MAX);
704
+ memset(&obj->sym, 0, sizeof(ELFsymbol)*GDBJIT_SYM__MAX);
705
+ /* Initialize sections. */
706
+ ctx->p = obj->space;
707
+ gdbjit_initsect(ctx, GDBJIT_SECT_shstrtab, gdbjit_secthdr);
708
+ gdbjit_initsect(ctx, GDBJIT_SECT_strtab, gdbjit_symtab);
709
+ gdbjit_initsect(ctx, GDBJIT_SECT_debug_info, gdbjit_debuginfo);
710
+ gdbjit_initsect(ctx, GDBJIT_SECT_debug_abbrev, gdbjit_debugabbrev);
711
+ gdbjit_initsect(ctx, GDBJIT_SECT_debug_line, gdbjit_debugline);
712
+ SECTALIGN(ctx->p, sizeof(uintptr_t));
713
+ gdbjit_initsect(ctx, GDBJIT_SECT_eh_frame, gdbjit_ehframe);
714
+ ctx->objsize = (size_t)((char *)ctx->p - (char *)obj);
715
+ lua_assert(ctx->objsize < sizeof(GDBJITobj));
716
+ }
717
+
718
+ #undef SECTALIGN
719
+
720
+ /* -- Interface to GDB JIT API -------------------------------------------- */
721
+
722
+ /* Add new entry to GDB JIT symbol chain. */
723
+ static void gdbjit_newentry(lua_State *L, GDBJITctx *ctx)
724
+ {
725
+ /* Allocate memory for GDB JIT entry and ELF object. */
726
+ MSize sz = (MSize)(sizeof(GDBJITentryobj) - sizeof(GDBJITobj) + ctx->objsize);
727
+ GDBJITentryobj *eo = lj_mem_newt(L, sz, GDBJITentryobj);
728
+ memcpy(&eo->obj, &ctx->obj, ctx->objsize); /* Copy ELF object. */
729
+ eo->sz = sz;
730
+ ctx->T->gdbjit_entry = (void *)eo;
731
+ /* Link new entry to chain and register it. */
732
+ eo->entry.prev_entry = NULL;
733
+ eo->entry.next_entry = __jit_debug_descriptor.first_entry;
734
+ if (eo->entry.next_entry)
735
+ eo->entry.next_entry->prev_entry = &eo->entry;
736
+ eo->entry.symfile_addr = (const char *)&eo->obj;
737
+ eo->entry.symfile_size = ctx->objsize;
738
+ __jit_debug_descriptor.first_entry = &eo->entry;
739
+ __jit_debug_descriptor.relevant_entry = &eo->entry;
740
+ __jit_debug_descriptor.action_flag = GDBJIT_REGISTER;
741
+ __jit_debug_register_code();
742
+ }
743
+
744
+ /* Add debug info for newly compiled trace and notify GDB. */
745
+ void lj_gdbjit_addtrace(jit_State *J, GCtrace *T)
746
+ {
747
+ GDBJITctx ctx;
748
+ GCproto *pt = &gcref(T->startpt)->pt;
749
+ TraceNo parent = T->ir[REF_BASE].op1;
750
+ const BCIns *startpc = mref(T->startpc, const BCIns);
751
+ ctx.T = T;
752
+ ctx.mcaddr = (uintptr_t)T->mcode;
753
+ ctx.szmcode = T->szmcode;
754
+ ctx.spadjp = CFRAME_SIZE_JIT +
755
+ (MSize)(parent ? traceref(J, parent)->spadjust : 0);
756
+ ctx.spadj = CFRAME_SIZE_JIT + T->spadjust;
757
+ lua_assert(startpc >= proto_bc(pt) && startpc < proto_bc(pt) + pt->sizebc);
758
+ ctx.lineno = lj_debug_line(pt, proto_bcpos(pt, startpc));
759
+ ctx.filename = proto_chunknamestr(pt);
760
+ if (*ctx.filename == '@' || *ctx.filename == '=')
761
+ ctx.filename++;
762
+ else
763
+ ctx.filename = "(string)";
764
+ gdbjit_buildobj(&ctx);
765
+ gdbjit_newentry(J->L, &ctx);
766
+ }
767
+
768
+ /* Delete debug info for trace and notify GDB. */
769
+ void lj_gdbjit_deltrace(jit_State *J, GCtrace *T)
770
+ {
771
+ GDBJITentryobj *eo = (GDBJITentryobj *)T->gdbjit_entry;
772
+ if (eo) {
773
+ if (eo->entry.prev_entry)
774
+ eo->entry.prev_entry->next_entry = eo->entry.next_entry;
775
+ else
776
+ __jit_debug_descriptor.first_entry = eo->entry.next_entry;
777
+ if (eo->entry.next_entry)
778
+ eo->entry.next_entry->prev_entry = eo->entry.prev_entry;
779
+ __jit_debug_descriptor.relevant_entry = &eo->entry;
780
+ __jit_debug_descriptor.action_flag = GDBJIT_UNREGISTER;
781
+ __jit_debug_register_code();
782
+ lj_mem_free(J2G(J), eo, eo->sz);
783
+ }
784
+ }
785
+
786
+ #endif
787
+ #endif