stage2: add the .debug_line header and associated data types

* the .debug_line header is written properly
 * link.File.Elf gains:
   - SrcFn, which is now a field in Module.Fn
   - SrcFile, which is now a field in Module.Scope.File
 * link.File.Elf gets a whole *Package field rather than only
   root_src_dir_path.
 * the fields first_dbg_line_file and last_dbg_line_file tell where the
   Line Number Program begins and ends, which alows moving files when
   the header gets too big, and allows appending files to the end.
 * codegen is passed a buffer for emitting .debug_line
   Line Number Program opcodes for functions.

See #5963

There is some work-in-progress code here, but I need to go make some
experimental changes to changing how to represent source locations and I
want to do that in a separate commit.
This commit is contained in:
Andrew Kelley
2020-07-31 23:22:35 -07:00
parent c0654d2db2
commit ba6e5cbfd2
4 changed files with 284 additions and 32 deletions

View File

@@ -279,6 +279,9 @@ pub const Fn = struct {
},
owner_decl: *Decl,
/// Represents the function in the linked output file.
link: link.File.Elf.SrcFn = link.File.Elf.SrcFn.empty,
/// This memory is temporary and points to stack memory for the duration
/// of Fn analysis.
pub const Analysis = struct {
@@ -503,6 +506,10 @@ pub const Scope = struct {
/// Direct children of the file.
decls: ArrayListUnmanaged(*Decl),
/// Represents the file in the linker code. The linker code
/// uses this field to store data relevant to its purposes.
link: link.File.Elf.SrcFile = link.File.Elf.SrcFile.empty,
pub fn unload(self: *File, gpa: *Allocator) void {
switch (self.status) {
.never_loaded,
@@ -792,7 +799,7 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module {
const bin_file_dir = options.bin_file_dir orelse std.fs.cwd();
const bin_file = try link.File.openPath(gpa, bin_file_dir, options.bin_file_path, .{
.root_name = root_name,
.root_src_dir_path = options.root_pkg.root_src_dir_path,
.root_pkg = options.root_pkg,
.target = options.target,
.output_mode = options.output_mode,
.link_mode = options.link_mode orelse .Static,