Browse Source

Fixed tests when using -fsanitize=thread

merge-requests/398/head
eidheim 7 years ago
parent
commit
16d9aa5525
  1. 24
      src/debug_lldb.cc
  2. 11
      src/debug_lldb.h
  3. 4
      src/project.cc
  4. 2
      src/project.h
  5. 5
      src/window.cc
  6. 2
      tests/lldb_test.cc

24
src/debug_lldb.cc

@ -12,6 +12,8 @@
extern char **environ; extern char **environ;
bool Debug::LLDB::initialized = false;
void log(const char *msg, void *) { void log(const char *msg, void *) {
std::cout << "debugger log: " << msg << std::endl; std::cout << "debugger log: " << msg << std::endl;
} }
@ -31,6 +33,21 @@ Debug::LLDB::LLDB() : state(lldb::StateType::eStateInvalid), buffer_size(131072)
} }
} }
void Debug::LLDB::destroy_() {
{
LockGuard lock(mutex);
if(process)
process->Kill();
}
if(debug_thread.joinable())
debug_thread.join();
LockGuard lock(mutex);
if(debugger)
lldb::SBDebugger::Destroy(*debugger);
}
std::tuple<std::vector<std::string>, std::string, std::vector<std::string>> Debug::LLDB::parse_run_arguments(const std::string &command) { std::tuple<std::vector<std::string>, std::string, std::vector<std::string>> Debug::LLDB::parse_run_arguments(const std::string &command) {
std::vector<std::string> environment; std::vector<std::string> environment;
std::string executable; std::string executable;
@ -89,6 +106,7 @@ void Debug::LLDB::start(const std::string &command, const boost::filesystem::pat
LockGuard lock(mutex); LockGuard lock(mutex);
if(!debugger) { if(!debugger) {
initialized = true;
lldb::SBDebugger::Initialize(); lldb::SBDebugger::Initialize();
debugger = std::make_unique<lldb::SBDebugger>(lldb::SBDebugger::Create(true, log, nullptr)); debugger = std::make_unique<lldb::SBDebugger>(lldb::SBDebugger::Create(true, log, nullptr));
listener = std::make_unique<lldb::SBListener>("juCi++ lldb listener"); listener = std::make_unique<lldb::SBListener>("juCi++ lldb listener");
@ -411,12 +429,6 @@ void Debug::LLDB::select_frame(uint32_t frame_index, uint32_t thread_index_id) {
} }
} }
void Debug::LLDB::cancel() {
kill();
if(debug_thread.joinable())
debug_thread.join();
}
std::string Debug::LLDB::get_value(const std::string &variable, const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index) { std::string Debug::LLDB::get_value(const std::string &variable, const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index) {
LockGuard lock(mutex); LockGuard lock(mutex);
if(state == lldb::StateType::eStateStopped) { if(state == lldb::StateType::eStateStopped) {

11
src/debug_lldb.h

@ -32,6 +32,9 @@ namespace Debug {
private: private:
LLDB(); LLDB();
void destroy_();
static bool initialized;
public: public:
static LLDB &get() { static LLDB &get() {
@ -39,6 +42,12 @@ namespace Debug {
return singleton; return singleton;
} }
/// Must be called before application terminates (cannot be placed in destructor sadly)
static void destroy() {
if(initialized)
get().destroy_();
}
std::list<std::function<void(const lldb::SBProcess &)>> on_start; std::list<std::function<void(const lldb::SBProcess &)>> on_start;
/// The handlers are not run in the main loop. /// The handlers are not run in the main loop.
std::list<std::function<void(int exit_status)>> on_exit; std::list<std::function<void(int exit_status)>> on_exit;
@ -61,8 +70,6 @@ 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 cancel();
/// Get value using variable name and location /// Get value using variable name and location
std::string get_value(const std::string &variable_name, const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index); std::string get_value(const std::string &variable_name, const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index);
/// Get value from expression /// Get value from expression

4
src/project.cc

@ -663,10 +663,6 @@ bool Project::LLDB::debug_is_running() {
void Project::LLDB::debug_write(const std::string &buffer) { void Project::LLDB::debug_write(const std::string &buffer) {
Debug::LLDB::get().write(buffer); Debug::LLDB::get().write(buffer);
} }
void Project::LLDB::debug_cancel() {
Debug::LLDB::get().cancel();
}
#endif #endif
void Project::LanguageProtocol::show_symbols() { void Project::LanguageProtocol::show_symbols() {

2
src/project.h

@ -74,7 +74,6 @@ 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_cancel() {}
}; };
class LLDB : public virtual Base { class LLDB : public virtual Base {
@ -98,7 +97,6 @@ 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_cancel() override;
#endif #endif
}; };

5
src/window.cc

@ -1,5 +1,6 @@
#include "window.h" #include "window.h"
#include "config.h" #include "config.h"
#include "debug_lldb.h"
#include "dialogs.h" #include "dialogs.h"
#include "directories.h" #include "directories.h"
#include "entrybox.h" #include "entrybox.h"
@ -1443,9 +1444,9 @@ bool Window::on_delete_event(GdkEventAny *event) {
return true; return true;
} }
Terminal::get().kill_async_processes(); Terminal::get().kill_async_processes();
#ifdef JUCI_ENABLE_DEBUG #ifdef JUCI_ENABLE_DEBUG
if(Project::current) Debug::LLDB::destroy();
Project::current->debug_cancel();
#endif #endif
return false; return false;

2
tests/lldb_test.cc

@ -136,5 +136,5 @@ int main() {
std::this_thread::sleep_for(std::chrono::milliseconds(10)); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
Debug::LLDB::get().cancel(); Debug::LLDB::destroy();
} }

Loading…
Cancel
Save