Commit Graph

39580 Commits

Author SHA1 Message Date
Simon Marchi 5e89eb3ab0 gdb.base/commands.exp: Remove unused global references
There are a few unused references to the gdb_prompt global.

gdb/testsuite/ChangeLog:

	* gdb.base/commands.exp (gdbvar_simple_if_test,
	gdbvar_simple_if_test, gdbvar_complex_if_while_test,
	progvar_simple_if_test, progvar_simple_while_test,
	progvar_complex_if_while_test, user_defined_command_test,
	user_defined_command_args_eval,
	user_defined_command_args_stack_test,
	user_defined_command_manyargs_test, bp_deleted_in_command_test,
	temporary_breakpoint_commands,
	gdb_test_no_prompt, redefine_hook_test,
	redefine_backtrace_test): Remove "global gdb_prompt".
2017-08-28 23:39:18 +02:00
Simon Marchi 3804a3431a Add missing PR number in ChangeLog
This should have been included in the previous commit.
2017-08-28 23:09:12 +02:00
Simon Marchi fd437cbc43 define_command: Don't convert command name to lower case
Commit

  Command names: make them case sensitive
  3d7b173c29

made command name lookup case sensitive.  However, define_command, used
when creating a user-defined command, converts the command name to
lowercase, assuming that the command name lookup works in a case
insensitive way.  This causes user-defined commands with capital letters
in their name to only be callable with a lowercase version:

  (gdb) define Foo
  Type commands for definition of "Foo".
  End with a line saying just "end".
  >print 1
  >end
  (gdb) Foo
  Undefined command: "Foo".  Try "help".
  (gdb) foo
  $1 = 1

This patch removes that conversion to lowercase, so that the user can
call the command with the same name they provided.

gdb/ChangeLog:

	* cli/cli-script.c (define_command): Don't convert command name
	to lower case.

gdb/testsuite/ChangeLog:

	* gdb.base/commands.exp (user_defined_command_case_sensitivity):
	New proc, call it from toplevel.
2017-08-28 23:05:04 +02:00
Joel Brobecker 988f6b3dc6 remove param "dispp" from ada-lang.c::ada_lookup_struct_elt_type
The function is always called with DISPP set to NULL, so there is
no need for this parameter anymore. This patch removes it, and
eliminates some dead code associated to that.

gdb/ChangeLog:

        * ada-lang.c (ada_lookup_struct_elt_type): Remove parameter "dispp".
        Update all callers accordingly. Remove all code blocks handling
        the case where DISPP is not NULL.

Tested on x86_64-linux, no regression.
2017-08-25 20:29:41 -04:00
Simon Marchi 6afd337d1a gdbserver: Rename some functions, thread -> inferior
These functions apply to thread, and not inferiors (in the gdbserver
sense, the abstraction for threads and processes, as in
inferior_list).  Therefore, it would make more sense if these functions
were named with "thread" rather than "inferior".

gdb/gdbserver/ChangeLog:

	* inferiors.h (inferior_target_data): Rename to ...
	(thread_target_data): ... this.
	(inferior_regcache_data): Rename to ...
	(thread_regcache_data): ... this.
	(set_inferior_regcache_data): Rename to ...
	(set_thread_regcache_data): ... this.
	* inferiors.c (inferior_target_data): Rename to ...
	(thread_target_data): ... this.
	(inferior_regcache_data): Rename to ...
	(thread_regcache_data): ... this.
	(set_inferior_regcache_data): Rename to ...
	(set_thread_regcache_data): ... this.
	(free_one_thread): Update.
	* linux-low.h (get_thread_lwp): Update.
	* regcache.c (get_thread_regcache): Update.
	(regcache_invalidate_thread): Update.
	(free_register_cache_thread): Update.
	* win32-i386-low.c (update_debug_registers_callback): Update.
	(win32_get_current_dr): Update.
	* win32-low.c (thread_rec): Update.
	(delete_thread_info): Update.
	(continue_one_thread): Update.
	(suspend_one_thread): Update.
2017-08-25 10:45:33 +02:00
Simon Marchi a160cc4628 Remove unused function set_inferior_target_data
The inferior (thread) target data is always set through add_thread.

gdb/gdbserver/ChangeLog:

	* inferiors.c (set_inferior_target_data): Remove.
	* inferiors.h (set_inferior_target_data): Remove.
2017-08-24 23:34:43 +02:00
Jan Kratochvil 663c44ac4d DWARF-5 Fix DW_FORM_implicit_const
-gdwarf-4:
ptype logical
type = const char [2]
(gdb) PASS: gdb.base/constvars.exp: ptype logical

-gdwarf-5:
ptype logical
type = const char []
(gdb) FAIL: gdb.base/constvars.exp: ptype logical

 <2><2fc>: Abbrev Number: 1 (DW_TAG_variable)
    <2fd>   DW_AT_name        : (indirect string, offset: 0x2eb): logical
    <301>   DW_AT_decl_file   : 1

   1      DW_TAG_variable    [no children]
    DW_AT_name         DW_FORM_strp
    DW_AT_decl_file    DW_FORM_implicit_const: 1

During symbol reading, invalid attribute class or form for
'DW_FORM_implicit_const' in '(null)'.

gdb/ChangeLog
2017-08-24  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR symtab/22003
	* dwarf2read.c (dwarf2_const_value_attr, dump_die_shallow)
	(dwarf2_get_attr_constant_value, dwarf2_fetch_constant_bytes)
	(skip_form_bytes, attr_form_is_constant): Handle DW_FORM_implicit_const.
2017-08-24 16:39:11 +02:00
Jan Kratochvil f1902523c9 DWARF-5: Fix -fdebug-types-section
GDB was now accessing as signatured_type memory allocated only by size of
dwarf2_per_cu_data.

gdb/ChangeLog
2017-08-24  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2read.c (build_type_psymtabs_reader): New prototype.
	(process_psymtab_comp_unit): Accept IS_DEBUG_TYPES.
	(read_comp_units_from_section): New parameter abbrev_section, use
	read_and_check_comp_unit_head, allocate signatured_type if needed.
	(create_all_comp_units): Update read_comp_units_from_section caller.
2017-08-24 10:26:52 +02:00
Sergio Durigan Junior 87215ad165 Fix PR remote/21852: Remote run without specifying a local binary crashes GDB
There is an assertion that is triggering when we start GDB and
instruct it to debug a remote inferior, but don't provide a local
binary, like:

  ./gdb -nx -q --data-directory=data-directory -ex "tar ext :1234" \
    -ex "set remote exec-file /bin/ls" -ex r

In this case, when calling exec_file_locate_attach to locate the
inferior, GDB is incorrectly resetting the breakpoints without a
thread/inferior even running, which causes an assertion to be
triggered:

  binutils-gdb/gdb/thread.c:1609: internal-error: scoped_restore_current_thread::scoped_restore_current_thread(): Assertion `tp != NULL' failed.
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.
  Quit this debugging session? (y or n)

This happens because add_current_inferior_and_thread (on remote.c) is
breaking an invariant: making inferior_ptid point to a non-existing
thread and then calling common code, which in this case is
breakpoint_re_set.  The fix is to make sure that inferior_ptid points
to null_ptid if there is no thread present.

A testcase is provided.  Regtested on buildbot.

gdb/ChangeLog:
2017-08-23  Pedro Alves  <palves@redhat.com>

	PR remote/21852
	* remote.c (add_current_inferior_and_thread): Set inferior_ptid
	to null_ptid and switch to thread without reading the registers
	after adding the inferior.

gdb/testsuite/ChangeLog:
2017-08-23  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR remote/21852
	* gdb.server/normal.c: New file, copied from gdb.base.
	* gdb.server/run-without-local-binary.exp: New file.
2017-08-23 17:28:02 -04:00
Jan Kratochvil 6e41ddec97 compile: Add 'set compile-gcc'
As discussed in
	How to use compile & execute function in GDB
	https://sourceware.org/ml/gdb/2015-04/msg00026.html

GDB currently searches for compilers on /usr/bin/ARCH-OS-gcc and
chooses a match from there.  However, it is not currently possible for
the user to override which compiler to use.  This is what this patch
implements.

It is also a sync between GCC's and GDB's interfaces.

gdb/ChangeLog
2017-08-23  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* NEWS (Changes since GDB 7.9): Add set compile-gcc and show
	compile-gcc.
	* compile/compile.c (compile_gcc, show_compile_gcc): New.
	(compile_to_object): Implement compile_gcc.
	(_initialize_compile): Install "set compile-gcc".  Initialize
	compile_gcc.

gdb/doc/ChangeLog
2017-08-23  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.texinfo (Compiling and Injecting Code): Add to subsection
	"Compiler search for the compile command" descriptions of set
	compile-gcc and show compile-gcc.

include/ChangeLog
2017-08-23  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gcc-interface.h (enum gcc_base_api_version): Update comment for
	GCC_FE_VERSION_1.
	(struct gcc_base_vtable): Rename set_arguments to set_arguments_v0.
	Add set_arguments, set_triplet_regexp and set_driver_filename.
2017-08-23 11:16:35 -04:00
Jan Kratochvil e68c32d53e compile: set debug compile: Display GCC driver filename
As discussed in
	How to use compile & execute function in GDB
	https://sourceware.org/ml/gdb/2015-04/msg00026.html

GDB currently searches for compilers on /usr/bin/ARCH-OS-gcc and
chooses a match from there.  However, it is not currently possible for
the user to display which compiler was selected.  Up until now, GDB's
compiler interface was not up-to-date with GCC's one, which means that
it wasn't possible to obtain this information.  This patch implements
the mechanisms necessary for that.

gdb/ChangeLog
2017-08-23  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* compile/compile.c (compile_to_object): Conditionally call
	set_verbose.  Conditionally call compile or compile_v0.

include/ChangeLog
2017-08-23  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gcc-interface.h (enum gcc_base_api_version): Add
	GCC_FE_VERSION_1.
	(struct gcc_base_vtable): Rename compile to compile_v0.  Update
	comment for compile.  New methods set_verbose and compile.
2017-08-23 11:15:03 -04:00
Weimin Pan 58afddc6c7 gdb: SPARC ADI support
The M7 processor supports an Application Data Integrity (ADI) feature
that detects invalid data accesses.  When software allocates data, it
chooses a 4-bit version number, sets the version in the upper 4 bits
of the 64-bit pointer to that data, and stores the 4-bit version in
every cacheline of the object.  Hardware saves the latter in spare
bits in the cache and memory hierarchy. On each load and store, the
processor compares the upper 4 VA (virtual address) bits to the
cacheline's version. If there is a mismatch, the processor generates a
version mismatch trap which can be either precise or disrupting.  The
trap is an error condition which the kernel delivers to the process as
a SIGSEGV signal.

The upper 4 bits of the VA represent a version and are not part of the
true address.  The processor clears these bits and sign extends bit 59
to generate the true address.

Note that 32-bit applications cannot use ADI.

This patch adds ADI support in gdb which allows the user to examine
current version tags and assign new version tags in the program.  It
also catches and reports precise or disrupting memory corruption
traps.

gdb/ChangeLog:
2017-08-07  Weimin Pan  <weimin.pan@oracle.com>

	* sparc64-tdep.h: (adi_normalize_address): New export.
	* sparc-nat.h: (open_adi_tag_fd): New export.
	* sparc64-linux-nat.c: (open_adi_tag_fd): New function.
	* sparc64-linux-tdep.c:
	(SEGV_ACCADI, SEGV_ADIDERR, SEGV_ADIPERR) New defines.
	(sparc64_linux_handle_segmentation_fault): New function.
	(sparc64_linux_init_abi): Register
	sparc64_linux_handle_segmentation_fault
	* sparc64-tdep.c: Include cli-utils.h,gdbcmd.h,auxv.h.
	(sparc64_addr_bits_remove): New function.
	(sparc64_init_abi): Register sparc64_addr_bits_remove.
	(MAX_PROC_NAME_SIZE): New macro.
	(AT_ADI_BLKSZ, AT_ADI_NBITS, AT_ADI_UEONADI) New defines.
	(sparc64adilist): New variable.
	(adi_proc_list): New variable.
	(find_adi_info): New function.
	(add_adi_info): New function.
	(get_adi_info_proc): New function.
	(get_adi_info): New function.
	(info_adi_command): New function.
	(read_maps_entry): New function.
	(adi_available): New function.
	(adi_normalize_address): New function.
	(adi_align_address): New function.
	(adi_convert_byte_count): New function.
	(adi_tag_fd): New function.
	(adi_is_addr_mapped): New function.
	(adi_read_versions): New function.
	(adi_write_versions): New function.
	(adi_print_versions): New function.
	(do_examine): New function.
	(do_assign): New function.
	(adi_examine_command): New function.
	(adi_assign_command): New function.
	(_initialize_sparc64_adi_tdep): New function.

gdb/doc/ChangeLog:
2017-08-07  Weimin Pan  <weimin.pan@oracle.com>

	* gdb.texinfo (Architectures): Add new Sparc64 section to document
	ADI support.
	* NEWS: Add "adi examine" and "adi assign" commands.

gdb/testsuite/ChangeLog:
2017-08-07  Weimin Pan  <weimin.pan@oracle.com>

	* gdb.arch/sparc64-adi.exp: New file.
	* gdb.arch/sparc64-adi.c: New file.
2017-08-23 10:57:37 +02:00
Simon Marchi 11db943032 Rename some command functions
This patch renames a few functions implementing CLI commands to follow
the style <command-name>_command, so that they are easier to search for.

gdb/ChangeLog:

	* breakpoint.c (breakpoints_info): Rename to ...
	(info_breakpoints_command): ... this.
	(watchpoints_info): Rename to ...
	(info_watchpoints_command): ... this.
	(tracepoints_info): Rename to ...
	(info_tracepoints_command): ... this.
	(_initialize_breakpoint): Adjust.
	* dcache.c (dcache_info): Rename to ...
	(info_display_command): ... this.
	(_initialize_dcache): Adjust.
	* frame.h (args_info): Rename to ...
	(info_args_command): ... this.
	(locals_info): Rename to ...
	(info_locals_command): ... this.
	* infcmd.c (nofp_registers_info): Rename to ...
	(info_registers_command): ... this.
	(float_info): Rename to ...
	(info_float_command): ... this.
	(program_info): Rename to ...
	(info_program_command): ... this.
	(all_registers_info): Rename to ...
	(info_all_registers_command): ... this.
	(vector_info): Rename to ...
	(info_vector_command): ... this.
	(float_info): Rename to ...
	(info_float_command): ... this.
	(_initialize_infcmd): Adjust.
	* inferior.h (term_info): Rename to ...
	(info_terminal_command): ... this.
	* inflow.c (term_info): Rename to ...
	(info_terminal_command): ... this.
	(_initialize_inflow): Adjust.
	* infrun.c (signals_info): Rename to ...
	(info_signals_command): ... this.
	(_initialize_infrun): Adjust.
	* objc-lang.c (classes_info): Rename to ...
	(info_classes_command): ... this.
	(selectors_info): Rename to ...
	(info_selectors_command): ... this.
	(_initialize_objc_language): Adjust.
	* printcmd.c (sym_info): Rename to ...
	(info_symbol_command): ... this.
	(address_info): Rename to ...
	(info_address_command): ... this.
	(display_info): Rename to ...
	(info_display_command): ... this.
	(_initialize_printcmd): Adjust.
	* reverse.c (bookmarks_info): Rename to ...
	(info_breakpoints_command): ... this.
	(_initialize_reverse): Adjust.
	* ser-go32.c (dos_info): Rename to ...
	(info_serial_command): ... this.
	(_initialize_ser_dos): Adjust.
	* skip.c (skip_info): Rename to ...
	(info_skip_command): ... this.
	(_initialize_step_skip): Adjust.
	* source.c (line_info): Rename to ...
	(info_line_command): ... this.
	(source_info): Rename to ...
	(info_source_command)
	* stack.c (frame_info): Rename to ...
	(info_frame_command): ... this.
	(locals_info): Rename to ...
	(info_locals_command): ... this.
	(args_info): Rename to ...
	(info_args_command): ... this.
	(_initialize_stack): Adjust.
	* symtab.c (sources_info): Rename to ...
	(info_sources_command): ... this.
	(variables_info): Rename to ...
	(info_variables_command): ... this.
	(functions_info): Rename to ...
	(info_functions_command): ... this.
	(types_info): Rename to ...
	(info_types_command): ... this.
	(_initialize_symtab): Adjust.
	* target.c (target_info): Rename to ...
	(info_target_command): ... this.
	(initialize_targets): Adjust.
	* tracepoint.c (tvariables_info): Rename to ...
	(info_tvariables_command): ... this.
	(scope_info): Rename to ...
	(info_scope_command): ... this.
	(trace_dump_actions): Adjust.
	(_initialize_tracepoint): Adjust.
2017-08-22 22:09:55 +02:00
Pedro Alves 5277199aeb Add test for "List actual code around more than one location" change
This adds a test for the "list" command change done in 0d999a6ef0
("List actual code around more than one location").

gdb/ChangeLog:
2017-08-22  Pedro Alves  <palves@redhat.com>

	* gdb.cp/overload.exp (line_range_pattern): New procedure.
	(top level): Add "list all overloads" tests.
2017-08-22 17:02:14 +01:00
Tom Tromey b270e6f9e0 Change install_breakpoint to take a std::unique_ptr
This changes install_breakpoint to take a std::unique_ptr rvalue-ref
argument.  This makes it clear that install_breakpoint takes ownership
of the pointer, and prevents bugs like the one fixed by the previous
patch.

ChangeLog
2017-08-22  Tom Tromey  <tom@tromey.com>

	* breakpoint.h (install_breakpoint): Update.
	* breakpoint.c (add_solib_catchpoint): Update.
	(install_breakpoint): Change argument to a std::unique_ptr.
	(create_fork_vfork_event_catchpoint): Use std::unique_ptr.
	(create_breakpoint_sal, create_breakpoint): Update.
	(watch_command_1, catch_exec_command_1)
	(strace_marker_create_breakpoints_sal): Use std::unique_ptr.
	(add_to_breakpoint_chain): Change argument to a std::unique_ptr.
	Return the breakpoint.
	(set_raw_breakpoint_without_location, set_raw_breakpoint)
	(new_single_step_breakpoint): Update.
	* break-catch-throw.c (handle_gnu_v3_exceptions): Use
	std::unique_ptr.
	* break-catch-syscall.c (create_syscall_event_catchpoint): Use
	std::unique_ptr.
	* break-catch-sig.c (create_signal_catchpoint): Use
	std::unique_ptr.
	* ada-lang.c (create_ada_exception_catchpoint): Use
	std::unique_ptr.
2017-08-22 09:38:07 -06:00
Tom Tromey 36bd8eaaa0 Fix erroneous cleanup use in add_solib_catchpoint
I happened to notice that add_solib_catchpoint allocated the new
catchpoint with "new" but installed a cleanup using "xfree".  This
patch fixes the bug by changing the function to use std::unique_ptr
instead.

ChangeLog
2017-08-22  Tom Tromey  <tom@tromey.com>

	* breakpoint.c (add_solib_catchpoint): Use std::unique_ptr.
2017-08-22 09:38:06 -06:00
Tom Tromey 56f3764524 Change psymtab_search_name to return a unique_xmalloc_ptr
This changes psymtab_search_name to return a unique_xmalloc_ptr and
fixes up its one caller.  This allows the removal of some cleanups.

ChangeLog
2017-08-22  Tom Tromey  <tom@tromey.com>

	* psymtab.c (psymtab_search_name): Return a unique_xmalloc_ptr.
	(lookup_partial_symbol): Update.
2017-08-22 09:30:13 -06:00
Tom Tromey 0b581c69fe Change rewrite_source_path to return a unique_xmalloc_ptr
This changes rewrite_source_path to return a unique_xmalloc_ptr and
fixes up the callers.  This allows removing some cleanups.

ChangeLog
2017-08-22  Tom Tromey  <tom@tromey.com>

	* source.h (rewrite_source_path): Return a unique_xmalloc_ptr.
	* source.c (rewrite_source_path): Return a unique_xmalloc_ptr.
	(find_and_open_source, symtab_to_fullname): Update.
	* psymtab.c (psymtab_to_fullname): Update.
2017-08-22 09:30:12 -06:00
Tom Tromey 14278e1fdb Change gdb_realpath to return a unique_xmalloc_ptr
This changes gdb_realpath to return a unique_xmalloc_ptr and fixes up
the callers.  This allows removing some cleanups.  This change by
itself caused xfullpath.exp to fail; and attempting to fix that ran
into various problems (like .get() being optimized out); so this patch
also rewrites xfullpath.exp to be a C++ selftest instead.

ChangeLog
2017-08-22  Tom Tromey  <tom@tromey.com>

	* exec.c (exec_file_attach): Update.
	* linux-thread-db.c (try_thread_db_load): Update.
	* guile/scm-safe-call.c (gdbscm_safe_source_script): Update.
	* utils.c (gdb_realpath): Change return type.
	(gdb_realpath_keepfile): Update.
	(gdb_realpath_check_trailer, gdb_realpath_tests): New functions.
	(_initialize_utils): Register the new self test.
	* source.c (openp): Update.
	(find_and_open_source): Update.
	* nto-tdep.c (nto_find_and_open_solib): Update.
	* main.c (set_gdb_data_directory): Update.
	(captured_main_1): Update.
	* dwarf2read.c (dwarf2_get_dwz_file): Update
	(dw2_map_symbol_filenames): Update.
	* auto-load.c (auto_load_safe_path_vec_update): Update.
	(filename_is_in_auto_load_safe_path_vec): Change type of
	"filename_realp".
	(auto_load_objfile_script): Update.
	(file_is_auto_load_safe): Update.  Use std::string.
	* utils.h (gdb_realpath): Return a gdb::unique_xmalloc_ptr.

testsuite/ChangeLog
2017-08-22  Tom Tromey  <tom@tromey.com>

	* gdb.gdb/xfullpath.exp: Remove.
2017-08-22 09:30:12 -06:00
Tom Tromey 4971c9a74b Change gdb_realpath_keepfile to return a unique_xmalloc_ptr
This changes gdb_realpath_keepfile to return a unique_xmalloc_ptr, and
fixes up the callers.

ChangeLog
2017-08-22  Tom Tromey  <tom@tromey.com>

	* utils.c (gdb_realpath_keepfile): Return a
	gdb::unique_xmalloc_ptr.
	* exec.c (exec_file_attach): Update.
	* utils.h (gdb_realpath_keepfile): Return a
	gdb::unique_xmalloc_ptr.
2017-08-22 09:30:11 -06:00
Tom Tromey e3e41d588a Change gdb_abspath to return a unique_xmalloc_ptr
This changes gdb_abspath to return a unique_xmalloc_ptr, and fixes up
the callers.  This allows the removal of a cleanup, and also puts
ownership rules into the API, where they belong.

ChangeLog
2017-08-22  Tom Tromey  <tom@tromey.com>

	* compile/compile.c (compile_file_command): Use
	gdb::unique_xmalloc_ptr, std::string.
	* utils.c (gdb_abspath): Change return type.
	* source.c (openp): Update.
	* objfiles.c (allocate_objfile): Update.
	* main.c (set_gdb_data_directory): Update.
	* utils.h (gdb_abspath): Return a gdb::unique_xmalloc_ptr.
2017-08-22 09:30:10 -06:00
Zhouyi Zhou 0d999a6ef0 List actual code around more than one location
With the following C++ code:
 int bar() { return 0;}
 int bar(int) { return 0; }

GDB behaves as:
 (gdb) list bar
  file: "overload.cc", line number: 1
  file: "overload.cc", line number: 2

It would be better for GDB to list the actual code around those two
locations, not just print the location.  Like:

 (gdb) list bar
 file: "overload.cc", line number: 1
 1       int bar() { return 0;}
 2       int bar(int) { return 0; }
 file: "overload.cc", line number: 2
 1       int bar() { return 0;}
 2       int bar(int) { return 0; }

That's what this this commit implements.

Tested on x86-64 GNU/Linux.

gdb/ChangeLog:
2017-08-22  Zhouyi Zhou  <zhouzhouyi@gmail.com>

	* cli-cmds.c (list_commands): List actual code around more than
	one location.
2017-08-22 15:32:19 +01:00
John Baldwin 329d5e7e56 Use an array type (lwpid_t[]) for the array of lwp IDs.
gdb/ChangeLog:

	* fbsd-nat.c (fbsd_add_threads): Use array type for `lwps'.
2017-08-21 09:35:25 -07:00
John Baldwin af3881e612 Correct earlier ChangeLog entry for fbsd_add_threads. 2017-08-21 09:34:55 -07:00
Pedro Alves bf223d3e80 Handle function aliases better (PR gdb/19487, errno printing)
(Ref: https://sourceware.org/ml/gdb/2017-06/msg00048.html)

This patch improves GDB support for function aliases defined with
__attribute__ alias.  For example, in the test added by this commit,
there is no reference to "func_alias" in the debug info at all, only
to "func"'s definition:

 $ nm  ./testsuite/outputs/gdb.base/symbol-alias/symbol-alias  | grep " func"
 00000000004005ae t func
 00000000004005ae T func_alias

 $ readelf -w ./testsuite/outputs/gdb.base/symbol-alias/symbol-alias | grep func -B 1 -A 8
 <1><db>: Abbrev Number: 5 (DW_TAG_subprogram)
    <dc>   DW_AT_name        : (indirect string, offset: 0x111): func
    <e0>   DW_AT_decl_file   : 1
    <e1>   DW_AT_decl_line   : 27
    <e2>   DW_AT_prototyped  : 1
    <e2>   DW_AT_type        : <0xf8>
    <e6>   DW_AT_low_pc      : 0x4005ae
    <ee>   DW_AT_high_pc     : 0xb
    <f6>   DW_AT_frame_base  : 1 byte block: 9c         (DW_OP_call_frame_cfa)
    <f8>   DW_AT_GNU_all_call_sites: 1

So all GDB knows about "func_alias" is from the minsym (elf symbol):

 (gdb) p func_alias
 $1 = {<text variable, no debug info>} 0x4005ae <func>
 (gdb) ptype func_alias
 type = int ()

 (gdb) p func
 $2 = {struct S *(void)} 0x4005ae <func>
 (gdb) ptype func
 type = struct S {
     int field1;
     int field2;
 } *(void)

The result is that calling func_alias from the command line produces
incorrect results.

This is similar (though not exactly the same) to the glibc
errno/__errno_location/__GI___errno_location situation.  On glibc,
errno is defined like this:

  extern int *__errno_location (void);
  #define errno (*__errno_location ())

with __GI___errno_location being an internal alias for
__errno_location.  On my system's libc (F23), I do see debug info for
__errno_location, in the form of name vs linkage name:

 <1><95a5>: Abbrev Number: 18 (DW_TAG_subprogram)
    <95a6>   DW_AT_external    : 1
    <95a6>   DW_AT_name        : (indirect string, offset: 0x2c26): __errno_location
    <95aa>   DW_AT_decl_file   : 1
    <95ab>   DW_AT_decl_line   : 24
    <95ac>   DW_AT_linkage_name: (indirect string, offset: 0x2c21): __GI___errno_location
    <95b0>   DW_AT_prototyped  : 1
    <95b0>   DW_AT_type        : <0x9206>
    <95b4>   DW_AT_low_pc      : 0x20f40
    <95bc>   DW_AT_high_pc     : 0x11
    <95c4>   DW_AT_frame_base  : 1 byte block: 9c       (DW_OP_call_frame_cfa)
    <95c6>   DW_AT_GNU_all_call_sites: 1

however that doesn't matter in practice, because GDB doesn't record
demangled names anyway, and so we end up with the exact same situation
covered by the testcase.

So the fix is to make the expression parser find a debug symbol for
the same address as the just-found minsym, when a lookup by name
didn't find a debug symbol by name.  We now get:

 (gdb) p func_alias
 $1 = {struct S *(void)} 0x4005ae <func>
 (gdb) p __errno_location
 $2 = {int *(void)} 0x7ffff6e92830 <__errno_location>

I've made the test exercise variable aliases too, for completeness.
Those already work correctly, because unlike for function aliases, GCC
emits debug information for variable aliases.

Tested on GNU/Linux.

gdb/ChangeLog:
2017-08-21  Pedro Alves  <palves@redhat.com>

	PR gdb/19487
	* c-exp.y (variable production): Handle function aliases.
	* minsyms.c (msymbol_is_text): New function.
	* minsyms.h (msymbol_is_text): Declare.
	* symtab.c (find_function_alias_target): New function.
	* symtab.h (find_function_alias_target): Declare.

gdb/testsuite/ChangeLog:
2017-08-21  Pedro Alves  <palves@redhat.com>

	PR gdb/19487
	* gdb.base/symbol-alias.c: New.
	* gdb.base/symbol-alias2.c: New.
	* gdb.base/symbol-alias.exp: New.
2017-08-21 11:34:32 +01:00
Pedro Alves c973d0aa4a Fix type casts losing typedefs and reimplement "whatis" typedef stripping
(Ref: https://sourceware.org/ml/gdb/2017-06/msg00020.html)

Assuming int_t is a typedef to int:

 typedef int int_t;

gdb currently loses this expression's typedef:

 (gdb) p (int_t) 0
 $1 = 0
 (gdb) whatis $1
 type = int

or:

 (gdb) whatis (int_t) 0
 type = int

or, to get "whatis" out of the way:

 (gdb) maint print type (int_t) 0
 ...
 name 'int'
 code 0x8 (TYPE_CODE_INT)
 ...

This prevents a type printer for "int_t" kicking in, with e.g.:

 (gdb) p (int_t) 0

From the manual, we can see that that "whatis (int_t) 0" command
invocation should have printed "type = int_t":

 If @var{arg} is a variable or an expression, @code{whatis} prints its
 literal type as it is used in the source code.  If the type was
 defined using a @code{typedef}, @code{whatis} will @emph{not} print
 the data type underlying the @code{typedef}.
 (...)
 If @var{arg} is a type name that was defined using @code{typedef},
 @code{whatis} @dfn{unrolls} only one level of that @code{typedef}.

That one-level stripping is currently done here, in
gdb/eval.c:evaluate_subexp_standard, handling OP_TYPE:

...
     else if (noside == EVAL_AVOID_SIDE_EFFECTS)
	{
	  struct type *type = exp->elts[pc + 1].type;

	  /* If this is a typedef, then find its immediate target.  We
	     use check_typedef to resolve stubs, but we ignore its
	     result because we do not want to dig past all
	     typedefs.  */
	  check_typedef (type);
	  if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
	    type = TYPE_TARGET_TYPE (type);
	  return allocate_value (type);
	}

However, this stripping is reachable in both:

 #1 - (gdb) whatis (int_t)0     # ARG is an expression with a cast to
                                # typedef type.
 #2 - (gdb) whatis int_t        # ARG is a type name.

while only case #2 should strip the typedef.  Removing that code from
evaluate_subexp_standard is part of the fix.  Instead, we make the
"whatis" command implementation itself strip one level of typedefs
when the command argument is a type name.

We then run into another problem, also fixed by this commit:
value_cast always drops any typedefs of the destination type.

With all that fixed, "whatis (int_t) 0" now works as expected:

 (gdb) whatis int_t
 type = int
 (gdb) whatis (int_t)0
 type = int_t

value_cast has many different exit/convertion paths, for handling many
different kinds of casts/conversions, and most of them had to be
tweaked to construct the value of the right "to" type.  The new tests
try to exercise most of it, by trying castin of many different
combinations of types.  With:

 $ make check TESTS="*/whatis-ptype*.exp */gnu_vector.exp */dfp-test.exp"

... due to combinatorial explosion, the testsuite results for the
tests above alone grow like:

 - # of expected passes            246
 + # of expected passes            3811

You'll note that the tests exposed one GCC buglet, filed here:

  Missing DW_AT_type in DW_TAG_typedef of "typedef of typedef of void"
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81267

gdb/ChangeLog:
2017-08-21  Pedro Alves  <palves@redhat.com>

	* eval.c (evaluate_subexp_standard) <OP_TYPE>: Don't dig past
	typedefs.
	* typeprint.c (whatis_exp): If handling "whatis", and expression
	is OP_TYPE, strip one typedef level.  Otherwise don't strip
	typedefs here.
	* valops.c (value_cast): Save "to" type before resolving
	stubs/typedefs.  Use that type as resulting value's type.

gdb/testsuite/ChangeLog:
2017-08-21  Pedro Alves  <palves@redhat.com>

	* gdb.base/dfp-test.c
	(d32_t, d64_t, d128_t, d32_t2, d64_t2, d128_t2, v_d32_t, v_d64_t)
	(v_d128_t, v_d32_t2, v_d64_t2, v_d128_t2): New.
	* gdb.base/dfp-test.exp: Add whatis/ptype/cast tests.
	* gdb.base/gnu_vector.exp: Add whatis/ptype/cast tests.
	* gdb.base/whatis-ptype-typedefs.c: New.
	* gdb.base/whatis-ptype-typedefs.exp: New.
	* gdb.python/py-prettyprint.c (int_type, int_type2): New typedefs.
	(an_int, an_int_type, an_int_type2): New globals.
	* gdb.python/py-prettyprint.exp (run_lang_tests): Add tests
	involving typedefs and cast expressions.
	* gdb.python/py-prettyprint.py (class pp_int_typedef): New.
	(lookup_typedefs_function): New.
	(typedefs_pretty_printers_dict): New.
	(top level): Register lookup_typedefs_function in
	gdb.pretty_printers.
2017-08-21 11:34:32 +01:00
Tom Tromey 2989a3651d Remove save_inferior_ptid
This removes save_inferior_ptid, a cleanup function, in favor of
scoped_restore.

This also fixes a possible (it seems unlikely that it could happen in
practice) memory leak -- save_inferior_ptid should have used
make_cleanup_dtor, because it allocated memory.

I tested this on the buildbot.  However, there are two caveats to
this.  First, sometimes it seems I misread the results.  Second, I
think this patch touches some platforms that can't be tested by the
buildbot.  So, extra care seems warranted.

ChangeLog
2017-08-18  Tom Tromey  <tom@tromey.com>
	    Pedro Alves  <palves@redhat.com>

	* spu-multiarch.c (parse_spufs_run): Use scoped_restore.
	* sol-thread.c (sol_thread_resume, sol_thread_wait)
	(sol_thread_xfer_partial, rw_common): Use scoped_restore.
	* procfs.c (procfs_do_thread_registers): Use scoped_restore.
	* proc-service.c (ps_xfer_memory): Use scoped_restore.
	* linux-tdep.c (linux_corefile_thread): Remove a cleanup.
	(linux_get_siginfo_data): Add "thread" argument.  Use
	scoped_restore.
	* linux-nat.c (linux_child_follow_fork)
	(check_stopped_by_watchpoint): Use scoped_restore.
	* infrun.c (displaced_step_prepare_throw, write_memory_ptid)
	(THREAD_STOPPED_BY, handle_signal_stop): Use scoped_restore.
	(restore_inferior_ptid, save_inferior_ptid): Remove.
	* btrace.c (btrace_fetch): Use scoped_restore.
	* bsd-uthread.c (bsd_uthread_fetch_registers)
	(bsd_uthread_store_registers): Use scoped_restore.
	* breakpoint.c (reattach_breakpoints, detach_breakpoints): Use
	scoped_restore.
	* aix-thread.c (aix_thread_resume, aix_thread_wait)
	(aix_thread_xfer_partial): Use scoped_restore.
	* inferior.h (save_inferior_ptid): Remove.
2017-08-18 11:06:26 -06:00
Yao Qi e60eb28803 [ARM] Mark USER_SPECIFIED_MACHINE_TYPE in disassemble_info.flags
opcodes/arm-dis.c:print_insn may update disassemble_info.mach to
bfd_mach_arm_unknown unless USER_SPECIFIED_MACHINE_TYPE is marked.
When default_print_insn is called for the first time,
disassemble_info.mach is correctly set in GDB, but arm-dis.c:print_insn
sets it to bfd_mach_arm_unknown.  Then, when default_print_insn is
called again (in a loop), it triggers the assert.

The patch fixes the assert by marking USER_SPECIFIED_MACHINE_TYPE so that
opcodes won't reset disassemble_info.mach.

gdb:

2017-08-18  Yao Qi  <yao.qi@linaro.org>

	PR tdep/21818
	* arm-tdep.c (gdb_print_insn_arm): Mark
	USER_SPECIFIED_MACHINE_TYPE if exec_bfd isn't NULL.
2017-08-18 09:30:12 +01:00
Yao Qi 6d580b635f GDBserver self tests
This patch uses GDB self test in GDBserver.  The self tests are run if
GDBserver is started with option --selftest.

gdb:

2017-08-18  Yao Qi  <yao.qi@linaro.org>

	* NEWS: Mention GDBserver's new option "--selftest".
	* Makefile.in (SFILES): Remove selftest.c, add common/selftest.c.
	* selftest.c: Move it to common/selftest.c.
	* selftest.h: Move it to common/selftest.h.
	* selftest-arch.c (reset): New function.
	(tests_with_arch): Call reset.

gdb/gdbserver:

2017-08-18  Yao Qi  <yao.qi@linaro.org>

	* Makefile.in (OBS): Add selftest.o.
	* configure.ac: AC_DEFINE GDB_SELF_TEST if $development.
	* configure, config.in: Re-generated.
	* server.c: Include common/sefltest.h.
	(captured_main): Handle option --selftest.

gdb/testsuite:

2017-08-18  Yao Qi  <yao.qi@linaro.org>

	* gdb.server/unittest.exp: New.

gdb/doc:

2017-08-18  Yao Qi  <yao.qi@linaro.org>

	* gdb.texinfo (Server): Document "--selftest".
2017-08-18 09:20:43 +01:00
Yao Qi 86dcbf50fe Remove some GDB specific stuff from selftest.c
The next patch moves selftest.c to common/selftest.c, so that GDBserver
can use it as well.  However selftest.c uses something isn't "portable" on
GDB and GDBserver.

First, this patch removes QUIT.  I don't expect that we type ctrl-c during
self/unit tests, and each test shouldn't take long time.  Secondly, I
replace exception_fprintf and printf_filtered with debug_printf.  Verified
that unit tests still catch fails.

gdb:

2017-08-18  Yao Qi  <yao.qi@linaro.org>

	* selftest.c (run_tests): Don't call QUIT.  Call debug_printf
	instead of exception_fprintf and printf_filtered.
2017-08-18 09:20:43 +01:00
Yao Qi 7649770c8e Put selftests api into selftests namespace
This patch changes register_self_test to selftests::register_test,
and run_self_tests to selftest::run_tests.

gdb:

2017-08-18  Yao Qi  <yao.qi@linaro.org>

	* selftest.c (register_self_test): Rename it to
	selftests::register_test.
	(run_self_tests): selftest::run_tests.
	* selftest.h: Update declarations.
	* selftest-arch.c (register_self_test_foreach_arch): Rename it to
	selftests::register_test_foreach_arch.
	* selftest-arch.h: Update declaration.
	* aarch64-tdep.c: Update.
	* arm-tdep.c: Likewise.
	* disasm-selftests.c: Likewise.
	* dwarf2loc.c: Likewise.
	* dwarf2-frame.c: Likewise.
	* findvar.c: Likewise.
	* gdbarch-selftests.c: Likewise.
	* maint.c (maintenance_selftest): Likewise.
	* regcache.c: Likewise.
	* rust-exp.y: Likewise.
	* selftest-arch.c: Likewise.
	* unittests/environ-selftests.c: Likewise.
	* unittests/function-view-selftests.c: Likewise.
	* unittests/offset-type-selftests.c: Likewise.
	* unittests/optional-selftests.c: Likewise.
	* unittests/scoped_restore-selftests.c: Likewise.
	* utils-selftests.c: Likewise.
2017-08-18 09:20:43 +01:00
Pedro Alves b0cba12e07 Plug source_command leak
The heap-allocated 'old_source_verbose' local was accidentally left
behind by commit 2ec845e758 ("More uses of scoped_restore").

Valgrind caught it, like:

 ==20123== 8 bytes in 1 blocks are definitely lost in loss record 4,609 of 13,785
 ==20123==    at 0x4C2A988: calloc (vg_replace_malloc.c:711)
 ==20123==    by 0x60A2F8: xcalloc (common-utils.c:84)
 ==20123==    by 0x4CDBE5: build_command_line(command_control_type, char const*) (cli-script.c:159)
 ==20123==    by 0x4CDC32: get_command_line(command_control_type, char const*) (cli-script.c:172)
 ==20123==    by 0x5230F1: python_command(char*, int) (python.c:421)
 ==20123==    by 0x4C61AD: do_cfunc(cmd_list_element*, char*, int) (cli-decode.c:106)
 ==20123==    by 0x4C911F: cmd_func(cmd_list_element*, char*, int) (cli-decode.c:1902)
 ==20123==    by 0x7CA79E: execute_command(char*, int) (top.c:650)
 ==20123==    by 0x695A0C: command_handler(char*) (event-top.c:590)
 ==20123==    by 0x7CA33F: read_command_file(_IO_FILE*) (top.c:461)
 ==20123==    by 0x4D0C3A: script_from_file(_IO_FILE*, char const*) (cli-script.c:1584)
 ==20123==    by 0x4C2727: source_script_from_stream(_IO_FILE*, char const*, char const*) (cli-cmds.c:589)

gdb/ChangeLog:
2017-08-17  Pedro Alves  <palves@redhat.com>

	* cli/cli-cmds.c (source_command): Delete 'old_source_verbose'
	local.
2017-08-17 23:57:45 +01:00
Pedro Alves 4c8aa72d0e Plug line_header leaks
This plugs a couple leaks introduced by commit fff8551cf5
("dwarf2read.c: Some C++fycation, use std::vector, std::unique_ptr").

The first problem is that nothing owns the temporary line_header that
handle_DW_AT_stmt_list creates in some cases.  Before the commit
mentioned above, the temporary line_header case used to have:

  make_cleanup (free_cu_line_header, cu);

and that cleanup was assumed to be run by process_die, after
handle_DW_AT_stmt_list returns and before child DIEs were processed.

The second problem is found in setup_type_unit_groups: that also used
to have a similar make_cleanup call, and ended up with a similar leak
after the commit mentioned above.

Fix both cases by recording in dwarf2_cu whether a line header is
owned by the cu/die, and have process_die explicitly free the
line_header if so, making use of a new RAII object that also replaces
the reset_die_in_process cleanup, while at it.

Thanks to Philippe Waroquiers for noticing the leak and pointing in
the right direction.

gdb/ChangeLog:
2017-08-17  Pedro Alves  <palves@redhat.com>

	* dwarf2read.c (struct dwarf2_cu) <line_header_die_owner>: New
	field.
	(reset_die_in_process): Delete, replaced by ...
	(process_die_scope): ... this new class.  Make it responsible for
	freeing cu->line_header too.
	(process_die): Use process_die_scope.
	(handle_DW_AT_stmt_list): Record the line header's owner CU/DIE in
	cu->line_header_die_owner.  Don't release the line header if it's
	owned by the CU.
	(setup_type_unit_groups): Make the CU/DIE own the line header.
	Don't release the line header here.
2017-08-17 22:53:53 +01:00
Alex Lindsay ba7139188c Synthetic symbol leak in elf_read_minimal_symbols
Detected this leak with valgrind memcheck:

==30840== 194 bytes in 1 blocks are definitely lost in loss record 9,138 of 10,922
==30840==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==30840==    by 0x80DF82: bfd_malloc (libbfd.c:193)
==30840==    by 0x80E12D: bfd_zmalloc (libbfd.c:278)
==30840==    by 0x819E80: elf_x86_64_get_synthetic_symtab (elf64-x86-64.c:6835)
==30840==    by 0x4F7B01: elf_read_minimal_symbols(objfile*, int, elfinfo const*) (elfread.c:1124)
==30840==    by 0x4F7CE7: elf_symfile_read(objfile*, enum_flags<symfile_add_flag>) (elfread.c:1182)
==30840==    by 0x7557FC: read_symbols(objfile*, enum_flags<symfile_add_flag>) (symfile.c:861)
==30840==    by 0x755EE1: syms_from_objfile_1(objfile*, section_addr_info*, enum_flags<symfile_add_flag>) (symfile.c:1062)

We perform a dynamic allocation in
elf64-x86-64.c:elf_x86_64_get_synthetic_symtab

  s = *ret = (asymbol *) bfd_zmalloc (size);

that appear to never get freed.

gdb:

2017-08-17  Alex Lindsay  <alexlindsay239@gmail.com>

	* elfread.c (elf_read_minimal_symbols): xfree synthsyms.
2017-08-17 11:53:53 +01:00
Ruslan Kabatsayev 44d0fb3a0a Mention new TUI Single-Key mode shortcuts for nexti and stepi in NEWS
gdb/ChangeLog:

	* NEWS: Mention new shortcuts for nexti and stepi in TUI
	Single-Key mode
2017-08-17 08:45:02 +03:00
Ruslan Kabatsayev a5afdb1665 Add shortcuts for "nexti" and "stepi" commands in Single-Key mode
Currently, "layout asm" is not so useful as "layout src" with Single-Key mode:
you have to use multi-key commands like "ni" and "si" to do single-stepping.
This patch adds, in addition to "next" and "step" commands, corresponding
assembly-level ones - "nexti" and "stepi" - to Single-Key mode, with the
shortcuts of "o" (from "step Over") and "i" (from "Step Into") respectively.

gdb/ChangeLog:

	* tui/tui.c (tui_commands): Add "nexti" and "stepi" to the Single-Key
	mode command list.

gdb/doc/ChangeLog:

	* gdb.texinfo (TUI Single Key Mode): Document the new shortcuts in
	Single-Key mode.
2017-08-16 21:44:29 +03:00
Stafford Horne 47613aeb8a Add myself as a write-after-approval GDB maintainer.
gdb/ChangeLog:

	* MAINTAINERS (Write After Approval): Add Stafford Horne.
2017-08-16 06:38:24 +09:00
Stafford Horne 9c3cc99930 xtensa: Properly strdup string when building reggroup
I noticed this while looking at the reggroup intializations.  It seems
for xtensa the "cpN" reggroup->name is getting assigned to the same text
pointer for each iteration of XTENSA_MAX_COPROCESSOR.

Note, internally reggroup_new() does not do any xstrdup().

gdb/ChangeLog:
2017-08-15  Stafford Horne  <shorne@gmail.com>

	* xtensa-tdep.c (xtensa_init_reggroups): Use xstrdup for cpname.
2017-08-16 06:12:45 +09:00
Sergio Durigan Junior 206726fbfd Fix PR gdb/21954: make 'unset environment' work again
When I made commit 9a6c7d9c02, which
C++-fied gdb/common/environ.[ch], I mistakenly altered the behaviour
of the 'unset environment' command.  This command, which should delete
all environment variables, is now resetting the list of variables to
the state they were when GDB was started.

This commit fixes this regression, and also adds a test on
gdb.base/environ.exp which really checks if 'unset environment'
worked.

gdb/ChangeLog:
2017-08-15  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR gdb/21954
	* infcmd.c (unset_environment_command): Use the 'clear' method on
	the environment instead of resetting it.

gdb/testsuite/ChangeLog:
2017-08-15  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR gdb/21954
	* gdb.base/environ.exp: Add test to check if 'unset environment'
	works.
2017-08-15 13:49:18 -04:00
John Baldwin 0335ac6d12 Fix compile on big-endian platforms in siginfo_t converter.
gdb/ChangeLog:

	* fbsd-nat.c (fbsd_convert_siginfo): Fix compile on big-endian
	platforms.
2017-08-15 08:05:21 -07:00
Andreas Arnez bf0ec4c276 GDB testsuite: Suppress GCC's colored output
Newer GCC versions yield colored diagnostic messages by default, which may
be useful when executing GDB interactively from a terminal.  But when run
from a GDB test case, the compiler output is written into gdb.log, where
such escape sequences are usually more inhibiting than helpful to the
evaluation of test results.  So this patch suppresses that.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (universal_compile_options): New caching proc.
	(gdb_compile): Suppress GCC's coloring of messages.
2017-08-14 20:31:09 +02:00
Tom Tromey d3abe1c8ef Remove BITS_IN_BYTES define
While working on the previous patch, I noticed that BITS_IN_BYTES can be
replaced by HOST_CHAR_BIT, which is used more widely in gdb.

ChangeLog
2017-08-14  Tom Tromey  <tom@tromey.com>

	* valprint.c (print_octal_chars): Use HOST_CHAR_BIT.
	(print_binary_chars): Likewise.
	(BITS_IN_BYTES): Remove.
2017-08-14 10:14:06 -06:00
Tom Tromey d6382fffde Fix two regressions in scalar printing
PR gdb/21675 points out a few regressions in scalar printing.

One type of regression is due to not carrying over the old handling of
floating point printing -- where a format like "/d" causes a floating
point number to first be cast to a signed integer.  This patch restores
this behavior.

The other regression is a longstanding bug in print_octal_chars: one of
the constants was wrong.  This patch fixes the constant and adds static
asserts to help catch this sort of error.

ChangeLog
2017-08-14  Tom Tromey  <tom@tromey.com>

	PR gdb/21675
	* valprint.c (LOW_ZERO): Change value to 034.
	(print_octal_chars): Add static_asserts for octal constants.
	* printcmd.c (print_scalar_formatted): Add 'd' case.

testsuite/ChangeLog
2017-08-14  Tom Tromey  <tom@tromey.com>

	PR gdb/21675:
	* gdb.base/printcmds.exp (test_radices): New function.
	* gdb.dwarf2/var-access.exp: Use p/u, not p/d.
	* gdb.base/sizeof.exp (check_valueof): Use p/d.
	* lib/gdb.exp (get_integer_valueof): Use p/d.
2017-08-14 10:14:05 -06:00
Tom Tromey f978cb06db Fix memory leak in add_symbol_file_command
I happened to notice that add_symbol_file_command leaks "sect_opts".
This patch fixes the leak by changing sect_opts to be a std::vector.

I had to change the logic in the loop a little bit.  Previously, it
was incrementing section_index after completing an entry; but this
changes it to push a new entry when the name is seen.

I believe the argument parsing here is mildly incorrect, in that
nothing checks whether the -s option actually had any arguments.
Maybe gdb can crash if "-s NAME" is given without an argument.  I
didn't try to fix this in this patch, but I do have another patch I
can send later that fixes it up.

Regression tested on the buildbot.

ChangeLog
2017-08-11  Tom Tromey  <tom@tromey.com>

	* symfile.c (add_symbol_file_command): Use std::vector.
2017-08-14 08:31:07 -06:00
Tom Tromey 2f5404b358 Use std::move in a few places
This patch adds std::move to few spots where it seems to be missing.

Regression tested by the buildbot.

ChangeLog
2017-08-14  Tom Tromey  <tom@tromey.com>

	* break-catch-throw.c (handle_gnu_v3_exceptions): Use std::move.
	* break-catch-syscall.c (create_syscall_event_catchpoint): Use
	std::move.
	* break-catch-sig.c (create_signal_catchpoint): Use std::move.
2017-08-14 08:24:15 -06:00
Sergio Durigan Junior ca145713f3 Fix typo on documentation ("show set startup-with-shell")
The documentation was erroneously saying that there is a command named
"show set startup-with-shell", while the correct version is "show
startup-with-shell".  This commit fixes obvious mistake.

gdb/doc/ChangeLog:
2017-08-12  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR gdb/21925
	* gdb.texinfo (Starting) <startup-with-shell>: Fix typo ("show
	set...").
2017-08-12 12:46:03 -04:00
Simon Marchi c2c2dd9f09 testsuite: Exclude end-of-line characters from get_valueof result
The get_valueof procedure allows tests to conveniently make gdb evaluate
an expression an return the value as a string.  However, it includes an
end-of-line character in its result.  I stumbled on this when trying to
use that result as part of a regex further in a test.

You can see this for example by adding a puts in
gdb.dwarf2/implref-struct.exp:get_members:

    set members [get_valueof "" ${var} ""]
    puts "<$members>"

The output is

    <{a = 0, b = 1, c = 2}
    >

This is because the regex in get_valueof is too greedy, the captured
portion matches anything up to the gdb_prompt, including the end of line
characters.  This patch changes it to capture everything but end of line
characters.

The output of the puts becomes:

    <{a = 0, b = 1, c = 2}>

I tested this by running gdb.dwarf2/implref-array.exp and
gdb.dwarf2/implref-struct.exp, the two only current users of that
procedure.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (get_valueof): Don't capture end-of-line
	characters.
2017-08-12 10:33:00 +02:00
Pedro Alves de7985c3cc More gdb/skip.c C++ification
- Make skiplist_entry a class with private data members.
- Move all construction logic to the ctor.
- Make skip_file_p etc be methods of skiplist_entry.
- Use std::list for the skip entries chain.  Make the list own its
  elements.
- Get rid of the ALL_SKIPLIST_ENTRIES/ALL_SKIPLIST_ENTRIES_SAFE
  macros, use range-for / iterators instead.
- function_name_is_marked_for_skip 'function_sal' argument must be
  non-NULL, so make it a reference instead.

All skiplist_entry invariants are now controlled by skiplist_entry
methods/internals.  Some gdb_asserts disappear for being redundant.

gdb/ChangeLog:
2017-08-11  Pedro Alves  <palves@redhat.com>

	* infrun.c (process_event_stop_test): Adjust
	function_name_is_marked_for_skip call.
	* skip.c: Include <list>.
	(skiplist_entry): Make it a class with private fields, and
	getters/setters.
	(skiplist_entry_chain): Delete.
	(skiplist_entries): New.
	(skiplist_entry_count): Delete.
	(highest_skiplist_entry_num): New.
	(ALL_SKIPLIST_ENTRIES, ALL_SKIPLIST_ENTRIES_SAFE): Delete.
	(add_skiplist_entry): Delete.
	(skiplist_entry::skiplist_entry): New.
	(skiplist_entry::add_entry): New.
	(skip_file_command, skip_function): Adjust.
	(compile_skip_regexp): Delete.
	(skip_command): Don't compile regexp here.  Adjust to use
	skiplist_entry::add_entry.
	(skip_info): Adjust to use range-for and getters.
	(skip_enable_command, skip_disable_command): Adjust to use
	range-for and setters.
	(skip_delete_command): Adjust to use std::list.
	(add_skiplist_entry): Delete.
	(skip_file_p): Delete, refactored as ...
	(skiplist_entry::do_skip_file_p): ... this new method.
	(skip_gfile_p): Delete, refactored as ...
	(skiplist_entry::do_gskip_file_p): ... this new method.
	(skip_function_p, skip_rfunction_p): Delete, refactored as ...
	(skiplist_entry::skip_function_p): ... this new method.
	(function_name_is_marked_for_skip): Now returns bool, and takes
	the function sal by const reference.  Adjust to use range-for and
	skiplist_entry methods.
	(_initialize_step_skip): Remove references to
	skiplist_entry_chain, skiplist_entry_count.
	* skip.h (function_name_is_marked_for_skip): Now returns bool, and
	takes the function sal by const reference.
2017-08-11 12:11:28 +01:00
Yao Qi be7d3cd5f1 Reset *THIS_CACHE in frame_unwind_try_unwinder in case of exception
It is required that unwinder->sniffer should set *this_cache to NULL if
the unwinder is not applicable or exception is thrown, so
78ac5f8316 adds clear_pointer_cleanup to set
*this_cache to NULL in case of exception in order to fix PR 14100.
https://sourceware.org/ml/gdb-patches/2012-08/msg00075.html

This patch removes that clear_pointer_cleanup, and catch all exception in
the caller of unwinder->sniffer.  In case of exception, reset *this_case.

gdb:

2017-08-11  Yao Qi  <yao.qi@linaro.org>

	* dwarf2-frame.c (clear_pointer_cleanup): Remove.
	(dwarf2_frame_cache): Remove reset_cache_cleanup.
	(dwarf2_frame_cache):
	* frame-unwind.c (frame_unwind_try_unwinder): Catch
	RETURN_MASK_ALL and set *this_case to NULL.
	* frame-unwind.h: Update comments.
2017-08-11 09:30:02 +01:00
Yao Qi 1c90d9f022 Class-fy dwarf2_frame_state_reg_info
This patch adds dwarf2_frame_state_reg_info ctor, dtor, copy ctor,
assignment operator, and move assignment.  This patch also adds unit test
to execute_cfa_program to cover the changes.

gdb:

2017-08-11  Yao Qi  <yao.qi@linaro.org>

	* dwarf2-frame.c (dwarf2_frame_state_alloc_regs): Remove.
	(dwarf2_frame_state_copy_regs): Remove.
	(dwarf2_frame_state_free_regs): Remove.
	(dwarf2_frame_state::~dwarf2_frame_state): Remove.
	(dwarf2_restore_rule): Call method .alloc_regs instead of
	dwarf2_frame_state_alloc_regs.
	(execute_cfa_program): Likewise.  Call dwarf2_frame_state_reg_info
	constructor.  Call std::move.
	(dwarf2_fetch_cfa_info): Don't call dwarf2_frame_state_copy_regs.
	(dwarf2_frame_cache): Likewise.

	[GDB_SELF_TEST]: Include selftest.h and
	selftest-arch.h.
	[GDB_SELF_TEST] (execute_cfa_program_test): New function.
	(_initialize_dwarf2_frame) [GDB_SELF_TEST]: Register
	execute_cfa_program_test.

	* dwarf2-frame.h (dwarf2_frame_state_reg_info): Add ctor, dtor,
	copy ctor, assignment operator, move assignment.
	<alloc_regs>: New method.
	<swap>: New method.
	(struct dwarf2_frame_state): Delete dtor.
	(dwarf2_frame_state_alloc_regs): Remove declaration.
	* sparc-tdep.c (sparc_execute_dwarf_cfa_vendor_op): Don't call
	dwarf2_frame_state_alloc_regs, use .alloc_regs instead.
2017-08-11 09:30:02 +01:00
Yao Qi afe37d6be5 Class-fy dwarf2_frame_state
This patch adds ctor and dtor to dwarf2_frame_state, so that we can
remove one cleanup "old_chain".

gdb:

2017-08-11  Yao Qi  <yao.qi@linaro.org>

	* dwarf2-frame.c (dwarf2_frame_state_free): Remove.
	(dwarf2_frame_state::dwarf2_frame_state): New.
	(dwarf2_frame_state::~dwarf2_frame_state): New.
	(dwarf2_fetch_cfa_info): Update.
	(dwarf2_frame_cache): Remove old_chain.  Change 'fs' to an object
	rather than a pointer.  Update code.
	* dwarf2-frame.h (struct dwarf2_frame_state): Declare ctor and
	dtor.
	<data_align, code_align, retaddr_column>: Change them to const.
	<armcc_cfa_offsets_sf, armcc_cfa_offsets_reversed>: Change them
	to bool.
2017-08-11 09:30:02 +01:00
Yao Qi b348037fd8 Move dwarf2_frame_state_reg.exp_len to union .loc
dwarf2_frame_state_reg.exp_len is only used together with .loc.exp, so
it makes more sense to exp_len to the union as well.

gdb:

2017-08-11  Yao Qi  <yao.qi@linaro.org>

	* dwarf2-frame.h (struct dwarf2_frame_state_reg) <exp_len>: Remove.
	<loc.exp>: New field.
	* dwarf2-frame.c (execute_cfa_program): Update.
	(dwarf2_frame_prev_register): Update.
2017-08-11 09:30:02 +01:00
Pedro Alves e7c9de2678 Allow gdb::unique_xmalloc_ptr<T[]>
Currently, if you try to use the array version of
gdb::unique_xmalloc_ptr (i.e., std::unique_ptr) in order to have
access to operator[], like:

  gdb::unique_xmalloc_ptr<char[]> buf ((char *) xmalloc (10));
  return buf[0];

then the build fails, like:

  /usr/include/c++/5.3.1/bits/unique_ptr.h: In instantiation of ‘std::unique_ptr<_Tp [], _Dp>::~unique_ptr() [with _Tp = char; _Dp = gdb::xfree_deleter<char []>]’:
  main.c:30:61:   required from here
  /usr/include/c++/5.3.1/bits/unique_ptr.h:484:17: error: no match for call to ‘(std::unique_ptr<char [], gdb::xfree_deleter<char []> >::deleter_type {aka gdb::xfree_deleter<char []>}) (char*&)’
      get_deleter()(__ptr);
		   ^
  In file included from src/gdb/common/common-defs.h:92:0,
		   from src/gdb/defs.h:28,
		   from src/gdb/main.c:20:
  src/gdb/common/gdb_unique_ptr.h:34:8: note: candidate: void gdb::xfree_deleter<T>::operator()(T*) const [with T = char []]
     void operator() (T *ptr) const { xfree (ptr); }
	  ^
  src/gdb/common/gdb_unique_ptr.h:34:8: note:   no known conversion for argument 1 from ‘char*’ to ‘char (*)[]’
  Makefile:1911: recipe for target 'main.o' failed
  make: *** [main.o] Error 1

The problem is that we're missing an xfree_deleter specialization for
arrays.

gdb/ChangeLog:
2017-08-10  Pedro Alves  <palves@redhat.com>

	* common/gdb_unique_ptr.h (xfree_deleter<T[]>): Define.
2017-08-10 14:18:02 +01:00
John Baldwin e8c6b620f7 Replace home-grown linked-lists in FreeBSD's native target with STL lists.
FreeBSD's native target uses linked-lists to keep track of pending fork
events and fake vfork done events.  Replace the first list with std::list
and the second with std::forward_list.

gdb/ChangeLog:

	* fbsd-nat.c (struct fbsd_fork_info): Remove.
	(fbsd_pending_children): Use std::list.
	(fbsd_remember_child): Likewise.
	(fbsd_is_child_pending): Likewise.
	(fbsd_pending_vfork_done): Use std::forward_list.
	(fbsd_add_vfork_done): Likewise.
	(fbsd_is_vfork_done_pending): Likewise.
	(fbsd_next_vfork_done): Likewise.
2017-08-09 15:24:46 -07:00
John Baldwin e4a26669b9 Replace remaining cleanups in fbsd-nat.c.
- Use a custom deleter with std::unique_ptr to free() memory returned
  by kinfo_getvmmap().
- Use std::string with string_printf() to generate the pathname of the
  procfs 'map' file.
- Use gdb::byte_vector to manage the dynamic buffer for
  TARGET_OBJECT_AUXV and the dynamically allocated array of LWP IDs.

gdb/ChangeLog:

	* fbsd-nat.c [HAVE_KINFO_GETVMMAP] (struct free_deleter): New.
	(fbsd_find_memory_regions): Use free_deleter with std::unique_ptr.
	[!HAVE_KINFO_GETVMMAP] (fbsd_find_memory_regions): Use std::string
	for `mapfilename'.
	(fbsd_xfer_partial): Use gdb::byte_vector.
	(fbsd_add_threads): Likewise.
2017-08-09 15:24:46 -07:00
John Baldwin 142311d325 Fix compile in the !HAVE_KINFO_GETVMMAP case.
gdb/ChangeLog:

	* fbsd-nat.c: [!HAVE_KINFO_GETVMMAP]: Include <sys/user.h> and
	"filestuff.h".
	(fbsd_find_memory_regions): Fix `mapfile' initialization.
2017-08-09 15:24:46 -07:00
Simon Marchi 0968fbae6b doc: Fix copy-pasto in Z0 packet documentation
The documentation for the cmd_list field of the Z0 packet refers to its
content as a conditional expression, which seems like a copy-paste error
from the cond_list field.

gdb/doc/ChangeLog:

	* gdb.texinfo (Packets): Fix Z0 cmd_list doc referring to
	conditional expression.
2017-08-09 22:16:14 +02:00
Tom Tromey 42fa2e0e1b C++-ify skip.c
I happened to notice that skiplist_entry, in skip.c, contains a
gdb::optional<compiled_regex> -- but that this object's destructor is
never run.  This can result in a memory leak.

This patch fixes the bug by applying a bit more C++: changing this
code to use new and delete, and std::unique_ptr; and removing cleanups
in the process.

Built and regression tested on x86-64 Fedora 25.

ChangeLog
2017-08-09  Tom Tromey  <tom@tromey.com>

	* skip.c (skiplist_entry): New constructor.
	(skiplist_entry::enabled, skiplist_entry::function_is_regexp)
	(skiplist_entry::file_is_glob): Now bool.
	(skiplist_entry::file, skiplist_entry::function): Now
	std::string.
	(make_skip_entry): Return a unique_ptr.  Use new.
	(free_skiplist_entry, free_skiplist_entry_cleanup)
	(make_free_skiplist_entry_cleanup): Remove.
	(skip_command, skip_disable_command, add_skiplist_entry)
	(skip_form_bytes, compile_skip_regexp, skip_command, skip_info)
	(skip_file_p, skip_gfile_p, skip_function_p, skip_rfunction_p)
	(function_name_is_marked_for_skip): Update.
	(skip_delete_command): Update.  Use delete.
2017-08-09 12:32:06 -06:00
Jiong Wang cd3af38d7b [AArch64] Implement gdbarch_core_read_description
Recommit with missing header files added.

gdb/
	* aarch64-linux-tdep.c: Include "auxv.h" and "elf/common.h".
	(aarch64_linux_core_read_description): New function.
	(aarch64_linux_init_abi): Register gdbarch_core_read_description.
2017-08-09 17:46:06 +01:00
Jiong Wang 0f76ffafce Revert "[AArch64] Implement gdbarch_core_read_description"
This reverts commit b1a6c1cea3.
2017-08-09 15:51:56 +01:00
Jiong Wang b1a6c1cea3 [AArch64] Implement gdbarch_core_read_description
Currently, AArch64 only have one target description which is tdesc_aarch64.  So,
we haven't implemented any target description detection mechanism for core file.

This patch is an initial implementation of core_read_description method.  Future
features can use this to return selected description.

gdb/
	* aarch64-linux-tdep.c (aarch64_linux_core_read_description): New
	function.
	(aarch64_linux_init_abi): Register gdbarch_core_read_description.
2017-08-09 15:37:20 +01:00
Pedro Alves 29592bde87 Make cp_comp_to_string return a gdb::unique_xmalloc_ptr<char>
To help avoid issues like the one fixed by e88e8651cf ("Fix memory
leak in cp-support.c").

gdb/ChangeLog:
2017-08-09  Pedro Alves  <palves@redhat.com>

	* cp-name-parser.y (cp_comp_to_string): Return a
	gdb::unique_xmalloc_ptr<char>.
	* cp-support.c (replace_typedefs_qualified_name)
	(replace_typedefs): Adjust to use gdb::unique_xmalloc_ptr<char>.
	(cp_canonicalize_string_full): Use op= instead of explicit
	convertion.
	(cp_class_name_from_physname, method_name_from_physname)
	(cp_func_name, cp_remove_params): Adjust to use
	gdb::unique_xmalloc_ptr<char>.
	* cp-support.h (cp_comp_to_string): Return a
	gdb::unique_xmalloc_ptr<char>.
	* python/py-type.c (typy_lookup_type): Adjust to use
	gdb::unique_xmalloc_ptr<char>.
2017-08-09 15:04:32 +01:00
H.J. Lu b33404388e gdb: Fix build failure with GCC 7
Fix:

/export/gnu/import/git/sources/binutils-gdb/gdb/dwarf2read.c: In function ‘const char* dwarf2_string_attr(die_info*, unsigned int, dwarf2_cu*)’:
/export/gnu/import/git/sources/binutils-gdb/gdb/dwarf2read.c:17626:39: error: enum constant in boolean context [-Werror=int-in-bool-context]
    || attr->form == DW_FORM_string || DW_FORM_GNU_str_index

	* dwarf2read.c (dwarf2_string_attr): Fix a typo.
2017-08-09 05:01:55 -07:00
Yao Qi e88e8651cf Fix memory leak in cp-support.c
The return value of cp_comp_to_string was never freed, creating a
sizable memory leak detectable with valgrind.

==21225== 8 bytes in 1 blocks are definitely lost in loss record 4,599 of 10,949^M
==21225==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M
==21225==    by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M
==21225==    by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M
==21225==    by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M
==21225==    by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M
==21225==    by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M
==21225==    by 0x53E1D4: cp_canonicalize_string_full[abi:cxx11](char const*, char const* (*)(type*, void*), void*) (cp-support.c:530)^M
==21225==    by 0x53E360: cp_canonicalize_string_no_typedefs[abi:cxx11](char const*) (cp-support.c:548)^M
==21225==    by 0x5D51D2: find_linespec_symbols(linespec_state*, VEC_symtab_ptr*, char const*, VEC_symbolp**, VEC_bound_minimal_symbol_d**) (linespec.c:4030)^M
==21225==    by 0x5D6CF6: linespec_parse_basic (linespec.c:1907)

==21279== 32 bytes in 1 blocks are definitely lost in loss record 6,066 of 10,947^M
==21279==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M
==21279==    by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M
==21279==    by 0x76CB31: d_growable_string_resize (cp-demangle.c:3963)^M
==21279==    by 0x76CB31: d_growable_string_init (cp-demangle.c:3942)^M
==21279==    by 0x76CB31: cplus_demangle_print (cp-demangle.c:4308)^M
==21279==    by 0x4C9535: cp_comp_to_string(demangle_component*, int) (cp-name-parser.y:1972)^M
==21279==    by 0x53EF14: cp_canonicalize_string[abi:cxx11](char const*) (cp-support.c:569)^M
==21279==    by 0x561B75: dwarf2_canonicalize_name(char const*, dwarf2_cu*, obstack*) [clone .isra.210] (dwarf2read.c:20159)

This patch fixes the leak.  It is a regression by 2f408ecb.

gdb:

2017-08-09  Alex Lindsay  <alexlindsay239@gmail.com>
	    Yao Qi  <yao.qi@linaro.org>

	* cp-support.c (cp_canonicalize_string_full): Use
	gdb::unique_xmalloc_ptr<char>.
	(cp_canonicalize_string): Likewise.
2017-08-09 12:39:16 +01:00
Yao Qi f5a29eb0a6 Clean up x86 non-linux GDBserver target descriptions
In GDBserver, only tdesc_i386 and tdesc_amd64 are used.  There is no point
of generating these *.dat files (which are used to generate *.c files during
GDBserver build.).

gdb:

2017-08-09  Yao Qi  <yao.qi@linaro.org>

	* features/Makefile (WHICH): Remove i386/ non-linux stuff.
	* regformats/i386/amd64-avx-avx512.dat: Remove.
	* regformats/i386/amd64-avx-mpx-avx512-pku.dat: Remove.
	* regformats/i386/amd64-avx-mpx.dat:Remove.
	* regformats/i386/amd64-avx.dat: Remove.
	* regformats/i386/amd64-mpx.dat: Remove.
	* regformats/i386/i386-avx-avx512.dat: Remove.
	* regformats/i386/i386-avx-mpx-avx512-pku.dat: Remove.
	* regformats/i386/i386-avx-mpx.dat: Remove.
	* regformats/i386/i386-mmx.dat: Remove.
	* regformats/i386/i386-mpx.dat: Remove.

gdb/gdbserver:

2017-08-09  Yao Qi  <yao.qi@linaro.org>

	* configure.srv (srv_i386_regobj): Remove i386-avx.o,
	i386-avx-avx512.o, i386-avx-mpx-avx512-pku.o, i386-mpx.o,
	i386-avx-mpx.o and i386-mmx.o.
	(srv_amd64_regobj): Remove amd64-avx.o, amd64-avx-avx512.o,
	amd64-avx-mpx-avx512-pku.o, amd64-mpx.o and amd64-avx-mpx.o.
	(srv_i386_xmlfiles): Remove i386/i386-avx.xml,
	i386/i386-avx-avx512.xml, i386/i386-avx-mpx-avx512-pku.xml,
	i386/i386-mpx.xml, i386/i386-avx-mpx.xml and i386/i386-mmx.xml.
	(srv_amd64_xmlfile):i386/amd64-avx.xml, i386/amd64-avx-avx512.xml,
	i386/amd64-avx-mpx-avx512-pku.xml, i386/amd64-mpx.xml,
	i386/amd64-avx-mpx.xml.
2017-08-09 12:29:21 +01:00
Yao Qi 57757c2f09 Remove x32 non-linux target descriptions
x32 non-linux target descriptions are not used in GDB or GDBserver.  This
patch removes them.

gdb:

2017-08-09  Yao Qi  <yao.qi@linaro.org>

	* amd64-tdep.h (tdesc_x32): Remove the declaration.
	* amd64-tdep.c: Don't include features/i386/x32*.c.
	(_initialize_amd64_tdep): Don't call initialize_tdesc_x32*
	functions.
	* features/Makefile (WHICH): Remove i386/x32, i386/x32-avx,
	and i386/x32-avx-avx512.
	(XMLTOC): Remove i386/x32-avx.xml, i386/x32-avx-avx512.xml,
	and i386/x32.xml.
	* features/i386/x32-avx-avx512.c: Removed.
	* features/i386/x32-avx-avx512.xml: Removed.
	* features/i386/x32-avx.c: Removed.
	* features/i386/x32-avx.xml: Removed.
	* features/i386/x32.c: Removed.
	* features/i386/x32.xml: Removed.
	* regformats/i386/x32-avx-avx512.dat: Removed.
	* regformats/i386/x32-avx.dat: Removed.
	* regformats/i386/x32.dat: Removed.

gdb/gdbserver:

2017-08-09  Yao Qi  <yao.qi@linaro.org>

	* configure.srv (srv_amd64_regobj): Remove x32.o, x32-avx.o
	and x32-avx-avx512.o.
	(srv_amd64_xmlfiles): Remove i386/x32.xml, i386/x32-avx.xml
	i386/x32-avx-avx512.xml.
2017-08-09 12:28:59 +01:00
Simon Marchi 7b005726f9 Add missing PR mention in ChangeLog
I noticed that the patch pushed previously had an open bug about it, so
add a reference to it.
2017-08-07 18:27:29 +02:00
Maciej W. Rozycki ba7b109b29 PR breakpoints/21886: mem-break: Fix breakpoint insertion location
Fix a commit cd6c3b4ffc ("New gdbarch methods breakpoint_kind_from_pc
and sw_breakpoint_from_kind") regression and restore the use of
`->placed_address' rather than `->reqstd_address' as the location for a
memory breakpoint to be inserted at.  Previously
`gdbarch_breakpoint_from_pc' was used that made that adjustment in
`default_memory_insert_breakpoint' from the preinitialized value,
however with the said commit that call is gone, so the passed
`->placed_address' has to be used for the initialization.

The regression manifests itself as the inability to debug any MIPS/Linux
compressed ISA dynamic executable as GDB corrupts the dynamic loader
with one of its implicit breakpoints, causing the program to crash, as
seen for example with the `mips-linux-gnu' target, o32 ABI, MIPS16 code,
and the gdb.base/advance.exp test case:

(gdb) continue
Continuing.

Program received signal SIGBUS, Bus error.
_dl_debug_initialize (ldbase=0, ns=0) at dl-debug.c:51
51	    r = &_r_debug;
(gdb) FAIL: gdb.base/advance.exp: Can't run to main

	gdb/
	PR breakpoints/21886
	* mem-break.c (default_memory_insert_breakpoint): Use
	`->placed_address' rather than `->reqstd_address' for the
	breakpoint location.
2017-08-07 17:02:04 +01:00
Maciej W. Rozycki e347efc38b GDB/opcodes: Remove arch/mach/endian disassembler assertions
Fix `set architecture' and `set endian' command disassembly regressions
from commit 39503f8242 ("Delegate opcodes to select disassembler in
GDB"), and commit 003ca0fd22 ("Refactor disassembler selection"), as
well as a MIPS compressed ISA disassembly target regression from commit
6394c60699 ("Don't use print_insn_XXX in GDB"), which caused assertion
failures to trigger.

For example with the `mips-linux-gnu' target we get:

$ cat main.c
int
main (void)
{
  return 0;
}
$ gcc -mips32r2 -O2 main.c -o main
$ gcc -mips16 -mips32r2 -O2 main.c -o main16
$ gdb
GNU gdb (GDB) 8.0.50.20170731-git
[...]
(gdb) file main
Reading symbols from main...done.
(gdb) show architecture
The target architecture is set automatically (currently mips:isa32r2)
(gdb) show endian
The target endianness is set automatically (currently big endian)
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400500 <+0>:	jr	ra
   0x00400504 <+4>:	move	v0,zero
End of assembler dump.
(gdb) set architecture mips:isa64r2
The target architecture is assumed to be mips:isa64r2
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400500 <+0>:
.../gdb/arch-utils.c:979: internal-error: int default_print_insn(bfd_vma, disassemble_info*): Assertion `info->mach == bfd_get_mach (exec_bfd)' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) n
[...]
Command aborted.
(gdb) set architecture auto
The target architecture is set automatically (currently mips:isa32r2)
(gdb) set endian little
The target is assumed to be little endian
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400500 <+0>:
.../gdb/arch-utils.c:978: internal-error: int default_print_insn(bfd_vma, disassemble_info*): Assertion `info->endian == (bfd_big_endian (exec_bfd) ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE)' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) n
[...]
Command aborted.
(gdb) set endian auto
The target endianness is set automatically (currently big endian)
(gdb) set architecture i386
The target architecture is assumed to be i386
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400500 <+0>:
.../gdb/arch-utils.c:976: internal-error: int default_print_insn(bfd_vma, disassemble_info*): Assertion `info->arch == bfd_get_arch (exec_bfd)' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) n
[...]
Command aborted.
(gdb) set architecture auto
The target architecture is set automatically (currently mips:isa32r2)
(gdb) file main16
Load new symbol table from "main16"? (y or n) y
Reading symbols from main16...done.
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400501 <+0>:
.../gdb/arch-utils.c:979: internal-error: int default_print_insn(bfd_vma, disassemble_info*): Assertion `info->mach == bfd_get_mach (exec_bfd)' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) n
Command aborted.
(gdb)

Remove the assertions then, restoring previous semantics:

(gdb) file main
Reading symbols from main...done.
(gdb) set architecture mips:isa64r2
The target architecture is assumed to be mips:isa64r2
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400500 <+0>:	jr	ra
   0x00400504 <+4>:	move	v0,zero
End of assembler dump.
(gdb) set endian little
The target is assumed to be little endian
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400500 <+0>:	j	0x3800c
   0x00400504 <+4>:	addiu	s0,t0,0
End of assembler dump.
(gdb) set architecture i386
The target architecture is assumed to be i386
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400500 <+0>:	add    %eax,%esp
   0x00400502 <+2>:	add    %cl,(%eax)
   0x00400504 <+4>:	add    %al,(%eax)
   0x00400506 <+6>:	adc    %ah,0x0
End of assembler dump.
(gdb) set architecture auto
The target architecture is set automatically (currently mips:isa32r2)
(gdb) set endian auto
The target endianness is set automatically (currently big endian)
(gdb) file main16
Load new symbol table from "main16"? (y or n) y
Reading symbols from main16...done.
(gdb) disassemble main
Dump of assembler code for function main:
   0x00400501 <+0>:	jr	ra
   0x00400503 <+2>:	li	v0,0
End of assembler dump.
(gdb)

	gdb/
	* arch-utils.c (default_print_insn): Remove arch/mach/endian
	assertions.

	opcodes/
	* disassemble.c (disassembler): Remove arch/mach/endian
	assertions.
2017-08-07 15:53:54 +01:00
Maciej W. Rozycki 0dba2a6c09 gdbarch: Use an anonymous union for target data in `gdbarch_info'
As an update to commit ede5f15146 ("gdbarch.h: Change
gdbarch_info::tdep_info's type to void *") replace the definition of the
`tdep_info' member in `struct gdbarch_info' with an anonymous union,
comprising the original member, with its type reverted to `struct
gdbarch_tdep_info *', a `tdesc_data' member of a `struct tdesc_arch_data
*' type and an `id' member of an `int *' type.  Remove now unnecessary
casts throughout use places then, making code easier to read an less
prone to errors, which may happen with casting.

	gdb/
	* gdbarch.sh (gdbarch_info): Replace the `tdep_info' member with
	a union of `tdep_info', `tdesc_data' and `id'.
	* aarch64-tdep.c (aarch64_gdbarch_init): Use `info.tdesc_data'
	rather than `info.tdep_info'.
	* amd64-linux-tdep.c (amd64_linux_init_abi): Likewise.
	* i386-linux-tdep.c (i386_linux_init_abi): Likewise.
	* i386-tdep.c (i386_gdbarch_init): Likewise.
	* mips-linux-tdep.c (mips_linux_init_abi): Likewise.
	* mips-tdep.c (mips_gdbarch_init): Likewise.
	* nds32-tdep.c (nds32_gdbarch_init): Likewise.
	* rs6000-tdep.c (rs6000_gdbarch_init): Likewise.
	* ppc-linux-tdep.c (ppu2spu_sniffer): Use `info.id' rather than
	`info.tdep_info'.
	(ppc_linux_init_abi): Use `info.tdesc_data' rather than
	`info.tdep_info'.
	* sparc-tdep.c (sparc32_gdbarch_init): Likewise.
	* spu-multiarch.c (spu_gdbarch): Use `info.id' rather than
	`info.tdep_info'.
	* spu-tdep.c (spu_gdbarch_init): Likewise.
	* gdbarch.h: Regenerate.
2017-08-07 15:53:54 +01:00
Leszek Swirski 16eb6b2db4 Fix dwarf2_string_attr for -gsplit-dwarf
The dwarf2_string_attr did not allow DW_FORM_GNU_str_index as a form for
string types. This manifested as null strings in the namespace_name
lookup (replaced with "(anonymous namespace)") when debugging
Fission-compiled code.

gdb/ChangeLog:

	* dwarf2read.c (dwarf2_string_attr): Allow DW_FORM_GNU_strp_alt.
2017-08-07 16:40:46 +02:00
Simon Marchi 74cbb09e74 remote-sim.c: Fix arg variables conflicts
The recent change introducing gdb_argv introduced some build failures in
remote-sim.c.

  /home/emaisin/src/binutils-gdb/gdb/remote-sim.c: In function 'void gdbsim_load(target_ops*, const char*, int)':
  /home/emaisin/src/binutils-gdb/gdb/remote-sim.c:573:22: error: conflicting declaration 'gdb_argv argv'
     gdb_argv argv (args);
                        ^
  /home/emaisin/src/binutils-gdb/gdb/remote-sim.c:565:10: note: previous declaration as 'char** argv'
     char **argv;
            ^~~~
  /home/emaisin/src/binutils-gdb/gdb/remote-sim.c: In function 'void gdbsim_open(const char*, int)':
  /home/emaisin/src/binutils-gdb/gdb/remote-sim.c:730:25: error: declaration of 'gdb_argv args' shadows a parameter
     gdb_argv args (arg_buf);

In gdbsim_load, the new gdb_argv object conflicts with old char **argv
variable.  I think the old variable should be removed.

In gdbsim_open, the new gdb_argv object conflicts with the args
parameter.  This patch renames it to argv.

Built-tested for a mips host.

gdb/ChangeLog:

	* remote-sim.c (gdbsim_load): Remove char **argv local variable.
	(gdbsim_open): Rename gdb_argv args object to argv.
2017-08-07 12:13:00 +02:00
Tom Tromey ee0c32930c Use gdb::unique_xmalloc_ptr when calling tilde_expand
This patch changes most sites calling tilde_expand to use
gdb::unique_xmalloc_ptr, rather than a cleanup.  It also changes
scan_expression_with_cleanup to return a unique pointer, because the
patch was already touching code in that area.

Regression tested on the buildbot.

ChangeLog
2017-08-05  Tom Tromey  <tom@tromey.com>

	* compile/compile-object-load.c (compile_object_load): Use
	gdb::unique_xmalloc_ptr.
	* cli/cli-dump.c (scan_filename): Rename from
	scan_filename_with_cleanup.  Change return type.
	(scan_expression): Rename from scan_expression_with_cleanup.
	Change return type.
	(dump_memory_to_file, dump_value_to_file, restore_command):
	Use gdb::unique_xmalloc_ptr.  Update.
	* cli/cli-cmds.c (find_and_open_script): Use
	gdb::unique_xmalloc_ptr.
	* tracefile-tfile.c (tfile_open): Use gdb::unique_xmalloc_ptr.
	* symmisc.c (maintenance_print_symbols)
	(maintenance_print_msymbols): Use gdb::unique_xmalloc_ptr.
	* symfile.c (symfile_bfd_open, generic_load)
	(add_symbol_file_command, remove_symbol_file_command): Use
	gdb::unique_xmalloc_ptr.
	* source.c (openp): Use gdb::unique_xmalloc_ptr.
	* psymtab.c (maintenance_print_psymbols): Use
	gdb::unique_xmalloc_ptr.
	* corelow.c (core_open): Use gdb::unique_xmalloc_ptr.
	* breakpoint.c (save_breakpoints): Use gdb::unique_xmalloc_ptr.
	* solib.c (solib_map_sections): Use gdb::unique_xmalloc_ptr.
	(reload_shared_libraries_1): Likewise.
2017-08-05 15:52:49 -06:00
Tom Tromey fdffd6f411 Fix Rust test suite for 1.20 beta
I ran the gdb.rust tests against Rust 1.20 (beta) and saw a few
failures.  The failures all came because a particular item moved to a
different module.  Since the particular choice of module name isn't
important here, I simply widened the allowable results.

Tested locally against rustc 1.19, 1.20, and 1.21.

testsuite/ChangeLog
2017-08-05  Tom Tromey  <tom@tromey.com>

	* gdb.rust/simple.exp: Allow String to appear in a different
	namespace.
2017-08-05 15:38:32 -06:00
Tom Tromey 3232fabd2d Remove cleanups from Rust parser
This removes the few remaining cleanups in the Rust language code.
The main difficulty here was that the earlier code allocated VEC heads
on an obstack.  The new code instead introduces an object that
allocates and maintains the storage for whatever vectors are needed
during the parse.

Regression tested on the buildbot.

ChangeLog
2017-08-05  Tom Tromey  <tom@tromey.com>

	* rust-exp.y (rust_op_ptr, set_field): Remove typedefs.
	(rust_op_vector, rust_set_vector): New typedefs.
	(current_parser): New global.
	(work_obstack): Change to pointer type.  Update all users.
	(rust_ast, pstate): Remove globals.
	(struct rust_parser): New.
	(%union) <params, field_inits>: Change type.
	(start, tuple_expr, unit_expr, struct_expr_list, literal)
	(field_expr, expr_list, maybe_expr_list, type_list): Update.
	(ast_call_ish, ast_path, ast_function_type, ast_tuple_type)
	(convert_params_to_types, convert_params_to_expression): Change
	type of "params".
	(ast_string): Change type of "fields".
	(rust_parse): Make a rust_parser.  Remove cleanups.
	(rust_lex_tests): Make and install an auto_obstack.
2017-08-05 11:14:06 -06:00
Yao Qi f02fd7745d Unbreak GDBserver build for x32
When I verify my target description changes, I build GDB and GDBserver for
x32, but it failed.

/../../binutils-gdb/gdb/gdbserver/linux-amd64-ipa.c
../../../binutils-gdb/gdb/gdbserver/linux-amd64-ipa.c: In function ‘const target_desc* get_ipa_tdesc(int)’:
../../../binutils-gdb/gdb/gdbserver/linux-amd64-ipa.c:184:10: error: ‘X86_TDESC_AVX512’ was not declared in this scope
     case X86_TDESC_AVX512:
          ^
../../../binutils-gdb/gdb/gdbserver/linux-amd64-ipa.c:185:14: error: ‘tdesc_x32_avx512_linux’ was not declared in this scope
       return tdesc_x32_avx512_linux;
              ^
../../../binutils-gdb/gdb/gdbserver/linux-amd64-ipa.c: In function ‘void initialize_low_tracepoint()’:
../../../binutils-gdb/gdb/gdbserver/linux-amd64-ipa.c:282:36: error: ‘init_registers_x32_avx512_linux’ was not declared in this scope
   init_registers_x32_avx512_linux ();
                                    ^

ipa_x32_linux_regobj use to be there, but removed by
22049425ce by mistake.

gdb/gdbserver:

2017-08-04  Yao Qi  <yao.qi@linaro.org>

	* configure.srv (ipa_x32_linux_regobj): New.
	* linux-amd64-ipa.c (get_ipa_tdesc): Use X86_TDESC_AVX_AVX512
	instead of X86_TDESC_AVX512.
	(initialize_low_tracepoint): Call
	init_registers_x32_avx_avx512_linux.
2017-08-04 16:06:01 +01:00
Yao Qi 91975afd35 Add namespace std to nullptr_t
This patch fixes the build failure for target i686-w64-mingw32,

In file included from ../../binutils-gdb/gdb/defs.h:786:0,
                 from ../../binutils-gdb/gdb/gdb.c:19:
../../binutils-gdb/gdb/utils.h:188:20: error: ‘nullptr_t’ has not been declared
   bool operator!= (nullptr_t)
                    ^
../../binutils-gdb/gdb/utils.h:193:20: error: ‘nullptr_t’ has not been declared
   bool operator== (nullptr_t)
                    ^

gdb:

2017-08-04  Yao Qi  <yao.qi@linaro.org>

	* utils.h (gdb_argv): Add namespace std for nullptr_t.
2017-08-04 14:27:58 +01:00
Ruslan Kabatsayev 2331fa3af5 Add myself as a write-after-approval GDB maintainer. 2017-08-03 22:23:22 +03:00
Tom Tromey 744e4fe1db Remove make_cleanup_freeargv and gdb_buildargv
After the previous patches in this series, make_cleanup_freeargv and
gdb_buildargv are now unused and can be removed.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* utils.c (make_cleanup_freeargv, do_freeargv, gdb_buildargv):
	Remove.
	* utils.h (make_cleanup_freeargv, gdb_buildargv): Remove.
2017-08-03 07:59:10 -06:00
Tom Tromey 1c034b67a0 Use gdb_argv in Python
This changes one spot in the Python code to use gdb_argv.  This
removes the last cleanup from the Python layer.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* python/py-param.c (compute_enum_values): Use gdb_argv.
2017-08-03 07:59:09 -06:00
Tom Tromey 773a1edcd1 Introduce gdb_argv, a class wrapper for buildargv
This introduces gdb_argv, a class wrapping an "argv" pointer; that is,
a pointer to a NULL-terminated array of char*, where both the array
and each non-NULL element in the array are xmalloc'd.

This patch then changes most users of gdb_buildargv to use gdb_argv
instead.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* utils.h (struct gdb_argv_deleter): New.
	(gdb_argv): New class.
	* utils.c (gdb_argv::reset): New method.
	* tracepoint.c (delete_trace_variable_command): Use gdb_argv.
	* tracefile.c (tsave_command): Use gdb_argv.
	* top.c (new_ui_command): Use gdb_argv.
	* symmisc.c (maintenance_print_symbols)
	(maintenance_print_msymbols, maintenance_expand_symtabs): Use gdb_argv.
	* symfile.c (symbol_file_command, generic_load)
	(remove_symbol_file_command): Use gdb_argv.
	* stack.c (backtrace_command): Use gdb_argv.
	* source.c (add_path, show_substitute_path_command)
	(unset_substitute_path_command, set_substitute_path_command):
	Use gdb_argv.
	* skip.c (skip_command): Use gdb_argv.  Use gdb_buildargv.
	* ser-mingw.c (pipe_windows_open): Use gdb_argv.
	* remote.c (extended_remote_run, remote_put_command)
	(remote_get_command, remote_delete_command): Use gdb_argv.
	* remote-sim.c (gdbsim_load, gdbsim_create_inferior)
	(gdbsim_open): Use gdb_argv.
	* python/py-cmd.c (gdbpy_string_to_argv): Use gdb_argv.
	* psymtab.c (maintenance_print_psymbols): Use gdb_argv.
	* procfs.c (procfs_info_proc): Use gdb_argv.
	* interps.c (interpreter_exec_cmd): Use gdb_argv.
	* infrun.c (handle_command): Use gdb_argv.
	* inferior.c (add_inferior_command, clone_inferior_command):
	Use gdb_argv.
	* guile/scm-string.c (gdbscm_string_to_argv): Use gdb_argv.
	* exec.c (exec_file_command): Use gdb_argv.
	* cli/cli-cmds.c (alias_command): Use gdb_argv.
	* compile/compile.c (build_argc_argv): Use gdb_argv.
2017-08-03 07:59:08 -06:00
Tom Tromey 0d50bde32b Remove a cleanup in Python
This removes cleanups from gdbpy_decode_line, in favor of a use of
unique_xmalloc_ptr.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* python/python.c (gdbpy_decode_line): Use unique_xmalloc_ptr.
2017-08-03 07:59:07 -06:00
Tom Tromey 7f968c899f Avoid some manual memory management in Python
This changes a few places in the Python code to avoid manual memory
management, in favor of letting std::string do the work.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* python/python.c (compute_python_string): Return std::string.
	(gdbpy_eval_from_control_command): Update.
	(do_start_initialization): Use std::string.
	* python/py-varobj.c (py_varobj_iter_next): Use string_printf, not
	xstrprintf.
	* python/py-breakpoint.c (local_setattro): Use string_printf, not
	xstrprintf.
2017-08-03 07:59:07 -06:00
Tom Tromey 3c9ebddd93 Replace do_restore_instream_cleanup with scoped_restore
This changes the users of do_restore_instream_cleanup to use a
scoped_restore instead.  This patch is broken out because it warrants
some additional attention: in particular it's unclear to me whether
current_ui can change in the body of these functions -- but if it can,
then the cleanup would have modified a different UI's instream member.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* top.h (do_restore_instream_cleanup): Remove.
	* top.c (do_restore_instream_cleanup): Remove.
	(read_command_file): Use scoped_restore.
	* cli/cli-script.c (execute_user_command): Use scoped_restore.
2017-08-03 07:59:06 -06:00
Tom Tromey b51b225eb9 Use a scoped_restore for command_nest_depth
This changes a couple of places to use a scoped_restore when
manipulating command_nest_depth.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* cli/cli-script.c (execute_user_command)
	(execute_control_command): Use scoped_restore.
2017-08-03 07:59:05 -06:00
Tom Tromey ac991630ca Remove user_call_depth
This changes execute_user_command to remove user_call_depth, using the
size of user_args_stack instead.  This avoids a cleanup.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* cli/cli-script.c (do_restore_user_call_depth): Remove.
	(execute_user_command): Remove user_call_depth; use
	user_args_stack's size instead.
2017-08-03 07:59:04 -06:00
Tom Tromey 898e0c8e87 Remove in_user_command
While working on the next patch in this series, I found that the
global in_user_command is not used.  This patch removes it.  (I didn't
think to check Insight until submitting this series; and it's not very
convenient to do so, so if someone has it checked out and could look
at it, that would be nice.)

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* top.h (in_user_command): Remove.
	* top.c (in_user_command): Remove.
	* cli/cli-script.c (do_restore_user_call_depth)
	(execute_user_command): Update.
2017-08-03 07:59:03 -06:00
Tom Tromey 26fcd5d757 Use containers to avoid cleanups
This patch introduces the use of various containers -- std::vector,
std::string, or gdb::byte_vector -- in several spots in gdb that were
using xmalloc and a cleanup.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* valops.c (search_struct_method): Use gdb::byte_vector.
	* valarith.c (value_concat): Use std::vector.
	* target.c (memory_xfer_partial): Use gdb::byte_vector.
	(simple_search_memory): Likewise.
	* printcmd.c (find_string_backward): Use gdb::byte_vector.
	* mi/mi-main.c (mi_cmd_data_write_memory): Use gdb::byte_vector.
	* gcore.c (gcore_copy_callback): Use gdb::byte_vector.
	* elfread.c (elf_rel_plt_read): Use std::string.
	* cp-valprint.c (cp_print_value): Use gdb::byte_vector.
	* cli/cli-dump.c (restore_section_callback): Use
	gdb::byte_vector.
2017-08-03 07:59:02 -06:00
Tom Tromey 7c218e6c9c Use unique_xmalloc_ptr in jit.c
This removes some cleanups from jit.c by using unique_xmalloc_ptr
instead.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* jit.c (jit_reader_load_command): Use unique_xmalloc_ptr.
2017-08-03 07:59:01 -06:00
Tom Tromey 31b68d4ad7 Replace tui_restore_gdbout with scoped_restore
This patch replaces tui_restore_gdbout (a cleaup function) with a use
of scoped_restore.  This one is broken out into its own patch because
it might slightly change the behavior of gdb: it saves and restores
pagination_enabled, whereas the tui_restore_gdbout unconditionally set
pagination_enabled to 1; and I think this warrants closer review.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* tui/tui-regs.c (tui_restore_gdbout): Remove.
	(tui_register_format): Use scoped_restore.
2017-08-03 07:59:01 -06:00
Tom Tromey 2ec845e758 More uses of scoped_restore
There were a few more places in gdb that could easily use
scoped_restore, replacing some cleanups.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* reverse.c (exec_direction_default): Remove.
	(exec_reverse_once): Use scoped_restore.
	* remote.c (restore_remote_timeout): Remove.
	(remote_flash_erase, remote_flash_write, remote_flash_done)
	(readchar, remote_serial_write): Use scoped_restore.
	* cli/cli-script.c (struct source_cleanup_lines_args)
	(source_cleanup_lines): Remove.
	(script_from_file): Use scoped_restore.
	* cli/cli-cmds.c (source_verbose_cleanup): Remove.
	(source_command): Use scoped_restore.
2017-08-03 07:59:00 -06:00
Tom Tromey b3bc84537b Remove make_cleanup_free_so
make_cleanup_free_so is used in a single spot.  This patch introduces
a unique pointer wrapper for struct so_list, and changes this spot to
use it.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* utils.h (make_cleanup_free_so): Remove.
	* utils.c (do_free_so, make_cleanup_free_so): Remove.
	* solist.h (struct so_deleter): New.
	(so_list_up): New typedef.
	* solib-svr4.c (svr4_read_so_list): Use so_list_up.
2017-08-03 07:58:59 -06:00
Tom Tromey e3ad2841b1 Remove make_cleanup_restore_current_language
This patch replaces make_cleanup_restore_current_language with an RAII
class that saves the current language, and restores it when the object
is destroyed.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* utils.h (make_cleanup_restore_current_language): Remove.
	* utils.c (do_restore_current_language)
	(make_cleanup_restore_current_language): Remove.
	* parse.c (parse_exp_in_context_1)
	(parse_expression_with_language): Use
	scoped_restore_current_language.
	* mi/mi-main.c (mi_cmd_execute): Use
	scoped_restore_current_language.
	* language.h (scoped_restore_current_language): New class.
2017-08-03 07:58:58 -06:00
Tom Tromey b80cf83844 Remove an unlink cleanup
compile/compile.c had its own cleanup to unlink a file.  This patch
replaces this cleanup with gdb::unlinker.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* compile/compile.c (cleanup_unlink_file): Remove.
	(compile_to_object): Use gdb::unlinker.
	(eval_compile_command): Likewise.
2017-08-03 07:58:57 -06:00
Tom Tromey fad0444a57 Remove make_cleanup_fclose
After the preceding patches, make_cleanup_fclose is no longer used, so
remove it.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* utils.h (make_cleanup_fclose): Remove.
	* utils.c (do_fclose_cleanup, make_cleanup_fclose): Remove.
2017-08-03 07:58:56 -06:00
Tom Tromey 6e7bc05c53 Change open_terminal_stream to return a gdb_file_up
This changes open_terminal_stream to return a gdb_file_up, eliminating
another use of make_cleanup_fclose.  Arguably perhaps new_ui should
take ownership of the files using a move, but there is at least one
spot where this isn't appropriate (or at least not currently done), so
I elected to use a more minimal approach.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* top.c (open_terminal_stream): Return gdb_file_up.
	(new_ui_command): Update.
2017-08-03 07:58:55 -06:00
Tom Tromey 4a45905b82 Use gdb_file_up in source.c
This changes some functions in source.c to use gdb_file_up.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* source.c (print_source_lines_base, forward_search_command)
	(reverse_search_command): Use gdb_file_up.
2017-08-03 07:58:54 -06:00
Tom Tromey 7cd06d6e89 Use gdb_file_up in fbsd-nat.c
This updates fbsd-nat.c to use gdb_file_up.  This removes a use of a
cleanup, and helps remove make_cleanup_fclose in a later patch.

I have no way to test this patch.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* fbsd-nat.c (fbsd_find_memory_regions): Update.
2017-08-03 07:58:54 -06:00
Tom Tromey ed1669453b Change return type of find_and_open_script
This changes find_and_open_script to return a
gdb::optional<open_script>, where open_script is a new type
encapsulating the two return values.  The new type helps avoid
cleanups in the callers.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* cli/cli-cmds.c (find_and_open_script): Change return type.
	Remove "streamp" and "full_path" parameters.
	(source_script_with_search): Update.
	* auto-load.c (source_script_file): Update.
	* cli/cli-cmds.h (find_and_open_script): Change type.
	(open_script): New struct.
2017-08-03 07:58:53 -06:00
Tom Tromey d419f42dd3 Introduce and use gdb_file_up
This introduces gdb_file_up, a unique pointer holding a FILE*, and
then changes some code in gdb to use it.  In particular
gdb_fopen_cloexec now returns a gdb_file_up.  This allow removing some
cleanups.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* xml-support.c (xml_fetch_content_from_file): Update.
	* ui-file.c (stdio_file::open): Update.
	* tracefile-tfile.c (tfile_start): Update.
	* remote.c (remote_file_put, remote_file_get): Update.
	* nat/linux-procfs.c (linux_proc_get_int)
	(linux_proc_pid_get_state, linux_proc_tid_get_name): Update.
	* nat/linux-osdata.c (linux_common_core_of_thread): Update.
	(command_from_pid, commandline_from_pid, linux_xfer_osdata_cpus)
	(print_sockets, linux_xfer_osdata_shm, linux_xfer_osdata_sem)
	(linux_xfer_osdata_msg, linux_xfer_osdata_modules): Update.
	* nat/linux-btrace.c (linux_determine_kernel_start): Update.
	* linux-nat.c (linux_proc_pending_signals): Update.
	* dwarf2read.c (write_psymtabs_to_index): Use gdb_file_up.
	(file_closer): Remove.
	* compile/compile.c (compile_to_object): Update.
	* common/filestuff.h (struct gdb_file_deleter): New.
	(gdb_file_up): New typedef.
	(gdb_fopen_cloexec): Change return type.
	* common/filestuff.c (gdb_fopen_cloexec): Return gdb_file_up.
	* cli/cli-dump.c (fopen_with_cleanup): Remove.
	(dump_binary_file, restore_binary_file): Update.
	* auto-load.c (auto_load_objfile_script_1): Update.
2017-08-03 07:58:52 -06:00
Tom Tromey 4a2b031d54 Introduce and use ui_out_emit_table
This introduces ui_out_emit_table, similar to the other existing
ui_out RAII classes, and then uses it in a number of places.  This
replaces some cleanups.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

	* tracepoint.c (tvariables_info_1): Use ui_out_emit_table.
	(info_static_tracepoint_markers_command): Likewise.
	* solib.c (info_sharedlibrary_command): Use ui_out_emit_table.
	* skip.c (skip_info): Use ui_out_emit_table.
	* progspace.c (print_program_space): Use ui_out_emit_table.
	* osdata.c (info_osdata): Use ui_out_emit_table.
	* mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions): Use
	ui_out_emit_table.
	* linux-thread-db.c (info_auto_load_libthread_db): Use
	ui_out_emit_table.
	* inferior.c (print_inferior): Use ui_out_emit_table.
	* gdb_bfd.c (maintenance_info_bfds): Use ui_out_emit_table.
	* breakpoint.c (breakpoint_1): Use ui_out_emit_table.
	* auto-load.c (auto_load_info_scripts): Use ui_out_emit_table.
	* ada-tasks.c (print_ada_task_info): Use ui_out_emit_table.
	* ui-out.h (class ui_out_emit_table): New.
2017-08-03 07:58:51 -06:00
Maciej W. Rozycki a4f320fd1b MIPS: Factor out FPU type naming in `gdbarch' debug
Replace chains of conditional expressions used in target-dependent MIPS
`gdbarch' debug output to get a textual name of the FPU type with calls
to a helper decoder function, improving code readability.  No functional
change.

	gdb/
	* mips-tdep.c (mips_fpu_type_str): New function.
	(mips_dump_tdep): Call it.
2017-08-02 16:40:16 +01:00
Maciej W. Rozycki a2f1f30853 MIPS: Consistently use MIPS_FPU_TYPE for `gdbarch' member
Complement commit 74ed0bb414 ("Replace current_gdbarch in *mips*"),
<https://sourceware.org/ml/gdb-patches/2008-06/msg00490.html>, and
consistently use the MIPS_FPU_TYPE macro to access the `->mips_fpu_type'
target-dependent `gdbarch' member.  No functional change.

	gdb/
	* mips-tdep.c (mips_gdbarch_init): Use MIPS_FPU_TYPE to access
	`->mips_fpu_type'.
2017-08-01 19:32:25 +01:00
Xavier Roirand 7e5ed83b22 Update ChangeLog (missed that in my previous commit)
gdb/
        * ChangeLog: Add previous commit entry

Change-Id: Ic4f07cca66126e73340f032f19a2d5029bf0d40a
2017-07-31 14:37:33 +02:00
Simon Marchi 791fb3d7a5 Fix documentation about rot agent expression bytecode
The rot agent expression bytecode rotates the three items on the top of
the stack.  It is not clear which way the rotation is.  However, the
documentation currently shows this as the effect of the instructions:

   a b c => c b a

which doesn't make sense, since the value b doesn't move.  The two
valid possibilities I see are

  a b c => b c a
  a b c => c a b

depending on which way you rotate.

When looking at the gdbserver code, the top of the stack becomes the
third item, and the next-to-top item becomes the top.  So the second
form would be the right one, since in this notation the top of the stack
is the rightmost element:

  a b c => c a b

I adjusted the symbolic description and added a bit of text to make it
more obvious.

gdb/doc/ChangeLog:

	* agentexpr.texi (rot): Fix symbolic description, improve
	textual description.
2017-07-31 11:26:50 +02:00
Xavier Roirand 4bbd4ef219 darwin: handle recent version of dyld
gdb/
        * solib-darwin.c (DYLD_VERSION_MAX): Increase value.

Change-Id: I45da25f46b3e452d44993b122a994c818d00020b
2017-07-31 11:10:14 +02:00
Xavier Roirand 4c9dc81149 Add myself as a write-after-approval GDB maintainer.
gdb/Changelog:

2017-07-27  Xavier Roirand  <roirand@adacore.com>

        * MAINTAINERS (Write After Approval): Add Xavier Roirand.

Change-Id: Iee1dae7597da8f2c8c3098c14649ff400a81a388
2017-07-27 16:06:55 +02:00
Yao Qi 27d41eac62 Add "maint check xml-descriptions" to test builtin xml target descriptions
Now, GDB is able to dynamically create i386-linux target descriptions
from features, instead of using pre-generated target descriptions.  These
pre-generated target descriptions are no longer used by GDB (note that
they are still used by GDBserver).

This patch add a new maint command "maint check xml-descriptions" to test
dynamically generated tdesc are identical to these generated from xml files.

gdb:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* cli/cli-cmds.c (maintenancechecklist): New variable.
	* gdbcmd.h (maintenancechecklist): Declare it.
	* i386-linux-tdep.c (_initialize_i386_linux_tdep) [GDB_SELF_TEST]:
	Call i386_linux_read_description with different masks.
	* maint.c (maintenance_check_command): New function.
	(_initialize_maint_cmds): Call add_prefix_cmd.
	* target-descriptions.c (tdesc_reg): override operator != and ==.
	(tdesc_type): Likewise.
	(tdesc_feature): Likewise.
	(target_desc): Likewise.
	[GDB_SELF_TEST] (selftests::record_xml_tdesc): New function.
	(maintenance_check_xml_descriptions): New function.
	(_initialize_target_descriptions) Add command "xml-descriptions".
	* target-descriptions.h (selftests::record_xml_tdesc): Declare.

gdb/testsuite:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* gdb.gdb/unittest.exp: Invoke command
	"maintenance check xml-descriptions".

gdb/doc:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* gdb.texinfo (Maintenance Commands): Document command
	"maint check xml-descriptions".
2017-07-26 14:55:31 +01:00
Yao Qi ea03d0d3c3 Lazily and dynamically create i386-linux target descriptions
Instead of using pre-generated target descriptions, this patch
changes GDB to lazily and dynamically create target descriptions
according to the target hardware capability (xcr0 in i386).
This support any combination of target features.

Some reg in target description has "regnum" attribute, so its register
number is got from the attribute value instead from sequential allocation.

  <reg name="xmm0" bitsize="128" type="vec128" regnum="32"/>

when target description is created, it should match the regnum, so this
patch adds a new field m_next_regnum to track it, if attribute number is
greater than the m_next_regnum, print the code to set register number
explicitly.

gdb:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* i386-linux-tdep.c: Don't include features/i386/i386-*linux.c.
	Include features/i386/32bit-*.c.
	(i386_linux_read_description): Generate target description if it
	doesn't exist.
	(_initialize_i386_linux_tdep): Don't call _initialize_tdesc_i386
	functions.
	* features/i386/32bit-linux.c: Re-generated.
	* features/i386/32bit-sse.c: Likewise.
	* target-descriptions.c (print_c_feature::visit): Print code to
	set register number if needed.
	(print_c_feature) <m_next_regnum>: New field.
2017-07-26 14:39:54 +01:00
Yao Qi 25aa13e522 Generate c for feature instead of tdesc
This patch changes Makefile and command "maint print c-files" so
that GDB can print c files for features instead target description.
Previously, we feed GDB a target description xml file, which generate
c files including multiple features.

With this patch, in Makefile, we wrap each feature xml file, and
create a temp target description which include only one feature.
Then, adjust the target description printer for them, and print
a c function for each given feature, so that we can use these
c functions later to create target description in a flexible way.

gdb:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* features/Makefile (CFILES): Rename with TDESC_CFILES.
	(FEATURE_XMLFILES): New.
	(FEATURE_CFILES): New.
	New rules.
	(clean-cfiles): Remove generated c files.
	* features/i386/32bit-avx.c: Generated.
 	* features/i386/32bit-avx512.c: Generated.
 	* features/i386/32bit-core.c: Generated.
 	* features/i386/32bit-linux.c: Generated.
 	* features/i386/32bit-mpx.c: Generated.
 	* features/i386/32bit-pkeys.c: Generated.
 	* features/i386/32bit-sse.c: Generated.
 	* target-descriptions.c: Include algorithm.
	(tdesc_element_visitor): Add method visit_end.
	(print_c_tdesc): Implement visit_end.
	(print_c_tdesc:: m_filename_after_features): Move it to
	protected.
	(print_c_feature): New class.
	(maint_print_c_tdesc_cmd): Use print_c_feature if XML file
	name starts with "i386/32bit-".
2017-07-26 14:24:08 +01:00
Yao Qi 6eb1e6a8c1 Use visitor pattern for "maint print c-tdesc"
Target description can be modeled as a tree, the target description
is the root node, features are children nodes, registers and types are
grand-children nodes.  So command "maint print c-tdesc" in effect
traverse/visit each node, and print them in c.  This can be
implemented by visitor pattern, this is the first reason.  Secondly,
I want to this command prints c files in a different way for some
specific xml files, but still print c files the same way for the rest
of xml files.  Third, I even want to print xml files from target
descriptions, so that GDBserver can use it to reply GDB's query
qXfer:features:read:target.xml.

gdb:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* target-descriptions.c (tdesc_element_visitor): New class.
	(tdesc_element): New class.
	(tdesc_reg): Inherit from tdesc_element.
	(tdesc_reg::accept): New function.
	(tdesc_type): Inherit from tdesc_element.
	(tdesc_type::accept): New function.
	(tdesc_feature): Inherit from tdesc_element.
	(tdesc_feature::accept): New function.
	(target_desc): Inherit from tdesc_element.
	(target_desc::target_desc): New.
	(target_desc::~target_desc): New.
	(target_desc::accept): New.
	(allocate_target_description): Use new.
	(free_target_description): Use delete.
	(print_c_tdesc): New class.
	(maint_print_c_tdesc_cmd): Adjust.

	* features/aarch64.c: Re-generated.
	* features/arc-arcompact.c: Re-generated.
	* features/arc-v2.c: Re-generated.
	* features/arm/arm-with-iwmmxt.c: Re-generated.
	* features/arm/arm-with-m.c: Re-generated.
	* features/arm/arm-with-m-fpa-layout.c: Re-generated.
	* features/arm/arm-with-m-vfp-d16.c: Re-generated.
	* features/arm/arm-with-neon.c: Re-generated.
	* features/arm/arm-with-vfpv2.c: Re-generated.
	* features/arm/arm-with-vfpv3.c: Re-generated.
	* features/i386/amd64-avx-avx512.c: Re-generated.
	* features/i386/amd64-avx-avx512-linux.c: Re-generated.
	* features/i386/amd64-avx.c: Re-generated.
	* features/i386/amd64-avx-linux.c: Re-generated.
	* features/i386/amd64-avx-mpx-avx512-pku.c: Re-generated.
	* features/i386/amd64-avx-mpx-avx512-pku-linux.c: Re-generated.
	* features/i386/amd64-avx-mpx.c: Re-generated.
	* features/i386/amd64-avx-mpx-linux.c: Re-generated.
	* features/i386/amd64.c: Re-generated.
	* features/i386/amd64-linux.c: Re-generated.
	* features/i386/amd64-mpx.c: Re-generated.
	* features/i386/amd64-mpx-linux.c: Re-generated.
	* features/i386/i386-avx-avx512.c: Re-generated.
	* features/i386/i386-avx-avx512-linux.c: Re-generated.
	* features/i386/i386-avx.c: Re-generated.
	* features/i386/i386-avx-linux.c: Re-generated.
	* features/i386/i386-avx-mpx-avx512-pku.c: Re-generated.
	* features/i386/i386-avx-mpx-avx512-pku-linux.c: Re-generated.
	* features/i386/i386-avx-mpx.c: Re-generated.
	* features/i386/i386-avx-mpx-linux.c: Re-generated.
	* features/i386/i386.c: Re-generated.
	* features/i386/i386-linux.c: Re-generated.
	* features/i386/i386-mmx.c: Re-generated.
	* features/i386/i386-mmx-linux.c: Re-generated.
	* features/i386/i386-mpx.c: Re-generated.
	* features/i386/i386-mpx-linux.c: Re-generated.
	* features/i386/x32-avx-avx512.c: Re-generated.
	* features/i386/x32-avx-avx512-linux.c: Re-generated.
	* features/i386/x32-avx.c: Re-generated.
	* features/i386/x32-avx-linux.c: Re-generated.
	* features/i386/x32.c: Re-generated.
	* features/i386/x32-linux.c: Re-generated.
	* features/microblaze.c: Re-generated.
	* features/microblaze-with-stack-protect.c: Re-generated.
	* features/mips64-dsp-linux.c: Re-generated.
	* features/mips64-linux.c: Re-generated.
	* features/mips-dsp-linux.c: Re-generated.
	* features/mips-linux.c: Re-generated.
	* features/nds32.c: Re-generated.
	* features/nios2.c: Re-generated.
	* features/nios2-linux.c: Re-generated.
	* features/rs6000/powerpc-32.c: Re-generated.
	* features/rs6000/powerpc-32l.c: Re-generated.
	* features/rs6000/powerpc-403.c: Re-generated.
	* features/rs6000/powerpc-403gc.c : Re-generated.
	* features/rs6000/powerpc-405.c: Re-generated.
	* features/rs6000/powerpc-505.c: Re-generated.
	* features/rs6000/powerpc-601.c: Re-generated.
	* features/rs6000/powerpc-602.c: Re-generated.
	* features/rs6000/powerpc-603.c: Re-generated.
	* features/rs6000/powerpc-604.c: Re-generated.
	* features/rs6000/powerpc-64.c: Re-generated.
	* features/rs6000/powerpc-64l.c: Re-generated.
	* features/rs6000/powerpc-7400.c: Re-generated.
	* features/rs6000/powerpc-750.c: Re-generated.
	* features/rs6000/powerpc-860.c: Re-generated.
	* features/rs6000/powerpc-altivec32.c: Re-generated.
	* features/rs6000/powerpc-altivec32l.c: Re-generated.
	* features/rs6000/powerpc-altivec64.c: Re-generated.
	* features/rs6000/powerpc-altivec64l.c: Re-generated.
	* features/rs6000/powerpc-cell32l.c: Re-generated.
	* features/rs6000/powerpc-cell64l.c: Re-generated.
	* features/rs6000/powerpc-e500.c: Re-generated.
	* features/rs6000/powerpc-e500l.c: Re-generated.
	* features/rs6000/powerpc-isa205-32l.c: Re-generated.
	* features/rs6000/powerpc-isa205-64l.c: Re-generated.
	* features/rs6000/powerpc-isa205-altivec32l.c: Re-generated.
	* features/rs6000/powerpc-isa205-altivec64l.c: Re-generated.
	* features/rs6000/powerpc-isa205-vsx32l.c: Re-generated.
	* features/rs6000/powerpc-isa205-vsx64l.c: Re-generated.
	* features/rs6000/powerpc-vsx32.c: Re-generated.
	* features/rs6000/powerpc-vsx32l.c: Re-generated.
	* features/rs6000/powerpc-vsx64.c: Re-generated.
	* features/rs6000/powerpc-vsx64l.c: Re-generated.
	* features/rs6000/rs6000.c: Re-generated.
	* features/s390-linux32.c: Re-generated.
	* features/s390-linux32v1.c: Re-generated.
	* features/s390-linux32v2.c: Re-generated.
	* features/s390-linux64.c: Re-generated.
	* features/s390-linux64v1.c: Re-generated.
	* features/s390-linux64v2.c: Re-generated.
	* features/s390-te-linux64.c: Re-generated.
	* features/s390-tevx-linux64.c: Re-generated.
	* features/s390-vx-linux64.c: Re-generated.
	* features/s390x-linux64.c: Re-generated.
	* features/s390x-linux64v1.c: Re-generated.
	* features/s390x-linux64v2.c: Re-generated.
	* features/s390x-te-linux64.c: Re-generated.
	* features/s390x-tevx-linux64.c: Re-generated.
	* features/s390x-vx-linux64.c: Re-generated.
	* features/sparc/sparc32-solaris.c: Re-generated.
	* features/sparc/sparc64-solaris.c: Re-generated.
	* features/tic6x-c62x.c: Re-generated.
	* features/tic6x-c62x-linux.c: Re-generated.
	* features/tic6x-c64x.c: Re-generated.
	* features/tic6x-c64x-linux.c: Re-generated.
	* features/tic6x-c64xp.c: Re-generated.
	* features/tic6x-c64xp-linux.c: Re-generated.
2017-07-26 12:56:54 +01:00
Yao Qi 35b4818d03 Centralize i386 linux target descriptions
This patch moves all the tdesc_i386*_linux target descriptions to a
function i386_linux_read_description, which returns the right target
description according to xcr0.  This also remove the duplication in
getting target descriptions in corefile and native target.

gdb:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* i386-linux-tdep.c (i386_linux_read_description): New function.
	(i386_linux_core_read_description): Call
	i386_linux_read_description.
	* i386-linux-tdep.h (i386_linux_read_description): Declare.
	(tdesc_i386_linux, tdesc_i386_mmx_linux): Remove declarations.
	(tdesc_i386_avx_linux, tdesc_i386_mpx_linux): Likewise
	(tdesc_i386_avx_mpx_linux, tdesc_i386_avx_avx512_linux): Likewise.
	(tdesc_i386_avx_mpx_avx512_pku_linux): Likewise.
	* x86-linux-nat.c (x86_linux_read_description): Call
	i386_linux_read_description.
2017-07-26 12:36:42 +01:00
Yao Qi 8e2141c6fb Add optional argument to command "maint prints c-tdesc"
Nowadays, we need two steps to print c files for xml target description,
that is, 1) read xml target description in, update the current tdesc,
2) visit the current tdesc, print the c file.  It is unnecessary to
involve in current tdesc, and some validations in each gdbarch are
performed unnecessarily, which will reject some target descriptions if
they are missing some mandatory feature.

This patch adds an optional argument to "maint print c-tdesc", which
is an XML file target description, so that we can combine the two
steps above into one step, and don't have to involve in global current
tdesc.

gdb:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* NEWS: Mention it.
	* features/Makefile (%.c: %.xml): Pass the xml file name to
	command "maint print c-tdesc".
	* target-descriptions.c (maint_print_c_tdesc_cmd): Get file
	name from 'arg'.

gdb/doc:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* gdb.texinfo (Maintenance Commands): Document optional
	argument of "maint print c-tdesc".
2017-07-26 12:03:47 +01:00
Yao Qi b468ff4cbf Class-fy target_desc
This patch adds ctor and dtor in target_desc.

gdb:

2017-07-26  Yao Qi  <yao.qi@linaro.org>

	* target-descriptions.c (target_desc): Add ctor and dtor.  Do
	in-class initialization.
	(tdesc_create_feature): Call new instead of XCNEW.
	(free_target_description): Ue delete.
2017-07-26 10:37:17 +01:00
Simon Marchi 229d26fc9e Add enum for result of fast_tracepoint_collecting
I got confused by the result value of fast_tracepoint_collecting, while
it sounds like it would return true/false (whether the thread is
collecting or not), it actually returns:

  0: not collecting
  1: in the jump pad, before the relocated instruction
  2: in the jump pad, at or after the relocated instruction

To avoid confusion, I think it would be nice to make it return an enum.
If you can help find a shorter but still relavant name, it would be
awesome.  Otherwise, we'll go with that, fast_tpoint_collect_result,
which is at least consistent with the existing
fast_tpoint_collect_status.

gdb/gdbserver/ChangeLog:

	* tracepoint.h (enum class fast_tpoint_collect_result): New
	enumeration.
	(fast_tracepoint_collecting): Change return type to
	fast_tpoint_collect_result.
	* tracepoint.c (fast_tracepoint_collecting): Likewise.
	* linux-low.h: Include tracepoint.h.
	(struct lwp_info) <collecting_fast_tracepoint>: Change type to
	fast_tpoint_collect_result.
	* linux-low.c (handle_tracepoints): Adjust.
	(linux_fast_tracepoint_collecting): Change return type to
	fast_tpoint_collect_result.
	(maybe_move_out_of_jump_pad, linux_wait_for_event_filtered,
	linux_wait_1, stuck_in_jump_pad_callback,
	lwp_signal_can_be_delivered, linux_resume_one_lwp_throw,
	proceed_one_lwp): Adjust to type change.
2017-07-26 10:57:07 +02:00
John Baldwin b9c0e1b40e Fix two NetBSD-specific typos in the configure.nat conversion.
- Add the '-lkvm' library requirement for NetBSD/sparc64.
- Fix spelling of 'nbsdelf' host.

gdb/Changelog:

	* configure.nat: Add "-lkvm" for NetBSD/sparc64 and fix typo.
2017-07-25 09:40:44 -07:00
Yao Qi a04b53379a Make amd64_x32_init_abi and amd64_init_abi argument constant
gdb:

2017-07-25  Yao Qi  <yao.qi@linaro.org>

	* amd64-tdep.c (amd64_init_abi): Make argument default_tdesc
	constant.
	(amd64_x32_init_abi): Likewise.
	* amd64-tdep.h (amd64_init_abi): Update declaration.
	(amd64_x32_init_abi): Likewise.
2017-07-25 15:25:38 +01:00
Yao Qi 46a62268b8 Catch exceptions thrown from gdbarch_skip_prologue
PR 21555 is caused by the exception during the prologue analysis when re-set
a breakpoint.

(gdb) bt
 #0  memory_error_message (err=TARGET_XFER_E_IO, gdbarch=0x153db50, memaddr=93824992233232) at ../../binutils-gdb/gdb/corefile.c:192
 #1  0x00000000005718ed in memory_error (err=TARGET_XFER_E_IO, memaddr=memaddr@entry=93824992233232) at ../../binutils-gdb/gdb/corefile.c:220
 #2  0x00000000005719d6 in read_memory_object (object=object@entry=TARGET_OBJECT_CODE_MEMORY, memaddr=93824992233232, memaddr@entry=1, myaddr=myaddr@entry=0x7fffffffd0a0 "P\333S\001", len=len@entry=1) at ../../binutils-gdb/gdb/corefile.c:259
 #3  0x0000000000571c6e in read_code (len=1, myaddr=0x7fffffffd0a0 "P\333S\001", memaddr=<optimized out>) at ../../binutils-gdb/gdb/corefile.c:287
 #4  read_code_unsigned_integer (memaddr=memaddr@entry=93824992233232, len=len@entry=1, byte_order=byte_order@entry=BFD_ENDIAN_LITTLE)                          at ../../binutils-gdb/gdb/corefile.c:362
 #5  0x000000000041d4a0 in amd64_analyze_prologue (gdbarch=gdbarch@entry=0x153db50, pc=pc@entry=93824992233232, current_pc=current_pc@entry=18446744073709551615, cache=cache@entry=0x7fffffffd1e0) at ../../binutils-gdb/gdb/amd64-tdep.c:2310
 #6  0x000000000041e404 in amd64_skip_prologue (gdbarch=0x153db50, start_pc=93824992233232) at ../../binutils-gdb/gdb/amd64-tdep.c:2459
 #7  0x000000000067bfb0 in skip_prologue_sal (sal=sal@entry=0x7fffffffd4e0) at ../../binutils-gdb/gdb/symtab.c:3628
 #8  0x000000000067c4d8 in find_function_start_sal (sym=sym@entry=0x1549960, funfirstline=1) at ../../binutils-gdb/gdb/symtab.c:3501
 #9  0x000000000060999d in symbol_to_sal (result=result@entry=0x7fffffffd5f0, funfirstline=<optimized out>, sym=sym@entry=0x1549960) at ../../binutils-gdb/gdb/linespec.c:3860
....
 #16 0x000000000054b733 in location_to_sals (b=b@entry=0x15792d0, location=0x157c230, search_pspace=search_pspace@entry=0x1148120, found=found@entry=0x7fffffffdc64) at ../../binutils-gdb/gdb/breakpoint.c:14211
 #17 0x000000000054c1f5 in breakpoint_re_set_default (b=0x15792d0) at ../../binutils-gdb/gdb/breakpoint.c:14301
 #18 0x00000000005412a9 in breakpoint_re_set_one (bint=bint@entry=0x15792d0) at ../../binutils-gdb/gdb/breakpoint.c:14412

This problem can be fixed by

 - either each prologue analyzer doesn't throw exception,
 - or catch the exception thrown from gdbarch_skip_prologue,

I choose the latter because the former needs to fix *every* prologue
analyzer to not throw exception.

This error can be reproduced by changing reread.exp.  The test reread.exp
has already test that breakpoint can be reset correctly after the
executable is re-read.  This patch extends this test by compiling test c
file with and without -fPIE.

(gdb) run ^M
The program being debugged has been started already.^M
Start it from the beginning? (y or n) y^M
x86_64/gdb/testsuite/outputs/gdb.base/reread/reread' has changed; re-reading symbols.
Error in re-setting breakpoint 1: Cannot access memory at address 0x555555554790^M
Error in re-setting breakpoint 2: Cannot access memory at address 0x555555554790^M
Starting program: /scratch/yao/gdb/build-git/x86_64/gdb/testsuite/outputs/gdb.base/reread/reread ^M
This is foo^M
[Inferior 1 (process 27720) exited normally]^M
(gdb) FAIL: gdb.base/reread.exp: opts= "-fPIE" "ldflags=-pie" : run to foo() second time (the program exited)

This patch doesn't re-indent the code, to keep the patch simple.

gdb:

2017-07-25  Yao Qi  <yao.qi@linaro.org>

	PR gdb/21555
	* arch-utils.c (gdbarch_skip_prologue_noexcept): New function.
	* arch-utils.h (gdbarch_skip_prologue_noexcept): Declare.
	* infrun.c: Include arch-utils.h
	(handle_step_into_function): Call gdbarch_skip_prologue_noexcept.
	(handle_step_into_function_backward): Likewise.
	* symtab.c (skip_prologue_sal): Likewise.

gdb/testsuite:

2017-07-25  Yao Qi  <yao.qi@linaro.org>

	PR gdb/21555
	* gdb.base/reread.exp: Wrap the whole test with two kinds of
	compilation flags, with -fPIE and without -fPIE.
2017-07-25 11:38:50 +01:00
Yao Qi 02ad7fc29f [ARM] Access FPSCR on vfpv2
GDB can fetch or store FPSCR on vfpv3, which has 32 VFP registers, but
fail to do so on vfpv2, which has 16 VFP registers.  GDB code is incorrect
for vfpv2,

       else if (tdep->vfp_register_count > 0
 	       && regno >= ARM_D0_REGNUM
	       && regno <= ARM_D0_REGNUM + tdep->vfp_register_count)

while FPSCR register number is defined as ARM_D0_REGNUM + 32.

  ARM_D0_REGNUM,		/* VFP double-precision registers.  */
  ARM_D31_REGNUM = ARM_D0_REGNUM + 31,
  ARM_FPSCR_REGNUM,

The code above uses "<=" rather than "<", in order to put FPSCR in the
range, but it is only correct when tdep->vfp_register_count is 32.  On
vpfv2, it is 16, and FPSCR is out of the range, so fetch_vfp_regs or
store_vfp_regs are not called.

gdb:

2017-07-25  Yao Qi  <yao.qi@linaro.org>

	PR tdep/21717
	* arm-linux-nat.c (arm_linux_fetch_inferior_registers): Update
	condition for FPSCR.
	(arm_linux_store_inferior_registers): Likewise.
2017-07-25 10:05:58 +01:00
Andreas Arnez 031ed05dd2 s390-vregs.exp: Fix Tcl error after non-zero-pad patch
s390-vregs.exp yields a Tcl error:

  ERROR: can't read "i": no such variable
      while executing
  "expr $a_high * ($i + 1) * $a_high "
      (procedure "hex128" line 2)
      invoked from within
  "hex128 $a_high $a_low $b_high $b_low"
  ...

This is a regression, caused by commit 30a254669b -- "Don't always
zero pad in print_*_chars".  That patch introduced a new procedure
"hex128" for formatting a 128-bit value as hex, but it accidentally moved
the calculation of the 128-bit value into that new procedure as well
instead of leaving it in the original context.  This is fixed.

gdb/testsuite/ChangeLog:

	* gdb.arch/s390-vregs.exp: Calculate parameters to hex128 in the
	calling context.
	(hex128): Drop erroneous calculation of parameters.
2017-07-24 18:35:30 +02:00
Tom Tromey b6f48cb022 Use std::vector in struct catch_syscall_inferior_data
This changes struct catch_syscall_inferior_data to use a std::vector
rather than a VEC.  It also changes it to be allocated with new and
destroyed with delete.

ChangeLog
2017-07-22  Tom Tromey  <tom@tromey.com>

	* break-catch-syscall.c (struct catch_syscall_inferior_data)
	<syscalls_counts>: Now a std::vector.
	(get_catch_syscall_inferior_data): Use "new".
	(catch_syscall_inferior_data_cleanup): Use "delete".
	(insert_catch_syscall, remove_catch_syscall)
	(clear_syscall_counts): Update.
2017-07-22 16:10:42 -06:00
Tom Tromey e12c9b7a0c Use std::vector in syscall_catchpoint
This changes syscall_catchpoint to use a std::vector rather than a VEC
for "syscalls_to_be_caught".  This simplifies the code a bit.

ChangeLog
2017-07-22  Tom Tromey  <tom@tromey.com>

	* break-catch-syscall.c (syscall_catchpoint)
	<syscalls_to_be_caught>: Now a std::vector<int>
	(~syscall_catchpoint): Remove.
	(insert_catch_syscall, remove_catch_syscall)
	(breakpoint_hit_catch_syscall, print_one_catch_syscall)
	(print_mention_catch_syscall, print_recreate_catch_syscall):
	Update.
	(create_syscall_event_catchpoint): Change type of "filter"
	parameter.
	(catch_syscall_split_args): Return a std::vector.
	(catch_syscall_command_1, catching_syscall_number_1): Update.
2017-07-22 16:10:42 -06:00
Tom Tromey 4fa8aeac19 C++-ify break-catch-throw
This changes exception_catchpoint's "exception_rx' member to be a
std::string, and updating the users.

ChangeLog
2017-07-22  Tom Tromey  <tom@tromey.com>

	* break-catch-throw.c (struct exception_catchpoint)
	<exception_rx>: Now a std::string.
	(~exception_catchpoint): Remove.
	(print_one_detail_exception_catchpoint): Update.
	(handle_gnu_v3_exceptions): Change type of except_rx.
	(extract_exception_regexp): Return a std::string.
	(catch_exception_command_1): Update.
2017-07-22 16:10:41 -06:00
Tom Tromey f746a15444 C++-ify break-catch-sig
This changes signal_catchpoint to be more of a C++ class, using
std::vector and updating the users.

ChangeLog
2017-07-22  Tom Tromey  <tom@tromey.com>

	* break-catch-sig.c (gdb_signal_type): Remove typedef.
	(struct signal_catchpoint) <signals_to_be_caught>: Now a
	std::vector.
	<catch_all>: Now a bool.
	(~signal_catchpoint): Remove.
	(signal_catchpoint_insert_location)
	(signal_catchpoint_remove_location)
	(signal_catchpoint_breakpoint_hit, signal_catchpoint_print_one)
	(signal_catchpoint_print_mention)
	(signal_catchpoint_print_recreate)
	(signal_catchpoint_explains_signal): Update.
	(create_signal_catchpoint): Change type of "filter" and
	"catch_all".
	(catch_signal_split_args): Return a std::vector.  Change type of
	"catch_all".
	(catch_signal_command): Update.
2017-07-22 16:10:41 -06:00
Simon Marchi dcd27ddf87 gdb.python/py-unwind: Disable stack protection
[I made some typo fixes but forgot to amend my commit before sending the patch,
 hence this v2.]

I see the following failure on Ubuntu 16.04's gcc 5.4.0:

Running /home/emaisin/src/binutils-gdb/gdb/testsuite/gdb.python/py-unwind.exp ...
FAIL: gdb.python/py-unwind.exp: continue to breakpoint: break backtrace-broken
FAIL: gdb.python/py-unwind.exp: Backtrace restored by unwinder (pattern 1)

The problem is that the test expects a very particular stack layout.
When stack protection is enabled, it adds a canary value which looks
like an additional local variable.  This makes the test complain about
a bad stack layout and fail.

The simple solution is to disable stack protection for that test using
-fno-stack-protector.  I checked older compilers (gcc 4.4, clang 3.5)
and they support that flag, so I don't think it's necessary to probe for
whether the compiler supports it.

Maybe a better solution would be to change the test to make it cope with
different stack layouts (perhaps it could save addresses of stuff in
some global variables which GDB/the unwinder would read).  I'll go with
the simple solution for now though.

gdb/testsuite/ChangeLog:

	* gdb.python/py-unwind.exp: Disable stack protection when
	building test file.
2017-07-22 00:01:03 +02:00
Pedro Alves 47e77640be Make language_def O(1)
Profiling GDB with the rest of series applied, I saw calls to
language_def showing up high in some runs.  The problem is that
language_def is O(N) currently, since walk the languages vector each
time to find the matching language_defn.

IMO, the add_language mechanism is pointless, because "enum language"
implies the core of GDB needs to know about all languages anyway.  So
simply make the languages vector array be an array where each
element's index is the corresponding enum language enumerator.  Note
that "local_language_defn" is gone along the way.  It's just a copy of
"auto", so the new code simply maps one to the other.  One fewer place
to update when we need to change the language vector...

Also, a while ago the output of "set language" was made out of order
as side effect of some other change.  While I was at it, I made them
sorted again.

gdb/ChangeLog:
2017-07-20  Pedro Alves  <palves@redhat.com>

	* ada-lang.c (ada_language_defn): Make extern.
	(_initialize_ada_language): Remove add_language call.
	* c-lang.c (c_language_defn, cplus_language_defn)
	(asm_language_defn, minimal_language_defn): Make extern.
	(_initialize_c_language): Delete.
	* completer.c (compare_cstrings): Delete, moved to utils.h.
	* d-lang.c (d_language_defn): Make extern.
	(_initialize_d_language): Remove add_language calls.
	* defs.h (enum language): Add comment.
	* f-lang.c (f_language_defn): Make extern.
	(_initialize_f_language): Remove add_language call.
	* go-lang.c (go_language_defn): Make extern.
	(_initialize_go_language): Remove add_language call.
	* language.c: Include <algorithm>.
	(languages): Redefine as const array.
	(languages_size, languages_allocsize, DEFAULT_ALLOCSIZE): Delete.
	(set_language_command): Handle "local".  Use for-range loop.
	(set_language): Remove loop.
	(language_enum): Rewrite.
	(language_def, language_str): Remove loops.
	(add_language): Delete.
	(add_set_language_command): New, based on add_languages.
	(skip_language_trampoline): Adjust.
	(local_language_defn): Delete.
	(language_gdbarch_post_init): Adjust.
	(_initialize_language): Remove add_language calls.  Call
	add_set_language_command.
	* language.h (add_language): Delete.
	(auto_language_defn)
	(unknown_language_defn, minimal_language_defn, ada_language_defn)
	(asm_language_defn, c_language_defn, cplus_language_defn)
	(d_language_defn, f_language_defn, go_language_defn)
	(m2_language_defn, objc_language_defn, opencl_language_defn)
	(pascal_language_defn, rust_language_defn): Declare.
	* m2-lang.c (m2_language_defn): Make extern.
	(_initialize_m2_language): Remove add_language call.
	* objc-lang.c (objc_language_defn): Make extern.
	(_initialize_objc_language): Remove add_language call.
	* opencl-lang.c (opencl_language_defn): Make extern.
	(_initialize_opencl_language): Remove add_language call.
	* p-lang.c (pascal_language_defn): Make extern.
	(_initialize_pascal_language): Delete.
	* rust-lang.c (rust_language_defn): Make extern.
	(_initialize_rust_language): Delete.
	* utils.h (compare_cstrings): New static inline function.

gdb/testsuite/ChangeLog:
2017-07-20  Pedro Alves  <palves@redhat.com>

	* gdb.base/default.exp (set language): Adjust expected output.
2017-07-20 18:28:01 +01:00
Pedro Alves edb0c9cb22 get_int_var_value
I noticed that get_int_var_value's parameters could use some
constification.  And then realized that client code would become
simpler by changing the interface to return the success/failure
indication as actual return value, as it allows getting rid of the
local "boolean" variable.

gdb/ChangeLog:
2017-07-20  Pedro Alves  <palves@redhat.com>

	* ada-lang.c (ada_to_fixed_type_1): Adjust.
	(get_var_value): Constify parameters.
	(get_int_var_value): Change prototype.
	(to_fixed_range_type): Adjust.
	* ada-lang.h (get_int_var_value): Change prototype.
2017-07-20 18:12:19 +01:00
Pedro Alves a778f165ad Use SYMBOL_MATCHES_SEARCH_NAME some more
gdb/ChangeLog:
2017-07-20  Pedro Alves  <palves@redhat.com>

	* dwarf2read.c (dw2_lookup_symbol): Use
	SYMBOL_MATCHES_SEARCH_NAME.
	* psymtab.c (psym_lookup_symbol): Use SYMBOL_MATCHES_SEARCH_NAME.
2017-07-20 18:06:13 +01:00
Pedro Alves 42edd901a2 Eliminate block_iter_name_*
This patch gets rid of block_iter_name_* as being unnecessary.  It's
the same as calling block_iter_match_*, and passing strcmp_iw as
comparison routine.

(A later patch will get rid of those new explicit strcmp_iw calls.)

gdb/ChangeLog:
2017-07-20  Pedro Alves  <palves@redhat.com>

	* block.c (block_iter_name_step, block_iter_name_first)
	(block_iter_name_next): Delete.
	(block_lookup_symbol_primary): Adjust to use
	dict_iter_match_first/dict_iter_match_next.
	* block.h (block_iter_name_first, block_iter_name_next): Delete
	declarations.
	(ALL_BLOCK_SYMBOLS_WITH_NAME): Adjust to use
	dict_iter_match_first/dict_iter_match_next.
2017-07-20 18:04:46 +01:00
Pedro Alves cf32529923 Fix cp_find_first_component_aux bug
Valgrind catches an out-of-bounds read here:

 $ gdb ./testsuite/outputs/gdb.cp/method2/method2
 (gdb) start
 [...]
 Temporary breakpoint 1, main (argc=1, argv=0x7fffffffd958) at src/gdb/testsuite/gdb.cp/method2.cc:26
 26        return 0;
 (gdb) b A::operator
 ==26907== Invalid read of size 1
 ==26907==    at 0x75C0AE: cp_find_first_component_aux(char const*, int) (cp-support.c:951)
 ==26907==    by 0x75C084: cp_find_first_component(char const*) (cp-support.c:925)
 ==26907==    by 0x75C3DA: cp_entire_prefix_len(char const*) (cp-support.c:1089)
 ==26907==    by 0x758B16: cp_lookup_symbol_in_namespace(char const*, char const*, block const*, domain_enum_tag, int) (cp-namespace.c:314)
 ==26907==    by 0x75972A: lookup_namespace_scope(language_defn const*, char const*, block const*, domain_enum_tag, char const*, int) (cp-namespace.c:739)
 ==26907==    by 0x7597CB: cp_lookup_symbol_nonlocal(language_defn const*, char const*, block const*, domain_enum_tag) (cp-namespace.c:768)
 ==26907==    by 0x8C1137: lookup_symbol_aux(char const*, block const*, domain_enum_tag, language, field_of_this_result*) (symtab.c:2016)
 ==26907==    by 0x8C098A: lookup_symbol_in_language(char const*, block const*, domain_enum_tag, language, field_of_this_result*) (symtab.c:1824)
 ==26907==    by 0x8C0A04: lookup_symbol(char const*, block const*, domain_enum_tag, field_of_this_result*) (symtab.c:1836)
 ==26907==    by 0x82CBE1: find_label_symbols(linespec_state*, VEC_symbolp*, VEC_symbolp**, char const*) (linespec.c:3390)
 ==26907==    by 0x828FB5: linespec_parse_basic(ls_parser*) (linespec.c:1620)
 ==26907==    by 0x82A78F: parse_linespec(ls_parser*, char const*) (linespec.c:2307)
 ==26907==  Address 0x910f97c is 0 bytes after a block of size 12 alloc'd
 ==26907==    at 0x4C28BF6: malloc (vg_replace_malloc.c:299)
 ==26907==    by 0x74E737: xmalloc (common-utils.c:43)
 ==26907==    by 0x74EAF4: savestring(char const*, unsigned long) (common-utils.c:179)
 ==26907==    by 0x826CEF: copy_token_string(ls_token) (linespec.c:488)
 ==26907==    by 0x828EF6: linespec_parse_basic(ls_parser*) (linespec.c:1599)
 ==26907==    by 0x82A78F: parse_linespec(ls_parser*, char const*) (linespec.c:2307)
 ==26907==    by 0x82AE27: event_location_to_sals(ls_parser*, event_location const*) (linespec.c:2469)
 ==26907==    by 0x82B1CE: decode_line_full(event_location const*, int, program_space*, symtab*, int, linespec_result*, char const*, char const*) (linespec.c:2557)
 ==26907==    by 0x720C8A: parse_breakpoint_sals(event_location const*, linespec_result*) (breakpoint.c:9550)
 ==26907==    by 0x72A2F7: create_sals_from_location_default(event_location const*, linespec_result*, bptype) (breakpoint.c:14484)
 ==26907==    by 0x727F86: bkpt_create_sals_from_location(event_location const*, linespec_result*, bptype) (breakpoint.c:13219)
 ==26907==    by 0x72146D: create_breakpoint(gdbarch*, event_location const*, char*, int, char*, int, int, bptype, int, auto_boolean, breakpoint_ops const*, int, int, int, unsigned int) (breakpoint.c:9759)

Tests exercising this will be added further down the series.

gdb/ChangeLog:
2017-07-20  Pedro Alves  <palves@redhat.com>

	* cp-support.c (cp_find_first_component_aux): Add missing case for
	end of string.
2017-07-20 17:58:17 +01:00
Pedro Alves 62d2a18a2e Make gdb.base/dmsym.exp independent of "set language ada"
This test is using "set language ada" expecting that to cause GDB to
do Ada symbol name matching.  That won't work when GDB uses the
symbol's language to decide which symbol matching algorithm to use,
because the test's symbols are C symbols.

So generalize the test a bit to not rely on Ada name matching rules.

Confirmed that by undoing the original fix the test was written for,
the test still fails.

gdb/testsuite/ChangeLog:
2017-07-20  Pedro Alves  <palves@redhat.com>

	* gdb.base/dmsym.c (pck__foo__bar__minsym): Rename to ...
	(test_minsym): ... this, and make static.
	(get_pck__foo__bar__minsym): Rename to ...
	(get_test_minsym): ... this.
	* gdb.base/dmsym.exp (): Remove "set language ada" call.  Adjust
	symbol names and comments.
	* gdb.base/dmsym_main.c (get_pck__foo__bar__minsym): Rename to ...
	(get_test_minsym): ... this.
	(pck__foo__bar__minsym__2): Rename to ...
	(test_minsym): ... this.
	(main): Adjust.
2017-07-20 17:52:03 +01:00
David Blaikie c5ed057625 Fix Fission (broken by my previous patch)
Turns out somewhere along the refactoring of the multiple-CU support
for Fission I broke the patch before submitting it (& seems to have
broken Fission support generally).

Syncing back to the point at which the patch was committed, the
previous test results on my machine are:

 expected passes: 36137
 unexpected failures: 416

with the previous (broken) patch committed:

 expected passes: 36131
 unexpected failures: 429

With this one line patch applied on top of the broken commit:

 expected passes: 36144
 unexpected failures: 416

(& all other result counts remained the same in all 3 cases)

gdb/ChangeLog:
2017-07-18  David Blaikie  <dblaikie@gmail.com>

	* dwarf2read.c (create_cus_hash_table): Re-add lost initialization
	of dwo_cu's dwo_file.
2017-07-18 16:06:17 +01:00
Yao Qi 27841e762c Remove one line comment
This patch is going to remove a line comment, which was added in this
commit,

commit 55fea07
Author: Jim Kingdon <jkingdon@engr.sgi.com>
Date:   Tue Sep 14 01:08:22 1993 +0000

        * remote.c: Define remote_debug to 0 and #if 0 baud_rate.  Temporary
        hack so this file compiles again.

        * remote-utils.c (gr_multi_scan): Cast return value from alloca.
        (gr_multi_scan): #if 0 never-reached return(-1).

and at that moment, remote_prepare_to_store does updates some global
state,

static void
remote_prepare_to_store ()
{
  /* Make sure the entire registers array is valid.  */
  read_register_bytes (0, (char *)NULL, REGISTER_BYTES);
}

However, now, remote_prepare_to_store doesn't do that at all, and
rsa->sizeof_g_packet is updated in init_remote_state, so the line of
comment is out of date, and this patch removes it.

gdb:

2017-07-18  Yao Qi  <yao.qi@linaro.org>

	* remote.c (store_registers_using_G): Remove one line comment.
2017-07-18 12:57:19 +01:00
Yao Qi cfb7e58b48 Simplify regcache_cpy and remove regcache::cpy_no_passthrough
Nowadays, regcache_cpy is used where src is read-only and dst is not
read-only, so the regcache_cpy can be simplified to handle this case only.
As a result, regcache::cpy_no_passthrough, which is about two read-only
regcache copy, is no longer used, remove it as well.

gdb:

2017-07-18  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (regcache_cpy): Simplify it.
	(regcache::cpy_no_passthrough): Remove it.
	* regcache.h (cpy_no_passthrough): Remove it.
	(regcache_dup, regcache_cpy): Update comments.
2017-07-18 12:46:14 +01:00
Yao Qi c646b4e87f Improve doc about "maint print c-tdesc"
In my patch extending command "maint print c-tdesc"
(https://sourceware.org/ml/gdb-patches/2017-06/msg00286.html), Eli
raised some questions on the existing doc to this command.  It is not
very clear, so this patch improves it.  Eli approved it.

gdb/doc:

2017-07-18  Yao Qi  <yao.qi@linaro.org>

	* gdb.texinfo (Maintenance Commands): Improve the doc to
	command "maint print c-tdesc".
2017-07-18 12:39:22 +01:00
Pedro Alves 386535dd91 Fix GDB builds that include the simulator
The completer rewrite series missed adjusting target sim to the new
completion_tracker interface.

src/gdb/remote-sim.c: In function ‘void _initialize_remote_sim()’:
src/gdb/remote-sim.c:1350:46: error: invalid conversion from ‘VEC_char_ptr* (*)(cmd_list_element*, const char*, const char*)’ to ‘void (*)(cmd_list_element*, completion_tracker&, const char*, const char*)’ [-fpermissive]
   set_cmd_completer (c, sim_command_completer);
                                              ^

This commit fixes it, and also takes care to be exception safe (the
previous code would leak if growing the VEC throws).

Tested manually with a --target=arm-none-eabi build.

gdb/ChangeLog:
2017-07-18  Pedro Alves  <palves@redhat.com>

	* remote-sim.c (sim_command_completer): Adjust to work with a
	completion_tracker instead of a VEC.
2017-07-18 11:38:17 +01:00
Pedro Alves c45ec17c07 A smarter linespec completer
Continuing the theme of the explicit locations patch, this patch gets
rid of the need for quoting function names in linespec TAB completion.
To recap, when you have overloads in your program, and you want to set
a breakpoint in one of them:

 void function(int);  // set breakpoint here.
 void function(long);

 (gdb) b function(i[TAB]
 <all the symbols in the program that start with "i" are uselessly shown...>

This patch gets rid of the need for quoting by switching the linespec
completer to use the custom completion word point mechanism added in
the previous explicit location patch (extending it as needed), to
correctly determine the right completion word point.  In the case
above, we want the completer to figure out that it's completing a
function name that starts with "function(i", and it now does.

We also want the completer to know when it's potentially completing a
source file name, for:

(gdb) break source.[TAB] -> source.c:
(gdb) break source.c:  # Type line number or function name now

And we want it to know to complete label names, which it doesn't today:

(gdb) break function:lab[TAB]

etc., etc.

So what we want is for completion to grok the input string as closely
to how the linespec parser groks it.

With that in mind, the solution suggests itself - make the linespec
completer use the same parsing code as normal linespec parsing.

That's what the patch does.  The old completer is replaced by one that
reuses the actual linespec parser as much as possible.  This (ideally)
eliminate differences between what completion understands and actually
setting breakpoints understands by design.

The completer now offers sensible completion candidates depending on
which component of the linespec is being completed, source filename,
function, line number, expression, and (a new addition), labels.  For
example, when completing the function part, we now show the full name
of the method as completion candidates, instead of showing whatever
comes after what readline considered the word break character:

 (gdb) break klass::method[TAB]
 klass:method1(int)
 klass:method2()

If input is past the function, then we now offer keyword condidates:

  (gdb) b function(int) [TAB]
  if      task    thread

If input is past a keyword, we offer expression completion, which is
different from linespec completion:

  (gdb) b main if 1 + glo[TAB]
  global

(e.g., completes on types, struct data fields, etc.)

As mentioned, this teaches the linespec completer about completing
label symbols too:

  (gdb) b source.c:function:lab[TAB]

A nice convenience is that when completion uniquely matches a source
name, gdb adds the ":" automatically for you:

  (gdb) b filenam[TAB]
  (gdb) b filename.c:  # ':' auto-added, cursor right after it.

It's the little details.  :-)

I worked on this patch in parallel with writing the (big) testcase
added closer to the end of the series, which exercises many many
tricky cases around quoting and whitespace insertion placement.  In
general, I think it now all Just Works.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* completer.c (complete_source_filenames): New function.
	(complete_address_and_linespec_locations): New function.
	(location_completer): Use complete_address_and_linespec_locations.
	(completion_tracker::build_completion_result): Honor the tracker's
	request to suppress append.
	* completer.h (completion_tracker::suppress_append_ws)
	(completion_tracker::set_suppress_append_ws): New methods.
	(completion_tracker::m_suppress_append_ws): New field.
	(complete_source_filenames): New declaration.
	* linespec.c (linespec_complete_what): New.
	(struct ls_parser) <complete_what, completion_word,
	completion_quote_char, completion_quote_end, completion_tracker>:
	New fields.
	(string_find_incomplete_keyword_at_end): New.
	(linespec_lexer_lex_string): Record quote char.  If in completion
	mode, don't throw.
	(linespec_lexer_consume_token): Advance the completion word point.
	(linespec_lexer_peek_token): Save/restore completion info.
	(save_stream_and_consume_token): New.
	(set_completion_after_number): New.
	(linespec_parse_basic): Set what to complete next depending on
	token.  Handle function and label completions specially.
	(parse_linespec): Disable objc shortcut in completion mode.  Set
	what to complete next depending on token type.  Skip keyword if in
	completion mode.
	(complete_linespec_component, linespec_complete): New.
	* linespec.h (linespec_complete): Declare.

gdb/testsuite/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* gdb.base/completion.exp: Adjust expected output.
	* gdb.linespec/ls-errs.exp: Don't send tab characters, now that
	the completer works.
2017-07-17 20:29:37 +01:00
Pedro Alves be966d4207 Linespec lexing and C++ operators
There's some lexing code in linespec that isn't handling C++ operators
correctly.  It's the usual confusion with operator< / operator<<, in
code that wants to skip past template parameters.

The linespec_lexer_lex_string change is necessary otherwise we get
this (with current master):

 (gdb) break 'operator<'
 unmatched quote

The need for the find_toplevel_char change was exposed by the use of
that function in the explicit location completer.  Without the fix,
that completer is not able to "see" past operator< symbols, without
quoting, like:

 (gdb) b -function operator<(int, int) -labe[TAB]    # nothing happens

gdb incorrectly thinks "-labe" is part of the "unclosed" template
parameter list started with "<".

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* linespec.c (linespec_lexer_lex_string, find_toplevel_char):
	Handle 'operator<' / 'operator<<'.
2017-07-17 20:28:12 +01:00
Pedro Alves a245927022 Explicit locations -label completer
We're missing a completer for

  (gdb) break -function func -label [TAB]

This patch adds one.  Tests will be added later in the series.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* completer.c (collect_explicit_location_matches): Handle
	MATCH_LABEL.
	(convert_explicit_location_to_linespec): New, factored out from
	...
	(convert_explicit_location_to_sals): ... this.
	(complete_label): New.
	(linespec_complete_label, find_label_symbols_in_block): New.
	(find_label_symbols): Add completion_mode parameter and adjust to
	call find_label_symbols_in_block.
	* linespec.h (linespec_complete_label): Declare.
2017-07-17 20:24:41 +01:00
Pedro Alves c6756f62e0 Rewrite/enhance explicit locations completer, parse left->right
One of the most annoying (to me) things about GDB's completion is when
you have overloads in your program, and you want to set a breakpoint
in one of them:

 void function(int);  // set breakpoint here.
 void function(long);

 (gdb) b -f func[TAB]
 (gdb) b -f function(       # ok, gdb completed as much as possible.
 (gdb) b -f function([TAB]  # show me the overloads, please.
 <_all_ symbols in the program are shown...>

E.g., when debugging GDB, that'd be:

 (gdb) b -f function([TAB]
 (anonymous namespace)::get_global()::global  pt_insn_get_offset@plt                       scm_new_port_table_entry
 asprintf                                     pt_pkt_alloc_decoder                         scm_new_port_table_entry@plt
 asprintf@plt                                 pt_pkt_alloc_decoder@plt                     scm_out_of_range
 bt_ctf_get_char_array                        pt_pkt_sync_forward                          scm_out_of_range@plt
 bt_ctf_get_char_array@plt                    pt_pkt_sync_forward@plt                      scm_putc
 bt_ctf_get_uint64                            pwrite                                       scm_putc@plt
 bt_ctf_get_uint64@plt                        pwrite@plt                                   scm_reverse_x
 bt_ctf_iter_read_event                       PyErr_Restore                                scm_reverse_x@plt
 bt_ctf_iter_read_event@plt                   PyErr_Restore@plt                            scm_set_port_filename_x
 <snip...>

Now that's a load of completely useless completions.

The reason GDB offers those is that the completer relies on readline
figuring out the completion word point in the input line based on the
language's word break characters, which include "(".  So readline
tells the completer to complete on "", the string that is after '('.
Likewise, if you type "function(i[TAB]" to try to complete to "int",
you're out of luck.  GDB shows you all the symbols in the program that
start with "i"...  This makes sense for the expression completer, as
what you'd want to type is e.g., a global variable, say:

(gdb) print function(i[TAB]

but, it makes no sense when specifying a function name for a
breakpoint location.

To get around that limitation, users need to quote the function name,
like:

 (gdb) b -f 'function([TAB]
 function(int)      function(long)
 (gdb) b 'function(i[TAB]
 (gdb) b 'function(int)' # now completes correctly!

Note that the quoting is only necessary for completion.  Creating the
breakpoint does not require the quoting:

 (gdb) b -f function(int) [RET]
 Breakpoint 1 at ....

This patch removes this limitation.

(
Actually, it's a necessary patch, though not sufficient.  That'll
start working correctly by the end of the series.  With this patch, if try it,
you'll see:

 (gdb) b -f function(i[TAB]
 (gdb) b -f function

i.e., gdb strips everything after the "(".  That's caused by some code
in symtab.c that'll be eliminated further down the series.  These
patches are all unfortunately interrelated, which is also the reason
new tests only appear much later in the series.
But let's ignore that reality for the remainder of the description.
)

So... this patch gets rid of the need for quoting.

It does that by adding a way for a completer to control the exact
completion word point that readline should start the completion
request for, instead of letting readline try to figure it out using
the current language's word break chars array, and often failing.

In the case above, we want the completer to figure out that it's
completing a function name that starts with "function(i".  It now
does.

It took me a while to figure out a way to ask readline to "use this
exact word point", and for a while I feared that it'd be impossible
with current readline (and having to rely on master readline for core
functionality is something I'd like to avoid very much).  Eventually,
after several different attempts, I came up with what is described in
the comment above gdb_custom_word_point_brkchars in the patch.

With this patch, the handle_brkchars phase of the explicit location
completer advances the expected word point as it parses the input line
left to right, until it figures out exactly what we're completing,
instead of expecting readline to break the string using the word break
characters, and then having the completer heuristically fix up a bad
decision by parsing the input string backwards.  This allows correctly
knowning that we're completing a symbol name after -function, complete
functions without quoting, etc.

Later, we'll make use of this same mechanims to implement a proper
linespec completer that avoids need for quoting too.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* ada-lang.c (ada_collect_symbol_completion_matches): Add
	complete_symbol_mode parameter.
	* cli/cli-cmds.c (complete_command): Get the completion result out
	of the handle_brkchars tracker if used a custom word point.
	* completer.c: Include "linespec.h".
	(enum explicit_location_match_type) <MATCH_LINE>: New enumerator.
	(advance_to_expression_complete_word_point): New.
	(completion_tracker::completes_to_completion_word): New.
	(complete_files_symbols): Pass down
	complete_symbol_mode::EXPRESSION.
	(explicit_options, probe_options): New.
	(collect_explicit_location_matches): Complete on the
	explictit_loc->foo instead of word.  Use
	linespec_complete_function.  Handle MATCH_LINE.  Handle offering
	keyword and options completions.
	(backup_text_ptr): Delete.
	(skip_keyword): New.
	(complete_explicit_location): Remove 'word' parameter.  Add
	language, quoted_arg_start and quoted_arg_end parameters.
	Rewrite, parsing left to right.
	(location_completer): Rewrite.
	(location_completer_handle_brkchars): New function.
	(symbol_completer): Pass down complete_symbol_mode::EXPRESSION.
	(enum complete_line_internal_reason): Adjust comments.
	(completion_tracker::discard_completions): New.
	(completer_handle_brkchars_func_for_completer): Handle
	location_completer.
	(gdb_custom_word_point_brkchars)
	(gdb_org_rl_basic_quote_characters): New.
	(gdb_completion_word_break_characters_throw)
	(completion_find_completion_word): Handle trackers that use a
	custom word point.
	(completion_tracker::advance_custom_word_point_by): New.
	(completion_tracker::build_completion_result): Don't rely on
	readline appending the quote char.
	(gdb_rl_attempted_completion_function_throw): Handle trackers that
	use a custom word point.
	(gdb_rl_attempted_completion_function): Restore
	rl_basic_quote_characters.
	* completer.h (class completion_tracker): Extend intro comment.
	(completion_tracker::set_quote_char)
	(completion_tracker::quote_char)
	(completion_tracker::set_use_custom_word_point)
	(completion_tracker::use_custom_word_point)
	(completion_tracker::custom_word_point)
	(completion_tracker::set_custom_word_point)
	(completion_tracker::advance_custom_word_point_by)
	(completion_tracker::completes_to_completion_word)
	(completion_tracker::discard_completions): New methods.
	(completion_tracker::m_quote_char)
	(completion_tracker::m_use_custom_word_point)
	(completion_tracker::m_custom_word_point): New fields.
	(advance_to_expression_complete_word_point): Declare.
	* f-lang.c (f_collect_symbol_completion_matches): Add
	complete_symbol_mode parameter.
	* language.h (struct language_defn)
	<la_collect_symbol_completion_matches>: Add complete_symbol_mode
	parameter.
	* linespec.c (linespec_keywords): Add NULL terminator.  Make extern.
	(linespec_complete_function): New function.
	(linespec_lexer_lex_keyword): Adjust.
	* linespec.h (linespec_keywords, linespec_complete_function): New
	declarations.
	* location.c (find_end_quote): New function.
	(explicit_location_lex_one): Add explicit_completion_info
	parameter.  Save quoting info.  Don't throw if being called for
	completion.  Don't handle Ada operators here.
	(is_cp_operator, skip_op_false_positives, first_of)
	(explicit_location_lex_one_function): New function.
	(string_to_explicit_location): Replace 'dont_throw' parameter with
	an explicit_completion_info pointer parameter.  Handle it.  Don't
	use explicit_location_lex_one to lex function names.  Use
	explicit_location_lex_one_function instead.
	* location.h (struct explicit_completion_info): New.
	(string_to_explicit_location): Replace 'dont_throw' parameter with
	an explicit_completion_info pointer parameter.
	* symtab.c (default_collect_symbol_completion_matches_break_on):
	Add complete_symbol_mode parameter.  Handle LINESPEC mode.
	(default_collect_symbol_completion_matches)
	(collect_symbol_completion_matches): Add complete_symbol_mode
	parameter.
	(collect_symbol_completion_matches_type): Pass down
	complete_symbol_mode::EXPRESSION.
	(collect_file_symbol_completion_matches): Add complete_symbol_mode
	parameter.  Handle LINESPEC mode.
	* symtab.h (complete_symbol_mode): New.
	(default_collect_symbol_completion_matches_break_on)
	(default_collect_symbol_completion_matches)
	(collect_symbol_completion_matches)
	(collect_file_symbol_completion_matches): Add complete_symbol_mode
	parameter.

gdb/testsuite/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* gdb.linespec/ls-errs.exp (do_test): Adjust expected output.
2017-07-17 20:21:33 +01:00
Pedro Alves 1d550c828c Introduce strncmp_iw
The explicit locations completer patch will need a strncmp_iw
function, that to strcmp_iw like strncmp is to strcmp.  This patch
implements it.

(Unit tests added a bit further down in this series will exercise
this.)

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* utils.c (enum class strncmp_iw_mode): New.
	(strcmp_iw): Rename to ...
	(strncmp_iw_with_mode): ... this.  Add string2_len and mode
	parameters.  Handle them.
	(strncmp_iw): New.
	(strcmp_iw): Reimplement as wrapper around strncmp_iw_with_mode.
	* utils.h (strncmp_iw): Declare.
	(strcmp_iw): Move describing comments here.
2017-07-17 20:08:48 +01:00
Pedro Alves 8090b426b5 Introduce CP_OPERATOR_STR/CP_OPERATOR_LEN and use throughout
Move LENGTH_OF_OPERATOR from cp-support.c to cp-support.h so we can
use it elsewhere.  Since there's already
CP_ANONYMOUS_NAMESPACE_STR/CP_ANONYMOUS_NAMESPACE_LEN there, follow
the same naming pattern for the new symbols.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* c-exp.y (operator_stoken): Use CP_OPERATOR_LEN and
	CP_OPERATOR_STR.
	* c-typeprint.c (is_type_conversion_operator): Use
	CP_OPERATOR_STR.
	* cp-support.c (LENGTH_OF_OPERATOR): Delete.
	(cp_find_first_component_aux): Use CP_OPERATOR_STR and
	CP_OPERATOR_LEN.
	* cp-support.h (CP_OPERATOR_STR, CP_OPERATOR_LEN): New.
	* gnu-v2-abi.c (gnuv2_is_operator_name): Use CP_OPERATOR_STR.
	* gnu-v3-abi.c (gnuv3_is_operator_name): Use CP_OPERATOR_STR.
	* linespec.c (linespec_lexer_lex_string): Use CP_OPERATOR_LEN and
	CP_OPERATOR_STR.
	* location.c: Include "cp-support.h".
	(explicit_location_lex_one): Use CP_OPERATOR_LEN and
	CP_OPERATOR_STR.
	* symtab.c (operator_chars): Use CP_OPERATOR_STR and
	CP_OPERATOR_LEN.
2017-07-17 15:51:55 +01:00
Pedro Alves 6a2c1b8790 "complete" command and completion word break characters
The linespec/locations/completer testcase added later in the series
tests every completion with both TAB completion and the "complete"
command.  This exposed problems in the "complete" command, around
determining the completion word point.

First, the complete command has a too-simple approximation of what
readline's TAB-completion code does to find the completion word point.
Unfortunately, readline doesn't expose the functionality it uses
internally, so to fix this this patch copies over the relevant code,
and adjusts it a bit to better fit the use cases we need it for.
(Specifically, our version avoids relying on the
rl_word_break_characters, etc. globals, and instead takes those as
arguments.)

A following patch will want to use this function for TAB-completion
too, but the "complete" command was a good excuse to split this to a
separate patch.

Then, notice how the complete_command does not call into the completer
for the command being completed to determine the right set of word
break characters.  It always uses the default set.  That is fixed by
having the "complete" command call into complete_line_internal for a
full handle_brkchars phase, just TAB-completion.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* cli/cli-cmds.c (complete_command): Use a completion tracker
	along with completion_find_completion_word for handle_brkchars
	phase.
	* completer.c (RL_QF_SINGLE_QUOTE, RL_QF_DOUBLE_QUOTE)
	(RL_QF_BACKSLASH, RL_QF_OTHER_QUOTE): New.
	(struct gdb_rl_completion_word_info): New.
	(gdb_rl_find_completion_word): New.
	(completion_find_completion_word): New.
	* completer.h (completion_find_completion_word): Declare.
2017-07-17 15:30:59 +01:00
Pedro Alves eb3ff9a551 Introduce class completion_tracker & rewrite completion<->readline interaction
This patch reworks the whole completion machinery, and prepares it
for later enhancements.

Adds a new "completion_tracker" class that is meant to hold everything
about the state of the current completion operation.

This class now has the responsibility of tracking the list of
completion matches, and checking whether the max completions limit has
been reached.  You can look at this as this patch starting out by
C++fying the existing "completion_tracker" in symtab.c (it's just an
htab_t typedef currently), moving it to completer.h/c, and then making
it a class/generalizing/enhancing it.

Unlike with the current tracking, completion_tracker now checks
whether the limit has been reached on each completion match list
insertion.  This both simplifies the max-completions handling code
(maybe_add_completion_enum is gone, for example), and is a
prerequisite for follow up patches.

The current completion_tracker is only used for symbol completions,
and the symbol code gets at the current instance via globals.  This
patch cleans that up by adding a completion_tracker reference to the
signature of the completion functions, and passing the tracker around
everywhere necessary.

Then, the patch changes how the completion match list is handed over
to readline.  Currently, we're using the rl_completion_entry_function
readline entry point, and the patch switches to
rl_attempted_completion_function.  A following patch will want to let
GDB itself decide the common completion prefix between all matches
(what readline calls the "lowest common denominator"), instead of
having readline compute it, and that's not possible with the
rl_completion_entry_function entry point.  Also,
rl_attempted_completion_function lets GDB hand over the match list to
readline as an array in one go instead of passing down matches one by
one, so from that angle it's a nicer entry point anyway.

Lastly, the patch catches exceptions around the readline entry points,
because we can't let C++ exceptions cross readline.  We handle that in
the readline input entry point, but the completion entry point isn't
guarded, so GDB can abort if completion throws.  E.g., in current
master:

 (gdb) b -function "fun<tab>
 terminate called after throwing an instance of 'gdb_exception_RETURN_MASK_ERROR'
 Aborted (core dumped)

This patch fixes that.  This will be exercised in the new tests added
later on in the series.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* ada-lang.c (symbol_completion_match): Adjust comments.
	(symbol_completion_add): Replace vector parameter with
	completion_tracker parameter.  Use it.
	(ada_make_symbol_completion_list): Rename to...
	(ada_collect_symbol_completion_matches): ... this.  Add
	completion_tracker parameter and use it.
	(ada_language_defn): Adjust.
	* break-catch-syscall.c (catch_syscall_completer): Adjust
	prototype and work with completion_tracker instead of VEC.
	* breakpoint.c (condition_completer): Adjust prototype and work
	with completion_tracker instead of VEC.
	* c-lang.c (c_language_defn, cplus_language_defn)
	(asm_language_defn, minimal_language_defn): Adjust to renames.
	* cli/cli-cmds.c (complete_command): Rework using
	completion_tracker.  Catch exceptions when completing.
	* cli/cli-decode.c (integer_unlimited_completer)
	(complete_on_cmdlist, complete_on_enum): Adjust prototype and work
	with completion_tracker instead of VEC.
	* command.h (struct completion_tracker): Forward declare.
	(completer_ftype, completer_handle_brkchars_ftype): Change
	types.
	(complete_on_cmdlist, complete_on_enum): Adjust.
	* completer.c: Include <algorithm>.
	(struct gdb_completer_state): New.
	(current_completion): New global.
	(readline_line_completion_function): Delete.
	(noop_completer, filename_completer)
	(filename_completer_handle_brkchars, complete_files_symbols)
	(linespec_location_completer): Adjust to work with a
	completion_tracker instead of a VEC.
	(string_or_empty): New.
	(collect_explicit_location_matches): Adjust to work with a
	completion_tracker instead of a VEC.
	(explicit_location_completer): Rename to ...
	(complete_explicit_location): ... this and adjust to work with a
	completion_tracker instead of a VEC.
	(location_completer): Adjust to work with a completion_tracker
	instead of a VEC.
	(add_struct_fields): Adjust to work with a completion_list instead
	of VEC.
	(expression_completer): Rename to ...
	(complete_expression): ... this and adjust to work with a
	completion_tracker instead of a VEC.  Use complete_files_symbols.
	(expression_completer): Reimplement on top of complete_expression.
	(symbol_completer): Adjust to work with a completion_tracker
	instead of a VEC.
	(enum complete_line_internal_reason): Add describing comments.
	(complete_line_internal_normal_command): Adjust to work with a
	completion_tracker instead of a VEC.
	(complete_line_internal): Rename to ...
	(complete_line_internal_1): ... this and adjust to work with a
	completion_tracker instead of a VEC.  Assert TEXT is NULL in the
	handle_brkchars phase.
	(new_completion_tracker): Delete.
	(complete_line_internal): Reimplement as TRY/CATCH wrapper around
	complete_line_internal_1.
	(free_completion_tracker): Delete.
	(INITIAL_COMPLETION_HTAB_SIZE): New.
	(completion_tracker::completion_tracker)
	(completion_tracker::~completion_tracker): New.
	(maybe_add_completion): Delete.
	(completion_tracker::maybe_add_completion)
	(completion_tracker::add_completion)
	(completion_tracker::add_completions): New.
	(throw_max_completions_reached_error): Delete.
	(complete_line): Adjust to work with a completion_tracker instead
	of a VEC.  Don't create a completion_tracker_t or check for max
	completions here.
	(command_completer, command_completer_handle_brkchars)
	(signal_completer, reg_or_group_completer_1)
	(reg_or_group_completer, default_completer_handle_brkchars):
	Adjust to work with a completion_tracker.
	(gdb_completion_word_break_characters_throw): New.
	(gdb_completion_word_break_characters): Reimplement.
	(line_completion_function): Delete.
	(completion_tracker::recompute_lowest_common_denominator)
	(expand_preserving_ws)
	(completion_tracker::build_completion_result)
	(completion_result::completion_result)
	(completion_result::completion_result)
	(completion_result::~completion_result)
	(completion_result::completion_result)
	(completion_result::release_match_list, compare_cstrings)
	(completion_result::sort_match_list)
	(completion_result::reset_match_list)
	(gdb_rl_attempted_completion_function_throw)
	(gdb_rl_attempted_completion_function): New.
	* completer.h (completion_list, struct completion_result)
	(class completion_tracker): New.
	(complete_line): Add completion_tracker parameter.
	(readline_line_completion_function): Delete.
	(gdb_rl_attempted_completion_function): New.
	(noop_completer, filename_completer, expression_completer)
	(location_completer, symbol_completer, command_completer)
	(signal_completer, reg_or_group_completer): Update prototypes.
	(completion_tracker_t, new_completion_tracker)
	(make_cleanup_free_completion_tracker): Delete.
	(enum maybe_add_completion_enum): Delete.
	(maybe_add_completion): Delete.
	(throw_max_completions_reached_error): Delete.
	* corefile.c (complete_set_gnutarget): Adjust to work with a
	completion_tracker instead of a VEC.
	* cp-abi.c (cp_abi_completer): Adjust to work with a
	completion_tracker instead of a VEC.
	* d-lang.c (d_language_defn): Adjust.
	* disasm.c (disassembler_options_completer): Adjust to work with a
	completion_tracker instead of a VEC.
	* f-lang.c (f_make_symbol_completion_list): Rename to ...
	(f_collect_symbol_completion_matches): ... this.  Adjust to work
	with a completion_tracker instead of a VEC.
	(f_language_defn): Adjust.
	* go-lang.c (go_language_defn): Adjust.
	* guile/scm-cmd.c (cmdscm_add_completion, cmdscm_completer):
	Adjust to work with a completion_tracker instead of a VEC.
	* infrun.c (handle_completer): Likewise.
	* interps.c (interpreter_completer): Likewise.
	* interps.h (interpreter_completer): Likewise.
	* language.c (unknown_language_defn, auto_language_defn)
	(local_language_defn): Adjust.
	* language.h (language_defn::la_make_symbol_completion_list):
	Rename to ...
	(language_defn::la_collect_symbol_completion_matches): ... this
	and adjust to work with a completion_tracker instead of a VEC.
	* m2-lang.c (m2_language_defn): Adjust.
	* objc-lang.c (objc_language_defn): Adjust.
	* opencl-lang.c (opencl_language_defn): Adjust.
	* p-lang.c (pascal_language_defn): Adjust.
	* python/py-cmd.c (cmdpy_completer_helper): Handle NULL word.
	(cmdpy_completer_handle_brkchars, cmdpy_completer): Adjust to work
	with a completion_tracker.
	* rust-lang.c (rust_language_defn): Adjust.
	* symtab.c (free_completion_list, do_free_completion_list)
	(return_val, completion_tracker): Delete.
	(completion_list_add_name, completion_list_add_symbol)
	(completion_list_add_msymbol, completion_list_objc_symbol)
	(completion_list_add_fields, add_symtab_completions): Add
	completion_tracker parameter and use it.
	(default_make_symbol_completion_list_break_on_1): Rename to...
	(default_collect_symbol_completion_matches_break_on): ... this.
	Add completion_tracker parameter and use it instead of allocating
	a completion tracker here.
	(default_make_symbol_completion_list_break_on): Delete old
	implementation.
	(default_make_symbol_completion_list): Delete.
	(default_collect_symbol_completion_matches): New.
	(make_symbol_completion_list): Delete.
	(collect_symbol_completion_matches): New.
	(make_symbol_completion_type): Rename to ...
	(collect_symbol_completion_matches_type): ... this.  Add
	completion_tracker parameter and use it instead of VEC.
	(make_file_symbol_completion_list_1): Rename to...
	(collect_file_symbol_completion_matches): ... this.  Add
	completion_tracker parameter and use it instead of VEC.
	(make_file_symbol_completion_list): Delete.
	(add_filename_to_list): Use completion_list instead of a VEC.
	(add_partial_filename_data::list): Now a completion_list.
	(make_source_files_completion_list): Work with a completion_list
	instead of a VEC.
	* symtab.h: Include "completer.h".
	(default_make_symbol_completion_list_break_on)
	(default_make_symbol_completion_list, make_symbol_completion_list)
	(make_symbol_completion_type, make_file_symbol_completion_list)
	(make_source_files_completion_list): Delete.
	(default_collect_symbol_completion_matches_break_on)
	(default_collect_symbol_completion_matches)
	(collect_symbol_completion_matches)
	(collect_symbol_completion_matches_type)
	(collect_file_symbol_completion_matches)
	(make_source_files_completion_list): New.
	* top.c (init_main): Don't install a rl_completion_entry_function
	hook.  Install a rl_attempted_completion_function hook instead.
	* tui/tui-layout.c (layout_completer): Adjust to work with a
	completion_tracker.
	* tui/tui-regs.c (tui_reggroup_completer):
	* tui/tui-win.c (window_name_completer, focus_completer)
	(winheight_completer): Adjust to work with a completion_tracker.
	* value.c: Include "completer.h".
	(complete_internalvar): Adjust to work with a completion_tracker.
	* value.h (complete_internalvar): Likewise.
2017-07-17 14:45:59 +01:00
Pedro Alves 6e1dbf8cda Clean up "completer_handle_brkchars" callback handling
This patch cleans up "completer_handle_brkchars" callback handling:

- Renames the function typedef to better match its intent:
  completer_ftype_void ->  completer_handle_brkchars_ftype

- Factors out common code in complete_line_internal handling the
  "handle_brkchars" callback to a separate function.

- Centralizes all the "completer method" to "handle_brkchars method"
  mapping in a single function.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* cli/cli-decode.c (set_cmd_completer_handle_brkchars): Adjust to
	renames.
	* cli/cli-decode.h (struct cmd_list_element) <completer>: Move
	comments to completer_ftype's declaration.
	<completer_handle_brkchars>: Change type to
	completer_handle_brkchars_ftype.
	* command.h (completer_ftype): Add describing comment and give
	names to parameters.
	(completer_ftype_void): Rename to ...
	(completer_handle_brkchars_ftype) ... this.  Add describing comment.
	(set_cmd_completer_handle_brkchars): Adjust.
	* completer.c (filename_completer_handle_brkchars): New function.
	(complete_line_internal_normal_command): New function, factored
	out from ...
	(complete_line_internal): ... here.
	(command_completer_handle_brkchars)
	(default_completer_handle_brkchars)
	(completer_handle_brkchars_func_for_completer): New functions.
	* completer.h (set_gdb_completion_word_break_characters): Delete
	declaration.
	(completer_handle_brkchars_func_for_completer): New declaration.
	* python/py-cmd.c (cmdpy_completer_handle_brkchars): Adjust to use
	completer_handle_brkchars_func_for_completer.
2017-07-17 12:05:03 +01:00
Pedro Alves 78b13106ed Rename make_symbol_completion_list_fn -> symbol_completer
"make_symbol_completion_list_fn" is odly named when you look at a list
of "standard" completers, like the Python/Guile completer lists
adjusted by this patch.  Rename / move it to completers.h/c, for
consistency.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* completer.c (symbol_completer): New function, based on
	make_symbol_completion_list_fn.
	* completer.h (symbol_completer): New declaration.
	* guile/scm-cmd.c (cmdscm_completers): Adjust.
	* python/py-cmd.c (completers): Adjust.
	* symtab.c (make_symbol_completion_list_fn): Delete.
	* symtab.h (make_symbol_completion_list_fn): Delete.
	* cli/cli-decode.c (add_cmd): Adjust.
2017-07-17 11:55:42 +01:00
Pedro Alves bbf2f4dfae Fix TAB-completion + .gdb_index slowness (generalize filename_seen_cache)
Tab completion when debugging a program binary that uses GDB index is
surprisingly much slower than when GDB uses psymtabs instead.  Around
1.5x/3x slower.  That's surprising, because the whole point of GDB
index is to speed things up...

For example, with:

 set pagination off
 set $count = 0
 while $count < 400
   complete b string_prin         # matches gdb's string_printf
   printf "count = %d\n", $count
   set $count = $count + 1
 end

 $ time ./gdb --batch -q  ./gdb-with-index -ex "source script.cmd"
 real    0m11.042s
 user    0m10.920s
 sys     0m0.042s

 $ time ./gdb --batch -q  ./gdb-without-index -ex "source script.cmd"
 real    0m4.635s
 user    0m4.590s
 sys     0m0.037s

Same but with:
 -   complete b string_prin
 +   complete b zzzzzz
to exercise the no-matches worst case, master currently gets you
something like:

 with index           without index
 real    0m11.971s    0m8.413s
 user    0m11.912s    0m8.355s
 sys     0m0.035s     0m0.035s

Running gdb under perf shows 80% spent inside
maybe_add_partial_symtab_filename, and 20% spent in the lbasename
inside that.

The problem that tab completion walks over all compunit symtabs, and
for each, walks the contained file symtabs.  And there a huge number
of file symtabs (each included system header, etc.) that appear in
each compunit symtab's file symtab list.  As in, when debugging GDB, I
have 367381 symtabs iterated, when of those only 5371 filenames are
unique...

This was a regression from the earlier (nice) split of symtabs in
compunit symtabs + file symtabs.

The fix here is to add a cache of unique filenames per objfile so that
the walk / uniquing is only done once.  There's already a abstraction
for this in symtab.c; this patch moves that code out to a separate
file and C++ifies it bit.

This makes the worst-case scenario above consistently drop to ~2.5s
(1.5s for the "string_prin" hit case), making it over 3.3x times
faster than psymtabs in this use case (7x in the "string_prin" hit
case).

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* Makefile.in (COMMON_OBS): Add filename-seen-cache.o.
	* dwarf2read.c: Include "filename-seen-cache.h".
	* dwarf2read.c (dwarf2_per_objfile) <filenames_cache>: New field.
	(dw2_map_symbol_filenames): Build and use a filenames_seen_cache.
	* filename-seen-cache.c: New file.
	* filename-seen-cache.h: New file.
	* symtab.c: Include "filename-seen-cache.h".
	(struct filename_seen_cache, INITIAL_FILENAME_SEEN_CACHE_SIZE)
	(create_filename_seen_cache, clear_filename_seen_cache)
	(delete_filename_seen_cache, filename_seen): Delete, parts moved
	to filename-seen-cache.h/filename-seen-cache.c.
	(output_source_filename, sources_info)
	(maybe_add_partial_symtab_filename)
	(make_source_files_completion_list): Adjust to use
	filename_seen_cache.
2017-07-17 11:38:11 +01:00
Pedro Alves 330cdd9891 C++ify dwarf2_per_objfile
This makes dwarf2_per_objfile a class with cdtors.

A following patch will add a non-trivial field to struct
dwarf2_per_objfile, making dwarf2_per_objfile itself non-trivial.
Since dwarf2_per_objfile is allocated in an obstack, we need to run
its cdtors manually.

Tested on x86-64 GNU/Linux.

gdb/ChangeLog:
2017-07-17  Pedro Alves  <palves@redhat.com>

	* dwarf2read.c (dwarf2_per_objfile): In-class initialize all
	fields.
	(dwarf2_per_objfile::dwarf2_per_objfile(objfile*, const
	dwarf2_debug_sections*)): New.
	(dwarf2_per_objfile::dwarf2_per_objfile(const
	dwarf2_per_objfile&)): Declare as deleted.
	(dwarf2_per_objfile::operator=): Declare as deleted.
	(dwarf2_per_objfile::dwarf2_per_objfile)
	(dwarf2_per_objfile::~dwarf2_per_objfile)
	(dwarf2_per_objfile::free_cached_comp_units): New.
	(dwarf2_has_info): dwarf2_per_objfile initialization code moved to
	ctor.  Call dwarf2_per_objfile's ctor manually.
	(dwarf2_locate_sections): Deleted/refactored as ...
	(dwarf2_per_objfile::locate_sections): ... this new method.
	(free_cached_comp_units): Defer to
	dwarf2_per_objfile::free_cached_comp_units.
	(dwarf2_free_objfile): Call dwarf2_per_objfile's dtor manually.
2017-07-17 11:31:20 +01:00
Andrew Burgess 5bd6848722 gdb: Make some test names unique
Make sure all of the tests have unique names in
gdb.mi/mi-vla-fortran.exp.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-vla-fortran.exp: Make test names unique.
2017-07-15 01:04:44 +01:00
Tom Tromey 8880f2a9cb Handle sizeof(type) in Rust
PR rust/21764 notes that "sizeof" does not work correctly for all types
in Rust.  The bug turns out to be an error in the conversion of the AST
to gdb expressions.  This patch fixes the bug and also avoids generating
incorrect expressions in another case.

Tested on the buildbot.  I'm checking this in.

2017-07-14  Tom Tromey  <tom@tromey.com>

	PR rust/21764:
	* rust-exp.y (convert_ast_to_expression): Add "want_type"
	parameter.
	<UNOP_SIZEOF>: Split into separate case.
	<UNOP_VAR_VALUE>: Handle want_type.  Add error case.

2017-07-14  Tom Tromey  <tom@tromey.com>

	PR rust/21764:
	* gdb.rust/simple.exp: Add tests.
2017-07-14 12:30:56 -06:00