Skip to content

Commit

Permalink
add "debug_name" field to STable struct and setdebugtypename
Browse files Browse the repository at this point in the history
  • Loading branch information
timo committed Mar 12, 2016
1 parent 0f7ea20 commit 4c01c3a
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 170 deletions.
216 changes: 111 additions & 105 deletions lib/MAST/Ops.nqp
Expand Up @@ -743,64 +743,65 @@ BEGIN {
1843,
1846,
1848,
1848,
1850,
1850,
1852,
1855,
1858,
1861,
1864,
1854,
1857,
1860,
1863,
1866,
1868,
1870,
1872,
1874,
1877,
1880,
1883,
1886,
1887,
1876,
1879,
1882,
1885,
1888,
1889,
1893,
1896,
1899,
1902,
1905,
1908,
1911,
1914,
1917,
1920,
1923,
1926,
1929,
1932,
1935,
1938,
1941,
1945,
1949,
1952,
1955,
1958,
1961,
1964,
1967,
1970,
1973,
1976,
1979,
1982,
1983,
1891,
1895,
1898,
1901,
1904,
1907,
1910,
1913,
1916,
1919,
1922,
1925,
1928,
1931,
1934,
1937,
1940,
1943,
1947,
1951,
1954,
1957,
1960,
1963,
1966,
1969,
1972,
1975,
1978,
1981,
1984,
1985,
1987,
1989,
1989,
1989,
1990,
1991,
1991,
1992);
1991,
1992,
1993,
1993,
1994);
MAST::Ops.WHO<@counts> := nqp::list_i(0,
2,
2,
Expand Down Expand Up @@ -1540,6 +1541,7 @@ BEGIN {
3,
3,
2,
2,
0,
2,
2,
Expand Down Expand Up @@ -3446,6 +3448,8 @@ BEGIN {
57,
33,
65,
57,
65,
16,
65,
128,
Expand Down Expand Up @@ -4331,66 +4335,67 @@ BEGIN {
'param_on2_u', 735,
'stat_time', 736,
'lstat_time', 737,
'sp_log', 738,
'sp_osrfinalize', 739,
'sp_guardconc', 740,
'sp_guardtype', 741,
'sp_guardcontconc', 742,
'sp_guardconttype', 743,
'sp_guardrwconc', 744,
'sp_guardrwtype', 745,
'sp_getarg_o', 746,
'sp_getarg_i', 747,
'sp_getarg_n', 748,
'sp_getarg_s', 749,
'sp_fastinvoke_v', 750,
'sp_fastinvoke_i', 751,
'sp_fastinvoke_n', 752,
'sp_fastinvoke_s', 753,
'sp_fastinvoke_o', 754,
'sp_namedarg_used', 755,
'sp_getspeshslot', 756,
'sp_findmeth', 757,
'sp_fastcreate', 758,
'sp_get_o', 759,
'sp_get_i64', 760,
'sp_get_i32', 761,
'sp_get_i16', 762,
'sp_get_i8', 763,
'sp_get_n', 764,
'sp_get_s', 765,
'sp_bind_o', 766,
'sp_bind_i64', 767,
'sp_bind_i32', 768,
'sp_bind_i16', 769,
'sp_bind_i8', 770,
'sp_bind_n', 771,
'sp_bind_s', 772,
'sp_p6oget_o', 773,
'sp_p6ogetvt_o', 774,
'sp_p6ogetvc_o', 775,
'sp_p6oget_i', 776,
'sp_p6oget_n', 777,
'sp_p6oget_s', 778,
'sp_p6obind_o', 779,
'sp_p6obind_i', 780,
'sp_p6obind_n', 781,
'sp_p6obind_s', 782,
'sp_deref_get_i64', 783,
'sp_deref_get_n', 784,
'sp_deref_bind_i64', 785,
'sp_deref_bind_n', 786,
'sp_jit_enter', 787,
'sp_boolify_iter', 788,
'sp_boolify_iter_arr', 789,
'sp_boolify_iter_hash', 790,
'prof_enter', 791,
'prof_enterspesh', 792,
'prof_enterinline', 793,
'prof_enternative', 794,
'prof_exit', 795,
'prof_allocated', 796,
'ctw_check', 797);
'setdebugtypename', 738,
'sp_log', 739,
'sp_osrfinalize', 740,
'sp_guardconc', 741,
'sp_guardtype', 742,
'sp_guardcontconc', 743,
'sp_guardconttype', 744,
'sp_guardrwconc', 745,
'sp_guardrwtype', 746,
'sp_getarg_o', 747,
'sp_getarg_i', 748,
'sp_getarg_n', 749,
'sp_getarg_s', 750,
'sp_fastinvoke_v', 751,
'sp_fastinvoke_i', 752,
'sp_fastinvoke_n', 753,
'sp_fastinvoke_s', 754,
'sp_fastinvoke_o', 755,
'sp_namedarg_used', 756,
'sp_getspeshslot', 757,
'sp_findmeth', 758,
'sp_fastcreate', 759,
'sp_get_o', 760,
'sp_get_i64', 761,
'sp_get_i32', 762,
'sp_get_i16', 763,
'sp_get_i8', 764,
'sp_get_n', 765,
'sp_get_s', 766,
'sp_bind_o', 767,
'sp_bind_i64', 768,
'sp_bind_i32', 769,
'sp_bind_i16', 770,
'sp_bind_i8', 771,
'sp_bind_n', 772,
'sp_bind_s', 773,
'sp_p6oget_o', 774,
'sp_p6ogetvt_o', 775,
'sp_p6ogetvc_o', 776,
'sp_p6oget_i', 777,
'sp_p6oget_n', 778,
'sp_p6oget_s', 779,
'sp_p6obind_o', 780,
'sp_p6obind_i', 781,
'sp_p6obind_n', 782,
'sp_p6obind_s', 783,
'sp_deref_get_i64', 784,
'sp_deref_get_n', 785,
'sp_deref_bind_i64', 786,
'sp_deref_bind_n', 787,
'sp_jit_enter', 788,
'sp_boolify_iter', 789,
'sp_boolify_iter_arr', 790,
'sp_boolify_iter_hash', 791,
'prof_enter', 792,
'prof_enterspesh', 793,
'prof_enterinline', 794,
'prof_enternative', 795,
'prof_exit', 796,
'prof_allocated', 797,
'ctw_check', 798);
MAST::Ops.WHO<@names> := nqp::list_s('no_op',
'const_i8',
'const_i16',
Expand Down Expand Up @@ -5129,6 +5134,7 @@ BEGIN {
'param_on2_u',
'stat_time',
'lstat_time',
'setdebugtypename',
'sp_log',
'sp_osrfinalize',
'sp_guardconc',
Expand Down
4 changes: 4 additions & 0 deletions src/6model/6model.h
Expand Up @@ -342,6 +342,10 @@ struct MVMSTable {
/* Also info we need to lazily deserialize the method cache. */
MVMuint32 method_cache_offset;
MVMSerializationContext *method_cache_sc;

/* A string associated with this STable for debugging purposes.
* Usually the name of the class this belongs to. */
char *debug_name;
};

/* The representation operations table. Note that representations are not
Expand Down
47 changes: 46 additions & 1 deletion src/6model/serialization.c
Expand Up @@ -10,7 +10,7 @@

/* Version of the serialization format that we are currently at and lowest
* version we support. */
#define CURRENT_VERSION 17
#define CURRENT_VERSION 18
#define MIN_VERSION 16

/* Various sizes (in bytes). */
Expand Down Expand Up @@ -324,6 +324,23 @@ static void expand_storage_if_needed(MVMThreadContext *tc, MVMSerializationWrite
}
}

/* Writing function for null-terminated char array strings */
void MVM_serialization_write_cstr(MVMThreadContext *tc, MVMSerializationWriter *writer, char *string) {
size_t len;
if (string)
len = strlen(string);
else
len = 0;
if (len) {
MVM_serialization_write_varint(tc, writer, len);
expand_storage_if_needed(tc, writer, len);
memcpy(*(writer->cur_write_buffer) + *(writer->cur_write_offset), string, len);
*(writer->cur_write_offset) += len;
} else {
MVM_serialization_write_varint(tc, writer, 0);
}
}

/* Writing function for native integers. */
void MVM_serialization_write_int(MVMThreadContext *tc, MVMSerializationWriter *writer, MVMint64 value) {
expand_storage_if_needed(tc, writer, 8);
Expand Down Expand Up @@ -1107,6 +1124,8 @@ static void serialize_stable(MVMThreadContext *tc, MVMSerializationWriter *write
add_param_intern(tc, writer, st->WHAT, ptype, params);
}

MVM_serialization_write_cstr(tc, writer, st->debug_name);

/* Store offset we save REPR data at. */
write_int32(writer->root.stables_table, offset + 8, writer->stables_data_offset);

Expand Down Expand Up @@ -1620,6 +1639,26 @@ MVMString * MVM_serialization_read_str(MVMThreadContext *tc, MVMSerializationRea
return read_string_from_heap(tc, reader, offset);
}

/* Reading function for null-terminated char array strings */
char *MVM_serialization_read_cstr(MVMThreadContext *tc, MVMSerializationReader *reader) {
size_t len = MVM_serialization_read_varint(tc, reader);
char *strbuf = 0;
if (len > 0) {
const MVMuint8 *read_at = (MVMuint8 *) *(reader->cur_read_buffer) + *(reader->cur_read_offset);
assert_can_read(tc, reader, len);
strbuf = MVM_malloc(len + 1);
if (strbuf == 0)
fail_deserialize(tc, reader, "Cannot read a c string: malloc failed.");
memcpy(strbuf, read_at, len);
strbuf[len] = 0;
*(reader->cur_read_offset) += len;
fprintf(stderr, "the debug name of this thing lives at %p and is %s\n", strbuf, strbuf);
} else if (len < 0) {

This comment has been minimized.

Copy link
@vendethiel

vendethiel Apr 21, 2016

Contributor

size_t is unsigned, so this is trivially false (thanks -Wtautological-compare)

fail_deserialize(tc, reader, "Cannot read a c string with negative length %d.", len);
}
return strbuf;
}

/* The SC id,idx pair is used in various ways, but common to them all is to
look up the SC, then use the index to call some other function. Putting the
common parts into one function permits the serialized representation to be
Expand Down Expand Up @@ -2481,6 +2520,12 @@ static void deserialize_stable(MVMThreadContext *tc, MVMSerializationReader *rea
MVM_repr_push_o(tc, lookup, st->WHAT);
}

if (reader->root.version >= 18) {
st->debug_name = MVM_serialization_read_cstr(tc, reader);
} else {
st->debug_name = 0;
}

/* If the REPR has a function to deserialize representation data, call it. */
if (st->REPR->deserialize_repr_data)
st->REPR->deserialize_repr_data(tc, st, reader);
Expand Down
14 changes: 14 additions & 0 deletions src/core/interp.c
Expand Up @@ -4974,6 +4974,20 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
GET_REG(cur_op, 0).n64 = MVM_file_time(tc, GET_REG(cur_op, 2).s, GET_REG(cur_op, 4).i64, 1);
cur_op += 6;
goto NEXT;
OP(setdebugtypename): {
MVMObject *obj = GET_REG(cur_op, 0).o;
if (MVM_string_graphs(tc, GET_REG(cur_op, 2).s)) {
char *debugname = MVM_string_utf8_encode_C_string(tc, GET_REG(cur_op, 2).s);
if (STABLE(obj)->debug_name) {
MVM_free(STABLE(obj)->debug_name);
}
STABLE(obj)->debug_name = debugname;
} else {
STABLE(obj)->debug_name = NULL;
}
cur_op += 4;
goto NEXT;
}
OP(sp_log):
if (tc->cur_frame->spesh_log_idx >= 0) {
MVM_ASSIGN_REF(tc, &(tc->cur_frame->static_info->common.header),
Expand Down
1 change: 1 addition & 0 deletions src/core/oplist
Expand Up @@ -777,6 +777,7 @@ param_rn2_u w(uint64) str str :noinline
param_on2_u w(uint64) str str ins :noinline
stat_time w(num64) r(str) r(int64)
lstat_time w(num64) r(str) r(int64)
setdebugtypename r(obj) r(str)

# Spesh ops. Naming convention: start with sp_. Must all be marked .s, which
# is how the validator knows to exclude them.
Expand Down

0 comments on commit 4c01c3a

Please sign in to comment.