Skip to main content

GsymBuilder

Struct GsymBuilder 

Source
pub struct GsymBuilder { /* private fields */ }
Expand description

Version-independent, deterministic GSYM construction API.

Add FileEntry values and Function records, then encode with Self::to_bytes or Self::write_to. The same inputs and options always produce the same bytes, so output can be compared or content-addressed.

Two things to know while building:

  • Self::add_file interns entries. Adding the same directory and basename twice returns the same FileIndex, and index zero is permanently the empty entry.
  • Self::add_function validates as it goes and rejects an empty name, a reversed range, or a line row outside the function. Cross-record checks that need the whole model, such as file references, run at encode time.

Functions may be added in any order. Setters take and return self, so they chain, while add_file and add_function take &mut self.

§Example

use gsym::{AddressRange, Function, Gsym, GsymBuilder};

let mut builder = GsymBuilder::new().base_address(0x1000);
builder.add_function(Function::new(
    AddressRange::new(0x1010, 0x1020),
    b"example",
))?;

let bytes = builder.to_bytes()?;
let gsym = Gsym::parse(bytes)?;
assert_eq!(gsym.lookup(0x1014)?.unwrap().frames()[0].name, b"example");

Implementations§

Source§

impl GsymBuilder

Source

pub fn new() -> Self

Creates an empty builder using default options.

Source

pub fn with_options(options: BuilderOptions) -> Self

Creates an empty builder using options.

Source

pub const fn options(&self) -> &BuilderOptions

Returns the active builder options.

Source

pub const fn version(self, version: GsymVersion) -> Self

Selects the output GSYM version.

Defaults to GsymVersion::V1, which current tooling reads. Selecting GsymVersion::V2 lifts v1’s 4 GiB offset limits and 20-byte build-ID limit but needs LLVM 23 or newer on the reading side. Encoding reports v1 limit errors and does not change versions automatically.

Source

pub const fn endian(self, endian: Endian) -> Self

Selects the output byte order.

Source

pub const fn base_address(self, address: u64) -> Self

Sets the image base address.

Leave it unset to use the lowest function address, which is what a standalone file wants. Set it to the base address of the image the data came from, so lookups can use that image’s virtual addresses.

Source

pub fn build_id(self, build_id: impl Into<Vec<u8>>) -> Self

Sets the opaque build identifier stored in the GSYM header.

Source

pub const fn repair_zero_sized_functions(self, enabled: bool) -> Self

Enables or disables final zero-sized-function repair.

Source

pub const fn function_set(self, policy: FunctionSetPolicy) -> Self

Selects how functions sharing an address range are finalized.

Source

pub const fn merge_equal_address_functions(self, enabled: bool) -> Self

Enables or disables merged records for equal-address functions.

Source

pub const fn function_set_policy(&self) -> FunctionSetPolicy

Returns how equal-range functions will be finalized.

Source

pub fn executable_ranges( self, ranges: impl IntoIterator<Item = AddressRange>, ) -> Self

Replaces the executable ranges used for liveness and size repair.

Source

pub fn add_file(&mut self, file: FileEntry) -> Result<FileIndex>

Intern a source file and return its stable one-based index. Index zero is permanently reserved for the empty file.

Repeated calls with an equal entry return the same index without adding a row, so callers can intern per line row instead of maintaining their own map.

§Errors

Returns an error if the table exceeds the GSYM u32 index space.

use gsym::{FileEntry, GsymBuilder};

let mut builder = GsymBuilder::new();
let first = builder.add_file(FileEntry::new(b"/src", b"main.rs"))?;
let again = builder.add_file(FileEntry::new(b"/src", b"main.rs"))?;
assert_eq!(first, again);
assert_eq!(builder.files().len(), 2); // reserved entry plus main.rs
Source

pub fn add_function(&mut self, function: Function) -> Result<()>

Adds a validated function record.

Insertion order does not matter. Line rows must already be sorted within the function, and inline ranges must nest inside their parent.

§Errors

Returns an error for an empty name, invalid range, oversized function, or line outside the function range.

Source

pub fn files(&self) -> &[FileEntry]

Returns the interned file table, including reserved index zero.

Source

pub fn functions(&self) -> &[Function]

Returns functions in insertion order before writer finalization.

Source

pub fn write_to(self, output: impl Write) -> Result<()>

Encodes this builder into output.

§Errors

Returns an error when the model cannot be represented by the selected GSYM version or when writing fails.

Source

pub fn to_bytes(self) -> Result<Vec<u8>>

Encodes this builder into a byte vector.

§Errors

Returns an error when the model cannot be represented by the selected GSYM version.

Trait Implementations§

Source§

impl Debug for GsymBuilder

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GsymBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more