Commit Graph

5419 Commits

Author SHA1 Message Date
Marcus Shawcroft 40d1a503c4 Drop prefix from unsupported source path. 2014-04-17 10:52:43 +01:00
Yao Qi 389b98f7d8 [testsuite] Set target-charset to ascii
Hi,
We find gdb.base/printcmds.exp fails a lot on windows host, like this,

 p ctable1[163]
 $204 = 163 '£'
 (gdb) FAIL: gdb.base/printcmds.exp: p ctable1[163]

however, on linux host,

 p ctable1[163]
 $205 = 163 '\243'
 (gdb) PASS: gdb.base/printcmds.exp: p ctable1[163]

The printing related code is in valprint.c:print_wchar,

  if (gdb_iswprint (w) && (!need_escape || (!gdb_iswdigit (w)
					    && w != LCST ('8')
					    && w != LCST ('9'))))
    {
      gdb_wchar_t wchar = w;

      if (w == gdb_btowc (quoter) || w == LCST ('\\'))
	obstack_grow_wstr (output, LCST ("\\"));
      obstack_grow (output, &wchar, sizeof (gdb_wchar_t));
    }
  else
   {
      // print W in hex or octal digits
   }

When I debug gdb on different hosts, I find
on windows host, gdb_iswprint (iswprint) returns true if 'w' is 163.
However, on linux host, iswprint returns false if 'w' is 163.  Looks
this difference is caused by the charset.  On Linux host,
the target-charset is ANSI_X3.4-1968, while on windows host, the
target-charset is CP1252.

We can see how target-charset affects the output.  On linux host,

 (gdb) set target-charset ASCII
 (gdb) p ctable1[163]
 $1 = 163 '\243'
 (gdb) set target-charset CP1252
 (gdb) p ctable1[163]
 $2 = 163 '£'

we can print the pound sign too, and it shows target-charset does
affect the output.

This patch is to set target-charset temporarily to ASCII for some
charset-sensitive tests.  Tested on arm-none-eabi and
powerpc-linux-gnu on mingw32 host.  More than one hundred fails are
fixed.

gdb/testsuite:

2014-04-17  Yao Qi  <yao@codesourcery.com>

	* lib/gdb.exp (with_target_charset): New proc.
	* gdb.base/printcmds.exp (test_print_all_chars): Wrap tests with
	with_target_charset.
	(test_print_strings): Likewise.
	(test_repeat_bytes): Likewise.
	* gdb.base/setvar.exp: Set target-charset to ASCII temporarily
	for some tests.
2014-04-17 10:33:19 +08:00
Keith Seitz 22869d73e1 PR gdb/15827
Install some sanity checks that sibling DIE offsets are not beyond the
defined limits of the DWARF input buffer in read_partial_die and skip_one_die.

2014-03-20  Keith Seitz  <keiths@redhat.com>

	PR gdb/15827
	* dwarf2read.c (skip_one_die): Check that all relative-offset
	sibling DIEs fall within range of the current reader's buffer.
	(read_partial_die): Likewise.

2014-03-20  Keith Seitz  <keiths@redhat.com>

	PR gdb/15827
	* gdb.dwarf2/corrupt.c: New file.
	* gdb.dwarf2/corrupt.exp: New file.
2014-04-16 14:39:10 -07:00
Keith Seitz c4f87ca6db PR c++/16597
[forgot to commit/push these with previous push]

If lookup_symbol_file tries to locate a member variable with NULL name:

      /* A simple lookup failed.  Check if the symbol was defined in
         a base class.  */

      cleanup = make_cleanup (null_cleanup, NULL);

      /* Find the name of the class and the name of the method,
         variable, etc.  */
      prefix_len = cp_entire_prefix_len (name);

      /* If no prefix was found, search "this".  */
      if (prefix_len == 0)
        {
          struct type *type;
          struct symbol *this;

         this = lookup_language_this (language_def (language_cplus), block);
          if (this == NULL)
            {
              do_cleanups (cleanup);
              return NULL;
            }

          type = check_typedef (TYPE_TARGET_TYPE (SYMBOL_TYPE (this)));
          klass = xstrdup (TYPE_NAME (type));
          nested = xstrdup (name);
        }

TYPE_NAME (type) is NULL, so xstrdup (NULL) and boom!

This can happen, e.g., with clang++.  See testsuite/gdb.cp/namelessclass.exp
or the bugzilla report.

This patch simply adds a fencepost against this case, allowing the caller
of lookup_symbol_file to search other blocks for the right symbol.
2014-04-16 14:20:19 -07:00
Keith Seitz fe28be73c7 PR c++/16597
If lookup_symbol_file tries to locate a member variable with NULL name:

      /* A simple lookup failed.  Check if the symbol was defined in
         a base class.  */

      cleanup = make_cleanup (null_cleanup, NULL);

      /* Find the name of the class and the name of the method,
         variable, etc.  */
      prefix_len = cp_entire_prefix_len (name);

      /* If no prefix was found, search "this".  */
      if (prefix_len == 0)
        {
          struct type *type;
          struct symbol *this;

         this = lookup_language_this (language_def (language_cplus), block);
          if (this == NULL)
            {
              do_cleanups (cleanup);
              return NULL;
            }

          type = check_typedef (TYPE_TARGET_TYPE (SYMBOL_TYPE (this)));
          klass = xstrdup (TYPE_NAME (type));
          nested = xstrdup (name);
        }

TYPE_NAME (type) is NULL, so xstrdup (NULL) and boom!

This can happen, e.g., with clang++.  See testsuite/gdb.cp/namelessclass.exp
or the bugzilla report.

This patch simply adds a fencepost against this case, allowing the caller
of lookup_symbol_file to search other blocks for the right symbol.
2014-04-16 14:12:22 -07:00
Doug Evans ab19de874b Fix wrapper.exp testcase with stdio gdbserver.
* lib/gdbserver-support.exp (gdbserver_default_get_remote_address):
	Add comment.
	(gdbserver_default_get_comm_port): New function.
	(gdbserver_start): Check if board file provided
	"gdbserver,get_comm_port" and use it if so.
	* boards/native-stdio-gdbserver.exp (sockethost): Set to "".
	(gdb,socketport): Set to "stdio".
	(gdbserver,get_comm_port): Set to ${board}_get_comm_port.
	(stdio_gdbserver_template): Delete.
	(${board}_get_remote_address): Update.
	(${board}_build_remote_cmd): Delete.
	(${board}_get_comm_port): New function.
	(${board}_spawn): Update.
	* boards/remote-stdio-gdbserver.exp (${board}_build_remote_cmd):
	Delete.
	(${board}_get_remote_address): Update.
	(${board}_get_comm_port): New function.
2014-04-16 10:40:41 -07:00
Andrew Burgess fc98a809db gdb.base/memattr.exp regexp improvements.
https://sourceware.org/ml/gdb-patches/2014-04/msg00210.html

Improve the regexp used in the memattr.exp test so allow for different
memory regions (.data / .bss) being laid out in different orders.

gdb/testsuite/ChangeLog:

	* gdb.base/memattr.exp: Improve regexps to handle memory regions
	appearing in any order.
2014-04-16 17:42:29 +01:00
Doug Evans 87fd9e6ed8 * gdb.gdb/selftest.exp (do_steps_and_nexts): Don't reference
uninitialized value of "description".
2014-04-15 16:13:19 -07:00
Keith Seitz 099fc3ea4c Remove unused globals in mi-simplerun.exp.
2014-04-15  Keith Seitz  <keiths@redhat.com>

	* gdb.mi/mi-simplerun.exp (test_breakpoints_creation_and_listing):
	Remove unused globals.
	(test_running_the_program): Likewise.
	(test_controlled_execution): Likewise.
	(test_controlling_breakpoints): Likewise.
	(test_program_termination): Likewise.
2014-04-15 12:07:33 -07:00
Keith Seitz 5da151d470 Test suite cleanup.
2014-04-15  Keith Seitz  <keiths@redhat.com>

	* gdb.mi/mi-break.exp (test_tbreak_creation_and_listing): Remove
	unused globals.
	(test_rbreak_creation_and_listing): Likewise.
	(test_ignore_count): Likewise.
	(test_error): Likewise.
2014-04-15 11:47:57 -07:00
Pedro Alves 35e5d2f0f8 gdb.base/sym-file.exp, hide guts of the custom loader.
This test uses a simple custom elf loader, implemented in
gdb.base/sym-file-loader.h|c.  This loader doesn't have a dlclose-like
function today, but I'll need one.  But, I found that the guts of the
loader are exposed too much to the client, making the interface more
complicated than necessary.  It's simpler if the loader just exports a
few dlopen/dlsym -style functions.  That's what this patch does.

Tested on x86_86 Fedora 17, native and gdbserver.

gdb/testsuite/
2014-04-15  Pedro Alves  <palves@redhat.com>

	* gdb.base/sym-file-loader.h: Move inclusion of <inttypes.h>,
	<ansidecl.h>, <elf/common.h> and <elf/external.h> to
	sym-file-loader.c.
	(Elf_External_Phdr, Elf_External_Ehdr, Elf_External_Shdr)
	(Elf_External_Sym, Elf_Addr, GET, GETADDR, struct segment): Move
	to sym-file-loader.c.
	(struct library): Forward declare.
	(load_shlib, lookup_function): Change prototypes.
	(find_shstrtab, find_strtab, find_shdr, find_symtab)
	(translate_offset): Remove declarations.
	(get_text_addr): New declaration.
	* gdb.base/sym-file-loader.c: Move inclusion of <inttypes.h>,
	<ansidecl.h>, <elf/common.h> and <elf/external.h> here from
	sym-file-loader.h.
	(Elf_External_Phdr, Elf_External_Ehdr, Elf_External_Shdr)
	(Elf_External_Sym, Elf_Addr, GET, GETADDR, struct segment): Move
	here from sym-file-loader.h.
	(struct library): New structure.
	(load_shlib, lookup_function): Change prototypes and adjust to
	work with a struct library.
	(find_shstrtab, find_strtab, find_shdr, find_symtab)
	(translate_offset): Make static.
	(get_text_addr): New function.
	* gdb.base/sym-file-main.c (main): Adjust to new loader interface.
2014-04-15 14:23:37 +01:00
Pedro Alves eb4c17106b gdb.base/sym-file-loader.c: Fix typo.
SELF_LINK, not SELK_LINK...

gdb/testsuite/
2014-04-15  Pedro Alves  <palves@redhat.com>

	* gdb.base/sym-file-loader.c: Fix typo.  SELF_LINK, not SELK_LINK.
2014-04-15 14:13:08 +01:00
Pedro Alves 2d1baf521e Make sym-file.exp work with remote targets and hosts.
The main issue here is that this test passes the host's absolute path
to the library to load to the "dlopen"-like routine, which doesn't
work when either the target or the host are remote, unless a shared
filesystem has been set up.

Tests that dynamically load a library solve this by dlopen'ing by
basename, and setting rpath to $ORIGIN.  See gdb_compile.

This test doesn't use dlopen, but instead uses its own simple elf
loader.  The fix is to pass this loader the library basename, and
teach it to look up the library by basename in the executable's
directory as well, i.e., assuming/emulating RPATH=$ORIGIN.

Tested on x86_64 Fedora 17, native and gdbserver.

I looked around in the web to figure out Linux's /proc/self/exe
equivalents in other ELF OSs.  I think I covered all relevant, but if
not, I think it'll be simple enough to add more.  (Note the test is
skipped on non-ELF targets.)

Tested on x86_64 Fedora 17, native and gdbserver.

gdb/testsuite/
2014-04-15  Pedro Alves  <palves@redhat.com>

	* gdb.base/sym-file-loader.c: Include <limits.h>.
	(SELF_LINK): New define.
	(get_origin): New function.
	(load_shlib): Use it.
	* gdb.base/sym-file.exp: Don't early return if the target is
	remote.  Use runto_main, and issue fail is that fails.  Use
	gdb_load_shlibs.
	(shlib_name): Delete.
	(lib_so, lib_syms, lib_dlopen): New globals.  Use them throughout.
2014-04-15 12:59:12 +01:00
Pedro Alves 7dd6df0171 gdb.base/sym-file.exp: clean up test messages a bit.
Remove regex characters from test message, and don't refer to
breakpoint numbers in test messages (subsequent patches will add more
breakpoints, changing these numbers).  Result:

 -PASS: gdb.base/sym-file.exp: add-symbol-file .*sym-file-lib\.so addr
 +PASS: gdb.base/sym-file.exp: add-symbol-file sym-file-lib.so addr

 -PASS: gdb.base/sym-file.exp: check if Breakpoint 2 is pending.
 -PASS: gdb.base/sym-file.exp: check if Breakpoint 3 is pending.
 +PASS: gdb.base/sym-file.exp: breakpoint at foo is pending
 +PASS: gdb.base/sym-file.exp: breakpoint at bar is pending

gdb/testsuite/
2014-04-15  Pedro Alves <palves@redhat.com>

	* gdb.base/sym-file.exp: Remove regex characters from test
	message.  Don't refer to breakpoint numbers in test messages.
2014-04-15 12:49:51 +01:00
Keith Seitz b50c861487 Remove symbol_matches_domain. This fixes
PR c++/16253.

symbol_matches_domain was permitting searches for a VAR_DOMAIN
symbol to also match STRUCT_DOMAIN symbols for languages like C++
where STRUCT_DOMAIN symbols also define a typedef of the same name,
e.g., "struct foo {}" introduces a typedef of the name "foo".

Problems occur if there exists both a VAR_DOMAIN and STRUCT_DOMAIN
symbol of the same name. Then it is essentially a race between which
symbol is found first. The other symbol is obscurred.
[This is a relatively common idiom: enum e { ... } e;]

This patchset moves this "language defines a typedef" logic to
lookup_symbol[_in_language], looking first for a symbol in the given
domain and falling back to searching STRUCT_DOMAIN when/if appropriate.

2014-04-14  Keith Seitz  <keiths@redhat.com>

	PR c++/16253
	* ada-lang.c (ada_symbol_matches_domain): Moved here and renamed
	from symbol_matches_domain in symtab.c. All local callers
	of symbol_matches_domain updated.
	(standard_lookup): If DOMAIN is VAR_DOMAIN and no symbol is found,
	search STRUCT_DOMAIN.
	(ada_find_any_type_symbol): Do not search STRUCT_DOMAIN
	independently.  standard_lookup will do that automatically.
	* cp-namespace.c (cp_lookup_symbol_nonlocal): Explain when/why
	VAR_DOMAIN searches may return a STRUCT_DOMAIN match.
	(cp_lookup_symbol_in_namespace): Likewise.
	If no VAR_DOMAIN symbol is found, search STRUCT_DOMAIN.
	(cp_lookup_symbol_exports): Explain when/why VAR_DOMAIN searches
	may return a STRUCT_DOMAIN match.
	(lookup_symbol_file): Search for the class name in STRUCT_DOMAIN.
	* cp-support.c: Include language.h.
	(inspect_type): Explicitly search STRUCT_DOMAIN before searching
	VAR_DOMAIN.
	* psymtab.c (match_partial_symbol): Compare the requested
	domain with the symbol's domain directly.
	(lookup_partial_symbol): Likewise.
	* symtab.c (lookup_symbol_in_language): Explain when/why
	VAR_DOMAIN searches may return a STRUCT_DOMAIN match.
	If no VAR_DOMAIN symbol is found, search STRUCT_DOMAIN for
	appropriate languages.
	(symbol_matches_domain): Renamed `ada_symbol_matches_domain'
	and moved to ada-lang.c
	(lookup_block_symbol): Explain that this function only returns
	symbol matching the requested DOMAIN.
	Compare the requested domain with the symbol's domain directly.
	(iterate_over_symbols): Compare the requested domain with the
	symbol's domain directly.
	* symtab.h (symbol_matches_domain): Remove.

2014-04-14  Keith Seitz  <keiths@redhat.com>

	PR c++/16253
	* gdb.cp/var-tag.cc: New file.
	* gdb.cp/var-tag.exp: New file.
	* gdb.dwarf2/dw2-ada-ffffffff.exp: Set the language to C++.
	* gdb.dwarf2/dw2-anon-mptr.exp: Likewise.
	* gdb.dwarf2/dw2-double-set-die-type.exp: Likewise.
	* gdb.dwarf2/dw2-inheritance.exp: Likewise.
2014-04-14 15:47:15 -07:00
Tom Tromey 3d567982ac implement support for "enum class"
This adds support for the C++11 "enum class" feature.  This is
PR c++/15246.

I chose to use the existing TYPE_DECLARED_CLASS rather than introduce
a new type code.  This seemed both simple and clear to me.

I made overloading support for the new enum types strict.  This is how
it works in C++; and it didn't seem like an undue burden to keep this,
particularly because enum constants are printed symbolically by gdb.

Built and regtested on x86-64 Fedora 20.

2014-04-14  Tom Tromey  <tromey@redhat.com>

	PR c++/15246:
	* c-exp.y (type_aggregate_p): New function.
	(qualified_name, classify_inner_name): Use it.
	* c-typeprint.c (c_type_print_base): Handle TYPE_DECLARED_CLASS
	and TYPE_TARGET_TYPE of an enum type.
	* dwarf2read.c (read_enumeration_type): Set TYPE_DECLARED_CLASS on
	an enum type.
	(determine_prefix) <case DW_TAG_enumeration_type>: New case;
	handle TYPE_DECLARED_CLASS.
	* gdbtypes.c (rank_one_type): Handle TYPE_DECLARED_CLASS on enum
	types.
	* gdbtypes.h (TYPE_DECLARED_CLASS): Update comment.
	* valops.c (enum_constant_from_type): New function.
	(value_aggregate_elt): Use it.
	* cp-namespace.c (cp_lookup_nested_symbol): Handle
	TYPE_CODE_ENUM.

2014-04-14  Tom Tromey  <tromey@redhat.com>

	* gdb.cp/classes.exp (test_enums): Handle underlying type.
	* gdb.dwarf2/enum-type.exp: Add test for enum with underlying
	type.
	* gdb.cp/enum-class.exp: New file.
	* gdb.cp/enum-class.cc: New file.
2014-04-14 11:42:18 -06:00
Tom Tromey 0626fc76d1 handle DW_AT_type on an enumeration
DWARF allows an enumeration type to have a DW_AT_type.  GDB doesn't
recognize this, but there is a patch to change GCC to emit it, and a
DWARF proposal to further allow an enum type with a DW_AT_type to omit
the DW_AT_byte_size.  This patch changes gdb to implement this.

Built and regtested on x86-64 Fedora 20.

2014-04-14  Tom Tromey  <tromey@redhat.com>

	* dwarf2read.c (read_enumeration_type): Handle DW_AT_type.

2014-04-14  Tom Tromey  <tromey@redhat.com>

	* gdb.dwarf2/enum-type.exp: New file.
2014-04-14 11:42:17 -06:00
Sanimir Agovic dca325b370 test: add mi vla test
testsuite/ChangeLog:

	* gdb.mi/mi-vla-c99.exp: New file.
	* gdb.mi/vla.c: New file.
2014-04-14 09:52:11 -07:00
Sanimir Agovic 5854b38a00 test: basic c99 vla tests for C primitives
gdb/testsuite/ChangeLog:

	* gdb.base/vla-datatypes.c: New file.
	* gdb.base/vla-datatypes.exp: New file.
2014-04-14 09:27:42 -07:00
Sanimir Agovic 463bb9571b test: evaluate pointers to C99 vla correctly.
gdb/testsuite/ChangeLog:

	* gdb.base/vla-ptr.c: New file.
	* gdb.base/vla-ptr.exp: New file.
2014-04-14 09:26:22 -07:00
Sanimir Agovic 3dd170be25 test: cover subranges with present DW_AT_count attribute
The dwarf attribute DW_AT_count specifies the elements of a subrange.
This test covers subranges with present count but absent upper bound
attribute, both with static and dynamic attribute values.

testsuite/ChangeLog:

	* gdb.dwarf2/count.exp: New file.
2014-04-14 09:23:44 -07:00
Sanimir Agovic 5ecaaa66e0 vla: evaluate operand of sizeof if its type is a vla
The c99 standard in "6.5.3.4 The sizeof operator" states:

 If the type of the operand is a variable length array type, the operand
 is evaluated;[...]

This patch mirrors the following c99 semantic in gdb:

 1| int vla[n][m];
 2| int i = 1;
 3| sizeof(vla[i++][0]); // No sideffect
 4| assert (i == 1);
 5| sizeof(vla[i++]);    // With sideffect
 6| assert (i == 2);

Note: ptype/whatis still do not allow any sideeffects.

This patch was motivated by:

  https://sourceware.org/ml/gdb-patches/2014-01/msg00732.html

gdb/ChangeLog:

	* eval.c (evaluate_subexp_for_sizeof): Add enum noside argument.
	(evaluate_subexp_standard): Pass noside argument.
	(evaluate_subexp_for_sizeof) <BINOP_SUBSCRIPT>: Handle subscript case
	if noside equals EVAL_NORMAL. If the subscript yields a vla type
	re-evaluate subscript operation with EVAL_NORMAL to enable sideffects.
	* gdbtypes.c (resolve_dynamic_bounds): Mark bound as evaluated.
	* gdbtypes.h (enum range_flags): Add RANGE_EVALUATED case.

testsuite/ChangeLog:

	* gdb.base/vla-sideeffect.c: New file.
	* gdb.base/vla-sideeffect.exp: New file.
2014-04-14 09:21:46 -07:00
David Blaikie 41f1ada5d2 Add return value for non-void function return statements to fix error in clang build.
Clang defaults this warning to an error, breaking the build & causing
these tests not to run.

gdb/testsuite/

	* gdb.mi/non-stop.c: Add return value for non-void function return
	statement.
	* gdb.threads/staticthreads.c: Ditto.
2014-04-14 08:34:51 -07:00
Doug Evans 0be03e8417 Copy over fix for fetching dynamic type of a reference from python side.
* guile/scm-value.c (gdbscm_value_dynamic_type): Use coerce_ref to
	dereference TYPE_CODE_REF values.

	testsuite/
	* gdb.guile/scm-value.c: Improve test case.
	* gdb.guile/scm-value.exp: Add new test.
2014-04-12 09:09:41 -07:00
David Blaikie f180a1fb46 Compile inline test with -std=gnu89 explicitly to override Clang's default (-std=c99)
gdb/testsuite/
	* gdb.opt/inline-break.exp: Explicitly specify -std=gnu89 to
	override Clang's default.
2014-04-11 17:26:23 -07:00
Joel Brobecker 191a8a9046 gdb/testsuite/ChangeLog: Fix path to a few files in previous entries. 2014-04-11 15:28:08 -07:00
Joel Brobecker 6b662e19e4 Revert the entire VLA series.
This reverts the following patch series, as they cause some regresssions.

commit 37c1ab67a3
type: add c99 variable length array support

	gdb/
	* dwarf2loc.c (dwarf2_locexpr_baton_eval): New function.
	(dwarf2_evaluate_property): New function.
	* dwarf2loc.h (dwarf2_evaluate_property): New function prototype.
	* dwarf2read.c (attr_to_dynamic_prop): New function.
	(read_subrange_type): Use attr_to_dynamic_prop to read high bound
	attribute.
	* gdbtypes.c: Include dwarf2loc.h.
	(is_dynamic_type): New function.
	(resolve_dynamic_type): New function.
	(resolve_dynamic_bounds): New function.
	(get_type_length): New function.
	(check_typedef): Use get_type_length to compute type length.
	* gdbtypes.h (TYPE_HIGH_BOUND_KIND): New macro.
	(TYPE_LOW_BOUND_KIND): New macro.
	(is_dynamic_type): New function prototype.
	* value.c (value_from_contents_and_address): Call resolve_dynamic_type
	to resolve dynamic properties of the type. Update comment.
	* valops.c (get_value_at, value_at, value_at_lazy): Update comment.

commit 26cb189f8b
vla: enable sizeof operator to work with variable length arrays

	gdb/
	* eval.c (evaluate_subexp_for_sizeof) <OP_VAR_VALUE>: If the type
	passed to sizeof is dynamic evaluate the argument to compute the length.

commit 04b19544ef
vla: enable sizeof operator for indirection

	gdb/
	* eval.c (evaluate_subexp_for_sizeof) <UNOP_IND>: Create an indirect
	value and retrieve the dynamic type size.

commit bcd629a44f
vla: update type from newly created value

	gdb/
	* ada-lang.c (ada_value_primitive_packed_val): Re-fetch type from value.
	(ada_template_to_fixed_record_type_1): Likewise.
	(ada_to_fixed_type_1): Likewise.
	* cp-valprint.c (cp_print_value_fields_rtti): Likewise.
	(cp_print_value): Likewise.
	* d-valprint.c (dynamic_array_type): Likewise.
	* eval.c (evaluate_subexp_with_coercion): Likewise.
	* findvar.c (address_of_variable): Likewise.
	* jv-valprint.c (java_value_print): Likewise.
	* valops.c (value_ind): Likewise.
	* value.c (coerce_ref): Likewise.

commit b86138fb04
vla: print "variable length" for unresolved dynamic bounds

	gdb/
	* c-typeprint.c (c_type_print_varspec_suffix): Added
	check for not yet resolved high bound. If unresolved, print
	"variable length" string to the console instead of random
	length.

commit e1969afbd4
vla: support for DW_AT_count

	gdb/
	* dwarf2read.c (read_subrange_type): Convert DW_AT_count to a dynamic
	property and store it as the high bound and flag the range accordingly.
	* gdbtypes.c (resolve_dynamic_bounds): If range is flagged as
	RANGE_UPPER_BOUND_IS_COUNT assign low + high - 1 as the new high bound.
	* gdbtypes.h (enum range_flags): New enum.
	(struct range_bounds): Add flags member.

commit 92b09522dc
vla: resolve dynamic bounds if value contents is a constant byte-sequence

	gdb/
	* findvar.c (default_read_var_value): Resolve dynamic bounds if location
	points to a constant blob.

commit 3bce82377f
vla: evaluate operand of sizeof if its type is a vla

	gdb/
	* eval.c (evaluate_subexp_for_sizeof): Add enum noside argument.
	(evaluate_subexp_standard): Pass noside argument.
	(evaluate_subexp_for_sizeof) <BINOP_SUBSCRIPT>: Handle subscript case
	if noside equals EVAL_NORMAL. If the subscript yields a vla type
	re-evaluate subscript operation with EVAL_NORMAL to enable sideffects.
	* gdbtypes.c (resolve_dynamic_bounds): Mark bound as evaluated.
	* gdbtypes.h (enum range_flags): Add RANGE_EVALUATED case.

	gdb/testsuite

	* gdb.base/vla-sideeffect.c: New file.
	* gdb.base/vla-sideeffect.exp: New file.

commit 504f34326e
test: cover subranges with present DW_AT_count attribute

	gdb/testsuite/
	* gdb.dwarf2/count.exp: New file.

commit 1a237e0ee5
test: multi-dimensional c99 vla.

	gdb/testsuite/
	* gdb.base/vla-multi.c: New file.
	* gdb.base/vla-multi.exp: New file.

commit 024e13b46f
test: evaluate pointers to C99 vla correctly.

	gdb/testsuite/
	* gdb.base/vla-ptr.c: New file.
	* gdb.base/vla-ptr.exp: New file.

commit c8655f75e2
test: basic c99 vla tests for C primitives

	gdb/testsuite/
	* gdb.base/vla-datatypes.c: New file.
	* gdb.base/vla-datatypes.exp: New file.

commit 58a84dcf29
test: add mi vla test

	gdb/testsuite/
	* gdb.mi/mi-vla-c99.exp: New file.
	* gdb.mi/vla.c: New file.
2014-04-11 15:26:21 -07:00
Keith Seitz 245a5f0b74 Fix c++/16675 -- sizeof reference type should give the size of
the referent, not the size of the actual reference variable.
2014-04-11 14:17:17 -07:00
Sanimir Agovic 58a84dcf29 test: add mi vla test
testsuite/gdb.mi/

	* mi-vla-c99.exp: New file.
	* vla.c: New file.
2014-04-11 13:44:00 +01:00
Sanimir Agovic c8655f75e2 test: basic c99 vla tests for C primitives
gdb/testsuite:
	* gdb.base/vla-datatypes.c: New file.
	* gdb.base/vla-datatypes.exp: New file.
2014-04-11 13:43:59 +01:00
Sanimir Agovic 024e13b46f test: evaluate pointers to C99 vla correctly.
gdb/testsuite:
	* gdb.base/vla-ptr.c: New file.
	* gdb.base/vla-ptr.exp: New file.
2014-04-11 13:43:58 +01:00
Sanimir Agovic 1a237e0ee5 test: multi-dimensional c99 vla.
gdb/testsuite:
	* gdb.base/vla-multi.c: New file.
	* gdb.base/vla-multi.exp: New file.
2014-04-11 13:43:57 +01:00
Sanimir Agovic 504f34326e test: cover subranges with present DW_AT_count attribute
The dwarf attribute DW_AT_count specifies the elements of a subrange.
This test covers subranges with present count but absent upper bound
attribute, both with static and dynamic attribute values.

testsuite:
	* gdb.dwarf2/count.exp: New file.
2014-04-11 13:43:56 +01:00
Sanimir Agovic 3bce82377f vla: evaluate operand of sizeof if its type is a vla
The c99 standard in "6.5.3.4 The sizeof operator" states:

 If the type of the operand is a variable length array type, the operand
 is evaluated;[...]

This patch mirrors the following c99 semantic in gdb:

 1| int vla[n][m];
 2| int i = 1;
 3| sizeof(vla[i++][0]); // No sideffect
 4| assert (i == 1);
 5| sizeof(vla[i++]);    // With sideffect
 6| assert (i == 2);

Note: ptype/whatsis still do not allow any sideeffects.

This patch was motivated by:

  https://sourceware.org/ml/gdb-patches/2014-01/msg00732.html

	* eval.c (evaluate_subexp_for_sizeof): Add enum noside argument.
	(evaluate_subexp_standard): Pass noside argument.
	(evaluate_subexp_for_sizeof) <BINOP_SUBSCRIPT>: Handle subscript case
	if noside equals EVAL_NORMAL. If the subscript yields a vla type
	re-evaluate subscript operation with EVAL_NORMAL to enable sideffects.
	* gdbtypes.c (resolve_dynamic_bounds): Mark bound as evaluated.
	* gdbtypes.h (enum range_flags): Add RANGE_EVALUATED case.

testsuite/gdb.base/

	* vla-sideeffect.c: New file.
	* vla-sideeffect.exp: New file.
2014-04-11 13:43:55 +01:00
Yao Qi 322f9c2100 Check file exists before completion tests
Doug told me that there are some regressions in gdb.base/completion.exp.
They are caused by my recent change, and can be reproduced via:

$ make check-parallel TESTS=gdb.base/completion.exp
FAIL: gdb.base/completion.exp: complete target core ./gdb.base/completion
FAIL: gdb.base/completion.exp: complete target tfile ./gdb.base/completion
FAIL: gdb.base/completion.exp: complete target exec ./gdb.base/completion

Current tests assume that gdb.base/completion exists but that is wrong
in a parallel run, because binary file and object files are placed
in outputs/gdb.base/completion/.

This patch is to check file exists on two candidate directories,
"gdb.base" and "outputs/gdb.base/completion/", and run tests with files
existed in either of them.

gdb/testsuite:

2014-04-11  Yao Qi  <yao@codesourcery.com>

	* gdb.base/completion.exp: Check file exists before running tests
	on file completion.
2014-04-11 12:54:09 +08:00
Pedro Alves d708bcd102 Conditional Z1 breakpoint hangs GDBserver.
While trying to fix hbreak2.exp against GDBserver I noticed this...

 (gdb) hbreak main if 1
 Sending packet: $m400580,40#2e...Packet received: e8d2ffffff5dc3554889e54883ec10c745fc00000000eb0eb800000000e8c1ffffff8345fc01817dfce70300007ee9b800000000c9c3662e0f1f840000000000
 Sending packet: $m40058f,1#31...Packet received: c7
 Hardware assisted breakpoint 1 at 0x40058f: file ../../../src/gdb/testsuite/gdb.base/break-idempotent.c, line 46.
 Sending packet: $Z1,40058f,1;X3,220127#9b...
 *hangs forever*

The issue is that nothing advances the packet pointer if
add_breakpoint_condition either fails to parse the agent expression,
or fails to find the breakpoint, resulting in an infinite loop in
process_point_options.  The latter case should really be fixed by
GDBserver tracking GDB Z1 breakpoints in its breakpoint structures
like Z0 breakpoints are, but the latter case still needs handling.
add_breakpoint_commands has the same issue, though at present I don't
know any way to trigger it other than sending a manually cooked
packet.

Unbelievably, it doesn't look like we have any test that tries setting
a conditional hardware breakpoint.  Looking at cond-eval-mode.exp, it
looks like the file was meant to actually test something, but it's
mostly empty today.  This patch adds tests that tries all sorts of
conditional breakpoints and watchpoints.  The test hangs/fails without
the GDBserver fix.

Tested on x86_64 Fedora 17.

gdb/gdbserver/
2014-04-10  Pedro Alves  <palves@redhat.com>

	* mem-break.c (add_breakpoint_condition, add_breakpoint_commands):
	Check if the condition or command is NULL before checking if the
	breakpoint is known.  On success, return true.
	* mem-break.h (add_breakpoint_condition): Document return.
	(add_breakpoint_commands): Add describing comment.
	* server.c (skip_to_semicolon): New function.
	(process_point_options): Use it.

gdb/testsuite/
2014-04-10  Pedro Alves  <palves@redhat.com>

	* gdb.base/cond-eval-mode.c: New file.
	* gdb.base/cond-eval-mode.exp: Use standard_testfile.  Adjust
	prepare_for_testing to build the new file.  Check result of
	runto_main.
	(test_break, test_watch): New procedures.
	(top level): Use them.
2014-04-10 17:14:12 +01:00
Pierre Muller ae1d276159 [testsuite] Disable Ctrl-V use for mingw hosts.
On mingw host, we have seen two fails as below,

p int1dim[0]^V@2
Invalid character '^V' in expression.
(gdb) FAIL: gdb.base/printcmds.exp: p int1dim[0]@2
p int1dim[0]^V@2^V@3
Invalid character '^V' in expression.
(gdb) FAIL: gdb.base/printcmds.exp: p int1dim[0]@2@3

In the test, the comment says "# Send \026@ instead of just @ in case
the kill character is @".  Historically, kill character was @, and
Ctrl-V (\026) is to escape the next character.  However, we don't have
to do so on mingw.  This patch is to disable ctrl-v usage on mingw
hots.  With this patch applied, it becomes:

p int1dim[0]@2
$607 = {0, 1}
(gdb) PASS: gdb.base/printcmds.exp: p int1dim[0]@2
p int1dim[0]@2@3
$608 = {{0, 1}, {2, 3}, {4, 5}}

Note that this patch is picked from Pierre's submission,

  [RFC 6/6] Fix remaining failures in gdb.base/printcmds.exp for mingw hosts.
  https://www.sourceware.org/ml/gdb-patches/2013-09/msg00943.html

gdb/testsuite:

2014-04-08  Pierre Muller  <muller@sourceware.org>

	* gdb.base/printcmds.exp (test_artificial_arrays): Disable
	Ctrl-V use for mingw hosts.
2014-04-08 14:07:28 +08:00
Siva Chandra 7af389b892 [python] Fix gdb.Value.dynamic_type for reference values.
gdb.Value.dynamic_type is supposed to work for reference and pointer
values.  However, the value object in the function 'valpy_get_dynamic_type'
was being dereferenced using 'value_ind' irrespective of the value type
being TYPE_CODE_PTR or TYPE_CODE_REF.  This patch fixes that to use
'coerce_ref' for TYPE_CODE_REF values.

ChangeLog:

	* python/py-value.c (valpy_get_dynamic_type): Use coerce_ref to
	dereference TYPE_CODE_REF values.

	testsuite/
	* gdb.python/py-value.c: Improve test case.
	* gdb.python/py-value.exp: Add new test.
2014-04-07 14:18:44 -07:00
Doug Evans 5e70318114 Add support to recognize clang.
* lib/compiler.c: Identify the clang compiler.
	* lib/compiler.cc: Ditto.
2014-04-07 14:14:03 -07:00
Yao Qi 9810b41048 Escape backslash in windows path
Hi,
On windows host, we see the following ERROR,

(gdb) PASS: gdb.base/setshow.exp: set history filename ~/foobar.baz
ERROR OCCURED: couldn't compile regular expression pattern: invalid escape \ seq
uence
    while executing
"expect -nobrace -i exp13 -timeout 10 -re {.*A problem internal to GDB has been
detected} {
	    fail "$message (GDB internal error)"
	    gdb_internal..."
    invoked from within
"expect {
-i exp13 -timeout 10
	-re ".*A problem internal to GDB has been detected" {
	    fail "$message (GDB internal error)"
	    gdb_internal_erro..."
    ("uplevel" body line 1)
    invoked from within
"uplevel $body" REGEXP REG_EESCAPE {invalid escape \ sequence} couldn't compile
regular expression pattern: invalid escape \ sequenceERROR: Process no longer ex
ists

which leads to
UNRESOLVED: gdb.base/setshow.exp: show history filename (~/foobar.baz)

and this error is thrown from this test below:

gdb_test "show history filename" \
    "The filename in which to record the command history is \"$HOME/foobar.baz\"..*" \
    "show history filename (~/foobar.baz)"

HOME is a windows path, like C:\foo\bar.  When it is used in gdb_test to match
output, the error is thrown because backslash is a special character in
regular expression.  This patch is to escape backslash to fix this
error by using string_to_regexp.

gdb/testsuite:

2014-04-03  Yao Qi  <yao@codesourcery.com>

	* gdb.base/setshow.exp: Invoke string_to_regexp to HOME and PWD.
2014-04-03 14:51:40 +08:00
Anton Blanchard 98d1b8dcd8 gdb.arch/ppc64-atomic-inst.exp: Improve error handling.
gdb/testsuite/
2014-04-01  Anton Blanchard  <anton@samba.org>

	* gdb.arch/ppc64-atomic-inst.exp: Use untested.  Make test
	messages unique.
2014-04-01 12:12:59 +11:00
Anton Blanchard 3114cea14b gdb.arch/ppc64-atomic-inst.exp: Use standard_testfile, prepare_for_testing.
gdb/testsuite/
2014-04-01  Anton Blanchard  <anton@samba.org>

	* gdb.arch/ppc64-atomic-inst.exp: Use standard_testfile,
	prepare_for_testing.
2014-04-01 12:12:55 +11:00
Anton Blanchard 62f7182c14 Fix ppc64 single step over atomic sequence testcase.
The current ppc64 single step over atomic sequence testcase is written
in C and breaks with some versions of gcc. Convert the test to
assembly and use stepi to step through it.

gdb/testsuite/
2014-04-01  Anton Blanchard  <anton@samba.org>

	* gdb.arch/ppc64-atomic-inst.c: Remove.
	* gdb.arch/ppc64-atomic-inst.S: New file.
	* gdb.arch/ppc64-atomic-inst.exp: Adapt for asm based testcase.
2014-04-01 12:12:48 +11:00
Doug Evans 770e7fc78c New option "set print symbol-loading".
* NEWS: Mention it.
	* solib.c (solib_read_symbols): Only print symbol loading messages
	if requested.
	(solib_add): If symbol loading is in "brief" mode, notify user
	symbols are being loaded.
	(reload_shared_libraries_1): Ditto.
	* symfile.c (print_symbol_loading_off): New static global.
	(print_symbol_loading_brief): New static global.
	(print_symbol_loading_full): New static global.
	(print_symbol_loading_enums): New static global.
	(print_symbol_loading): New static global.
	(print_symbol_loading_p): New function.
	(symbol_file_add_with_addrs): Only print symbol loading messages
	if requested.
	(_initialize_symfile): Register "print symbol-loading" set/show
	command.
	* symfile.h (print_symbol_loading_p): Declare.

	doc/
	* gdb.texinfo (Symbols): Document set/show print symbol-loading.

	testsuite/
	* gdb.base/print-symbol-loading-lib.c: New file.
	* gdb.base/print-symbol-loading-main.c: New file.
	* gdb.base/print-symbol-loading.exp: New file.
2014-03-31 12:07:48 -07:00
Yao Qi 46e2bafa7a Allow ';' as a directory separator
Hi,
I find two fails in source-dir.exp on mingw32 host.

(gdb) directory /nOtExStInG/a /nOtExStInG/b /nOtExStInG/c^M
Warning: /nOtExStInG/a: No such file or directory.^M
Warning: /nOtExStInG/b: No such file or directory.^M
Warning: /nOtExStInG/c: No such file or directory.^M
Source directories searched: /nOtExStInG/a;/nOtExStInG/b;/nOtExStInG/c;$cdir;$cwd^M
(gdb) FAIL: gdb.base/source-dir.exp: directory /nOtExStInG/a /nOtExStInG/b /nOtExStInG/c
directory /nOtExStInG/b /nOtExStInG/d /nOtExStInG/c^M
Warning: /nOtExStInG/b: No such file or directory.^M
Warning: /nOtExStInG/d: No such file or directory.^M
Warning: /nOtExStInG/c: No such file or directory.^M
Source directories searched: /nOtExStInG/b;/nOtExStInG/d;/nOtExStInG/c;/nOtExStInG/a;$cdir;$cwd^M
(gdb) FAIL: gdb.base/source-dir.exp: directory /nOtExStInG/b /nOtExStInG/d /nOtExStInG/c

The regular expression expects ':' and ';' is path separator on Windows.
This patch is to allow ';' as a path separator in regular expression.

This patch is similar to Dan's patch to fix a similar problem here

 Re: directory separators on minGW hosts
 https://sourceware.org/ml/gdb-patches/2006-02/msg00359.html

It is obvious.  Pushed it in.

gdb/testsuite:

2014-03-31  Yao Qi  <yao@codesourcery.com>

	* gdb.base/source-dir.exp: Allow ';' as a directory separator.
2014-03-31 15:00:28 +08:00
Joel Brobecker 8776cfe971 [varobj] false type-changed status for reference to Ada array
Given the following variable...

   BT : Bounded := New_Bounded (Low => 1, High => 3);

... where type Bounded is defined as a simple unconstrained array:

   type Bounded is array (Integer range <>) of Integer;

Creating a varobj for that variable, and immediately asking for
varobj updates, GDB says that our varobj changed types!

    (gdb)
    -var-create bt * bt
    ^done,name="bt",numchild="3",value="[3]",type="<ref> array (1 .. 3) of integer",has_more="0"
    (gdb)
    -var-update 1 *
    ^done,changelist=[{name="bt",value="[3]",in_scope="true",type_changed="true",new_type="<ref> array (1 .. 3) of integer",new_num_children="3",has_more="0"}]

The expected output for the -var-update command is, in this case:

    (gdb)
    -var-update 1 *
    ^done,changelist=[]

The problem occurs because the ada-varobj module does not handle
references, and while the references gets stripped when the varobj
gets created, it doesn't when computing varobj updates.

More specifically, when creating the varobj, varobj_create creates
a new value which is a reference to a TYPE_CODE_ARRAY. It then calls
install_new_value which calls coerce_ref with the following comment:

    /* We are not interested in the address of references, and given
       that in C++ a reference is not rebindable, it cannot
       meaningfully change.  So, get hold of the real value.  */
    if (value)
      value = coerce_ref (value);

This leaves the varobj's type component still a ref, while
the varobj's value is now our array, without the ref. This explains
why the "value" field in the varobj indicates an array with 3 elements
"[3]" while the "type" field shows a ref to an array. Generally
speaking, most users have said that showing the ref was a useful
piece of information, so this patch is not touching this part.

Next, when the user issues the -var-update request, varobj_update
calls value_of_root to compute the varobj's new value as well as
determine whether the value's type has changed or not. What happens
in a nutshell is that it calls value_of_root_1 (which re-evaluates
the expression and returns the corresponding new value), finds that
the new value is not NULL, and thus asks whether it has mutated:

    else if (varobj_value_has_mutated (var, value, value_type (value)))

This then indirectly delegates the determination to the language-specific
callback, which fails, because it does not handle references.

This patch fixes the issue by adjusting varobj_value_has_mutated to
expect references, and strip them when seen. This allows the various
language-specific implementations to remain unaware of references.

gdb/ChangeLog:

        * varobj.c (varobj_value_has_mutated): If NEW_VALUE is
        a reference, strip the reference layer before calling
        the lang_ops value_has_mutated callback.

gdb/testsuite/ChangeLog:

        * gdb.ada/mi_dyn_arr: New testcase.
2014-03-28 06:22:24 -07:00
Doug Evans 5d1ef36157 * gdb.dwarf2/dw2-abs-hi-pc.exp: Build tests with "nodebug". 2014-03-27 11:38:30 -07:00
Yao Qi b5bee91426 Return zero in can_single_step_to_signal_handler for nios2-*-* target
nios2 uses software single step, so GDB is unable to single step to
the signal handler.  In order to reflect this, teach
can_single_step_to_signal_handler to return zero for nios2 target.

gdb/testsuite:

2014-03-27  Yao Qi  <yao@codesourcery.com>

	* lib/gdb.exp (can_single_step_to_signal_handler): Return zero
	if target is nios2-*-*.
2014-03-27 16:34:35 +08:00
Yao Qi 0d4d0e772a Skip tests on completion and readline when readline lib isn't used
The completion feature and other features on readline depend on the
readline library.  However, readline library is not always used, for
example, running testsuite like

  make check RUNTESTFLAGS="--host_board=local-remote-host"

the input stream is not a tty, and GDB doesn't use readline library
as a result.

This patch is to skip tests on completion and readline if
'show editing' is off, which means readline isn't used.  Note that
some tests in gdb.base/completion.exp test command complete, which
isn't related to readline, so these tests aren't affected by readline
library.  This patch also moves these tests up, run them
unconditionally, and run the rest if readline library is used.

gdb/testsuite:

2014-03-26  Yao Qi  <yao@codesourcery.com>

	* lib/gdb.exp (readline_is_used): New proc.
	* gdb.base/completion.exp: Move tests on command complete up.
	Skip the rest of tests if readline is not used.
	* gdb.ada/complete.exp: Skp the test if readline is not
	used.
	* gdb.base/filesym.exp: Likewise.
	* gdb.base/macscp.exp: Likewise.
	* gdb.base/readline-ask.exp: Likewise.
	* gdb.base/readline.exp: Likewise.
	* gdb.python/py-cmd.exp: Likewise.
	* gdb.trace/tfile.exp: Likewise.
2014-03-26 21:11:08 +08:00
Yao Qi 29361eee14 Fix code format issues gdb.base/macscp.exp
When I do something else, I find code format in gdb.base/macscp.exp is
messy.  This patch is to fix various code format issues in it.

Pushed as it is obvious.

gdb/testsuite:

2014-03-26  Yao Qi  <yao@codesourcery.com>

	* gdb.base/macscp.exp: Fix code format issues.
2014-03-26 13:17:37 +08:00