diff --git a/src/debug_clang.cc b/src/debug_clang.cc index 143cba4..b5fe479 100644 --- a/src/debug_clang.cc +++ b/src/debug_clang.cc @@ -357,7 +357,7 @@ void Debug::Clang::select_frame(uint32_t frame_index, uint32_t thread_index_id) } } -void Debug::Clang::delete_debug() { +void Debug::Clang::cancel() { kill(); if(debug_thread.joinable()) debug_thread.join(); diff --git a/src/debug_clang.h b/src/debug_clang.h index 0e9001a..3be3c1b 100644 --- a/src/debug_clang.h +++ b/src/debug_clang.h @@ -55,7 +55,7 @@ namespace Debug { std::vector get_variables(); void select_frame(uint32_t frame_index, uint32_t thread_index_id=0); - void delete_debug(); //can't use delete as function name + void cancel(); std::string get_value(const std::string &variable, const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index); std::string get_return_value(const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index); diff --git a/src/project.cc b/src/project.cc index ed4634d..43dc663 100644 --- a/src/project.cc +++ b/src/project.cc @@ -504,9 +504,9 @@ void Project::Clang::debug_write(const std::string &buffer) { Debug::Clang::get().write(buffer); } -void Project::Clang::debug_delete() { +void Project::Clang::debug_cancel() { std::unique_lock lock(debug_start_mutex); - Debug::Clang::get().delete_debug(); + Debug::Clang::get().cancel(); } #endif diff --git a/src/project.h b/src/project.h index 3e4cc8e..f12556d 100644 --- a/src/project.h +++ b/src/project.h @@ -52,7 +52,7 @@ namespace Project { virtual void debug_remove_breakpoint(const boost::filesystem::path &file_path, int line_nr, int line_count) {} virtual bool debug_is_running() { return false; } virtual void debug_write(const std::string &buffer) {} - virtual void debug_delete() {} + virtual void debug_cancel() {} }; class Clang : public Base { @@ -83,7 +83,7 @@ namespace Project { void debug_remove_breakpoint(const boost::filesystem::path &file_path, int line_nr, int line_count) override; bool debug_is_running() override; void debug_write(const std::string &buffer) override; - void debug_delete() override; + void debug_cancel() override; #endif }; diff --git a/src/window.cc b/src/window.cc index dc0099c..a8b67f5 100644 --- a/src/window.cc +++ b/src/window.cc @@ -910,7 +910,7 @@ bool Window::on_delete_event(GdkEventAny *event) { Terminal::get().kill_async_processes(); #ifdef JUCI_ENABLE_DEBUG if(Project::current) - Project::current->debug_delete(); + Project::current->debug_cancel(); #endif return false; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 31c8f4d..1c3bb94 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,4 @@ -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-access-control -DJUCI_TESTS_PATH=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\"") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-access-control -DJUCI_BUILD_PATH=\\\"${CMAKE_BINARY_DIR}\\\" -DJUCI_TESTS_PATH=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\"") set(global_includes ${Boost_INCLUDE_DIRS} @@ -52,3 +52,11 @@ add_executable(source_clang_test source_clang_test.cc $ $) target_link_libraries(source_clang_test ${global_libraries}) add_test(source_clang_test source_clang_test) + +if(LIBLLDB_FOUND) + add_executable(lldb_test lldb_test.cc + $ $) + target_link_libraries(lldb_test ${global_libraries}) + add_test(lldb_test lldb_test) + add_subdirectory("lldb_test_files") +endif() diff --git a/tests/lldb_test.cc b/tests/lldb_test.cc new file mode 100644 index 0000000..49d2332 --- /dev/null +++ b/tests/lldb_test.cc @@ -0,0 +1,71 @@ +#include +#include "debug_clang.h" +#include +#include +#include + +int main() { + auto build_path=boost::filesystem::canonical(JUCI_BUILD_PATH); + auto exec_path=build_path/"tests"/"lldb_test_files"/"lldb_test_executable"; + g_assert(boost::filesystem::exists(exec_path)); + + auto tests_path=boost::filesystem::canonical(JUCI_TESTS_PATH); + auto source_path=tests_path/"lldb_test_files"/"main.cpp"; + g_assert(boost::filesystem::exists(source_path)); + + std::vector > breakpoints; + breakpoints.emplace_back(source_path, 2); + + std::atomic exited(false); + int exit_status; + std::atomic line_nr(0); + std::thread debug_thread([&] { + Debug::Clang::get().start(exec_path.string(), "", breakpoints, [&](int exit_status_){ + exit_status=exit_status_; + exited=true; + }, [](const std::string &status) { + + }, [&](const boost::filesystem::path &file_path, int line_nr_, int line_index) { + line_nr=line_nr_; + }); + }); + debug_thread.detach(); + + for(;;) { + if(exited) { + g_assert_cmpint(exit_status, ==, 0); + break; + } + else if(line_nr>0) { + for(;;) { + if(Debug::Clang::get().is_stopped()) + break; + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + g_assert_cmpint(line_nr, ==, 2); + g_assert(Debug::Clang::get().get_backtrace().size()>0); + auto variables=Debug::Clang::get().get_variables(); + g_assert_cmpstr(variables.at(0).name.c_str(), ==, "an_int"); + line_nr=0; + Debug::Clang::get().step_over(); + for(;;) { + if(line_nr>0 && Debug::Clang::get().is_stopped()) + break; + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + g_assert_cmpint(line_nr, ==, 3); + g_assert(Debug::Clang::get().get_backtrace().size()>0); + variables=Debug::Clang::get().get_variables(); + g_assert_cmpstr(variables.at(0).name.c_str(), ==, "an_int"); + auto value=Debug::Clang::get().get_value("an_int", source_path, 2, 7); + g_assert_cmpuint(value.size(), >, 16); + auto value_substr=value.substr(0, 16); + g_assert_cmpstr(value_substr.c_str(), ==, "(int) an_int = 1"); + line_nr=0; + Debug::Clang::get().continue_debug(); + } + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + + Debug::Clang::get().cancel(); +} diff --git a/tests/lldb_test_files/CMakeLists.txt b/tests/lldb_test_files/CMakeLists.txt new file mode 100644 index 0000000..92fae30 --- /dev/null +++ b/tests/lldb_test_files/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 2.8) + +set(CMAKE_CXX_FLAGS "-g") + +add_executable(lldb_test_executable main.cpp) diff --git a/tests/lldb_test_files/main.cpp b/tests/lldb_test_files/main.cpp new file mode 100644 index 0000000..37b7a13 --- /dev/null +++ b/tests/lldb_test_files/main.cpp @@ -0,0 +1,4 @@ +int main() { + int an_int=1; + an_int++; +} diff --git a/tests/source_clang_test.cc b/tests/source_clang_test.cc index 4ed2e8d..6a4c65e 100644 --- a/tests/source_clang_test.cc +++ b/tests/source_clang_test.cc @@ -24,7 +24,7 @@ int main() { Gsv::init(); Config::get().project.default_build_path="./build"; - Source::ClangView *clang_view=new Source::ClangView(boost::filesystem::canonical(std::string(JUCI_TESTS_PATH)+"/clang_project/main.cpp"), + Source::ClangView *clang_view=new Source::ClangView(boost::filesystem::canonical(std::string(JUCI_TESTS_PATH)+"/source_clang_test_files/main.cpp"), Gsv::LanguageManager::get_default()->get_language("cpp")); while(!clang_view->parsed) flush_events(); diff --git a/tests/clang_project/CMakeLists.txt b/tests/source_clang_test_files/CMakeLists.txt similarity index 100% rename from tests/clang_project/CMakeLists.txt rename to tests/source_clang_test_files/CMakeLists.txt diff --git a/tests/clang_project/build/compile_commands.json b/tests/source_clang_test_files/build/compile_commands.json similarity index 100% rename from tests/clang_project/build/compile_commands.json rename to tests/source_clang_test_files/build/compile_commands.json diff --git a/tests/clang_project/main.cpp b/tests/source_clang_test_files/main.cpp similarity index 100% rename from tests/clang_project/main.cpp rename to tests/source_clang_test_files/main.cpp diff --git a/tests/source_test.cc b/tests/source_test.cc index 475767a..a3ab90c 100644 --- a/tests/source_test.cc +++ b/tests/source_test.cc @@ -25,7 +25,7 @@ int main() { Gsv::init(); auto tests_path=boost::filesystem::canonical(JUCI_TESTS_PATH); - auto source_file=tests_path/"tmp"/"source_file.txt"; + auto source_file=tests_path/"tmp"/"source_file.cpp"; { Source::View source_view(source_file, Glib::RefPtr());