Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce a fuzz testing web interface #20958

Merged
merged 34 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift click to select a range
97643c1
fuzzer: track code coverage from all runs
andrewrk Jul 30, 2024
ffc050e
fuzzer: log errors and move deduplicated runs to shared mem
andrewrk Jul 30, 2024
e0ffac4
introduce a web interface for fuzzing
andrewrk Aug 1, 2024
107b272
fuzzer: share zig to html rendering with autodocs
andrewrk Aug 1, 2024
2e12b45
introduce tool for dumping coverage file
andrewrk Aug 2, 2024
de47acd
code coverage dumping tool basic implementation
andrewrk Aug 3, 2024
66954e8
std.debug.FixedBufferReader is fine
andrewrk Aug 3, 2024
1792258
std.debug.Dwarf: precompute .debug_line table
andrewrk Aug 3, 2024
c2ab461
std.Debug.Info: remove std.Progress integration
andrewrk Aug 3, 2024
53aa9d7
std.debug.Info.resolveSourceLocations: O(N) implementation
andrewrk Aug 4, 2024
5f92a03
README: update how std lib docs are found in a release build
andrewrk Aug 4, 2024
517cfb0
fuzzing: progress towards web UI
andrewrk Aug 4, 2024
d36c182
std.posix: add some more void bits
andrewrk Aug 4, 2024
b9fd0ee
add std.http.WebSocket
andrewrk Aug 4, 2024
2292563
std.debug.Coverage: use extern structs
andrewrk Aug 4, 2024
dec7e45
fuzzer web UI: receive coverage information
andrewrk Aug 4, 2024
f56d113
fuzzer web ui: render stats
andrewrk Aug 4, 2024
6e6164f
fuzzer web ui: add coverage stat
andrewrk Aug 4, 2024
e64a009
fuzzer web ui: introduce entry points
andrewrk Aug 5, 2024
db69641
fuzzing web ui: make entry point links clickable
andrewrk Aug 5, 2024
ef4c219
fuzzer web UI: navigate by source location index
andrewrk Aug 5, 2024
3d48602
fuzzer web UI: annotated PCs in source view
andrewrk Aug 5, 2024
38227e9
fuzzer web UI: render PCs with red or green depending on coverage
andrewrk Aug 5, 2024
bfc2ee0
fuzzer web ui: resolve cwd in sources.tar
andrewrk Aug 6, 2024
895fa87
dump-cov: show seen PCs
andrewrk Aug 6, 2024
1484f17
fuzzer web ui: fail scrolling into view gracefully
andrewrk Aug 6, 2024
5f5a7b5
wasm zig source rendering: fix annotation location off-by-one
andrewrk Aug 6, 2024
529df8c
libfuzzer: fix looking at wrong memory for pc counters
andrewrk Aug 6, 2024
8dae629
update branch for latest std.sort changes
andrewrk Aug 6, 2024
40edd11
std.debug: fix compile errors on windows and macos
andrewrk Aug 6, 2024
ff503ed
Compilation: fix not showing sub-errors for autodocs
andrewrk Aug 6, 2024
904fcda
Compilation: fix -femit-docs
andrewrk Aug 6, 2024
2a651ea
build runner: --fuzz not yet supported on Windows
andrewrk Aug 6, 2024
d721d9a
update coff_dwarf standalone test to new API
andrewrk Aug 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
introduce tool for dumping coverage file
with debug info resolved.

begin efforts of providing `std.debug.Info`, a cross-platform
abstraction for loading debug information into an in-memory format that
supports queries such as "what is the source location of this virtual
memory address?"

Unlike `std.debug.SelfInfo`, this API does not assume the debug
information in question happens to match the host CPU architecture, OS,
or other target properties.
  • Loading branch information
andrewrk committed Aug 7, 2024
commit 2e12b45d8b43d69e144887df4b04a2d383ff25d4
8 changes: 4 additions & 4 deletions lib/std/Build/Cache/Path.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 32,16 @@ pub fn resolvePosix(p: Path, arena: Allocator, sub_path: []const u8) Allocator.E
};
}

pub fn joinString(p: Path, allocator: Allocator, sub_path: []const u8) Allocator.Error![]u8 {
pub fn joinString(p: Path, gpa: Allocator, sub_path: []const u8) Allocator.Error![]u8 {
const parts: []const []const u8 =
if (p.sub_path.len == 0) &.{sub_path} else &.{ p.sub_path, sub_path };
return p.root_dir.join(allocator, parts);
return p.root_dir.join(gpa, parts);
}

pub fn joinStringZ(p: Path, allocator: Allocator, sub_path: []const u8) Allocator.Error![:0]u8 {
pub fn joinStringZ(p: Path, gpa: Allocator, sub_path: []const u8) Allocator.Error![:0]u8 {
const parts: []const []const u8 =
if (p.sub_path.len == 0) &.{sub_path} else &.{ p.sub_path, sub_path };
return p.root_dir.joinZ(allocator, parts);
return p.root_dir.joinZ(gpa, parts);
}

pub fn openFile(
Expand Down
33 changes: 20 additions & 13 deletions lib/std/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 17,7 @@ pub const MemoryAccessor = @import("debug/MemoryAccessor.zig");
pub const Dwarf = @import("debug/Dwarf.zig");
pub const Pdb = @import("debug/Pdb.zig");
pub const SelfInfo = @import("debug/SelfInfo.zig");
pub const Info = @import("debug/Info.zig");

/// Unresolved source locations can be represented with a single `usize` that
/// corresponds to a virtual memory address of the program counter. Combined
Expand All @@ -28,6 29,12 @@ pub const SourceLocation = struct {
file_name: []const u8,
};

pub const Symbol = struct {
name: []const u8 = "???",
compile_unit_name: []const u8 = "???",
source_location: ?SourceLocation = null,
};

/// Deprecated because it returns the optimization mode of the standard
/// library, when the caller probably wants to use the optimization mode of
/// their own module.
Expand Down Expand Up @@ -871,13 878,13 @@ pub fn printSourceAtAddress(debug_info: *SelfInfo, out_stream: anytype, address:
error.MissingDebugInfo, error.InvalidDebugInfo => return printUnknownSource(debug_info, out_stream, address, tty_config),
else => return err,
};
defer symbol_info.deinit(debug_info.allocator);
defer if (symbol_info.source_location) |sl| debug_info.allocator.free(sl.file_name);

return printLineInfo(
out_stream,
symbol_info.line_info,
symbol_info.source_location,
address,
symbol_info.symbol_name,
symbol_info.name,
symbol_info.compile_unit_name,
tty_config,
printLineFromFileAnyOs,
Expand All @@ -886,7 893,7 @@ pub fn printSourceAtAddress(debug_info: *SelfInfo, out_stream: anytype, address:

fn printLineInfo(
out_stream: anytype,
line_info: ?SourceLocation,
source_location: ?SourceLocation,
address: usize,
symbol_name: []const u8,
compile_unit_name: []const u8,
Expand All @@ -896,8 903,8 @@ fn printLineInfo(
nosuspend {
try tty_config.setColor(out_stream, .bold);

if (line_info) |*li| {
try out_stream.print("{s}:{d}:{d}", .{ li.file_name, li.line, li.column });
if (source_location) |*sl| {
try out_stream.print("{s}:{d}:{d}", .{ sl.file_name, sl.line, sl.column });
} else {
try out_stream.writeAll("???:?:?");
}
Expand All @@ -910,11 917,11 @@ fn printLineInfo(
try out_stream.writeAll("\n");

// Show the matching source code line if possible
if (line_info) |li| {
if (printLineFromFile(out_stream, li)) {
if (li.column > 0) {
if (source_location) |sl| {
if (printLineFromFile(out_stream, sl)) {
if (sl.column > 0) {
// The caret already takes one char
const space_needed = @as(usize, @intCast(li.column - 1));
const space_needed = @as(usize, @intCast(sl.column - 1));

try out_stream.writeByteNTimes(' ', space_needed);
try tty_config.setColor(out_stream, .green);
Expand All @@ -932,10 939,10 @@ fn printLineInfo(
}
}

fn printLineFromFileAnyOs(out_stream: anytype, line_info: SourceLocation) !void {
fn printLineFromFileAnyOs(out_stream: anytype, source_location: SourceLocation) !void {
// Need this to always block even in async I/O mode, because this could potentially
// be called from e.g. the event loop code crashing.
var f = try fs.cwd().openFile(line_info.file_name, .{});
var f = try fs.cwd().openFile(source_location.file_name, .{});
defer f.close();
// TODO fstat and make sure that the file has the correct size

Expand All @@ -944,7 951,7 @@ fn printLineFromFileAnyOs(out_stream: anytype, line_info: SourceLocation) !void
const line_start = seek: {
var current_line_start: usize = 0;
var next_line: usize = 1;
while (next_line != line_info.line) {
while (next_line != source_location.line) {
const slice = buf[current_line_start..amt_read];
if (mem.indexOfScalar(u8, slice, '\n')) |pos| {
next_line = 1;
Expand Down
Loading