Skip to content

Commit 90df737

Browse files
author
kr-2003
committed
added breakpoints
1 parent 3c6be4e commit 90df737

File tree

9 files changed

+137
-201
lines changed

9 files changed

+137
-201
lines changed

CMakeLists.txt

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ else()
180180
configure_native_kernel("/share/jupyter/kernels/xcpp17/")
181181
configure_native_kernel("/share/jupyter/kernels/xcpp20/")
182182
configure_native_kernel("/share/jupyter/kernels/xcpp23/")
183-
if(XEUS_CPP_USE_DEBUGGER)
184-
configure_native_kernel("/share/jupyter/kernels/xcpp17-debugger/")
185-
endif()
183+
configure_native_kernel("/share/jupyter/kernels/xcpp17-debugger/")
186184
endif()
187185

188186
# Source files
@@ -199,17 +197,12 @@ set(XEUS_CPP_HEADERS
199197
include/xeus-cpp/xmagics.hpp
200198
include/xeus-cpp/xoptions.hpp
201199
include/xeus-cpp/xpreamble.hpp
200+
include/xeus-cpp/xdebugger.hpp
202201
#src/xinspect.hpp
203202
#src/xsystem.hpp
204203
#src/xparser.hpp
205204
)
206205

207-
if(XEUS_CPP_USE_DEBUGGER)
208-
list(APPEND XEUS_CPP_HEADERS
209-
include/xeus-cpp/xdebugger.hpp
210-
)
211-
endif()
212-
213206
set(XEUS_CPP_SRC
214207
src/xholder.cpp
215208
src/xinput.cpp
@@ -219,6 +212,9 @@ set(XEUS_CPP_SRC
219212
src/xparser.cpp
220213
src/xutils.cpp
221214
src/xmagics/os.cpp
215+
src/xdebugger.cpp
216+
src/xdebuglldb_client.cpp
217+
src/xinternal_utils.cpp
222218
)
223219

224220
if(NOT EMSCRIPTEN)
@@ -227,14 +223,6 @@ if(NOT EMSCRIPTEN)
227223
)
228224
endif()
229225

230-
if(XEUS_CPP_USE_DEBUGGER)
231-
list(APPEND XEUS_CPP_SRC
232-
src/xdebugger.cpp
233-
src/xdebuglldb_client.cpp
234-
src/xinternal_utils.cpp
235-
)
236-
endif()
237-
238226
if(EMSCRIPTEN)
239227
list(APPEND XEUS_CPP_SRC src/xinterpreter_wasm.cpp)
240228
endif()
@@ -564,9 +552,3 @@ if(EMSCRIPTEN)
564552
"$<TARGET_FILE_DIR:xcpp>/xcpp.data"
565553
DESTINATION ${CMAKE_INSTALL_BINDIR})
566554
endif ()
567-
568-
if(XEUS_CPP_USE_DEBUGGER)
569-
add_definitions(
570-
-DXEUS_CPP_USE_DEBUGGER
571-
)
572-
endif()

include/xeus-cpp/xdebugger.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "nlohmann/json.hpp"
2424
#include "xeus-zmq/xdebugger_base.hpp"
2525
#include "xeus_cpp_config.hpp"
26+
#include "xeus-cpp/xinterpreter.hpp"
2627

2728
namespace xcpp
2829
{
@@ -48,14 +49,16 @@ namespace xcpp
4849
nl::json stack_trace_request(const nl::json& message);
4950
nl::json attach_request(const nl::json& message);
5051
nl::json configuration_done_request(const nl::json& message);
52+
nl::json set_breakpoints_request(const nl::json& message);
53+
nl::json dump_cell_request(const nl::json& message);
5154

5255
nl::json variables_request_impl(const nl::json& message) override;
5356

5457
bool start_lldb();
5558
bool start() override;
5659
void stop() override;
5760
xeus::xdebugger_info get_debugger_info() const override;
58-
std::string get_cell_temporary_file(const std::string& code) const override;
61+
virtual std::string get_cell_temporary_file(const std::string& code) const override;
5962

6063
bool connect_to_lldb_tcp();
6164
std::string send_dap_message(const nl::json& message);
@@ -64,12 +67,19 @@ namespace xcpp
6467
xdebuglldb_client* p_debuglldb_client;
6568
std::string m_lldb_host;
6669
std::string m_lldb_port;
67-
std::string m_lldbdap_port;
6870
nl::json m_debugger_config;
6971
bool m_is_running;
7072
int m_tcp_socket;
7173
bool m_tcp_connected;
7274
pid_t jit_process_pid;
75+
76+
using breakpoint_list_t = std::map<std::string, std::vector<nl::json>>;
77+
breakpoint_list_t m_breakpoint_list;
78+
79+
xcpp::interpreter* m_interpreter;
80+
81+
std::unordered_map<std::string, std::vector<std::string>> m_hash_to_sequential;
82+
std::unordered_map<std::string, std::string> m_sequential_to_hash;
7383
};
7484

7585
XEUS_CPP_API

include/xeus-cpp/xinterpreter.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ namespace xcpp
4242

4343
static pid_t get_current_pid();
4444

45+
std::vector<int> get_execution_count(const std::string& code) const
46+
{
47+
auto it = m_code_to_execution_count_map.find(code);
48+
if (it != m_code_to_execution_count_map.end())
49+
{
50+
return it->second;
51+
}
52+
return {};
53+
}
54+
4555
private:
4656

4757
void configure_impl() override;
@@ -64,8 +74,6 @@ namespace xcpp
6474

6575
void shutdown_request_impl() override;
6676

67-
nl::json internal_request_impl(const nl::json& content) override;
68-
6977
nl::json get_error_reply(
7078
const std::string& ename,
7179
const std::string& evalue,
@@ -89,6 +97,8 @@ namespace xcpp
8997

9098
xoutput_buffer m_cout_buffer;
9199
xoutput_buffer m_cerr_buffer;
100+
101+
std::map<std::string, std::vector<int>> m_code_to_execution_count_map;
92102
};
93103
}
94104

share/jupyter/kernels/xcpp17-debugger/kernel.json.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"@XEUS_CPP_KERNELSPEC_PATH@xcpp",
99
"-f",
1010
"{connection_file}",
11-
"-gdwarf-4",
11+
"-g",
1212
"-O0",
1313
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
1414
"-I", "@XEUS_CPP_INCLUDE_DIR@",

src/main.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,15 @@ int main(int argc, char* argv[])
6060
#endif
6161
signal(SIGINT, xcpp::stop_handler);
6262

63-
#ifdef XEUS_CPP_USE_DEBUGGER
63+
std::string file_name = xeus::extract_filename(argc, argv);
64+
auto interpreter = std::make_unique<xcpp::interpreter>(argc, argv);
65+
std::unique_ptr<xeus::xcontext> context = xeus::make_zmq_context();
66+
6467
nl::json debugger_config;
6568
debugger_config["lldb"]["initCommands"] = {
6669
"settings set plugin.jit-loader.gdb.enable on"
6770
};
68-
#endif
69-
70-
std::string file_name = xeus::extract_filename(argc, argv);
71-
auto interpreter = std::make_unique<xcpp::interpreter>(argc, argv);
72-
std::unique_ptr<xeus::xcontext> context = xeus::make_zmq_context();
71+
debugger_config["interpreter_ptr"] = reinterpret_cast<std::uintptr_t>(interpreter.get());
7372

7473
if (!file_name.empty())
7574
{
@@ -86,13 +85,9 @@ int main(int argc, char* argv[])
8685
xeus::make_console_logger(
8786
xeus::xlogger::msg_type,
8887
xeus::make_file_logger(xeus::xlogger::content, "xeus.log")
89-
#ifdef XEUS_CPP_USE_DEBUGGER
9088
),
9189
xcpp::make_cpp_debugger,
9290
debugger_config
93-
#else
94-
)
95-
#endif
9691
);
9792

9893
std::clog << "Starting xcpp kernel...\n\n"
@@ -113,13 +108,9 @@ int main(int argc, char* argv[])
113108
xeus::make_console_logger(
114109
xeus::xlogger::msg_type,
115110
xeus::make_file_logger(xeus::xlogger::content, "xeus.log")
116-
#ifdef XEUS_CPP_USE_DEBUGGER
117111
),
118112
xcpp::make_cpp_debugger,
119113
debugger_config
120-
#else
121-
)
122-
#endif
123114
);
124115

125116
std::cout << "Getting config" << std::endl;

0 commit comments

Comments
 (0)