Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bins/dwarf-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ async fn run_source_line_benchmark(
let (file_path, line_number) = parse_source_line(source)?;

let load_start = Instant::now();
let (mut analyzer, load_breakdown) = load_analyzer_with_breakdown(pid, target_path).await?;
let (analyzer, load_breakdown) = load_analyzer_with_breakdown(pid, target_path).await?;
let loading_time = load_start.elapsed();

let mut query_times = Vec::with_capacity(runs);
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/tests/cpp_script_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ async fn compile_cpp_complex_script(
script: &str,
) -> anyhow::Result<ghostscope_compiler::CompilationResult> {
let binary_path = FIXTURES.get_test_binary("cpp_complex_program")?;
let mut analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path)
let analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path)
.await
.map_err(|e| anyhow::anyhow!("failed to load DWARF for cpp_complex_program: {e}"))?;
let compile_options = ghostscope_compiler::CompileOptions {
binary_path_hint: Some(binary_path.to_string_lossy().into_owned()),
..Default::default()
};

ghostscope_compiler::compile_script(script, &mut analyzer, None, Some(1), &compile_options)
ghostscope_compiler::compile_script(script, &analyzer, None, Some(1), &compile_options)
.map_err(|e| anyhow::anyhow!("compile_script failed: {e}"))
}

Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/tests/dwarf_index_regressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ async fn assert_partitioned_ranges_source_line_query_recovers_function_scope(
binary_path: PathBuf,
scenario: &str,
) -> anyhow::Result<()> {
let mut analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path).await?;
let analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path).await?;
let query_results = analyzer
.query_source_line_best_effort("partitioned_ranges_program.c", 18)
.map_err(|e| anyhow::anyhow!("Failed source-line query for {scenario}: {e}"))?;
Expand Down Expand Up @@ -614,7 +614,7 @@ async fn test_inline_callsite_clang_dwarf5_resolves_debug_addr_entry_pc() -> any
);
let target = spawn_inline_callsite_program(binary_path).await?;
let query_result: anyhow::Result<()> = async {
let mut pid_analyzer = ghostscope_dwarf::DwarfAnalyzer::from_pid(target.host_pid()).await?;
let pid_analyzer = ghostscope_dwarf::DwarfAnalyzer::from_pid(target.host_pid()).await?;
let query_results =
pid_analyzer.query_source_line_best_effort("inline_callsite_program.c", INLINE_TRACE_LINE)?;
anyhow::ensure!(
Expand Down
8 changes: 4 additions & 4 deletions e2e-tests/tests/member_pointer_compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ async fn compile_member_pointer_script(
opt_level: OptimizationLevel,
) -> anyhow::Result<ghostscope_compiler::CompilationResult> {
let binary_path = FIXTURES.get_test_binary_with_opt("member_pointer_program", opt_level)?;
let mut analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path)
let analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path)
.await
.map_err(|e| anyhow::anyhow!("failed to load DWARF for member_pointer_program: {e}"))?;
let compile_options = ghostscope_compiler::CompileOptions {
binary_path_hint: Some(binary_path.to_string_lossy().into_owned()),
..Default::default()
};

ghostscope_compiler::compile_script(script, &mut analyzer, None, Some(1), &compile_options)
ghostscope_compiler::compile_script(script, &analyzer, None, Some(1), &compile_options)
.map_err(|e| anyhow::anyhow!("compile_script failed: {e}"))
}

Expand All @@ -27,7 +27,7 @@ async fn test_member_pointer_planner_resolves_o2_chain_accesses() -> anyhow::Res

let binary_path =
FIXTURES.get_test_binary_with_opt("member_pointer_program", OptimizationLevel::O2)?;
let mut analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path)
let analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path)
.await
.map_err(|e| anyhow::anyhow!("failed to load DWARF for member_pointer_program: {e}"))?;
let addrs = analyzer.lookup_addresses_by_source_line("member_pointer_program.c", TRACE_LINE);
Expand Down Expand Up @@ -201,7 +201,7 @@ async fn test_complex_bitfield_chain_planner_resolves_member_offsets() -> anyhow

let binary_path =
FIXTURES.get_test_binary_with_opt("complex_types_program", OptimizationLevel::Debug)?;
let mut analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path)
let analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path)
.await
.map_err(|e| anyhow::anyhow!("failed to load DWARF for complex_types_program: {e}"))?;
let addrs = analyzer.lookup_addresses_by_source_line("complex_types_program.c", 15);
Expand Down
12 changes: 6 additions & 6 deletions e2e-tests/tests/optimized_inline_call_value_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async fn test_optimized_inline_parameters_are_live_before_internal_call() -> any
init();

let binary_path = FIXTURES.get_test_binary("inline_call_value_program")?;
let mut analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path).await?;
let analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path).await?;
let addrs = analyzer.lookup_addresses_by_source_line(
"inline_call_value_program.c",
INLINE_BEFORE_CALL_TRACE_LINE,
Expand Down Expand Up @@ -134,7 +134,7 @@ async fn test_optimized_inline_parameters_are_live_before_internal_call() -> any
}

let target = spawn_inline_call_value_program(&binary_path).await?;
let mut pid_analyzer = ghostscope_dwarf::DwarfAnalyzer::from_pid(target.host_pid()).await?;
let pid_analyzer = ghostscope_dwarf::DwarfAnalyzer::from_pid(target.host_pid()).await?;
let pid_results = pid_analyzer.query_source_line_best_effort(
"inline_call_value_program.c",
INLINE_BEFORE_CALL_TRACE_LINE,
Expand All @@ -157,7 +157,7 @@ async fn test_optimized_inline_parameters_have_exact_values_before_internal_call
init();

let binary_path = FIXTURES.get_test_binary("inline_call_value_program")?;
let mut analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path).await?;
let analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path).await?;
let addrs = analyzer.lookup_addresses_by_source_line(
"inline_call_value_program.c",
INLINE_BEFORE_CALL_TRACE_LINE,
Expand Down Expand Up @@ -221,7 +221,7 @@ async fn test_optimized_inline_parameters_survive_internal_call_sites() -> anyho
init();

let binary_path = FIXTURES.get_test_binary("inline_call_value_program")?;
let mut analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path).await?;
let analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path).await?;
let addrs = analyzer.lookup_addresses_by_source_line(
"inline_call_value_program.c",
INLINE_AFTER_CALL_TRACE_LINE,
Expand Down Expand Up @@ -250,7 +250,7 @@ async fn test_optimized_inline_parameters_survive_internal_call_sites() -> anyho
}

let target = spawn_inline_call_value_program(&binary_path).await?;
let mut pid_analyzer = ghostscope_dwarf::DwarfAnalyzer::from_pid(target.host_pid()).await?;
let pid_analyzer = ghostscope_dwarf::DwarfAnalyzer::from_pid(target.host_pid()).await?;
let pid_results = pid_analyzer.query_source_line_best_effort(
"inline_call_value_program.c",
INLINE_AFTER_CALL_TRACE_LINE,
Expand All @@ -274,7 +274,7 @@ async fn test_entry_value_recovers_outer_parameter_inside_optimized_inline_after
init();

let binary_path = FIXTURES.get_test_binary("inline_call_value_program")?;
let mut analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path).await?;
let analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path).await?;
let addrs = analyzer.lookup_addresses_by_source_line(
"inline_call_value_program.c",
INLINE_AFTER_CALL_TRACE_LINE,
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/tests/optimized_inline_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async fn test_optimized_inline_struct_member_access_resolves_inline_parameter_na
init();

let binary_path = FIXTURES.get_test_binary("inline_callsite_program")?;
let mut analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path)
let analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path)
.await
.map_err(|e| anyhow::anyhow!("Failed to load DWARF for inline_callsite_program: {}", e))?;
let addrs = analyzer
Expand Down Expand Up @@ -190,7 +190,7 @@ async fn test_optimized_inline_struct_member_access_resolves_inline_parameter_na
// The analyzer runs in the host test process, so it must inspect the host PID.
// `visible_pid_from(observer)` is only correct for processes that actually run
// inside the observer sandbox, such as GhostScope itself.
let mut pid_analyzer = ghostscope_dwarf::DwarfAnalyzer::from_pid(target.host_pid()).await?;
let pid_analyzer = ghostscope_dwarf::DwarfAnalyzer::from_pid(target.host_pid()).await?;
let pid_addrs = pid_analyzer
.lookup_addresses_by_source_line("inline_callsite_program.c", INLINE_STATE_TRACE_LINE);
anyhow::ensure!(
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/tests/script_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ async fn test_capture_len_uses_scalar_script_var_from_dwarf_expr() -> anyhow::Re
init();

let binary_path = FIXTURES.get_test_binary("sample_program")?;
let mut analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path)
let analyzer = ghostscope_dwarf::DwarfAnalyzer::from_exec_path(&binary_path)
.await
.map_err(|e| anyhow::anyhow!("failed to load DWARF for sample_program: {e}"))?;
let script_content = r#"
Expand All @@ -436,7 +436,7 @@ trace sample_lib.c:45 {
};
let result = ghostscope_compiler::compile_script(
script_content,
&mut analyzer,
&analyzer,
None,
Some(1),
&compile_options,
Expand Down
4 changes: 2 additions & 2 deletions ghostscope-compiler/src/ebpf/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub struct EbpfContext<'ctx, 'dw> {
pub optimized_out_vars: HashMap<String, bool>, // Optimized out variables
pub var_pc_addresses: HashMap<String, u64>, // Variable -> PC address
pub variable_context: Option<VariableContext>, // Scope validation context
pub process_analyzer: Option<&'dw mut DwarfAnalyzer>, // Multi-module DWARF analyzer
pub(super) process_analyzer: Option<&'dw DwarfAnalyzer>, // Multi-module DWARF analyzer
pub current_trace_id: Option<u32>, // Current trace_id being compiled
pub current_compile_time_context: Option<CompileTimeContext>, // PC address and module for DWARF queries

Expand Down Expand Up @@ -287,7 +287,7 @@ impl<'ctx, 'dw> EbpfContext<'ctx, 'dw> {
pub fn new_with_process_analyzer(
context: &'ctx Context,
module_name: &str,
process_analyzer: Option<&'dw mut DwarfAnalyzer>,
process_analyzer: Option<&'dw DwarfAnalyzer>,
trace_id: Option<u32>,
compile_options: &crate::CompileOptions,
) -> Result<Self> {
Expand Down
12 changes: 5 additions & 7 deletions ghostscope-compiler/src/ebpf/dwarf_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<'ctx, 'dw> EbpfContext<'ctx, 'dw> {

/// Compute section code for an address within a module (text=0, rodata=1, data=2, bss=3).
fn section_code_for_address(&mut self, module_path: &str, link_addr: u64) -> u8 {
if let Some(analyzer) = self.process_analyzer.as_deref_mut() {
if let Some(analyzer) = self.process_analyzer {
if let Some(st) = analyzer.classify_section_for_address(module_path, link_addr) {
return match st {
ghostscope_dwarf::core::SectionType::Text => 0,
Expand Down Expand Up @@ -1320,7 +1320,6 @@ impl<'ctx, 'dw> EbpfContext<'ctx, 'dw> {

let analyzer = self
.process_analyzer
.as_deref_mut()
.ok_or_else(|| CodeGenError::DwarfError("No DWARF analyzer available".to_string()))?;

let module_address = ghostscope_dwarf::ModuleAddress::new(
Expand All @@ -1329,7 +1328,7 @@ impl<'ctx, 'dw> EbpfContext<'ctx, 'dw> {
);

let module_path_owned = module_path;
let lookup_globals = |analyzer: &mut ghostscope_dwarf::DwarfAnalyzer| -> Result<
let lookup_globals = |analyzer: &ghostscope_dwarf::DwarfAnalyzer| -> Result<
Option<(std::path::PathBuf, VariableWithEvaluation)>,
> {
debug!(
Expand Down Expand Up @@ -1647,7 +1646,7 @@ impl<'ctx, 'dw> EbpfContext<'ctx, 'dw> {
let ctx = self.get_compile_time_context()?;
let module_path = ctx.module_path.clone();
let pc_address = ctx.pc_address;
let analyzer = self.process_analyzer.as_deref_mut().ok_or_else(|| {
let analyzer = self.process_analyzer.ok_or_else(|| {
CodeGenError::DwarfError("No DWARF analyzer available".to_string())
})?;
let module_address = ghostscope_dwarf::ModuleAddress::new(
Expand Down Expand Up @@ -1801,7 +1800,7 @@ impl<'ctx, 'dw> EbpfContext<'ctx, 'dw> {
let ctx = self.get_compile_time_context()?;
let module_path = ctx.module_path.clone();
let pc_address = ctx.pc_address;
let analyzer = self.process_analyzer.as_deref_mut().ok_or_else(|| {
let analyzer = self.process_analyzer.ok_or_else(|| {
CodeGenError::DwarfError("No DWARF analyzer available".to_string())
})?;
let module_address = ghostscope_dwarf::ModuleAddress::new(
Expand Down Expand Up @@ -1927,7 +1926,6 @@ impl<'ctx, 'dw> EbpfContext<'ctx, 'dw> {
let pc_address = ctx.pc_address;
let analyzer = self
.process_analyzer
.as_deref_mut()
.ok_or_else(|| CodeGenError::DwarfError("No DWARF analyzer available".to_string()))?;
// First attempt: current module at current PC (locals/params)
let module_address = ghostscope_dwarf::ModuleAddress::new(
Expand Down Expand Up @@ -2095,7 +2093,7 @@ impl<'ctx, 'dw> EbpfContext<'ctx, 'dw> {
}
let ctx = self.get_compile_time_context()?;
let module_path = ctx.module_path.clone();
if let Some(analyzer) = self.process_analyzer.as_deref_mut() {
if let Some(analyzer) = self.process_analyzer {
let mut alias_used: Option<String> = None;
for n in candidate_names {
// Prefer cross-module definitions first to avoid forward decls with size=0 in current CU
Expand Down
2 changes: 1 addition & 1 deletion ghostscope-compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl Default for CompileOptions {
/// to perform compilation across main executable and dynamic libraries
pub fn compile_script(
script_source: &str,
process_analyzer: &mut ghostscope_dwarf::DwarfAnalyzer,
process_analyzer: &ghostscope_dwarf::DwarfAnalyzer,
pid: Option<u32>,
trace_id: Option<u32>,
compile_options: &CompileOptions,
Expand Down
12 changes: 6 additions & 6 deletions ghostscope-compiler/src/script/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct FailedTarget {

/// Unified AST compiler that performs DWARF queries and code generation in single pass
pub struct AstCompiler<'a> {
process_analyzer: Option<&'a mut ghostscope_dwarf::DwarfAnalyzer>,
process_analyzer: Option<&'a ghostscope_dwarf::DwarfAnalyzer>,
uprobe_configs: Vec<UProbeConfig>,
failed_targets: Vec<FailedTarget>, // Track failed compilation attempts
binary_path_hint: Option<String>,
Expand All @@ -85,7 +85,7 @@ pub struct AstCompiler<'a> {

impl<'a> AstCompiler<'a> {
pub fn new(
process_analyzer: Option<&'a mut ghostscope_dwarf::DwarfAnalyzer>,
process_analyzer: Option<&'a ghostscope_dwarf::DwarfAnalyzer>,
binary_path_hint: Option<String>,
starting_trace_id: u32,
compile_options: crate::CompileOptions,
Expand Down Expand Up @@ -223,7 +223,7 @@ impl<'a> AstCompiler<'a> {
let default_msg =
format!("No addresses resolved for source line {file_path}:{line_number}");

let analyzer = match &mut self.process_analyzer {
let analyzer = match self.process_analyzer {
Some(a) => a,
None => return default_msg,
};
Expand Down Expand Up @@ -329,7 +329,7 @@ impl<'a> AstCompiler<'a> {
line_number,
} => {
// Obtain addresses first in a separate scope to avoid holding a mutable borrow of self
let module_addresses = if let Some(analyzer) = &mut self.process_analyzer {
let module_addresses = if let Some(analyzer) = self.process_analyzer {
analyzer.lookup_addresses_by_source_line(file_path, *line_number)
} else {
Vec::new()
Expand Down Expand Up @@ -590,7 +590,7 @@ impl<'a> AstCompiler<'a> {
}
TracePattern::FunctionName(func_name) => {
// Resolve all addresses for the function name and generate per-PC programs
let module_addresses = if let Some(analyzer) = &mut self.process_analyzer {
let module_addresses = if let Some(analyzer) = self.process_analyzer {
analyzer.lookup_function_addresses(func_name)
} else {
Vec::new()
Expand Down Expand Up @@ -756,7 +756,7 @@ impl<'a> AstCompiler<'a> {
let mut codegen_new = crate::ebpf::context::NewCodeGen::new_with_process_analyzer(
&context,
&ebpf_function_name,
self.process_analyzer.as_deref_mut(),
self.process_analyzer,
Some(assigned_trace_id),
&self.compile_options,
)
Expand Down
Loading
Loading