Skip to content

Commit

Permalink
on lambda types we have to replace unique name with hash,
Browse files Browse the repository at this point in the history
otherwise visual studio wont show local variables in lambdas
  • Loading branch information
NikitaSmith057 committed Jan 17, 2025
1 parent de2ea38 commit 89ff4d0
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/linker/lnk_debug_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -2505,15 +2505,17 @@ THREAD_POOL_TASK_FUNC(lnk_replace_type_names_with_hashes_lenient_task)
map = &task->maps[task_id];
}

U64 hash_max_chars = hash_length;
U64 hash_max_chars = hash_length*2;
U8 temp[128];

for (U64 leaf_idx = range.min; leaf_idx < range.max; ++leaf_idx) {
CV_Leaf leaf = cv_debug_t_get_leaf(debug_t, leaf_idx);
if (leaf.kind == CV_LeafKind_STRUCTURE || leaf.kind == CV_LeafKind_CLASS) {
CV_UDTInfo udt_info = cv_get_udt_info(leaf.kind, leaf.data);

if (udt_info.props & CV_TypeProp_HasUniqueName && udt_info.unique_name.size > hash_max_chars) {
if ((udt_info.props & CV_TypeProp_HasUniqueName) &&
udt_info.unique_name.size > hash_max_chars &&
udt_info.name.size > hash_max_chars) {
// hash unique name
U128 name_hash;
blake3_hasher hasher; blake3_hasher_init(&hasher);
Expand All @@ -2523,27 +2525,33 @@ THREAD_POOL_TASK_FUNC(lnk_replace_type_names_with_hashes_lenient_task)
// emit hash -> unique name map
if (make_map) {
lnk_format_u128(temp, sizeof(temp), hash_length, name_hash);
str8_list_pushf(map_arena, map, "%s %.*s\n", temp, str8_varg(udt_info.unique_name));
str8_list_pushf(map_arena, map, "%s %S\n", temp, str8_varg(udt_info.unique_name));
}

// parse leaf size
CV_NumericParsed dummy;
U64 numeric_size = cv_read_numeric(leaf.data, sizeof(CV_LeafStruct), &dummy);

U64 colon_pos = str8_find_needle_reverse(udt_info.name, 0, str8_lit("<lambda_"), 0);
B32 is_lambda = colon_pos != 0;
String8 lambda_prefix = str8_lit("<lambda_");
U64 colon_pos = str8_find_needle_reverse(udt_info.name, 0, lambda_prefix, 0);
B32 is_lambda = colon_pos != 0;

if (is_lambda) {
// replace display type string with unique type name hash
udt_info.name.size = lnk_format_u128(udt_info.name.str, udt_info.name.size, hash_length, name_hash);
U64 size = lnk_format_u128(temp, sizeof(temp), hash_length, name_hash);
Assert(size < udt_info.name.size);
Assert(size < udt_info.unique_name.size);
MemoryCopy(udt_info.name.str, temp, size+1);
MemoryCopy(udt_info.name.str+size+1, temp, size+1);
udt_info.name.size = size;
udt_info.unique_name.size = size;

// update leaf header
CV_LeafHeader *header = cv_debug_t_get_leaf_header(debug_t, leaf_idx);
header->size = sizeof(CV_LeafKind) + sizeof(CV_LeafStruct) + numeric_size + udt_info.name.size + 1;

// discard unique name
CV_LeafStruct *lf = (CV_LeafStruct *)(header + 1);
lf->props &= ~CV_TypeProp_HasUniqueName;
header->size = sizeof(CV_LeafKind) +
sizeof(CV_LeafStruct) +
numeric_size +
udt_info.name.size + 1 +
udt_info.unique_name.size + 1;
} else {
// replace uniuqe type name with hash
udt_info.unique_name.str = udt_info.name.str + udt_info.name.size + 1;
Expand Down

0 comments on commit 89ff4d0

Please sign in to comment.