]> git.siccegge.de Git - frida/frida.git/blob - src/bindings/Guile.cxx
Properly fail if no appropriate Disassembler can be constructed
[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 scm_init_guile();
13
14 scm_c_use_module("system repl server");
15 scm_call_0(scm_c_public_ref("system repl server", "spawn-server"));
16 scm_c_load_extension("libguile-frida-binding",
17 "scm_init_frida_module");
18
19 guile_output_port = scm_open_output_string();
20 guile_error_port = scm_open_output_string();
21 scm_set_current_output_port(guile_output_port);
22 scm_set_current_error_port(guile_error_port);
23 }
24
25 int GuileInterpreter::evaluate(const std::string& command,
26 std::ostream& stdout,
27 std::ostream& stderr,
28 std::string& result) {
29
30 SCM result_obj = scm_internal_catch(SCM_BOOL_T,
31 (SCM (*)(void *))scm_c_eval_string,
32 (void*)command.c_str(),
33 handler, NULL);
34
35 SCM result_str = scm_object_to_string(result_obj, SCM_UNDEFINED);
36
37 SCM output = scm_get_output_string(guile_output_port);
38 stdout << scm_to_locale_string(output);
39
40 output = scm_get_output_string(guile_error_port);
41 stderr << scm_to_locale_string(output);
42
43 result = scm_to_locale_string(result_str);
44
45 scm_truncate_file(guile_output_port, scm_from_uint16(0));
46 scm_truncate_file(guile_error_port, scm_from_uint16(0));
47
48 return 0;
49 }
50
51 int GuileInterpreter::loadFile(const std::string& filename,
52 std::ostream& stdout,
53 std::ostream& stderr,
54 std::string& result) {
55 scm_c_primitive_load(filename.c_str());
56 }