Skip to content

Wrong fallback logic for name() libbacktrace backend#224

Open
prbegd wants to merge 5 commits into
boostorg:developfrom
prbegd:develop
Open

Wrong fallback logic for name() libbacktrace backend#224
prbegd wants to merge 5 commits into
boostorg:developfrom
prbegd:develop

Conversation

@prbegd

@prbegd prbegd commented Jan 30, 2026

Copy link
Copy Markdown

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.

@prbegd prbegd changed the title Fix name() not working in libbacktrace_impls.hpp on mingw-w64 Wrong fallback logic for name() libbacktrace backend Jul 11, 2026
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

1 participant