~laumann/hadb

48e49de476f178148144c4fcf0bedec2466fb94f — Thomas Bracht Laumann Jespersen 4 months ago ee660f6 master
format/dwarf: call freestrs() in test
2 files changed, 12 insertions(+), 9 deletions(-)

M format/dwarf/abbrev.ha
M format/dwarf/str.ha
M format/dwarf/abbrev.ha => format/dwarf/abbrev.ha +2 -2
@@ 148,8 148,8 @@ export fn decodeabbrev(input: []u8) (([]abbrev, size) | partialread) = {
	};
};

@test fn larger() void = {
	const bin: []u8 = [
@test fn largerabbrev() void = {
	const bin: [_]u8 = [
		0x01, 0x11, 0x01, 0x25, 0x0e, 0x13, 0x0b, 0x03,
		0x0e, 0x1b, 0x0e, 0x11, 0x01, 0x12, 0x01, 0x10,
		0x06, 0x00, 0x00, 0x02, 0x2e, 0x01, 0x3f, 0x0c,

M format/dwarf/str.ha => format/dwarf/str.ha +10 -7
@@ 1,6 1,12 @@
// Load the string table that is .debug_str
use strings;

export fn freestrs(strs: [](str, size)) void = {
	for (let i = 0z; i < len(strs); i += 1)
		free(strs[i].0);
	free(strs);
};

// Return the strings in .debug_str as a list of tuples - the strings
// themselves and their index in the section.
//


@@ 8,11 14,7 @@ use strings;
export fn decodestr(input: []u8) (([](str, size), size) | partialread) = {
	let strs: [](str, size) = [];
	let err = true;
	defer if (err) {
		for (let i = 0z; i < len(strs); i += 1)
			free(strs[i].0);
		free(strs);
	};
	defer if (err) freestrs(strs);

	let i = 0z;
	let p = 0z;


@@ 30,7 32,7 @@ export fn decodestr(input: []u8) (([](str, size), size) | partialread) = {
};

@test fn decodestr() void = {
	const bin: []u8 = [
	const bin: [_]u8 = [
		// Hex dump of section '.debug_str':
		0x73, 0x68, 0x6f, 0x72, 0x74, 0x20, 0x69, 0x6e, 0x74, 0x00, 0x6c, 0x6f, 0x6e, 0x67, 0x20, 0x75,
		0x6e, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x74, 0x00, 0x47, 0x4e, 0x55, 0x20,


@@ 44,7 46,7 @@ export fn decodestr(input: []u8) (([](str, size), size) | partialread) = {
		0x74, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00,
	];

	let expected: [](str, size) = [
	let expected: [_](str, size) = [
		("short int", 0),
		("long unsigned int", 10),
		("GNU C17 13.2.1 20230826 -mtune=generic -march=x86-64 -gdwarf-2", 28),


@@ 56,6 58,7 @@ export fn decodestr(input: []u8) (([](str, size), size) | partialread) = {
	];

	let (strs, read) = decodestr(bin)!;
	defer freestrs(strs);
	assert(len(strs) == len(expected));
	assert(read == len(bin));