]> git.siccegge.de Git - frida/frida.git/blob - src/bindings/Guile.cxx
Make signals from geiser work
[frida/frida.git] / src / bindings / Guile.cxx
1 #include "Guile.hxx"
2 #include "Config.hxx"
3 #include "core/Settings.hxx"
4
5 namespace {
6 SCM handler (void*, SCM tag, SCM throw_args) {
7 scm_handle_by_message_noexit ((void*)"foo", tag, throw_args);
8 return SCM_BOOL_F;
9 }
10 }
11
12 GuileInterpreter::GuileInterpreter()
13 : logger(log4cxx::Logger::getLogger("bindings.Guile")) {
14
15 scm_init_guile();
16 scm_c_use_module("system repl server");
17
18 guile::Geiser* geiser = new guile::Geiser(this);
19 geiser->start();
20
21 scm_c_load_extension("libguile-frida-binding",
22 "scm_init_frida_module");
23
24 guile_output_port = scm_open_output_string();
25 guile_error_port = scm_open_output_string();
26 scm_set_current_output_port(guile_output_port);
27 scm_set_current_error_port(guile_error_port);
28 LOG4CXX_INFO(logger, "Initializing GUILE finished");
29 }
30
31 int GuileInterpreter::evaluateWithErrorHandling(SCM (*fun)(void *),
32 void* data,
33 std::ostream& stdout,
34 std::ostream& stderr,
35 std::string& result) {
36 SCM result_obj = scm_internal_catch(SCM_BOOL_T,
37 fun,
38 data,
39 handler, NULL);
40
41 SCM result_str = scm_object_to_string(result_obj, SCM_UNDEFINED);
42
43 SCM output = scm_get_output_string(guile_output_port);
44 stdout << scm_to_locale_string(output);
45
46 output = scm_get_output_string(guile_error_port);
47 stderr << scm_to_locale_string(output);
48
49 result = scm_to_locale_string(result_str);
50
51 scm_truncate_file(guile_output_port, scm_from_uint16(0));
52 scm_truncate_file(guile_error_port, scm_from_uint16(0));
53 return 0;
54 }
55
56 int GuileInterpreter::evaluate(const std::string& command,
57 std::ostream& stdout,
58 std::ostream& stderr,
59 std::string& result) {
60
61 return evaluateWithErrorHandling((SCM (*)(void *))scm_c_eval_string,
62 (void*)command.c_str(),
63 stdout, stderr, result);
64
65 }
66
67 int GuileInterpreter::loadFile(const std::string& filename,
68 std::ostream& stdout,
69 std::ostream& stderr,
70 std::string& result) {
71 LOG4CXX_DEBUG(logger, "Loading file \"" << filename << "\"");
72 evaluateWithErrorHandling((SCM (*)(void *))scm_c_primitive_load,
73 (void*)filename.c_str(),
74 stdout, stderr, result);
75 LOG4CXX_DEBUG(logger, "Finished file \"" << filename << "\"");
76 return 0;
77 }
78
79 namespace guile {
80 void Geiser::run() {
81 scm_init_guile();
82
83 QString socketpath = Settings::get()->getRuntimeDirectory()->canonicalPath()
84 + "/frida." + QString::number(QCoreApplication::applicationPid(), 16) + ".geiser.sock";
85
86 SCM scm_socketpath = scm_from_locale_string(socketpath.toStdString().c_str());
87 SCM socket = scm_call_2(scm_c_public_ref("system repl server", "make-unix-domain-server-socket"),
88 scm_from_locale_keyword("path"), scm_socketpath);
89 scm_call_1(scm_c_public_ref("system repl server", "run-server"), socket);
90 }
91 }