forked from Imagelibrary/binutils-gdb
Add parameter support for Guile.
* Makefile.in (SUBDIR_GUILE_OBS): Add scm-param.o. (SUBDIR_GUILE_SRCS): Add scm-param.c. (scm-param.o): New rule. * guile/guile-internal.h (gdbscm_gc_dup_argv): Declare. (gdbscm_misc_error): Declare. (gdbscm_canonicalize_command_name): Declare. (gdbscm_scm_to_host_string): Declare. (gdbscm_scm_from_host_string): Declare. (gdbscm_initialize_parameters): Declare. * guile/guile.c (initialize_gdb_module): Call gdbscm_initialize_parameters. * guile/lib/gdb.scm: Export parameter symbols. * guile/scm-cmd.c (gdbscm_canonicalize_command_name): Renamed from cmdscm_canonicalize_name and made public. All callers updated. * guile/scm-exception.c (gdbscm_misc_error): New function. * guile/scm-param.c: New file. * guile/scm-string.c (gdbscm_scm_to_string): Add comments. (gdbscm_scm_to_host_string): New function. (gdbscm_scm_from_host_string): New function. * scm-utils.c (gdbscm_gc_dup_argv): New function. testsuite/ * gdb.guile/scm-parameter.exp: New file. doc/ * guile.texi (Guile API): Add entry for Parameters In Guile. (GDB Scheme Data Types): Mention <gdb:parameter> object. (Parameters In Guile): New node.
This commit is contained in:
@@ -166,6 +166,8 @@ extern void gdbscm_dynwind_xfree (void *ptr);
|
||||
extern int gdbscm_is_procedure (SCM proc);
|
||||
|
||||
extern char *gdbscm_gc_xstrdup (const char *);
|
||||
|
||||
extern const char * const *gdbscm_gc_dup_argv (char **argv);
|
||||
|
||||
/* GDB smobs, from scm-gsmob.c */
|
||||
|
||||
@@ -301,6 +303,10 @@ extern void gdbscm_out_of_range_error (const char *subr, int arg_pos,
|
||||
extern SCM gdbscm_make_misc_error (const char *subr, int arg_pos,
|
||||
SCM bad_value, const char *error);
|
||||
|
||||
extern void gdbscm_misc_error (const char *subr, int arg_pos,
|
||||
SCM bad_value, const char *error)
|
||||
ATTRIBUTE_NORETURN;
|
||||
|
||||
extern void gdbscm_throw (SCM exception) ATTRIBUTE_NORETURN;
|
||||
|
||||
extern SCM gdbscm_scm_from_gdb_exception (struct gdb_exception exception);
|
||||
@@ -388,6 +394,9 @@ extern char *gdbscm_parse_command_name (const char *name,
|
||||
|
||||
extern int gdbscm_valid_command_class_p (int command_class);
|
||||
|
||||
extern char *gdbscm_canonicalize_command_name (const char *name,
|
||||
int want_trailing_space);
|
||||
|
||||
/* scm-frame.c */
|
||||
|
||||
typedef struct _frame_smob frame_smob;
|
||||
@@ -476,6 +485,10 @@ extern char *gdbscm_scm_to_string (SCM string, size_t *lenp,
|
||||
extern SCM gdbscm_scm_from_string (const char *string, size_t len,
|
||||
const char *charset, int strict);
|
||||
|
||||
extern char *gdbscm_scm_to_host_string (SCM string, size_t *lenp, SCM *except);
|
||||
|
||||
extern SCM gdbscm_scm_from_host_string (const char *string, size_t len);
|
||||
|
||||
/* scm-symbol.c */
|
||||
|
||||
extern int syscm_is_symbol (SCM scm);
|
||||
@@ -565,6 +578,7 @@ extern void gdbscm_initialize_lazy_strings (void);
|
||||
extern void gdbscm_initialize_math (void);
|
||||
extern void gdbscm_initialize_objfiles (void);
|
||||
extern void gdbscm_initialize_pretty_printers (void);
|
||||
extern void gdbscm_initialize_parameters (void);
|
||||
extern void gdbscm_initialize_ports (void);
|
||||
extern void gdbscm_initialize_pspaces (void);
|
||||
extern void gdbscm_initialize_smobs (void);
|
||||
|
||||
@@ -544,6 +544,7 @@ initialize_gdb_module (void *data)
|
||||
gdbscm_initialize_lazy_strings ();
|
||||
gdbscm_initialize_math ();
|
||||
gdbscm_initialize_objfiles ();
|
||||
gdbscm_initialize_parameters ();
|
||||
gdbscm_initialize_ports ();
|
||||
gdbscm_initialize_pretty_printers ();
|
||||
gdbscm_initialize_pspaces ();
|
||||
|
||||
@@ -275,6 +275,26 @@
|
||||
current-objfile
|
||||
objfiles
|
||||
|
||||
;; scm-param.c
|
||||
|
||||
PARAM_BOOLEAN
|
||||
PARAM_AUTO_BOOLEAN
|
||||
PARAM_ZINTEGER
|
||||
PARAM_UINTEGER
|
||||
PARAM_ZUINTEGER
|
||||
PARAM_ZUINTEGER_UNLIMITED
|
||||
PARAM_STRING
|
||||
PARAM_STRING_NOESCAPE
|
||||
PARAM_OPTIONAL_FILENAME
|
||||
PARAM_FILENAME
|
||||
PARAM_ENUM
|
||||
|
||||
make-parameter
|
||||
register-parameter!
|
||||
parameter?
|
||||
parameter-value
|
||||
set-parameter-value!
|
||||
|
||||
;; scm-ports.c
|
||||
|
||||
input-port
|
||||
|
||||
@@ -603,8 +603,8 @@ gdbscm_valid_command_class_p (int command_class)
|
||||
but that is the caller's responsibility.
|
||||
Space for the result is allocated on the GC heap. */
|
||||
|
||||
static char *
|
||||
cmdscm_canonicalize_name (const char *name, int want_trailing_space)
|
||||
char *
|
||||
gdbscm_canonicalize_command_name (const char *name, int want_trailing_space)
|
||||
{
|
||||
int i, out, seen_word;
|
||||
char *result = scm_gc_malloc_pointerless (strlen (name) + 2, FUNC_NAME);
|
||||
@@ -699,7 +699,7 @@ gdbscm_make_command (SCM name_scm, SCM rest)
|
||||
doc = xstrdup (_("This command is not documented."));
|
||||
|
||||
s = name;
|
||||
name = cmdscm_canonicalize_name (s, is_prefix);
|
||||
name = gdbscm_canonicalize_command_name (s, is_prefix);
|
||||
xfree (s);
|
||||
s = doc;
|
||||
doc = gdbscm_gc_xstrdup (s);
|
||||
|
||||
@@ -360,12 +360,23 @@ gdbscm_out_of_range_error (const char *subr, int arg_pos, SCM bad_value,
|
||||
|
||||
SCM
|
||||
gdbscm_make_misc_error (const char *subr, int arg_pos, SCM bad_value,
|
||||
const char *error)
|
||||
const char *error)
|
||||
{
|
||||
return gdbscm_make_arg_error (scm_misc_error_key,
|
||||
subr, arg_pos, bad_value, NULL, error);
|
||||
}
|
||||
|
||||
/* Throw a misc-error error. */
|
||||
|
||||
void
|
||||
gdbscm_misc_error (const char *subr, int arg_pos, SCM bad_value,
|
||||
const char *error)
|
||||
{
|
||||
SCM exception = gdbscm_make_misc_error (subr, arg_pos, bad_value, error);
|
||||
|
||||
gdbscm_throw (exception);
|
||||
}
|
||||
|
||||
/* Return a <gdb:exception> object for gdb:memory-error. */
|
||||
|
||||
SCM
|
||||
|
||||
1163
gdb/guile/scm-param.c
Normal file
1163
gdb/guile/scm-param.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -90,10 +90,17 @@ gdbscm_call_scm_to_stringn (void *datap)
|
||||
|
||||
/* Convert an SCM string to a string in charset CHARSET.
|
||||
This function is guaranteed to not throw an exception.
|
||||
|
||||
If LENP is NULL then the returned string is NUL-terminated,
|
||||
and an exception is thrown if the string contains embedded NULs.
|
||||
Otherwise the string is not guaranteed to be NUL-terminated, but worse
|
||||
there's no space to put a NUL if we wanted to (scm_to_stringn limitation).
|
||||
|
||||
If STRICT is non-zero, and there's a conversion error, then a
|
||||
<gdb:exception> object is stored in *EXCEPT_SCMP, and NULL is returned.
|
||||
If STRICT is zero, then escape sequences are used for characters that
|
||||
can't be converted, and EXCEPT_SCMP may be passed as NULL.
|
||||
|
||||
Space for the result is allocated with malloc, caller must free.
|
||||
It is an error to call this if STRING is not a string. */
|
||||
|
||||
@@ -151,6 +158,7 @@ gdbscm_call_scm_from_stringn (void *datap)
|
||||
|
||||
/* Convert STRING to a Scheme string in charset CHARSET.
|
||||
This function is guaranteed to not throw an exception.
|
||||
|
||||
If STRICT is non-zero, and there's a conversion error, then a
|
||||
<gdb:exception> object is returned.
|
||||
If STRICT is zero, then question marks are used for characters that
|
||||
@@ -183,6 +191,36 @@ gdbscm_scm_from_string (const char *string, size_t len,
|
||||
return scm_result;
|
||||
}
|
||||
|
||||
/* Convert an SCM string to a host string.
|
||||
This function is guaranteed to not throw an exception.
|
||||
|
||||
If LENP is NULL then the returned string is NUL-terminated,
|
||||
and if the string contains embedded NULs then NULL is returned with
|
||||
an exception object stored in *EXCEPT_SCMP.
|
||||
Otherwise the string is not guaranteed to be NUL-terminated, but worse
|
||||
there's no space to put a NUL if we wanted to (scm_to_stringn limitation).
|
||||
|
||||
Returns NULL if there is a conversion error, with the exception object
|
||||
stored in *EXCEPT_SCMP.
|
||||
Space for the result is allocated with malloc, caller must free.
|
||||
It is an error to call this if STRING is not a string. */
|
||||
|
||||
char *
|
||||
gdbscm_scm_to_host_string (SCM string, size_t *lenp, SCM *except_scmp)
|
||||
{
|
||||
return gdbscm_scm_to_string (string, lenp, host_charset (), 1, except_scmp);
|
||||
}
|
||||
|
||||
/* Convert a host string to an SCM string.
|
||||
This function is guaranteed to not throw an exception.
|
||||
Returns a <gdb:exception> object if there's a conversion error. */
|
||||
|
||||
SCM
|
||||
gdbscm_scm_from_host_string (const char *string, size_t len)
|
||||
{
|
||||
return gdbscm_scm_from_string (string, len, host_charset (), 1);
|
||||
}
|
||||
|
||||
/* (string->argv string) -> list
|
||||
Return list of strings split up according to GDB's argv parsing rules.
|
||||
This is useful when writing GDB commands in Scheme. */
|
||||
|
||||
@@ -595,3 +595,32 @@ gdbscm_gc_xstrdup (const char *str)
|
||||
strcpy (result, str);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Return a duplicate of ARGV living on the GC heap. */
|
||||
|
||||
const char * const *
|
||||
gdbscm_gc_dup_argv (char **argv)
|
||||
{
|
||||
int i, len;
|
||||
size_t string_space;
|
||||
char *p, **result;
|
||||
|
||||
for (len = 0, string_space = 0; argv[len] != NULL; ++len)
|
||||
string_space += strlen (argv[len]) + 1;
|
||||
|
||||
/* Allocating "pointerless" works because the pointers are all
|
||||
self-contained within the object. */
|
||||
result = scm_gc_malloc_pointerless (((len + 1) * sizeof (char *))
|
||||
+ string_space, "parameter enum list");
|
||||
p = (char *) &result[len + 1];
|
||||
|
||||
for (i = 0; i < len; ++i)
|
||||
{
|
||||
result[i] = p;
|
||||
strcpy (p, argv[i]);
|
||||
p += strlen (p) + 1;
|
||||
}
|
||||
result[i] = NULL;
|
||||
|
||||
return (const char * const *) result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user