From ff7ec7ddc87e1a364c6b1ed05d4197327a068954 Mon Sep 17 00:00:00 2001 From: eidheim Date: Thu, 31 Dec 2015 11:23:49 +0100 Subject: [PATCH] Debug process now has correct environment variables, and handles stdin --- src/debug.cc | 26 ++++++++++++++++++++++---- src/debug.h | 3 +++ src/terminal.cc | 16 ++++++++++++++-- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/debug.cc b/src/debug.cc index 5c4da51..739ab21 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -1,4 +1,7 @@ #include "debug.h" +#include +#include +#include "terminal.h" #include #include @@ -10,10 +13,9 @@ #include #include -#include "terminal.h" +using namespace std; //TODO: remove -#include //TODO: remove -using namespace std; +extern const char **environ; void log(const char *msg, void *) { cout << "debugger log: " << msg << endl; @@ -44,7 +46,7 @@ void Debug::start(std::shared_ptr(new lldb::SBProcess(target.Launch(listener, nullptr, nullptr, nullptr, nullptr, nullptr, path.string().c_str(), lldb::eLaunchFlagNone, false, error))); + process = std::unique_ptr(new lldb::SBProcess(target.Launch(listener, nullptr, environ, nullptr, nullptr, nullptr, path.string().c_str(), lldb::eLaunchFlagNone, false, error))); if(error.Fail()) { Terminal::get().async_print(std::string("Error (debug): ")+error.GetCString()+'\n', true); return; @@ -220,3 +222,19 @@ std::string Debug::get_value(const std::string &variable, const boost::filesyste event_mutex.unlock(); return variable_value; } + +bool Debug::is_running() { + bool running; + event_mutex.lock(); + running=state==lldb::StateType::eStateRunning; + event_mutex.unlock(); + return running; +} + +void Debug::write(const std::string &buffer) { + event_mutex.lock(); + if(state==lldb::StateType::eStateRunning) { + process->PutSTDIN(buffer.c_str(), buffer.size()); + } + event_mutex.unlock(); +} diff --git a/src/debug.h b/src/debug.h index 07abe79..d91fc5e 100644 --- a/src/debug.h +++ b/src/debug.h @@ -31,6 +31,9 @@ public: void delete_debug(); //can't use delete as function name std::string get_value(const std::string &variable, const boost::filesystem::path &file_path, unsigned int line_nr); + + bool is_running(); + void write(const std::string &buffer); private: lldb::SBDebugger debugger; diff --git a/src/terminal.cc b/src/terminal.cc index 546328c..130e098 100644 --- a/src/terminal.cc +++ b/src/terminal.cc @@ -2,6 +2,9 @@ #include #include "logging.h" #include "config.h" +#ifdef JUCI_ENABLE_DEBUG +#include "debug.h" +#endif Terminal::InProgress::InProgress(const std::string& start_msg): stop(false) { waiting_print.connect([this](){ @@ -243,7 +246,11 @@ void Terminal::async_print(int line_nr, const std::string &message) { bool Terminal::on_key_press_event(GdkEventKey *event) { processes_mutex.lock(); - if(processes.size()>0) { + bool debug_is_running=false; +#ifdef JUCI_ENABLE_DEBUG + debug_is_running=Debug::get().is_running(); +#endif + if(processes.size()>0 || debug_is_running) { get_buffer()->place_cursor(get_buffer()->end()); auto unicode=gdk_keyval_to_unicode(event->keyval); char chr=(char)unicode; @@ -261,7 +268,12 @@ bool Terminal::on_key_press_event(GdkEventKey *event) { } else if(event->keyval==GDK_KEY_Return) { stdin_buffer+='\n'; - processes.back()->write(stdin_buffer); + if(debug_is_running) +#ifdef JUCI_ENABLE_DEBUG + Debug::get().write(stdin_buffer); +#endif + else + processes.back()->write(stdin_buffer); get_buffer()->insert_at_cursor(stdin_buffer.substr(stdin_buffer.size()-1)); stdin_buffer.clear(); }