mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-17 07:53:51 +08:00

This patch removes some unused variables, found with -Wunused. I have not removed everything reported by -Wunused, because some expressions such as struct type *arg_type = check_typedef (value_type); in bfin-tdep.c could have an unexpected but important side-effect. I removed others that I considered more low-risk, such as: struct gdbarch *gdbarch = get_objfile_arch (objfile); I tested building with Python 2/Python 3/no Python, with/without expat, with/without libipt and with/without babeltrace. gdb/ChangeLog: * ada-lang.c (ada_collect_symbol_completion_matches): Remove unused variables. (ada_is_redundant_range_encoding): Likewise. * ada-varobj.c (ada_varobj_get_value_of_array_variable): Likewise. * alpha-tdep.c (alpha_software_single_step): Likewise. * arm-tdep.c (_initialize_arm_tdep): Likewise. * auto-load.c (info_auto_load_cmd): Likewise. * break-catch-syscall.c (insert_catch_syscall): Likewise. (remove_catch_syscall): Likewise. * breakpoint.c (condition_completer): Likewise. (clear_command): Likewise. (update_breakpoint_locations): Likewise. * btrace.c (btrace_disable): Likewise. (btrace_teardown): Likewise. (btrace_maint_update_pt_packets): Likewise. (maint_btrace_clear_cmd): Likewise. * cli/cli-decode.c (lookup_cmd_1): Likewise. (lookup_cmd_composition): Likewise. * cli/cli-dump.c (scan_filename): Likewise. (restore_command): Likewise. * compile/compile-loc2c.c (compute_stack_depth): Likewise. * compile/compile-object-load.c (compile_object_load): Likewise. * compile/compile-object-run.c (compile_object_run): Likewise. * compile/compile.c (compile_to_object): Likewise. * completer.c (filename_completer): Likewise. (complete_files_symbols): Likewise. (complete_expression): Likewise. * corelow.c (core_open): Likewise. * ctf.c (ctf_start): Likewise. (ctf_write_status): Likewise. (ctf_write_uploaded_tsv): Likewise. (ctf_write_definition_end): Likewise. (ctf_open_dir): Likewise. (ctf_xfer_partial): Likewise. (ctf_trace_find): Likewise. * disasm.c (gdb_pretty_print_disassembler::pretty_print_insn): Likewise. * dwarf2loc.c (allocate_piece_closure): Likewise. (indirect_pieced_value): Likewise. (dwarf2_evaluate_loc_desc_full): Likewise. * dwarf2read.c (dw2_expand_marked_cus): Likewise. (dw2_expand_symtabs_matching): Likewise. (dw2_map_symbol_filenames): Likewise. (read_and_check_comp_unit_head): Likewise. (read_cutu_die_from_dwo): Likewise. (lookup_dwo_unit): Likewise. (read_comp_units_from_section): Likewise. (dwarf2_compute_name): Likewise. (handle_DW_AT_stmt_list): Likewise. (create_cus_hash_table): Likewise. (create_dwp_v2_section): Likewise. (dwarf2_rnglists_process): Likewise. (dwarf2_ranges_process): Likewise. (dwarf2_record_block_ranges): Likewise. (is_vtable_name): Likewise. (read_formatted_entries): Likewise. (skip_form_bytes): Likewise. * elfread.c (elf_symtab_read): Likewise. * exec.c (exec_file_command): Likewise. * f-valprint.c (f_val_print): Likewise. (info_common_command_for_block): Likewise. * guile/guile.c (initialize_scheme_side): Likewise. * guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Likewise. * guile/scm-cmd.c (cmdscm_completer): Likewise. (gdbscm_register_command_x): Likewise. * guile/scm-frame.c (gdbscm_frame_read_var): Likewise. * guile/scm-param.c (gdbscm_parameter_value): Likewise. * guile/scm-ports.c (file_port_magic): Likewise. * guile/scm-pretty-print.c (ppscm_search_pp_list): Likewise. (ppscm_pretty_print_one_value): Likewise. (ppscm_print_children): Likewise. * guile/scm-string.c (gdbscm_string_to_argv): Likewise. * guile/scm-symtab.c (gdbscm_sal_symtab): Likewise. * guile/scm-type.c (gdbscm_type_next_field_x): Likewise. * guile/scm-utils.c (gdbscm_parse_function_args): Likewise. * i386-tdep.c (i386_register_reggroup_p): Likewise. * infcmd.c (run_command_1): Likewise. (until_next_fsm_clean_up): Likewise. * linespec.c (linespec_complete): Likewise. (find_label_symbols): Likewise. * m2-valprint.c (m2_val_print): Likewise. * memattr.c (require_user_regions): Likewise. (lookup_mem_region): Likewise. (disable_mem_command): Likewise. (mem_delete): Likewise. * mep-tdep.c (mep_register_name): Likewise. (mep_analyze_prologue): Likewise. * mi/mi-cmd-file.c (mi_cmd_file_list_shared_libraries): Likewise. * mi/mi-interp.c (mi_on_sync_execution_done): Likewise. * mi/mi-main.c (mi_cmd_trace_frame_collected): Likewise. * microblaze-linux-tdep.c (microblaze_linux_init_abi): Likewise. * minidebug.c (lzma_open): Likewise. * minsyms.c (lookup_minimal_symbol): Likewise. * mips-linux-tdep.c (mips64_fill_fpregset): Likewise. * mips-tdep.c (mips_stub_frame_sniffer): Likewise. (mips_o64_return_value): Likewise. (mips_single_step_through_delay): Likewise. (_initialize_mips_tdep): Likewise. * nios2-tdep.c (nios2_push_dummy_call): Likewise. (nios2_software_single_step): Likewise. * parse.c (find_minsym_type_and_address): Likewise. * psymtab.c (psym_relocate): Likewise. * python/py-breakpoint.c (bppy_get_commands): Likewise. (gdbpy_breakpoint_modified): Likewise. * python/py-infevents.c (create_inferior_call_event_object): Likewise. * python/py-record-btrace.c (btpy_list_item): Likewise. * python/py-type.c (typy_str): Likewise. * python/py-value.c (valpy_call): Likewise. * python/python.c (do_start_initialization): Likewise. * record-btrace.c (record_btrace_insn_history_range): Likewise. (record_btrace_call_history_range): Likewise. (record_btrace_record_method): Likewise. (record_btrace_xfer_partial): Likewise. (btrace_get_frame_function): Likewise. * record-full.c (record_full_open): Likewise. * record.c (get_context_size): Likewise. * registry.h (DEFINE_REGISTRY): Likewise. * remote-fileio.c (remote_fileio_request): Likewise. * remote.c (remote_update_thread_list): Likewise. (remote_check_symbols): Likewise. (remote_commit_resume): Likewise. (remote_interrupt): Likewise. (remote_insert_breakpoint): Likewise. (compare_sections_command): Likewise. * rust-exp.y (super_name): Likewise. (lex_string): Likewise. (convert_ast_to_type): Likewise. (convert_ast_to_expression): Likewise. * rust-lang.c (rust_print_struct_def): Likewise. (rust_print_type): Likewise. (rust_evaluate_subexp): Likewise. * rx-tdep.c (rx_register_type): Likewise. * ser-event.c (serial_event_clear): Likewise. * serial.c (serial_open): Likewise. * spu-tdep.c (spu_overlay_new_objfile): Likewise. * symfile.c (section_is_overlay): Likewise. (overlay_unmapped_address): Likewise. (overlay_mapped_address): Likewise. (simple_overlay_update_1): Likewise. (simple_overlay_update): Likewise. * symtab.c (symbol_find_demangled_name): Likewise. (search_symbols): Likewise. * target-descriptions.c (tdesc_predefined_type): Likewise. * target.c (target_commit_resume): Likewise. * thread.c (print_selected_thread_frame): Likewise. * top.c (new_ui_command): Likewise. (gdb_readline_no_editing): Likewise. * tracefile-tfile.c (tfile_open): Likewise. * tracepoint.c (create_tsv_from_upload): Likewise. * utils.c (quit): Likewise. (defaulted_query): Likewise. * valarith.c (value_concat): Likewise. * xml-syscall.c (xml_list_syscalls_by_group): Likewise. * xml-tdesc.c (target_fetch_description_xml): Likewise. * xtensa-tdep.c (xtensa_pseudo_register_read): Likewise. (xtensa_pseudo_register_write): Likewise. gdb/gdbserver/ChangeLog: * regcache.c (registers_to_string): Remove unused variable.
645 lines
16 KiB
C
645 lines
16 KiB
C
/* General utility routines for GDB/Scheme code.
|
||
|
||
Copyright (C) 2014-2017 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 "guile-internal.h"
|
||
|
||
/* Define VARIABLES in the gdb module. */
|
||
|
||
void
|
||
gdbscm_define_variables (const scheme_variable *variables, int is_public)
|
||
{
|
||
const scheme_variable *sv;
|
||
|
||
for (sv = variables; sv->name != NULL; ++sv)
|
||
{
|
||
scm_c_define (sv->name, sv->value);
|
||
if (is_public)
|
||
scm_c_export (sv->name, NULL);
|
||
}
|
||
}
|
||
|
||
/* Define FUNCTIONS in the gdb module. */
|
||
|
||
void
|
||
gdbscm_define_functions (const scheme_function *functions, int is_public)
|
||
{
|
||
const scheme_function *sf;
|
||
|
||
for (sf = functions; sf->name != NULL; ++sf)
|
||
{
|
||
SCM proc = scm_c_define_gsubr (sf->name, sf->required, sf->optional,
|
||
sf->rest, sf->func);
|
||
|
||
scm_set_procedure_property_x (proc, gdbscm_documentation_symbol,
|
||
gdbscm_scm_from_c_string (sf->doc_string));
|
||
if (is_public)
|
||
scm_c_export (sf->name, NULL);
|
||
}
|
||
}
|
||
|
||
/* Define CONSTANTS in the gdb module. */
|
||
|
||
void
|
||
gdbscm_define_integer_constants (const scheme_integer_constant *constants,
|
||
int is_public)
|
||
{
|
||
const scheme_integer_constant *sc;
|
||
|
||
for (sc = constants; sc->name != NULL; ++sc)
|
||
{
|
||
scm_c_define (sc->name, scm_from_int (sc->value));
|
||
if (is_public)
|
||
scm_c_export (sc->name, NULL);
|
||
}
|
||
}
|
||
|
||
/* scm_printf, alas it doesn't exist. */
|
||
|
||
void
|
||
gdbscm_printf (SCM port, const char *format, ...)
|
||
{
|
||
va_list args;
|
||
char *string;
|
||
|
||
va_start (args, format);
|
||
string = xstrvprintf (format, args);
|
||
va_end (args);
|
||
scm_puts (string, port);
|
||
xfree (string);
|
||
}
|
||
|
||
/* Utility for calling from gdb to "display" an SCM object. */
|
||
|
||
void
|
||
gdbscm_debug_display (SCM obj)
|
||
{
|
||
SCM port = scm_current_output_port ();
|
||
|
||
scm_display (obj, port);
|
||
scm_newline (port);
|
||
scm_force_output (port);
|
||
}
|
||
|
||
/* Utility for calling from gdb to "write" an SCM object. */
|
||
|
||
void
|
||
gdbscm_debug_write (SCM obj)
|
||
{
|
||
SCM port = scm_current_output_port ();
|
||
|
||
scm_write (obj, port);
|
||
scm_newline (port);
|
||
scm_force_output (port);
|
||
}
|
||
|
||
/* Subroutine of gdbscm_parse_function_args to simplify it.
|
||
Return the number of keyword arguments. */
|
||
|
||
static int
|
||
count_keywords (const SCM *keywords)
|
||
{
|
||
int i;
|
||
|
||
if (keywords == NULL)
|
||
return 0;
|
||
for (i = 0; keywords[i] != SCM_BOOL_F; ++i)
|
||
continue;
|
||
|
||
return i;
|
||
}
|
||
|
||
/* Subroutine of gdbscm_parse_function_args to simplify it.
|
||
Validate an argument format string.
|
||
The result is a boolean indicating if "." was seen. */
|
||
|
||
static int
|
||
validate_arg_format (const char *format)
|
||
{
|
||
const char *p;
|
||
int length = strlen (format);
|
||
int optional_position = -1;
|
||
int keyword_position = -1;
|
||
int dot_seen = 0;
|
||
|
||
gdb_assert (length > 0);
|
||
|
||
for (p = format; *p != '\0'; ++p)
|
||
{
|
||
switch (*p)
|
||
{
|
||
case 's':
|
||
case 't':
|
||
case 'i':
|
||
case 'u':
|
||
case 'l':
|
||
case 'n':
|
||
case 'L':
|
||
case 'U':
|
||
case 'O':
|
||
break;
|
||
case '|':
|
||
gdb_assert (keyword_position < 0);
|
||
gdb_assert (optional_position < 0);
|
||
optional_position = p - format;
|
||
break;
|
||
case '#':
|
||
gdb_assert (keyword_position < 0);
|
||
keyword_position = p - format;
|
||
break;
|
||
case '.':
|
||
gdb_assert (p[1] == '\0');
|
||
dot_seen = 1;
|
||
break;
|
||
default:
|
||
gdb_assert_not_reached ("invalid argument format character");
|
||
}
|
||
}
|
||
|
||
return dot_seen;
|
||
}
|
||
|
||
/* Our version of SCM_ASSERT_TYPE that calls gdbscm_make_type_error. */
|
||
#define CHECK_TYPE(ok, arg, position, func_name, expected_type) \
|
||
do { \
|
||
if (!(ok)) \
|
||
{ \
|
||
return gdbscm_make_type_error ((func_name), (position), (arg), \
|
||
(expected_type)); \
|
||
} \
|
||
} while (0)
|
||
|
||
/* Subroutine of gdbscm_parse_function_args to simplify it.
|
||
Check the type of ARG against FORMAT_CHAR and extract the value.
|
||
POSITION is the position of ARG in the argument list.
|
||
The result is #f upon success or a <gdb:exception> object. */
|
||
|
||
static SCM
|
||
extract_arg (char format_char, SCM arg, void *argp,
|
||
const char *func_name, int position)
|
||
{
|
||
switch (format_char)
|
||
{
|
||
case 's':
|
||
{
|
||
char **arg_ptr = (char **) argp;
|
||
|
||
CHECK_TYPE (gdbscm_is_true (scm_string_p (arg)), arg, position,
|
||
func_name, _("string"));
|
||
*arg_ptr = gdbscm_scm_to_c_string (arg);
|
||
break;
|
||
}
|
||
case 't':
|
||
{
|
||
int *arg_ptr = (int *) argp;
|
||
|
||
/* While in Scheme, anything non-#f is "true", we're strict. */
|
||
CHECK_TYPE (gdbscm_is_bool (arg), arg, position, func_name,
|
||
_("boolean"));
|
||
*arg_ptr = gdbscm_is_true (arg);
|
||
break;
|
||
}
|
||
case 'i':
|
||
{
|
||
int *arg_ptr = (int *) argp;
|
||
|
||
CHECK_TYPE (scm_is_signed_integer (arg, INT_MIN, INT_MAX),
|
||
arg, position, func_name, _("int"));
|
||
*arg_ptr = scm_to_int (arg);
|
||
break;
|
||
}
|
||
case 'u':
|
||
{
|
||
int *arg_ptr = (int *) argp;
|
||
|
||
CHECK_TYPE (scm_is_unsigned_integer (arg, 0, UINT_MAX),
|
||
arg, position, func_name, _("unsigned int"));
|
||
*arg_ptr = scm_to_uint (arg);
|
||
break;
|
||
}
|
||
case 'l':
|
||
{
|
||
long *arg_ptr = (long *) argp;
|
||
|
||
CHECK_TYPE (scm_is_signed_integer (arg, LONG_MIN, LONG_MAX),
|
||
arg, position, func_name, _("long"));
|
||
*arg_ptr = scm_to_long (arg);
|
||
break;
|
||
}
|
||
case 'n':
|
||
{
|
||
unsigned long *arg_ptr = (unsigned long *) argp;
|
||
|
||
CHECK_TYPE (scm_is_unsigned_integer (arg, 0, ULONG_MAX),
|
||
arg, position, func_name, _("unsigned long"));
|
||
*arg_ptr = scm_to_ulong (arg);
|
||
break;
|
||
}
|
||
case 'L':
|
||
{
|
||
LONGEST *arg_ptr = (LONGEST *) argp;
|
||
|
||
CHECK_TYPE (scm_is_signed_integer (arg, INT64_MIN, INT64_MAX),
|
||
arg, position, func_name, _("LONGEST"));
|
||
*arg_ptr = gdbscm_scm_to_longest (arg);
|
||
break;
|
||
}
|
||
case 'U':
|
||
{
|
||
ULONGEST *arg_ptr = (ULONGEST *) argp;
|
||
|
||
CHECK_TYPE (scm_is_unsigned_integer (arg, 0, UINT64_MAX),
|
||
arg, position, func_name, _("ULONGEST"));
|
||
*arg_ptr = gdbscm_scm_to_ulongest (arg);
|
||
break;
|
||
}
|
||
case 'O':
|
||
{
|
||
SCM *arg_ptr = (SCM *) argp;
|
||
|
||
*arg_ptr = arg;
|
||
break;
|
||
}
|
||
default:
|
||
gdb_assert_not_reached ("invalid argument format character");
|
||
}
|
||
|
||
return SCM_BOOL_F;
|
||
}
|
||
|
||
#undef CHECK_TYPE
|
||
|
||
/* Look up KEYWORD in KEYWORD_LIST.
|
||
The result is the index of the keyword in the list or -1 if not found. */
|
||
|
||
static int
|
||
lookup_keyword (const SCM *keyword_list, SCM keyword)
|
||
{
|
||
int i = 0;
|
||
|
||
while (keyword_list[i] != SCM_BOOL_F)
|
||
{
|
||
if (scm_is_eq (keyword_list[i], keyword))
|
||
return i;
|
||
++i;
|
||
}
|
||
|
||
return -1;
|
||
}
|
||
|
||
/* Utility to parse required, optional, and keyword arguments to Scheme
|
||
functions. Modelled on PyArg_ParseTupleAndKeywords, but no attempt is made
|
||
at similarity or functionality.
|
||
There is no result, if there's an error a Scheme exception is thrown.
|
||
|
||
Guile provides scm_c_bind_keyword_arguments, and feel free to use it.
|
||
This is for times when we want a bit more parsing.
|
||
|
||
BEGINNING_ARG_POS is the position of the first argument passed to this
|
||
routine. It should be one of the SCM_ARGn values. It could be > SCM_ARG1
|
||
if the caller chooses not to parse one or more required arguments.
|
||
|
||
KEYWORDS may be NULL if there are no keywords.
|
||
|
||
FORMAT:
|
||
s - string -> char *, malloc'd
|
||
t - boolean (gdb uses "t", for biT?) -> int
|
||
i - int
|
||
u - unsigned int
|
||
l - long
|
||
n - unsigned long
|
||
L - longest
|
||
U - unsigned longest
|
||
O - random scheme object
|
||
| - indicates the next set is for optional arguments
|
||
# - indicates the next set is for keyword arguments (must follow |)
|
||
. - indicates "rest" arguments are present, this character must appear last
|
||
|
||
FORMAT must match the definition from scm_c_{make,define}_gsubr.
|
||
Required and optional arguments appear in order in the format string.
|
||
Afterwards, keyword-based arguments are processed. There must be as many
|
||
remaining characters in the format string as their are keywords.
|
||
Except for "|#.", the number of characters in the format string must match
|
||
#required + #optional + #keywords.
|
||
|
||
The function is required to be defined in a compatible manner:
|
||
#required-args and #optional-arguments must match, and rest-arguments
|
||
must be specified if keyword args are desired, and/or regular "rest" args.
|
||
|
||
Example: For this function,
|
||
scm_c_define_gsubr ("execute", 2, 3, 1, foo);
|
||
the format string + keyword list could be any of:
|
||
1) "ss|ttt#tt", { "key1", "key2", NULL }
|
||
2) "ss|ttt.", { NULL }
|
||
3) "ss|ttt#t.", { "key1", NULL }
|
||
|
||
For required and optional args pass the SCM of the argument, and a
|
||
pointer to the value to hold the parsed result (type depends on format
|
||
char). After that pass the SCM containing the "rest" arguments followed
|
||
by pointers to values to hold parsed keyword arguments, and if specified
|
||
a pointer to hold the remaining contents of "rest".
|
||
|
||
For keyword arguments pass two pointers: the first is a pointer to an int
|
||
that will contain the position of the argument in the arg list, and the
|
||
second will contain result of processing the argument. The int pointed
|
||
to by the first value should be initialized to -1. It can then be used
|
||
to tell whether the keyword was present.
|
||
|
||
If both keyword and rest arguments are present, the caller must pass a
|
||
pointer to contain the new value of rest (after keyword args have been
|
||
removed).
|
||
|
||
There's currently no way, that I know of, to specify default values for
|
||
optional arguments in C-provided functions. At the moment they're a
|
||
work-in-progress. The caller should test SCM_UNBNDP for each optional
|
||
argument. Unbound optional arguments are ignored. */
|
||
|
||
void
|
||
gdbscm_parse_function_args (const char *func_name,
|
||
int beginning_arg_pos,
|
||
const SCM *keywords,
|
||
const char *format, ...)
|
||
{
|
||
va_list args;
|
||
const char *p;
|
||
int i, have_rest, num_keywords, position;
|
||
int have_optional = 0;
|
||
SCM status;
|
||
SCM rest = SCM_EOL;
|
||
/* Keep track of malloc'd strings. We need to free them upon error. */
|
||
VEC (char_ptr) *allocated_strings = NULL;
|
||
char *ptr;
|
||
|
||
have_rest = validate_arg_format (format);
|
||
num_keywords = count_keywords (keywords);
|
||
|
||
va_start (args, format);
|
||
|
||
p = format;
|
||
position = beginning_arg_pos;
|
||
|
||
/* Process required, optional arguments. */
|
||
|
||
while (*p && *p != '#' && *p != '.')
|
||
{
|
||
SCM arg;
|
||
void *arg_ptr;
|
||
|
||
if (*p == '|')
|
||
{
|
||
have_optional = 1;
|
||
++p;
|
||
continue;
|
||
}
|
||
|
||
arg = va_arg (args, SCM);
|
||
if (!have_optional || !SCM_UNBNDP (arg))
|
||
{
|
||
arg_ptr = va_arg (args, void *);
|
||
status = extract_arg (*p, arg, arg_ptr, func_name, position);
|
||
if (!gdbscm_is_false (status))
|
||
goto fail;
|
||
if (*p == 's')
|
||
VEC_safe_push (char_ptr, allocated_strings, *(char **) arg_ptr);
|
||
}
|
||
++p;
|
||
++position;
|
||
}
|
||
|
||
/* Process keyword arguments. */
|
||
|
||
if (have_rest || num_keywords > 0)
|
||
rest = va_arg (args, SCM);
|
||
|
||
if (num_keywords > 0)
|
||
{
|
||
SCM *keyword_args = XALLOCAVEC (SCM, num_keywords);
|
||
int *keyword_positions = XALLOCAVEC (int, num_keywords);
|
||
|
||
gdb_assert (*p == '#');
|
||
++p;
|
||
|
||
for (i = 0; i < num_keywords; ++i)
|
||
{
|
||
keyword_args[i] = SCM_UNSPECIFIED;
|
||
keyword_positions[i] = -1;
|
||
}
|
||
|
||
while (scm_is_pair (rest)
|
||
&& scm_is_keyword (scm_car (rest)))
|
||
{
|
||
SCM keyword = scm_car (rest);
|
||
|
||
i = lookup_keyword (keywords, keyword);
|
||
if (i < 0)
|
||
{
|
||
status = gdbscm_make_error (scm_arg_type_key, func_name,
|
||
_("Unrecognized keyword: ~a"),
|
||
scm_list_1 (keyword), keyword);
|
||
goto fail;
|
||
}
|
||
if (!scm_is_pair (scm_cdr (rest)))
|
||
{
|
||
status = gdbscm_make_error
|
||
(scm_arg_type_key, func_name,
|
||
_("Missing value for keyword argument"),
|
||
scm_list_1 (keyword), keyword);
|
||
goto fail;
|
||
}
|
||
keyword_args[i] = scm_cadr (rest);
|
||
keyword_positions[i] = position + 1;
|
||
rest = scm_cddr (rest);
|
||
position += 2;
|
||
}
|
||
|
||
for (i = 0; i < num_keywords; ++i)
|
||
{
|
||
int *arg_pos_ptr = va_arg (args, int *);
|
||
void *arg_ptr = va_arg (args, void *);
|
||
SCM arg = keyword_args[i];
|
||
|
||
if (! scm_is_eq (arg, SCM_UNSPECIFIED))
|
||
{
|
||
*arg_pos_ptr = keyword_positions[i];
|
||
status = extract_arg (p[i], arg, arg_ptr, func_name,
|
||
keyword_positions[i]);
|
||
if (!gdbscm_is_false (status))
|
||
goto fail;
|
||
if (p[i] == 's')
|
||
{
|
||
VEC_safe_push (char_ptr, allocated_strings,
|
||
*(char **) arg_ptr);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/* Process "rest" arguments. */
|
||
|
||
if (have_rest)
|
||
{
|
||
if (num_keywords > 0)
|
||
{
|
||
SCM *rest_ptr = va_arg (args, SCM *);
|
||
|
||
*rest_ptr = rest;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (! scm_is_null (rest))
|
||
{
|
||
status = gdbscm_make_error (scm_args_number_key, func_name,
|
||
_("Too many arguments"),
|
||
SCM_EOL, SCM_BOOL_F);
|
||
goto fail;
|
||
}
|
||
}
|
||
|
||
va_end (args);
|
||
VEC_free (char_ptr, allocated_strings);
|
||
return;
|
||
|
||
fail:
|
||
va_end (args);
|
||
for (i = 0; VEC_iterate (char_ptr, allocated_strings, i, ptr); ++i)
|
||
xfree (ptr);
|
||
VEC_free (char_ptr, allocated_strings);
|
||
gdbscm_throw (status);
|
||
}
|
||
|
||
/* Return longest L as a scheme object. */
|
||
|
||
SCM
|
||
gdbscm_scm_from_longest (LONGEST l)
|
||
{
|
||
return scm_from_int64 (l);
|
||
}
|
||
|
||
/* Convert scheme object L to LONGEST.
|
||
It is an error to call this if L is not an integer in range of LONGEST.
|
||
(because the underlying Scheme function will thrown an exception,
|
||
which is not part of our contract with the caller). */
|
||
|
||
LONGEST
|
||
gdbscm_scm_to_longest (SCM l)
|
||
{
|
||
return scm_to_int64 (l);
|
||
}
|
||
|
||
/* Return unsigned longest L as a scheme object. */
|
||
|
||
SCM
|
||
gdbscm_scm_from_ulongest (ULONGEST l)
|
||
{
|
||
return scm_from_uint64 (l);
|
||
}
|
||
|
||
/* Convert scheme object U to ULONGEST.
|
||
It is an error to call this if U is not an integer in range of ULONGEST
|
||
(because the underlying Scheme function will thrown an exception,
|
||
which is not part of our contract with the caller). */
|
||
|
||
ULONGEST
|
||
gdbscm_scm_to_ulongest (SCM u)
|
||
{
|
||
return scm_to_uint64 (u);
|
||
}
|
||
|
||
/* Same as scm_dynwind_free, but uses xfree. */
|
||
|
||
void
|
||
gdbscm_dynwind_xfree (void *ptr)
|
||
{
|
||
scm_dynwind_unwind_handler (xfree, ptr, SCM_F_WIND_EXPLICITLY);
|
||
}
|
||
|
||
/* Return non-zero if PROC is a procedure. */
|
||
|
||
int
|
||
gdbscm_is_procedure (SCM proc)
|
||
{
|
||
return gdbscm_is_true (scm_procedure_p (proc));
|
||
}
|
||
|
||
/* Same as xstrdup, but the string is allocated on the GC heap. */
|
||
|
||
char *
|
||
gdbscm_gc_xstrdup (const char *str)
|
||
{
|
||
size_t len = strlen (str);
|
||
char *result
|
||
= (char *) scm_gc_malloc_pointerless (len + 1, "gdbscm_gc_xstrdup");
|
||
|
||
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 = (char **) 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;
|
||
}
|
||
|
||
/* Return non-zero if the version of Guile being used it at least
|
||
MAJOR.MINOR.MICRO. */
|
||
|
||
int
|
||
gdbscm_guile_version_is_at_least (int major, int minor, int micro)
|
||
{
|
||
if (major > gdbscm_guile_major_version)
|
||
return 0;
|
||
if (major < gdbscm_guile_major_version)
|
||
return 1;
|
||
if (minor > gdbscm_guile_minor_version)
|
||
return 0;
|
||
if (minor < gdbscm_guile_minor_version)
|
||
return 1;
|
||
if (micro > gdbscm_guile_micro_version)
|
||
return 0;
|
||
return 1;
|
||
}
|