swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.74k stars 1.34k forks source link

[SR-11008] lldb debug error when compiling project with SPM on Ubuntu 16.04 #4857

Open swift-ci opened 5 years ago

swift-ci commented 5 years ago
Previous ID SR-11008
Radar rdar://problem/52118932
Original Reporter dddong (JIRA User)
Type Bug
Environment OS: Ubuntu 16.04 64bit Swift version 5.0.1 (swift-5.0.1-RELEASE) Target: x86_64-unknown-linux-gnu
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Package Manager | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 7776a2f54aef3e1e7d4cfa79901fb415

Issue Description:

When debugging a swift binary with lldb, I got the following error when using `p` or `expression` command

(lldb) p varMap
error: warning: failed to get module 'Fuzzilli' from AST contexterror: in auto-import:
failed to get module 'Fuzzilli' from AST context

And there is an issue related to this problem which was fired before, https://bugs.swift.org/browse/SR-85. `-g` option has been included in the compile command, I don't know why this problem happens again.

output of `swift build -c debug -v`

➜ fuzzilli git:(master) ✗ swift build -c debug -v 
lsb_release -r 
which clang 
/home/dddong/swift/swift-5.0.1-RELEASE-ubuntu16.04/usr/bin/swiftc -module-name Fuzzilli -incremental -emit-dependencies -emit-module -emit-module-path /home/dddong/workspace/fuzzilli/.build/x86_64-unknown-linux/debug/Fuzzilli.swiftmodule -output-file-map /home/dddong/workspace/fuzzilli/.build/x86_64-unknown-linux/debug/Fuzzilli.build/output-file-map.json -parse-as-library -c /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Configuration.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Core/CodeGenerators.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Core/Component.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Core/Corpus.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Core/Events.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Core/FuzzerCore.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Core/JavaScriptEnvironment.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Core/Logging.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Core/ProgramBuilder.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Core/Timers.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Evaluation/ProgramAspects.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Evaluation/ProgramCoverageEvaluator.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Evaluation/ProgramEvaluator.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Execution/Execution.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Execution/Forkserver.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Execution/REPRL.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Execution/ScriptRunner.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/FuzzIL/Analyzer.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/FuzzIL/Blocks.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/FuzzIL/Instruction.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/FuzzIL/Operations.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/FuzzIL/Program.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/FuzzIL/TypeSystem.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/FuzzIL/Variable.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Fuzzer.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Lifting/Expression.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Lifting/InliningPolicy.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Lifting/JSExpressions.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Lifting/JavaScriptLifter.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Lifting/Lifter.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Lifting/ScriptWriter.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Minimization/BlockReducer.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Minimization/CallArgumentReducer.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Minimization/GenericInstructionReducer.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Minimization/InliningReducer.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Minimization/Minimizer.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Minimization/Reducer.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Minimization/ReplaceReducer.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Modules/Module.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Modules/NetworkSync.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Modules/Statistics.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Modules/Storage.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Modules/ThreadSync.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Mutators/BaseInstructionMutator.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Mutators/CombineMutator.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Mutators/ConcatMutator.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Mutators/GrowMutator.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Mutators/InputMutator.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Mutators/InsertionMutator.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Mutators/JITStressMutator.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Mutators/Mutator.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Mutators/OperationMutator.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Mutators/SpliceMutator.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Util/CInterop.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Util/Misc.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Util/MovingAverage.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Util/Random.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Util/VariableMap.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Util/VariableSet.swift /home/dddong/workspace/fuzzilli/Sources/Fuzzilli/Util/WeightedList.swift -I /home/dddong/workspace/fuzzilli/.build/x86_64-unknown-linux/debug -target x86_64-unknown-linux -swift-version 5 -enable-batch-mode -index-store-path /home/dddong/workspace/fuzzilli/.build/x86_64-unknown-linux/debug/index/store -sdk / -Onone -g -enable-testing -j4 -DSWIFT_PACKAGE -DDEBUG -Xcc -fmodule-map-file=/home/dddong/workspace/fuzzilli/.build/x86_64-unknown-linux/debug/libcoverage.build/module.modulemap -I /home/dddong/workspace/fuzzilli/Sources/libcoverage/include -Xcc -fmodule-map-file=/home/dddong/workspace/fuzzilli/.build/x86_64-unknown-linux/debug/libreprl.build/module.modulemap -I /home/dddong/workspace/fuzzilli/Sources/libreprl/include -Xcc -fmodule-map-file=/home/dddong/workspace/fuzzilli/.build/x86_64-unknown-linux/debug/libsocket.build/module.modulemap -I /home/dddong/workspace/fuzzilli/Sources/libsocket/include -Xcc -fmodule-map-file=/home/dddong/workspace/fuzzilli/.build/x86_64-unknown-linux/debug/libforkserver.build/module.modulemap -I /home/dddong/workspace/fuzzilli/Sources/libforkserver/include -module-cache-path /home/dddong/workspace/fuzzilli/.build/x86_64-unknown-linux/debug/ModuleCache -Xfrontend -color-diagnostics 
/home/dddong/swift/swift-5.0.1-RELEASE-ubuntu16.04/usr/bin/swiftc -sdk / -g -L /home/dddong/workspace/fuzzilli/.build/x86_64-unknown-linux/debug -o /home/dddong/workspace/fuzzilli/.build/x86_64-unknown-linux/debug/FuzzilliCli -module-name FuzzilliCli -emit-executable -Xlinker '-rpath=$ORIGIN' @/home/dddong/workspace/fuzzilli/.build/x86_64-unknown-linux/debug/FuzzilliCli.product/Objects.LinkFileList -lrt
belkadan commented 5 years ago

cc @aciidb0mb3r, @adrian-prantl

adrian-prantl commented 5 years ago

@aciidb0mb3r This looks like the bug that swiftpm doesn't perform the -modulerwrap action and thus isn't linking in the debug info. Is there a JIRA ticket for that?

aciidgh commented 5 years ago

Not sure what is modulerwrap, do you mean this https://bugs.swift.org/browse/SR-3280 ?

adrian-prantl commented 5 years ago

That seems to refer to the same problem although it isn't very specific.

The correct way to build a debuggable program on Darwin is:

$ swiftc -g -c a.swift ...
produces a.o, a.swiftmodule
$ ld a.o -o a --add_ast_apth /path/to/a.swiftmodule
$ dsymutil a
this is optional

On Linux it is:
$ swiftc -g -c a.swift ...
produces a.o, a.swiftmodule
$ swiftc -modulewrap a.swiftmodule -o a.swiftmodule.o
wraps the swiftmodule in an ELF object
$ ld a.o a.swiftmodule.o -o a

adrian-prantl commented 5 years ago

In radar-land the bug is rdar://problem/46509520.

aciidgh commented 5 years ago

Thanks for the examples. That bug is tracking the work for Darwin. I'll use this bug for Linux.

swift-ci commented 5 years ago

Comment by JD Xie (JIRA)

So is there a work around for this now?

adrian-prantl commented 5 years ago

Yes, compiling manually / with a Makefile that ensures that the wrapped swiftmodule is linked with the binary as outlined by my example above.