Skip to content
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

Frame callback support #10

Open
denravonska opened this issue May 23, 2023 · 0 comments · May be fixed by #11
Open

Frame callback support #10

denravonska opened this issue May 23, 2023 · 0 comments · May be fixed by #11

Comments

@denravonska
Copy link

I have an application where I want to extract traces on crashes, but I already have a backtrace data structure on the application layer. With the current way backtrace works I'd have to allocate a second set of array, populate it and then copy it to my application's structure.

I'm thinking about extending the library so it works similarly to _Unwind_Backtrace where you provide a callback that handles the copying (on a frame by frame basis) and decides when to stop. Essentially, in addition to the current API:

int backtrace_unwind_from_frame(backtrace_t *buffer, int size, backtrace_frame_t frame);
int backtrace_unwind(backtrace_t *buffer, int size)

two new functions would be introduced:

enum
{
	UNWIND_CONTINUE,
	UNWIND_STOP
} unwind_code_t

typedef unwind_code_t *unwind_trace_fn(backtrace *trace, void *context);
int backtrace_unwind_from_frame(unwind_trace_fn callback, backtrace_frame_t frame);
int backtrace_unwind(unwind_trace_fn callback)

Is that something you'd need/want upstream? If so I can do it on Github and make a proper PR.

denravonska added a commit to denravonska/backtrace that referenced this issue May 23, 2023
In addition to the previous API where the caller provided a buffer and a size,
it's now possible to instead proviced a callback and a context. This allows
the caller to use their own data structures without having to allocate an
additional set of objects to pass to backtrace.

The old API is still intact but has internally been rewritten to also use the
callback mechanisms. Note that this does increase the stack strain a bit as
each frame has to go through the callback.

Additionally, this also adds support for traversing a frame provided by the
user, with or without callbacks).

Closes red-rocket-computing#10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant