Skip to content

[SR-755] Tool for re-symbolicating fatal stacktraces on Linux. #4479

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

Merged

Conversation

gmilos
Copy link
Contributor

@gmilos gmilos commented Aug 24, 2016

What's in this pull request?

On Linux stack traces are full of symbols. This provides a tool to re-symbolicate such stack trace.

The cause is difference in behaviour of dladdr between Linux & Darwin. See SR.

Resolved bug number: (SR-755)


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

A smoke test on macOS does the following:

  1. Builds the compiler incrementally.
  2. Builds the standard library only for macOS. Simulator standard libraries and
    device standard libraries are not built.
  3. lldb is not built.
  4. The test and validation-test targets are run only for macOS. The optimized
    version of these tests are not run.

A smoke test on Linux does the following:

  1. Builds the compiler incrementally.
  2. Builds the standard library incrementally.
  3. lldb is built incrementally.
  4. The swift test and validation-test targets are run. The optimized version of these
    tests are not run.
  5. lldb is tested.

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

@DougGregor
Copy link
Member

@swift-ci please smoke test

@gmilos
Copy link
Contributor Author

gmilos commented Aug 26, 2016

The failure on Linux was a timeout, doesn't seem to be related to the change I made. Trying to kick off another round of ci.

@gmilos
Copy link
Contributor Author

gmilos commented Aug 26, 2016

@swift-ci please smoke test

@gmilos
Copy link
Contributor Author

gmilos commented Aug 26, 2016

@swift-ci Please test Linux platform

@DougGregor
Copy link
Member

@swift-ci please smoke test Linux

@@ -72,7 +72,6 @@ static bool getSymbolNameAddr(llvm::StringRef libraryName, Dl_info dlinfo,
// If the address is unavailable, just use <unavailable> as the symbol
Copy link
Contributor

@modocache modocache Aug 26, 2016

Choose a reason for hiding this comment

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

nit-pick: Since you remove the "" string below, I think this comment here might no longer accurate. Could you update this comment as well?

@modocache
Copy link
Contributor

You'll want to run the Python linter on this new code, which contains a few violations. There's a handy utility to run the linter, just run utils/python-lint.


dynlibs = {}
def process_ldd(lddoutput):
global dynlibs
Copy link
Contributor

@modocache modocache Aug 27, 2016

Choose a reason for hiding this comment

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

This line, global dynlibs, is not needed. Since you define dynlibs in a global scope above, you are able to reference it throughout this file. This is why you're able to reference it in the process_stack function below.

Also, I believe the Python linter will raise this issue, but I think that typically Python globals tend to be in UPPER_SNAKE_CASE.

@gmilos gmilos force-pushed the SR-755-linux-fatal-stacktrace-symbolication branch 2 times, most recently from d252514 to 84cc469 Compare August 31, 2016 18:37
@gmilos
Copy link
Contributor Author

gmilos commented Aug 31, 2016

@modocache re utils/python-lint. I run it + fixed up all the issues it found. Thanks for the suggestion.

@gmilos
Copy link
Contributor Author

gmilos commented Sep 1, 2016

@DougGregor could you kick off another round of tests? I've addressed all the comments, so hopefully this is ready to be merged, pending successful tests.



def main():
global BINARY
Copy link
Contributor

@modocache modocache Sep 1, 2016

Choose a reason for hiding this comment

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

Instead of storing args.binary below into this global BINARY variable, I would suggest passing binary as an argument into the create_lldb_target() and process_stack() functions. I think doing so limits the scope where BINARY is used and makes the control flow of the program easier to understand.

@gmilos
Copy link
Contributor Author

gmilos commented Sep 1, 2016

@modocache All comments addressed. @DougGregor ready for CI again.

if (foundSymbol) {
static const char *backtraceEntryFormat = "%-4u %-34s 0x%0.16lx %s + %td\n";
fprintf(stderr, backtraceEntryFormat, index, libraryName.data(), symbolAddr,
symbolName.c_str(), ptrdiff_t(uintptr_t(framePC) - symbolAddr));
Copy link
Contributor

Choose a reason for hiding this comment

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

In C++ code, the line after the linebreak should be aligned with the opening paren. (Here, symbolName should start in the same column as stderr.)

@gribozavr
Copy link
Contributor

The code changes generally LGTM, but it would be good to add some tests.

@gribozavr
Copy link
Contributor

@swift-ci Please smoke test

@gribozavr
Copy link
Contributor

@swift-ci Please Python lint

@gribozavr
Copy link
Contributor

@swift-ci Please smoke test

@gribozavr
Copy link
Contributor

@swift-ci Please Python lint

@rintaro
Copy link
Member

rintaro commented Sep 14, 2016

@swift-ci Please smoke test

@modocache
Copy link
Contributor

The tests appear to have passed, but in reality the new test was never run. From the logs:

12:04:04 UNSUPPORTED: Swift(linux-x86_64) :: Runtime/linux-fatal-backtrace.swift (266 of 8611)

@gmilos
Copy link
Contributor Author

gmilos commented Sep 14, 2016

@modocache @rintaro There was a bug working out if lldb PRODUCT is enabled. This is now fixed. Could you please kick off Smoke Tests (where I expect the test to be run) and regular tests (where I don't). I have now tested this locally (I finally understand enough about how the presets work to reproduce, hopefully equivalent, test run locally).

@gmilos
Copy link
Contributor Author

gmilos commented Sep 15, 2016

@modocache @rintaro Could either one of you kick off Smoke Tests + regular Tests? (I don't have the rights to do that :( ). I've just resolved a superficial merge conflict.

@gmilos
Copy link
Contributor Author

gmilos commented Sep 16, 2016

@DougGregor @gribozavr Any chance either one of you could kick off Smoke + regular tests please?

@gribozavr
Copy link
Contributor

@swift-ci Please smoke test

@gribozavr
Copy link
Contributor

@swift-ci Please test

@gribozavr
Copy link
Contributor

@swift-ci Please smoke test

@gribozavr
Copy link
Contributor

@swift-ci Please test

@DougGregor
Copy link
Member

Tests pass, but now we have a conflict. Argh! @gmilos , can you clear up the conflict so we can merge?

@gmilos
Copy link
Contributor Author

gmilos commented Sep 20, 2016

@DougGregor yep, simple conflict in .pep8 now fixed (hit that before too).

Another round of tests would be very useful. Could you kick them off for me please? Alternatively, if you added me to the Apple group, I could make sure the tests are all green before asking for review/merge.

@DougGregor
Copy link
Member

@swift-ci please smoke test and merge

@DougGregor
Copy link
Member

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 74ff4da
Test requested by - @DougGregor

@gmilos
Copy link
Contributor Author

gmilos commented Sep 20, 2016

Build failure is unrelated to the patch:

15:56:37 FAILED: /usr/bin/clang++   -DCLANG_ENABLE_ARCMT -DCLANG_ENABLE_OBJC_REWRITER -DCLANG_ENABLE_STATIC_ANALYZER -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/clang/lib/CodeGen -I/home/buildnode/jenkins/workspace/swift-PR-Linux/branch-master/llvm/tools/clang/lib/CodeGen -I/home/buildnode/jenkins/workspace/swift-PR-Linux/branch-master/llvm/tools/clang/include -Itools/clang/include -Iinclude -I/home/buildnode/jenkins/workspace/swift-PR-Linux/branch-master/llvm/include -fno-stack-protector -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Werror=date-time -std=c++11 -fcolor-diagnostics -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3    -UNDEBUG  -fno-exceptions -fno-rtti -MMD -MT tools/clang/lib/CodeGen/CMakeFiles/clangCodeGen.dir/CGDebugInfo.cpp.o -MF tools/clang/lib/CodeGen/CMakeFiles/clangCodeGen.dir/CGDebugInfo.cpp.o.d -o tools/clang/lib/CodeGen/CMakeFiles/clangCodeGen.dir/CGDebugInfo.cpp.o -c /home/buildnode/jenkins/workspace/swift-PR-Linux/branch-master/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp
15:56:37 
/home/buildnode/jenkins/workspace/swift-PR-Linux/branch-master/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp:3572:64: error: cannot initialize a parameter of type 'llvm::DIExpression *' with an lvalue of type 'llvm::GlobalVariable *'
15:56:37                                        Var->hasLocalLinkage(), Var, nullptr);

@gmilos
Copy link
Contributor Author

gmilos commented Sep 20, 2016

Same failure is present here:
https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-15_10/7724/consoleFull#-1191272582ee1a197b-acac-4b17-83cf-a53b95139a76
(that shows the offending set of changes too).

@DougGregor would you mind kicking of another set of tests on this PR (both smoke and regular) once the above llvm issue is fixed?

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 74ff4da
Test requested by - @DougGregor

@DougGregor
Copy link
Member

@swift-ci please smoke test

@DougGregor
Copy link
Member

@DougGregor DougGregor merged commit f1a4dd7 into swiftlang:master Sep 21, 2016
jmikola added a commit to mongodb/mongo-swift-driver that referenced this pull request Jul 23, 2018
Document how symbolicate-linux-fatal tool from swiftlang/swift#4479 can be used to add symbols to backtraces on Linux
jmikola added a commit to mongodb/mongo-swift-driver that referenced this pull request Jul 24, 2018
Document how symbolicate-linux-fatal tool from swiftlang/swift#4479 can be used to add symbols to backtraces on Linux
kateinoigakukun added a commit that referenced this pull request Aug 31, 2022
[pull] swiftwasm from main
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.

9 participants