Skip to main content

ghostscope_dwarf/semantics/
pc_context.rs

1//! PC-centered semantic context types.
2
3use crate::core::{CuId, DieRef, FunctionId, InlineContextId, ModuleId, ScopeId};
4use std::path::PathBuf;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct PcContext {
8    pub module: ModuleId,
9    /// Runtime PC in the target process address space.
10    pub pc: u64,
11    /// Module-normalized PC used for DWARF and object-file queries.
12    pub normalized_pc: u64,
13    pub cu: Option<CuId>,
14    pub function: Option<FunctionId>,
15    /// Best-effort display name until stable function DIE ids are wired in.
16    pub function_name: Option<String>,
17    pub lexical_scopes: Vec<ScopeId>,
18    pub inline_chain: Vec<InlineFrame>,
19    /// Best-effort inline classification until inline DIE chains are exposed.
20    pub is_inline: Option<bool>,
21    pub line: Option<PcLineInfo>,
22    pub address_space: AddressSpaceInfo,
23}
24
25#[derive(Debug, Clone, PartialEq, Eq)]
26pub struct FunctionParameter {
27    pub name: String,
28    pub type_name: String,
29    pub is_artificial: bool,
30}
31
32#[derive(Debug, Clone, PartialEq, Eq)]
33pub struct InlineFrame {
34    pub context: Option<InlineContextId>,
35    pub call_site: Option<PcLineInfo>,
36    pub abstract_origin: Option<DieRef>,
37    pub concrete_die: DieRef,
38    pub function_name: Option<String>,
39}
40
41#[derive(Debug, Clone, PartialEq, Eq)]
42pub struct PcLineInfo {
43    pub file_path: String,
44    pub line_number: u32,
45    pub column: Option<u32>,
46    pub address: u64,
47}
48
49#[derive(Debug, Clone, PartialEq, Eq)]
50pub struct AddressSpaceInfo {
51    pub module_path: Option<PathBuf>,
52    pub runtime_base: Option<u64>,
53    pub link_base: Option<u64>,
54}
55
56#[derive(Debug, Clone, Copy, PartialEq, Eq)]
57pub struct PcRange {
58    pub start: u64,
59    pub end: u64,
60}
61
62impl PcRange {
63    pub fn contains(&self, pc: u64) -> bool {
64        if self.start == self.end {
65            pc == self.start
66        } else {
67            pc >= self.start && pc < self.end
68        }
69    }
70}