diff --git a/README.md b/README.md index 91bc4a87..0585fbdf 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,12 @@ Licensed under [Boost Software License](http://www.boost.org/LICENSE_1_0.txt) [![Build Status](https://travis-ci.org/satoren/LRDB.svg?branch=master)](https://travis-ci.org/satoren/LRDB) [![Coverage Status](https://coveralls.io/repos/github/satoren/LRDB/badge.svg?branch=master)](https://coveralls.io/github/satoren/LRDB?branch=master) +## Fork changes + +This fork is modified to use absolute paths instead of relative in communication with remote debugger. + +This fork works only with similarly modified vscode-lrdb extension - [kapecp/vscode-lrdb](https://github.com/kapecp/vscode-lrdb). + ## Introduction LRDB is Debugger for Lua programing language. diff --git a/include/lrdb/debugger.hpp b/include/lrdb/debugger.hpp index e9e69fc4..649fe93a 100644 --- a/include/lrdb/debugger.hpp +++ b/include/lrdb/debugger.hpp @@ -634,6 +634,9 @@ class debugger { const std::string& hit_condition = "") { breakpoint_info info; info.file = file; + if (!is_path_separator(file.at(0)) && working_dir) { // is relative path and working_dir is set + info.file = std::string(working_dir) + "/" + info.file; + } info.line = line; info.condition = condition; if (!hit_condition.empty()) { @@ -776,6 +779,25 @@ class debugger { return v; } + /// @brief set wcurrent working directory for relative path resolution + void set_working_dir(char* arg_working_dir) { + working_dir = (char*) malloc(4096 * sizeof(char)); + strcpy(working_dir, arg_working_dir); + } + + void path_to_absolute(char* path_absolute, const char* path) { + if (path[0] == '@') { + path++; + path_absolute[0] = '@'; + path_absolute[1] = '\0'; + } + if (!is_path_separator(path[0]) && working_dir) { // is a relative path and working_dir is set + strcat(path_absolute, working_dir); + strcat(path_absolute, "/"); + } + strcat(path_absolute, path); + } + private: void sethook() { lua_pushlightuserdata(state_, this_data_key()); @@ -837,7 +859,13 @@ class debugger { if (source[0] == '@') { source++; } - if (is_file_path_match(it->file.c_str(), source)) { + else { // @ is prepended to all filenames. When there is no @, the line is from eval, therefore can not have a breakpoint + return 0; + } + char source_absolute[4096] = {0}; + path_to_absolute(source_absolute, source); + + if (is_file_path_match(it->file.c_str(), source_absolute)) { return &(*it); } } @@ -964,6 +992,8 @@ class debugger { STEP_ENTRY, }; + char *working_dir = NULL; + lua_State* state_; bool pause_; // bool error_break_; diff --git a/include/lrdb/server.hpp b/include/lrdb/server.hpp index 8316741e..ef85951a 100644 --- a/include/lrdb/server.hpp +++ b/include/lrdb/server.hpp @@ -20,7 +20,7 @@ namespace lrdb { -#define LRDB_SERVER_PROTOCOL_VERSION "2" +#define LRDB_SERVER_PROTOCOL_VERSION "3" /// @brief Debug Server Class /// template type is messaging communication customization point @@ -70,6 +70,9 @@ class basic_server { private: void init() { + getcwd(working_dir, 4096); // probably will need to check for trailing slash + debugger_.set_working_dir(working_dir); + debugger_.set_pause_handler([&](debugger&) { send_pause_status(); while (debugger_.paused() && command_stream_.is_open()) { @@ -101,6 +104,10 @@ class basic_server { json::object param; param["protocol_version"] = json::value(LRDB_SERVER_PROTOCOL_VERSION); + char working_dir[4096]; + getcwd(working_dir, 4096); + param["working_directory"] = json::value(working_dir); + json::object lua; lua["version"] = json::value(LUA_VERSION); lua["release"] = json::value(LUA_RELEASE); @@ -233,8 +240,17 @@ class basic_server { json::array res; for (auto& s : callstack) { json::object data; - if (s.source()) { - data["file"] = json::value(s.source()); + + char absolute_source[4096] = {0}; + const char* source = s.source(); + + if (source && source[0] == '@') { + debugger_.path_to_absolute(absolute_source, s.source()); + source = absolute_source; + } + + if (source) { + data["file"] = json::value(source); } const char* name = s.name(); if (!name || name[0] == '\0') { @@ -247,7 +263,7 @@ class basic_server { name = s.what(); } if (!name || name[0] == '\0') { - name = s.source(); + name = source; } data["func"] = json::value(name); data["line"] = json::value(double(s.currentline())); @@ -411,6 +427,7 @@ class basic_server { } } + char working_dir[4096]; bool wait_for_connect_; debugger debugger_; StreamType command_stream_;