| 1 |
// SPDX-License-Identifier: MPL-2.0 |
| 2 |
// (c) Hare authors <https://harelang.org> |
| 3 |
|
| 4 |
use debug::image; |
| 5 |
use format::elf; |
| 6 |
use io; |
| 7 |
use types::c; |
| 8 |
|
| 9 |
export type string_table = struct { |
| 10 |
data: []u8, |
| 11 |
}; |
| 12 |
|
| 13 |
// Loads a DWARF string table from .debug_str. |
| 14 |
export fn load_strings( |
| 15 |
image: *image::image, |
| 16 |
) (string_table | void | io::error) = { |
| 17 |
const sec = match (image::section_byname(image, ".debug_str")) { |
| 18 |
case let sec: *elf::section64 => |
| 19 |
yield sec; |
| 20 |
case null => |
| 21 |
return; |
| 22 |
}; |
| 23 |
return string_table { |
| 24 |
data = image::section_data(image, sec), |
| 25 |
}; |
| 26 |
}; |
| 27 |
|
| 28 |
// Returns a string from the string table. |
| 29 |
export fn get_strp(table: *string_table, offs: u64) const str = { |
| 30 |
const string = &table.data[offs]: *const c::char; |
| 31 |
return c::tostr(string)!; |
| 32 |
}; |