Commit Graph

627 Commits

Author SHA1 Message Date
Tom Tromey e99b03dcf4 Remove ptid_get_pid
This removes ptid_get_pid in favor of calling the ptid_t::pid method.

gdb/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* common/ptid.c (ptid_get_pid): Remove.
	* common/ptid.h (ptid_get_pid): Don't declare.
	* aarch64-linux-nat.c: Update.
	* ada-lang.c: Update.
	* aix-thread.c: Update.
	* alpha-bsd-nat.c: Update.
	* amd64-fbsd-nat.c: Update.
	* amd64-linux-nat.c: Update.
	* arm-linux-nat.c: Update.
	* arm-nbsd-nat.c: Update.
	* auxv.c: Update.
	* break-catch-syscall.c: Update.
	* breakpoint.c: Update.
	* bsd-uthread.c: Update.
	* corelow.c: Update.
	* ctf.c: Update.
	* darwin-nat.c: Update.
	* fbsd-nat.c: Update.
	* fbsd-tdep.c: Update.
	* gcore.c: Update.
	* gnu-nat.c: Update.
	* hppa-nbsd-nat.c: Update.
	* hppa-obsd-nat.c: Update.
	* i386-fbsd-nat.c: Update.
	* ia64-linux-nat.c: Update.
	* inf-ptrace.c: Update.
	* infcmd.c: Update.
	* inferior.c: Update.
	* inferior.h: Update.
	* inflow.c: Update.
	* infrun.c: Update.
	* linux-fork.c: Update.
	* linux-nat.c: Update.
	* linux-tdep.c: Update.
	* linux-thread-db.c: Update.
	* m68k-bsd-nat.c: Update.
	* mi/mi-interp.c: Update.
	* mi/mi-main.c: Update.
	* mips-linux-nat.c: Update.
	* mips-nbsd-nat.c: Update.
	* mips64-obsd-nat.c: Update.
	* nat/aarch64-linux-hw-point.c: Update.
	* nat/aarch64-linux.c: Update.
	* nat/linux-btrace.c: Update.
	* nat/linux-osdata.c: Update.
	* nat/linux-procfs.c: Update.
	* nat/x86-linux-dregs.c: Update.
	* nto-procfs.c: Update.
	* obsd-nat.c: Update.
	* ppc-linux-nat.c: Update.
	* ppc-nbsd-nat.c: Update.
	* ppc-obsd-nat.c: Update.
	* proc-service.c: Update.
	* procfs.c: Update.
	* python/py-inferior.c: Update.
	* python/py-infthread.c: Update.
	* ravenscar-thread.c: Update.
	* record.c: Update.
	* remote-sim.c: Update.
	* remote.c: Update.
	* rs6000-nat.c: Update.
	* s390-linux-nat.c: Update.
	* sh-nbsd-nat.c: Update.
	* sol-thread.c: Update.
	* sparc-nat.c: Update.
	* sparc64-tdep.c: Update.
	* spu-linux-nat.c: Update.
	* spu-tdep.c: Update.
	* target-debug.h: Update.
	* target.c: Update.
	* thread.c: Update.
	* tid-parse.c: Update.
	* tracefile-tfile.c: Update.
	* vax-bsd-nat.c: Update.
	* windows-nat.c: Update.
	* x86-linux-nat.c: Update.
	* x86-nat.c: Update.

gdb/gdbserver/ChangeLog
2018-07-03  Tom Tromey  <tom@tromey.com>

	* linux-low.c: Update.
	* linux-mips-low.c: Update.
	* lynx-low.c: Update.
	* mem-break.c: Update.
	* nto-low.c: Update.
	* remote-utils.c: Update.
	* server.c: Update.
	* spu-low.c: Update.
	* target.c: Update.
	* tracepoint.c: Update.
2018-07-03 11:36:42 -06:00
Tom Tromey 69d340c684 Remove la_error
While working on the parser code, I noticed that yyerror is exported
from each parser.  It is used by this code in parse.c:

   TRY
     {
       if (lang->la_parser (&ps))
         lang->la_error (NULL);
     }

However, it seems to me that la_error will never be called here,
because in every case, la_parser throws an exception on error -- each
implementation of yyerror just calls error.

So, this patch removes la_error and makes all the yyerror functions
static.  This is handy primarily because it makes it simpler to make
the expression parsers pure.

Tested by the buildbot.

gdb/ChangeLog
2018-06-18  Tom Tromey  <tom@tromey.com>

	* rust-lang.h (rust_yyerror): Don't declare.
	* rust-lang.c (rust_language_defn): Update.
	* rust-exp.y (yyerror): Now static.
	* parse.c (parse_exp_in_context_1): Update.
	* p-lang.h (p_yyerror): Don't declare.
	* p-lang.c (p_language_defn): Update.
	* p-exp.y (yyerror): Now static.
	* opencl-lang.c (opencl_language_defn): Update.
	* objc-lang.c (objc_language_defn): Update.
	* m2-lang.h (m2_yyerror): Don't declare.
	* m2-lang.c (m2_language_defn): Update.
	* m2-exp.y (yyerror): Now static.
	* language.h (struct language_defn) <la_error>: Remove.
	* language.c (unk_lang_error): Remove.
	(unknown_language_defn, auto_language_defn): Remove.
	* go-lang.h (go_yyerror): Don't declare.
	* go-lang.c (go_language_defn): Update.
	* go-exp.y (yyerror): Now static.
	* f-lang.h (f_yyerror): Don't declare.
	* f-lang.c (f_language_defn): Update.
	* f-exp.y (yyerror): Now static.
	* d-lang.h (d_yyerror): Don't declare.
	* d-lang.c (d_language_defn): Update.
	* d-exp.y (yyerror): Now static.
	* c-lang.h (c_yyerror): Don't declare.
	* c-lang.c (c_language_defn, cplus_language_defn)
	(asm_language_defn, minimal_language_defn): Update.
	* c-exp.y (yyerror): Now static.
	* ada-lang.h (ada_yyerror): Don't declare.
	* ada-lang.c (ada_language_defn): Update.
	* ada-exp.y (yyerror): Now static.
2018-06-18 12:29:15 -06:00
Tom Tromey 54d343a240 Remove last Ada cleanups
This removes the last cleanups from the Ada code by changing
ada_lookup_symbol_list's out parameter to be a std::vector, and then
fixing up the fallout.

This is a relatively shallow change.  Deeper changes are possible, for
example (1) changing various other functions to accept a vector rather
than a pointer, or (2) changing ada_lookup_symbol_list to return the
vector and omitting the length entirely.

Tested by the buildbot, but I'll wait for Joel to test these as well.

gdb/ChangeLog
2018-06-04  Tom Tromey  <tom@tromey.com>

	* ada-lang.h (ada_lookup_symbol_list): Update.
	* ada-lang.c (resolve_subexp): Update.
	(symbols_are_identical_enums): Change type of syms.  Remove nsyms
	parameter.
	(remove_extra_symbols, remove_irrelevant_renamings): Likewise.
	(ada_lookup_symbol_list_worker, ada_lookup_symbol_list): Change
	results parameter to std::vector.
	(ada_iterate_over_symbols, ada_lookup_symbol, get_var_value):
	Update.
	* ada-exp.y (block_lookup): Update.
	(select_possible_type_sym): Change type of syms.  Remove nsyms
	parameter.
	(write_var_or_type, write_name_assoc): Update.
2018-06-04 15:33:28 -06:00
Tom Tromey a737d952e0 Remove type_name_no_tag and rename type_name_no_tag_or_error
type_name_no_tag is just a plain wrapper for TYPE_NAME now, so this
patch removes it.  And, because tag names no longer exist, this
renames type_name_no_tag_or_error to type_name_or_error.

gdb/ChangeLog
2018-06-01  Tom Tromey  <tom@tromey.com>

	* valops.c (value_cast_structs, destructor_name_p): Update.
	* symtab.c (gdb_mangle_name): Update.
	* stabsread.c (define_symbol, read_cpp_abbrev, read_baseclasses):
	Update.
	* p-valprint.c (pascal_object_is_vtbl_ptr_type)
	(pascal_object_print_value_fields, pascal_object_print_value):
	Update.
	* p-typeprint.c (pascal_type_print_derivation_info): Update.
	* linespec.c (find_methods): Update.
	* gdbtypes.h (type_name_no_tag): Remove.
	(type_name_or_error): Rename from type_name_no_tag_or_error.
	* gdbtypes.c (type_name_no_tag): Remove.
	(type_name_or_error): Rename from type_name_no_tag_or_error.
	(lookup_struct_elt_type, check_typedef): Update.
	* expprint.c (print_subexp_standard): Update.
	* dwarf2read.c (dwarf2_add_field, load_partial_dies): Update.
	* d-namespace.c (d_lookup_nested_symbol): Update.
	* cp-valprint.c (cp_is_vtbl_ptr_type, cp_print_value_fields)
	(cp_print_class_member): Update.
	* cp-namespace.c (cp_lookup_nested_symbol): Update.
	* completer.c (add_struct_fields): Update.
	* c-typeprint.c (cp_type_print_derivation_info)
	(c_type_print_varspec_prefix, c_type_print_base_struct_union):
	Update.
	* ada-lang.c (parse_old_style_renaming, xget_renaming_scope)
	(ada_prefer_type, ada_is_exception_sym): Update.
2018-06-01 10:19:55 -06:00
Tom Tromey e86ca25fd6 Remove TYPE_TAG_NAME
TYPE_TAG_NAME has been an occasional source of confusion and bugs.  It
seems to me that it is only useful for C and C++ -- but even there,
not so much, because at least with DWARF there doesn't seem to be any
way to wind up with a type where the name and the tag name are both
non-NULL and different.

So, this patch removes TYPE_TAG_NAME entirely.  This should save a
little memory, but more importantly, it simplifies this part of gdb.

A few minor test suite adjustments were needed.  In some situations
the new code does not yield identical output to the old code.

gdb/ChangeLog
2018-06-01  Tom Tromey  <tom@tromey.com>

	* valops.c (enum_constant_from_type, value_namespace_elt)
	(value_maybe_namespace_elt): Update.
	* valarith.c (find_size_for_pointer_math): Update.
	* target-descriptions.c (make_gdb_type): Update.
	* symmisc.c (print_symbol): Update.
	* stabsread.c (define_symbol, read_type)
	(complain_about_struct_wipeout, add_undefined_type)
	(cleanup_undefined_types_1): Update.
	* rust-lang.c (rust_tuple_type_p, rust_slice_type_p)
	(rust_range_type_p, val_print_struct, rust_print_struct_def)
	(rust_internal_print_type, rust_composite_type)
	(rust_evaluate_funcall, rust_evaluate_subexp)
	(rust_inclusive_range_type_p): Update.
	* python/py-type.c (typy_get_tag): Update.
	* p-typeprint.c (pascal_type_print_base): Update.
	* mdebugread.c (parse_symbol, parse_type): Update.
	* m2-typeprint.c (m2_long_set, m2_record_fields, m2_enum):
	Update.
	* guile/scm-type.c (gdbscm_type_tag): Update.
	* go-lang.c (sixg_string_p): Update.
	* gnu-v3-abi.c (build_gdb_vtable_type, build_std_type_info_type):
	Update.
	* gdbtypes.h (struct main_type) <tag_name>: Remove.
	(TYPE_TAG_NAME): Remove.
	* gdbtypes.c (type_name_no_tag): Simplify.
	(check_typedef, check_types_equal, recursive_dump_type)
	(copy_type_recursive, arch_composite_type): Update.
	* f-typeprint.c (f_type_print_base): Update.  Print "Type" prefix
	in summary mode when needed.
	* eval.c (evaluate_funcall): Update.
	* dwarf2read.c (fixup_go_packaging, read_structure_type)
	(process_structure_scope, read_enumeration_type)
	(read_namespace_type, read_module_type, determine_prefix): Update.
	* cp-support.c (inspect_type): Update.
	* coffread.c (process_coff_symbol, decode_base_type): Update.
	* c-varobj.c (c_is_path_expr_parent): Update.
	* c-typeprint.c (c_type_print_base_struct_union): Update.
	(c_type_print_base_1): Update.  Print struct/class/union/enum in
	summary when using C language.
	* ax-gdb.c (gen_struct_ref, gen_namespace_elt)
	(gen_maybe_namespace_elt): Update.
	* ada-lang.c (ada_type_name): Simplify.
	(empty_record, ada_template_to_fixed_record_type_1)
	(template_to_static_fixed_type)
	(to_record_with_fixed_variant_part, ada_check_typedef): Update.

gdb/testsuite/ChangeLog
2018-06-01  Tom Tromey  <tom@tromey.com>

	* gdb.xml/tdesc-regs.exp (load_description): Update expected
	results.
	* gdb.dwarf2/method-ptr.exp: Set language to C++.
	* gdb.dwarf2/member-ptr-forwardref.exp: Set language to C++.
	* gdb.cp/typeid.exp (do_typeid_tests): Update type_re.
	* gdb.base/maint.exp (maint_pass_if): Update.
2018-06-01 10:19:55 -06:00
Joel Brobecker 241db429d5 fix "stale cleanup" internal-warning when using "catch assert" command
Trying to insert a catchpoint on all Ada assertions now triggers
the following internal warning regardless of the situation. For
instance, not even debugging any program:

    (gdb) catch assert
    /[...]/gdb/common/cleanups.c:264: internal-warning:
    restore_my_cleanups has found a stale cleanup

This is due to a small bug in the following C++-ification commit:

    commit bc18fbb575
    Author: Tom Tromey <tom@tromey.com>
    Date:   Fri May 18 15:58:50 2018 -0600
    Subject: Change ada_catchpoint::excep_string to be a std::string

The stale cleanup in question is the following one in top.c:execute_command:

    cleanup_if_error = make_bpstat_clear_actions_cleanup ();

This cleanup is expected to be discarded if there are no exception.
There were no GDB exception; however, a C++ exception was triggered,
because we passed NULL as the excep_string argument when calling
create_ada_exception_catchpoint, which is a reference to a const
string. So we get a C++ exception during the std::string constructor,
which propagates up, causing the cleanup to unexpectedly remain
in the cleanup chain.

This patch fixes the immediate issue of the incorrect call to
create_ada_exception_catchpoint.

gdb/ChangeLog:

        * ada-lang.c (catch_assert_command): Pass empty string instead
        of NULL for excep_string argument.

Tested on x86_64-linux, fixes the following failures:

  * catch_assert_if.exp: insert catchpoint on failed assertions with condition
  * catch_ex.exp: insert catchpoint on failed assertions

This also fixes about a dozen UNRESOLVED tests that are a consequence
of the two tests above failing and crashing GDB.
2018-05-22 10:25:50 -04:00
Tom Tromey bc18fbb575 Change ada_catchpoint::excep_string to be a std::string
This changes ada_catchpoint::excep_string to be a std::string and then
fixes up all t he users.

This found a memory leak in catch_ada_exception_command_split, where
"cond" was copied but never freed.

I changed the type of the "cond_string" argument to
catch_ada_exception_command_split to follow the rule that out
parameters should be pointers and not references.

This patch enables the removal of some cleanups and also the function
ada_get_next_arg.

ChangeLog
2018-05-21  Tom Tromey  <tom@tromey.com>

	* mi/mi-cmd-catch.c (mi_cmd_catch_assert)
	(mi_cmd_catch_exception, mi_cmd_catch_handlers): Update.
	* ada-lang.h (create_ada_exception_catchpoint): Update.
	* ada-lang.c (struct ada_catchpoint) <excep_string>: Now a
	std::string.
	(create_excep_cond_exprs, ~ada_catchpoint)
	(should_stop_exception, print_one_exception)
	(print_mention_exception, print_recreate_exception): Update.
	(ada_get_next_arg): Remove.
	(catch_ada_exception_command_split): Use std::string.  Change type
	of "excep_string", "cond_string".
	(catch_ada_exception_command): Update.
	(create_ada_exception_catchpoint): Change type of excep_string.
	(ada_exception_sal): Remove excep_string parameter.
	(~ada_catchpoint): Remove.
2018-05-21 10:01:15 -06:00
Tom Tromey 790217f673 Remove cleanup from ada_collect_symbol_completion_matches
ada_collect_symbol_completion_matches installs a null_cleanup but not
any other cleanups.  This patch removes it.

ChangeLog
2018-05-21  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_collect_symbol_completion_matches): Remove
	cleanup.
2018-05-21 10:01:15 -06:00
Tom Tromey 6f46ac8531 Remove cleanup from ada-lang.c
This removes a cleanup from ada-lang.c by having
ada_exception_message_1 return a unique_xmalloc_ptr.

ChangeLog
2018-05-21  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_exception_message_1, ada_exception_message):
	Return unique_xmalloc_ptr.
	(print_it_exception): Update.
2018-05-21 10:01:14 -06:00
Simon Marchi e39db4db7c Use XOBNEW/XOBNEWVEC/OBSTACK_ZALLOC when possible
Since XOBNEW/XOBNEWVEC/OBSTACK_ZALLOC are now poisoned to prevent using
them with non-trivially-constructible objects, it is worth using them
over plain obstack_alloc.  This patch changes the locations I could find
where we can do that change easily.

gdb/ChangeLog:

	* ada-lang.c (cache_symbol): Use XOBNEW and/or XOBNEWVEC and/or
	OBSTACK_ZALLOC.
	* dwarf2-frame.c (dwarf2_build_frame_info): Likewise.
	* hppa-tdep.c (hppa_init_objfile_priv_data): Likewise.
	* mdebugread.c (mdebug_build_psymtabs): Likewise.
	(add_pending): Likewise.
	(parse_symbol): Likewise.
	(parse_partial_symbols): Likewise.
	(psymtab_to_symtab_1): Likewise.
	(new_psymtab): Likewise.
	(elfmdebug_build_psymtabs): Likewise.
	* minsyms.c (terminate_minimal_symbol_table): Likewise.
	* objfiles.c (get_objfile_bfd_data): Likewise.
	(objfile_register_static_link): Likewise.
	* psymtab.c (allocate_psymtab): Likewise.
	* stabsread.c (read_member_functions): Likewise.
	* xcoffread.c (xcoff_end_psymtab): Likewise.
2018-05-20 21:07:03 -04:00
Tom Tromey 862d101ada Remove cleanup from print_mention_exception
This removes a cleanup from print_mention_exception by using
string_printf.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (print_mention_exception): Use std::string.
2018-05-04 12:12:16 -06:00
Tom Tromey cb7de75eb3 Return std::string from ada_exception_catchpoint_cond_string
This changes ada_exception_catchpoint_cond_string to return a
std::string, allowing for the removal of a cleanup in
create_excep_cond_exprs.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (create_excep_cond_exprs): Update.
	(ada_exception_catchpoint_cond_string): Use std::string.
2018-05-04 12:12:16 -06:00
Tom Tromey 49d83361cd Remove cleanup from old_renaming_is_invisible
This removes a cleanup from ada-lang.c by changing xget_renaming_scope
to return a std::string.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (xget_renaming_scope): Return std::string.
	(old_renaming_is_invisible): Update.
2018-05-04 12:12:16 -06:00
Tom Tromey 459a2e4ccf Change streq to return bool
I wanted to use streq with std::unique in another (upcoming) patch in
this seres, so I changed it to return bool.  To my surprise, this lead
to regressions.  The cause turned out to be that streq was used as an
htab callback -- by casting it to the correct function type.  This
sort of cast is invalid, so this patch adds a variant which is
directly suitable for use by htab.  (Note that I did not add an
overload, as I could not get that to work with template deduction in
the other patch.)

ChangeLog
2018-04-05  Tom Tromey  <tom@tromey.com>

	* completer.c (completion_tracker::completion_tracker): Remove
	cast.
	(completion_tracker::discard_completions): Likewise.
	* breakpoint.c (ambiguous_names_p): Remove cast.
	* ada-lang.c (_initialize_ada_language): Remove cast.
	* utils.h (streq): Update.
	(streq_hash): Add new declaration.
	* utils.c (streq): Return bool.
	(streq_hash): New function.
2018-04-05 07:39:36 -06:00
Tom Tromey e83e4e2402 Change target_read_string to use unique_xmalloc_ptr
This changes the out parameter of target_read_string to be a
unique_xmalloc_ptr.  This avoids a cleanup and sets the stage for more
cleanup removals.

This patch also removes a seemingly needless alloca from
print_subexp_standard.

gdb/ChangeLog
2018-03-30  Tom Tromey  <tom@tromey.com>

	* windows-nat.c (handle_output_debug_string, handle_exception):
	Update.
	* target.h (target_read_string): Update.
	* target.c (target_read_string): Change "string" to
	unique_xmalloc_ptr.
	* solib-svr4.c (open_symbol_file_object, svr4_read_so_list):
	Update.
	* solib-frv.c (frv_current_sos): Update.
	* solib-dsbt.c (dsbt_current_sos): Update.
	* solib-darwin.c (darwin_current_sos): Update.
	* linux-thread-db.c (inferior_has_bug): Update.
	* expprint.c (print_subexp_standard) <case OP_OBJC_MSGCALL>:
	Update.  Remove alloca.
	* ada-lang.c (ada_main_name): Update.
2018-03-30 13:22:58 -06:00
Joel Brobecker 3fcded8f30 set varsize-limit: New GDB setting for maximum dynamic object size
This is a command we somehow forgot to contribute at the time the Ada
language was first contributed to the FSF. This command allows
the user to change the maximum size we allow when reading memory
from dynamic objects (the default is 65536 bytes).

At the moment, this limit is only used by Ada, and so the implementation
is kept inside ada-lang.c. However, it is conceivable that other language
might want to use it also to handle the same kind of issues; for instance,
this might be useful when handling dynamic types in C. So the name
of the setting was made language-neutral, to allow for this.

Note that an alias for "set var" needs to be introduced as well.
We are not adding a test for that, since this is a feature that is
already exercized by numerous existing tests.

gdb/ChangeLog

        * NEWS: Add entry describing new "set|show varsize-limit" command.
        * ada-lang.c (_initialize_ada_language): Add "set/show varsize-limit"
        command.
        * printcmd.c (_initialize_printcmd): Add "set var" alias of
        "set variable".

gdb/doc/ChangeLog:

        * gdb.texinfo (Ada Settings): New subsubsection.

gdb/testsuite/ChangeLog:

        * gdb.ada/varsize_limit: New testcase.

Tested on x86_64-linux.
2018-03-27 10:17:45 -04:00
Joel Brobecker 59cc4834e5 problem looking up some symbols when they have a linkage name
This patch fixes a known failure in gdb.ada/maint_with_ada.exp
(maintenance check-psymtabs). Another way to witness the same
issue is by considering the following Ada declarations...

   type Wrapper is record
      A : Integer;
   end record;
   u00045 : constant Wrapper := (A => 16#060287af#);
   pragma Export (C, u00045, "symada__cS");

... which declares a variable name "u00045" but with a linkage
name which is "symada__cS". This variable is a record with one
component, the Ada equivalent of a struct with one field in C.
Trying to print that variable's value currently yields:

    (gdb) p /x <symada__cS>
    'symada(char, signed)' has unknown type; cast it to its declared type

This indicates that GDB was only able to find the minimal symbol,
but not the full symbol. The expected output is:

    (gdb) print /x <symada__cS>
    $1 = (a => 0x60287af)

The error message gives a hint about what's happening: We processed
the symbol through gdb_demangle, which in the case of this particular
symbol name, ends up matching the C++ naming scheme. As a result,
the demangler transforms our symbol name into 'symada(char, signed)',
thus breaking Ada lookups.

This patch fixes the issue by first introducing a new language_defn
attribute called la_store_sym_names_in_linkage_form_p, which is a boolean
to be set to true for the few languages that do not want their symbols
to have their names stored in demangled form, and false otherwise.
We then use this language attribute to skip the call to gdb_demangle
for all languages whose la_store_sym_names_in_linkage_form_p is true.

In terms of the selection of languages for which the new attribute
is set to true, the selection errs on the side of preserving the
existing behavior, and only changes the behavior for the languages
where we are certain storing symbol names in demangling form is not
needed. It is conceivable that other languages might be in the same
situation, but I not knowing in detail the symbol name enconding
strategy, I decided to play it safe and let other language maintainers
potentially adjust their language if it makes sense to do so.

gdb/ChangeLog:

        PR gdb/22670
        * dwarf2read.c (dwarf2_physname): Do not return the demangled
        symbol name if the CU's language stores symbol names in linkage
        format.
        * language.h (struct language_defn)
        <la_store_sym_names_in_linkage_form_p>: New field.  Adjust
        all instances of this struct.

gdb/testsuite/ChangeLog:

        * gdb.ada/maint_with_ada.exp: Remove PR gdb/22670 setup_kfail.

        * gdb.ada/notcplusplus: New testcase.

        * gdb.base/c-linkage-name.c: New file.
        * gdb.base/c-linkage-name.exp: New testcase.

Tested on x86_64-linux.
This also passes AdaCore's internal GDB testsuite.
2018-03-27 09:57:16 -04:00
Tom Tromey 76727919ce Convert observers to C++
This converts observers from using a special source-generating script
to be plain C++.  This version of the patch takes advantage of C++11
by using std::function and variadic templates; incorporates Pedro's
patches; and renames the header file to "observable.h" (this change
eliminates the need for a clean rebuild).

Note that Pedro's patches used a template lambda in tui-hooks.c, but
this failed to compile on some buildbot instances (presumably due to
differing C++ versions); I replaced this with an ordinary template
function.

Regression tested on the buildbot.

gdb/ChangeLog
2018-03-19  Pedro Alves  <palves@redhat.com>
	    Tom Tromey  <tom@tromey.com>

	* unittests/observable-selftests.c: New file.
	* common/observable.h: New file.
	* observable.h: New file.
	* ada-lang.c, ada-tasks.c, agent.c, aix-thread.c, annotate.c,
	arm-tdep.c, auto-load.c, auxv.c, break-catch-syscall.c,
	breakpoint.c, bsd-uthread.c, cli/cli-interp.c, cli/cli-setshow.c,
	corefile.c, dummy-frame.c, event-loop.c, event-top.c, exec.c,
	extension.c, frame.c, gdbarch.c, guile/scm-breakpoint.c,
	infcall.c, infcmd.c, inferior.c, inflow.c, infrun.c, jit.c,
	linux-tdep.c, linux-thread-db.c, m68klinux-tdep.c,
	mi/mi-cmd-break.c, mi/mi-interp.c, mi/mi-main.c, objfiles.c,
	ppc-linux-nat.c, ppc-linux-tdep.c, printcmd.c, procfs.c,
	python/py-breakpoint.c, python/py-finishbreakpoint.c,
	python/py-inferior.c, python/py-unwind.c, ravenscar-thread.c,
	record-btrace.c, record-full.c, record.c, regcache.c, remote.c,
	riscv-tdep.c, sol-thread.c, solib-aix.c, solib-spu.c, solib.c,
	spu-multiarch.c, spu-tdep.c, stack.c, symfile-mem.c, symfile.c,
	symtab.c, thread.c, top.c, tracepoint.c, tui/tui-hooks.c,
	tui/tui-interp.c, valops.c: Update all users.
	* tui/tui-hooks.c (tui_bp_created_observer)
	(tui_bp_deleted_observer, tui_bp_modified_observer)
	(tui_inferior_exit_observer, tui_before_prompt_observer)
	(tui_normal_stop_observer, tui_register_changed_observer):
	Remove.
	(tui_observers_token): New global.
	(attach_or_detach, tui_attach_detach_observers): New functions.
	(tui_install_hooks, tui_remove_hooks): Use
	tui_attach_detach_observers.
	* record-btrace.c (record_btrace_thread_observer): Remove.
	(record_btrace_thread_observer_token): New global.
	* observer.sh: Remove.
	* observer.c: Rename to observable.c.
	* observable.c (namespace gdb_observers): Define new objects.
	(observer_debug): Move into gdb_observers namespace.
	(struct observer, struct observer_list, xalloc_observer_list_node)
	(xfree_observer_list_node, generic_observer_attach)
	(generic_observer_detach, generic_observer_notify): Remove.
	(_initialize_observer): Update.
	Don't include observer.inc.
	* Makefile.in (generated_files): Remove observer.h, observer.inc.
	(clean mostlyclean): Likewise.
	(observer.h, observer.inc): Remove targets.
	(SUBDIR_UNITTESTS_SRCS): Add observable-selftests.c.
	(COMMON_SFILES): Use observable.c, not observer.c.
	* .gitignore: Remove observer.h.

gdb/doc/ChangeLog
2018-03-19  Tom Tromey  <tom@tromey.com>

	* observer.texi: Remove.

gdb/testsuite/ChangeLog
2018-03-19  Tom Tromey  <tom@tromey.com>

	* gdb.gdb/observer.exp: Remove.
2018-03-19 09:37:49 -06:00
Joel Brobecker 355c559b74 delete ada-lang.c::ada_to_fixed_value_create advance declaration
This advance declaration really isn't necesary, since the implementation
of this function comes before the first reference to it.

gdb/ChangeLog:

        * ada-lang.c (ada_to_fixed_value_create): Delete advance
        declaration.

Tested by rebuilding GDB.
2018-02-14 22:59:20 -05:00
Joel Brobecker f98b2e334f Remove references to ada_name_for_lookup (deleted)
This function was deleted on 2017-11-08, but its declaration and
a reference to it in a comment was left behind.  This patch just
removes those.

gdb/ChangeLog:

        * ada-lang.c (name_match_type_from_name): Remove reference to
        ada_name_for_lookup in function's documentation.
        * ada-lang.h (ada_name_for_lookup): Delete declaration.

Tested by rebuilding GDB.
2018-02-14 05:48:48 -05:00
Xavier Roirand 56ecd069f0 (Ada) C++fy conditional string when catching exception.
This commit C++fy the conditional string used when catching Ada exception.

gdb/ChangeLog:

        * ada-lang.c (catch_ada_exception_command_split)
        (create_ada_exception_catchpoint) <cond_string>: Change parameter
        type.  Update code accordingly.
        (catch_ada_exception_command, catch_ada_handlers_command): Use
        C++ string instead of char* for conditional var.
        (catch_ada_assert_command_split) <cond_string>: Change parameter
        type.  Update code accordingly.
        (catch_assert_command): Use C++ string instead of char* for
        conditional var.
        * ada-lang.h (create_ada_exception_catchpoint) <cond_string>:
        Update declaration.
        * mi/mi-cmd-catch.c (mi_cmd_catch_assert, mi_cmd_catch_exception):
        Use std::string instead of char* for condition string.

Tested on x86_64-linux.
2018-01-31 13:42:30 +01:00
Andrew Burgess aee1fcdf97 gdb: New API for tracking innermost block
This commit is preparation for a later change, at this point there
should be no user visible change.

We currently maintain a global innermost_block which tracks the most
inner block encountered when parsing an expression.

This commit wraps the innermost_block into a new class, and switches all
direct accesses to the variable to use the class API.

gdb/ChangeLog:

	* ada-exp.y (write_var_from_sym): Switch to innermost_block API.
	* ada-lang.c (resolve_subexp): Likewise.
	* breakpoint.c (set_breakpoint_condition) Likewise.
	(watch_command_1) Likewise.
	* c-exp.y (variable): Likewise.
	* d-exp.y (PrimaryExpression): Likewise.
	* f-exp.y (variable): Likewise.
	* go-exp.y (variable): Likewise.
	* m2-exp.y (variable): Likewise.
	* objfiles.c (objfile::~objfile): Likewise.
	* p-exp.y (variable): Likewise.
	* parse.c (innermost_block): Change type.
	* parser-defs.h (class innermost_block_tracker): New.
	(innermost_block): Change to innermost_block_tracker.
	* printcmd.c (display_command): Switch to innermost_block API.
	(do_one_display): Likewise.
	* rust-exp.y (do_one_display): Likewise.
	* symfile.c (clear_symtab_users): Likewise.
	* varobj.c (varobj_create): Switch to innermost_block API, replace
	use of innermost_block with block stored on varobj object.
2018-01-21 15:15:47 +00:00
Pedro Alves d4c2a405cb Fix gdb.ada/complete.exp's "complete break ada" test (PR gdb/22670)
This patch fixes the regression covered by the test added by:

    commit 344420da6b
    Date: Thu Jan 4 03:30:37 2018 -0500
    Subject: Add "complete break ada" test to gdb.ada/complete.exp

The regression had been introduced by:

    commit b5ec771e60
    Date:   Wed Nov 8 14:22:32 2017 +0000
    Subject: Introduce lookup_name_info and generalize Ada's FULL/WILD name matching

The gist of it is that linespec completion in Ada mode is generating
additional matches that should not appear in the match list
(internally generated symbols, or symbols that should be enclosed
between "<...>").  These extraneous entries have uppercase characters, such as:

    break ada__stringsS
    break ada__strings__R11s
    [etc]

These matches come from minimal symbols.  The problem is that Ada
minsyms end up with no language set (language_auto), and thus we end
up using the generic symbol name matcher for those instead of Ada's.
We already had a special case for in compare_symbol_name to handle
this, but it was limited to expressions, while the case at hand is
completing a linespec.  Fix this by applying the special case to
linespec completion as well.  I.e., remove the EXPRESSION check from
compare_symbol_name.  That alone turns out to not be sufficient still
-- GDB would still show a couple entries that shouldn't be there:

~~
    break ada__exceptions__exception_data__append_info_exception_name__2Xn
    break ada__exceptions__exception_data__exception_name_length__2Xn
~~

The reason is that these minimal symbols end up with their language
set to language_cplus / C++, because those encoded names manage to
demangle successfully as C++ symbols (using an old C++ mangling
scheme):

  $ echo ada__exceptions__exception_data__append_info_exception_name__2Xn | c++filt
  Xn::ada__exceptions__exception_data__append_info_exception_name(void)

It's unfortunate that Ada's encoding scheme doesn't start with some
unique prefix like "_Z" in the C++ Itanium ABI mangling scheme.  For
now, paper over that by treating C++ minsyms as Ada minsyms.

gdb/ChangeLog:
2018-01-10  Pedro Alves  <palves@redhat.com>

        PR gdb/22670
	* ada-lang.c (ada_collect_symbol_completion_matches): If the
	minsym's language is language_auto or language_cplus, pass down
	language_ada instead.
	* symtab.c (compare_symbol_name): Don't frob symbol language here.

gdb/testsuite/ChangeLog:
2018-01-10  Pedro Alves  <palves@redhat.com>

        PR gdb/22670
	* gdb.ada/complete.exp ("complete break ada"): Replace kfail with
	a fail.
2018-01-10 20:46:09 +00:00
Pedro Alves de63c46b54 Fix regresssion(internal-error) printing subprogram argument (PR gdb/22670)
At <https://sourceware.org/ml/gdb-patches/2017-12/msg00298.html>, Joel
wrote:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider the following code which first declares a tagged type (the
equivalent of a class in Ada), and then a procedure which takes a
pointer (access) to this type's 'Class.

    package Pck is
       type Top_T is tagged record
          N : Integer := 1;
       end record;
       procedure Inspect (Obj: access Top_T'Class);
    end Pck;

Putting a breakpoint in that procedure and then running to it triggers
an internal error:

    (gdb) break inspect
    (gdb) continue
    Breakpoint 1, pck.inspect (obj=0x63e010
    /[...]/gdb/stack.c:621: internal-error: void print_frame_args(symbol*, frame_info*, int, ui_file*): Assertion `nsym != NULL' failed.

What's special about this subprogram is that it takes an access to
what we call a 'Class type, and for implementation reasons, the
compiler adds an extra argument named "objL". If you are curious why,
it allows the compiler for perform dynamic accessibility checks that
are mandated by the language.

If we look at the location where we get the internal error (in
stack.c), we find that we are looping over the symbol of each
parameter, and for each parameter, we do:

    /* We have to look up the symbol because arguments can have
       two entries (one a parameter, one a local) and the one we
       want is the local, which lookup_symbol will find for us.
    [...]
        nsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
                              b, VAR_DOMAIN, NULL).symbol;
        gdb_assert (nsym != NULL);

The lookup_symbol goes through the lookup structure, which means the
symbol's linkage name ("objL") gets transformed into a
lookup_name_info object (in block_lookup_symbol), before it gets fed
to the block symbol dictionary iterators.  This, in turn, triggers the
symbol matching by comparing the "lookup" name which, for Ada, means
among other things, lowercasing the given name to "objl".  It is this
transformation that causes the lookup find no matches, and therefore
trip this assertion.

Going back to the "offending" call to lookup_symbol in stack.c, what
we are trying to do, here, is do a lookup by linkage name.  So, I
think what we mean to be doing is a completely literal symbol lookup,
so maybe not even strcmp_iw, but actually just plain strcmp???

In the past, in practice, you could get that effect by doing a lookup
using the C language. But that doesn't work, because we still end up
somehow using Ada's lookup_name routine which transforms "objL".

So, ideally, as I hinted before, I think what we need is a way to
perform a literal lookup so that searches by linkage names like the
above can be performed.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This commit fixes the problem by implementing something similar to
Joel's literal idea, but with some important differences.

I considered adding a symbol_name_match_type::LINKAGE and supporting
searching by linkage name for any language, but the problem with that
is that the dictionaries only work with SYMBOL_SEARCH_NAME, because
that's what is used for hashing.  We'd need separate dictionaries for
hashed linkage names.

So with the current symbol tables infrastructure, it's not literal
linkage names that we want to pass down, but instead literal _search_
names (SYMBOL_SEARCH_NAME, etc.).

However, psymbols have no overload/function parameter info in C++, so
a straight strcmp doesn't work properly for C++ name matching.

So what we do is be a little less aggressive then and add a new
symbol_name_match_type::SEARCH_SYMBOL instead that takes as input a
non-user-input search symbol, and then we skip any decoding/demangling
steps and make:

 - Ada treat that as a verbatim match,
 - other languages treat it as symbol_name_match_type::FULL.

This also fixes the new '"maint check-psymtabs" for Ada' testcase for
me (gdb.ada/maint_with_ada.exp).  I've not removed the kfail yet
because Joel still sees that testcase failing with this patch.
That'll be fixed in follow up patches.

gdb/ChangeLog:
2018-01-05  Pedro Alves  <palves@redhat.com>

	PR gdb/22670
	* ada-lang.c (literal_symbol_name_matcher): New function.
	(ada_get_symbol_name_matcher): Use it for
	symbol_name_match_type::SEARCH_NAME.
	* block.c (block_lookup_symbol): New parameter 'match_type'.  Pass
	it down instead of assuming symbol_name_match_type::FULL.
	* block.h (block_lookup_symbol): New parameter 'match_type'.
	* c-valprint.c (print_unpacked_pointer): Use
	lookup_symbol_search_name instead of lookup_symbol.
	* compile/compile-object-load.c (get_out_value_type): Pass down
	symbol_name_match_type::SEARCH_NAME.
	* cp-namespace.c (cp_basic_lookup_symbol): Pass down
	symbol_name_match_type::FULL.
	* cp-support.c (cp_get_symbol_name_matcher): Handle
	symbol_name_match_type::SEARCH_NAME.
	* infrun.c (insert_exception_resume_breakpoint): Use
	lookup_symbol_search_name.
	* p-valprint.c (pascal_val_print): Use lookup_symbol_search_name.
	* psymtab.c (maintenance_check_psymtabs): Use
	symbol_name_match_type::SEARCH_NAME and SYMBOL_SEARCH_NAME.
	* stack.c (print_frame_args): Use lookup_symbol_search_name and
	SYMBOL_SEARCH_NAME.
	* symtab.c (lookup_local_symbol): Don't demangle the lookup name
	if symbol_name_match_type::SEARCH_NAME.
	(lookup_symbol_in_language): Pass down
	symbol_name_match_type::FULL.
	(lookup_symbol_search_name): New.
	(lookup_language_this): Pass down
	symbol_name_match_type::SEARCH_NAME.
	(lookup_symbol_aux, lookup_local_symbol): New parameter
	'match_type'.  Pass it down.
	* symtab.h (symbol_name_match_type::SEARCH_NAME): New enumerator.
	(lookup_symbol_search_name): New declaration.
	(lookup_symbol_in_block): New 'match_type' parameter.

gdb/testsuite/ChangeLog:
2018-01-05  Joel Brobecker  <brobecker@adacore.com>

	PR gdb/22670
	* gdb.ada/access_tagged_param.exp: New file.
	* gdb.ada/access_tagged_param/foo.adb: New file.
2018-01-05 16:07:00 +00:00
Pedro Alves f98fc17b3a Fix gdb.ada/info_addr_mixed_case.exp (PR gdb/22670)
The comments about mixed case in the testcase are actually a red
herring.  The problem here is that we'd get to
ada_lookup_encoded_symbol with "my_table", which wraps the looked up
name in "<>"s to force a verbatim match, and that in turn disables
wild matching.

Fix this by swapping around the internals of ada_lookup_encoded_symbol
and ada_lookup_symbol, thus avoiding the encoding and
verbatim-wrapping in the ada_lookup_symbol case, the case that starts
with a user-provided lookup name.

Ada encoding is still done of course, in the ada_lookup_name_info
ctor.  This could be also seen as avoiding the double-encoding problem
in a different way.

gdb/ChangeLog:
2018-01-05  Pedro Alves  <palves@redhat.com>

	PR gdb/22670
	* ada-lang.c (ada_lookup_encoded_symbol): Reimplement in terms of
	ada_lookup_symbol.
	(ada_lookup_symbol): Reimplement in terms of
	ada_lookup_symbol_list, bits factored out from
	ada_lookup_encoded_symbol.

gdb/testsuite/ChangeLog:
2018-01-05  Pedro Alves  <palves@redhat.com>

	PR gdb/22670
	* gdb.ada/info_addr_mixed_case.exp: Remove kfail.  Extend test to
	exercise lower case too, and to exercise both full matching and
	wild matching.
2018-01-05 16:01:57 +00:00
Jerome Guitton 7150d33cda (Ada) Fix Length attribute on array access
Consider the following variable "Indexed_By_Enum", declared as
an access to an array whose index type is an enumerated type
whose underlying values have "gaps":

   type Enum_With_Gaps is (LIT0, LIT1, LIT2, LIT3, LIT4);
   for Enum_With_Gaps use (LIT0 => 3,
                           LIT1 => 5,
                           LIT2 => 8,
                           LIT3 => 13,
                           LIT4 => 21);
   for Enum_With_Gaps'size use 16;

   type MyWord is range 0 .. 16#FFFF# ;
   for MyWord'Size use 16;

   type AR is array (Enum_With_Gaps range <>) of MyWord;
   type AR_Access is access AR;

   Indexed_By_Enum : AR_Access :=
     new AR'(LIT1 => 1,  LIT2 => 43, LIT3 => 42, LIT4 => 41);

Trying to print the length (number of elements) of this array using
the 'Length attribute does not work:

    (gdb) print indexed_by_enum'length
    'POS only defined on discrete types

The problem occurs while trying to get the array's index type.
It was using TYPE_INDEX_TYPE for that. It does not work for Ada arrays
in general; use ada_index_type instead.

gdb/ChangeLog:

	* ada-lang.c (ada_array_length): Use ada_index_type instead of
	TYPE_INDEX_TYPE.

gdb/testsuite/ChangeLog:

        * gdb.ada/arr_acc_idx_w_gap: New testcase.

Tested on x86_64-linux.
2018-01-05 03:14:19 -05:00
Joel Brobecker cc0e770c0d memory error printing component of record from convenience variable
Consider the following situation Ada code:

   type Kind_T is (One, Two, Three);
   type Time_Set_T is array (Kind_T) of Integer;

   type T  is record
      Started    : Time_Set_T;
   end record;

   Null_T : constant T := (Started => (others => 0));

   My_Item : Pck.T := Pck.Null_T;

Trying to print the value of My_Item.Started is no problem:

    (gdb) p item.started
    $1 = (0, 0, 0)

However, if you save My_Item into a convenience variable first,
and then try to print a component of that record, you get
an unexpected memory error, instead of getting the same result.
For instance:

    (gdb) set variable $item := item
    (gdb) p $item.started
    Cannot access memory at address 0x0

The issue occurs when, after we extracted the component from
the convenience variable, we next try to "fix" it (which is
ada-lang speak for resolving the type into a static type).
This is done in ada_to_fixed_value, which delegates to
ada_to_fixed_value_create via:

    val = ada_to_fixed_value_create (value_type (val),
                                     value_address (val), val);

And looking at ada_to_fixed_value_create, we see that:

  struct type *type = ada_to_fixed_type (type0, 0, address, NULL, 1);

  if (type == type0 && val0 != NULL)
    return val0;
  else
    return value_from_contents_and_address (type, 0, address);

The part that interests us, in this case, is the "else" branch,
where we obviously make the implicit assumption that our object
has an address, which is not true, in this case, because we are
actually dealing with a convenience variable.

This patch plugs that hole by adding special handing for situations
where val does not live in memory. In that case, we just create
a not_lval value using val's contents.

gdb/ChangeLog:

        * ada-lang.c (ada_to_fixed_value_create): Add handling of
        the case where VALUE_LVAL (val0) is not lval_memory.

gdb/testsuite/ChangeLog:

        * gdb.ada/convvar_comp: New testcase.

Tested on x86_64-linux.
2018-01-05 02:41:28 -05:00
Xavier Roirand 9f757bf7fc (Ada) New command to stop at start of exception handler.
When using gdb for debugging Ada source code, there are several catchpoint
types you can define in order to stop upon certain conditions.  Let's
use this small example:

procedure Foo is
begin
   begin
      raise Constraint_Error;
   exception
      when Program_Error =>
         null;
      when Constraint_Error =>
         null;
      when others =>
         null;
   end;
end Foo;

One can stop when the exception is being raised by using the exception
catchpoint like below:

(gdb) catch exception
Catchpoint 1: all Ada exceptions
(gdb)

In that case, when running Foo, gdb will stop at the line where the exception
was raised:

   begin
>>>   raise Constraint_Error;
   exception

This patch introduces new type of catchpoint, when the user wants to stop
at the location of the exception handling.
Imagine we want to stop on any exception handled by the program, we can do:

(gdb) catch handlers
Catchpoint 1: all Ada exceptions handlers
(gdb) r
Starting program: /tmp/foo

By doing so, when running Foo, gdb will stop here:

Catchpoint 1, exception at 0x000000000040255a in foo () at foo.adb:25
25          when Constraint_Error =>
(gdb)

It is also possible to stop when the Constraint_Error exception is being
handled in this program.  With this patch, we can use:

(gdb) catch handlers Constraint_Error
Catchpoint 1: `Constraint_Error' Ada exception handlers
(gdb)

Like for other catchpoint, you can set a condition when adding a catchpoint
on exception handlers.
Here the handlers catchpoint checks Global_Var:

(gdb) catch handlers Constraint_Error if Global_Var /= 0

gdb/ChangeLog:

        * ada-lang.h (ada_exception_catchpoint_kind) <ada_catch_handlers>:
        Add field.
        * ada-lang.c (struct exception_support_info) <catch_handlers_sym>:
        Add field.
        (default_exception_support_info) <catch_handlers_sym>: Add field.
        (exception_support_info_fallback) <catch_handlers_sym>: Add field.
        (ada_exception_name_addr_1): Add "catch handlers" handling.
        (ada_exception_catchpoint_cond_string) <ex>: New parameter.
        Update all callers.
        (create_excep_cond_exprs) <ex>: Add parameter.
        (re_set_exception): Update create_excep_cond_exprs call.
        (print_it_exception, print_one_exception, print_mention_exception)
        (print_recreate_exception): Add "catch handler" handling.
        (allocate_location_catch_handlers, re_set_catch_handlers)
        (check_status_catch_handlers, print_it_catch_handlers)
        (print_one_catch_handlers, print_mention_catch_handlers)
        (print_recreate_catch_handlers): New function.
        (catch_handlers_breakpoint_ops): New variable.
        (catch_ada_exception_command_split) <is_catch_handlers_cmd>:
        Add parameter.  Add "catch handler" handling.
        (ada_exception_sym_name, ada_exception_breakpoint_ops):
        Add "catch handler" handling.
        (ada_exception_catchpoint_cond_string): Add "catch handler"
        handling.
        (create_ada_exception_catchpoint): Update create_excep_cond_exprs
        call.
        (catch_ada_handlers_command): New function.
        (initialize_ada_catchpoint_ops): Initialize "catch handlers"
        operations structure.
        (_initialize_ada_language): Add "catch handlers" command entry.
        * NEWS: Document "catch handlers" feature.

gdb/doc/ChangeLog:

        * gdb.texinfo (Set Catchpoints): Add documentation for new
        "catch handlers" action.

gdb/testsuite/ChangeLog:

        * gdb.ada/excep_handle.exp: New testcase.
        * gdb.ada/excep_handle/foo.adb: New file.
        * gdb.ada/excep_handle/pck.ads: New file.

Tested on x86_64-linux.
2018-01-03 11:02:53 +01:00
Joel Brobecker 9fe561ab7f [gdb/Ada] slices of arrays with dynamic strides
Consider the following Ada code:

       procedure Nested (L, U : Integer) is
          subtype Small_Type is Integer range L .. U;
          type Record_Type (I : Small_Type := L) is record
             S : String (1 .. I);
          end record;
          type Array_Type is array (Integer range <>) of Record_Type;

          A1 : Array_Type :=
            (1 => (I => 0, S => <>),
             2 => (I => 1, S => "A"),
             3 => (I => 2, S => "AB"));

          procedure Discard (R : Record_Type) is
          begin
             null;
          end Discard;

       begin
          Discard (A1 (1));  -- STOP
       end;

Trying to print a slice of that array currently yields:

    (gdb) p a1(1..3)
    $1 = ((i => 0, s => ""), (i => 0, s => ""), (i => 0, s => ""))

We expected instead:

    (gdb) p a1(1..3)
    $1 = ((i => 0, s => ""), (i => 1, s => "A"), (i => 2, s => "AB"))

This is because the functions we use in ada-lang.c to create the type
of the array slice (ada_value_slice and ada_value_slice_from_ptr) was
not taking into account the stride of the array. This patch fixes this.

gdb/ChangeLog:

        * ada-lang.c (ada_value_slice_from_ptr): Take array stride into
        account when creating the array type of the slice.
        (ada_value_slice): Likewise.

gdb/testsuite/ChangeLog:

        * gdb.ada/dyn_stride.exp: Add slice test.

Note that, with the current use of ada_value_slice, the enhancement
to handle dynamic array strides seems unnecessary, because I do not
see how an array with a dynamic stride can be referenced by either
by reference or pointer. Since references are coerced to array pointers,
in both cases, the slice is performed by ada_value_slice_from_ptr.
But ada_value_slice is enhanced nonetheless, in the spirit of making
the code more robust, in case we missed something, and also as similar
as possible with its from_ptr counterpart.

tested on x86_64-linux.
2018-01-01 22:53:55 -05:00
Joel Brobecker e2882c8578 Update copyright year range in all GDB files
gdb/ChangeLog:

        Update copyright year range in all GDB files
2018-01-02 07:38:06 +04:00
Tom Tromey e9d9f57e11 C++-ify parser_state
This mildly C++-ifies parser_state and stap_parse_info -- just enough
to remove some cleanups.

This version includes the changes implemented by Simon.

Regression tested by the buildbot.

gdb/ChangeLog
2017-12-30  Tom Tromey  <tom@tromey.com>
	    Simon Marchi  <simon.marchi@ericsson.com>

	* stap-probe.h (struct stap_parse_info): Add constructor,
	destructor.
	* stap-probe.c (stap_parse_argument): Update.
	* rust-exp.y (rust_lex_tests): Update.
	* parser-defs.h (struct parser_state): Add constructor,
	destructor, release method.
	<expout>: Change type to expression_up.
	(null_post_parser): Change type.
	(initialize_expout, reallocate_expout): Remove.
	* parse.c (parser_state::parser_state): Rename from
	initialize_expout.
	(parser_state::release): Rename from reallocate_expout.
	(write_exp_elt, parse_exp_in_context_1, increase_expout_size):
	Update.
	(null_post_parser): Change type of "exp".
	* dtrace-probe.c (dtrace_probe::build_arg_exprs): Update.
	* ada-lang.c (resolve, resolve_subexp)
	(replace_operator_with_call): Change type of "expp".
	* language.h (struct language_defn) <la_post_parser>: Change type
	of "expp".
2017-12-30 17:05:37 -07:00
Joel Brobecker eccab96d54 improved error message when getting an exception printing a variable
Consider the following Ada code defining a global variable whose
type is an array of static bounds (1 .. 2), but where its elements
are a variant record whose size is not statically known:

    type Ints is array (Natural range <>) of Integer;
    type Bounded_Ints (Max_Size : Natural) is record
       Length : Natural := 0;
       Objs   : Ints (1 .. Max_Size);
    end record;

    type Ints_Doubled is array (1 .. 2) of Bounded_Ints (Idem (0));

    Global : Ints_Doubled;

When compiling this program at -O2 using a GCC-6.4-based compiler
on x86_64-linux, trying to print the value of that global variable
yields:

    (gdb) p global
    $1 =

Let's look at the debugging info, which starts with the global
variable itself...

        .uleb128 0x19   # (DIE (0x25e) DW_TAG_variable)
        .long   .LASF32 # DW_AT_name: "fd__global"
        .long   0x273   # DW_AT_type

... its type is a reference to a typedef ...

        .uleb128 0x14   # (DIE (0x273) DW_TAG_reference_type)
        .byte   0x8     # DW_AT_byte_size
        .long   0x202   # DW_AT_type
        [...]
        .uleb128 0x15   # (DIE (0x202) DW_TAG_typedef)
        .long   .LASF19 # DW_AT_name: "fd__ints_doubled"
        .long   0x20d   # DW_AT_type

... of an array (1..2) ...

        .uleb128 0x2    # (DIE (0x20d) DW_TAG_array_type)
        .long   .LASF19 # DW_AT_name: "fd__ints_doubled"
        .long   0x15b   # DW_AT_type
        .long   0x221   # DW_AT_sibling
        .uleb128 0x16   # (DIE (0x21a) DW_TAG_subrange_type)
        .long   0x40    # DW_AT_type
        .sleb128 2      # DW_AT_upper_bound
        .byte   0       # end of children of DIE 0x20d

... of a struct whose name is fd__Tints_doubledC:

        .uleb128 0x10   # (DIE (0x15b) DW_TAG_structure_type)
        .long   .LASF11 # DW_AT_name: "fd__Tints_doubledC"
        .long   0x1e4   # DW_AT_GNAT_descriptive_type
                        # DW_AT_artificial
        .long   0x1e4   # DW_AT_sibling
        .uleb128 0x7    # (DIE (0x16a) DW_TAG_member)
        .long   .LASF4  # DW_AT_name: "max_size"
        [snip]

The error occurs while Ada evaluator is trying to "fix"
the element type inside the array, so as to determine its actual
size. For that, it searches for a parallel "XVZ" variable,
which, when found, contains the object's actual size.

Unfortunately in our case, the variable exists but has been
optimized out, as seen by the presence of a variable DIE in
the debugging info, but with no address attribute:

        .uleb128 0x18   # (DIE (0x24e) DW_TAG_variable)
        .long   .LASF31 # DW_AT_name: "fd__Tints_doubledC___XVZ"
        .long   0x257   # DW_AT_type
                        # DW_AT_artificial

Discussing this with some members of AdaCore's compiler team,
it is expected that the optimizer can get rid of this variable,
and we don't want to pessimize the code just to improve debuggability,
since -O2 is about performance. So, the idea of this patch is
not to make it work, but provide a bit more information to help
users understand what kind of error is preventing GDB from being
able to print the variable's value.

The first hurdle we had to clear was the fact that ada_val_print
traps all exceptions (including QUIT ones!), and does so completly
silently. So, the fix was to add a trace of the exception being
generated. While doing so, we fix an old XXX/FIXME by only catching
errors, letting QUIT exceptions go through.

Once this is done, we now get an error message, which gives a first
clue as to what was happening:

    (gdb) p fd.global
    $1 = <error reading variable: value has been optimized out>

However, it would be more useful to know which value it was
that was optimized out. For that purpose, we enhanced
ada-lang.c::ada_to_fixed_type_1 so as to re-throw the error
with a message which indicates which variable we failed to read.

With those changes, the new output is now:

    (gdb) p fd.global
    $1 = <error reading variable: unable to read value of fd__Tints_doubledC___XVZ (value has been optimized out)>

gdb/ChangeLog:

        * ada-lang.c (ada_to_fixed_type_1): Rethrow errors with
        a more detailed exception message when getting an exception
        while trying to read the value of an XVZ variable.
        * ada-valprint.c (ada_val_print): Only catch RETURN_MASK_ERROR
        exceptions.  Print an error message when an exception is caught.

gdb/testsuite/ChangeLog:

        * gdb.dwarf2/ada-valprint-error.c: New file.
        * gdb.dwarf2/ada-valprint-error.exp: New file.

Tested on x86_64-linux
2017-12-17 22:39:33 -05:00
Joel Brobecker 0e2da9f013 (Ada) crash assigning to record component which is an array
Consider the following code, which declares a variabled called "input"
of type "parameter", which is a record with one component called "u2",
where the type of that component is a simple 3-element array of
floating point values:

   type Float_Array_3 is array (1 .. 3) of Float;
   type parameters is record
      u2 : Float_Array_3;
   end record;
   input : parameters;

Trying to assign a value to input.u2 causes GDB to crash:

    (gdb) p input.u2 := (0.25,0.5,0.75)
    [1]    20228 segmentation fault (core dumped) [...]/gdb

The crash occurs because input.u2 is described in the debugging
info as a typedef of an array. Indeed, input's type is:

 <1><ae9>: Abbrev Number: 7 (DW_TAG_structure_type)
    <aea>   DW_AT_name        : (indirect string, offset: 0x1045): target_wrapper__parameters
    [...]
 <2><af5>: Abbrev Number: 8 (DW_TAG_member)
    <af6>   DW_AT_name        : u2
    [...]
    <afb>   DW_AT_type        : <0xaca>

and, looking at DIE 0xaca to get input.u2's type, we see:

 <1><aca>: Abbrev Number: 4 (DW_TAG_typedef)
    <acb>   DW_AT_name        : (indirect string, offset: 0x1060): target_wrapper__float_array_3
    [...]
    <ad1>   DW_AT_type        : <0xad5>

We can also confirm, following the DW_AT_type attribute (0xad5), that
it's a typedef of our array:

 <1><ad5>: Abbrev Number: 5 (DW_TAG_array_type)
    <ad6>   DW_AT_name        : (indirect string, offset: 0x1060): target_wrapper__float_array_3
    [...]

In fact, this scenario uncovered 2 areas where typedef handling
is missing, thus causing a crash. The first happens inside
assign_aggregate:

   if (ada_is_direct_array_type (lhs_type))
     {
       lhs = ada_coerce_to_simple_array (lhs);
       lhs_type = value_type (lhs);
       low_index = TYPE_ARRAY_LOWER_BOUND_VALUE (lhs_type);
       high_index = TYPE_ARRAY_UPPER_BOUND_VALUE (lhs_type);
     }

Here, lhs_type is a TYPE_CODE_TYPEDEF. ada_is_direct_array_type
knows how to handle it, but TYPE_ARRAY_LOWER_BOUND_VALUE assumes
that the given type is a TYPE_CODE_ARRAY. As such, it ends up
accessing some fields in lhs_type which it shouldn't, and kaboom.

We fixed this issue by making sure that the TYPE_CODE_TYPEDEF
layer gets stripped.

Once this is done, we hit a different kind of error, also leading to
a SEGV, this time in assign_component. The code looks like this:

  if (TYPE_CODE (value_type (lhs)) == TYPE_CODE_ARRAY)
    [...]
  else
    [...]

Because once again lhs is a TYPE_CODE_TYPEDEF, the check fail,
and we end up assuming that lhs is a struct, executing the "else"
block, which is:

  else
    {
      elt = ada_index_struct_field (index, lhs, 0, value_type (lhs));
      elt = ada_to_fixed_value (elt);
    }

Since lhs is not a struct, ada_index_struct_field returns NULL,
which ada_to_fixed_value does not handle well, hence another crash.

This patch fixes this other issue the same way, by stripping
TYPE_CODE_TYPEDEF layers.

gdb/ChangeLog:

        * ada-lang.c (assign_component): Strip any TYPE_CODE_TYPEDEF
        layer from lhs' type.
        (assign_aggregate): Likewise.

gdb/testsuite:

        * gdb.ada/assign_arr: New testcase.

Tested on x86_64-linux.
2017-12-17 22:11:40 -05:00
Xavier Roirand cb923fcc23 Ada: fix bad handling in ada_convert_actual
Using this small example:

procedure Foo is

   type Integer_Access is access all Integer;

   procedure P (A : Integer_Access) is
   begin
      null;
   end P;

begin
   P (null);
end Foo;

and doing this debug session:

(gdb) b p
Breakpoint 1 at 0x402d67: file foo.adb, line 7.
(gdb) print p(null)

Breakpoint 1, foo.p (a=0x641010) at foo.adb:10
...                  ^^^^^^^^^^

shows that something goes wrong between the initial null value and the
received parameter value in the 'f' function.
The value for the parameter 'a' we get is the address of the value we
would expect instead of the value itself. This can be checked by doing:

(gdb) p *a
$1 = 0

Before this fix, in ada_convert_value, this function was looking to the
actual value (the null value here) to determine if the formal (parameter
'a' in the procedure 'P' in this exemple) requires a pointer or not which
is a wrong assumption and leads to push the address of the value to the
inferior instead of the value itself.

This is fixed by this patch.

gdb/ChangeLog:

        * ada-lang.c (ada_convert_actual): Change the way actual value
        are passed to the inferior when the inferior expects a pointer type.

gdb/testsuite/ChangeLog:

        * gdb.ada/funcall_ptr: New testcase.

Tested on x86_64-linux.
2017-12-17 22:01:32 -05:00
Xavier Roirand 828d584679 (Ada) Handle same component names when searching in tagged types
Consider the following code:

   type Top_T is tagged record
      N : Integer := 1;
      U : Integer := 974;
      A : Integer := 48;
   end record;

   type Middle_T is new Top.Top_T with record
      N : Character := 'a';
      C : Integer := 3;
   end record;

  type Bottom_T is new Middle.Middle_T with record
     N : Float := 4.0;
     C : Character := '5';
     X : Integer := 6;
     A : Character := 'J';
  end record;

Tagged records in Ada provide object-oriented features, and what
is interesting in the code above is that a child tagged record
introduce additional components (fields) which sometimes have
the same name as one of the components in the parent. For instance,
Bottom_T introduces a component named "C", while at the same time
inheriting from Middle_T which also has a component named "C";
so, in essence, type Bottom_T has two components with the same name!

And before people start wondering why the language can possibly
be allowing that, this can only happen if the parent type has
a private definition. In our case, this was brought to our attention
when the parent was a generic paramenter.

With that in mind...  Let's say we now have a variable declared
and initialized as follow:

  TC : Top_A := new Bottom_T;

And then we use this variable to call this function

  procedure Assign (Obj: in out Top_T; TV : Integer);

  as follow:

  Assign (Top_T (B), 12);

Now, we're in the debugger, and we're inside that procedure
(Top.Assign in our gdb testcase), and we want to print
the value of obj.c:

Usually, the tagged record or one of the parent type owns the
component to print and there's no issue but in this particular
case, what does it mean to ask for Obj.C ? Since the actual
type for object is type Bottom_T, it could mean two things: type
component C from the Middle_T view, but also component C from
Bottom_T. So in that "undefined" case, when the component is
not found in the non-resolved type (which includes all the
components of the parent type), then resolve it and see if we
get better luck once expanded.

In the case of homonyms in the derived tagged type, we don't
guaranty anything, and pick the one that's easiest for us
to program.

This patch fixes the behavior like described above.

gdb/ChangeLog:

        * ada-lang.c (ada_value_primitive_field): Handle field search
        in case of homonyms.
        (find_struct_field): Ditto.
        (ada_search_struct_field): Ditto.
        (ada_value_struct_elt): Ditto.
        (ada_lookup_struct_elt_type): Ditto.

gdb/testsuite/ChangeLog:

        * gdb.ada/same_component_name: New testcase.

Tested on x86_64-linux.
2017-12-14 23:35:38 -05:00
Joel Brobecker 79e8fcaafa Ada: unable to compare strings (Attempt to compare array with non-array)
Consider the following Ada Code:

   type Str is new String (1 .. 4);
   My_str : Str := "ABCD";

This simply declares a 4-character string type. Trying to perform
equality tests using it currently yield an error:

    (gdb) p my_str = my_str
    Attempt to compare array with non-array
    (gdb) p my_str = "ABCD"
    Attempt to compare array with non-array

The error occurs because my_str is defined as an object whose
type is a typdef to a TYPE_CODE_ARRAY, which ada_value_equal
is not expecting at all (yet). This patch fixes this oversight.

gdb/ChangeLog:

        * ada-lang.c (ada_value_equal): Add handling of typedef types
        when comparing array objects.

gdb/testsuite/ChangeLog:

        * gdb.ada/str_binop_equal: New testcase.

Tested on x86_64-linux.
2017-12-14 00:16:39 -05:00
Xavier Roirand 08f49010a1 (Ada) change tagged types base_address computation
There was a difference between C++ dispatch table and Ada's in the
way the Offset_To_Top field is used to determined the base address
of an object:

* in C++ it is a negative offset, so converting abstract interface to
deriving object requires adding this offset to “this”;

* in Ada, it was a positive offset, so the same conversion required
subtracting the offset value.

So in ada, the base address for a tagged type was computed using this formula:

base_address = value_address (obj) - offset_to_top;

The offset_to_top value was previously set to 0 or a positive value.
With recent version of AdaCore's GNAT compiler, the offset has been
changed to match C++, which means it's set to zero or a negative value

As a result, the new formula has to be:

base_address = value_address (obj) + offset_to_top;

Because we want to support old code compiled before GNAT compiler change
done in 19.0w (20171023-64) with this version and future versions of gdb,
then we change the sign of the offset_to_top if required. Required here
means if offset_to_top is positive since it indicates that the code has
been compiled with an old GNAT compiler.

This patch changes the formula as described above.

Also, one side-effect of offset_to_top now being negative is that
we now have to worry about the sign when we read its value from the
inferior. Up to now, we have been reading its value using the data
address builtin type. But since addresses are not always signed, we
now need to make sure we use the proper type (type Storage_Offset
from System.Storage_Elements). Ideally, we would be looking this type
up from the inferior, and then use that type. However, it is not
guaranteed that this type always be described in the debugging
information, so this patch just builds our own, adding it to Ada's
list of primitive types.

gdb/ChangeLog:

        * ada-lang.c (ada_tag_value_at_base_address): Change the way
        tagged type base address is computed.
        (enum ada_primitive_types) <ada_primitive_type_storage_offset>:
        New enumerate.
        (ada_language_arch_info): Set the ada_primitive_type_storage_offset
        element of lai->primitive_type_vector.

Tested on x86_64-linux. Fixes the following tests when using the newer
version of the compiler.

    gdb.ada/iwide.exp: print My_Drawable
    gdb.ada/iwide.exp: print d_access.all
    gdb.ada/iwide.exp: print dp_access.all
    gdb.ada/mi_interface.exp: create ggg1 varobj (unexpected output)
    gdb.ada/mi_interface.exp: list ggg1's children (unexpected output)
    gdb.mi/mi-var-rtti.exp: run to mi-var-rtti.cc:63 (set breakpoint) (unexpected output)
    gdb.mi/mi-var-rtti.exp: run to mi-var-rtti.cc:63 (set breakpoint)
2017-12-11 00:23:06 -05:00
Simon Marchi 798a7429f9 Remove some unused variables
This patch removes some unused variables, found with -Wunused.  I have
not removed everything reported by -Wunused, because some expressions
such as

  struct type *arg_type = check_typedef (value_type);

in bfin-tdep.c could have an unexpected but important side-effect.  I
removed others that I considered more low-risk, such as:

  struct gdbarch *gdbarch = get_objfile_arch (objfile);

I tested building with Python 2/Python 3/no Python, with/without expat,
with/without libipt and with/without babeltrace.

gdb/ChangeLog:

	* ada-lang.c (ada_collect_symbol_completion_matches): Remove
	unused variables.
	(ada_is_redundant_range_encoding): Likewise.
	* ada-varobj.c (ada_varobj_get_value_of_array_variable):
	Likewise.
	* alpha-tdep.c (alpha_software_single_step): Likewise.
	* arm-tdep.c (_initialize_arm_tdep): Likewise.
	* auto-load.c (info_auto_load_cmd): Likewise.
	* break-catch-syscall.c (insert_catch_syscall): Likewise.
	(remove_catch_syscall): Likewise.
	* breakpoint.c (condition_completer): Likewise.
	(clear_command): Likewise.
	(update_breakpoint_locations): Likewise.
	* btrace.c (btrace_disable): Likewise.
	(btrace_teardown): Likewise.
	(btrace_maint_update_pt_packets): Likewise.
	(maint_btrace_clear_cmd): Likewise.
	* cli/cli-decode.c (lookup_cmd_1): Likewise.
	(lookup_cmd_composition): Likewise.
	* cli/cli-dump.c (scan_filename): Likewise.
	(restore_command): Likewise.
	* compile/compile-loc2c.c (compute_stack_depth): Likewise.
	* compile/compile-object-load.c (compile_object_load): Likewise.
	* compile/compile-object-run.c (compile_object_run): Likewise.
	* compile/compile.c (compile_to_object): Likewise.
	* completer.c (filename_completer): Likewise.
	(complete_files_symbols): Likewise.
	(complete_expression): Likewise.
	* corelow.c (core_open): Likewise.
	* ctf.c (ctf_start): Likewise.
	(ctf_write_status): Likewise.
	(ctf_write_uploaded_tsv): Likewise.
	(ctf_write_definition_end): Likewise.
	(ctf_open_dir): Likewise.
	(ctf_xfer_partial): Likewise.
	(ctf_trace_find): Likewise.
	* disasm.c (gdb_pretty_print_disassembler::pretty_print_insn):
	Likewise.
	* dwarf2loc.c (allocate_piece_closure): Likewise.
	(indirect_pieced_value): Likewise.
	(dwarf2_evaluate_loc_desc_full): Likewise.
	* dwarf2read.c (dw2_expand_marked_cus): Likewise.
	(dw2_expand_symtabs_matching): Likewise.
	(dw2_map_symbol_filenames): Likewise.
	(read_and_check_comp_unit_head): Likewise.
	(read_cutu_die_from_dwo): Likewise.
	(lookup_dwo_unit): Likewise.
	(read_comp_units_from_section): Likewise.
	(dwarf2_compute_name): Likewise.
	(handle_DW_AT_stmt_list): Likewise.
	(create_cus_hash_table): Likewise.
	(create_dwp_v2_section): Likewise.
	(dwarf2_rnglists_process): Likewise.
	(dwarf2_ranges_process): Likewise.
	(dwarf2_record_block_ranges): Likewise.
	(is_vtable_name): Likewise.
	(read_formatted_entries): Likewise.
	(skip_form_bytes): Likewise.
	* elfread.c (elf_symtab_read): Likewise.
	* exec.c (exec_file_command): Likewise.
	* f-valprint.c (f_val_print): Likewise.
	(info_common_command_for_block): Likewise.
	* guile/guile.c (initialize_scheme_side): Likewise.
	* guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Likewise.
	* guile/scm-cmd.c (cmdscm_completer): Likewise.
	(gdbscm_register_command_x): Likewise.
	* guile/scm-frame.c (gdbscm_frame_read_var): Likewise.
	* guile/scm-param.c (gdbscm_parameter_value): Likewise.
	* guile/scm-ports.c (file_port_magic): Likewise.
	* guile/scm-pretty-print.c (ppscm_search_pp_list): Likewise.
	(ppscm_pretty_print_one_value): Likewise.
	(ppscm_print_children): Likewise.
	* guile/scm-string.c (gdbscm_string_to_argv): Likewise.
	* guile/scm-symtab.c (gdbscm_sal_symtab): Likewise.
	* guile/scm-type.c (gdbscm_type_next_field_x): Likewise.
	* guile/scm-utils.c (gdbscm_parse_function_args): Likewise.
	* i386-tdep.c (i386_register_reggroup_p): Likewise.
	* infcmd.c (run_command_1): Likewise.
	(until_next_fsm_clean_up): Likewise.
	* linespec.c (linespec_complete): Likewise.
	(find_label_symbols): Likewise.
	* m2-valprint.c (m2_val_print): Likewise.
	* memattr.c (require_user_regions): Likewise.
	(lookup_mem_region): Likewise.
	(disable_mem_command): Likewise.
	(mem_delete): Likewise.
	* mep-tdep.c (mep_register_name): Likewise.
	(mep_analyze_prologue): Likewise.
	* mi/mi-cmd-file.c (mi_cmd_file_list_shared_libraries): Likewise.
	* mi/mi-interp.c (mi_on_sync_execution_done): Likewise.
	* mi/mi-main.c (mi_cmd_trace_frame_collected): Likewise.
	* microblaze-linux-tdep.c (microblaze_linux_init_abi): Likewise.
	* minidebug.c (lzma_open): Likewise.
	* minsyms.c (lookup_minimal_symbol): Likewise.
	* mips-linux-tdep.c (mips64_fill_fpregset): Likewise.
	* mips-tdep.c (mips_stub_frame_sniffer): Likewise.
	(mips_o64_return_value): Likewise.
	(mips_single_step_through_delay): Likewise.
	(_initialize_mips_tdep): Likewise.
	* nios2-tdep.c (nios2_push_dummy_call): Likewise.
	(nios2_software_single_step): Likewise.
	* parse.c (find_minsym_type_and_address): Likewise.
	* psymtab.c (psym_relocate): Likewise.
	* python/py-breakpoint.c (bppy_get_commands): Likewise.
	(gdbpy_breakpoint_modified): Likewise.
	* python/py-infevents.c (create_inferior_call_event_object):
	Likewise.
	* python/py-record-btrace.c (btpy_list_item): Likewise.
	* python/py-type.c (typy_str): Likewise.
	* python/py-value.c (valpy_call): Likewise.
	* python/python.c (do_start_initialization): Likewise.
	* record-btrace.c (record_btrace_insn_history_range): Likewise.
	(record_btrace_call_history_range): Likewise.
	(record_btrace_record_method): Likewise.
	(record_btrace_xfer_partial): Likewise.
	(btrace_get_frame_function): Likewise.
	* record-full.c (record_full_open): Likewise.
	* record.c (get_context_size): Likewise.
	* registry.h (DEFINE_REGISTRY): Likewise.
	* remote-fileio.c (remote_fileio_request): Likewise.
	* remote.c (remote_update_thread_list): Likewise.
	(remote_check_symbols): Likewise.
	(remote_commit_resume): Likewise.
	(remote_interrupt): Likewise.
	(remote_insert_breakpoint): Likewise.
	(compare_sections_command): Likewise.
	* rust-exp.y (super_name): Likewise.
	(lex_string): Likewise.
	(convert_ast_to_type): Likewise.
	(convert_ast_to_expression): Likewise.
	* rust-lang.c (rust_print_struct_def): Likewise.
	(rust_print_type): Likewise.
	(rust_evaluate_subexp): Likewise.
	* rx-tdep.c (rx_register_type): Likewise.
	* ser-event.c (serial_event_clear): Likewise.
	* serial.c (serial_open): Likewise.
	* spu-tdep.c (spu_overlay_new_objfile): Likewise.
	* symfile.c (section_is_overlay): Likewise.
	(overlay_unmapped_address): Likewise.
	(overlay_mapped_address): Likewise.
	(simple_overlay_update_1): Likewise.
	(simple_overlay_update): Likewise.
	* symtab.c (symbol_find_demangled_name): Likewise.
	(search_symbols): Likewise.
	* target-descriptions.c (tdesc_predefined_type): Likewise.
	* target.c (target_commit_resume): Likewise.
	* thread.c (print_selected_thread_frame): Likewise.
	* top.c (new_ui_command): Likewise.
	(gdb_readline_no_editing): Likewise.
	* tracefile-tfile.c (tfile_open): Likewise.
	* tracepoint.c (create_tsv_from_upload): Likewise.
	* utils.c (quit): Likewise.
	(defaulted_query): Likewise.
	* valarith.c (value_concat): Likewise.
	* xml-syscall.c (xml_list_syscalls_by_group): Likewise.
	* xml-tdesc.c (target_fetch_description_xml): Likewise.
	* xtensa-tdep.c (xtensa_pseudo_register_read): Likewise.
	(xtensa_pseudo_register_write): Likewise.

gdb/gdbserver/ChangeLog:

	* regcache.c (registers_to_string): Remove unused variable.
2017-12-05 16:05:50 -05:00
Joel Brobecker ec6a20c268 (Ada) GDB crash printing expression with type casting
One of our users reported that trying to print the following expression,
caused GDB to SEGV:

    (gdb) print some_package.some_type (val)

In this particular instance, the crash occurred inside ada_args_match
because it is given a NULL "func", leading to the SEGV because of:

    struct type *func_type = SYMBOL_TYPE (func);

This NULL symbol comes from a list of symbols which was given to
ada_resolve_function (parameter called "syms") which then iterates
over each of them to discard the ones that don't match the actuals:

     for (k = 0; k < nsyms; k += 1)
       {
         struct type *type = ada_check_typedef (SYMBOL_TYPE (syms[k].symbol));

         if (ada_args_match (syms[k].symbol, args, nargs)
             && (fallback || return_match (type, context_type)))
         [...]
       }

What's really interesting is that, when entering the block above for
the first time, all entries in SYMS have a valid (non-NULL) symbol.
However, once we return from the call to ada_check_typedef, the first
entry of our SYMS table gets set to all zeros:

    (gdb) p syms[0]
    $2 = {symbol = 0x0, block = 0x0}

Hence the call to ada_args_match with a NULL symbol, and the ensuing
SEGV.

To find out why this happen, we need to step back a little and look
at how syms was allocated. This list of symbols comes from a symbol
lookup, which means ada_lookup_symbol_list_worker. We have our first
hint when we look at the function's documentation and see:

    This vector is transient---good only to the next call of
    ada_lookup_symbol_list.

Implementation-wise, this is done by using a static global obstack,
which we just re-initialize each time ada_lookup_symbol_list_worker
gets called:

    obstack_free (&symbol_list_obstack, NULL);
    obstack_init (&symbol_list_obstack);

This property was probably established in order to facilitate the use
of the returned vector, since the users of that function would not have
to worry about releasing that memory when no longer needed. However,
I found during this investigation that it is all to easy to indirectly
trigger another symbol lookup while still using the results of a previous
lookup.

In our particular case, there is the call to ada_check_typedef, which
leads to check_typedef. As it happens, my first symbol had a type which
was a typedef to a stub type, so check_typedef calls lookup_symbol to
find the non-stub version. This in turn eventually leads us back to
ada_lookup_symbol_list_worker, where the first thing it does is free
the memory area when our list of symbols have been residing and then
recreates a new one. in other words, SYMS then becomes a dangling
pointer!

This patch fixes the issue by having ada_lookup_symbol_list_worker
return a copy of the list of symbols, with the responsibility of
deallocating that list now transfered to the users of that list.

More generally speaking, it is absolutely amazing that we haven't seen
consequences of this issue before. This can happen fairly frequently.
For instance, I found that ada-exp.y::write_var_or_type calls
ada_lookup_symbol_list, and then, while processing that list, calls
select_possible_type_sym, which leads to ada_prefer_type, eventually
leading to ada_check_typedef again (via eg. ada_is_array_descriptor_type).

Even more amazing is the fact that, while I was able to produce multiple
scenarios where the corruption occurs, none of them leads to incorrect
behavior at the user level. In other words, it requires a very precise
set of conditions for the corruption to become user-visible, and
despite having a megalarge program where the crash occured, using that
as a template for creating a reproducer did not work (pb goes away).
This is why this patch does not come with a reproducer. On the other hand,
this should not be a problem in terms of testing coverage, as the changes
are made in common areas which, at least for the most part, are routinely
exercised during testing.

gdb/ChangeLog:

        * ada-lang.c (symbol_list_obstack): Delete.
        (resolve_subexp): Make sure "candidates" gets xfree'ed.
        (ada_lookup_symbol_list_worker): Remove the limitation that
        the result is only good until the next call, now making it
        the responsibility of the caller to free the result when no
        longer needed.  Adjust the function's intro comment accordingly.
        (ada_lookup_symbol_list): Adjust the function's intro comment.
        (ada_iterate_over_symbols): Make sure "results" gets xfree'ed.
        (ada_lookup_encoded_symbol, get_var_value): Likewise.
        (_initialize_ada_language): Remove symbol_list_obstack
        initialization.
        * ada-exp.y (block_lookup): Make sure "syms" gets xfree'ed.
        (write_var_or_type, write_name_assoc): Likewise.

Tested on x86_64-linux.
2017-12-01 16:18:30 -05:00
Joel Brobecker f5a9147212 preserve type length in ada-lang.c::to_fixed_range_type
This patch fixes a potential issue which was noticed by code inspection:
ada-lang.c::to_fixed_range_type uses gdbtypes.c::create_static_range_type
to create most of the range type, which relies on create_range_type to
do most of the work. The latter has the following piece of code which
sets the length of the range type to match the length of the index_type:

    if (TYPE_STUB (index_type))
      TYPE_TARGET_STUB (result_type) = 1;
    else
      TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));

In Ada, it is actually possible to have a range type whose size
is smaller than its base type. For instance, with:

    type Unsigned2_T is  range 0 .. 2 ** 16 - 1;
    for Unsigned2_T'SIZE use 16;

The compiler generates the following DWARF:

        .uleb128 0x3    # (DIE (0x4e) DW_TAG_subrange_type)
        .byte   0x2     # DW_AT_byte_size
        .byte   0       # DW_AT_lower_bound
        .value  0xffff  # DW_AT_upper_bound
        .long   .LASF64 # DW_AT_name: "try__unsigned2_t___XDLU_0__65535"
        .long   0x616   # DW_AT_type

... which points to the following base type...

        .uleb128 0x1d   # (DIE (0x616) DW_TAG_base_type)
        .byte   0x4     # DW_AT_byte_size
        .byte   0x5     # DW_AT_encoding
        .long   .LASF57 # DW_AT_name: "try__Tunsigned2_tB"
                        # DW_AT_artificial

... which has a size of 4 bytes.

With a type like this one, create_range_type returns a type whose
size is 4 bytes, instead of 2, which is not what we we would normally
expect.

Currently, this function is only used to handle array index types,
so the length of the type actually does not matter and there should
not be any user-visible consequences of the current behavior. But
it seems best to plug this latent bug now, rather than wait for it
to surface....

gdb/ChangeLog:

        * ada-lang.c (to_fixed_range_type): Make sure that the size
        of the range type being returned is the same as the size
        of the range type being fixed.

Tested on x86_64-linux, no regression.
2017-11-29 18:32:17 -05:00
Pedro Alves a207cff2da Handle custom completion match prefix / LCD
A following patch will add support for wild matching for C++ symbols,
making completing on "b push_ba" on a C++ program complete to
std::vector<...>::push_back, std::string::push_back etc., like:

 (gdb) b push_ba[TAB]
 std::vector<...>::push_back(....)
 std::string<...>::push_back(....)

Currently, we compute the "lowest common denominator" between all
completion candidates (what the input line is adjusted to) as the
common prefix of all matches.  That's problematic with wild matching
as above, as then we'd end up with TAB changing the input line to
"b std::", losing the original input, like:

 (gdb) b push_ba[TAB]
 std::vector<...>::push_back(....)
 std::string<...>::push_back(....)
 (gdb) b std::

while obviously we'd want it to adjust itself to "b push_back(" instead:

 (gdb) b push_ba[TAB]
 std::vector<...>::push_back(....)
 std::string<...>::push_back(....)
 (gdb) b push_back(

This patch adds the core code necessary to support this, though
nothing really makes use of it yet in this patch.

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

	* ada-lang.c (ada_lookup_name_info::matches): Change type of
	parameter from completion_match to completion_match_result.
	Adjust.
	(do_wild_match, do_full_match, ada_symbol_name_matches): Likewise.
	* completer.c (completion_tracker::maybe_add_completion): Add
	match_for_lcd parameter and use it.
	(completion_tracker::add_completion): Likewise.
	* completer.h (class completion_match_for_lcd): New class.
	(completion_match_result::match_for_lcd): New field.
	(completion_match_result::set_match): New method.
	(completion_tracker): Add comments.
	(completion_tracker::add_completion): Add match_for_lcd parameter.
	(completion_tracker::reset_completion_match_result): Reset
	match_for_lcd too.
	(completion_tracker::maybe_add_completion): Add match_for_lcd
	parameter.
	(completion_tracker::m_lowest_common_denominator_unique): Extend
	comments.
	* cp-support.c (cp_symbol_name_matches_1)
	(cp_fq_symbol_name_matches): Change type of parameter from
	completion_match to completion_match_result.  Adjust.
	* language.c (default_symbol_name_matcher): Change type of
	parameter from completion_match to completion_match_result.
	Adjust.
	* language.h (completion_match_for_lcd): Forward declare.
	(default_symbol_name_matcher): Change type of parameter from
	completion_match to completion_match_result.
	* symtab.c (compare_symbol_name): Adjust.
	(completion_list_add_name): Pass the match_for_lcd to the tracker.
	* symtab.h (ada_lookup_name_info::matches): Change type of
	parameter from completion_match to completion_match_result.
	(symbol_name_matcher_ftype): Likewise, and update comments.
2017-11-29 19:33:23 +00:00
Joel Brobecker e547c119d0 (Ada) provide the exception message when hitting an exception catchpoint
This patch enhances the debugger to print the exception message, when
available, as part of an exception catchpoint hit notification (both
GDB/CLI and GDB/MI). For instance, with the following code...

    procedure A is
    begin
       raise Constraint_Error with "hello world";
    end A;

... instead of printing...

    Catchpoint 1, CONSTRAINT_ERROR at 0x000000000040245c in a () at a.adb:3

... it now prints:

    Catchpoint 1, CONSTRAINT_ERROR (hello world) at 0x000000000040245c in a ()
                                   ^^^^^^^^^^^^^

This enhancement requires runtime support. If not present, the debugger
just behaves as before.

In GDB/MI mode, if the exception message is available, it is provided
as an extra field named "exception-message" in the catchpoint notification:

    *stopped,bkptno="1",[...],exception-name="CONSTRAINT_ERROR",
       exception-message="hello world",[...]

gdb/ChangeLog:

        * ada-lang.c (ada_exception_message_1, ada_exception_message):
        New functions.
        (print_it_exception): If available, display the exception
        message as well.
        * NEWS: Document new feature.

gdb/doc/ChangeLog:

        * gdb.texinfo (GDB/MI Ada Exception Information): Document
        new "exception-message" field.

gdb/testsuite/ChangeLog:

        * gdb.ada/catch_ex.exp, gdb.ada/mi_catch_ex.exp,
        gdb.ada/mi_ex_cond.exp: Accept optional exception message in
        when hitting an exception catchpoint.
2017-11-24 17:15:30 -05:00
Joel Brobecker ced9779b4c (Ada) fix handling of minimal symbols (UNOP_CAST and UNOP_ADDR)
Consider a program which provides a symbol without debugging
information. For instance, compiling the following code without -g:

    Some_Minimal_Symbol : Integer := 1234;
    pragma Export (C, Some_Minimal_Symbol, "some_minsym");

Trying to print this variable with GDB now causes an error, which
is now expected:

    (gdb) p some_minsym
    'some_minsym' has unknown type; cast it to its declared type

However, trying to cast this symbol, or to take its address
does not work:

    (gdb) p integer(some_minsym)
    'some_minsym' has unknown type; cast it to its declared type
    (gdb) p &some_minsym
    'some_minsym' has unknown type; cast it to its declared type

Another manisfestation of this issue can be seen when trying to
insert an Ada exception catchpoint for a specific standard exception
(this only occurs if the Ada runtime is built without debugging
information, which is the default).  For instance:

    $ (gdb) catch exception constraint_error
    warning: failed to reevaluate internal exception condition for catchpoint 0: 'constraint_error' has unknown type; cast it to its declared type

This is because, internally, the cachtpoint uses a condition referencing
a minimal symbol, more precisely:

   long_integer (e) = long_integer (&constraint_error)

This patch fixes all issues listed above:

  1. resolve_subexp: Special-case the handling of OP_VAR_MSYM_VALUE
     expression elements, where there are no ambiguities to be resolved
     in that situation;

  2. ada_evaluate_subexp: Enhance the handling of the UNOP_CAST
     handling so as to process the case where the target of
     the cast is a minimal symbol (as well as a symbol with debugging
     information). This mimics what's done in C.

gdb/ChangeLog:

        * ada-lang.c (resolve_subexp): Add handling of OP_VAR_MSYM_VALUE.
        (ada_evaluate_subexp_for_cast): New function.
        (ada_evaluate_subexp) <UNOP_CAST>: Replace code by call to
        ada_evaluate_subexp_for_cast.
        (ada_evaluate_subexp) <nosideret>: Replace code by call to
        eval_skip_value.
        * eval.c (evaluate_var_value): Make non-static.
        (evaluate_var_msym_value, eval_skip_value): Likewise.
        * value.h (evaluate_var_value, evaluate_var_msym_value)
        (eval_skip_value): Declare.

gdb/testsuite/ChangeLog:

        * gdb.ada/minsyms: New testcase.

Tested on x86_64-linux. No regression. Fixes the following failures:

    catch_ex.exp: continuing to Program_Error exception
    catch_ex.exp: continuing to failed assertion
    catch_ex.exp: continuing to unhandled exception
    catch_ex.exp: continuing to program completion
    complete.exp: p <Exported_Capitalized>
    complete.exp: p Exported_Capitalized
    complete.exp: p exported_capitalized
    mi_catch_ex.exp: catch Program_Error (unexpected output)
    mi_catch_ex.exp: continue to exception catchpoint hit (unknown output after running)
    mi_catch_ex.exp: continue to assert failure catchpoint hit (unknown output after running)
    mi_catch_ex.exp: continue to unhandled exception catchpoint hit (unknown output after running)
    mi_ex_cond.exp: catch C_E if i = 2 (unexpected output)
2017-11-17 12:45:43 -05:00
Joel Brobecker b7e2285082 ada-lang.c::ada_value_cast: remove unused parameter noside
gdb/ChangeLog:

        * ada-lang.c (ada_value_cast): Remove parameter "noside".
        Update all callers.
2017-11-16 19:26:20 -05:00
Joel Brobecker 31432a672f fix typos in ada-lang.c comment
gdb/ChangeLog:

        * ada-lang.c: Fix some typos in the general command documenting
        how Ada expressions are being evaluated and how their result
        is printed.
2017-11-09 12:02:27 -08:00
Pedro Alves f9d67a2239 Make the linespec/location completer ignore data symbols
Currently "b foo[TAB]" offers data symbols as completion candidates.
This doesn't make sense, since you can't set a breakpoint on data
symbols, only on code symbols.

 (gdb) b globa[TAB]
 (gdb) b global [ENTER]
 Function "global" not defined.
 Make breakpoint pending on future shared library load? (y or [n]) n
 (gdb) info symbol global
 global in section .rodata

So this patch makes linespec completion ignore data symbols.

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

	* ada-lang.c (ada_make_symbol_completion_list): Use
	completion_skip_symbol.
	* symtab.c (symbol_is_function_or_method(minimal_symbol*)): New.
	(symbol_is_function_or_method(symbol*)): New.
	(add_symtab_completions): Add complete_symbol_mode parameter.  Use
	completion_skip_symbol.
	(default_collect_symbol_completion_matches_break_on): Use
	completion_skip_symbol.  Pass down mode.
	(collect_file_symbol_completion_matches): Pass down mode.
	* symtab.h (symbol_is_function_or_method): New declarations.
	(completion_skip_symbol): New template function.
2017-11-08 16:06:25 +00:00
Pedro Alves 1b0261195e Simplify completion_list_add_name | remove sym_text / sym_text_len
sym_text_len existed to strip parameters out of the lookup name.  Now
that that's handled by the lookup_name_info objects, the
sym_text/sym_text_len parameters are no longer necessary.

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

	* ada-lang.c (ada_make_symbol_completion_list): Remove text and
	text_len locals and don't pass them down.
	* symtab.c (completion_list_add_name): Remove
	sym_text/sym_text_len parameters and adjust.
	(completion_list_add_symbol, completion_list_add_msymbol)
	(completion_list_objc_symbol, completion_list_add_fields)
	(add_symtab_completions): Likewise.
	(default_collect_symbol_completion_matches_break_on)
	(collect_file_symbol_completion_matches): Remove sym_text_len
	local and don't pass it down.
	* symtab.h (completion_list_add_name): Remove
	sym_text/sym_text_len parameters.
2017-11-08 16:05:45 +00:00
Pedro Alves b5ec771e60 Introduce lookup_name_info and generalize Ada's FULL/WILD name matching
Summary:
 - This is preparation for supporting wild name matching on C++ too.
 - This is also preparation for TAB-completion fixes.
 - Makes symbol name matching (think strcmp_iw) be based on a per-language method.
 - Merges completion and non-completion name comparison (think
   language_ops::la_get_symbol_name_cmp generalized).
 - Avoid re-hashing lookup name multiple times
 - Centralizes preparing a name for lookup (Ada name encoding / C++ Demangling),
   both completion and non-completion.
 - Fixes Ada latent bug with verbatim name matches in expressions
 - Makes ada-lang.c use common|symtab.c completion code a bit more.

Ada's wild matching basically means that

 "(gdb) break foo"

will find all methods named "foo" in all packages.  Translating to
C++, it's roughly the same as saying that "break klass::method" sets
breakpoints on all "klass::method" methods of all classes, no matter
the namespace.  A following patch will teach GDB about fullname vs
wild matching for C++ too.  This patch is preparatory work to get
there.

Another idea here is to do symbol name matching based on the symbol
language's algorithm.  I.e., avoid dependency on current language set.

This allows for example doing

  (gdb) b foo::bar< int > (<tab>

and having gdb name match the C++ symbols correctly even if the
current language is C or Assembly (or Rust, or Ada, or ...), which can
easily happen if you step into an Assembly/C runtime library frame.

By encapsulating all the information related to a lookup name in a
class, we can also cache hash computation for a given language in the
lookup name object, to avoid recomputing it over and over.

Similarly, because we don't really know upfront which languages the
lookup name will be matched against, for each language we store the
lookup name transformed into a search name.  E.g., for C++, that means
demangling the name.  But for Ada, it means encoding the name.  This
actually forces us to centralize all the different lookup name
encoding in a central place, resulting in clearer code, IMO.  See
e.g., the new ada_lookup_name_info class.

The lookup name -> symbol search name computation is also done only
once per language.

The old language->la_get_symbol_name_cmp / symbol_name_cmp_ftype are
generalized to work with both completion, and normal symbol look up.

At some point early on, I had separate completion vs non-completion
language vector entry points, but a single method ends up being better
IMO for simplifying things -- the more we merge the completion /
non-completion name lookup code paths, the less changes for bugs
causing completion vs normal lookup finding different symbols.

The ada-lex.l change is necessary because when doing

  (gdb) p <UpperCase>

then the name that is passed to write_ write_var_or_type ->
ada_lookup_symbol_list misses the "<>", i.e., it's just "UpperCase",
and we end up doing a wild match against "UpperCase" lowercased by
ada_lookup_name_info's constructor.  I.e., "uppercase" wouldn't ever
match "UpperCase", and the symbol lookup fails.

This wouldn't cause any regression in the testsuite, but I added a new
test that would pass before the patch and fail after, if it weren't
for that fix.

This is latent bug that happens to go unnoticed because that
particular path was inconsistent with the rest of Ada symbol lookup by
not lowercasing the lookup name.

Ada's symbol_completion_add is deleted, replaced by using common
code's completion_list_add_name.  To make the latter work for Ada, we
needed to add a new output parameter, because Ada wants to return back
a custom completion candidates that are not the symbol name.

With this patch, minimal symbol demangled name hashing is made
consistent with regular symbol hashing.  I.e., it now goes via the
language vector's search_name_hash method too, as I had suggested in a
previous patch.

dw2_expand_symtabs_matching / .gdb_index symbol names were a
challenge.  The problem is that we have no way to telling what is the
language of each symbol name found in the index, until we expand the
corresponding full symbol, which is off course what we're trying to
avoid.  Language information is simply not considered in the index
format...  Since the symbol name hashing and comparison routines are
per-language, we now have a problem.  The patch sorts this out by
matching each name against all languages.  This is inneficient, and
indeed slows down completion several times.  E.g., with:

 $ cat script.cmd
 set pagination off
 set $count = 0
 while $count < 400
   complete b string_prin
   printf "count = %d\n", $count
   set $count = $count + 1
 end

 $ time gdb --batch -q ./gdb-with-index -ex "source script-string_printf.cmd"

I get, before patch (-O2, x86-64):

 real    0m1.773s
 user    0m1.737s
 sys     0m0.040s

While after patch (-O2, x86-64):

 real    0m9.843s
 user    0m9.482s
 sys     0m0.034s

However, the following patch will optimize this, and will actually
make this use case faster compared to the "before patch" above:

 real    0m1.321s
 user    0m1.285s
 sys     0m0.039s

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

	* ada-lang.c (ada_encode): Rename to ..
	(ada_encode_1): ... this.  Add throw_errors parameter and handle
	it.
	(ada_encode): Reimplement.
	(match_name): Delete, folded into full_name.
	(resolve_subexp): No longer pass the encoded name to
	ada_lookup_symbol_list.
	(should_use_wild_match): Delete.
	(name_match_type_from_name): New.
	(ada_lookup_simple_minsym): Use lookup_name_info and the
	language's symbol_name_matcher_ftype.
	(add_symbols_from_enclosing_procs, ada_add_local_symbols)
	(ada_add_block_renamings): Adjust to use lookup_name_info.
	(ada_lookup_name): New.
	(add_nonlocal_symbols, ada_add_all_symbols)
	(ada_lookup_symbol_list_worker, ada_lookup_symbol_list)
	(ada_iterate_over_symbols): Adjust to use lookup_name_info.
	(ada_name_for_lookup): Delete.
	(ada_lookup_encoded_symbol): Construct a verbatim name.
	(wild_match): Reverse sense of return type.  Use bool.
	(full_match): Reverse sense of return type.  Inline bits of old
	match_name here.
	(ada_add_block_symbols): Adjust to use lookup_name_info.
	(symbol_completion_match): Delete, folded into...
	(ada_lookup_name_info::matches): ... .this new method.
	(symbol_completion_add): Delete.
	(ada_collect_symbol_completion_matches): Add name_match_type
	parameter.  Adjust to use lookup_name_info and
	completion_list_add_name.
	(get_var_value, ada_add_global_exceptions): Adjust to use
	lookup_name_info.
	(ada_get_symbol_name_cmp): Delete.
	(do_wild_match, do_full_match): New functions.
	(ada_lookup_name_info::ada_lookup_name_info): New method.
	(ada_symbol_name_matches, ada_get_symbol_name_matcher): New
	functions.
	(ada_language_defn): Install ada_get_symbol_name_matcher.
	* ada-lex.l (processId): If name starts with '<', copy it
	verbatim.
	* block.c (block_iter_match_step, block_iter_match_first)
	(block_iter_match_next, block_lookup_symbol)
	(block_lookup_symbol_primary, block_find_symbol): Adjust to use
	lookup_name_info.
	* block.h (block_iter_match_first, block_iter_match_next)
	(ALL_BLOCK_SYMBOLS_WITH_NAME): Adjust to use lookup_name_info.
	* c-lang.c (c_language_defn, cplus_language_defn)
	(asm_language_defn, minimal_language_defn): Adjust comments to
	refer to la_get_symbol_name_matcher.
	* completer.c (complete_files_symbols)
	(collect_explicit_location_matches, symbol_completer): Pass a
	symbol_name_match_type down.
	* completer.h (class completion_match, completion_match_result):
	New classes.
	(completion_tracker::reset_completion_match_result): New method.
	(completion_tracker::m_completion_match_result): New field.
	* cp-support.c (make_symbol_overload_list_block): Adjust to use
	lookup_name_info.
	(cp_fq_symbol_name_matches, cp_get_symbol_name_matcher): New
	functions.
	* cp-support.h (cp_get_symbol_name_matcher): New declaration.
	* d-lang.c: Adjust comments to refer to
	la_get_symbol_name_matcher.
	* dictionary.c (dict_vector) <iter_match_first, iter_match_next>:
	Adjust to use lookup_name_info.
	(dict_iter_match_first, dict_iter_match_next)
	(iter_match_first_hashed, iter_match_next_hashed)
	(iter_match_first_linear, iter_match_next_linear): Adjust to work
	with a lookup_name_info.
	* dictionary.h (dict_iter_match_first, dict_iter_match_next):
	Likewise.
	* dwarf2read.c (dw2_lookup_symbol): Adjust to use lookup_name_info.
	(dw2_map_matching_symbols): Adjust to use symbol_name_match_type.
	(gdb_index_symbol_name_matcher): New class.
	(dw2_expand_symtabs_matching) Adjust to use lookup_name_info and
	gdb_index_symbol_name_matcher.  Accept a NULL symbol_matcher.
	* f-lang.c (f_collect_symbol_completion_matches): Adjust to work
	with a symbol_name_match_type.
	(f_language_defn): Adjust comments to refer to
	la_get_symbol_name_matcher.
	* go-lang.c (go_language_defn): Adjust comments to refer to
	la_get_symbol_name_matcher.
	* language.c (default_symbol_name_matcher)
	(language_get_symbol_name_matcher): New functions.
	(unknown_language_defn, auto_language_defn): Adjust comments to
	refer to la_get_symbol_name_matcher.
	* language.h (symbol_name_cmp_ftype): Delete.
	(language_defn) <la_collect_symbol_completion_matches>: Add match
	type parameter.
	<la_get_symbol_name_cmp>: Delete field.
	<la_get_symbol_name_matcher>: New field.
	<la_iterate_over_symbols>: Adjust to use lookup_name_info.
	(default_symbol_name_matcher, language_get_symbol_name_matcher):
	Declare.
	* linespec.c (iterate_over_all_matching_symtabs)
	(iterate_over_file_blocks): Adjust to use lookup_name_info.
	(find_methods): Add language parameter, and use lookup_name_info
	and the language's symbol_name_matcher_ftype.
	(linespec_complete_function): Adjust.
	(lookup_prefix_sym): Use lookup_name_info.
	(add_all_symbol_names_from_pspace): Adjust.
	(find_superclass_methods): Add language parameter and pass it
	down.
	(find_method): Pass symbol language down.
	(find_linespec_symbols): Don't demangle or Ada encode here.
	(search_minsyms_for_name): Add lookup_name_info parameter.
	(add_matching_symbols_to_info): Add name_match_type parameter.
	Use lookup_name_info.
	* m2-lang.c (m2_language_defn): Adjust comments to refer to
	la_get_symbol_name_matcher.
	* minsyms.c: Include <algorithm>.
	(add_minsym_to_demangled_hash_table): Remove table parameter and
	add objfile parameter.  Use search_name_hash, and add language to
	demangled languages vector.
	(struct found_minimal_symbols): New struct.
	(lookup_minimal_symbol_mangled, lookup_minimal_symbol_demangled):
	New functions.
	(lookup_minimal_symbol): Adjust to use them.  Don't canonicalize
	input names here.  Use lookup_name_info instead.  Lookup up
	demangled names once for each language in the demangled names
	vector.
	(iterate_over_minimal_symbols): Use lookup_name_info.  Lookup up
	demangled names once for each language in the demangled names
	vector.
	(build_minimal_symbol_hash_tables): Adjust.
	* minsyms.h (iterate_over_minimal_symbols): Adjust to pass down a
	lookup_name_info.
	* objc-lang.c (objc_language_defn): Adjust comment to refer to
	la_get_symbol_name_matcher.
	* objfiles.h: Include <vector>.
	(objfile_per_bfd_storage) <demangled_hash_languages>: New field.
	* opencl-lang.c (opencl_language_defn): Adjust comment to refer to
	la_get_symbol_name_matcher.
	* p-lang.c (pascal_language_defn): Adjust comment to refer to
	la_get_symbol_name_matcher.
	* psymtab.c (psym_lookup_symbol): Use lookup_name_info.
	(match_partial_symbol): Use symbol_name_match_type,
	lookup_name_info and psymbol_name_matches.
	(lookup_partial_symbol): Use lookup_name_info.
	(map_block): Use symbol_name_match_type and lookup_name_info.
	(psym_map_matching_symbols): Use symbol_name_match_type.
	(psymbol_name_matches): New.
	(recursively_search_psymtabs): Use lookup_name_info and
	psymbol_name_matches.  Rename 'kind' parameter to 'domain'.
	(psym_expand_symtabs_matching): Use lookup_name_info.  Rename
	'kind' parameter to 'domain'.
	* rust-lang.c (rust_language_defn): Adjust comment to refer to
	la_get_symbol_name_matcher.
	* symfile-debug.c (debug_qf_map_matching_symbols)
	(debug_qf_map_matching_symbols): Use symbol_name_match_type.
	(debug_qf_expand_symtabs_matching): Use lookup_name_info.
	* symfile.c (expand_symtabs_matching): Use lookup_name_info.
	* symfile.h (quick_symbol_functions) <map_matching_symbols>:
	Adjust to use symbol_name_match_type.
	<expand_symtabs_matching>: Adjust to use lookup_name_info.
	(expand_symtabs_matching): Adjust to use lookup_name_info.
	* symmisc.c (maintenance_expand_symtabs): Use
	lookup_name_info::match_any ().
	* symtab.c (symbol_matches_search_name): New.
	(eq_symbol_entry): Adjust to use lookup_name_info and the
	language's matcher.
	(demangle_for_lookup_info::demangle_for_lookup_info): New.
	(lookup_name_info::match_any): New.
	(iterate_over_symbols, search_symbols): Use lookup_name_info.
	(compare_symbol_name): Add language, lookup_name_info and
	completion_match_result parameters, and use them.
	(completion_list_add_name): Make extern.  Add language and
	lookup_name_info parameters.  Use them.
	(completion_list_add_symbol, completion_list_add_msymbol)
	(completion_list_objc_symbol): Add lookup_name_info parameters and
	adjust.  Pass down language.
	(completion_list_add_fields): Add lookup_name_info parameters and
	adjust.  Pass down language.
	(add_symtab_completions): Add lookup_name_info parameters and
	adjust.
	(default_collect_symbol_completion_matches_break_on): Add
	name_match_type parameter, and use it.  Use lookup_name_info.
	(default_collect_symbol_completion_matches)
	(collect_symbol_completion_matches): Add name_match_type
	parameter, and pass it down.
	(collect_symbol_completion_matches_type): Adjust.
	(collect_file_symbol_completion_matches): Add name_match_type
	parameter, and use lookup_name_info.
	* symtab.h: Include <string> and "common/gdb_optional.h".
	(enum class symbol_name_match_type): New.
	(class ada_lookup_name_info): New.
	(struct demangle_for_lookup_info): New.
	(class lookup_name_info): New.
	(symbol_name_matcher_ftype): New.
	(SYMBOL_MATCHES_SEARCH_NAME): Use symbol_matches_search_name.
	(symbol_matches_search_name): Declare.
	(MSYMBOL_MATCHES_SEARCH_NAME): Delete.
	(default_collect_symbol_completion_matches)
	(collect_symbol_completion_matches)
	(collect_file_symbol_completion_matches): Add name_match_type
	parameter.
	(iterate_over_symbols): Use lookup_name_info.
	(completion_list_add_name): Declare.
	* utils.c (enum class strncmp_iw_mode): Moved to utils.h.
	(strncmp_iw_with_mode): Now extern.
	* utils.h (enum class strncmp_iw_mode): Moved from utils.c.
	(strncmp_iw_with_mode): Declare.

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

	* gdb.ada/complete.exp (p <Exported_Capitalized>): New test.
	(p Exported_Capitalized): New test.
	(p exported_capitalized): New test.
2017-11-08 16:02:24 +00:00
Pedro Alves 5ffa079369 Per-language symbol name hashing algorithm
Currently, we have a mess of symbol name hashing/comparison routines.
There's msymbol_hash for mangled names, and dict_hash and
msymbol_hash_iw for demangled names.  Then there's strcmp_iw,
strcmp_iw_ordered and Ada's full_match/wild_match, which all have to
agree with the hashing routines.  That's why dict_hash is really about
Ada names.  From the inconsistency department, minimal symbol hashing
doesn't go via dict_hash, so Ada's wild matching can't ever work with
minimal symbols.

This patch starts fixing this, by doing two things:

#1 - adds a language vector method to let each language decide how to
     compute a symbol name hash.

#2 - makes dictionaries know the language of the symbols they hold,
     and then use the dictionaries language to decide which hashing
     method to use.

For now, this is just scaffolding, since all languages install the
default method.  The series will make C++ install its own hashing
method later on, and will add per-language symbol name comparison
routines too.

This patch was originally based on a patch that Keith wrote for the
libcc1/C++ WIP support.

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

	* ada-lang.c (ada_language_defn): Install
	default_search_name_hash.
	* buildsym.c (struct buildsym_compunit): <language>: New field.
	(finish_block_internal): Pass language when creating dictionaries.
	(start_buildsym_compunit, start_symtab): New language parameters.
	Use them.
	(restart_symtab): Pass down compilation unit's language.
	* buildsym.h (enum language): Forward declare.
	(start_symtab): New 'language' parameter.
	* c-lang.c (c_language_defn, cplus_language_defn)
	(asm_language_defn, minimal_language_defn): Install
	default_search_name_hash.
	* coffread.c (coff_start_symtab): Adjust.
	* d-lang.c (d_language_defn): Install default_search_name_hash.
	* dbxread.c (struct symloc): Add 'pst_language' field.
	(PST_LANGUAGE): Define.
	(start_psymtab, read_ofile_symtab): Use it.
	(process_one_symbol): New 'language' parameter.  Pass it down.
	* dictionary.c (struct dictionary) <language>: New field.
	(DICT_LANGUAGE): Define.
	(dict_create_hashed, dict_create_hashed_expandable)
	(dict_create_linear, dict_create_linear_expandable): New parameter
	'language'.  Set the dictionary's language.
	(iter_match_first_hashed): Adjust to rename.
	(insert_symbol_hashed): Assert we don't see mismatching
	languages.  Adjust to rename.
	(dict_hash): Rename to ...
	(default_search_name_hash): ... this and make extern.
	* dictionary.h (struct language_defn): Forward declare.
	(dict_create_hashed): New parameter 'language'.
	* dwarf2read.c (dwarf2_start_symtab): Pass down language.
	* f-lang.c (f_language_defn): Install default_search_name_hash.
	* go-lang.c (go_language_defn): Install default_search_name_hash.
	* jit.c (finalize_symtab): Pass compunit's language to dictionary
	creation.
	* language.c (unknown_language_defn, auto_language_defn):
	* language.h (language_defn::la_search_name_hash): New field.
	(default_search_name_hash): Declare.
	* m2-lang.c (m2_language_defn): Install default_search_name_hash.
	* mdebugread.c (new_block): New parameter 'language'.
	* mdebugread.c (parse_symbol): Pass symbol language to block
	allocation.
	(psymtab_to_symtab_1): Pass down language.
	(new_symtab): Pass compunit's language to block allocation.
	* objc-lang.c (objc_language_defn): Install
	default_search_name_hash.
	* opencl-lang.c (opencl_language_defn):
	* p-lang.c (pascal_language_defn): Install
	default_search_name_hash.
	* rust-lang.c (rust_language_defn): Install
	default_search_name_hash.
	* stabsread.h (enum language): Forward declare.
	(process_one_symbol): Add 'language' parameter.
	* symtab.c (search_name_hash): New function.
	* symtab.h (search_name_hash): Declare.
	* xcoffread.c (read_xcoff_symtab): Pass language to start_symtab.
2017-11-08 16:02:24 +00:00
Tom Tromey eb4c3f4aaa Constify add_setshow_*
This constifies the add_setshow_* family of functions, and then fixes
up the fallout.  The bulk of this patch was written by script.

gdb/ChangeLog
2017-11-07  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (catch_ada_exception_command): Constify.
	(catch_assert_command): Constify.
	* break-catch-throw.c (catch_catch_command, catch_throw_command)
	(catch_rethrow_command): Constify.
	(catch_exception_command_1): Constify.
	* breakpoint.h (add_catch_command): Constify.
	* break-catch-syscall.c (catch_syscall_command_1): Constify.
	(catch_syscall_split_args): Constify.
	* break-catch-sig.c (catch_signal_command): Constify.
	(catch_signal_split_args): Constify.
	* cli/cli-decode.h (struct cmd_list_element) <function>: Use
	cmd_const_sfunc_ftype.
	* cli/cli-decode.c (add_setshow_cmd_full): Constify.
	(add_setshow_enum_cmd, add_setshow_auto_boolean_cmd)
	(add_setshow_boolean_cmd, add_setshow_filename_cmd)
	(add_setshow_string_cmd, struct cmd_list_element)
	(add_setshow_optional_filename_cmd, add_setshow_integer_cmd)
	(add_setshow_uinteger_cmd, add_setshow_zinteger_cmd)
	(add_setshow_zuinteger_unlimited_cmd, add_setshow_zuinteger_cmd):
	Constify.
	(set_cmd_sfunc): Constify.
	(empty_sfunc): Constify.
	* command.h (add_setshow_enum_cmd, add_setshow_auto_boolean_cmd)
	(add_setshow_boolean_cmd, add_setshow_filename_cmd)
	(add_setshow_string_cmd, add_setshow_string_noescape_cmd)
	(add_setshow_optional_filename_cmd, add_setshow_integer_cmd)
	(add_setshow_uinteger_cmd, add_setshow_zinteger_cmd)
	(add_setshow_zuinteger_cmd, add_setshow_zuinteger_unlimited_cmd):
	Constify.
	(set_cmd_sfunc): Constify.
	(cmd_sfunc_ftype): Remove.
	* compile/compile.c (set_compile_args): Constify.
	* infrun.c (set_disable_randomization): Constify.
	* infcmd.c (set_args_command, set_cwd_command): Constify.
	* breakpoint.c (set_condition_evaluation_mode): Constify.
	(add_catch_command): Constify.
	(catch_fork_command_1, catch_exec_command_1)
	(catch_load_command_1, catch_unload_command_1): Constify.
	(catch_load_or_unload): Constify.
	* guile/scm-param.c (pascm_set_func): Constify.
	(add_setshow_generic): Constify.
	* python/py-param.c (get_set_value): Constify.
	* top.h (set_verbose): Constify.
	* tui/tui-win.c (tui_set_var_cmd): Constify.
	* mi/mi-main.c (set_mi_async_command): Constify.
	* cli/cli-logging.c (set_logging_overwrite)
	(set_logging_redirect): Constify.
	* value.c (set_max_value_size): Constify.
	* valprint.c (set_input_radix, set_output_radix): Constify.
	* utils.c (set_width_command, set_height_command): Constify.
	* typeprint.c (set_print_type_methods, set_print_type_typedefs): Constify.
	* tracepoint.c (set_disconnected_tracing)
	(set_circular_trace_buffer, set_trace_buffer_size)
	(set_trace_user, set_trace_notes, set_trace_stop_notes): Constify.
	* top.c (set_history_size_command, set_verbose, set_editing)
	(set_gdb_datadir, set_history_filename): Constify.
	* target.c (set_targetdebug, maint_set_target_async_command)
	(maint_set_target_non_stop_command, set_target_permissions)
	(set_write_memory_permission): Constify.
	(open_target): Constify.
	* target-descriptions.c (set_tdesc_filename_cmd): Constify.
	* target-dcache.c (set_stack_cache, set_code_cache): Constify.
	* symtab.c (set_symbol_cache_size_handler): Constify.
	* symfile.c (set_ext_lang_command): Constify.
	* symfile-debug.c (set_debug_symfile): Constify.
	* source.c (set_directories_command): Constify.
	* solib.c (reload_shared_libraries, gdb_sysroot_changed): Constify.
	* serial.c (set_parity): Constify.
	* rs6000-tdep.c (powerpc_set_soft_float, powerpc_set_vector_abi): Constify.
	* remote.c (set_remote_exec_file, set_remotebreak)
	(set_remote_protocol_Z_packet_cmd, set_range_stepping): Constify.
	* record.c (set_record_insn_history_size)
	(set_record_call_history_size): Constify.
	* record-full.c (set_record_full_insn_max_num): Constify.
	* proc-api.c (set_procfs_trace_cmd, set_procfs_file_cmd): Constify.
	* osabi.c (set_osabi): Constify.
	* mips-tdep.c (set_mips64_transfers_32bit_regs)
	(reinit_frame_cache_sfunc, mips_abi_update): Constify.
	* maint.c (maintenance_set_profile_cmd): Constify.
	* linux-thread-db.c (set_libthread_db_search_path): Constify.
	* language.c (set_language_command, set_range_command)
	(set_case_command): Constify.
	* infrun.c (set_non_stop, set_observer_mode)
	(set_stop_on_solib_events, set_schedlock_func)
	(set_exec_direction_func): Constify.
	* infcmd.c (set_inferior_tty_command): Constify.
	* disasm.c (set_disassembler_options_sfunc): Constify.
	* demangle.c (set_demangling_command): Constify.
	* dcache.c (set_dcache_size, set_dcache_line_size): Constify.
	* cris-tdep.c (set_cris_version, set_cris_mode)
	(set_cris_dwarf2_cfi): Constify.
	* corefile.c (set_gnutarget_command): Constify.
	* charset.c (set_host_charset_sfunc, set_target_charset_sfunc)
	(set_target_wide_charset_sfunc): Constify.
	* breakpoint.c (update_dprintf_commands): Constify.
	* auto-load.c (set_auto_load_dir, set_auto_load_safe_path): Constify.
	* arm-tdep.c (set_fp_model_sfunc, arm_set_abi)
	(set_disassembly_style_sfunc): Constify.
	* arch-utils.c (set_endian, set_architecture): Constify.
	* alpha-tdep.c (reinit_frame_cache_sfunc): Constify.
	* agent.c (set_can_use_agent): Constify.
2017-11-07 13:59:09 -07:00