From a9098e8304fb20c725c03d50162c8711ffcffc0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Lasersk=C3=B6ld?= Date: Thu, 2 Nov 2023 22:39:36 +0100 Subject: [PATCH] Add logic for getting the current breakpoints from gdb. Left to do is to publish so it is visible as annotations like the lspplugin does it --- src/plugin/gdbdebugger.cpp | 29 +++++++++++++++++------------ src/plugin/gdbdebugger.h | 14 ++++++++------ src/screen/serializescreen.cpp | 2 -- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/plugin/gdbdebugger.cpp b/src/plugin/gdbdebugger.cpp index 93d46b2..df6ab50 100644 --- a/src/plugin/gdbdebugger.cpp +++ b/src/plugin/gdbdebugger.cpp @@ -133,8 +133,12 @@ void GdbDebugger::setBreakpoint(SourceLocation loc) { _connection.send("b " + loc.path.string() + ":" + std::to_string(loc.position.y() + 1)); waitForDone(); + _breakpointInfos.clear(); _connection.send("info b"); // Request information about all set breakpoints + // New breakpoint infos will be added in the input thread waitForDone(); + + // TODO: Publish the information somehow } void GdbDebugger::deleteBreakpoint(SourceLocation loc) {} @@ -188,18 +192,19 @@ void GdbDebugger::inputThread(std::istream &in) { } } - constexpr auto breakpointStr = std::string_view{"~\"Breakpoint "}; - if (line.rfind(breakpointStr, 0) == 0) { - static const std::regex breakpointRegex( - R"~(~"Breakpoint (\d+) at (0x[0-9a-fA-F]+): file (.*), line (\d+).\\n")~"); - if (std::regex_match(line, matches, breakpointRegex)) { - // std::cout << "Breakpoint Number: " << - // matches[1].str() - // << std::endl; - // std::cout << "Address: " << matches[2].str() - // << std::endl; std::cout << "Filename: " << - // matches[3].str() << std::endl; std::cout << - // "Line: " << matches[4].str() << std::endl; + if (line.starts_with("~")) { + static const auto re = std::regex{ + R"(~"(\d+)\s+breakpoint\s+.* in ([^\s]+) at ([^\s]+):(\d+))"}; + + auto match = std::smatch{}; + + if (std::regex_search(line, match, re)) { + _breakpointInfos.push_back({ + .breakpointNumber = match[1].str(), + .functionSignature = match[2].str(), + .filePath = match[3].str(), + .lineNumber = std::stoi(match[4].str()), + }); } } diff --git a/src/plugin/gdbdebugger.h b/src/plugin/gdbdebugger.h index 72e5503..0edbccb 100644 --- a/src/plugin/gdbdebugger.h +++ b/src/plugin/gdbdebugger.h @@ -11,6 +11,13 @@ #include #include +struct BreakpointInfo { + std::string breakpointNumber; + std::string functionSignature; + std::string filePath; + int lineNumber; +}; + class GdbDebugger : public IDebugger { public: GdbDebugger(); @@ -72,12 +79,7 @@ class GdbDebugger : public IDebugger { std::string _debugArgs; std::filesystem::path _workingDirectory; - enum RequestedInfo { - None, - BreakpointList, - }; - - RequestedInfo _requestedInfo = None; + std::vector _breakpointInfos; bool _isWaiting = false; std::mutex _waitMutex; diff --git a/src/screen/serializescreen.cpp b/src/screen/serializescreen.cpp index b81510e..bdcac2f 100644 --- a/src/screen/serializescreen.cpp +++ b/src/screen/serializescreen.cpp @@ -174,8 +174,6 @@ std::string SerializeScreen::request(std::string_view method) { } } -// void SerializeScreen::receive(const nlohmann::json &json) { -// void SerializeScreen::receive(Archive &arch) { void SerializeScreen::receive(std::string_view str) { PROFILE_FUNCTION(); auto ss = std::istringstream{std::string{str}};