mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-08 07:34:07 +00:00
Avoid string allocation in GDB JIT API.
This commit is contained in:
parent
5ff994fa37
commit
41ec9a94b3
@ -68,7 +68,7 @@ lj_gc.o: lj_gc.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
|
|||||||
lj_state.h lj_frame.h lj_bc.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h \
|
lj_state.h lj_frame.h lj_bc.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h \
|
||||||
lj_traceerr.h lj_vm.h
|
lj_traceerr.h lj_vm.h
|
||||||
lj_gdbjit.o: lj_gdbjit.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
lj_gdbjit.o: lj_gdbjit.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
||||||
lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_frame.h lj_bc.h lj_jit.h \
|
lj_gc.h lj_err.h lj_errmsg.h lj_frame.h lj_bc.h lj_jit.h \
|
||||||
lj_ir.h lj_dispatch.h
|
lj_ir.h lj_dispatch.h
|
||||||
lj_ir.o: lj_ir.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
|
lj_ir.o: lj_ir.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
|
||||||
lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \
|
lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
#include "lj_gc.h"
|
#include "lj_gc.h"
|
||||||
#include "lj_err.h"
|
#include "lj_err.h"
|
||||||
#include "lj_str.h"
|
|
||||||
#include "lj_frame.h"
|
#include "lj_frame.h"
|
||||||
#include "lj_jit.h"
|
#include "lj_jit.h"
|
||||||
#include "lj_dispatch.h"
|
#include "lj_dispatch.h"
|
||||||
@ -385,7 +384,6 @@ typedef struct GDBJITctx {
|
|||||||
MSize spadj; /* Stack adjustment for trace itself. */
|
MSize spadj; /* Stack adjustment for trace itself. */
|
||||||
BCLine lineno; /* Starting line number. */
|
BCLine lineno; /* Starting line number. */
|
||||||
const char *filename; /* Starting file name. */
|
const char *filename; /* Starting file name. */
|
||||||
const char *trname; /* Name of trace. */
|
|
||||||
size_t objsize; /* Final size of ELF object. */
|
size_t objsize; /* Final size of ELF object. */
|
||||||
GDBJITobj obj; /* In-memory ELF object. */
|
GDBJITobj obj; /* In-memory ELF object. */
|
||||||
} GDBJITctx;
|
} GDBJITctx;
|
||||||
@ -402,6 +400,13 @@ static uint32_t gdbjit_strz(GDBJITctx *ctx, const char *str)
|
|||||||
return ofs;
|
return ofs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Append a decimal number. */
|
||||||
|
static void gdbjit_catnum(GDBJITctx *ctx, uint32_t n)
|
||||||
|
{
|
||||||
|
if (n >= 10) { uint32_t m = n / 10; n = n % 10; gdbjit_catnum(ctx, m); }
|
||||||
|
*ctx->p++ = '0' + n;
|
||||||
|
}
|
||||||
|
|
||||||
/* Add a ULEB128 value. */
|
/* Add a ULEB128 value. */
|
||||||
static void gdbjit_uleb128(GDBJITctx *ctx, uint32_t v)
|
static void gdbjit_uleb128(GDBJITctx *ctx, uint32_t v)
|
||||||
{
|
{
|
||||||
@ -488,7 +493,8 @@ static void LJ_FASTCALL gdbjit_symtab(GDBJITctx *ctx)
|
|||||||
sym->info = ELFSYM_TYPE_FILE|ELFSYM_BIND_LOCAL;
|
sym->info = ELFSYM_TYPE_FILE|ELFSYM_BIND_LOCAL;
|
||||||
|
|
||||||
sym = &ctx->obj.sym[GDBJIT_SYM_FUNC];
|
sym = &ctx->obj.sym[GDBJIT_SYM_FUNC];
|
||||||
sym->name = gdbjit_strz(ctx, ctx->trname);
|
sym->name = gdbjit_strz(ctx, "TRACE_"); ctx->p--;
|
||||||
|
gdbjit_catnum(ctx, ctx->T->traceno); *ctx->p++ = '\0';
|
||||||
sym->sectidx = GDBJIT_SECT_text;
|
sym->sectidx = GDBJIT_SECT_text;
|
||||||
sym->value = 0;
|
sym->value = 0;
|
||||||
sym->size = ctx->szmcode;
|
sym->size = ctx->szmcode;
|
||||||
@ -701,7 +707,6 @@ static void gdbjit_newentry(lua_State *L, GDBJITctx *ctx)
|
|||||||
void lj_gdbjit_addtrace(jit_State *J, GCtrace *T)
|
void lj_gdbjit_addtrace(jit_State *J, GCtrace *T)
|
||||||
{
|
{
|
||||||
GDBJITctx ctx;
|
GDBJITctx ctx;
|
||||||
lua_State *L = J->L;
|
|
||||||
GCproto *pt = &gcref(T->startpt)->pt;
|
GCproto *pt = &gcref(T->startpt)->pt;
|
||||||
TraceNo parent = T->ir[REF_BASE].op1;
|
TraceNo parent = T->ir[REF_BASE].op1;
|
||||||
uintptr_t pcofs = (uintptr_t)(T->snap[0].mapofs+T->snap[0].nent);
|
uintptr_t pcofs = (uintptr_t)(T->snap[0].mapofs+T->snap[0].nent);
|
||||||
@ -721,10 +726,8 @@ void lj_gdbjit_addtrace(jit_State *J, GCtrace *T)
|
|||||||
ctx.filename++;
|
ctx.filename++;
|
||||||
else
|
else
|
||||||
ctx.filename = "(string)";
|
ctx.filename = "(string)";
|
||||||
ctx.trname = lj_str_pushf(L, "TRACE_%d", T->traceno);
|
|
||||||
L->top--;
|
|
||||||
gdbjit_buildobj(&ctx);
|
gdbjit_buildobj(&ctx);
|
||||||
gdbjit_newentry(L, &ctx);
|
gdbjit_newentry(J->L, &ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delete debug info for trace and notify GDB. */
|
/* Delete debug info for trace and notify GDB. */
|
||||||
|
Loading…
Reference in New Issue
Block a user