mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-14 08:51:02 +00:00
903cbd7159
- Implement the visitor interface. This simplifies working with the AST, for example transformations into other IRs or collecting and analyzing various statistics. - Switch the explorer to use the visitor interface. - Add the reciprocal function name conversion for function names. - Some drive-by cosmetic fixes. --------- Signed-off-by: xermicus <bigcyrill@hotmail.com>
69 lines
2.1 KiB
Rust
69 lines
2.1 KiB
Rust
//! The `llvm-dwarfdump` utility helper library.
|
|
|
|
use std::{
|
|
path::{Path, PathBuf},
|
|
process::{Command, Stdio},
|
|
};
|
|
|
|
pub static EXECUTABLE: &str = "llvm-dwarfdump";
|
|
pub static DEBUG_LINES_ARGUMENTS: [&str; 1] = ["--debug-line"];
|
|
pub static SOURCE_FILE_ARGUMENTS: [&str; 1] = ["--show-sources"];
|
|
|
|
/// Calls the `llvm-dwarfdump` tool to extract debug line information
|
|
/// from the shared object at `path`. Returns the output.
|
|
///
|
|
/// Provide `Some(dwarfdump_exectuable)` to override the default executable.
|
|
pub fn debug_lines(
|
|
shared_object: &Path,
|
|
dwarfdump_executable: &Option<PathBuf>,
|
|
) -> anyhow::Result<String> {
|
|
dwarfdump(shared_object, dwarfdump_executable, &DEBUG_LINES_ARGUMENTS)
|
|
}
|
|
|
|
/// Calls the `llvm-dwarfdump` tool to extract the source file name.
|
|
/// Returns the source file path.
|
|
///
|
|
/// Provide `Some(dwarfdump_exectuable)` to override the default executable.
|
|
pub fn source_file(
|
|
shared_object: &Path,
|
|
dwarfdump_executable: &Option<PathBuf>,
|
|
) -> anyhow::Result<PathBuf> {
|
|
let output = dwarfdump(shared_object, dwarfdump_executable, &SOURCE_FILE_ARGUMENTS)?;
|
|
let output = output.trim();
|
|
|
|
if output.is_empty() {
|
|
anyhow::bail!(
|
|
"the shared object at path `{}` doesn't contain the source file name. Hint: compile with debug information (-g)?",
|
|
shared_object.display()
|
|
);
|
|
}
|
|
|
|
Ok(output.into())
|
|
}
|
|
|
|
/// The internal `llvm-dwarfdump` helper function.
|
|
fn dwarfdump(
|
|
shared_object: &Path,
|
|
dwarfdump_executable: &Option<PathBuf>,
|
|
arguments: &[&str],
|
|
) -> anyhow::Result<String> {
|
|
let executable = dwarfdump_executable
|
|
.to_owned()
|
|
.unwrap_or_else(|| PathBuf::from(EXECUTABLE));
|
|
|
|
let output = Command::new(executable)
|
|
.args(arguments)
|
|
.arg(shared_object)
|
|
.stdin(Stdio::null())
|
|
.stdout(Stdio::piped())
|
|
.stderr(Stdio::piped())
|
|
.spawn()?
|
|
.wait_with_output()?;
|
|
|
|
if !output.status.success() {
|
|
anyhow::bail!(String::from_utf8_lossy(&output.stderr).to_string());
|
|
}
|
|
|
|
Ok(String::from_utf8_lossy(&output.stdout).to_string())
|
|
}
|