rudy_dwarf/parser/
pointers.rs

1//! Option parser implementation using combinators
2
3use super::Parser;
4use crate::{
5    parser::primitives::{data_offset, entry_type, is_member_tag, member},
6    Die,
7};
8
9/// Parser for NonNull
10///
11/// This basically just walks the "pointer" member to the pointer
12/// type, and then from the pointer type to the inner type. Does
13/// a little verification along the way.
14pub fn nonnull() -> impl Parser<Die> {
15    // NonNull<T> should generally be a thin wrapper around a pointer type,
16    // we'll verify some of this though
17    member("pointer")
18        .then(
19            data_offset().and(
20                entry_type().then(is_member_tag(gimli::DW_TAG_pointer_type).then(entry_type())),
21            ),
22        )
23        .map_res(|(offset, inner_type)| {
24            if offset != 0 {
25                anyhow::bail!("NonNull pointer offset is not zero, found: {offset:#x}");
26            }
27
28            // Return the inner type
29            Ok(inner_type)
30        })
31}