Skip to content

adding #[track_caller] to #[global_allocator] to trace allocation source #74433

Closed
@Geal

Description

@Geal

Hello,
I am using a custom allocator to trace allocations and deallocations when debugging code. I was wondering if adding #[track_caller] to the GlobalAlloc::alloc and GlobalAlloc::dealloc methods could give me the origin of allocations (even if it ends up in libstd), but unfortunately, it only gives me the position of the #[global_allocator] attribute.

As an alternative, I am trying to obtain it with the backtrace crate, but apparently I cannot resolve the symbols for a stackframe (I suspect it would allocate), so I would need to store the instruction address at runtime, and post process the result with gimli.

Making #[track_caller] usable from a custom allocator would simplify a lot that use case, since everything returned by panic::Location::caller() is 'static, so there are no allocations.

So I'm not sure if this request fits the use case of #[track_caller] but I'm probably not the only one wanting a nice way to track allocations :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-allocatorsArea: Custom and system allocatorsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.F-track_caller`#![feature(track_caller)]`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions