Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

2 fixes for rt.backtrace.dwarf #2151

Merged
merged 1 commit into from Apr 15, 2019
Merged

2 fixes for rt.backtrace.dwarf #2151

merged 1 commit into from Apr 15, 2019

Conversation

kinke
Copy link
Contributor

@kinke kinke commented Mar 25, 2018

No description provided.

{
buffer[0 .. 5] = "??:? ";
bufferLength = 5;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix 1:

addressBuffer[] = "??:? \0";

=> object.Error@(0): Array lengths don't match for copy https://run.dlang.io/is/4RQZWh

Copy link
Member

Choose a reason for hiding this comment

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

Any chance we can add a test for this to prevent future regressions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's pretty bad with -release, causing a segfault as long as the destination buffer is sufficiently large: https://run.dlang.io/is/NEqZOB. Without -release an exception is thrown during stacktrace generation, which is also pretty bad.

The latter is how I stumbled on this. LLVM 6.0 led to DWARF v4 debuginfos, rt.backtrace.dwarf doesn't support that version, so no file/line infos => "??:? \0" + exception (debug druntime only; release druntime compiled with -release happily reads beyond the string constant, causing no segfault on x86 apparently). The exception with debug-druntime is swallowed in my test case, it only manifests itself in an incomplete stack trace (single entry).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wilzbach: There's no debug druntime (i.e., compiled with enabled bounds checks) available for CI, right? Then it's untestable.

static if (size_t.sizeof == 8)
appendToBuffer("[0x%llx]", callstack[i]);
else
appendToBuffer("[0x%x]", callstack[i]);
Copy link
Contributor Author

@kinke kinke Mar 25, 2018

Choose a reason for hiding this comment

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

Fix 2: don't restrict to lower 32 bits of address on 64-bit platforms, e.g., now ??:? __libc_start_main [0x7f7bb141182f].

@JinShil
Copy link
Contributor

JinShil commented Mar 25, 2018

Does this fix https://issues.dlang.org/show_bug.cgi?id=18068?

@kinke
Copy link
Contributor Author

kinke commented Mar 25, 2018

Nope, but I discovered bug no. 1 because of missing file/line infos too, or rather because the code here doesn't handle Dwarf v4+ debuginfos.

@dlang-bot
Copy link
Contributor

dlang-bot commented Mar 25, 2018

Thanks for your pull request and interest in making D better, @kinke! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + druntime#2151"

@kinke kinke reopened this May 1, 2018
@dlang-bot dlang-bot added the Bug Fix Include reference to corresponding bugzilla issue label May 1, 2018
@kinke
Copy link
Contributor Author

kinke commented May 1, 2018

I extended the previous trivial fix by a revised version of rt.backtrace.dwarf, tackling:

  • Support for DWARF v4.
  • Support for 64-bit DWARF.
  • Alignment issues on non-x86 architectures (DWARF data is packed).
  • Issue #18068; DSO-relative DWARF addresses vs. absolute addresses returned by backtrace().

Tests are missing, I'm unsure how to tackle that in a robust fashion (for DMD, I'd know how for LDC ;)).

@kinke kinke changed the title Fix rt.backtrace.dwarf Revise & fix rt.backtrace.dwarf (DWARF v4, 64-bit DWARF, DSO-relative addresses) May 1, 2018
kinke added a commit to ldc-developers/druntime that referenced this pull request Jun 18, 2018
kinke added a commit to ldc-developers/druntime that referenced this pull request Jun 18, 2018
@wilzbach
Copy link
Member

wilzbach commented Jun 28, 2018

With #2230 merged at least the getMemoryRegion part should become obsolete.

@kinke
Copy link
Contributor Author

kinke commented Jun 28, 2018

Rebased and obsolete 18068 fix removed. FWIW, the first commit is part of LDC 1.9, the second in 1.10.

@kinke kinke changed the title Revise & fix rt.backtrace.dwarf (DWARF v4, 64-bit DWARF, DSO-relative addresses) Revise & fix rt.backtrace.dwarf (DWARF v4, 64-bit DWARF) Jul 11, 2018
Fix 1: mismatching array lengths for a copy (the `??:? \0` piece).
Luckily, these bounds checks are disabled in non-debug druntime, so that
people haven't seen this bug (in backtrace-printing code!) that often.

Fix 2: print the full 64-bit address on 64-bit systems, not just the 32
lower bits. That's one part of Issue 19653.
@kinke kinke changed the title Revise & fix rt.backtrace.dwarf (DWARF v4, 64-bit DWARF) 2 fixes for rt.backtrace.dwarf Apr 14, 2019
@kinke
Copy link
Contributor Author

kinke commented Apr 14, 2019

I restricted this to the first trivial fixes again and moved the 2nd commit to #2559. @thewilsonator: Please push.

@thewilsonator thewilsonator merged commit 50d8d09 into dlang:master Apr 15, 2019
@kinke kinke deleted the bt_dwarf branch April 15, 2019 21:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Fix Include reference to corresponding bugzilla issue
Projects
None yet
5 participants