]> git.siccegge.de Git - frida/frida.git/blob - src/bindings/Guile.cxx
356757d095ccb7ffb6d4a7bc4575bf4a7e70b74a
[frida/frida.git] / src / bindings / Guile.cxx
1 #include "Guile.hxx"
2 #include "Config.hxx"
3
4 namespace {
5 SCM handler (void*, SCM tag, SCM throw_args) {
6 scm_handle_by_message_noexit ((void*)"foo", tag, throw_args);
7 return SCM_BOOL_F;
8 }
9 }
10
11 GuileInterpreter::GuileInterpreter()
12 : logger(log4cxx::Logger::getLogger("bindings.Guile")) {
13 scm_init_guile();
14
15 scm_c_use_module("system repl server");
16 scm_call_0(scm_c_public_ref("system repl server", "spawn-server"));
17 scm_c_load_extension("libguile-frida-binding",
18 "scm_init_frida_module");
19
20 guile_output_port = scm_open_output_string();
21 guile_error_port = scm_open_output_string();
22 scm_set_current_output_port(guile_output_port);
23 scm_set_current_error_port(guile_error_port);
24 LOG4CXX_INFO(logger, "Initializing GUILE finished");
25 }
26
27 int GuileInterpreter::evaluate(const std::string& command,
28 std::ostream& stdout,
29 std::ostream& stderr,
30 std::string& result) {
31
32 SCM result_obj = scm_internal_catch(SCM_BOOL_T,
33 (SCM (*)(void *))scm_c_eval_string,
34 (void*)command.c_str(),
35 handler, NULL);
36
37 SCM result_str = scm_object_to_string(result_obj, SCM_UNDEFINED);
38
39 SCM output = scm_get_output_string(guile_output_port);
40 stdout << scm_to_locale_string(output);
41
42 output = scm_get_output_string(guile_error_port);
43 stderr << scm_to_locale_string(output);
44
45 result = scm_to_locale_string(result_str);
46
47 scm_truncate_file(guile_output_port, scm_from_uint16(0));
48 scm_truncate_file(guile_error_port, scm_from_uint16(0));
49
50 return 0;
51 }
52
53 int GuileInterpreter::loadFile(const std::string& filename,
54 std::ostream& stdout,
55 std::ostream& stderr,
56 std::string& result) {
57 LOG4CXX_INFO(logger, "Loading file \"" << filename << "\"");
58 scm_c_primitive_load(filename.c_str());
59 LOG4CXX_INFO(logger, "Finished file \"" << filename << "\"");
60 return 0;
61 }