aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2017-04-05-Wwrite-strings: The RestPedro Alves150-452/+737
This is the remainder boring constification that all looks more of less borderline obvious IMO. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * ada-exp.y (yyerror): Constify. * ada-lang.c (bound_name, get_selections) (ada_variant_discrim_type) (ada_variant_discrim_name, ada_value_struct_elt) (ada_lookup_struct_elt_type, is_unchecked_variant) (ada_which_variant_applies, standard_exc, ada_get_next_arg) (catch_ada_exception_command_split) (catch_ada_assert_command_split, catch_assert_command) (ada_op_name): Constify. * ada-lang.h (ada_yyerror, get_selections) (ada_variant_discrim_name, ada_value_struct_elt): Constify. * arc-tdep.c (arc_print_frame_cache): Constify. * arm-tdep.c (arm_skip_stub): Constify. * ax-gdb.c (gen_binop, gen_struct_ref_recursive, gen_struct_ref) (gen_aggregate_elt_ref): Constify. * bcache.c (print_bcache_statistics): Constify. * bcache.h (print_bcache_statistics): Constify. * break-catch-throw.c (catch_exception_command_1): * breakpoint.c (struct ep_type_description::description): Constify. (add_solib_catchpoint): Constify. (catch_fork_command_1): Add cast. (add_catch_command): Constify. * breakpoint.h (add_catch_command, add_solib_catchpoint): Constify. * bsd-uthread.c (bsd_uthread_state): Constify. * buildsym.c (patch_subfile_names): Constify. * buildsym.h (next_symbol_text_func, patch_subfile_names): Constify. * c-exp.y (yyerror): Constify. (token::oper): Constify. * c-lang.h (c_yyerror, cp_print_class_member): Constify. * c-varobj.c (cplus_describe_child): Constify. * charset.c (find_charset_names): Add cast. (find_charset_names): Constify array and add const_cast. * cli/cli-cmds.c (complete_command, cd_command): Constify. (edit_command): Constify. * cli/cli-decode.c (lookup_cmd): Constify. * cli/cli-dump.c (dump_memory_command, dump_value_command): Constify. (struct dump_context): Constify. (add_dump_command, restore_command): Constify. * cli/cli-script.c (get_command_line): Constify. * cli/cli-script.h (get_command_line): Constify. * cli/cli-utils.c (check_for_argument): Constify. * cli/cli-utils.h (check_for_argument): Constify. * coff-pe-read.c (struct read_pe_section_data): Constify. * command.h (lookup_cmd): Constify. * common/print-utils.c (decimal2str): Constify. * completer.c (gdb_print_filename): Constify. * corefile.c (set_gnutarget): Constify. * cp-name-parser.y (yyerror): Constify. * cp-valprint.c (cp_print_class_member): Constify. * cris-tdep.c (cris_register_name, crisv32_register_name): Constify. * d-exp.y (yyerror): Constify. (struct token::oper): Constify. * d-lang.h (d_yyerror): Constify. * dbxread.c (struct header_file_location::name): Constify. (add_old_header_file, add_new_header_file, last_function_name) (dbx_next_symbol_text, add_bincl_to_list) (find_corresponding_bincl_psymtab, set_namestring) (find_stab_function_addr, read_dbx_symtab, start_psymtab) (dbx_end_psymtab, read_ofile_symtab, process_one_symbol): * defs.h (command_line_input, print_address_symbolic) (deprecated_readline_begin_hook): Constify. * dwarf2read.c (anonymous_struct_prefix, dwarf_bool_name): Constify. * event-top.c (handle_line_of_input): Constify and add cast. * exceptions.c (catch_errors): Constify. * exceptions.h (catch_errors): Constify. * expprint.c (print_subexp_standard, op_string, op_name) (op_name_standard, dump_raw_expression, dump_raw_expression): * expression.h (op_name, op_string, dump_raw_expression): Constify. * f-exp.y (yyerror): Constify. (struct token::oper): Constify. (struct f77_boolean_val::name): Constify. * f-lang.c (f_word_break_characters): Constify. * f-lang.h (f_yyerror): Constify. * fork-child.c (fork_inferior): Add cast. * frv-tdep.c (struct gdbarch_tdep::register_names): Constify. (new_variant): Constify. * gdbarch.sh (pstring_ptr, pstring_list): Constify. * gdbarch.c: Regenerate. * gdbcore.h (set_gnutarget): Constify. * go-exp.y (yyerror): Constify. (token::oper): Constify. * go-lang.h (go_yyerror): Constify. * go32-nat.c (go32_sysinfo): Constify. * guile/scm-breakpoint.c (gdbscm_breakpoint_expression): Constify. * guile/scm-cmd.c (cmdscm_function): Constify. * guile/scm-param.c (pascm_param_value): Constify. * h8300-tdep.c (h8300_register_name, h8300s_register_name) (h8300sx_register_name): Constify. * hppa-tdep.c (hppa32_register_name, hppa64_register_name): Constify. * ia64-tdep.c (ia64_register_names): Constify. * infcmd.c (construct_inferior_arguments): Constify. (path_command, attach_post_wait): Constify. * language.c (show_range_command, show_case_command) (unk_lang_error): Constify. * language.h (language_defn::la_error) (language_defn::la_name_of_this): Constify. * linespec.c (decode_line_2): Constify. * linux-thread-db.c (thread_db_err_str): Constify. * lm32-tdep.c (lm32_register_name): Constify. * m2-exp.y (yyerror): Constify. * m2-lang.h (m2_yyerror): Constify. * m32r-tdep.c (m32r_register_names): Constify and make static. * m68hc11-tdep.c (m68hc11_register_names): Constify. * m88k-tdep.c (m88k_register_name): Constify. * macroexp.c (appendmem): Constify. * mdebugread.c (fdr_name, add_data_symbol, parse_type) (upgrade_type, parse_external, parse_partial_symbols) (mdebug_next_symbol_text, cross_ref, mylookup_symbol, new_psymtab) (new_symbol): Constify. * memattr.c (mem_info_command): Constify. * mep-tdep.c (register_name_from_keyword): Constify. * mi/mi-cmd-env.c (mi_cmd_env_path, _initialize_mi_cmd_env): Constify. * mi/mi-cmd-stack.c (list_args_or_locals): Constify. * mi/mi-cmd-var.c (mi_cmd_var_show_attributes): Constify. * mi/mi-main.c (captured_mi_execute_command): Constify and add cast. (mi_execute_async_cli_command): Constify. * mips-tdep.c (mips_register_name): Constify. * mn10300-tdep.c (register_name, mn10300_generic_register_name) (am33_register_name, am33_2_register_name) * moxie-tdep.c (moxie_register_names): Constify. * nat/linux-osdata.c (osdata_type): Constify fields. * nto-tdep.c (nto_parse_redirection): Constify. * objc-lang.c (lookup_struct_typedef, lookup_objc_class) (lookup_child_selector): Constify. (objc_methcall::name): Constify. * objc-lang.h (lookup_objc_class, lookup_child_selector) (lookup_struct_typedef): Constify. * objfiles.c (pc_in_section): Constify. * objfiles.h (pc_in_section): Constify. * p-exp.y (struct token::oper): Constify. (yyerror): Constify. * p-lang.h (pascal_yyerror): Constify. * parser-defs.h (op_name_standard): Constify. (op_print::string): Constify. (exp_descriptor::op_name): Constify. * printcmd.c (print_address_symbolic): Constify. * psymtab.c (print_partial_symbols): Constify. * python/py-breakpoint.c (stop_func): Constify. (bppy_get_expression): Constify. * python/py-cmd.c (cmdpy_completer::name): Constify. (cmdpy_function): Constify. * python/py-event.c (evpy_add_attribute) (gdbpy_initialize_event_generic): Constify. * python/py-event.h (evpy_add_attribute) (gdbpy_initialize_event_generic): Constify. * python/py-evts.c (add_new_registry): Constify. * python/py-finishbreakpoint.c (outofscope_func): Constify. * python/py-framefilter.c (get_py_iter_from_func): Constify. * python/py-inferior.c (get_buffer): Add cast. * python/py-param.c (parm_constant::name): Constify. * python/py-unwind.c (fprint_frame_id): Constify. * python/python.c (gdbpy_parameter_value): Constify. * remote-fileio.c (remote_fio_func_map): Make 'name' const. * remote.c (memory_packet_config::name): Constify. (show_packet_config_cmd, remote_write_bytes) (remote_buffer_add_string): * reverse.c (exec_reverse_once): Constify. * rs6000-tdep.c (variant::name, variant::description): Constify. * rust-exp.y (rustyyerror): Constify. * rust-lang.c (rust_op_name): Constify. * rust-lang.h (rustyyerror): Constify. * serial.h (serial_ops::name): Constify. * sh-tdep.c (sh_sh_register_name, sh_sh3_register_name) (sh_sh3e_register_name, sh_sh2e_register_name) (sh_sh2a_register_name, sh_sh2a_nofpu_register_name) (sh_sh_dsp_register_name, sh_sh3_dsp_register_name) (sh_sh4_register_name, sh_sh4_nofpu_register_name) (sh_sh4al_dsp_register_name): Constify. * sh64-tdep.c (sh64_register_name): Constify. * solib-darwin.c (lookup_symbol_from_bfd): Constify. * spu-tdep.c (spu_register_name, info_spu_dma_cmdlist): Constify. * stabsread.c (patch_block_stabs, read_type_number) (ref_map::stabs, ref_add, process_reference) (symbol_reference_defined, define_symbol, define_symbol) (error_type, read_type, read_member_functions, read_cpp_abbrev) (read_one_struct_field, read_struct_fields, read_baseclasses) (read_tilde_fields, read_struct_type, read_array_type) (read_enum_type, read_sun_builtin_type, read_sun_floating_type) (read_huge_number, read_range_type, read_args, common_block_start) (find_name_end): Constify. * stabsread.h (common_block_start, define_symbol) (process_one_symbol, symbol_reference_defined, ref_add): * symfile.c (get_section_index, add_symbol_file_command): * symfile.h (get_section_index): Constify. * target-descriptions.c (tdesc_type::name): Constify. (tdesc_free_type): Add cast. * target.c (find_default_run_target): (add_deprecated_target_alias, find_default_run_target) (target_announce_detach): Constify. (do_option): Constify. * target.h (add_deprecated_target_alias): Constify. * thread.c (print_thread_info_1): Constify. * top.c (deprecated_readline_begin_hook, command_line_input): Constify. (init_main): Add casts. * top.h (handle_line_of_input): Constify. * tracefile-tfile.c (tfile_write_uploaded_tsv): Constify. * tracepoint.c (tvariables_info_1, trace_status_mi): Constify. (tfind_command): Rename to ... (tfind_command_1): ... this and constify. (tfind_command): New function. (tfind_end_command, tfind_start_command): Adjust. (encode_source_string): Constify. * tracepoint.h (encode_source_string): Constify. * tui/tui-data.c (tui_partial_win_by_name): Constify. * tui/tui-data.h (tui_partial_win_by_name): Constify. * tui/tui-source.c (tui_set_source_content_nil): Constify. * tui/tui-source.h (tui_set_source_content_nil): Constify. * tui/tui-win.c (parse_scrolling_args): Constify. * tui/tui-windata.c (tui_erase_data_content): Constify. * tui/tui-windata.h (tui_erase_data_content): Constify. * tui/tui-winsource.c (tui_erase_source_content): Constify. * tui/tui.c (tui_enable): Add cast. * utils.c (defaulted_query): Constify. (init_page_info): Add cast. (puts_debug, subset_compare): Constify. * utils.h (subset_compare): Constify. * varobj.c (varobj_format_string): Constify. * varobj.h (varobj_format_string): Constify. * vax-tdep.c (vax_register_name): Constify. * windows-nat.c (windows_detach): Constify. * xcoffread.c (process_linenos, xcoff_next_symbol_text): Constify. * xml-support.c (gdb_xml_end_element): Constify. * xml-tdesc.c (tdesc_start_reg): Constify. * xstormy16-tdep.c (xstormy16_register_name): Constify. * xtensa-tdep.c (xtensa_find_register_by_name): Constify. * xtensa-tdep.h (xtensa_register_t::name): Constify. gdb/gdbserver/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * gdbreplay.c (sync_error): Constify. * linux-x86-low.c (push_opcode): Constify.
2017-04-05-Wwrite-strings: More SolarisPedro Alves8-24/+37
Some obvious constifications found by attempting to build 64-bit GDB on Solaris 11. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * proc-api.c (struct trans): Constify. (procfs_note): Constify. * proc-events.c (struct trans, syscall_table): * proc-flags.c (struct trans): Constify. * proc-utils.h (procfs_note): Constify. * proc-why.c (struct trans): Constify. * procfs.c (dead_procinfo, find_syscall, proc_warn, proc_error) (procfs_detach): Constify. * sol-thread.c (struct string_map): Constify. (td_err_string, td_state_string): Constify.
2017-04-05-Wwrite-strings: Fix Solaris "set procfs-file"Pedro Alves2-3/+10
Compiling GDB with -Wwrite-strings flags this code in gdb/proc-api.c: static char *procfs_filename = "procfs_trace"; as needing a cast. However, this variable is a command variable, and as such it's incorrect to initialize it to a literal, since when you use the corresponding set command, gdb frees the old string... I didn't manage to fully build Solaris gdb (fails for other reasons), but I confirmed that the system GDB on Solaris 11 crashes when running this command: (gdb) set procfs-file foo Segmentation Fault (core dumped) So I don't think this commit can make it worse than the status quo. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * proc-api.c (procfs_filename): Don't initialize procfs_filename. (prepare_to_trace): Assume procfs_filename is non-NULL. (_initialize_proc_api): Give procfs_filename a default value here.
2017-04-05-Wwrite-strings: Some constification in gdb/breakpoint.cPedro Alves6-29/+72
The main motivation here is avoiding having to write a couple casts like these: if (!arg) - arg = ""; + arg = (char *) ""; in catch_exception_command_1 and catch_exec_command_1. That requires making ep_parse_optional_if_clause and check_for_argument take pointers to const strings. I then tried propagating the resulting constification all the way, but that was spiraling out of control, so instead I settled for keeping const and non-const overloads. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * break-catch-throw.c (handle_gnu_v3_exceptions): Constify 'cond_string' parameter. (extract_exception_regexp): Constify 'string' parameter. (catch_exception_command_1): Constify. * breakpoint.c (init_catchpoint) (create_fork_vfork_event_catchpoint): Constify 'cond_string' parameter. (ep_parse_optional_if_clause, catch_fork_command_1) (catch_exec_command_1): Constify. * breakpoint.h (init_catchpoint): Constify 'cond_string' parameter. (ep_parse_optional_if_clause): Constify. * cli/cli-utils.c (remove_trailing_whitespace) (check_for_argument): Constify. * cli/cli-utils.h (remove_trailing_whitespace): Constify and add non-const overload. (check_for_argument): Likewise.
2017-04-05-Wwrite-strings: execute_command calls with string literalsPedro Alves5-13/+25
This is ugly, but it's just making the uglyness explicit. All these places would better be calling some API function directly instead of going through execute_command & friends... gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * event-top.c (command_line_handler): Add cast to execute_command call. * record-btrace.c (cmd_record_btrace_bts_start) (cmd_record_btrace_pt_start, cmd_record_btrace_start) (cmd_record_btrace_start): Add cast to execute_command call. * record-full.c (record_full_goto_insn): * record.c (record_start, record_stop): Add cast to execute_command_to_string calls. (cmd_record_start): Add cast to execute_command calls.
2017-04-05-Wwrite-strings: Add a PyArg_ParseTupleAndKeywords "const char *" overloadPedro Alves12-63/+111
-Wwrite-strings flags code like: static char *keywords[] = {"command", "from_tty", "to_string", NULL }; as needing "(char *)" casts, because string literals are "const char []". We can get rid of the casts by changing the array type like this: - static char *keywords[] = {"command", "from_tty", "to_string", NULL }; + static const char *keywords[] = {"command", "from_tty", "to_string", NULL }; However, passing the such array to PyArg_ParseTupleAndKeywords no longer works OOTB, because PyArg_ParseTupleAndKeywords expects a "char **": PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, char *keywords[], ...); and "const char **" is not implicitly convertible to "char **". C++ is more tolerant that C here WRT aliasing, and a const_cast<char **> is fine. However, to avoid having all callers do the cast themselves, this commit defines a gdb_PyArg_ParseTupleAndKeywords function here with a corresponding 'keywords' parameter type that does the cast in a single place. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * python/python-internal.h (gdb_PyArg_ParseTupleAndKeywords): New static inline function. * python/py-arch.c (archpy_disassemble): Constify 'keywords' array and use gdb_PyArg_ParseTupleAndKeywords. * python/py-cmd.c (cmdpy_init): Likewise. * python/py-finishbreakpoint.c (bpfinishpy_init): Likewise. * python/py-inferior.c (infpy_read_memory, infpy_write_memory) (infpy_search_memory): Likewise. * python/py-objfile.c (objfpy_add_separate_debug_file) (gdbpy_lookup_objfile): Likewise. * python/py-symbol.c (gdbpy_lookup_symbol) (gdbpy_lookup_global_symbol): Likewise. * python/py-type.c (gdbpy_lookup_type): Likewise. * python/py-value.c (valpy_lazy_string, valpy_string): Likewise. * python/python.c (execute_gdb_command, gdbpy_write, gdbpy_flush): Likewise.
2017-04-05-Wwrite-strings: Wrap PyGetSetDef for construction with string literalsPedro Alves18-19/+72
Unfortunately, PyGetSetDef's 'name' and 'doc' members are 'char *' instead of 'const char *', meaning that in order to list-initialize PyGetSetDef arrays using string literals requires writing explicit 'char *' casts. For example: static PyGetSetDef value_object_getset[] = { - { "address", valpy_get_address, NULL, "The address of the value.", + { (char *) "address", valpy_get_address, NULL, + (char *) "The address of the value.", NULL }, - { "is_optimized_out", valpy_get_is_optimized_out, NULL, - "Boolean telling whether the value is optimized " + { (char *) "is_optimized_out", valpy_get_is_optimized_out, NULL, + (char *) "Boolean telling whether the value is optimized " "out (i.e., not available).", NULL }, - { "type", valpy_get_type, NULL, "Type of the value.", NULL }, - { "dynamic_type", valpy_get_dynamic_type, NULL, - "Dynamic type of the value.", NULL }, - { "is_lazy", valpy_get_is_lazy, NULL, - "Boolean telling whether the value is lazy (not fetched yet\n\ + { (char *) "type", valpy_get_type, NULL, + (char *) "Type of the value.", NULL }, + { (char *) "dynamic_type", valpy_get_dynamic_type, NULL, + (char *) "Dynamic type of the value.", NULL }, + { (char *) "is_lazy", valpy_get_is_lazy, NULL, + (char *) "Boolean telling whether the value is lazy (not fetched yet\n\ from the inferior). A lazy value is fetched when needed, or when\n\ the \"fetch_lazy()\" method is called.", NULL }, {NULL} /* Sentinel */ We have ~20 such arrays, and I first wrote a patch that fixed all of them like that... It's not pretty... One way to make these a bit less ugly would be add a new macro that hides the casts, like: #define GDBPY_GSDEF(NAME, GET, SET, DOC, CLOSURE) \ { (char *) NAME, GET, SET, (char *) DOC, CLOSURE } and then use it like: static PyGetSetDef value_object_getset[] = { GDBPY_GSDEF ("address", valpy_get_address, NULL, "The address of the value.", NULL), GDBPY_GSDEF ("is_optimized_out", valpy_get_is_optimized_out, NULL, "Boolean telling whether the value is optimized ", NULL), {NULL} /* Sentinel */ }; But since we have C++11, which gives us constexpr and list initialization, I thought of a way that requires no changes where the arrays are initialized: We add a new type that extends PyGetSetDef (called gdb_PyGetSetDef), and add constexpr constructors that accept const 'name' and 'doc', and then list/aggregate initialization simply "calls" these matching constructors instead. I put "calls" in quotes, because given "constexpr", it's all done at compile time, and there's no overhead either in binary size or at run time. In fact, we get identical binaries, before/after this change. Unlike the fixes that fix some old Python API to match the API of more recent Python, this switches to using explicit "gdb_PyGetSetDef" everywhere, just to be clear that we are using our own version of it. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * python/python-internal.h (gdb_PyGetSetDef): New type. * python/py-block.c (block_object_getset) (breakpoint_object_getset): Now a gdb_PyGetSetDef array. * python/py-event.c (event_object_getset) (finish_breakpoint_object_getset): Likewise. * python/py-inferior.c (inferior_object_getset): Likewise. * python/py-infthread.c (thread_object_getset): Likewise. * python/py-lazy-string.c (lazy_string_object_getset): Likewise. * python/py-linetable.c (linetable_entry_object_getset): Likewise. * python/py-objfile.c (objfile_getset): Likewise. * python/py-progspace.c (pspace_getset): Likewise. * python/py-record-btrace.c (btpy_insn_getset, btpy_call_getset): Likewise. * python/py-record.c (recpy_record_getset): Likewise. * python/py-symbol.c (symbol_object_getset): Likewise. * python/py-symtab.c (symtab_object_getset, sal_object_getset): Likewise. * python/py-type.c (type_object_getset, field_object_getset): Likewise. * python/py-value.c (value_object_getset): Likewise.
2017-04-05-Wwrite-strings: More fix-old-Python-API wrappersPedro Alves2-0/+71
When building against Python 2.7, -Wwrite-strings flags several cases of passing a string literal to Python functions that expect a "char *". This commit addresses the issue like we already handle several other similar cases -- wrap the Python API with our own fixed version that adds the necessary constification. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * python/python-internal.h (gdb_PyObject_CallMethod) (gdb_PyErr_NewException, gdb_PySys_GetObject, gdb_PySys_SetPath): New functions. (GDB_PYSYS_SETPATH_CHAR, PyObject_CallMethod, PyErr_NewException) (PySys_GetObject, PySys_SetPath): New macros.
2017-04-05-Wwrite-strings: gdbserver/win32-low.c and TARGET_WAITKIND_EXECDPedro Alves2-5/+6
src/gdb/gdbserver/win32-low.c:1499:39: error: ISO C++ forbids converting a string constant to 'char*' [-Werror=write-strings] ourstatus->value.execd_pathname = "Main executable"; ^ This reporting via TARGET_WAITKIND_EXECD it's totally unnecessary. get_child_debug_event returns a TARGET_WAITKIND_SPURIOUS by default, which works just as well here, and is what the equivalent code in gdb/windows-nat.c does too. gdb/gdbserver/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * win32-low.c (get_child_debug_event) <CREATE_PROCESS_DEBUG_EVENT>: Don't report TARGET_WAITKIND_EXECD. Report TARGET_WAITKIND_SPURIOUS instead.
2017-04-05-Wwrite-strings: gdbserver's 'port' parsingPedro Alves4-10/+21
-Wwrite-strings flags this assignment as requiring a cast: port = STDIO_CONNECTION_NAME; because 'port' is a "char *", and STDIO_CONNECTION_NAME is a string literal. gdb/gdbserver/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * remote-utils.c (remote_prepare, remote_open): Constify. * remote-utils.h (remote_prepare, remote_open): Constify. * server.c (captured_main): Constify 'port' handling.
2017-04-05-Wwrite-strings: MI -info-osPedro Alves4-5/+29
-Wwrite-strings flags this attempt to convert a string literal to "char *": info_osdata_command ("", 0); info_osdata_command is a command function. We could address this by simply passing NULL instead of "". However, I went a little bit further and added a new function that is called by both the CLI and MI. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * mi/mi-cmd-info.c (mi_cmd_info_os): Call info_osdata instead of info_osdata_command. * osdata.c (info_osdata_command): Rename to ... (info_osdata): ... this. Constify 'type' parameter, and remove the 'from_tty' parameter. Accept NULL TYPE. (info_osdata_command): New function. * osdata.h (info_osdata_command): Remove declaration. (info_osdata): New declaration.
2017-04-05-Wwrite-strings: Constify mi_cmd_argv_ftype's 'command' parameterPedro Alves14-94/+155
-Wwrite-strings flags this attempt to pass a literal to a "char *": mi_cmd_interpreter_exec ("-interpreter-exec", argv, 2); Fix that by constifying mi_cmd_argv_ftype's 'command' parameter and adjusting all MI commands. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * mi/mi-cmd-break.c (mi_cmd_break_insert_1, mi_cmd_break_insert) (mi_cmd_dprintf_insert, mi_cmd_break_passcount) (mi_cmd_break_watch, mi_cmd_break_commands): Constify 'command' parameter. * mi/mi-cmd-catch.c (mi_cmd_catch_assert, mi_cmd_catch_exception) (mi_cmd_catch_load, mi_cmd_catch_unload): Constify cmd' parameter. * mi/mi-cmd-disas.c (mi_cmd_disassemble): Constify 'command' parameter. * mi/mi-cmd-env.c (mi_cmd_env_pwd, mi_cmd_env_cd, mi_cmd_env_path) (mi_cmd_env_dir, mi_cmd_inferior_tty_set, _cmd_inferior_tty_show) * mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_file) (mi_cmd_file_list_exec_source_files) (mi_cmd_file_list_shared_libraries): Constify 'command' parameter. * mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions) (mi_cmd_info_gdb_mi_command, mi_cmd_info_os): Constify 'command' parameter. * mi/mi-cmd-stack.c (mi_cmd_enable_frame_filters) (mi_cmd_stack_list_frames, mi_cmd_stack_info_depth) (mi_cmd_stack_list_locals, mi_cmd_stack_list_args) (mi_cmd_stack_list_variables, mi_cmd_stack_select_frame) (mi_cmd_stack_info_frame): Constify 'command' parameter. * mi/mi-cmd-target.c (mi_cmd_target_file_get) (mi_cmd_target_file_put, mi_cmd_target_file_delete): Constify 'command' parameter. * mi/mi-cmd-var.c (mi_cmd_var_create, mi_cmd_var_delete) (mi_cmd_var_set_format, mi_cmd_var_set_visualizer) (mi_cmd_var_set_frozen, mi_cmd_var_show_format) (mi_cmd_var_info_num_children, mi_cmd_var_list_children) (mi_cmd_var_info_type, mi_cmd_var_info_path_expression) (mi_cmd_var_info_expression, mi_cmd_var_show_attributes) (mi_cmd_var_evaluate_expression, mi_cmd_var_assign) (mi_cmd_var_update, mi_cmd_enable_pretty_printing) (mi_cmd_var_set_update_range): Constify 'command' parameter. * mi/mi-cmds.h (mi_cmd_argv_ftype): Constify 'command' parameter. * mi/mi-interp.c (mi_cmd_interpreter_exec): Constify 'command' parameter. * mi/mi-main.c (mi_cmd_gdb_exit, mi_cmd_exec_next) (mi_cmd_exec_next_instruction, mi_cmd_exec_step) (mi_cmd_exec_step_instruction, mi_cmd_exec_finish) (mi_cmd_exec_return ,mi_cmd_exec_jump, mi_cmd_exec_continue) (mi_cmd_exec_interrupt, mi_cmd_exec_run, mi_cmd_target_detach) (mi_cmd_target_flash_erase, mi_cmd_thread_select) (mi_cmd_thread_list_ids, mi_cmd_thread_info) (mi_cmd_list_thread_groups, mi_cmd_data_list_register_names) (mi_cmd_data_list_changed_registers) (mi_cmd_data_write_register_values) (mi_cmd_data_evaluate_expression, mi_cmd_data_read_memory) (mi_cmd_data_read_memory_bytes, mi_cmd_data_write_memory) (mi_cmd_data_write_memory_bytes, mi_cmd_enable_timings) (mi_cmd_list_features, mi_cmd_list_target_features) (mi_cmd_add_inferior, mi_cmd_remove_inferior) (mi_cmd_trace_define_variable, mi_cmd_trace_list_variables) (mi_cmd_trace_find, mi_cmd_trace_save, mi_cmd_trace_start) (mi_cmd_trace_status, mi_cmd_trace_stop, mi_cmd_ada_task_info) (mi_cmd_trace_frame_collected): Constify 'command' parameter. * mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines): Constify 'command' parameter.
2017-04-05-Wwrite-strings: Constify word break character arraysPedro Alves8-34/+69
-Wwrite-strings flags several cases of missing casts around initializations like: static char *gdb_completer_command_word_break_characters = " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,"; Obviously these could/should be const. However, while at it, there's no need for these variables to be pointers instead of arrays. They are never changed to point to anything else. Unfortunately, readline's rl_completer_word_break_characters is "char *", not "const char *". So we always need a cast somewhere. The approach taken here is to add a new set_rl_completer_word_break_characters function that becomes the only place that writes to rl_completer_word_break_characters, and thus the single place that needs the cast. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * ada-lang.c (ada_completer_word_break_characters): Now a const array. (ada_get_gdb_completer_word_break_characters): Constify. * completer.c (gdb_completer_command_word_break_characters) (gdb_completer_file_name_break_characters) (gdb_completer_quote_characters): Now const arrays. (get_gdb_completer_quote_characters): Constify. (set_rl_completer_word_break_characters): New function. (set_gdb_completion_word_break_characters) (complete_line_internal): Use it. * completer.h (get_gdb_completer_quote_characters): Constify. (set_rl_completer_word_break_characters): Declare. * f-lang.c (f_word_break_characters): Constify. * language.c (default_word_break_characters): Constify. * language.h (language_defn::la_word_break_characters): Constify. (default_word_break_characters): Constify. * top.c (init_main): Use set_rl_completer_word_break_characters.
2017-04-05-Wwrite-strings: Constify target_pid_to_str and target_thread_extra_thread_infoPedro Alves33-56/+99
-Wwrite-strings flagged a missing cast for example here: static char * ravenscar_extra_thread_info (struct target_ops *self, struct thread_info *tp) { return "Ravenscar task"; Since callers are not supposed to free the string returned by these methods, change the methods' signature to return const strings. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * aix-thread.c (aix_thread_pid_to_str) (aix_thread_extra_thread_info): Constify. * bsd-kvm.c (bsd_kvm_pid_to_str): Constify. * bsd-uthread.c (bsd_uthread_extra_thread_info) (bsd_uthread_pid_to_str): Constify. * corelow.c (core_pid_to_str): Constify. * darwin-nat.c (darwin_pid_to_str): Constify. * fbsd-nat.c (fbsd_pid_to_str): Constify. * fbsd-tdep.c (fbsd_core_pid_to_str, gdbarch_core_pid_to_str): Constify. * gnu-nat.c (gnu_pid_to_str): Constify. * go32-nat.c (go32_pid_to_str): Constify. * i386-cygwin-tdep.c (i386_windows_core_pid_to_str): Constify. * inf-ptrace.c (inf_ptrace_pid_to_str): Constify. * inferior.c (inferior_pid_to_str): Constify. * linux-nat.c (linux_nat_pid_to_str): Constify. * linux-tdep.c (linux_core_pid_to_str): Constify. * linux-thread-db.c (thread_db_pid_to_str) (thread_db_extra_thread_info): Constify. * nto-tdep.c (nto_extra_thread_info): Constify. * nto-tdep.h (nto_extra_thread_info): Constify. * obsd-nat.c (obsd_pid_to_str): Constify. * procfs.c (procfs_pid_to_str): Constify. * ravenscar-thread.c (ravenscar_extra_thread_info) (ravenscar_pid_to_str): Constify. * remote-sim.c (gdbsim_pid_to_str): Constify. * remote.c (remote_threads_extra_info, remote_pid_to_str): Constify. * sol-thread.c (solaris_pid_to_str): Constify. * sol2-tdep.c (sol2_core_pid_to_str): Constify. * sol2-tdep.h (sol2_core_pid_to_str): Constify. * target.c (default_pid_to_str, target_pid_to_str) (normal_pid_to_str, default_pid_to_str): Constify. * target.h (target_ops::to_pid_to_str) (target_ops::to_extra_thread_info): Constify. (target_pid_to_str, normal_pid_to_str): Constify. * windows-nat.c (windows_pid_to_str): Constify. * gdbarch.sh (core_pid_to_str): Constify. * target-delegates.c: Regenerate. * gdbarch.h, gdbarch.c: Regenerate.
2017-04-05-Wwrite-strings: Constify warning_pre_printPedro Alves4-4/+13
-Wwrite-strings flags a warning here: char *warning_pre_print = "\nwarning: "; gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * main.c (captured_main_1): Use gdb::unique_xmalloc_ptr to manage the memory of the temporary warning_pre_print override. * utils.c (warning_pre_print): Constify. * utils.h (warning_pre_print): Constify.
2017-04-05-Wwrite-strings: Constify shell_escape and plug make_command leakPedro Alves2-11/+22
gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * cli/cli-cmds.c (shell_escape): Constify 'arg' parameter. (shell_command): New function. (make_command): Use std::string. (init_cli_cmds): Register shell_command instead of shell_escape.
2017-04-05-Wwrite-strings: Don't initialize string command variables to empty stringPedro Alves3-3/+8
-Wwrite-strings flags these initializations as requiring a cast. However, these variables are command variables, and as such point to heap-allocated memory. The initial allocation is always done when the corresponding command is registered. E.g.,: dprintf_function = xstrdup ("printf"); add_setshow_string_cmd ("dprintf-function", class_support, &dprintf_function, _("\ Set the function to use for dynamic printf"), _("\ Show the function to use for dynamic printf"), NULL, update_dprintf_commands, NULL, &setlist, &showlist); That's why we never reach a bogus attempt to free these string literals. So, just drop the incorrect initializations. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * breakpoint.c (dprintf_function, dprintf_channel): Don't initialize. * tracepoint.c (default_collect): Don't initialize.
2017-04-05-Wwrite-strings: Constify macroexp.c:init_shared_bufferPedro Alves2-11/+23
There's one call in the file that passes a string literal, like: init_shared_buffer (&va_arg_name, "__VA_ARGS__", strlen ("__VA_ARGS__")); Instead of adding a cast here, make init_shared_buffer take a 'const char *', and remove the several casts in the file that are made obsolete. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * macroexp.c (macro_buffer::shared): Now a bool. (init_buffer): Update. (init_shared_buffer): Constify 'addr' parameter. (substitute_args, expand, macro_expand, macro_expand_next): Remove casts.
2017-04-05-Wwrite-strings: Constify struct disassemble_info's disassembler_options fieldPedro Alves11-15/+32
The memory disassemble_info::disassembler_options points to is always owned by the client. I.e., that field is an non-owning, observing pointer. Thus const makes sense. Are the include/ and opcodes/ bits OK? Tested on x86_64 Fedora 23, built with --enable-targets=all. include/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * dis-asm.h (disassemble_info) <disassembler_options>: Now a "const char *". (next_disassembler_option): Constify. opcodes/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * arc-dis.c (parse_option, parse_disassembler_options): Constify. * arm-dis.c (parse_arm_disassembler_options): Constify. * ppc-dis.c (powerpc_init_dialect): Constify local. * vax-dis.c (parse_disassembler_options): Constify. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * arm-tdep.c (show_disassembly_style_sfunc): Constify local. * disasm.c (set_disassembler_options): Constify local. * i386-tdep.c (i386_print_insn): Remove cast and FIXME comment.
2017-04-05PR 21352: Add testsuite for "tsave -r" commandSergio Durigan Junior2-0/+9
This commit adds a test for the fix of PR 21352. gdb/testsuite/ChangeLog: 2017-04-05 Sergio Durigan Junior <sergiodj@redhat.com> PR gdb/21352 * gdb.trace/tsv.exp: Add test for "tsave -r".
2017-04-05Fix PR 21352: Command tsave does not support -r argumentSergio Durigan Junior2-1/+7
This is an obvious fix for PR 21352. The problem is that the argument parsing loop is not using an "else if" where it should, and therefore the '-r' option ends up unrecognized by GDB. gdb/ChangeLog: 2017-04-05 Sergio Durigan Junior <sergiodj@redhat.com> PR gdb/21352 * tracefile.c (tsave_command): Fix argument parsing for '-r' option.
2017-04-05Use frame_unwind_register_value in frame_unwind_register_unsignedYao Qi2-3/+25
gdb: 2017-04-05 Yao Qi <yao.qi@linaro.org> * frame.c (frame_unwind_register_unsigned): Call frame_unwind_register_value.
2017-04-05Fix racy test in gdb.threads/thread-specific-bp.expYao Qi2-3/+11
I see the following test fail from time to time, due to the racy test in gdb.threads/thread-specific-bp.exp. continue -a^M Continuing.^M ^M Thread 1 "thread-specific" hit Breakpoint 4, end () at binutils-gdb/gdb/testsuite/gdb.threads/thread-specific-bp.c:29^M 29 }^M (gdb) [Thread 0x40322460 (LWP 12950) exited]^M Thread-specific breakpoint 3 deleted - thread 2 no longer in the thread list.^M FAIL: gdb.threads/thread-specific-bp.exp: non-stop: continue to end (timeout) This patch changes gdb_test to gdb_test_multiple to match prompt only instead of both prompt and anchor. gdb/testsuite: 2017-04-05 Yao Qi <yao.qi@linaro.org> * gdb.threads/thread-specific-bp.exp (check_thread_specific_breakpoint): Use gdb_test_multiple, and don't match anchor.
2017-04-05PowerPC64le PLT reference countingAlan Modra2-11/+35
A fix for ELFv2 ABI garbage-collection. * elf64-ppc.c (ppc64_elf_gc_sweep_hook): Support ELFv2 PLT reference counting.
2017-04-05New global maintainer - Simon MarchiPedro Alves2-1/+6
gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * MAINTAINERS (Global Maintainers): Add Simon Marchi. (Write After Approval): Remove Simon Marchi.
2017-04-05PR ld/21233: xfail failing test-parts for cris*-*-*Hans-Peter Nilsson2-2/+9
2017-04-05Initialize gdb::optional empty payload to quiet false -Wmaybe-uninitialized ↵Pedro Alves2-2/+8
warnings Commit ecfb656c37b982 ("dwarf2read.c: Make dir_index and file_name_index strong typedefs") added a use of gdb::optional that triggers bogus -Wmaybe-uninitialized warnings: GCC trunk is complaining like this: ../../binutils-gdb/gdb/dwarf2read.c: In function void read_formatted_entries(bfd*, const gdb_byte**, line_header*, const comp_unit_head*, void (*)(line_header*, const char*, dir_index, unsigned int, unsigned int)): ../../binutils-gdb/gdb/dwarf2read.c:17779:65: error: fe.file_entry::length may be used uninitialized in this function [-Werror=maybe-uninitialized] callback (lh, fe.name, fe.d_index, fe.mod_time, fe.length); ^ ../../binutils-gdb/gdb/dwarf2read.c:17779:65: error: *((void*)& fe +8) may be used uninitialized in this function [-Werror=maybe-uninitialized] ../../binutils-gdb/gdb/dwarf2read.c:17779:65: error: fe.file_entry::mod_time may be used uninitialized in this function [-Werror=maybe-uninitialized] ../../binutils-gdb/gdb/dwarf2read.c:17779:65: error: fe.file_entry::name may be used uninitialized in this function [-Werror=maybe-uninitialized] While some older GCCs are complaining like this: ../../binutils-gdb/gdb/dwarf2read.c: In function void read_formatted_entries(bfd*, const gdb_byte**, line_header*, const comp_unit_head*, void (*)(line_header*, const char*, dir_index, unsigned int, unsigned int)): ../../binutils-gdb/gdb/dwarf2read.c:17779:65: error: uint may be used uninitialized in this function [-Werror=maybe-uninitialized] callback (lh, fe.name, fe.d_index, fe.mod_time, fe.length); Looking around the web, I see that boost's optional implementation triggers this kind of issue often too. See: http://www.boost.org/doc/libs/1_63_0/libs/optional/doc/html/boost_optional/tutorial/gotchas/false_positive_with__wmaybe_uninitialized.html I noticed that replacing the gdb::optional uses with real C++17 std::optional uses against GCC 7/trunk makes the warnings go away. Looking at the implementation, AFAICS, libstdc++ always initializes its "empty" union payload member (_M_empty, which is defined as an empty class, like ours). I.e., all payload types have this ctor: struct _Optional_payload..... { constexpr _Optional_payload() : _M_empty() {} The constexpr makes a diference too. Without it, GCC7 still warns. So I'm applying the same treatment to our gdb::optional. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * common/gdb_optional.h (optional::optional): Make constexpr and initialize m_dummy.
2017-04-05Automatic date update in version.inGDB Administrator1-1/+1
2017-04-04PR ld/21233: Avoid sweeping forced-undefined symbols in section GCMaciej W. Rozycki9-0/+101
Complement commit 902e9fc76a0e ("PR ld/20828: Move symbol version processing ahead of GC symbol sweep"), commit b531344c34b0 ("PR ld/20828: Reorder the symbol sweep stage of section GC") and commit 81ff47b3a546 ("PR ld/20828: Fix linker script symbols wrongly forced local with section GC"), and prevent symbols forcibly entered in the output file with the use of the `--undefined=' or `--require-defined=' linker command line options or the EXTERN linker script command from being swept in section garbage collection and consequently recorded in the dynamic symbol table as local entries. This happens in certain circumstances, where a symbol reference also exists in one of the static input files, however only in a section which is garbage-collected and does not make it to the output file, and the symbol is defined in a dynamic object present in the link. For example with the `i386-linux' target and the `pr21233.s' and `pr21233-l.s' sources, and the `pr21233.ld' linker script included with this change we get: $ as -o pr21233-l.o pr21233-l.s $ ld -shared -T pr21233.ld -o libpr21233.so pr21233-l.o $ as -o pr21233.o pr21233.s $ ld --gc-sections -e foo --require-defined=bar -T pr21233.ld -o pr21233 pr21233.o libpr21233.so $ readelf --dyn-syms pr21233 Symbol table '.dynsym' contains 2 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 0 OBJECT LOCAL DEFAULT UND bar $ which makes the run-time `bar' dependency of the `pr21233' executable different from its corresponding link-time dependency, i.e. the presence of `libpr21233.so' and its `bar' symbol is required at the link time, however at the run time a copy of `libpr21233.so' without `bar' will do. Similarly with `--undefined=' and EXTERN which do not actually require the reference to the symbol requested to be satisfied with a definition at the link time, however once the definition has been pulled at the link time, so it should at the dynamic load time. Additionally with the `mips-linux' target we get: $ ld --gc-sections -e foo --require-defined=bar -T pr21233.ld -o pr21233 pr21233.o libpr21233.so ld: BFD (GNU Binutils) 2.28.51.20170324 assertion fail .../bfd/elfxx-mips.c:3861 $ as the target is not prepared to handle such a local dynamic symbol. With this change in effect we get: $ readelf --dyn-syms pr21233 Symbol table '.dynsym' contains 2 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 0 OBJECT GLOBAL DEFAULT UND bar $ instead, for both targets. ld/ PR ld/21233 * ldlang.c (insert_undefined): Set `mark' for ELF symbols. * testsuite/ld-elf/pr21233.sd: New test. * testsuite/ld-elf/pr21233-l.sd: New test. * testsuite/ld-elf/pr21233.ld: New test linker script. * testsuite/ld-elf/pr21233-e.ld: New test linker script. * testsuite/ld-elf/pr21233.s: New test source. * testsuite/ld-elf/pr21233-l.s: New test source. * testsuite/ld-elf/shared.exp: Run the new tests.
2017-04-04Remove support for using the bsd-uthread target on FreeBSD.John Baldwin5-129/+19
The bsd-uthread target supports an old thread library ("libc_r") that was last included in FreeBSD release 6.4 released in 2008. However, this library has not been used as the default library since FreeBSD 5.0 (2003) and 4.11 (2005). Thread support for modern FreeBSD binaries is provided via "normal" LWP support in core files and the native FreeBSD target. gdb/ChangeLog: * amd64-fbsd-tdep.c: Remove "bsd-uthread.h" include. (amd64fbsd_jmp_buf_reg_offset): Remove. (amd64fbsd_supply_uthread): Remove function. (amd64fbsd_collect_uthread): Remove function. (amd64fbsd_init_abi): Don't set bsd-uthread callbacks. * configure.tgt (i[34567]86-*-freebsd*): Remove bsd-uthread.o. (x86_64-*-freebsd*): Remove bsd-uthread.o. (fbsd-nat.c): Update comment. * i386-fbsd-tdep.c: Remove "bsd-uthread.h" include. (i386fbsd_jmp_buf_reg_offset): Remove. (i386fbsd_supply_uthread): Remove function. (i386fbsd_collect_uthread): Remove function. (i386fbsd_init_abi): Don't set bsd-uthread callbacks.
2017-04-04Remove support for FreeBSD/alpha.John Baldwin7-147/+21
FreeBSD last shipped a release for Alpha (6.3) in 2008. This also removes support for GNU/kFreeBSD on Alpha. gdb/ChangeLog: * Makefile.in (ALL_64_TARGET_OBS): Remove alpha-fbsd-tdep.o. (ALLDEPFILES): Remove alpha-fbsd-tdep.c * NEWS: Mention that support for FreeBSD/alpha was removed. * alpha-fbsd-tdep.c: Delete file. * config/alpha/fbsd.mh: Delete file. * configure.host: Delete alpha*-*-freebsd* and alpha*-*-kfreebsd*-gnu. * configure.tgt: Delete alpha*-*-freebsd* and alpha*-*-kfreebsd*-gnu.
2017-04-04Use ptid from regcache instead of inferior_ptid.John Baldwin2-18/+19
gdb/ChangeLog: * amd64-bsd-nat.c (amd64bsd_fetch_inferior_registers, amd64bsd_store_inferior_registers): Use ptid from regcache.
2017-04-04dwarf2read.c: C++fy lnp_state_machinePedro Alves2-198/+267
While I was looking at the file, I noticed that this struct could be nicely converted to a class. As I was progressing, I ended up moving all state machine actual internal state manipulation to methods of lnp_state_machine, essentially decoupling DWARF parsing from state tracking. I also noticed that the lnp_reader_state doesn't really serve any good use, so that's eliminated in the process. gdb/ChangeLog: 2017-04-04 Pedro Alves <palves@redhat.com> * dwarf2read.c (lnp_state_machine): Now a class. Initialize all data fields, make them private and add "m_" prefixes. (lnp_state_machine::lnp_state_machine): New ctor. (record_line, check_line_address, handle_set_discriminator) (handle_set_address, handle_advance_pc, handle_special_opcode) (handle_advance_line, handle_set_file, handle_negate_stmt) (handle_const_add_pc, handle_fixed_advance_pc, handle_copy) (end_sequence, advance_line): New methods. (m_gdbarch, m_record_lines_p): New fields. (lnp_reader_state): Delete. (dwarf_record_line): Rename to ... (lnp_state_machine::record_line): ... adjust. (init_lnp_state_machine): Delete. (lnp_state_machine::lnp_state_machine): New. (check_line_address): Rename to ... (lnp_state_machine::check_line_address): This. (dwarf_decode_lines_1): Remove reference to "reader_state". Adjust lnp_state_machine having a non-default ctor. Use bool. State machine internal state manipulation moved to lnp_state_machine methods.
2017-04-04Make sect_offset and cu_offset strong typedefs instead of structsPedro Alves12-384/+900
A while ago, back when GDB was a C program, the sect_offset and cu_offset types were made structs in order to prevent incorrect mixing of those offsets. Now that we require C++11, we can make them integers again, while keeping the safety, by exploiting "enum class". We can add a bit more safety, even, by defining operators that the types _should_ support, helping making the suspicious uses stand out more. Getting at the underlying type is done with the new to_underlying function added by the previous patch, which also helps better spot where do we need to step out of the safety net. Mostly, that's around parsing the DWARF, and when we print the offset for complaint/debug purposes. But there are other occasional uses. Since we have to define the sect_offset/cu_offset types in a header anyway, I went ahead and generalized/library-fied the idea of "offset" types, making it trivial to add more such types if we find a use. See common/offset-type.h and the DEFINE_OFFSET_TYPE macro. I needed a couple generaly-useful preprocessor bits (e.g., yet another CONCAT implementation), so I started a new common/preprocessor.h file. I included units tests covering the "offset" types API. These are mostly compile-time tests, using SFINAE to check that expressions that shouldn't compile (e.g., comparing unrelated offset types) really are invalid and would fail to compile. This same idea appeared in my pending enum-flags revamp from a few months ago (though this version is a bit further modernized compared to what I had posted), and I plan on reusing the "check valid expression" bits added here in that series, so I went ahead and defined the CHECK_VALID_EXPR macro in its own header -- common/valid-expr.h. I think that's nicer regardless. I was borderline between calling the new types "offset" types, or "index" types, BTW. I stuck with "offset" simply because that's what we're already calling them, mostly. gdb/ChangeLog: 2017-04-04 Pedro Alves <palves@redhat.com> * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add unittests/offset-type-selftests.c. (SUBDIR_UNITTESTS_OBS): Add offset-type-selftests.o. * common/offset-type.h: New file. * common/preprocessor.h: New file. * common/traits.h: New file. * common/valid-expr.h: New file. * dwarf2expr.c: Include "common/underlying.h". Adjust to use sect_offset and cu_offset strong typedefs throughout. * dwarf2expr.h: Adjust to use sect_offset and cu_offset strong typedefs throughout. * dwarf2loc.c: Include "common/underlying.h". Adjust to use sect_offset and cu_offset strong typedefs throughout. * dwarf2read.c: Adjust to use sect_offset and cu_offset strong typedefs throughout. * gdbtypes.h: Include "common/offset-type.h". (cu_offset): Now an offset type (strong typedef) instead of a struct. (sect_offset): Likewise. (union call_site_parameter_u): Rename "param_offset" field to "param_cu_off". * unittests/offset-type-selftests.c: New file.
2017-04-04dwarf2read.c: Make dir_index and file_name_index strong typedefsPedro Alves3-74/+149
This should help catch mistakes related to mixing the 1-based DWARF indexes with 0-based std::vector indexes, since the new types do not implicitly convert to anything. The change in read_formatted_entries relates to the fact that doing the seemingly simpler: - uintp = &fe.dir_index; + uintp = (unsigned int *) &fe.dir_index; would be undefined C/C++. So to address that, I made the function extract the form before assigning to the file_entry. It felt natural to use gdb::optional for "do I have this value", and this is what motivated the previous patch that added the missing observer methods to gdb::optional. gdb/ChangeLog: 2017-04-04 Pedro Alves <palves@redhat.com> * common/underlying.h: New file. * dwarf2read.c: Include "common/gdb_optional.h" and "common/underlying.h". (dir_index, file_name_index): New types. (file_entry): Use them. (file_entry::include): Use to_underlying. (line_header::add_file_name): Use dir_index. (read_formatted_entries): Use gdb::optional. Read form before writting to file_entry. (dwarf_decode_line_header): Use dir_index. (lnp_state_machine::current_file): Use to_underlying. (lnp_state_machine::file): Change type to file_name_index. (dwarf_record_line): Use to_underlying. (init_lnp_state_machine): Use file_name_index. (dwarf_decode_lines_1): Use dir_index and file_name_index.
2017-04-04gdb::optional: Add observersPedro Alves2-0/+34
Currently, gdb::optional is really minimal and can only be used for lazy initialization. There's no way to get at the value contained inside the optinal. This commit corrects that, by adding observer methods, mostly copied from libstdc++'s implementation of C++17 std::optional. This will be used in the following patch. gdb/ChangeLog: 2017-04-04 Pedro Alves <palves@redhat.com> * common/gdb_optional.h (gdb::optiona): Add operator->, operator*, operator bool, has_value and get methods.
2017-04-04dwarf2read.c: Some C++fycation, use std::vector, std::unique_ptrPedro Alves2-180/+166
This starts off as replacing a couple custom open coded vector implementations in the file with std::vector, and then the rest falls off of that. I.e., use new/delete instead of XCNEW/xfree, add ctors/dtors/initializers where appropriate. And then use std::unique_ptr instead of cleanups. Some functions became methods, and in a couple spots, some single-use callback functions that would have to be tweaked anyway are converted to lambdas instead. gdb/ChangeLog: 2017-04-04 Pedro Alves <palves@redhat.com> * dwarf2read.c (struct file_entry): Add ctors, and initialize all fields. (line_header): Initialize all data fields. Change type of standard_opcode_lengths to std::unique_ptr<unsigned char[]>. Change type of include_dirs to std::vector<const char *>. Remove num_include_dirs, include_dirs_size. Change type of file_names to std::vector<file_entry>. Remove num_file_names, file_names_size. (line_header::line_header): New. (line_header::add_include_dir, line_header::add_file_name): New methods. (line_header::include_dir_at): Remove NULL check. (line_header::file_name_at): Add const overload. (line_header_up): New unique_ptr typedef. (dw2_get_file_names_reader): Use line_header_up. Adjust to use std::vector. Remove free_line_header call. (dwarf2_build_include_psymtabs): Use line_header_up. Remove free_line_header call. (free_cu_line_header): Delete. (handle_DW_AT_stmt_list, handle_DW_AT_stmt_list) (setup_type_unit_groups): Use line_header_up instead of cleanups. Adjust to use std::vector. (free_line_header): Delete. (free_line_header_voidp): Use delete. (add_include_dir): Replace with ... (line_header::add_include_dir): ... this method. Use std::vector. (add_file_name): Replace with ... (line_header::add_file_name): ... this method. Use std::vector. (add_include_dir_stub): Delete. (read_formatted_entries): Remove memset. (dwarf_decode_line_header): Return a line_header_up instead of a raw pointer. Remove cleanup handling. Pass lambdas to read_formatted_entries. Adjust to use line_header methods. (dwarf_decode_lines_1): Adjust to use line_header methods. (dwarf_decode_lines, file_file_name, file_full_name): Adjust to use std::vector.
2017-04-04Use symbolic constants instead of magic numbers with add_data_entry()Jon Turney2-5/+11
Use symbolic constants from include/coff/internal.h instead of magic numbers with add_data_entry() bfd/ChangeLog: 2017-04-02 Jon Turney <jon.turney@dronecode.org.uk> (_bfd_XXi_swap_aouthdr_out): For clarity, use defines rather than numbers for DataDirectory entry indicies passed to add_data_entry().
2017-04-04Support ELF SHF_GNU_MBIND and PT_GNU_MBIND_XXXH.J. Lu40-31/+660
Mark an ALLOC section, which should be placed in special memory area, with SHF_GNU_MBIND. Its sh_info field indicates the special memory type. GNU_MBIND section names start with ".mbind" so that they are placed as orphan sections by linker. All input GNU_MBIND sections with the same sh_type, sh_flags and sh_info are placed in one output GNU_MBIND section. In executable and shared object, create a GNU_MBIND segment for each GNU_MBIND section and its segment type is PT_GNU_MBIND_LO plus the sh_info value. Each GNU_MBIND segment is aligned at page boundary. The assembler syntax: .section .mbind.foo,"adx",%progbits ^ 0: Special memory type. | 'd' for SHF_GNU_MBIND. .section .mbind.foo,"adx",%progbits,0x1 ^ 1: Special memory type. | 'd' for SHF_GNU_MBIND. .section .mbind.bar,"adG",%progbits,.foo_group,comdat,0x2 ^ 2: Special memory type. | 'd' for SHF_GNU_MBIND. bfd/ * elf.c (get_program_header_size): Add a GNU_MBIND segment for each GNU_MBIND section and align GNU_MBIND section to page size. (_bfd_elf_map_sections_to_segments): Create a GNU_MBIND segment for each GNU_MBIND section. (_bfd_elf_init_private_section_data): Copy sh_info from input for GNU_MBIND section. binutils/ * NEWS: Mention support for ELF SHF_GNU_MBIND and PT_GNU_MBIND_XXX. * readelf.c (get_segment_type): Handle PT_GNU_MBIND_XXX. (get_elf_section_flags): Handle SHF_GNU_MBIND. (process_section_headers): Likewise. * testsuite/binutils-all/mbind1.s: New file. * testsuite/binutils-all/objcopy.exp: Run readelf test on mbind1.s. gas/ * NEWS: Mention support for ELF SHF_GNU_MBIND. * config/obj-elf.c (section_match): New. (get_section): Match both sh_info and group name. (obj_elf_change_section): Add argument for sh_info. Pass both sh_info and group name to get_section. Issue an error for SHF_GNU_MBIND section without SHF_ALLOC. Set sh_info. (obj_elf_parse_section_letters): Set SHF_GNU_MBIND for 'd'. (obj_elf_section): Support SHF_GNU_MBIND section info. * config/obj-elf.h (obj_elf_change_section): Add argument for sh_info. * config/tc-arm.c (start_unwind_section): Pass 0 as sh_info to obj_elf_change_section. * config/tc-ia64.c (obj_elf_vms_common): Likewise. * config/tc-microblaze.c (microblaze_s_data): Likewise. (microblaze_s_sdata): Likewise. (microblaze_s_rdata): Likewise. (microblaze_s_bss): Likewise. * config/tc-mips.c (s_change_section): Likewise. * config/tc-msp430.c (msp430_profiler): Likewise. * config/tc-rx.c (parse_rx_section): Likewise. * config/tc-tic6x.c (tic6x_start_unwind_section): Likewise. * doc/as.texinfo: Document 'd' for SHF_GNU_MBIND. * testsuite/gas/elf/elf.exp: Run section12a, section12b and section13. * testsuite/gas/elf/section10.d: Updated. * testsuite/gas/elf/section10.s: Likewise. * testsuite/gas/elf/section12.s: New file. * testsuite/gas/elf/section12a.d: Likewise. * testsuite/gas/elf/section12b.d: Likewise. * testsuite/gas/elf/section13.l: Likewise. * testsuite/gas/elf/section13.d: Likewise. * testsuite/gas/elf/section13.s: Likewise. include/ * elf/common.h (PT_GNU_MBIND_NUM): New. (PT_GNU_MBIND_LO): Likewise. (PT_GNU_MBIND_HI): Likewise. (SHF_GNU_MBIND): Likewise. ld/ * NEWS: Mention support for ELF SHF_GNU_MBIND and PT_GNU_MBIND_XXX. * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Place input GNU_MBIND sections with the same type, attributes and sh_info field into a single output GNU_MBIND section. * testsuite/ld-elf/elf.exp: Run mbind2a and mbind2b. * testsuite/ld-elf/mbind1.s: New file. * testsuite/ld-elf/mbind1a.d: Likewise. * testsuite/ld-elf/mbind1b.d: Likewise. * testsuite/ld-elf/mbind1c.d: Likewise. * testsuite/ld-elf/mbind2a.s: Likewise. * testsuite/ld-elf/mbind2b.c: Likewise.
2017-04-04RISC-V: Resurrect GP-relative disassembly hintsPalmer Dabbelt6-7/+22
We missed a "_gp" when changing the GP symbol. To make sure that doesn't happen again, we now use the same definition everywhere (thanks, Nick). include/ChangeLog: 2017-04-03 Palmer Dabbelt <palmer@dabbelt.com> * elf/riscv.h (RISCV_GP_SYMBOL): New define. bfd/ChangeLog: 2017-04-03 Palmer Dabbelt <palmer@dabbelt.com> * elfnn-riscv.c (GP_NAME): Delete. (riscv_global_pointer_value): Change GP_NAME to RISCV_GP_SYMBOL. (_bfd_riscv_relax_lui): Likewise. opcodes/ChangeLog: 2017-04-03 Palmer Dabbelt <palmer@dabbelt.com> * riscv-dis.c (riscv_disassemble_insn): Change "_gp" to RISCV_GP_SYMBOL.
2017-04-04gdbserver: Clear .deps on cleanSimon Marchi2-0/+5
In some situations, the dependency tracking files in .deps can refer to source files that were removed or renamed, leading to errors like: make: *** No rule to make target `version.c', needed by `version.o'. Stop. This patch makes the clean target clear the .deps directory, which gives the user a chance to recover from the error wihtout knowing about the internals of the build system. It is already done for GDB. See here for more details: https://sourceware.org/ml/gdb-patches/2009-03/msg00000.html gdb/gdbserver/ChangeLog: * Makefile.in (clean): Clear .deps.
2017-04-04remote.c: Use ptid_t instead of struct ptidSimon Marchi2-5/+10
It's the only place in the codebase that uses "struct ptid", so change it to ptid_t for consistency. gdb/ChangeLog: * remote.c (set_general_thread, set_continue_thread): Use ptid_t instead of struct ptid.
2017-04-04Fix null pointer dereferences when using a link built with clang.Nick Clifton2-14/+29
PR binutils/21342 * elflink.c (_bfd_elf_define_linkage_sym): Prevent null pointer dereference. (bfd_elf_final_link): Only initialize the extended symbol index section if there are extended symbol tables to list.
2017-04-04Remove MAX_REGISTER_SIZE from frame.cAlan Hayward2-13/+27
gdb/ * frame.c (get_frame_register_bytes): Unwind using value. (put_frame_register_bytes): Likewise.
2017-04-04Automatic date update in version.inGDB Administrator1-1/+1
2017-04-03RISC-V: Avoid a const warningPalmer Dabbelt2-1/+6
2017-04-03 Palmer Dabbelt <palmer@dabbelt.com> * config/tc-riscv.c (riscv_clear_subsets): Cast argument to free to avoid const warnings.
2017-04-03 IA16 supportAndrew Jenner5-1/+24
* config.sub: Handle ia16 in $basic_machine. bfd/ * config.bfd: Handle ia16. gas/ * configure.tgt: Handle ia16. ld/ * configure.tgt: Handle ia16.
2017-04-03Correct the ChangeLog entryH.J. Lu1-1/+1
2017-04-03ld: Support ELF GNU program propertiesH.J. Lu50-3/+1851
From .note.gnu.property section in each ELF input, we build a list of GNU properties if .note.gnu.property section isn't corrupt. The unknown properties are ignored. All property lists in relocatable inputs are merged into an output property list. When -z stack-size=N is used and N isn't 0, the GNU_PROPERTY_STACK_SIZE property will be merged with or added to the output property list. .note.gnu.property section is generated in output from the output property list. bfd/ * Makefile.am (BFD32_BACKENDS): Add elf-properties.lo. (BFD32_BACKENDS_CFILES): Add elf-properties.c. * configure.ac (elf): Add elf-properties.lo. * Makefile.in: Regenerated. * configure: Likewise. * elf-bfd.h (elf_property_kind): New. (elf_property): Likewise. (elf_property_list): Likewise. (elf_properties): Likewise. (_bfd_elf_parse_gnu_properties): Likewise. (_bfd_elf_get_property): Likewise. (_bfd_elf_link_setup_gnu_properties): Likewise. (elf_backend_data): Add parse_gnu_properties, merge_gnu_properties and setup_gnu_properties. (elf_obj_tdata): Add properties. * elf-properties.c: New file. * elf32-i386.c (elf_i386_parse_gnu_properties): New. (elf_i386_merge_gnu_properties): Likewise. (elf_backend_parse_gnu_properties): Likewise. (elf_backend_merge_gnu_properties): Likewise. * elf64-x86-64.c (elf_x86_64_parse_gnu_properties): Likewise. (elf_x86_64_merge_gnu_properties): Likewise. (elf_backend_parse_gnu_properties): Likewise. (elf_backend_merge_gnu_properties): Likewise. * elfxx-target.h (elf_backend_merge_gnu_properties): Likewise. (elf_backend_parse_gnu_properties): Likewise. (elf_backend_setup_gnu_properties): Likewise. (elfNN_bed): Add elf_backend_parse_gnu_properties, elf_backend_merge_gnu_properties and elf_backend_setup_gnu_properties. ld/ * ld/NEWS: Mention support for ELF GNU program properties. * emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Call ELF setup_gnu_properties. * testsuite/ld-i386/i386.exp: Run property tests for Linux/i386. * testsuite/ld-i386/pass.c: New file. * testsuite/ld-i386/property-1.r: Likewise. * testsuite/ld-i386/property-2.r: Likewise. * testsuite/ld-i386/property-3.r: Likewise. * testsuite/ld-i386/property-4.r: Likewise. * testsuite/ld-i386/property-5.r: Likewise. * testsuite/ld-i386/property-6.r: Likewise. * testsuite/ld-i386/property-6a.c: Likewise. * testsuite/ld-i386/property-6b.c: Likewise. * testsuite/ld-i386/property-6c.S: Likewise. * testsuite/ld-i386/property-7.r: Likewise. * testsuite/ld-i386/property-no-copy.S: Likewise. * testsuite/ld-i386/property-stack.S: Likewise. * testsuite/ld-i386/property-unsorted-1.S: Likewise. * testsuite/ld-i386/property-unsorted-2.S: Likewise. * testsuite/ld-i386/property-x86-1.S: Likewise. * testsuite/ld-i386/property-x86-2.S: Likewise. * testsuite/ld-x86-64/pass.c: Likewise. * testsuite/ld-x86-64/property-1.r: Likewise. * testsuite/ld-x86-64/property-2.r: Likewise. * testsuite/ld-x86-64/property-3.r: Likewise. * testsuite/ld-x86-64/property-4.r: Likewise. * testsuite/ld-x86-64/property-5.r: Likewise. * testsuite/ld-x86-64/property-6.r: Likewise. * testsuite/ld-x86-64/property-6a.c: Likewise. * testsuite/ld-x86-64/property-6b.c: Likewise. * testsuite/ld-x86-64/property-6c.S: Likewise. * testsuite/ld-x86-64/property-7.r: Likewise. * testsuite/ld-x86-64/property-no-copy.S: Likewise. * testsuite/ld-x86-64/property-stack.S: Likewise. * testsuite/ld-x86-64/property-unsorted-1.S: Likewise. * testsuite/ld-x86-64/property-unsorted-2.S: Likewise. * testsuite/ld-x86-64/property-x86-1.S: Likewise. * testsuite/ld-x86-64/property-x86-2.S: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run property tests for Linux/x86-64.
2017-04-03readelf: Fix overlarge memory allocation when reading a binary with an ↵Nick Clifton2-3/+20
excessive number of program headers. PR binutils/21345 * readelf.c (get_program_headers): Check for there being too many program headers before attempting to allocate space for them.