[Lldb-commits] [lldb] [lldb-dap] Remove an incorrect assumption on reverse requests. (PR #136210)
https://github.com/ashgti closed https://github.com/llvm/llvm-project/pull/136210 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] ec6828c - [lldb-dap] Remove an incorrect assumption on reverse requests. (#136210)
Author: John Harrison Date: 2025-04-19T13:45:59-07:00 New Revision: ec6828c1ecad7fe2f799f7b5af3361885a5d5bb9 URL: https://github.com/llvm/llvm-project/commit/ec6828c1ecad7fe2f799f7b5af3361885a5d5bb9 DIFF: https://github.com/llvm/llvm-project/commit/ec6828c1ecad7fe2f799f7b5af3361885a5d5bb9.diff LOG: [lldb-dap] Remove an incorrect assumption on reverse requests. (#136210) Reverse requests do have a 'seq' set still from VSCode. I incorrectly interpreted https://github.com/microsoft/vscode/blob/dede7bb4b7e9c9ec69155a243bb84037a40588fe/src/vs/workbench/contrib/debug/common/abstractDebugAdapter.ts#L65 to mean they have a 'seq' of '0', however the 'seq' is set in 'internalSend' here https://github.com/microsoft/vscode/blob/dede7bb4b7e9c9ec69155a243bb84037a40588fe/src/vs/workbench/contrib/debug/common/abstractDebugAdapter.ts#L178. Removing the check that 'seq=0' on reverse requests and updating the dap_server.py impl to also set the seq. Added: Modified: lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py lldb/tools/lldb-dap/Protocol/ProtocolBase.cpp Removed: diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py index 61d7fa94479b8..a9915ba2f6de6 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py @@ -343,25 +343,21 @@ def send_recv(self, command): self.send_packet( { "type": "response", -"seq": 0, "request_seq": response_or_request["seq"], "success": True, "command": "runInTerminal", "body": {}, }, -set_sequence=False, ) elif response_or_request["command"] == "startDebugging": self.send_packet( { "type": "response", -"seq": 0, "request_seq": response_or_request["seq"], "success": True, "command": "startDebugging", "body": {}, }, -set_sequence=False, ) else: desc = 'unknown reverse request "%s"' % ( diff --git a/lldb/tools/lldb-dap/Protocol/ProtocolBase.cpp b/lldb/tools/lldb-dap/Protocol/ProtocolBase.cpp index bfd68448fb483..bc4fee4aa8b8d 100644 --- a/lldb/tools/lldb-dap/Protocol/ProtocolBase.cpp +++ b/lldb/tools/lldb-dap/Protocol/ProtocolBase.cpp @@ -163,11 +163,6 @@ bool fromJSON(json::Value const &Params, Response &R, json::Path P) { return false; } - if (seq != 0) { -P.field("seq").report("expected to be '0'"); -return false; - } - if (R.command.empty()) { P.field("command").report("expected to not be ''"); return false; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Avoid force loading symbols in statistics collection (PR #136236)
https://github.com/royitaqi edited https://github.com/llvm/llvm-project/pull/136236 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Remove an incorrect assumption on reverse requests. (PR #136210)
JDevlieghere wrote: Yeah, according to the [spec](https://microsoft.github.io/debug-adapter-protocol/specification#Base_Protocol_ProtocolMessage) all protocol messages have a sequence number and the sequence number is 1-based: > Sequence number of the message (also known as message ID). The `seq` for > the first message sent by a client or debug adapter is 1, and for each > subsequent message is 1 greater than the previous message sent by that > actor. `seq` can be used to order requests, responses, and events, and to > associate requests with their corresponding responses. For protocol > messages of type `request` the sequence number can be used to cancel the > request. The spec says "can" but the sequence number is not optional. https://github.com/llvm/llvm-project/pull/136210 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Remove an incorrect assumption on reverse requests. (PR #136210)
https://github.com/JDevlieghere approved this pull request. https://github.com/llvm/llvm-project/pull/136210 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Avoid force loading symbols in statistics collection (PR #136236)
https://github.com/royitaqi updated https://github.com/llvm/llvm-project/pull/136236 >From 85cb8cca4fe41cf4080b3dbf7ce4f98c4b15a3c7 Mon Sep 17 00:00:00 2001 From: Roy Shi Date: Thu, 17 Apr 2025 15:03:00 -0700 Subject: [PATCH 1/4] [lldb] Do not parse symtab during statistics dump Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D73218490 --- lldb/include/lldb/Symbol/ObjectFile.h | 2 +- lldb/include/lldb/Symbol/SymbolFile.h | 4 ++-- lldb/include/lldb/Symbol/SymbolFileOnDemand.h | 2 +- lldb/source/Core/Module.cpp | 2 +- lldb/source/Symbol/ObjectFile.cpp | 4 ++-- lldb/source/Symbol/SymbolFile.cpp | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lldb/include/lldb/Symbol/ObjectFile.h b/lldb/include/lldb/Symbol/ObjectFile.h index cfcca04a76de8..7fca6383fa9f3 100644 --- a/lldb/include/lldb/Symbol/ObjectFile.h +++ b/lldb/include/lldb/Symbol/ObjectFile.h @@ -319,7 +319,7 @@ class ObjectFile : public std::enable_shared_from_this, /// /// \return /// The symbol table for this object file. - Symtab *GetSymtab(); + Symtab *GetSymtab(bool can_create = true); /// Parse the symbol table into the provides symbol table object. /// diff --git a/lldb/include/lldb/Symbol/SymbolFile.h b/lldb/include/lldb/Symbol/SymbolFile.h index f35d3ee9f22ae..df2f263b18e17 100644 --- a/lldb/include/lldb/Symbol/SymbolFile.h +++ b/lldb/include/lldb/Symbol/SymbolFile.h @@ -144,7 +144,7 @@ class SymbolFile : public PluginInterface { virtual uint32_t GetNumCompileUnits() = 0; virtual lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx) = 0; - virtual Symtab *GetSymtab() = 0; + virtual Symtab *GetSymtab(bool can_create = true) = 0; virtual lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) = 0; /// Return the Xcode SDK comp_unit was compiled against. @@ -533,7 +533,7 @@ class SymbolFileCommon : public SymbolFile { return m_abilities; } - Symtab *GetSymtab() override; + Symtab *GetSymtab(bool can_create = true) override; ObjectFile *GetObjectFile() override { return m_objfile_sp.get(); } const ObjectFile *GetObjectFile() const override { diff --git a/lldb/include/lldb/Symbol/SymbolFileOnDemand.h b/lldb/include/lldb/Symbol/SymbolFileOnDemand.h index 7a366bfabec86..ce9fc8626ac34 100644 --- a/lldb/include/lldb/Symbol/SymbolFileOnDemand.h +++ b/lldb/include/lldb/Symbol/SymbolFileOnDemand.h @@ -186,7 +186,7 @@ class SymbolFileOnDemand : public lldb_private::SymbolFile { uint32_t GetAbilities() override; - Symtab *GetSymtab() override { return m_sym_file_impl->GetSymtab(); } + Symtab *GetSymtab(bool can_create = true) override { return m_sym_file_impl->GetSymtab(can_create); } ObjectFile *GetObjectFile() override { return m_sym_file_impl->GetObjectFile(); diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index ad7046e596278..625c14e4a2153 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -997,7 +997,7 @@ SymbolFile *Module::GetSymbolFile(bool can_create, Stream *feedback_strm) { Symtab *Module::GetSymtab(bool can_create) { if (SymbolFile *symbols = GetSymbolFile(can_create)) -return symbols->GetSymtab(); +return symbols->GetSymtab(can_create); return nullptr; } diff --git a/lldb/source/Symbol/ObjectFile.cpp b/lldb/source/Symbol/ObjectFile.cpp index 2f2c59d6af620..292c00b9ac166 100644 --- a/lldb/source/Symbol/ObjectFile.cpp +++ b/lldb/source/Symbol/ObjectFile.cpp @@ -735,9 +735,9 @@ void llvm::format_provider::format( } -Symtab *ObjectFile::GetSymtab() { +Symtab *ObjectFile::GetSymtab(bool can_create) { ModuleSP module_sp(GetModule()); - if (module_sp) { + if (module_sp && can_create) { // We can't take the module lock in ObjectFile::GetSymtab() or we can // deadlock in DWARF indexing when any file asks for the symbol table from // an object file. This currently happens in the preloading of symbols in diff --git a/lldb/source/Symbol/SymbolFile.cpp b/lldb/source/Symbol/SymbolFile.cpp index 94e32b55572dd..870d778dca740 100644 --- a/lldb/source/Symbol/SymbolFile.cpp +++ b/lldb/source/Symbol/SymbolFile.cpp @@ -152,10 +152,10 @@ void SymbolFile::AssertModuleLock() { SymbolFile::RegisterInfoResolver::~RegisterInfoResolver() = default; -Symtab *SymbolFileCommon::GetSymtab() { +Symtab *SymbolFileCommon::GetSymtab(bool can_create) { std::lock_guard guard(GetModuleMutex()); // Fetch the symtab from the main object file. - auto *symtab = GetMainObjectFile()->GetSymtab(); + auto *symtab = GetMainObjectFile()->GetSymtab(can_create); if (m_symtab != symtab) { m_symtab = symtab; >From 1fccd09dde2d1f8da6f8253516c5c908049eb270 Mon Sep 17 00:00:00 2001 From: Roy Shi Date: Thu, 17 Apr 2025 21:45:48 -0700 Subject: [PATCH 2/4] Fix compilation of a unit test --- lldb/unittests/Symbol/LineTableTest.cpp
[Lldb-commits] [lldb] [lldb] Avoid force loading symbols in statistics collection (PR #136236)
https://github.com/royitaqi updated https://github.com/llvm/llvm-project/pull/136236 >From 85cb8cca4fe41cf4080b3dbf7ce4f98c4b15a3c7 Mon Sep 17 00:00:00 2001 From: Roy Shi Date: Thu, 17 Apr 2025 15:03:00 -0700 Subject: [PATCH 1/5] [lldb] Do not parse symtab during statistics dump Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D73218490 --- lldb/include/lldb/Symbol/ObjectFile.h | 2 +- lldb/include/lldb/Symbol/SymbolFile.h | 4 ++-- lldb/include/lldb/Symbol/SymbolFileOnDemand.h | 2 +- lldb/source/Core/Module.cpp | 2 +- lldb/source/Symbol/ObjectFile.cpp | 4 ++-- lldb/source/Symbol/SymbolFile.cpp | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lldb/include/lldb/Symbol/ObjectFile.h b/lldb/include/lldb/Symbol/ObjectFile.h index cfcca04a76de8..7fca6383fa9f3 100644 --- a/lldb/include/lldb/Symbol/ObjectFile.h +++ b/lldb/include/lldb/Symbol/ObjectFile.h @@ -319,7 +319,7 @@ class ObjectFile : public std::enable_shared_from_this, /// /// \return /// The symbol table for this object file. - Symtab *GetSymtab(); + Symtab *GetSymtab(bool can_create = true); /// Parse the symbol table into the provides symbol table object. /// diff --git a/lldb/include/lldb/Symbol/SymbolFile.h b/lldb/include/lldb/Symbol/SymbolFile.h index f35d3ee9f22ae..df2f263b18e17 100644 --- a/lldb/include/lldb/Symbol/SymbolFile.h +++ b/lldb/include/lldb/Symbol/SymbolFile.h @@ -144,7 +144,7 @@ class SymbolFile : public PluginInterface { virtual uint32_t GetNumCompileUnits() = 0; virtual lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx) = 0; - virtual Symtab *GetSymtab() = 0; + virtual Symtab *GetSymtab(bool can_create = true) = 0; virtual lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) = 0; /// Return the Xcode SDK comp_unit was compiled against. @@ -533,7 +533,7 @@ class SymbolFileCommon : public SymbolFile { return m_abilities; } - Symtab *GetSymtab() override; + Symtab *GetSymtab(bool can_create = true) override; ObjectFile *GetObjectFile() override { return m_objfile_sp.get(); } const ObjectFile *GetObjectFile() const override { diff --git a/lldb/include/lldb/Symbol/SymbolFileOnDemand.h b/lldb/include/lldb/Symbol/SymbolFileOnDemand.h index 7a366bfabec86..ce9fc8626ac34 100644 --- a/lldb/include/lldb/Symbol/SymbolFileOnDemand.h +++ b/lldb/include/lldb/Symbol/SymbolFileOnDemand.h @@ -186,7 +186,7 @@ class SymbolFileOnDemand : public lldb_private::SymbolFile { uint32_t GetAbilities() override; - Symtab *GetSymtab() override { return m_sym_file_impl->GetSymtab(); } + Symtab *GetSymtab(bool can_create = true) override { return m_sym_file_impl->GetSymtab(can_create); } ObjectFile *GetObjectFile() override { return m_sym_file_impl->GetObjectFile(); diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index ad7046e596278..625c14e4a2153 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -997,7 +997,7 @@ SymbolFile *Module::GetSymbolFile(bool can_create, Stream *feedback_strm) { Symtab *Module::GetSymtab(bool can_create) { if (SymbolFile *symbols = GetSymbolFile(can_create)) -return symbols->GetSymtab(); +return symbols->GetSymtab(can_create); return nullptr; } diff --git a/lldb/source/Symbol/ObjectFile.cpp b/lldb/source/Symbol/ObjectFile.cpp index 2f2c59d6af620..292c00b9ac166 100644 --- a/lldb/source/Symbol/ObjectFile.cpp +++ b/lldb/source/Symbol/ObjectFile.cpp @@ -735,9 +735,9 @@ void llvm::format_provider::format( } -Symtab *ObjectFile::GetSymtab() { +Symtab *ObjectFile::GetSymtab(bool can_create) { ModuleSP module_sp(GetModule()); - if (module_sp) { + if (module_sp && can_create) { // We can't take the module lock in ObjectFile::GetSymtab() or we can // deadlock in DWARF indexing when any file asks for the symbol table from // an object file. This currently happens in the preloading of symbols in diff --git a/lldb/source/Symbol/SymbolFile.cpp b/lldb/source/Symbol/SymbolFile.cpp index 94e32b55572dd..870d778dca740 100644 --- a/lldb/source/Symbol/SymbolFile.cpp +++ b/lldb/source/Symbol/SymbolFile.cpp @@ -152,10 +152,10 @@ void SymbolFile::AssertModuleLock() { SymbolFile::RegisterInfoResolver::~RegisterInfoResolver() = default; -Symtab *SymbolFileCommon::GetSymtab() { +Symtab *SymbolFileCommon::GetSymtab(bool can_create) { std::lock_guard guard(GetModuleMutex()); // Fetch the symtab from the main object file. - auto *symtab = GetMainObjectFile()->GetSymtab(); + auto *symtab = GetMainObjectFile()->GetSymtab(can_create); if (m_symtab != symtab) { m_symtab = symtab; >From 1fccd09dde2d1f8da6f8253516c5c908049eb270 Mon Sep 17 00:00:00 2001 From: Roy Shi Date: Thu, 17 Apr 2025 21:45:48 -0700 Subject: [PATCH 2/5] Fix compilation of a unit test --- lldb/unittests/Symbol/LineTableTest.cpp
[Lldb-commits] [lldb] [lldb] Avoid force loading symbols in statistics collection (PR #136236)
@@ -749,10 +749,20 @@ TEST_F(SymtabTest, TestSymtabCreatedOnDemand) { ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded()); auto module_sp = std::make_shared(ExpectedFile->moduleSpec()); - // The symbol table should not be loaded by default. + // The symbol file should not be created by default. Symtab *module_symtab = module_sp->GetSymtab(/*can_create=*/false); ASSERT_EQ(module_symtab, nullptr); + // Even if the symbol file is created, the symbol table should not be created by default. + + // TODO: + // I need to create a symbol file here, but without causing it to parse the symbol table. + // See next line as a failed attempt. + + // module_sp->GetSymbolFile(/*can_create=*/true); // Cannot do this because it will parse the symbol table. royitaqi wrote: @dmpots I found a way to add a unit test (where a symbol file can be created without creating a symbol table). Should be ready for review now. https://github.com/llvm/llvm-project/pull/136236 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix use-color settings not persistent (PR #135626)
https://github.com/JDevlieghere approved this pull request. LGTM. https://github.com/llvm/llvm-project/pull/135626 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix use-color settings not persistent (PR #135626)
@@ -99,6 +99,12 @@ class IOHandler { // Prompt support isn't mandatory return false; } + + virtual bool SetUseColor(bool use_color) { +// Use color isn't mandatory JDevlieghere wrote: ```suggestion // Color support isn't mandatory. ``` https://github.com/llvm/llvm-project/pull/135626 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix use-color settings not persistent (PR #135626)
https://github.com/JDevlieghere edited https://github.com/llvm/llvm-project/pull/135626 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Avoid force loading symbols in statistics collection (PR #136236)
https://github.com/royitaqi edited https://github.com/llvm/llvm-project/pull/136236 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Avoid force loading symbols in statistics collection (PR #136236)
https://github.com/royitaqi edited https://github.com/llvm/llvm-project/pull/136236 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix connecting via abstract socket (PR #136466)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- lldb/include/lldb/Host/linux/AbstractSocket.h lldb/include/lldb/Host/posix/DomainSocket.h lldb/source/Host/linux/AbstractSocket.cpp lldb/source/Host/posix/DomainSocket.cpp lldb/tools/lldb-server/lldb-platform.cpp `` View the diff from clang-format here. ``diff diff --git a/lldb/tools/lldb-server/lldb-platform.cpp b/lldb/tools/lldb-server/lldb-platform.cpp index 1f12f0902..59a83c28b 100644 --- a/lldb/tools/lldb-server/lldb-platform.cpp +++ b/lldb/tools/lldb-server/lldb-platform.cpp @@ -475,13 +475,13 @@ int main_platform(int argc, char *argv[]) { // Check if fd represents domain socket or abstract socket. struct sockaddr_un addr; socklen_t addr_len = sizeof(addr); - if (getsockname(fd, (struct sockaddr*)&addr, &addr_len) == -1) { + if (getsockname(fd, (struct sockaddr *)&addr, &addr_len) == -1) { LLDB_LOGF(log, "lldb-platform child: not a socket or error occurred"); return socket_error; } if (addr.sun_family == AF_UNIX && addr.sun_path[0] == '\0') { - protocol = Socket::ProtocolUnixAbstract; +protocol = Socket::ProtocolUnixAbstract; } #endif } `` https://github.com/llvm/llvm-project/pull/136466 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Fix connecting via abstract socket (PR #136466)
https://github.com/emrekultursay created https://github.com/llvm/llvm-project/pull/136466 Commits 82ee31f and 2e89312 added socket sharing, but only for unix domain sockets. That broke Android, which uses unix-abstract sockets. >From 950bafe1b6b900384b8d0f925f1cdab19a2c8e3d Mon Sep 17 00:00:00 2001 From: Emre Kultursay Date: Sun, 20 Apr 2025 01:11:31 + Subject: [PATCH] Fix connecting via abstract socket Commits 82ee31f and 2e89312 added socket sharing, but only for unix domain sockets. That broke Android, which uses unix-abstract sockets. --- lldb/include/lldb/Host/linux/AbstractSocket.h | 1 + lldb/include/lldb/Host/posix/DomainSocket.h | 1 + lldb/source/Host/linux/AbstractSocket.cpp | 3 ++ lldb/source/Host/posix/DomainSocket.cpp | 6 +++ lldb/tools/lldb-server/lldb-platform.cpp | 40 +-- 5 files changed, 47 insertions(+), 4 deletions(-) diff --git a/lldb/include/lldb/Host/linux/AbstractSocket.h b/lldb/include/lldb/Host/linux/AbstractSocket.h index accfd01457a5e..c6a0e2f8af63b 100644 --- a/lldb/include/lldb/Host/linux/AbstractSocket.h +++ b/lldb/include/lldb/Host/linux/AbstractSocket.h @@ -15,6 +15,7 @@ namespace lldb_private { class AbstractSocket : public DomainSocket { public: AbstractSocket(); + AbstractSocket(NativeSocket socket, bool should_close); protected: size_t GetNameOffset() const override; diff --git a/lldb/include/lldb/Host/posix/DomainSocket.h b/lldb/include/lldb/Host/posix/DomainSocket.h index 3dbe6206da2c5..562c011ee73e6 100644 --- a/lldb/include/lldb/Host/posix/DomainSocket.h +++ b/lldb/include/lldb/Host/posix/DomainSocket.h @@ -33,6 +33,7 @@ class DomainSocket : public Socket { protected: DomainSocket(SocketProtocol protocol); + DomainSocket(SocketProtocol protocol, NativeSocket socket, bool should_close); virtual size_t GetNameOffset() const; virtual void DeleteSocketFile(llvm::StringRef name); diff --git a/lldb/source/Host/linux/AbstractSocket.cpp b/lldb/source/Host/linux/AbstractSocket.cpp index 8393a80e86e72..681aa2d1ebc72 100644 --- a/lldb/source/Host/linux/AbstractSocket.cpp +++ b/lldb/source/Host/linux/AbstractSocket.cpp @@ -15,6 +15,9 @@ using namespace lldb_private; AbstractSocket::AbstractSocket() : DomainSocket(ProtocolUnixAbstract) {} +AbstractSocket::AbstractSocket(NativeSocket socket, bool should_close) +: DomainSocket(ProtocolUnixAbstract, socket, should_close) {} + size_t AbstractSocket::GetNameOffset() const { return 1; } void AbstractSocket::DeleteSocketFile(llvm::StringRef name) {} diff --git a/lldb/source/Host/posix/DomainSocket.cpp b/lldb/source/Host/posix/DomainSocket.cpp index 6c490cdda47ed..9b1e4f71bba2a 100644 --- a/lldb/source/Host/posix/DomainSocket.cpp +++ b/lldb/source/Host/posix/DomainSocket.cpp @@ -67,6 +67,12 @@ DomainSocket::DomainSocket(NativeSocket socket, m_socket = socket; } +DomainSocket::DomainSocket(SocketProtocol protocol, NativeSocket socket, + bool should_close) +: Socket(protocol, should_close) { + m_socket = socket; +} + Status DomainSocket::Connect(llvm::StringRef name) { sockaddr_un saddr_un; socklen_t saddr_un_len; diff --git a/lldb/tools/lldb-server/lldb-platform.cpp b/lldb/tools/lldb-server/lldb-platform.cpp index 23d36ffb4cb66..1f12f0902b954 100644 --- a/lldb/tools/lldb-server/lldb-platform.cpp +++ b/lldb/tools/lldb-server/lldb-platform.cpp @@ -39,11 +39,19 @@ #if LLDB_ENABLE_POSIX #include "lldb/Host/posix/DomainSocket.h" #endif +#ifdef __linux__ +#include "lldb/Host/linux/AbstractSocket.h" +#endif #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/UriParser.h" +#if LLDB_ENABLE_POSIX +#include +#include +#endif + using namespace lldb; using namespace lldb_private; using namespace lldb_private::lldb_server; @@ -455,14 +463,28 @@ int main_platform(int argc, char *argv[]) { lldb_private::Args inferior_arguments; inferior_arguments.SetArguments(argc, const_cast(argv)); + Log *log = GetLog(LLDBLog::Platform); Socket::SocketProtocol protocol = Socket::ProtocolUnixDomain; if (fd != SharedSocket::kInvalidFD) { // Child process will handle the connection and exit. -if (gdbserver_port) +if (gdbserver_port) { protocol = Socket::ProtocolTcp; +} else { +#ifdef LLDB_ENABLE_POSIX + // Check if fd represents domain socket or abstract socket. + struct sockaddr_un addr; + socklen_t addr_len = sizeof(addr); + if (getsockname(fd, (struct sockaddr*)&addr, &addr_len) == -1) { +LLDB_LOGF(log, "lldb-platform child: not a socket or error occurred"); +return socket_error; + } -Log *log = GetLog(LLDBLog::Platform); + if (addr.sun_family == AF_UNIX && addr.sun_path[0] == '\0') { + protocol = Socket::ProtocolUnixAbstract; + } +#endif +} NativeSocket sockfd; error = SharedSocket::GetNativeSocket(fd, sockfd); @@ -473,1
[Lldb-commits] [lldb] Fix connecting via abstract socket (PR #136466)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Emre Kultursay (emrekultursay) Changes Commits 82ee31f and 2e89312 added socket sharing, but only for unix domain sockets. That broke Android, which uses unix-abstract sockets. --- Full diff: https://github.com/llvm/llvm-project/pull/136466.diff 5 Files Affected: - (modified) lldb/include/lldb/Host/linux/AbstractSocket.h (+1) - (modified) lldb/include/lldb/Host/posix/DomainSocket.h (+1) - (modified) lldb/source/Host/linux/AbstractSocket.cpp (+3) - (modified) lldb/source/Host/posix/DomainSocket.cpp (+6) - (modified) lldb/tools/lldb-server/lldb-platform.cpp (+36-4) ``diff diff --git a/lldb/include/lldb/Host/linux/AbstractSocket.h b/lldb/include/lldb/Host/linux/AbstractSocket.h index accfd01457a5e..c6a0e2f8af63b 100644 --- a/lldb/include/lldb/Host/linux/AbstractSocket.h +++ b/lldb/include/lldb/Host/linux/AbstractSocket.h @@ -15,6 +15,7 @@ namespace lldb_private { class AbstractSocket : public DomainSocket { public: AbstractSocket(); + AbstractSocket(NativeSocket socket, bool should_close); protected: size_t GetNameOffset() const override; diff --git a/lldb/include/lldb/Host/posix/DomainSocket.h b/lldb/include/lldb/Host/posix/DomainSocket.h index 3dbe6206da2c5..562c011ee73e6 100644 --- a/lldb/include/lldb/Host/posix/DomainSocket.h +++ b/lldb/include/lldb/Host/posix/DomainSocket.h @@ -33,6 +33,7 @@ class DomainSocket : public Socket { protected: DomainSocket(SocketProtocol protocol); + DomainSocket(SocketProtocol protocol, NativeSocket socket, bool should_close); virtual size_t GetNameOffset() const; virtual void DeleteSocketFile(llvm::StringRef name); diff --git a/lldb/source/Host/linux/AbstractSocket.cpp b/lldb/source/Host/linux/AbstractSocket.cpp index 8393a80e86e72..681aa2d1ebc72 100644 --- a/lldb/source/Host/linux/AbstractSocket.cpp +++ b/lldb/source/Host/linux/AbstractSocket.cpp @@ -15,6 +15,9 @@ using namespace lldb_private; AbstractSocket::AbstractSocket() : DomainSocket(ProtocolUnixAbstract) {} +AbstractSocket::AbstractSocket(NativeSocket socket, bool should_close) +: DomainSocket(ProtocolUnixAbstract, socket, should_close) {} + size_t AbstractSocket::GetNameOffset() const { return 1; } void AbstractSocket::DeleteSocketFile(llvm::StringRef name) {} diff --git a/lldb/source/Host/posix/DomainSocket.cpp b/lldb/source/Host/posix/DomainSocket.cpp index 6c490cdda47ed..9b1e4f71bba2a 100644 --- a/lldb/source/Host/posix/DomainSocket.cpp +++ b/lldb/source/Host/posix/DomainSocket.cpp @@ -67,6 +67,12 @@ DomainSocket::DomainSocket(NativeSocket socket, m_socket = socket; } +DomainSocket::DomainSocket(SocketProtocol protocol, NativeSocket socket, + bool should_close) +: Socket(protocol, should_close) { + m_socket = socket; +} + Status DomainSocket::Connect(llvm::StringRef name) { sockaddr_un saddr_un; socklen_t saddr_un_len; diff --git a/lldb/tools/lldb-server/lldb-platform.cpp b/lldb/tools/lldb-server/lldb-platform.cpp index 23d36ffb4cb66..1f12f0902b954 100644 --- a/lldb/tools/lldb-server/lldb-platform.cpp +++ b/lldb/tools/lldb-server/lldb-platform.cpp @@ -39,11 +39,19 @@ #if LLDB_ENABLE_POSIX #include "lldb/Host/posix/DomainSocket.h" #endif +#ifdef __linux__ +#include "lldb/Host/linux/AbstractSocket.h" +#endif #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/UriParser.h" +#if LLDB_ENABLE_POSIX +#include +#include +#endif + using namespace lldb; using namespace lldb_private; using namespace lldb_private::lldb_server; @@ -455,14 +463,28 @@ int main_platform(int argc, char *argv[]) { lldb_private::Args inferior_arguments; inferior_arguments.SetArguments(argc, const_cast(argv)); + Log *log = GetLog(LLDBLog::Platform); Socket::SocketProtocol protocol = Socket::ProtocolUnixDomain; if (fd != SharedSocket::kInvalidFD) { // Child process will handle the connection and exit. -if (gdbserver_port) +if (gdbserver_port) { protocol = Socket::ProtocolTcp; +} else { +#ifdef LLDB_ENABLE_POSIX + // Check if fd represents domain socket or abstract socket. + struct sockaddr_un addr; + socklen_t addr_len = sizeof(addr); + if (getsockname(fd, (struct sockaddr*)&addr, &addr_len) == -1) { +LLDB_LOGF(log, "lldb-platform child: not a socket or error occurred"); +return socket_error; + } -Log *log = GetLog(LLDBLog::Platform); + if (addr.sun_family == AF_UNIX && addr.sun_path[0] == '\0') { + protocol = Socket::ProtocolUnixAbstract; + } +#endif +} NativeSocket sockfd; error = SharedSocket::GetNativeSocket(fd, sockfd); @@ -473,17 +495,27 @@ int main_platform(int argc, char *argv[]) { GDBRemoteCommunicationServerPlatform platform(protocol, gdbserver_port); Socket *socket; -if (protocol == Socket::ProtocolTcp) +if (protocol == Socket::ProtocolTcp) {