Skip to content

Commit

Permalink
fix: Make Windows ModuleFinder more resilient to missing Debug Info (#…
Browse files Browse the repository at this point in the history
…732)

Previously the Windows ModuleFinder would early-return in case the
loaded library had no debug directory / codeview record.
In that case, the image type and code-id would be missing which results
in normalization errors in Relay. We now always write the image type,
and the code-id as early as possible.
  • Loading branch information
Swatinem authored Jul 1, 2022
1 parent 6531a26 commit f32330b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/modulefinder/sentry_modulefinder_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ extract_pdb_info(uintptr_t module_addr, sentry_value_t module)
return;
}

char id_buf[50];
snprintf(id_buf, sizeof(id_buf), "%08x%X",
nt_headers->FileHeader.TimeDateStamp,
nt_headers->OptionalHeader.SizeOfImage);
sentry_value_set_by_key(module, "code_id", sentry_value_new_string(id_buf));

uint32_t relative_addr
= nt_headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG]
.VirtualAddress;
Expand All @@ -63,18 +69,11 @@ extract_pdb_info(uintptr_t module_addr, sentry_value_t module)

sentry_uuid_t debug_id_base
= sentry__uuid_from_native(&debug_info->pdb_signature);
char id_buf[50];
sentry_uuid_as_string(&debug_id_base, id_buf);
id_buf[36] = '-';
snprintf(id_buf + 37, 10, "%x", debug_info->pdb_age);
sentry_value_set_by_key(
module, "debug_id", sentry_value_new_string(id_buf));

snprintf(id_buf, sizeof(id_buf), "%08x%X",
nt_headers->FileHeader.TimeDateStamp,
nt_headers->OptionalHeader.SizeOfImage);
sentry_value_set_by_key(module, "code_id", sentry_value_new_string(id_buf));
sentry_value_set_by_key(module, "type", sentry_value_new_string("pe"));
}

static void
Expand All @@ -97,6 +96,8 @@ load_modules(void)
module.modBaseAddr, &vmem_info, sizeof(vmem_info))
&& vmem_info.State == MEM_COMMIT) {
sentry_value_t rv = sentry_value_new_object();
sentry_value_set_by_key(
rv, "type", sentry_value_new_string("pe"));
sentry_value_set_by_key(rv, "image_addr",
sentry__value_new_addr((uint64_t)module.modBaseAddr));
sentry_value_set_by_key(rv, "image_size",
Expand Down

0 comments on commit f32330b

Please sign in to comment.