Skip to content

Commit

Permalink
Add logic for getting the current breakpoints from gdb.
Browse files Browse the repository at this point in the history
Left to do is to publish so it is visible as annotations like
the lspplugin does it
  • Loading branch information
mls-m5 committed Nov 2, 2023
1 parent 211dd04 commit a9098e8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
29 changes: 17 additions & 12 deletions src/plugin/gdbdebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down Expand Up @@ -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()),
});
}
}

Expand Down
14 changes: 8 additions & 6 deletions src/plugin/gdbdebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
#include <string_view>
#include <vector>

struct BreakpointInfo {
std::string breakpointNumber;
std::string functionSignature;
std::string filePath;
int lineNumber;
};

class GdbDebugger : public IDebugger {
public:
GdbDebugger();
Expand Down Expand Up @@ -72,12 +79,7 @@ class GdbDebugger : public IDebugger {
std::string _debugArgs;
std::filesystem::path _workingDirectory;

enum RequestedInfo {
None,
BreakpointList,
};

RequestedInfo _requestedInfo = None;
std::vector<BreakpointInfo> _breakpointInfos;

bool _isWaiting = false;
std::mutex _waitMutex;
Expand Down
2 changes: 0 additions & 2 deletions src/screen/serializescreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}};
Expand Down

0 comments on commit a9098e8

Please sign in to comment.