]> git.siccegge.de Git - frida/frida.git/blobdiff - src/bindings/Guile.cxx
Make signals from geiser work
[frida/frida.git] / src / bindings / Guile.cxx
index 78ad3805044600813dfaa2a3974a7eb1e66a871c..18d12e95eef91b5edec0624b5797a68081678546 100644 (file)
@@ -1,5 +1,6 @@
 #include "Guile.hxx"
 #include "Config.hxx"
+#include "core/Settings.hxx"
 
 namespace {
        SCM handler (void*, SCM tag, SCM throw_args) {
@@ -8,11 +9,15 @@ namespace {
        }
 }
 
-GuileInterpreter::GuileInterpreter() {
-       scm_init_guile();
+GuileInterpreter::GuileInterpreter()
+       : logger(log4cxx::Logger::getLogger("bindings.Guile")) {
 
+       scm_init_guile();
        scm_c_use_module("system repl server");
-       scm_call_0(scm_c_public_ref("system repl server", "spawn-server"));
+
+       guile::Geiser* geiser = new guile::Geiser(this);
+       geiser->start();
+
        scm_c_load_extension("libguile-frida-binding",
                             "scm_init_frida_module");
 
@@ -20,16 +25,17 @@ GuileInterpreter::GuileInterpreter() {
        guile_error_port = scm_open_output_string();
        scm_set_current_output_port(guile_output_port);
        scm_set_current_error_port(guile_error_port);
+       LOG4CXX_INFO(logger, "Initializing GUILE finished");
 }
 
-int GuileInterpreter::evaluate(const std::string& command,
-                               std::ostream& stdout,
-                               std::ostream& stderr,
-                               std::string& result) {
-
+int GuileInterpreter::evaluateWithErrorHandling(SCM (*fun)(void *),
+                                                void* data,
+                                                std::ostream& stdout,
+                                                std::ostream& stderr,
+                                                std::string& result) {
        SCM result_obj = scm_internal_catch(SCM_BOOL_T,
-                                           (SCM (*)(void *))scm_c_eval_string,
-                                           (void*)command.c_str(),
+                                           fun,
+                                           data,
                                            handler, NULL);
 
        SCM result_str = scm_object_to_string(result_obj, SCM_UNDEFINED);
@@ -44,14 +50,42 @@ int GuileInterpreter::evaluate(const std::string& command,
 
        scm_truncate_file(guile_output_port, scm_from_uint16(0));
        scm_truncate_file(guile_error_port, scm_from_uint16(0));
-
        return 0;
 }
 
+int GuileInterpreter::evaluate(const std::string& command,
+                               std::ostream& stdout,
+                               std::ostream& stderr,
+                               std::string& result) {
+
+       return evaluateWithErrorHandling((SCM (*)(void *))scm_c_eval_string,
+                                        (void*)command.c_str(),
+                                        stdout, stderr, result);
+
+}
+
 int GuileInterpreter::loadFile(const std::string& filename,
                                std::ostream& stdout,
                                std::ostream& stderr,
                                std::string& result) {
-       scm_c_primitive_load(filename.c_str());
+       LOG4CXX_DEBUG(logger, "Loading file \"" << filename << "\"");
+       evaluateWithErrorHandling((SCM (*)(void *))scm_c_primitive_load,
+                                        (void*)filename.c_str(),
+                                        stdout, stderr, result);
+       LOG4CXX_DEBUG(logger, "Finished file \"" << filename << "\"");
        return 0;
 }
+
+namespace guile {
+       void Geiser::run() {
+               scm_init_guile();
+
+               QString socketpath = Settings::get()->getRuntimeDirectory()->canonicalPath()
+                       + "/frida." + QString::number(QCoreApplication::applicationPid(), 16) + ".geiser.sock";
+
+               SCM scm_socketpath = scm_from_locale_string(socketpath.toStdString().c_str());
+               SCM socket = scm_call_2(scm_c_public_ref("system repl server", "make-unix-domain-server-socket"),
+                                       scm_from_locale_keyword("path"), scm_socketpath);
+               scm_call_1(scm_c_public_ref("system repl server", "run-server"), socket);
+       }
+}