Skip to content

Commit

Permalink
Read in debug local names when in debug mode
Browse files Browse the repository at this point in the history
Place them in a hash, and make sure we mark it. We hang this off the
instrumentation struct, meaning that this costs no extra memory if we
are not in debug mode.
  • Loading branch information
jnthn committed Jan 29, 2019
1 parent 8c8b0b0 commit 6db78b9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/6model/reprs/MVMStaticFrame.c
Expand Up @@ -113,6 +113,7 @@ static void copy_to(MVMThreadContext *tc, MVMSTable *st, void *src, MVMObject *d
static void gc_mark(MVMThreadContext *tc, MVMSTable *st, void *data, MVMGCWorklist *worklist) {
MVMStaticFrameBody *body = (MVMStaticFrameBody *)data;
MVMLexicalRegistry *current;
MVMStaticFrameDebugLocal *current_debug_local;

/* mvmobjects */
MVM_gc_worklist_add(tc, worklist, &body->cu);
Expand Down Expand Up @@ -143,6 +144,13 @@ static void gc_mark(MVMThreadContext *tc, MVMSTable *st, void *data, MVMGCWorkli

/* Spesh. */
MVM_gc_worklist_add(tc, worklist, &body->spesh);

/* Debug symbols. */
if (body->instrumentation) {
HASH_ITER_FAST(tc, hash_handle, body->instrumentation->debug_locals, current_debug_local, {
MVM_gc_worklist_add(tc, worklist, &current_debug_local->name);
});
}
}

/* Called by the VM in order to free memory associated with this object. */
Expand Down
10 changes: 10 additions & 0 deletions src/6model/reprs/MVMStaticFrame.h
Expand Up @@ -134,6 +134,16 @@ struct MVMStaticFrameInstrumentation {
MVMFrameHandler *uninstrumented_handlers;
MVMuint32 uninstrumented_bytecode_size;
MVMuint32 instrumented_bytecode_size;
MVMStaticFrameDebugLocal *debug_locals;
};

struct MVMStaticFrameDebugLocal {
/* The index of the local where the value lives. */
MVMuint16 local_idx;
/* The name of the lexical. */
MVMString *name;
/* The uthash hash handle inline struct. */
UT_hash_handle hash_handle;
};

/* Function for REPR setup. */
Expand Down
23 changes: 21 additions & 2 deletions src/core/bytecode.c
Expand Up @@ -580,7 +580,7 @@ static MVMStaticFrame ** deserialize_frames(MVMThreadContext *tc, MVMCompUnit *c
/* Finishes up reading and exploding of a frame. */
void MVM_bytecode_finish_frame(MVMThreadContext *tc, MVMCompUnit *cu,
MVMStaticFrame *sf, MVMint32 dump_only) {
MVMuint32 j;
MVMuint32 j, num_debug_locals;
MVMuint8 *pos;
MVMuint16 slvs;
MVMuint16 bytecode_version = cu->body.bytecode_version;
Expand All @@ -605,8 +605,10 @@ void MVM_bytecode_finish_frame(MVMThreadContext *tc, MVMCompUnit *cu,
/* Locate start of frame body. */
pos = sf->body.frame_data_pos;

/* Get the number of static lex values we'll need to apply. */
/* Get the number of static lex values and debug local names we'll need
* to apply. */
slvs = read_int16(pos, 40);
num_debug_locals = read_int16(pos, 50);

/* Skip past header. */
pos += FRAME_HEADER_SIZE;
Expand Down Expand Up @@ -698,6 +700,23 @@ void MVM_bytecode_finish_frame(MVMThreadContext *tc, MVMCompUnit *cu,
pos += FRAME_SLV_SIZE;
}

/* Read in the debug local names if we're running the debug server. */
if (tc->instance->debugserver) {
MVMStaticFrameInstrumentation *ins = sf->body.instrumentation;
if (!ins)
ins = MVM_calloc(1, sizeof(MVMStaticFrameInstrumentation));
for (j = 0; j < num_debug_locals; j++) {
MVMuint16 idx = read_int16(pos, 0);
MVMString *name = get_heap_string(tc, cu, NULL, pos, 2);
MVMStaticFrameDebugLocal *entry = MVM_calloc(1, sizeof(MVMStaticFrameDebugLocal));
entry->local_idx = idx;
MVM_ASSIGN_REF(tc, &(sf->common.header), entry->name, name);
MVM_HASH_BIND(tc, ins->debug_locals, name, entry);
pos += 6;
}
sf->body.instrumentation = ins;
}

/* Mark the frame fully deserialized. */
sf->body.fully_deserialized = 1;

Expand Down
6 changes: 4 additions & 2 deletions src/instrument/line_coverage.c
Expand Up @@ -266,7 +266,9 @@ static void add_instrumentation(MVMThreadContext *tc, MVMStaticFrame *sf, MVMuin
else
instrument_graph_with_breakpoints(tc, sg);
sc = MVM_spesh_codegen(tc, sg);
ins = MVM_calloc(1, sizeof(MVMStaticFrameInstrumentation));
ins = sf->body.instrumentation;
if (!ins)
ins = MVM_calloc(1, sizeof(MVMStaticFrameInstrumentation));
ins->instrumented_bytecode = sc->bytecode;
ins->instrumented_handlers = sc->handlers;
ins->instrumented_bytecode_size = sc->bytecode_size;
Expand All @@ -283,7 +285,7 @@ static void add_instrumentation(MVMThreadContext *tc, MVMStaticFrame *sf, MVMuin
static void line_numbers_instrument(MVMThreadContext *tc, MVMStaticFrame *sf, MVMuint8 want_coverage) {
if (!sf->body.instrumentation || sf->body.bytecode != sf->body.instrumentation->instrumented_bytecode) {
/* Handle main, non-specialized, bytecode. */
if (!sf->body.instrumentation)
if (!sf->body.instrumentation || !sf->body.instrumentation->instrumented_bytecode)
add_instrumentation(tc, sf, want_coverage);
sf->body.bytecode = sf->body.instrumentation->instrumented_bytecode;
sf->body.handlers = sf->body.instrumentation->instrumented_handlers;
Expand Down
1 change: 1 addition & 0 deletions src/types.h
Expand Up @@ -205,6 +205,7 @@ typedef struct MVMSTable MVMSTable;
typedef struct MVMStaticFrame MVMStaticFrame;
typedef struct MVMStaticFrameBody MVMStaticFrameBody;
typedef struct MVMStaticFrameInstrumentation MVMStaticFrameInstrumentation;
typedef struct MVMStaticFrameDebugLocal MVMStaticFrameDebugLocal;
typedef struct MVMStaticFrameSpesh MVMStaticFrameSpesh;
typedef struct MVMStaticFrameSpeshBody MVMStaticFrameSpeshBody;
typedef struct MVMStorageSpec MVMStorageSpec;
Expand Down

0 comments on commit 6db78b9

Please sign in to comment.