File: strings.ha

package info (click to toggle)
hare 0.25.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,948 kB
  • sloc: asm: 1,264; makefile: 123; sh: 114; lisp: 101
file content (32 lines) | stat: -rw-r--r-- 729 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// SPDX-License-Identifier: MPL-2.0
// (c) Hare authors <https://harelang.org>

use debug::image;
use format::elf;
use io;
use types::c;

export type string_table = struct {
	data: []u8,
};

// Loads a DWARF string table from .debug_str.
export fn load_strings(
	image: *image::image,
) (string_table | void | io::error) = {
	const sec = match (image::section_byname(image, ".debug_str")) {
	case let sec: *elf::section64 =>
		yield sec;
	case null =>
		return;
	};
	return string_table {
		data = image::section_data(image, sec),
	};
};

// Returns a string from the string table.
export fn get_strp(table: *string_table, offs: u64) const str = {
	const string = &table.data[offs]: *const c::char;
	return c::tostr(string)!;
};