Skip to content

Commit

Permalink
fixup! Implement support for debug information in the runtime system
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorng committed Jan 29, 2025
1 parent f181f0d commit 463d057
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
33 changes: 20 additions & 13 deletions erts/emulator/beam/beam_bif_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -1288,27 +1288,31 @@ BIF_RETTYPE code_get_debug_info_1(BIF_ALIST_1)
alloc_size = 0;

for (i = 0; i < debug->item_count; i++) {
/* [ {Index, {FrameSize,[{Name,Value}]} ] */
alloc_size += 2 + 3 + 3 + debug->items[i].num_vars * (2 + 3 + 3);
/* [ {Line, {FrameSize, Pairs}} ] */
alloc_size += 2 + 3 + 3;
/* Pairs = [{Name, Value}], where Value is an atom or 2-tuple.
*
* Assume they are all 2-tuples and HRelease() the excess
* later. */
alloc_size += debug->items[i].num_vars * (2 + 3 + 3);
}

hp = HAlloc(BIF_P, alloc_size);
hend = hp + alloc_size;

for (i = debug->item_count-1; i >= 0; i--) {
BeamDebugItem* items = &debug->items[i];
Uint32 location_index;
Sint frame_size = items->frame_size;
Uint32 location;
Uint num_vars = items->num_vars;
Eterm *tp = items->first + 2 * num_vars - 2;
Eterm *tp = &items->first[2 * (num_vars - 1)];
Uint32 location_index, location;
Eterm frame_size_term;
Eterm var_list = NIL;
Eterm tmp;

location_index = items->location_index;

if (location_index == (Uint32)-1) {
if (location_index == ERTS_UINT32_MAX) {
continue;
}
if (lt->loc_size == 2) {
Expand All @@ -1326,6 +1330,7 @@ BIF_RETTYPE code_get_debug_info_1(BIF_ALIST_1)
frame_size_term = am_none;
break;
default:
ASSERT(frame_size >= 0);
frame_size_term = make_small(frame_size);
break;
}
Expand All @@ -1334,17 +1339,19 @@ BIF_RETTYPE code_get_debug_info_1(BIF_ALIST_1)
Eterm val;
Eterm tag;

if (_is_loader_x_reg(tp[1])) {
Uint xreg = loader_x_reg_index(tp[1]);
switch(loader_tag(tp[1])) {
case LOADER_X_REG:
tag = am_x;
val = make_small(xreg);
} else if (_is_loader_y_reg(tp[1])) {
Uint yreg = loader_y_reg_index(tp[1]);
val = make_small(loader_x_reg_index(tp[1]));
break;
case LOADER_Y_REG:
tag = am_y;
val = make_small(yreg);
} else {
val = make_small(loader_y_reg_index(tp[1]));
break;
default:
tag = am_value;
val = tp[1];
break;
}
tmp = TUPLE2(hp, tag, val);
hp += 3;
Expand Down
6 changes: 5 additions & 1 deletion erts/emulator/beam/beam_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,10 +753,14 @@ static int parse_debug_chunk_data(BeamFile *beam, BeamReader *p_reader) {

arg++;

if (extra_args % 2 != 0) {
goto error;
}

/* Process the list of variable mappings. */

num_vars = extra_args / 2;
if (2 * num_vars != extra_args || num_vars > total_num_vars) {
if (num_vars > total_num_vars) {
goto error;
}
total_num_vars -= num_vars;
Expand Down

0 comments on commit 463d057

Please sign in to comment.