]>
git.siccegge.de Git - frida/frida.git/blob - src/bindings/Guile.cxx
3 #include "core/Settings.hxx"
6 SCM
handler (void*, SCM tag
, SCM throw_args
) {
7 scm_handle_by_message_noexit ((void*)"foo", tag
, throw_args
);
12 GuileInterpreter::GuileInterpreter()
13 : logger(log4cxx::Logger::getLogger("bindings.Guile")) {
16 scm_c_use_module("system repl server");
18 geiser
= new guile::Geiser(this);
21 scm_c_load_extension("libguile-frida-binding",
22 "scm_init_frida_module");
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");
31 GuileInterpreter::~GuileInterpreter() {
36 int GuileInterpreter::evaluateWithErrorHandling(SCM (*fun
)(void *),
40 std::string
& result
) {
41 SCM result_obj
= scm_internal_catch(SCM_BOOL_T
,
46 SCM result_str
= scm_object_to_string(result_obj
, SCM_UNDEFINED
);
48 SCM output
= scm_get_output_string(guile_output_port
);
49 stdout
<< scm_to_locale_string(output
);
51 output
= scm_get_output_string(guile_error_port
);
52 stderr
<< scm_to_locale_string(output
);
54 result
= scm_to_locale_string(result_str
);
56 scm_truncate_file(guile_output_port
, scm_from_uint16(0));
57 scm_truncate_file(guile_error_port
, scm_from_uint16(0));
61 int GuileInterpreter::evaluate(const std::string
& command
,
64 std::string
& result
) {
66 return evaluateWithErrorHandling((SCM (*)(void *))scm_c_eval_string
,
67 (void*)command
.c_str(),
68 stdout
, stderr
, result
);
72 int GuileInterpreter::loadFile(const std::string
& filename
,
75 std::string
& result
) {
76 LOG4CXX_DEBUG(logger
, "Loading file \"" << filename
<< "\"");
77 evaluateWithErrorHandling((SCM (*)(void *))scm_c_primitive_load
,
78 (void*)filename
.c_str(),
79 stdout
, stderr
, result
);
80 LOG4CXX_DEBUG(logger
, "Finished file \"" << filename
<< "\"");
88 QString socketpath
= Settings::get()->getRuntimeDirectory()->canonicalPath()
89 + "/frida." + QString::number(QCoreApplication::applicationPid(), 16) + ".geiser.sock";
91 SCM scm_socketpath
= scm_from_locale_string(socketpath
.toStdString().c_str());
92 SCM socket
= scm_call_2(scm_c_public_ref("system repl server", "make-unix-domain-server-socket"),
93 scm_from_locale_keyword("path"), scm_socketpath
);
94 scm_call_1(scm_c_public_ref("system repl server", "run-server"), socket
);