[GDBserver] Avoid stale errno

Although most compilers follow right-to-left evaluation order, the
order of evaluation of a function call's arguments is really
unspecified.  target_pid_to_str or ptid_of may well clobber errno when
we get to evaluate the third argument to debug_printf.

gdb/gdbserver/
2014-07-15  Pedro Alves  <palves@redhat.com>

	* linux-low.c (linux_kill_one_lwp): Save errno and work with saved
	copy.
Handle OP_STRING in dump_subexp_body_standard

For some reason, OP_STRING is not handled in dump_subexp_body_standard.
This makes the output of "set debug expression 1" very bad when a string
is involved. Example:

(gdb) set debug expression 1
(gdb) print "hello"
... (random garbage, possibly segfault)

This commit handles OP_STRING and skips the appropriate number of exp
elements. The line corresponding to the string now looks like:

	    0  OP_STRING             Language-specific string type: 0

gdb/ChangeLog:

2014-07-15  Simon Marchi  <simon.marchi@ericsson.com>

	* expprint.c (dump_subexp_body_standard): Handle OP_STRING.
[GDB/Linux] Avoid stale errno

The fix that went into GDBserver is also needed on the GDB side.

Although most compilers follow right-to-left evaluation order, the
order of evaluation of a function call's arguments is really
unspecified.  target_pid_to_str may well clobber errno when we get to
evaluate the third argument to fprintf_unfiltered.

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

	* linux-nat.c (kill_callback): Save errno and work with saved
	copy.
Add support for the __flash qualifier on AVR

The __flash qualifier is part of the named address spaces for AVR [1]. It
allows putting read-only data in the flash memory, normally reserved for
code.

When used together with a pointer, the DW_AT_address_class attribute is set
to 1 and allows GDB to detect that when it will be dereferenced, the data
will be loaded from the flash memory (with the LPM instruction).

We can now properly debug the following code:

~~~
const __flash char data_in_flash = 0xab;

int
main (void)
{
  const __flash char *pointer_to_flash = &data_in_flash;
}
~~~

~~~
(gdb) print pointer_to_flash
$1 = 0x1e8 <data_in_flash> "\253"
(gdb) print/x *pointer_to_flash
$2 = 0xab
(gdb) x/x pointer_to_flash
0x1e8 <data_in_flash>: 0xXXXXXXab
~~~

Whereas previously, GDB would revert to the default address space which is
RAM and mapped in higher memory:

~~~
(gdb) print pointer_to_flash
$1 = 0x8001e8 ""
~~~

[1] https://gcc.gnu.org/onlinedocs/gcc/Named-Address-Spaces.html

2014-07-15  Pierre Langlois  <pierre.langlois@embecosm.com>

gdb/
	* avr-tdep.c (AVR_TYPE_ADDRESS_CLASS_FLASH): New macro.
	(AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH): Likewise.
	(avr_address_to_pointer): Check for AVR_TYPE_ADDRESS_CLASS_FLASH.
	(avr_pointer_to_address): Likewise.
	(avr_address_class_type_flags): New function.
	(avr_address_class_type_flags_to_name): Likewise.
	(avr_address_class_name_to_type_flags): Likewise.
	(avr_gdbarch_init): Set address_class_type_flags,
	address_class_type_flags_to_name and
	address_class_name_to_type_flags.

gdb/testsuite/
	* gdb.arch/avr-flash-qualifer.c: New.
	* gdb.arch/avr-flash-qualifer.exp: New.
gdb.base/reread.exp: Really restart GDB

The other day I noticed that default_gdb_start reuses the GDB process
if it has been spawned already:

proc default_gdb_start { } {
...
    if [info exists gdb_spawn_id] {
	return 0
    }

I was a bit surprised, and so I hacked in an error to check whether
anything is relying on it:

 + if [info exists gdb_spawn_id] {
 +    error "GDB already spawned"
 + }

And lo, that tripped on a funny buglet (see below).  The comment in
reread.exp says "Restart GDB entirely", but in reality, due to the
above, that's not what is happening, as a gdb_exit call is missing.
The test is proceeding with the previous GDB process...

I don't really want to go hunt for whether there's an odd setup out
there that assumes this in its board file or something, so for now,
I'm taking the simple route of just making the test do what it says it
does.  I think this much makes it an obvious fix.

 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 (gdb) PASS: gdb.base/reread.exp: run to foo() second time
 ERROR: tcl error sourcing ../src/gdb/testsuite/gdb.base/reread.exp.
 ERROR: GDB already spawned
     while executing
 "error "GDB already spawned""
     invoked from within
 "if [info exists gdb_spawn_id] {
	 error "GDB already spawned"
     }"
     (procedure "default_gdb_start" line 22)
     invoked from within
 "default_gdb_start"
     (procedure "gdb_start" line 2)
     invoked from within
 "gdb_start"
     invoked from within
 "if [is_remote target] {
     unsupported "second pass: GDB should check for changes before running"
 } else {

     # Put the older executable back in pl..."
     (file "../src/gdb/testsuite/gdb.base/reread.exp" line 114)
     invoked from within
 "source ../src/gdb/testsuite/gdb.base/reread.exp"
     ("uplevel" body line 1)
     invoked from within
 "uplevel #0 source ../src/gdb/testsuite/gdb.base/reread.exp"
     invoked from within
 "catch "uplevel #0 source $test_file_name""
 testcase ../src/gdb/testsuite/gdb.base/reread.exp completed in 1 seconds
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

	* gdb.base/reread.exp: Use clean_restart.
Update elf_i386_compute_jump_table_size

Commit e1f987424b7b3f5ac63a2a6ae044a202a44b8ff8 changed how
next_tls_desc_index was set up.  This patch updates
elf_i386_compute_jump_table_size to use elf.srelplt->reloc_count
instead of next_tls_desc_index.

bfd/

	PR ld/17057
	* elf32-i386.c (elf_i386_compute_jump_table_size): Replace
	next_tls_desc_index with elf.srelplt->reloc_count.

ld/testsuite/

	PR ld/17057
	* ld-i386/i386.exp: Run pr17057.
	* ld-i386/pr17057.d: New file.
	* ld-i386/pr17057.s: Likewise.
daily update
Introduce common/errors.h

This introduces common/errors.h.  This holds some error- and
warning-related declarations that can be used by the code in common.
Clients of the "common" code must provide definitions for these
functions.

gdb/
2014-07-16  Tom Tromey  <tromey@redhat.com>
	    Gary Benson  <gbenson@redhat.com>

	* common/errors.h: New file.
	* utils.h: Include errors.h.
	(perror_with_name, error, fatal, warning): Don't declare.
	* common/common-utils.h: Include errors.h.
	(malloc_failure, internal_error): Don't declare.

gdb/gdbserver/
2014-07-16  Tom Tromey  <tromey@redhat.com>

	* utils.h: Include errors.h.
	(perror_with_name, error, fatal, warning): Don't declare.
Remove some GDBSERVER checks from linux-ptrace

This patch removes some GDBSERVER checks from nat/linux-ptrace.c.
Currently the code uses a compile-time check to decide whether some
flags should be used.  This changes the code to instead let users of
the module specify an additional set of flags; and then changes gdb's
linux-nat.c to call this function.  At some later date, when the back
ends are fully merged, we will be able to remove this function again.

gdb/
2014-07-16  Tom Tromey  <tromey@redhat.com>
	    Gary Benson  <gbenson@redhat.com>

	* nat/linux-ptrace.c (additional_flags): New global.
	(linux_test_for_tracesysgood, linux_test_for_tracefork): Use
	additional_flags; don't check GDBSERVER.
	(linux_ptrace_set_additional_flags): New function.
	* nat/linux-ptrace.h (linux_ptrace_set_additional_flags):
	Declare.
	* linux-nat.c (_initialize_linux_nat): Call
	linux_ptrace_set_additional_flags.
Make gdbserver CORE_ADDR unsigned

gdbserver defines CORE_ADDR to be signed.  This seems erroneous to
me; and furthermore likely to cause problems in common/, as it is
different from gdb's definition.

gdb/gdbserver/
2014-07-16  Tom Tromey  <tromey@redhat.com>
	    Gary Benson  <gbenson@redhat.com>

	* server.h (CORE_ADDR): Now unsigned.
Introduce common-types.h

This introduces common-types.h.  This file defines various standard
types used by gdb and gdbserver.

Currently these types are conditionally defined based on GDBSERVER.
The long term goal is to remove all such tests; however, this is
difficult as currently gdb uses definitions from BFD.  In the meantime
this is still a step in the right direction.

gdb/
2014-07-16  Tom Tromey  <tromey@redhat.com>
	    Gary Benson  <gbenson@redhat.com>

	* common/common-types.h: New file.
	* nat/linux-ptrace.c: Include common-types.h.
	* defs.h: Include common-types.h.
	(gdb_byte, CORE_ADDR, CORE_ADDR_MAX, LONGEST, ULONGEST): Remove.

gdb/gdbserver/
2014-07-16  Tom Tromey  <tromey@redhat.com>

	* server.h: Include common-types.h.  Move gdb_assert.h include
	earlier.  Add static assertion.
	(gdb_byte, CORE_ADDR, LONGEST, ULONGEST): Remove.
Introduce and use debug_printf and debug_vprintf

This introduces debug_printf and debug_vprintf, a function that
clients of "common" are expected to implement.  gdbserver's
existing debug_printf is repurposed as debug_vprintf, and a new
wrapper is written.

common/agent.c is changed to use debug_vprintf rather than
defining the macro DEBUG_AGENT depending on GDBSERVER.

nat/i386-dregs.c is changed to use the externally-implemented
debug_printf, rather than defining it itself.

gdb/
2014-07-16  Tom Tromey  <tromey@redhat.com>
	    Gary Benson  <gbenson@redhat.com>

	* common/common-debug.h: New file.
	* debug.c: Likewise.
	* utils.h: Include common-debug.h.
	* common/agent.c (debug_agent_print): New function.
	(DEBUG_AGENT): Redefine.
	* nat/i386-dregs.c (debug_printf): Undefine.

gdb/gdbserver/
2014-07-16  Tom Tromey  <tromey@redhat.com>
	    Gary Benson  <gbenson@redhat.com>

	* utils.h: Include common-debug.h.
	* debug.h (debug_printf): Don't declare.
	* debug.c (debug_vprintf): New function.
	(debug_printf): Use the above.
Remove simple GDBSERVER uses from common, nat and target

This removes various simple GDBSERVER uses from common, nat and
target.  The simple uses are just cases where the code includes defs.h
or server.h depending on GDBSERVER.  Instead, now the files include
the headers that they require.  Unfortunately we still need to check
GDBSERVER for some files to decide which gnulib config header to
import, but this is a step in the right direction.

gdb/
2014-07-16  Tom Tromey  <tromey@redhat.com>
	    Gary Benson  <gbenson@redhat.com>

	* common/buffer.c: Don't include server.h or defs.h; update
	includes.
	* common/common-utils.c: Don't include server.h or defs.h; update
	includes.
	* common/filestuff.c: Don't include server.h or defs.h; update
	includes.
	* common/filestuff.h: Include stdio.h.
	* common/format.c: Don't include server.h or defs.h; update
	includes.
	* common/gdb_vecs.c: Don't include server.h or defs.h; update
	includes.
	* common/print-utils.c: Don't include server.h or defs.h; update
	includes.
	* common/rsp-low.c: Don't include server.h or defs.h; update
	includes.
	* common/signals.c: Don't include server.h or defs.h; update
	includes.
	* common/vec.c: Don't include server.h or defs.h; update includes.
	* common/xml-utils.c: Don't include server.h or defs.h; update
	includes.
	* nat/linux-osdata.c: Don't include server.h or defs.h; update
	includes.
	* nat/linux-procfs.c: Don't include server.h or defs.h; update
	includes.
	* nat/linux-ptrace.c: Don't include server.h or defs.h; update
	includes.
	* nat/mips-linux-watch.h: Don't include server.h or defs.h; update
	includes.
	* target/waitstatus.c: Don't include server.h or defs.h; update
	includes.
Remove GDBSERVER use from nat/i386-dregs.c

This removes the use of GDBSERVER from nat/i386-dregs.c.  Neither
defs.h or server.h are included: the specific files required are
listed instead.  Also, a declaration previously made only outside
of gdbserver is made unconditional.

gdb/
2014-07-16  Gary Benson  <gbenson@redhat.com>

	* gdb/nat/i386-dregs.c: Don't include server.h or defs.h; update
	includes.
	(debug_hw_points): Declare regardless of GDBSERVER.
Make btrace-common.h not use GDBSERVER

This changes btrace-common.h not to include defs.h or server.h.
Instead it moves the defs.h include to btrace.c.

gdb/
2014-07-16  Tom Tromey  <tromey@redhat.com>

	* btrace.c: Include defs.h.
	* common/btrace-common.h: Don't include server.h or defs.h.
Mostly remove GDBSERVER from linux-waitpid.c

This commit mostly removes the use of GDBSERVER from
nat/linux-waitpid.c.  A use remains for some debugging
code that I will remove when the Linux thread_db code
is refactored.

gdb/
2014-07-16  Gary Benson  <gbenson@redhat.com>

	* nat/linux-waitpid.c: Don't include server.h or defs.h.
	(linux_debug) [debug_threads]: New declaration.
Add target/target.h

This adds target/target.h.  This file declares some functions that the
"common" code can use and that the clients must implement.  It also
changes code in common to use these functions.

gdb/
2014-07-16  Tom Tromey  <tromey@redhat.com>
	    Gary Benson  <gbenson@redhat.com>

	* target.h: Include target/target.h.
	(target_read_memory, target_write_memory): Don't declare.
	* target.c (target_read_uint32): New function.
	* common/agent.c: Don't include server.h or defs.h; update
	includes.
	(agent_get_helper_thread_id): Use target_read_uint32.
	(agent_run_command): Always use target_write_memory,
	target_read_memory.
	(agent_capability_check): Use target_read_uint32.
	* target/target.h: New file.

gdb/gdbserver/
2014-07-16  Tom Tromey  <tromey@redhat.com>

	* target.c (target_read_memory, target_read_uint32)
	(target_write_memory): New functions.
More target unification

This unifies a few more top-level target functions -- target_resume,
target_wait, and target_stop -- and the declaration of the variable
"non_stop".  This follows the usual pattern, where clients of "common"
are expected to define the objects appropriately, thus simplifying
common/agent.c a bit more.

gdb/
2014-07-16  Tom Tromey  <tromey@redhat.com>

	* target/target.h (target_resume, target_wait, target_stop)
	(non_stop): Moved from target.h.
	* target.h (target_resume, target_wait, target_stop, non_stop):
	Move to target/target.h.
	* common/agent.c (agent_run_command): Always use target_resume,
	target_stop, and target_wait.

gdb/gdbserver/
2014-07-16  Tom Tromey  <tromey@redhat.com>
	    Gary Benson  <gbenson@redhat.com>

	* target.c (target_wait, target_stop, target_resume): New
	functions.
Add target/symbol.h, update users

This adds a new "target/symbol.h" file, that declares a symbol-lookup
function used by code in common.  It follows the usual pattern, where
clients of "common" have their own definitions of this function.  This
simplifies agent.c a bit.

gdb/
2014-07-16  Tom Tromey  <tromey@redhat.com>
	    Gary Benson  <gbenson@redhat.com>

	* target/symbol.h: New file.
	* target.h: Include target/symbol.h.
	* target.c (target_look_up_symbol): New function.
	* common/agent.c: Include target/symbol.h.
	(agent_look_up_symbols): Use target_look_up_symbol.

gdb/gdbserver/
2014-07-16  Tom Tromey  <tromey@redhat.com>
	    Gary Benson  <gbenson@redhat.com>

	* target.c: Include target/symbol.h.
	(target_look_up_symbol): New function.
Finally remove GDBSERVER (mostly) from agent.c

This reduces the use of the GDBSERVER define in agent.c to deciding
which gnulib header to include.