Skip to content

GSOC Debugger #2

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

GSOC Debugger #2

wants to merge 11 commits into from

Conversation

kr-2003
Copy link
Owner

@kr-2003 kr-2003 commented May 17, 2025

No description provided.

@kr-2003
Copy link
Owner Author

kr-2003 commented May 17, 2025

Screenshot 2025-05-17 at 2 24 40 PM

github-actions[bot]

This comment was marked as off-topic.

@kr-2003
Copy link
Owner Author

kr-2003 commented May 17, 2025

Screenshot 2025-05-17 at 6 48 09 PM

github-actions[bot]

This comment was marked as off-topic.

@kr-2003

This comment was marked as resolved.

@kr-2003
Copy link
Owner Author

kr-2003 commented May 19, 2025

The connection to lldb-dap now persists. As you can see we can get ACK(response of first msg) and then response of init_request.
Screenshot 2025-05-19 at 6 32 50 PM

github-actions[bot]

This comment was marked as off-topic.

@kr-2003
Copy link
Owner Author

kr-2003 commented May 19, 2025

Can't recieve multiple responses from lldb-dap.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 98. Check the log or trigger a new build to see more.

// Register request handlers
register_request_handler(
"inspectVariables",
std::bind(&debugger::inspect_variables_request, this, _1),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::placeholders::_1" is directly included [misc-include-cleaner]

            std::bind(&debugger::inspect_variables_request, this, _1),
                                                                  ^

// Register request handlers
register_request_handler(
"inspectVariables",
std::bind(&debugger::inspect_variables_request, this, _1),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: prefer a lambda to std::bind [modernize-avoid-bind]

Suggested change
std::bind(&debugger::inspect_variables_request, this, _1),
[this](auto && PH1) { return inspect_variables_request(std::forward<decltype(PH1)>(PH1)); },

std::bind(&debugger::inspect_variables_request, this, _1),
false
);
register_request_handler("stackTrace", std::bind(&debugger::stack_trace_request, this, _1), false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: prefer a lambda to std::bind [modernize-avoid-bind]

Suggested change
register_request_handler("stackTrace", std::bind(&debugger::stack_trace_request, this, _1), false);
register_request_handler("stackTrace", [this](auto && PH1) { return stack_trace_request(std::forward<decltype(PH1)>(PH1)); }, false);

false
);
register_request_handler("stackTrace", std::bind(&debugger::stack_trace_request, this, _1), false);
register_request_handler("attach", std::bind(&debugger::attach_request, this, _1), true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: prefer a lambda to std::bind [modernize-avoid-bind]

Suggested change
register_request_handler("attach", std::bind(&debugger::attach_request, this, _1), true);
register_request_handler("attach", [this](auto && PH1) { return attach_request(std::forward<decltype(PH1)>(PH1)); }, true);

register_request_handler("attach", std::bind(&debugger::attach_request, this, _1), true);
register_request_handler(
"configurationDone",
std::bind(&debugger::configuration_done_request, this, _1),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: prefer a lambda to std::bind [modernize-avoid-bind]

Suggested change
std::bind(&debugger::configuration_done_request, this, _1),
[this](auto && PH1) { return configuration_done_request(std::forward<decltype(PH1)>(PH1)); },

true
);

std::cout << "Debugger initialized with config: " << m_debugger_config.dump() << std::endl;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]

Suggested change
std::cout << "Debugger initialized with config: " << m_debugger_config.dump() << std::endl;
std::cout << "Debugger initialized with config: " << m_debugger_config.dump() << '\n';


debugger::~debugger()
{
std::cout << "Stopping debugger..........." << std::endl;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]

Suggested change
std::cout << "Stopping debugger..........." << std::endl;
std::cout << "Stopping debugger..........." << '\n';

m_lldb_port = xeus::find_free_port(100, 9999, 10099);
if (m_lldb_port.empty())
{
std::cout << "Failed to find a free port for LLDB-DAP" << std::endl;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]

Suggested change
std::cout << "Failed to find a free port for LLDB-DAP" << std::endl;
std::cout << "Failed to find a free port for LLDB-DAP" << '\n';

if (std::getenv("XEUS_LOG") != nullptr)
{
std::ofstream out("xeus.log", std::ios_base::app);
out << "===== DEBUGGER CONFIG =====" << std::endl;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]

Suggested change
out << "===== DEBUGGER CONFIG =====" << std::endl;
out << "===== DEBUGGER CONFIG =====" << '\n';

{
std::ofstream out("xeus.log", std::ios_base::app);
out << "===== DEBUGGER CONFIG =====" << std::endl;
out << m_debugger_config.dump() << std::endl;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]

Suggested change
out << m_debugger_config.dump() << std::endl;
out << m_debugger_config.dump() << '\n';

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 96. Check the log or trigger a new build to see more.

#include "xeus-cpp/xdebugger.hpp"

#include <arpa/inet.h> // For inet_pton(), htons()
#include <chrono> // For std::chrono (used in sleep_for)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header inet.h is not used directly [misc-include-cleaner]

Suggested change
#include <chrono> // For std::chrono (used in sleep_for)
#include <chrono> // For std::chrono (used in sleep_for)


#include <arpa/inet.h> // For inet_pton(), htons()
#include <chrono> // For std::chrono (used in sleep_for)
#include <cstdlib>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header chrono is not used directly [misc-include-cleaner]

Suggested change
#include <cstdlib>
#include <cstdlib>

#include <chrono> // For std::chrono (used in sleep_for)
#include <cstdlib>
#include <fcntl.h>
#include <fstream>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header fcntl.h is not used directly [misc-include-cleaner]

Suggested change
#include <fstream>
#include <fstream>

#include <fstream>
#include <iostream>
#include <netinet/in.h> // For sockaddr_in, AF_INET
#include <sys/socket.h> // For socket(), connect(), send(), recv()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header in.h is not used directly [misc-include-cleaner]

Suggested change
#include <sys/socket.h> // For socket(), connect(), send(), recv()
#include <sys/socket.h> // For socket(), connect(), send(), recv()

#include <iostream>
#include <netinet/in.h> // For sockaddr_in, AF_INET
#include <sys/socket.h> // For socket(), connect(), send(), recv()
#include <sys/types.h>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header socket.h is not used directly [misc-include-cleaner]

Suggested change
#include <sys/types.h>
#include <sys/types.h>

#include <sys/socket.h> // For socket(), connect(), send(), recv()
#include <sys/types.h>
#include <sys/wait.h>
#include <thread>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header wait.h is not used directly [misc-include-cleaner]

Suggested change
#include <thread>
#include <thread>

#include <sys/wait.h>
#include <thread>
#include <unistd.h>

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header unistd.h is not used directly [misc-include-cleaner]

Suggested change


namespace xcpp
{
debugger::debugger(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: constructor does not initialize these fields: m_tcp_socket, m_tcp_connected [cppcoreguidelines-pro-type-member-init]

include/xeus-cpp/xdebugger.hpp:69:

-         int m_tcp_socket;
-         bool m_tcp_connected;
+         int m_tcp_socket{};
+         bool m_tcp_connected{};

namespace xcpp
{
debugger::debugger(
xeus::xcontext& context,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "xeus::xcontext" is directly included [misc-include-cleaner]

src/xdebugger.cpp:14:

+ #include <xeus/xeus_context.hpp>

{
debugger::debugger(
xeus::xcontext& context,
const xeus::xconfiguration& config,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "xeus::xconfiguration" is directly included [misc-include-cleaner]

src/xdebugger.cpp:14:

+ #include <xeus/xkernel_configuration.hpp>

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 85. Check the log or trigger a new build to see more.

debugger::debugger(
xeus::xcontext& context,
const xeus::xconfiguration& config,
const std::string& user_name,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::string" is directly included [misc-include-cleaner]

src/xdebugger.cpp:9:

- #include <sys/socket.h>  // For socket(), connect(), send(), recv()
+ #include <string>
+ #include <sys/socket.h>  // For socket(), connect(), send(), recv()

const xeus::xconfiguration& config,
const std::string& user_name,
const std::string& session_id,
const nl::json& debugger_config
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "nlohmann::json" is directly included [misc-include-cleaner]

src/xdebugger.cpp:9:

- #include <sys/socket.h>  // For socket(), connect(), send(), recv()
+ #include <nlohmann/json_fwd.hpp>
+ #include <sys/socket.h>  // For socket(), connect(), send(), recv()

const xeus::xconfiguration& config,
const std::string& user_name,
const std::string& session_id,
const nl::json& debugger_config
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: pass by value and use std::move [modernize-pass-by-value]

src/xdebugger.cpp:13:

- #include <unistd.h>
+ #include <utility>
+ #include <unistd.h>
Suggested change
const nl::json& debugger_config
nl::json debugger_config

src/xdebugger.cpp:42:

-         , m_debugger_config(debugger_config)
+         , m_debugger_config(std::move(debugger_config))

include/xeus-cpp/xdebugger.hpp:40:

-                  const nl::json& debugger_config);
+                  nl::json  debugger_config);

const std::string& session_id,
const nl::json& debugger_config
)
: xdebugger_base(context)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "xeus::xdebugger_base" is directly included [misc-include-cleaner]

src/xdebugger.cpp:14:

+ #include <xeus-zmq/xdebugger_base.hpp>

context,
config,
xeus::get_socket_linger(),
xdap_tcp_configuration(xeus::dap_tcp_type::client, xeus::dap_init_type::parallel, user_name, session_id),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "xeus::dap_tcp_type" is directly included [misc-include-cleaner]

src/xdebugger.cpp:14:

+ #include <xeus-zmq/xdap_tcp_client.hpp>

// Register request handlers
register_request_handler(
"inspectVariables",
std::bind(&debugger::inspect_variables_request, this, _1),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::bind" is directly included [misc-include-cleaner]

src/xdebugger.cpp:7:

- #include <iostream>
+ #include <functional>
+ #include <iostream>


bool debugger::start_lldb()
{
std::cout << "debugger::start_lldb" << std::endl;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]

Suggested change
std::cout << "debugger::start_lldb" << std::endl;
std::cout << "debugger::start_lldb" << '\n';

code += "int main() {\n";

// Construct LLDB-DAP command arguments
code += " vector<string> lldb_args = {\"lldb-dap\", \"--port\", \"" + m_lldb_port + "\"};\n";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: escaped string literal can be written as a raw string literal [modernize-raw-string-literal]

Suggested change
code += " vector<string> lldb_args = {\"lldb-dap\", \"--port\", \"" + m_lldb_port + "\"};\n";
code += R"( vector<string> lldb_args = {"lldb-dap", "--port", ")" + m_lldb_port + "\"};\n";

{
if (it->contains("initCommands"))
{
std::cout << "Adding init commands to lldb-dap command" << std::endl;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]

Suggested change
std::cout << "Adding init commands to lldb-dap command" << std::endl;
std::cout << "Adding init commands to lldb-dap command" << '\n';

if (it->contains("initCommands"))
{
std::cout << "Adding init commands to lldb-dap command" << std::endl;
for (const auto& cmd : it->at("initCommands").get<std::vector<std::string>>())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::vector" is directly included [misc-include-cleaner]

src/xdebugger.cpp:14:

+ #include <vector>

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 227. Check the log or trigger a new build to see more.

@@ -0,0 +1,147 @@
#pragma once

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: header is missing header guard [llvm-header-guard]

Suggested change
#pragma once
#ifndef XEUS_CPP_XSHARED_MEMORY_HPP
#define XEUS_CPP_XSHARED_MEMORY_HPP
#pragma once

include/xeus-cpp/xshared_memory.hpp:-1:

+ 
+ #endif

@@ -0,0 +1,147 @@
#pragma once

#include <string>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: #includes are not sorted properly [llvm-include-order]

Suggested change
#include <string>
#include <atomic>

include/xeus-cpp/xshared_memory.hpp:4:

- #include <atomic>
- #include <vector>
- #include <sstream>
+ #include <sstream>
+ #include <string>
+ #include <vector>

static constexpr size_t MAX_ERROR_SIZE = 8 * 1024; // 8KB for errors
static constexpr size_t MAX_COMPLETION_SIZE = 8 * 1024; // 8KB for completions

enum class RequestType : uint32_t {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: enum 'RequestType' uses a larger base type ('uint32_t' (aka 'unsigned int'), size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size]

    enum class RequestType : uint32_t {
               ^

static constexpr size_t MAX_ERROR_SIZE = 8 * 1024; // 8KB for errors
static constexpr size_t MAX_COMPLETION_SIZE = 8 * 1024; // 8KB for completions

enum class RequestType : uint32_t {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "uint32_t" is directly included [misc-include-cleaner]

include/xeus-cpp/xshared_memory.hpp:2:

- #include <string>
+ #include <cstdint>
+ #include <string>

SHUTDOWN
};

enum class ResponseStatus : uint32_t {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: enum 'ResponseStatus' uses a larger base type ('uint32_t' (aka 'unsigned int'), size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size]

    enum class ResponseStatus : uint32_t {
               ^

std::atomic<RequestType> request_type{RequestType::NONE};
std::atomic<ResponseStatus> response_status{ResponseStatus::NONE};

char code_buffer[MAX_CODE_SIZE];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]

    char code_buffer[MAX_CODE_SIZE];
    ^

uint32_t code_length;
int cursor_pos;

char output_buffer[MAX_OUTPUT_SIZE];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]

    char output_buffer[MAX_OUTPUT_SIZE];
    ^

int cursor_pos;

char output_buffer[MAX_OUTPUT_SIZE];
char error_buffer[MAX_ERROR_SIZE];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]

    char error_buffer[MAX_ERROR_SIZE];
    ^

uint32_t output_length;
uint32_t error_length;
bool compilation_result;
int64_t evaluation_result;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "int64_t" is directly included [misc-include-cleaner]

    int64_t evaluation_result;
    ^

bool compilation_result;
int64_t evaluation_result;

char completion_buffer[MAX_COMPLETION_SIZE]; // Use separate size constant

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]

    char completion_buffer[MAX_COMPLETION_SIZE]; // Use separate size constant
    ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant