Skip to content

Commit f3272d7

Browse files
committed
fix: improve eBPF loader error propagation and diagnostics
1 parent 4869280 commit f3272d7

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

ghostscope/src/cli/runtime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ async fn run_cli_with_session(
113113
)
114114
.await
115115
{
116-
error!("Failed to compile and load script: {}", e);
116+
error!("Failed to compile and load script: {:#}", e);
117117
info!("GhostScope encountered an error during script compilation. Exiting gracefully.");
118118
return Err(e);
119119
}

ghostscope/src/script/compiler.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,18 @@ async fn create_and_attach_loader(
3232
.as_ref()
3333
.map(|c| c.ebpf_config.proc_module_offsets_max_entries as u32)
3434
.unwrap_or(4096);
35+
let pin_path = ghostscope_process::maps::proc_offsets_pin_path();
3536
if let Err(e) = ghostscope_process::maps::ensure_pinned_proc_offsets_exists(max_entries) {
36-
warn!(
37-
"Failed to ensure pinned proc_module_offsets map exists ({} entries): {}",
38-
max_entries, e
37+
error!(
38+
"Failed to ensure pinned proc_module_offsets map exists at {} ({} entries): {:#}",
39+
pin_path.display(),
40+
max_entries,
41+
e
3942
);
43+
return Err(e.context(format!(
44+
"Unable to prepare pinned proc_module_offsets map at {}",
45+
pin_path.display()
46+
)));
4047
}
4148

4249
let mut loader = GhostScopeLoader::new(&config.ebpf_bytecode)
@@ -398,14 +405,17 @@ pub async fn compile_and_load_script_for_tui(
398405
}
399406
Err(e) => {
400407
error!(
401-
"Failed to attach uprobe for trace_id {}: {}",
408+
"Failed to attach uprobe for trace_id {}: {:#}",
402409
config.assigned_trace_id, e
403410
);
411+
tracing::info!(
412+
"Attachment hints: check privileges, target binary availability, PID validity, and function addresses if needed."
413+
);
404414
// Update corresponding result to failed
405415
for result in &mut results {
406416
if result.pc_address == config.function_address.unwrap_or(0) {
407417
result.status =
408-
ExecutionStatus::Failed(format!("Failed to attach uprobe: {e}"));
418+
ExecutionStatus::Failed(format!("Failed to attach uprobe: {e:#}"));
409419
success_count -= 1;
410420
failed_count += 1;
411421
break;
@@ -682,17 +692,16 @@ pub async fn compile_and_load_script_for_cli(
682692
}
683693
Err(e) => {
684694
error!(
685-
"Failed to attach uprobe for trace_id {}: {}",
695+
"Failed to attach uprobe for trace_id {}: {:#}",
686696
config.assigned_trace_id, e
687697
);
688-
return Err(anyhow::anyhow!(
689-
"Failed to attach uprobe: {}. Possible reasons: \
690-
1. Need root permissions (run with sudo), \
691-
2. Target binary doesn't exist or lacks debug info, \
692-
3. Process not running or PID invalid, \
693-
4. Function addresses not accessible",
694-
e
695-
));
698+
tracing::info!(
699+
"Attachment hints: check privileges, target binary availability, PID validity, and function addresses if needed."
700+
);
701+
return Err(e.context(format!(
702+
"Failed to attach uprobe for trace_id {}",
703+
config.assigned_trace_id
704+
)));
696705
}
697706
}
698707
}

ghostscope/src/tracing/instance.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ impl TraceInstance {
5454
info!("Trace {} is already enabled", self.trace_id);
5555
Ok(())
5656
} else if let Some(ref mut loader) = self.loader {
57-
info!(
58-
"Enabling trace {} for target '{}' at PC 0x{:x} in binary '{}'",
59-
self.trace_id, self.target_display, self.pc, self.binary_path
60-
);
61-
if loader.is_uprobe_attached() {
62-
warn!("Uprobe already attached for trace {}", self.trace_id);
57+
let already_attached = loader.is_uprobe_attached();
58+
if !already_attached {
59+
info!(
60+
"Enabling trace {} for target '{}' at PC 0x{:x} in binary '{}'",
61+
self.trace_id, self.target_display, self.pc, self.binary_path
62+
);
63+
}
64+
if already_attached {
6365
self.is_enabled = true;
6466
Ok(())
6567
} else if loader.get_attachment_info().is_some() {

0 commit comments

Comments
 (0)