Commit Graph

35597 Commits

Author SHA1 Message Date
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
Doug Evans 34ef845277 cp-namespace.c (lookup_symbol_file): Move next to only caller.
gdb/ChangeLog:

	* cp-namespace.c (lookup_symbol_file): Move next to only caller.
2014-12-10 10:21:31 -08:00
Doug Evans 9a80057aa0 cp_lookup_symbol_imports: Make static.
gdb/ChangeLog:

	* cp-namespace.c (cp_lookup_symbol_imports): Make static.
	* cp-support.c (cp_lookup_symbol_imports): Delete.
2014-12-10 10:05:32 -08:00
Simon Marchi 1abf3a1437 Restore terminal state in mi_thread_exit (PR gdb/17627)
When a thread exits, the terminal is left in mode "terminal_is_ours"
while the target executes.  This patch fixes that.

We need to manually restore the terminal setting in this particular
observer.  In the case of the other MI observers that call
target_terminal_ours, gdb will end up resuming the inferior later in the
execution and call target_terminal_inferior.  In the case of the thread
exit event, we still need to call target_terminal_ours to be able to
print something, but there is nothing that gdb will need to resume after
that. We therefore need to call target_terminal_inferior ourselves.

gdb/ChangeLog:

	PR gdb/17627
	* target.c (cleanup_restore_target_terminal): New function.
	(make_cleanup_restore_target_terminal): New function.
	* target.h (make_cleanup_restore_target_terminal): New
	declaration.
	* mi/mi-interp.c (mi_thread_exit): Use the new cleanup.

Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
2014-12-10 13:03:47 -05:00
Doug Evans d4d1e336f9 python/py-objfile.c (objfpy_get_owner): Increment refcount of result.
gdb/ChangeLog:

	* python/py-objfile.c (objfpy_get_owner): Increment refcount of result.
2014-12-08 18:27:41 -08:00
Doug Evans a0be3e44c7 New "owner" attribute for gdb.Objfile.
gdb/ChangeLog:

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

gdb/doc/ChangeLog:

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

gdb/testsuite/ChangeLog:

	* gdb.python/py-objfile.exp: Add tests for objfile.owner.
2014-12-08 08:50:48 -08:00
Jan Kratochvil 6c1c7be347 Unify lookup_symbol_in_objfile_symtabs
That's right, block_lookup_symbol_primary()'s additional requirement over
block_lookup_symbol() is:
	Function is useful if one iterates all global/static blocks of an
	objfile.

Which is satisfied both in lookup_symbol_in_objfile_symtabs() and in
lookup_global_symbol_from_objfile() thanks to their's ALL_OBJFILE_COMPUNITS.

In fact after reverting that ba715d7fe4 above
the lines of code were exactly the same.

So instead of accelerating both lookup_symbol_in_objfile_symtabs() and
lookup_global_symbol_from_objfile() I just accelerated
lookup_symbol_in_objfile_symtabs() and I am proposing to reuse
lookup_symbol_in_objfile_symtabs() in lookup_global_symbol_from_objfile()
instead.  In fact such unification would already save some lines of code even
before the checked-in acceleration patch above.

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

	* symtab.c (lookup_symbol_in_objfile_symtabs): New declaration.
	(lookup_global_symbol_from_objfile): Call it.
2014-12-05 19:39:12 +01:00
Jan Kratochvil efad9b6a7a Remove const from many struct objfile *
I am just not sure if we should go the route of
        struct objfile * -> const struct objfile *
or the other way of:
        const struct objfile * -> struct objfile *

Normally const adding is better but here I do not see much useful to have any
struct objfile * const and then it just causes pointer compatibility problems.

On Wed, 03 Dec 2014 18:18:44 +0100, Doug Evans wrote:
struct objfile is one case where I've decided to just leave the const
out and not worry about it.

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

	Remove const from struct objfile *.
	* solib-darwin.c, solib-spu.c, solib-svr4.c, solib.c, solist.h,
	symtab.c, symtab.h: In these files.
2014-12-05 19:11:53 +01:00
Andreas From 069bb7eced Add myself as write after approval maintainer
gdb/ChangeLog:

	* MAINTAINERS (Write After Approval): Add "Andreas From".
2014-12-05 11:35:34 -05:00
Yao Qi a13c5393d5 Revert: Don't enable gdbtk in testsuite
This patch is to revert my previous commit, because we shouldn't remove
gdbtk bits from gdb/testsuite/configure.ac while keep gdbtk bits in
gdb/configure.ac.

gdb/testsuite:

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

	Revert:

	* configure.ac: Remove AC_ARG_ENABLE for gdbtk.  Don't invoke
	AC_CONFIG_SUBDIRS(gdb.gdbtk).
	* configure: Re-generated.
2014-12-05 19:56:19 +08:00
Yao Qi df1b803ada Fix parallel testing issues in gdb.guile tests
Some gdb.guile tests such as scm-error.exp copies .scm file to
${subdir}/, how ${subdir} doesn't exist in parallel testing
(outputs/${subdir} exists).

$ make -j3 check TESTS='gdb.guile/scm-section-script.exp gdb.guile/scm-error.exp gdb.guile/scm-frame-args.exp'

ERROR: remote_download to host of ../../../../git/gdb/testsuite/gdb.guile/scm-section-script.scm to gdb.guile/t-scm-section-script.scm: cp: cannot create regular file 'gdb.guile/t-scm-section-script.scm': No such file or directory
ERROR: remote_download to host of ../../../../git/gdb/testsuite/gdb.guile/scm-frame-args.scm to gdb.guile/t-scm-frame-args.scm: cp: cannot create regular file
'gdb.guile/t-scm-frame-args.scm': No such file or directory
ERROR: remote_download to host of ../../../../git/gdb/testsuite/gdb.guile/scm-error-1.scm to gdb.guile/t-scm-error-1.scm: cp: cannot create regular file 'gdb.guile/t-scm-error-1.scm': No such file or directory

This patch is to remove the third argument of gdb_remote_download, so
that gdb_remote_download can return the correct location.

Further, these tests only copy .scm files to a different name.  From what
I can tell from the comments, looks we do this to avoid clobbering file
in in-tree build.  However, if source and dest of copy are the same, the
operation is no-op.  So it makes few sense to copy .scm files to a
different names.  I tried in-tree build/test with this patch, test
result isn't changed.

gdb/testsuite:

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

	* gdb.guile/scm-error.exp: Remove the third argument to
	gdb_remote_download.
	* gdb.guile/scm-frame-args.exp: Likewise.
	* gdb.guile/scm-section-script.exp: Likewise.
2014-12-05 19:45:04 +08:00
Doug Evans 642a8d8067 Revert: linespec.c (iterate_name_matcher): Fix arguments to symbol_name_cmp.
This patch causes regressions in ada's operator_bp.exp test.
That's because it uses wild_match which expects arguments in
the original order.

There is still a bug here.  It's hard to see because either minsyms
save the day, or the needed symtab gets expanded before linespecs
need it because of the call to cp_canonicalize_string_no_typedefs
in linespec.c:find_linespec_symbols.
But if you disable both of those things, then the bug is visible.

bash$ ./gdb -D ./data-directory testsuite/gdb.cp/anon-ns
(gdb) b doit(void)
Function "doit(void)" not defined.

gdb/ChangeLog:

	Revert:
	PR symtab/17602
	* linespec.c (iterate_name_matcher): Fix arguments to symbol_name_cmp.
2014-12-05 01:04:07 -08:00
Yao Qi ddb9f679fa Use standard_testfile in i386-bp_permanent.exp
This patch is to use standard_testfile in i386-bp_permanent.exp to replace
existing setting to testfile, srcfile and binfile.  So it fixes a problem
in i386-bp_permanent.exp in parallel testing.

$ make -j3 check TESTS='gdb.guile/scm-section-script.exp gdb.arch/i386-bp_permanent.exp'
....
gdb compile failed, /usr/bin/ld: cannot open output file x86/gdb/testsuite/gdb.arch/i386-bp_permanent: No such file or directory
collect2: error: ld returned 1 exit status

gdb/testsuite:

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

	* gdb.arch/i386-bp_permanent.exp: Use standard_testfile.
2014-12-05 15:32:00 +08:00
Doug Evans 86e4ed3959 New python method gdb.Objfile.add_separate_debug_file.
gdb/ChangeLog:

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

gdb/doc/ChangeLog:

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

gdb/testsuite/ChangeLog:

	* gdb.python/py-objfile.exp: Add tests for
	objfile.add_separate_debug_file.
2014-12-04 12:01:22 -08:00
Doug Evans 7c50a93137 New python attribute gdb.Objfile.build_id.
gdb/ChangeLog:

	* NEWS: Mention gdb.Objfile.build_id.
	* build-id.c (build_id_bfd_get): Make non-static.
	* build-id.h (build_id_bfd_get): Add declaration.
	* python/py-objfile.c: #include "build-id.h", "elf-bfd.h".
	(OBJFPY_REQUIRE_VALID): New macro.
	(objfpy_get_build_id): New function.
	(objfile_getset): Add "build_id".
	* utils.c (make_hex_string): New function.
	* utils.h (make_hex_string): Add declaration.

gdb/doc/ChangeLog:

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

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (get_build_id): New function.
	(build_id_debug_filename_get): Rewrite to use it.
	* gdb.python/py-objfile.exp: Add test for objfile.build_id.
2014-12-04 11:32:24 -08:00
Jan Kratochvil ba715d7fe4 Accelerate lookup_symbol_aux_objfile 85x
During debugging I get 10-30 seconds for a response to simple commands like:
	(gdb) print vectorvar.size()
With this patch the performance gets to 1-2 seconds which is somehow
acceptable.  The problem is that dwarf2_gdb_index_functions.lookup_symbol
(quick_symbol_functions::lookup_symbol) may return (and returns) NULL even for
symbols which are present in .gdb_index but which can be found in already
expanded symtab.  But searching in the already expanded symtabs is just too
slow when there are 400000+ expanded symtabs.  There would be needed some
single global hash table for each objfile so that one does not have to iterate
all symtabs.  Which .gdb_index could perfectly serve for, just its
lookup_symbol() would need to return authoritative yes/no answers.

Even after such fix these two simple patches are useful for example for
non-.gdb_index files.

One can reproduce the slugging interactive GDB performance with:
	#include <string>
	using namespace std;
	string var;
	class C {
	public:
	  void m() {}
	};
	int main() {
	  C c;
	  c.m();
	  return 0;
	}
g++ -o slow slow.C -Wall -g $(pkg-config --libs gtkmm-3.0)
gdb ./slow -ex 'b C::m' -ex 'maintenance set per-command space' -ex 'maintenance set per-command symtab' -ex 'maintenance set per-command
time' -ex r
[...]
(gdb) p <tab><tab>
Display all 183904 possibilities? (y or n) n
(gdb) p/r var
$1 = {static npos = <optimized out>, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No
data fields>}, _M_p = 0x3a4db073d8 <std::string::_Rep::_S_empty_rep_storage+24> ""}}
Command execution time: 20.023000 (cpu), 20.118665 (wall)
                        ^^^^^^^^^
Space used: 927997952 (+0 for this command)

Without DWZ there are X global blocks for X primary symtabs for X CUs of
objfile.  With DWZ there are X+Y global blocks for X+Y primary symtabs for
X+Y CUs where Y are 'DW_TAG_partial_unit's.

For 'DW_TAG_partial_unit's (Ys) their blockvector is usually empty.  But not
always, I have found there typedef symbols, there can IMO be optimized-out
static variables etc.

Neither of the patches should cause any visible behavior change.

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

	* block.c (block_lookup_symbol_primary): New function.
	* block.h (block_lookup_symbol_primary): New declaration.
	* symtab.c (lookup_symbol_in_objfile_symtabs): Assert BLOCK_INDEX.
	Call block_lookup_symbol_primary.
2014-12-04 08:26:26 +01:00
Maciej W. Rozycki 621661e3fa Correct invalid assumptions made by (mostly) DWARF-2 tests
Address issues triggered by the MIPS ISA bit handling change, usually in
tests that make artificial DWARF-2 records:

* gdb.cp/expand-psymtabs-cxx.exp -- this test is debugging an object file
  and assuming addresses will be 0; with the ISA bit set code addresses
  are 1 instead:

(gdb) PASS: gdb.cp/expand-psymtabs-cxx.exp: set language c++
p 'method(long)'
$1 = {void (long)} 0x1 <method(long)>
(gdb) FAIL: gdb.cp/expand-psymtabs-cxx.exp: before expand
p method
$2 = {void (long)} 0x1 <method(long)>
(gdb) FAIL: gdb.cp/expand-psymtabs-cxx.exp: force expand
p 'method(long)'
$3 = {void (long)} 0x1 <method(long)>
(gdb) FAIL: gdb.cp/expand-psymtabs-cxx.exp: after expand

  Fix by matching any hex number, there's no value AFAICT for the test
  in matching 0 exactly, and I suppose the method's offset within
  section can be non-zero for some other reasons on other targets too.

* gdb.cp/nsalias.exp -- this assumes instructions can be aligned
  arbitrarily and places code labels at odd addreses, setting the ISA
  bit and wreaking havoc:

(gdb) PASS: gdb.cp/nsalias.exp: print outer::inner::innermost::x
list outer::inner::innermost::foo
Function "outer::inner::innermost::foo" not defined.
(gdb) FAIL: gdb.cp/nsalias.exp: list outer::inner::innermost::foo
break *outer::inner::innermost::foo
No symbol "foo" in namespace "outer::inner::innermost".
(gdb) FAIL: gdb.cp/nsalias.exp: setting breakpoint at
*outer::inner::innermost::foo
delete $bpnum
No breakpoint number 6.
(gdb) FAIL: gdb.cp/nsalias.exp: (outer::inner::innermost): delete $bpnum

  -- etc., etc...  Fix by aligning labels to 4; required by many
  processors.

* gdb.dwarf2/dw2-canonicalize-type.exp, gdb.dwarf2/dw2-empty-pc-range.exp,
  gdb.dwarf2/pr11465.exp -- these assume an instruction and consequently
  a function can take as little as 1 byte, which makes it impossible to
  look up a code symbol by an address with the ISA bit set as the
  address is already beyond the end of the function:

(gdb) ptype f
No symbol "f" in current context.
(gdb) FAIL: gdb.dwarf2/dw2-canonicalize-type.exp: ptype f

(gdb) PASS: gdb.dwarf2/dw2-empty-pc-range.exp: empty range before CU load
ptype realrange
No symbol "realrange" in current context.
(gdb) FAIL: gdb.dwarf2/dw2-empty-pc-range.exp: valid range after CU load

(gdb) p N::c.C
Cannot take address of method C.
(gdb) FAIL: gdb.dwarf2/pr11465.exp: p N::c.C

  -- fix by increasing the size of the function to 4 (perhaps code in
  gdb/mips-tdep.c could look up code symbols up to twice, with and
  failing that without the ISA bit set, but it seems wrong to me to
  implement specific handling for invalid code just to satisfy test
  cases that assume too much about the target).

* gdb.dwarf2/dw2-case-insensitive.exp -- an artificial code label is
  created, but does not work because data (a `.align' pseudo-op in this
  case) follows and as a result the label has no MIPS16 or microMIPS
  annotation in the symbol table:

(gdb) PASS: gdb.dwarf2/dw2-case-insensitive.exp: set case-sensitive off
info functions fUnC_lang
All functions matching regular expression "fUnC_lang":

File file1.txt:
foo FUNC_lang(void);

Non-debugging symbols:
0x004006e0  FUNC_lang_start
(gdb) FAIL: gdb.dwarf2/dw2-case-insensitive.exp: regexp case-sensitive off

  -- fix by adding a `.insn' pseudo-op on MIPS targets; the pseudo-op
  marks data as instructions.

* gdb.dwarf2/dw2-stack-boundary.exp -- the test case enables complaints
  and assumes none will be issued beyond ones explicitly arranged by the
  test case, however overlapping sections are noticed while minimal
  symbols are looked up by `mips_adjust_dwarf2_addr' in DWARF-2 record
  processing:

(gdb) set complaints 100
(gdb) PASS: gdb.dwarf2/dw2-stack-boundary.exp: set complaints 100
file ./dw2-stack-boundary
Reading symbols from ./dw2-stack-boundary...location description stack
underflow...location description stack overflow...unexpected overlap
between:
 (A) section `.reginfo' from `.../gdb.dwarf2/dw2-stack-boundary' [0x0, 0x18)
 (B) section `*COM*' from `.../gdb.dwarf2/dw2-stack-boundary' [0x0, 0x0).
Will ignore section B...unexpected overlap between:
 (A) section `.reginfo' from `.../gdb.dwarf2/dw2-stack-boundary' [0x0, 0x18)
 (B) section `*UND*' from `.../gdb.dwarf2/dw2-stack-boundary' [0x0, 0x0).
Will ignore section B...unexpected overlap between:
 (A) section `.reginfo' from `.../gdb.dwarf2/dw2-stack-boundary' [0x0, 0x18)
 (B) section `*ABS*' from `.../gdb.dwarf2/dw2-stack-boundary' [0x0, 0x0).
Will ignore section B...done.

(gdb) FAIL: gdb.dwarf2/dw2-stack-boundary.exp: check partial symtab errors

  -- fix by ignoring any extra noise as long as what we look for is
  found.

	* gdb.cp/expand-psymtabs-cxx.exp: Accept any address of
	`method(long)', not just 0x0.
	* gdb.cp/nsalias.exp: Align code labels to 4.
	* gdb.dwarf2/dw2-canonicalize-type.S (main): Expand to 4-bytes.
	* gdb.dwarf2/dw2-empty-pc-range.S (main): Likewise.
	* gdb.dwarf2/pr11465.S (_ZN1N1cE): Likewise.
	* gdb.dwarf2/dw2-case-insensitive.c (START_INSNS): New macro.
	(cu_text_start, FUNC_lang_start): Use `START_INSNS'.
	* gdb.dwarf2/dw2-stack-boundary.exp: Accept noise in complaints.
2014-12-04 00:06:10 +00:00
Maciej W. Rozycki 858339f2b7 MIPS: Add support for microMIPS Linux signal trampolines
The necessity for this change has been revealed in the course of
investigation related to proposed changes in the treatment of the ISA
bit encoded in function symbols on the MIPS target.  This change adds
support for Linux signal trampolines encoded with the microMIPS
instruction set.  Such trampolines are used by the Linux kernel if
compiled as a microMIPS binary (even if the binary run/debugged itself
contains no microMIPS code at all).

To see if we need to check whether the execution mode selected matches
the given trampoline I have checked what the bit patterns of all the
trampoline sequences decode to in the opposite instruction set.  This
produced useless or at least unusual code in most cases, for example:

microMIPS/EB, o32 sigreturn, decoded as MIPS code:
	30401017 	andi	zero,v0,0x1017
	00008b7c 	dsll32	s1,zero,0xd

MIPS/EL, o32 sigreturn, decoded as microMIPS code:
	1017 2402 	addi	zero,s7,9218
	000c 0000 	sll	zero,t0,0x0

However in some corner cases reasonable code can mimic a trampoline, for
example:

MIPS/EB, n32 rt_sigreturn, decoded as microMIPS code:
	2402      	sll	s0,s0,1
	1843 0000 	sb	v0,0(v1)
	000c 0f3c 	jr	t0

-- here the first instruction is a 16-bit one, making things nastier
even as there are some other microMIPS instructions whose first 16-bit
halfword is 0x000c and therefore matches this whole trampoline pattern.

To overcome this problem I have decided the signal trampoline unwinder
has to ask the platform backend whether it can apply a given trampoline
pattern to the code location being concerned or not.  Anticipating the
acceptance of the ISA bit proposal I decided the handler not to merely
be a predicate, but also to be able to provide an adjusted PC if
required.  I decided that returning zero will mean that the trampoline
pattern is not applicable and any other value is the adjusted PC to use;
a handler may return the value requested if the trampoline pattern and
the PC requested as-is are both accepted.

This changes the semantics of the trampoline unwinder a bit in that the
zero PC now has a special value.  I think this should be safe as a NULL
pointer is generally supposed to be invalid.

	* tramp-frame.h (tramp_frame): Add `validate' member.
	* tramp-frame.c (tramp_frame_start): Validate trampoline before
	scanning.
	* mips-linux-tdep.c (MICROMIPS_INST_LI_V0): New macro.
	(MICROMIPS_INST_POOL32A, MICROMIPS_INST_SYSCALL): Likewise.
	(mips_linux_o32_sigframe): Initialize `validate' member.
	(mips_linux_o32_rt_sigframe): Likewise.
	(mips_linux_n32_rt_sigframe): Likewise.
	(mips_linux_n64_rt_sigframe): Likewise.
	(micromips_linux_o32_sigframe): New variable.
	(micromips_linux_o32_rt_sigframe): Likewise.
	(micromips_linux_n32_rt_sigframe): Likewise.
	(micromips_linux_n64_rt_sigframe): Likewise.
	(mips_linux_o32_sigframe_init): Handle microMIPS trampolines.
	(mips_linux_n32n64_sigframe_init): Likewise.
	(mips_linux_sigframe_validate): New function.
	(micromips_linux_sigframe_validate): Likewise.
	(mips_linux_init_abi): Install microMIPS trampoline unwinders.
2014-12-03 20:57:06 +00:00
Ulrich Weigand ff1eb2b544 Use core regset iterators on Sparc Solaris
Remove native-only core file handling on Sparc Solaris.  Instead,
enable the sparc target generic core regset logic on Solaris by
providing appropriate register offset maps.

Thanks to Joel Brobecker for testing!

gdb/
	* config/sparc/sol2.mh (NATDEPFILES): Remove core-regset.o.
	* sparc-sol2-tdep.c: Include "regset.h".
	(sparc32_sol2_supply_core_gregset): New function.
	(sparc32_sol2_collect_core_gregset): Likewise.
	(sparc32_sol2_supply_core_fpregset): Likewise.
	(sparc32_sol2_collect_core_fpregset): Likewise.
	(sparc32_sol2_gregset, sparc32_sol2_fpregset): New variables.
	(sparc32_sol2_init_abi): Set tdep->gregset/sizeof_gregset and
	tdep->fpregset/sizeof_fpregset.
	* sparc64-sol2-tdep.c: Include "regset.h".
	(sparc64_sol2_supply_core_gregset): New function.
	(sparc64_sol2_collect_core_gregset): Likewise.
	(sparc64_sol2_supply_core_fpregset): Likewise.
	(sparc64_sol2_collect_core_fpregset): Likewise.
	(sparc64_sol2_gregset, sparc64_sol2_fpregset): New variables.
	(sparc64_sol2_init_abi): Set tdep->gregset/sizeof_gregset and
	tdep->fpregset/sizeof_fpregset.
2014-12-03 15:38:46 +01:00
Simon Marchi 75783939d7 Fix make_cleanup_dtor signature to match declaration
The definition does not use the typedef for the dtor function pointer
type that the declaration uses.  It's a cosmetic-only change.

ChangeLog:

	* common/cleanups.c (make_cleanup_dtor): Use typedef for dtor
	type.
2014-12-03 08:56:10 -05:00
Doug Evans 7c5fdd25eb Remove cplus_specific from general_symbol_info.
This patch reverts the addition of cplus_specific added here:

2010-07-16  Sami Wagiaalla  <swagiaal@redhat.com>

	* symtab.h (symbol_set_demangled_name): Now takes an optional objfile*
	argument.
	(cplus_specific): New struct.
	* symtab.c (symbol_set_demangled_name): Updated.
	Use cplus_specific for cplus symbols.
	(symbol_get_demangled_name): Retrive the name from the cplus_specific
	struct for cplus symbols.
	(symbol_init_language_specific): Set cplus_specific for cplus symbols.
	(symbol_set_names): Pass objfile to symbol_set_demangled_name.
	* symtab.c (symbol_init_cplus_specific): New function.

It was added in anticipation of improved template support:

https://sourceware.org/ml/gdb-patches/2010-05/msg00594.html
https://sourceware.org/ml/gdb-patches/2010-07/msg00284.html

However, minsyms pay the price for this space too.
For my standard benchmark this patch gets back 44MB of memory
when gdb starts.  [There's still ~440MB of memory used
by the demangled ELF symbols of this benchmark, but that's another topic.]

When the improved templated support is added,
I wonder if this can be moved to struct symbol.
Hmmm, we already have a special version of
struct symbol for templates (struct template_symbol).

gdb/ChangeLog:

	* symtab.c (symbol_init_cplus_specific): Delete.
	(symbol_set_demangled_name): Remove special c++ support.
	(symbol_get_demangled_name, symbol_set_language): Ditto.
	* symtab.h (struct cplus_specific): Delete.
	(struct general_symbol_info) <language_specific>: Remove
	cplus_specific.
2014-12-02 16:55:52 -08:00
Doug Evans 29f0c3b7b2 PR symtab/17602
gdb/ChangeLog:

	PR symtab/17602
	* linespec.c (iterate_name_matcher): Fix arguments to symbol_name_cmp.

gdb/testsuite/ChangeLog:

        PR symtab/17602
	* gdb.cp/anon-ns.cc: Move guts of this file to ...
	* gdb.cp/anon-ns-2.cc: ... here.  New file.
	* gdb.cp/anon-ns.exp: Update.
2014-12-02 16:40:38 -08:00
Doug Evans 72998fb37a PR symtab/17591
gdb/ChangeLog:

	PR symtab/17591
	* dwarf2read.c (find_slot_in_mapped_hash): Use cp_remove_params
	to strip parameters.
2014-12-02 16:24:37 -08:00
Doug Evans 422b9917ce dwarf2read.c (peek_die_abbrev): Improve error message text.
gdb/ChangeLog:

	* dwarf2read.c (peek_die_abbrev): Improve error message text.
2014-12-02 16:22:18 -08:00
Doug Evans 47c6ee4990 Remove remnant of Chill support.
gdb/ChangeLog:

	* valops.c (do_search_struct_field): Remove remnant of Chill support.
	Ref: commit 4c2260aa5c
2014-12-02 16:15:53 -08:00
Simon Marchi 5da3ffc99d Fix comment typo
ChangeLog:

	* common/cleanups.c (make_cleanup_dtor): Fix comment typo.
2014-12-02 17:22:07 -05:00
Nick Bull 162078c893 New python events: inferior call, register/memory changed.
gdb/ChangeLog:

	* NEWS: Mention new Python events.
	* Makefile.in (SUBDIR_PYTHON_OBS): Add py-infevents.o.
	(SUBDIR_PYTHON_SRCS): Add py-infevents.c.
	(py-infevents.o): New rule.
	* doc/observer.texi (inferior_call_pre, inferior_call_post)
	(memory_changed, register_changed): New observers.
	* infcall.c (call_function_by_hand): Notify observer before and
	after inferior call.
	* python/py-event.h (inferior_call_kind): New enum.
	(emit_inferior_call_event): New prototype.
	(emit_register_changed_event): New prototype.
	(emit_memory_changed_event): New prototype.
	* python/py-events.h (events_object): New registries
	inferior_call, memory_changed and register_changed.
	* python/py-evts.c (gdbpy_initialize_py_events): Add the
	inferior_call, memory_changed and register_changed registries.
	* python/py-infevents.c: New.
	* python/py-inferior.c (python_on_inferior_call_pre)
	(python_on_inferior_call_post, python_on_register_change)
	(python_on_memory_change): New functions.
	(gdbpy_initialize_inferior): Attach python handler to new
	observers.
	* python/py-infthread.c(gdbpy_create_ptid_object): New.
	(thpy_get_ptid) Use gdbpy_create_ptid_object.
	* python/python-internal.h:
	(gdbpy_create_ptid_object)
	(gdbpy_initialize_inferior_call_pre_event)
	(gdbpy_initialize_inferior_call_post_event)
	(gdbpy_initialize_register_changed_event)
	(gdbpy_initialize_memory_changed_event): New prototypes.
	* python/python.c (_initialize_python): Initialize new events.
	* valops.c (value_assign): Notify register_changed observer.

gdb/doc/ChangeLog:

	* python.texi (Events In Python): Document new events
	InferiorCallPreEvent, InferiorCallPostEvent, MemoryChangedEvent
	and RegisterChangedEvent.

gdb/testsuite/ChangeLog:

	* gdb.python/py-events.py (inferior_call_handler): New.
	(register_changed_handler, memory_changed_handler): New.
	(test_events.invoke): Register new handlers.
	* gdb.python/py-events.exp: Add tests for inferior call,
	memory_changed and register_changed events.
2014-12-02 11:15:29 -08:00
Doug Evans 71dd4b30a7 revert previous patch so that I can re-commit with correct author 2014-12-02 11:12:49 -08:00
Doug Evans dc6c87175b New python events: infcall, register/memory changed.
gdb/ChangeLog:

	* NEWS: Mention new Python events.
	* Makefile.in (SUBDIR_PYTHON_OBS): Add py-infevents.o.
	(SUBDIR_PYTHON_SRCS): Add py-infevents.c.
	(py-infevents.o): New rule.
	* doc/observer.texi (inferior_call_pre, inferior_call_post)
	(memory_changed, register_changed): New observers.
	* infcall.c (call_function_by_hand): Notify observer before and
	after inferior call.
	* python/py-event.h (inferior_call_kind): New enum.
	(emit_inferior_call_event): New prototype.
	(emit_register_changed_event): New prototype.
	(emit_memory_changed_event): New prototype.
	* python/py-events.h (events_object): New registries
	inferior_call, memory_changed and register_changed.
	* python/py-evts.c (gdbpy_initialize_py_events): Add the
	inferior_call, memory_changed and register_changed registries.
	* python/py-infevents.c: New.
	* python/py-inferior.c (python_on_inferior_call_pre)
	(python_on_inferior_call_post, python_on_register_change)
	(python_on_memory_change): New functions.
	(gdbpy_initialize_inferior): Attach python handler to new
	observers.
	* python/py-infthread.c(gdbpy_create_ptid_object): New.
	(thpy_get_ptid) Use gdbpy_create_ptid_object.
	* python/python-internal.h:
	(gdbpy_create_ptid_object)
	(gdbpy_initialize_inferior_call_pre_event)
	(gdbpy_initialize_inferior_call_post_event)
	(gdbpy_initialize_register_changed_event)
	(gdbpy_initialize_memory_changed_event): New prototypes.
	* python/python.c (_initialize_python): Initialize new events.
	* valops.c (value_assign): Notify register_changed observer.

gdb/doc/ChangeLog:

	* python.texi (Events In Python): Document new events
	InferiorCallPreEvent, InferiorCallPostEvent, MemoryChangedEvent
	and RegisterChangedEvent.

gdb/testsuite/ChangeLog:

	* gdb.python/py-events.py (inferior_call_handler): New.
	(register_changed_handler, memory_changed_handler): New.
	(test_events.invoke): Register new handlers.
	* gdb.python/py-events.exp: Add tests for inferior call,
	memory_changed and register_changed events.
2014-12-02 10:59:08 -08:00
Doug Evans 007baf27e4 python/py-infthread.c: Whitespace fixes.
gdb/ChangeLog:

	* python/py-infthread.c: Whitespace fixes.
2014-12-02 10:01:07 -08:00
Andreas Arnez fdb09caf23 execl-update-breakpoints.exp: Move whole segment instead of .text section
The test case builds two copies of the program, one with the compile
option "ldflags=-Wl,-Ttext=0x1000000" and the other with the address
changed to 0x2000000.  However, when linking with ld.bfd, the
resulting executables crash early in ld.so on S390 and i386.

Analysis of the crash: The default linker script establishes a certain
order of loadable sections, and the option "-Ttext" effectively splits
these into an "unaffected" lot (everything before .text) and an
"affected" lot.  The affected lot is placed at the given address,
whereas the unaffected lot stays at its default address.  The
unaffected lot starts at an aligned address plus Elf header sizes,
which is good if it is the first LOAD segment (like on AMD64).  But if
the affected lot comes first instead (like on S390 and i386), the PHDR
doesn't fit there and is placed *outside* any LOAD segments.  Then the
PHDR is not mapped when the loader gets control, and the loader runs
into a segmentation fault while trying to access it.

Since we are lucky about the order of segments on AMD64, the test
succeeds there, but the resulting binaries are unusually large -- 2.1M
each, with lots of padding within.

When replacing '-Ttext' by '-Ttext-segment', the linker moves all
segments consistently, the binaries have normal sizes, and the test
case succeeds on all mentioned platforms.

Since old versions of the gold linker don't support '-Ttext-segment',
the patch also adds logic for falling back to '-Ttext'.

gdb/testsuite/ChangeLog:

	* gdb.base/execl-update-breakpoints.exp: Specify the link address
	with '-Ttext-segment' instead of '-Ttext'.  Fall back to '-Ttext'
	if the linker doesn't understand this.
2014-12-02 16:35:47 +01:00
Andreas Arnez d5552aabd6 S390: Fix 'expedite' for s390-te-linux64
Fix a typo in the expedited registers for s390-te-linux64.

gdb/ChangeLog:

	* features/Makefile (s390-te-linux64-expedite): Replace
	non-existant r14 and r15 by r14l and r15l, respectively.
	* regformats/s390-te-linux64.dat: Regenerate.
2014-12-02 10:47:30 +01:00
Simon Marchi 30b5e341f3 Remove duplicate comment
gdb/ChangeLog:

	* objfiles.c (allocate_objfile): Remove duplicate comment.
2014-12-01 09:12:59 -05:00
Simon Marchi 55cfb2c4c8 Fix Python help() test for Python 3
The message displayed when using help() changed a bit with time, so this
adjusts the test accordingly.

gdb/testsuite/ChangeLog:

	* gdb.python/python.exp: Change expected reply to help().
2014-12-01 08:08:06 -05:00
Ulrich Weigand ac3d87c0d2 Use core regset iterators on GNU Hurd
Remove native-only core file handling on GNU Hurd.  Instead, enable the
x86 target generic core regset logic on the Hurd by providing an
appropriate register offset map.

Thanks to Samuel Thibault for testing!

gdb/

	* config/i386/i386gnu.mh (NATDEPFILES): Remove core-regset.o.
	* i386gnu-nat.c: Do not include <sys/procfs.h> or "gregset.h".
	(CREG_OFFSET, creg_offset, CREG_ADDR): Remove.
	(supply_gregset, supply_fpregset): Remove.
	* i386gnu-tdep.c (i386gnu_gregset_reg_offset): New variable.
	(i386gnu_init_abi): Set tdep->gregset_reg_offset, gregset_num_regs,
	and sizeof_gregset.
2014-12-01 13:42:41 +01:00
Yao Qi 9e8cd6df3c Don't enable gdbtk in testsuite
When I skim configure.ac and Makefile.in in gdb/testsuite, I happen to
see that directory gdb.gdbtk is added to subdirs, however it doesn't
exist.  gdb/testsuite/gdb.gdbtk was removed by the patch below,

  [rfa] git repo fixup: delete gdb/testsuite/gdb.gdbtk
  http://thread.gmane.org/gmane.comp.gdb.patches/61489

and we should cleanup configure.ac accordingly.

gdb/testsuite:

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

	* configure.ac: Remove AC_ARG_ENABLE for gdbtk.  Don't invoke
	AC_CONFIG_SUBDIRS(gdb.gdbtk).
	* configure: Re-generated.
2014-12-01 14:13:17 +08:00
Jan Kratochvil f10c5b19e0 Add add-auto-load-scripts-directory.
There is already "add-auto-load-safe-path" which works
like "set auto-load safe-path" but in append mode.

There was missing an append equivalent for "set auto-load scripts-directory".

ABRT has directory /var/cache/abrt-di/ as an alternative one
to /usr/lib/debug/ . Therefore ABRT needs to use -iex parameters to add this
/var/cache/abrt-di/ directory as a first-class debuginfo directory.
Using absolute "set auto-load scripts-directory" would hard-code the path
possibly overriding local system directory additions; besides it would not be
nice anyway.

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

	Add add-auto-load-scripts-directory.
	* NEWS (Changes since GDB 7.8): Add add-auto-load-scripts-directory.
	* auto-load.c (add_auto_load_dir): New function.
	(_initialize_auto_load): Install it.

gdb/doc/ChangeLog
2014-11-30  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Add add-auto-load-scripts-directory.
	* gdb.texinfo (Auto-loading): Add add-auto-load-scripts-directory link.
	(objfile-gdbdotext file): Add add-auto-load-scripts-directory.
2014-11-30 20:25:48 +01:00
Jan Kratochvil 413b59aecb Fix add-auto-load-safe-path typo.
gdb/doc/ChangeLog
2014-11-30  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.texinfo (Auto-loading safe path): Fix add-auto-load-safe-path
	description typo.
2014-11-30 20:22:24 +01:00
Martin Galvan f0d4ba1fc4 frame.c: Fix the check for FID_STACK_INVALID in frame_id_eq()
I noticed in frame_id_eq() we were checking for the "l" frame_id being
invalid twice instead of checking both "l" and "r", so this patch
corrects it.

gdb/ChangeLog:

	* frame.c (frame_id_eq): Fix the check for FID_STACK_INVALID.
2014-11-30 19:37:31 +04:00
Siva Chandra 18ac6ffc9b Check that thread stack temps are not already enabled before enabling them.
This fixes a regression introduced by 6c659fc2c7.

gdb/ChangeLog:

	* eval.c (evaluate_subexp): Check that thread stack temporaries
	are not already enabled before enabling them.
2014-11-29 15:47:39 -08:00
Yao Qi 4072f9208f [arm] compute framereg and framesize when needed
I find local variables framereg and framesize is only used when cache
isn't NULL.  This patch to move the code into "if (cache)" block.

gdb:

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

	* arm-tdep.c (arm_analyze_prologue): Move local variables
	'framereg' and 'framesize' to inner block.  Move code to
	inner block too.
2014-11-29 22:26:35 +08:00
Siva Chandra 6c659fc2c7 Enable chained function calls in C++ expressions.
gdb/ChangeLog:

	* eval.c: Include gdbthread.h.
	(evaluate_subexp): Enable thread stack temporaries before
	evaluating a complete expression and clean them up after the
	evaluation is complete.
	* gdbthread.h: Include common/vec.h.
	(value_ptr): New typedef.
	(VEC (value_ptr)): New vector type.
	(value_vec): New typedef.
	(struct thread_info): Add new fields stack_temporaries_enabled
	and stack_temporaries.
	(enable_thread_stack_temporaries)
	(thread_stack_temporaries_enabled_p, push_thread_stack_temporary)
	(get_last_thread_stack_temporary)
	(value_in_thread_stack_temporaries): Declare.
	* gdbtypes.c (class_or_union_p): New function.
	* gdbtypes.h (class_or_union_p): Declare.
	* infcall.c (call_function_by_hand): Store return values of class
	type as	temporaries on stack.
	* thread.c (enable_thread_stack_temporaries): New function.
	(thread_stack_temporaries_enabled_p, push_thread_stack_temporary)
	(get_last_thread_stack_temporary): Likewise.
	(value_in_thread_stack_temporaries): Likewise.
	* value.c (value_force_lval): New function.
	* value.h (value_force_lval): Declare.

gdb/testsuite/ChangeLog:

	* gdb.cp/chained-calls.cc: New file.
	* gdb.cp/chained-calls.exp: New file.
	* gdb.cp/smartp.exp: Remove KFAIL for "p c2->inta".
2014-11-28 16:01:16 -08:00
Simon Marchi d7fc3181f7 Fix prints in tests for Python 3
Python 3's print requires to use parentheses, so this patch adds them
where they were missing.

gdb/testsuite/ChangeLog:

	* gdb.ada/py_range.exp: Add parentheses to calls to print.
	* gdb.dwarf2/symtab-producer.exp: Same.
	* gdb.gdb/python-interrupts.exp: Same.
	* gdb.gdb/python-selftest.exp: Same.
	* gdb.python/py-linetable.exp: Same.
	* gdb.python/py-type.exp: Same.
	* gdb.python/py-value-cc.exp: Same.
	* gdb.python/py-value.exp: Same.
2014-11-28 11:36:52 -05:00
Pierre Muller f7ca3fcfcc Fix amd64 dwarf register number mapping (MMX register and higher)
Dwarf register numbers are defined in "System V Application Binary
Interface AMD64 Architecture Processor Supplement Draft Version 0.99.6"

The amd64_dwarf_regmap array is missing the 8 MMX registers in Figure
3.36: DWARF Register Number Mapping page 57.  This leads to a wrong
value for the registers past this point.

gdb/ChangeLog:

        Pushed by Joel Brobecker  <brobecker@adacore.com>.
        * amd64-tdep.c (amd64_dwarf_regmap array): Add missing MMX
        registers.

Tested on x86_64-linux.
2014-11-28 19:30:43 +04:00
Ulrich Weigand b2859a9a54 Remove (dead-code) native core file sniffers on Linux targets
Since Andreas Arnez' recent patch series, all Linux targets install
gdbarch_iterate_over_regset_sections routines.  This means that on
Linux native targets, old-style core sniffers are never used.

Most Linux targets haven't been using such sniffers for a long time
anyway, but a couple remain: ia64 and sparc use core-regset.o, and
m68k installs its own core_fns.  All this is now dead code, which
this commit removes.

gdb/
2014-11-28  Ulrich Weigand  <uweigand@de.ibm.com>

	* config/ia64/linux.mh (NATDEPFILES): Remove core-regset.o.
	* config/sparc/linux.mh (NATDEPFILES): Likewise.
	* config/sparc/linux64.mh (NATDEPFILES): Likewise.
	* m68klinux-nat.c (fetch_core_registers): Remove.
	(linux_elf_core_fns): Remove.
	(_initialize_m68k_linux_nat): Do not call deprecated_add_core_fns.
2014-11-28 15:53:05 +01:00
Joel Brobecker 0fa9473ff0 gdb_realpath: Rework comment about handling on Windows.
Rework the comment to explain why we're still relying on GetFullPathName
even though gnulib ensures that canonicalize_file_name is now available
on all platforms, including Windows.

gdb/ChangeLog:

        * utils.c (gdb_realpath): Rework comment about handling on
        Windows.
2014-11-28 18:37:08 +04:00
Yao Qi 6a29c58ef8 Import rename module
This patch is to import rename module.

gdb:

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

	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add
	rename.
	* gnulib/aclocal.m4: Re-generated.
	* gnulib/config.in: Re-generated.
	* gnulib/configure: Re-generated.
	* gnulib/import/Makefile.am: Re-generated.
	* gnulib/import/Makefile.in: Re-generated.
	* gnulib/import/m4/gnulib-cache.m4: Re-generated.
	* gnulib/import/m4/gnulib-comp.m4: Re-generated.
	* import/basename-lgpl.c: New file.
	* import/dirname-lgpl.c: New file.
	* import/dirname.h: New file.
	* import/m4/dirname.m4: New file.
	* import/m4/malloc.m4: New file.
	* import/m4/rename.m4: New file.
	* import/m4/rmdir.m4: New file.
	* import/m4/stdio_h.m4: New file.
	* import/malloc.c: New file.
	* import/rename.c: New file.
	* import/rmdir.c: New file.
	* import/same-inode.h: New file.
	* import/stdio.c: New file.
	* import/stdio.in.h: New file.
	* import/stripslash.c: New file.
2014-11-28 18:38:21 +08:00
Yao Qi abbffc8924 Use canonicalize_file_name unconditionally
gdb:

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

	* configure.ac (AC_CHECK_FUNCS): Remove canonicalize_file_name
	and realpath.
	* config.in: Re-generated.
	* configure: Re-generated.
	* utils.c (gdb_realpath): Remove code calling realpath,
	canonicalize_file_name and pathconf.
	[!_WIN32]: Call canonicalize_file_name.
2014-11-28 18:38:16 +08:00
Yao Qi 9839978095 Import canonicalize-lgpl
This patch is to import canonicalize-lgpl module, which provides
readlpath and canonicalize_file_name.

gdb:

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

	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add
	canonicalize-lgpl.
	* aclocal.m4: Re-generated.
	* config.in: Re-generated.
	* configure: Re-generated.
	* import/Makefile.am: Re-generated.
	* import/Makefile.in: Re-generated.
	* import/m4/gnulib-cache.m4: Re-generated.
	* import/m4/gnulib-comp.m4: Re-generated.
	* import/canonicalize-lgpl.c: New file.
	* import/extra/snippet/_Noreturn.h: New file.
	* import/m4/canonicalize.m4: New file.
	* import/m4/double-slash-root.m4: New file.
	* import/m4/eealloc.m4: New file.
	* import/m4/malloca.m4: New file.
	* import/m4/nocrash.m4: New file.
	* import/m4/stdlib_h.m4: New file.
	* import/malloca.c: New file.
	* import/malloca.h: New file.
	* import/malloca.valgrind: New file.
2014-11-28 18:38:10 +08:00
Yao Qi 3332aaf289 Use lstat unconditionally
Since lstat gnulib module is imported, we can use it unconditionally.
lstat usage was introduced by this patch

https://sourceware.org/ml/gdb-patches/2012-01/msg00390.html

during the review, it was suggested to import gnulib lstat module, but
we didn't do that.

gdb:

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

	* configure.ac (AC_CHECK_FUNCS): Remove lstat.
	* config.in, configure: Regenerate.
	* symfile.c (find_separate_debug_file_by_debuglink): Remove
	code checking HAVE_LSTAT is defined.
2014-11-28 18:38:02 +08:00
Yao Qi f45c62c4d5 Import lstat
This patch is to import lstat gnulib module.

gdb:

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

	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add
	lstat.
	* gnulib/aclocal.m4: Re-generated.
	* gnulib/config.in: Re-generated.
	* gnulib/configure: Re-generated.
	* gnulib/import/Makefile.am: Re-generated.
	* gnulib/import/Makefile.in: Re-generated.
	* gnulib/import/m4/gnulib-cache.m4: Re-generated.
	* gnulib/import/m4/gnulib-comp.m4: Re-generated.
	* gnulib/import/lstat.c: New file.
	* gnulib/import/m4/lstat.m4: New file.
2014-11-28 18:37:57 +08:00
Yao Qi bdca27a2f5 Use readlink unconditionally
Since readlink module is imported, we can use it unconditionally.
This patch is to remove configure checks and HAVE_READLINK checks in
code.  It was mentioned in the patch below

  [RFA/commit] gdbserver: return ENOSYS if readlink not supported.
  https://sourceware.org/ml/gdb-patches/2012-02/msg00148.html

to use readlink in gdbserver, but we chose something simple at that
moment.

gdb:

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

	* configure.ac (AC_CHECK_FUNCS): Remove readlink.
	* config.in, configure: Re-generate.
	* inf-child.c (inf_child_fileio_readlink): Don't check
	HAVE_READLINK is defined.

gdb/gdbserver:

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

	* configure.ac(AC_CHECK_FUNCS): Remove readlink.
	* config.in, configure: Re-generate.
	* hostio.c (handle_unlink): Remove code checking HAVE_READLINK
	is defined.
2014-11-28 18:37:52 +08:00
Yao Qi 2196f55f01 Import readlink
This patch is to import readlink gnulib module.  stat module is imported
too, but it isn't used by gdb.

gdb:

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

	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add readlink.
	* gnulib/aclocal.m4: Re-generated.
	* gnulib/config.in: Likewise.
	* gnulib/configure: Likewise.
	* gnulib/import/Makefile.am: Likewise.
	* gnulib/import/Makefile.in: Likewise.
	* gnulib/import/m4/gnulib-cache.m4: Likewise.
	* gnulib/import/m4/gnulib-comp.m4: Likewise.
	* gnulib/import/dosname.h: New file
 	* gnulib/import/m4/largefile.m4: New file.
	* gnulib/import/m4/readlink.m4: New file.
	* gnulib/import/m4/stat.m4: New file.
	* gnulib/import/readlink.c: New file.
 	* gnulib/import/stat.c: New file.
2014-11-28 18:37:47 +08:00
Yao Qi 7014e923da Fix date in changelog 2014-11-28 17:23:26 +08:00
Yao Qi 10e79639cc Match library name prefixed with sysroot
We enable systemtap probe in glibc recently, and see the following gdb fail,

(gdb) set solib-absolute-prefix /.
...
Stopped due to shared library event:^M
  Inferior loaded /./foo/bar/gdb.base/break-probes-solib.so
...
(gdb) FAIL: gdb.base/break-probes.exp: run til our library loads (the program exited)

$binfile_lib is /foo/bar/gdb.base/break-probes-solib.so, but the
sysroot is prefixed in solib.c:solib_find, as comments described:

   Global variable GDB_SYSROOT is used as a prefix directory
   to search for shared libraries if they have an absolute path.

so the output becomes "/./foo/bar/gdb.base/break-probes-solib.so", which
is still correct.  However, the test repeatedly continue the program
and tries to match $binfile_lib, finally, the program exits and the
test fails.

This patch is to adjust the pattern to match $sysroot$binfile_lib
instead of $binfile_lib.

gdb/testsuite:

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

	* gdb.base/break-probes.exp: Match library name prefixed with
	sysroot.
2014-11-28 11:21:48 +08:00
Simon Marchi f28a0564dd Fix test always passing in python/py-linetable.exp
The following test is found in python/py-linetable.exp:

gdb_test "python print sorted(fset)" \
    "\[20L, 21L, 22L, 24L, 25L, 28L, 29L, 30L, 32L, 33L, 37L, 39L, 40L, 42L, 44L, 45L, 46L\].*" \
    "Test frozen set contains line numbers"

I noticed that it passed when using Python 3, even though it should fail
because of the missing parentheses for the call print.

There needs to be more escaping of the square brackets. Currently, it is
interpreted as "any one character from this big list of characters,
followed by .*". When adding the required amount of backslashes, the
test starts failing as it should.

Moreover, both in Python 2.7 and Python 3.3 the numbers don't have the L
suffix, so now the test fails because of that. Anybody knows why they
were there in the first place? I just tested with Python 2.4 and there
are no Ls.

gdb/testsuite/ChangeLog:

	* gdb.python/py-linetable.exp: Escape properly sorted(fset)
	test expected output.  Add parentheses for the call to print.
	Remove L suffix from integers.

Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
2014-11-27 09:27:08 -05:00
Doug Evans 3fe1ce1d5b gdb.dwarf2/dw2-op-out-param.S: Fix comment.
gdb/ChangeLog:

	* gdb.dwarf2/dw2-op-out-param.S: Fix comment.
2014-11-26 14:44:46 -08:00
Mark Wielaard 0cfd832fc7 Recognize new DWARFv5 C11, C++11 and C++14 DW_LANG constants.
gdb/ChangeLog

	* dwarf2read.c (set_cu_language): Recognize DW_LANG_C11,
	DW_LANG_C_plus_plus_11, DW_LANG_C_plus_plus_14.

include/ChangeLog

	* dwarf2.h: Add DW_LANG_C_plus_plus_11, DW_LANG_C11 and
	DW_LANG_C_plus_plus_14.
2014-11-26 12:47:29 +01:00
Sandra Loosemore aa4893954a Fix Nios II prologue analyzer to handle multiple stack adjustments.
2014-11-25  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/
	* nios2-tdep.c (nios2_analyze_prologue): Replace restriction
	that there can be only one stack adjustment in the prologue
	with tests to detect specific disallowed stack adjustments.
2014-11-25 18:40:28 -08:00
Sandra Loosemore 7f1659b587 Fix Nios II GDB epilogue detection to handle multiple stack adjustments.
2014-11-25  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/
	* nios2-tdep.c (nios2_in_epilogue_p): Handle multiple stack
	adjustments.
2014-11-25 18:37:41 -08:00
Sandra Loosemore d53c26c753 Refactor Nios II GDB support to use helper functions for disassembly and
instruction matching.

2014-11-25  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/
	* nios2-tdep.c (nios2_fetch_insn): Move up in file.  Disassemble
	the instruction as well as reading it from memory.
	(nios2_match_add): New.
	(nios2_match_sub): New.
	(nios2_match_addi): New.
	(nios2_match_orhi): New.
	(nios2_match_stw): New.
	(nios2_match_ldw): New.
	(nios2_match_rdctl): New.
	(enum branch_condition): New.
	(nios2_match_branch): New.
	(nios2_match_jmpi): New.
	(nios2_match_calli): New.
	(nios2_match_jmpr): New.
	(nios2_match_callr): New.
	(nios2_match_break): New.
	(nios2_match_trap): New.
	(nios2_in_epilogue_p): Rewrite to use new functions.
	(nios2_analyze_prologue): Likewise.
	(nios2_skip_prologue): Delete unused local limit_pc.
	(nios2_breakpoint_from_pc): Make R1-specific encodings explicit.
	(nios2_get_next_pc): Rewrite to use new functions.
2014-11-25 18:34:51 -08:00
Jan Kratochvil cac9b138f7 Reindent code (resolve_dynamic_type_internal).
gdb/ChangeLog
2014-11-24  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdbtypes.c (resolve_dynamic_type_internal): Reindent the code.
2014-11-24 18:05:04 +01:00
Samuel Thibault a441dfbc4e [Hurd] Fix deallocation after proc_getprocinfo call
2014-11-24  Samuel Thibault  <samuel.thibault@ens-lyon.org>

	* gdb/gnu-nat.c (inf_validate_procinfo): Multiply the number of
	elements pi_len by the size of the elements before calling
	vm_deallocate.
	(inf_validate_task_sc): Likewise, and properly deallocate the
	noise array.
2014-11-24 13:28:03 +04:00
Doug Evans 4c9e848275 Fix dumping of function arguments.
gdb/ChangeLog:

	* gdbtypes.c (print_args): Renamed from print_arg_types.  Print arg
	number and name if present.  All callers updated.
	(dump_fn_fieldlists): Fix indentation of args.
2014-11-23 20:31:18 -08:00
Patrick Palka 15ee0bbdde Add myself as write-after-approval GDB maintainer
gdb/ChangeLog:
	* MAINTAINERS (Write After Approval): Add myself.
2014-11-23 11:18:22 -05:00
Joel Brobecker e8af5d7a5c Always consider infcall breakpoints as non-permanent.
A recent change...

    commit 1a853c5224
    Date:   Wed Nov 12 10:10:49 2014 +0000
    Subject: make "permanent breakpoints" per location and disableable

... broke function calls on sparc-elf when running over QEMU. Any
function call should demonstrate the problem.

For instance, seen from the debugger:

    (gdb) call pn(1234)
    [Inferior 1 (Remote target) exited normally]
    The program being debugged exited while in a function called from GDB.
    Evaluation of the expression containing the function

And seen from QEMU:

    qemu: fatal: Trap 0x02 while interrupts disabled, Error state
    [register dump removed]

What happens in this case is that GDB sets the inferior function call
by not only creating the dummy frame, but also writing a breakpoint
instruction at the return address for our function call. See infcall.c:

        /* Write a legitimate instruction at the point where the infcall
           breakpoint is going to be inserted.  While this instruction
           is never going to be executed, a user investigating the
           memory from GDB would see this instruction instead of random
           uninitialized bytes.  We chose the breakpoint instruction
           as it may look as the most logical one to the user and also
           valgrind 3.7.0 needs it for proper vgdb inferior calls.

           If software breakpoints are unsupported for this target we
           leave the user visible memory content uninitialized.  */

        bp_addr_as_address = bp_addr;
        bp_bytes = gdbarch_breakpoint_from_pc (gdbarch, &bp_addr_as_address,
                                               &bp_size);
        if (bp_bytes != NULL)
          write_memory (bp_addr_as_address, bp_bytes, bp_size);

This instruction triggers a change introduced by the commit above,
where we consider bp locations as being permanent breakpoints
if there is already a breakpoint instruction at that address:

        +  if (bp_loc_is_permanent (loc))
        +    {
        +      loc->inserted = 1;
        +      loc->permanent = 1;
        +    }

As a result, when resuming the program's execution for the inferior
function call, GDB decides that it does not need to insert a breakpoint
at this address, expecting the target to just report a SIGTRAP when
trying to execute that instruction.

But unfortunately for us, at least some versions of QEMU for SPARC
just terminate the execution entirely instead of reporting a breakpoint,
thus producing the behavior reported here.

Although it appears like QEMU might be misbehaving and should therefore
be fixed (to be verified) from the user's point of view, the recent
change does introduce a regression. So this patch tries to mitigate
a bit the damage by handling such infcall breakpoints as special and
making sure that they are never considered permanent, thus restoring
the previous behavior specifically for those breakpoints.

The option of not writing the breakpoint instructions in the first
place was considered, and would probably work also. But the comment
associated to it seems to indicate that there is still reason to
keep it.

gdb/ChangeLog:

        * breakpoint.c (bp_loc_is_permanent): Return 0 if LOC corresponds
        to a bp_call_dummy breakpoint type.

Tested on x86_64-linux. Also testing on sparc-elf/QEMU using
AdaCore's testsuite.
2014-11-23 14:34:52 +04:00
Patrick Palka a344fc094d Specify SA_RESTART when registering the SIGWINCH signal handler
SA_RESTART allows system calls to be restarted across a signal handler.
By specifying this flag we fix the issue where if the user is being
prompted to answer yes or no, and the terminal gets resized in the
meantime, the prompt will think that the user sent an EOF and so it will
take the default action for that prompt (in the case of the quit prompt,
it will quit GDB).

gdb/ChangeLog:

	* tui/tui-win.c (tui_initialize_win): Specify SA_RESTART when
	registering the signal handler.
2014-11-23 14:12:05 +04:00
Patrick Palka d64e57faa8 Fix the processing of Meta-key commands in TUI
This patch fixes the annoying bug where key sequences such as Alt_F or
Alt_B (go forward or backwards by a word) do not behave promptly in TUI.
You have to press a third key in order for the key sequence to register.

This is mostly ncurses' fault.  Calling wgetch() normally causes ncurses
to read only a single key from stdin.  However if the key read is the
start-sequence key (^[ a.k.a. ESC) then wgetch() reads TWO keys from
stdin, storing the 2nd key into an internal FIFO buffer and returning
the start-sequence key.  The extraneous read of the 2nd key makes us
miss its corresponding stdin event, so the event loop blocks until a
third key is pressed.  This explains why such key sequences do not
behave promptly in TUI.

To fix this issue, we must somehow compensate for the missed stdin event
corresponding to the 2nd byte of a key sequence.  This patch achieves
this by hacking  up the stdin event handler to conditionally execute the
readline callback multiple times in a row.  This is done via a new
global variable, call_stdin_event_handler_again_p, which is set from
tui_getc() when we receive a start-sequence key and notice extra pending
input in the ncurses buffer.

Tested on x86_64-unknown-linux-gnu.

gdb/ChangeLog:

	* event-top.h (call_stdin_event_handler_again_p): Declare.
	* event-top.c (call_stdin_event_handler_again_p): Define.
	(stdin_event_handler): Use it.
	* tui/tui-io.c (tui_getc): Prepare to call the stdin event
	handler again if there is pending input following a
	start sequence.
2014-11-23 14:04:09 +04:00
Patrick Palka 6f9d33d898 checkpoint: print index of new checkpoint in response message
This way the user can know the index of the latest checkpoint without
having to run "info checkpoints" afterwards.

gdb/ChangeLog:

	* linux-fork.c (checkpoint_command): Print index of new
	checkpoint in response message.
2014-11-23 13:58:06 +04:00
Yao Qi 88db67effd Refine read_string
In read_string, we have this line

  chunksize = (len == -1 ? min (8, fetchlimit) : fetchlimit);

but chunksize is only used in the block that lne == -1, so IWBN to
move chunksize to the block in which it is used, and simplify the
condition setting chunksize.  This patch also moves 'found_nul' to
inner block.  This patch also splits a paragraph of comment into two,
and move them to different condition blocks (len > 0 and len == -1)
respectively.

gdb:

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

	* valprint.c (read_string): Move local variables 'found_nul',
	'chunksize' and 'limit' to inner scope.  Update comments.
2014-11-23 13:57:00 +08:00
Doug Evans 01465b569e symtab.c: Comment and whitespace improvements.
gdb/ChangeLog:

	* symtab.c (lookup_symbol_in_objfile_from_linkage_name): Improve
	function comment.
	(search_symbols): Fix comments and whitespace.
2014-11-22 11:29:08 -08:00
Doug Evans 07a1c2c3c7 cp-namespace.c (cp_lookup_symbol_nonlocal): Fix comment.
gdb/ChangeLog:

	* cp-namespace.c (cp_lookup_symbol_nonlocal): Fix comment.
2014-11-22 10:46:52 -08:00
Yao Qi 84429e27c8 Use MACRO_AT_func in entry-values.exp
MACRO_AT_func can be used in gdb.trace/entry-values.exp to correctly
get function's address in generated debug info.  As a result, the test
is more friendly to clang.  Currently, there are some fails in
entry-values.exp when the test is compiled by clang.  With this patch
applied, all fails go away.

gdb/testsuite:

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

	* gdb.trace/entry-values.c: Remove asms.
	(foo): Add foo_label.
	(bar): Add bar_label.
	* gdb.trace/entry-values.exp: Remove code computing  foo's
	length and bar's length.
	(Dwarf::assemble): Invoke function_range for bar and use
	MACRO_AT_func for foo.
2014-11-22 21:28:31 +08:00
Yao Qi 267418593c [arm] Fix fails in dw2-compdir-oldgcc.exp
This patch fixes two fails in dw2-compdir-oldgcc.exp I've seen on arm
target thumb mode.

  FAIL: gdb.dwarf2/dw2-compdir-oldgcc.exp: info source gcc42
  FAIL: gdb.dwarf2/dw2-compdir-oldgcc.exp: info source gcc43

When fill in DW_AT_low_pc, the label should be used rather than the
function, otherwise, the LSB bit of the address in DW_AT_low_pc is
set and the debug info is wrong.  This patch is to add two labels for
functions gcc42 and gcc43 respectively, and use them.  These two
fails are fixed.

gdb/testsuite:

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

	* gdb.dwarf2/dw2-compdir-oldgcc.S: Define label .Lgcc42_procstart
	and .Lgcc43_procstart.  Use .Lgcc42_procstart instead of gcc42.
	Use .Lgcc43_procstart instead of gcc43.
2014-11-22 21:22:01 +08:00
Doug Evans b2a919a82b psymtab.c (psymtab_search_name): Fix whitespace.
gdb/ChangeLog:

	* psymtab.c (psymtab_search_name): Fix whitespace.
2014-11-21 09:50:56 -08:00
Yao Qi 278289d5d7 Import errno explicitly
errno.h is included in common/common-defs.h, and gnulib errno module
was imported to gdb.  This patch is to import it explicitly.

gdb:

	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add
	errno.
	* gnulib/import/Makefile.am: Re-generated.
	* gnulib/import/Makefile.in: Likewise.
	* gnulib/import/m4/gnulib-cache.m4: Likewise.
2014-11-21 22:05:42 +08:00
Yao Qi e01e2baa69 Include wchar.h and wctype.h unconditionally
As gnulib modules wchar and wctype is imported, we can include wchar.h
and wctype.h unconditionally.  This patch is also to remove HAVE_WCHAR_H
check.

gdb:

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

	* gdb_wchar.h: Include wchar.h and wctype.h.
	[HAVE_ICONV && HAVE_BTOWC]: Don't check HAVE_WCHAR_T and don't
	include wchar.h and wctype.h.
	Don't check HAVE_WCHAR_H.
2014-11-21 22:05:41 +08:00
Yao Qi f0c00af8b4 Import wchar and wctype-h explicitly
gnulib module wchar and wctype-h was imported as a dependency, but
they are used by gdb_wchar.h too.  This patch is to import them
explicitly.

gdb:

	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add wchar
	and wctype-h.
	* gnulib/import/Makefile.am: Re-generated.
	* gnulib/import/Makefile.in: Likewise.
	* gnulib/import/m4/gnulib-cache.m4: Likewise.
2014-11-21 22:05:41 +08:00
Yao Qi 0cae13bb02 Import memchr explicitly
memchr has been used in gdb source and gnulib memchr module was
imported as a dependency.  This patch is to import it explicitly.

gdb:

	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add
	memchr.
	* gnulib/import/Makefile.am: Re-generated.
	* gnulib/import/Makefile.in: Likewise.
	* gnulib/import/m4/gnulib-cache.m4: Likewise.
2014-11-21 22:05:41 +08:00
Yao Qi 9c232dda88 Include alloca.h unconditionally
Since gnulib alloca module was imported, we can include alloca.h in
both gdb and gdbserver unconditionally, so this patch adds inclusion
of alloca.h in common-defs.h.  This patch also removes AC_FUNC_ALLOCA
in configure.ac because we don't need to check alloca any more.

This patch below is removed in fact.

  [RFA/commit] include alloca.h if available.
  https://www.sourceware.org/ml/gdb-patches/2010-08/msg00566.html

Since alloca.h is from gnulib now, we don't have to check malloc.h in
configure and include malloc.h in code.  This patch also remove them
too.

gdb:

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

	* common/common-defs.h: Include alloca.h
	* configure.ac: Don't invoke AC_FUNC_ALLOCA.
	* configure: Re-generated.
	* defs.h: Remove code handling alloca.
	* utils.c (gdb_realpath): Don't check HAVE_ALLOCA is defined
	or not.

gdb/gdbserver:

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

	* configure.ac: Don't invoke AC_FUNC_ALLOCA.
	(AC_CHECK_HEADERS): Remove malloc.h.
	* configure: Re-generated.
	* config.in: Re-generated.
	* server.h: Don't include alloca.h and malloc.h.
	* gdbreplay.c: Don't check HAVE_ALLOCA_H is defined.
	Don't include malloc.h.
2014-11-21 22:05:41 +08:00
Yao Qi 00d7f58fd4 Import alloca explicitly
gnulib's alloca module was imported to gdb, and alloca is used.  This
patch is to explicitly import it.

gdb:

	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULE): Add
	alloca.
	* gnulib/import/Makefile.am: Re-generated.
	* gnulib/import/Makefile.in: Likewise..
	* gnulib/import/m4/gnulib-cache.m4: Likewise.
2014-11-21 22:05:41 +08:00