f486487f55
This is a patch I extracted from Pedro's C++ branch. It contains the most trivial enum fixes, where an integer type/value was used instead of the appropriate enum type/value. It fixes many C++ errors, since in C++ you can't mix integers and enums implicitely. Regardless of the C++ conversion, I think this is a good cleanup to make use of the appropriate enum types. Regression-tested on native x86_64. gdb/ChangeLog: * aarch64-linux-nat.c (aarch64_linux_can_use_hw_breakpoint): Use enum type or value instead of integer. (aarch64_linux_insert_watchpoint): Likewise. (aarch64_linux_remove_watchpoint): Likewise. * ada-lang.c (ada_op_print_tab): Likewise. * amd64-linux-tdep.c (amd64_canonicalize_syscall): Likewise. (amd64_linux_syscall_record_common): Likewise. * arch-utils.c (target_byte_order_user): Likewise. (default_byte_order): Likewise. * arm-linux-nat.c (arm_linux_can_use_hw_breakpoint): Likewise. (arm_linux_get_hwbp_type): Likewise. (arm_linux_hw_watchpoint_initialize): Likewise. (arm_linux_insert_watchpoint): Likewise. * arm-linux-tdep.c (arm_canonicalize_syscall): Likewise. (arm_linux_syscall_record): Likewise. * breakpoint.c (update_watchpoint): Likewise. (breakpoint_here_p): Likewise. (bpstat_print): Likewise. (enable_breakpoint_disp): Likewise. * c-lang.c (c_op_print_tab): Likewise. * cli/cli-decode.c (add_info_alias): Likewise. * d-lang.c (d_op_print_tab): Likewise. * eval.c (evaluate_subexp_standard): Likewise. * f-exp.y (dot_ops): Likewise. (f77_keywords): Likewise. * f-lang.c (f_op_print_tab): Likewise. * go-lang.c (go_op_print_tab): Likewise. * guile/scm-breakpoint.c (gdbscm_make_breakpoint): Likewise. * guile/scm-cmd.c (gdbscm_make_command): Likewise. * guile/scm-param.c (gdbscm_make_parameter): Likewise. * guile/scm-pretty-print.c (gdbscm_apply_val_pretty_printer): Likewise. * guile/scm-string.c (struct scm_to_stringn_data): Likewise. (struct scm_from_stringn_data): Likewise. * i386-linux-tdep.c (i386_canonicalize_syscall): Likewise. * ia64-linux-nat.c (ia64_linux_insert_watchpoint): Likewise. (ia64_linux_remove_watchpoint): Likewise. (ia64_linux_can_use_hw_breakpoint): Likewise. * infrun.c (print_stop_event): Likewise. * jv-lang.c (java_op_print_tab): Likewise. * linux-nat.c (linux_proc_xfer_partial): Likewise. * linux-nat.h (struct lwp_info): Likewise. * linux-thread-db.c (enable_thread_event): Likewise. * m2-lang.c (m2_op_print_tab): Likewise. * mi/mi-cmd-stack.c (mi_cmd_stack_list_locals): Likewise. (mi_cmd_stack_list_variables): Likewise. * mi/mi-main.c (mi_cmd_trace_frame_collected): Likewise. * mi/mi-out.c (mi_table_begin): Likewise. (mi_table_header): Likewise. * mips-linux-nat.c (mips_linux_can_use_hw_breakpoint): Likewise. (mips_linux_insert_watchpoint): Likewise. (mips_linux_remove_watchpoint): Likewise. * nat/mips-linux-watch.c (mips_linux_watch_type_to_irw): Likewise. * nat/mips-linux-watch.h (struct mips_watchpoint): Likewise. (mips_linux_watch_type_to_irw): Likewise. * nto-procfs.c (procfs_can_use_hw_breakpoint): Likewise. (procfs_insert_hw_watchpoint): Likewise. (procfs_remove_hw_watchpoint): Likewise. (procfs_hw_watchpoint): Likewise. (procfs_can_use_hw_breakpoint): Likewise. (procfs_remove_hw_watchpoint): Likewise. (procfs_insert_hw_watchpoint): Likewise. * p-lang.c (pascal_op_print_tab): Likewise. * ppc-linux-nat.c (ppc_linux_can_use_hw_breakpoint): Likewise. * ppc-linux-tdep.c (ppu2spu_unwind_register): Likewise. * ppc-sysv-tdep.c (get_decimal_float_return_value): Likewise. * procfs.c (procfs_can_use_hw_breakpoint): Likewise. (procfs_insert_watchpoint): Likewise. (procfs_remove_watchpoint): Likewise. * psymtab.c (recursively_search_psymtabs): Likewise. * remote-m32r-sdi.c (m32r_can_use_hw_watchpoint): Likewise. (m32r_insert_watchpoint): Likewise. * remote-mips.c (mips_can_use_watchpoint): Likewise. (mips_insert_watchpoint): Likewise. (mips_remove_watchpoint): Likewise. * remote.c (watchpoint_to_Z_packet): Likewise. (remote_insert_watchpoint): Likewise. (remote_remove_watchpoint): Likewise. (remote_check_watch_resources): Likewise. * s390-linux-nat.c (s390_insert_watchpoint): Likewise. (s390_remove_watchpoint): Likewise. (s390_can_use_hw_breakpoint): Likewise. * s390-linux-tdep.c (s390_gdbarch_init): Likewise. * spu-linux-nat.c (spu_can_use_hw_breakpoint): Likewise. * target.h (struct target_ops): Likewise. * tilegx-tdep.c (tilegx_analyze_prologue): Likewise. * ui-out.c (struct ui_out_hdr): Likewise. (append_header_to_list): Likewise. (get_next_header): Likewise. (verify_field): Likewise. (ui_out_begin): Likewise. (ui_out_field_int): Likewise. (ui_out_field_fmt_int): Likewise. (ui_out_field_skip): Likewise. (ui_out_field_string): Likewise. (ui_out_field_fmt): Likewise. * varobj.c (new_variable): Likewise. * x86-nat.c (x86_insert_watchpoint): Likewise. (x86_remove_watchpoint): Likewise. (x86_can_use_hw_breakpoint): Likewise. * xtensa-tdep.h (struct gdbarch_tdep): Likewise. * inflow.c (enum gdb_has_a_terminal_flag_enum): Add name to previously anonymous enumeration type.. * linux-record.h (enum gdb_syscall): Add gdb_sys_no_syscall value. * target-debug.h (target_debug_print_enum_target_hw_bp_type): New. (target_debug_print_enum_bptype): New. * target-delegates.c: Regenerate.
283 lines
7.7 KiB
C
283 lines
7.7 KiB
C
/* GDB/Scheme charset interface.
|
||
|
||
Copyright (C) 2014-2015 Free Software Foundation, Inc.
|
||
|
||
This file is part of GDB.
|
||
|
||
This program is free software; you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
the Free Software Foundation; either version 3 of the License, or
|
||
(at your option) any later version.
|
||
|
||
This program is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU General Public License for more details.
|
||
|
||
You should have received a copy of the GNU General Public License
|
||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||
|
||
/* See README file in this directory for implementation notes, coding
|
||
conventions, et.al. */
|
||
|
||
#include "defs.h"
|
||
#include "charset.h"
|
||
#include "guile-internal.h"
|
||
|
||
/* Convert STRING to an int.
|
||
STRING must be a valid integer. */
|
||
|
||
int
|
||
gdbscm_scm_string_to_int (SCM string)
|
||
{
|
||
char *s = scm_to_latin1_string (string);
|
||
int r = atoi (s);
|
||
|
||
free (s);
|
||
return r;
|
||
}
|
||
|
||
/* Convert a C (latin1) string to an SCM string.
|
||
"latin1" is chosen because Guile won't throw an exception. */
|
||
|
||
SCM
|
||
gdbscm_scm_from_c_string (const char *string)
|
||
{
|
||
return scm_from_latin1_string (string);
|
||
}
|
||
|
||
/* Convert an SCM string to a C (latin1) string.
|
||
"latin1" is chosen because Guile won't throw an exception.
|
||
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_c_string (SCM string)
|
||
{
|
||
return scm_to_latin1_string (string);
|
||
}
|
||
|
||
/* Use printf to construct a Scheme string. */
|
||
|
||
SCM
|
||
gdbscm_scm_from_printf (const char *format, ...)
|
||
{
|
||
va_list args;
|
||
char *string;
|
||
SCM result;
|
||
|
||
va_start (args, format);
|
||
string = xstrvprintf (format, args);
|
||
va_end (args);
|
||
result = scm_from_latin1_string (string);
|
||
xfree (string);
|
||
|
||
return result;
|
||
}
|
||
|
||
/* Struct to pass data from gdbscm_scm_to_string to
|
||
gdbscm_call_scm_to_stringn. */
|
||
|
||
struct scm_to_stringn_data
|
||
{
|
||
SCM string;
|
||
size_t *lenp;
|
||
const char *charset;
|
||
scm_t_string_failed_conversion_handler conversion_kind;
|
||
char *result;
|
||
};
|
||
|
||
/* Helper for gdbscm_scm_to_string to call scm_to_stringn
|
||
from within scm_c_catch. */
|
||
|
||
static SCM
|
||
gdbscm_call_scm_to_stringn (void *datap)
|
||
{
|
||
struct scm_to_stringn_data *data = datap;
|
||
|
||
data->result = scm_to_stringn (data->string, data->lenp, data->charset,
|
||
data->conversion_kind);
|
||
return SCM_BOOL_F;
|
||
}
|
||
|
||
/* 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. */
|
||
|
||
char *
|
||
gdbscm_scm_to_string (SCM string, size_t *lenp,
|
||
const char *charset, int strict, SCM *except_scmp)
|
||
{
|
||
struct scm_to_stringn_data data;
|
||
SCM scm_result;
|
||
|
||
data.string = string;
|
||
data.lenp = lenp;
|
||
data.charset = charset;
|
||
data.conversion_kind = (strict
|
||
? SCM_FAILED_CONVERSION_ERROR
|
||
: SCM_FAILED_CONVERSION_ESCAPE_SEQUENCE);
|
||
data.result = NULL;
|
||
|
||
scm_result = gdbscm_call_guile (gdbscm_call_scm_to_stringn, &data, NULL);
|
||
|
||
if (gdbscm_is_false (scm_result))
|
||
{
|
||
gdb_assert (data.result != NULL);
|
||
return data.result;
|
||
}
|
||
gdb_assert (gdbscm_is_exception (scm_result));
|
||
*except_scmp = scm_result;
|
||
return NULL;
|
||
}
|
||
|
||
/* Struct to pass data from gdbscm_scm_from_string to
|
||
gdbscm_call_scm_from_stringn. */
|
||
|
||
struct scm_from_stringn_data
|
||
{
|
||
const char *string;
|
||
size_t len;
|
||
const char *charset;
|
||
scm_t_string_failed_conversion_handler conversion_kind;
|
||
SCM result;
|
||
};
|
||
|
||
/* Helper for gdbscm_scm_from_string to call scm_from_stringn
|
||
from within scm_c_catch. */
|
||
|
||
static SCM
|
||
gdbscm_call_scm_from_stringn (void *datap)
|
||
{
|
||
struct scm_from_stringn_data *data = datap;
|
||
|
||
data->result = scm_from_stringn (data->string, data->len, data->charset,
|
||
data->conversion_kind);
|
||
return SCM_BOOL_F;
|
||
}
|
||
|
||
/* 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
|
||
can't be converted (limitation of underlying Guile conversion support). */
|
||
|
||
SCM
|
||
gdbscm_scm_from_string (const char *string, size_t len,
|
||
const char *charset, int strict)
|
||
{
|
||
struct scm_from_stringn_data data;
|
||
SCM scm_result;
|
||
|
||
data.string = string;
|
||
data.len = len;
|
||
data.charset = charset;
|
||
/* The use of SCM_FAILED_CONVERSION_QUESTION_MARK is specified by Guile. */
|
||
data.conversion_kind = (strict
|
||
? SCM_FAILED_CONVERSION_ERROR
|
||
: SCM_FAILED_CONVERSION_QUESTION_MARK);
|
||
data.result = SCM_UNDEFINED;
|
||
|
||
scm_result = gdbscm_call_guile (gdbscm_call_scm_from_stringn, &data, NULL);
|
||
|
||
if (gdbscm_is_false (scm_result))
|
||
{
|
||
gdb_assert (!SCM_UNBNDP (data.result));
|
||
return data.result;
|
||
}
|
||
gdb_assert (gdbscm_is_exception (scm_result));
|
||
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. */
|
||
|
||
static SCM
|
||
gdbscm_string_to_argv (SCM string_scm)
|
||
{
|
||
char *string;
|
||
char **c_argv;
|
||
int i;
|
||
SCM result = SCM_EOL;
|
||
|
||
gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, NULL, "s",
|
||
string_scm, &string);
|
||
|
||
if (string == NULL || *string == '\0')
|
||
{
|
||
xfree (string);
|
||
return SCM_EOL;
|
||
}
|
||
|
||
c_argv = gdb_buildargv (string);
|
||
for (i = 0; c_argv[i] != NULL; ++i)
|
||
result = scm_cons (gdbscm_scm_from_c_string (c_argv[i]), result);
|
||
|
||
freeargv (c_argv);
|
||
xfree (string);
|
||
|
||
return scm_reverse_x (result, SCM_EOL);
|
||
}
|
||
|
||
/* Initialize the Scheme charset interface to GDB. */
|
||
|
||
static const scheme_function string_functions[] =
|
||
{
|
||
{ "string->argv", 1, 0, 0, gdbscm_string_to_argv,
|
||
"\
|
||
Convert a string to a list of strings split up according to\n\
|
||
gdb's argv parsing rules." },
|
||
|
||
END_FUNCTIONS
|
||
};
|
||
|
||
void
|
||
gdbscm_initialize_strings (void)
|
||
{
|
||
gdbscm_define_functions (string_functions, 1);
|
||
}
|