diff options
author | Mike Pall <mike> | 2010-05-09 03:27:24 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2010-05-09 03:27:24 +0200 |
commit | 41ec9a94b39dd7033c719eb89d13339dc77d9146 (patch) | |
tree | 5050521d12491f8653845245e737702163d7c336 /src | |
parent | 5ff994fa3767e47ebc3ed66959d63caba990d920 (diff) | |
download | luajit-41ec9a94b39dd7033c719eb89d13339dc77d9146.tar.gz luajit-41ec9a94b39dd7033c719eb89d13339dc77d9146.tar.bz2 luajit-41ec9a94b39dd7033c719eb89d13339dc77d9146.zip |
Avoid string allocation in GDB JIT API.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.dep | 2 | ||||
-rw-r--r-- | src/lj_gdbjit.c | 17 |
2 files changed, 11 insertions, 8 deletions
diff --git a/src/Makefile.dep b/src/Makefile.dep index aeeeeff5..22eb56b0 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep | |||
@@ -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 \ | |||
68 | lj_state.h lj_frame.h lj_bc.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h \ | 68 | lj_state.h lj_frame.h lj_bc.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h \ |
69 | lj_traceerr.h lj_vm.h | 69 | lj_traceerr.h lj_vm.h |
70 | lj_gdbjit.o: lj_gdbjit.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 70 | lj_gdbjit.o: lj_gdbjit.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
71 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_frame.h lj_bc.h lj_jit.h \ | 71 | lj_gc.h lj_err.h lj_errmsg.h lj_frame.h lj_bc.h lj_jit.h \ |
72 | lj_ir.h lj_dispatch.h | 72 | lj_ir.h lj_dispatch.h |
73 | lj_ir.o: lj_ir.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ | 73 | lj_ir.o: lj_ir.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \ |
74 | lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \ | 74 | lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \ |
diff --git a/src/lj_gdbjit.c b/src/lj_gdbjit.c index dc85c076..30aab774 100644 --- a/src/lj_gdbjit.c +++ b/src/lj_gdbjit.c | |||
@@ -12,7 +12,6 @@ | |||
12 | 12 | ||
13 | #include "lj_gc.h" | 13 | #include "lj_gc.h" |
14 | #include "lj_err.h" | 14 | #include "lj_err.h" |
15 | #include "lj_str.h" | ||
16 | #include "lj_frame.h" | 15 | #include "lj_frame.h" |
17 | #include "lj_jit.h" | 16 | #include "lj_jit.h" |
18 | #include "lj_dispatch.h" | 17 | #include "lj_dispatch.h" |
@@ -385,7 +384,6 @@ typedef struct GDBJITctx { | |||
385 | MSize spadj; /* Stack adjustment for trace itself. */ | 384 | MSize spadj; /* Stack adjustment for trace itself. */ |
386 | BCLine lineno; /* Starting line number. */ | 385 | BCLine lineno; /* Starting line number. */ |
387 | const char *filename; /* Starting file name. */ | 386 | const char *filename; /* Starting file name. */ |
388 | const char *trname; /* Name of trace. */ | ||
389 | size_t objsize; /* Final size of ELF object. */ | 387 | size_t objsize; /* Final size of ELF object. */ |
390 | GDBJITobj obj; /* In-memory ELF object. */ | 388 | GDBJITobj obj; /* In-memory ELF object. */ |
391 | } GDBJITctx; | 389 | } GDBJITctx; |
@@ -402,6 +400,13 @@ static uint32_t gdbjit_strz(GDBJITctx *ctx, const char *str) | |||
402 | return ofs; | 400 | return ofs; |
403 | } | 401 | } |
404 | 402 | ||
403 | /* Append a decimal number. */ | ||
404 | static void gdbjit_catnum(GDBJITctx *ctx, uint32_t n) | ||
405 | { | ||
406 | if (n >= 10) { uint32_t m = n / 10; n = n % 10; gdbjit_catnum(ctx, m); } | ||
407 | *ctx->p++ = '0' + n; | ||
408 | } | ||
409 | |||
405 | /* Add a ULEB128 value. */ | 410 | /* Add a ULEB128 value. */ |
406 | static void gdbjit_uleb128(GDBJITctx *ctx, uint32_t v) | 411 | static void gdbjit_uleb128(GDBJITctx *ctx, uint32_t v) |
407 | { | 412 | { |
@@ -488,7 +493,8 @@ static void LJ_FASTCALL gdbjit_symtab(GDBJITctx *ctx) | |||
488 | sym->info = ELFSYM_TYPE_FILE|ELFSYM_BIND_LOCAL; | 493 | sym->info = ELFSYM_TYPE_FILE|ELFSYM_BIND_LOCAL; |
489 | 494 | ||
490 | sym = &ctx->obj.sym[GDBJIT_SYM_FUNC]; | 495 | sym = &ctx->obj.sym[GDBJIT_SYM_FUNC]; |
491 | sym->name = gdbjit_strz(ctx, ctx->trname); | 496 | sym->name = gdbjit_strz(ctx, "TRACE_"); ctx->p--; |
497 | gdbjit_catnum(ctx, ctx->T->traceno); *ctx->p++ = '\0'; | ||
492 | sym->sectidx = GDBJIT_SECT_text; | 498 | sym->sectidx = GDBJIT_SECT_text; |
493 | sym->value = 0; | 499 | sym->value = 0; |
494 | sym->size = ctx->szmcode; | 500 | sym->size = ctx->szmcode; |
@@ -701,7 +707,6 @@ static void gdbjit_newentry(lua_State *L, GDBJITctx *ctx) | |||
701 | void lj_gdbjit_addtrace(jit_State *J, GCtrace *T) | 707 | void lj_gdbjit_addtrace(jit_State *J, GCtrace *T) |
702 | { | 708 | { |
703 | GDBJITctx ctx; | 709 | GDBJITctx ctx; |
704 | lua_State *L = J->L; | ||
705 | GCproto *pt = &gcref(T->startpt)->pt; | 710 | GCproto *pt = &gcref(T->startpt)->pt; |
706 | TraceNo parent = T->ir[REF_BASE].op1; | 711 | TraceNo parent = T->ir[REF_BASE].op1; |
707 | uintptr_t pcofs = (uintptr_t)(T->snap[0].mapofs+T->snap[0].nent); | 712 | 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) | |||
721 | ctx.filename++; | 726 | ctx.filename++; |
722 | else | 727 | else |
723 | ctx.filename = "(string)"; | 728 | ctx.filename = "(string)"; |
724 | ctx.trname = lj_str_pushf(L, "TRACE_%d", T->traceno); | ||
725 | L->top--; | ||
726 | gdbjit_buildobj(&ctx); | 729 | gdbjit_buildobj(&ctx); |
727 | gdbjit_newentry(L, &ctx); | 730 | gdbjit_newentry(J->L, &ctx); |
728 | } | 731 | } |
729 | 732 | ||
730 | /* Delete debug info for trace and notify GDB. */ | 733 | /* Delete debug info for trace and notify GDB. */ |