@@ -4893,6 +4893,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
48934893 var fetch_mode : Package.Fetch.JobQueue.Mode = .needed ;
48944894 var system_pkg_dir_path : ? []const u8 = null ;
48954895 var debug_target : ? []const u8 = null ;
4896+ var debug_libc_paths_file : ? []const u8 = null ;
48964897
48974898 const argv_index_exe = child_argv .items .len ;
48984899 _ = try child_argv .addOne ();
@@ -5016,6 +5017,14 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
50165017 } else {
50175018 warn ("Zig was compiled without debug extensions. --debug-target has no effect." , .{});
50185019 }
5020+ } else if (mem .eql (u8 , arg , "--debug-libc" )) {
5021+ if (i + 1 >= args .len ) fatal ("expected argument after '{s}'" , .{arg });
5022+ i += 1 ;
5023+ if (build_options .enable_debug_extensions ) {
5024+ debug_libc_paths_file = args [i ];
5025+ } else {
5026+ warn ("Zig was compiled without debug extensions. --debug-libc has no effect." , .{});
5027+ }
50195028 } else if (mem .eql (u8 , arg , "--verbose-link" )) {
50205029 verbose_link = true ;
50215030 } else if (mem .eql (u8 , arg , "--verbose-cc" )) {
@@ -5103,6 +5112,14 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
51035112 .is_explicit_dynamic_linker = false ,
51045113 };
51055114 };
5115+ // Likewise, `--debug-libc` allows overriding the libc installation.
5116+ const libc_installation : ? * const LibCInstallation = lci : {
5117+ const paths_file = debug_libc_paths_file orelse break :lci null ;
5118+ if (! build_options .enable_debug_extensions ) unreachable ;
5119+ const lci = try arena .create (LibCInstallation );
5120+ lci .* = try .parse (arena , paths_file , & resolved_target .result );
5121+ break :lci lci ;
5122+ };
51065123
51075124 process .raiseFileDescriptorLimit ();
51085125
@@ -5367,6 +5384,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
53675384 }
53685385
53695386 const comp = Compilation .create (gpa , arena , .{
5387+ .libc_installation = libc_installation ,
53705388 .dirs = dirs ,
53715389 .root_name = "build" ,
53725390 .config = config ,
0 commit comments