Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Geal opened this issue Jul 17, 2020 · 2 comments
Closed

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

Geal opened this issue Jul 17, 2020 · 2 comments
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)]`

Comments

@Geal
Copy link
Contributor

Geal commented Jul 17, 2020

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 :)

@jonas-schievink jonas-schievink added C-feature-request Category: A feature request, i.e: not implemented / a PR. F-track_caller `#![feature(track_caller)]` A-allocators Area: Custom and system allocators labels Jul 17, 2020
@anp
Copy link
Member

anp commented Jul 29, 2020

This would be cool but I'm not sure it can be supported backwards-compatibly (see #74763 also). AIUI, it would require adding the attribute to symbols that are exposed as externs which would be a breaking change.

@Geal
Copy link
Contributor Author

Geal commented Aug 16, 2020

I see, it was a fun thought only :)

@Geal Geal closed this as completed Aug 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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)]`
Projects
None yet
Development

No branches or pull requests

3 participants