-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[lldb] Adjust ProtocolServer connection defaults. #155714
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
Changes from 2 commits
831a505
5f01863
bb96a78
9ffaa4f
51f63c3
b2d06b0
310785f
be5c25c
f278e4c
1f5cba9
0134646
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,14 +10,14 @@ | |
| #include "Resource.h" | ||
| #include "Tool.h" | ||
| #include "lldb/Core/PluginManager.h" | ||
| #include "lldb/Protocol/MCP/MCPError.h" | ||
| #include "lldb/Protocol/MCP/Tool.h" | ||
| #include "lldb/Host/FileSystem.h" | ||
| #include "lldb/Protocol/MCP/Server.h" | ||
| #include "lldb/Utility/LLDBLog.h" | ||
| #include "lldb/Utility/Log.h" | ||
| #include "llvm/ADT/StringExtras.h" | ||
| #include "llvm/Support/Error.h" | ||
| #include "llvm/Support/Threading.h" | ||
| #include <thread> | ||
| #include <variant> | ||
|
|
||
| using namespace lldb_private; | ||
| using namespace lldb_private::mcp; | ||
|
|
@@ -104,6 +104,43 @@ llvm::Error ProtocolServerMCP::Start(ProtocolServer::Connection connection) { | |
| if (llvm::Error error = handles.takeError()) | ||
| return error; | ||
|
|
||
| auto listening_uris = m_listener->GetListeningConnectionURI(); | ||
| if (listening_uris.empty()) | ||
| return createStringError("Failed to list listening connections"); | ||
ashgti marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| std::string address = | ||
| llvm::join(m_listener->GetListeningConnectionURI(), ", "); | ||
|
|
||
| llvm::SmallString<128> user_home_dir; | ||
| FileSystem::Instance().GetHomeDirectory(user_home_dir); | ||
| FileSpec mcp_registry_dir = FileSpec(user_home_dir.c_str()); | ||
| mcp_registry_dir.AppendPathComponent(".lldb"); | ||
|
||
| mcp_registry_dir.AppendPathComponent("mcp"); | ||
|
|
||
| Status error(llvm::sys::fs::create_directory(mcp_registry_dir.GetPath())); | ||
| if (error.Fail()) | ||
| return error.takeError(); | ||
|
|
||
| m_mcp_registry_entry_path = mcp_registry_dir.CopyByAppendingPathComponent( | ||
| formatv("lldb-{0}.json", getpid()).str()); | ||
|
|
||
| const File::OpenOptions flags = File::eOpenOptionWriteOnly | | ||
| File::eOpenOptionCanCreate | | ||
| File::eOpenOptionTruncate; | ||
| llvm::Expected<lldb::FileUP> file = | ||
| FileSystem::Instance().Open(m_mcp_registry_entry_path, flags, | ||
| lldb::eFilePermissionsFileDefault, false); | ||
| if (!file) | ||
| return file.takeError(); | ||
|
|
||
| ServerMetadata metadata; | ||
| metadata.connection_uri = listening_uris[0]; | ||
| metadata.pid = getpid(); | ||
|
|
||
| std::string buf = formatv("{0}", toJSON(metadata)).str(); | ||
| size_t num_bytes = buf.size(); | ||
| if (llvm::Error error = (*file)->Write(buf.data(), num_bytes).takeError()) | ||
| return error; | ||
|
|
||
| m_running = true; | ||
| m_listen_handlers = std::move(*handles); | ||
| m_loop_thread = std::thread([=] { | ||
|
|
@@ -122,6 +159,10 @@ llvm::Error ProtocolServerMCP::Stop() { | |
| m_running = false; | ||
| } | ||
|
|
||
| if (!m_mcp_registry_entry_path.GetPath().empty()) | ||
| FileSystem::Instance().RemoveFile(m_mcp_registry_entry_path); | ||
| m_mcp_registry_entry_path.Clear(); | ||
|
|
||
| // Stop the main loop. | ||
| m_loop.AddPendingCallback( | ||
| [](lldb_private::MainLoopBase &loop) { loop.RequestTermination(); }); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.