forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 349
🍒 Backport lldb-dap changes before JSONTransport change #11598
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…lvm#148738) # Lldb-server crash We have seen stacks like the following in lldb-server core dumps: ``` [ "__GI___pthread_kill at pthread_kill.c:46", "__GI_raise at raise.c:26", "__GI_abort at abort.c:100", "__assert_fail_base at assert.c:92", "__GI___assert_fail at assert.c:101", "lldb_private::NativeProcessProtocol::RemoveSoftwareBreakpoint(unsigned long) at /redacted/lldb-server:0" ] ``` # Hypothesis of root cause In `NativeProcessProtocol::RemoveSoftwareBreakpoint()` ([code](https://github.com/llvm/llvm-project/blob/19b2dd9d798c124406b0124a1b8debb711675281/lldb/source/Host/common/NativeProcessProtocol.cpp#L359-L423)), a `ref_count` is asserted and reduced. If it becomes zero, the code first go through a series of memory reads and writes to remove the breakpoint trap opcode and to restore the original process code, then, if everything goes fine, removes the entry from the map `m_software_breakpoints` at the end of the function. However, if any of the validations for the above reads and writes goes wrong, the code returns an error early, skipping the removal of the entry. This leaves the entry behind with a `ref_count` of zero. The next call to `NativeProcessProtocol::RemoveSoftwareBreakpoint()` for the same breakpoint[*] would violate the assertion about `ref_count > 0` ([here](https://github.com/llvm/llvm-project/blob/19b2dd9d798c124406b0124a1b8debb711675281/lldb/source/Host/common/NativeProcessProtocol.cpp#L365)), which would cause a crash. [*] We haven't found a *regular* way to repro such a next call in lldb or lldb-dap. This is because both of them remove the breakpoint from their internal list when they get any response from the lldb-server (OK or error). Asking the client to delete the breakpoint a second time doesn't trigger the client to send the `$z` gdb packet to lldb-server. We are able to trigger the crash by sending the `$z` packet directly, see "Manual test" below. # Fix Lift the removal of the map entry to be immediately after the decrement of `ref_count`, before the early returns. This ensures that the asserted case will never happen. The validation errors can still happen, and whether they happen or not, the breakpoint has been removed from the perspective of the lldb-server (same as that of lldb and lldb-dap). # Manual test & unit test See PR. (cherry picked from commit a13712e)
This typo was introduced in PR llvm#140331. This branch will never get executed. We also set the `disconnecting = true` in the `DAP::Disconnect()` so I am not sure if we need it in both places. (cherry picked from commit de453e8)
…lvm#149133) Currently, the "stopped" event returned when a breakpoint is hit will always return only the ID of first breakpoint returned from `GetStopReasonDataAtIndex`. This is slightly different from the behaviour in `lldb`, where multiple breakpoints can exist at a single instruction address and all are returned as part of the stop reason when that address is hit. This patch allows all multiple hit breakpoints to be returned in the "stopped" event, both in the hitBreakpointIds field and in the description, using the same formatting as lldb e.g. "breakpoint 1.1 2.1". I'm not aware of any effect this will have on debugger plugins; as far as I can tell, it makes no difference within the VS Code UI - this just fixes a minor issue encountered while writing an `lldb-dap` backend for Dexter. (cherry picked from commit d544005)
This PR resolves llvm#149316 --------- Co-authored-by: Ebuka Ezike <yerimyah1@gmail.com> (cherry picked from commit 0b9470b)
Generated by running the formatter: ``` royshi-mac-home ~/public_llvm/llvm-project/lldb/tools/lldb-dap % yarn format yarn run v1.22.22 warning package.json: License should be a valid SPDX license expression warning lldb-dap@0.2.15: The engine "vscode" appears to be invalid. $ npx prettier './src-ts/' --write src-ts/debug-adapter-factory.ts 65ms src-ts/debug-configuration-provider.ts 17ms (unchanged) src-ts/debug-session-tracker.ts 11ms (unchanged) src-ts/disposable-context.ts 2ms (unchanged) src-ts/extension.ts 3ms (unchanged) src-ts/lldb-dap-server.ts 7ms src-ts/ui/error-with-notification.ts 4ms (unchanged) src-ts/ui/modules-data-provider.ts 5ms (unchanged) src-ts/ui/show-error-message.ts 6ms (unchanged) src-ts/uri-launch-handler.ts 5ms (unchanged) ✨ Done in 0.99s. ``` (cherry picked from commit cd83444)
- ~Add `winston` dependency (MIT license) to handle logging setup~ - Have an `LogOutputChannel` to log user facing information, errors, warnings - Write a debug session logs under the provided `logUri` to capture further diagnostics when the `lldb-dap.captureSessionLogs` setting is enabled. *Note* the `lldb-dap.log-path` setting takes precedence when set Issue: llvm#146880 --------- Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com> (cherry picked from commit ae7be39)
(cherry picked from commit dd0bb2c)
# Problem `yarn package` cannot be run twice in a row - the second time will error out: > Error: ENOENT: no such file or directory, stat '<path>/llvm-project/lldb/tools/lldb-dap/out/lldb-dap.vsix' This error is also weird, because the file actually exists. See the end of this [full output](https://gist.github.com/royitaqi/f3f4838ed30d7ade846f53f0fb7d68f4). # Fix Delete the `lldb-dap.vsix` file at the start of each run. See consecutive runs [being successful](https://gist.github.com/royitaqi/9609181b4fe6a8a4e71880c36cd0c7c9). (cherry picked from commit 4882874)
…lvm#151973) I discovered this building the lldb test suite with `-mthumb` set, so that all test programs are purely Arm Thumb code. When C++ expressions did a function lookup, they took a different path from C programs. That path happened to land on the line that I've changed. Where we try to look something up as a function, but don't then resolve the address as if it's a callable. With Thumb, if you do the non-callable lookup, the bottom bit won't be set. This means when lldb's expression wrapper function branches into the found function, it'll be in Arm mode trying to execute Thumb code. Thumb is the only instance where you'd notice this. Aside from maybe MicroMIPS or MIPS16 perhaps but I expect that there are 0 users of that and lldb. I have added a new test case that will simulate this situation in "normal" Arm builds so that it will get run on Linaro's buildbot. This change also fixes the following existing tests when `-mthumb` is used: ``` lldb-api :: commands/expression/anonymous-struct/TestCallUserAnonTypedef.py lldb-api :: commands/expression/argument_passing_restrictions/TestArgumentPassingRestrictions.py lldb-api :: commands/expression/call-function/TestCallStopAndContinue.py lldb-api :: commands/expression/call-function/TestCallUserDefinedFunction.py lldb-api :: commands/expression/char/TestExprsChar.py lldb-api :: commands/expression/class_template_specialization_empty_pack/TestClassTemplateSpecializationParametersHandling.py lldb-api :: commands/expression/context-object/TestContextObject.py lldb-api :: commands/expression/formatters/TestFormatters.py lldb-api :: commands/expression/import_base_class_when_class_has_derived_member/TestImportBaseClassWhenClassHasDerivedMember.py lldb-api :: commands/expression/inline-namespace/TestInlineNamespace.py lldb-api :: commands/expression/namespace-alias/TestInlineNamespaceAlias.py lldb-api :: commands/expression/no-deadlock/TestExprDoesntBlock.py lldb-api :: commands/expression/pr35310/TestExprsBug35310.py lldb-api :: commands/expression/static-initializers/TestStaticInitializers.py lldb-api :: commands/expression/test/TestExprs.py lldb-api :: commands/expression/timeout/TestCallWithTimeout.py lldb-api :: commands/expression/top-level/TestTopLevelExprs.py lldb-api :: commands/expression/unwind_expression/TestUnwindExpression.py lldb-api :: commands/expression/xvalue/TestXValuePrinting.py lldb-api :: functionalities/thread/main_thread_exit/TestMainThreadExit.py lldb-api :: lang/cpp/call-function/TestCallCPPFunction.py lldb-api :: lang/cpp/chained-calls/TestCppChainedCalls.py lldb-api :: lang/cpp/class-template-parameter-pack/TestClassTemplateParameterPack.py lldb-api :: lang/cpp/constructors/TestCppConstructors.py lldb-api :: lang/cpp/function-qualifiers/TestCppFunctionQualifiers.py lldb-api :: lang/cpp/function-ref-qualifiers/TestCppFunctionRefQualifiers.py lldb-api :: lang/cpp/global_operators/TestCppGlobalOperators.py lldb-api :: lang/cpp/llvm-style/TestLLVMStyle.py lldb-api :: lang/cpp/multiple-inheritance/TestCppMultipleInheritance.py lldb-api :: lang/cpp/namespace/TestNamespace.py lldb-api :: lang/cpp/namespace/TestNamespaceLookup.py lldb-api :: lang/cpp/namespace_conflicts/TestNamespaceConflicts.py lldb-api :: lang/cpp/operators/TestCppOperators.py lldb-api :: lang/cpp/overloaded-functions/TestOverloadedFunctions.py lldb-api :: lang/cpp/rvalue-references/TestRvalueReferences.py lldb-api :: lang/cpp/static_methods/TestCPPStaticMethods.py lldb-api :: lang/cpp/template/TestTemplateArgs.py lldb-api :: python_api/thread/TestThreadAPI.py ``` There are other failures that are due to different problems, and this change does not make those worse. (I have no plans to run the test suite with `-mthumb` regularly, I just did it to test some other refactoring) (cherry picked from commit 4077e66)
…vm#151828) # Problem When the user changes lldb-dap's arguments (e.g. path), there is a race condition, where the new lldb-dap process could be started first and have set the extension's `serverProcess` and `serverInfo` according to the new process, while the old lldb-dap process exits later and wipes out these two fields. Consequences: 1. This causes `getServerProcess()` to return `undefined` when it should return the new process. 2. This also causes wrong behavior when starting the next debug session that a new lldb-dap process will be started and the old not reused nor killed. # Fix When wiping the two fields, check if `serverProcess` equals to the process captured by the handler. If they equal, wipe the fields. If not, then the fields have already been updated (either new process has started, or the fields were already wiped out by another handler), and so the wiping should be skipped. (cherry picked from commit bb2642f)
…m#151827) This allows other debugger extensions to leverage the `lldb-dap` extension's settings and logic (e.g. "Server Mode"). Other debugger extensions can invoke these commands to resolve configuration, create adapter descriptor, and get the `lldb-dap` process for state tracking, additional interaction, and telemetry. VS Code commands added: * `lldb-dap.resolveDebugConfiguration` * `lldb-dap.resolveDebugConfigurationWithSubstitutedVariables` * `lldb-dap.createDebugAdapterDescriptor` * `lldb-dap.getServerProcess` (cherry picked from commit 0e0ea71)
This has been very flakey lately: ====================================================================== ERROR: test_writeMemory (TestDAP_memory.TestDAP_memory) Tests the 'writeMemory' request ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/memory/TestDAP_memory.py", line 202, in test_writeMemory mem_response = self.writeMemory( File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py", line 545, in writeMemory response = self.dap_server.request_writeMemory( File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py", line 850, in request_writeMemory return self.send_recv(command_dict) File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py", line 403, in send_recv raise ValueError(desc) ValueError: no response for "writeMemory" Config=arm-/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang ====================================================================== ERROR: test_writeMemory (TestDAP_memory.TestDAP_memory) Tests the 'writeMemory' request ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 2067, in tearDown Base.tearDown(self) File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 1105, in tearDown hook() # try the plain call and hope it works File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py", line 486, in cleanup self.dap_server.request_disconnect(terminateDebuggee=True) File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py", line 799, in request_disconnect return self.send_recv(command_dict) File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py", line 397, in send_recv self.send_packet(command) File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py", line 349, in send_packet self.send.flush() BrokenPipeError: [Errno 32] Broken pipe Config=arm-/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang ---------------------------------------------------------------------- General tracking issue - llvm#137660 (cherry picked from commit b800930)
Resolves llvm#141955 - Adds data to breakpoints `Source` object, in order for assembly breakpoints, which rely on a temporary `sourceReference` value, to be able to resolve in future sessions like normal path+line breakpoints - Adds optional `instructions_offset` parameter to `BreakpointResolver` (cherry picked from commit 4d3feae)
This patch fixes: lldb/unittests/DAP/ProtocolTypesTest.cpp:112:67: error: missing field 'adapterData' initializer [-Werror,-Wmissing-field-initializers] lldb/unittests/DAP/ProtocolTypesTest.cpp:571:70: error: missing field 'adapterData' initializer [-Werror,-Wmissing-field-initializers] (cherry picked from commit f091b40)
This test has been flakey on our bot: https://lab.llvm.org/buildbot/#/builders/18/builds/20410 ``` ====================================================================== FAIL: test_extra_launch_commands (TestDAP_launch.TestDAP_launch) Tests the "launchCommands" with extra launching settings ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py", line 482, in test_extra_launch_commands self.verify_commands("stopCommands", output, stopCommands) File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py", line 228, in verify_commands self.assertTrue( AssertionError: False is not true : verify 'frame variable' found in console output for 'stopCommands' Config=arm-/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang ---------------------------------------------------------------------- ``` Likely a timing issue waiting for the command output on a slower machine. General tracking issue - llvm#137660 (cherry picked from commit 4f65345)
@swift-ci test |
Related: #11599 |
@swift-ci test |
(cherry picked from commit 61d569f)
@swift-ci test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR backports the DAP changes leading up to the big JSONTransport refactor.