Browse Source

Debug process now has correct environment variables, and handles stdin

merge-requests/365/head
eidheim 10 years ago
parent
commit
ff7ec7ddc8
  1. 26
      src/debug.cc
  2. 3
      src/debug.h
  3. 14
      src/terminal.cc

26
src/debug.cc

@ -1,4 +1,7 @@
#include "debug.h"
#include <stdio.h>
#include <iostream>
#include "terminal.h"
#include <lldb/API/SBTarget.h>
#include <lldb/API/SBProcess.h>
@ -10,10 +13,9 @@
#include <lldb/API/SBCommandInterpreter.h>
#include <lldb/API/SBCommandReturnObject.h>
#include "terminal.h"
using namespace std; //TODO: remove
#include <iostream> //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<std::vector<std::pair<boost::filesystem::path,
}
lldb::SBError error;
process = std::unique_ptr<lldb::SBProcess>(new lldb::SBProcess(target.Launch(listener, nullptr, nullptr, nullptr, nullptr, nullptr, path.string().c_str(), lldb::eLaunchFlagNone, false, error)));
process = std::unique_ptr<lldb::SBProcess>(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();
}

3
src/debug.h

@ -32,6 +32,9 @@ public:
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;
lldb::SBListener listener;

14
src/terminal.cc

@ -2,6 +2,9 @@
#include <iostream>
#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,6 +268,11 @@ bool Terminal::on_key_press_event(GdkEventKey *event) {
}
else if(event->keyval==GDK_KEY_Return) {
stdin_buffer+='\n';
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();

Loading…
Cancel
Save