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
0 commit comments