Skip to content

Commit 78e14aa

Browse files
author
kr-2003
committed
added XEUS_CPP_USE_DEBUGGER var
1 parent 73fd7d5 commit 78e14aa

File tree

3 files changed

+75
-76
lines changed

3 files changed

+75
-76
lines changed

CMakeLists.txt

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +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/")
183+
if(XEUS_CPP_USE_DEBUGGER)
184+
configure_native_kernel("/share/jupyter/kernels/xcpp17-debugger/")
185+
endif()
184186
endif()
185187

186188
# Source files
@@ -197,12 +199,17 @@ set(XEUS_CPP_HEADERS
197199
include/xeus-cpp/xmagics.hpp
198200
include/xeus-cpp/xoptions.hpp
199201
include/xeus-cpp/xpreamble.hpp
200-
include/xeus-cpp/xdebugger.hpp
201202
#src/xinspect.hpp
202203
#src/xsystem.hpp
203204
#src/xparser.hpp
204205
)
205206

207+
if(XEUS_CPP_USE_DEBUGGER)
208+
list(APPEND XEUS_CPP_HEADERS
209+
include/xeus-cpp/xdebugger.hpp
210+
)
211+
endif()
212+
206213
set(XEUS_CPP_SRC
207214
src/xholder.cpp
208215
src/xinput.cpp
@@ -212,9 +219,6 @@ set(XEUS_CPP_SRC
212219
src/xparser.cpp
213220
src/xutils.cpp
214221
src/xmagics/os.cpp
215-
src/xdebugger.cpp
216-
src/xinternal_utils.cpp
217-
src/xdebuglldb_client.cpp
218222
)
219223

220224
if(NOT EMSCRIPTEN)
@@ -223,6 +227,14 @@ if(NOT EMSCRIPTEN)
223227
)
224228
endif()
225229

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+
226238
if(EMSCRIPTEN)
227239
list(APPEND XEUS_CPP_SRC src/xinterpreter_wasm.cpp)
228240
endif()
@@ -473,13 +485,11 @@ include(CMakePackageConfigHelpers)
473485

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

476-
if(NOT EMSCRIPTEN)
477-
install(DIRECTORY ${XCPP_TAGFILES_DIR}
478-
DESTINATION ${XEUS_CPP_DATA_DIR})
488+
install(DIRECTORY ${XCPP_TAGFILES_DIR}
489+
DESTINATION ${XEUS_CPP_DATA_DIR})
479490

480-
install(DIRECTORY ${XCPP_TAGCONFS_DIR}
481-
DESTINATION ${XEUS_CPP_CONF_DIR})
482-
endif()
491+
install(DIRECTORY ${XCPP_TAGCONFS_DIR}
492+
DESTINATION ${XEUS_CPP_CONF_DIR})
483493

484494
# Install xeus-cpp and xeus-cpp-static
485495
if (XEUS_CPP_BUILD_SHARED)
@@ -554,3 +564,9 @@ if(EMSCRIPTEN)
554564
"$<TARGET_FILE_DIR:xcpp>/xcpp.data"
555565
DESTINATION ${CMAKE_INSTALL_BINDIR})
556566
endif ()
567+
568+
if(XEUS_CPP_USE_DEBUGGER)
569+
add_definitions(
570+
-DXEUS_CPP_USE_DEBUGGER
571+
)
572+
endif()

src/main.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
#endif
2121

2222
#include "nlohmann/json.hpp"
23-
#include "xeus/xhelper.hpp"
24-
#include "xeus/xkernel.hpp"
25-
#include "xeus/xkernel_configuration.hpp"
23+
#include <xeus/xhelper.hpp>
24+
#include <xeus/xkernel.hpp>
25+
#include <xeus/xkernel_configuration.hpp>
2626
#include "xeus-zmq/xzmq_context.hpp"
27-
#include "xeus-zmq/xserver_zmq.hpp"
27+
#include <xeus-zmq/xserver_zmq.hpp>
2828
#include "xeus-cpp/xeus_cpp_config.hpp"
2929
#include "xeus-cpp/xinterpreter.hpp"
3030
#include "xeus-cpp/xutils.hpp"
@@ -60,11 +60,12 @@ int main(int argc, char* argv[])
6060
#endif
6161
signal(SIGINT, xcpp::stop_handler);
6262

63-
// Debugger configuration for LLDB-DAP
63+
#ifdef XEUS_CPP_USE_DEBUGGER
6464
nl::json debugger_config;
6565
debugger_config["lldb"]["initCommands"] = {
6666
"settings set plugin.jit-loader.gdb.enable on"
6767
};
68+
#endif
6869

6970
std::string file_name = xeus::extract_filename(argc, argv);
7071
auto interpreter = std::make_unique<xcpp::interpreter>(argc, argv);
@@ -85,9 +86,13 @@ int main(int argc, char* argv[])
8586
xeus::make_console_logger(
8687
xeus::xlogger::msg_type,
8788
xeus::make_file_logger(xeus::xlogger::content, "xeus.log")
89+
#ifdef XEUS_CPP_USE_DEBUGGER
8890
),
8991
xcpp::make_cpp_debugger,
9092
debugger_config
93+
#else
94+
)
95+
#endif
9196
);
9297

9398
std::clog << "Starting xcpp kernel...\n\n"
@@ -108,9 +113,13 @@ int main(int argc, char* argv[])
108113
xeus::make_console_logger(
109114
xeus::xlogger::msg_type,
110115
xeus::make_file_logger(xeus::xlogger::content, "xeus.log")
116+
#ifdef XEUS_CPP_USE_DEBUGGER
111117
),
112118
xcpp::make_cpp_debugger,
113119
debugger_config
120+
#else
121+
)
122+
#endif
114123
);
115124

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

src/xinterpreter.cpp

Lines changed: 34 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -29,89 +29,69 @@ using Args = std::vector<const char*>;
2929

3030
void* createInterpreter(const Args& ExtraArgs = {})
3131
{
32-
Args ClangArgs = {/*"-xc++"*/ "-v"};
33-
if (std::find_if(
34-
ExtraArgs.begin(),
35-
ExtraArgs.end(),
36-
[](const std::string& s)
37-
{
38-
return s == "-resource-dir";
39-
}
40-
)
41-
== ExtraArgs.end())
42-
{
32+
Args ClangArgs = {/*"-xc++"*/"-v"};
33+
if (std::find_if(ExtraArgs.begin(), ExtraArgs.end(), [](const std::string& s) {
34+
return s == "-resource-dir";}) == ExtraArgs.end()) {
4335
std::string resource_dir = Cpp::DetectResourceDir();
44-
if (!resource_dir.empty())
45-
{
36+
if (!resource_dir.empty()) {
4637
ClangArgs.push_back("-resource-dir");
4738
ClangArgs.push_back(resource_dir.c_str());
48-
}
49-
else
50-
{
39+
} else {
5140
std::cerr << "Failed to detect the resource-dir\n";
5241
}
5342
}
5443
std::vector<std::string> CxxSystemIncludes;
5544
Cpp::DetectSystemCompilerIncludePaths(CxxSystemIncludes);
56-
for (const std::string& CxxInclude : CxxSystemIncludes)
57-
{
45+
for (const std::string& CxxInclude : CxxSystemIncludes) {
5846
ClangArgs.push_back("-isystem");
5947
ClangArgs.push_back(CxxInclude.c_str());
6048
}
6149
ClangArgs.insert(ClangArgs.end(), ExtraArgs.begin(), ExtraArgs.end());
6250

6351
// FIXME: We should process the kernel input options and conditionally pass
6452
// the gpu args here.
65-
if (std::find_if(
66-
ExtraArgs.begin(),
67-
ExtraArgs.end(),
68-
[](const std::string& s)
69-
{
70-
return s == "-gdwarf-4";
71-
}
72-
)
73-
== ExtraArgs.end())
74-
{
53+
if (std::find_if(ExtraArgs.begin(), ExtraArgs.end(), [](const std::string& s) {
54+
return s == "-gdwarf-4";}) == ExtraArgs.end()) {
7555
// If no debugger option, then use the non-OOP JIT execution.
7656
return Cpp::CreateInterpreter(ClangArgs /*, {"-cuda"}*/);
7757
}
7858

79-
// If debugger option is set, then use the OOP JIT execution.
59+
#ifdef XEUS_CPP_USE_DEBUGGER
60+
// If debugger option is set, then use the OOP JIT execution.
8061
return Cpp::CreateInterpreter(ClangArgs, {}, true);
62+
#else
63+
return Cpp::CreateInterpreter(ClangArgs);
64+
#endif
8165
}
8266

8367
using namespace std::placeholders;
8468

8569
namespace xcpp
8670
{
87-
struct StreamRedirectRAII
88-
{
89-
std::string &out, &err;
90-
91-
StreamRedirectRAII(std::string& o, std::string& e)
92-
: out(o)
93-
, err(e)
94-
{
95-
Cpp::BeginStdStreamCapture(Cpp::kStdErr);
96-
Cpp::BeginStdStreamCapture(Cpp::kStdOut);
97-
}
98-
99-
~StreamRedirectRAII()
100-
{
101-
out = Cpp::EndStdStreamCapture();
102-
err = Cpp::EndStdStreamCapture();
103-
}
71+
struct StreamRedirectRAII {
72+
std::string &err;
73+
StreamRedirectRAII(std::string &e) : err(e) {
74+
Cpp::BeginStdStreamCapture(Cpp::kStdErr);
75+
Cpp::BeginStdStreamCapture(Cpp::kStdOut);
76+
}
77+
~StreamRedirectRAII() {
78+
std::string out = Cpp::EndStdStreamCapture();
79+
err = Cpp::EndStdStreamCapture();
80+
std::cout << out;
81+
}
10482
};
10583

10684
void interpreter::configure_impl()
10785
{
10886
xeus::register_interpreter(this);
10987
}
11088

89+
#ifdef XEUS_CPP_USE_DEBUGGER
11190
pid_t interpreter::get_current_pid()
11291
{
11392
return Cpp::GetExecutorPID();
11493
}
94+
#endif
11595

11696
static std::string get_stdopt()
11797
{
@@ -140,8 +120,8 @@ __get_cxx_version ()
140120
return std::to_string(cxx_version);
141121
}
142122

143-
interpreter::interpreter(int argc, const char* const* argv)
144-
: xmagics()
123+
interpreter::interpreter(int argc, const char* const* argv):
124+
xmagics()
145125
, p_cout_strbuf(nullptr)
146126
, p_cerr_strbuf(nullptr)
147127
, m_cout_buffer(std::bind(&interpreter::publish_stdout, this, _1))
@@ -202,12 +182,12 @@ __get_cxx_version ()
202182
std::cerr.rdbuf(&null);
203183
}
204184

205-
std::string out, err;
185+
std::string err;
206186

207187
// Attempt normal evaluation
208188
try
209189
{
210-
StreamRedirectRAII R(out, err);
190+
StreamRedirectRAII R(err);
211191
compilation_result = Cpp::Process(code.c_str());
212192
}
213193
catch (std::exception& e)
@@ -229,10 +209,6 @@ __get_cxx_version ()
229209
evalue = "Compilation error! " + err;
230210
std::cerr << err;
231211
}
232-
else
233-
{
234-
std::cout << out;
235-
}
236212

237213
// Flush streams
238214
std::cout << std::flush;
@@ -254,8 +230,7 @@ __get_cxx_version ()
254230
//
255231
// JupyterLab displays the "{ename}: {evalue}" if the traceback is
256232
// empty.
257-
if (evalue.size() < 4)
258-
{
233+
if (evalue.size() < 4) {
259234
ename = " ";
260235
}
261236
std::vector<std::string> traceback({ename + evalue});
@@ -301,8 +276,7 @@ __get_cxx_version ()
301276

302277
Cpp::CodeComplete(results, code.c_str(), 1, _cursor_pos + 1);
303278

304-
return xeus::create_complete_reply(
305-
results /*matches*/,
279+
return xeus::create_complete_reply(results /*matches*/,
306280
cursor_pos - to_complete.length() /*cursor_start*/,
307281
cursor_pos /*cursor_end*/
308282
);
@@ -514,11 +488,11 @@ __get_cxx_version ()
514488

515489
void interpreter::init_preamble()
516490
{
517-
// NOLINTBEGIN(cppcoreguidelines-owning-memory)
491+
//NOLINTBEGIN(cppcoreguidelines-owning-memory)
518492
preamble_manager.register_preamble("introspection", std::make_unique<xintrospection>());
519493
preamble_manager.register_preamble("magics", std::make_unique<xmagics_manager>());
520494
preamble_manager.register_preamble("shell", std::make_unique<xsystem>());
521-
// NOLINTEND(cppcoreguidelines-owning-memory)
495+
//NOLINTEND(cppcoreguidelines-owning-memory)
522496
}
523497

524498
void interpreter::init_magic()

0 commit comments

Comments
 (0)