authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-21 10:14:23+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-21 11:51:38+02:00
logbedd7efa2bca82aa1c101ca4144b6bce65c9ab87
treeeec3115aa39dbef693a7f22892859a1b43737c3c
parent28ca203b7132ba0513a3854bd3bcbd0ee9bca067

debug: add smoke test


1 files changed, 13 insertions(+), 5 deletions(-)

lib/std/debug.zig+13-5
...@@ -682,7 +682,6 @@ test "machoSearchSymbols" {...@@ -682,7 +682,6 @@ test "machoSearchSymbols" {
682 try testing.expectEqual(&symbols[2], machoSearchSymbols(&symbols, 5000).?);682 try testing.expectEqual(&symbols[2], machoSearchSymbols(&symbols, 5000).?);
683}683}
684684
685/// TODO resources https://github.com/ziglang/zig/issues/4353
686pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: anytype, address: usize, tty_config: TTY.Config) !void {685pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: anytype, address: usize, tty_config: TTY.Config) !void {
687 const module = debug_info.getModuleForAddress(address) catch |err| switch (err) {686 const module = debug_info.getModuleForAddress(address) catch |err| switch (err) {
688 error.MissingDebugInfo, error.InvalidDebugInfo => {687 error.MissingDebugInfo, error.InvalidDebugInfo => {
...@@ -768,7 +767,6 @@ pub const OpenSelfDebugInfoError = error{...@@ -768,7 +767,6 @@ pub const OpenSelfDebugInfoError = error{
768 UnsupportedOperatingSystem,767 UnsupportedOperatingSystem,
769};768};
770769
771/// TODO resources https://github.com/ziglang/zig/issues/4353
772pub fn openSelfDebugInfo(allocator: mem.Allocator) anyerror!DebugInfo {770pub fn openSelfDebugInfo(allocator: mem.Allocator) anyerror!DebugInfo {
773 nosuspend {771 nosuspend {
774 if (builtin.strip_debug_info)772 if (builtin.strip_debug_info)
...@@ -793,7 +791,6 @@ pub fn openSelfDebugInfo(allocator: mem.Allocator) anyerror!DebugInfo {...@@ -793,7 +791,6 @@ pub fn openSelfDebugInfo(allocator: mem.Allocator) anyerror!DebugInfo {
793791
794/// This takes ownership of coff_file: users of this function should not close792/// This takes ownership of coff_file: users of this function should not close
795/// it themselves, even on error.793/// it themselves, even on error.
796/// TODO resources https://github.com/ziglang/zig/issues/4353
797/// TODO it's weird to take ownership even on error, rework this code.794/// TODO it's weird to take ownership even on error, rework this code.
798fn readCoffDebugInfo(allocator: mem.Allocator, coff_file: File) !ModuleDebugInfo {795fn readCoffDebugInfo(allocator: mem.Allocator, coff_file: File) !ModuleDebugInfo {
799 nosuspend {796 nosuspend {
...@@ -863,7 +860,6 @@ fn chopSlice(ptr: []const u8, offset: u64, size: u64) ![]const u8 {...@@ -863,7 +860,6 @@ fn chopSlice(ptr: []const u8, offset: u64, size: u64) ![]const u8 {
863860
864/// This takes ownership of elf_file: users of this function should not close861/// This takes ownership of elf_file: users of this function should not close
865/// it themselves, even on error.862/// it themselves, even on error.
866/// TODO resources https://github.com/ziglang/zig/issues/4353
867/// TODO it's weird to take ownership even on error, rework this code.863/// TODO it's weird to take ownership even on error, rework this code.
868pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugInfo {864pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugInfo {
869 nosuspend {865 nosuspend {
...@@ -937,7 +933,6 @@ pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugIn...@@ -937,7 +933,6 @@ pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugIn
937 }933 }
938}934}
939935
940/// TODO resources https://github.com/ziglang/zig/issues/4353
941/// This takes ownership of macho_file: users of this function should not close936/// This takes ownership of macho_file: users of this function should not close
942/// it themselves, even on error.937/// it themselves, even on error.
943/// TODO it's weird to take ownership even on error, rework this code.938/// TODO it's weird to take ownership even on error, rework this code.
...@@ -1934,3 +1929,16 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void {...@@ -1934,3 +1929,16 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void {
1934 );1929 );
1935 std.debug.print("{} sp = 0x{x}\n", .{ prefix, sp });1930 std.debug.print("{} sp = 0x{x}\n", .{ prefix, sp });
1936}1931}
1932
1933test "#4353: std.debug should manage resources correctly" {
1934 if (builtin.os.tag == .wasi) return error.SkipZigTest;
1935
1936 const writer = std.io.null_writer;
1937 var di = try openSelfDebugInfo(testing.allocator);
1938 defer di.deinit();
1939 try printSourceAtAddress(&di, writer, showMyTrace(), detectTTYConfig());
1940}
1941
1942noinline fn showMyTrace() usize {
1943 return @returnAddress();
1944}