Browse Source

Added lldb_test

merge-requests/365/head
eidheim 10 years ago
parent
commit
99571e10a3
  1. 2
      src/debug_clang.cc
  2. 2
      src/debug_clang.h
  3. 4
      src/project.cc
  4. 4
      src/project.h
  5. 2
      src/window.cc
  6. 10
      tests/CMakeLists.txt
  7. 71
      tests/lldb_test.cc
  8. 5
      tests/lldb_test_files/CMakeLists.txt
  9. 4
      tests/lldb_test_files/main.cpp
  10. 2
      tests/source_clang_test.cc
  11. 0
      tests/source_clang_test_files/CMakeLists.txt
  12. 0
      tests/source_clang_test_files/build/compile_commands.json
  13. 0
      tests/source_clang_test_files/main.cpp
  14. 2
      tests/source_test.cc

2
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(); kill();
if(debug_thread.joinable()) if(debug_thread.joinable())
debug_thread.join(); debug_thread.join();

2
src/debug_clang.h

@ -55,7 +55,7 @@ namespace Debug {
std::vector<Variable> get_variables(); std::vector<Variable> get_variables();
void select_frame(uint32_t frame_index, uint32_t thread_index_id=0); 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_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); std::string get_return_value(const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index);

4
src/project.cc

@ -504,9 +504,9 @@ void Project::Clang::debug_write(const std::string &buffer) {
Debug::Clang::get().write(buffer); Debug::Clang::get().write(buffer);
} }
void Project::Clang::debug_delete() { void Project::Clang::debug_cancel() {
std::unique_lock<std::mutex> lock(debug_start_mutex); std::unique_lock<std::mutex> lock(debug_start_mutex);
Debug::Clang::get().delete_debug(); Debug::Clang::get().cancel();
} }
#endif #endif

4
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 void debug_remove_breakpoint(const boost::filesystem::path &file_path, int line_nr, int line_count) {}
virtual bool debug_is_running() { return false; } virtual bool debug_is_running() { return false; }
virtual void debug_write(const std::string &buffer) {} virtual void debug_write(const std::string &buffer) {}
virtual void debug_delete() {} virtual void debug_cancel() {}
}; };
class Clang : public Base { 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; void debug_remove_breakpoint(const boost::filesystem::path &file_path, int line_nr, int line_count) override;
bool debug_is_running() override; bool debug_is_running() override;
void debug_write(const std::string &buffer) override; void debug_write(const std::string &buffer) override;
void debug_delete() override; void debug_cancel() override;
#endif #endif
}; };

2
src/window.cc

@ -910,7 +910,7 @@ bool Window::on_delete_event(GdkEventAny *event) {
Terminal::get().kill_async_processes(); Terminal::get().kill_async_processes();
#ifdef JUCI_ENABLE_DEBUG #ifdef JUCI_ENABLE_DEBUG
if(Project::current) if(Project::current)
Project::current->debug_delete(); Project::current->debug_cancel();
#endif #endif
return false; return false;
} }

10
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 set(global_includes
${Boost_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
@ -52,3 +52,11 @@ add_executable(source_clang_test source_clang_test.cc
$<TARGET_OBJECTS:project_shared> $<TARGET_OBJECTS:stubs>) $<TARGET_OBJECTS:project_shared> $<TARGET_OBJECTS:stubs>)
target_link_libraries(source_clang_test ${global_libraries}) target_link_libraries(source_clang_test ${global_libraries})
add_test(source_clang_test source_clang_test) add_test(source_clang_test source_clang_test)
if(LIBLLDB_FOUND)
add_executable(lldb_test lldb_test.cc
$<TARGET_OBJECTS:project_shared> $<TARGET_OBJECTS:stubs>)
target_link_libraries(lldb_test ${global_libraries})
add_test(lldb_test lldb_test)
add_subdirectory("lldb_test_files")
endif()

71
tests/lldb_test.cc

@ -0,0 +1,71 @@
#include <glib.h>
#include "debug_clang.h"
#include <thread>
#include <boost/filesystem.hpp>
#include <atomic>
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<std::pair<boost::filesystem::path, int> > breakpoints;
breakpoints.emplace_back(source_path, 2);
std::atomic<bool> exited(false);
int exit_status;
std::atomic<int> 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();
}

5
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)

4
tests/lldb_test_files/main.cpp

@ -0,0 +1,4 @@
int main() {
int an_int=1;
an_int++;
}

2
tests/source_clang_test.cc

@ -24,7 +24,7 @@ int main() {
Gsv::init(); Gsv::init();
Config::get().project.default_build_path="./build"; 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")); Gsv::LanguageManager::get_default()->get_language("cpp"));
while(!clang_view->parsed) while(!clang_view->parsed)
flush_events(); flush_events();

0
tests/clang_project/CMakeLists.txt → tests/source_clang_test_files/CMakeLists.txt

0
tests/clang_project/build/compile_commands.json → tests/source_clang_test_files/build/compile_commands.json

0
tests/clang_project/main.cpp → tests/source_clang_test_files/main.cpp

2
tests/source_test.cc

@ -25,7 +25,7 @@ int main() {
Gsv::init(); Gsv::init();
auto tests_path=boost::filesystem::canonical(JUCI_TESTS_PATH); 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<Gsv::Language>()); Source::View source_view(source_file, Glib::RefPtr<Gsv::Language>());

Loading…
Cancel
Save