adding #[track_caller] to #[global_allocator] to trace allocation source #74433
Labels
A-allocators
Area: Custom and system allocators
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
F-track_caller
`#![feature(track_caller)]`
Hello,
I am using a custom allocator to trace allocations and deallocations when debugging code. I was wondering if adding
#[track_caller]
to theGlobalAlloc::alloc
andGlobalAlloc::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 bypanic::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 :)The text was updated successfully, but these errors were encountered: