helper for checking if ELF has DWARF debug sections

This commit is contained in:
Nikita Smith
2025-03-26 12:18:47 -07:00
parent b9c4774786
commit a84028d67a
4 changed files with 129 additions and 51 deletions
+4 -38
View File
@@ -1,44 +1,10 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal DW_Input
dw_input_from_coff_section_table(Arena *arena,
String8 raw_image,
U64 string_table_off,
U64 section_count,
COFF_SectionHeader *sections)
{
DW_Input input = {0};
B32 sect_status[ArrayCount(input.sec)] = {0};
#ifndef DWARF_COFF_H
#define DWARF_COFF_H
for (U64 i = 0; i < section_count; ++i) {
COFF_SectionHeader *header = &sections[i];
Rng1U64 raw_data_range = rng_1u64(header->foff, header->foff + header->fsize);
String8 name = coff_name_from_section_header(raw_image, header, string_table_off);
DW_SectionKind s = DW_Section_Null;
B32 is_dwo = 0;
#define X(_K,_L,_M,_W) \
if (str8_match_lit(_L, name, 0)) { s = DW_Section_##_K; } \
if (str8_match_lit(_M, name, 0)) { s = DW_Section_##_K; } \
if (str8_match_lit(_W, name, 0)) { s = DW_Section_##_K; is_dwo = 1; }
DW_SectionKind_XList(X)
#undef X
if (s != DW_Section_Null) {
if (sect_status[s]) {
Assert(!"too many debug sections with identical name, picking first");
} else {
sect_status[s] = 1;
DW_Section *d = &input.sec[s];
d->name = push_str8_copy(arena, name);
d->data = str8_substr(raw_image, raw_data_range);
d->is_dwo = is_dwo;
}
}
}
return input;
}
internal DW_Input dw_input_from_coff_section_table(Arena *arena, String8 raw_image, U64 string_table_off, U64 section_count, COFF_SectionHeader *sections);
#endif // DWARF_COFF_H