Skip to content
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

make debugger expand relative paths to absolute #19

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
32 changes: 31 additions & 1 deletion include/lrdb/debugger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -964,6 +992,8 @@ class debugger {
STEP_ENTRY,
};

char *working_dir = NULL;

lua_State* state_;
bool pause_;
// bool error_break_;
Expand Down
25 changes: 21 additions & 4 deletions include/lrdb/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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') {
Expand All @@ -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()));
Expand Down Expand Up @@ -411,6 +427,7 @@ class basic_server {
}
}

char working_dir[4096];
bool wait_for_connect_;
debugger debugger_;
StreamType command_stream_;
Expand Down