From c559a67ad318092cd468e6509a1378e854a74233 Mon Sep 17 00:00:00 2001 From: swananan Date: Thu, 21 May 2026 23:04:33 +0800 Subject: [PATCH] refactor: tighten dwarf public api --- ghostscope-dwarf/src/core/mod.rs | 32 ++++++++++++++----- ghostscope-dwarf/src/index/mod.rs | 14 ++++---- ghostscope-dwarf/src/lib.rs | 10 +++--- .../src/objfile/function_lookup.rs | 11 ++++--- ghostscope-dwarf/src/objfile/mod.rs | 2 +- ghostscope-dwarf/src/parser/mod.rs | 4 ++- ghostscope-dwarf/src/semantics/mod.rs | 22 ++++++++++--- 7 files changed, 66 insertions(+), 29 deletions(-) diff --git a/ghostscope-dwarf/src/core/mod.rs b/ghostscope-dwarf/src/core/mod.rs index 9094de9b..a76d4ed7 100644 --- a/ghostscope-dwarf/src/core/mod.rs +++ b/ghostscope-dwarf/src/core/mod.rs @@ -12,14 +12,30 @@ pub mod plan; pub mod symbol_names; pub mod types; -pub use demangle::*; -pub use diagnostic::*; -pub use errors::*; -pub use evaluation::*; -pub use ids::*; -pub use plan::*; -pub(crate) use symbol_names::*; -pub use types::*; +pub use demangle::is_likely_mangled; +pub use diagnostic::{ + AmbiguityReason, Availability, HelperMode, Provenance, RuntimeCapabilities, RuntimeRequirement, + TargetArch, UnsupportedReason, VerifierRisk, +}; +pub use errors::{DwarfError, Result}; +pub(crate) use evaluation::{ + plan_expr_steps_to_expression, DirectValueResult, LocationResult, PieceResult, + RawExpressionResult, +}; +pub use evaluation::{ + CallerFrameRecovery, CfaResult, EntryValueCase, MemoryAccessSize, PlanExprOp, +}; +pub use ids::{CuId, DieRef, FunctionId, InlineContextId, ModuleId, ScopeId, TypeId, VariableId}; +pub(crate) use plan::ParsedLocation; +pub use plan::{AddressExpr, PieceLocation, VariableLocation}; +pub(crate) use symbol_names::{ + demangled_name, extract_name_fragments, normalize_demangled_signature, + symbol_name_matches_query, +}; +pub use types::{ + FunctionDieKind, FunctionInfo, GlobalVariableInfo, IndexEntry, IndexFlags, LineEntry, + ModuleAddress, SectionType, SourceLocation, +}; pub(crate) fn attr_u64(value: gimli::AttributeValue) -> Option { match value { diff --git a/ghostscope-dwarf/src/index/mod.rs b/ghostscope-dwarf/src/index/mod.rs index f5a91077..6e63410f 100644 --- a/ghostscope-dwarf/src/index/mod.rs +++ b/ghostscope-dwarf/src/index/mod.rs @@ -6,10 +6,12 @@ pub(crate) mod line_mapping; pub(crate) mod path; pub(crate) mod type_index; -pub(crate) use block_index::*; -pub(crate) use cfi_index::*; -pub(crate) use lightweight_file_index::*; -pub(crate) use lightweight_index::*; -pub(crate) use line_mapping::*; +pub(crate) use block_index::{BlockIndex, BlockIndexBuilder, FunctionBlocks, VarRef}; +#[cfg(test)] +pub(crate) use block_index::{BlockNode, CallSiteParameter, CallSiteRecord}; +pub(crate) use cfi_index::CfiIndex; +pub(crate) use lightweight_file_index::{LightweightFileIndex, ScopedFileIndexManager}; +pub(crate) use lightweight_index::{LightweightIndex, LightweightIndexShard}; +pub(crate) use line_mapping::LineMappingTable; pub(crate) use path::{directory_from_index, resolve_file_path}; -pub(crate) use type_index::*; +pub(crate) use type_index::TypeNameIndex; diff --git a/ghostscope-dwarf/src/lib.rs b/ghostscope-dwarf/src/lib.rs index 14c4c7cf..4f75afe0 100644 --- a/ghostscope-dwarf/src/lib.rs +++ b/ghostscope-dwarf/src/lib.rs @@ -14,16 +14,16 @@ pub(crate) mod loader; pub(crate) mod objfile; pub(crate) mod parser; pub(crate) mod path_match; -pub mod semantics; +pub(crate) mod semantics; // Main entry point -pub mod analyzer; +pub(crate) mod analyzer; // Re-export main public API only pub use analyzer::{ - AddressQueryResult, DwarfAnalyzer, FunctionQueryResult, MainExecutableInfo, - ModuleDefaultPolicy, ModuleLoadingEvent, ModuleLoadingStats, ModuleStats, SharedLibraryInfo, - SimpleFileInfo, SourceLineAddressSearch, SourceLineQuerySearch, + AddressQueryResult, AnalyzerStats, DwarfAnalyzer, ExecutableFileInfo, FunctionQueryResult, + MainExecutableInfo, ModuleDefaultPolicy, ModuleLoadingEvent, ModuleLoadingStats, ModuleStats, + SectionInfo, SharedLibraryInfo, SimpleFileInfo, SourceLineAddressSearch, SourceLineQuerySearch, }; // Re-export essential core and semantic support types. diff --git a/ghostscope-dwarf/src/objfile/function_lookup.rs b/ghostscope-dwarf/src/objfile/function_lookup.rs index 3485407a..4c60886c 100644 --- a/ghostscope-dwarf/src/objfile/function_lookup.rs +++ b/ghostscope-dwarf/src/objfile/function_lookup.rs @@ -1255,8 +1255,9 @@ mod tests { fn fragment_candidates_match_demangled_function_queries() { let mangled = "_ZN2ns6Widget3runEv".to_string(); let demangled = - crate::core::demangle_by_lang(Some(gimli::DW_LANG_C_plus_plus_17), &mangled).unwrap(); - let leaf = crate::core::demangled_leaf(&demangled); + crate::core::demangle::demangle_by_lang(Some(gimli::DW_LANG_C_plus_plus_17), &mangled) + .unwrap(); + let leaf = crate::core::demangle::demangled_leaf(&demangled); let mut functions = HashMap::new(); functions.insert( @@ -1293,7 +1294,8 @@ mod tests { #[test] fn fragment_candidates_match_rust_v0_demangled_function_queries() { let mangled = "_RNvCs73fAdSrgOJL_4test4main".to_string(); - let demangled = crate::core::demangle_by_lang(Some(gimli::DW_LANG_Rust), &mangled).unwrap(); + let demangled = + crate::core::demangle::demangle_by_lang(Some(gimli::DW_LANG_Rust), &mangled).unwrap(); let mut functions = HashMap::new(); functions.insert( @@ -1326,7 +1328,8 @@ mod tests { fn scan_fallback_matches_substitution_heavy_cpp_queries() { let mangled = "_ZNSt6vectorIiSaIiEE3endEv".to_string(); let demangled = - crate::core::demangle_by_lang(Some(gimli::DW_LANG_C_plus_plus_17), &mangled).unwrap(); + crate::core::demangle::demangle_by_lang(Some(gimli::DW_LANG_C_plus_plus_17), &mangled) + .unwrap(); let mut functions = HashMap::new(); functions.insert( diff --git a/ghostscope-dwarf/src/objfile/mod.rs b/ghostscope-dwarf/src/objfile/mod.rs index e083a4d8..5e667b32 100644 --- a/ghostscope-dwarf/src/objfile/mod.rs +++ b/ghostscope-dwarf/src/objfile/mod.rs @@ -7,4 +7,4 @@ pub(crate) mod loading; pub(crate) mod source_location; pub(crate) mod variables; -pub(crate) use loaded::*; +pub(crate) use loaded::LoadedObjfile; diff --git a/ghostscope-dwarf/src/parser/mod.rs b/ghostscope-dwarf/src/parser/mod.rs index a7976548..7db38fbb 100644 --- a/ghostscope-dwarf/src/parser/mod.rs +++ b/ghostscope-dwarf/src/parser/mod.rs @@ -11,5 +11,7 @@ pub(crate) use detailed_parser::ParsedVariable; // Internal re-exports for crate use pub(crate) use crate::dwarf_expr::ExpressionEvaluator; pub(crate) use detailed_parser::DetailedParser; -pub(crate) use fast_parser::*; +pub(crate) use fast_parser::{ + CompilationUnit, DebugParseResult, DwarfParseResult, DwarfParser, LineParseResult, SourceFile, +}; pub(crate) use range_extractor::RangeExtractor; diff --git a/ghostscope-dwarf/src/semantics/mod.rs b/ghostscope-dwarf/src/semantics/mod.rs index c6330ea5..5c172e9e 100644 --- a/ghostscope-dwarf/src/semantics/mod.rs +++ b/ghostscope-dwarf/src/semantics/mod.rs @@ -7,12 +7,26 @@ pub(crate) mod origins; pub(crate) mod pc; pub(crate) mod types; -pub use c_types::*; +pub use c_types::{ + c_integer_comparison_type, is_c_aggregate_type, is_c_pointer_or_array_type, + is_c_signed_integer_type, strip_type_aliases, usual_c_arithmetic_comparison_plan, + CIntegerComparisonPlan, CIntegerComparisonType, +}; pub(crate) use origins::{ resolve_attr_with_unit_origins, resolve_name_with_origins, resolve_origin_entry, }; pub(crate) use pc::{range_contains_pc, ranges_contain_pc}; -pub use pc_context::*; +pub use pc_context::{AddressSpaceInfo, InlineFrame, PcContext, PcLineInfo, PcRange}; pub(crate) use types::{resolve_type_ref_in_same_unit_with_origins, resolve_type_ref_with_origins}; -pub use unwind_plan::*; -pub use variable_plan::*; +pub use unwind_plan::{ + CfaRulePlan, CompactUnwindRow, CompactUnwindStats, CompactUnwindTable, RegisterRecoveryPlan, + UnwindDiagnostic, UnwindDiagnosticKind, +}; +pub(crate) use variable_plan::PlanError; +pub use variable_plan::{ + AddressOrigin, LvalueAddressPlan, PlannedAddress, PlannedAddressKind, PlannedValue, + RuntimeComputedExpr, RuntimeComputedKind, VariableAccessPath, VariableAccessSegment, + VariableLoweringKind, VariableLoweringPlan, VariableMaterialization, + VariableMaterializationPlan, VariablePlan, VariableQueryDiagnostic, VariableReadPlan, + VisibleVariable, VisibleVariablesResult, +};