From c54a5b99ce0d4908698ea5d1c49467e22e691a81 Mon Sep 17 00:00:00 2001 From: wpt967 Date: Wed, 14 Aug 2024 14:36:18 +0100 Subject: [PATCH] [solidity] Add CLI option '-g' to generate debug information. Add command line option '-g' to generate source level debug information in the output code. This only works with the LLVM-IR code generator. Add flag 'emit_debug_info' to the llvm-context optimizer/code-gen settings structure, to record the setting of the '-g' CLI option. --- .../llvm-context/src/optimizer/settings/mod.rs | 16 +++++++++++++++- crates/solidity/src/resolc/arguments.rs | 5 +++++ crates/solidity/src/resolc/main.rs | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/llvm-context/src/optimizer/settings/mod.rs b/crates/llvm-context/src/optimizer/settings/mod.rs index 8d8df1ba..d8ce2c3d 100644 --- a/crates/llvm-context/src/optimizer/settings/mod.rs +++ b/crates/llvm-context/src/optimizer/settings/mod.rs @@ -9,7 +9,7 @@ use itertools::Itertools; use self::size_level::SizeLevel; -/// The LLVM optimizer settings. +/// The LLVM optimizer and code-gen settings. #[derive(Debug, Serialize, Deserialize, Clone, Eq)] pub struct Settings { /// The middle-end optimization level. @@ -28,6 +28,9 @@ pub struct Settings { pub is_verify_each_enabled: bool, /// Whether the LLVM `debug logging` option is enabled. pub is_debug_logging_enabled: bool, + + /// Whether to generate source-level debug information. + pub emit_debug_info: bool, } impl Settings { @@ -47,6 +50,8 @@ impl Settings { is_verify_each_enabled: false, is_debug_logging_enabled: false, + + emit_debug_info: false, } } @@ -58,6 +63,8 @@ impl Settings { is_verify_each_enabled: bool, is_debug_logging_enabled: bool, + + emit_debug_info: bool, ) -> Self { Self { level_middle_end, @@ -69,6 +76,8 @@ impl Settings { is_verify_each_enabled, is_debug_logging_enabled, + + emit_debug_info, } } @@ -220,6 +229,11 @@ impl Settings { pub fn is_system_request_memoization_disabled(&self) -> bool { self.is_system_request_memoization_disabled } + + /// Whether source-level debug information should be emitted. + pub fn emit_debug_info(&self) -> bool { + return self.emit_debug_info; + } } impl PartialEq for Settings { diff --git a/crates/solidity/src/resolc/arguments.rs b/crates/solidity/src/resolc/arguments.rs index 4bc5dd86..2824ed1c 100644 --- a/crates/solidity/src/resolc/arguments.rs +++ b/crates/solidity/src/resolc/arguments.rs @@ -149,6 +149,11 @@ pub struct Arguments { #[structopt(long = "suppress-warnings")] pub suppress_warnings: Option>, + /// Generate source based debug information in the output code file. This only has an effect + /// with the LLVM-IR code generator and is ignored otherwise. + #[structopt(short = 'g')] + pub emit_source_debug_info: bool, + /// Dump all IRs to files in the specified directory. /// Only for testing and debugging. #[structopt(long = "debug-output-dir")] diff --git a/crates/solidity/src/resolc/main.rs b/crates/solidity/src/resolc/main.rs index 20c808b0..3876cd2e 100644 --- a/crates/solidity/src/resolc/main.rs +++ b/crates/solidity/src/resolc/main.rs @@ -106,6 +106,7 @@ fn main_inner() -> anyhow::Result<()> { } optimizer_settings.is_verify_each_enabled = arguments.llvm_verify_each; optimizer_settings.is_debug_logging_enabled = arguments.llvm_debug_logging; + optimizer_settings.emit_debug_info = arguments.emit_source_debug_info; let include_metadata_hash = match arguments.metadata_hash { Some(metadata_hash) => {