Skip to content

Wrong fallback logic for name() libbacktrace backend - #234

Merged
apolukhin merged 2 commits into
boostorg:developfrom
prbegd:fix/libbacktrace-frame-name
Sep 7, 2026
Merged

Wrong fallback logic for name() libbacktrace backend#234
apolukhin merged 2 commits into
boostorg:developfrom
prbegd:fix/libbacktrace-frame-name

Conversation

@prbegd

@prbegd prbegd commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #212

https://github.com/ianlancetaylor/libbacktrace/blob/master/backtrace.h#L180 shows that the return value of backtrace_pcinfo depends on the return value of the callback function. But the current libbacktrace_full_callback always returns 0:

inline int libbacktrace_full_callback(void *data, uintptr_t /*pc*/, const char *filename, int lineno, const char *function) {
pc_data& d = *static_cast<pc_data*>(data);
if (d.filename && filename) {
*d.filename = filename;
}
if (d.function && function) {
*d.function = function;
}
d.line = static_cast<std::size_t>(lineno);
return 0;
}

This leads the invocation of backtrace_pcinfo to always return 0, which makes the logical OR expression always evaluate the right hand side backtrace_syminfo:
::backtrace_pcinfo(
state,
reinterpret_cast<uintptr_t>(addr),
boost::stacktrace::detail::libbacktrace_full_callback,
boost::stacktrace::detail::libbacktrace_error_callback,
&data
)
||
::backtrace_syminfo(
state,
reinterpret_cast<uintptr_t>(addr),
boost::stacktrace::detail::libbacktrace_syminfo_callback,
boost::stacktrace::detail::libbacktrace_error_callback,
&data
);

Therefore, the result from backtrace_pcinfo is always overwritten by the result from backtrace_syminfo.

As a solution, libbacktrace_full_callback will now return 1 only when there's valid data.

@apolukhin
apolukhin merged commit 6e8707f into boostorg:develop Sep 7, 2026
44 checks passed
@apolukhin

Copy link
Copy Markdown
Member

Many thanks for the PR! Great job!

@prbegd
prbegd deleted the fix/libbacktrace-frame-name branch September 7, 2026 14:46
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 this pull request may close these issues.

name() returns the wrong result with libbacktrace backend and mingw

2 participants