/* GDB/Scheme support for safe calls into the Guile interpreter.
- Copyright (C) 2014-2015 Free Software Foundation, Inc.
+ Copyright (C) 2014-2019 Free Software Foundation, Inc.
This file is part of GDB.
#include "defs.h"
#include "filenames.h"
#include "guile-internal.h"
+#include "common/pathstuff.h"
/* Struct to marshall args to scscm_safe_call_body. */
struct c_data
{
- void *(*func) (void *);
+ const char *(*func) (void *);
void *data;
/* An error message or NULL for success. */
- void *result;
+ const char *result;
};
/* Struct to marshall args through gdbscm_with_catch. */
static SCM
scscm_recording_pre_unwind_handler (void *datap, SCM key, SCM args)
{
- struct with_catch_data *data = datap;
+ struct with_catch_data *data = (struct with_catch_data *) datap;
excp_matcher_func *matcher = data->excp_matcher;
if (matcher != NULL && matcher (key))
static SCM
scscm_recording_unwind_handler (void *datap, SCM key, SCM args)
{
- struct with_catch_data *data = datap;
+ struct with_catch_data *data = (struct with_catch_data *) datap;
/* We need to record the stack in the exception since we're about to
throw and lose the location that got the exception. We do this by
static void *
gdbscm_with_catch (void *data)
{
- struct with_catch_data *d = data;
+ struct with_catch_data *d = (struct with_catch_data *) data;
d->catch_result
= scm_c_catch (SCM_BOOL_T,
d->unwind_handler, d,
d->pre_unwind_handler, d);
+#if HAVE_GUILE_MANUAL_FINALIZATION
+ scm_run_finalizers ();
+#endif
+
return NULL;
}
The result if NULL if no exception occurred, otherwise it is a statically
allocated error message (caller must *not* free). */
-void *
-gdbscm_with_guile (void *(*func) (void *), void *data)
+const char *
+gdbscm_with_guile (const char *(*func) (void *), void *data)
{
struct c_data c_data;
struct with_catch_data catch_data;
static SCM
scscm_call_0_body (void *argsp)
{
- SCM *args = argsp;
+ SCM *args = (SCM *) argsp;
return scm_call_0 (args[0]);
}
static SCM
scscm_call_1_body (void *argsp)
{
- SCM *args = argsp;
+ SCM *args = (SCM *) argsp;
return scm_call_1 (args[0], args[1]);
}
static SCM
scscm_call_2_body (void *argsp)
{
- SCM *args = argsp;
+ SCM *args = (SCM *) argsp;
return scm_call_2 (args[0], args[1], args[2]);
}
static SCM
scscm_call_3_body (void *argsp)
{
- SCM *args = argsp;
+ SCM *args = (SCM *) argsp;
return scm_call_3 (args[0], args[1], args[2], args[3]);
}
static SCM
scscm_call_4_body (void *argsp)
{
- SCM *args = argsp;
+ SCM *args = (SCM *) argsp;
return scm_call_4 (args[0], args[1], args[2], args[3], args[4]);
}
static SCM
scscm_apply_1_body (void *argsp)
{
- SCM *args = argsp;
+ SCM *args = (SCM *) argsp;
return scm_apply_1 (args[0], args[1], args[2]);
}
/* Wrapper to eval a C string in the Guile interpreter.
This is passed to gdbscm_with_guile. */
-static void *
+static const char *
scscm_eval_scheme_string (void *datap)
{
- struct eval_scheme_string_data *data = datap;
+ struct eval_scheme_string_data *data
+ = (struct eval_scheme_string_data *) datap;
SCM result = scm_c_eval_string (data->string);
if (data->display_result && !scm_is_eq (result, SCM_UNSPECIFIED))
and preventing continuation capture.
The result is NULL if no exception occurred. Otherwise, the exception is
printed according to "set guile print-stack" and the result is an error
- message allocated with malloc, caller must free. */
+ message. */
-char *
+gdb::unique_xmalloc_ptr<char>
gdbscm_safe_eval_string (const char *string, int display_result)
{
struct eval_scheme_string_data data = { string, display_result };
- void *result;
+ const char *result;
result = gdbscm_with_guile (scscm_eval_scheme_string, (void *) &data);
if (result != NULL)
- return xstrdup (result);
+ return make_unique_xstrdup (result);
return NULL;
}
\f
/* Helper function for gdbscm_safe_source_scheme_script. */
-static void *
+static const char *
scscm_source_scheme_script (void *data)
{
- const char *filename = data;
+ const char *filename = (const char *) data;
/* The Guile docs don't specify what the result is.
Maybe it's SCM_UNSPECIFIED, but the docs should specify that. :-) */
%load-path, but we don't want %load-path to be searched. At least not
by default. This function is invoked by the "source" GDB command which
already has its own path search support. */
- char *abs_filename = NULL;
- void *result;
+ gdb::unique_xmalloc_ptr<char> abs_filename;
+ const char *result;
if (!IS_ABSOLUTE_PATH (filename))
{
abs_filename = gdb_realpath (filename);
- filename = abs_filename;
+ filename = abs_filename.get ();
}
result = gdbscm_with_guile (scscm_source_scheme_script,
(void *) filename);
- xfree (abs_filename);
if (result != NULL)
return xstrdup (result);
return NULL;