From 1bdafbf2268588eeecc66e7d94ccb208d246b856 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 16 Aug 2021 10:48:10 -0700 Subject: [PATCH] Don't require `DW_AT_comp_dir` for debuginfo I'm not too well-versed in this area of debuginfo, but I think this should address #3184 where it appears not all compilers emit `DW_AT_comp_dir`. This seems to match the default behavior of `gimli` when it maps an existing line program to a new line program as well (choosing an empty name for the compilation directory). Closes #3184 --- crates/debug/src/transform/line_program.rs | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/crates/debug/src/transform/line_program.rs b/crates/debug/src/transform/line_program.rs index 7906fbcd40..a9b309bfe5 100644 --- a/crates/debug/src/transform/line_program.rs +++ b/crates/debug/src/transform/line_program.rs @@ -63,17 +63,20 @@ where }; let comp_dir = root.attr_value(gimli::DW_AT_comp_dir)?; let comp_name = root.attr_value(gimli::DW_AT_name)?; - let out_comp_dir = clone_attr_string( - comp_dir.as_ref().context("comp_dir")?, - gimli::DW_FORM_strp, - unit, - debug_str, - debug_str_offsets, - debug_line_str, - out_strings, - )?; + let out_comp_dir = match &comp_dir { + Some(comp_dir) => Some(clone_attr_string( + comp_dir, + gimli::DW_FORM_strp, + unit, + debug_str, + debug_str_offsets, + debug_line_str, + out_strings, + )?), + None => None, + }; let out_comp_name = clone_attr_string( - comp_name.as_ref().context("comp_name")?, + comp_name.as_ref().context("missing DW_AT_name attribute")?, gimli::DW_FORM_strp, unit, debug_str, @@ -102,7 +105,7 @@ where let mut out_program = write::LineProgram::new( out_encoding, line_encoding, - out_comp_dir, + out_comp_dir.unwrap_or_else(|| write::LineString::String(Vec::new())), out_comp_name, None, );