Skip to content
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
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"iostream": "cpp"
}
}
76 changes: 72 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ else()
configure_native_kernel("/share/jupyter/kernels/xcpp17/")
configure_native_kernel("/share/jupyter/kernels/xcpp20/")
configure_native_kernel("/share/jupyter/kernels/xcpp23/")
configure_native_kernel("/share/jupyter/kernels/xcpp17-debugger/")
endif()

# Source files
Expand All @@ -193,6 +194,8 @@ set(XEUS_CPP_HEADERS
include/xeus-cpp/xmagics.hpp
include/xeus-cpp/xoptions.hpp
include/xeus-cpp/xpreamble.hpp
include/xeus-cpp/xdebugger.hpp
include/xeus-cpp/xshared_memory.hpp
#src/xinspect.hpp
#src/xsystem.hpp
#src/xparser.hpp
Expand All @@ -207,6 +210,10 @@ set(XEUS_CPP_SRC
src/xparser.cpp
src/xutils.cpp
src/xmagics/os.cpp
src/xdebugger.cpp
src/xinternal_utils.cpp
src/xdebuglldb_client.cpp
src/xcppinterop_process.cpp
)

if(NOT EMSCRIPTEN)
Expand Down Expand Up @@ -458,11 +465,13 @@ include(CMakePackageConfigHelpers)

set(XEUS_CPP_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for xeus-cppConfig.cmake")

install(DIRECTORY ${XCPP_TAGFILES_DIR}
DESTINATION ${XEUS_CPP_DATA_DIR})
if(NOT EMSCRIPTEN)
install(DIRECTORY ${XCPP_TAGFILES_DIR}
DESTINATION ${XEUS_CPP_DATA_DIR})

install(DIRECTORY ${XCPP_TAGCONFS_DIR}
DESTINATION ${XEUS_CPP_CONF_DIR})
install(DIRECTORY ${XCPP_TAGCONFS_DIR}
DESTINATION ${XEUS_CPP_CONF_DIR})
endif()

# Install xeus-cpp and xeus-cpp-static
if (XEUS_CPP_BUILD_SHARED)
Expand Down Expand Up @@ -503,6 +512,65 @@ if(XEUS_CPP_BUILD_EXECUTABLE OR EMSCRIPTEN)
endif ()
endif ()

# cppinterop_process executable
# =============================

if (XEUS_CPP_BUILD_EXECUTABLE AND NOT EMSCRIPTEN)
# Define source files for cppinterop_process
set(CPPINTEROP_PROCESS_SRC
src/xcppinterop_process.cpp # You'll need to create this file
# Add any other source files needed for the process
${XEUS_CPP_HEADERS}
)

add_executable(cppinterop_process ${CPPINTEROP_PROCESS_SRC})

# Add xeus-cpp include directory
target_include_directories(cppinterop_process
PRIVATE
${XEUS_CPP_INCLUDE_DIR}
)

# Set common compile options
xeus_cpp_set_common_options(cppinterop_process)

target_compile_options(cppinterop_process PRIVATE
-gdwarf-4 # Generate DWARF-4 debug information
-O0 # Disable optimization
)

# Link with necessary libraries
target_link_libraries(cppinterop_process PRIVATE
clangCppInterOp
${CMAKE_THREAD_LIBS_INIT}
)

# Add any additional libraries needed for shared memory, etc.
if(CMAKE_DL_LIBS)
target_link_libraries(cppinterop_process PRIVATE ${CMAKE_DL_LIBS} util)
endif()

# Set target properties
set_target_properties(cppinterop_process PROPERTIES
INSTALL_RPATH_USE_LINK_PATH TRUE
)

if (APPLE)
set_target_properties(cppinterop_process PROPERTIES
MACOSX_RPATH ON
)
else()
set_target_properties(cppinterop_process PROPERTIES
BUILD_WITH_INSTALL_RPATH 1
SKIP_BUILD_RPATH FALSE
)
endif()

# Install the executable
install(TARGETS cppinterop_process
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

# Configure 'xeus-cppConfig.cmake' for a build tree
set(XEUS_CPP_CONFIG_CODE "####### Expanded from \@XEUS_CPP_CONFIG_CODE\@ #######\n")
set(XEUS_CPP_CONFIG_CODE "${XEUS_CPP_CONFIG_CODE}set(CMAKE_MODULE_PATH \"${CMAKE_CURRENT_SOURCE_DIR}/cmake;\${CMAKE_MODULE_PATH}\")\n")
Expand Down
86 changes: 86 additions & 0 deletions include/xeus-cpp/xdebugger.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/************************************************************************************
* Copyright (c) 2023, xeus-cpp contributors *
* Copyright (c) 2023, Johan Mabille, Loic Gouarin, Sylvain Corlay, Wolf Vollprecht *
* *
* 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_DEBUGGER_HPP
#define XEUS_CPP_DEBUGGER_HPP

Choose a reason for hiding this comment

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

warning: header guard does not follow preferred style [llvm-header-guard]

Suggested change
#define XEUS_CPP_DEBUGGER_HPP
#ifndef XEUS_CPP_XDEBUGGER_HPP
#define XEUS_CPP_XDEBUGGER_HPP


#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
#endif

#include <map>
#include <mutex>

Choose a reason for hiding this comment

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

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

Suggested change
#include <mutex>
#include <mutex>

#include <set>

Choose a reason for hiding this comment

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

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

Suggested change
#include <set>
#include <set>

#include <string>

Choose a reason for hiding this comment

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

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

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


#include "nlohmann/json.hpp"
#include "xeus-zmq/xdebugger_base.hpp"

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-zmq/xdebugger_base.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

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,

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:12:

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

const xeus::xconfiguration& config,

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:12:

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

const std::string& user_name,
const std::string& session_id,
const nl::json& debugger_config);

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:12:

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


virtual ~debugger();

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 variables_request_impl(const nl::json& message) override;

bool start_lldb();
bool start() override;
void stop() override;
xeus::xdebugger_info get_debugger_info() const override;

Choose a reason for hiding this comment

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

warning: function 'get_debugger_info' should be marked [[nodiscard]] [modernize-use-nodiscard]

Suggested change
xeus::xdebugger_info get_debugger_info() const override;
[[nodiscard]] xeus::xdebugger_info get_debugger_info() const override;

std::string get_cell_temporary_file(const std::string& code) const override;

Choose a reason for hiding this comment

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

warning: function 'get_cell_temporary_file' should be marked [[nodiscard]] [modernize-use-nodiscard]

Suggested change
std::string get_cell_temporary_file(const std::string& code) const override;
[[nodiscard]] 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;

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;
std::string m_lldbdap_port;
nl::json m_debugger_config;
bool m_is_running;
int m_tcp_socket;
bool m_tcp_connected;
};

XEUS_CPP_API
std::unique_ptr<xeus::xdebugger> make_cpp_debugger(xeus::xcontext& context,

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::unique_ptr" is directly included [misc-include-cleaner]

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

- #ifdef __GNUC__
+ #include <memory>
+ #ifdef __GNUC__

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" is directly included [misc-include-cleaner]

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

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

const xeus::xconfiguration& config,
const std::string& user_name,
const std::string& session_id,
const nl::json& debugger_config);
}

Choose a reason for hiding this comment

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

warning: namespace 'xcpp' not terminated with a closing comment [llvm-namespace-comment]

Suggested change
}
} // namespace xcpp
Additional context

include/xeus-cpp/xdebugger.hpp:26: namespace 'xcpp' starts here

namespace xcpp
          ^


#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

#endif
7 changes: 7 additions & 0 deletions include/xeus-cpp/xinterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ namespace nl = nlohmann;

namespace xcpp
{
class CppInterOpClient;
class XEUS_CPP_API interpreter : public xeus::xinterpreter
{
public:

interpreter(int argc, const char* const* argv);
virtual ~interpreter();

void set_cppinterop_client(std::shared_ptr<CppInterOpClient> client);

void publish_stdout(const std::string&);
void publish_stderr(const std::string&);

Expand All @@ -62,6 +65,8 @@ namespace xcpp

void shutdown_request_impl() override;

nl::json internal_request_impl(const nl::json& content) override;

nl::json get_error_reply(
const std::string& ename,
const std::string& evalue,
Expand All @@ -85,6 +90,8 @@ namespace xcpp

xoutput_buffer m_cout_buffer;
xoutput_buffer m_cerr_buffer;

std::shared_ptr<CppInterOpClient> m_cppinterop_client;
};
}

Expand Down
147 changes: 147 additions & 0 deletions include/xeus-cpp/xshared_memory.hpp
Original file line number Diff line number Diff line change
@@ -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


#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>

#include <cstring>
#include <atomic>
#include <vector>
#include <sstream>

struct SharedMemoryBuffer {
// FIXED: Reduced buffer sizes to fit within 64KB system limit
// Total struct size should be around 52KB, leaving room for other fields
static constexpr size_t MAX_CODE_SIZE = 16 * 1024; // 16KB for code
static constexpr size_t MAX_OUTPUT_SIZE = 16 * 1024; // 16KB for output
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 {
               ^

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>

NONE = 0,
PROCESS_CODE,
CODE_COMPLETE,
EVALUATE,
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 {
               ^

NONE = 0,
SUCCESS,
COMPILATION_ERROR,
RUNTIME_ERROR,
SYSTEM_ERROR
};

std::atomic<bool> request_ready{false};
std::atomic<bool> response_ready{false};
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];
    ^

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;
    ^


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
    ^

uint32_t completion_length;

void reset() {
request_ready.store(false, std::memory_order_relaxed);
response_ready.store(false, std::memory_order_relaxed);
request_type.store(RequestType::NONE, std::memory_order_relaxed);
response_status.store(ResponseStatus::NONE, std::memory_order_relaxed);
code_length = 0;
output_length = 0;
error_length = 0;
completion_length = 0;
cursor_pos = 0;
compilation_result = false;
evaluation_result = 0;

memset(code_buffer, 0, MAX_CODE_SIZE);
memset(output_buffer, 0, MAX_OUTPUT_SIZE);
memset(error_buffer, 0, MAX_ERROR_SIZE);
memset(completion_buffer, 0, MAX_COMPLETION_SIZE);
}

void set_code(const std::string& code) {
code_length = std::min(code.length(), MAX_CODE_SIZE - 1);
memcpy(code_buffer, code.c_str(), code_length);
code_buffer[code_length] = '\0';
}

std::string get_code() const {
return std::string(code_buffer, code_length);
}

void set_output(const std::string& output) {
output_length = std::min(output.length(), MAX_OUTPUT_SIZE - 1);
memcpy(output_buffer, output.c_str(), output_length);
output_buffer[output_length] = '\0';
}

std::string get_output() const {
return std::string(output_buffer, output_length);
}

void set_error(const std::string& error) {
error_length = std::min(error.length(), MAX_ERROR_SIZE - 1);
memcpy(error_buffer, error.c_str(), error_length);
error_buffer[error_length] = '\0';
}

std::string get_error() const {
return std::string(error_buffer, error_length);
}

void set_completions(const std::vector<std::string>& completions) {
std::string combined;
for (const auto& comp : completions) {
if (!combined.empty()) combined += "\n";
combined += comp;
}
completion_length = std::min(combined.length(), MAX_COMPLETION_SIZE - 1);
memcpy(completion_buffer, combined.c_str(), completion_length);
completion_buffer[completion_length] = '\0';
}

std::vector<std::string> get_completions() const {
std::vector<std::string> result;
std::string data(completion_buffer, completion_length);
std::istringstream iss(data);
std::string line;
while (std::getline(iss, line)) {
result.push_back(line);
}
return result;
}

// Helper function to get the total size of this struct
static constexpr size_t total_size() {
return sizeof(SharedMemoryBuffer);
}

// Helper function to check if a given size can accommodate this struct
static bool fits_in_size(size_t available_size) {
return available_size >= sizeof(SharedMemoryBuffer);
}
};

// Static assertion to ensure the struct fits in reasonable shared memory limits
static_assert(sizeof(SharedMemoryBuffer) <= 65536,
"SharedMemoryBuffer too large for typical shared memory limits");

// Print size information for debugging
inline void print_buffer_size_info() {
std::cout << "SharedMemoryBuffer size breakdown:" << std::endl;
std::cout << " Code buffer: " << SharedMemoryBuffer::MAX_CODE_SIZE << " bytes" << std::endl;
std::cout << " Output buffer: " << SharedMemoryBuffer::MAX_OUTPUT_SIZE << " bytes" << std::endl;
std::cout << " Error buffer: " << SharedMemoryBuffer::MAX_ERROR_SIZE << " bytes" << std::endl;
std::cout << " Completion buffer: " << SharedMemoryBuffer::MAX_COMPLETION_SIZE << " bytes" << std::endl;
std::cout << " Total struct size: " << sizeof(SharedMemoryBuffer) << " bytes" << std::endl;
std::cout << " Fits in 64KB: " << (sizeof(SharedMemoryBuffer) <= 65536 ? "YES" : "NO") << std::endl;
}
Loading
Loading