external/binutils.git
7 years agogdb/ctf.c: Get rid of mkdir redefinition
Pedro Alves [Thu, 17 Nov 2016 14:43:02 +0000 (14:43 +0000)]
gdb/ctf.c: Get rid of mkdir redefinition

Making GDB use gnulib's C++ namespace support shows this build error
on mingw:

 ../../src/gdb/ctf.c: In function 'void ctf_start(trace_file_writer*, const char*)':
 ../../src/gdb/ctf.c:309:46: error: no match for call to '(const gnulib::_gl_mkdir_wrapper) (const char*&)'
  #define mkdir(pathname, mode) mkdir (pathname)
       ^
 ../../src/gdb/ctf.c:327:15: note: in expansion of macro 'mkdir'
    if (gnulib::mkdir (dirname, hmode) && errno != EEXIST)
^
 ../../src/gdb/ctf.c:309:46: note: candidate: gnulib::_gl_mkdir_wrapper::type {aka int (*)(const char*, short unsigned int)} <conversion>
  #define mkdir(pathname, mode) mkdir (pathname)
       ^
 ../../src/gdb/ctf.c:327:15: note: in expansion of macro 'mkdir'
    if (gnulib::mkdir (dirname, hmode) && errno != EEXIST)
^
 ../../src/gdb/ctf.c:309:46: note:   candidate expects 3 arguments, 2 provided
  #define mkdir(pathname, mode) mkdir (pathname)
       ^
 ../../src/gdb/ctf.c:327:15: note: in expansion of macro 'mkdir'
    if (gnulib::mkdir (dirname, hmode) && errno != EEXIST)
^

The problem is the '#define mkdir ...'

Fortunately, we can just remove it, since gnulib's sys/stat.h
replacement already takes care of the Windows mkdir prototype quirk:

~~~
 /* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
    Additionally, it declares _mkdir (and depending on compile flags, an
    alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
    which are included above.  */
 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__

 #  if !GNULIB_defined_rpl_mkdir
 static int
 rpl_mkdir (char const *name, mode_t mode)
 {
   return _mkdir (name);
 }
~~~

That's sys_stat.in.h, part of the sys_stat module, which we explictly
pull in nowadays.  It wasn't being pulled when this macro was added:

  https://sourceware.org/ml/gdb-patches/2013-03/msg00736.html

That patch was partially reverted meanwhile here:

  https://sourceware.org/ml/gdb-patches/2013-12/msg00023.html

But the mkdir macro had been left behind unnoticed.

gdb/ChangeLog:
2016-11-17  Pedro Alves  <palves@redhat.com>

* ctf.c [USE_WIN32API] (mkdir): Delete.

7 years agogdb/ada-lang.c: one malloc -> unique_ptr<[]>
Pedro Alves [Wed, 16 Nov 2016 11:38:49 +0000 (11:38 +0000)]
gdb/ada-lang.c: one malloc -> unique_ptr<[]>

Switching gdb to use gnulib's C++ namespace mode reveals we're calling
malloc instead of xmalloc here:

 ..../src/gdb/ada-lang.c: In function ‘value* ada_value_primitive_packed_val(value*, const gdb_byte*, long int, int, int, type*)’:
 ..../src/gdb/ada-lang.c:2592:50: error: call to ‘malloc’ declared with attribute warning: The symbol ::malloc refers to the system function. Use gnulib::malloc instead. [-Werror]
staging = (gdb_byte *) malloc (staging_len);
   ^

We're unconditionaly using the result afterwards -- so it's not a case
of gracefully handling huge allocations.

Since we want to get rid of all cleanups, fix this by switching to
new[] and unique_ptr<[]> instead, while at it.

Regtested on Fedora 23.

gdb/ChangeLog:
2016-11-16  Pedro Alves  <palves@redhat.com>

* ada-lang.c (ada_value_primitive_packed_val): Use unique_ptr and
new gdb_byte[] instead of malloc and cleanups.

7 years agogdb/tracepoint.c: Don't use printf_vma
Pedro Alves [Thu, 17 Nov 2016 00:23:17 +0000 (00:23 +0000)]
gdb/tracepoint.c: Don't use printf_vma

I noticed that bfd's printf_vma prints to stdout directly:

  bfd-in2.h:202:#define printf_vma(x) fprintf_vma(stdout,x)

This is a bad idea in gdb, where we should use
gdb_stdout/gdb_stderr/gdb_stdlog, etc., to support redirection.

Eliminate uses of sprintf_vma too while at it.

Tested on Fedora 23, w/ gdbserver.

gdb/ChangeLog:
2016-11-17  Pedro Alves  <palves@redhat.com>

* tracepoint.c (collection_list::add_memrange): Add gdbarch
parameter.  Use paddress instead of printf_vma.  Adjust recursive
calls.
(collection_list::stringify): Use paddress and phex_nz instead of
sprintf_vma.  Adjust add_memrange call.
* tracepoint.h (collection_list::add_memrange): Add gdbarch
parameter.

7 years agoAutomatic date update in version.in
GDB Administrator [Thu, 17 Nov 2016 00:00:19 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoStash frame id of current frame before stashing frame id for previous frame
Kevin Buettner [Mon, 31 Oct 2016 19:47:42 +0000 (12:47 -0700)]
Stash frame id of current frame before stashing frame id for previous frame

This patch ensures that the frame id for the current frame is stashed
before that of the previous frame (to the current frame).

First, it should be noted that the frame id for the current frame is
not stashed by get_current_frame().  The current frame's frame id is
lazily computed and stashed via calls to get_frame_id().  However,
it's possible for get_prev_frame() to be called without first stashing
the current frame.

The frame stash is used not only to speed up frame lookups, but
also to detect cycles.  When attempting to compute the frame id
for a "previous" frame (in get_prev_frame_if_no_cycle), a cycle
is detected if the computed frame id is already in the stash.

If it should happen that a previous frame id is stashed which should
represent a cycle for the current frame, then an assertion failure
will trigger should get_frame_id() be later called to determine
the frame id for the current frame.

As of late 2016, with the "Tweak meaning of VALUE_FRAME_ID" patch in
place, this actually occurs when running the
gdb.dwarf2/dw2-dup-frame.exp test.  While attempting to generate a
backtrace, the python frame filter code is invoked, leading to
frame_info_to_frame_object() (in python/py-frame.c) being called.
That function will potentially call get_prev_frame() before
get_frame_id() is called.  The call to get_prev_frame() can eventually
end up in get_prev_frame_if_no_cycle() which, in turn, calls
compute_frame_id(), after which the frame id is stashed for the
previous frame.

If the frame id for the current frame is stashed, the cycle detection
code (which relies on the frame stash) in get_prev_frame_if_no_cycle()
will be triggered for a cycle starting with the current frame.  If the
current frame's id is not stashed, the cycle detecting code can't
operate as designed.  Instead, when get_frame_id() is called on the
current frame at some later point, the current frame's id will found
to be already in the stash, triggering an assertion failure.

Below is an in depth examination of the failure which lead to this change.
I've shortened pathnames for brevity and readability.

Here's the portion of the log file showing the failure/internal error:

(gdb) break stop_frame
Breakpoint 1 at 0x40059a: file dw2-dup-frame.c, line 22.
(gdb) run
Starting program: testsuite/outputs/gdb.dwarf2/dw2-dup-frame/dw2-dup-frame

Breakpoint 1, stop_frame () at dw2-dup-frame.c:22
22 }
(gdb) bt
gdb/frame.c:544: internal-error: frame_id get_frame_id(frame_info*): Assertion `stashed' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n)
FAIL: gdb.dwarf2/dw2-dup-frame.exp: backtrace from stop_frame (GDB internal error)

Here's a partial backtrace from the internal error, showing the frames
which I think are relevant, plus several extra to provide context:

    #0  internal_error (
file=0x932b98 "gdb/frame.c", line=544,
fmt=0x932b20 "%s: Assertion `%s' failed.")
at gdb/common/errors.c:54
    #1  0x000000000072207e in get_frame_id (fi=0xe5a760)
at gdb/frame.c:544
    #2  0x00000000004eb50d in frame_info_to_frame_object (frame=0xe5a760)
at gdb/python/py-frame.c:390
    #3  0x00000000004ef5be in bootstrap_python_frame_filters (frame=0xe5a760,
frame_low=0, frame_high=-1)
at gdb/python/py-framefilter.c:1453
    #4  0x00000000004ef7a9 in gdbpy_apply_frame_filter (
extlang=0x8857e0 <extension_language_python>, frame=0xe5a760, flags=7,
args_type=CLI_SCALAR_VALUES, out=0xf6def0, frame_low=0, frame_high=-1)
at gdb/python/py-framefilter.c:1548
    #5  0x00000000005f2c5a in apply_ext_lang_frame_filter (frame=0xe5a760,
flags=7, args_type=CLI_SCALAR_VALUES, out=0xf6def0, frame_low=0,
frame_high=-1)
at gdb/extension.c:572
    #6  0x00000000005ea896 in backtrace_command_1 (count_exp=0x0, show_locals=0,
no_filters=0, from_tty=1)
at gdb/stack.c:1834

Examination of the code in frame_info_to_frame_object(), which is in
python/py-frame.c, is key to understanding this problem:

      if (get_prev_frame (frame) == NULL
  && get_frame_unwind_stop_reason (frame) != UNWIND_NO_REASON
  && get_next_frame (frame) != NULL)
{
  frame_obj->frame_id = get_frame_id (get_next_frame (frame));
  frame_obj->frame_id_is_next = 1;
}
      else
{
  frame_obj->frame_id = get_frame_id (frame);
  frame_obj->frame_id_is_next = 0;
}

I will first note that the frame id for frame has not been computed yet.  (This
was verified by placing a breakpoint on compute_frame_id().)

The call to get_prev_frame() causes the the frame id to (eventually) be
computed for the previous frame.  Here's a backtrace showing how we
get there:

    #0  compute_frame_id (fi=0x10e2810)
at gdb/frame.c:496
    #1  0x0000000000724a67 in get_prev_frame_if_no_cycle (this_frame=0xe5a760)
at gdb/frame.c:1871
    #2  0x0000000000725136 in get_prev_frame_always_1 (this_frame=0xe5a760)
at gdb/frame.c:2045
    #3  0x000000000072516b in get_prev_frame_always (this_frame=0xe5a760)
at gdb/frame.c:2061
    #4  0x000000000072570f in get_prev_frame (this_frame=0xe5a760)
at gdb/frame.c:2303
    #5  0x00000000004eb471 in frame_info_to_frame_object (frame=0xe5a760)
at gdb/python/py-frame.c:381

For this particular case, we end up in the else clause of the code above
which calls get_frame_id (frame).  It's at this point that the frame id
for frame is computed.  Again, here's a backtrace:

    #0  compute_frame_id (fi=0xe5a760)
at gdb/frame.c:496
    #1  0x000000000072203d in get_frame_id (fi=0xe5a760)
at gdb/frame.c:539
    #2  0x00000000004eb50d in frame_info_to_frame_object (frame=0xe5a760)
at gdb/python/py-frame.c:390

The test in question, dw2-dup-frame.exp, deliberately creates a broken
(cyclic) stack.  So, in this instance, the frame id for the prev
`frame' will be the same as that for `frame'.  But that particular
frame id ended up in the stash during the previous frame operation.
When, just a few lines later, we compute the frame id for `frame', the
id in question is already in the stash, thus triggering the assertion
failure.

I considered two other solutions to solving this problem:

We could prevent get_prev_frame() from being called before
get_frame_id() in frame_info_to_frame_object().  (See above for the
snippet of code where this happens.) A call to get_frame_id (frame)
could be placed ahead of that code snippet above.  I have tested this
approach and, while it does work, I can't be certain that
get_prev_frame() isn't called ahead of stashing the current frame
somewhere else in GDB, but in a less obvious way.

Another approach is to stash the current frame's id by calling
get_frame_id() in get_current_frame().  This approach is conceptually
simpler, but when importing a python unwinder, has the unwelcome side
effect of causing the unwinder to be called during import.

A cleaner looking fix would be to place this code after code
corresponding to the "Don't compute the frame id of the current frame
yet..." comment in get_prev_frame_if_no_cycle().  Sadly, this does not
work though; by the time we get to this point, the frame state for the
prev frame has been modified just enough to cause an internal error to
occur when attempting to compute the (current) frame id for inline
frames.  (The unexpected failure count increases by roughly 130
failures.)  Therefore, I decided to place it as early as possible
in get_prev_frame().

gdb/ChangeLog:

* frame.c (get_prev_frame): Stash frame id for current frame
prior to computing frame id for previous frame.

7 years agoMake gdb.PendingFrame.read_register handle "user" registers.
Kevin Buettner [Wed, 28 Sep 2016 05:45:19 +0000 (22:45 -0700)]
Make gdb.PendingFrame.read_register handle "user" registers.

The C function, pending_framepy_read_register(), which implements
the python interface gdb.PendingFrame.read_register does not handle
the so called "user" registers like "pc".  An assertion error is
triggered due to the user registers having numbers larger than or
equal to gdbarch_num_regs(gdbarch).

With the VALUE_FRAME_ID tweak in place, the call to
get_frame_register_value() can simply be replaced by a call to
value_of_register(), which handles both real registers as well as the
user registers.

gdb/ChangeLog:

* python/py-unwind.c (pending_framepy_read_register): Use
value_of_register() instead of get_frame_register_value().

7 years agoChange meaning of VALUE_FRAME_ID; rename to VALUE_NEXT_FRAME_ID
Kevin Buettner [Wed, 28 Sep 2016 04:18:44 +0000 (21:18 -0700)]
Change meaning of VALUE_FRAME_ID; rename to VALUE_NEXT_FRAME_ID

The VALUE_FRAME_ID macro provides access to a member in struct value
that's used to hold the frame id that's used when determining a
register's value or when assigning to a register.  The underlying
member has a long and obscure name.  I won't refer to it here, but
will simply refer to VALUE_FRAME_ID as if it's the struct value member
instead of being a convenient macro.

At the moment, without this patch in place, VALUE_FRAME_ID is set in
value_of_register_lazy() and several other locations to hold the frame
id of the frame passed to those functions.

VALUE_FRAME_ID is used in the lval_register case of
value_fetch_lazy().  To fetch the register's value, it calls
get_frame_register_value() which, in turn, calls
frame_unwind_register_value() with frame->next.

A python based unwinder may wish to determine the value of a register
or evaluate an expression containing a register.  When it does this,
value_fetch_lazy() will be called under some circumstances.  It will
attempt to determine the frame id associated with the frame passed to
it.  In so doing, it will end up back in the frame sniffer of the very
same python unwinder that's attempting to learn the value of a
register as part of the sniffing operation.  This recursion is not
desirable.

As noted above, when value_fetch_lazy() wants to fetch a register's
value, it does so (indirectly) by unwinding from frame->next.

With this in mind, a solution suggests itself:  Change VALUE_FRAME_ID
to hold the frame id associated with the next frame.  Then, when it
comes time to obtain the value associated with the register, we can
simply unwind from the frame corresponding to the frame id stored in
VALUE_FRAME_ID.  This neatly avoids the python unwinder recursion
problem by changing when the "next" operation occurs.  Instead of the
"next" operation occuring when the register value is fetched, it
occurs earlier on when assigning a frame id to VALUE_FRAME_ID.
(Thanks to Pedro for this suggestion.)

This patch implements this idea.

It builds on the patch "Distinguish sentinel frame from null frame".
Without that work in place, it's necessary to check for null_id at
several places and then obtain the sentinel frame.

It also renames most occurences of VALUE_FRAME_ID to
VALUE_NEXT_FRAME_ID to reflect the new meaning of this field.

There are several uses of VALUE_FRAME_ID which were not changed.  In
each case, the original meaning of VALUE_FRAME_ID is required to get
correct results.  In all but one of these uses, either
put_frame_register_bytes() or get_frame_register_bytes() is being
called with the frame value obtained from VALUE_FRAME_ID.  Both of
these functions perform some unwinding by performing a "->next"
operation on the frame passed to it.  If we were to use the new
VALUE_NEXT_FRAME_ID macro, this would effectively do two "->next"
operations, which is not what we want.

The VALUE_FRAME_ID macro has been redefined in terms of
VALUE_NEXT_FRAME_ID.  It simply fetches the previous frame's id,
providing this id as the value of the macro.

gdb/ChangeLog:

* value.h (VALUE_FRAME_ID): Rename to VALUE_NEXT_FRAME_ID. Update
comment.  Create new VALUE_FRAME_ID which is defined in terms of
VALUE_NEXT_FRAME_ID.
(deprecated_value_frame_id_hack): Rename to
deprecated_value_next_frame_id_hack.
* dwarf2loc.c, findvar.c, frame-unwind.c, sentinel-frame.c,
valarith.c, valops.c, value.c: Adjust nearly all occurences of
VALUE_FRAME_ID to VALUE_NEXT_FRAME_ID. Add comments for those
which did not change.
* value.c (struct value): Rename frame_id field to next_frame_id.
Update comment.
(deprecated_value_frame_id_hack): Rename to
deprecated_value_next_frame_id_hack.
(value_fetch_lazy): Call frame_unwind_register_value()
instead of get_frame_register_value().
* frame.c (get_prev_frame_id_by_id): New function.
* frame.h (get_prev_frame_id_by_id): Declare.
* dwarf2loc.c (dwarf2_evaluate_loc_desc_full): Make
VALUE_NEXT_FRAME_ID refer to the next frame.
* findvar.c (value_of_register_lazy): Likewise.
(default_value_from_register): Likewise.
(value_from_register): Likewise.
* frame_unwind.c (frame_unwind_got_optimized): Likewise.
* sentinel-frame.c (sentinel_frame_prev_register): Likewise.
* value.h (VALUE_FRAME_ID): Update comment describing this macro.

7 years agoDistinguish sentinel frame from null frame.
Kevin Buettner [Wed, 28 Sep 2016 03:33:38 +0000 (20:33 -0700)]
Distinguish sentinel frame from null frame.

This patch replaces the `current_frame' static global in frame.c with
`sentinel_frame'.  It also makes the sentinel frame id unique and
different from the null frame.

By itself, there is not much point to this patch, but it makes
the code cleaner for the VALUE_FRAME_ID changes in another patch.
Since we now allow "navigation" to the sentinel frame, it removes
the necessity of adding special cases to other parts of GDB.

Note that a new function, get_next_frame_sentinel_okay, is introduced
in this patch.  It will be used by the VALUE_FRAME_ID changes that
I've made.

Thanks to Pedro Alves for this suggestion.

gdb/ChangeLog:

     * frame.h (enum frame_id_stack_status): Add FID_STACK_SENTINEL.
     (struct frame_id): Increase number of bits required for storing
     stack status to 3 from 2.
     (sentinel_frame_id): New declaration.
     (get_next_frame_sentinel_okay): Declare.
     (frame_find_by_id_sentinel_okay): Declare.
     * frame.c (current_frame): Rename this static global to...
     (sentinel_frame): ...this static global, which has also been
     moved an earlier location in the file.
     (fprint_frame_id): Add case for sentinel frame id.
     (get_frame_id): Return early for sentinel frame.
     (sentinel_frame_id): Define.
     (frame_find_by_id): Add case for sentinel_frame_id.
     (create_sentinel_frame): Use sentinel_frame_id for this_id.value
     instead of null_frame_id.
     (get_current_frame): Add local declaration for `current_frame'.
     Remove local declaration for `sentinel_frame.'
     (get_next_frame_sentinel_okay): New function.
     (reinit_frame_cache): Use `sentinel_frame' in place of
     `current_frame'.

7 years agoExtend test gdb.python/py-recurse-unwind.exp
Kevin Buettner [Mon, 26 Sep 2016 22:00:37 +0000 (15:00 -0700)]
Extend test gdb.python/py-recurse-unwind.exp

This patch modifies the unwinder (sniffer) defined in
py-recurse-unwind.py so that, depending upon the value of one of its
class variables, it will take different paths through the code,
testing different functionality.

The original test attempted to obtain the value of an undefined
symbol.

This somewhat expanded test checks to see if 'pc' can be read via
gdb.PendingFrame.read_register() and also via gdb.parse_and_eval().

gdb/testsuite/ChangeLog:

* gdb.python/py-recurse-unwind.c (main): Add loop.
* gdb.python/py-recurse-unwind.py (TestUnwinder): Add calls
to read_register() and gdb.parse_and_eval().  Make each code
call a separate case that can be individually tested.
* gdb.python/py-recurse-unwind.exp (cont_and_backtrace): New
proc. Call cont_and_backtrace for each of the code paths that
we want to test in the unwinder.

7 years agoFix PR20789 - relaxation with negative valued diff relocs
Senthil Kumar Selvaraj [Wed, 16 Nov 2016 10:41:46 +0000 (16:11 +0530)]
Fix PR20789 - relaxation with negative valued diff relocs

Fix issues with diff relocs that have a negative value
i.e. sym2 - sym1 where sym2 is lesser than sym1.

The assembler generates a diff reloc with symbol as start of section
and addend as sym2 offset, and encodes assembly time difference at
the reloc offset.

The existing relaxation logic adjusts addends if the relaxed insn lies
between symbol and addend. That doesn't work for diff relocs where
sym2 is less than sym1 *and* the relaxed insn happens to be between
sym2 and sym1.

Fix the problems by

1. Using signed handling of the difference value (bfd_signed_vma instead
of bfd_vma, bfd_{get,set}_signed_xxx instead of bfd_{get,set}_xxx).

2. Not assuming sym2 is bigger than sym1. It instead computes the actual
addresses and sets the lower and higher addresses as start and end
addresses respectively and then sees if insn is between start and end.

3. Creating a new function elf32_avr_adjust_reloc_if_spans_insn to
centralize reloc adjustment, and ensuring diff relocs get adjusted
correctly even if their sym + addend doesn't overlap a relaxed insn.

It also removes a redundant variable did_pad. It is never set if
did_shrink is TRUE, and the code does a early return if did_shrink is
FALSE.

bfd/ChangeLog

2016-11-15  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>

       PR ld/20789
       * bfd/elf32-avr.c (elf32_avr_adjust_diff_reloc_value): Do signed
       manipulation of diff value, and don't assume sym2 is less than sym1.
       (elf32_avr_adjust_reloc_if_spans_insn): New function.
       (elf32_avr_relax_delete_bytes): Use elf32_avr_adjust_diff_reloc_value,
       and remove redundant did_pad.

ld/ChangeLog

2016-11-15  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>

       PR ld/20789
       * ld/testsuite/ld-avr/pr20789.d: New test.
       * ld/testsuite/ld-avr/pr20789.s: New test.

7 years agoAutomatic date update in version.in
GDB Administrator [Wed, 16 Nov 2016 00:00:20 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agogdb: update gnulib to pull in C++ namespace support fixes
Pedro Alves [Tue, 15 Nov 2016 19:29:14 +0000 (19:29 +0000)]
gdb: update gnulib to pull in C++ namespace support fixes

I've been experimenting with making use of gnulib's C++ namespace support:

 https://www.gnu.org/software/gnulib/manual/html_node/A-C_002b_002b-namespace-for-gnulib.html

That stumbled on a few gnulib issues, which I've fixed upstream:

 [PATCH] Fix gnulib C++ namespace support and std::frexp
 https://lists.gnu.org/archive/html/bug-gnulib/2016-11/msg00039.html

 [PATCH] Fix real-floating argument functions in C++ mode
 https://lists.gnu.org/archive/html/bug-gnulib/2016-11/msg00049.html

 [PATCH] Avoid having GNULIB_NAMESPACE::func always inject references to rpl_func
 https://lists.gnu.org/archive/html/bug-gnulib/2016-11/msg00040.html

 [PATCH] C++: "#define timeval rpl_timeval" -> typedef in GNULIB_NAMESPACE
 https://lists.gnu.org/archive/html/bug-gnulib/2016-11/msg00058.html

This merge pulls those in.

gdb/ChangeLog:
2016-11-15  Pedro Alves  <palves@redhat.com>

* gnulib/update-gnulib.sh (GNULIB_COMMIT_SHA1): Set to
38237baf99386101934cd93278023aa4ae523ec0.
* gnulib/configure, gnulib/config.in: Regenerate.
* gnulib/import/Makefile.am: Regenerate.
* gnulib/import/Makefile.in: Regenerate.
* gnulib/import/canonicalize-lgpl.c: Update.
* gnulib/import/extra/snippet/c++defs.h: Update.
* gnulib/import/m4/stdint.m4: Update.
* gnulib/import/m4/stdlib_h.m4: Update.
* gnulib/import/math.in.h: Update.
* gnulib/import/stdlib.in.h: Update.
* gnulib/import/sys_time.in.h: Update.

7 years agoDelete gdb::unique_ptr/gdb::move
Pedro Alves [Tue, 15 Nov 2016 19:54:21 +0000 (19:54 +0000)]
Delete gdb::unique_ptr/gdb::move

Now that we require C++11 and all uses of gdb::unique_ptr and
gdb::move are gone, let's remove their definitions...

With my lazy hat on, I repurposed the header for "generally useful
unique_ptr specializations", and left gdb::unique_xmalloc_ptr in
there.  Not sure whether we it'd be better move it out of the gdb
namespace or leave it be.  I left it because it's less work and avoids
disrupting yet-unmerged patches that use it.

gdb/ChangeLog:
2016-11-15  Pedro Alves  <palves@redhat.com>

* common/common-defs.h: Update comment.
* common/gdb_unique_ptr.h: Update header comment and copyright
year.
(gdb::unique_ptr, gdb::move): Delete.

7 years agogdb::{unique_ptr,move} -> std::{unique_ptr,move}
Pedro Alves [Tue, 15 Nov 2016 19:54:21 +0000 (19:54 +0000)]
gdb::{unique_ptr,move} -> std::{unique_ptr,move}

Now that we require C++11, use std::unique_ptr and std::move directly.

gdb/ChangeLog:
2016-11-15  Pedro Alves  <palves@redhat.com>

* ada-lang.c (create_excep_cond_exprs): Use std::move instead of
gdb::move.
* break-catch-throw.c (handle_gnu_v3_exceptions): Use
std::unique_ptr instead of gdb::unique_ptr.
* breakpoint.c (watch_command_1): Use std::move instead of
gdb::move.
* cli/cli-dump.c (dump_memory_to_file, restore_binary_file): Use
std::unique_ptr instead of gdb::unique_ptr.
* dtrace-probe.c (dtrace_process_dof_probe): Use std::move instead
of gdb::move.
* elfread.c (elf_read_minimal_symbols): Use std::unique_ptr
instead of gdb::unique_ptr.
* mi/mi-main.c (mi_cmd_data_read_memory): Use std::unique_ptr
instead of gdb::unique_ptr.
* parse.c (parse_expression_for_completion): Use std::move instead
of gdb::move.
* printcmd.c (display_command): std::move instead of gdb::move.

7 years agobitfield-parent-optimized-out: Fix struct definition
Andreas Arnez [Tue, 15 Nov 2016 19:52:03 +0000 (20:52 +0100)]
bitfield-parent-optimized-out: Fix struct definition

The "struct S" type in bitfield-parent-optimized-out.exp is declared to
have a size of 4 bytes but to hold two 4-byte members: an int-based
bitfield and a 4-byte int.  Also, both members have the same
data_member_location 2, causing them to overlap and to reach 2 bytes
beyond the structure's boundary.

This is fixed by increasing the structure size to 8 and setting the
first and second member's data_member_location to 0 and 4, respectively.

gdb/testsuite/ChangeLog:

* gdb.dwarf2/bitfield-parent-optimized-out.exp: Fix DWARF code for
the definition of struct S.

7 years agoFix SPARC relocations generated for the .eh_frame section.
Nick Clifton [Tue, 15 Nov 2016 15:41:27 +0000 (15:41 +0000)]
Fix SPARC relocations generated for the .eh_frame section.

PR gas/20803
* config/tc-sparc.c (cons_fix_new_sparc): Use unaligned relocs in
the .eh_frame section.

7 years agoAutomatic date update in version.in
GDB Administrator [Tue, 15 Nov 2016 00:00:20 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoAlso check GOT PLT for R_X86_64_PLTOFF64
H.J. Lu [Mon, 14 Nov 2016 18:13:03 +0000 (10:13 -0800)]
Also check GOT PLT for R_X86_64_PLTOFF64

Since "-z now" replaces PLT with GOT PLT, we should also check GOT PLT
for R_X86_64_PLTOFF64 relocation.

bfd/

PR ld/20800
* elf64-x86-64.c (elf_x86_64_relocate_section): Also check
plt_got.offset for R_X86_64_PLTOFF64.

ld/

PR ld/20800
* testsuite/ld-x86-64/pr20800a.S: New file.
* testsuite/ld-x86-64/pr20800b.S: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run PR ld/20800 test.

7 years agoGenerate correct hint value for IDATA6.
Rudy [Mon, 14 Nov 2016 16:30:45 +0000 (16:30 +0000)]
Generate correct hint value for IDATA6.

PR binutils/20814
* dlltool.c (struct export): Remove hint field.
(make_one_lib_file): Store the ordinal value for IDATA6 not the
hint.
(gen_lib_file): Delete reference to hint field.
(mangle_defs): Delete computation of hint field.

7 years agobtrace: read entire aux buffer
Markus Metzger [Fri, 14 Oct 2016 07:08:01 +0000 (09:08 +0200)]
btrace: read entire aux buffer

The data_head of a perf event data buffer grows indefinitely.  Users are
expected to compute data_head % data_size to find the location inside the perf
event data buffer.

The aux_head of a perf event aux buffer wraps around and always stays within the
perf event aux buffer.

Well, at least that's the behaviour for BTS and PT - where BTS uses the data
buffer and PT the aux buffer.

GDB does not read beyond data_head or aux_head.  This is OK for BTS but wrong
for PT.  It causes only a portion of the trace to be considered by GDB.  In the
extreme case, the buffer may appear (almost) empty.

Thanks to Tim Wiederhake  <tim.wiederhake@intel.com> for reporting the anomaly.

Change it to read the entire aux buffer for PT.  The buffer is initially zero so
any extra zeroes we read before aux_head wraps around the first time will be
ignored when searching for the first PSB packet in order to synchronize onto the
trace stream.

gdb/
* nat/linux-btrace.c (perf_event_read): Allow data_head < size.
* nat/linux-btrace.c (perf_event_read_all): Do not adjust size.

Change-Id: If4f8049a2080a5f16f336309450b32a3eb1e3ec9

7 years ago lexsup.c (parse_args): Add break at end of default case.
Nick Clifton [Mon, 14 Nov 2016 08:59:23 +0000 (08:59 +0000)]
  lexsup.c (parse_args): Add break at end of default case.

7 years agoFix typo "Faal through" should be "Fall through".
Nick Clifton [Mon, 14 Nov 2016 08:44:17 +0000 (08:44 +0000)]
Fix typo "Faal through" should be "Fall through".

7 years agoAutomatic date update in version.in
GDB Administrator [Mon, 14 Nov 2016 00:00:19 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoadd missing ChangeLog entry
Anthony Green [Sun, 13 Nov 2016 13:11:44 +0000 (08:11 -0500)]
add missing ChangeLog entry

7 years agoAssemble 'bad' moxie instruction
Anthony Green [Sun, 13 Nov 2016 12:37:02 +0000 (07:37 -0500)]
Assemble 'bad' moxie instruction

7 years agoAutomatic date update in version.in
GDB Administrator [Sun, 13 Nov 2016 00:00:20 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoRemove some cleanups from the rust code
Tom Tromey [Wed, 9 Nov 2016 03:32:50 +0000 (20:32 -0700)]
Remove some cleanups from the rust code

This removes some cleanups from the rust code, in favor of C++ objects
with destructors.

2016-11-12  Tom Tromey  <tom@tromey.com>

* rust-exp.y (super_name): Use std::vector.
(lex_number): Use std::string.
(convert_params_to_types): Return std::vector.
(convert_ast_to_type, convert_name): Update.
* rust-lang.c (rust_get_disr_info): Use unique_xmalloc_ptr.

7 years agoUse std::string in rust_get_disr_info
Tom Tromey [Wed, 9 Nov 2016 03:22:29 +0000 (20:22 -0700)]
Use std::string in rust_get_disr_info

This changes rust_get_disr_info to use std::string in one more spot,
avoiding a memory leak.

2016-11-12  Tom Tromey  <tom@tromey.com>

* rust-lang.c (rust_get_disr_info): Use std::string in one more
spot.

7 years agosim: mips: add PR info to ChangeLog
Mike Frysinger [Sat, 12 Nov 2016 06:02:23 +0000 (01:02 -0500)]
sim: mips: add PR info to ChangeLog

7 years agoAutomatic date update in version.in
GDB Administrator [Sat, 12 Nov 2016 00:00:19 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoDon't handle unavailable/optimized-out in spu_software_single_step
Yao Qi [Fri, 11 Nov 2016 16:50:42 +0000 (16:50 +0000)]
Don't handle unavailable/optimized-out in spu_software_single_step

When we do software single step, frame is always the innermost one,
so it is impossible to get unavailable/optimized-out errors.

gdb:

2016-11-11  Yao Qi  <yao.qi@linaro.org>

* spu-tdep.c (spu_software_single_step): Don't call
get_frame_register_bytes, call get_frame_register_unsigned
instead.

7 years ago Identify verilog dump tests as such.
Catherine Moore [Fri, 11 Nov 2016 15:42:37 +0000 (07:42 -0800)]
Identify verilog dump tests as such.

A couple of the verilog dump tests were marked as ihex tests.  This
patch identifies the tests as verilog format dump tests.

7 years agoAccept L and LL suffixes to integer constants.
Nick Clifton [Fri, 11 Nov 2016 15:13:07 +0000 (15:13 +0000)]
Accept L and LL suffixes to integer constants.

PR gas/20732
* expr.c (integer_constant): If tc_allow_L_suffix is defined and
non-zero then accept a L or LL suffix.
* testsuite/gas/sparc/pr20732.d: New test source file.
* testsuite/gas/sparc/pr20732.d: New test output file.
* testsuite/gas/sparc/sparc.exp: Run new test.

7 years agoExtend information displayed about objdump's output of dynamic symbols.
Nick Clifton [Fri, 11 Nov 2016 14:13:02 +0000 (14:13 +0000)]
Extend information displayed about objdump's output of dynamic symbols.

7 years agoAdd the ability for nm to display symbol version information.
Nick Clifton [Fri, 11 Nov 2016 11:49:45 +0000 (11:49 +0000)]
Add the ability for nm to display symbol version information.

PR binutils/20751
* nm.c (with_symbol_versions): New local variable.
(long_options): Add --with-symbol-versions.
(usage): Mention --with-symbol-versions.
(print_symbol): If with_symbol_versions is set then display the
version information associated with the symbol.
* NEWS: Mention the new feature.
* doc/binutils.texi (nm): Document the new option.
(objdump): Describe how symbol version information is displayed
for dynamic symbol dumps.
(readelf): Describe how symbol version information is displayed.
* testsuite/binutils-all/nm.exp: Add a test of the new feature.

7 years ago[AArch64] Add ARMv8.3 combined pointer authentication branch instructions
Szabolcs Nagy [Fri, 11 Nov 2016 10:43:15 +0000 (10:43 +0000)]
[AArch64] Add ARMv8.3 combined pointer authentication branch instructions

Add support for ARMv8.3 pointer authentication instructions
that are encoded as unconditional branch instructions.

opcodes/
2016-11-11  Szabolcs Nagy  <szabolcs.nagy@arm.com>

* aarch64-tbl.h (arch64_opcode_table): Add braa, brab, blraa, blrab, braaz,
brabz, blraaz, blrabz, retaa, retab, eretaa, eretab.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

gas/
2016-11-08  Szabolcs Nagy  <szabolcs.nagy@arm.com>

* testsuite/gas/aarch64/pac.s: Add ARMv8.3 branch instruction tests.
* testsuite/gas/aarch64/pac.d: Likewise.

7 years ago[AArch64] Add ARMv8.3 PACGA instruction
Szabolcs Nagy [Fri, 11 Nov 2016 10:39:46 +0000 (10:39 +0000)]
[AArch64] Add ARMv8.3 PACGA instruction

Add support for the ARMv8.3 PACGA instruction.

include/
2016-11-11  Szabolcs Nagy  <szabolcs.nagy@arm.com>

* opcode/aarch64.h (enum aarch64_opnd): Add AARCH64_OPND_Rm_SP.

opcodes/
2016-11-11  Szabolcs Nagy  <szabolcs.nagy@arm.com>

* aarch64-tbl.h (arch64_opcode_table): Add pacga.
(AARCH64_OPERANDS): Add Rm_SP.
* aarch64-opc.c (aarch64_print_operand): Handle AARCH64_OPND_Rm_SP.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

gas/
2016-11-11  Szabolcs Nagy  <szabolcs.nagy@arm.com>

* config/tc-aarch64.c (process_omitted_operand): Handle AARCH64_OPND_Rm_SP.
(parse_operands): Likewise.
* testsuite/gas/aarch64/pac.s: Add pacga.
* testsuite/gas/aarch64/pac.d: Add pacga.

7 years ago[AArch64] Add ARMv8.3 single source PAC instructions
Szabolcs Nagy [Fri, 11 Nov 2016 10:36:32 +0000 (10:36 +0000)]
[AArch64] Add ARMv8.3 single source PAC instructions

Add support for ARMv8.3 pointer authentication instructions
that are encoded as single source data processing instructions.

opcodes/
2016-11-08  Szabolcs Nagy  <szabolcs.nagy@arm.com>

* aarch64-tbl.h (arch64_opcode_table): Add pacia, pacib, pacda, pacdb, autia,
autib, autda, autdb, paciza, pacizb, pacdza, pacdzb, autiza, autizb, autdza,
autdzb, xpaci, xpacd.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

gas/testsuite/
2016-11-11  Szabolcs Nagy  <szabolcs.nagy@arm.com>

* testsuite/gas/aarch64/pac.s: New.
* testsuite/gas/aarch64/pac.d: New.

7 years ago[AArch64] Add ARMv8.3 pointer authentication key registers
Szabolcs Nagy [Fri, 11 Nov 2016 10:33:30 +0000 (10:33 +0000)]
[AArch64] Add ARMv8.3 pointer authentication key registers

Add support for system registers introduced in ARMv8.3
for pointer authentication.

opcodes/
2016-11-11  Szabolcs Nagy  <szabolcs.nagy@arm.com>

* aarch64-opc.c (aarch64_sys_regs): Add apiakeylo_el1, apiakeyhi_el1,
apibkeylo_el1, apibkeyhi_el1, apdakeylo_el1, apdakeyhi_el1,
apdbkeylo_el1, apdbkeyhi_el1, apgakeylo_el1 and apgakeyhi_el1.
(aarch64_sys_reg_supported_p): Add feature test for new registers.

gas/
2016-11-11  Szabolcs Nagy  <szabolcs.nagy@arm.com>

* testsuite/gas/aarch64/sysreg-3.s: New.
* testsuite/gas/aarch64/sysreg-3.d: New.
* testsuite/gas/aarch64/illegal-sysreg-3.l: New.
* testsuite/gas/aarch64/illegal-sysreg-3.d: New.

7 years ago[AArch64] Add ARMv8.3 instructions which are in the NOP space
Szabolcs Nagy [Fri, 11 Nov 2016 10:29:07 +0000 (10:29 +0000)]
[AArch64] Add ARMv8.3 instructions which are in the NOP space

This patch adds support for a subset of the ARMv8.3 pointer authentication
instructions: XPACLRI, PACIA1716, PACIB1716, AUTIA1716, AUTIA1716, PACIAZ,
PACIASP, PACIBZ, PACISP, AUTIAZ, AUTIASP, AUTIBZ, AUTIBSP.

These are aliases to HINT #0x7, HINT #0x8, HINT #0xa, HINT #0xc, HINT #0xe,
HINT #0x18, HINT #0x19, ..., HINT #0x1f respectively.

For more details about pointer authentication in ARMv8.3 see
https://community.arm.com/groups/processors/blog/2016/10/27/armv8-a-architecture-2016-additions

opcodes/
2016-11-11  Szabolcs Nagy  <szabolcs.nagy@arm.com>

* aarch64-tbl.h (aarch64_feature_v8_3, ARMV8_3, V8_3_INSN): New.
(arch64_opcode_table): Add xpaclri, pacia1716, pacib1716, autia1716,
autib1716, paciaz, paciasp, pacibz, pacibsp, autiaz, autiasp, autibz,
autibsp.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.

gas/
2016-11-11  Szabolcs Nagy  <szabolcs.nagy@arm.com>

* testsuite/gas/aarch64/system-3.s: New.
* testsuite/gas/aarch64/system-3.d: New.
* testsuite/gas/aarch64/system.d: Update expected output.

7 years ago[AArch64] Increase max_num_aliases in aarch64-gen
Szabolcs Nagy [Fri, 11 Nov 2016 10:22:56 +0000 (10:22 +0000)]
[AArch64] Increase max_num_aliases in aarch64-gen

Some ARMv8.3 pointer authentication instructions are encoded as HINT aliases,
so to allow more instruction aliases in the generator, max_num_aliases is
increased from 16 to 32.

opcodes/
2016-11-11  Szabolcs Nagy  <szabolcs.nagy@arm.com>

* aarch64-gen.c (find_alias_opcode): Increase max_num_aliases to 32.

7 years ago[AArch64] Add ARMv8.3 command line option and feature flag
Szabolcs Nagy [Fri, 11 Nov 2016 10:20:30 +0000 (10:20 +0000)]
[AArch64] Add ARMv8.3 command line option and feature flag

ARMv8.3 can be selected with -march=armv8.3-a command line option.
An overview of the ARMv8.3 architecture extension is at
https://community.arm.com/groups/processors/blog/2016/10/27/armv8-a-architecture-2016-additions

gas/
2016-11-11  Szabolcs Nagy  <szabolcs.nagy@arm.com>

* config/tc-aarch64.c (aarch64_archs): Add "armv8.3-a".
* doc/c-aarch64.texi (-march): Likewise.

include/
2016-11-11  Szabolcs Nagy  <szabolcs.nagy@arm.com>

* opcode/aarch64.h (AARCH64_FEATURE_V8_3): Define.
(AARCH64_ARCH_V8_3): Define.
(AARCH64_ARCH_V8_1, AARCH64_ARCH_V8_2): Simplify.

7 years ago[AArch64] Fix feature dependencies for +simd and +crypto
Szabolcs Nagy [Fri, 11 Nov 2016 10:14:31 +0000 (10:14 +0000)]
[AArch64] Fix feature dependencies for +simd and +crypto

According to the gas manual, +simd implies +fp and +crypto implies +simd.
Make sure +nofp turns +simd, +crypto and +fp16 off.

gas/
2016-11-07  Szabolcs Nagy  <szabolcs.nagy@arm.com>

* config/tc-aarch64.c (aarch64_features): Fix "simd" and "crypto".
* testsuite/gas/aarch64/illegal-crypto-nofp.d: New.
* testsuite/gas/aarch64/illegal-crypto-nofp.l: New.
* testsuite/gas/aarch64/illegal-fp16-nofp.d: New.
* testsuite/gas/aarch64/illegal-fp16-nofp.l: New.
* testsuite/gas/aarch64/illegal-fp16-nofp.s: New.

7 years agoAccept hidden COFF symbols, but treat them as if they were debugging symbols.
Luke Allardyce [Fri, 11 Nov 2016 10:08:05 +0000 (10:08 +0000)]
Accept hidden COFF symbols, but treat them as if they were debugging symbols.

PR ld/20722
* coffcode.h (coff_slurp_symbol_table): Accept C_HIDDEN symbols,
but treat them as debugging symbols.

7 years agoRemove apply_val_pretty_printer parameter valaddr
Yao Qi [Fri, 11 Nov 2016 08:38:31 +0000 (08:38 +0000)]
Remove apply_val_pretty_printer parameter valaddr

This patch removes the parameter valaddr of
extension_language_ops::apply_val_pretty_printer and remove const from
"struct value *val".  valaddr can be got in each extension language's
implementation of apply_val_pretty_printer.

gdb:

2016-11-11  Yao Qi  <yao.qi@linaro.org>

* cp-valprint.c (cp_print_value): Remove local base_valaddr.
* extension-priv.h (struct extension_language_ops)
<apply_val_pretty_printer>: Remove the second parameter.
Remove const from "struct value *".  Callers updated.
* extension.c (apply_ext_lang_val_pretty_printer): Update
comments.  Remove parameter valaddr.  Remove const from
"struct value *".
* extension.h (apply_ext_lang_val_pretty_printer): Update
declaration.
* guile/guile-internal.h (gdbscm_apply_val_pretty_printer):
Update declaration.
* guile/scm-pretty-print.c (gdbscm_apply_val_pretty_printer):
Remove parameter valaddr.  Remove const from "struct value *".
* python/py-prettyprint.c (gdbpy_apply_val_pretty_printer):
Likewise.
* python/python-internal.h (gdbpy_apply_val_pretty_printer):
Update declaration.

7 years agoRemove parameter valaddr from c print functions
Yao Qi [Fri, 11 Nov 2016 08:38:31 +0000 (08:38 +0000)]
Remove parameter valaddr from c print functions

This patch removes parameter valaddr from some c print functions.

gdb:

2016-11-11  Yao Qi  <yao.qi@linaro.org>

* c-lang.h (cp_print_value_fields): Update declaration.
* cp-valprint.c (cp_print_value): Update declaration.
(cp_print_value_fields): Remove parameter valaddr.  Callers
updated.
(cp_print_value): Likewise.

7 years agosim: mips: fix dv-tx3904cpu build error
Mike Frysinger [Fri, 11 Nov 2016 06:29:21 +0000 (01:29 -0500)]
sim: mips: fix dv-tx3904cpu build error

When building for mipstx39-rtems4.12 targets, some funcs use SD and CPU
implicitly.  Restore the defines for these to the local sd and cpu vars.

This was broken by the clean up in commit d47f5b30d8481272e9480118bdcb.

Reported-by: Joel Sherrill <joel.sherrill@oarcorp.com>
7 years agosim: mips: fix builds for r3900 cpus due to missing check_u64
Mike Frysinger [Fri, 11 Nov 2016 06:28:36 +0000 (01:28 -0500)]
sim: mips: fix builds for r3900 cpus due to missing check_u64

7 years agoAutomatic date update in version.in
GDB Administrator [Fri, 11 Nov 2016 00:00:08 +0000 (00:00 +0000)]
Automatic date update in version.in

8 years agoProvide a more helpful error message when the BFD library is unable to load an extrem...
Nick Clifton [Thu, 10 Nov 2016 12:26:53 +0000 (12:26 +0000)]
Provide a more helpful error message when the BFD library is unable to load an extremely large section.

PR target/20737
* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Bind defined
symbol locally in PIE.

8 years ago[AArch64] Bind defined symbol locally in PIE
Jiong Wang [Thu, 10 Nov 2016 09:25:17 +0000 (09:25 +0000)]
[AArch64] Bind defined symbol locally in PIE

bfd/
PR target/20737
* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Bind defined
symbol locally in PIE.

ld/
* testsuite/ld-aarch64/pie-bind-locally-a.s: New test source.
* testsuite/ld-aarch64/pie-bind-locally-b.s: Likewise.
* testsuite/ld-aarch64/pie-bind-locally.d: New testcase.
* testsuite/ld-aarch64/aarch64-elf.exp: Run new testcase.

8 years agoUse unique_xmalloc_ptr in Python code
Tom Tromey [Sat, 15 Oct 2016 15:20:02 +0000 (09:20 -0600)]
Use unique_xmalloc_ptr in Python code

This changes some utility functions in the Python code to return
unique_xmalloc_ptr, and then fixes up the callers.

I chose unique_xmalloc_ptr rather than std::string because at a few
call points the xmalloc'd string is released and ownership transferred
elsewhere.

This patch found a few existing memory leaks.  For example,
py-unwind.c called gdbpy_obj_to_string but never freed the result.

Built and regression tested on the buildbot.

2016-11-09  Tom Tromey  <tom@tromey.com>

* varobj.h (varobj_get_display_hint): Change return type.
* varobj.c (varobj_get_display_hint): Return unique_xmalloc_ptr.
(varobj_value_get_print_value): Update.
* python/python.c (gdbpy_before_prompt_hook, gdbpy_print_stack)
(gdbpy_apply_type_printers): Update.
* python/python-internal.h (unicode_to_target_string)
(python_string_to_target_string, python_string_to_host_string)
(gdbpy_obj_to_string, gdbpy_exception_to_string)
(gdbpy_get_display_hint): Change return types.
* python/py-varobj.c (py_varobj_iter_next): Update.
* python/py-value.c (valpy_getitem, convert_value_from_python):
Update.
* python/py-utils.c (unicode_to_encoded_string)
(unicode_to_target_string, python_string_to_target_string)
(python_string_to_host_string, gdbpy_obj_to_string)
(gdbpy_exception_to_string): Return unique_xmalloc_ptr.
* python/py-unwind.c (pyuw_parse_register_id): Update.
* python/py-type.c (typy_getitem): Update.
* python/py-prettyprint.c (gdbpy_get_display_hint)
(print_stack_unless_memory_error, print_children)
(gdbpy_apply_val_pretty_printer): Update.
* python/py-param.c (set_parameter_value): Update.
(get_doc_string, call_doc_function): Return unique_xmalloc_ptr.
(get_set_value, get_show_value, compute_enum_values, parmpy_init):
Update.
* python/py-infthread.c (thpy_set_name): Update.
* python/py-function.c (fnpy_call, fnpy_init): Update.
* python/py-framefilter.c (extract_sym): Change "name" to
unique_xmalloc_ptr.
(enumerate_args, enumerate_locals): Update.
(py_print_frame): Use unique_xmalloc_ptr.
* python/py-frame.c (frapy_read_var): Update.  Remove cleanup.
* python/py-cmd.c (cmdpy_function, cmdpy_completer, cmdpy_init):
Update.
* python/py-breakpoint.c (bppy_set_condition): Use
unique_xmalloc_ptr.
(bppy_init): Likewise.  Remove cleanup.
(local_setattro): Update.
* mi/mi-cmd-var.c (print_varobj, mi_cmd_var_list_children)
(varobj_update_one): Update.

8 years agoAutomatic date update in version.in
GDB Administrator [Thu, 10 Nov 2016 00:00:17 +0000 (00:00 +0000)]
Automatic date update in version.in

8 years agoX86: Remove the .s suffix from EVEX vpextrw
H.J. Lu [Wed, 9 Nov 2016 22:00:18 +0000 (14:00 -0800)]
X86: Remove the .s suffix from EVEX vpextrw

The .s suffix indicates that the instruction is encoded by swapping
2 register operands.  Since vpextrw takes an XMM register and an
integer register, the .s suffix should be ignored for EVEX vpextrw.

gas/

PR binutils/20799
* testsuite/gas/i386/opcode.s: Add a test for EVEX vpextrw.
* testsuite/gas/i386/opcode-intel.d: Updated.
* testsuite/gas/i386/opcode-suffix.d: Likewise.
* testsuite/gas/i386/opcode.d: Likewise.
* testsuite/gas/i386/x86-64-avx512bw-opts.s: Remove vpextrw
tests.
* testsuite/gas/i386/x86-64-avx512bw-opts-intel.d: Updated.
* testsuite/gas/i386/x86-64-avx512bw-opts.d: Likewise.

opcodes/

PR binutils/20799
* i386-dis-evex.h (evex_table): Replace EdqwS with Edqw.
* i386-dis.c (EdqwS): Removed.
(dqw_swap_mode): Likewise.
(intel_operand_size): Don't check dqw_swap_mode.
(OP_E_register): Likewise.
(OP_E_memory): Likewise.
(OP_G): Likewise.
(OP_EX): Likewise.
* i386-opc.tbl: Remove "S" from EVEX vpextrw.
* i386-tbl.h: Regerated.

8 years agoUpdate opcodes/ChangeLog
H.J. Lu [Wed, 9 Nov 2016 21:44:42 +0000 (13:44 -0800)]
Update opcodes/ChangeLog

8 years agoX86: Update opcode-suffix.d
H.J. Lu [Wed, 9 Nov 2016 20:11:50 +0000 (12:11 -0800)]
X86: Update opcode-suffix.d

PR binutils/20754
* testsuite/gas/i386/opcode-suffix.d: Updated.

8 years agoFurther cleanup/modernization of gdb.base/commands.exp
Pedro Alves [Wed, 9 Nov 2016 18:48:25 +0000 (18:48 +0000)]
Further cleanup/modernization of gdb.base/commands.exp

 - Use multi_line for matching multi-line GDB output.

 - Add a multi_line_input variant of multi_line to build GDB input and
   use it throughout.

   (The two changes above make the tests much more readable, IMO.)

 - Add a new valnum_re global to get rid of the multiple "\\\$\[0-9\]*".

 - Remove gdb_stop_suppressing_tests uses.

 - tighten a few regexps.

 - Replace send_gdb/gdb_expect with gdb_test_multiple and simplify,
   making pass/fail messages the same.

gdb/ChangeLog:
2016-11-09  Pedro Alves  <palves@redhat.com>

* gdb.base/commands.exp (runto_or_return): New procedure.
(gdbvar_simple_if_test, gdbvar_simple_while_test)
(gdbvar_complex_if_while_test, progvar_simple_if_test)
(progvar_simple_while_test, progvar_complex_if_while_test)
(if_while_breakpoint_command_test)
(infrun_breakpoint_command_test, breakpoint_command_test)
(user_defined_command_test, watchpoint_command_test)
(test_command_prompt_position, redefine_hook_test)
(stray_arg0_test, error_clears_commands_left, redefine_hook_test)
(redefine_backtrace_test): Use runto_or_return, $valnum_re,
multi_line_input and multi_line.  Remove gdb_expect and
gdb_stop_suppressing_tests uses.
* lib/gdb.exp (valnum_re): New global.
* lib/gdb.exp (valnum_re): New global.
(multi_line_input): New procedure.

8 years agoX86: Merge AVX512F vmovq
H.J. Lu [Wed, 9 Nov 2016 18:20:13 +0000 (10:20 -0800)]
X86: Merge AVX512F vmovq

AVX512F vmovq doesn't support masking.  We can't swap register operand
in AVX512F vmovq with Reg64 since Reg64 != RegXMM.  This patch merges
AVX512F vmovq.

* i386-opc.tbl: Merge AVX512F vmovq.

8 years agoMake gdb.mi/user-selected-context-sync.exp use proc_with_prefix
Simon Marchi [Wed, 9 Nov 2016 15:55:14 +0000 (10:55 -0500)]
Make gdb.mi/user-selected-context-sync.exp use proc_with_prefix

Pedro's patch provides a cleaner way to prefix tests with the proc name,
so let's use that.

gdb/testsuite/ChangeLog:

* gdb.mi/user-selected-context-sync.exp (with_test_prefix_procname):
Remove.
(test_setup): Define with proc_with_prefix.
(test_cli_inferior): Likewise.
(test_cli_thread): Likewise.
(test_cli_frame): Likewise.
(test_cli_select_frame): Likewise.
(test_cli_up_down): Likewise.
(test_mi_thread_select): Likewise.
(test_mi_stack_select_frame): Likewise.
(test_cli_in_mi_inferior): Likewise.
(test_cli_in_mi_thread): Likewise.
(test_cli_in_mi_frame): Likewise.
(top level): Do not use with_test_prefix_procname.

8 years agogdb/testsuite: Introduce "proc_with_prefix"
Pedro Alves [Wed, 9 Nov 2016 15:45:49 +0000 (15:45 +0000)]
gdb/testsuite: Introduce "proc_with_prefix"

While adding new tests to gdb.base/commands.exp, I noticed that the
file includes a bunch of individual testcases split into their own
procedures, and that none have ever been adjusted to use
with_test_prefix.  Instead, each gdb_test/gdb_test_multiple/etc
invocation takes care of including the procedure name in the test
message, in order to make sure test messages are unique.

Simon convinced me that using the procedure name as prefix is not that
bad of an idea:
  https://sourceware.org/ml/gdb-patches/2016-10/msg00020.html

This commit adds an IMO simpler alternative to
with_test_prefix_procname added by that patch -- a new
"proc_with_prefix" convenience proc that is meant to be used in place
of "proc", and then uses it in commands.exp.  Procedures defined with
this automatically run their bodies under with_test_prefix $proc_name.

Here's a sample of the resulting gdb.sum diff:

 [...]
 -PASS: gdb.base/commands.exp: break factorial #3
 -PASS: gdb.base/commands.exp: set value to 5 in test_command_prompt_position
 -PASS: gdb.base/commands.exp: if test in test_command_prompt_position
 -PASS: gdb.base/commands.exp: > OK in test_command_prompt_position
 +PASS: gdb.base/commands.exp: test_command_prompt_position: break factorial
 +PASS: gdb.base/commands.exp: test_command_prompt_position: set value to 5
 +PASS: gdb.base/commands.exp: test_command_prompt_position: if test
 +PASS: gdb.base/commands.exp: test_command_prompt_position: > OK
 [...]

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

* gdb.base/commands.exp (gdbvar_simple_if_test)
(gdbvar_simple_while_test, gdbvar_complex_if_while_test)
(progvar_simple_if_test, progvar_simple_while_test)
(progvar_complex_if_while_test, if_while_breakpoint_command_test)
(infrun_breakpoint_command_test, breakpoint_command_test)
(user_defined_command_test, watchpoint_command_test)
(test_command_prompt_position, deprecated_command_test)
(bp_deleted_in_command, temporary_breakpoint_commands)
(stray_arg0_test, source_file_with_indented_comment)
(recursive_source_test, if_commands_test)
(error_clears_commands_left, redefine_hook_test)
(redefine_backtrace_test): Use proc_with_prefix.
* lib/gdb.exp (proc_with_prefix): New proc.

8 years agoFix formattting of gdb/ChangeLog and gdb/testsuite/ChangeLog enties
Pedro Alves [Wed, 9 Nov 2016 15:09:31 +0000 (15:09 +0000)]
Fix formattting of gdb/ChangeLog and gdb/testsuite/ChangeLog enties

Leading tab/spaces.  Missing periods.  Duplicate date.

8 years agoagent_expr_up: gdb::unique_ptr -> std::unique_ptr
Pedro Alves [Wed, 9 Nov 2016 12:49:43 +0000 (12:49 +0000)]
agent_expr_up: gdb::unique_ptr -> std::unique_ptr

Now that we require C++11, use std::unique_ptr directly.  This allows
simplifying collection_list a bit by placing unique pointers in the
vector directly, making the vector own its elements.

gdb/ChangeLog:
2016-11-09  Pedro Alves  <palves@redhat.com>

* ax-gdb.c (agent_eval_command_one): Use std::move instead of
gdb::move.
* ax.h (agent_expr_up): Use std::unique_ptr instead of
gdb::unique_ptr.
* breakpoint.c (parse_cond_to_aexpr): Use std::move instead of
gdb::move.
* tracepoint.c (collection_list::collect_symbol): Likewise.
(collection_list::~collection_list): Delete.
(encode_actions_1): Use std::move instead of gdb::move.
(collection_list::add_aexpr): Use std::move instead of
unique_ptr::release.
* tracepoint.h (collection_list) <~collection_list>: Delete
declaration.
<m_aexprs>: Now a vector of agent_ptr_up.

8 years agogdb: Use vector::emplace_back
Pedro Alves [Wed, 9 Nov 2016 14:53:58 +0000 (14:53 +0000)]
gdb: Use vector::emplace_back

Now that we require C++11, we can use vector::emplace_back to
construct elements in place instead of constructing and then copying.

gdb/ChangeLog:
2016-11-09  Pedro Alves  <palves@redhat.com>

* main.c (struct cmdarg): Add constructor.
(captured_main_1): Use vector::emplace_back.
* tracepoint.c (collection_list::add_memrange): Likewise.

8 years agotui-winsource: Remove failed-allocation logic
Andreas Arnez [Wed, 9 Nov 2016 12:02:13 +0000 (13:02 +0100)]
tui-winsource: Remove failed-allocation logic

This removes dead code in tui_alloc_source_buffer for handling a NULL
return value from xmalloc.

gdb/ChangeLog:

* tui/tui-winsource.c (tui_alloc_source_buffer): Remove
failed-xmalloc handling.

8 years agotui-winsource: Allocate for actual lines only
Andreas Arnez [Wed, 9 Nov 2016 12:02:13 +0000 (13:02 +0100)]
tui-winsource: Allocate for actual lines only

The logic for allocating a TUI source window's content buffer allocates
two more lines than needed, because it does not reduce the window height
by the highlight box's overhead.  However, it does reduce the line width
accordingly.  This patch makes the height and width calculation
consistent and improves the comment.

gdb/ChangeLog:

* tui/tui-winsource.c (tui_alloc_source_buffer): Subtract
highlight box's overhead when calculating the content height.

8 years agotui-disasm: Fix line buffer size calculation
Andreas Arnez [Wed, 9 Nov 2016 12:02:13 +0000 (13:02 +0100)]
tui-disasm: Fix line buffer size calculation

The code that fills the TUI disassembly window content first calculates
the maximum full length of a displayed disassembly line.  This
calculation typically yields the wrong result.  The result is too large,
so the bug does not cause any run-time failures, but unnecessary
confusion for the reader.  This patch fixes the calculation.

gdb/ChangeLog:

* tui/tui-disasm.c (tui_set_disassem_content): Fix calculation of
the longest disassembly line's length.

8 years agotui-disasm: Fix window content buffer overrun
Andreas Arnez [Wed, 9 Nov 2016 12:02:12 +0000 (13:02 +0100)]
tui-disasm: Fix window content buffer overrun

A user reported a GDB crash with TUI when trying to debug a function
with a long demangled C++ method name.  It turned out that the logic for
displaying the TUI disassembly window has a bug that can cause a buffer
overrun, possibly overwriting GDB-internal data structures.  In
particular, the logic performs an unguarded strcpy.

Another (harmless) bug in tui_alloc_source_buffer causes the buffer to
be two lines longer than needed.  This may have made the crash appear
less frequently.

gdb/ChangeLog:

* tui/tui-disasm.c (tui_set_disassem_content): Fix line buffer
overrun due to unchecked strcpy.

gdb/testsuite/ChangeLog:

* gdb.base/tui-layout.c: New file.
* gdb.base/tui-layout.exp: Use tui-layout.c, to ensure that the
disassembly window contains very long lines.

8 years agodarwin-nat.c: handle Darwin 16 (aka Sierra).
Tristan Gingold [Wed, 9 Nov 2016 09:25:00 +0000 (10:25 +0100)]
darwin-nat.c: handle Darwin 16 (aka Sierra).

Support message from new task and dead name notification on task of an
existing process.
With Sierra, exec(2) terminate the current task and creates a new one.
'set startup-with-shell off' must still be used on Darwin 16.

2016-11-09  Tristan Gingold  <gingold@adacore.com>

* darwin-nat.c (find_inferior_task_it): Fix indentation.
(find_inferior_notify_it): Remove.
(find_inferior_pid_it): New function.
(darwin_find_inferior_by_notify): Remove.
(darwin_find_inferior_by_pid): New function.
(darwin_find_new_inferior): New function.
(darwin_check_message_ndr): New function from
darwin_decode_exception_message.
(darwin_decode_exception_message): Call darwin_check_message_ndr.
Handle SIGTRAP addressed to an unknown task (when a task spawned).
(darwin_decode_notify_message): New function.
(darwin_decode_message): Handle unknown task.
(darwin_deallocate_threads): New function from darwin_mourn_inferior.
(darwin_mourn_inferior): Use darwin_deallocate_threads and
darwin_deallocate_exception_ports.
(darwin_deallocate_exception_ports): New function from
darwin_mourn_inferior.
(darwin_setup_exceptions): New function from darwin_attach_pid.
(darwin_setup_request_notification): Likewise.
(darwin_attach_pid): Call darwin_setup_request_notification and
darwin_setup_request_notification.

8 years agoAutomatic date update in version.in
GDB Administrator [Wed, 9 Nov 2016 00:00:27 +0000 (00:00 +0000)]
Automatic date update in version.in

8 years agoX86: Remove the THREE_BYTE_0F7A entry
H.J. Lu [Tue, 8 Nov 2016 19:03:06 +0000 (11:03 -0800)]
X86: Remove the THREE_BYTE_0F7A entry

Remove the THREE_BYTE_0F7A entry which is leftover from SSE5.

PR binutils/20701
* i386-dis.c (THREE_BYTE_0F7A): Removed.
(dis386_twobyte): Don't use THREE_BYTE_0F7A.
(three_byte_table): Remove THREE_BYTE_0F7A.

8 years agoFix py-value.exp failure on Python 3
Tom Tromey [Mon, 31 Oct 2016 17:23:34 +0000 (11:23 -0600)]
Fix py-value.exp failure on Python 3

I happened to notice that one test in py-value.exp did not work
properly with Python 3.  This patch fixes the problem.

2016-11-08  Tom Tromey  <tom@tromey.com>

* gdb.python/py-value.exp (test_value_creation): Make "long" test
depend on Python 2.

8 years agoFix some error-handling bugs in python frame filters
Tom Tromey [Mon, 31 Oct 2016 17:10:35 +0000 (11:10 -0600)]
Fix some error-handling bugs in python frame filters

While writing a Python frame filter, I found a few bugs in the current
frame filter code.  In particular:

* One spot converts a Python long to a CORE_ADDR using PyLong_AsLong.
  However, this can fail on overflow.  I changed this to use
  get_addr_from_python.

* Another spot is doing the same but with PyLong_AsUnsignedLongLong; I
  changed this as well just for consistency.

* Converting line numbers can print "-1" if conversion from long
  fails.  This isn't fatal but just a bit ugly.

I've included a test case for the first issue.  The line number one
didn't seem important enough to bother with.

2016-11-08  Tom Tromey  <tom@tromey.com>

* python/py-framefilter.c (py_print_frame): Use
get_addr_from_python.  Check for errors when getting line number.

2016-11-08  Tom Tromey  <tom@tromey.com>

* gdb.python/py-framefilter.py (ElidingFrameDecorator.address):
New method.

8 years agoRemove parameter valaddr from la_val_print
Yao Qi [Tue, 8 Nov 2016 16:02:42 +0000 (16:02 +0000)]
Remove parameter valaddr from la_val_print

Nowadays, we pass both val and return value of
value_contents_for_printing (val) to la_val_print.  The latter is
unnecessary.  This patch removes the second parameter of la_val_print,
and get valaddr in each language's implementation by calling
value_contents_for_printing.  Since value_contents_for_printing calls
value_fetch_lazy, I also make VAL non-const.

Note that
 - I don't clean up the valaddr usages in each language's routines,
 - I don't remove valaddr from apply_ext_lang_val_pretty_printer, and
   extension language ops apply_val_pretty_printer.

They can be done in followup patches.

gdb:

2016-11-08  Yao Qi  <yao.qi@linaro.org>

* ada-lang.h (ada_val_print): Remove second parameter.  Remove
const from "struct value *".
* ada-valprint.c (print_field_values): Remove const from
"struct value *".
(val_print_packed_array_elements): Likewise.
(print_variant_part): Likewise.
(ada_val_print_string): Likewise.
(ada_val_print_gnat_array): Likewise.
(ada_val_print_ptr): Likewise.
(ada_val_print_num): Likewise.
(ada_val_print_enum): Likewise.
(ada_val_print_flt): Likewise.
(ada_val_print_union): Likewise.
(ada_val_print_struct_union): Likewise.
(ada_val_print_ref): Likewise.
(ada_val_print_1): Remove second parameter.  Remove const from
"struct value *".
(ada_val_print): Likewise.
* c-lang.h (c_val_print): Likewise.
* c-valprint.c (c_val_print_array): Remove const from
"struct value *".
(c_val_print_ptr): Likewise.
(c_val_print_struct): Likewise.
(c_val_print_union): Likewise.
(c_val_print_int): Likewise.
(c_val_print_memberptr): Likewise.
(c_val_print): Remove second parameter.  Remove const from
"struct value *".  All callers updated.
* cp-valprint.c (cp_print_value): Remove const from
"struct value *".
(cp_print_value_fields): Likewise.
(c_val_print_value): Likewise.
* d-lang.h (d_val_print): Remove second parameter.  Remove const
from "struct value *".
* d-valprint.c (dynamic_array_type): Likewise.
(d_val_print): Likewise.
* f-lang.h (f_val_print): Likewise.
* f-valprint.c (f_val_print): Likewise.
* go-lang.h (go_val_print): Likewise.
* go-valprint.c (print_go_string): Likewise.
(go_val_print): Likewise.
* language.c (unk_lang_val_print): Likewise.
* language.h (struct language_defn) <la_val_print>: Likewise.
Update comments.
(LA_VAL_PRINT): Remove.
* m2-lang.h (m2_val_print): Remove const from
"struct value *".
* m2-valprint.c (m2_print_array_contents): Likewise.
(m2_val_print): Likewise.
* p-lang.h (pascal_val_print): Remove second parameter.  Remove
const from "struct value *".
(pascal_object_print_value_fields): Likewise.
* p-valprint.c (pascal_val_print): Likewise.
(pascal_object_print_value_fields): Likewise.
(pascal_object_print_value): Likewise.
* rust-lang.c (rust_get_disr_info): Likewise.
(val_print_struct): Likewise.
(rust_val_print): Likewise.
* valprint.c (generic_val_print_array): Likewise.
(generic_val_print_ptr): Likewise.
(generic_val_print_memberptr): Likewise.
(generic_val_print_ref): Likewise.
(generic_val_print_enum): Likewise.
(generic_val_print_flags): Likewise.
(generic_val_print_func): Likewise.
(generic_val_print_bool): Likewise.
(generic_val_print_int): Likewise.
(generic_val_print_char): Likewise.
(generic_val_print_float): Likewise.
(generic_val_print_decfloat): Likewise.
(generic_val_print_complex): Likewise.
(generic_val_print): Likewise.
(val_print): Likewise.
(common_val_print): Likewise.
(val_print_type_code_flags): Likewise.
(val_print_scalar_formatted): Likewise.
(val_print_array_elements): Likewise.
* valprint.h (val_print_array_elements): Update declaration.
(val_print_scalar_formatted): Likewise.
(generic_val_print): Likewise.
* value.h (val_print): Likewise.

8 years agoUse get_frame_register_value instead of deprecated_frame_register_read
Yao Qi [Tue, 8 Nov 2016 15:58:47 +0000 (15:58 +0000)]
Use get_frame_register_value instead of deprecated_frame_register_read

This patch calls get_frame_register_value instead of
deprecated_frame_register_read, so that we can pass
value_contents_for_printing to val_print.  Both
get_frame_register_value and deprecated_frame_register_read call
frame_unwind_register_value indirectly, so no functionality is changed
by this patch.

gdb:

2016-11-08  Yao Qi  <yao.qi@linaro.org>

* mt-tdep.c (mt_registers_info): Call
get_frame_register_value instead of
deprecated_frame_register_read.
* sh64-tdep.c (sh64_do_register): Likewise.

8 years agoEliminate agent_expr_p; VEC -> std::vector in struct bp_target_info
Pedro Alves [Tue, 8 Nov 2016 15:26:47 +0000 (15:26 +0000)]
Eliminate agent_expr_p; VEC -> std::vector in struct bp_target_info

After the previous patch, we end up with these two types with quite
similar, and potentially confusing names:

  typedef gdb::unique_ptr<agent_expr> agent_expr_up;

  /* Pointer to an agent_expr structure.  */
  typedef struct agent_expr *agent_expr_p;

The latter is only necessary to put agent_expr pointers in VECs.  So
just eliminate it and use std::vector instead.

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

* ax.h (agent_expr_p): Delete.
(DEF_VEC_P (agent_expr_p)): Delete.
* breakpoint.c (build_target_condition_list)
(build_target_command_list): Adjust to use of std::vector.
(bp_location_dtor): Remove now unnecessary VEC_free calls.
* breakpoint.h: Include <vector>.
(struct bp_target_info) <conditions, tcommands>: Now
std::vector's.
* remote.c (remote_add_target_side_condition): bp_tgt->conditions
is now a std::vector; adjust.
(remote_add_target_side_commands, remote_insert_breakpoint):
bp_tgt->tcommands is now a std::vector; adjust.

8 years ago'struct agent_expr *' -> unique_ptr<agent_expr>
Pedro Alves [Tue, 8 Nov 2016 15:26:47 +0000 (15:26 +0000)]
'struct agent_expr *' -> unique_ptr<agent_expr>

This patch makes the gen_* functions return a unique_ptr instead of
raw pointer:

  typedef gdb::unique_ptr<agent_expr> agent_expr_up;

and then adjusts the codebase throughout to stop using
make_cleanup_free_agent_expr.

The cond_bytecode and cmd_bytecode fields of struct bp_location are
owning pointers, so they're changed to be unique_ptr's instead of raw
pointers.

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

* ax-gdb.c (is_nontrivial_conversion): Use agent_expr_up.
(gen_trace_for_var, gen_trace_for_expr, gen_eval_for_expr)
(gen_trace_for_return_address, gen_printf): Use and return an
agent_expr_up.  Don't use make_cleanup_free_agent_expr.
(agent_eval_command_one, maint_agent_printf_command): Use
agent_expr_up.  Don't use make_cleanup_free_agent_expr.
* ax-gdb.h (gen_trace_for_expr, gen_trace_for_var)
(gen_trace_for_return_address, gen_eval_for_expr, gen_printf): Use
agent_expr_up.
* ax-general.c (new_agent_expr): Rename to ...
(agent_expr::agent_expr): ... this, and now a constructor.
(free_agent_expr): Rename to ...
(agent_expr::~agent_exp): ... this, and now a destructor.
(do_free_agent_expr_cleanup, make_cleanup_free_agent_expr):
Delete.
* ax.h (struct agent_expr): Add ctor/dtor.
(agent_expr_up): New typedef.
(new_agent_expr, free_agent_expr, make_cleanup_free_agent_expr):
Delete declarations.
* breakpoint.c (parse_cond_to_aexpr): Use and return an
agent_expr_up.  Don't use make_cleanup_free_agent_expr.
(build_target_condition_list): Adjust to use agent_expr_up.
(parse_cmd_to_aexpr): Use and return an agent_expr_up.  Don't use
make_cleanup_free_agent_expr.
(build_target_command_list): Adjust to use agent_expr_up.
(force_breakpoint_reinsertion): Adjust to use agent_expr_up.
(bp_location_dtor): Remove unnecessary free_agent_expr and xfree
calls.
* breakpoint.h (struct bp_target_info) <cond_bytecode,
cmd_bytecode>: Now agent_expr_up's.
* remote.c (remote_download_tracepoint): Adjust to use
agent_expr_up and remove use of make_cleanup_free_agent_expr.
* tracepoint.c (validate_actionline, collect_symbol): Adjust to
use agent_expr_up and remove uses of make_cleanup_free_agent_expr.
(collection_list::~collection_list): Call delete instead of
free_agent_expr.
(encode_actions_1): Adjust to use agent_expr_up and remove uses of
make_cleanup_free_agent_expr.
(add_aexpr): Change parameter type to agent_expr_up; Return a raw
agent_expr pointer.

8 years agoUse ui_file_as_string throughout more
Pedro Alves [Tue, 8 Nov 2016 15:26:47 +0000 (15:26 +0000)]
Use ui_file_as_string throughout more

This replaces most of the remaining ui_file_xstrdup calls with
ui_file_as_string calls.  Whenever a call was replaced, that led to a
cascade of other necessary adjustments throughout, to make the code
use std::string instead of raw pointers.  And then whenever I added a
std::string as member of a struct, I needed to adjust
allocation/destruction of said struct to use new/delete instead of
xmalloc/xfree.

The stopping point was once gdb built again.  These doesn't seem to be
a way to reasonably split this out further.

Maybe-not-obvious changes:

 - demangle_for_lookup returns a cleanup today.  To get rid of that,
   and avoid unnecessary string dupping/copying, this introduces a
   demangle_result_storage type that the caller instantiates and
   passes to demangle_for_lookup.

 - Many methods returned a "char *" to indicate that the caller owns
   the memory and must free it.  Those are switched to return a
   std::string instead.  Methods that return a "view" into some
   internal string return a "const char *" instead.  I.e., we only
   copy/allocate when necessary.

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

* ada-lang.c (ada_name_for_lookup, type_as_string): Use and return
std::string.
(type_as_string_and_cleanup): Delete.
(ada_lookup_struct_elt_type): Use type_as_string.
* ada-lang.h (ada_name_for_lookup): Now returns std::string.
* ada-varobj.c (ada_varobj_scalar_image): Return a std::string.
(ada_varobj_describe_child): Make 'child_name' and
'child_path_expr' parameters std::string pointers.
(ada_varobj_describe_struct_child, ada_varobj_describe_ptr_child):
Likewise, and use string_printf.
(ada_varobj_describe_simple_array_child)
(ada_varobj_describe_child): Likewise.
(ada_varobj_get_name_of_child, ada_varobj_get_path_expr_of_child)
(ada_varobj_get_value_image)
(ada_varobj_get_value_of_array_variable)
(ada_varobj_get_value_of_variable, ada_name_of_variable)
(ada_name_of_child, ada_path_expr_of_child)
(ada_value_of_variable): Now returns std::string.  Use
string_printf.
(ada_value_of_child): Adjust.
* break-catch-throw.c (check_status_exception_catchpoint): Adjust
to use std::string.
* breakpoint.c (watch_command_1): Adjust to use std::string.
* c-lang.c (c_get_string): Adjust to use std::string.
* c-typeprint.c (print_name_maybe_canonical): Use std::string.
* c-varobj.c (varobj_is_anonymous_child): Use ==/!= std::string
operators.
(c_name_of_variable): Now returns a std::string.
(c_describe_child): The 'cname' and 'cfull_expression' output
parameters are now std::string pointers.  Adjust.
(c_name_of_child, c_path_expr_of_child, c_value_of_variable)
(cplus_number_of_children): Adjust to use std::string and
string_printf.
(cplus_name_of_variable): Now returns a std::string.
(cplus_describe_child): The 'cname' and 'cfull_expression' output
parameters are now std::string pointers.  Adjust.
(cplus_name_of_child, cplus_path_expr_of_child)
(cplus_value_of_variable): Now returns a std::string.
* cp-abi.c (cplus_typename_from_type_info): Return std::string.
* cp-abi.h (cplus_typename_from_type_info): Return std::string.
(struct cp_abi_ops) <get_typename_from_type_info>: Return
std::string.
* cp-support.c (inspect_type): Use std::string.
(cp_canonicalize_string_full, cp_canonicalize_string_no_typedefs)
(cp_canonicalize_string): Return std::string and adjust.
* cp-support.h (cp_canonicalize_string)
(cp_canonicalize_string_no_typedefs, cp_canonicalize_string_full):
Return std::string.
* dbxread.c (read_dbx_symtab): Use std::string.
* dwarf2read.c (dwarf2_canonicalize_name): Adjust to use std::string.
* gdbcmd.h (lookup_struct_elt_type): Adjust to use std::string.
* gnu-v3-abi.c (gnuv3_get_typeid): Use std::string.
(gnuv3_get_typename_from_type_info): Return a std::string and
adjust.
(gnuv3_get_type_from_type_info): Adjust to use std::string.
* guile/guile.c (gdbscm_execute_gdb_command): Adjust to use
std::string.
* infcmd.c (print_return_value_1): Adjust to use std::string.
* linespec.c (find_linespec_symbols): Adjust to
demangle_for_lookup API change.  Use std::string.
* mi/mi-cmd-var.c (print_varobj, mi_cmd_var_set_format)
(mi_cmd_var_info_type, mi_cmd_var_info_path_expression)
(mi_cmd_var_info_expression, mi_cmd_var_evaluate_expression)
(mi_cmd_var_assign, varobj_update_one): Adjust to use std::string.
* minsyms.c (lookup_minimal_symbol): Use std::string.
* python/py-varobj.c (py_varobj_iter_next): Use new instead of
XNEW.  vitem->name is a std::string now, adjust.
* rust-exp.y (convert_ast_to_type, convert_name): Adjust to use
std::string.
* stabsread.c (define_symbol): Adjust to use std::string.
* symtab.c (demangle_for_lookup): Now returns 'const char *'.  Add
a demangle_result_storage parameter.  Use it for storage.
(lookup_symbol_in_language)
(lookup_symbol_in_objfile_from_linkage_name): Adjust to new
demangle_for_lookup API.
* symtab.h (struct demangle_result_storage): New type.
(demangle_for_lookup): Now returns 'const char *'.  Add a
demangle_result_storage parameter.
* typeprint.c (type_to_string): Return std::string and use
ui_file_as_string.
* value.h (type_to_string): Change return type to std::string.
* varobj-iter.h (struct varobj_item) <name>: Now a std::string.
(varobj_iter_delete): Use delete instead of xfree.
* varobj.c (create_child): Return std::string instead of char * in
output parameter.
(name_of_variable, name_of_child, my_value_of_variable): Return
std::string instead of char *.
(varobj_create, varobj_get_handle): Constify 'objname' parameter.
Adjust to std::string fields.
(varobj_get_objname): Return a const char * instead of a char *.
(varobj_get_expression): Return a std::string.
(varobj_list_children): Adjust to use std::string.
(varobj_get_type): Return a std::string.
(varobj_get_path_expr): Return a const char * instead of a char *.
Adjust to std::string fields.
(varobj_get_formatted_value, varobj_get_value): Return a
std::string.
(varobj_set_value): Change type of 'expression' parameter to
std::string.  Use std::string.
(install_new_value): Use std::string.
(delete_variable_1): Adjust to use std::string.
(create_child): Change the 'name' parameter to a std::string
reference.  Swap it into the new item's name.
(create_child_with_value): Swap item's name into the new child's
name.  Use string_printf.
(new_variable): Use new instead of XNEW.
(free_variable): Don't xfree fields that are now std::string.
(name_of_variable, name_of_child): Now returns std::string.
(value_of_root): Adjust to use std::string.
(my_value_of_variable, varobj_value_get_print_value): Return
and use std::string.
(varobj_value_get_print_value): Adjust to use ui_file_as_string
and std::string.
* varobj.h (struct varobj) <name, path_expr, obj_name,
print_value>: Now std::string's.
<name_of_variable, name_of_child, path_expr_of_child,
value_of_variable>: Return std::string.
(varobj_create, varobj_get_handle): Constify 'objname' parameter.
(varobj_get_objname): Return a const char * instead of a char *.
(varobj_get_expression, varobj_get_type): Return a std::string.
(varobj_get_path_expr): Return a const char * instead of a char *.
(varobj_get_formatted_value, varobj_get_value): Return a
std::string.
(varobj_set_value): Constify 'expression' parameter.
(varobj_value_get_print_value): Return a std::string.

8 years agoUse ui_file_as_string in gdb/language.c
Pedro Alves [Tue, 8 Nov 2016 15:26:47 +0000 (15:26 +0000)]
Use ui_file_as_string in gdb/language.c

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

* language.c (add_language): Use ui_file_as_string and adjust to
use std::string.

8 years agoUse ui_file_as_string in gdb/rust-lang.c
Pedro Alves [Tue, 8 Nov 2016 15:26:46 +0000 (15:26 +0000)]
Use ui_file_as_string in gdb/rust-lang.c

gdb/ChangeLog:
2016-11-08  Pedro Alves  <palves@redhat.com>
    Tom Tromey  <tom@tromey.com>

* rust-lang.c (struct disr_info) <name>: Now a std::string.
(rust_get_disr_info): Use ui_file_as_string and adjust to use
std::string.
(rust_val_print): Adjust to use std::string.

8 years agoUse ui_file_as_string in gdb/infrun.c
Pedro Alves [Tue, 8 Nov 2016 15:26:46 +0000 (15:26 +0000)]
Use ui_file_as_string in gdb/infrun.c

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

* infrun.c (print_target_wait_results): Use ui_file_as_string and
std::string.

8 years agoUse ui_file_as_string in gdb/ada-lang.c
Pedro Alves [Tue, 8 Nov 2016 15:26:46 +0000 (15:26 +0000)]
Use ui_file_as_string in gdb/ada-lang.c

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

* ada-lang.c (type_as_string): Use ui_file_as_string and return
std::string.
(type_as_string_and_cleanup): Delete.
(ada_lookup_struct_elt_type): Use type_as_string.

8 years agoUse ui_file_as_string in gdbarch.sh/gdbarch.c
Pedro Alves [Tue, 8 Nov 2016 15:26:46 +0000 (15:26 +0000)]
Use ui_file_as_string in gdbarch.sh/gdbarch.c

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

* gdbarch.sh (verify_gdbarch): Use ui_file_as_string and
std::string.
* gdbarch.c: Regenerate.

8 years agoUse ui_file_as_string in gdb/c-exp.y
Pedro Alves [Tue, 8 Nov 2016 15:26:46 +0000 (15:26 +0000)]
Use ui_file_as_string in gdb/c-exp.y

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

* c-exp.y (OPERATOR NEW): Adjust to use ui_file_as_string and
std::string.

8 years agoUse ui_file_as_string in gdb/compile/
Pedro Alves [Tue, 8 Nov 2016 15:26:46 +0000 (15:26 +0000)]
Use ui_file_as_string in gdb/compile/

Using ui_file_as_string would imply changing a few prototypes to pass
around source and object file names as std::string.  Instead of that,
wrap those two in a new class.  This ends up eliminating a small
wrinkle: get_new_file_names and compile_object_load have swapped
parameters.  The former takes "source, objfile", while the latter
takes "objfile, source".

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

* c-lang.h (c_compute_program): Now returns std::string.
* compile/compile-internal.h (class compile_file_names): New
class.
* compile/compile-object-load.c (compile_object_load): Replace
object_file and source_file parameters with a compile_file_names
parameter.  Adjust.
* compile-object-load.h: Include "compile-internal.h".
(compile_object_load): Replace object_file and source_file
parameters with a compile_file_names parameter.
* compile/compile-c-support.c (c_compute_program): Now returns a
std::string.  Use ui_file_as_string.
* compile/compile.c (get_new_file_names): Remove parameters and
return a compile_file_names instead.
(compile_to_object): Now returns a compile_file_names.  Use
ui_file_as_string.
(eval_compile_command): Use compile_file_names.
* language.h (struct language_defn) <la_compute_program>: Now
returns std::string.

8 years agoUse ui_file_as_string in gdb/cli/cli-setshow.c
Pedro Alves [Tue, 8 Nov 2016 15:26:45 +0000 (15:26 +0000)]
Use ui_file_as_string in gdb/cli/cli-setshow.c

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

* cli/cli-setshow.c (do_show_command): Adjust to use
ui_file_as_string and std::string.

8 years agoUse ui_file_as_string in gdb/remote.c
Pedro Alves [Tue, 8 Nov 2016 15:26:45 +0000 (15:26 +0000)]
Use ui_file_as_string in gdb/remote.c

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

* remote.c (escape_buffer): Use ui_file_as_string and return
std::string.
(putpkt_binary, read_frame): Adjust to use std::string.

8 years agoUse ui_file_as_string in gdb/python/
Pedro Alves [Tue, 8 Nov 2016 15:26:45 +0000 (15:26 +0000)]
Use ui_file_as_string in gdb/python/

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

* python/py-arch.c (archpy_disassemble): Use ui_file_as_string and
std::string.
* python/py-breakpoint.c (bppy_get_commands): Use
ui_file_as_string and std::string.
* python/py-frame.c (frapy_str): Likewise.
* python/py-type.c (typy_str): Likewise.
* python/py-unwind.c (unwind_infopy_str): Likewise.
* python/py-value.c (valpy_str): Likewise.

8 years agoUse ui_file_as_string in gdb/printcmd.c
Pedro Alves [Tue, 8 Nov 2016 15:26:45 +0000 (15:26 +0000)]
Use ui_file_as_string in gdb/printcmd.c

Yet another cleanup eliminated.

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

* printcmd.c (eval_command): Use ui_file_as_string and
std::string.

8 years agoUse ui_file_as_string in gdb/top.c
Pedro Alves [Tue, 8 Nov 2016 15:26:45 +0000 (15:26 +0000)]
Use ui_file_as_string in gdb/top.c

Yet another cleanup is eliminated.

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

* top.c (quit_confirm): Use ui_file_as_string and std::string.

8 years agoUse ui_file_as_string in execute_command_to_string
Pedro Alves [Tue, 8 Nov 2016 15:26:45 +0000 (15:26 +0000)]
Use ui_file_as_string in execute_command_to_string

... and then return std::string and adjust all callers.

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

* gdbcmd.h (execute_command_to_string): Now returns std::string.
(lookup_struct_elt_type): Adjust to use std::string.
* top.c (execute_command_to_string): Use ui_file_as_string and
return std::string.
* guile/guile.c (gdbscm_execute_gdb_command): Adjust to use
std::string.
* python/python.c (execute_gdb_command): Adjust to use
std::string.

8 years agoUse ui_file_as_string in gdb/guile/
Pedro Alves [Tue, 8 Nov 2016 15:26:44 +0000 (15:26 +0000)]
Use ui_file_as_string in gdb/guile/

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

* guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Use
ui_file_as_string and adjust to use std::string.
* guile/scm-disasm.c (gdbscm_arch_disassemble): Likewise.
* guile/scm-frame.c (frscm_print_frame_smob): Likewise.
* guile/scm-type.c (tyscm_type_name): Use ui_file_as_string and
adjust to use std::string.  Throw exception directly instead of
returning it in EXCP output parameter.
(tyscm_print_type_smob, gdbscm_type_print_name): Adjust to
tyscm_type_name interface change.
* guile/scm-value.c (vlscm_print_value_smob, gdbscm_value_print):
Use ui_file_as_string and std::string.

8 years agoUse ui_file_as_string in gdb/arm-tdep.c
Pedro Alves [Tue, 8 Nov 2016 15:26:44 +0000 (15:26 +0000)]
Use ui_file_as_string in gdb/arm-tdep.c

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

* arm-tdep.c (_initialize_arm_tdep): Use ui_file_as_string and
std::string.

8 years agoUse ui_file_as_string in gdb/utils.c
Pedro Alves [Tue, 8 Nov 2016 15:26:44 +0000 (15:26 +0000)]
Use ui_file_as_string in gdb/utils.c

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

* utils.c (error_stream): Use ui_file_as_string and std::string.

8 years agoUse ui_file_as_string in gdb/ui-out.c
Pedro Alves [Tue, 8 Nov 2016 15:26:44 +0000 (15:26 +0000)]
Use ui_file_as_string in gdb/ui-out.c

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

* ui-out.c (ui_out_field_stream): Use ui_file_as_string.

8 years agoUse ui_file_as_string in gdb/ada-valprint.c
Pedro Alves [Tue, 8 Nov 2016 15:26:44 +0000 (15:26 +0000)]
Use ui_file_as_string in gdb/ada-valprint.c

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

* ada-valprint.c (ada_print_floating): Use ui_file_as_string and
std::string.

8 years agoUse ui_file_as_string in gdb/xtensa-tdep.c
Pedro Alves [Tue, 8 Nov 2016 15:26:44 +0000 (15:26 +0000)]
Use ui_file_as_string in gdb/xtensa-tdep.c

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

* xtensa-tdep.c (xtensa_verify_config): Use ui_file_as_string and
std::string.

8 years agoUse ui_file_as_string in dwarf2_compute_name
Pedro Alves [Tue, 8 Nov 2016 15:26:44 +0000 (15:26 +0000)]
Use ui_file_as_string in dwarf2_compute_name

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

* dwarf2read.c (dwarf2_compute_name): Use ui_file_as_string and
std::string.

8 years agoClean up tracepoint.h/c:collection_list
Pedro Alves [Tue, 8 Nov 2016 15:26:43 +0000 (15:26 +0000)]
Clean up tracepoint.h/c:collection_list

Noticed we could do this while working on the expression_up change.

The main goal here was getting rid of the
encode_actions_and_make_cleanup / do_clear_collection_list cleanups.

While at it, uncrustify the code:

 - Make collection_list a C++ class, with data members private (and
   thus renamed m_...).

 - Make related functions be member methods.

 - Use std::vector instead of an open coding a vector implementation.

 - Use std::sort instead of qsort.

 - Rename the "list" member of collection_list, which is an incredibly
   obfuscating name.

 - Rename a couple other things here and there for clarify.

 - Use "bool" more.

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

* mi/mi-main.c (print_variable_or_computed): Constify 'expression'
parameter.
(mi_cmd_trace_frame_collected): Call encode_actions instead of
encode_actions_and_make_cleanup.  Adjust to use std::vector.
* tracepoint.c (memrange_cmp): Delete.
(memrange_comp): New.
(memrange_sortmerge): Take a memrange vector as parameter instead
of a collection_list.  Use std::sort instead of qsort.
(add_register): Now a method of collection_list.  Adjust to m_
prefix of data fields.
(add_memrange): Now a method of collection_list.  Adjust to m_
prefix of data fields.  Adjust to use std::vector.
(collect_symbol): Now a method of collection_list.  Adjust to m_
prefix of data fields.
(do_collect_symbol): Adjust.  Call add_wholly_collected instead of
accessing the vector directly.
(collection_list::add_wholly_collected): New.
(add_local_symbols): Now a method of collection_list.
(add_static_trace_data): Now a method of collection_list.  Adjust
to use bool.
(clear_collection_list, do_clear_collection_list): Delete.
(init_collection_list): Delete.
(collection_list::collection_list): New.
(collection_list::~collection_list): New.
(stringify_collection_list): Rename to ...
(collection_list::stringify): ... this and adjust to being a
method of collection_list.  Adjust to use of std::vector.
(append_exp): Now a method of collection_list.  Use
ui_file_as_string.  Adjust to std::vector.
(collection_list::finish): New.
(encode_actions_1): Adjust.
(encode_actions_and_make_cleanup): Rename to ...
(encode_actions)... this.  No longer returns a cleanup.  No longer
call init_collection_list nor install do_clear_collection_list
cleanups.  Call collection_list::finish instead of
memrange_sortmerge directly.
(encode_actions_rsp): Adjust to call encode_actions instead of
encode_actions_and_make_cleanup.  Adjust to method renames.
(add_aexpr): Now a method of collection_list.
* tracepoint.h: Include <vector> and <string>.
(struct memrange): Add constructors.
(struct collection_list): Now a class.
(class collection_list) <collection_list, ~collection_list,
add_wholly_collected, append_exp, add_aexpr, add_register,
add_memrange, collect_symbol, add_local_symbols,
add_static_trace_data, finish, stringify, wholly_collected, and
computed>: New methods.
<regs_mask>: Rename to ...
<m_regs_mask>: ... this.
<listsize, next_memrange, list>: Delete fields.
<m_memranges>: New field.
<aexpr_listsize, next_aexpr_elt, aexpr_list>: Delete fields.
<m_aexprs>: New field.
<strace_data>: Rename to ...
<m_strace_data>: ... this.  Now a bool.
<wholly_collected>: Rename to ...
<m_wholly_collected>: ... this.  Now a std::vector<std::string>.
<computed>: Rename to ...
<m_computed>: ... this.  Now a std::vector<std::string>.
(encode_actions_and_make_cleanup): Delete declaration.
(encode_actions): New declaration.

8 years agoIntroduce ui_file_as_string
Pedro Alves [Tue, 8 Nov 2016 15:26:43 +0000 (15:26 +0000)]
Introduce ui_file_as_string

ui_file_as_string is a variant of ui_file_xstrdup that returns a
std::string instead of a xmalloc'ed char *.  The idea is using the new
function to eliminate "make_cleanup (xfree, ...)"  cleanups
throughout.

Following patches will make use of this.

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

* ui-file.c (do_ui_file_as_string, ui_file_as_string): New
functions.
* ui-file.h: Include <string>.
(ui_file_as_string): New declaration.

8 years ago'struct expression *' -> gdb::unique_xmalloc_ptr<expression>
Pedro Alves [Tue, 8 Nov 2016 15:26:43 +0000 (15:26 +0000)]
'struct expression *' -> gdb::unique_xmalloc_ptr<expression>

This patch makes parse_expression and friends return a unique_ptr
instead of raw pointer [1]:

  typedef gdb::unique_malloc_ptr<expression> expression_up;

and then adjusts the codebase throughout to stop using cleanups to
manage lifetime of expression pointers.

Whenever I found a structure owning an expression pointer, I made it
store a unique_ptr instead of a raw pointer, which then requires using
new/delete of the holding structure, instead of XNEW/xfree.

[1] - I'd like to set the rule that types named with an "_up" suffix
      are unique_ptr typedefs.

Note I used gdb::unique_xmalloc_ptr instead of gdb::unique_ptr, simply
because we still use xmalloc instead of new to allocate expression
objects.  Once that's changed, all we need to do is change the
expression_up typedef and the smart pointer will then call delete
instead of xfree.

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

* ada-lang.c (ada_read_renaming_var_value): Use expression_up.
(struct ada_catchpoint_location) <excep_cond_expr>: Now an
expression_up.
(ada_catchpoint_location_dtor): Reset excep_cond_expr instead of
using xfree.
(create_excep_cond_exprs): Use expression_up and gdb::move.
(allocate_location_exception): Use new instead of XNEW.
(should_stop_exception): Likewise.  Adjust to use expression_up.
(create_ada_exception_catchpoint): Use new instead of XNEW.
* ax-gdb.c (agent_eval_command_one): Use expression_up instead of
cleanups.
(maint_agent_printf_command): Use expression_up.
* break-catch-sig.c (create_signal_catchpoint): Use new instead of
XNEW.
* break-catch-syscall.c (create_syscall_event_catchpoint):
Likewise.
* break-catch-throw.c (handle_gnu_v3_exceptions): Use new instead
of XCNEW.  Use gdb::unique_ptr instead of cleanups.
* breakpoint.c (set_breakpoint_condition, update_watchpoint)
(parse_cmd_to_aexpr, watchpoint_check)
(bpstat_check_breakpoint_conditions, watchpoint_locations_match):
Adjust to use expression_up.
(init_bp_location): Adjust.
(free_bp_location): Use delete instead of xfree.
(set_raw_breakpoint_without_location, set_raw_breakpoint)
(add_solib_catchpoint, create_fork_vfork_event_catchpoint)
(new_single_step_breakpoint, create_breakpoint_sal): Use new
instead of XNEW.
(find_condition_and_thread): Adjust to use expression_up.
(create_breakpoint): Use new instead of XNEW.
(dtor_watchpoint): Don't xfree expression pointers, they're
unique_ptr's now.
(insert_watchpoint, remove_watchpoint): Adjust.
(watch_command_1): Use expression_up.  Use new instead of XCNEW.
(catch_exec_command_1): Use new instead of XNEW.
(bp_location_dtor): Don't xfree expression pointers, they're
unique_ptr's now.
(base_breakpoint_allocate_location)
(strace_marker_create_breakpoints_sal): Use new instead of XNEW.
(delete_breakpoint): Use delete instead of xfree.
* breakpoint.h (struct bp_location) <cond>: Now an
unique_ptr<expression> instead of a raw pointer.
(struct watchpoint) <exp, cond_exp>: Likewise.
* cli/cli-script.c (execute_control_command): Use expression_up
instead of cleanups.
* dtrace-probe.c (dtrace_process_dof_probe): Use expression_up.
* eval.c (parse_and_eval_address, parse_and_eval_long)
(parse_and_eval, parse_to_comma_and_eval, parse_and_eval_type):
Use expression_up instead of cleanups.
* expression.h (expression_up): New typedef.
(parse_expression, parse_expression_with_language, parse_exp_1):
Change return type to expression_up.
* mi/mi-main.c (mi_cmd_data_evaluate_expression)
(print_variable_or_computed): Use expression_up.
* objc-lang.c (print_object_command): Use expression_up instead of
cleanups.
* parse.c (parse_exp_1, parse_exp_in_context)
(parse_exp_in_context_1, parse_expression)
(parse_expression_with_language): Return an expression_up instead
of a raw pointer.
(parse_expression_for_completion): Use expression_up.
* printcmd.c (struct display) <exp>: Now an expression_up instead
of a raw pointer.
(print_command_1, output_command_const, set_command, x_command):
Use expression_up instead of cleanups.
(display_command): Likewise.  Use new instead of XNEW.
(free_display): Use delete instead of xfree.
(do_one_display): Adjust to use expression_up.
* remote.c (remote_download_tracepoint): Likewise.
* stack.c (return_command): Likewise.
* tracepoint.c (validate_actionline, encode_actions_1): Use
expression_up instead of cleanups.
* typeprint.c (whatis_exp, maintenance_print_type): Likewise.
* value.c (init_if_undefined_command): Likewise.
* varobj.c (struct varobj_root) <exp>: Now an expression_up
instead of a raw pointer.
(varobj_create): Adjust.
(varobj_set_value): Use an expression_up instead of cleanups.
(new_root_variable): Use new instead of XNEW.
(free_variable): Use delete instead of xfree.
(value_of_root_1): Use std::swap.