mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-05 13:28:40 +00:00
helper for checking if ELF has DWARF debug sections
This commit is contained in:
+63
-2
@@ -1,7 +1,68 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#pragma once
|
||||
internal B32
|
||||
dw_is_dwarf_present_coff_section_table(String8 raw_image,
|
||||
U64 string_table_off,
|
||||
U64 section_count,
|
||||
COFF_SectionHeader *sections)
|
||||
{
|
||||
B32 is_dwarf_present = 0;
|
||||
|
||||
for (U64 i = 0; i < section_count; ++i) {
|
||||
COFF_SectionHeader *header = §ions[i];
|
||||
String8 name = coff_name_from_section_header(raw_image, header, string_table_off);
|
||||
|
||||
DW_SectionKind s = dw_section_kind_from_string(name);
|
||||
if (s == DW_Section_Null) {
|
||||
s = dw_section_dwo_kind_from_string(name);
|
||||
}
|
||||
|
||||
is_dwarf_present = s != DW_Section_Null;
|
||||
if (is_dwarf_present) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return is_dwarf_present;
|
||||
}
|
||||
|
||||
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};
|
||||
|
||||
for (U64 i = 0; i < section_count; ++i) {
|
||||
COFF_SectionHeader *header = §ions[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_kind_from_string(name);
|
||||
B32 is_dwo = 0;
|
||||
if (s == DW_Section_Null) {
|
||||
s = dw_section_dwo_kind_from_string(name);
|
||||
is_dwo = 1;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user