2 ** Client for the GDB JIT API.
3 ** Copyright (C) 2005-2016 Mike Pall. See Copyright Notice in luajit.h
18 #include "lj_dispatch.h"
20 /* This is not compiled in by default.
21 ** Enable with -DLUAJIT_USE_GDBJIT in the Makefile and recompile everything.
23 #ifdef LUAJIT_USE_GDBJIT
25 /* The GDB JIT API allows JIT compilers to pass debug information about
26 ** JIT-compiled code back to GDB. You need at least GDB 7.0 or higher
27 ** to see it in action.
29 ** This is a passive API, so it works even when not running under GDB
30 ** or when attaching to an already running process. Alas, this implies
31 ** enabling it always has a non-negligible overhead -- do not use in
34 ** The LuaJIT GDB JIT client is rather minimal at the moment. It gives
35 ** each trace a symbol name and adds a source location and frame unwind
36 ** information. Obviously LuaJIT itself and any embedding C application
37 ** should be compiled with debug symbols, too (see the Makefile).
39 ** Traces are named TRACE_1, TRACE_2, ... these correspond to the trace
40 ** numbers from -jv or -jdump. Use "break TRACE_1" or "tbreak TRACE_1" etc.
41 ** to set breakpoints on specific traces (even ahead of their creation).
43 ** The source location for each trace allows listing the corresponding
44 ** source lines with the GDB command "list" (but only if the Lua source
45 ** has been loaded from a file). Currently this is always set to the
46 ** location where the trace has been started.
48 ** Frame unwind information can be inspected with the GDB command
49 ** "info frame". This also allows proper backtraces across JIT-compiled
50 ** code with the GDB command "bt".
52 ** You probably want to add the following settings to a .gdbinit file
53 ** (or add them to ~/.gdbinit):
54 ** set disassembly-flavor intel
55 ** set breakpoint pending on
57 ** Here's a sample GDB session:
58 ** ------------------------------------------------------------------------
62 for inner=1,100 do end
68 [TRACE 2 (1/3) x.lua:1 -> 1]
70 $ gdb --quiet --args luajit x.lua
72 Function "TRACE_1" not defined.
73 Temporary breakpoint 1 (TRACE_1) pending.
75 Starting program: luajit x.lua
77 Temporary breakpoint 1, TRACE_1 () at x.lua:2
78 2 for inner=1,100 do end
81 2 for inner=1,100 do end
84 #0 TRACE_1 () at x.lua:2
85 #1 0x08053690 in lua_pcall [...]
87 #7 0x0806ff90 in main [...]
89 Dump of assembler code for function TRACE_1:
90 0xf7fd9fba <TRACE_1+0>: mov DWORD PTR ds:0xf7e0e2a0,0x1
91 0xf7fd9fc4 <TRACE_1+10>: movsd xmm7,QWORD PTR [edx+0x20]
93 0xf7fd9ff8 <TRACE_1+62>: jmp 0xf7fd2014
94 End of assembler dump.
96 Function "TRACE_2" not defined.
97 Temporary breakpoint 2 (TRACE_2) pending.
101 Temporary breakpoint 2, TRACE_2 () at x.lua:1
104 Stack level 0, frame at 0xffffd7c0:
105 eip = 0xf7fd9f60 in TRACE_2 (x.lua:1); saved eip 0x8053690
106 called by frame at 0xffffd7e0
107 source language unknown.
108 Arglist at 0xffffd78c, args:
109 Locals at 0xffffd78c, Previous frame's sp is 0xffffd7c0
111 ebx at 0xffffd7ac, ebp at 0xffffd7b8, esi at 0xffffd7b0, edi at 0xffffd7b4,
115 ** ------------------------------------------------------------------------
118 /* -- GDB JIT API --------------------------------------------------------- */
120 /* GDB JIT actions. */
128 typedef struct GDBJITentry
{
129 struct GDBJITentry
*next_entry
;
130 struct GDBJITentry
*prev_entry
;
131 const char *symfile_addr
;
132 uint64_t symfile_size
;
135 /* GDB JIT descriptor. */
136 typedef struct GDBJITdesc
{
138 uint32_t action_flag
;
139 GDBJITentry
*relevant_entry
;
140 GDBJITentry
*first_entry
;
143 GDBJITdesc __jit_debug_descriptor
= {
144 1, GDBJIT_NOACTION
, NULL
, NULL
147 /* GDB sets a breakpoint at this function. */
148 void LJ_NOINLINE
__jit_debug_register_code()
150 __asm__
__volatile__("");
153 /* -- In-memory ELF object definitions ------------------------------------ */
155 /* ELF definitions. */
156 typedef struct ELFheader
{
179 typedef struct ELFsectheader
{
192 #define ELFSECT_IDX_ABS 0xfff1
195 ELFSECT_TYPE_PROGBITS
= 1,
196 ELFSECT_TYPE_SYMTAB
= 2,
197 ELFSECT_TYPE_STRTAB
= 3,
198 ELFSECT_TYPE_NOBITS
= 8
201 #define ELFSECT_FLAGS_WRITE 1
202 #define ELFSECT_FLAGS_ALLOC 2
203 #define ELFSECT_FLAGS_EXEC 4
205 typedef struct ELFsymbol
{
224 ELFSYM_TYPE_FUNC
= 2,
225 ELFSYM_TYPE_FILE
= 4,
226 ELFSYM_BIND_LOCAL
= 0 << 4,
227 ELFSYM_BIND_GLOBAL
= 1 << 4,
230 /* DWARF definitions. */
231 #define DW_CIE_VERSION 1
235 DW_CFA_offset_extended
= 0x5,
236 DW_CFA_def_cfa
= 0xc,
237 DW_CFA_def_cfa_offset
= 0xe,
238 DW_CFA_offset_extended_sf
= 0x11,
239 DW_CFA_advance_loc
= 0x40,
245 DW_EH_PE_textrel
= 0x20
249 DW_TAG_compile_unit
= 0x11
259 DW_AT_stmt_list
= 0x10,
266 DW_FORM_data4
= 0x06,
267 DW_FORM_string
= 0x08
271 DW_LNS_extended_op
= 0,
273 DW_LNS_advance_pc
= 2,
274 DW_LNS_advance_line
= 3
278 DW_LNE_end_sequence
= 1,
279 DW_LNE_set_address
= 2
284 DW_REG_AX
, DW_REG_CX
, DW_REG_DX
, DW_REG_BX
,
285 DW_REG_SP
, DW_REG_BP
, DW_REG_SI
, DW_REG_DI
,
288 /* Yes, the order is strange, but correct. */
289 DW_REG_AX
, DW_REG_DX
, DW_REG_CX
, DW_REG_BX
,
290 DW_REG_SI
, DW_REG_DI
, DW_REG_BP
, DW_REG_SP
,
291 DW_REG_8
, DW_REG_9
, DW_REG_10
, DW_REG_11
,
292 DW_REG_12
, DW_REG_13
, DW_REG_14
, DW_REG_15
,
305 #error "Unsupported target architecture"
309 /* Minimal list of sections for the in-memory ELF object. */
313 GDBJIT_SECT_eh_frame
,
314 GDBJIT_SECT_shstrtab
,
317 GDBJIT_SECT_debug_info
,
318 GDBJIT_SECT_debug_abbrev
,
319 GDBJIT_SECT_debug_line
,
330 /* In-memory ELF object. */
331 typedef struct GDBJITobj
{
332 ELFheader hdr
; /* ELF header. */
333 ELFsectheader sect
[GDBJIT_SECT__MAX
]; /* ELF sections. */
334 ELFsymbol sym
[GDBJIT_SYM__MAX
]; /* ELF symbol table. */
335 uint8_t space
[4096]; /* Space for various section data. */
338 /* Combined structure for GDB JIT entry and ELF object. */
339 typedef struct GDBJITentryobj
{
345 /* Template for in-memory ELF header. */
346 static const ELFheader elfhdr_template
= {
347 .emagic
= { 0x7f, 'E', 'L', 'F' },
348 .eclass
= LJ_64
? 2 : 1,
349 .eendian
= LJ_ENDIAN_SELECT(1, 2),
352 .eosabi
= 0, /* Nope, it's not 3. */
353 #elif defined(__FreeBSD__)
355 #elif defined(__NetBSD__)
357 #elif defined(__OpenBSD__)
359 #elif defined(__DragonFly__)
361 #elif (defined(__sun__) && defined(__svr4__))
367 .epad
= { 0, 0, 0, 0, 0, 0, 0 },
380 #error "Unsupported target architecture"
385 .shofs
= offsetof(GDBJITobj
, sect
),
387 .ehsize
= sizeof(ELFheader
),
390 .shentsize
= sizeof(ELFsectheader
),
391 .shnum
= GDBJIT_SECT__MAX
,
392 .shstridx
= GDBJIT_SECT_shstrtab
395 /* -- In-memory ELF object generation ------------------------------------- */
397 /* Context for generating the ELF object for the GDB JIT API. */
398 typedef struct GDBJITctx
{
399 uint8_t *p
; /* Pointer to next address in obj.space. */
400 uint8_t *startp
; /* Pointer to start address in obj.space. */
401 GCtrace
*T
; /* Generate symbols for this trace. */
402 uintptr_t mcaddr
; /* Machine code address. */
403 MSize szmcode
; /* Size of machine code. */
404 MSize spadjp
; /* Stack adjustment for parent trace or interpreter. */
405 MSize spadj
; /* Stack adjustment for trace itself. */
406 BCLine lineno
; /* Starting line number. */
407 const char *filename
; /* Starting file name. */
408 size_t objsize
; /* Final size of ELF object. */
409 GDBJITobj obj
; /* In-memory ELF object. */
412 /* Add a zero-terminated string. */
413 static uint32_t gdbjit_strz(GDBJITctx
*ctx
, const char *str
)
416 uint32_t ofs
= (uint32_t)(p
- ctx
->startp
);
418 *p
++ = (uint8_t)*str
;
424 /* Append a decimal number. */
425 static void gdbjit_catnum(GDBJITctx
*ctx
, uint32_t n
)
427 if (n
>= 10) { uint32_t m
= n
/ 10; n
= n
% 10; gdbjit_catnum(ctx
, m
); }
431 /* Add a ULEB128 value. */
432 static void gdbjit_uleb128(GDBJITctx
*ctx
, uint32_t v
)
435 for (; v
>= 0x80; v
>>= 7)
436 *p
++ = (uint8_t)((v
& 0x7f) | 0x80);
441 /* Add a SLEB128 value. */
442 static void gdbjit_sleb128(GDBJITctx
*ctx
, int32_t v
)
445 for (; (uint32_t)(v
+0x40) >= 0x80; v
>>= 7)
446 *p
++ = (uint8_t)((v
& 0x7f) | 0x80);
447 *p
++ = (uint8_t)(v
& 0x7f);
451 /* Shortcuts to generate DWARF structures. */
452 #define DB(x) (*p++ = (x))
453 #define DI8(x) (*(int8_t *)p = (x), p++)
454 #define DU16(x) (*(uint16_t *)p = (x), p += 2)
455 #define DU32(x) (*(uint32_t *)p = (x), p += 4)
456 #define DADDR(x) (*(uintptr_t *)p = (x), p += sizeof(uintptr_t))
457 #define DUV(x) (ctx->p = p, gdbjit_uleb128(ctx, (x)), p = ctx->p)
458 #define DSV(x) (ctx->p = p, gdbjit_sleb128(ctx, (x)), p = ctx->p)
459 #define DSTR(str) (ctx->p = p, gdbjit_strz(ctx, (str)), p = ctx->p)
460 #define DALIGNNOP(s) while ((uintptr_t)p & ((s)-1)) *p++ = DW_CFA_nop
461 #define DSECT(name, stmt) \
462 { uint32_t *szp_##name = (uint32_t *)p; p += 4; stmt \
463 *szp_##name = (uint32_t)((p-(uint8_t *)szp_##name)-4); } \
465 /* Initialize ELF section headers. */
466 static void LJ_FASTCALL
gdbjit_secthdr(GDBJITctx
*ctx
)
470 *ctx
->p
++ = '\0'; /* Empty string at start of string table. */
472 #define SECTDEF(id, tp, al) \
473 sect = &ctx->obj.sect[GDBJIT_SECT_##id]; \
474 sect->name = gdbjit_strz(ctx, "." #id); \
475 sect->type = ELFSECT_TYPE_##tp; \
478 SECTDEF(text
, NOBITS
, 16);
479 sect
->flags
= ELFSECT_FLAGS_ALLOC
|ELFSECT_FLAGS_EXEC
;
480 sect
->addr
= ctx
->mcaddr
;
482 sect
->size
= ctx
->szmcode
;
484 SECTDEF(eh_frame
, PROGBITS
, sizeof(uintptr_t));
485 sect
->flags
= ELFSECT_FLAGS_ALLOC
;
487 SECTDEF(shstrtab
, STRTAB
, 1);
488 SECTDEF(strtab
, STRTAB
, 1);
490 SECTDEF(symtab
, SYMTAB
, sizeof(uintptr_t));
491 sect
->ofs
= offsetof(GDBJITobj
, sym
);
492 sect
->size
= sizeof(ctx
->obj
.sym
);
493 sect
->link
= GDBJIT_SECT_strtab
;
494 sect
->entsize
= sizeof(ELFsymbol
);
495 sect
->info
= GDBJIT_SYM_FUNC
;
497 SECTDEF(debug_info
, PROGBITS
, 1);
498 SECTDEF(debug_abbrev
, PROGBITS
, 1);
499 SECTDEF(debug_line
, PROGBITS
, 1);
504 /* Initialize symbol table. */
505 static void LJ_FASTCALL
gdbjit_symtab(GDBJITctx
*ctx
)
509 *ctx
->p
++ = '\0'; /* Empty string at start of string table. */
511 sym
= &ctx
->obj
.sym
[GDBJIT_SYM_FILE
];
512 sym
->name
= gdbjit_strz(ctx
, "JIT mcode");
513 sym
->sectidx
= ELFSECT_IDX_ABS
;
514 sym
->info
= ELFSYM_TYPE_FILE
|ELFSYM_BIND_LOCAL
;
516 sym
= &ctx
->obj
.sym
[GDBJIT_SYM_FUNC
];
517 sym
->name
= gdbjit_strz(ctx
, "TRACE_"); ctx
->p
--;
518 gdbjit_catnum(ctx
, ctx
->T
->traceno
); *ctx
->p
++ = '\0';
519 sym
->sectidx
= GDBJIT_SECT_text
;
521 sym
->size
= ctx
->szmcode
;
522 sym
->info
= ELFSYM_TYPE_FUNC
|ELFSYM_BIND_GLOBAL
;
525 /* Initialize .eh_frame section. */
526 static void LJ_FASTCALL
gdbjit_ehframe(GDBJITctx
*ctx
)
531 /* Emit DWARF EH CIE. */
533 DU32(0); /* Offset to CIE itself. */
535 DSTR("zR"); /* Augmentation. */
536 DUV(1); /* Code alignment factor. */
537 DSV(-(int32_t)sizeof(uintptr_t)); /* Data alignment factor. */
538 DB(DW_REG_RA
); /* Return address register. */
539 DB(1); DB(DW_EH_PE_textrel
|DW_EH_PE_udata4
); /* Augmentation data. */
540 DB(DW_CFA_def_cfa
); DUV(DW_REG_SP
); DUV(sizeof(uintptr_t));
542 DB(DW_CFA_offset_extended_sf
); DB(DW_REG_RA
); DSV(-1);
544 DB(DW_CFA_offset
|DW_REG_RA
); DUV(1);
546 DALIGNNOP(sizeof(uintptr_t));
549 /* Emit DWARF EH FDE. */
551 DU32((uint32_t)(p
-framep
)); /* Offset to CIE. */
552 DU32(0); /* Machine code offset relative to .text. */
553 DU32(ctx
->szmcode
); /* Machine code length. */
554 DB(0); /* Augmentation data. */
555 /* Registers saved in CFRAME. */
557 DB(DW_CFA_offset
|DW_REG_BP
); DUV(2);
558 DB(DW_CFA_offset
|DW_REG_DI
); DUV(3);
559 DB(DW_CFA_offset
|DW_REG_SI
); DUV(4);
560 DB(DW_CFA_offset
|DW_REG_BX
); DUV(5);
562 DB(DW_CFA_offset
|DW_REG_BP
); DUV(2);
563 DB(DW_CFA_offset
|DW_REG_BX
); DUV(3);
564 DB(DW_CFA_offset
|DW_REG_15
); DUV(4);
565 DB(DW_CFA_offset
|DW_REG_14
); DUV(5);
566 /* Extra registers saved for JIT-compiled code. */
567 DB(DW_CFA_offset
|DW_REG_13
); DUV(9);
568 DB(DW_CFA_offset
|DW_REG_12
); DUV(10);
572 for (i
= 11; i
>= 4; i
--) { DB(DW_CFA_offset
|i
); DUV(2+(11-i
)); }
577 DB(DW_CFA_offset_extended
); DB(DW_REG_CR
); DUV(55);
578 for (i
= 14; i
<= 31; i
++) {
579 DB(DW_CFA_offset
|i
); DUV(37+(31-i
));
580 DB(DW_CFA_offset
|32|i
); DUV(2+2*(31-i
));
586 DB(DW_CFA_offset
|30); DUV(2);
587 for (i
= 23; i
>= 16; i
--) { DB(DW_CFA_offset
|i
); DUV(26-i
); }
588 for (i
= 30; i
>= 20; i
-= 2) { DB(DW_CFA_offset
|32|i
); DUV(42-i
); }
591 #error "Unsupported target architecture"
593 if (ctx
->spadjp
!= ctx
->spadj
) { /* Parent/interpreter stack frame size. */
594 DB(DW_CFA_def_cfa_offset
); DUV(ctx
->spadjp
);
595 DB(DW_CFA_advance_loc
|1); /* Only an approximation. */
597 DB(DW_CFA_def_cfa_offset
); DUV(ctx
->spadj
); /* Trace stack frame size. */
598 DALIGNNOP(sizeof(uintptr_t));
604 /* Initialize .debug_info section. */
605 static void LJ_FASTCALL
gdbjit_debuginfo(GDBJITctx
*ctx
)
610 DU16(2); /* DWARF version. */
611 DU32(0); /* Abbrev offset. */
612 DB(sizeof(uintptr_t)); /* Pointer size. */
614 DUV(1); /* Abbrev #1: DW_TAG_compile_unit. */
615 DSTR(ctx
->filename
); /* DW_AT_name. */
616 DADDR(ctx
->mcaddr
); /* DW_AT_low_pc. */
617 DADDR(ctx
->mcaddr
+ ctx
->szmcode
); /* DW_AT_high_pc. */
618 DU32(0); /* DW_AT_stmt_list. */
624 /* Initialize .debug_abbrev section. */
625 static void LJ_FASTCALL
gdbjit_debugabbrev(GDBJITctx
*ctx
)
629 /* Abbrev #1: DW_TAG_compile_unit. */
630 DUV(1); DUV(DW_TAG_compile_unit
);
632 DUV(DW_AT_name
); DUV(DW_FORM_string
);
633 DUV(DW_AT_low_pc
); DUV(DW_FORM_addr
);
634 DUV(DW_AT_high_pc
); DUV(DW_FORM_addr
);
635 DUV(DW_AT_stmt_list
); DUV(DW_FORM_data4
);
641 #define DLNE(op, s) (DB(DW_LNS_extended_op), DUV(1+(s)), DB((op)))
643 /* Initialize .debug_line section. */
644 static void LJ_FASTCALL
gdbjit_debugline(GDBJITctx
*ctx
)
649 DU16(2); /* DWARF version. */
651 DB(1); /* Minimum instruction length. */
652 DB(1); /* is_stmt. */
653 DI8(0); /* Line base for special opcodes. */
654 DB(2); /* Line range for special opcodes. */
655 DB(3+1); /* Opcode base at DW_LNS_advance_line+1. */
656 DB(0); DB(1); DB(1); /* Standard opcode lengths. */
657 /* Directory table. */
659 /* File name table. */
660 DSTR(ctx
->filename
); DUV(0); DUV(0); DUV(0);
664 DLNE(DW_LNE_set_address
, sizeof(uintptr_t)); DADDR(ctx
->mcaddr
);
666 DB(DW_LNS_advance_line
); DSV(ctx
->lineno
-1);
669 DB(DW_LNS_advance_pc
); DUV(ctx
->szmcode
);
670 DLNE(DW_LNE_end_sequence
, 0);
678 /* Undef shortcuts. */
690 /* Type of a section initializer callback. */
691 typedef void (LJ_FASTCALL
*GDBJITinitf
)(GDBJITctx
*ctx
);
693 /* Call section initializer and set the section offset and size. */
694 static void gdbjit_initsect(GDBJITctx
*ctx
, int sect
, GDBJITinitf initf
)
696 ctx
->startp
= ctx
->p
;
697 ctx
->obj
.sect
[sect
].ofs
= (uintptr_t)((char *)ctx
->p
- (char *)&ctx
->obj
);
699 ctx
->obj
.sect
[sect
].size
= (uintptr_t)(ctx
->p
- ctx
->startp
);
702 #define SECTALIGN(p, a) \
703 ((p) = (uint8_t *)(((uintptr_t)(p) + ((a)-1)) & ~(uintptr_t)((a)-1)))
705 /* Build in-memory ELF object. */
706 static void gdbjit_buildobj(GDBJITctx
*ctx
)
708 GDBJITobj
*obj
= &ctx
->obj
;
709 /* Fill in ELF header and clear structures. */
710 memcpy(&obj
->hdr
, &elfhdr_template
, sizeof(ELFheader
));
711 memset(&obj
->sect
, 0, sizeof(ELFsectheader
)*GDBJIT_SECT__MAX
);
712 memset(&obj
->sym
, 0, sizeof(ELFsymbol
)*GDBJIT_SYM__MAX
);
713 /* Initialize sections. */
715 gdbjit_initsect(ctx
, GDBJIT_SECT_shstrtab
, gdbjit_secthdr
);
716 gdbjit_initsect(ctx
, GDBJIT_SECT_strtab
, gdbjit_symtab
);
717 gdbjit_initsect(ctx
, GDBJIT_SECT_debug_info
, gdbjit_debuginfo
);
718 gdbjit_initsect(ctx
, GDBJIT_SECT_debug_abbrev
, gdbjit_debugabbrev
);
719 gdbjit_initsect(ctx
, GDBJIT_SECT_debug_line
, gdbjit_debugline
);
720 SECTALIGN(ctx
->p
, sizeof(uintptr_t));
721 gdbjit_initsect(ctx
, GDBJIT_SECT_eh_frame
, gdbjit_ehframe
);
722 ctx
->objsize
= (size_t)((char *)ctx
->p
- (char *)obj
);
723 lua_assert(ctx
->objsize
< sizeof(GDBJITobj
));
728 /* -- Interface to GDB JIT API -------------------------------------------- */
730 /* Add new entry to GDB JIT symbol chain. */
731 static void gdbjit_newentry(lua_State
*L
, GDBJITctx
*ctx
)
733 /* Allocate memory for GDB JIT entry and ELF object. */
734 MSize sz
= (MSize
)(sizeof(GDBJITentryobj
) - sizeof(GDBJITobj
) + ctx
->objsize
);
735 GDBJITentryobj
*eo
= lj_mem_newt(L
, sz
, GDBJITentryobj
);
736 memcpy(&eo
->obj
, &ctx
->obj
, ctx
->objsize
); /* Copy ELF object. */
738 ctx
->T
->gdbjit_entry
= (void *)eo
;
739 /* Link new entry to chain and register it. */
740 eo
->entry
.prev_entry
= NULL
;
741 eo
->entry
.next_entry
= __jit_debug_descriptor
.first_entry
;
742 if (eo
->entry
.next_entry
)
743 eo
->entry
.next_entry
->prev_entry
= &eo
->entry
;
744 eo
->entry
.symfile_addr
= (const char *)&eo
->obj
;
745 eo
->entry
.symfile_size
= ctx
->objsize
;
746 __jit_debug_descriptor
.first_entry
= &eo
->entry
;
747 __jit_debug_descriptor
.relevant_entry
= &eo
->entry
;
748 __jit_debug_descriptor
.action_flag
= GDBJIT_REGISTER
;
749 __jit_debug_register_code();
752 /* Add debug info for newly compiled trace and notify GDB. */
753 void lj_gdbjit_addtrace(jit_State
*J
, GCtrace
*T
)
756 GCproto
*pt
= &gcref(T
->startpt
)->pt
;
757 TraceNo parent
= T
->ir
[REF_BASE
].op1
;
758 const BCIns
*startpc
= mref(T
->startpc
, const BCIns
);
760 ctx
.mcaddr
= (uintptr_t)T
->mcode
;
761 ctx
.szmcode
= T
->szmcode
;
762 ctx
.spadjp
= CFRAME_SIZE_JIT
+
763 (MSize
)(parent
? traceref(J
, parent
)->spadjust
: 0);
764 ctx
.spadj
= CFRAME_SIZE_JIT
+ T
->spadjust
;
765 lua_assert(startpc
>= proto_bc(pt
) && startpc
< proto_bc(pt
) + pt
->sizebc
);
766 ctx
.lineno
= lj_debug_line(pt
, proto_bcpos(pt
, startpc
));
767 ctx
.filename
= proto_chunknamestr(pt
);
768 if (*ctx
.filename
== '@' || *ctx
.filename
== '=')
771 ctx
.filename
= "(string)";
772 gdbjit_buildobj(&ctx
);
773 gdbjit_newentry(J
->L
, &ctx
);
776 /* Delete debug info for trace and notify GDB. */
777 void lj_gdbjit_deltrace(jit_State
*J
, GCtrace
*T
)
779 GDBJITentryobj
*eo
= (GDBJITentryobj
*)T
->gdbjit_entry
;
781 if (eo
->entry
.prev_entry
)
782 eo
->entry
.prev_entry
->next_entry
= eo
->entry
.next_entry
;
784 __jit_debug_descriptor
.first_entry
= eo
->entry
.next_entry
;
785 if (eo
->entry
.next_entry
)
786 eo
->entry
.next_entry
->prev_entry
= eo
->entry
.prev_entry
;
787 __jit_debug_descriptor
.relevant_entry
= &eo
->entry
;
788 __jit_debug_descriptor
.action_flag
= GDBJIT_UNREGISTER
;
789 __jit_debug_register_code();
790 lj_mem_free(J2G(J
), eo
, eo
->sz
);