~laumann/hadb

ee660f6549b63abdb1e88c17935554539d5f77c9 — Thomas Bracht Laumann Jespersen 4 months ago 8b0cac7
format/dwarf: parse DW_FORM_implicit_const extra param
2 files changed, 14 insertions(+), 15 deletions(-)

M cmd/decodeabbrev/main.ha
M format/dwarf/abbrev.ha
M cmd/decodeabbrev/main.ha => cmd/decodeabbrev/main.ha +7 -15
@@ 7,28 7,20 @@ use io;
// section, we should try to exhaustively decode all of it.

export fn main() void = {
	fmt::println("usage: decodeabbrev [file]")!;
	for (let i = 0z; i < len(os::args); i +=1 ) {
		fmt::printfln(" - {}", os::args[i])!;
	};

	let f = if (len(os::args) < 2) {
		// read from os::stdin
		yield os::stdin_file;
	} else {
		// open file for reading
		fmt::printfln("opening {}", os::args[1])!;
		yield os::open(os::args[1])!;
	};
	let f = if (len(os::args) < 2) os::stdin_file
		else os::open(os::args[1])!;

	let bin = io::drain(f)!;
	let (abbrevs, read) = dwarf::decodeabbrev(bin)!;
	defer dwarf::freeabbrevs(abbrevs);
	fmt::printfln("read {} ({:_04x}) bytes of {} total", read, read, len(bin))!;

	fmt::printfln("read {} (0x{:_04x}) bytes of {} total", read, read, len(bin))!;
	for (let i = 0z; i < len(abbrevs); i += 1) {
		const abbrev = abbrevs[i];
		fmt::printfln("<{}> tag = {:_02x} [{}]",
		fmt::printfln("<{}> tag = {:_02x} [{}] ({} attrs)",
			abbrev.code: uint, abbrev.tag: uint,
			if (abbrev.haschildren) "has children" else "no children")!;
			if (abbrev.haschildren) "has children" else "no children",
			len(abbrev.attrs))!;
	};
};

M format/dwarf/abbrev.ha => format/dwarf/abbrev.ha +7 -0
@@ 53,6 53,13 @@ export fn decodeabbrev(input: []u8) (([]abbrev, size) | partialread) = {
			p = p[r..];
			if (at == 0 && dwform == 0)
				break; // done
			switch (dwform) {
			case form::IMPLICIT_CONST: uint =>
				const (x, r) = readsleb128(p)!;
				p = p[r..];
			case =>
				void;
			};
			append(attrs, (at: attr, dwform: form));
		};
		append(ret, abbrev {