Skip to content

Commit 1bdd2ce

Browse files
authored
Auto-generate DWARF debug symbols in debug builds (#6863)
## Description DWARF debug symbols are now automatically generated and saved as `debug_symbols.obj` in the output directory when using debug builds. This enables better debugging support out of the box in development without requiring the `-g` flag. The `-g` flag is still supported for specifying custom debug symbol output paths or generating debug symbols in other build profiles. ## Checklist - [ ] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
1 parent b03c76e commit 1bdd2ce

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

forc-pkg/src/pkg.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -2279,8 +2279,13 @@ pub fn build_with_options(build_options: &BuildOpts) -> Result<Built> {
22792279
if let Some(outfile) = &binary_outfile {
22802280
built_package.write_bytecode(outfile.as_ref())?;
22812281
}
2282-
if let Some(outfile) = &debug_outfile {
2283-
built_package.write_debug_info(outfile.as_ref())?;
2282+
// Generate debug symbols if explicitly requested via -g flag or if in debug build
2283+
if debug_outfile.is_some() || build_profile.name == BuildProfile::DEBUG {
2284+
let debug_path = debug_outfile
2285+
.as_ref()
2286+
.map(|p| output_dir.join(p))
2287+
.unwrap_or_else(|| output_dir.join("debug_symbols.obj"));
2288+
built_package.write_debug_info(&debug_path)?;
22842289
}
22852290
built_package.write_output(minify, &pkg_manifest.project.name, &output_dir)?;
22862291
built_workspace.push(Arc::new(built_package));

sway-core/src/debug_generation/dwarf.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ pub fn write_dwarf(
4747
sway_error::error::CompileError::InternalOwned(err.to_string(), Span::dummy())
4848
})?;
4949

50-
let file = File::create(out_file).unwrap();
50+
// Create parent directories if they don't exist
51+
if let Some(parent) = out_file.parent() {
52+
std::fs::create_dir_all(parent).map_err(|err| {
53+
sway_error::error::CompileError::InternalOwned(err.to_string(), Span::dummy())
54+
})?;
55+
}
56+
let file = File::create(out_file).map_err(|err| {
57+
sway_error::error::CompileError::InternalOwned(err.to_string(), Span::dummy())
58+
})?;
5159
let mut obj = Object::new(
5260
object::BinaryFormat::Elf,
5361
object::Architecture::X86_64,

0 commit comments

Comments
 (0)