authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-17 16:59:27-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-08-17 16:59:27-04:00
log624e643872130de5b6f6f1f120c8cf60a31f58e8
tree695ef653f88aef50bad66c46031e11d9a18d2751
parentc00d3d47f06abfc8321b132232586ccc4349cf02
parent16d118a8d9ce48143ef406ff7b3a1f9d62021d98
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #6046 from heidezomp/std-log-scoped-part2

std.log: (breaking) remove scope parameter from logging functions

7 files changed, 103 insertions(+), 149 deletions(-)

doc/langref.html.in+1-1
...@@ -325,7 +325,7 @@ pub fn main() !void {...@@ -325,7 +325,7 @@ pub fn main() !void {
325 represents writing data to a file. When the disk is full, a write to the file will fail.325 represents writing data to a file. When the disk is full, a write to the file will fail.
326 However, we typically do not expect writing text to the standard output to fail. To avoid having326 However, we typically do not expect writing text to the standard output to fail. To avoid having
327 to handle the failure case of printing to standard output, you can use alternate functions: the327 to handle the failure case of printing to standard output, you can use alternate functions: the
328 <code>std.log</code> function for proper logging or the <code>std.debug.print</code> function.328 functions in <code>std.log</code> for proper logging or the <code>std.debug.print</code> function.
329 This documentation will use the latter option to print to standard error (stderr) and silently return329 This documentation will use the latter option to print to standard error (stderr) and silently return
330 on failure. The next code sample, <code>hello_again.zig</code> demonstrates the use of330 on failure. The next code sample, <code>hello_again.zig</code> demonstrates the use of
331 <code>std.debug.print</code>.331 <code>std.debug.print</code>.
lib/std/heap/general_purpose_allocator.zig+5-4
...@@ -93,6 +93,7 @@...@@ -93,6 +93,7 @@
93//! in a `std.HashMap` using the backing allocator.93//! in a `std.HashMap` using the backing allocator.
9494
95const std = @import("std");95const std = @import("std");
96const log = std.log.scoped(.std);
96const math = std.math;97const math = std.math;
97const assert = std.debug.assert;98const assert = std.debug.assert;
98const mem = std.mem;99const mem = std.mem;
...@@ -288,7 +289,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -288,7 +289,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
288 if (is_used) {289 if (is_used) {
289 const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index);290 const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index);
290 const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);291 const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);
291 std.log.err(.std, "Memory leak detected: {}", .{stack_trace});292 log.err("Memory leak detected: {}", .{stack_trace});
292 leaks = true;293 leaks = true;
293 }294 }
294 if (bit_index == math.maxInt(u3))295 if (bit_index == math.maxInt(u3))
...@@ -315,7 +316,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -315,7 +316,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
315 }316 }
316 }317 }
317 for (self.large_allocations.items()) |*large_alloc| {318 for (self.large_allocations.items()) |*large_alloc| {
318 std.log.err(.std, "Memory leak detected: {}", .{large_alloc.value.getStackTrace()});319 log.err("Memory leak detected: {}", .{large_alloc.value.getStackTrace()});
319 leaks = true;320 leaks = true;
320 }321 }
321 return leaks;322 return leaks;
...@@ -450,7 +451,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -450,7 +451,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
450 .index = 0,451 .index = 0,
451 };452 };
452 std.debug.captureStackTrace(ret_addr, &free_stack_trace);453 std.debug.captureStackTrace(ret_addr, &free_stack_trace);
453 std.log.err(.std, "Allocation size {} bytes does not match free size {}. Allocation: {} Free: {}", .{454 log.err("Allocation size {} bytes does not match free size {}. Allocation: {} Free: {}", .{
454 entry.value.bytes.len,455 entry.value.bytes.len,
455 old_mem.len,456 old_mem.len,
456 entry.value.getStackTrace(),457 entry.value.getStackTrace(),
...@@ -533,7 +534,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -533,7 +534,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
533 .index = 0,534 .index = 0,
534 };535 };
535 std.debug.captureStackTrace(ret_addr, &second_free_stack_trace);536 std.debug.captureStackTrace(ret_addr, &second_free_stack_trace);
536 std.log.err(.std, "Double free detected. Allocation: {} First free: {} Second free: {}", .{537 log.err("Double free detected. Allocation: {} First free: {} Second free: {}", .{
537 alloc_stack_trace,538 alloc_stack_trace,
538 free_stack_trace,539 free_stack_trace,
539 second_free_stack_trace,540 second_free_stack_trace,
lib/std/log.zig+61-108
...@@ -6,12 +6,16 @@ const root = @import("root");...@@ -6,12 +6,16 @@ const root = @import("root");
6//! of programs and libraries using this interface to be formatted and filtered6//! of programs and libraries using this interface to be formatted and filtered
7//! by the implementer of the root.log function.7//! by the implementer of the root.log function.
8//!8//!
9//! The scope parameter should be used to give context to the logging. For9//! Each log message has an associated scope enum, which can be used to give
10//! example, a library called 'libfoo' might use .libfoo as its scope.10//! context to the logging. The logging functions in std.log implicitly use a
11//! This parameter can either be passed explicitly to the logging functions11//! scope of .default.
12//! provided here, or a scoped logging namespace can be created12//!
13//! using the `log.scoped` function. If logging scopes are not relevant for13//! A logging namespace using a custom scope can be created using the
14//! your use case, the `log.default` scope namespace can be used.14//! std.log.scoped function, passing the scope as an argument; the logging
15//! functions in the resulting struct use the provided scope parameter.
16//! For example, a library called 'libfoo' might use
17//! `const log = std.log.scoped(.libfoo);` to use .libfoo as the scope of its
18//! log messages.
15//!19//!
16//! An example root.log might look something like this:20//! An example root.log might look something like this:
17//!21//!
...@@ -29,9 +33,9 @@ const root = @import("root");...@@ -29,9 +33,9 @@ const root = @import("root");
29//! args: anytype,33//! args: anytype,
30//! ) void {34//! ) void {
31//! // Ignore all non-critical logging from sources other than35//! // Ignore all non-critical logging from sources other than
32//! // .my_project and .nice_library36//! // .my_project, .nice_library and .default
33//! const scope_prefix = "(" ++ switch (scope) {37//! const scope_prefix = "(" ++ switch (scope) {
34//! .my_project, .nice_library => @tagName(scope),38//! .my_project, .nice_library, .default => @tagName(scope),
35//! else => if (@enumToInt(level) <= @enumToInt(std.log.Level.crit))39//! else => if (@enumToInt(level) <= @enumToInt(std.log.Level.crit))
36//! @tagName(scope)40//! @tagName(scope)
37//! else41//! else
...@@ -48,26 +52,24 @@ const root = @import("root");...@@ -48,26 +52,24 @@ const root = @import("root");
48//! }52//! }
49//!53//!
50//! pub fn main() void {54//! pub fn main() void {
51//! // Using explicit scopes:55//! // Using the default scope:
52//! // Won't be printed as log_level is .warn56//! std.log.info("Just a simple informational log message", .{}); // Won't be printed as log_level is .warn
53//! std.log.info(.my_project, "Starting up.", .{});57//! std.log.warn("Flux capacitor is starting to overheat", .{});
54//! std.log.err(.nice_library, "Something went very wrong, sorry.", .{});
55//! // Won't be printed as it gets filtered out by our log function
56//! std.log.err(.lib_that_logs_too_much, "Added 1 + 1", .{});
57//!58//!
58//! // Using a scoped logging namespace:59//! // Using scoped logging:
59//! const scoped_log = std.log.scoped(.my_project);60//! const my_project_log = std.log.scoped(.my_project);
60//! scoped_log.alert("The scope for this message is implicitly .my_project", .{});61//! const nice_library_log = std.log.scoped(.nice_library);
62//! const verbose_lib_log = std.log.scoped(.verbose_lib);
61//!63//!
62//! // Using the default namespace:64//! my_project_log.info("Starting up", .{}); // Won't be printed as log_level is .warn
63//! // Won't be printed as log_level is .warn65//! nice_library_log.err("Something went very wrong, sorry", .{});
64//! std.log.default.info("I don't care about my namespace", .{});66//! verbose_lib_log.err("Added 1 + 1: {}", .{1 + 1}); // Won't be printed as it gets filtered out by our log function
65//! }67//! }
66//! ```68//! ```
67//! Which produces the following output:69//! Which produces the following output:
68//! ```70//! ```
69//! [err] (nice_library): Something went very wrong, sorry.71//! [warn] (default): Flux capacitor is starting to overheat
70//! [alert] (my_project): The scope for this message is implicitly .my_project72//! [err] (nice_library): Something went very wrong, sorry
71//! ```73//! ```
7274
73pub const Level = enum {75pub const Level = enum {
...@@ -129,92 +131,6 @@ fn log(...@@ -129,92 +131,6 @@ fn log(
129 }131 }
130}132}
131133
132/// Log an emergency message. This log level is intended to be used
133/// for conditions that cannot be handled and is usually followed by a panic.
134pub fn emerg(
135 comptime scope: @Type(.EnumLiteral),
136 comptime format: []const u8,
137 args: anytype,
138) void {
139 @setCold(true);
140 log(.emerg, scope, format, args);
141}
142
143/// Log an alert message. This log level is intended to be used for
144/// conditions that should be corrected immediately (e.g. database corruption).
145pub fn alert(
146 comptime scope: @Type(.EnumLiteral),
147 comptime format: []const u8,
148 args: anytype,
149) void {
150 @setCold(true);
151 log(.alert, scope, format, args);
152}
153
154/// Log a critical message. This log level is intended to be used
155/// when a bug has been detected or something has gone wrong and it will have
156/// an effect on the operation of the program.
157pub fn crit(
158 comptime scope: @Type(.EnumLiteral),
159 comptime format: []const u8,
160 args: anytype,
161) void {
162 @setCold(true);
163 log(.crit, scope, format, args);
164}
165
166/// Log an error message. This log level is intended to be used when
167/// a bug has been detected or something has gone wrong but it is recoverable.
168pub fn err(
169 comptime scope: @Type(.EnumLiteral),
170 comptime format: []const u8,
171 args: anytype,
172) void {
173 @setCold(true);
174 log(.err, scope, format, args);
175}
176
177/// Log a warning message. This log level is intended to be used if
178/// it is uncertain whether something has gone wrong or not, but the
179/// circumstances would be worth investigating.
180pub fn warn(
181 comptime scope: @Type(.EnumLiteral),
182 comptime format: []const u8,
183 args: anytype,
184) void {
185 log(.warn, scope, format, args);
186}
187
188/// Log a notice message. This log level is intended to be used for
189/// non-error but significant conditions.
190pub fn notice(
191 comptime scope: @Type(.EnumLiteral),
192 comptime format: []const u8,
193 args: anytype,
194) void {
195 log(.notice, scope, format, args);
196}
197
198/// Log an info message. This log level is intended to be used for
199/// general messages about the state of the program.
200pub fn info(
201 comptime scope: @Type(.EnumLiteral),
202 comptime format: []const u8,
203 args: anytype,
204) void {
205 log(.info, scope, format, args);
206}
207
208/// Log a debug message. This log level is intended to be used for
209/// messages which are only useful for debugging.
210pub fn debug(
211 comptime scope: @Type(.EnumLiteral),
212 comptime format: []const u8,
213 args: anytype,
214) void {
215 log(.debug, scope, format, args);
216}
217
218/// Returns a scoped logging namespace that logs all messages using the scope134/// Returns a scoped logging namespace that logs all messages using the scope
219/// provided here.135/// provided here.
220pub fn scoped(comptime scope: @Type(.EnumLiteral)) type {136pub fn scoped(comptime scope: @Type(.EnumLiteral)) type {
...@@ -301,3 +217,40 @@ pub fn scoped(comptime scope: @Type(.EnumLiteral)) type {...@@ -301,3 +217,40 @@ pub fn scoped(comptime scope: @Type(.EnumLiteral)) type {
301217
302/// The default scoped logging namespace.218/// The default scoped logging namespace.
303pub const default = scoped(.default);219pub const default = scoped(.default);
220
221/// Log an emergency message using the default scope. This log level is
222/// intended to be used for conditions that cannot be handled and is usually
223/// followed by a panic.
224pub const emerg = default.emerg;
225
226/// Log an alert message using the default scope. This log level is intended to
227/// be used for conditions that should be corrected immediately (e.g. database
228/// corruption).
229pub const alert = default.alert;
230
231/// Log a critical message using the default scope. This log level is intended
232/// to be used when a bug has been detected or something has gone wrong and it
233/// will have an effect on the operation of the program.
234pub const crit = default.crit;
235
236/// Log an error message using the default scope. This log level is intended to
237/// be used when a bug has been detected or something has gone wrong but it is
238/// recoverable.
239pub const err = default.err;
240
241/// Log a warning message using the default scope. This log level is intended
242/// to be used if it is uncertain whether something has gone wrong or not, but
243/// the circumstances would be worth investigating.
244pub const warn = default.warn;
245
246/// Log a notice message using the default scope. This log level is intended to
247/// be used for non-error but significant conditions.
248pub const notice = default.notice;
249
250/// Log an info message using the default scope. This log level is intended to
251/// be used for general messages about the state of the program.
252pub const info = default.info;
253
254/// Log a debug message using the default scope. This log level is intended to
255/// be used for messages which are only useful for debugging.
256pub const debug = default.debug;
src-self-hosted/Module.zig+9-9
...@@ -6,7 +6,7 @@ const Value = @import("value.zig").Value;...@@ -6,7 +6,7 @@ const Value = @import("value.zig").Value;
6const Type = @import("type.zig").Type;6const Type = @import("type.zig").Type;
7const TypedValue = @import("TypedValue.zig");7const TypedValue = @import("TypedValue.zig");
8const assert = std.debug.assert;8const assert = std.debug.assert;
9const log = std.log;9const log = std.log.scoped(.module);
10const BigIntConst = std.math.big.int.Const;10const BigIntConst = std.math.big.int.Const;
11const BigIntMutable = std.math.big.int.Mutable;11const BigIntMutable = std.math.big.int.Mutable;
12const Target = std.Target;12const Target = std.Target;
...@@ -1079,7 +1079,7 @@ pub fn performAllTheWork(self: *Module) error{OutOfMemory}!void {...@@ -1079,7 +1079,7 @@ pub fn performAllTheWork(self: *Module) error{OutOfMemory}!void {
1079 // lifetime annotations in the ZIR.1079 // lifetime annotations in the ZIR.
1080 var decl_arena = decl.typed_value.most_recent.arena.?.promote(self.gpa);1080 var decl_arena = decl.typed_value.most_recent.arena.?.promote(self.gpa);
1081 defer decl.typed_value.most_recent.arena.?.* = decl_arena.state;1081 defer decl.typed_value.most_recent.arena.?.* = decl_arena.state;
1082 std.log.debug(.module, "analyze liveness of {}\n", .{decl.name});1082 log.debug("analyze liveness of {}\n", .{decl.name});
1083 try liveness.analyze(self.gpa, &decl_arena.allocator, payload.func.analysis.success);1083 try liveness.analyze(self.gpa, &decl_arena.allocator, payload.func.analysis.success);
1084 }1084 }
10851085
...@@ -1141,7 +1141,7 @@ pub fn ensureDeclAnalyzed(self: *Module, decl: *Decl) InnerError!void {...@@ -1141,7 +1141,7 @@ pub fn ensureDeclAnalyzed(self: *Module, decl: *Decl) InnerError!void {
1141 .complete => return,1141 .complete => return,
11421142
1143 .outdated => blk: {1143 .outdated => blk: {
1144 log.debug(.module, "re-analyzing {}\n", .{decl.name});1144 log.debug("re-analyzing {}\n", .{decl.name});
11451145
1146 // The exports this Decl performs will be re-discovered, so we remove them here1146 // The exports this Decl performs will be re-discovered, so we remove them here
1147 // prior to re-analysis.1147 // prior to re-analysis.
...@@ -1592,7 +1592,7 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void {...@@ -1592,7 +1592,7 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void {
1592 // Handle explicitly deleted decls from the source code. Not to be confused1592 // Handle explicitly deleted decls from the source code. Not to be confused
1593 // with when we delete decls because they are no longer referenced.1593 // with when we delete decls because they are no longer referenced.
1594 for (deleted_decls.items()) |entry| {1594 for (deleted_decls.items()) |entry| {
1595 log.debug(.module, "noticed '{}' deleted from source\n", .{entry.key.name});1595 log.debug("noticed '{}' deleted from source\n", .{entry.key.name});
1596 try self.deleteDecl(entry.key);1596 try self.deleteDecl(entry.key);
1597 }1597 }
1598}1598}
...@@ -1645,7 +1645,7 @@ fn analyzeRootZIRModule(self: *Module, root_scope: *Scope.ZIRModule) !void {...@@ -1645,7 +1645,7 @@ fn analyzeRootZIRModule(self: *Module, root_scope: *Scope.ZIRModule) !void {
1645 // Handle explicitly deleted decls from the source code. Not to be confused1645 // Handle explicitly deleted decls from the source code. Not to be confused
1646 // with when we delete decls because they are no longer referenced.1646 // with when we delete decls because they are no longer referenced.
1647 for (deleted_decls.items()) |entry| {1647 for (deleted_decls.items()) |entry| {
1648 log.debug(.module, "noticed '{}' deleted from source\n", .{entry.key.name});1648 log.debug("noticed '{}' deleted from source\n", .{entry.key.name});
1649 try self.deleteDecl(entry.key);1649 try self.deleteDecl(entry.key);
1650 }1650 }
1651}1651}
...@@ -1657,7 +1657,7 @@ fn deleteDecl(self: *Module, decl: *Decl) !void {...@@ -1657,7 +1657,7 @@ fn deleteDecl(self: *Module, decl: *Decl) !void {
1657 // not be present in the set, and this does nothing.1657 // not be present in the set, and this does nothing.
1658 decl.scope.removeDecl(decl);1658 decl.scope.removeDecl(decl);
16591659
1660 log.debug(.module, "deleting decl '{}'\n", .{decl.name});1660 log.debug("deleting decl '{}'\n", .{decl.name});
1661 const name_hash = decl.fullyQualifiedNameHash();1661 const name_hash = decl.fullyQualifiedNameHash();
1662 self.decl_table.removeAssertDiscard(name_hash);1662 self.decl_table.removeAssertDiscard(name_hash);
1663 // Remove itself from its dependencies, because we are about to destroy the decl pointer.1663 // Remove itself from its dependencies, because we are about to destroy the decl pointer.
...@@ -1744,17 +1744,17 @@ fn analyzeFnBody(self: *Module, decl: *Decl, func: *Fn) !void {...@@ -1744,17 +1744,17 @@ fn analyzeFnBody(self: *Module, decl: *Decl, func: *Fn) !void {
1744 const fn_zir = func.analysis.queued;1744 const fn_zir = func.analysis.queued;
1745 defer fn_zir.arena.promote(self.gpa).deinit();1745 defer fn_zir.arena.promote(self.gpa).deinit();
1746 func.analysis = .{ .in_progress = {} };1746 func.analysis = .{ .in_progress = {} };
1747 log.debug(.module, "set {} to in_progress\n", .{decl.name});1747 log.debug("set {} to in_progress\n", .{decl.name});
17481748
1749 try zir_sema.analyzeBody(self, &inner_block.base, fn_zir.body);1749 try zir_sema.analyzeBody(self, &inner_block.base, fn_zir.body);
17501750
1751 const instructions = try arena.allocator.dupe(*Inst, inner_block.instructions.items);1751 const instructions = try arena.allocator.dupe(*Inst, inner_block.instructions.items);
1752 func.analysis = .{ .success = .{ .instructions = instructions } };1752 func.analysis = .{ .success = .{ .instructions = instructions } };
1753 log.debug(.module, "set {} to success\n", .{decl.name});1753 log.debug("set {} to success\n", .{decl.name});
1754}1754}
17551755
1756fn markOutdatedDecl(self: *Module, decl: *Decl) !void {1756fn markOutdatedDecl(self: *Module, decl: *Decl) !void {
1757 log.debug(.module, "mark {} outdated\n", .{decl.name});1757 log.debug("mark {} outdated\n", .{decl.name});
1758 try self.work_queue.writeItem(.{ .analyze_decl = decl });1758 try self.work_queue.writeItem(.{ .analyze_decl = decl });
1759 if (self.failed_decls.remove(decl)) |entry| {1759 if (self.failed_decls.remove(decl)) |entry| {
1760 entry.value.destroy(self.gpa);1760 entry.value.destroy(self.gpa);
src-self-hosted/link.zig+25-25
...@@ -8,7 +8,7 @@ const fs = std.fs;...@@ -8,7 +8,7 @@ const fs = std.fs;
8const elf = std.elf;8const elf = std.elf;
9const codegen = @import("codegen.zig");9const codegen = @import("codegen.zig");
10const c_codegen = @import("codegen/c.zig");10const c_codegen = @import("codegen/c.zig");
11const log = std.log;11const log = std.log.scoped(.link);
12const DW = std.dwarf;12const DW = std.dwarf;
13const trace = @import("tracy.zig").trace;13const trace = @import("tracy.zig").trace;
14const leb128 = std.debug.leb;14const leb128 = std.debug.leb;
...@@ -746,7 +746,7 @@ pub const File = struct {...@@ -746,7 +746,7 @@ pub const File = struct {
746 const file_size = self.base.options.program_code_size_hint;746 const file_size = self.base.options.program_code_size_hint;
747 const p_align = 0x1000;747 const p_align = 0x1000;
748 const off = self.findFreeSpace(file_size, p_align);748 const off = self.findFreeSpace(file_size, p_align);
749 log.debug(.link, "found PT_LOAD free space 0x{x} to 0x{x}\n", .{ off, off + file_size });749 log.debug("found PT_LOAD free space 0x{x} to 0x{x}\n", .{ off, off + file_size });
750 try self.program_headers.append(self.base.allocator, .{750 try self.program_headers.append(self.base.allocator, .{
751 .p_type = elf.PT_LOAD,751 .p_type = elf.PT_LOAD,
752 .p_offset = off,752 .p_offset = off,
...@@ -767,7 +767,7 @@ pub const File = struct {...@@ -767,7 +767,7 @@ pub const File = struct {
767 // page align.767 // page align.
768 const p_align = if (self.base.options.target.os.tag == .linux) 0x1000 else @as(u16, ptr_size);768 const p_align = if (self.base.options.target.os.tag == .linux) 0x1000 else @as(u16, ptr_size);
769 const off = self.findFreeSpace(file_size, p_align);769 const off = self.findFreeSpace(file_size, p_align);
770 log.debug(.link, "found PT_LOAD free space 0x{x} to 0x{x}\n", .{ off, off + file_size });770 log.debug("found PT_LOAD free space 0x{x} to 0x{x}\n", .{ off, off + file_size });
771 // TODO instead of hard coding the vaddr, make a function to find a vaddr to put things at.771 // TODO instead of hard coding the vaddr, make a function to find a vaddr to put things at.
772 // we'll need to re-use that function anyway, in case the GOT grows and overlaps something772 // we'll need to re-use that function anyway, in case the GOT grows and overlaps something
773 // else in virtual memory.773 // else in virtual memory.
...@@ -789,7 +789,7 @@ pub const File = struct {...@@ -789,7 +789,7 @@ pub const File = struct {
789 assert(self.shstrtab.items.len == 0);789 assert(self.shstrtab.items.len == 0);
790 try self.shstrtab.append(self.base.allocator, 0); // need a 0 at position 0790 try self.shstrtab.append(self.base.allocator, 0); // need a 0 at position 0
791 const off = self.findFreeSpace(self.shstrtab.items.len, 1);791 const off = self.findFreeSpace(self.shstrtab.items.len, 1);
792 log.debug(.link, "found shstrtab free space 0x{x} to 0x{x}\n", .{ off, off + self.shstrtab.items.len });792 log.debug("found shstrtab free space 0x{x} to 0x{x}\n", .{ off, off + self.shstrtab.items.len });
793 try self.sections.append(self.base.allocator, .{793 try self.sections.append(self.base.allocator, .{
794 .sh_name = try self.makeString(".shstrtab"),794 .sh_name = try self.makeString(".shstrtab"),
795 .sh_type = elf.SHT_STRTAB,795 .sh_type = elf.SHT_STRTAB,
...@@ -847,7 +847,7 @@ pub const File = struct {...@@ -847,7 +847,7 @@ pub const File = struct {
847 const each_size: u64 = if (small_ptr) @sizeOf(elf.Elf32_Sym) else @sizeOf(elf.Elf64_Sym);847 const each_size: u64 = if (small_ptr) @sizeOf(elf.Elf32_Sym) else @sizeOf(elf.Elf64_Sym);
848 const file_size = self.base.options.symbol_count_hint * each_size;848 const file_size = self.base.options.symbol_count_hint * each_size;
849 const off = self.findFreeSpace(file_size, min_align);849 const off = self.findFreeSpace(file_size, min_align);
850 log.debug(.link, "found symtab free space 0x{x} to 0x{x}\n", .{ off, off + file_size });850 log.debug("found symtab free space 0x{x} to 0x{x}\n", .{ off, off + file_size });
851851
852 try self.sections.append(self.base.allocator, .{852 try self.sections.append(self.base.allocator, .{
853 .sh_name = try self.makeString(".symtab"),853 .sh_name = try self.makeString(".symtab"),
...@@ -889,7 +889,7 @@ pub const File = struct {...@@ -889,7 +889,7 @@ pub const File = struct {
889 const file_size_hint = 200;889 const file_size_hint = 200;
890 const p_align = 1;890 const p_align = 1;
891 const off = self.findFreeSpace(file_size_hint, p_align);891 const off = self.findFreeSpace(file_size_hint, p_align);
892 log.debug(.link, "found .debug_info free space 0x{x} to 0x{x}\n", .{892 log.debug("found .debug_info free space 0x{x} to 0x{x}\n", .{
893 off,893 off,
894 off + file_size_hint,894 off + file_size_hint,
895 });895 });
...@@ -914,7 +914,7 @@ pub const File = struct {...@@ -914,7 +914,7 @@ pub const File = struct {
914 const file_size_hint = 128;914 const file_size_hint = 128;
915 const p_align = 1;915 const p_align = 1;
916 const off = self.findFreeSpace(file_size_hint, p_align);916 const off = self.findFreeSpace(file_size_hint, p_align);
917 log.debug(.link, "found .debug_abbrev free space 0x{x} to 0x{x}\n", .{917 log.debug("found .debug_abbrev free space 0x{x} to 0x{x}\n", .{
918 off,918 off,
919 off + file_size_hint,919 off + file_size_hint,
920 });920 });
...@@ -939,7 +939,7 @@ pub const File = struct {...@@ -939,7 +939,7 @@ pub const File = struct {
939 const file_size_hint = 160;939 const file_size_hint = 160;
940 const p_align = 16;940 const p_align = 16;
941 const off = self.findFreeSpace(file_size_hint, p_align);941 const off = self.findFreeSpace(file_size_hint, p_align);
942 log.debug(.link, "found .debug_aranges free space 0x{x} to 0x{x}\n", .{942 log.debug("found .debug_aranges free space 0x{x} to 0x{x}\n", .{
943 off,943 off,
944 off + file_size_hint,944 off + file_size_hint,
945 });945 });
...@@ -964,7 +964,7 @@ pub const File = struct {...@@ -964,7 +964,7 @@ pub const File = struct {
964 const file_size_hint = 250;964 const file_size_hint = 250;
965 const p_align = 1;965 const p_align = 1;
966 const off = self.findFreeSpace(file_size_hint, p_align);966 const off = self.findFreeSpace(file_size_hint, p_align);
967 log.debug(.link, "found .debug_line free space 0x{x} to 0x{x}\n", .{967 log.debug("found .debug_line free space 0x{x} to 0x{x}\n", .{
968 off,968 off,
969 off + file_size_hint,969 off + file_size_hint,
970 });970 });
...@@ -1090,7 +1090,7 @@ pub const File = struct {...@@ -1090,7 +1090,7 @@ pub const File = struct {
1090 debug_abbrev_sect.sh_offset = self.findFreeSpace(needed_size, 1);1090 debug_abbrev_sect.sh_offset = self.findFreeSpace(needed_size, 1);
1091 }1091 }
1092 debug_abbrev_sect.sh_size = needed_size;1092 debug_abbrev_sect.sh_size = needed_size;
1093 log.debug(.link, ".debug_abbrev start=0x{x} end=0x{x}\n", .{1093 log.debug(".debug_abbrev start=0x{x} end=0x{x}\n", .{
1094 debug_abbrev_sect.sh_offset,1094 debug_abbrev_sect.sh_offset,
1095 debug_abbrev_sect.sh_offset + needed_size,1095 debug_abbrev_sect.sh_offset + needed_size,
1096 });1096 });
...@@ -1237,7 +1237,7 @@ pub const File = struct {...@@ -1237,7 +1237,7 @@ pub const File = struct {
1237 debug_aranges_sect.sh_offset = self.findFreeSpace(needed_size, 16);1237 debug_aranges_sect.sh_offset = self.findFreeSpace(needed_size, 16);
1238 }1238 }
1239 debug_aranges_sect.sh_size = needed_size;1239 debug_aranges_sect.sh_size = needed_size;
1240 log.debug(.link, ".debug_aranges start=0x{x} end=0x{x}\n", .{1240 log.debug(".debug_aranges start=0x{x} end=0x{x}\n", .{
1241 debug_aranges_sect.sh_offset,1241 debug_aranges_sect.sh_offset,
1242 debug_aranges_sect.sh_offset + needed_size,1242 debug_aranges_sect.sh_offset + needed_size,
1243 });1243 });
...@@ -1405,7 +1405,7 @@ pub const File = struct {...@@ -1405,7 +1405,7 @@ pub const File = struct {
1405 shstrtab_sect.sh_offset = self.findFreeSpace(needed_size, 1);1405 shstrtab_sect.sh_offset = self.findFreeSpace(needed_size, 1);
1406 }1406 }
1407 shstrtab_sect.sh_size = needed_size;1407 shstrtab_sect.sh_size = needed_size;
1408 log.debug(.link, "writing shstrtab start=0x{x} end=0x{x}\n", .{ shstrtab_sect.sh_offset, shstrtab_sect.sh_offset + needed_size });1408 log.debug("writing shstrtab start=0x{x} end=0x{x}\n", .{ shstrtab_sect.sh_offset, shstrtab_sect.sh_offset + needed_size });
14091409
1410 try self.base.file.?.pwriteAll(self.shstrtab.items, shstrtab_sect.sh_offset);1410 try self.base.file.?.pwriteAll(self.shstrtab.items, shstrtab_sect.sh_offset);
1411 if (!self.shdr_table_dirty) {1411 if (!self.shdr_table_dirty) {
...@@ -1426,7 +1426,7 @@ pub const File = struct {...@@ -1426,7 +1426,7 @@ pub const File = struct {
1426 debug_strtab_sect.sh_offset = self.findFreeSpace(needed_size, 1);1426 debug_strtab_sect.sh_offset = self.findFreeSpace(needed_size, 1);
1427 }1427 }
1428 debug_strtab_sect.sh_size = needed_size;1428 debug_strtab_sect.sh_size = needed_size;
1429 log.debug(.link, "debug_strtab start=0x{x} end=0x{x}\n", .{ debug_strtab_sect.sh_offset, debug_strtab_sect.sh_offset + needed_size });1429 log.debug("debug_strtab start=0x{x} end=0x{x}\n", .{ debug_strtab_sect.sh_offset, debug_strtab_sect.sh_offset + needed_size });
14301430
1431 try self.base.file.?.pwriteAll(self.debug_strtab.items, debug_strtab_sect.sh_offset);1431 try self.base.file.?.pwriteAll(self.debug_strtab.items, debug_strtab_sect.sh_offset);
1432 if (!self.shdr_table_dirty) {1432 if (!self.shdr_table_dirty) {
...@@ -1460,7 +1460,7 @@ pub const File = struct {...@@ -1460,7 +1460,7 @@ pub const File = struct {
14601460
1461 for (buf) |*shdr, i| {1461 for (buf) |*shdr, i| {
1462 shdr.* = sectHeaderTo32(self.sections.items[i]);1462 shdr.* = sectHeaderTo32(self.sections.items[i]);
1463 std.log.debug(.link, "writing section {}\n", .{shdr.*});1463 log.debug("writing section {}\n", .{shdr.*});
1464 if (foreign_endian) {1464 if (foreign_endian) {
1465 bswapAllFields(elf.Elf32_Shdr, shdr);1465 bswapAllFields(elf.Elf32_Shdr, shdr);
1466 }1466 }
...@@ -1473,7 +1473,7 @@ pub const File = struct {...@@ -1473,7 +1473,7 @@ pub const File = struct {
14731473
1474 for (buf) |*shdr, i| {1474 for (buf) |*shdr, i| {
1475 shdr.* = self.sections.items[i];1475 shdr.* = self.sections.items[i];
1476 log.debug(.link, "writing section {}\n", .{shdr.*});1476 log.debug("writing section {}\n", .{shdr.*});
1477 if (foreign_endian) {1477 if (foreign_endian) {
1478 bswapAllFields(elf.Elf64_Shdr, shdr);1478 bswapAllFields(elf.Elf64_Shdr, shdr);
1479 }1479 }
...@@ -1484,10 +1484,10 @@ pub const File = struct {...@@ -1484,10 +1484,10 @@ pub const File = struct {
1484 self.shdr_table_dirty = false;1484 self.shdr_table_dirty = false;
1485 }1485 }
1486 if (self.entry_addr == null and self.base.options.output_mode == .Exe) {1486 if (self.entry_addr == null and self.base.options.output_mode == .Exe) {
1487 log.debug(.link, "flushing. no_entry_point_found = true\n", .{});1487 log.debug("flushing. no_entry_point_found = true\n", .{});
1488 self.error_flags.no_entry_point_found = true;1488 self.error_flags.no_entry_point_found = true;
1489 } else {1489 } else {
1490 log.debug(.link, "flushing. no_entry_point_found = false\n", .{});1490 log.debug("flushing. no_entry_point_found = false\n", .{});
1491 self.error_flags.no_entry_point_found = false;1491 self.error_flags.no_entry_point_found = false;
1492 try self.writeElfHeader();1492 try self.writeElfHeader();
1493 }1493 }
...@@ -1816,10 +1816,10 @@ pub const File = struct {...@@ -1816,10 +1816,10 @@ pub const File = struct {
1816 try self.offset_table.ensureCapacity(self.base.allocator, self.offset_table.items.len + 1);1816 try self.offset_table.ensureCapacity(self.base.allocator, self.offset_table.items.len + 1);
18171817
1818 if (self.local_symbol_free_list.popOrNull()) |i| {1818 if (self.local_symbol_free_list.popOrNull()) |i| {
1819 log.debug(.link, "reusing symbol index {} for {}\n", .{ i, decl.name });1819 log.debug("reusing symbol index {} for {}\n", .{ i, decl.name });
1820 decl.link.elf.local_sym_index = i;1820 decl.link.elf.local_sym_index = i;
1821 } else {1821 } else {
1822 log.debug(.link, "allocating symbol index {} for {}\n", .{ self.local_symbols.items.len, decl.name });1822 log.debug("allocating symbol index {} for {}\n", .{ self.local_symbols.items.len, decl.name });
1823 decl.link.elf.local_sym_index = @intCast(u32, self.local_symbols.items.len);1823 decl.link.elf.local_sym_index = @intCast(u32, self.local_symbols.items.len);
1824 _ = self.local_symbols.addOneAssumeCapacity();1824 _ = self.local_symbols.addOneAssumeCapacity();
1825 }1825 }
...@@ -2016,11 +2016,11 @@ pub const File = struct {...@@ -2016,11 +2016,11 @@ pub const File = struct {
2016 !mem.isAlignedGeneric(u64, local_sym.st_value, required_alignment);2016 !mem.isAlignedGeneric(u64, local_sym.st_value, required_alignment);
2017 if (need_realloc) {2017 if (need_realloc) {
2018 const vaddr = try self.growTextBlock(&decl.link.elf, code.len, required_alignment);2018 const vaddr = try self.growTextBlock(&decl.link.elf, code.len, required_alignment);
2019 log.debug(.link, "growing {} from 0x{x} to 0x{x}\n", .{ decl.name, local_sym.st_value, vaddr });2019 log.debug("growing {} from 0x{x} to 0x{x}\n", .{ decl.name, local_sym.st_value, vaddr });
2020 if (vaddr != local_sym.st_value) {2020 if (vaddr != local_sym.st_value) {
2021 local_sym.st_value = vaddr;2021 local_sym.st_value = vaddr;
20222022
2023 log.debug(.link, " (writing new offset table entry)\n", .{});2023 log.debug(" (writing new offset table entry)\n", .{});
2024 self.offset_table.items[decl.link.elf.offset_table_index] = vaddr;2024 self.offset_table.items[decl.link.elf.offset_table_index] = vaddr;
2025 try self.writeOffsetTableEntry(decl.link.elf.offset_table_index);2025 try self.writeOffsetTableEntry(decl.link.elf.offset_table_index);
2026 }2026 }
...@@ -2038,7 +2038,7 @@ pub const File = struct {...@@ -2038,7 +2038,7 @@ pub const File = struct {
2038 const decl_name = mem.spanZ(decl.name);2038 const decl_name = mem.spanZ(decl.name);
2039 const name_str_index = try self.makeString(decl_name);2039 const name_str_index = try self.makeString(decl_name);
2040 const vaddr = try self.allocateTextBlock(&decl.link.elf, code.len, required_alignment);2040 const vaddr = try self.allocateTextBlock(&decl.link.elf, code.len, required_alignment);
2041 log.debug(.link, "allocated text block for {} at 0x{x}\n", .{ decl_name, vaddr });2041 log.debug("allocated text block for {} at 0x{x}\n", .{ decl_name, vaddr });
2042 errdefer self.freeTextBlock(&decl.link.elf);2042 errdefer self.freeTextBlock(&decl.link.elf);
20432043
2044 local_sym.* = .{2044 local_sym.* = .{
...@@ -2148,7 +2148,7 @@ pub const File = struct {...@@ -2148,7 +2148,7 @@ pub const File = struct {
2148 if (needed_size > self.allocatedSize(debug_line_sect.sh_offset)) {2148 if (needed_size > self.allocatedSize(debug_line_sect.sh_offset)) {
2149 const new_offset = self.findFreeSpace(needed_size, 1);2149 const new_offset = self.findFreeSpace(needed_size, 1);
2150 const existing_size = last_src_fn.off;2150 const existing_size = last_src_fn.off;
2151 log.debug(.link, "moving .debug_line section: {} bytes from 0x{x} to 0x{x}\n", .{2151 log.debug("moving .debug_line section: {} bytes from 0x{x} to 0x{x}\n", .{
2152 existing_size,2152 existing_size,
2153 debug_line_sect.sh_offset,2153 debug_line_sect.sh_offset,
2154 new_offset,2154 new_offset,
...@@ -2227,7 +2227,7 @@ pub const File = struct {...@@ -2227,7 +2227,7 @@ pub const File = struct {
2227 try dbg_info_buffer.writer().print("{}\x00", .{ty});2227 try dbg_info_buffer.writer().print("{}\x00", .{ty});
2228 },2228 },
2229 else => {2229 else => {
2230 log.err(.compiler, "TODO implement .debug_info for type '{}'", .{ty});2230 std.log.scoped(.compiler).err("TODO implement .debug_info for type '{}'", .{ty});
2231 try dbg_info_buffer.append(abbrev_pad1);2231 try dbg_info_buffer.append(abbrev_pad1);
2232 },2232 },
2233 }2233 }
...@@ -2299,7 +2299,7 @@ pub const File = struct {...@@ -2299,7 +2299,7 @@ pub const File = struct {
2299 if (needed_size > self.allocatedSize(debug_info_sect.sh_offset)) {2299 if (needed_size > self.allocatedSize(debug_info_sect.sh_offset)) {
2300 const new_offset = self.findFreeSpace(needed_size, 1);2300 const new_offset = self.findFreeSpace(needed_size, 1);
2301 const existing_size = last_decl.dbg_info_off;2301 const existing_size = last_decl.dbg_info_off;
2302 log.debug(.link, "moving .debug_info section: {} bytes from 0x{x} to 0x{x}\n", .{2302 log.debug("moving .debug_info section: {} bytes from 0x{x} to 0x{x}\n", .{
2303 existing_size,2303 existing_size,
2304 debug_info_sect.sh_offset,2304 debug_info_sect.sh_offset,
2305 new_offset,2305 new_offset,
src-self-hosted/liveness.zig+1-1
...@@ -151,5 +151,5 @@ fn analyzeInst(...@@ -151,5 +151,5 @@ fn analyzeInst(
151 @panic("Handle liveness analysis for instructions with many parameters");151 @panic("Handle liveness analysis for instructions with many parameters");
152 }152 }
153153
154 std.log.debug(.liveness, "analyze {}: 0b{b}\n", .{ base.tag, base.deaths });154 std.log.scoped(.liveness).debug("analyze {}: 0b{b}\n", .{ base.tag, base.deaths });
155}155}
src-self-hosted/main.zig+1-1
...@@ -557,7 +557,7 @@ fn updateModule(gpa: *Allocator, module: *Module, zir_out_path: ?[]const u8) !vo...@@ -557,7 +557,7 @@ fn updateModule(gpa: *Allocator, module: *Module, zir_out_path: ?[]const u8) !vo
557 });557 });
558 }558 }
559 } else {559 } else {
560 std.log.info(.compiler, "Update completed in {} ms\n", .{update_nanos / std.time.ns_per_ms});560 std.log.scoped(.compiler).info("Update completed in {} ms\n", .{update_nanos / std.time.ns_per_ms});
561 }561 }
562562
563 if (zir_out_path) |zop| {563 if (zir_out_path) |zop| {