Skip to content

Improve crash backtraces for non-reproducible faults#2880

Open
DL6ER wants to merge 1 commit into
developmentfrom
tweak/backtrace2
Open

Improve crash backtraces for non-reproducible faults#2880
DL6ER wants to merge 1 commit into
developmentfrom
tweak/backtrace2

Conversation

@DL6ER
Copy link
Copy Markdown
Member

@DL6ER DL6ER commented May 5, 2026

What does this implement/fix?

Prefer signal-context frame walking in crash handlers, with _Unwind_Backtrace fallback. Add mapping safety checks and log the unwind source so field crash reports show whether frames came from signal context or fallback.


Related issue or feature (if applicable): N/A

Pull request in docs with documentation (if applicable): N/A


By submitting this pull request, I confirm the following:

  1. I have read and understood the contributors guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented my proposed changes within the code.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the EUPL 1.2 license
  5. I have squashed any insignificant commits. (git rebase)

Checklist:

  • The code change is tested and works locally.
  • I based my code and PRs against the repositories development branch.
  • I signed off all commits. Pi-hole enforces the DCO for all contributions
  • I signed all my commits. Pi-hole requires signatures to verify authorship
  • I have read the above and my PR is ready for review.

…acktrace fallback. Add mapping safety checks and log the unwind source so field crash reports show whether frames came from signal context or fallback.

Signed-off-by: Dominik <dl6er@dl6er.de>
Copilot AI review requested due to automatic review settings May 5, 2026 17:49
@DL6ER DL6ER requested a review from a team as a code owner May 5, 2026 17:49
@DL6ER DL6ER added the Debugging label May 5, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves crash diagnostics in src/signals.c by preferring backtrace collection from the interrupted signal context (frame-pointer walk) and falling back to _Unwind_Backtrace when that fails. It also adds mapping-safety checks for the signal-context unwinder and logs which unwinding source was used so crash reports are easier to interpret.

Changes:

  • Add signal-context-based frame collection (x86_64/aarch64) with _Unwind_Backtrace fallback and record the unwind source in logs.
  • Add /proc/self/maps-based readability/executability checks to reduce unsafe memory dereferences during frame-pointer walking.
  • Refine frame resolution result categories (FRAME_UNRESOLVABLE vs FRAME_UNRESOLVED) and adjust backtrace logging accordingly.
Comments suppressed due to low confidence (1)

src/signals.c:317

  • The log_frame() doc comment describing return values is now out of sync with the frame_result enum: it mentions only FRAME_UNRESOLVED/FRAME_SKIPPED, but the function can also return FRAME_UNRESOLVABLE. Please update the comment to reflect the new enum semantics so future changes don’t mis-handle the result codes.
// Log one backtrace frame as a single line.
// Resolved:   "  #N  func_name                    src/file.c:line"
// Unresolved: "  #N  0xADDRESS  (reason)"
// Returns FRAME_RESOLVED when addr2line produced a result, FRAME_UNRESOLVED
// when addr2line was tried but failed, FRAME_SKIPPED when it was not attempted.
static enum frame_result log_frame(const int idx, const void *addr, const void *rel_addr)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/signals.c
Comment on lines +132 to +161
// True when [addr, addr+bytes) is inside a readable mapping in /proc/self/maps.
static bool is_readable_range(const uintptr_t addr, const size_t bytes)
{
if(bytes == 0u)
return false;

FILE *maps = fopen("/proc/self/maps", "r");
if(maps == NULL)
return false;

bool readable = false;
char line[512];
while(fgets(line, sizeof(line), maps) != NULL)
{
uintptr_t start = 0, end = 0;
char perms[8] = { 0 };
const int n = sscanf(line, "%" SCNxPTR "-%" SCNxPTR " %7s %*s %*s %*s",
&start, &end, perms);
if(n != 3 || perms[0] != 'r')
continue;

if(addr >= start && addr < end && (size_t)(end - addr) >= bytes)
{
readable = true;
break;
}
}

fclose(maps);
return readable;
Comment thread src/signals.c
Comment on lines +164 to +191
// True when addr points into an executable mapping.
static bool is_executable_address(const uintptr_t addr)
{
FILE *maps = fopen("/proc/self/maps", "r");
if(maps == NULL)
return false;

bool executable = false;
char line[512];
while(fgets(line, sizeof(line), maps) != NULL)
{
uintptr_t start = 0, end = 0;
char perms[8] = { 0 };
const int n = sscanf(line, "%" SCNxPTR "-%" SCNxPTR " %7s %*s %*s %*s",
&start, &end, perms);
if(n != 3 || perms[2] != 'x')
continue;

if(addr >= start && addr < end)
{
executable = true;
break;
}
}

fclose(maps);
return executable;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants