Skip to content

Commit

Permalink
DAP protocol fixes
Browse files Browse the repository at this point in the history
Fixed issue with DAP client can not handle non valid UTF8 output
generted by DAP server

Signed-off-by: Eran Ifrah <[email protected]>
  • Loading branch information
eranif committed Dec 5, 2024
1 parent 98338bb commit 162a4d6
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions CodeLiteIDE-macOS.workspace
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"file_extensions": "*.cpp;*.c;*.txt;*.json;*.hpp;*.cc;*.cxx;*.xml;*.h;*.wxcp;*.xrc;*.py",
"excludeFilesPattern": "*.o;*.pyc;*.obj;*.workspace;*.o.d;*.exe;*.dll;*.project",
"excludePaths": "codelite-cli;codelite-icons;codelite-icons-dark;codelite-icons-fresh-farm;codelite-stdio;codelite_echo;codelite_launcher;codelite_make;bitmaps;bitmaps-dark;bitmaps-light;build-release;CallGraph",
"debugger": "lldb-vscode"
"debugger": "GNU gdb debugger"
}, {
"name": "Release",
"targets": [["Run CMake - Release", "mkdir -p build-release && cd build-release && cmake -DCMAKE_BUILD_TYPE=Release .. -Wno-dev"], ["build", "cd build-release && make -j8 install"], ["clean", "cd build-release && make -j8 clean"]],
"file_extensions": "*.cpp;*.c;*.txt;*.json;*.hpp;*.cc;*.cxx;*.xml;*.h;*.wxcp;.*.xrc;*.cmake;*.rc;*.py",
"excludeFilesPattern": "*.o;*.pyc;*.obj;*.workspace;*.o.d;*.exe;*.dll;*.project",
"excludePaths": "codelite-cli;codelite-icons;codelite-icons-dark;codelite-icons-fresh-farm;codelite-stdio;codelite_echo;codelite_launcher;codelite_make;bitmaps;bitmaps-dark;bitmaps-light;build-release;CallGraph",
"debugger": "lldb-vscode"
"debugger": "GNU gdb debugger"
}]
}
10 changes: 5 additions & 5 deletions DebugAdapterClient/DebugAdapterClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ class StdioTransport : public dap::Transport
* @returns true on success, false in case of an error. True is also returned when timeout occurs, check the buffer
* length if it is 0, timeout occurred
*/
bool Read(wxString& buffer, int msTimeout) override
bool Read(std::string& buffer, int msTimeout) override
{
if (wxThread::IsMain()) {
LOG_ERROR(LOG) << "StdioTransport::Read is called from the main thread!" << endl;
return false;
}

wxString msg;
std::string msg;
switch (m_dap_server->Queue().ReceiveTimeout(msTimeout, msg)) {
case wxMSGQUEUE_NO_ERROR:
case wxMSGQUEUE_TIMEOUT:
Expand All @@ -136,7 +136,7 @@ class StdioTransport : public dap::Transport
* @brief send data over the network
* @return number of bytes written
*/
size_t Send(const wxString& buffer) override
size_t Send(const std::string& buffer) override
{
if (!m_dap_server->Write(buffer)) {
return 0;
Expand Down Expand Up @@ -1267,7 +1267,7 @@ void DebugAdapterClient::StartAndConnectToDapServer()
// Using socket transport
auto socket_transport = new dap::SocketTransport();
LOG_DEBUG(LOG) << "Connecting to dap server:" << m_session.dap_server.GetConnectionString() << endl;
if (!socket_transport->Connect(m_session.dap_server.GetConnectionString(), 10)) {
if (!socket_transport->Connect(m_session.dap_server.GetConnectionString().ToStdString(), 10)) {
wxMessageBox("Failed to connect to DAP server using socket", DAP_MESSAGE_BOX_TITLE,
wxICON_ERROR | wxOK | wxCENTRE);
wxDELETE(socket_transport);
Expand Down Expand Up @@ -1315,7 +1315,7 @@ void DebugAdapterClient::OnProcessOutput(clProcessEvent& event)
{
event.Skip();
if (m_dap_server && m_dap_server->IsRedirect()) {
m_dap_server->Queue().Post(event.GetOutput());
m_dap_server->Queue().Post(event.GetOutputRaw());
}
}

Expand Down
6 changes: 3 additions & 3 deletions DebugAdapterClient/DebugAdapterClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct DapProcess {
}
}

bool Write(const wxString& buffer)
bool Write(const std::string& buffer)
{
if (m_process) {
return m_process->WriteRaw(buffer);
Expand All @@ -79,12 +79,12 @@ struct DapProcess {
}

bool IsRedirect() const { return m_process && m_process->IsRedirect(); }
wxMessageQueue<wxString>& Queue() { return m_readQueue; }
wxMessageQueue<std::string>& Queue() { return m_readQueue; }
typedef std::shared_ptr<DapProcess> Ptr_t;

private:
IProcess::Ptr_t m_process = nullptr;
wxMessageQueue<wxString> m_readQueue;
wxMessageQueue<std::string> m_readQueue;
};

class DebugAdapterClient : public IPlugin
Expand Down
4 changes: 2 additions & 2 deletions DebugAdapterClient/StdioTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ dap::StdioTransport::StdioTransport() {}

dap::StdioTransport::~StdioTransport() {}

bool dap::StdioTransport::Read(wxString& buffer, int msTimeout)
bool dap::StdioTransport::Read(std::string& buffer, int msTimeout)
{
wxUnusedVar(buffer);
wxUnusedVar(msTimeout);
return false;
}

size_t dap::StdioTransport::Send(const wxString& buffer)
size_t dap::StdioTransport::Send(const std::string& buffer)
{
wxUnusedVar(buffer);
return false;
Expand Down
4 changes: 2 additions & 2 deletions DebugAdapterClient/StdioTransport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class StdioTransport : public dap::Transport
* @returns true on success, false in case of an error. True is also returned when timeout occurs, The caller should
* check the buffer length: if it is 0, than timeout occurred.
*/
bool Read(wxString& buffer, int msTimeout) override;
bool Read(std::string& buffer, int msTimeout) override;

/**
* @brief send data over the network
* @return number of bytes written
*/
size_t Send(const wxString& buffer) override;
size_t Send(const std::string& buffer) override;
};

} // namespace dap
Expand Down

0 comments on commit 162a4d6

Please sign in to comment.