Commit Graph

35877 Commits

Author SHA1 Message Date
Joel Brobecker 4a0ca9ec1e [Ada/varobj] number of children of null pointer to dynamic array.
This is preparation work to avoid a regression in the Ada/varobj.
An upcoming patch is going to add support for types in DWARF
which have dynamic properties whose value is a reference to another
DIE.

Consider for instance the following declaration:

   type Variant_Type (N : Int := 0) is record
      F : String(1 .. N) := (others => 'x');
   end record;
   type Variant_Type_Access is access all Variant_Type;
   VTA : Variant_Type_Access := null;

This declares a variable "VTA" which is an access (=pointer)
to a variant record Variant_Type. This record contains two
components, the first being "N" (the discriminant), and the
second being "F", an array whose lower bound is 1, and whose
upper bound depends on the value of "N" (the discriminant).

Of interest to us, here, is that second component ("F"), and
in particular its bounds. The debugging info, and in particular
the info for the array looks like the following...

        .uleb128 0x9    # (DIE (0x91) DW_TAG_array_type)
        .long   .LASF16 # DW_AT_name: "bar__variant_type__T2b"
        .long   0xac    # DW_AT_GNAT_descriptive_type
        .long   0x2cb   # DW_AT_type
        .long   0xac    # DW_AT_sibling
        .uleb128 0xa    # (DIE (0xa2) DW_TAG_subrange_type)
        .long   0xc4    # DW_AT_type
        .long   0x87    # DW_AT_upper_bound
        .byte   0       # end of children of DIE 0x91

... where the upper bound of the array's subrange type is a reference
to "n"'s DIE (0x87):

        .uleb128 0x8    # (DIE (0x87) DW_TAG_member)
        .ascii "n\0"    # DW_AT_name
        [...]

Once the patch to handle this dynamic property gets applied,
this is what happens when creating a varobj for variable "VTA"
(whose value is null), and then trying to list its children:

    (gdb)
    -var-create vta * vta
    ^done,name="vta",numchild="2",value="0x0",
          type="bar.variant_type_access",has_more="0"
    (gdb)
    -var-list-children 1 vta
    ^done,numchild="2",
          children=[child={name="vta.n",[...]},
                    child={name="vta.f",exp="f",
                           numchild="43877616",  <<<<-----
                           value="[43877616]",   <<<<-----
                           type="array (1 .. n) of character"}],
          has_more="0"

It has an odd number of children.

In this case, we cannot really determine the number of children,
since that number depends on the value of a field in a record
for which we do not have a value. Up to now, the value we've been
displaying is zero - meaning we have an empty array.

What happens in this case, is that, because the VTA is a null pointer,
we're not able to resolve the pointer's target type, and therefore
end up asking ada_varobj_get_array_number_of_children to return
the number of elements in that array; for that, it relies blindly
on get_array_bounds, which assumes the type is no longer dynamic,
and therefore the reads the bound without seeing that it's value
is actually a reference rather than a resolved constant.

This patch prevents the issue by explicitly handling the case of
dynamic arrays, and returning zero child in that case.

gdb/ChangeLog:

        * ada-varobj.c (ada_varobj_get_array_number_of_children):
        Return zero if PARENT_VALUE is NULL and parent_type's
        range type is dynamic.

gdb/testsuite/ChangeLog:

        * gdb.ada/mi_var_array: New testcase.

Tested on x86_64-linux.
2015-01-29 12:07:25 +04:00
Joel Brobecker ddb87a81ac gdb/DWARF: dynamic subrange type of dynamic subrange type.
Consider the following code:

   type Record_Type (N : Integer) is record
      A : Array_Type (1 .. N);
   end record;
   [...]
   R : Record_Type := Get (10);

Trying to print the bounds of the array R.A yielded:

    (gdb) p r.a'last
    $4 = cannot find reference address for offset property

A slightly different example, but from the same cause:

    (gdb) ptype r
    type = <ref> record
        n: integer;
        a: array (cannot find reference address for offset property

Looking at the debugging info, "A" is described as...

        .uleb128 0x11   # (DIE (0x181) DW_TAG_member)
        .ascii "a\0"    # DW_AT_name
        .long   0x15d   # DW_AT_type
        [...]

... which is an array...

        .uleb128 0x12   # (DIE (0x15d) DW_TAG_array_type)
        .long   .LASF18 # DW_AT_name: "foo__record_type__T4b"
        .long   0x194   # DW_AT_type
        .long   0x174   # DW_AT_sibling

... whose bounds are described as:

        .uleb128 0x13   # (DIE (0x16a) DW_TAG_subrange_type)
        .long   0x174   # DW_AT_type
        .long   0x153   # DW_AT_upper_bound
        .byte   0       # end of children of DIE 0x15d

We can see above that the range has an implict lower value of
1, and an upper value which is a reference 0x153="n". All Good.

But looking at the array's subrange subtype, we see...

        .uleb128 0x14   # (DIE (0x174) DW_TAG_subrange_type)
        .long   0x153   # DW_AT_upper_bound
        .long   .LASF19 # DW_AT_name: "foo__record_type__T3b"
        .long   0x18d   # DW_AT_type

... another subrange type whose bounds are exactly described
the same way. So we have a subrange of a subrange, both with
one bound that's dynamic.

What happens in the case above is that GDB's resolution of "R.A"
yields a array whose index type has static bounds. However, the
subtype of the array's index type was left untouched, so, when
taking the subtype of the array's subrange type, we were left
with the unresolved subrange type, triggering the error above.

gdb/ChangeLog:

        * gdbtypes.c (is_dynamic_type_internal) <TYPE_CODE_RANGE>: Return
        nonzero if the type's subtype is dynamic.
        (resolve_dynamic_range): Also resolve the range's subtype.

Tested on x86_64-linux, no regression.
2015-01-29 12:05:36 +04:00
Alexander Klimov 7a270e0c9b Fix build failure in symfile.c::unmap_overlay_command (GCC5 bug)
Compilation of (GDB) 7.9.50.20150127-cvs with (GCC) 5.0.0 20150127
fails with

In file included from symfile.c:32:0:
symfile.c: In function 'unmap_overlay_command':
objfiles.h:628:3: error: 'sec' may be used uninitialized in this
function [-Werror=maybe-uninitialized]
   for (osect = objfile->sections; osect < objfile->sections_end; osect++) \
   ^
symfile.c:3442:23: note: 'sec' was declared here
   struct obj_section *sec;
                       ^
cc1: all warnings being treated as errors
make[2]: *** [symfile.o] Error 1
make[2]: Leaving directory `gdb/gdb'

While the bug was reported to GCC as
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64823>,
the attached patch simply initializes sec with NULL.

gdb/ChangeLog:

        * symfile.c (unmap_overlay_command): Initialize sec to NULL.

Tested on x86_64-linux.
2015-01-29 11:28:02 +04:00
Doug Evans 3a8b707add Add gdb.Objfile.username.
gdb/ChangeLog:

	* NEWS: Mention gdb.Objfile.username.
	* python/py-objfile.c (objfpy_get_username): New function.
	(objfile_getset): Add "username".

gdb/doc/ChangeLog:

	* python.texi (Objfiles In Python): Document Objfile.username.

gdb/testsuite/ChangeLog:

	* gdb.python/py-objfile.exp: Add tests for objfile.username.
	Add test for objfile.filename, objfile.username after objfile
	has been unloaded.
2015-01-27 10:13:52 -08:00
Doug Evans 1b5493961a Improve docs of objfile filename method.
gdb/doc/ChangeLog:

	* python.texi (Objfiles In Python) <Objfile.filename>: Improve docs.
	* guile.texi (Objfiles In Guile) <objfile-filename>: Improve docs.
2015-01-27 10:03:15 -08:00
Mark Wielaard d35b90fb6e Fix ARI warning in stack.c (return_command).
gdb/ChangeLog

    * stack.c (return_command): Markup warning message with _.
2015-01-26 12:37:57 +01:00
Joel Brobecker f8313f6ec4 check gdb.lookup_type return value in gdb.python/py-lookup-type.exp
This further improves this testcase to check the output of
our calls to gdb.lookup_type.

gdb/ChangeLog:

        * gdb.python/py-lookup-type.exp (test_lookup_type): Change
        the second test to print the name attribute of value
        returned by the call to gdb.lookup_type, and adjust
        the expected output accordingly.
2015-01-26 08:41:37 +04:00
Mark Wielaard 37bc665e4e Remove testsuite compile errors with GCC5.
GCC5 defaults to the GNU11 standard for C and warns by default for
implicit function declarations and implicit return types.
https://gcc.gnu.org/gcc-5/porting_to.html

Fixing these issues in the testsuite turns 9 untested and 17 unsupported
testcases into 417 new passes when compiling with GCC5.

gdb/testsuite/ChangeLog:

        * gdb.arch/i386-bp_permanent.c (standard): New declaration.
        * gdb.base/disp-step-fork.c: Include unistd.h.
        * gdb.base/siginfo-obj.c: Include stdio.h.
        * gdb.base/siginfo-thread.c: Likewise.
        * gdb.mi/non-stop.c: Include unistd.h.
        * gdb.mi/nsthrexec.c: Include stdio.h.
        * gdb.mi/pthreads.c: Include unistd.h.
        * gdb.modula2/unbounded1.c (main): Declare returns int.
        * gdb.reverse/consecutive-reverse.c: Likewise.
        * gdb.threads/create-fail.c: Include unistd.h.
        * gdb.threads/killed.c: Likewise.
        * gdb.threads/linux-dp.c: Likewise.
        * gdb.threads/non-ldr-exc-1.c: Include stdio.h and string.h.
        * gdb.threads/non-ldr-exc-2.c: Likewise.
        * gdb.threads/non-ldr-exc-3.c: Likewise.
        * gdb.threads/non-ldr-exc-4.c: Likewise.
        * gdb.threads/pthreads.c: Include unistd.h.
        (main): Declare returns int.
        * gdb.threads/tls-main.c (foo): New declaration.
        * gdb.threads/watchpoint-fork-mt.c: Define _GNU_SOURCE.
2015-01-25 18:50:56 +01:00
Doug Evans 734ae1256d gdbtypes.h (TYPE_TYPE_SPECIFIC): Delete.
gdb/ChangeLog:

	* gdbtypes.h (TYPE_TYPE_SPECIFIC): Delete.
2015-01-24 11:17:08 -08:00
Jan Kratochvil 527f3840e1 Fix 100x slowdown regression on DWZ files
Since Fedora started to use DWZ DWARF compressor:
	http://fedoraproject.org/wiki/Features/DwarfCompressor
GDB has slowed down a lot.  To make it clear - DWZ is DWARF structure
rearrangement, "compressor" does not mean any zlib style data compression.

This patch reduces LibreOffice backtrace from 5 minutes to 3 seconds (100x)
and it also reduces memory consumption 20x.
[ benchmark is at the bottom of this mail ]

Example of DWZ output:
------------------------------------------------------------------------------
  Compilation Unit @ offset 0xc4:
 <0><cf>: Abbrev Number: 17 (DW_TAG_partial_unit)
    <d0>   DW_AT_stmt_list   : 0x0
    <d4>   DW_AT_comp_dir    : (indirect string, offset: 0x6f): /usr/src/debug/gdb-7.7.1/build-x86_64-redhat-linux-gnu/gdb
 <1><d8>: Abbrev Number: 9 (DW_TAG_typedef)
    <d9>   DW_AT_name        : (indirect string, offset: 0x827dc): size_t
    <dd>   DW_AT_decl_file   : 4
    <de>   DW_AT_decl_line   : 212
    <df>   DW_AT_type        : <0xae>

  Compilation Unit @ offset 0xe4:
 <0><ef>: Abbrev Number: 13 (DW_TAG_partial_unit)
    <f0>   DW_AT_stmt_list   : 0x0
    <f4>   DW_AT_comp_dir    : (indirect string, offset: 0x6f): /usr/src/debug/gdb-7.7.1/build-x86_64-redhat-linux-gnu/gdb
 <1><f8>: Abbrev Number: 45 (DW_TAG_typedef)
    <f9>   DW_AT_name        : (indirect string, offset: 0x251): __off_t
    <fd>   DW_AT_decl_file   : 3
    <fe>   DW_AT_decl_line   : 131
    <ff>   DW_AT_type        : <0x68>

  Compilation Unit @ offset 0x62d9f9:
 <0><62da04>: Abbrev Number: 20 (DW_TAG_compile_unit)
[...]
    <62da12>   DW_AT_low_pc	 : 0x807e10
    <62da1a>   DW_AT_high_pc     : 134
    <62da1c>   DW_AT_stmt_list   : 0xf557e
 <1><62da20>: Abbrev Number: 7 (DW_TAG_imported_unit)
    <62da21>   DW_AT_import	 : <0xcf>	[Abbrev Number: 17]
------------------------------------------------------------------------------

One can see all DW_TAG_partial_unit have DW_AT_stmt_list 0x0 which causes
repeated decoding of that .debug_line unit on each DW_TAG_imported_unit.

This was OK before as each DW_TAG_compile_unit has its own .debug_line unit.
But since the introduction of DW_TAG_partial_unit by DWZ one should cache
read-in DW_AT_stmt_list .debug_line units.

Fortunately one does not need to cache whole
        struct linetable *symtab->linetable
and other data from .debug_line mapping PC<->lines
------------------------------------------------------------------------------
 Line Number Statements:
  Extended opcode 2: set Address to 0x45c880
  Advance Line by 25 to 26
  Copy
------------------------------------------------------------------------------
as the only part of .debug_line which GDB needs for DW_TAG_partial_unit is:
------------------------------------------------------------------------------
 The Directory Table:
  ../../gdb
  /usr/include/bits
[...]
 The File Name Table:
  Entry Dir     Time    Size    Name
  1     1	0	0	gdb.c
  2     2	0	0	string3.h
[...]
------------------------------------------------------------------------------
specifically referenced in GDB for DW_AT_decl_file at a single place:
------------------------------------------------------------------------------
              fe = &cu->line_header->file_names[file_index - 1];
              SYMBOL_SYMTAB (sym) = fe->symtab;
------------------------------------------------------------------------------

This is because for some reason DW_TAG_partial_unit never contains PC-related
DWARF information.  I do not know exactly why, the compression ratio is a bit
lower due to it but thanksfully currently it is that way:
dwz.c:
------------------------------------------------------------------------------
        /* These attributes reference code, prevent moving
           DIEs with them.  */
        case DW_AT_low_pc:
        case DW_AT_high_pc:
        case DW_AT_entry_pc:
        case DW_AT_ranges:
          die->die_ck_state = CK_BAD;
+
  /* State of checksum computation.  Not computed yet, computed and
     suitable for moving into partial units, currently being computed
     and finally determined unsuitable for moving into partial units.  */
  enum { CK_UNKNOWN, CK_KNOWN, CK_BEING_COMPUTED, CK_BAD } die_ck_state : 2;
------------------------------------------------------------------------------
I have also verified also real-world Fedora debuginfo files really comply with
that assumption with dwgrep
	https://github.com/pmachata/dwgrep
using:
------------------------------------------------------------------------------
dwgrep -e 'entry ?DW_TAG_partial_unit child* ( ?DW_AT_low_pc , ?DW_AT_high_pc , ?DW_AT_ranges )' /usr/lib/debug/**
------------------------------------------------------------------------------

BTW I think GDB already does not support the whole DW_TAG_imported_unit and
DW_TAG_partial_unit usage possibilities as specified by the DWARF standard.
I think GDB would not work if DW_TAG_imported_unit was used in some inner
level and not at the CU level (readelf -wi level <1>) - this is how DWZ is
using DW_TAG_imported_unit.  Therefore I do not think further assumptions
about DW_TAG_imported_unit and DW_TAG_partial_unit usage by DWZ are a problem
for GDB.

One could save the whole .debug_line decoded PC<->lines mapping (and not just
the DW_AT_decl_file table) but:
 * there are some problematic corner cases so one could do it incorrectly
 * there are no real world data to really test such patch extension
 * such extension could be done perfectly incrementally on top of this patch

------------------------------------------------------------------------------

benchmark - on Fedora 20 x86_64 and FSF GDB HEAD:
echo -e 'thread apply all bt\nset confirm no\nq'|./gdb -p `pidof soffice.bin` -ex 'set pagination off' -ex 'maintenance set per-command
space' -ex 'maintenance set per-command symtab' -ex 'maintenance set per-command time'

FSF GDB HEAD ("thread apply all bt"):
Command execution time: 333.693000 (cpu), 335.587539 (wall)
                                          ---sec
Space used: 1736404992 (+1477189632 for this command)
                         ----MB
vs.
THIS PATCH ("thread apply all bt"):
Command execution time: 2.595000 (cpu), 2.607573 (wall)
                                        -sec
Space used: 340058112 (+85917696 for this command)
                        --MB

FSF GDB HEAD ("thread apply all bt full"):
Command execution time: 466.751000 (cpu), 468.345837 (wall)
                                          ---sec
Space used: 2330132480 (+2070974464 for this command)
                         ----MB
vs.
THIS PATCH ("thread apply all bt full"):
Command execution time: 18.907000 (cpu), 18.964125 (wall)
                                         --sec
Space used: 364462080 (+110325760 for this command)
                        ---MB

------------------------------------------------------------------------------

gdb/ChangeLog
2015-01-24  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix 100x slowdown regression on DWZ files.
	* dwarf2read.c (struct dwarf2_per_objfile): Add line_header_hash.
	(struct line_header): Add offset and offset_in_dwz.
	(dwarf_decode_lines): Add parameter decode_mapping to the declaration.
	(free_line_header_voidp): New declaration.
	(line_header_hash, line_header_hash_voidp, line_header_eq_voidp): New
	functions.
	(dwarf2_build_include_psymtabs): Update dwarf_decode_lines caller.
	(handle_DW_AT_stmt_list): Use line_header_hash.
	(free_line_header_voidp): New function.
	(dwarf_decode_line_header): Initialize offset and offset_in_dwz.
	(dwarf_decode_lines): New parameter decode_mapping, use it.
	(dwarf2_free_objfile): Free line_header_hash.
2015-01-24 15:44:52 +01:00
Simon Marchi f7e5394d61 Catch exception in value_rtti_indirect_type
In the situation described in bug 17416 [1]:

  * "set print object" is on;
  * The variable object is a pointer to a struct, and it contains an
    invalid value (e.g. NULL, or random uninitialized value);
  * The variable object (struct) has a child which is also a pointer to a
    struct;
  * We try to use "-var-list-children".

... an exception thrown in value_ind can propagate too far and leave an
half-built variable object, leading to a wrong state. This patch adds a
TRY_CATCH to catch it and makes value_rtti_indirect_type return NULL in
that case, meaning that the type of the pointed object could not be
found.

A test for the fix is also added.

New in v2:

  * Added test.
  * Restructured "catch" code.
  * Added details about the bug in commit log.

gdb/Changelog:

	* valops.c (value_rtti_indirect_type): Catch exception thrown by
	value_ind.

gdb/testsuite/ChangeLog

	* gdb.mi/mi-var-list-children-invalid-grandchild.c: New file.
	* gdb.mi/mi-var-list-children-invalid-grandchild.exp: New file.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=17416
2015-01-23 12:59:24 -05:00
Mark Wielaard 743649fd80 Use GCC5/DWARF5 DW_AT_noreturn to mark functions that don't return normally.
Add a flag field is_noreturn to struct func_type. Make calling_convention
a small bit field to not increase the size of the struct. Set is_noreturn
if the new GCC5/DWARF5 DW_AT_noreturn is set on a DW_TAG_subprogram.
Use this information to warn the user before doing a finish or return from
a function that does not return normally to its caller.

(gdb) finish
warning: Function endless does not return normally.
Try to finish anyway? (y or n)

(gdb) return
warning: Function does not return normally to caller.
Make endless return now? (y or n)

gdb/ChangeLog

	* dwarf2read.c (read_subroutine_type): Set TYPE_NO_RETURN from
	DW_AT_noreturn.
	* gdbtypes.h (struct func_type): Add is_noreturn field flag. Make
	calling_convention an 8 bit bit field.
	(TYPE_NO_RETURN): New macro.
	* infcmd.c (finish_command): Query if function does not return
	normally.
	* stack.c (return_command): Likewise.

gdb/testsuite/ChangeLog

	* gdb.base/noreturn-return.c: New file.
	* gdb.base/noreturn-return.exp: New file.
	* gdb.base/noreturn-finish.c: New file.
	* gdb.base/noreturn-finish.exp: New file.

include/ChangeLog

	* dwarf2.def (DW_AT_noreturn): New DWARF5 attribute.

The dwarf2.h addition and the code to emit the new attribute is already in
the gcc tree.
2015-01-23 17:29:19 +01:00
Pedro Alves 198297aafb Linux: make target_is_async_p return false when async is off
linux_nat_is_async_p currently always returns true, even when the
target is _not_ async.  That confuses
gdb_readline_wrapper/gdb_readline_wrapper_cleanup, which
force-disables target-async while the secondary prompt is active.  As
a result, when gdb_readline_wrapper returns, the target is left async,
even through it was sync to begin with.

That can result in weird bugs, like the one the test added by this
commit exposes.

Ref: https://sourceware.org/ml/gdb-patches/2015-01/msg00592.html

gdb/ChangeLog:
2015-01-23  Pedro Alves  <palves@redhat.com>

	* linux-nat.c (linux_is_async_p): New macro.
	(linux_nat_is_async_p):
	(linux_nat_terminal_inferior): Check whether the target can async
	instead of whether it is already async.
	(linux_nat_terminal_ours): Don't check whether the target is
	async.
	(linux_async_pipe): Use linux_is_async_p.

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

	* gdb.threads/continue-pending-after-query.c: New file.
	* gdb.threads/continue-pending-after-query.exp: New file.
2015-01-23 11:12:39 +00:00
Joel Brobecker bbbbffbbfc Fix filename in one of the recent gdb/ChangeLog entries (remove "gdb/"). 2015-01-23 08:16:43 +01:00
Anders Granlund 717cf30c82 Introduce gdb_interact in testsuite
gdb_interact is a small utility that we have found quite useful to debug
test cases.

Putting gdb_interact in a test suspends it and allows to interact with
gdb to inspect whatever you want. You can then type ">>>" to resume the
test execution. Of course, this is only for gdb devs. It wouldn't make
sense to leave a gdb_interact permanently in a test case.

When starting the interaction with the user, the script prints this
banner:

+------------------------------------------+
| Script interrupted, you can now interact |
| with by gdb. Type >>> to continue.       |
+------------------------------------------+

Notes:
* When gdb is launched, the gdb_spawn_id variable (lib/gdb.exp) is
  assigned -1. Given the name, I would expect it to contain the gdb
  expect spawn id, which is needed for interact. I changed all places
  that set gdb_spawn_id to -1 to set it to the actual gdb spawn id
  instead.

* When entering the "interact" mode, the last (gdb) prompt is already
  eaten by expect, so it doesn't show up on the terminal. Subsequent
  prompts do appear though. We tried to print "(gdb)" just before the
  interact to replace it. However, it could be misleading if you are
  debugging an MI test case, it makes you think that you are typing in a
  CLI prompt, when in reality it's MI. In the end I decided that since
  the feature is for developers who know what they're doing and that one
  is normally consciously using gdb_interact, the script doesn't need
  to babysit the user.

* There are probably some quirks depending on where in the script
  gdb_interact appears (e.g. it could interfere with following
  commands and make them fail), but it works for most cases. Quirks can
  always be fixed later.

The idea and original implementation was contributed by Anders
Granlund, a colleague of mine. Thanks to him.

gdb/testsuite/ChangeLog:

	* gdb.base/statistics.exp: Assign spawn id to gdb_spawn_id.
	* gdb.base/valgrind-db-attach.exp: Same.
	* gdb.base/valgrind-infcall.exp: Same.
	* lib/mi-support.exp (default_mi_gdb_start): Same.
	* lib/prompt.exp (default_prompt_gdb_start): Same.
	* lib/gdb.exp (default_gdb_spawn): Same.
	(gdb_interact): New.
2015-01-22 15:49:08 -05:00
Jan Kratochvil 253828f102 Sort threads for thread apply all
downstream Fedora request:
	Please make it easier to find the backtrace of the crashing thread
	https://bugzilla.redhat.com/show_bug.cgi?id=1024504

Currently after loading a core file GDB prints:

Core was generated by `./threadcrash1'.
Program terminated with signal SIGSEGV, Segmentation fault.
8       *(volatile int *)0=0;
(gdb) _

there is nowhere seen which of the threads had crashed.  In reality GDB always
numbers that thread as #1 and it is the current thread that time.  But after
dumping all the info into a file for later analysis it is no longer obvious.
'thread apply all bt' even puts the thread #1 to the _end_ of the output!!!

I find maybe as good enough and with no risk of UI change flamewar to just
sort the threads by their number.  Currently they are printed as they happen
in the internal GDB list which has no advantage.  Printing thread #1 as the
first one with assumed 'thread apply all bt' (after the core file is loaded)
should make the complaint resolved I guess.

On Thu, 15 Jan 2015 20:29:07 +0100, Doug Evans wrote:
No objection to sorting the list, but if thread #1 is the important one,
then a concern could be it'll have scrolled off the screen (such a
concern has been voiced in another thread in another context),
and if not lost (say it's in an emacs buffer) one would still have
to scroll back to see it.
So one *could* still want #1 to be last.
Do we want an option to choose the sort direction?

gdb/ChangeLog
2015-01-22  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* NEWS (Changes since GDB 7.9): Add 'thread apply all' option
	'-ascending'.
	* thread.c (tp_array_compar_ascending, tp_array_compar): New.
	(thread_apply_all_command): Parse CMD for tp_array_compar_ascending.
	Sort tp_array using tp_array_compar.
	(_initialize_thread): Extend thread_apply_all_command help.

gdb/doc/ChangeLog
2015-01-22  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.texinfo (Threads): Describe -ascending for thread apply all.
2015-01-22 21:04:53 +01:00
Jan Kratochvil f0e8c4c5d1 Print current thread after loading a core file
downstream Fedora request:
	Please make it easier to find the backtrace of the crashing thread
	https://bugzilla.redhat.com/show_bug.cgi?id=1024504

Currently after loading a core file GDB prints:

Core was generated by `./threadcrash1'.
Program terminated with signal SIGSEGV, Segmentation fault.
8       *(volatile int *)0=0;
(gdb) _

there is nowhere seen which of the threads had crashed.  In reality GDB always
numbers that thread as #1 and it is the current thread that time.  But after
dumping all the info into a file for later analysis it is no longer obvious.
'thread apply all bt' even puts the thread #1 to the _end_ of the output!!!

Should GDB always print after loading a core file what "thread" command would
print?
[Current thread is 1 (Thread 0x7fcbe28fe700 (LWP 15453))]

BTW I think it will print the thread even when loading single/non-threaded
core file when other inferior(s) exist.  But that currently crashes
	[Bug threads/12074] multi-inferior internal error
	https://sourceware.org/bugzilla/show_bug.cgi?id=12074
plus I think that would be a correct behavior anyway.

gdb/ChangeLog
2015-01-22  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* corelow.c (core_open): Call also thread_command.
	* gdbthread.h (thread_command): New prototype moved from ...
	* thread.c (thread_command): ... here.
	(thread_command): Make it global.
2015-01-22 21:02:24 +01:00
Pedro Alves 03b7960334 mingw32: fix windows-termcap/curses check
When GDB is configured with "--without-tui --with-curses" or "--with-tui",
$prefer_curses is set to yes.  But, that still doesn't mean that curses
will be used.  configure will still search for the curses library, and
continue building without it.  That's done here:

 curses_found=no
 if test x"$prefer_curses" = xyes; then
 ...
   AC_SEARCH_LIBS(waddstr, [ncurses cursesX curses])

   if test "$ac_cv_search_waddstr" != no; then
     curses_found=yes
   fi
 fi

So if waddstr is not found, meaning curses is not really
available, even though it'd be preferred, $prefer_curses is
'yes', but $curses_found is 'no'.

So the right fix to tell whether we're linking with curses is
$curses_found=yes.

gdb/ChangeLog:
2015-01-22  Pedro Alves  <palves@redhat.com>

	* configure.ac [*mingw32*]: Check $curses_found instead of
	$prefer_curses.
	* configure: Regenerate.
	* windows-termcap.c: Remove HAVE_CURSES_H, HAVE_NCURSES_H and
	HAVE_NCURSES_NCURSES_H checks.
2015-01-22 18:30:01 +00:00
Eli Zaretskii 6b8a872ff1 Fix MinGW TUI build
gdb/
2015-01-22  Eli Zaretskii  <eliz@gnu.org>

	* gdb/tui/tui.c (tui_enable) [__MINGW32__]: If the call to 'newterm'
	fails with the 1st arg NULL, try again with "unknown".  Don't test
	the "cup" capability: it isn't supported by the Windows port of
	ncurses, but the Windows console driver is still capable of
	supporting TUI.
2015-01-22 20:24:57 +02:00
Jan Kratochvil 4b62a76e0c compile: Fix function pointers
TBH while I always comment reasons for each of the compilation options in
reality I tried them all and chose that combination that needs the most simple
compile/compile-object-load.c (ld.so emulation) implementation.

gdb/ChangeLog
2015-01-22  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* compile/compile.c (_initialize_compile): Use -fPIE for compile_args.

gdb/testsuite/ChangeLog
2015-01-22  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.compile/compile.exp (pointer to jit function): New test.
2015-01-22 19:18:16 +01:00
Eli Zaretskii 82a864f96a Partial fix for "make TAGS".
gdb/
2015-01-22  Eli Zaretskii  <eliz@gnu.org>

	* Makefile.in (HFILES_NO_SRCDIR): Remove ada-varobj.h.
	(ALLDEPFILES): Remove irix5-nat.c.  These two are part of the
	reason that "make TAGS" is broken.
2015-01-22 20:05:59 +02:00
Chen Gang b35018fd7a gdb/hppa-tdep.c: Fix logical working flow issues and check additional store instructions.
Original working flow has several issues:

 - typo issue: "(inst >> 26) == 0x1f && ..." for checking 'stw(m)'.

 - "(inst >> 6) == 0xa" needs to be "((inst >> 6) & 0xf) == 0xa".

And also need check additional store instructions:

 - For absolute memory: 'stby', 'stdby'.

 - For unaligned: 'stwa', 'stda'.

The original code also can be improved:

 - Remove redundant double check "(inst >> 26) == 0x1b" for 'stwm'.

 - Use 2 'switch' statements instead of all 'if' statements.

	* hppa-tdep.c (inst_saves_gr): Fix logical working flow issues
	and check additional store instructions.
2015-01-22 20:47:10 +08:00
Wei-cheng Wang ffbc46469f Add myself as write-after-approval GDB maintainer.
gdb/ChangeLog:

	* MAINTAINERS (Write After Approval): Add "Wei-cheng Wang".
2015-01-21 23:39:23 +08:00
Wei-cheng Wang ddeca1dffb Add missing comments in rs6000-tdep.c, ppc64-tdep.c and ppc-linux-tdep.c.
gdb/ChangeLog:

	* ppc-linux-tdep.c (ppc_skip_trampoline_code,
	ppc_canonicalize_syscall, ppc_linux_syscall_record,
	ppc_linux_record_signal, ppc_init_linux_record_tdep): Add comments.
	* ppc64-tdep.c (ppc64_skip_trampoline_code): Likewise.
	* rs6000-tdep.c (rs6000_epilogue_frame_cache,
	rs6000_epilogue_frame_this_id, rs6000_epilogue_frame_prev_register,
	rs6000_epilogue_frame_sniffer, ppc_record_vsr, ppc_process_record_op4,
	ppc_process_record_op19, ppc_process_record_op31,
	ppc_process_record_op59, ppc_process_record_op60,
	ppc_process_record_op63): Likewise.
2015-01-21 23:38:09 +08:00
Joel Brobecker 049bb5dee8 gdb/ARI: Call safe_strerror instead of strerror in linux-ptrace.c
gdb/ChangeLog:

        * nat/linux-ptrace.c (linux_ptrace_attach_fail_reason_string)
        (linux_ptrace_test_ret_to_nx): Use safe_strerror instead of
        strerror.
2015-01-20 19:08:17 +01:00
Joel Brobecker 42b87c63bc Fix date in gdb/ChangeLog. 2015-01-20 19:04:26 +01:00
Wei-cheng Wang 810c102655 Fix format warning in rs6000t-dep.c 2015-01-20 22:59:39 +08:00
Chen Gang 569340fcf2 Add myself as write-after-approval GDB maintainer.
gdb/ChangeLog:

	* MAINTAINERS (Write After Approval): Add "Chen Gang".
2015-01-20 22:17:09 +08:00
Eli Zaretskii 63413d8587 Don't use windows-termcap.c when linking against a curses library
gdb/
2015-01-17  Eli Zaretskii  <eliz@gnu.org>

        * configure.ac [*mingw32*]: Only add windows-termcap.o to
        CONFIG_OBS if not building with a curses library.
        * configure: Regenerate.

        * windows-termcap.c: Include defs.h.  Make the whole body empty if
        either one of HAVE_CURSES_H or HAVE_NCURSES_H or
        HAVE_NCURSES_NCURSES_H is defined.
2015-01-19 16:35:11 +01:00
Joel Brobecker 16d8013cf7 Fix ARI warning in rs6000-tdep.c::rs6000_gdbarch_init.
gdb/ChangeLog:

        * rs6000-tdep.c (rs6000_gdbarch_init): Move divide operator
        from end of line to start of next line.
2015-01-19 08:54:02 +01:00
Wei-cheng Wang cf90fd9a07 Skip-trampoline for PowerPC reverse-stepping. 2015-01-17 19:48:22 +08:00
Wei-cheng Wang b4cdae6fe5 Reverse debugging for PowerPC. 2015-01-17 19:48:22 +08:00
Wei-cheng Wang 2608dbf8a3 Epilogue unwinder for PowerPC. 2015-01-17 19:48:22 +08:00
Eli Zaretskii 2ef60e94e7 Really add a prototype for tui_rehighlight_all. 2015-01-16 19:58:04 +02:00
Sergio Durigan Junior 4c347be60a Fix nat/linux-personality.c regression on RHEL-5
This commit fixes the regression on RHEL-5 systems introduced by
nat/linux-personality.c's check of HAVE_DECL_ADDR_NO_RANDOMIZE.
RHEL-5 systems define HAVE_DECL_ADDR_NO_RANDOMIZE as zero, so we
cannot use #ifndef; instead this patch uses the "#if !" construction.

The regression was reported by Ulrich Weigand here:

  <https://sourceware.org/ml/gdb-patches/2015-01/msg00458.html>

gdb/ChangeLog
2015-01-16  Sergio Durigan Junior  <sergiodj@redhat.com>

	* nat/linux-personality.c: Replace "#ifndef
	HAVE_DECL_ADDR_NO_RANDOMIZE" by "#if
	!HAVE_DECL_ADDR_NO_RANDOMIZE", fixing a regression in RHEL-5
	systems.
2015-01-16 11:42:28 -05:00
Eli Zaretskii c54da50d66 Fix an erroneous commentary.
gdb/
2015-01-16  Eli Zaretskii  <eliz@gnu.org>

    * tui/tui-win.c (tui_set_tab_width_command): Fix the commentary.
2015-01-16 18:32:42 +02:00
Eli Zaretskii 6cdb25f4df Make setting TUI border attributes take effect immediately
gdb/
2015-01-16  Eli Zaretskii  <eliz@gnu.org>

     * tui/tui-win.c (tui_rehighlight_all, tui_set_var_cmd): New
     functions.
     (_initialize_tui_win) <border-kind, border-mode>:
     <active-border-mode>: Use tui_set_var_cmd as the "set" function.
     * tui/tui-win.h: Add prototype for tui_rehighlight_all.
2015-01-16 18:24:16 +02:00
Eli Zaretskii cb86fcc13b Make the change of tab size in TUI mode effective immediately
gdb/ChangeLog:
2015-01-16  Eli Zaretskii  <eliz@gnu.org>

    * tui/tui-win.c (tui_set_tab_width_command): Delete and
    recreate the source and the disassembly windows, to show the
    effect of the changed tab size immediately.
2015-01-16 17:46:12 +02:00
Eli Zaretskii bf555842fc Fix TUI-related documentation.
tui/tui-win.c (tui_scroll_left_command, tui_scroll_right_command):
Doc fix.
doc/gdb.texinfo (TUI Commands): Document the possible
values of NAME argument to 'winheight' command.  Explain the
effect of 'tabset' setting better.
2015-01-16 13:33:25 +02:00
Eli Zaretskii 9f2850baa3 Leave more space in TUI mode for thread ID.
gdb/tui/tui-data.h (LINE_PREFIX): Make shorter
(MAX_PID_WIDTH): Enlarge from 14 to 19, to leave enough space for
"Thread NNNNN.XXXX" thread ID notation on Windows.
2015-01-16 13:24:20 +02:00
Jan Kratochvil 95761b2d9c Fix gcc-5 compilation
With gcc-5.0 pre-release one gets:

hppa-tdep.c: In function ‘inst_saves_gr’:
hppa-tdep.c:1406:30: error: comparison of constant ‘9’ with boolean expression is always false [-Werror=bool-compare]

I find the misplaced parentheses obvious.

gdb/ChangeLog
2015-01-16  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix gcc-5 compilation.
	* hppa-tdep.c (inst_saves_gr): Fix parentheses typo.
2015-01-16 06:39:47 +01:00
Sergio Durigan Junior 8cc73a3902 Move code to disable ASR to nat/
This patch moves the shared code present on
gdb/linux-nat.c:linux_nat_create_inferior and
gdb/gdbserver/linux-low.c:linux_create_inferior to
nat/linux-personality.c.  This code is responsible for disabling
address space randomization based on user setting, and using
<sys/personality.h> to do that.  I decided to put the prototype of the
maybe_disable_address_space_randomization on nat/linux-osdata.h
because it seemed the best place to put it.

I regression-tested this patch on Fedora 20 x86_64, and found no
regressions.

gdb/ChangeLog
2015-01-15  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (HFILES_NO_SRCDIR): Add nat/linux-personality.h.
	(linux-personality.o): New rule.
	* common/common-defs.h: Include <stdint.h>.
	* config/aarch64/linux.mh (NATDEPFILES): Include
	linux-personality.o.
	* config/alpha/alpha-linux.mh (NATDEPFILES): Likewise.
	* config/arm/linux.mh (NATDEPFILES): Likewise.
	* config/i386/linux64.mh (NATDEPFILES): Likewise.
	* config/i386/linux.mh (NATDEPFILES): Likewise.
	* config/ia64/linux.mh (NATDEPFILES): Likewise.
	* config/m32r/linux.mh (NATDEPFILES): Likewise.
	* config/m68k/linux.mh (NATDEPFILES): Likewise.
	* config/mips/linux.mh (NATDEPFILES): Likewise.
	* config/pa/linux.mh (NATDEPFILES): Likewise.
	* config/powerpc/linux.mh (NATDEPFILES): Likewise.
	* config/powerpc/ppc64-linux.mh (NATDEPFILES): Likewise.
	* config/powerpc/spu-linux.mh (NATDEPFILES): Likewise.
	* config/s390/linux.mh (NATDEPFILES): Likewise.
	* config/sparc/linux64.mh (NATDEPFILES): Likewise.
	* config/sparc/linux.mh (NATDEPFILES): Likewise.
	* config/tilegx/linux.mh (NATDEPFILES): Likewise.
	* config/xtensa/linux.mh (NATDEPFILES): Likewise.
	* defs.h: Remove #include <stdint.h> (moved to
	common/common-defs.h).
	* linux-nat.c: Include nat/linux-personality.h.  Remove #include
	<sys/personality.h>; do not define ADDR_NO_RANDOMIZE (moved to
	nat/linux-personality.c).
	(linux_nat_create_inferior): Remove code to disable address space
	randomization (moved to nat/linux-personality.c).  Create cleanup
	to disable address space randomization.
	* nat/linux-personality.c: New file.
	* nat/linux-personality.h: Likewise.

gdb/gdbserver/ChangeLog
2015-01-15  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (SFILES): Add linux-personality.c.
	(linux-personality.o): New rule.
	* configure.srv (srv_linux_obj): Add linux-personality.o to the
	list of objects to be built.
	* linux-low.c: Include nat/linux-personality.h.
	(linux_create_inferior): Remove code to disable address space
	randomization (moved to ../nat/linux-personality.c).  Create
	cleanup to disable address space randomization.
2015-01-15 15:10:49 -05:00
Sergio Durigan Junior fb23d55442 Move safe_strerror to common/
This patch moves safe_strerror from the gdb/{posix,mingw}-hdep.c files
to the respective common/{posix,mingw}-strerror.c files.  This is a
preparation for the next patch, which shares a common code (to disable
address space randomization when creating a new inferior).

The patch has been regtested on Fedora 20 x86_64, and no regressions
were found.

gdb/ChangeLog
2015-01-15  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (ALLDEPFILES): Including common/mingw-strerror.c and
	common/posix-strerror.c.
	(posix-strerror.o): New rule.
	(mingw-strerror.o): Likewise.
	* common/common-utils.h (safe_strerror): Move prototype to here,
	from utils.h.
	* common/common.host: New file.
	* common/mingw-strerror.c: Likewise.
	* common/posix-strerror.c: Likewise.
	* configure: Regenerated.
	* configure.ac: Source common/common.host.  Add variable
	common_host_obs to gdb_host_obs.
	* contrib/ari/gdb_ari.sh: Mention gdb/common/mingw-strerror.c and
	gdb/common/posix-strerror.c when warning about the use of
	strerror.
	* mingw-hdep.c (safe_strerror): Remove definition; move it to
	common/mingw-strerror.c.
	* posix-hdep.c (safe_strerror): Remove definition; move it to
	common/posix-hdep.c.
	* utils.h (safe_strerror): Remove prototype; move to
	common/common-utils.h.

gdb/gdbserver/ChangeLog
2015-01-15  Sergio Durigan Junior  <sergiodj@redhat.com>

	* Makefile.in (posix-strerror.o): New rule.
	(mingw-strerror.o): Likewise.
	* configure: Regenerated.
	* configure.ac: Source file ../common/common.host.  Initialize new
	variable srv_host_obs.  Add srv_host_obs to GDBSERVER_DEPFILES.
2015-01-15 15:09:15 -05:00
Don Breazeal d221e7efd6 Skip two more attach tests when testing against stub-like targets
This patch updates two attach tests to use utility procs for checking if
the attach test should run and for launching the program to be attached, as
follows:

1) Use can_spawn_for_attach instead of is_remote target
2) Use spawn_wait_for_attach instead of exec/sleep

Tested (1) with i686-mingw32 host and i686-pc-linux-gnu build/target and
both with x86_64 Ubuntu.

gdb/testsuite/ChangeLog:

	* gdb.base/attach-pie-noexec.exp: Use can_spawn_for_attach
	instead of checking whether the target board is remote and
	use spawn_wait_for_attach instead of exec/sleep.
	* gdb.base/attach-twice.exp: Likewise.
2015-01-15 10:59:57 -08:00
Joel Brobecker 3af8af43f7 Document the GDB 7.8.2 release in gdb/ChangeLog
gdb/ChangeLog:

	GDB 7.8.2 released.
2015-01-15 15:10:36 +04:00
Joel Brobecker bafffb51c4 [Ada] 'first/'last/'length of array whose bound is a discriminant
Consider the following code:

   type Table is array (Positive range <>) of Integer;
   type Object (N : Integer) is record
       Data : Table (1 .. N);
   end record;
   My_Object : Object := (N => 3, Data => (3, 5, 8));

Trying to print the range and length of the My_Object.Data array yields:

    (gdb) print my_object.data'first
    $1 = 1
    (gdb) print my_object.data'last
    $2 = 0
    (gdb) print my_object.data'length
    $3 = 0

The first one is correct, and that is thanks to the fact that
the lower bound is statically known.  However, for the upper
bound, and consequently the array's length, the values are incorrect.
It should be:

    (gdb) print my_object.data'last
    $2 = 3
    (gdb) print my_object.data'length
    $3 = 3

What happens here is that ada_array_bound_from_type sees that
our array has a parallel "___XA" type, and therefore tries to
use it.  In particular, it described our array's index type as:
[...]___XDLU_1__n, which means lower bound = 1, and upper bound
is value of "n". Unfortunately, ada_array_bound_from_type does
not have access to the discriminant, and is therefore unable to
compute the bound correctly.

Fortunately, at this stage, the bound has already been computed
a while ago, and therefore doesn't need to be re-computed here.
This patch fixes the issue by ignoring that ___XA type if the array
is marked as already fixed.

This also fixes the same issue with packed arrays.

gdb/ChangeLog:

        * ada-lang.c (ada_array_bound_from_type): Ignore array's parallel
        ___XA type if the array has already been fixed.

gdb/testsuite/ChangeLog:

        * gdb.ada/var_arr_attrs: New testcase.
2015-01-15 12:53:33 +04:00
Yao Qi cdf436294f Detect 64-bit-ness in PowerPC Book III-E
This patch is to teach both GDB and GDBServer to detect 64-bit inferior
correctly.  We find a problem that GDBServer is unable to detect on a
e5500 core processor.  Current GDBServer assumes that MSR is a 64-bit
register, but MSR is a 32-bit register in Book III-E.  This patch is
to fix this problem by checking the right bit in MSR, in order to handle
both Book III-S and Book III-E.  In order to detect Book III-S and
Book III-E, we check the PPC_FEATURE_BOOKE from the host's HWCAP (by
getauxval on glibc >= 2.16.  If getauxval doesn't exist, we implement
the fallback by parsing /proc/self/auxv), because it should an invariant
on the same machine cross different processes.

In order to share code, I add nat/ppc-linux.c for both GDB and
GDBserver side.

gdb:

2015-01-14  Yao Qi  <yao@codesourcery.com>

	* Makefile.in (ppc-linux.o): New rule.
	* config/powerpc/ppc64-linux.mh (NATDEPFILES): Add ppc-linux.o.
	* configure.ac: AC_CHECK_FUNCS(getauxval).
	* config.in: Re-generated.
	* configure: Re-generated.
	* nat/ppc-linux.h [__powerpc64__] (ppc64_64bit_inferior_p):
	Declare.
	* nat/ppc-linux.c: New file.
	* ppc-linux-nat.c (ppc_linux_target_wordsize) [__powerpc64__]:
	Call ppc64_64bit_inferior_p.

gdb/gdbserver:

2015-01-14  Yao Qi  <yao@codesourcery.com>

	* Makefile.in (SFILES): Add nat/ppc-linux.c.
	(ppc-linux.o): New rule.
	* configure.srv (powerpc*-*-linux*): Add ppc-linux.o.
	* configure.ac: AC_CHECK_FUNCS(getauxval).
	* config.in: Re-generated.
	* configure: Re-generated.
	* linux-ppc-low.c (ppc_arch_setup) [__powerpc64__]: Call
	ppc64_64bit_inferior_p
2015-01-14 22:28:27 +08:00
Yao Qi 514c533895 Move some ppc macros to nat/ppc-linux.h
When I use PPC_FEATURE_BOOKE in GDBserver, I find it is defined in GDB
but not in GDBserver.  After taking a further look, I find some macros
are duplicated between ppc-linux-nat.c and linux-ppc-low.c, so this
patch is to move them into nat/ppc-linux.h.

gdb/gdbserver:

2015-01-14  Yao Qi  <yao@codesourcery.com>

	* linux-ppc-low.c: Include "nat/ppc-linux.h".
	 (PPC_FEATURE_HAS_VSX): Move to nat/ppc-linux.h.
	(PPC_FEATURE_HAS_ALTIVEC,  PPC_FEATURE_HAS_SPE): Likewise.
	(PT_ORIG_R3, PT_TRAP): Likewise.
	(PTRACE_GETVSXREGS, PTRACE_SETVSXREGS): Likewise.
	(PTRACE_GETVRREGS, PTRACE_SETVRREGS): Likewise.
	(PTRACE_GETEVRREGS, PTRACE_SETEVRREGS): Likewise.

gdb:

2015-01-14  Yao Qi  <yao@codesourcery.com>

	* ppc-linux-nat.c (PT_ORIG_R3, PT_TRAP): Move to
	nat/ppc-linux.h.
	(PPC_FEATURE_CELL, PPC_FEATURE_BOOKE): Likewise.
	(PPC_FEATURE_HAS_DFP): Likewise.
	(PTRACE_GETVRREGS, PTRACE_SETVRREGS): Likewise.
	(PTRACE_GETVSXREGS, PTRACE_SETVSXREGS): Likewise.
	(PTRACE_GETEVRREGS, PTRACE_SETEVRREGS): Likewise.
	Include "nat/ppc-linux.h".
	* nat/ppc-linux.h: New file.
	* Makefile.in (HFILES_NO_SRCDIR): Add nat/ppc-linux.h.
2015-01-14 22:28:22 +08:00
Pedro Alves 5589af0e66 PR17525 - breakpoint commands not executed when program run from -x script
Executing a gdb script that runs the inferior (from the command line
with -x), and has it hit breakpoints with breakpoint commands that
themselves run the target, is currently broken on async targets
(Linux, remote).

While we're executing a command list or a script, we force the
interpreter to be sync, which results in some functions nesting an
event loop and waiting for the target to stop, instead of returning
immediately and having the top level event loop handle the stop.

The issue with this bug is simply that bpstat_do_actions misses
checking whether the interpreter is sync.  When we get here, in the
case of executing a script (or, when the interpreter is sync), the
program has already advanced to the next breakpoint, through
maybe_wait_sync_command_done.  We need to process its breakpoints
immediately, just like with a sync target.

Tested on x86_64 Fedora 20.

gdb/
2015-01-14  Pedro Alves  <palves@redhat.com>

	PR gdb/17525
	* breakpoint.c: Include "interps.h".
	(bpstat_do_actions_1): Also check whether the interpreter is
	async.

gdb/testsuite/
2015-01-14  Pedro Alves  <palves@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>

	PR gdb/17525
	* gdb.base/bp-cmds-execution-x-script.c: New file.
	* gdb.base/bp-cmds-execution-x-script.exp: New file.
	* gdb.base/bp-cmds-execution-x-script.gdb: New file.
2015-01-14 12:34:12 +00:00
Pedro Alves 6c400b59d5 PR cli/17828: -batch -ex r breaks terminal
Commit d3d4baed (PR python/17372 - Python hangs when displaying
help()) had the side effect of causing 'gdb -batch' to leave the
terminal in the wrong state if the program was run.  E.g,.

 $ echo 'main(){*(int*)0=0;}' | gcc -x c -; ./gdb/gdb -batch -ex r ./a.out
 Program received signal SIGSEGV, Segmentation fault.
 0x00000000004004ff in main ()
 $

If you start typing the next command, seemingly nothing happens - GDB
left the terminal with echo disabled.

The issue is that that "r" ends up in fetch_inferior_event, which
calls reinstall_readline_callback_handler_cleanup, which causes
readline to prep the terminal (raw, echo disabled).  But "-batch"
causes GDB to exit before the top level event loop is first started,
and then nothing de-preps the terminal.

The reinstall_readline_callback_handler_cleanup function's intro
comment mentions:

 "Need to do this as we go back to the event loop, ready to process
 further input."

but the implementation forgets the case of when the interpreter is
sync, which indicates we won't return to the event loop yet, or as in
the case of -batch, we have not started it yet.

The fix is to not install the readline callback in that case.

For the test, in this case, checking that command echo still works is
sufficient.  Comparing stty output before/after running GDB is even
better.  Because stty may not be available, the test tries both ways.
In any case, since expect's spawn (what we use to start gdb) creates a
new pseudo tty, another expect spawn or tcl exec after GDB exits would
not see the wrong terminal settings.  So instead, the test spawns a
shell and runs stty and GDB in it.

Tested on x86_64 Fedora 20.

gdb/
2015-01-14  Pedro Alves  <palves@redhat.com>

	PR cli/17828
	* infrun.c (reinstall_readline_callback_handler_cleanup): Don't
	reinstall if the interpreter is sync.

gdb/testsuite/
2015-01-14  Pedro Alves  <palves@redhat.com>

	PR cli/17828
	* gdb.base/batch-preserve-term-settings.c: New file.
	* gdb.base/batch-preserve-term-settings.exp: New file.
2015-01-14 11:51:06 +00:00
Doug Evans e02c96a799 Enhance gdb.lookup_objfile so that it works with a symlinked binary.
gdb/Changelog:

	* objfiles.c (objfile_filename): New function.
	* objfiles.h (objfile_filename): Declare it.
	(objfile_name): Add function comment.
	* python/py-objfile.c (objfpy_lookup_objfile_by_name): Try both the
	bfd file name (which may be realpath'd), and the original name.

gdb/testsuite/ChangeLog:

	* gdb.python/py-objfile.exp: Test gdb.lookup_objfile on symlinked
	binary.
2015-01-13 17:02:53 -08:00
Joel Brobecker 576fd14c68 gdb/testsuite: Make clean mostlyclean should not delete *.py.
A sanity-check in my release scripts caught something: After having
created the tarballs, I verify that no checked-in file disappeared
in the process, and lo and behod, it found that the following file
got wiped:

    - gdb/testsuite/dg-extract-results.py:

And it's not part of the tarball either.

I don't understand while we delete all *.py files in gdb/testsuite,
since I don't see a rule that expected to create one. A run of the
testsuite also doesn't seem to be creating .py files there.
I traced this to the following commit, which unfortunately provided
no explanation. Perhaps we used to run some tests in the gdb/testsuite
directory and caused files to be left behind there. Perhaps we still
do today?

In the meantime, Executive Decision: In order to allow me to create
tarballs without losing files, I removed it. It's easy to put something
back if we find out why it might still be needed.

gdb/testsuite/ChangeLog:

        * Makefile.in (clean mostlyclean): Do not delete *.py.

Tested on x86_64-linux by running the src-release.sh script again,
and this time, dg-extract-results.py no longer gets wiped.
2015-01-13 19:24:54 +04:00
Joel Brobecker 3b2f13ff2f Update NEWS post GDB 7.9 branch creation.
gdb/ChangeLog:

	* NEWS: Create a new section for the next release branch.
	Rename the section of the current branch, now that it has
	been cut.
2015-01-13 16:24:45 +04:00
Joel Brobecker b4cfe7f88e Bump version to 7.9.50.DATE-cvs.
Now that the GDB 7.9 branch has been created, we can
bump the version number.

gdb/ChangeLog:

	GDB 7.9 branch created (92fc2e6978):
	* version.in: Bump version to 7.9.50.DATE-cvs.
2015-01-13 16:16:07 +04:00
Joel Brobecker 92fc2e6978 [ARI] Remove trailing new-line in argument of call to warning.
gdb/ChangeLog:

        * nat/linux-procfs.c (linux_proc_attach_tgid_threads):
        Remove trailing new-line in argument of call to warning.
2015-01-13 14:38:19 +04:00
Joel Brobecker f71f0b0d6b [ARI] Remove trailing new-line in argument of call to warning.
gdb/ChangeLog:

	* linux-nat.c (attach_proc_task_lwp_callback): Remove trailing
	new-line in argument of call to "warning".
2015-01-13 14:38:18 +04:00
Joel Brobecker 04dccad086 [python/Ada] gdb.lookup_type fails to looking primitive type
The following change...

    commit 1994afbf19
    Date:   Tue Dec 23 07:55:39 2014 -0800
    Subject: Look up primitive types as symbols.

... caused the following regression:

    % gdb
    (gdb) set lang ada
    (gdb) python print gdb.lookup_type('character')
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    gdb.error: No type named character.
    Error while executing Python code.

This is because the language_lookup_primitive_type_as_symbol call
was moved to the la_lookup_symbol_nonlocal hook. A couple of
implementations have been upated accordingly, but the Ada version
has not. This patch fixes this omission.

gdb/ChangeLog:

        * ada-lang.c (ada_lookup_symbol_nonlocal): If name not found
        in static block, then try searching for primitive types.

gdb/testsuite/ChangeLog:

        * gdb.python/py-lookup-type.exp: New file.
2015-01-13 13:38:58 +04:00
Patrick Palka 08b13bdd82 Append to input history file instead of overwriting it
This patch makes readline append new history lines to the GDB history
file on exit instead of overwriting the entire history file on exit.
This change allows us to run multiple simultaneous GDB sessions without
having each session overwrite the added history of each other session on
exit.

Care must be taken to ensure that the history file doesn't get corrupted
when multiple GDB processes are trying to simultaneously append to and
then truncate it.  Safety is achieved in such a situation by using an
intermediate local history file to mutually exclude multiple processes
from simultaneously performing write operations on the global history
file.

gdb/ChangeLog:

	* top.h (gdb_add_history): Declare.
	* top.c (command_count): New variable.
	(gdb_add_history): New function.
	(gdb_safe_append_history): New static function.
	(quit_force): Call it.
	(command_line_input): Use gdb_add_history instead of
	add_history.
	* event-top.c (command_line_handler): Likewise.
2015-01-12 17:51:33 -05:00
James Clarke 4ac15b59f2 [darwin/gdb] Use <setjmp.h> instead of <machine/setjmp.h>
The `machine/setjmp.h' header is no longer present on OS X 10.10, and is
non-standard. Instead, `darwin-nat.c' should be using the standard
`setjmp.h' header.

gdb/ChangeLog:

2015-01-12  James Clarke  <jrtc27@jrtc27.com>  (tiny patch)

	PR gdb/17046
	* darwin-nat.c: Replace <machine/setjmp.h> #include by
	<setjmp.h> #include.
2015-01-12 21:18:16 +04:00
Pedro Alves 3d230f7174 gdb.python/py-prompt.exp: restore GDBFLAGS
The previous change to py-prompt.exp made it return without restoring
GDBFLAGS, resulting in breaking the following tests:

  $ make check RUNTESTFLAGS="--target_board=native-gdbserver --directory=gdb.python"
  ...
  Running src/gdb/testsuite/gdb.python/py-prompt.exp ...
  Running src/gdb/testsuite/gdb.python/py-section-script.exp ...
  ERROR: (timeout) GDB never initialized after 10 seconds.
  ERROR: no fileid for gdbuild
  ERROR: Couldn't send python print ('test') to GDB.
  ERROR: no fileid for gdbuild
  ERROR: Couldn't send python print (sys.version_info[0]) to GDB.
  ERROR: no fileid for gdbuild
  ERROR: Couldn't send python print (sys.version_info[1]) to GDB.
  ERROR: no fileid for gdbuild
  ERROR: no fileid for gdbuild
  ...

gdb/testsuite/
2015-01-12  Pedro Alves  <palves@redhat.com>

	* gdb.python/py-prompt.exp: When the board can't spawn for attach,
	restore GDBFLAGS before returning.
2015-01-12 17:10:06 +00:00
Jan Kratochvil 7e67715dd3 [testsuite patch] Fix new FAIL: py-frame.exp: test Frame.read_register(rip)
for x86_64 -m32 run one gets:

+FAIL: gdb.python/py-frame.exp: test Frame.read_register(rip)

I do not have x32 OS here but the %rip test should PASS there I think.

On Sun, 11 Jan 2015 14:58:06 +0100, Yao Qi wrote:
With your patch applied, this test is skipped on 'x86_64 -m32'.  I
prefer to increasing the test coverage, so how about extending the test
for 'x86_64 -m32'?  I mean test Frame.read_register(eip)...

gdb/testsuite/ChangeLog
2015-01-12  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.python/py-frame.exp (test Frame.read_register(rip)): Use
	is_amd64_regs_target and is_x86_like_target.
2015-01-12 11:02:46 +01:00
Doug Evans 005e54bb79 dwarf2read.c (compute_delayed_physnames): Use TYPE_FN_FIELD_PHYSNAME.
gdb/ChangeLog:

	* dwarf2read.c (compute_delayed_physnames): Use TYPE_FN_FIELD_PHYSNAME.
2015-01-11 16:39:46 -08:00
Doug Evans f2e0d4b4eb Require numeric attributes to specify the form.
gdb/testsuite/ChangeLog:

	* lib/dwarf.exp (Dwarf): Flag an error if a numeric attribute value
	is given without an explicit form.
	* gdb.dwarf2/arr-subrange.exp: Specify forms for all numeric
	attributes.
	* gdb.dwarf/corrupt.exp: Ditto.
	* gdb.dwarf2/enum-type.exp: Ditto.
	* gdb.trace/entry-values.exp: Ditto.
	* gdb.trace/unavailable-dwarf-piece.exp: Ditto.
2015-01-11 15:45:43 -08:00
Doug Evans 6a3ca06752 Temporarily revert symbol lookup cache.
clear_symtab_users calls breakpoint_re_set before
observer_notify_new_objfile(NULL), and thus symbol lookup
done during breakpoint_re_set will see a stale cache.

Presumably we just need to move the call to observer_notify_new_objfile(NULL)
to before breakpoint_re_set, but need to check for other such issues,
and 7.9 is scheduled to branch tomorrow.

Reverts commits:
b2fb95e006
400678a494
d98b9ccbcc
77087adf50

gdb/ChangeLog:

	* symtab.c (eq_symbol_entry): Use SYMBOL_SEARCH_NAME and
	symbol_matches_domain for symbol comparisons.

	* symtab.c (symbol_cache_mark_found): Improve function comment.
	Rename parameter objfile to objfile_context.
	(symbol_cache_mark_not_found): Improve function comment.

	Add symbol lookup cache.
	* NEWS: Document new options and commands.
	* symtab.c (symbol_cache_key): New static global.
	(DEFAULT_SYMBOL_CACHE_SIZE, MAX_SYMBOL_CACHE_SIZE): New macros.
	(SYMBOL_LOOKUP_FAILED): New macro.
	(symbol_cache_slot_state): New enum.
	(block_symbol_cache): New struct.
	(symbol_cache): New struct.
	(new_symbol_cache_size, symbol_cache_size): New static globals.
	(hash_symbol_entry, eq_symbol_entry): New functions.
	(symbol_cache_byte_size, resize_symbol_cache): New functions.
	(make_symbol_cache, free_symbol_cache): New functions.
	(get_symbol_cache, symbol_cache_cleanup): New function.
	(set_symbol_cache_size, set_symbol_cache_size_handler): New functions.
	(symbol_cache_lookup, symbol_cache_clear_slot): New function.
	(symbol_cache_mark_found, symbol_cache_mark_not_found): New functions.
	(symbol_cache_flush, symbol_cache_dump): New functions.
	(maintenance_print_symbol_cache): New function.
	(maintenance_flush_symbol_cache): New function.
	(symbol_cache_stats): New function.
	(maintenance_print_symbol_cache_statistics): New function.
	(symtab_new_objfile_observer): New function.
	(symtab_free_objfile_observer): New function.
	(lookup_static_symbol, lookup_global_symbol): Use symbol cache.
	(_initialize_symtab): Init symbol_cache_key.  New parameter
	maint symbol-cache-size.  New maint commands print symbol-cache,
	print symbol-cache-statistics, flush-symbol-cache.
	Install new_objfile, free_objfile observers.

gdb/doc/ChangeLog:

	* gdb.texinfo (Symbols): Document new commands
	"maint print symbol-cache", "maint print symbol-cache-statistics",
	"maint flush-symbol-cache".  Document new option
	"maint set symbol-cache-size".
2015-01-11 15:16:26 -08:00
Doug Evans 439250fbac PR gdb/15830
gdb/ChangeLog:

	PR gdb/15830
	* NEWS: The "maint demangle" command is renamed as "demangle".
	* demangle.c: #include cli/cli-utils.h, language.h.
	(demangle_command): New function.
	(_initialize_demangle): Add new command "demangle".
	* maint.c (maintenance_demangle): Stub out.
	(_initialize_maint_cmds): Update help text for "maint demangle",
	and mark as deprecated.

gdb/doc/ChangeLog:

	* gdb.texinfo (Debugging C Plus Plus): Mention "demangle".
	(Symbols): Ditto.
	(Maintenance Commands): Delete docs for "maint demangle".

gdb/testsuite/ChangeLog:

	* gdb.base/maint.exp: Remove references to "maint demangle".
	* gdb.cp/demangle.exp: Update.  "maint demangle" -> "demangle".
	Add tests for explicitly specifying language to demangle.
	* gdb.dlang/demangle.exp: Ditto.
2015-01-11 14:06:34 -08:00
Mark Kettenis ebf3aa7224 Fix build on OpenBSD.
gdb/ChangeLog:

	* inf-ptrace.c (inf_ptrace_follow_fork): Adjust now that
	inferior_thread is a function.
2015-01-11 22:16:11 +01:00
Doug Evans 77087adf50 symtab.c (eq_symbol_entry): Use SYMBOL_SEARCH_NAME and symbol_matches_domain.
gdb/ChangeLog:

	* symtab.c (eq_symbol_entry): Use SYMBOL_SEARCH_NAME and
	symbol_matches_domain for symbol comparisons.
2015-01-11 12:02:23 -08:00
Doug Evans d98b9ccbcc tweak previous entry 2015-01-11 11:40:41 -08:00
Doug Evans 400678a494 Improve comments for symbol_cache_mark_{not_,}found.
gdb/ChangeLog:

	* symtab.c (symbol_cache_mark_found): Improve function comment.
	Rename parameter objfile to objfile_context.
	(symbol_cache_mark_not_found): Ditto.
2015-01-11 11:36:36 -08:00
Doug Evans b2fb95e006 Add symbol lookup cache.
gdb/ChangeLog:

	Add symbol lookup cache.
	* NEWS: Document new options and commands.
	* symtab.c (symbol_cache_key): New static global.
	(DEFAULT_SYMBOL_CACHE_SIZE, MAX_SYMBOL_CACHE_SIZE): New macros.
	(SYMBOL_LOOKUP_FAILED): New macro.
	(symbol_cache_slot_state): New enum.
	(block_symbol_cache): New struct.
	(symbol_cache): New struct.
	(new_symbol_cache_size, symbol_cache_size): New static globals.
	(hash_symbol_entry, eq_symbol_entry): New functions.
	(symbol_cache_byte_size, resize_symbol_cache): New functions.
	(make_symbol_cache, free_symbol_cache): New functions.
	(get_symbol_cache, symbol_cache_cleanup): New function.
	(set_symbol_cache_size, set_symbol_cache_size_handler): New functions.
	(symbol_cache_lookup, symbol_cache_clear_slot): New function.
	(symbol_cache_mark_found, symbol_cache_mark_not_found): New functions.
	(symbol_cache_flush, symbol_cache_dump): New functions.
	(maintenance_print_symbol_cache): New function.
	(maintenance_flush_symbol_cache): New function.
	(symbol_cache_stats): New function.
	(maintenance_print_symbol_cache_statistics): New function.
	(symtab_new_objfile_observer): New function.
	(symtab_free_objfile_observer): New function.
	(lookup_static_symbol, lookup_global_symbol): Use symbol cache.
	(_initialize_symtab): Init symbol_cache_key.  New parameter
	maint symbol-cache-size.  New maint commands print symbol-cache,
	print symbol-cache-statistics, flush-symbol-cache.
	Install new_objfile, free_objfile observers.

doc/ChangeLog:

	* gdb.texinfo (Symbols): Document new commands
	"maint print symbol-cache", "maint print symbol-cache-statistics",
	"maint flush-symbol-cache".  Document new option
	"maint set symbol-cache-size".
2015-01-10 22:27:10 -08:00
Joel Brobecker 3368c1e5ce Fix use of wrong struct i387_xsave field in i387_cache_to_xsave
gdb/gdbserver/ChangeLog:

        * i387-fp.c (i387_cache_to_xsave): In look over
        num_avx512_zmmh_high_registers, replace use of struct i387_xsave
        zmmh_low_space field by use of zmmh_high_space.

Tested on x86_64-linux, using boards/native-gdbserver.exp.
2015-01-10 09:57:23 +04:00
Patrick Palka 6bf045cd32 Don't munge yacc's #line directives
The #line directives within GDB's autogenerated yacc files (e.g.
c-exp.c) are being incorrectly munged, causing these directives to refer
to nonexistent source files, e.g.

 #line 36 "/home/patrick/binutils-gdb/gdb//home/patrick/binutils-gdb/gdb/c-exp.y"

as opposed to

  #line 36 "/home/patrick/binutils-gdb/gdb/c-exp.y"

The munging happens due to a sed expression added by commit 954d8cae
whose intended purpose[1] was to work around the fact that ylwrap emitted #line
directives without any directory information, e.g.

  #line 36 "c-exp.y"

So the sed expression was meant to munge such directives to refer to
absolute paths instead.  But the behavior of ylwrap was changed some
years ago[2] to emit absolute paths within #line directives.  And when
our local copy of ylwrap was synced by commit e30465112, the sed
expression in question became unnecessary, and indeed harmful.

This patch removes the now-obsolete sed expression.  The emitted #line
directives are now correct without it.

gdb/ChangeLog:

	* Makefile.in (.y.c): Don't munge yacc's #line
	directives.

[1]: https://sourceware.org/ml/gdb-patches/2010-11/msg00265.html
[2]: http://git.savannah.gnu.org/cgit/automake.git/commit/lib/ylwrap?id=b6359a5f3
2015-01-09 17:19:06 -05:00
Patrick Palka 588dcc3edb Consolidate the custom TUI query hook with the default query hook
This patch primarily rewrites defaulted_query() to use
gdb_readline_wrapper() to prompt the user for input, like
prompt_for_continue() does.  The motivation for this rewrite is to be
able to reuse the default query hook in TUI, obviating the need for a
custom TUI query hook.

However, having TUI use the default query mechanism exposed a couple of
latent bugs in tui_redisplay_readline() related to the handling of
multi-line prompts, in particular GDB's multi-line quit prompt.

The first issue is an off-by-one error in the calculation of the height
of the prompt.  The check in question should be col <= prev_col, not c <
prev_col, to properly account for the case when a prompt contains
multiple consecutive newlines.  Failing to do so makes TUI have the
wrong idea of the vertical height of the prompt.  This patch fixes the
column check.

The second issue is that cur_line does not get updated to reflect the
cursor position if the user's prompt cursor is at the end of the prompt
(i.e. if rl_point == rl_end).  cur_line only gets updated if rl_point
lies between 0..rl_end-1 because that is the bounds of the for loop
responsible for updating cur_line.  This patch changes the loop's bounds
to 0..rl_end so that cur_line always gets updated.

With these two bug fixes out of the way, the default query mechanism
works well in TUI even with multi-line prompts like GDB's quit prompt.

gdb/ChangeLog:

	* utils.c (defaulted_query): Rewrite to use gdb_readline_wrapper
	to prompt for input.
	* tui/tui-hooks.c (tui_query_hook): Remove.
	(tui_install_hooks): Don't set deprecated_query_hook.
	* tui/tui-io.c (tui_redisplay_readline): Fix off-by-one error in
	height calculation.  Always update the command window's cur_line.
2015-01-09 13:27:56 -05:00
Pedro Alves ede9f622af add non-stop test that stresses thread starvation issues
This commit adds a non-stop mode test originally inspired by
signal-while-stepping-over-bp-other-thread.exp, that exposes the
thread starvation issues fixed by the previous patches.  It sets a set
of threads stepping in parallel, and has one of them get a signal.
Without the previous fixes, this would fail with timeouts.

gdb/testsuite/
2015-01-09  Pedro Alves  <palves@redhat.com>

	* gdb.threads/non-stop-fair-events.c: New file.
	* gdb.threads/non-stop-fair-events.exp: New file.
2015-01-09 14:44:42 +00:00
Pedro Alves 582511be69 [gdbserver] linux-low.c: better starvation avoidance, handle non-stop mode too
This patch applies the same starvation avoidance improvements of the
previous patch to the Linux gdbserver side.

Without this, the test added by the following commit
(gdb.threads/non-stop-fair-events.exp) always fails with time outs.

gdb/gdbserver/
2015-01-09  Pedro Alves  <palves@redhat.com>

	* linux-low.c (step_over_bkpt): Move higher up in the file.
	(handle_extended_wait): Don't store the stop_pc here.
	(get_stop_pc): Adjust comments and rename to ...
	(check_stopped_by_breakpoint): ... this.  Record whether the LWP
	stopped for a software breakpoint or hardware breakpoint.
	(thread_still_has_status_pending_p): New function.
	(status_pending_p_callback): Use
	thread_still_has_status_pending_p.  If the event is no longer
	interesting, resume the LWP.
	(handle_tracepoints): Add assert.
	(maybe_move_out_of_jump_pad): Remove cancel_breakpoints call.
	(wstatus_maybe_breakpoint): New function.
	(cancel_breakpoint): Delete function.
	(check_stopped_by_watchpoint): New function, factored out from
	linux_low_filter_event.
	(lp_status_maybe_breakpoint): Delete function.
	(linux_low_filter_event): Remove filter_ptid argument.
	Leave thread group exits pending here.	Store the LWP's stop PC.
	Always leave events pending.
	(linux_wait_for_event_filtered): Pull all events out of the
	kernel, and leave them all pending.
	(count_events_callback, select_event_lwp_callback): Consider all
	events.
	(cancel_breakpoints_callback, linux_cancel_breakpoints): Delete.
	(select_event_lwp): Only give preference to the stepping LWP in
	all-stop mode.	Adjust comments.
	(ignore_event): New function.
	(linux_wait_1): Delete 'retry' label.  Use ignore_event.  Remove
	references to cancel_breakpoints.  Adjust to renames.  Also give
	equal priority to all LWPs that have had events in non-stop mode.
	If reporting a software breakpoint event, unadjust the LWP's PC.
	(linux_wait): If linux_wait_1 returned an ignored event, retry.
	(stuck_in_jump_pad_callback, move_out_of_jump_pad_callback):
	Adjust.
	(linux_resume_one_lwp): Store the LWP's PC.  Adjust.
	(resume_status_pending_p): Use thread_still_has_status_pending_p.
	(linux_stopped_by_watchpoint): Adjust.
	(linux_target_ops): Remove reference to linux_cancel_breakpoints.
	* linux-low.h (enum lwp_stop_reason): New.
	(struct lwp_info) <stop_pc>: Adjust comment.
	<stopped_by_watchpoint>: Delete field.
	<stop_reason>: New field.
	* linux-x86-low.c (x86_linux_prepare_to_resume): Adjust.
	* mem-break.c (software_breakpoint_inserted_here)
	(hardware_breakpoint_inserted_here): New function.
	* mem-break.h (software_breakpoint_inserted_here)
	(hardware_breakpoint_inserted_here): Declare.
	* target.h (struct target_ops) <cancel_breakpoints>: Remove field.
	(cancel_breakpoints): Delete.
	* tracepoint.c (clear_installed_tracepoints, stop_tracing)
	(upload_fast_traceframes): Remove references to
	cancel_breakpoints.
2015-01-09 14:42:32 +00:00
Pedro Alves 9c02b52532 linux-nat.c: better starvation avoidance, handle non-stop mode too
Running the testsuite with a series that reimplements user-visible
all-stop behavior on top of a target running in non-stop mode revealed
problems related to event starvation avoidance.

For example, I see
gdb.threads/signal-while-stepping-over-bp-other-thread.exp failing.
What happens is that GDB core never gets to see the signal event.  It
ends up processing the events for the same threads over an over,
because Linux's waitpid(-1, ...) returns that first task in the task
list that has an event, starving threads on the tail of the task list.

So I wrote a non-stop mode test originally inspired by
signal-while-stepping-over-bp-other-thread.exp, to stress this
independently of all-stop on top of non-stop.  Fixing it required the
changes described below.  The test will be added in a following
commit.

1) linux-nat.c has code in place that picks an event LWP at random out
of all that have had events.  This is because on the kernel side,
"waitpid(-1, ...)"  just walks the task list linearly looking for the
first that had an event.  But, this code is currently only used in
all-stop mode.  So with a multi-threaded program that has multiple
events triggering debug events in parallel, GDB ends up starving some
threads.

To make the event randomization work in non-stop mode too, the patch
makes us pull out all the already pending events on the kernel side,
with waitpid, before deciding which LWP to report to the core.

There's some code in linux_wait that takes care of leaving events
pending if they were for LWPs the caller is not interested in.  The
patch moves that to linux_nat_filter_event, so that we only have one
place that leaves events pending.  With that in place, conceptually,
the flow is simpler and more normalized:

 #1 - walk the LWP list looking for an LWP with a pending event to report.
 #2 - if no pending event, pull events out of the kernel, and store
      them in the LWP structures as pending.
 #3- goto #1.

2) Then, currently the event randomization code only considers SIGTRAP
(or trap-like) events.  That means that if e.g., have have multiple
threads stepping in parallel that hit a breakpoint that needs stepping
over, and one gets a signal, the signal may end up never getting
processed, because GDB will always be giving priority to the SIGTRAPs.
The patch fixes this by making the randomization code consider all
kinds of pending events.

3) If multiple threads hit a breakpoint, we report one of those, and
"cancel" the others.  Cancelling means decrementing the PC, and
discarding the event.  If the next time the LWP is resumed the
breakpoint is still installed, the LWP should hit it again, and we'll
report the hit then.  The problem I found is that this delays threads
from advancing too much, with the kernel potentially ending up
scheduling the same threads over and over, and others not advancing.
So the patch switches away from cancelling the breakpoints, and
instead remembering that the LWP had stopped for a breakpoint.  If on
resume the breakpoint is still installed, we report it.  If it's no
longer installed, we discard the pending event then.  This is actually
how GDBserver used to handle this before d50171e4 (Teach linux
gdbserver to step-over-breakpoints), but with the difference that back
then we'd delay adjusting the PC until resuming, which made it so that
"info threads" could wrongly see threads with unadjusted PCs.

gdb/
2015-01-09  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (hardware_breakpoint_inserted_here_p): New
	function.
	* breakpoint.h (hardware_breakpoint_inserted_here_p): New
	declaration.
	* linux-nat.c (linux_nat_status_is_event): Move higher up in file.
	(linux_resume_one_lwp): Store the thread's PC.  Adjust to clear
	stop_reason.
	(check_stopped_by_watchpoint): New function.
	(save_sigtrap): Reimplement.
	(linux_nat_stopped_by_watchpoint): Adjust.
	(linux_nat_lp_status_is_event): Delete.
	(stop_wait_callback): Only call save_sigtrap after storing the
	pending status.
	(status_callback): If the thread had been stopped for a breakpoint
	that has since been removed, discard the event and resume the LWP.
	(count_events_callback, select_event_lwp_callback): Use
	lwp_status_pending_p instead of linux_nat_lp_status_is_event.
	(cancel_breakpoint): Rename to ...
	(check_stopped_by_breakpoint): ... this.  Record whether the LWP
	stopped for a software breakpoint or hardware breakpoint.
	(select_event_lwp): Only give preference to the stepping LWP in
	all-stop mode.  Adjust comments.
	(stop_and_resume_callback): Remove references to new_pending_p.
	(linux_nat_filter_event): Likewise.  Leave exit events of the
	leader thread pending here.  Handle signal short circuiting here.
	Only call save_sigtrap after storing the pending waitstatus.
	(linux_nat_wait_1): Remove 'retry' label.  Remove references to
	new_pending.  Don't handle leaving events the caller is not
	interested in pending here, nor handle signal short-circuiting
	here.  Also give equal priority to all LWPs that have had events
	in non-stop mode.  If reporting a software breakpoint event,
	unadjust the LWP's PC.
	* linux-nat.h (enum lwp_stop_reason): New.
	(struct lwp_info) <stop_pc>: New field.
	(struct lwp_info) <stopped_by_watchpoint>: Delete field.
	(struct lwp_info) <stop_reason>: New field.
	* x86-linux-nat.c (x86_linux_prepare_to_resume): Adjust.
2015-01-09 14:42:03 +00:00
Pedro Alves 8af756ef81 linux-nat.c: always mark execing LWP as resumed
A subsequent patch will make the Linux backend's target_wait method
pull all events out of the kernel (with waitpid) and store them as
pending status in the LWP structure if no pending status was already
available.  Then, the backend goes over the pending statuses and pick
one to report to the core.

With that, the existing thread-execl.exp test exposes a bug, like:

 (gdb) set scheduler-locking on
 (gdb) PASS: gdb.threads/thread-execl.exp: schedlock on: set scheduler-locking on
 next
 FAIL: gdb.threads/thread-execl.exp: schedlock on: get to main in new image (timeout)

Recall that when the non-leader thread execs, all threads in the
process die, the execing thread changes its pid to the tgid, and then
waitpid returns an exec event to the tgid.  If GDB didn't resume the
leader LWP, then GDB sees an event for an LWP that was supposedly
stopped, and thus not marked as resumed.  Because the code that picks
a pending event to report to the core ignores not-resumed LWPs:

 /* Return non-zero if LP has a wait status pending.  */

 static int
 status_callback (struct lwp_info *lp, void *data)
 {
   /* Only report a pending wait status if we pretend that this has
      indeed been resumed.  */
   if (!lp->resumed)
     return 0;

the event ends up pending forever, thus the timeout.

gdb/
2015-01-09  Pedro Alves  <palves@redhat.com>

	* linux-nat.c (linux_handle_extended_wait) <PTRACE_EVENT_EXEC>:
	Set the LWP's 'resumed' flag.
2015-01-09 14:41:15 +00:00
Pedro Alves 8a99810d42 linux-nat.c: clean up pending status checking and resuming LWPs
Whenever we resume an LWP, we must clear a few flags and flush the
LWP's register cache.  We actually currently flush the register cache
of all LWPs, but that's unnecessary.  This patch makes us flush the
register cache of only the LWP that is resumed.  Instead of open
coding all that in many places, we use a helper function.

Likewise, we have two fields in the LWP structure where a pending
status may be recorded.  Add a helper predicate that checks both and
use it throughout instead of open coding the checks.

gdb/
2015-01-09  Pedro Alves  <palves@redhat.com>

	* linux-nat.c (linux_resume_one_lwp): New function.
	(resume_lwp): Use lwp_status_pending_p and linux_resume_one_lwp.
	(linux_nat_resume): Use lwp_status_pending_p and
	linux_resume_one_lwp.
	(linux_handle_syscall_trap): Use linux_resume_one_lwp.
	(linux_handle_extended_wait): Use linux_resume_one_lwp.
	(status_callback, running_callback): Use lwp_status_pending_p.
	(lwp_status_pending_p): New function.
	(stop_and_resume_callback): Use lwp_status_pending_p.
	(linux_nat_filter_event): Use linux_resume_one_lwp.
	(linux_nat_wait_1): Always use status_callback to look for an LWP
	with a pending status.  Use linux_resume_one_lwp.
	(resume_stopped_resumed_lwps): Use lwp_status_pending_p and
	linux_resume_one_lwp.
2015-01-09 14:40:53 +00:00
Pedro Alves f7ce857f51 cleanup and speed up (software_)breakpoint_inserted_here_p
Factor out common code, and use the more efficient
ALL_BP_LOCATIONS_AT_ADDR.

gdb/
2015-01-09  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (bp_location_inserted_here_p): New function,
	factored out from ...
	(breakpoint_inserted_here_p): ... here.  Use
	ALL_BP_LOCATIONS_AT_ADDR.
	(software_breakpoint_inserted_here_p): Use
	bp_location_inserted_here_p and ALL_BP_LOCATIONS_AT_ADDR.
2015-01-09 14:40:11 +00:00
Pedro Alves a7b796db4f watch_thread_num.exp and targets with fairer event reporting
This patch fixes the watch_thread_num.exp test to work when the target
is better at making event handling be fair among threads.

I wrote patches that make GDB native and GDBserver event handling
fairer between threads.  That is, if threads A and B both
simultaneously trigger some debug event, GDB will pick either A or B
at random, rather than always handling the event of A first.  There's
code for that in the Linux backends (gdb and gdbserver) already, but
it can be improved, and only works in all-stop mode.

With those fixes in place, I found that the watch_thread_num.exp would
often time out.  The problem is that the test only works _because_
event handling isn't as fair as intended.  With the fairness fixes,
the test falls victim of PR10116 (gdb drops watchpoints on
multi-threaded apps) quite often.

To expand on the PR10116 reference, consider that stop events are
serialized to GDB core, through target_wait.  Say a thread-specific
watchpoint as set on thread A.  When the "right" thread and some other
"wrong" thread both trigger a watchpoint simultaneously, the target
may report the "wrong" thread's hit to GDB first (thread B).  When
handling that event, GDB notices the watchpoint is for another thread,
and so shouldn't cause a user-visible stop.  On resume, GDB saves the
now current value of the watched expression.  Afterwards, the "right"
thread (thread A) reports its watchpoint trigger.  But the watched
value hasn't changed since GDB last saved it, and so GDB doesn't
report the watchpoint hit to the user.

The way the test is written, the watchpoint is associated with the
first thread that happens to report an event.  It happens that GDB is
processing events much more often for one of the threads, which
usually will be that same first thread.

Hacking the test with "set debug infrun 1", we see exactly that:

$ grep  "infrun.*\[Thread.*," testsuite/gdb.log | sort | uniq -c | sort -nr
     70 infrun:   8798 [Thread 8798],
     37 infrun:   8798 [Thread 8802],
     36 infrun:   8798 [Thread 8804],
     36 infrun:   8798 [Thread 8803],
     35 infrun:   8798 [Thread 8805],
     34 infrun:   8798 [Thread 8806],

The first column shows the number of times the target reported an
event for that thread, from:

 infrun: target_wait (-1, status) =
 infrun:   8798 [Thread 8798],
 infrun:   status->kind = stopped, signal = GDB_SIGNAL_TRAP

This masks out the PR10116 issue.

However, if the target is better at giving equal priority to all
threads, the PR10116 issue happens often, so it may take quite a while
for the right thread to be the first to report its watchpoint event
just after the memory being watched really changed, resulting in test
time outs.

Here's the number of events handled for each thread on a gdbserver run
with the event fairness patches:

$ grep  "infrun.*\[Thread.*," gdb.log | sort | uniq -c
   2961 infrun:   13591 [Thread 13591],
   2956 infrun:   13591 [Thread 13595],
   2941 infrun:   13591 [Thread 13596],
   2932 infrun:   13591 [Thread 13597],
   2905 infrun:   13591 [Thread 13598],
   2891 infrun:   13591 [Thread 13599],

Note how the number of events is much higher.  The test routinely
takes over 10 seconds to finish on my machine rather than under a
second as with unpatched gdbserver, when it succeeds, but often it'll
fail with timeouts too.

So to make the test robust, this patch switches the tests to using
"awatch" instead of "watch", as access watchpoints don't care about
the watchpoint's "old value".  With this, the test always finishes
quickly, and we can even bump the number of threads concurrently
writting to the shared variable, to have better assurance we're really
testing the case of the "wrong" thread triggering a watchpoint.

Here's the number of events I see for each thread on a run on my
machine, with a gdbserver patched with the event fairness series:

$ grep  "infrun.*\[Thread.*," testsuite/gdb.log | sort | uniq -c
      5 infrun:   5298 [Thread 5302],
      4 infrun:   5298 [Thread 5303],
      4 infrun:   5298 [Thread 5304],
      4 infrun:   5298 [Thread 5305],
      4 infrun:   5298 [Thread 5306],
      4 infrun:   5298 [Thread 5307],
      4 infrun:   5298 [Thread 5308],
      4 infrun:   5298 [Thread 5309],
      4 infrun:   5298 [Thread 5310],
      4 infrun:   5298 [Thread 5311],
      4 infrun:   5298 [Thread 5312],
      4 infrun:   5298 [Thread 5313],
      4 infrun:   5298 [Thread 5314],
      4 infrun:   5298 [Thread 5315],
      4 infrun:   5298 [Thread 5316],

gdb/testsuite/
2015-01-09  Pedro Alves  <palves@redhat.com>

	* gdb.base/annota1.exp (thread_test): Use srcfile and binfile from
	the global scope.  Set a breakpoint after all threads are started
	rather than stepping over two source lines.  Expect the prompt.
	* gdb.base/watch_thread_num.c (threads_started_barrier): New
	global.
	(NUM): Now 15.
	(main): Use threads_started_barrier to wait for all threads to
	start.  Main thread no longer calls thread_function.  Exit after
	180 seconds.
	(loop): New function.
	(thread_function): Wait on threads_started_barrier barrier.  Call
	'loop' at each iteration.
	* gdb.base/watch_thread_num.exp: Continue to breakpoint after all
	threads have started, instead of hardcoding number of "next"
	steps.  Use an access watchpoint instead of a write watchpoint.
2015-01-09 14:39:41 +00:00
Pedro Alves 9665ffdd59 gdb.threads/{siginfo-thread.c,watchthreads-reorder.c,ia64-sigill.c} races with GDB
These three test all spawn a few threads and then send a SIGSTOP to
their parent GDB in order to pause it while the new threads set things
up for the test.  With a GDB patch that changes the inferior thread's
scheduling a bit, I sometimes see:

  FAIL: gdb.threads/siginfo-threads.exp: catch signal 0 (timeout)
  ...
  FAIL: gdb.threads/watchthreads-reorder.exp: reorder1: continue a (timeout)
  ...
  FAIL: gdb.threads/ia64-sigill.exp: continue (timeout)
  ...

The issue is that the test program stops GDB before it had a chance of
processing the new thread's clone event:

  (gdb) PASS: gdb.threads/siginfo-threads.exp: get pid
  continue
  Continuing.
  Stopping GDB PID 21541.
  Waiting till the threads initialize their TIDs.
  FAIL: gdb.threads/siginfo-threads.exp: catch signal 0 (timeout)

On Linux (at least), new threads start stopped, and the debugger must
resume them.  The fix is to make the test program wait for the new
threads to be running before stopping GDB.

gdb/testsuite/
2015-01-09  Pedro Alves  <palves@redhat.com>

	* gdb.threads/ia64-sigill.c (threads_started_barrier): New global.
	(thread_func): Wait on barrier.
	(main): Wait for all threads to start before stopping GDB.
	* gdb.threads/siginfo-threads.c (threads_started_barrier): New
	global.
	(thread1_func, thread2_func): Wait on barrier.
	(main): Wait for all threads to start before stopping GDB.
	* gdb.threads/watchthreads-reorder.c (threads_started_barrier):
	New global.
	(thread1_func, thread2_func): Wait on barrier.
	(main): Wait for all threads to start before stopping GDB.
2015-01-09 13:58:29 +00:00
Pedro Alves c945a99f01 Test attaching to a program that constantly spawns short-lived threads
Before the previous fixes, on Linux, this would trigger several
different problems, like:

 [New LWP 27106]
 [New LWP 27047]
 warning: unable to open /proc file '/proc/-1/status'
 [New LWP 27813]
 [New LWP 27869]
 warning: Can't attach LWP 11962: No child processes
 Warning: couldn't activate thread debugging using libthread_db: Cannot find new threads: debugger service failed
 warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.

gdb/testsuite/
2015-01-09  Pedro Alves  <palves@redhat.com>

	* gdb.threads/attach-many-short-lived-threads.c: New file.
	* gdb.threads/attach-many-short-lived-threads.exp: New file.
2015-01-09 11:44:04 +00:00
Pedro Alves c1a747c109 Linux: Skip thread_db thread event reporting if PTRACE_EVENT_CLONE is supported
[A test I wrote stumbled on a libthread_db issue related to thread
event breakpoints.  See glibc PR17705:
 [nptl_db: stale thread create/death events if debugger detaches]
 https://sourceware.org/bugzilla/show_bug.cgi?id=17705

This patch avoids that whole issue by making GDB stop using thread
event breakpoints in the first place, which is good for other reasons
as well, anyway.]

Before PTRACE_EVENT_CLONE (Linux 2.6), the only way to learn about new
threads in the inferior (to attach to them) or to learn about thread
exit was to coordinate with the inferior's glibc/runtime, using
libthread_db.  That works by putting a breakpoint at a magic address
which is called when a new thread is spawned, or when a thread is
about to exit.  When that breakpoint is hit, all threads are stopped,
and then GDB coordinates with libthread_db to read data structures out
of the inferior to learn about what happened.  Then the breakpoint is
single-stepped, and then all threads are re-resumed.  This isn't very
efficient (stops all threads) and is more fragile (inferior's thread
list in memory may be corrupt; libthread_db bugs, etc.) than ideal.

When the kernel supports PTRACE_EVENT_CLONE (which we already make use
of), there's really no need to use libthread_db's event reporting
mechanism to learn about new LWPs.  And if the kernel supports that,
then we learn about LWP exits through regular WIFEXITED wait statuses,
so no need for the death event breakpoint either.

GDBserver has been likewise skipping the thread_db events for a long
while:
  https://sourceware.org/ml/gdb-patches/2007-10/msg00547.html

There's one user-visible difference: we'll no longer print about
threads being created and exiting while the program is running, like:

 [Thread 0x7ffff7dbb700 (LWP 30670) exited]
 [New Thread 0x7ffff7db3700 (LWP 30671)]
 [Thread 0x7ffff7dd3700 (LWP 30667) exited]
 [New Thread 0x7ffff7dab700 (LWP 30672)]
 [Thread 0x7ffff7db3700 (LWP 30671) exited]
 [Thread 0x7ffff7dcb700 (LWP 30668) exited]

This is exactly the same behavior as when debugging against remote
targets / gdbserver.  I actually think that's a good thing (and as
such have listed this in the local/remote parity wiki page a while
ago), as the printing slows down the inferior.  It's also a
distraction to keep bothering the user about short-lived threads that
she won't be able to interact with anyway.  Instead, the user (and
frontend) will be informed about new threads that currently exist in
the program when the program next stops:

 (gdb) c
 ...
 * ctrl-c *
 [New Thread 0x7ffff7963700 (LWP 7797)]
 [New Thread 0x7ffff796b700 (LWP 7796)]

 Program received signal SIGINT, Interrupt.
 [Switching to Thread 0x7ffff796b700 (LWP 7796)]
 clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:81
 81              testq   %rax,%rax
 (gdb) info threads

A couple of tests had assumptions on GDB thread numbers that no longer
hold.

Tested on x86_64 Fedora 20.

gdb/
2014-01-09  Pedro Alves  <palves@redhat.com>

	Skip enabling event reporting if the kernel supports
	PTRACE_EVENT_CLONE.
	* linux-thread-db.c: Include "nat/linux-ptrace.h".
	(thread_db_use_events): New function.
	(try_thread_db_load_1): Check thread_db_use_events before enabling
	event reporting.
	(update_thread_state): New function.
	(attach_thread): Use it.  Check thread_db_use_events before
	enabling event reporting.
	(thread_db_detach): Check thread_db_use_events before disabling
	event reporting.
	(find_new_threads_callback): Check thread_db_use_events before
	enabling event reporting.  Update the thread's state if not using
	libthread_db events.

gdb/testsuite/
2014-01-09  Pedro Alves  <palves@redhat.com>

	* gdb.threads/fork-thread-pending.exp: Switch to the main thread
	instead of to thread 2.
	* gdb.threads/signal-command-multiple-signals-pending.c (main):
	Add barrier around each pthread_create call instead of around all
	calls.
	* gdb.threads/signal-command-multiple-signals-pending.exp (test):
	Set a break on thread_function and have the child threads hit it
	one at at a time.
2015-01-09 11:42:57 +00:00
Pedro Alves a33e39599c libthread_db: Skip attaching to terminated and joined threads
I wrote a test that attaches to a program that constantly spawns
short-lived threads, which exposed several issues.  This is one of
them.

On GNU/Linux, attaching to a multi-threaded program sometimes prints
out warnings like:

 ...
 [New LWP 20700]
 warning: unable to open /proc file '/proc/-1/status'
 [New LWP 20850]
 [New LWP 21019]
 ...

That happens because when a thread exits, and is joined, glibc does:

nptl/pthread_join.c:
pthread_join ()
{
...
  if (__glibc_likely (result == 0))
    {
      /* We mark the thread as terminated and as joined.  */
      pd->tid = -1;
...
     /* Free the TCB.  */
      __free_tcb (pd);
    }

So if we attach or interrupt the program (which does an implicit "info
threads") at just the right (or rather, wrong) time, we can find and
return threads in the libthread_db/pthreads thread list with kernel
thread ID -1.  I've filed glibc PR nptl/17707 for this.  You'll find
more info there.

This patch handles this as a special case in GDB.

This is actually more than just a cosmetic issue.  lin_lwp_attach_lwp
will think that this -1 is an LWP we're not attached to yet, and after
failing to attach will try to check we were already attached to the
process, using a waitpid call, which in this case ends up being
"waitpid (-1, ...", which obviously results in GDB potentially
discarding an event when it shouldn't...

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/gdbserver/
2015-01-09  Pedro Alves  <palves@redhat.com>

	* thread-db.c (find_new_threads_callback): Ignore thread if the
	kernel thread ID is -1.

gdb/
2015-01-09  Pedro Alves  <palves@redhat.com>

	* linux-nat.c (lin_lwp_attach_lwp): Assert that the lwp id we're
	about to wait for is > 0.
	* linux-thread-db.c (find_new_threads_callback): Ignore thread if
	the kernel thread ID is -1.
2015-01-09 11:41:01 +00:00
Pedro Alves 8784d56326 Linux: on attach, attach to lwps listed under /proc/$pid/task/
... instead of relying on libthread_db.

I wrote a test that attaches to a program that constantly spawns
short-lived threads, which exposed several issues.  This is one of
them.

On Linux, we need to attach to all threads of a process (thread group)
individually.  We currently rely on libthread_db to list the threads,
but that is problematic, because libthread_db relies on reading data
structures out of the inferior (which may well be corrupted).  If
threads are being created or exiting just while we try to attach, we
may trip on inconsistencies in the inferior's thread list.  To work
around that, when we see a seemingly corrupt list, we currently retry
a few times:

 static void
 thread_db_find_new_threads_2 (ptid_t ptid, int until_no_new)
 {
 ...
   if (until_no_new)
     {
       /* Require 4 successive iterations which do not find any new threads.
	  The 4 is a heuristic: there is an inherent race here, and I have
	  seen that 2 iterations in a row are not always sufficient to
	  "capture" all threads.  */
 ...

That heuristic may well fail, and when it does, we end up with threads
in the program that aren't under GDB's control.  That's obviously bad
and results in quite mistifying failures, like e.g., the process dying
for seeminly no reason when a thread that wasn't attached trips on a
breakpoint.

There's really no reason to rely on libthread_db for this nowadays
when we have /proc mounted.  In that case, which is the usual case, we
can list the LWPs from /proc/PID/task/.  In fact, GDBserver is already
doing this.  The patch factors out that code that knows to walk the
task/ directory out of GDBserver, and makes GDB use it too.

Like GDBserver, the patch makes GDB attach to LWPs and _not_ wait for
them to stop immediately.  Instead, we just tag the LWP as having an
expected stop.  Because we can only set the ptrace options when the
thread stops, we need a new flag in the lwp structure to keep track of
whether we've already set the ptrace options, just like in GDBserver.
Note that nothing issues any ptrace command to the threads between the
PTRACE_ATTACH and the stop, so this is safe (unlike one scenario
described in gdbserver's linux-low.c).

When we attach to a program that has threads exiting while we attach,
it's easy to race with a thread just exiting as we try to attach to
it, like:

  #1 - get current list of threads
  #2 - attach to each listed thread
  #3 - ooops, attach failed, thread is already gone

As this is pretty normal, we shouldn't be issuing a scary warning in
step #3.

When #3 happens, PTRACE_ATTACH usually fails with ESRCH, but sometimes
we'll see EPERM as well.  That happens when the kernel still has the
thread in its task list, but the thread is marked as dead.
Unfortunately, EPERM is ambiguous and we'll get it also on other
scenarios where the thread isn't dead, and in those cases, it's useful
to get a warning.  To distiguish the cases, when we get an EPERM
failure, we open /proc/PID/status, and check the thread's state -- if
the /proc file no longer exists, or the state is "Z (Zombie)" or "X
(Dead)", we ignore the EPERM error silently; otherwise, we'll warn.
Unfortunately, there seems to be a kernel race here.  Sometimes I get
EPERM, and then the /proc state still indicates "R (Running)"...  If
we wait a bit and retry, we do end up seeing X or Z state, or get an
ESRCH.  I thought of making GDB retry the attach a few times, but even
with a 500ms wait and 4 retries, I still see the warning sometimes.  I
haven't been able to identify the kernel path that causes this yet,
but in any case, it looks like a kernel bug to me.  As this just
results failure to suppress a warning that we've been printing since
about forever anyway, I'm just making the test cope with it, and issue
an XFAIL.

gdb/gdbserver/
2015-01-09  Pedro Alves  <palves@redhat.com>

	* linux-low.c (linux_attach_fail_reason_string): Move to
	nat/linux-ptrace.c, and rename.
	(linux_attach_lwp): Update comment.
	(attach_proc_task_lwp_callback): New function.
	(linux_attach): Adjust to rename and use
	linux_proc_attach_tgid_threads.
	(linux_attach_fail_reason_string): Delete declaration.

gdb/
2015-01-09  Pedro Alves  <palves@redhat.com>

	* linux-nat.c (attach_proc_task_lwp_callback): New function.
	(linux_nat_attach): Use linux_proc_attach_tgid_threads.
	(wait_lwp, linux_nat_filter_event): If not set yet, set the lwp's
	ptrace option flags.
	* linux-nat.h (struct lwp_info) <must_set_ptrace_flags>: New
	field.
	* nat/linux-procfs.c: Include <dirent.h>.
	(linux_proc_get_int): New parameter "warn".  Handle it.
	(linux_proc_get_tgid): Adjust.
	(linux_proc_get_tracerpid): Rename to ...
	(linux_proc_get_tracerpid_nowarn): ... this.
	(linux_proc_pid_get_state): New function, factored out from
	(linux_proc_pid_has_state): ... this.  Add new parameter "warn"
	and handle it.
	(linux_proc_pid_is_gone): New function.
	(linux_proc_pid_is_stopped): Adjust.
	(linux_proc_pid_is_zombie_maybe_warn)
	(linux_proc_pid_is_zombie_nowarn): New functions.
	(linux_proc_pid_is_zombie): Use
	linux_proc_pid_is_zombie_maybe_warn.
	(linux_proc_attach_tgid_threads): New function.
	* nat/linux-procfs.h (linux_proc_get_tgid): Update comment.
	(linux_proc_get_tracerpid): Rename to ...
	(linux_proc_get_tracerpid_nowarn): ... this, and update comment.
	(linux_proc_pid_is_gone): New declaration.
	(linux_proc_pid_is_zombie): Update comment.
	(linux_proc_pid_is_zombie_nowarn): New declaration.
	(linux_proc_attach_lwp_func): New typedef.
	(linux_proc_attach_tgid_threads): New declaration.
	* nat/linux-ptrace.c (linux_ptrace_attach_fail_reason): Adjust to
	use nowarn functions.
	(linux_ptrace_attach_fail_reason_string): Move here from
	gdbserver/linux-low.c and rename.
	(ptrace_supports_feature): If the current ptrace options are not
	known yet, check them now, instead of asserting.
	* nat/linux-ptrace.h (linux_ptrace_attach_fail_reason_string):
	Declare.
2015-01-09 11:39:49 +00:00
Pedro Alves 883ed13e4a libthread_db: debug output should go to gdb_stdlog
Some debug output in linux-thread-db.c was being sent to gdb_stdout,
and some to gdb_stderr, while the right place to send debug output to is
gdb_stdlog.

gdb/
2015-01-09  Pedro Alves  <palves@redhat.com>

	* linux-thread-db.c (thread_db_find_new_threads_silently)
	(try_thread_db_load_1, try_thread_db_load, thread_db_load_search)
	(find_new_threads_once): Print debug output on gdb_stdlog.
2015-01-09 11:25:25 +00:00
Pedro Alves 60b3033e6e skip "attach" tests when testing against stub-like targets
We already skip "attach" tests if the target board is remote, in
dejagnu's sense, as we use TCL's exec to spawn the program on the
build machine.  We should also skip these tests if testing with
"target remote" or other stub-like targets where "attach" doesn't make
sense.

Add a helper procedure that centralizes the checks a test that needs
to spawn a program for testing "attach" and make all test files that
use spawn_wait_for_attach check it.

gdb/testsuite/
2015-01-09  Pedro Alves  <palves@redhat.com>

	* lib/gdb.exp (can_spawn_for_attach): New procedure.
	(spawn_wait_for_attach): Error out if can_spawn_for_attach returns
	false.
	* gdb.base/attach.exp: Use can_spawn_for_attach instead of
	checking whether the target board is remote.
	* gdb.multi/multi-attach.exp: Likewise.
	* gdb.python/py-sync-interp.exp: Likewise.
	* gdb.server/ext-attach.exp: Likewise.
	* gdb.python/py-prompt.exp: Use can_spawn_for_attach before the
	tests that need to attach, instead of checking whether the target
	board is remote at the top of the file.
2015-01-09 11:04:19 +00:00
Chen Gang 1710aab8af gdb/compile/compile.c: Check return value of 'system' to avoid compiler warning
Add missing ChangeLog entry.

2015-01-09  Chen Gang  <gang.chen.5i5j@gmail.com>
	    Pedro Alves  <palves@redhat.com>

	* compile/compile.c: Include "gdb_wait.h".
	(do_rmdir): Check return value, and free 'zap'.
2015-01-09 10:09:03 +00:00
Chen Gang 3ce348af7f gdb/compile/compile.c: Check return value of 'system' to avoid compiler warning
Under Ubuntu 12, we need to check the return value of system(), or the
compiler warns:

  gcc -g -O2   -I. -I../../binutils-gdb/gdb -I../../binutils-gdb/gdb/common -I../../binutils-gdb/gdb/config -DLOCALEDIR="\"/usr/local/share/locale\"" -DHAVE_CONFIG_H -I../../binutils-gdb/gdb/../include/opcode -I../../binutils-gdb/gdb/../opcodes/.. -I../../binutils-gdb/gdb/../readline/.. -I../bfd -I../../binutils-gdb/gdb/../bfd -I../../binutils-gdb/gdb/../include -I../libdecnumber -I../../binutils-gdb/gdb/../libdecnumber  -I../../binutils-gdb/gdb/gnulib/import -Ibuild-gnulib/import   -DTUI=1  -Wall -Wdeclaration-after-statement -Wpointer-arith -Wpointer-sign -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wmissing-prototypes -Wdeclaration-after-statement -Wempty-body -Wmissing-parameter-type -Wold-style-declaration -Wold-style-definition -Wformat-nonliteral -Werror -c -o compile.o -MT compile.o -MMD -MP -MF .deps/compile.Tpo ../../binutils-gdb/gdb/compile/compile.c
  ../../binutils-gdb/gdb/compile/compile.c: In function ‘do_rmdir’:
  ../../binutils-gdb/gdb/compile/compile.c:175:10: error: ignoring return value of ‘system’, declared with attribute warn_unused_result [-Werror=unused-result]
  cc1: all warnings being treated as errors
  make[2]: *** [compile.o] Error 1
  make[2]: Leaving directory `/upstream/build-binutils-s390/gdb'
  make[1]: *** [all-gdb] Error 2
  make[1]: Leaving directory `/upstream/build-binutils-s390'
  make: *** [all] Error 2

Also, 'zap' is leaking.

2015-01-09  Chen Gang  <gang.chen.5i5j@gmail.com>
	    Pedro Alves  <palves@redhat.com>

	* compile/compile.c: Include "gdb_wait.h".
	(do_rmdir): Check return value, and free 'zap'.
2015-01-09 09:18:32 +00:00
Yao Qi b597c318b8 always read synthetic pointers as signed integers
I see the error message "access outside bounds of object referenced
via synthetic pointer" in the two fails below of mips gdb testing

print d[-2]^M
access outside bounds of object referenced via synthetic pointer^M
(gdb) FAIL: gdb.dwarf2/implptrconst.exp: print d[-2]
(gdb) print/d p[-1]^M
access outside bounds of object referenced via synthetic pointer^M
(gdb) FAIL: gdb.dwarf2/implptrpiece.exp: print/d p[-1]

in the first test, 'd[-2]' is processed by GDB as '* (&d[-2])'.  'd'
is a synthetic pointer, so its value is zero, the address of 'd[-2]'
is -2.  In dwarf2loc.c:indirect_pieced_value,

  /* This is an offset requested by GDB, such as value subscripts.
     However, due to how synthetic pointers are implemented, this is
     always presented to us as a pointer type.  This means we have to
     sign-extend it manually as appropriate.  */
  byte_offset = value_as_address (value);
  if (TYPE_LENGTH (value_type (value)) < sizeof (LONGEST))
    byte_offset = gdb_sign_extend (byte_offset,
				   8 * TYPE_LENGTH (value_type (value)));
  byte_offset += piece->v.ptr.offset;

We know that the value is really an offset instead of address, so the
fix is to extract the value as an (signed) offset.

gdb:

2015-01-08  Pedro Alves  <palves@redhat.com>
	    Yao Qi  <yao@codesourcery.com>

	* dwarf2loc.c (indirect_pieced_value): Don't call
	gdb_sign_extend.  Call extract_signed_integer instead.
	* utils.c (gdb_sign_extend): Remove.
	* utils.h (gdb_sign_extend): Remove declaration.
2015-01-08 21:04:00 +08:00
Pierre Muller 025ac41482 Set language for C++ special symbols.
The special handling of C++ special symbol
generates symbols that have no language.
Those symbols cannot be displayed correctly in the backtrace stack.

See
https://sourceware.org/bugzilla/show_bug.cgi?id=17811
for details and examples in C++ and pascal language.

The patch below fixes this issue, by
setting language of new symbol before
special handling of special C++ symbols.

2015-01-07  Pierre Muller  <muller@sourceware.org>

	PR symtab/17811
	* stabsread.c (define_symbol): Set language for C++ special symbols.
2015-01-08 09:01:04 +01:00
Yao Qi acc018ac03 Recognize branch instruction on MIPS in gdb.trace/entry-values.exp
The test entry-values.exp doesn't recognize the call instructions
on MIPS, such as JAL, JALS and etc, so this patch sets call_insn
to match various jump and branch instructions first.

Currently, we assume the next instruction address of call instruction
is the address returned from foo, however it is not correct on MIPS
which has delay slot.  We extend variable call_insn to match one
instruction after jump or branch instruction, so that
$returned_from_foo is correct on MIPS.

All tests in entry-values.exp are PASS.

gdb/testsuite:

2015-01-08  Yao Qi  <yao@codesourcery.com>

	* gdb.trace/entry-values.exp: Set call_insn for MIPS target.
2015-01-08 11:45:51 +08:00
Patrick Palka fa5af12a25 Trivially tweak the comment documenting initial_gdb_ttystate
gdb/ChangeLog:

	* inflow.c (initial_gdb_ttystate): Tweak comment.
2015-01-07 16:42:02 -05:00
Joel Brobecker ea42d6f8d1 Empty line after comment documenting set_initial_gdb_ttystate.
gdb/ChangeLog:

        * inflow.c (set_initial_gdb_ttystate): Add empty line after
        comment documenting function.
2015-01-07 18:51:29 +04:00
Jan Kratochvil 50a18af83d [testsuite patch] Fix avx512.exp regression
+gdb compile failed, ^[[01m^[[Kgdb/testsuite/gdb.arch/i386-avx512.c:20:27:^[[m^[[K ^[[01;31m^[[Kfatal error: ^[[m^[[Knat/x86-cpuid.h: No
such file or directory
+ #include "nat/x86-cpuid.h"
+^[[01;32m^[[K                           ^^[[m^[[K
+compilation terminated.
+UNTESTED: gdb.arch/i386-avx512.exp: i386-avx512.exp

125f8a3dde is the first bad commit
commit 125f8a3dde
Author: Gary Benson <gbenson@redhat.com>
Date:   Thu Jun 19 14:46:38 2014 +0100
    Move shared native target specific code to gdb/nat

gdb/testsuite/ChangeLog
2015-01-07  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix testcase compilation.
	* gdb.arch/i386-avx512.exp (comp_flags): Remove /common.
2015-01-07 15:42:57 +01:00
Patrick Palka 6a06d66006 Don't propagate our current terminal state to the inferior
Currently when we start an inferior we have the inferior inherit our
terminal state.  Under TUI, our terminal is highly modified by ncurses
and readline.  So when starting an inferior under TUI, the inferior will
have a highly modified terminal state which will interfere with standard
I/O. For example,

$ gdb gdb
(gdb) break main
(gdb) run
(gdb) print puts ("a\nb")
a
b
$1 = 4
(gdb) [enter TUI mode]
(gdb) run
(gdb) [exit TUI mode]
(gdb) print puts ("a\nb")
a
 b
  $2 = 4
(gdb) print puts ("a\r\nb\r")
a
b
$3 = 6

As you can see, when we start the inferior under the regular interface,
puts() prints the text properly.  But when we start the inferior under
TUI, puts() does not print the text properly.  This is because when we
start the inferior under TUI it inherits our current terminal state
which has been modified by ncurses to, among other things, require an
explicit \r\n to print a new line. As a result the inferior performs
standard I/O in an unexpected way.

Because of this discrepancy, it doesn't seem like a good idea to have
the inferior inherit our _current_ terminal state for it may have been
modified by readline and/or ncurses.  Instead, we should have the
inferior inherit a pristine snapshot of our terminal state taken before
readline or ncurses have had a chance to alter it.  This enables the
inferior to run in a more accurate way, more closely mimicking the
program's behavior had it run standalone.  And it fixes the above
mentioned issue.

Tested on x86_64-unknown-linux-gnu.

gdb/ChangeLog:

	* terminal.h (set_initial_gdb_ttystate): Declare.
	* inflow.c (initial_gdb_ttystate): New static variable.
	(set_initial_gdb_ttystate): New setter.
	(child_terminal_init_with_pgrp): Copy initial_gdb_ttystate
	instead of our current terminal state.
	* top.c (gdb_init): Call set_initial_gdb_ttystate.
2015-01-07 09:02:07 -05:00
Joel Brobecker e810d75b1c [python,guile] Add comment beside conditions testing empty arrays.
gdb/ChangeLog:

        * guile/scm-type.c (tyscm_array_1): Add comment.
        * python/py-type.c (typy_array_1): Add comment.
2015-01-07 07:36:20 +04:00
Joel Brobecker fce10a8494 gdb/guile: Do not error when trying to create empty array.
This fixes a similar error as in the Python support code where
trying to create an empty array.

In guile/scm-type.c::tyscm_array_1, the funtion raises an exception
if N2 < N1:

   if (n2 < n1)
     {
       gdbscm_out_of_range_error (func_name, SCM_ARG3,

But it should be doing so if N2 == N1 - 1, since that would simply
be an empty array, not an array with a negative length.

gdb/ChangeLog:

        * guile/scm-type.c (tyscm_array_1): Do not raise out-of-range
        error if N2 is equal to N1 - 1.
2015-01-06 19:09:54 +04:00
Joel Brobecker 8503d6e1e5 gdb/python: exception trying to create empty array
The following python command fails:

    (gdb) python print gdb.lookup_type('char').array(1, 0)
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ValueError: Array length must not be negative
    Error while executing Python code.

The above is trying to create an empty array, which is fairly command
in Ada.

gdb/ChangeLog:

        * python/py-type.c (typy_array_1): Do not raise negative-length
        exception if N2 is equal to N1 - 1.

gdb/testsuite/ChangeLog:

        * gdb.python/py-type.exp: Add a couple test about empty
        array creation, and negative-length array creation.
2015-01-06 19:07:12 +04:00
Doug Evans e1e061e77d fix spelling of anon-ns2.cc in earlier entry, and whitespace in same entry 2015-01-03 12:35:41 -08:00
Doug Evans 4d29c0a8b7 c-exp.y: misc cleanup, no code changes
gdb/ChangeLog:

	* c-exp.y: Whitespace cleanup.
	(classify_inner_name): Remove extra ;.
2015-01-03 12:01:29 -08:00
Doug Evans cc73dbcc08 gdb.cp/nsalias.exp: Fix output of external/declaration flags.
gdb/testsuite/ChangeLog:

	* gdb.cp/nsalias.exp: Fix output of external/declaration flags.
2015-01-02 22:00:57 -08:00
Maciej W. Rozycki eaa6a9a482 MIPS: Make the extracted stack offset signed in the prologue scanner
Make the extracted stack offset signed in the standard MIPS prologue
scanner, to simplify handling and make sure register offsets are correct
in all cases, especially where $fp equals the virtual frame pointer (old
GCC frames) and therefore offsets to save slots are negative.

	* mips-tdep.c (mips32_scan_prologue): Make the extracted stack
	offset signed.
2015-01-02 23:54:27 +00:00
Doug Evans 0300bbc7c5 gdb.dwarf2/dw4-sig-types.exp: Also pass -fdebug-types-section to gcc.
gdb/testsuite/ChangeLog:

	* gdb.dwarf2/dw4-sig-types.exp: Also pass -fdebug-types-section to gcc.
2015-01-02 12:59:44 -08:00
Doug Evans 02fe997271 dwarf2read.c (setup_type_unit_groups): Remove outdated comment.
gdb/ChangeLog:

	* dwarf2read.c (setup_type_unit_groups): Remove outdated comment.
2015-01-02 11:49:14 -08:00
Doug Evans e2ada9cb46 symtab.h (struct symbol): Fix typo in comment.
gdb/ChangeLog:

	* symtab.h (struct symbol): Fix typo in comment.
2015-01-02 11:02:31 -08:00
Joel Brobecker 32d0add0a6 Update year range in copyright notice of all files owned by the GDB project.
gdb/ChangeLog:

        Update year range in copyright notice of all files.
2015-01-01 13:32:14 +04:00
Joel Brobecker 76f2b779a1 Update copyright year printed by gdb, gdbserver and gdbreplay.
gdb/ChangeLog:

        * top.c (print_gdb_version): Update copyright year to 2015.

gdbserver/ChangeLog:

        * gdbreplay.c (gdbreplay_version): Update copyright year to 2015.
        * server.c (gdbserver_version): Likewise.
2015-01-01 13:27:08 +04:00
Joel Brobecker 077309e264 Yearly gdb/ChangeLog rotation.
This patch renames gdb/'s ChangeLog to ChangeLog-2014 and creates
a new one for 2015. config/djgpp/fnchange.lst is updated accordingly.

gdb/ChangeLog:

 	* config/djgpp/fnchange.lst: Add entry for gdb/ChangeLog-2014.
2015-01-01 13:23:33 +04:00
Joel Brobecker 6bf6fd090a Remove "add-shared-symbol-files", "dll-symbols" and "assf" commands doc.
This patch removes documentation from some commands whose support has
been recently removed.

gdb/ChangeLog:

        * NEWS: Document removal of "dll-symbols", "add-shared-symbol-files"
        and "assf" commands.

gdb/doc/ChangeLog:

        * gdb.texinfo (Files): Remove documentation of the
        "add-shared-symbol-files" and "assf" commands.
        (Cygwin Native): Remove documentation of the "dll-symbols"
        command.
2014-12-31 11:13:00 +04:00
Joel Brobecker 1a667e98b7 Remove "dll-symbols", "add-shared-symbol-files" and assf" commands.
This patch removes a set of commands that have been deprecated for
a while, and which we agreed to remove after the GDB 7.8 release.

gdb/ChangeLog:

	* windows-nat.c (safe_symbol_file_add_stub)
	(safe_symbol_file_add_cleanup, safe_symbol_file_add)
	(dll_symbol_command): Delete.
	(_initialize_windows_nat): Delete local variable "c".
	Remove "dll-symbols", "add-shared-symbol-files" and assf"
	commands.

Tested by rebuilding GDB on x86-windows.
2014-12-30 11:30:01 +04:00
Sergio Durigan Junior fafcc06ab2 Sanitize input_interrupt output
Hi,

This patch is a follow-up of the following discussions:

  <https://sourceware.org/ml/gdb-patches/2014-12/msg00421.html>
  <https://gcc.gnu.org/ml/gcc-patches/2014-12/msg01293.html>

input_interrupt is currently emiting non-printable characters, which
is confusing the dg-extract-results.sh script.  This is obviously not
a good thing, and, by following Pedro's advices here:

  <https://gcc.gnu.org/ml/gcc-patches/2014-12/msg01320.html>

I adapted the function to print "client connection closed" when it
receives a NUL character, or use the "isprint" function to decide how
to print the received char.  I tested it by running the testcases that
were printing the non-printable chars before:

  gdb.base/gdb-sigterm.exp
  gdb.threads/non-ldr-exc-1.exp
  gdb.threads/non-ldr-exc-2.exp
  gdb.threads/non-ldr-exc-3.exp
  gdb.threads/non-ldr-exc-4.exp
  gdb.threads/thread-execl.exp

and confirming that they print the right message.  I tried a bit to
come up with a testcase for this, but failed, and since I did not want
to spend too much time on it, I'm sending the patch anyway.

Comments are welcome, as usual.

gdb/gdbserver/ChangeLog:
2014-12-29  Sergio Durigan Junior  <sergiodj@redhat.com>

	* remote-utils.c: Include ctype.h.
	(input_interrupt): Explicitly handle the case when the char
	received is the NUL byte.  Improve the printing of non-ASCII
	characters.
2014-12-29 14:23:54 -05:00
Jiong Wang b35b02984b [PATCH] Remove cast in Tag_ABI_VFP_args switch case stmts
2014-12-29  Thomas Preud'homme  <thomas.preudhomme@arm.com>

  gdb/
    * arm-tdep.c (arm_gdbarch_init): Remove casts in Tag_ABI_VFP_args
    switch case statements.
2014-12-29 14:56:36 +00:00
Yao Qi 9d85a0ec6b Clean up gdb.trace/entry-values.exp
This patch is to clean up gdb.trace/entry-values.exp as a preparation
of the next patch.  It updates the comments to reflect the code.

One DIE generated in dwarf assembler is

 		GNU_call_site {
		    {low_pc "$bar_start + $bar_call_foo" addr}
 		    {abstract_origin :$foo_label}

the DW_AT_low_pc attribute is the return address after the call, so I
rename variable bar_call_foo to returned_from_foo.

gdb/testsuite:

2014-12-29  Yao Qi  <yao@codesourcery.com>

	* gdb.trace/entry-values.exp: Update comments.  Rename variable
	bar_call_foo to returned_from_foo.
2014-12-29 15:42:38 +08:00
Anthony Green 91529dc5ce Add moxiebox target support 2014-12-29 00:42:55 -05:00
Joel Brobecker ce637ffbe6 Fix small spelling mistake in gdb/ChangeLog. 2014-12-28 07:44:49 +04:00
Anthony Green 6441e6db4a Update for moxie ISA changes 2014-12-27 18:37:58 -05:00
Terry Guo 5c294fee9a ARM: Add support for value 3 of Tag_ABI_VFP_args attribute
*** bfd/ChangeLog ***

2014-12-25  Thomas Preud'homme  <thomas.preudhomme@arm.com>

	* elf32-arm.c (elf32_arm_merge_eabi_attributes): Handle new
	Tag_ABI_VFP_args value and replace hardcoded values by enum
	values.
	(elf32_arm_post_process_headers): Set e_flags in ELF header
	as hard float only when Tag_ABI_VFP_args is 1, using new enum
	value AEABI_VFP_args_vfp to check that.

*** binutils/ChangeLog ***

2014-12-25  Thomas Preud'homme  <thomas.preudhomme@arm.com>

	* readelf.c (arm_attr_tag_ABI_VFP_args): Add "compatible".

*** gdb/ChangeLog ***

2014-12-25  Thomas Preud'homme  <thomas.preudhomme@arm.com>

	* arm-tdep.c (arm_gdbarch_init): Explicitely handle value 3 of
	Tag_ABI_VFP_args. Also replace hardcoded values by enum values
	in the switch handling the different values of Tag_ABI_VFP_args.

*** gold/ChangeLog ***

2014-12-25  Thomas Preud'homme  <thomas.preudhomme@arm.com>

	* arm.cc (Target_arm::do_adjust_elf_header): Set e_flags in ELF
	header as hard float only when Tag_ABI_VFP_args is 1, using new
	enum value AEABI_VFP_args_vfp to check that.
	(Target_arm::merge_object_attributes): Handle new Tag_ABI_VFP_args
	value and replace hardcoded values by enum values.

*** include/elf/ChangeLog ***

2014-12-25  Thomas Preud'homme  <thomas.preudhomme@arm.com>

	* arm.h: New AEABI_FP_number_model_* and AEABI_VFP_args_* enum
	values.

*** ld/testsuite/ChangeLog ***

2014-12-25  Thomas Preud'homme  <thomas.preudhomme@arm.com>

	* ld-arm/attr-merge-2a.s: Add Tag_ABI_VFP_args.
	* ld-arm/attr-merge-2b.s: Likewise.
	* ld-arm/attr-merge-2.attr: Likewise.
	* ld-arm/attr-merge-4a.s: Add Tag_ABI_FP_number_model and
	Tag_ABI_VFP_args.
	* ld-arm/attr-merge-4b.s: Likewise.
	* ld-arm/attr-merge-4.attr: Likewise.
	* ld-arm/attr-merge-6a.s: Likewise.
	* ld-arm/attr-merge-6b.s: Likewise.
	* ld-arm/attr-merge-6.attr: Add Tag_ABI_FP_number_model.
2014-12-25 09:55:03 +08:00
Doug Evans 1994afbf19 Look up primitive types as symbols.
gdb/ChangeLog:

	* ada-lang.c (user_select_syms): Only fetch symtab if symbol is
	objfile-owned.
	(cache_symbol): Ignore symbols that are not objfile-owned.
	* block.c (block_objfile): New function.
	(block_gdbarch): New function.
	* block.h (block_objfile): Declare.
	(block_gdbarch): Declare.
	* c-exp.y (classify_name): Remove call to
	language_lookup_primitive_type.  No longer necessary.
	* gdbtypes.c (lookup_typename): Call lookup_symbol_in_language.
	Remove call to language_lookup_primitive_type.  No longer necessary.
	* guile/scm-symbol.c (syscm_gdbarch_data_key): New static global.
	(syscm_gdbarch_data): New struct.
	(syscm_init_arch_symbols): New function.
	(syscm_get_symbol_map): Renamed from syscm_objfile_symbol_map.
	All callers updated.  Handle symbols owned by arches.
	(gdbscm_symbol_symtab): Handle symbols owned by arches.
	(gdbscm_initialize_symbols): Initialize syscm_gdbarch_data_key.
	* language.c (language_lookup_primitive_type_1): New function.
	(language_lookup_primitive_type): Call it.
	(language_alloc_type_symbol): New function.
	(language_init_primitive_type_symbols): New function.
	(language_lookup_primitive_type_as_symbol): New function.
	* language.h (struct language_arch_info) <primitive_type_symbols>:
	New member.
	(language_lookup_primitive_type): Add function comment.
	(language_lookup_primitive_type_as_symbol): Declare.
	* printcmd.c (address_info): Handle arch-owned symbols.
	* python/py-symbol.c (sympy_get_symtab): Ditto.
	(set_symbol): Ditto.
	(sympy_dealloc): Ditto.
	* symmisc.c (print_symbol): Ditto.
	* symtab.c (fixup_symbol_section): Ditto.
	(lookup_symbol_aux): Initialize block_found.
	(basic_lookup_symbol_nonlocal): Try looking up the symbol as a
	primitive type.
	(initialize_objfile_symbol_1): New function.
	(initialize_objfile_symbol): Call it.
	(allocate_symbol): Call it.
	(allocate_template_symbol): Call it.
	(symbol_objfile): Assert symbol is objfile-owned.
	(symbol_arch, symbol_symtab, symbol_set_symtab): Ditto.
	* symtab.h (struct symbol) <owner>: Replaces member "symtab".
	(struct symbol) <is_objfile_owned>: New member.
	(SYMBOL_OBJFILE_OWNED): New macro.
	* cp-namespace.c (cp_lookup_bare_symbol): New arg langdef.
	All callers updated.  Try to find the symbol as a primitive type.
	(lookup_namespace_scope): New arg langdef.  All callers updated.
	Call cp_lookup_bare_symbol directly for simple bare symbols.
2014-12-23 07:58:14 -08:00
Doug Evans c01feb3675 symtab.h (SYMBOL_DOMAIN_BITS): New macro.
gdb/ChangeLog:

	* symtab.h (SYMBOL_DOMAIN_BITS): New macro.
	(struct symbol) <domain>: Use it.
2014-12-23 07:31:00 -08:00
Doug Evans 38bf1463f4 initialize_objfile_symbol: Renamed from initialize_symbol.
gdb/ChangeLog:

	* symtab.c (initialize_objfile_symbol): Renamed from initialize_symbol.
	All callers updated.
2014-12-23 07:28:28 -08:00
Doug Evans f606139ae8 Add langdef arg to la_lookup_symbol_nonlocal.
gdb/ChangeLog:

	* language.h (struct language_defn) <la_lookup_symbol_nonlocal>:
	New arg language_defn.  All uses updated.
2014-12-23 07:24:48 -08:00
Doug Evans 08be3fe322 Replace some symbol accessor macros with functions.
gdb/ChangeLog:

	* symtab.h (SYMBOL_SYMTAB): Delete
	(SYMBOL_OBJFILE): Delete.
	(symbol_symtab, symbol_set_symtab): Declare.
	(symbol_objfile, symbol_arch): Declare.
	* symtab.c (symbol_symtab): Replaces SYMBOL_SYMTAB.  All uses updated.
	All references to symbol->symtab redirected through here.
	(symbol_set_symtab): New function.  All assignments to SYMBOL_SYMTAB
	redirected through here.
	(symbol_arch): New function.
	(symbol_objfile): New function.  Replaces SYMBOL_OBJFILE.
	All uses updated.
	* cp-namespace.c (cp_lookup_symbol_imports_or_template): Call
	symbol_arch.
	* findvar.c (default_read_var_value): Call symbol_arch.
	* guile/scm-frame.c (gdbscm_frame_block): Call symbol_objfile.
	* jv-lang.c (add_class_symtab_symbol): Call symbol_arch.
	* printcmd.c (address_info): Call symbol_arch.
	* tracepoint.c (scope_info): Call symbol_arch.
2014-12-23 07:21:10 -08:00
Doug Evans f953163fe9 cp-namespace.c (cp_lookup_symbol_via_all_imports): New function.
gdb/ChangeLog:

	* cp-namespace.c (cp_lookup_symbol_via_all_imports): New function.
	(cp_lookup_symbol_namespace): Call it.
	(cp_lookup_symbol_nonlocal): Ditto.
2014-12-22 09:29:25 -08:00
Doug Evans 4bd0864e21 cp-namespace.c (cp_lookup_symbol_via_imports): New arg "search_scope_first".
gdb/ChangeLog:

	* cp-namespace.c (cp_lookup_symbol_via_imports): New arg
	"search_scope_first".  All callers updated.
2014-12-22 09:20:50 -08:00
Doug Evans 6f27419a4d cp-namespace.c (cp_lookup_nested_symbol_1): New function.
gdb/ChangeLog:

	* cp-namespace.c (cp_lookup_nested_symbol_1): New function.
	(cp_basic_lookup_symbol): Renamed from lookup_symbol_file.  Delete
	arg "search".  All callers updated.
	(cp_lookup_bare_symbol): New function.
	(cp_search_static_and_baseclasses): New function.
	(cp_lookup_symbol_in_namespace): Rewrite, move more logic here.
	(find_symbol_in_baseclass): Simplify, call cp_lookup_nested_symbol_1.
	(cp_lookup_nested_symbol): Ditto.
2014-12-22 09:11:44 -08:00
Doug Evans d276311738 cp-namespace.c (cp_lookup_symbol_in_namespace): Simplify.
gdb/ChangeLog:

	* cp-namespace.c (cp_lookup_symbol_in_namespace): Simplify.
2014-12-22 08:44:50 -08:00
Doug Evans 791244bea2 cp-namespace.c: Whitespace cleanup.
gdb/ChangeLog:

	* cp-namespace.c: Whitespace cleanup.
2014-12-22 08:42:02 -08:00
Mihail-Marian Nistor 87186c6a5c gdb/17394: cannot put breakpoint only in selected ASM file.
This patch fixes a problem when trying to insert a breakpoint on
a specific symbol defined in a specific file, eg:

    break foo.c:func

This currently works for files in C/C++/Ada, etc, but doesn't always
work for Asm files. Analysis of the problem showed that this related
to a limitation in gas, which does not generate debug info for functions/
symbols.  Thus, we have a symtab for the file ("info sources" shows
the file), but it contains no symbols.

When find_linespec_symbols is called in linespec_parse_basic, it calls
find_function_symbols, which uses add_matching_symbols_to_info to
collect all matching symbols.

That function does [pardon any mangled formatting]:

  for (ix = 0; VEC_iterate (symtab_ptr, info->file_symtabs, ix, elt); ++ix)
    {
      if (elt == NULL)
        {
          iterate_over_all_matching_symtabs (info->state, name, VAR_DOMAIN,
                                             collect_symbols, info,
                                             pspace, 1);
          search_minsyms_for_name (info, name, pspace);
        }
      else if (pspace == NULL || pspace == SYMTAB_PSPACE (elt))
        {
          /* Program spaces that are executing startup should have
             been filtered out earlier.  */
          gdb_assert (!SYMTAB_PSPACE (elt)->executing_startup);
          set_current_program_space (SYMTAB_PSPACE (elt));
          iterate_over_file_blocks (elt, name, VAR_DOMAIN,
                                    collect_symbols, info);
        }
    }

This iterates over the symtabs. In the failing use case, ELT is
non-NULL (points to the symtab for the .s file), so it calls
iterate_over_file_blocks. Herein is where the problem exists: it is
assumed that if NAME exists, it must exist in the given symtab -- a
reasonable assumption for "normal" (non-asm) cases. It never searches
minimal symbols (or in the global default symtab).

This patch fixes the problem by doing so. It is important to note that
iterating over minsyms is fairly expensive, so this patch only adds
that extra search if the language is language_asm and
iterate_over_file_blocks returns no symbols.

gdb/ChangeLog:
2014-12-20  Keith Seitz  <keiths@redhat.com>
            Mihail-Marian Nistor  <mihail.nistor@freescale.com>

        PR gdb/17394
        * linespec.c (struct collect_minsyms): Add new member `symtab'.
        (add_minsym): Handle cases where info.symtab is non-NULL.
        (search_minsyms_for_name): Add new parameter `symtab'.
        Handle limiting searches to a specific symtab.
        (add_matching_symtabs_to_info): Search through minimal symbols
        for language_asm files for which no new symbols are found.

gdb/testsuite/ChangeLog:
2014-12-20  Mihail-Marian Nistor  <mihail.nistor@freescale.com>

        PR gdb/17394
        * gdb.linespec/break-asm-file.c: New file.
        * gdb.linespec/break-asm-file.exp: New file.
        * gdb.linespec/break-asm-file0.s: New file.
        * gdb.linespec/break-asm-file1.s: New file.
2014-12-20 11:32:25 -05:00
Yao Qi bb7e3f4d51 MIPS SDE OS ABI support
This patch is to add SDE OS ABI support in GDB, which has been used in
codesourcery gdb tree for some years.

gdb:

2014-12-19  Maciej W. Rozycki  <macro@codesourcery.com>
	    Nigel Stephens  <nigel@mips.com>
	    Chris Dearman  <chris@mips.com>
	    Luis Machado  <lgustavo@codesourcery.com>

	* Makefile.in (ALL_TARGET_OBS): Add mips-sde-tdep.o.
	(ALLDEPFILES): Add mips-sde-tdep.c.
	* mips-sde-tdep.c: New file containg SDE specific code.
	* configure.tgt (mips*-sde*-elf*): Add mips-sde-dep.o to
	gdb_target_obs.
	* defs.h (gdb_osabi): Add GDB_OSABI_SDE.
	* osabi.c (gdb_osabi_names): Add SDE.
	* NEWS: Mention the change.
2014-12-19 13:13:07 +08:00
Simon Marchi db7a9bcd53 A few comment cleanups
I stumbled upon a few comments that I think are outdated.

Comment for elfread.c (elf_symfile_init): As far as history goes in git,
I don't see anything related to that.

Comment for elfread.c (elf_symfile_read): References a parameter that was
removed in 1999.

Comment for struct sym_fns/sym_offsets: References a parameter that was
changed in 1999.

gdb/ChangeLog:

	* elfread.c (elf_symfile_init): Remove stale comment.
	(elf_symfile_read): Same.
	* symfile.h (struct sym_fns): Same.
2014-12-18 11:39:44 -05:00
Yao Qi 1bab73830f MIPS: Provide FPU info and decode FCSR in `info float'
This patch is the V2.  V1 can be found in
https://sourceware.org/ml/gdb-patches/2012-05/msg00938.html
V2 is to address Joel's comment
<https://sourceware.org/ml/gdb-patches/2012-06/msg00289.html> about
keeping dumping floating point registers.  Additionally, command
'info float' prints bits on nan2008 and abs2008.

------------------------------------------------------------------

 The change below provides a MIPS-specific handler for the:

(gdb) info float

command.  It provides information about the FPU type available (if any),
the FPU register width, and decodes the CP1 Floating Point Control and
Status Register (FCSR):

(gdb) print /x $fsr
$1 = 0xff83ffff
(gdb) info float
fpu type: double-precision
reg size: 32 bits
cond    : 0 1 2 3 4 5 6 7
cause   : inexact uflow oflow div0 inval unimp
mask    : inexact uflow oflow div0 inval
flags   : inexact uflow oflow div0 inval
rounding: -inf
flush   : zero

 One point to note about CP1.FCSR are the non-standard Flush-to-Nearest
and Flush-Override bits.  They are not a part of the MIPS architecture and
take two positions reserved for an implementation-dependent use in the
architecture.  They are present in all the FPU implementations made by
MIPS Technologies since the spin-off from SGI.

 I haven't been able to track down a single other MIPS FPU implementation
that would make any use of these bits and they are required to be
hardwired to zero by the architecture specification if unimplemented.
Therefore I think it makes sense to report them in the current way.

 GDB has no guaranteed access to the CP0 Processor Identification (PRId)
register to validate this feature properly and the ID information stored
in the CP1 Floating Point Implementation Register (FIR) is from my
experience not reliable enough (there's no Company ID available there for
once unlike in CP0.PRId and Processor ID is not guaranteed to be unique).

 As a side note we should probably dump CP1.FIR information as well, as
there's useful stuff indicating some FPU features there.  That's material
for another change however.

gdb/

2014-12-18  Nigel Stephens  <nigel@mips.com>
            Maciej W. Rozycki  <macro@codesourcery.com>

	* mips-tdep.c (print_fpu_flags): New function.
	(mips_print_float_info): Likewise.
	(mips_gdbarch_init): Install mips_print_float_info as gdbarch
	print_float_info routine.

gdb/testsuite/

2014-12-18  Nigel Stephens  <nigel@mips.com>
            Maciej W. Rozycki  <macro@codesourcery.com>

	* gdb.base/float.exp: Handle the new output from "info float" on
	MIPS targets.
2014-12-18 20:47:28 +08:00
Yao Qi cc86d1cb95 Refactor gdbarch method print_float_info
This patch is to change print_float_info gdbarch method for the
following two reasons,

 1. we want to add a default implementation of print_float_info to
    dump the float pointer registers.  It can be reused by backend to
    print something more than float point registers.
 2. we want to simplify the caller of print_float_info,
    infcmd.c:print_float_info.

gdb:

2014-12-18  Yao Qi  <yao@codesourcery.com>

 	* gdbarch.sh (print_float_info): Change its type from 'M' to 'm'.
	* gdbarch.c: Re-generated.
	* gdbarch.h: Likewise.
	* infcmd.c (default_print_float_info): New function.
	(print_float_info): Removed.  Move code to
	default_print_float_info.
	(float_info): Adjust to call gdbarch_print_float_info.
	* inferior.h (default_print_float_info): Declare it.
2014-12-18 20:47:28 +08:00
Yao Qi 2ad47ec433 Remove h8300_print_float_info
In infcmd.c:print_float_info, if the architecture doesn't have gdbarch
method print_float_info implemented and doesn't float reggroup, GDB
will prints "No floating-point info available for this processor."
The h8300 port doesn't have float registers, and don't need to
implement print_float_info.  This patch is to remove it.

gdb:

2014-12-18  Yao Qi  <yao@codesourcery.com>

	* h8300-tdep.c (h8300_print_float_info): Remove.
	(h8300_gdbarch_init): Remove the call to
	set_gdbarch_print_float_info.
2014-12-18 20:47:27 +08:00
Doug Evans 253342b8e6 infcmd.c (jump_command): Minor simplification.
gdb/ChangeLog:

	* infcmd.c (jump_command): Minor simplification.
2014-12-18 01:32:59 -08:00
Doug Evans 46b0da1738 language_lookup_primitive_type: Renamed from language_lookup_primitive_type_by_name.
gdb/ChangeLog:

	* language.c (language_lookup_primitive_type): Renamed from
	language_lookup_primitive_type_by_name.  All callers updated.
2014-12-18 01:10:34 -08:00
Doug Evans 99d4b98d4b Fix file name in earlier entry. 2014-12-18 00:52:40 -08:00
Jan Kratochvil 1bc1068a0c Fix MinGW compilation
On Sun, 14 Dec 2014 07:00:28 +0100, Yao Qi wrote:
The build on mingw host is broken because mingw has no mkdtemp.

../../../git/gdb/compile/compile.c: In function 'get_compile_file_tempdir':
../../../git/gdb/compile/compile.c:194:3: error: implicit declaration of function 'mkdtemp' [-Werror=implicit-function-declaration]
   tempdir_name = mkdtemp (tname);
   ^
../../../git/gdb/compile/compile.c:194:16: error: assignment makes pointer from integer without a cast [-Werror]
   tempdir_name = mkdtemp (tname);
                ^
cc1: all warnings being treated as errors

In the end I have managed to test it by Wine myself:

$ wine build_win32/gdb/gdb.exe -q build_win32/gdb/gdb.exe -ex start -ex 'compile code 1' -ex 'set confirm no' -ex quit
[...]
Temporary breakpoint 1, main (argc=1, argv=0x241418) at ../../gdb/gdb.c:29
29        args.argc = argc;
Could not load libcc1.so: Module not found.

Even if it managed to load libcc1.so (it needs host-dependent name libcc1.dll)
then it would soon end up at least on:

default_infcall_mmap:
  error (_("This target does not support inferior memory allocation by mmap."));

As currently there is only:

linux-tdep.c:
  set_gdbarch_infcall_mmap (gdbarch, linux_infcall_mmap);

While one could debug Linux targets from MS-Windows host I find it somehow
overcomplicated now when we are trying to get it running at least on native
Linux x86*.

The 'compile' project needs a larger port effort to run on MS-Windows.

gdb/ChangeLog
2014-12-17  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix MinGW compilation.
	* compile/compile.c (get_compile_file_tempdir): Call error if
	!HAVE_MKDTEMP.
	* config.in: Regenerate.
	* configure: Regenerate.
	* configure.ac (AC_CHECK_FUNCS): Add mkdtemp.

gdb/testsuite/ChangeLog
2014-12-17  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix MinGW compilation.
	* gdb.compile/compile-ops.exp: Update untested message if
	!skip_compile_feature_tests.
	* gdb.compile/compile-setjmp.exp: Likewise.
	* gdb.compile/compile-tls.exp: Likewise.
	* gdb.compile/compile.exp: Likewise.
	* lib/gdb.exp (skip_compile_feature_tests): Check also "Command not
	supported on this host".
2014-12-17 20:09:02 +01:00
Doug Evans 5e3c72e6b8 value_maybe_namespace_elt: Remove redundant call to lookup_static_symbol.
Anytime you can remove a symbol lookup that loops over all objfiles
is A Good Thing.

The call to lookup_static_symbol in valops.c:value_maybe_namespace_elt
is redundant with this call in cp_lookup_nested_symbol:

	/* Now search all static file-level symbols.  We have to do this
	   for things like typedefs in the class.  We do not try to
	   guess any imported namespace as even the fully specified
	   namespace search is already not C++ compliant and more
	   assumptions could make it too magic.  */

	size = strlen (parent_name) + 2 + strlen (nested_name) + 1;
	concatenated_name = alloca (size);
	xsnprintf (concatenated_name, size, "%s::%s",
		 parent_name, nested_name);
	sym = lookup_static_symbol (concatenated_name, VAR_DOMAIN);
	if (sym != NULL)
	  return sym;

Earlier in value_maybe_namespace_elt we do this:

  sym = cp_lookup_symbol_namespace (namespace_name, name,
				    get_selected_block (0), VAR_DOMAIN);

That sequence goes like:

value_maybe_namespace_elt
-> cp_lookup_symbol_namespace
-> cp_lookup_symbol_in_namespace
-> lookup_symbol_file
-> cp_lookup_nested_symbol
-> lookup_static_symbol

The call was added in commit 41f62f3939.
https://sourceware.org/ml/gdb-patches/2010-06/msg00663.html
With a part 2 here:
https://sourceware.org/ml/gdb-patches/2010-06/msg00664.html

At the time the call to lookup_static_symbol (spelled
lookup_static_symbol_aux at the time) was needed.

However, this patch, 8dea366bbe,
https://sourceware.org/ml/gdb-patches/2012-11/msg00387.html
augmented lookup_symbol_file to call cp_lookup_nested_symbol
and introduced the redundancy.

It's kinda buried, so it's totally not unexpected that this happened.

gdb/ChangeLog:

	* valops.c (value_maybe_namespace_elt): Remove redundant call to
	lookup_static_symbol.
2014-12-17 00:30:29 -08:00
Doug Evans cc485e6201 New parameter "debug symbol-lookup".
gdb/ChangeLog:

	New parameter "debug symbol-lookup".
	* NEWS: Mention it.
	* cp-namespace.c (cp_lookup_symbol_imports_or_template): Add debug
	output.
	(cp_lookup_symbol_namespace, cp_lookup_symbol_nonlocal): Ditto.
	(cp_lookup_nested_symbol): Ditto.
	* language.c (language_lookup_primitive_type_by_name): Add debug
	output.
	* minsyms.c (lookup_minimal_symbol): Add debug output.
	* objfiles.c (objfile_debug_name): Moved here, and renamed ...
	* symfile-debug.c (debug_objfile_name): ... from here.  All callers
	updated.
	* objfiles.h (objfile_debug_name): Declare.
	* symtab.h (symbol_lookup_debug): Declare.
	* symtab.c (symbol_lookup_debug): New global.
	(lookup_language_this): Add debug output.
	(lookup_symbol_aux, lookup_symbol_in_block): Ditto.
	(lookup_symbol_in_objfile_symtabs, lookup_symbol_via_quick_fns): Ditto.
	(lookup_symbol_in_static_block, lookup_symbol_in_objfile): Ditto.
	(_initialize_symtab): Add new parameter "debug symbol-lookup".

gdb/doc/ChangeLog:

	* gdb.texinfo (Debugging Output): Document "debug symbol-lookup".
2014-12-17 00:17:27 -08:00
Doug Evans 0ab9ce852b Make buildsym set-up/tear-down more consistent, and document it.
gdb/ChangeLog:

	* buildsym.c: Add comments describing how the buildsym machinery
	is used by the various file formats.
	(really_free_pendings): Enhance function comment.
	See pending_macros to NULL.  Simplify resetting pending_addrmap.
	Call free_buildsym_compunit.
	(free_buildsym_compunit): Set current_subfile to NULL.
	(prepare_for_building): New function.
	(start_symtab): Call it.  Remove call to set_last_source_file.
	(restart_symtab): New arg "cust".  All callers updated.
	Simplify, call prepare_for_building.  Re-initialize buildsym_compunit.
	(reset_symtab_globals): Enhance function comment.
	Set local_symbols, file_symbols, global_symbols to NULL.
	Set pending_macros to NULL.  Simplify resetting pending_addrmap.
	Call free_buildysym_compunit.
	(end_symtab_without_blockvector): Delete.  All callers updated.
	(end_symtab_with_blockvector): Remove redundant call to
	free_buildsym_compunit.
	(augment_type_symtab): Remove arg "cust".  All callers updated.
	(buildsym_init): Remove resetting of free_pendings, file_symbols,
	global_symbols, pending_blocks, pending_macros.  Instead make
	handling consistent with pending_addrmap: Assert value was reset
	at end of previous symtab building.  Initialize context_stack here.
2014-12-17 00:00:14 -08:00
Doug Evans b6615d1086 boards/stabs.exp: New file.
gdb/ChangeLog:

	* boards/stabs.exp: New file.
2014-12-16 23:10:54 -08:00
Doug Evans 55accf4a1e cp_lookup_symbol_via_imports: Renamed from cp_lookup_symbol_imports.
gdb/ChangeLog:

	* cp-namespace.c (cp_lookup_symbol_via_imports): Renamed from
	cp_lookup_symbol_imports.  All callers updated.
2014-12-16 22:19:15 -08:00
Doug Evans a07e3e182d cp_find_type_baseclass_by_name: Renamed from find_type_baseclass_by_name.
gdb/ChangeLog:

	* cp-namespace.c (cp_find_type_baseclass_by_name): Renamed from
	find_type_baseclass_by_name.  All callers updated.
2014-12-16 22:13:57 -08:00
Doug Evans d01060f023 symtab.h (struct symbol_search) <symtab>: Delete, unnecessary.
gdb/ChangeLog:

	* symtab.h (struct symbol_search) <symtab>: Delete.  All uses updated.
	* symtab.c (compare_search_syms): Use SYMBOL_SYMTAB accessor.
	(print_symbol_info): Delete arg symtab.  All callers updated.
	(symtab_symbol_info): Use SYMBOL_SYMTAB accessor.
2014-12-16 22:00:13 -08:00
Andreas Arnez 25dda427ec Fix indentation of "maint print user-registers"
This fixes a failure of the test case "complete 'info registers '" in
completion.exp on architectures where the user registers have numbers
above 99.  In that case the output of "maint print user-registers" was
no longer indented, and the regexp in the test case failed to add them
to the list of expected completion results.  The fix also swaps the
columns "Name" and "Nr", such that the indentation is always the same,
and to be consistent with the output of "maint print registers".

gdb/ChangeLog:

	* user-regs.c (maintenance_print_user_registers): Swap "Nr" and
	"Name" columns.  Assure that the output is always indented.

gdb/testsuite/ChangeLog:

	* gdb.base/completion.exp: Adjust to format changes of "maint
	print user-registers".
2014-12-16 16:06:42 +01:00
Joel Brobecker beed38b827 [Linux] Ask kernel to kill inferior when GDB terminates
This patch enhances GDB on GNU/Linux systems in the situation where
we are debugging an inferior that was created from GDB (as opposed
to attached to), by asking the kernel to kill the inferior if GDB
terminates without doing it itself.

This would typically happen when GDB encounters a problem and
crashes, or when it gets killed by an external process. This can
be observed by starting a program under GDB, and then killing
GDB with signal 9. After GDB is killed, the inferior still remains.

This patch also fixes GDBserver similarly.

This fix is conditional on the kernel supporting the PTRACE_O_EXITKILL
feature.  On older kernels, the behavior remains unchanged.

gdb/ChangeLog:

        * nat/linux-ptrace.h (PTRACE_O_EXITKILL): Define if not
        already defined.
        (linux_enable_event_reporting): Add parameter "attached".
        * nat/linux-ptrace.c (linux_test_for_exitkill): New forward
        declaration.  New function.
        (linux_check_ptrace_features): Add linux_test_for_exitkill call.
        (linux_enable_event_reporting): Add new parameter "attached".
        Do not call ptrace with the PTRACE_O_EXITKILL if ATTACHED is
        nonzero.
        * linux-nat.c (linux_init_ptrace): Add parameter "attached".
        Use it.  Update function description.
        (linux_child_post_attach, linux_child_post_startup_inferior):
        Update call to linux_enable_event_reporting.

gdb/gdbserver/ChangeLog:

        * linux-low.c (linux_low_filter_event): Update call to
        linux_enable_event_reporting following the addition of
        a new parameter to that function.

Tested on x86_64-linux, native and native-gdbserver.

I also verified by hand that the inferior gets killed when killing
GDB in the "run" case, while the inferior remains in the "attach"
case. Same for GDBserver.
2014-12-16 07:56:46 -05:00
Catalin Udma bf330350c2 aarch64/gdbserver: fix floating point registers display
When using aarch64 gdb with gdbserver, floating point registers are
not correctly displayed, as below:
  (gdb) info registers fpsr fpcr
  fpsr           <unavailable>
  fpcr           <unavailable>

To fix these problems, the missing fpsr and fpcr registers are added
when floating point registers are read/write
Add test for aarch64 floating point
PR server/17457

gdb/gdbserver/

    PR server/17457
    * linux-aarch64-low.c (AARCH64_FPSR_REGNO): New define.
    (AARCH64_FPCR_REGNO): Likewise.
    (AARCH64_NUM_REGS): Update to include fpsr/fpcr registers.
    (aarch64_fill_fpregset): Add missing fpsr/fpcr registers.
    (aarch64_store_fpregset): Likewise.

gdb/testsuite/

    PR server/17457
    * gdb.arch/aarch64-fp.c: New file.
    * gdb.arch/aarch64-fp.exp: New file.

Signed-off-by: Catalin Udma <catalin.udma@freescale.com>
2014-12-16 09:51:42 +02:00
Yao Qi 8fda906819 Move NEWS entries to the right section
gdb:

2014-12-16  Yao Qi  <yao@codesourcery.com>

	* NEWS: Move some entries to "Changes since GDB 7.8" section.
2014-12-16 13:21:49 +08:00
Yao Qi 2a54636794 Replace ARG_MAX with ARG_LAST
We define an enum ARG_MAX in linux_infcall_mmap, but it is conflict
with macro ARG_MAX which is defined in /usr/include/linux/limits.h.
This causes a build failure below,

 gdb/linux-tdep.c: In function 'linux_infcall_mmap':
 gdb/linux-tdep.c:1945:70: error: expected identifier before numeric constant

the enum in the pre-processed source becomes:

  enum
    {
      ARG_ADDR, ARG_LENGTH, ARG_PROT, ARG_FLAGS, ARG_FD, ARG_OFFSET, 131072
    };

This patch is to replace ARG_MAX with ARG_LAST.

gdb:

2014-12-16  Yao Qi  <yao@codesourcery.com>

	* linux-tdep.c (linux_infcall_mmap): Replace ARG_MAX with
	ARG_LAST.
2014-12-16 13:13:17 +08:00
Sergio Durigan Junior 395cf596db Merge dg-extract-results.{sh,py} from GCC upstream
It has been a while since we don't sync this file with GCC upstream,
and in the meantime some interesting things have happened.  The most
interesting is the inclusion of a new dg-extract-results.py which is
apparently faster than its shell equivalent.

This merge will probably fix the bug described in

  <https://sourceware.org/ml/gdb-patches/2014-12/msg00421.html>

Though I am still proposing the patch for upstream GCC.  Once it gets
accepted, I will merge it too.

OK to apply?

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

	Merge dg-extract-results.{sh,py} from GCC upstream (r210243,
	r210637, r210913, r211666, r215400, r215817).

	2014-05-08  Richard Sandiford  <rdsandiford@googlemail.com>
		* dg-extract-results.py: New file.
		* dg-extract-results.sh: Use it if the environment seems
		suitable.

	2014-05-20  Richard Sandiford  <rdsandiford@googlemail.com>

		* dg-extract-results.py (parse_run): Handle warnings that
		are printed before a test harness is run.

	2014-05-25  Richard Sandiford  <rdsandiford@googlemail.com>

		* dg-extract-results.py (Named): Remove __cmp__ method.
		(output_variation): Use a key to sort variation.harnesses.

	2014-06-14  Richard Sandiford  <rdsandiford@googlemail.com>

		* dg-extract-results.py: For Python 3, force sys.stdout to
		handle surrogate escape sequences.
		(safe_open): New function.
		(output_segment, main): Use it.

	2014-09-19  Segher Boessenkool  <segher@kernel.crashing.org>

		* dg-extract-results.py (Prog.result_re): Include options
		in test name.

	2014-10-02  Segher Boessenkool  <segher@kernel.crashing.org>

		* dg-extract-results.py (output_variation): Always sort if
		do_sum.
2014-12-15 19:37:55 -05:00
Simon Marchi c9657e708a Introduce utility function find_inferior_ptid
This patch introduces find_inferior_ptid to replace the common idiom

  find_inferior_pid (ptid_get_pid (...));

It replaces all the instances of that idiom that I found with the new
function.

No significant changes before/after the patch in the regression suite
on amd64 linux.

gdb/ChangeLog:

	* inferior.c (find_inferior_ptid): New function.
	* inferior.h (find_inferior_ptid): New declaration.
	* ada-tasks.c (ada_get_task_number): Use find_inferior_ptid.
	* corelow.c (core_pid_to_str): Same.
	* darwin-nat.c (darwin_resume): Same.
	* infrun.c (fetch_inferior_event): Same.
	(get_inferior_stop_soon): Same.
	(handle_inferior_event): Same.
	(handle_signal_stop): Same.
	* linux-nat.c (resume_lwp): Same.
	(stop_wait_callback): Same.
	* mi/mi-interp.c (mi_new_thread): Same.
	(mi_thread_exit): Same.
	* proc-service.c (ps_pglobal_lookup): Same.
	* record-btrace.c (record_btrace_step_thread): Same.
	* remote-sim.c (gdbsim_close_inferior): Same.
	(gdbsim_resume): Same.
	(gdbsim_stop): Same.
	* sol2-tdep.c (sol2_core_pid_to_str): Same.
	* target.c (memory_xfer_partial_1): Same.
	(default_thread_address_space): Same.
	* thread.c (thread_change_ptid): Same.
	(switch_to_thread): Same.
	(do_restore_current_thread_cleanup): Same.
2014-12-15 12:00:55 -05:00
Simon Marchi e882ef3cfc testsuite: expect possible pagination when starting gdb
When gdb starts, the lines that appear before the first prompt may get
paginated if the terminal in which the tests are ran is too small (in
terms of rows). These lines include the welcome/license message and
possibly more, such as "Reading symbols from...". Pagination is disabled
right after gdb is started (with "set height 0"), but this output happens
before we are able to set height.

If these lines get paginated, gdb waits for the user to press enter and
the test harness waits for gdb to print its prompt, resulting in a
deadlock.

My first idea was to launch gdb with --quiet. However, some lines are
still printed ("Reading symbols from...", some more stuff when attaching
with --pid, etc).

The proposed solution simply expects that pagination can occur after
starting gdb. If this is the case, it sends a "\n" and loops.

gdb/testsuite/Changelog:

	* lib/gdb.exp (default_gdb_start): After starting gdb, loop
	as long as we get pagination notifications.
2014-12-15 11:46:44 -05:00
Simon Marchi 38bcc89d48 Fix build with Python 3.4 (PR python/16784)
The type of the function pointer PyOS_ReadlineFunctionPointer (part of the
Python C API), which we use, slightly changed starting with Python 3.4. The
signature went from

PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *);

to

PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *);

The parameter that changed is the prompt text.

This commits adjust gdb accordingly by making the prompt_arg parameter
const, as well as the fallouts of that. I needed to rework how
annotations are added to the prompt, since the it is now const. If
annotations are enabled, it will make a copy of the prompt overwrite the
prompt variable that is used throughout the function. Otherwise, no copy
is done and the original prompt_arg value is passed.

I changed the signature of deprecated_readline_hook. I would've changed any
user of it, but it seems like nothing is using it,

Built-tested with python 2.7.x, 3.3.y and 3.4.z.

gdb/ChangeLog:

	* defs.h (gdb_readline): Constify argument.
	(gdb_readline_wrapper): Same.
	(command_line_input): Same.
	(deprecated_readline_hook): Same.
	* top.c (deprecated_readline_hook): Same.
	(gdb_readline): Same.
	(gdb_readline_wrapper): Same.
	(command_line_input): Constify argument. Pass prompt to
	called functions instead of local_prompt, overwriting prompt
	if using annotations.
	* event-top.h (display_gdb_prompt): Constify argument.
	* event-top.c (display_gdb_prompt): Same.
	* python/py-gdb-readline.c (gdbpy_readline_wrapper): Constify
	argument if building with Python 3.4 and up.

Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
2014-12-15 11:40:00 -05:00
Simon Marchi 89ed8ea187 python extended prompt: Use os.getcwd() instead of os.getcwdu()
It seems like using os.getcwdu() here is wrong both for Python 2 and Python 3.

For Python 2, this returns a 'unicode' object, which tries to get concatenated
to a 'str' object in substitute_prompt. The implicit conversion works when the
unicode string contains no accent. When it does contain an accent though,
displaying the prompt results in the following error:

(gdb) set extended-prompt \w
...
  File "/home/simark/build/binutils-gdb-python2/gdb/data-directory/python/gdb/prompt.py", line 138, in substitute_prompt
    result += str(cmd(arg))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 49: ordinal not in range(128)

When using os.getcwd() instead, it works correctly. I suppose that Python does
the necessary decoding internally.

For Python 3, this method simply does not exist. It works fine with os.getcwd().

gdb/ChangeLog:

	* python/lib/gdb/prompt.py (_prompt_pwd): Use os.getcwd() instead of
	os.getcwdu().
2014-12-15 11:40:00 -05:00
Jason Merrill 4992aa2019 * Makefile.in (check-gdb.%): Restore.
* README: Mention it.
2014-12-15 10:35:30 -05:00
Joel Brobecker 5227d62525 Use PTRACE_SINGLESTEP_ONE when single-stepping one thread.
Currently, when we receive a request to single-step one single thread
(Eg, when single-stepping out of a breakpoint), we use the
PTRACE_SINGLESTEP pthread request, which does single-step
the corresponding thread, but also resumes execution of all
other threads in the inferior.

This causes problems when debugging programs where another thread
receives multiple debug events while trying to single-step a specific
thread out of a breakpoint (with infrun traces turned on):

    (gdb) continue
    Continuing.
    infrun: clear_proceed_status_thread (Thread 126)
    [...]
    infrun: clear_proceed_status_thread (Thread 142)
    [...]
    infrun: clear_proceed_status_thread (Thread 146)
    infrun: clear_proceed_status_thread (Thread 125)
    infrun: proceed (addr=0xffffffff, signal=GDB_SIGNAL_DEFAULT, step=0)
    infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=1, current thread [Thread 142] at 0x10684838
    infrun: wait_for_inferior ()
    infrun: target_wait (-1, status) =
    infrun:   42000 [Thread 146],
    infrun:   status->kind = stopped, signal = GDB_SIGNAL_REALTIME_34
    infrun: infwait_normal_state
    infrun: TARGET_WAITKIND_STOPPED
    infrun: stop_pc = 0x10a187f4
    infrun: context switch
    infrun: Switching context from Thread 142 to Thread 146
    infrun: random signal (GDB_SIGNAL_REALTIME_34)
    infrun: switching back to stepped thread
    infrun: Switching context from Thread 146 to Thread 142
    infrun: resume (step=1, signal=GDB_SIGNAL_0), trap_expected=1, current thread [Thread 142] at 0x10684838
    infrun: prepare_to_wait
    [...handling of similar events for threads 145, 144 and 143 snipped...]
    infrun: prepare_to_wait
    infrun: target_wait (-1, status) =
    infrun:   42000 [Thread 146],
    infrun:   status->kind = stopped, signal = GDB_SIGNAL_REALTIME_34
    infrun: infwait_normal_state
    infrun: TARGET_WAITKIND_STOPPED
    infrun: stop_pc = 0x10a187f4
    infrun: context switch
    infrun: Switching context from Thread 142 to Thread 146
    ../../src/gdb/inline-frame.c:339: internal-error: skip_inline_frames: Assertion `find_inline_frame_state (ptid) == NULL' failed.

What happens is that GDB keeps sending requests to resume one specific
thread, and keeps receiving debugging events for other threads.
Things break down when the one of the other threads receives a debug
event for the second time (thread 146 in the example above).

This patch fixes the problem by making sure that only one thread
gets resumed, thus preventing the other threads from generating
an unexpected event.

gdb/gdbserver/ChangeLog:

        * lynx-low.c (lynx_resume): Use PTRACE_SINGLESTEP_ONE if N == 1.
        Remove FIXME comment about assumption about N.
2014-12-15 09:53:56 -05:00
Catalin Udma aacd3e8c4f Fix info mem command for 32 bits host/64 bits target
When running gdb on 32 bits host for 64 bits target, info mem command
truncates the target address to 32 bits, like in the example below
	(gdb) set architecture powerpc:common64
	(gdb) mem 0x100000000 0x200000000 rw
	(gdb) info mem
	1   y  	0x0000000000000000 0x0000000000000000 rw nocache

gdb/ChangeLog:

        PR gdb/15684
        * memattr.c (mem_info_command): Remove "unsigned long" casts.

Signed-off-by: Catalin Udma <catalin.udma@freescale.com>
2014-12-15 16:41:29 +02:00
Doug Evans dc4d68869c utils.c (make_hex_string): Fix off-by-one error.
gdb/ChangeLog:

	* utils.c (make_hex_string): Fix off-by-one error.
2014-12-13 14:04:05 -08:00
Joel Brobecker c1b5a1a6e7 Internal error trying to print uninitialized string.
Trying to print the value of a string whose size is not known at
compile-time before it gets assigned a value can lead to the following
internal error:

    (gdb) p my_str
    $1 =
    /[...]/utils.c:1089: internal-error: virtual memory exhausted.

What happens is that my_str is described as a reference to an array
type whose bounds are dynamic. During the read of that variable's
value (in default_read_var_value), we end up resolving dynamic types
which, for reference types, makes us also resolve the target of that
reference type. This means we resolve our variable to a reference
to an array whose bounds are undefined, and unfortunately very far
appart.

So, when we pass that value to ada-valprint, and in particular to
da_val_print_ref, we eventually try to allocate too large of a buffer
corresponding to the (bogus) size of our array, hence the internal
error.

This patch fixes the problem by adding a size_check before trying
to print the dereferenced value. To perform this check, a function
that was previously specific to ada-lang.c (check_size) gets
exported, and renamed to something less prone to name collisions
(ada_ensure_varsize_limit).

gdb/ChangeLog:

        * ada-lang.h (ada_ensure_varsize_limit): Declare.
        * ada-lang.c (check_size): Remove advance declaration.
        (ada_ensure_varsize_limit): Renames check_size.
        Replace calls to check_size by calls to ada_ensure_varsize_limit
        throughout.
        * ada-valprint.c (ada_val_print_ref): Add call to
        ada_ensure_varsize_limit.  Add comment explaining why.

gdb/testsuite/ChangeLog:

        * gdb.ada/str_uninit: New testcase.
2014-12-13 11:00:24 -05:00
Joel Brobecker 3c46a02f50 Avoid use of sprintf in gdb/utils.c:make_hex_string
The use of sprintf is discouraged in GDB. Use xsnprintf instead.

gdb/ChangeLog:

        * utils.c (make_hex_string): Replace use of sprintf by use of
        xsnprintf.

Tested on x86_64-linux.
2014-12-13 10:28:58 -05:00
Joel Brobecker 8e8347b895 Fix ARI warnings in gdb/compile/compile-object-load.c.
gdb/ChangeLog:

        * compile/compile-object-load.c (link_callbacks_multiple_definition)
        (link_callbacks_warning, link_callbacks_einfo): Remove trailing
        newline at end of warning message.

Tested on x86_64-linux.
2014-12-13 10:26:47 -05:00
Joel Brobecker e078298010 Add missing ChangeLog entry for PR backtrace/16215. 2014-12-13 10:25:41 -05:00
Joel Brobecker f93b65a0f4 Add ChangeLog entries missing from the previous commit. 2014-12-13 10:24:14 -05:00
Joel Brobecker 648d586d84 configure gdb/gnulib with --disable-largefile if largefile support disabled.
This patch mostly aims at fixing a GDB build failure on 32bit Solaris
systems (Sparc and x86), due to a recent gnulib update adding the
readlink module. But it might also fix related issues when configuring
with --disable-largefile.

A side-effect of the gnulib readlink module addition is that it caused
largefile support to be added as well, and in particular
gnulib/import/m4/largefile.m4 introduced the following new #define in
gnulib's config.in:

| +/* Number of bits in a file offset, on hosts where this is settable. */
| +#undef _FILE_OFFSET_BITS

When defined to 64, it triggers an issue with procfs.h while trying
to build sparc-sol2-nat.c:

| #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
| #error  "Cannot use procfs in the large file compilation environment"
| #endif

As it turns out, this is a fairly familiar problem, and one of
the reasons behind ACX_LARGEFILE having been created. In that macro,
we have some code which disables largefile support on solaris hosts:

|   sparc-*-solaris*|i[3-7]86-*-solaris*)
| changequote([,])dnl
|     # On native 32bit sparc and ia32 solaris, large-file and procfs support
|     # are mutually exclusive; and without procfs support, the bfd/ elf module
|     # cannot provide certain routines such as elfcore_write_prpsinfo
|     # or elfcore_write_prstatus.  So unless the user explicitly requested
|     # large-file support through the --enable-largefile switch, disable
|     # large-file support in favor of procfs support.
|     test "${target}" = "${host}" -a "x$plugins" = xno \
|       && : ${enable_largefile="no"}
|     ;;

But gnulib ignores this fact, and so tries to determine how to
enable large-file support irrespective of whether we want it or not.
This patch fixes the issue by passing --disable-largefile to gnulib's
configure when large-file support in GDB is disabled. This is done
by first enhancing ACX_CONFIGURE_DIR to allow us to pass extra
arguments to be passed to the configure command, and then by modifying
GDB's configure to pass --disable-largefile if large-file support
is disabled.

gdb/ChangeLog:

	* acx_configure_dir.m4 (ACX_CONFIGURE_DIR): Add support for
        new "EXTRA-ARGS" parameter.
	* configure.ac: If large-file support is disabled in GDB,
        pass --disable-largefile to ACX_CONFIGURE_DIR call for "gnulib".
	* configure: Regenerate.

gdb/gdbserver/ChangeLog:

	* configure.ac: If large-file support is disabled in GDBserver,
        pass --disable-largefile to ACX_CONFIGURE_DIR call for "gnulib".
        * configure: Regenerate.

Tested by rebuilding on sparc-solaris and x86_64-linux (with gdbserver).
This fixes the build failure on sparc-solaris. I also verified in
gnulib's config.log file that we pass --disable-largefile in the solaris
case, while we do not in the GNU/Linux case.
2014-12-13 09:45:57 -05:00
Jan Kratochvil 5537b57769 Fix 7.8 regression: resolve_dynamic_struct: Assertion `TYPE_NFIELDS (type) > 0' (PR 17642)
https://sourceware.org/bugzilla/show_bug.cgi?id=17642

Regression since:
commit 012370f681
Author: Tom Tromey <tromey@redhat.com>
Date:   Thu May 8 11:26:44 2014 -0600
    handle VLA in a struct or union

Bugreport:
Regression with gdb scripts for Linux kernel
https://sourceware.org/ml/gdb/2014-08/msg00127.html

That big change after "else" is just reindentation.

gdb/ChangeLog
2014-12-13  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR symtab/17642
	* gdbtypes.c (resolve_dynamic_type_internal): Apply check_typedef to
	TYPE if not TYPE_CODE_TYPEDEF.

gdb/testsuite/ChangeLog
2014-12-13  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR symtab/17642
	* gdb.base/vla-stub-define.c: New file.
	* gdb.base/vla-stub.c: New file.
	* gdb.base/vla-stub.exp: New file.
2014-12-13 15:31:59 +01:00
Joel Brobecker 14aba1ac0d Lift DWARF unwinder restriction in dwarf2-frame.c::dwarf2_frame_cfa
GDB is currently broken on all SPARC targets when using GCC 4.9.
When trying to print any local variable:

    (gdb) p x
    can't compute CFA for this frame

This is related to the fact that the compiler now generates DWARF 4
debugging info by default, and in particular that it now emits
DW_OP_call_frame_cfa, which triggers a limitation in dwarf2_frame_cfa:

   /* This restriction could be lifted if other unwinders are known to
      compute the frame base in a way compatible with the DWARF
      unwinder.  */
   if (!frame_unwinder_is (this_frame, &dwarf2_frame_unwind)
       && !frame_unwinder_is (this_frame, &dwarf2_tailcall_frame_unwind))
     error (_("can't compute CFA for this frame"));

We couldn't append the dwarf2 unwinder to all SPARC targets because
it does not work properly with StackGhost:
    https://www.sourceware.org/ml/gdb-patches/2014-07/msg00012.html

We also later discovered that using the DWARF2 unwinder means
using it for computing the function's return address, which
is buggy when it comes to functions returning a struct (where
the return address is saved-pc+12 instead of saved-pc+8).
This is because GCC is emitting the info about the return address
as %o7/%i7 instead of the actual return address.  For functions
that have debugging info, we compensate by looking at the function's
return type and add the extra +4, but for function without debug
info, we're stuck.

EricB and I twisted the issue in all the directions we could think of,
and unfortunately couldn't find a way to make it work without
introduction one regression or another.

But, stepping back a little, just removing the restriction seems to work
well for us on all both sparc-elf and {sparc,sparc64}-solaris.
After reviewing the previous discussions about this test, I could
not figure out whether some unwinders were already known to have
incompatible CFAs or if the concern was purely theoretical:
    https://www.sourceware.org/ml/gdb-patches/2009-06/msg00191.html
    https://www.sourceware.org/ml/gdb-patches/2009-07/msg00570.html
    https://www.sourceware.org/ml/gdb-patches/2009-09/msg00027.html

At the moment, we took the approach of trying it out, and see what
happens...

gdb/ChangeLog:

        PR backtrace/16215:
        * dwarf2-frame.c (dwarf2_frame_cfa): Remove the restriction
        the frame unwinder must either be the dwarf2_frame_unwind
        or the dwarf2_tailcall_frame_unwind.  Verify that this_frame's
        stack_addr is valid before calling get_frame_base.  Throw
        an error if not valid.

Tested on sparc-solaris and sparc-elf with AdaCore's testsuite
(the FSF testsuite crashes all of AdaCore's solaris machines).
2014-12-13 08:26:31 -05:00
Doug Evans ae6a105d22 value_maybe_namespace_elt: Remove unnecessary test of result != NULL.
Both allocate_value and value_of_variable are guaranteed to return non-NULL.

gdb/ChangeLog:

	* valops.c (value_maybe_namespace_elt): Remove unnecessary test of
	result != NULL.
2014-12-12 23:25:46 -08:00
Doug Evans 59da4d04cb Rename cp_is_anonymous to cp_is_in_anonymous.
gdb/ChangeLog:

	* cp-support.h (cp_is_in_anonymous): Renamed from cp_is_anonymous.
	All callers updated.  Rename arg "namespace" to "symbol_name".
2014-12-12 22:33:26 -08:00
Doug Evans 838275403d Give quick_symbol_functions "methods" a consistent naming scheme.
Add missing function comments.

gdb/ChangeLog:

	* psymtab.c (psym_map_symtabs_matching_filename): Renamed from
	partial_map_symtabs_matching_filename.  All uses updated.
	(psym_find_pc_sect_compunit_symtab): Renamed from
	find_pc_sect_compunit_symtab_from_partial.  All uses updated.
	Add function comment.
	(psym_lookup_symbol): Renamed from lookup_symbol_aux_psymtabs.
	All uses updated.  Add function comment.
	(psym_relocate): Renamed from relocate_psymtabs.  All uses updated.
	Add function comment.
	(psym_find_last_source_symtab): Renamed from
	find_last_source_symtab_from_partial.  All uses updated.
	Add function comment.
	(psym_forget_cached_source_info): Renamed from
	forget_cached_source_info_partial.  All uses updated.
	Add function comment.
	(psym_print_stats): Renamed from print_psymtab_stats_for_objfile.
	All uses updated.  Add function comment.
	(psym_dump): Renamed from dump_psymtabs_for_objfile.  All uses
	updated.  Add function comment.
	(psym_expand_symtabs_for_function): Renamed from
	read_symtabs_for_function.  All uses updated.  Update function comment.
	(psym_expand_all_symtabs): Renamed from expand_partial_symbol_tables.
	All uses updated.  Add function comment.
	(psym_expand_symtabs_with_fullname): Renamed from
	read_psymtabs_with_fullname.  All uses updated.  Add function comment.
	(psym_map_symbol_filenames): Renamed from map_symbol_filenames_psymtab.
	All uses updated.  Add function comment.
	(psym_map_matching_symbols): Renamed from map_matching_symbols_psymtab.
	All uses updated.
	(psym_expand_symtabs_matching): Renamed from
	expand_symtabs_matching_via_partial.  All uses updated.
	Add function comment.
	(psym_has_symbols): Renamed from objfile_has_psyms.  All uses updated.
	Add function comment.
2014-12-12 22:27:23 -08:00
Tom Tromey bb2ec1b34e the "compile" command
This final patch adds the new "compile" command and subcommands, and
all the machinery needed to make it work.

A shared library supplied by gcc is used for all communications with
gcc.  Types and most aspects of symbols are provided directly by gdb
to the compiler using this library.

gdb provides some information about the user's code using plain text.
Macros are emitted this way, and DWARF location expressions (and
bounds for VLA) are compiled to C code.

This hybrid approach was taken because, on the one hand, it is better
to provide global declarations and such on demand; but on the other
hand, for local variables, translating DWARF location expressions to C
was much simpler than exporting a full compiler API to gdb -- the same
result, only easier to implement, understand, and debug.

In the ordinary mode, the user's expression is wrapped in a dummy
function.  After compilation, gdb inserts the resulting object code
into the inferior, then calls this function.

Access to local variables is provided by noting which registers are
used by location expressions, and passing a structure of register
values into the function.  Writes to registers are supported by
copying out these values after the function returns.

This approach was taken so that we could eventually implement other
more interesting features based on this same infrastructure; for
example, we're planning to investigate inferior-side breakpoint
conditions.

gdb/ChangeLog
2014-12-12  Phil Muldoon  <pmuldoon@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Tom Tromey  <tromey@redhat.com>

	* NEWS: Update.
	* symtab.h (struct symbol_computed_ops) <generate_c_location>: New
	field.
	* p-lang.c (pascal_language_defn): Update.
	* opencl-lang.c (opencl_language_defn): Update.
	* objc-lang.c (objc_language_defn): Update.
	* m2-lang.c (m2_language_defn): Update.
	* language.h (struct language_defn) <la_get_compile_instance,
	la_compute_program>: New fields.
	* language.c (unknown_language_defn, auto_language_defn)
	(local_language_defn): Update.
	* jv-lang.c (java_language_defn): Update.
	* go-lang.c (go_language_defn): Update.
	* f-lang.c (f_language_defn): Update.
	* dwarf2loc.h (dwarf2_compile_property_to_c): Declare.
	* dwarf2loc.c (dwarf2_compile_property_to_c)
	(locexpr_generate_c_location, loclist_generate_c_location): New
	functions.
	(dwarf2_locexpr_funcs, dwarf2_loclist_funcs): Update.
	* defs.h (enum compile_i_scope_types): New.
	(enum command_control_type) <compile_control>: New constant.
	(struct command_line) <control_u>: New field.
	* d-lang.c (d_language_defn): Update.
	* compile/compile.c: New file.
	* compile/compile-c-support.c: New file.
	* compile/compile-c-symbols.c: New file.
	* compile/compile-c-types.c: New file.
	* compile/compile.h: New file.
	* compile/compile-internal.h: New file.
	* compile/compile-loc2c.c: New file.
	* compile/compile-object-load.c: New file.
	* compile/compile-object-load.h: New file.
	* compile/compile-object-run.c: New file.
	* compile/compile-object-run.h: New file.
	* cli/cli-script.c (multi_line_command_p, print_command_lines)
	(execute_control_command, process_next_line)
	(recurse_read_control_structure): Handle compile_control.
	* c-lang.h (c_get_compile_context, c_compute_program): Declare.
	* c-lang.c (c_language_defn, cplus_language_defn)
	(asm_language_defn, minimal_language_defn): Update.
	* ada-lang.c (ada_language_defn): Update.
	* Makefile.in (SUBDIR_GCC_COMPILE_OBS, SUBDIR_GCC_COMPILE_SRCS):
	New variables.
	(SFILES): Add SUBDIR_GCC_COMPILE_SRCS.
	(HFILES_NO_SRCDIR): Add compile.h.
	(COMMON_OBS): Add SUBDIR_GCC_COMPILE_OBS.
	(INIT_FILES): Add SUBDIR_GCC_COMPILE_SRCS.
	(compile.o, compile-c-types.o, compile-c-symbols.o)
	(compile-object-load.o, compile-object-run.o, compile-loc2c.o)
	(compile-c-support.o): New targets.

gdb/doc/ChangeLog
2014-12-12  Phil Muldoon  <pmuldoon@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.texinfo (Altering): Update.
	(Compiling and Injecting Code): New node.

gdb/testsuite/ChangeLog
2014-12-12  Phil Muldoon  <pmuldoon@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Tom Tromey  <tromey@redhat.com>

	* configure.ac: Add gdb.compile/.
	* configure: Regenerate.
	* gdb.compile/Makefile.in: New file.
	* gdb.compile/compile-ops.exp: New file.
	* gdb.compile/compile-ops.c: New file.
	* gdb.compile/compile-tls.c: New file.
	* gdb.compile/compile-tls.exp: New file.
	* gdb.compile/compile-constvar.S: New file.
	* gdb.compile/compile-constvar.c: New file.
	* gdb.compile/compile-mod.c: New file.
	* gdb.compile/compile-nodebug.c: New file.
	* gdb.compile/compile-setjmp-mod.c: New file.
	* gdb.compile/compile-setjmp.c: New file.
	* gdb.compile/compile-setjmp.exp: New file.
	* gdb.compile/compile-shlib.c: New file.
	* gdb.compile/compile.c: New file.
	* gdb.compile/compile.exp: New file.
	* lib/gdb.exp (skip_compile_feature_tests): New proc.
2014-12-12 22:28:44 +01:00
Jan Kratochvil a2658febe2 add s390_gcc_target_options
This adds s390_gcc_target_options, an implementation of the new
"gcc_target_options" gdbarch method.  This was needed because the
default implementation of the method doesn't work properly for S390,
as this architecture needs "-m31" rather than "-m32".

gdb/ChangeLog
2014-12-12  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* s390-linux-tdep.c (s390_gcc_target_options): New function.
	(s390_gdbarch_init): Add it to gdbarch.
2014-12-12 22:28:17 +01:00
Jan Kratochvil 3bc3cebe8a add linux_infcall_mmap
This implements the new gdbarch "infcall_mmap" method for Linux.

gdb/ChangeLog
2014-12-12  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* linux-tdep.c: Include objfiles.h and infcall.h.
	(GDB_MMAP_MAP_PRIVATE, GDB_MMAP_MAP_ANONYMOUS, linux_infcall_mmap): New
	function.
	(linux_init_abi): Add linux_infcall_mmap to gdbarch.
2014-12-12 22:27:46 +01:00
Jan Kratochvil d064d1bef5 export dwarf2_reg_to_regnum_or_error
This exports a utility function, dwarf2_reg_to_regnum_or_error, that
was previously private to dwarf2loc.c.

gdb/ChangeLog
2014-12-12  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2loc.h (dwarf2_reg_to_regnum_or_error): Declare.
	* dwarf2loc.c (dwarf2_reg_to_regnum_or_error): Rename from
	translate_register.  Now public.
	(dwarf2_compile_expr_to_ax): Update.
2014-12-12 22:27:31 +01:00
Tom Tromey af945b7535 make dwarf_expr_frame_base_1 public
This exports dwarf_expr_frame_base_1 so that other code can use it.

gdb/ChangeLog
2014-12-12  Tom Tromey  <tromey@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2loc.c (dwarf_expr_frame_base_1): Remove declaration.
	(dwarf_expr_frame_base): Update caller.
	(dwarf_expr_frame_base_1): Rename to ...
	(func_get_frame_base_dwarf_block): ... this and make it public.
	(dwarf2_compile_expr_to_ax, locexpr_describe_location_piece): Update
	callers.
	* dwarf2loc.h (func_get_frame_base_dwarf_block): New declaration.
2014-12-12 22:27:12 +01:00
Tom Tromey a8fd558970 split dwarf2_fetch_cfa_info from dwarf2_compile_expr_to_ax
This removes dwarf2_compile_expr_to_ax, replacing it with a utility
function that fetches the CFA data and adding the code to actually
compile to an agent expression directly into
dwarf2_compile_expr_to_ax.  This refactoring lets a later patch reuse
the new dwarf2_fetch_cfa_info.

gdb/ChangeLog
2014-12-12  Tom Tromey  <tromey@redhat.com>

	* dwarf2loc.c (dwarf2_compile_expr_to_ax) <DW_OP_call_frame_cfa>:
	Update.
	* dwarf2-frame.c (dwarf2_fetch_cfa_info): New function, based on
	dwarf2_compile_cfa_to_ax.
	(dwarf2_compile_cfa_to_ax): Remove.
	* dwarf2-frame.h (dwarf2_fetch_cfa_info): Declare.
	(dwarf2_compile_cfa_to_ax): Remove.
2014-12-12 22:26:57 +01:00
Jan Kratochvil ed12ef62cc introduce call_function_by_hand_dummy
This provides a variant of call_function_by_hand that allows the dummy
frame destructor to be set.  This is used by the compiler code to
manage some resources when calling the gdb-generated inferior
function.

gdb/ChangeLog
2014-12-12  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* infcall.h (call_function_by_hand_dummy): Declare.
	* infcall.c (call_function_by_hand): Use
	call_function_by_hand_dummy.
	(call_function_by_hand_dummy): Rename from call_function_by_hand.
	Add arguments.  Register a destructor.
2014-12-12 22:26:41 +01:00
Tom Tromey ac04f72bb4 add gnu_triplet_regexp gdbarch method
gdb has to inform libcc1.so of the target being used, so that the
correct compiler can be invoked.  The compiler is invoked using the
GNU configury triplet prefix, e.g., "x86_64-unknown-linux-gnu-gcc".

In order for this to work we need to map the gdbarch to the GNU
configury triplet arch.  In most cases these are identical; however,
the x86 family poses some problems, as the BFD arch names are quite
different from the GNU triplet names.  So, we introduce a new gdbarch
method for this.  A regular expression is used because there are
various valid values for the arch prefix in the triplet.

This patch also updates the osabi code to associate a regular
expression with the OS ABI.  I have only added a concrete value for
Linux.  Note that the "-gnu" part is optional, at least on Fedora it
is omitted from the installed GCC executable's name.

gdb/ChangeLog
2014-12-12  Tom Tromey  <tromey@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	* osabi.h (osabi_triplet_regexp): Declare.
	* osabi.c (struct osabi_names): New.
	(gdb_osabi_names): Change type to struct osabi_names.  Update
	values.
	(gdbarch_osabi_name): Update.
	(osabi_triplet_regexp): New function.
	(osabi_from_tdesc_string, _initialize_gdb_osabi): Update.
	* i386-tdep.c (i386_gnu_triplet_regexp): New method.
	(i386_elf_init_abi, i386_go32_init_abi, i386_gdbarch_init): Call
	set_gdbarch_gnu_triplet_regexp.
	* gdbarch.sh (gnu_triplet_regexp): New method.
	* gdbarch.c, gdbarch.h: Rebuild.
	* arch-utils.h (default_gnu_triplet_regexp): Declare.
	* arch-utils.c (default_gnu_triplet_regexp): New function.
2014-12-12 22:26:11 +01:00
Jan Kratochvil f208eee0f3 add infcall_mmap and gcc_target_options gdbarch methods
The compiler needed two new gdbarch methods.

The infcall_mmap method allocates memory in the inferior.
This is used when inserting the object code.

The gcc_target_options method computes some arch-specific gcc options
to pass to the compiler.  This is used to ensure that gcc generates
object code for the correct architecture.

gdb/ChangeLog
2014-12-12  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* arch-utils.c (default_infcall_mmap)
	(default_gcc_target_options): New functions.
	* arch-utils.h (GDB_MMAP_PROT_READ, GDB_MMAP_PROT_WRITE)
	(GDB_MMAP_PROT_EXEC): Define.
	(default_infcall_mmap, default_gcc_target_options): Declare.
	* gdbarch.h: Rebuild.
	* gdbarch.c: Rebuild.
	* gdbarch.sh (infcall_mmap, gcc_target_options): New methods.
2014-12-12 22:25:37 +01:00
Jan Kratochvil 233a8fb382 add dummy frame destructor
The compiler code needed a hook into dummy frame destruction, so that
some state could be kept while the inferior call is made and then
destroyed when the inferior call finishes.

This patch adds an optional destructor to dummy frames and a new API
to access it.

gdb/ChangeLog
2014-12-12  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dummy-frame.c (struct dummy_frame) <dtor, dtor_data>: New
	fields.
	(pop_dummy_frame): Call the destructor if it exists.
	(register_dummy_frame_dtor, find_dummy_frame_dtor): New
	functions.
	* dummy-frame.h (dummy_frame_dtor_ftype): New typedef.
	(register_dummy_frame_dtor, find_dummy_frame_dtor): Declare.
2014-12-12 22:25:15 +01:00
Tom Tromey f166002710 add make_unqualified_type
There's seemingly no function to get the unqualified variant of a
type, so this patch adds one.  This new function will be used in the
final patch.

gdb/ChangeLog
2014-12-12  Tom Tromey  <tromey@redhat.com>

	* gdbtypes.h (make_unqualified_type): Declare.
	* gdbtypes.c (make_unqualified_type): New function.
2014-12-12 22:24:37 +01:00
Tom Tromey 4ff709eb44 add some missing ops to DWARF assembler
This changes the DWARF assembler to allow comments in a location
expression, and also adds support for a few new opcodes I needed.

gdb/testsuite/ChangeLog
2014-12-12  Tom Tromey  <tromey@redhat.com>

	* lib/dwarf.exp (_location): Ignore blank lines.  Allow comments.
	Handle DW_OP_pick, DW_OP_skip, DW_OP_bra.
2014-12-12 22:24:17 +01:00
Tom Tromey de571fc5fb introduce ui_file_write_for_put
This introduces a small helper function, ui_file_write_for_put.  It is
a wrapper for ui_write that is suitable for passing directly to
ui_file_put.

This patch also updates one existing spot to use this new function.

gdb/ChangeLog
2014-12-12  Tom Tromey  <tromey@redhat.com>

	* ui-file.h (ui_file_write_for_put): Declare.
	* ui-file.c (ui_file_write_for_put): New function.
	* mi/mi-out.c (do_write): Remove.
	(mi_out_put): Use ui_file_write_for_put.
2014-12-12 22:12:12 +01:00
Doug Evans 6dddd6a574 New python function gdb.lookup_objfile.
gdb/ChangeLog:

	* NEWS: Mention gdb.lookup_objfile.
	* python/python.c (GdbMethods): Add lookup_objfile.
	* python/python-internal.h (gdbpy_lookup_objfile): Declare.
	* python/py-objfile.c: #include "symtab.h".
	(objfpy_build_id_ok, objfpy_build_id_matches): New functions.
	(objfpy_lookup_objfile_by_name): New function.
	(objfpy_lookup_objfile_by_build_id): New function.
	(gdbpy_lookup_objfile): New function.

gdb/doc/ChangeLog:

	* python.texi (Objfiles In Python): Document gdb.lookup_objfile.

gdb/testsuite/ChangeLog:

	* lib/gdb-python.exp (get_python_valueof): New function.
	* gdb.python/py-objfile.exp: Add tests for gdb.lookup_objfile.
2014-12-12 09:48:13 -08:00
Maciej W. Rozycki f161c17134 MIPS: Define aliases for MSYMBOL_TARGET_FLAG macros
* mips-tdep.h (MSYMBOL_TARGET_FLAG_MIPS16): New macro.
	(MSYMBOL_TARGET_FLAG_MICROMIPS): Likewise.
	* mips-tdep.c (mips_elf_make_msymbol_special): Use the new
	macros.
	(msymbol_is_mips, msymbol_is_mips16, msymbol_is_micromips):
	Likewise.
2014-12-12 16:36:10 +00:00
Andreas Arnez 71c247087c Provide completer for "info registers"
Provide a new completion function for the argument of "info
registers", "info all-registers", and the "lr" command in dbx mode.
Without this patch the default symbol completer is used, which is more
confusing than helpful.

Also add a test for this new feature to "completion.exp": Determine
the target's available set of registers/reggroups and compare this to
the completion of "info registers ".  For determining the available
registers involve the new "maint print user-registers" command.

gdb/ChangeLog:

	* completer.c: Include "target.h", "reggroups.h", and
	"user-regs.h".
	(reg_or_group_completer): New.
	* completer.h (reg_or_group_completer): Declare.
	* infcmd.c (_initialize_infcmd): Set reg_or_group_completer for
	the "info registers" and "info all-registers" commands and the
	dbx-mode "lr" command.

gdb/testsuite/ChangeLog:

	* gdb.base/completion.exp: Add test for completion of "info
	registers ".
2014-12-12 17:11:22 +01:00
Andreas Arnez f5b95c01fb Add new GDB command "maint print user-registers"
This adds a command for listing the "user" registers.  So far GDB
offered no means of determining the set of user registers and omitted
them from all other register listings.

gdb/ChangeLog:

	* user-regs.c: Include "arch-utils.h", "command.h", and
	"cli/cli-cmds.h".
	(maintenance_print_user_registers): New.
	(_initialize_user_regs): Register new "maint print user-registers"
	subcommand.
	* NEWS: Mention new GDB command "maint print user-registers".

gdb/doc/ChangeLog:

	* gdb.texinfo: Document "maint print user-registers".
2014-12-12 17:11:22 +01:00
Maciej W. Rozycki 3e29f34a4e MIPS: Keep the ISA bit in compressed code addresses
1. Background information

The MIPS architecture, as originally designed and implemented in
mid-1980s has a uniform instruction word size that is 4 bytes, naturally
aligned.  As such all MIPS instructions are located at addresses that
have their bits #1 and #0 set to zeroes, and any attempt to execute an
instruction from an address that has any of the two bits set to one
causes an address error exception.  This may for example happen when a
jump-register instruction is executed whose register value used as the
jump target has any of these bits set.

Then in mid 1990s LSI sought a way to improve code density for their
TinyRISC family of MIPS cores and invented an alternatively encoded
instruction set in a joint effort with MIPS Technologies (then a
subsidiary of SGI).  The new instruction set has been named the MIPS16
ASE (Application-Specific Extension) and uses a variable instruction
word size, which is 2 bytes (as the name of the ASE suggests) for most,
but there are a couple of exceptions that take 4 bytes, and then most of
the 2-byte instructions can be treated with a 2-byte extension prefix to
expand the range of the immediate operands used.

As a result instructions are no longer 4-byte aligned, instead they are
aligned to a multiple of 2.  That left the bit #0 still unused for code
references, be it for the standard MIPS (i.e. as originally invented) or
for the MIPS16 instruction set, and based on that observation a clever
trick was invented that on one hand allowed the processor to be
seamlessly switched between the two instruction sets at any time at the
run time while on the other avoided the introduction of any special
control register to do that.

So it is the bit #0 of the instruction address that was chosen as the
selector and named the ISA bit.  Any instruction executed at an even
address is interpreted as a standard MIPS instruction (the address still
has to have its bit #1 clear), any instruction executed at an odd
address is interpreted as a MIPS16 instruction.

To switch between modes ordinary jump instructions are used, such as
used for function calls and returns, specifically the bit #0 of the
source register used in jump-register instructions selects the execution
(ISA) mode for the following piece of code to be interpreted in.
Additionally new jump-immediate instructions were added that flipped the
ISA bit to select the opposite mode upon execution.  They were
considered necessary to avoid the need to make register jumps in all
cases as the original jump-immediate instructions provided no way to
change the bit #0 at all.

This was all important for cases where standard MIPS and MIPS16 code had
to be mixed, either for compatibility with the existing binary code base
or to access resources not reachable from MIPS16 code (the MIPS16
instruction set only provides access to general-purpose registers, and
not for example floating-point unit registers or privileged coprocessor
0 registers) -- pieces of code in the opposite mode can be executed as
ordinary subroutine calls.

A similar approach has been more recently adopted for the MIPS16
replacement instruction set defined as the so called microMIPS ASE.
This is another instruction set encoding introduced to the MIPS
architecture.  Just like the MIPS16 ASE, the microMIPS instruction set
uses a variable-length encoding, where each instruction takes a multiple
of 2 bytes.  The ISA bit has been reused and for microMIPS-capable
processors selects between the standard MIPS and the microMIPS mode
instead.

2. Statement of the problem

To put it shortly, MIPS16 and microMIPS code pointers used by GDB are
different to these observed at the run time.  This results in the same
expressions being evaluated producing different results in GDB and in
the program being debugged.  Obviously it's the results obtained at the
run time that are correct (they define how the program behaves) and
therefore by definition the results obtained in GDB are incorrect.

A bit longer description will record that obviously at the run time the
ISA bit has to be set correctly (refer to background information above
if unsure why so) or the program will not run as expected.  This is
recorded in all the executable file structures used at the run time: the
dynamic symbol table (but not always the static one!), the GOT, and
obviously in all the addresses embedded in code or data of the program
itself, calculated by applying the appropriate relocations at the static
link time.

While a program is being processed by GDB, the ISA bit is stripped off
from any code addresses, presumably to make them the same as the
respective raw memory byte address used by the processor to access the
instruction in the instruction fetch access cycle.  This stripping is
actually performed outside GDB proper, in BFD, specifically
_bfd_mips_elf_symbol_processing (elfxx-mips.c, see the piece of code at
the very bottom of that function, starting with an: "If this is an
odd-valued function symbol, assume it's a MIPS16 or microMIPS one."
comment).

This function is also responsible for symbol table dumps made by
`objdump' too, so you'll never see the ISA bit reported there by that
tool, you need to use `readelf'.

This is however unlike what is ever done at the run time, the ISA bit
once present is never stripped off, for example a cast like this:

(short *) main

will not strip the ISA bit off and if the resulting pointer is intended
to be used to access instructions as data, for example for software
instruction decoding (like for fault recovery or emulation in a signal
handler) or for self-modifying code then the bit still has to be
stripped off by an explicit AND operation.

This is probably best illustrated with a simple real program example.
Let's consider the following simple program:

$ cat foobar.c
int __attribute__ ((mips16)) foo (void)
{
  return 1;
}

int __attribute__ ((mips16)) bar (void)
{
  return 2;
}

int __attribute__ ((nomips16)) foo32 (void)
{
  return 3;
}

int (*foo32p) (void) = foo32;
int (*foop) (void) = foo;
int fooi = (int) foo;

int
main (void)
{
  return foop ();
}
$

This is plain C with no odd tricks, except from the instruction mode
attributes.  They are not necessary to trigger this problem, I just put
them here so that the program can be contained in a single source file
and to make it obvious which function is MIPS16 code and which is not.

Let's try it with Linux, so that everyone can repeat this experiment:

$ mips-linux-gnu-gcc -mips16 -g -O2 -o foobar foobar.c
$

Let's have a look at some interesting symbols:

$ mips-linux-gnu-readelf -s foobar | egrep 'table|foo|bar'
Symbol table '.dynsym' contains 7 entries:
Symbol table '.symtab' contains 95 entries:
    55: 00000000     0 FILE    LOCAL  DEFAULT  ABS foobar.c
    66: 0040068c     4 FUNC    GLOBAL DEFAULT [MIPS16]    12 bar
    68: 00410848     4 OBJECT  GLOBAL DEFAULT   21 foo32p
    70: 00410844     4 OBJECT  GLOBAL DEFAULT   21 foop
    78: 00400684     8 FUNC    GLOBAL DEFAULT   12 foo32
    80: 00400680     4 FUNC    GLOBAL DEFAULT [MIPS16]    12 foo
    88: 00410840     4 OBJECT  GLOBAL DEFAULT   21 fooi
$

Hmm, no sight of the ISA bit, but notice how foo and bar (but not
foo32!) have been marked as MIPS16 functions (ELF symbol structure's
`st_other' field is used for that).

So let's try to run and poke at this program with GDB.  I'll be using a
native system for simplicity (I'll be using ellipses here and there to
remove unrelated clutter):

$ ./foobar
$ echo $?
1
$

So far, so good.

$ gdb ./foobar
[...]
(gdb) break main
Breakpoint 1 at 0x400490: file foobar.c, line 23.
(gdb) run
Starting program: .../foobar

Breakpoint 1, main () at foobar.c:23
23        return foop ();
(gdb)

Yay, it worked!  OK, so let's poke at it:

(gdb) print main
$1 = {int (void)} 0x400490 <main>
(gdb) print foo32
$2 = {int (void)} 0x400684 <foo32>
(gdb) print foo32p
$3 = (int (*)(void)) 0x400684 <foo32>
(gdb) print bar
$4 = {int (void)} 0x40068c <bar>
(gdb) print foo
$5 = {int (void)} 0x400680 <foo>
(gdb) print foop
$6 = (int (*)(void)) 0x400681 <foo>
(gdb)

A-ha!  Here's the difference and finally the ISA bit!

(gdb) print /x fooi
$7 = 0x400681
(gdb) p/x $pc
p/x $pc
$8 = 0x400491
(gdb)

And here as well...

(gdb) advance foo
foo () at foobar.c:4
4       }
(gdb) disassemble
Dump of assembler code for function foo:
   0x00400680 <+0>:     jr      ra
   0x00400682 <+2>:     li      v0,1
End of assembler dump.
(gdb) finish
Run till exit from #0  foo () at foobar.c:4
main () at foobar.c:24
24      }
Value returned is $9 = 1
(gdb) continue
Continuing.
[Inferior 1 (process 14103) exited with code 01]
(gdb)

So let's be a bit inquisitive...

(gdb) run
Starting program: .../foobar

Breakpoint 1, main () at foobar.c:23
23        return foop ();
(gdb)

Actually we do not like to run foo here at all.  Let's run bar instead!

(gdb) set foop = bar
(gdb) print foop
$10 = (int (*)(void)) 0x40068c <bar>
(gdb)

Hmm, no ISA bit.  Is it going to work?

(gdb) advance bar
bar () at foobar.c:9
9       }
(gdb) p/x $pc
$11 = 0x40068c
(gdb) disassemble
Dump of assembler code for function bar:
=> 0x0040068c <+0>:     jr      ra
   0x0040068e <+2>:     li      v0,2
End of assembler dump.
(gdb) finish
Run till exit from #0  bar () at foobar.c:9

Program received signal SIGILL, Illegal instruction.
bar () at foobar.c:9
9       }
(gdb)

Oops!

(gdb) p/x $pc
$12 = 0x40068c
(gdb)

We're still there!

(gdb) continue
Continuing.

Program terminated with signal SIGILL, Illegal instruction.
The program no longer exists.
(gdb)

So let's try something else:

(gdb) run
Starting program: .../foobar

Breakpoint 1, main () at foobar.c:23
23        return foop ();
(gdb) set foop = foo
(gdb) advance foo
foo () at foobar.c:4
4       }
(gdb) disassemble
Dump of assembler code for function foo:
=> 0x00400680 <+0>:     jr      ra
   0x00400682 <+2>:     li      v0,1
End of assembler dump.
(gdb) finish
Run till exit from #0  foo () at foobar.c:4

Program received signal SIGILL, Illegal instruction.
foo () at foobar.c:4
4       }
(gdb) continue
Continuing.

Program terminated with signal SIGILL, Illegal instruction.
The program no longer exists.
(gdb)

The same problem!

(gdb) run
Starting program:
/net/build2-lucid-cs/scratch/macro/mips-linux-fsf-gcc/isa-bit/foobar

Breakpoint 1, main () at foobar.c:23
23        return foop ();
(gdb) set foop = foo32
(gdb) advance foo32
foo32 () at foobar.c:14
14      }
(gdb) disassemble
Dump of assembler code for function foo32:
=> 0x00400684 <+0>:     jr      ra
   0x00400688 <+4>:     li      v0,3
End of assembler dump.
(gdb) finish
Run till exit from #0  foo32 () at foobar.c:14
main () at foobar.c:24
24      }
Value returned is $14 = 3
(gdb) continue
Continuing.
[Inferior 1 (process 14113) exited with code 03]
(gdb)

That did work though, so it's the ISA bit only!

(gdb) quit

Enough!

That's the tip of the iceberg only though.  So let's rebuild the
executable with some dynamic symbols:

$ mips-linux-gnu-gcc -mips16 -Wl,--export-dynamic -g -O2 -o foobar-dyn foobar.c
$ mips-linux-gnu-readelf -s foobar-dyn | egrep 'table|foo|bar'
Symbol table '.dynsym' contains 32 entries:
     6: 004009cd     4 FUNC    GLOBAL DEFAULT   12 bar
     8: 00410b88     4 OBJECT  GLOBAL DEFAULT   21 foo32p
     9: 00410b84     4 OBJECT  GLOBAL DEFAULT   21 foop
    15: 004009c4     8 FUNC    GLOBAL DEFAULT   12 foo32
    17: 004009c1     4 FUNC    GLOBAL DEFAULT   12 foo
    25: 00410b80     4 OBJECT  GLOBAL DEFAULT   21 fooi
Symbol table '.symtab' contains 95 entries:
    55: 00000000     0 FILE    LOCAL  DEFAULT  ABS foobar.c
    69: 004009cd     4 FUNC    GLOBAL DEFAULT   12 bar
    71: 00410b88     4 OBJECT  GLOBAL DEFAULT   21 foo32p
    72: 00410b84     4 OBJECT  GLOBAL DEFAULT   21 foop
    79: 004009c4     8 FUNC    GLOBAL DEFAULT   12 foo32
    81: 004009c1     4 FUNC    GLOBAL DEFAULT   12 foo
    89: 00410b80     4 OBJECT  GLOBAL DEFAULT   21 fooi
$

OK, now the ISA bit is there for a change, but the MIPS16 `st_other'
attribute gone, hmm...  What does `objdump' do then:

$ mips-linux-gnu-objdump -Tt foobar-dyn | egrep 'SYMBOL|foo|bar'
foobar-dyn:     file format elf32-tradbigmips
SYMBOL TABLE:
00000000 l    df *ABS*  00000000              foobar.c
004009cc g     F .text  00000004              0xf0 bar
00410b88 g     O .data  00000004              foo32p
00410b84 g     O .data  00000004              foop
004009c4 g     F .text  00000008              foo32
004009c0 g     F .text  00000004              0xf0 foo
00410b80 g     O .data  00000004              fooi
DYNAMIC SYMBOL TABLE:
004009cc g    DF .text  00000004  Base        0xf0 bar
00410b88 g    DO .data  00000004  Base        foo32p
00410b84 g    DO .data  00000004  Base        foop
004009c4 g    DF .text  00000008  Base        foo32
004009c0 g    DF .text  00000004  Base        0xf0 foo
00410b80 g    DO .data  00000004  Base        fooi
$

Hmm, the attribute (0xf0, printed raw) is back, and the ISA bit gone
again.

Let's have a look at some DWARF-2 records GDB uses (I'll be stripping
off a lot here for brevity) -- debug info:

$ mips-linux-gnu-readelf -wi foobar
Contents of the .debug_info section:
[...]
  Compilation Unit @ offset 0x88:
   Length:        0xbb (32-bit)
   Version:       4
   Abbrev Offset: 62
   Pointer Size:  4
 <0><93>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <94>   DW_AT_producer    : (indirect string, offset: 0x19e): GNU C 4.8.0 20120513 (experimental) -meb -mips16 -march=mips32r2 -mhard-float -mllsc -mplt -mno-synci -mno-shared -mabi=32 -g -O2
    <98>   DW_AT_language    : 1        (ANSI C)
    <99>   DW_AT_name        : (indirect string, offset: 0x190): foobar.c
    <9d>   DW_AT_comp_dir    : (indirect string, offset: 0x225): [...]
    <a1>   DW_AT_ranges      : 0x0
    <a5>   DW_AT_low_pc      : 0x0
    <a9>   DW_AT_stmt_list   : 0x27
 <1><ad>: Abbrev Number: 2 (DW_TAG_subprogram)
    <ae>   DW_AT_external    : 1
    <ae>   DW_AT_name        : foo
    <b2>   DW_AT_decl_file   : 1
    <b3>   DW_AT_decl_line   : 1
    <b4>   DW_AT_prototyped  : 1
    <b4>   DW_AT_type        : <0xc2>
    <b8>   DW_AT_low_pc      : 0x400680
    <bc>   DW_AT_high_pc     : 0x400684
    <c0>   DW_AT_frame_base  : 1 byte block: 9c         (DW_OP_call_frame_cfa)
    <c2>   DW_AT_GNU_all_call_sites: 1
 <1><c2>: Abbrev Number: 3 (DW_TAG_base_type)
    <c3>   DW_AT_byte_size   : 4
    <c4>   DW_AT_encoding    : 5        (signed)
    <c5>   DW_AT_name        : int
 <1><c9>: Abbrev Number: 4 (DW_TAG_subprogram)
    <ca>   DW_AT_external    : 1
    <ca>   DW_AT_name        : (indirect string, offset: 0x18a): foo32
    <ce>   DW_AT_decl_file   : 1
    <cf>   DW_AT_decl_line   : 11
    <d0>   DW_AT_prototyped  : 1
    <d0>   DW_AT_type        : <0xc2>
    <d4>   DW_AT_low_pc      : 0x400684
    <d8>   DW_AT_high_pc     : 0x40068c
    <dc>   DW_AT_frame_base  : 1 byte block: 9c         (DW_OP_call_frame_cfa)
    <de>   DW_AT_GNU_all_call_sites: 1
 <1><de>: Abbrev Number: 2 (DW_TAG_subprogram)
    <df>   DW_AT_external    : 1
    <df>   DW_AT_name        : bar
    <e3>   DW_AT_decl_file   : 1
    <e4>   DW_AT_decl_line   : 6
    <e5>   DW_AT_prototyped  : 1
    <e5>   DW_AT_type        : <0xc2>
    <e9>   DW_AT_low_pc      : 0x40068c
    <ed>   DW_AT_high_pc     : 0x400690
    <f1>   DW_AT_frame_base  : 1 byte block: 9c         (DW_OP_call_frame_cfa)
    <f3>   DW_AT_GNU_all_call_sites: 1
 <1><f3>: Abbrev Number: 5 (DW_TAG_subprogram)
    <f4>   DW_AT_external    : 1
    <f4>   DW_AT_name        : (indirect string, offset: 0x199): main
    <f8>   DW_AT_decl_file   : 1
    <f9>   DW_AT_decl_line   : 21
    <fa>   DW_AT_prototyped  : 1
    <fa>   DW_AT_type        : <0xc2>
    <fe>   DW_AT_low_pc      : 0x400490
    <102>   DW_AT_high_pc     : 0x4004a4
    <106>   DW_AT_frame_base  : 1 byte block: 9c        (DW_OP_call_frame_cfa)
    <108>   DW_AT_GNU_all_tail_call_sites: 1
[...]
$

-- no sign of the ISA bit anywhere -- frame info:

$ mips-linux-gnu-readelf -wf foobar
[...]
Contents of the .debug_frame section:

00000000 0000000c ffffffff CIE
  Version:               1
  Augmentation:          ""
  Code alignment factor: 1
  Data alignment factor: -4
  Return address column: 31

  DW_CFA_def_cfa_register: r29
  DW_CFA_nop

00000010 0000000c 00000000 FDE cie=00000000 pc=00400680..00400684

00000020 0000000c 00000000 FDE cie=00000000 pc=00400684..0040068c

00000030 0000000c 00000000 FDE cie=00000000 pc=0040068c..00400690

00000040 00000018 00000000 FDE cie=00000000 pc=00400490..004004a4
  DW_CFA_advance_loc: 6 to 00400496
  DW_CFA_def_cfa_offset: 32
  DW_CFA_offset: r31 at cfa-4
  DW_CFA_advance_loc: 6 to 0040049c
  DW_CFA_restore: r31
  DW_CFA_def_cfa_offset: 0
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop
[...]
$

-- no sign of the ISA bit anywhere -- range info (GDB doesn't use arange):

$ mips-linux-gnu-readelf -wR foobar
Contents of the .debug_ranges section:

    Offset   Begin    End
    00000000 00400680 00400690
    00000000 00400490 004004a4
    00000000 <End of list>

$

-- no sign of the ISA bit anywhere -- line info:

$ mips-linux-gnu-readelf -wl foobar
Raw dump of debug contents of section .debug_line:
[...]
  Offset:                      0x27
  Length:                      78
  DWARF Version:               2
  Prologue Length:             31
  Minimum Instruction Length:  1
  Initial value of 'is_stmt':  1
  Line Base:                   -5
  Line Range:                  14
  Opcode Base:                 13

 Opcodes:
  Opcode 1 has 0 args
  Opcode 2 has 1 args
  Opcode 3 has 1 args
  Opcode 4 has 1 args
  Opcode 5 has 1 args
  Opcode 6 has 0 args
  Opcode 7 has 0 args
  Opcode 8 has 0 args
  Opcode 9 has 1 args
  Opcode 10 has 0 args
  Opcode 11 has 0 args
  Opcode 12 has 1 args

 The Directory Table is empty.

 The File Name Table:
  Entry Dir     Time    Size    Name
  1     0       0       0       foobar.c

 Line Number Statements:
  Extended opcode 2: set Address to 0x400681
  Special opcode 6: advance Address by 0 to 0x400681 and Line by 1 to 2
  Special opcode 7: advance Address by 0 to 0x400681 and Line by 2 to 4
  Special opcode 55: advance Address by 3 to 0x400684 and Line by 8 to 12
  Special opcode 7: advance Address by 0 to 0x400684 and Line by 2 to 14
  Advance Line by -7 to 7
  Special opcode 131: advance Address by 9 to 0x40068d and Line by 0 to 7
  Special opcode 7: advance Address by 0 to 0x40068d and Line by 2 to 9
  Advance PC by 3 to 0x400690
  Extended opcode 1: End of Sequence

  Extended opcode 2: set Address to 0x400491
  Advance Line by 21 to 22
  Copy
  Special opcode 6: advance Address by 0 to 0x400491 and Line by 1 to 23
  Special opcode 60: advance Address by 4 to 0x400495 and Line by -1 to 22
  Special opcode 34: advance Address by 2 to 0x400497 and Line by 1 to 23
  Special opcode 62: advance Address by 4 to 0x40049b and Line by 1 to 24
  Special opcode 32: advance Address by 2 to 0x40049d and Line by -1 to 23
  Special opcode 6: advance Address by 0 to 0x40049d and Line by 1 to 24
  Advance PC by 7 to 0x4004a4
  Extended opcode 1: End of Sequence
[...]

-- a-ha, the ISA bit is there!  However it's not always right for some
reason, I don't have a small test case to show it, but here's an excerpt
from MIPS16 libc, a prologue of a function:

00019630 <__libc_init_first>:
   19630:       e8a0            jrc     ra
   19632:       6500            nop

00019634 <_init>:
   19634:       f000 6a11       li      v0,17
   19638:       f7d8 0b08       la      v1,15e00 <_DYNAMIC+0x15c54>
   1963c:       f400 3240       sll     v0,16
   19640:       e269            addu    v0,v1
   19642:       659a            move    gp,v0
   19644:       64f6            save    48,ra,s0-s1
   19646:       671c            move    s0,gp
   19648:       d204            sw      v0,16(sp)
   1964a:       f352 984c       lw      v0,-27828(s0)
   1964e:       6724            move    s1,a0

and the corresponding DWARF-2 line info:

 Line Number Statements:
  Extended opcode 2: set Address to 0x19631
  Advance Line by 44 to 45
  Copy
  Special opcode 8: advance Address by 0 to 0x19631 and Line by 3 to 48
  Special opcode 66: advance Address by 4 to 0x19635 and Line by 5 to 53
  Advance PC by constant 17 to 0x19646
  Special opcode 25: advance Address by 1 to 0x19647 and Line by 6 to 59
  Advance Line by -6 to 53
  Special opcode 33: advance Address by 2 to 0x19649 and Line by 0 to 53
  Special opcode 39: advance Address by 2 to 0x1964b and Line by 6 to 59
  Advance Line by -6 to 53
  Special opcode 61: advance Address by 4 to 0x1964f and Line by 0 to 53

-- see that "Advance PC by constant 17" there?  It clears the ISA bit,
however code at 0x19646 is not standard MIPS code at all.  For some
reason the constant is always 17, I've never seen DW_LNS_const_add_pc
used with any other value -- is that a binutils bug or what?

3. Solution:

I think we should retain the value of the ISA bit in code references,
that is effectively treat them as cookies as they indeed are (although
trivially calculated) rather than raw memory byte addresses.

In a perfect world both the static symbol table and the respective
DWARF-2 records should be fixed to include the ISA bit in all the cases.
I think however that this is infeasible.

All the uses of `_bfd_mips_elf_symbol_processing' can not necessarily be
tracked down.  This function is used by `elf_slurp_symbol_table' that in
turn is used by `bfd_canonicalize_symtab' and
`bfd_canonicalize_dynamic_symtab', which are public interfaces.

Similarly DWARF-2 records are used outside GDB, one notable if a bit
questionable is the exception unwinder (libgcc/unwind-dw2.c) -- I have
identified at least bits in `execute_cfa_program' and
`uw_frame_state_for', both around the calls to `_Unwind_IsSignalFrame',
that would need an update as they effectively flip the ISA bit freely;
see also the comment about MASK_RETURN_ADDR in gcc/config/mips/mips.h.
But there may be more places.  Any change in how DWARF-2 records are
produced would require an update there and would cause compatibility
problems with libgcc.a binaries already distributed; given that this is
a static library a complex change involving function renames would
likely be required.

I propose therefore to accept the existing inconsistencies and deal with
them entirely within GDB.  I have figured out that the ISA bit lost in
various places can still be recovered as long as we have symbol
information -- that'll have the `st_other' attribute correctly set to
one of standard MIPS/MIPS16/microMIPS encoding.

Here's the resulting change.  It adds a couple of new `gdbarch' hooks,
one to update symbol information with the ISA bit lost in
`_bfd_mips_elf_symbol_processing', and two other ones to adjust DWARF-2
records as they're processed.  The ISA bit is set in each address
handled according to information retrieved from the symbol table for the
symbol spanning the address if any; limits are adjusted based on the
address they point to related to the respective base address.
Additionally minimal symbol information has to be adjusted accordingly
in its gdbarch hook.

With these changes in place some complications with ISA bit juggling in
the PC that never fully worked can be removed from the MIPS backend.
Conversely, the generic dynamic linker event special breakpoint symbol
handler has to be updated to call the minimal symbol gdbarch hook to
record that the symbol is a MIPS16 or microMIPS address if applicable or
the breakpoint will be set at the wrong address and either fail to work
or cause SIGTRAPs (this is because the symbol is handled early on and
bypasses regular symbol processing).

4. Results obtained

The change fixes the example above -- to repeat only the crucial steps:

(gdb) break main
Breakpoint 1 at 0x400491: file foobar.c, line 23.
(gdb) run
Starting program: .../foobar

Breakpoint 1, main () at foobar.c:23
23        return foop ();
(gdb) print foo
$1 = {int (void)} 0x400681 <foo>
(gdb) set foop = bar
(gdb) advance bar
bar () at foobar.c:9
9       }
(gdb) disassemble
Dump of assembler code for function bar:
=> 0x0040068d <+0>:     jr      ra
   0x0040068f <+2>:     li      v0,2
End of assembler dump.
(gdb) finish
Run till exit from #0  bar () at foobar.c:9
main () at foobar.c:24
24      }
Value returned is $2 = 2
(gdb) continue
Continuing.
[Inferior 1 (process 14128) exited with code 02]
(gdb)

-- excellent!

The change removes about 90 failures per MIPS16 multilib in mips-sde-elf
testing too, results for MIPS16 are now similar to that for standard
MIPS; microMIPS results are a bit worse because of host-I/O problems in
QEMU used instead of MIPSsim for microMIPS testing only:

                === gdb Summary ===

# of expected passes            14299
# of unexpected failures        187
# of expected failures          56
# of known failures             58
# of unresolved testcases       11
# of untested testcases         52
# of unsupported tests          174

MIPS16:

                === gdb Summary ===

# of expected passes            14298
# of unexpected failures        187
# of unexpected successes       2
# of expected failures          54
# of known failures             58
# of unresolved testcases       12
# of untested testcases         52
# of unsupported tests          174

microMIPS:

                === gdb Summary ===

# of expected passes            14149
# of unexpected failures        201
# of unexpected successes       2
# of expected failures          54
# of known failures             58
# of unresolved testcases       7
# of untested testcases         53
# of unsupported tests          175

2014-12-12  Maciej W. Rozycki  <macro@codesourcery.com>
            Maciej W. Rozycki  <macro@mips.com>
            Pedro Alves  <pedro@codesourcery.com>

	gdb/
	* gdbarch.sh (elf_make_msymbol_special): Change type to `F',
	remove `predefault' and `invalid_p' initializers.
	(make_symbol_special): New architecture method.
	(adjust_dwarf2_addr, adjust_dwarf2_line): Likewise.
	(objfile, symbol): New declarations.
	* arch-utils.h (default_elf_make_msymbol_special): Remove
	prototype.
	(default_make_symbol_special): New prototype.
	(default_adjust_dwarf2_addr): Likewise.
	(default_adjust_dwarf2_line): Likewise.
	* mips-tdep.h (mips_unmake_compact_addr): New prototype.
	* arch-utils.c (default_elf_make_msymbol_special): Remove
	function.
	(default_make_symbol_special): New function.
	(default_adjust_dwarf2_addr): Likewise.
	(default_adjust_dwarf2_line): Likewise.
	* dwarf2-frame.c (decode_frame_entry_1): Call
	`gdbarch_adjust_dwarf2_addr'.
	* dwarf2loc.c (dwarf2_find_location_expression): Likewise.
	* dwarf2read.c (create_addrmap_from_index): Likewise.
	(process_psymtab_comp_unit_reader): Likewise.
	(add_partial_symbol): Likewise.
	(add_partial_subprogram): Likewise.
	(process_full_comp_unit): Likewise.
	(read_file_scope): Likewise.
	(read_func_scope): Likewise.  Call `gdbarch_make_symbol_special'.
	(read_lexical_block_scope): Call `gdbarch_adjust_dwarf2_addr'.
	(read_call_site_scope): Likewise.
	(dwarf2_ranges_read): Likewise.
	(dwarf2_record_block_ranges): Likewise.
	(read_attribute_value): Likewise.
	(dwarf_decode_lines_1): Call `gdbarch_adjust_dwarf2_line'.
	(new_symbol_full): Call `gdbarch_adjust_dwarf2_addr'.
	* elfread.c (elf_symtab_read): Don't call
	`gdbarch_elf_make_msymbol_special' if unset.
	* mips-linux-tdep.c (micromips_linux_sigframe_validate): Strip
	the ISA bit from the PC.
	* mips-tdep.c (mips_unmake_compact_addr): New function.
	(mips_elf_make_msymbol_special): Set the ISA bit in the symbol's
	address appropriately.
	(mips_make_symbol_special): New function.
	(mips_pc_is_mips): Set the ISA bit before symbol lookup.
	(mips_pc_is_mips16): Likewise.
	(mips_pc_is_micromips): Likewise.
	(mips_pc_isa): Likewise.
	(mips_adjust_dwarf2_addr): New function.
	(mips_adjust_dwarf2_line): Likewise.
	(mips_read_pc, mips_unwind_pc): Keep the ISA bit.
	(mips_addr_bits_remove): Likewise.
	(mips_skip_trampoline_code): Likewise.
	(mips_write_pc): Don't set the ISA bit.
	(mips_eabi_push_dummy_call): Likewise.
	(mips_o64_push_dummy_call): Likewise.
	(mips_gdbarch_init): Install `mips_make_symbol_special',
	`mips_adjust_dwarf2_addr' and `mips_adjust_dwarf2_line' gdbarch
	handlers.
	* solib.c (gdb_bfd_lookup_symbol_from_symtab): Get
	target-specific symbol address adjustments.
	* gdbarch.h: Regenerate.
	* gdbarch.c: Regenerate.

2014-12-12  Maciej W. Rozycki  <macro@codesourcery.com>

	gdb/testsuite/
	* gdb.base/func-ptrs.c: New file.
	* gdb.base/func-ptrs.exp: New file.
2014-12-12 13:49:06 +00:00
Andreas Arnez e5a9158d09 S390: Fix gdbserver support for TDB
This makes gdbserver actually provide values for the TDB registers
when the inferior was stopped in a transaction.  The change in
linux-low.c is needed to suppress the warning for an unavailable TDB.

The test case 's390-tdbregs.exp' passes with this patch and fails
without.

gdb/gdbserver/ChangeLog:

	* linux-low.c (regsets_fetch_inferior_registers): Suppress the
	warning upon ENODATA from ptrace.
	* linux-s390-low.c (s390_store_tdb): New.
	(s390_regsets): Add regset for NT_S390_TDB.
2014-12-12 14:15:07 +01:00
Andreas Arnez feea5f36a9 gdbserver: Support read-only regsets in linux-low.c
For GNU/Linux targets using the regsets interface, this change
supports regsets that can be read but not written.  The S390 "last
break" regset is an example.  So far it had been defined with
regset->set_request == PTRACE_GETREGSET, such that the respective
ptrace call does not cause any harm.  Now we just skip the whole
read/modify/write sequence for regsets that do not define a
fill_function.

gdb/gdbserver/ChangeLog:

	* linux-low.c (regsets_store_inferior_registers): Skip regsets
	without a fill_function.
	* linux-s390-low.c (s390_fill_last_break): Remove.
	(s390_regsets): Set fill_function to NULL for NT_S390_LAST_BREAK.
	(s390_arch_setup): Use regset's size instead of fill_function for
	loop end condition.
2014-12-12 14:15:07 +01:00
Andreas Arnez 098dbe6124 gdbserver: Prevent stale/random values in register cache
When fetch_inferior_registers does not update all registers, this
patch assures that no stale register values remain in the register
cache.  On Linux platforms using the regsets interface, when one of
the ptrace calls used for fetching the register values returns an
error, this patch also avoids copying the random data returned from
ptrace into the register cache.  All unfetched registers are marked
"unavailable" instead.

gdb/gdbserver/ChangeLog:

	* linux-low.c (regsets_fetch_inferior_registers): Do not invoke
	the regset's store function when ptrace returned an error.
	* regcache.c (get_thread_regcache): Invalidate register cache
	before fetching inferior's registers.
2014-12-12 14:15:07 +01:00
Andreas Arnez 28eef6727d gdbserver: Rephrase loops in regsets_fetch/store_inferior_registers
Replace the while-loops in linux-low.c that iterate over regsets by
for-loops.  This makes it clearer what is iterated over.  Also, since
"continue" now moves on to the next iteration without having to
increment the regset pointer first, the code is slightly reduced.

In case of EIO the old code did not increment the regset pointer, but
iterated over the same (now disabled) regset again.  This extra
iteration is now avoided.

gdb/gdbserver/ChangeLog:

	* linux-low.c (regsets_fetch_inferior_registers): Rephrase
	while-loop as for-loop.
	(regsets_store_inferior_registers): Likewise.
2014-12-12 14:15:06 +01:00
Yao Qi 21daaaaffc Improve arm_skip_prologue by using arm_analyze_prologue
Hi,
I see many fails in dw2-dir-file-name.exp on arm target when test
case is compiled with -marm, however, these fails are disappeared when
test case is compiled with -mthumb.

The difference of pass and fail shown below is that "0x000085d4 in" isn't
printed out, but test case expects to see it.

-Breakpoint 2, compdir_missing__ldir_missing__file_basename () at tmp-dw2-dir-file-name.c:999^M
-(gdb) FAIL: gdb.dwarf2/dw2-dir-file-name.exp: compdir_missing__ldir_missing__file_basename: continue to breakpoint: compdir_missing__ldir_missing__file_basename
+Breakpoint 2, 0x000085d4 in compdir_missing__ldir_missing__file_basename () at tmp-dw2-dir-file-name.c:999^M
+(gdb) PASS: gdb.dwarf2/dw2-dir-file-name.exp: compdir_missing__ldir_missing__file_basename: continue to breakpoint: compdir_missing__ldir_missing__file_basename

This difference is caused by setting breakpoint at the first instruction
in the function (actually, the first instruction in prologue, at [1]),
so that frame_show_address returns false, and print_frame doesn't print the
address.

   0x00008620 <+0>:     push    {r11}           ; (str r11, [sp, #-4]!)  <--[1]
   0x00008624 <+4>:     add     r11, sp, #0
   0x00008628 <+8>:     ldr     r3, [pc, #24]   ; 0x8648 <compdir_missing__ldir_missing__file_basename+40>
   0x0000862c <+12>:    ldr     r3, [r3]
   0x00008630 <+16>:    add     r3, r3, #1
   0x00008634 <+20>:    ldr     r2, [pc, #12]   ; 0x8648 <compdir_missing__ldir_missing__file_basename+40>

Then, it must be the arm_skip_prologue's fault that unable to skip
instructions in prologue.  At the end of arm_skip_prologue, it matches
several instructions, such as "str  r(0123),[r11,#-nn]" and
"str  r(0123),[sp,#nn]", but "push {r11}" isn't handled.

These instruction matching code in arm_skip_prologue, which can be regarded
as leftover of development for many years, should be merged to
arm_analyze_prologue and use arm_analyze_prologue in arm_skip_prologue.
Here is the something like the history of arm_{skip,scan,analyze}_prologue.
Around 2002, there are arm_skip_prologue and arm_scan_prologue, but code are
duplicated to some extent.  When match an instruction, both functions should
be modified, for example in Michael Snyder's patch
https://sourceware.org/ml/gdb-patches/2002-05/msg00205.html and Michael
expressed the willingness to merge both into one.  Daniel added code call
thumb_analyze_prologue in arm_skip_prologue in 2006, but didn't handle its
counterpart arm_analyze_prologue, which is added in 2010
<https://sourceware.org/ml/gdb-patches/2010-03/msg00820.html>
however, the instructions matching at the bottom of arm_skip_prologue wasn't
cleaned up.  This patch is to merge them into arm_analyze_prologue.

gdb:

2014-12-12  Yao Qi  <yao@codesourcery.com>

	PR tdep/14261
	* arm-tdep.c (arm_skip_prologue): Remove unused local variable
	'skip_pc'.  Remove code skipping prologue instructions, use
	arm_analyze_prologue instead.
	(arm_analyze_prologue): Stop the scanning for unrecognized
	instruction when skipping prologue.
2014-12-12 08:46:34 +08:00
Yao Qi f303bc3e6c Don't scan prologue past epilogue
This patch is to stop prologue analysis past epilogue in for arm mode,
while we've already had done the same to thumb mode (see
thumb_instruction_restores_sp).  This is useful to parse functions
with empty body (epilogue follows prologue).

gdb:

2014-12-12  Yao Qi  <yao@codesourcery.com>

	* arm-tdep.c (arm_instruction_restores_sp): New function.
	(arm_analyze_prologue): Call arm_instruction_restores_sp.
	(arm_in_function_epilogue_p): Move code to
	arm_instruction_restores_sp.
2014-12-12 08:46:25 +08:00
Doug Evans 05a6c3c813 cp-namespace.c (cp_lookup_nested_symbol): Fix comments.
gdb/ChangeLog:

	* cp-namespace.c (cp_lookup_nested_symbol): Fix comments.
2014-12-11 12:05:25 -08:00
Doug Evans fe2a438d59 (lookup_global_symbol_from_objfile): Simplify.
gdb/ChangeLog:

	* symtab.c (lookup_symbol_in_objfile_symtabs): Delete forward decl.
	(symbol *lookup_symbol_via_quick_fns): Ditto.
	(lookup_symbol_in_objfile): Add forward decl.
	(lookup_global_symbol_from_objfile): Simplify, call
	lookup_symbol_in_objfile.
2014-12-11 09:55:29 -08:00
Doug Evans 540feddfde symtab.c (domain_name) <MODULE_DOMAIN>: Add missing case.
gdb/ChangeLog:

	* symtab.c (domain_name) <MODULE_DOMAIN>: Add missing case.
2014-12-11 09:27:42 -08:00
Simon Marchi fc1269757f Only leave dprintf inserted if it is marked as persistent (PR breakpoints/17012)
On Linux native, if dprintfs are inserted when detaching, they are left
in the inferior which causes it to crash from a SIGTRAP. It also happens
with dprintfs on remote targets, when set disconnected-dprintf is off.

The rationale of the line modified by the patch was to leave dprintfs
inserted in order to support disconnected dprintfs. However, not all
dprintfs are persistent. Also, there's no reason other kinds of
breakpoints can't be persistent either. So this replaces the bp_dprintf
check with a check on whether the location is persistent.

bl->target_info.persist will be 1 only if disconnected-dprintf is on and
we are debugging a remote target. On native, it will always be 0,
regardless of the value of disconnected-dprintf. This makes sense, since
disconnected dprintfs are not supported by the native target.

One issue about the test is that it does not pass when using
--target_board=native-extended-gdbserver, partly due to bug 17302 [1].

One quick hack I tried for this was to add a useless "next" between the
call to getpid() and detach, which avoids the bug. There is still one
case where the test fails, and that is with:

- breakpoint always-inserted on
- dprintf-style agent
- disconnected-dprintf on

What happens is that my detach does not actually detach the process,
because some persistent commands (the disconnected dprintf) is present.
However since gdbserver is ran with --once, when gdb disconnects,
gdbserver goes down and takes with it all the processes it spawned and
that are still under its control (which includes my test process).
When the test checks if the test process is still alive, it obvisouly
fails. Investigating about that led me to ask a question on the ML [2]
about the behavior of detach.

Until the remote case is sorted out, the problematic test is marked as
KFAIL.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=17302
[2] https://sourceware.org/ml/gdb/2014-08/msg00115.html

gdb/Changelog:

	PR breakpoints/17012
	* breakpoint.c (remove_breakpoints_pid): Skip removing
	breakpoint if it is marked as persistent.

gdb/testsuite/ChangeLog:

	PR breakpoints/17012
	* gdb.base/dprintf-detach.c: New file.
	* gdb.base/dprintf-detach.exp: New file.
2014-12-10 16:10:05 -05:00
Simon Marchi 0a46d518c7 Introduce target_is_gdbserver
This patch introduces a function in gdbserver-support.exp to find out
whether the current target is GDBserver.

The code was inspired from gdb.trace/qtro.exp, so it replaces the code
there by a call to the new function.

gdb/testsuite/ChangeLog:

	* gdb.trace/qtro.exp: Replace gdbserver detection code by...
	* lib/gdb.exp (target_is_gdbserver): New
	procedure.
2014-12-10 15:12:17 -05:00
Doug Evans 56286edfdc cp_lookup_symbol_nonlocal: Move definition closer to its subroutines.
gdb/ChangeLog:

	* cp-namespace.c (cp_lookup_symbol_nonlocal): Move definition,
	closer to its subroutines.
2014-12-10 10:42:22 -08:00