Skip to content

Commit 4b284a2

Browse files
author
kr-2003
committed
oop/debug kernels & xdebugger.hpp
1 parent 7a3a24b commit 4b284a2

File tree

14 files changed

+262
-0
lines changed

14 files changed

+262
-0
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ 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+
configure_native_kernel("/share/jupyter/kernels/xcpp17-debugger/")
184+
configure_native_kernel("/share/jupyter/kernels/xcpp20-debugger/")
185+
configure_native_kernel("/share/jupyter/kernels/xcpp23-debugger/")
183186
endif()
184187

185188
# Source files

include/xeus-cpp/xdebugger.hpp

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/************************************************************************************
2+
* Copyright (c) 2023, xeus-cpp contributors *
3+
* *
4+
* Distributed under the terms of the BSD 3-Clause License. *
5+
* *
6+
* The full license is in the file LICENSE, distributed with this software. *
7+
************************************************************************************/
8+
9+
#ifndef XEUS_CPP_DEBUGGER_HPP
10+
#define XEUS_CPP_DEBUGGER_HPP
11+
12+
#ifdef __GNUC__
13+
#pragma GCC diagnostic push
14+
#pragma GCC diagnostic ignored "-Wattributes"
15+
#endif
16+
17+
#include <map>
18+
#include <mutex>
19+
#include <set>
20+
#include <string>
21+
22+
#include "nlohmann/json.hpp"
23+
#include "xeus-cpp/xinterpreter.hpp"
24+
#include "xeus-zmq/xdebugger_base.hpp"
25+
#include "xeus_cpp_config.hpp"
26+
27+
namespace xcpp
28+
{
29+
class xdebuglldb_client;
30+
31+
class XEUS_CPP_API debugger : public xeus::xdebugger_base
32+
{
33+
public:
34+
35+
using base_type = xeus::xdebugger_base;
36+
37+
debugger(
38+
xeus::xcontext& context,
39+
const xeus::xconfiguration& config,
40+
const std::string& user_name,
41+
const std::string& session_id,
42+
const nl::json& debugger_config
43+
);
44+
45+
virtual ~debugger();
46+
47+
private:
48+
49+
nl::json inspect_variables_request(const nl::json& message);
50+
nl::json stack_trace_request(const nl::json& message);
51+
nl::json attach_request(const nl::json& message);
52+
nl::json configuration_done_request(const nl::json& message);
53+
nl::json set_breakpoints_request(const nl::json& message);
54+
nl::json dump_cell_request(const nl::json& message);
55+
nl::json rich_inspect_variables_request(const nl::json& message);
56+
nl::json copy_to_globals_request(const nl::json& message);
57+
nl::json source_request(const nl::json& message);
58+
59+
bool get_variable_info_from_lldb(
60+
const std::string& var_name,
61+
int frame_id,
62+
nl::json& data,
63+
nl::json& metadata,
64+
int sequence
65+
);
66+
void get_container_info(
67+
const std::string& var_name,
68+
int frame_id,
69+
const std::string& var_type,
70+
nl::json& data,
71+
nl::json& metadata,
72+
int sequence,
73+
int size
74+
);
75+
bool is_container_type(const std::string& type) const;
76+
77+
bool start_lldb();
78+
bool start() override;
79+
void stop() override;
80+
xeus::xdebugger_info get_debugger_info() const override;
81+
virtual std::string get_cell_temporary_file(const std::string& code) const override;
82+
83+
bool connect_to_lldb_tcp();
84+
std::string send_dap_message(const nl::json& message);
85+
std::string receive_dap_response();
86+
87+
xdebuglldb_client* p_debuglldb_client;
88+
std::string m_lldb_host;
89+
std::string m_lldb_port;
90+
nl::json m_debugger_config;
91+
bool m_is_running;
92+
int m_tcp_socket;
93+
bool m_tcp_connected;
94+
pid_t jit_process_pid;
95+
96+
using breakpoint_list_t = std::map<std::string, std::vector<nl::json>>;
97+
breakpoint_list_t m_breakpoint_list;
98+
99+
xcpp::interpreter* m_interpreter;
100+
101+
std::unordered_map<std::string, std::vector<std::string>> m_hash_to_sequential;
102+
std::unordered_map<std::string, std::string> m_sequential_to_hash;
103+
104+
bool m_copy_to_globals_available;
105+
};
106+
107+
XEUS_CPP_API
108+
std::unique_ptr<xeus::xdebugger> make_cpp_debugger(
109+
xeus::xcontext& context,
110+
const xeus::xconfiguration& config,
111+
const std::string& user_name,
112+
const std::string& session_id,
113+
const nl::json& debugger_config
114+
);
115+
}
116+
117+
#ifdef __GNUC__
118+
#pragma GCC diagnostic pop
119+
#endif
120+
121+
#endif
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"display_name": "C++17-Debugger",
3+
"env": {
4+
"PATH":"@XEUS_CPP_PATH@",
5+
"LD_LIBRARY_PATH":"@XEUS_CPP_LD_LIBRARY_PATH@"
6+
},
7+
"argv": [
8+
"@XEUS_CPP_KERNELSPEC_PATH@xcpp",
9+
"-f",
10+
"{connection_file}",
11+
"-g",
12+
"-O0",
13+
"--use-oop-jit",
14+
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
15+
"-I", "@XEUS_CPP_INCLUDE_DIR@",
16+
"-std=c++17"
17+
],
18+
"language": "cpp",
19+
"metadata": {"debugger": true
20+
}
21+
}
1.48 KB
Loading
3.04 KB
Loading
Lines changed: 25 additions & 0 deletions
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"display_name": "C++20-Debugger",
3+
"env": {
4+
"PATH":"@XEUS_CPP_PATH@",
5+
"LD_LIBRARY_PATH":"@XEUS_CPP_LD_LIBRARY_PATH@"
6+
},
7+
"argv": [
8+
"@XEUS_CPP_KERNELSPEC_PATH@xcpp",
9+
"-f",
10+
"{connection_file}",
11+
"-g",
12+
"-O0",
13+
"--use-oop-jit",
14+
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
15+
"-I", "@XEUS_CPP_INCLUDE_DIR@",
16+
"-std=c++20"
17+
],
18+
"language": "cpp",
19+
"metadata": {"debugger": true
20+
}
21+
}
1.48 KB
Loading
3.04 KB
Loading
Lines changed: 25 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)