Skip to content
Draft
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ bld

# MacOS specific files
*.DS_Store

.cache/
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ configure_kernel("/share/jupyter/kernels/xc11/")
configure_kernel("/share/jupyter/kernels/xc17/")
configure_kernel("/share/jupyter/kernels/xc23/")

if(NOT EMSCRIPTEN AND NOT WIN32)
configure_kernel("/share/jupyter/kernels/xcpp17-debugger/")
endif()

Copy link
Collaborator

Choose a reason for hiding this comment

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

These kernels require the --use-oop-jit flag, so shouldn't be added for Linux arm for osx x86.

Also we should have debugger kernels for c++20, c++23 and the the c kernels too.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if we should switch to out of process in general all kernels. I suspect there are still several missing features but we should start enumerating them at least…

# Source files
# ============

Expand All @@ -178,6 +182,7 @@ set(XEUS_CPP_HEADERS
include/xeus-cpp/xmagics.hpp
include/xeus-cpp/xoptions.hpp
include/xeus-cpp/xpreamble.hpp
include/xeus-cpp/xdebugger.hpp
#src/xinspect.hpp
#src/xsystem.hpp
#src/xparser.hpp
Expand All @@ -192,6 +197,9 @@ set(XEUS_CPP_SRC
src/xparser.cpp
src/xutils.cpp
src/xmagics/os.cpp
src/xdebugger.cpp
src/xdebuglldb_client.cpp
src/xinternal_utils.cpp
)

if(NOT EMSCRIPTEN)
Expand Down
118 changes: 118 additions & 0 deletions include/xeus-cpp/xdebugger.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/************************************************************************************
* Copyright (c) 2023, xeus-cpp contributors *
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Copyright (c) 2023, xeus-cpp contributors *
* Copyright (c) 2025, xeus-cpp contributors *

* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
************************************************************************************/

#ifndef XEUS_CPP_XDEBUGGER_HPP
#define XEUS_CPP_XDEBUGGER_HPP

#ifdef __GNUC__
#pragma GCC diagnostic push
Copy link
Contributor

Choose a reason for hiding this comment

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

Why these are needed? Ideally we should write code that does not produce warnings.

#pragma GCC diagnostic ignored "-Wattributes"
#endif

#include <string>

#include "nlohmann/json.hpp"
#include "xeus-cpp/xinterpreter.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: included header json.hpp is not used directly [misc-include-cleaner]

Suggested change
#include "xeus-cpp/xinterpreter.hpp"
#include "xeus-cpp/xinterpreter.hpp"

#include "xeus-zmq/xdebugger_base.hpp"
#include "xeus_cpp_config.hpp"

namespace xcpp
{
class xdebuglldb_client;

class XEUS_CPP_API debugger : public xeus::xdebugger_base
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: class 'debugger' defines a destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]

    class XEUS_CPP_API debugger : public xeus::xdebugger_base
                       ^

{
public:

using base_type = xeus::xdebugger_base;

debugger(
xeus::xcontext& context,
Copy link
Contributor

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]

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

- #ifdef __GNUC__
+ #include <xeus/xeus_context.hpp>
+ #ifdef __GNUC__

const xeus::xconfiguration& config,
Copy link
Contributor

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]

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

- #ifdef __GNUC__
+ #include <xeus/xkernel_configuration.hpp>
+ #ifdef __GNUC__

const std::string& user_name,
const std::string& session_id,
const nl::json& debugger_config
Copy link
Contributor

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]

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

- #ifdef __GNUC__
+ #include <nlohmann/json_fwd.hpp>
+ #ifdef __GNUC__

);

virtual ~debugger();
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [cppcoreguidelines-explicit-virtual-functions]

Suggested change
virtual ~debugger();
~debugger() override;


private:

nl::json inspect_variables_request(const nl::json& message);
nl::json stack_trace_request(const nl::json& message);
nl::json attach_request(const nl::json& message);
nl::json configuration_done_request(const nl::json& message);
nl::json set_breakpoints_request(const nl::json& message);
nl::json dump_cell_request(const nl::json& message);
nl::json rich_inspect_variables_request(const nl::json& message);
nl::json copy_to_globals_request(const nl::json& message);
nl::json source_request(const nl::json& message);

bool get_variable_info_from_lldb(
const std::string& var_name,
int frame_id,
nl::json& data,
nl::json& metadata,
int sequence
);
void get_container_info(
const std::string& var_name,
int frame_id,
const std::string& var_type,
nl::json& data,
nl::json& metadata,
int sequence,
int size
);
bool is_container_type(const std::string& type) const;

bool start_lldb();
bool start() override;
void stop() override;
xeus::xdebugger_info get_debugger_info() const override;
virtual std::string get_cell_temporary_file(const std::string& code) const override;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 'virtual' is redundant since the function is already declared 'override' [cppcoreguidelines-explicit-virtual-functions]

Suggested change
virtual std::string get_cell_temporary_file(const std::string& code) const override;
std::string get_cell_temporary_file(const std::string& code) const override;


bool connect_to_lldb_tcp();
std::string send_dap_message(const nl::json& message);
std::string receive_dap_response();

xdebuglldb_client* p_debuglldb_client;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: invalid case style for private member 'p_debuglldb_client' [readability-identifier-naming]

Suggested change
xdebuglldb_client* p_debuglldb_client;
xdebuglldb_client* m_p_debuglldb_client;

std::string m_lldb_host;
std::string m_lldb_port;
nl::json m_debugger_config;
bool m_is_running;
int m_tcp_socket;
bool m_tcp_connected;
pid_t jit_process_pid;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: invalid case style for private member 'jit_process_pid' [readability-identifier-naming]

Suggested change
pid_t jit_process_pid;
pid_t m_jit_process_pid;

Copy link
Contributor

Choose a reason for hiding this comment

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

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

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

- #ifdef __GNUC__
+ #include <sys/types.h>
+ #ifdef __GNUC__


using breakpoint_list_t = std::map<std::string, std::vector<nl::json>>;
breakpoint_list_t m_breakpoint_list;

xcpp::interpreter* m_interpreter;

std::unordered_map<std::string, std::vector<std::string>> m_hash_to_sequential;
std::unordered_map<std::string, std::string> m_sequential_to_hash;

bool m_copy_to_globals_available;
};

XEUS_CPP_API
std::unique_ptr<xeus::xdebugger> make_cpp_debugger(
xeus::xcontext& context,
const xeus::xconfiguration& config,
const std::string& user_name,
const std::string& session_id,
const nl::json& debugger_config
);
}

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

#endif
25 changes: 25 additions & 0 deletions include/xeus-cpp/xinterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <streambuf>
#include <string>
#include <vector>
#include <thread>

#include "clang/Interpreter/CppInterOp.h" // from CppInterOp package

Expand All @@ -39,6 +40,27 @@ namespace xcpp

void publish_stdout(const std::string&);
void publish_stderr(const std::string&);
static int32_t get_current_pid();

std::vector<int> get_execution_count(const std::string& code) const
{
auto it = m_code_to_execution_count_map.find(code);
if (it != m_code_to_execution_count_map.end())
{
return it->second;
}
return {};
}

std::string get_code_from_execution_count(int execution_count) const
{
auto it = m_execution_count_to_code_map.find(execution_count);
if(it != m_execution_count_to_code_map.end())
{
return it->second;
}
return "";
}

private:

Expand Down Expand Up @@ -85,6 +107,9 @@ namespace xcpp

xoutput_buffer m_cout_buffer;
xoutput_buffer m_cerr_buffer;

std::map<std::string, std::vector<int>> m_code_to_execution_count_map;
std::map<int, std::string> m_execution_count_to_code_map;
};
}

Expand Down
Loading
Loading