Add two new internal functions $_cimag and $_creal that extract the
imaginary and real parts of a complex value.
These internal functions can take a complex value of any type 'float
complex', 'double complex', or 'long double complex' and return a
suitable floating point value 'float', 'double', or 'long double'.
So we can now do this:
(gdb) p z1
$1 = 1.5 + 4.5 * I
(gdb) p $_cimag (z1)
$4 = 4.5
(gdb) p $_creal (z1)
$4 = 1.5
The components of a complex value are not strictly named types in
DWARF, as the complex type is itself the base type. However, once we
are able to extract the components it makes sense to be able to ask
what the type of these components is and get a sensible answer back,
rather than the error we would currently get. Currently GDB says:
(gdb) ptype z1
type = complex double
(gdb) p $_cimag (z1)
$4 = 4.5
(gdb) ptype $
type = <invalid type code 9>
With the changes in dwarf2read.c, GDB now says:
(gdb) ptype z1
type = complex double
(gdb) p $_cimag (z1)
$4 = 4.5
(gdb) ptype $
type = double
Which seems to make more sense.
gdb/ChangeLog:
* NEWS: Mention new internal functions.
* dwarf2read.c (dwarf2_init_complex_target_type): New function.
(read_base_type): Use dwarf2_init_complex_target_type.
* value.c (creal_internal_fn): New function.
(cimag_internal_fn): New function.
(_initialize_values): Register new internal functions.
gdb/doc/ChangeLog:
* gdb.texinfo (Convenience Funs): Document '$_creal' and
'$_cimag'.
gdb/testsuite/ChangeLog:
* gdb.base/complex-parts.c: New file.
* gdb.base/complex-parts.exp: New file.
The test gdb.threads/watchthreads-reorder.exp verifies that the
'set debug infrun 1' debug output does not crash GDB.
Under high load, the test can still cause a GDB internal error (see details
below).
This patch fixes this crash, and improves/factorises some wait kind traces.
Tested on debian/amd64 + run one test with 'set debug infrun 1'.
Changes compared to the first version:
* Handles the suggestions of Kevin to trace the relevant elements
of the wait status (this is done by calling target_waitstatus_to_string).
* Some other changes to factorise wait status tracing.
Note that using target_waitstatus_to_string instead of the 'locally printed'
status kind strings means that debug trace that was using strings such as:
"EXITED" or "TARGET_WAITKIND_EXITED"
will now use what is printed by target_waitstatus_to_string e.g.
"exited".
gdb/ChangeLog
2019-04-01 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* infrun.c (stop_all_threads): If debug_infrun, always
trace the wait status after wait_one, using
target_waitstatus_to_string and target_pid_to_str.
(handle_inferior_event): Replace various trace of
wait status kind by a single trace.
* gdb/gnu-nat.c (gnu_nat_target::wait): Replace local
wait status kind image by target_waitstatus_to_string.
* target/waitstatus.c (target_waitstatus_to_string): Fix
obsolete comment.
(top-gdb) bt
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1 0x00007f3d54a0642a in __GI_abort () at abort.c:89
#2 0x0000555c24c60e66 in dump_core () at ../../fixleaks/gdb/utils.c:201
#3 0x0000555c24c63d49 in internal_vproblem(internal_problem *, const char *, int, const char *, typedef __va_list_tag __va_list_tag *) (problem=problem@entry=0x555c25338d40 <internal_error_problem>, file=<optimized out>, line=287,
fmt=<optimized out>, ap=<optimized out>) at ../../fixleaks/gdb/utils.c:411
#4 0x0000555c24c63eab in internal_verror (file=<optimized out>, line=<optimized out>, fmt=<optimized out>,
ap=<optimized out>) at ../../fixleaks/gdb/utils.c:436
#5 0x0000555c249e8c22 in internal_error (file=file@entry=0x555c24e0f2ad "../../fixleaks/gdb/inferior.c",
line=line@entry=287, fmt=<optimized out>) at ../../fixleaks/gdb/common/errors.c:55
#6 0x0000555c247d3f5c in find_inferior_pid (pid=<optimized out>) at ../../fixleaks/gdb/inferior.c:287
#7 0x0000555c24ad2248 in find_inferior_pid (pid=<optimized out>) at ../../fixleaks/gdb/inferior.c:302
#8 find_inferior_ptid (ptid=...) at ../../fixleaks/gdb/inferior.c:301
#9 0x0000555c24c35f25 in find_thread_ptid (ptid=...) at ../../fixleaks/gdb/thread.c:522
#10 0x0000555c24b0ab4d in thread_db_target::pid_to_str[abi:cxx11](ptid_t) (
this=0x555c2532e3e0 <the_thread_db_target>, ptid=...) at ../../fixleaks/gdb/linux-thread-db.c:1637
#11 0x0000555c24c2f420 in target_pid_to_str[abi:cxx11](ptid_t) (ptid=...) at ../../fixleaks/gdb/target.c:2083
#12 0x0000555c24ad9cab in stop_all_threads () at ../../fixleaks/gdb/infrun.c:4373
#13 0x0000555c24ada00f in stop_waiting (ecs=<optimized out>) at ../../fixleaks/gdb/infrun.c:7464
#14 0x0000555c24adc401 in process_event_stop_test (ecs=ecs@entry=0x7ffc9402d9d0) at ../../fixleaks/gdb/infrun.c:6181
...
(top-gdb) fr 12
#12 0x0000555c24ad9cab in stop_all_threads () at ../../fixleaks/gdb/infrun.c:4373
(top-gdb) p event_ptid
$5 = {m_pid = 25419, m_lwp = 25427, m_tid = 0}
(top-gdb) p ptid
$6 = {m_pid = 0, m_lwp = 0, m_tid = 0}
(top-gdb) p ws
$7 = {kind = TARGET_WAITKIND_THREAD_EXITED, value = {integer = 0, sig = GDB_SIGNAL_0, related_pid = {m_pid = 0,
m_lwp = 0, m_tid = 0}, execd_pathname = 0x0, syscall_number = 0}}
(top-gdb)
The gdb.log corresponding to the above crash is:
(gdb) PASS: gdb.threads/watchthreads-reorder.exp: reorder1: set debug infrun 1
continue
Continuing.
infrun: clear_proceed_status_thread (Thread 0x7ffff7fcfb40 (LWP 25419))
infrun: clear_proceed_status_thread (Thread 0x7ffff7310700 (LWP 25427))
infrun: clear_proceed_status_thread (Thread 0x7ffff6b0f700 (LWP 25428))
infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT)
infrun: proceed: resuming Thread 0x7ffff7fcfb40 (LWP 25419)
infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7fcfb40 (LWP 25419)] at 0x7ffff7344317
infrun: infrun_async(1)
infrun: prepare_to_wait
infrun: proceed: resuming Thread 0x7ffff7310700 (LWP 25427)
infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff7310700 (LWP 25427)] at 0x5555555553d7
infrun: prepare_to_wait
infrun: proceed: resuming Thread 0x7ffff6b0f700 (LWP 25428)
infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [Thread 0x7ffff6b0f700 (LWP 25428)] at 0x5555555554c8
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun: -1.0.0 [process -1],
infrun: status->kind = ignore
infrun: TARGET_WAITKIND_IGNORE
infrun: prepare_to_wait
Joining the threads.
[Thread 0x7ffff6b0f700 (LWP 25428) exited]
infrun: target_wait (-1.0.0, status) =
infrun: -1.0.0 [process -1],
infrun: status->kind = ignore
infrun: TARGET_WAITKIND_IGNORE
infrun: prepare_to_wait
infrun: target_wait (-1.0.0, status) =
infrun: 25419.25419.0 [Thread 0x7ffff7fcfb40 (LWP 25419)],
infrun: status->kind = stopped, signal = GDB_SIGNAL_TRAP
infrun: TARGET_WAITKIND_STOPPED
infrun: stop_pc = 0x555555555e50
infrun: context switch
infrun: Switching context from Thread 0x7ffff6b0f700 (LWP 25428) to Thread 0x7ffff7fcfb40 (LWP 25419)
infrun: BPSTAT_WHAT_STOP_NOISY
infrun: stop_waiting
infrun: stop_all_threads
infrun: stop_all_threads, pass=0, iterations=0
infrun: Thread 0x7ffff7fcfb40 (LWP 25419) not executing
infrun: Thread 0x7ffff7310700 (LWP 25427) executing, need stop
[Thread 0x7ffff7310700 (LWP 25427) exited]
infrun: target_wait (-1.0.0, status) =
infrun: 25419.25427.0 [LWP 25427],
infrun: status->kind = thread exited, status = 0
infrun: infrun_async(0)
../../fixleaks/gdb/inferior.c:287: internal-error: inferior* find_inferior_pid(int): Assertion `pid != 0' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) FAIL: gdb.threads/watchthreads-reorder.exp: reorder1: continue to breakpoint: break-at-exit (GDB internal error)
Resyncing due to internal error.
n
infrun: infrun_async(1)
This is a bug, please report it. For instructions, see:
<http://www.gnu.org/software/gdb/bugs/>.
infrun: infrun_async(0)
../../fixleaks/gdb/inferior.c:287: internal-error: inferior* find_inferior_pid(int): Assertion `pid != 0' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) y
add_partial_subprogram does not handle DW_AT_ranges, while the full
symtab reader does. This can lead to discrepancies where a function
is not put into a partial symtab, and so is not available to "break"
and the like -- but is available if the full symtab has somehow been
read.
This patch fixes the bug by arranging to read DW_AT_ranges when
reading partial DIEs.
This is PR symtab/23331.
The new test case is derived from dw2-ranges-func.exp, which is why I
kept the copyright dates.
gdb/ChangeLog
2019-04-01 Tom Tromey <tromey@adacore.com>
PR symtab/23331:
* dwarf2read.c (partial_die_info::read): Handle DW_AT_ranges.
gdb/testsuite/ChangeLog
2019-04-01 Tom Tromey <tromey@adacore.com>
PR symtab/23331:
* gdb.dwarf2/dw2-ranges-main.c: New file.
* gdb.dwarf2/dw2-ranges-psym.c: New file.
* gdb.dwarf2/dw2-ranges-psym.exp: New file.
When the user exits GDB, we might still have some allocated values in
the chain, which, in specific scenarios, can cause problems when GDB
attempts to destroy them in "quit_force". For example, see the bug
reported at:
https://bugzilla.redhat.com/show_bug.cgi?id=1690120
And the thread starting at:
https://sourceware.org/ml/gdb-patches/2019-03/msg00475.html
Message-ID: <87r2azkhmq.fsf@redhat.com>
In order to avoid that, and to be more aware of our allocated
resources, this commit implements a new function "finalize_values" and
calls it from inside "quit_force".
Tested by the BuildBot.
2019-04-01 Sergio Durigan Junior <sergiodj@redhat.com>
Pedro Alves <palves@redhat.com>
* top.c (quit_force): Call 'finalize_values'.
* value.c (finalize_values): New function.
* value.h (finalize_values): Declare.
I noticed that the help for "info addr" did not include a "usage"
line; and when adding it I went through and fixed a few minor issues
in printcmd.c:
* Added usage lines to all commands
* Updated the help text for some commands
* Changed some help to use upper case metasyntactic variables
* Removed some dead code
Regression tested on x86-64 Fedora 29.
gdb/ChangeLog
2019-03-29 Tom Tromey <tromey@adacore.com>
* printcmd.c (_initialize_printcmd): Add usage lines. Update some
help text. Remove dead code.
gdb/testsuite/ChangeLog
2019-03-29 Tom Tromey <tromey@adacore.com>
* gdb.base/help.exp: Tighten apropos regexp.
This is the fortran part of the patch, including tests, which
are essentially unchanged from Siddhesh's original 2012 submission:
https://sourceware.org/ml/gdb-patches/2012-08/msg00562.html
There is, however, one large departure. In the above thread,
Jan pointed out problems with GCC debuginfo for -m32 builds
(filed usptream as gcc/54934). After investigating the issue,
I am dropping the hand-tweaked assembler source file to workaround
this case.
While I would normally do something to accommodate this, in
this case, given the ubiquity of 64-bit systems today (where
the tests pass) and the apparent lack of urgency on the compiler
side (by users), I don't think the additional complexity and
maintenance costs are worth it. It will be very routinely tested
on 64-bit systems. [For example, at Red Hat, we always
test -m64 and -m32 configurations for all GDB releases.]
gdb/ChangeLog:
From Siddhesh Poyarekar:
* f-lang.h (f77_get_upperbound): Return LONGEST.
(f77_get_lowerbound): Likewise.
* f-typeprint.c (f_type_print_varspec_suffix): Expand
UPPER_BOUND and LOWER_BOUND to LONGEST. Use plongest to format
print them.
(f_type_print_base): Expand UPPER_BOUND to LONGEST. Use
plongest to format print it.
* f-valprint.c (f77_get_lowerbound): Return LONGEST.
(f77_get_upperbound): Likewise.
(f77_get_dynamic_length_of_aggregate): Expand UPPER_BOUND,
LOWER_BOUND to LONGEST.
(f77_create_arrayprint_offset_tbl): Likewise.
gdb/testsuite/ChangeLog:
* gdb.fortran/array-bounds.exp: New file.
* gdb.fortran/array-bounds.f90: New file.
This series is revisit of Siddhesh Poyarekar's patch from back in
2012. The last status on the patch is in the following gdb-patches
thread:
https://sourceware.org/ml/gdb-patches/2012-08/msg00562.html
It appears that Tom approved the patch, but Jan had some issues
with a compiler error that made the test fail on -m32 test runs.
He wrote up a hand-tweaked .S file to deal with it. Siddesh said
he would update tests. Then nothing.
Siddesh and Jan have both moved on since.
The patch originally required a large precursor patch to work.
I have whittled this down to/rewritten the bare minimum, and this
first patch is the result, changing the type of TYPE_LENGTH
to ULONGEST from unsigned int.
The majority of the changes involve changing printf format
strings to use %s and pulongest instead of %d.
gdb/ChangeLog:
* ada-lang.c (ada_template_to_fixed_record_type_1): Use
%s/pulongest for TYPE_LENGTH instead of %d in format
strings.
* ada-typerint.c (ada_print_type): Likewise.
* amd64-windows-tdep.c (amd64_windows_store_arg_in_reg): Likewise.
* compile/compile-c-support.c (generate_register_struct): Likewise.
* gdbtypes.c (recursive_dump_type): Likewise.
* gdbtypes.h (struct type) <length>: Change type to ULONGEST.
* m2-typeprint.c (m2_array): Use %s/pulongest for TYPE_LENGTH
instead of %d in format strings.
* riscv-tdep.c (riscv_type_alignment): Cast second argument
to std::min to ULONGEST.
* symmisc.c (print_symbol): Use %s/pulongest for TYPE_LENGTH
instead of %d in format strings.
* tracepoint.c (info_scope_command): Likewise.
* typeprint.c (print_offset_data::update)
(print_offset_data::finish): Likewise.
* xtensa-tdep.c (xtensa_store_return_value)
(xtensa_push_dummy_call): Likewise.
DWORD type is not a long on 64-bit Cygwin, because that it is LP64.
Explicitly cast DWORD values to unsigned long and use an appropriate
format.
gdb/ChangeLog:
2019-03-28 Jon Turney <jon.turney@dronecode.org.uk>
* windows-nat.c (display_selector): Fixed format specifications
for 64-bit Cygwin.
When running under valgrind, multi-arch-exec.exp blocks forever.
Some (painful) investigation shows this is due to valgrind slowing
down GDB, and GDB has to output some messages at a different time,
when GDB does not have the terminal for output.
To reproduce the problem, you need to slow down GDB.
It can be reproduced by:
cd gdb/testsuite/outputs/gdb.multi/multi-arch-exec/
../../../../gdb -ex 'set debug lin-lwp 1' -ex 'break all_started' -ex 'run' ./2-multi-arch-exec
The above stops at a breakpoint. Do continue.
GDB is then suspended because of SIGTTOU.
The stacktrace that leads to the hanging GDB is:
(top-gdb) bt
at ../../binutils-gdb/gdb/exceptions.c:130
....
Alternatively, the same happens when doing
strace -o s.out ../../../../gdb -ex 'break all_started' -ex 'run' ./2-multi-arch-exec
And of course, valgrind is also sufficiently slowing down GDB to
reproduce this :).
Fix this by calling target_terminal::ours_for_output ();
at the beginning of follow_exec.
Note that all this terminal handling is not very clear to me:
* Some code takes the terminal, and then takes care to give it back to the inferior
if the terminal was belonging to the inferior.
(e.g. annotate_breakpoints_invalid).
* some code takes the terminal, but does not give it back
(e.g. update_inserted_breakpoint_locations).
* some code takes it, and unconditionally gives it back
(e.g. handle_jit_event)
* here and there, we also find
gdb::optional<target_terminal::scoped_restore_terminal_state> term_state;
before a (sometimes optional) call to ours_for_output.
And such calls to ours_for_output is sometimes protected by:
if (target_supports_terminal_ours ())
(e.g. exceptions.c: print_flush).
but most of the code calls it without checking if the target supports it.
* some code is outputting some errors, but only takes the terminal
after. E.g. infcmd.c: prepare_one_step
gdb/ChangeLog
2019-03-28 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* infrun.c (follow_exec): Call target_terminal::ours_for_output.
This patch fixes a problem on nios2-linux-gnu with stepping past the
kernel helper __kuser_cmpxchg, which was exposed by the testcase
gdb.threads/watchpoint-fork.exp. The kernel maps this function into
user space on an unwritable page. In this testcase, the cmpxchg
helper is invoked indirectly from the setbuf call in the test program.
Since this target lacks hardware breakpoint/watchpoint support, GDB
tries to single-step through the program by setting software
breakpoints, and was just giving an error when it reached the function
on the unwritable page.
The solution here is to always step over the call instead of stepping
into it; cmpxchg is supposed to be an atomic operation so this
behavior seems reasonable. The hook in nios2_get_next_pc is somewhat
generic, but at present cmpxchg is the only helper provided by the
Linux kernel that is invoked by an ordinary function call. (Signal
return trampolines also go through the unwritable page but not by a
function call.)
Fixing this issue also revealed that the testcase needs a much larger
timeout factor when software single-stepping is used. That has also
been fixed in this patch.
gdb/ChangeLog
2019-03-28 Sandra Loosemore <sandra@codesourcery.com>
* nios2-tdep.h (struct gdbarch_tdep): Add is_kernel_helper.
* nios2-tdep.c (nios2_get_next_pc): Skip over kernel helpers.
* nios2-linux-tdep.c (nios2_linux_is_kernel_helper): New.
(nios2_linux_init_abi): Install it.
gdb/testsuite/ChangeLog
2019-03-28 Sandra Loosemore <sandra@codesourcery.com>
* gdb.threads/watchpoint-fork.exp (test): Use large timeout
factor when no hardware watchpoint support.
When SVE is enabled, the V registers become pseudo registers based
on the Z registers. They should look the same as they do when
there is no SVE.
The existing code viewed them as single value registers. Switch
this to a vector.
gdb/ChangeLog:
* aarch64-tdep.c (aarch64_vnv_type): Use vector types.
SVE can view Z registers as 128bit values using .q prefix.
Add this view to the SVE feature.
gdb/ChangeLog:
* features/aarch64-sve.c (create_feature_aarch64_sve): Add q view.
Valgrind detects the following error in a bunch of tests,
e.g. in gdb.base/foll-fork.exp.
==15155== VALGRIND_GDB_ERROR_BEGIN
==15155== Invalid read of size 8
==15155== at 0x55BE04: minimal_symbol_upper_bound(bound_minimal_symbol) (minsyms.c:1504)
==15155== by 0x3B2E9C: find_pc_partial_function(unsigned long, char const**, unsigned long*, unsigned long*, block const**) (blockframe.c:340)
==15155== by 0x3B3135: find_function_entry_range_from_pc(unsigned long, char const**, unsigned long*, unsigned long*) (blockframe.c:385)
==15155== by 0x4F5597: fill_in_stop_func(gdbarch*, execution_control_state*) [clone .part.16] (infrun.c:4124)
==15155== by 0x4FBE01: fill_in_stop_func (infrun.c:7636)
==15155== by 0x4FBE01: process_event_stop_test(execution_control_state*) (infrun.c:6279)
...
==15155== Address 0x715bec8 is 0 bytes after a block of size 2,952 alloc'd
==15155== at 0x4C2E2B3: realloc (vg_replace_malloc.c:836)
==15155== by 0x405F2C: xrealloc (common-utils.c:62)
==15155== by 0x55BA4E: xresizevec<minimal_symbol> (poison.h:170)
==15155== by 0x55BA4E: minimal_symbol_reader::install() (minsyms.c:1399)
==15155== by 0x4981C7: elf_read_minimal_symbols (elfread.c:1165)
...
This seems to be a regression created by:
commit 042d75e42c
Author: Tom Tromey <tom@tromey.com>
AuthorDate: Sat Mar 2 12:29:48 2019 -0700
Commit: Tom Tromey <tom@tromey.com>
CommitDate: Fri Mar 15 16:02:10 2019 -0600
Allocate minimal symbols with malloc
Before this commit, the array of 'struct minimal_symbol'
contained a last element that was a "null symbol". The comment in
minimal_symbol_reader::install was:
/* We also terminate the minimal symbol table with a "null symbol",
which is *not* included in the size of the table. This makes it
easier to find the end of the table when we are handed a pointer
to some symbol in the middle of it. Zero out the fields in the
"null symbol" allocated at the end of the array. Note that the
symbol count does *not* include this null symbol, which is why it
is indexed by mcount and not mcount-1. */
memset (&msymbols[mcount], 0, sizeof (struct minimal_symbol));
However, minimal_symbol_upper_bound was still based on the assumption
that the array of minsym is terminated by a minsym with a null symbol:
it is looping with:
for (i = 1; MSYMBOL_LINKAGE_NAME (msymbol + i) != NULL; i++)
Replace this NULL comparison by a logic that calculates how
many msymbol are following the msymbols from which we are starting from.
(Re-)tested on debian/amd64, natively and under valgrind.
gdb/ChangeLog
2019-03-24 Philippe Waroquiers <philippe.waroquiers@skynet.be>
Tom Tromey <tromey@adacore.com>
* minsyms.c (minimal_symbol_upper_bound): Fix buffer overflow.
I noticed that trying to print the contents of a struct main_type
would fail when the type was a TYPE_CODE_RANGE:
(gdb) p *type.main_type
$1 = Python Exception <class 'gdb.error'> There is no member named low_undefined.:
And indeed, Python is right, fields "low_undefined" has been removed
from struct range_bounds back in ... 2014! It was done when we introduced
dynamic bounds handling. This patch fixes gdb-gdb.py.in according to
the new structure.
gdb/ChangeLog:
* gdb-gdb.py.in (StructMainTypePrettyPrinter.bound_img): New method.
(StructMainTypePrettyPrinter.bounds_img): Use new "bound_img"
method to compute the bounds of range types. Also print "[evaluated]"
if the bounds' values come from a dynamic evaluation.
While writing a new test for 'set print pretty on' I spotted that GDB
will sometimes add a trailing whitespace character when pretty
printing. This commit removes the trailing whitespace and updates the
expected results in one tests where this was an issue.
I've added an extra test for 'set print pretty on' as it doesn't seem
to have much testing.
gdb/ChangeLog:
* cp-valprint.c (cp_print_value_fields): Don't print trailing
whitespace when pretty printing is on.
gdb/testsuite/ChangeLog:
* gdb.base/finish-pretty.exp: Update expected results.
* gdb.base/pretty-print.c: New file.
* gdb.base/pretty-print.exp: New file.
Commit ab42892fb7 ("Fix vertical scrolling of TUI source window")
introduced a use-after-free in source_cache::get_source_lines.
At the beginning of the method, we get the fullname of the symtab:
const char *fullname = symtab_to_fullname (s);
fullname points to the string owned by the symtab (s.fullname). When we
later do
scoped_fd desc = open_source_file (s);
s.fullname gets reallocated (even though the string contents may not
change). The fullname local variable now points to freed memory.
To avoid it, refresh the value of fullname after calling
open_source_file.
Here is the ASan report:
$ ./gdb -nx --data-directory=data-directory ./a.out
(gdb) start
Temporary breakpoint 1 at 0x1130: file test.cpp, line 12.
Starting program: /home/simark/build/binutils-gdb/gdb/a.out
Temporary breakpoint 1, main () at test.cpp:12
=================================================================
==26068==ERROR: AddressSanitizer: heap-use-after-free on address 0x6210003d4100 at pc 0x7fed89a34681 bp 0x7ffd8d185d80 sp 0x7ffd8d185528
READ of size 2 at 0x6210003d4100 thread T0
#0 0x7fed89a34680 in __interceptor_strlen /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:301
#1 0x55b6edf6c2f7 in std::char_traits<char>::length(char const*) /usr/include/c++/8.2.1/bits/char_traits.h:320
#2 0x55b6edf6c9b2 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) /usr/include/c++/8.2.1/bits/basic_string.h:516
#3 0x55b6ef09121b in source_cache::get_source_lines(symtab*, int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) /home/simark/src/binutils-gdb/gdb/source-cache.c:214
#4 0x55b6ef0a15cb in print_source_lines_base /home/simark/src/binutils-gdb/gdb/source.c:1340
#5 0x55b6ef0a2045 in print_source_lines(symtab*, int, int, enum_flags<print_source_lines_flag>) /home/simark/src/binutils-gdb/gdb/source.c:1415
#6 0x55b6ef112c87 in print_frame_info(frame_info*, int, print_what, int, int) /home/simark/src/binutils-gdb/gdb/stack.c:914
#7 0x55b6ef10e90d in print_stack_frame(frame_info*, int, print_what, int) /home/simark/src/binutils-gdb/gdb/stack.c:180
#8 0x55b6ee9592f8 in print_stop_location /home/simark/src/binutils-gdb/gdb/infrun.c:7853
#9 0x55b6ee95948f in print_stop_event(ui_out*) /home/simark/src/binutils-gdb/gdb/infrun.c:7870
#10 0x55b6ef34b962 in tui_on_normal_stop /home/simark/src/binutils-gdb/gdb/tui/tui-interp.c:98
#11 0x55b6ee01a14d in std::_Function_handler<void (bpstats*, int), void (*)(bpstats*, int)>::_M_invoke(std::_Any_data const&, bpstats*&&, int&&) /usr/include/c++/8.2.1/bits/std_function.h:297
#12 0x55b6ee965415 in std::function<void (bpstats*, int)>::operator()(bpstats*, int) const /usr/include/c++/8.2.1/bits/std_function.h:687
#13 0x55b6ee962f1b in gdb::observers::observable<bpstats*, int>::notify(bpstats*, int) const /home/simark/src/binutils-gdb/gdb/common/observable.h:106
#14 0x55b6ee95a6e7 in normal_stop() /home/simark/src/binutils-gdb/gdb/infrun.c:8142
#15 0x55b6ee93f236 in fetch_inferior_event(void*) /home/simark/src/binutils-gdb/gdb/infrun.c:3782
#16 0x55b6ee8f2641 in inferior_event_handler(inferior_event_type, void*) /home/simark/src/binutils-gdb/gdb/inf-loop.c:43
#17 0x55b6eea2a1f0 in handle_target_event /home/simark/src/binutils-gdb/gdb/linux-nat.c:4358
#18 0x55b6ee7045f1 in handle_file_event /home/simark/src/binutils-gdb/gdb/event-loop.c:733
#19 0x55b6ee704e89 in gdb_wait_for_event /home/simark/src/binutils-gdb/gdb/event-loop.c:859
#20 0x55b6ee7027b5 in gdb_do_one_event() /home/simark/src/binutils-gdb/gdb/event-loop.c:322
#21 0x55b6ee702907 in start_event_loop() /home/simark/src/binutils-gdb/gdb/event-loop.c:371
#22 0x55b6eeadfc16 in captured_command_loop /home/simark/src/binutils-gdb/gdb/main.c:331
#23 0x55b6eeae2ef9 in captured_main /home/simark/src/binutils-gdb/gdb/main.c:1174
#24 0x55b6eeae30c2 in gdb_main(captured_main_args*) /home/simark/src/binutils-gdb/gdb/main.c:1190
#25 0x55b6edf4fa89 in main /home/simark/src/binutils-gdb/gdb/gdb.c:32
#26 0x7fed88ad8222 in __libc_start_main (/usr/lib/libc.so.6+0x24222)
#27 0x55b6edf4f86d in _start (/home/simark/build/binutils-gdb/gdb/gdb+0x197186d)
0x6210003d4100 is located 0 bytes inside of 4096-byte region [0x6210003d4100,0x6210003d5100)
freed by thread T0 here:
#0 0x7fed89a8ac19 in __interceptor_free /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:66
#1 0x55b6edfe12df in xfree<char> /home/simark/src/binutils-gdb/gdb/common/common-utils.h:60
#2 0x55b6edfea675 in gdb::xfree_deleter<char>::operator()(char*) const /home/simark/src/binutils-gdb/gdb/common/gdb_unique_ptr.h:34
#3 0x55b6edfe532c in std::unique_ptr<char, gdb::xfree_deleter<char> >::reset(char*) /usr/include/c++/8.2.1/bits/unique_ptr.h:382
#4 0x55b6edfe7329 in std::unique_ptr<char, gdb::xfree_deleter<char> >::operator=(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) /usr/include/c++/8.2.1/bits/unique_ptr.h:289
#5 0x55b6ef09ec2b in find_and_open_source(char const*, char const*, std::unique_ptr<char, gdb::xfree_deleter<char> >*) /home/simark/src/binutils-gdb/gdb/source.c:990
#6 0x55b6ef09f56a in open_source_file(symtab*) /home/simark/src/binutils-gdb/gdb/source.c:1069
#7 0x55b6ef090f78 in source_cache::get_source_lines(symtab*, int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) /home/simark/src/binutils-gdb/gdb/source-cache.c:205
#8 0x55b6ef0a15cb in print_source_lines_base /home/simark/src/binutils-gdb/gdb/source.c:1340
#9 0x55b6ef0a2045 in print_source_lines(symtab*, int, int, enum_flags<print_source_lines_flag>) /home/simark/src/binutils-gdb/gdb/source.c:1415
#10 0x55b6ef112c87 in print_frame_info(frame_info*, int, print_what, int, int) /home/simark/src/binutils-gdb/gdb/stack.c:914
#11 0x55b6ef10e90d in print_stack_frame(frame_info*, int, print_what, int) /home/simark/src/binutils-gdb/gdb/stack.c:180
#12 0x55b6ee9592f8 in print_stop_location /home/simark/src/binutils-gdb/gdb/infrun.c:7853
#13 0x55b6ee95948f in print_stop_event(ui_out*) /home/simark/src/binutils-gdb/gdb/infrun.c:7870
#14 0x55b6ef34b962 in tui_on_normal_stop /home/simark/src/binutils-gdb/gdb/tui/tui-interp.c:98
#15 0x55b6ee01a14d in std::_Function_handler<void (bpstats*, int), void (*)(bpstats*, int)>::_M_invoke(std::_Any_data const&, bpstats*&&, int&&) /usr/include/c++/8.2.1/bits/std_function.h:297
#16 0x55b6ee965415 in std::function<void (bpstats*, int)>::operator()(bpstats*, int) const /usr/include/c++/8.2.1/bits/std_function.h:687
#17 0x55b6ee962f1b in gdb::observers::observable<bpstats*, int>::notify(bpstats*, int) const /home/simark/src/binutils-gdb/gdb/common/observable.h:106
#18 0x55b6ee95a6e7 in normal_stop() /home/simark/src/binutils-gdb/gdb/infrun.c:8142
#19 0x55b6ee93f236 in fetch_inferior_event(void*) /home/simark/src/binutils-gdb/gdb/infrun.c:3782
#20 0x55b6ee8f2641 in inferior_event_handler(inferior_event_type, void*) /home/simark/src/binutils-gdb/gdb/inf-loop.c:43
#21 0x55b6eea2a1f0 in handle_target_event /home/simark/src/binutils-gdb/gdb/linux-nat.c:4358
#22 0x55b6ee7045f1 in handle_file_event /home/simark/src/binutils-gdb/gdb/event-loop.c:733
#23 0x55b6ee704e89 in gdb_wait_for_event /home/simark/src/binutils-gdb/gdb/event-loop.c:859
#24 0x55b6ee7027b5 in gdb_do_one_event() /home/simark/src/binutils-gdb/gdb/event-loop.c:322
#25 0x55b6ee702907 in start_event_loop() /home/simark/src/binutils-gdb/gdb/event-loop.c:371
#26 0x55b6eeadfc16 in captured_command_loop /home/simark/src/binutils-gdb/gdb/main.c:331
#27 0x55b6eeae2ef9 in captured_main /home/simark/src/binutils-gdb/gdb/main.c:1174
#28 0x55b6eeae30c2 in gdb_main(captured_main_args*) /home/simark/src/binutils-gdb/gdb/main.c:1190
#29 0x55b6edf4fa89 in main /home/simark/src/binutils-gdb/gdb/gdb.c:32
previously allocated by thread T0 here:
#0 0x7fed89a8b019 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:86
#1 0x7fed88af983f in realpath@@GLIBC_2.3 (/usr/lib/libc.so.6+0x4583f)
#2 0x7fed899dbbbc in __interceptor_canonicalize_file_name /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3297
#3 0x55b6ee376a03 in gdb_realpath(char const*) /home/simark/src/binutils-gdb/gdb/common/pathstuff.c:72
#4 0x55b6ef09ec12 in find_and_open_source(char const*, char const*, std::unique_ptr<char, gdb::xfree_deleter<char> >*) /home/simark/src/binutils-gdb/gdb/source.c:990
#5 0x55b6ef09f56a in open_source_file(symtab*) /home/simark/src/binutils-gdb/gdb/source.c:1069
#6 0x55b6ef0a0f12 in print_source_lines_base /home/simark/src/binutils-gdb/gdb/source.c:1270
#7 0x55b6ef0a2045 in print_source_lines(symtab*, int, int, enum_flags<print_source_lines_flag>) /home/simark/src/binutils-gdb/gdb/source.c:1415
#8 0x55b6ef112c87 in print_frame_info(frame_info*, int, print_what, int, int) /home/simark/src/binutils-gdb/gdb/stack.c:914
#9 0x55b6ef10e90d in print_stack_frame(frame_info*, int, print_what, int) /home/simark/src/binutils-gdb/gdb/stack.c:180
#10 0x55b6ee9592f8 in print_stop_location /home/simark/src/binutils-gdb/gdb/infrun.c:7853
#11 0x55b6ee95948f in print_stop_event(ui_out*) /home/simark/src/binutils-gdb/gdb/infrun.c:7870
#12 0x55b6ef34b962 in tui_on_normal_stop /home/simark/src/binutils-gdb/gdb/tui/tui-interp.c:98
#13 0x55b6ee01a14d in std::_Function_handler<void (bpstats*, int), void (*)(bpstats*, int)>::_M_invoke(std::_Any_data const&, bpstats*&&, int&&) /usr/include/c++/8.2.1/bits/std_function.h:297
#14 0x55b6ee965415 in std::function<void (bpstats*, int)>::operator()(bpstats*, int) const /usr/include/c++/8.2.1/bits/std_function.h:687
#15 0x55b6ee962f1b in gdb::observers::observable<bpstats*, int>::notify(bpstats*, int) const /home/simark/src/binutils-gdb/gdb/common/observable.h:106
#16 0x55b6ee95a6e7 in normal_stop() /home/simark/src/binutils-gdb/gdb/infrun.c:8142
#17 0x55b6ee93f236 in fetch_inferior_event(void*) /home/simark/src/binutils-gdb/gdb/infrun.c:3782
#18 0x55b6ee8f2641 in inferior_event_handler(inferior_event_type, void*) /home/simark/src/binutils-gdb/gdb/inf-loop.c:43
#19 0x55b6eea2a1f0 in handle_target_event /home/simark/src/binutils-gdb/gdb/linux-nat.c:4358
#20 0x55b6ee7045f1 in handle_file_event /home/simark/src/binutils-gdb/gdb/event-loop.c:733
#21 0x55b6ee704e89 in gdb_wait_for_event /home/simark/src/binutils-gdb/gdb/event-loop.c:859
#22 0x55b6ee7027b5 in gdb_do_one_event() /home/simark/src/binutils-gdb/gdb/event-loop.c:322
#23 0x55b6ee702907 in start_event_loop() /home/simark/src/binutils-gdb/gdb/event-loop.c:371
#24 0x55b6eeadfc16 in captured_command_loop /home/simark/src/binutils-gdb/gdb/main.c:331
#25 0x55b6eeae2ef9 in captured_main /home/simark/src/binutils-gdb/gdb/main.c:1174
#26 0x55b6eeae30c2 in gdb_main(captured_main_args*) /home/simark/src/binutils-gdb/gdb/main.c:1190
#27 0x55b6edf4fa89 in main /home/simark/src/binutils-gdb/gdb/gdb.c:32
#28 0x7fed88ad8222 in __libc_start_main (/usr/lib/libc.so.6+0x24222)
gdb/ChangeLog:
* source-cache.c (source_cache::get_source_lines): Re-read
fullname after calling open_source_file.
Philippe pointed out that some comments in minsyms.c still referred to
obstack allocation. This patch fixes these up.
In most cases here, my view is that the comments were more misleading
than helpful. So, I've generally removed text.
gdb/ChangeLog
2019-03-25 Tom Tromey <tromey@adacore.com>
* minsyms.c (BUNCH_SIZE): Update comment.
(~minimal_symbol_reader): Remove old comment.
(compact_minimal_symbols): Update comment.
(minimal_symbol_reader::install): Remove old comment. Update
other comments.
expression.h includes symtab.h, but apparently only for the
declaration of struct block. This patch changes it to foward-declare
the structure, and remove the include.
gdb/ChangeLog
2019-03-24 Tom Tromey <tom@tromey.com>
* expression.h: Don't include symtab.h.
(struct block): Forward declare.
I noticed that there are still many places referring to non-const
blocks. This constifies all the remaining ones that I found that
could be constified.
In a few spots, this search found unused variables or fields. I
removed these. I've also removed some unnecessary casts to
"struct block *".
gdb/ChangeLog
2019-03-24 Tom Tromey <tom@tromey.com>
* c-exp.y (typebase): Remove casts.
* gdbtypes.c (lookup_unsigned_typename, )
(lookup_signed_typename): Remove cast.
* eval.c (parse_to_comma_and_eval): Remove cast.
* parse.c (write_dollar_variable): Remove cast.
* block.h (struct block) <superblock>: Now const.
* symfile-debug.c (debug_qf_map_matching_symbols): Update.
* psymtab.c (psym_map_matching_symbols): Make "block" const.
(map_block): Make "block" const.
* symfile.h (struct quick_symbol_functions)
<map_matching_symbols>: Constify block argument to "callback".
* symtab.c (basic_lookup_transparent_type_quick): Make "block"
const.
(find_pc_sect_compunit_symtab): Make "b" const.
(find_symbol_at_address): Likewise.
(search_symbols): Likewise.
* dwarf2read.c (dw2_lookup_symbol): Make "block" const.
(dw2_debug_names_lookup_symbol): Likewise.
(dw2_map_matching_symbols): Update.
* p-valprint.c (pascal_val_print): Remove "block".
* ada-lang.c (ada_add_global_exceptions): Make "b" const.
(aux_add_nonlocal_symbols): Make "block" const.
(resolve_subexp): Remove cast.
* linespec.c (iterate_over_all_matching_symtabs): Make "block"
const.
(iterate_over_file_blocks): Likewise.
* f-exp.y (%union) <bval>: Remove.
* coffread.c (patch_opaque_types): Make "b" const.
* spu-tdep.c (spu_catch_start): Make "block" const.
* c-valprint.c (print_unpacked_pointer): Remove "block".
* symmisc.c (dump_symtab_1): Make "b" const.
(block_depth): Make "block" const.
* d-exp.y (%union) <bval>: Remove.
* cp-support.h (cp_lookup_rtti_type): Update.
* cp-support.c (cp_lookup_rtti_type): Make "block" const.
* psymtab.c (psym_lookup_symbol): Make "block" const.
(maintenance_check_psymtabs): Make "b" const.
* python/py-framefilter.c (extract_sym): Make "sym_block" const.
(enumerate_locals, enumerate_args): Update.
* python/py-symtab.c (stpy_global_block): Make "block" const.
(stpy_static_block): Likewise.
* inline-frame.c (block_starting_point_at): Make "new_block"
const.
* block.c (find_block_in_blockvector): Make return type const.
(blockvector_for_pc_sect): Make "b" const.
(find_block_in_blockvector): Make "b" const.
I ran across a comment in symfile.c today:
/* Clear globals which might have pointed into a removed objfile.
FIXME: It's not clear which of these are supposed to persist
between expressions and which ought to be reset each time. */
It seems to me that this can be clarified: the parser entry points
ought to reset the innermost block tracker (and the expression context
block), and these should not be considered valid for code to use at
arbitrary times -- only immediately after an expression has been
parsed.
This patch implements this idea. This could be further improved by
removing the parser globals and changing the parser functions to
return this information, but I have not done this.
Tested by the buildbot.
gdb/ChangeLog
2019-03-23 Tom Tromey <tom@tromey.com>
* varobj.c (varobj_create): Update.
* symfile.c (clear_symtab_users): Don't reset innermost_block.
* printcmd.c (display_command, do_one_display): Don't reset
innermost_block.
* parser-defs.h (enum innermost_block_tracker_type): Move to
expression.h.
(innermost_block): Update comment.
* parse.c (parse_exp_1): Add tracker_types parameter.
(parse_exp_in_context): Rename from parse_exp_in_context_1. Add
tracker_types parameter. Reset innermost_block.
(parse_exp_in_context): Remove.
(parse_expression_for_completion): Update.
* objfiles.c (~objfile): Don't reset expression_context_block or
innermost_block.
* expression.h (enum innermost_block_tracker_type): Move from
parser-defs.h.
(parse_exp_1): Add tracker_types parameter.
* breakpoint.c (set_breakpoint_condition, watch_command_1): Don't
reset innermost_block.
objfiles.h needs "struct bcache" to be complete, so it should include
bcache.h. This patch implements this.
Tested by rebuilding.
gdb/ChangeLog
2019-03-23 Tom Tromey <tom@tromey.com>
* objfiles.h: Include bcache.h.
I found a couple of spots that manually saved and restored the current
language. This patch changes them to use
scoped_restore_current_language.
Tested by the buildbot.
gdb/ChangeLog
2019-03-23 Tom Tromey <tom@tromey.com>
* linespec.c (get_current_search_block): Use
scoped_restore_current_language.
* symmisc.c (dump_symtab): Use scoped_restore_current_language.
Pauth address signing is enabled at binary compile time. When enabled the
return addresses for functions may be mangled. This patch adds functionality
to restore the original address for use in the prologue scan unwinder.
In the prologue analyzer, check for PACIASP/PACIBSP (enable address mangling)
and AUTIASP/AUTIBSP (disable address mangling).
When unwinding the PC from the prologue, unmask the register if required.
Add a test case to the prologue tests.
gdb/ChangeLog:
* aarch64-tdep.c (aarch64_analyze_prologue): Check for pauth
instructions.
(aarch64_analyze_prologue_test): Add PACIASP test.
(aarch64_prologue_prev_register): Unmask PC value.
Pauth address signing is enabled at binary compile time. When enabled the
return addresses for functions may be mangled. This patch adds functionality
to restore the original address for use in the DWARF unwinder.
DW_CFA_AARCH64_negate_ra_state in a binary indicates the toggling of address
signing between enabled and disabled. Ensure the state is stored in the DWARF
register ra_state.
Ensure the pauth DWARF registers are initialised.
gdb/ChangeLog:
* aarch64-tdep.c (aarch64_frame_unmask_address): New function.
(aarch64_dwarf2_prev_register): Unmask PC value.
(aarch64_dwarf2_frame_init_reg): Init pauth registers.
(aarch64_execute_dwarf_cfa_vendor_op): Check for
DW_CFA_AARCH64_negate_ra_state.
(aarch64_gdbarch_init): Add aarch64_execute_dwarf_cfa_vendor_op.
Map the pauth registers to DWARF.
Add a new pseudo register ra_state and also map this to DWARF. This register
is hidden from the user - prevent it from being read or written to. It will
be used for the unmangling of addresses.
gdb/ChangeLog:
* aarch64-tdep.c (aarch64_dwarf_reg_to_regnum): Check for pauth
registers.
(aarch64_pseudo_register_name): Likewise.
(aarch64_pseudo_register_type): Likewise.
(aarch64_pseudo_register_reggroup_p): Likewise.
(aarch64_gdbarch_init): Add pauth registers.
* aarch64-tdep.h (AARCH64_DWARF_PAUTH_RA_STATE): New define.
(AARCH64_DWARF_PAUTH_DMASK): Likewise.
(AARCH64_DWARF_PAUTH_CMASK): Likewise.
(struct gdbarch_tdep): Add regnum for ra_state.
Add the pauth registers to the regset lists.
Add a new regset type OPTIONAL_REGS which allows for the regset read to fail.
Once the read fails, it will not be checked again. This allows targets with
optional features to keep a single static regset_info structure.
gdb/ChangeLog:
* arch/aarch64.h (AARCH64_PAUTH_REGS_SIZE): New define.
gdb/gdbserver/ChangeLog:
* linux-aarch64-low.c (aarch64_store_pauthregset): New function.
* linux-low.c (regsets_store_inferior_registers): Allow optional reads
to fail.
* linux-low.h (enum regset_type): Add OPTIONAL_REGS.
Initialise the pauth registers when creating a target description, and store
the regnum of the first pauth register.
Use ptrace to read the registers in the pauth feature.
Do not allow the registers to be written.
gdb/ChangeLog:
* aarch64-linux-nat.c (fetch_pauth_masks_from_thread): New
function.
(aarch64_linux_nat_target::fetch_registers): Read pauth registers.
* aarch64-tdep.c (aarch64_cannot_store_register): New function.
(aarch64_gdbarch_init): Add puth registers.
* aarch64-tdep.h (struct gdbarch_tdep): Add pauth features.
* arch/aarch64.h (AARCH64_PAUTH_DMASK_REGNUM): New define.
(AARCH64_PAUTH_CMASK_REGNUM): Likewise.
Add aarch64_get_hwcap functions for reading the HWCAP.
From this extract the PACA value and use this to enable pauth.
gdb/ChangeLog:
* aarch64-linux-nat.c
(aarch64_linux_nat_target::read_description): Read PACA hwcap.
* aarch64-linux-tdep.c
(aarch64_linux_core_read_description): Likewise.
(aarch64_linux_get_hwcap): New function.
* aarch64-linux-tdep.h (AARCH64_HWCAP_PACA): New define.
(aarch64_linux_get_hwcap): New declaration.
gdb/gdbserver/ChangeLog:
* linux-aarch64-low.c (AARCH64_HWCAP_PACA): New define.
(aarch64_get_hwcap): New function.
(aarch64_arch_setup): Read APIA hwcap.
Pointer Authentication is a new feature in AArch64 v8.3-a. When enabled in
the compiler, function return addresses will be mangled by the kernel.
Add register description xml and wire up to aarch64_linux_read_description.
This description includes the two pauth user registers.
Nothing yet uses the feature - that is added in later patches.
gdb/ChangeLog:
* aarch64-linux-nat.c
(aarch64_linux_nat_target::read_description): Add pauth param.
* aarch64-linux-tdep.c
(aarch64_linux_core_read_description): Likewise.
* aarch64-tdep.c (struct target_desc): Add in pauth.
(aarch64_read_description): Add pauth param.
(aarch64_gdbarch_init): Likewise.
* aarch64-tdep.h (aarch64_read_description): Likewise.
* arch/aarch64.c (aarch64_create_target_description): Likewise.
* arch/aarch64.h (aarch64_create_target_description): Likewise.
* features/Makefile: Add new files.
* features/aarch64-pauth.c: New file.
* features/aarch64-pauth.xml: New file.
gdb/doc/ChangeLog:
* gdb.texinfo: Describe pauth feature.
gdb/gdbserver/ChangeLog:
* linux-aarch64-ipa.c (get_ipa_tdesc): Add pauth param.
(initialize_low_tracepoint): Likewise.
* linux-aarch64-low.c (aarch64_arch_setup): Likewise.
* linux-aarch64-tdesc-selftest.c (aarch64_tdesc_test): Likewise.
* linux-aarch64-tdesc.c (struct target_desc): Likewise.
(aarch64_linux_read_description): Likewise.
* linux-aarch64-tdesc.h (aarch64_linux_read_description): Likewise.
I noticed that handle_inferior_event is just a small wrapper that
frees the value chain. This patch replaces it with a
scoped_value_mark, reducing the number of lines of code here.
Regression tested on x86-64 Fedora 29.
gdb/ChangeLog
2019-03-20 Tom Tromey <tromey@adacore.com>
* infrun.c (handle_inferior_event): Rename from
handle_inferior_event_1. Create a scoped_value_mark.
(handle_inferior_event): Remove.
If you run "gdb -i=mi2" and set a "display", then when "next"ing the
displays will be shown twice:
~"1: x = 23\n"
~"7\t printf(\"%d\\n\", x);\n"
~"1: x = 23\n"
*stopped,reason="end-stepping-range",frame={addr="0x0000000000400565",func="main",args=[],file="q.c",fullname="/tmp/q.c",line="7"},thread-id="1",stopped-threads="all",core="1"
The immediate cause of this is this code in mi_on_normal_stop_1:
print_stop_event (mi_uiout);
console_interp = interp_lookup (current_ui, INTERP_CONSOLE);
if (should_print_stop_to_console (console_interp, tp))
print_stop_event (mi->cli_uiout);
... which obviously prints the stop twice.
However, I think the first call to print_stop_event is intended just
to emit the MI *stopped notification, which explains why the source
line does not show up two times.
This patch fixes the bug by changing print_stop_event to only call
do_displays for non-MI-like ui-outs.
Tested on x86-64 Fedora 29.
gdb/ChangeLog
2019-03-19 Tom Tromey <tromey@adacore.com>
* mi/mi-interp.c (mi_on_normal_stop_1): Only show displays once.
* infrun.h (print_stop_event): Add "displays" parameter.
* infrun.c (print_stop_event): Add "displays" parameter.
gdb/testsuite/ChangeLog
2019-03-19 Tom Tromey <tromey@adacore.com>
* gdb.mi/mi2-cli-display.c: New file.
* gdb.mi/mi2-cli-display.exp: New file.
This commit add comments describing tui_ui_out and its fields, and
cleans up the code a little bit.
Also switch to using in-class initialization so that the initial
values can be seen alongside the comments.
I see no reason for initializing m_line as -1 instead of 0, since all
the checks in the .c file are of the form "> 0". AFAICS there's no
practical difference between -1 and 0. So it seems simpler to
initialize it as 0.
There's a bit of redundancy in tui_ui_out::do_field_string, which is
fixed by this commit.
gdb/ChangeLog:
2019-03-19 Pedro Alves <palves@redhat.com>
* tui/tui-out.c (tui_ui_out::do_field_string): Simplify.
(tui_ui_out::do_text): Add comments. Reset M_LINE to 0 instead of
to -1. Fix TABs vs spaces.
(tui_ui_out::tui_ui_out): Don't initialize fields here.
* tui/tui-out.h (tui_ui_out) Add intro comments.
<m_line, m_start_of_line>: In-class initialize, and add describing
comment.
The following commit broke the build for Arm:
d3a70e03cf
Change iterate_over_lwps to take a gdb::function_view
Correct the changes made to arm_linux_insert_hw_breakpoint1 and make
similar changes to arm_linux_remove_hw_breakpoint1.
2019-03-18 Alan Hayward <alan.hayward@arm.com>
* arm-linux-nat.c (arm_linux_insert_hw_breakpoint1): Fix
variable names.
(arm_linux_remove_hw_breakpoint1): Use a gdb::function_view.
The first time you type UP or DOWN arrow in the command window, GDB
should scroll the source window, but instead it displays the line
number and the file name in the command window(?).
What happens there is that the first time we call
tui_ui_out::do_field_int, it doesn't initialize m_line, because
m_start_of_line is -1, as set by the constructor; and then the
following call to tui_ui_out::do_field_string falls back to
cli_ui_out::do_field_string because m_line is zero.
The problem is caused by a typo in the C++ification of tui_ui_out,
commit 112e8700a6, where m_line and m_start_of_line's initial values
were swapped from what they used to be:
-struct ui_out *
-tui_out_new (struct ui_file *stream)
+tui_ui_out::tui_ui_out (ui_file *stream)
+: cli_ui_out (stream, 0),
+ m_line (0),
+ m_start_of_line (-1)
{
-
- /* Initialize our fields. */
- data->line = -1;
- data->start_of_line = 0;
This commit fixes it.
gdb/ChangeLog:
2019-03-18 Pedro Alves <palves@redhat.com>
Eli Zaretskii <eliz@gnu.org>
* tui/tui-out.c (tui_ui_out::tui_ui_out): Fix initialization of
m_line and m_start_of_line.
gdb/ChangeLog:
2019-03-18 Eli Zaretskii <eliz@gnu.org>
* tui/tui-io.c (gdb_wgetch): Don't echo CR.
(tui_getc): When gdb_wgetch returns a CR, behave the same as when
it returns a newline. This fixes a regression in TUI mode, whereby
the next line is output on the same screen line as the user input.
The earlier patch to change minimal symbol allocations to use xmalloc
erroneously left a call to obstack_blank in
minimal_symbol_reader::install. Because obstack_blank does not finish
the object allocation on an obstack, this in turn could cause invalid
memory reads in some situations.
This patch fixes the problem by removing the call. Tested on x86-64
Fedora 29; also verified with valgrind.
gdb/ChangeLog
2019-03-18 Tom Tromey <tromey@adacore.com>
* minsyms.c (minimal_symbol_reader::install): Remove call to
obstack_blank.
With styling enabled, I think the way we display the TUI's
highlighted/current line is very ugly and distracting. The problem in
my view is that we reverse foreground/background in colored text as
well, leading to rainbow of background colors.
This patch changes that to something that I find much more sensible --
only reverse the default foreground/background colors, leave styled
text colors alone. If the foreground color is not the default
(because the text was styled), leave the foreground color as is. If
e.g., the terminal is fg=BLACK, and bg=WHITE, and the style wants to
print text in RED, reverse the background color (print in BLACK), but
still print the text in RED.
Note: The new ui_file_style::set_fg method isn't called set_foreground
instead, because set_foreground is a macro in /usr/lib/term.h (ncurses).
gdb/ChangeLog:
2019-03-18 Pedro Alves <palves@redhat.com>
* tui/tui-io.c (reverse_mode_p, reverse_save_bg, reverse_save_fg):
New globals.
(apply_style): New, factored out from ...
(apply_ansi_escape): ... this. Handle reverse video mode.
(tui_set_reverse_mode): New function.
* tui/tui-io.h (tui_set_reverse_mode): New declaration.
* tui/tui-winsource.c (tui_show_source_line): Use
tui_set_reverse_mode instead of setting A_STANDOUT.
* ui-style.h (struct ui_file_style) <set_reverse, set_fg, set_bg>:
New setter methods.
This commit fixes two issues in scrolling right in the TUI:
#1 - Scrolling right with the arrow keys, the first keypress doesn't
do anything. The problem is that copy_source_line() checks if
(column < first_col), and because of the ++column directly before, it
basically starts with 1 instead of 0.
#2 - Scrolling right handles TABS and escaped characters as single
characters, which just looks weird. The problem is that there's a
spot that misses handling TABS.
gdb/ChangeLog:
2019-03-18 Hannes Domani <ssbssa@yahoo.de>
* tui/tui-source.c (copy_source_line): Fix handling of 'column'.
Handle tabs.
Using ptype on an array type in Ada can sometimes show an incorrect
high bound. This happens because ada_evaluate_subexp will create an
array with an incorrect upper bound in the EVAL_AVOID_SIDE_EFFECTS
case.
This patch fixes the problem by arranging to always create such an
array with valid bounds.
Tested on x86-64 Fedora 29.
gdb/ChangeLog
2019-03-18 Tom Tromey <tromey@adacore.com>
* ada-lang.c (empty_array): Add "high" parameter.
(ada_evaluate_subexp): Update.
gdb/testsuite/ChangeLog
2019-03-18 Joel Brobecker <brobecker@adacore.com>
Tom Tromey <tromey@adacore.com>
* gdb.ada/ptype_array/pck.adb: New file.
* gdb.ada/ptype_array/pck.ads: New file.
* gdb.ada/ptype_array/foo.adb: New file.
* gdb.ada/ptype_array.exp: New file.
The build failure was noticed by Helmut Jarausch in
https://bugs.gentoo.org/680232:
$ ./configure CXXFLAGS='-std=c++17 -Os'
...
CXXLD gdb
ld: init.o: in function `initialize_all_files()':
init.c:(.text+0x113): undefined reference to `_initialize_string_view_selftests()'
It happens because '_initialize_string_view_selftests()' is
conditionally defined based on C++ default.
The change defines '_initialize_string_view_selftests()'
unconditionally and leaves implementation a no-op on c++17
compilers.
gdb/ChangeLog:
2019-03-17 Sergei Trofimovich <siarheit@google.com>
* unittests/string_view-selftests.c: Define
_initialize_string_view_selftests unconditionally.
There is unused variable text_vma in function windows_make_so. This
leads to build error on Windows using Cygwin.
gdb/ChangeLog:
2019-03-17 Vladimir Martyanov <vilgeforce@gmail.com>
PR gdb/24350
* windows-nat.c (windows_make_so): Remove unused text_vma variable.
There are a wrong format strings in function display_selector() in
file windows-nat.c. This leads to build error using Cygwin on Windows.
LDT_ENTRY.HighWord is a DWORD, which is unsigned long int, so the
format specification should be for long int, not simply int.
gdb/ChangeLog:
2019-03-17 Vladimir Martyanov <vilgeforce@gmail.com>
PR gdb/24351
* windows-nat.c (display_selector): Format specifications fixed
Without this change, when the current line is longer than the source
window width, redisplaying that line overwrites the window frame and
also portions of the next line.
gdb/ChangeLog:
2019-03-17 Eli Zaretskii <eliz@gnu.org>
* tui/tui-winsource.c (tui_set_is_exec_point_at): Call
tui_refill_source_window instead of tui_refresh_win, to update the
current execution line. This fixes redisplay of the current line
when stepping through very long lines with "next" or "step".
gdb/ChangeLog:
2019-03-16 Eli Zaretskii <eliz@gnu.org>
* source-cache.c (source_cache::get_source_lines): Call
find_source_lines to initialize s->nlines. This fixes vertical
scrolling of TUI source window when the DOWN arrow is pressed.
gdb/ChangeLog:
2019-03-16 Eli Zaretskii <eliz@gnu.org>
* tui/tui-winsource.c (tui_show_source_line): Revert "Use
wclrtoeol in tui_show_source_line". This reverts changes made in
commit 4a3045920b.
This changes struct minimal_symbol to inherit from general_symbol_info
and updates various macros to cope.
Because MSYMBOL_SET_LANGUAGE and MSYMBOL_SET_NAMES were only used from
a single spot, this patch removes them in favor of simply inlining
their definitions. I consider this to be somewhat cleaner, not least
because the "phony polymorphism" provided by such macros is not useful
in practice.
gdb/ChangeLog
2019-03-15 Tom Tromey <tom@tromey.com>
* symtab.h (struct minimal_symbol): Derive from
general_symbol_info.
(MSYMBOL_VALUE, MSYMBOL_VALUE_RAW_ADDRESS)
(MSYMBOL_VALUE_ADDRESS, MSYMBOL_VALUE_BYTES)
(MSYMBOL_BLOCK_VALUE, MSYMBOL_VALUE_CHAIN, MSYMBOL_LANGUAGE)
(MSYMBOL_SECTION, MSYMBOL_OBJ_SECTION, MSYMBOL_NATURAL_NAME)
(MSYMBOL_LINKAGE_NAME, MSYMBOL_DEMANGLED_NAME)
(MSYMBOL_SEARCH_NAME): Update.
(MSYMBOL_SET_LANGUAGE, MSYMBOL_SET_NAMES): Remove.
* solib.c (gdb_bfd_lookup_symbol_from_symtab): Don't use memset.
* minsyms.c (minimal_symbol_reader::record_full): Update.
minimal_symbol_reader::install copies minsyms from the msym_bunch
objects into the allocated memory. It seemed better to me to do this
via memcpy, as that is frequently optimized in libc.
gdb/ChangeLog
2019-03-15 Tom Tromey <tom@tromey.com>
* minsyms.c (minimal_symbol_reader::install): Use memcpy.
Currently, minimal symbols are allocated on the per-BFD obstack.
However, it is also possible for multiple symbol readers to create
minimal symbols for a given objfile. In this case, the minimal
symbols will be reallocated on the obstack, leading to some waste of
storage.
This is a memory leak, but I think it won't be caught by tools like
valgrind, because valgrind doesn't know about obstacks.
This patch fixes the problem by using malloc to allocate the storage
for minimal symbols.
gdb/ChangeLog
2019-03-15 Tom Tromey <tom@tromey.com>
* objfiles.h (struct objfile_per_bfd_storage) <msymbols>: Now a
unique_xmalloc_ptr.
(objfile::msymbols_range::begin, objfile::msymbols_range::end):
Update.
* minsyms.c (lookup_minimal_symbol_by_pc_section)
(build_minimal_symbol_hash_tables)
(minimal_symbol_reader::install): Update.
This changes objfile_per_bfd_storage::demangled_names_hash to be an
htab_up. This lets us remove some manual management code from the
objfile_per_bfd_storage destructor.
gdb/ChangeLog
2019-03-15 Tom Tromey <tom@tromey.com>
* symtab.c (create_demangled_names_hash): Update.
(symbol_set_names): Update.
* objfiles.h (struct objfile_per_bfd_storage)
<demangled_names_hash>: Now an htab_up.
* objfiles.c (objfile_per_bfd_storage): Simplify.
There's no reason that the objfile_per_bfd_storage must be allocated
via bfd_alloc. This patch changes objfile_per_bfd_storage to be
managed more simply, via ordinary new and delete; and moves some code
into its (new) destructor.
While doing this I also noticed an extra initialization of
language_of_main, and removed it.
gdb/ChangeLog
2019-03-15 Tom Tromey <tom@tromey.com>
* objfiles.h (struct objfile_per_bfd_storage): Declare
destructor.
* objfiles.c (objfile_per_bfd_storage::~objfile_per_bfd_storage):
New.
(get_objfile_bfd_data): Use new. Don't initialize
language_of_main.
(free_objfile_per_bfd_storage): Remove.
(objfile_bfd_data_free, objfile::~objfile): Use delete.
I was curious what used the terminating "null" minimal symbol; and
after looking I could not find anything. This patch removes
terminate_minimal_symbol_table and the extra minimal symbol that is
allocated for it.
gdb/ChangeLog
2019-03-15 Tom Tromey <tom@tromey.com>
* symfile.c (reread_symbols): Update.
* objfiles.c (objfile::objfile): Update.
* minsyms.h (terminate_minimal_symbol_table): Don't declare.
* minsyms.c (lookup_minimal_symbol_by_pc_section): Update
comment.
(minimal_symbol_reader::install): Update.
(terminate_minimal_symbol_table): Remove.
* jit.c (jit_object_close_impl): Update.
minimal_symbol_reader::record_full does not need to initialize any
minsym fields to 0, because that was already done implicitly via the
use of XCNEW when allocating the msym_bunch.
gdb/ChangeLog
2019-03-15 Tom Tromey <tom@tromey.com>
* minsyms.c (minimal_symbol_reader::record_full): Remove some
initializations.
I noticed that objfile_per_bfd_storage::demangled_hash_languages is a
std::vector, which seemed quite large for something that,
fundamentally, can be represented as a bitset. This patch
reimplements it as a std::bitset.
gdb/ChangeLog
2019-03-15 Tom Tromey <tom@tromey.com>
* objfiles.h (struct objfile_per_bfd_storage)
<demangled_hash_languages>: Now a bitset.
* minsyms.c (add_minsym_to_demangled_hash_table): Update.
(lookup_minimal_symbol): Update.
Only one caller of minimal_symbol_reader::record_with_info was using
the return value, so this patch simplifies this code by having it
return void and changing that caller to use record_full instead.
gdb/ChangeLog
2019-03-15 Tom Tromey <tom@tromey.com>
* minsyms.h (class minimal_symbol_reader) <record_with_info>:
Don't return the symbol.
* coffread.c (record_minimal_symbol): Use record_full.
The MS-Windows port of ncurses fails to switch to a color pair if
one or both of the colors are the implicit default colors. This
change records the default colors when TUI is initialized, and
then specifies them explicitly when a color pair uses the default
colors. This allows color styling in TUI mode on MS-Windows.
gdb/ChangeLog:
2019-03-14 Eli Zaretskii <eliz@gnu.org>
* tui/tui-io.c [__MINGW32__]: Include windows.h. Declare
ncurses_norm_attr.
(tui_initialize_io) [__MINGW32__]: Record the default terminal
colors in ncurses_norm_attr.
(apply_ansi_escape) [__MINGW32__]: If a color in a color pair is
"none", replace it with the default color recorded in
ncurses_norm_attr.
If the first requested line is larger than the number of lines in the
source buffer, source_cache::extract_lines could crash, because it
would try to pass string::npos" to string::substr.
This patch avoids the crash by checking for this case.
This version of the patch changes get_source_lines to return
std::string.
gdb/ChangeLog
2019-03-14 Tom Tromey <tromey@adacore.com>
* source-cache.h (class source_cache) <get_source_lines>: Return
std::string.
* source-cache.c (source_cache::extract_lines): Handle case where
first_pos==npos. Return std::string.
(source_cache::get_source_lines): Update.
When the user toggles "set style enabled", the TUI should react by
redrawing the source window, if necessary. This patch implements this
behavior.
No test because the TUI is generally not tested.
This version of the patch incorporates Pedro's patch to provide a
clean way to force the TUI to update the source window's contents.
gdb/ChangeLog
2019-03-14 Pedro Alves <palves@redhat.com>
Tom Tromey <tromey@adacore.com>
* tui/tui-winsource.h (tui_refill_source_window): Declare.
* tui/tui-winsource.c (tui_refill_source_window): New function,
from...
(tui_horizontal_source_scroll): ... here. Move some logic.
* cli/cli-style.c (set_style_enabled): Notify new observable.
* tui/tui-hooks.c (tui_redisplay_source): New function.
(tui_attach_detach_observers): Attach or detach
tui_redisplay_source.
* observable.h (source_styling_changed): New observable.
* observable.c: Define source_styling_changed observable.
New in v2:
- Addressed comments about doc, updated the MI version table
- New doc for the Breakpoint information format
- New -fix-multi-location-breakpoint-output command, with associated
doc, test and NEWS updated accordingly
- Fixed the output, the locations list is now actually in the tuple
representing the breakpoint.
Various MI commands or events related to breakpoints output invalid MI
records when printing information about a multi-location breakpoint.
For example:
-break-insert allo
^done,bkpt={...,addr="<MULTIPLE>",...},{number="1.1",...},{number="1.2",...}
The problem is that according to the syntax [1], the top-level elements
are of type "result" and should be of the form "variable=value".
This patch changes the output to wrap the locations in a list:
^done,bkpt={...,addr="<MULTIPLE>",locations=[{number="1.1",...},{number="1.2",...}]}
The events =breakpoint-created, =breakpoint-modified, as well as the
-break-info command also suffer from this (and maybe others I didn't
find).
Since this is a breaking change for MI, we have to deal somehow with
backwards compatibility. The approach taken by this patch is to bump
the MI version, use the new syntax in MI3 while retaining the old syntax
in MI2. Frontends are expected to use a precise MI version (-i=mi2), so
if they do that they should be unaffected.
The patch also adds the command -fix-multi-location-breakpoint-output,
which front ends can use to enable this behavior with MI <= 2.
[1] https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Output-Syntax.html#GDB_002fMI-Output-Syntax
gdb/ChangeLog:
* NEWS: Mention that the new default MI version is 3. Mention
changes to the output of commands and events that deal with
multi-location breakpoints.
* breakpoint.c: Include "mi/mi-out.h".
(print_one_breakpoint): Change output syntax if using MI version
>= 3.
* mi/mi-main.h (mi_cmd_fix_multi_location_breakpoint_output):
New.
(mi_multi_location_breakpoint_output_fixed): New.
* mi/mi-main.c (fix_multi_location_breakpoint_output): New.
(mi_cmd_fix_multi_location_breakpoint_output): New.
(mi_multi_location_breakpoint_output_fixed): New.
* mi/mi-cmds.c (mi_cmds): Register command
-fix-multi-location-breakpoint-output.
* mi/mi-out.c (mi_out_new): Instantiate version 3 when using
interpreter "mi".
gdb/testsuite/ChangeLog:
* mi-breakpoint-location-ena-dis.exp: Rename to ...
* mi-breakpoint-multiple-locations.exp: ... this.
(make_breakpoints_pattern): New proc.
(do_test): Add mi_version parameter, test -break-insert,
-break-info and =breakpoint-created.
gdb/doc/ChangeLog:
* gdb.texinfo (Mode Options): Mention mi3.
(Interpreters): Likewise.
(GDB/MI Development and Front Ends): Add entry for MI 3 in
version table. Document -fix-multi-location-breakpoint-output.
(GDB/MI Breakpoint Information): Document format of breakpoint
location output.
When re-reviewing this [1] I noticed that there were two spots encoding
the logic of instantiating an mi_ui_out object based on the interpreter
name ("mi", "mi1", "mi2" or "mi3"):
- mi_interp::init
- mi_load_progress
Both encode the logic to choose what the default version is when the
interpreter name is "mi". I had forgotten the one in mi_load_progress.
Therefore, I propose extracting that logic to a single function. I
started to add a new overload of mi_out_new, then realized the current
mi_out_new wasn't very useful, being just a thing wrapper around "new
mi_ui_out". So I ended up with just an mi_out_new function taking the
interp name as parameter.
I ran the gdb.mi tests, and verified manually the behavior (including
the load command).
[1] https://sourceware.org/ml/gdb-patches/2019-01/msg00427.html
gdb/ChangeLog:
* mi/mi-out.h (mi_out_new): Change parameter to const char *.
* mi/mi-out.c (mi_out_new): Change parameter to const char *,
instantiate mi_ui_out based on interpreter name.
* mi/mi-interp.c (mi_interp::init): Use the new mi_out_new.
* mi/mi-main.c (mi_load_progress): Likewise.
Derive the pointer to the DTV array from the %r2 register on 32-bit
powerpc and %r13 on 64-bit powerpc.
gdb/ChangeLog:
* ppc-fbsd-tdep.c (ppcfbsd_get_thread_local_address): New.
(ppcfbsd_init_abi): Install gdbarch
"fetch_tls_load_module_address" and "get_thread_local_address"
methods.
Derive the pointer to the DTV array from the tp register.
gdb/ChangeLog:
* riscv-fbsd-tdep.c (riscv_fbsd_get_thread_local_address): New.
(riscv_fbsd_init_abi): Install gdbarch
"fetch_tls_load_module_address" and "get_thread_local_address"
methods.
Derive the pointer to the DTV array from the gs_base register. As
with FreeBSD/amd64, gs_base is currently only available via the native
target.
gdb/ChangeLog:
* i386-fbsd-tdep.c (i386fbsd_get_thread_local_address): New.
(i386fbsd_init_abi): Install gdbarch
"fetch_tls_load_module_address" and "get_thread_local_address"
methods.
Use the fs_base register to fetch the address of a thread's tcb and
calculate the address of the DTV array. This value is then passed to
fbsd_get_thread_local_address to compute the final variable address.
Note that fs_base is currently only available via the native target as
core dumps on FreeBSD do not store the value of fs_base.
gdb/ChangeLog:
* amd64-fbsd-tdep.c (amd64fbsd_get_thread_local_address): New.
(amd64fbsd_init_abi): Install gdbarch
"fetch_tls_load_module_address" and "get_thread_local_address"
methods.
The fbsd_get_thread_local_address function accepts the base address of
a thread's DTV array and the base address of an object file's link map
and uses this to compute a TLS variable's address. FreeBSD
architectures use an architecture-specific method to determine the
address of the DTV array pointer and call this helper function to
perform the rest of the address calculation.
* fbsd-tdep.c (fbsd_pspace_data_handle): New variable.
(struct fbsd_pspace_data): New type.
(get_fbsd_pspace_data, fbsd_pspace_data_cleanup)
(fbsd_read_integer_by_name, fbsd_fetch_rtld_offsets)
(fbsd_get_tls_index, fbsd_get_thread_local_address): New function.
(_initialize_fbsd_tdep): Initialize 'fbsd_pspace_data_handle'.
* fbsd-tdep.c (fbsd_get_thread_local_address): New prototype.
lookup_struct_elt is a new function which returns a tuple of
information about a component of a structure or union. The returned
tuple contains a pointer to the struct field object for the component
as well as a bit offset of that field within the structure. If the
field names a field in an anonymous substructure, the offset is the
"global" offset relative to the original structure type. If noerr is
set, then the returned tuple will set the field pointer to NULL to
indicate a missing component rather than throwing an error.
lookup_struct_elt_type is now reimplemented in terms of this new
function. It simply returns the type of the returned field.
gdb/ChangeLog:
* gdbtypes.c (lookup_struct_elt): New function.
(lookup_struct_elt_type): Reimplement via lookup_struct_elt.
* gdbtypes.h (struct struct_elt): New type.
(lookup_struct_elt): New prototype.
Update the comment above the function to reflect the code removal and
document the existing behavior.
gdb/ChangeLog:
* gdbtypes.c (lookup_struct_elt_type): Update comment and
remove disabled code block.
Permit TLS variable addresses to be resolved purely by an ABI rather
than requiring a target method. This doesn't try the target method if
the ABI function is present (even if the ABI function fails) to
simplify error handling.
gdb/ChangeLog:
* gdbarch.sh (get_thread_local_address): New method.
* gdbarch.h, gdbarch.c: Regenerate.
* target.c (target_translate_tls_address): Use
gdbarch_get_thread_local_address if present instead of
target::get_thread_local_address.
There isn't an 'objfile' parameter, instead 'load_module_addr' is used
to indicate the executable or shared library. Also, the function
throws errors rather than returning error values.
gdb/ChangeLog:
* target.h (target::get_thread_local_address): Update comment.
If a TLS variable is provided by a minisym from a separate debug file,
the separate debug file is passed to
gdbarch_fetch_tls_load_module_address. However, the object files
stored in the shared object list are the original object files, not
the separate debug object files. In this case,
svr4_fetch_objfile_link_map was failing to find the link map entry
since the debug object file is not in its internal list, only the
original object file.
gdb/ChangeLog:
* solib-svr4.c (svr4_fetch_objfile_link_map): Look for
objfile->separate_debug_objfile_backlink if not NULL.
The i386 BSD native target uses the same ptrace operations
(PT_[GS]ET[FG]SBASE) as the amd64 BSD native target to fetch and store
the registers.
The amd64 BSD native now uses 'tdep->fsbase_regnum' instead of
hardcoding AMD64_FSBASE_REGNUM and AMD64_GSBASE_REGNUM to support
32-bit targets. In addition, the store operations explicitly zero the
new register value before fetching it from the register cache to
ensure 32-bit values are zero-extended.
gdb/ChangeLog:
* amd64-bsd-nat.c (amd64bsd_fetch_inferior_registers): Use
tdep->fsbase_regnum instead of constants for fs_base and gs_base.
(amd64bsd_store_inferior_registers): Likewise.
* amd64-fbsd-nat.c (amd64_fbsd_nat_target::read_description):
Enable segment base registers.
* i386-bsd-nat.c (i386bsd_fetch_inferior_registers): Use
PT_GETFSBASE and PT_GETGSBASE.
(i386bsd_store_inferior_registers): Use PT_SETFSBASE and
PT_SETGSBASE.
* i386-fbsd-nat.c (i386_fbsd_nat_target::read_description): Enable
segment base registers.
* i386-fbsd-tdep.c (i386fbsd_core_read_description): Likewise.
As on amd64, these registers hold the base address of the fs and gs
segments, respectively. For i386 these two registers are 32 bits.
gdb/ChangeLog:
* amd64-fbsd-nat.c (amd64_fbsd_nat_target::read_description):
Update calls to i386_target_description to add 'segments'
parameter.
* amd64-tdep.c (amd64_init_abi): Set tdep->fsbase_regnum. Don't
add segment base registers.
* arch/i386.c (i386_create_target_description): Add 'segments'
parameter to enable segment base registers.
* arch/i386.h (i386_create_target_description): Likewise.
* features/i386/32bit-segments.xml: New file.
* features/i386/32bit-segments.c: Generate.
* i386-fbsd-nat.c (i386_fbsd_nat_target::read_description): Update
call to i386_target_description to add 'segments' parameter.
* i386-fbsd-tdep.c (i386fbsd_core_read_description): Likewise.
* i386-go32-tdep.c (i386_go32_init_abi): Likewise.
* i386-linux-tdep.c (i386_linux_read_description): Likewise.
* i386-tdep.c (i386_validate_tdesc_p): Add segment base registers
if feature is present.
(i386_gdbarch_init): Pass I386_NUM_REGS to set_gdbarch_num_regs.
Add 'segments' parameter to call to i386_target_description.
(i386_target_description): Add 'segments' parameter to enable
segment base registers.
(_initialize_i386_tdep) [GDB_SELF_TEST]: Add 'segments' parameter
to call to i386_target_description.
* i386-tdep.h (struct gdbarch_tdep): Add 'fsbase_regnum'.
(enum i386_regnum): Add I386_FSBASE_REGNUM and I386_GSBASE_REGNUM.
Define I386_NUM_REGS.
(i386_target_description): Add 'segments' parameter to enable
segment base registers.
gdb/gdbserver/ChangeLog:
* linux-x86-tdesc.c (i386_linux_read_description): Update call to
i386_create_target_description for 'segments' parameter.
* lynx-i386-low.c (lynx_i386_arch_setup): Likewise.
* nto-x86-low.c (nto_x86_arch_setup): Likewise.
* win32-i386-low.c (i386_arch_setup): Likewise.
This changes magic_null_ptid, not_sent_ptid, and any_thread_ptid to be
"const". This is a minor improvement that makes it so these can't be
accidentally modified.
Tested by rebuilding. I'm checking this in.
gdb/ChangeLog
2019-03-12 Tom Tromey <tromey@adacore.com>
* remote.c (magic_null_ptid, not_sent_ptid, any_thread_ptid): Now
const. Add initializers.
(_initialize_remote): Don't initialize ptid globals.
$ make test-cp-name-parser
...
CXX test-cp-name-parser.o
src/gdb/cp-name-parser.y: In function ‘int gdb::main(int, char**)’:
src/gdb/cp-name-parser.y:2137:6: error: unused variable ‘len’ [-Werror=unused-variable]
int len;
^~~
cc1plus: all warnings being treated as errors
gdb/ChangeLog:
2019-03-12 Pedro Alves <palves@redhat.com>
* cp-name-parser.y (main): Remove unused 'len' variable.
This makes null_ptid and minus_one_ptid "const". I think this is an
improvement because it means they can't be accidentally modified.
2019-03-12 Tom Tromey <tromey@adacore.com>
* common/ptid.c (null_ptid, minus_one_ptid): Now const.
* common/ptid.h (null_ptid, minus_one_ptid): Now const.
dwarf2_find_containing_comp_unit has two assignments to "this_cu" in
quick succession, both of which are just:
this_cu = dwarf2_per_objfile->all_comp_units[low];
... with no intervening assignments.
This patch removes the second assignment. I'm checking this in as
obvious. Tested on x86-64 Fedora 29.
gdb/ChangeLog
2019-03-11 Tom Tromey <tromey@adacore.com>
* dwarf2read.c (dwarf2_find_containing_comp_unit): Remove
redundant assignment to "this_cu".
We return INCOMPATIBLE_TYPE_BADNESS for all these type codes, so we might as
well just let them go to the default case.
Incidentally, this patch also makes this false positive error go away when
compiling with gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0, default compiler on
Ubuntu 18.04.
CXX gdbtypes.o
/home/smarchi/src/binutils-gdb/gdb/gdbtypes.c: In function ‘rank rank_one_type(type*, type*, value*)’:
/home/smarchi/src/binutils-gdb/gdb/gdbtypes.c:4259:1: error: control reaches end of non-void function [-Werror=return-type]
}
^
gdb/ChangeLog:
* gdbtypes.c (rank_one_type): Remove unnecessary cases from switch.
Without this patch, the help stops after 'e.g.' :
(gdb) apropos \(inferior\|thread\) event
set print inferior-events -- Set printing of inferior events (e.g.
set print thread-events -- Set printing of thread events (such as thread start and exit)
show print inferior-events -- Show printing of inferior events (e.g.
show print thread-events -- Show printing of thread events (such as thread start and exit)
Using the same notation as for the thread evenets (i.e. 'such as') gives:
(gdb) apropos \(inferior\|thread\) event
set print inferior-events -- Set printing of inferior events (such as inferior start and exit)
set print thread-events -- Set printing of thread events (such as thread start and exit)
show print inferior-events -- Show printing of inferior events (such as inferior start and exit)
show print thread-events -- Show printing of thread events (such as thread start and exit)
gdb/ChangeLog:
2019-03-08 Eli Zaretskii <eliz@gnu.org>
PR/24315
* utils.c (can_emit_style_escape) [_WIN32]: Don't disable styling
on MS-Windows if $TERM is not defined.
* cli/cli-style.c: Set cli_styling to 1 in the MinGW build.
* posix-hdep.c (gdb_console_fputs):
* mingw-hdep.c (rgb_to_16colors, gdb_console_fputs): New
functions.
* ui-file.h (gdb_console_fputs): Add prototype.
* ui-file.c (stdio_file::puts): Call gdb_console_fputs, and fall
back to fputs only if the former returns zero.
TARGET_WAITKIND_NO_RESUMED doesn't have an associated event thread, so
we shouldn't be referring to inferior_thread() assuming it points to
one.
This was caught on the multi-target branch, where we always switch to
no-thread-selected whenever we start handling an event, exactly to
catch places that incorrectly use "inferior_ptid/inferior_thread()"
without switching to the right event thread / target.
Here, on the branch, we assert in inferior_thread() because
TARGET_WAITKIND_NO_RESUMED doesn't have an associated event thread, so
inferior_ptid is still null_ptid.
gdb/ChangeLog:
2019-03-07 Pedro Alves <palves@redhat.com>
* infrun.c (normal_stop): Also check for
TARGET_WAITKIND_NO_RESUMED before referring to inferior_thread().
The function value_from_host_double can be moved from f-lang.c into
value.c as a generally useful function, and then used more widely.
Tested on X86-64/GNU Linux with no regressions.
gdb/ChangeLog:
* f-lang.c (value_from_host_double): Moved to...
* value.c (value_from_host_double): ...here.
* value.h (value_from_host_double): Declare.
* guile/scm-math.c (vlscm_convert_typed_number): Use
value_from_host_double.
(vlscm_convert_number): Likewise.
* guile/scm-value.c (gdbscm_value_to_real): Likewise.
* python/py-value.c (convert_value_from_python): Likewise.
This replaces a TRY/CATCH in write_gcore_file with a use of SCOPE_EXIT
instead. I find that this is simpler to understand.
2019-03-06 Tom Tromey <tom@tromey.com>
* gcore.c (write_gcore_file): Use SCOPE_EXIT.
free_current_contents is no longer used, so this patch removes it.
2019-03-06 Tom Tromey <tom@tromey.com>
* utils.h (free_current_contents): Don't declare.
* utils.c (free_current_contents): Remove.
This removes a cleanup from remote.c, replacing it with
unique_xmalloc_ptr.
2019-03-06 Tom Tromey <tom@tromey.com>
* remote.c (remote_target::remote_parse_stop_reply): Use
unique_xmalloc_ptr.
This removes the last cleanups from stabsread.c. Similar code in
dwarf2read.c was C++-ified, but considering that stabs are deprecated,
it seemed simpler to just change these allocations to use an obstack
and leave the data structures in place.
This patch renames field_info to stabs_field_info -- adding a
constructor here provoked a bug due to the resulting ODR violation.
2019-03-06 Tom Tromey <tom@tromey.com>
* stabsread.c (struct stabs_field_info): Rename from field_info.
<list, fnlist>: Add initializers.
<obstack>: New member.
(read_member_functions, read_struct_fields, read_baseclasses):
Allocate on obstack. Don't use cleanups.
(read_one_struct_field, read_member_functions, read_struct_fields)
(read_baseclasses, read_tilde_fields, attach_fn_fields_to_type)
(attach_fields_to_type, read_cpp_abbrev, read_member_functions)
(read_struct_type): Update.
This removes the last cleanup from linux-namespaces.c, replacing it
with a use of SCOPE_EXIT.
2019-03-06 Tom Tromey <tom@tromey.com>
* nat/linux-namespaces.c (linux_mntns_access_fs): Use SCOPE_EXIT.
* common/filestuff.h (make_cleanup_close): Don't declare.
* common/filestuff.c (do_close_cleanup, make_cleanup_close):
Remove.
This removes the last cleanup solib-aix.c, replacing it with a use of
make_scope_exit.
2019-03-06 Tom Tromey <tom@tromey.com>
* solib-aix.c: Use make_scope_exit.
This removes the last cleanups from solib-svr4.c, replacing them with
uses of make_scope_exit.
2019-03-06 Tom Tromey <tom@tromey.com>
* solib-svr4.c (svr4_parse_libraries, svr4_current_sos_direct):
Use make_scope_exit.
This removes a cleanup from solib-svr4.c, replacing it with
make_scope_exit.
2019-03-06 Tom Tromey <tom@tromey.com>
* solib-svr4.c (disable_probes_interface): Remove parameter.
(svr4_handle_solib_event): Use make_scope_exit.
This C++ifies the remote notification code -- replacing function
pointers with virtual methods and using unique_ptr. This allows for
the removal of some cleanups.
2019-03-06 Tom Tromey <tom@tromey.com>
* remote.c (struct stop_reply_deleter): Remove.
(stop_reply_up): Update.
(struct stop_reply): Derive from notif_event. Don't typedef.
<regcache>: Now a std::vector.
(stop_reply_xfree): Remove.
(stop_reply::~stop_reply): Rename from stop_reply_dtr.
(remote_notif_stop_alloc_reply): Return a unique_ptr. Use new.
(remote_target::discard_pending_stop_replies): Use delete.
(remote_target::remote_parse_stop_reply): Update.
(remote_target::process_stop_reply): Update.
* remote-notif.h (struct notif_event): Add virtual destructor.
Remove "dtr" member.
(struct notif_client) <alloc_event>: Return a unique_ptr.
(notif_event_xfree): Don't declare.
(notif_event_up): New typedef.
* remote-notif.c (remote_notif_ack, remote_notif_parse): Update.
(notif_event_xfree, do_notif_event_xfree): Remove.
(remote_notif_state_xfree): Update.
This changes displaced_step_clear_cleanup to be a forward_scope_exit
and updates the callers.
gdb/ChangeLog
2019-03-06 Tom Tromey <tom@tromey.com>
* infrun.c (displaced_step_clear_cleanup): Now a
forward_scope_exit type.
(displaced_step_prepare_throw): Update.
(displaced_step_fixup): Update.
This updates another couple of comments to remove mentions of
cleanups.
gdb/ChangeLog
2019-03-06 Tom Tromey <tom@tromey.com>
* inferior.h (class inferior): Update comment.
* gdbthread.h (class thread_info): Update comment.
This removes the remaining cleanups from coffread.c.
Tested by the buildbot and also some manual testing.
This version includes the fix provided by Joel.
gdb/ChangeLog
2019-03-06 Joel Brobecker <brobecker@adacore.com>
Tom Tromey <tom@tromey.com>
* stabsread.h (struct stab_section_list): Remove.
(coffstab_build_psymtabs): Update.
* dbxread.c (symbuf_sections): Now a std::vector.
(sect_idx): New global.
(fill_symbuf): Update.
(coffstab_build_psymtabs): Change type of stabsects parameter.
Update.
* coffread.c (struct coff_symfile_info) <stabsects>: Now a
std::vector.
(linetab, linetab_offset, linetab_size, stringtab): Move earlier.
(coff_locate_sections): Update.
(coff_symfile_read): Remove cleanups. Update.
(init_stringtab): Add storage parameter.
(free_stringtab, free_stringtab_cleanup): Remove.
(init_lineno): Add storage parameter.
(free_linetab, free_linetab_cleanup): Remove.
All fork_save_infrun_state callers pass '1' as CLOBBER_REGS nowadays.
The larger hunk in fork_save_infrun_state is just a reindentation.
gdb/ChangeLog:
2019-03-06 Pedro Alves <palves@redhat.com>
* linux-fork.c (fork_info::clobber_regs): Delete.
(fork_load_infrun_state): Remove reference to 'clobber_regs'.
(fork_save_infrun_state): Remove 'clobber_regs' parameter. Update
comment. Adjust.
(scoped_switch_fork_info::scoped_switch_fork_info)
(checkpoint_command, linux_fork_context): Adjust
fork_save_infrun_state calls.
There's no need to iterate over all threads of all inferiors here.
gdb/ChangeLog:
2019-03-06 Pedro Alves <palves@redhat.com>
* linux-fork.c (inf_has_multiple_thread_cb): Delete.
(inf_has_multiple_threads): Return 'bool' and rewrite using
inferior_info::threads().
Don't rely on "inferior_ptid" deep within add_fork. In the
multi-target branch, I'm forcing inferior_ptid to null_ptid early in
infrun event handling to make sure we don't inadvertently rely on the
current thread/target when we shouldn't, and that caught some bad or
unnecessary assumptions throughout.
gdb/ChangeLog:
2019-03-06 Pedro Alves <palves@redhat.com>
* linux-fork.c (new_fork): New, split out of ...
(add_fork): ... this. Return void. Move "first fork" special
case from here, to ...
(checkpoint_command): ... here.
* linux-linux.h (add_fork): Return void.
This patch adds support for the older TYPE*SIZE typenames that are
still around in older code.
For implementation this currently reuses the kind mechanism, as under
gFortran the kind number is equivalent to the size, however, this is
not necessarily true for all compilers. If the rules for other
compilers are better understood then this code might need to be
improved slightly to allow for a distinction between size and kind,
however, adding this extra complexity now seems pointless.
gdb/ChangeLog:
* f-exp.y (direct_abs_decl): Handle TYPE*SIZE type names.
gdb/testsuite/ChangeLog:
* gdb.fortran/type-kinds.exp: Extend to cover TYPE*SIZE cases.
Adds support for the abs intrinsic function, this requires adding a
new pattern to the Fortran parser. Currently only float and integer
argument types are supported to ABS, complex is still not supported,
this can be added later if needed.
gdb/ChangeLog:
* f-exp.y: New token, UNOP_INTRINSIC.
(exp): New pattern using UNOP_INTRINSIC token.
(f77_keywords): Add 'abs' keyword.
* f-lang.c: Add 'target-float.h' and 'math.h' includes.
(value_from_host_double): New function.
(evaluate_subexp_f): Support UNOP_ABS.
gdb/testsuite/ChangeLog:
* gdb.fortran/intrinsics.exp: Extend to cover ABS.
Switch to using TYPE_CODE_CHAR for character types. This appears to
have little impact on the test results as gFortran uses the
DW_TAG_string_type to represent all character variables (as far as I
can see). The only place this has an impact is when the user casts a
variable to a character type, in which case GDB does now use the CHAR
type, and prints the variable as both a value and a character, for
example, before:
(gdb) p ((character) 97)
$1 = 97
and after:
(gdb) p ((character) 97)
$1 = 97 'a'
gdb/ChangeLog:
* f-lang.c (build_fortran_types): Use TYPE_CODE_CHAR for character
types.
gdb/testsuite/ChangeLog:
* gdb.fortran/type-kinds.exp: Update expected results.
Add a new builtin type, an 8-byte integer, and allow GDB to parse
'integer (kind=8)', returning the new 8-byte integer.
gdb/ChangeLog:
* f-exp.y (convert_to_kind_type): Handle integer (kind=8).
* f-lang.c (build_fortran_types): Setup builtin_integer_s8.
* f-lang.h (struct builtin_f_type): Add builtin_integer_s8 field.
gdb/testsuite/ChangeLog:
* gdb.fortran/type-kinds.exp: Test new integer type kind.
Expand the number of types that can be adjusted with a (kind=N) type
extension.
gdb/ChangeLog:
* f-exp.y (convert_to_kind_type): Handle more type kinds.
gdb/testsuite/ChangeLog:
* gdb.fortran/type-kinds.exp (test_cast_1_to_type_kind): New
function.
(test_basic_parsing_of_type_kinds): Expand types tested.
(test_parsing_invalid_type_kinds): New function.
The 'kind' keyword has two uses in Fortran, it is the name of a
builtin intrinsic function, and it is also a keyword used to create a
type of a specific kind.
This commit adds support for using kind as an intrinsic function, and
also adds some initial support for using kind to create types of a
specific kind.
This commit only allows the creation of the type 'character(kind=1)',
however, it will be easy enough to extend this in future to support
more type kinds.
The kind of any expression can be queried using the kind intrinsic
function. At the moment the kind returned corresponds to the size of
the type, this matches how gfortran handles kinds. However, the
correspondence between kind and type size depends on the compiler
and/or the specific target, so this might not be correct for
everyone. If we want to support different compilers/targets in future
the code to compute the kind from a type will need to be updated.
gdb/ChangeLog:
* expprint.c (dump_subexp_body_standard): Support UNOP_KIND.
* f-exp.y: Define 'KIND' token.
(exp): New pattern for KIND expressions.
(ptype): Handle types with a kind extension.
(direct_abs_decl): Extend to spot kind extensions.
(f77_keywords): Add 'kind' to the list.
(push_kind_type): New function.
(convert_to_kind_type): New function.
* f-lang.c (evaluate_subexp_f): Support UNOP_KIND.
* parse.c (operator_length_standard): Likewise.
* parser-defs.h (enum type_pieces): Add tp_kind.
* std-operator.def: Add UNOP_KIND.
gdb/testsuite/ChangeLog:
* gdb.fortran/intrinsics.exp: New file.
* gdb.fortran/intrinsics.f90: New file.
* gdb.fortran/type-kinds.exp: New file.
This is an initial restructure, it adds a new function in which
Fortran specific expressions can be evaluated. No Fortran specific
expressions are added with this commit though, so for now, the new
function just forwards all expressions to the default expression
handler, as such, there should be no user visible changes after this
commit. However, the new function will be useful in later commits.
gdb/ChangeLog:
* f-lang.c (evaluate_subexp_f): New function.
(exp_descriptor_f): New global.
(f_language_defn): Use exp_descriptor_f instead of
exp_descriptor_standard.
Use strncasecmp to compare Fortran dot operations (like .AND.) and for
the keywords list. This allows for some duplication to be removed
from the token arrays. I've also performed whitespace cleanup around
the code I've changed.
I have added some tests to ensure that upper and lowercase dot
operations are correctly tested. The keywords list remains always
lowercase for now.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* f-exp.y (struct token): Add comments.
(dot_ops): Remove uppercase versions and the end marker.
(f77_keywords): Likewise.
(yylex): Use ARRAY_SIZE to iterate over dot_ops, assert all
entries in the dot_ops array are case insensitive, and use
strncasecmp to compare strings. Also some whitespace cleanup in
this area. Similar for the f77_keywords array, except entries in
this list might be case sensitive.
gdb/testsuite/ChangeLog:
* gdb.fortran/dot-ops.exp: New file.
This patch cleans up the code used for parsing the Fortran logical
constants '.TRUE.' and '.FALSE.'. Instead of listing both upper and
lowercase versions of these strings we now use strncasecmp.
I've also switched to use ARRAY_SIZE for the array iteration, and I've
cleaned up whitespace in the vicinity of the code I've changed.
Finally, I've added a test to ensure that both the upper and lower
case versions of the logical constants are understood by GDB,
something that was missing previously.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* f-exp.y (struct f77_boolean_val): Add comments.
(boolean_values): Remove uppercase versions, and end marker.
(yylex): Use ARRAY_SIZE for iterating over boolean_values array,
and use strncasecmp to achieve case insensitivity. Additionally,
perform whitespace cleanup around this code.
gdb/testsuite/ChangeLog:
* gdb.fortran/types.exp (test_logical_literal_types_accepted):
Check upper and lower case logical literals.
John Darrington pointed out that commit 18cb7c9f3 ("Introduce
ATTRIBUTE_UNUSED_RESULT and use it") broke the build:
/home/john/binutils-gdb/gdb/remote-sim.c: In function 'void gdbsim_target_open(const char*, int)':
/home/john/binutils-gdb/gdb/remote-sim.c:765:18: error: ignoring return value of 'char** gdb_argv::release()', declared with attribute warn_unused_result [-Werror=unused-result]
This patch fixes the problem by arranging to use the result of the
release method.
Tested by rebuilding with a simulator enabled.
gdb/ChangeLog
2019-03-06 Tom Tromey <tromey@adacore.com>
* remote-sim.c (gdbsim_target_open): Use result of
gdb_argv::release.
Prior to this patch, calling functions on the inferior with arguments and
then using these arguments within a function resulted in an invalid
memory access. This is because Fortran arguments are typically passed as
pointers to values.
It is possible to call Fortran functions, but memory must be allocated in
the inferior, so a pointer can be passed to the function, and the
language must be set to C to enable C-style casting. This is cumbersome
and not a pleasant debug experience.
This patch implements the GNU Fortran argument passing conventions with
caveats. Firstly, it does not handle the VALUE attribute as there is
insufficient DWARF information to determine when this is the case.
Secondly, functions with optional parameters can only be called with all
parameters present. Both these cases are marked as KFAILS in the test.
Since the GNU Fortran argument passing convention has been implemented,
there is no guarantee that this patch will work correctly, in all cases,
with other compilers.
Despite these limitations, this patch improves the ease with which
functions can be called in many cases, without taking away the existing
approach of calling with the language set to C.
Regression tested on x86_64, aarch64 and POWER9 with GCC 7.3.0.
Regression tested with Ada on x86_64.
Regression tested with native-extended-gdbserver target board.
gdb/ChangeLog:
* eval.c (evaluate_subexp_standard): Call Fortran argument
wrapping logic.
* f-lang.c (struct value): A value which can be passed into a
Fortran function call.
(fortran_argument_convert): Wrap Fortran arguments in a pointer
where appropriate.
(struct type): Value ready for a Fortran function call.
(fortran_preserve_arg_pointer): Undo check_typedef, the pointer
is needed.
* f-lang.h (fortran_argument_convert): Declaration.
(fortran_preserve_arg_pointer): Declaration.
* infcall.c (value_arg_coerce): Call Fortran argument logic.
gdb/testsuite/ChangeLog:
* gdb.fortran/function-calls.exp: New file.
* gdb.fortran/function-calls.f90: New test.
A recent patch from Kevin Buettner taught me that the PyBytes API is
available on Python 2. This patch removes a couple of related #ifs in
the Python code.
Tested on x86-64 Fedora 29, using both Python 3.7 and Python 2.7.
gdb/ChangeLog
2019-03-05 Tom Tromey <tromey@adacore.com>
* python/py-prettyprint.c (print_string_repr): Remove #if.
* python/py-utils.c (unicode_to_encoded_string): Remove #if.
While debugging gdb, I printed the target stack and got:
(top-gdb) p g_target_stack
$10 = {
m_top = thread_stratum,
m_stack = {0x142b0b0, 0x13da600 <exec_ops>, 0x1c70690, 0x13d63b0 <ravenscar_ops>, 0x0, 0x0, 0x0}
}
(This is clearly from before the change to make ravenscar
multi-target-capable.)
Here, 0x142b0b0 is the singleton dummy target. It seems to me that
since this is always a singleton, it would be a bit nicer if it were a
global, so that it would be noted in the above.
This patch implements this idea, and now I get:
(top-gdb) p g_target_stack
$2 = {
m_top = dummy_stratum,
m_stack = {0x1f1b040 <the_dummy_target>, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}
}
I did not do the same for the debug target. It didn't seem as useful
to me.
gdb/ChangeLog
2019-03-05 Tom Tromey <tromey@adacore.com>
* target.c (the_dummy_target): Move later. Change type to
"dummy_target".
(initialize_targets): Don't initialize the_dummy_target.
I noticed that gdb_bfd_fdopenr is no longer used, so this patch
removes it. Tested by rebuilding and by grep.
gdb/ChangeLog
2019-03-05 Tom Tromey <tromey@adacore.com>
* gdb_bfd.c (gdb_bfd_fdopenr): Remove.
* gdb_bfd.h (gdb_bfd_fdopenr): Don't declare.
A customer noticed some mildly odd MI output, where CLI output was
split into multiple MI strings at unusual boundaries, like this:
~"$1 = (b => true"
~", p => 0x407260"
This is technically correct according to the MI spec, but still
unusual, in that there's no particular reason for the string to be
split where it is.
I tracked this down to a call to gdb_flush in generic_val_print.
Then, I went through all calls to gdb_flush and removed the ones I
thought were superfluous. In particular:
* Any call in the value-printing code;
* Likewise the type-printing code (just a single call); and
* Any call that immediately followed a printf that obviously
ended with a newline, my belief being that gdb's standard output
streams are line buffered (by inheriting the behavior from stdio)
Regression tested on x86-64 Fedora 29.
I didn't add a new test case. I tend to think we don't necessarily
want to specify this behavior in the tests. Let me know what you
think of this.
gdb/ChangeLog
2019-03-05 Tom Tromey <tromey@adacore.com>
* windows-nat.c (windows_nat_target::attach)
(windows_nat_target::detach): Don't call gdb_flush.
* valprint.c (generic_val_print, val_print, val_print_string):
Don't call gdb_flush.
* utils.c (defaulted_query): Don't call gdb_flush.
* typeprint.c (print_type_scalar): Don't call gdb_flush.
* target.c (target_announce_detach): Don't call gdb_flush.
* sparc64-tdep.c (adi_print_versions): Don't call gdb_flush.
* remote.c (extended_remote_target::attach): Don't call
gdb_flush.
* procfs.c (procfs_target::detach): Don't call gdb_flush.
* printcmd.c (do_examine): Don't call gdb_flush.
(info_display_command): Don't call gdb_flush.
* p-valprint.c (pascal_val_print): Don't call gdb_flush.
* nto-procfs.c (nto_procfs_target::attach): Don't call gdb_flush.
* memattr.c (info_mem_command): Don't call gdb_flush.
* mdebugread.c (mdebug_build_psymtabs): Don't call gdb_flush.
* m2-valprint.c (m2_val_print): Don't call gdb_flush.
* infrun.c (follow_exec, handle_command): Don't call gdb_flush.
* inf-ptrace.c (inf_ptrace_target::attach): Don't call gdb_flush.
* hppa-tdep.c (unwind_command): Don't call gdb_flush.
* gnu-nat.c (gnu_nat_target::attach): Don't call gdb_flush.
(gnu_nat_target::detach): Don't call gdb_flush.
* f-valprint.c (f_val_print): Don't call gdb_flush.
* darwin-nat.c (darwin_nat_target::attach): Don't call gdb_flush.
* cli/cli-script.c (read_command_lines): Don't call gdb_flush.
* cli/cli-cmds.c (shell_escape, print_disassembly): Don't call
gdb_flush.
* c-valprint.c (c_val_print): Don't call gdb_flush.
* ada-valprint.c (ada_print_scalar): Don't call gdb_flush.
This applies ATTRIBUTE_UNUSED_RESULT to ref_ptr::release and updates a
few spots to comply. I believe one use in install_default_visualizer
was in error, fixed by this patch.
gdb/ChangeLog
2019-03-05 Tom Tromey <tromey@adacore.com>
* varobj.c (update_dynamic_varobj_children): Update.
(install_default_visualizer): Use reset, not release.
* value.c (set_internalvar): Update.
* dwarf2loc.c (value_of_dwarf_reg_entry): Update.
* common/gdb_ref_ptr.h (class ref_ptr) <release>: Add
ATTRIBUTE_UNUSED_RESULT.
This applies ATTRIBUTE_UNUSED_RESULT to scoped_mmap::release and fixes
a couple of spots to comply.
gdb/ChangeLog
2019-03-05 Tom Tromey <tromey@adacore.com>
* nat/linux-btrace.c (linux_enable_bts, linux_enable_pt): Update.
* common/scoped_mmap.h (class scoped_mmap) <release>: Add
ATTRIBUTE_UNUSED_RESULT.
This introduces the new ATTRIBUTE_UNUSED_RESULT define, and applies it
to gdb_argv::release.
gdb/ChangeLog
2019-03-05 Tom Tromey <tromey@adacore.com>
* utils.h (class gdb_argv) <release>: Add
ATTRIBUTE_UNUSED_RESULT.
* common/common-defs.h (ATTRIBUTE_UNUSED_RESULT): Define.
gdb/ChangeLog:
2019-03-02 Eli Zaretskii <eliz@gnu.org>
PR gdb/24292
* common/netstuff.c:
* gdbserver/gdbreplay.c
* gdbserver/remote-utils.c:
* ser-tcp.c:
* unittests/parse-connection-spec-selftests.c [USE_WIN32API]:
Include ws2tcpip.h instead of wsiapi.h and winsock2.h. Redefine
_WIN32_WINNT to 0x0501 if defined to a smaller value, as
'getaddrinfo' and 'freeaddrinfo' were not available before
Windows XP, and mingw.org's MinGW headers by default define
_WIN32_WINNT to 0x500.
This commit fixes a resource leak found by Coverity, where
coff_start_symtab performs an xstrdup that is now performed
within start_symtab by buildsym_compunit::buildsym_compunit.
gdb/ChangeLog:
* coffread.c (coff_start_symtab): Remove unnecessary xstrdup.
If gdb attaches to a process that either has no controlling terminal,
or the controlling terminal differs from the one gdb is running under,
break/^C doesn't interrupt the debugged process on Solaris.
Fixed as follows, analogous to what all all other targets do. Patch from
the PR, recently re-submitted by Brian Vandenberg.
Tested on amd64-pc-solaris2.11, sparcv9-sun-solaris2.11, and
x86_64-pc-linux-gnu.
2019-02-28 Brian Vandenberg <phantall@gmail.com>
Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
gdb:
PR gdb/8527
* procfs.c (proc_wait_for_stop): Wrap write of PCWSTOP in
set_sigint_trap, clear_sigint_trap.
gdb/testsuite:
PR gdb/8527
* gdb.base/interrupt-daemon-attach.c,
gdb.base/interrupt-daemon-attach.exp: New test.
Valgrind reports leaks like the below in various tests,
e.g. gdb.threads/attach-slow-waitpid.exp, gdb.ada/task_switch_in_core.exp, ...
Fix the leak by clearing the regcache when detaching from an inferior.
Note that these leaks are 'created' when GDB exits,
when the regcache::current_regcache is destroyed : the elements
of the forward_list are pointers, and the 'pointed to' memory is not
deleted by the forward_list destructor.
Nevertheless, fixing this leak is good as it makes a bunch of
tests 'leak clean'.
Also, it seems strange to keep a register cache for a process from
which GDB detached : it is not clear if this cache is still valid
after detach. And effectively, when clearing only the regcache,
(and not the frame cache), then the frame cache was still 'pointing'
at this regcache and was used when switching to the child process
in the test gdb.threads/watchpoint-fork.exp, which seems strange.
So, we solve the leak and avoid possible accesses to the regcache
and frame cache of the detached inferior, by clearing both the
regcache and the frame cache.
Tested on debian/amd64, natively, under Valgrind,
and with make check RUNTESTFLAGS="--target_board=native-gdbserver".
==27679== VALGRIND_GDB_ERROR_BEGIN
==27679== 1,123 (72 direct, 1,051 indirect) bytes in 1 blocks are definitely lost in loss record 2,942 of 3,400
==27679== at 0x4C2C4CC: operator new(unsigned long) (vg_replace_malloc.c:344)
==27679== by 0x5CDF71: get_thread_arch_aspace_regcache(ptid_t, gdbarch*, address_space*) (regcache.c:330)
==27679== by 0x5CE12A: get_thread_regcache (regcache.c:366)
==27679== by 0x5CE12A: get_current_regcache() (regcache.c:372)
==27679== by 0x4FF63D: post_create_inferior(target_ops*, int) (infcmd.c:452)
==27679== by 0x43AF62: core_target_open(char const*, int) (corelow.c:458)
==27679== by 0x408B68: cmd_func(cmd_list_element*, char const*, int) (cli-decode.c:1892)
...
gdb/ChangeLog
2019-02-27 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* target.c (target_detach): Clear the regcache and the
frame cache.
When we cap the height/width sizes before passing to readline, tweak
the corresponding command variable to show "unlimited":
(gdb) set height 0x8000
(gdb) show height
Number of lines gdb thinks are in a page is unlimited.
Instead of the current output:
(gdb) set height 0x8000
(gdb) show height
Number of lines gdb thinks are in a page is 32768.
gdb/ChangeLog:
2019-02-27 Pedro Alves <palves@redhat.com>
* utils.c (set_screen_size): When we cap the height/width sizes,
tweak the corresponding command variable to show "unlimited":
gdb/testsuite/ChangeLog:
2019-02-27 Pedro Alves <palves@redhat.com>
* gdb.base/page.exp: Add tests for "set/show width/height" with
"infinite" values.
GDB calls rl_set_screen_size in readline with the current screen size,
measured in rows and columns. To represent "infinite" sizes, GDB
passes in INT_MAX; however, since rl_set_screen_size internally
multiplies the number of rows and columns, this causes a signed
integer overflow. To prevent this we can instead pass in the
approximate square root of INT_MAX (which is still reasonably large),
so that even when the number of rows and columns is "infinite" we
don't overflow.
gdb/ChangeLog:
2019-02-27 Saagar Jha <saagar@saagarjha.com>
Pedro Alves <palves@redhat.com>
* utils.c (set_screen_size): Reduce "infinite" rows and columns
before calling rl_set_screen_size.
This patch removes the non-IS_PY3K code in infpy_write_memory()
and infpy_search_memory(). In both cases, the remaining code
from these ifdefs is related to use of the PEP 3118 buffer protocol.
(Deleted code is either due to simplification or related to use of the
old buffer protocol.) PEP 3118 is sometimes referred to as the "new"
buffer protocol, though it's not that new anymore.
The link below describes new features in Python 2.6. In particular,
it says that the buffer protocol described by PEP 3118 is in Python
2.6. It also says (at the top of the page) that Python 2.6 was
released on Oct 1, 2008.
https://docs.python.org/3/whatsnew/2.6.html#pep-3118-revised-buffer-protocol
The last security release for the Python 2.6 series was 2.6.9. It was
released on Oct 29, 2013. According to this document...
https://www.python.org/download/releases/2.6.9/
...support for the 2.6 series has ended:
With the 2.6.9 release, and five years after its first release,
the Python 2.6 series is now officially retired. All official
maintenance for Python 2.6, including security patches, has ended.
For ongoing maintenance releases, please see the Python 2.7
series.
As noted earlier, Python 2.6, Python 2.7, and Python 3.X all have
support for the PEP 3118 buffer protocol. Python releases prior
to 2.6 use an older buffer protocol. Since Python 2.6 has been
retired for a good while now, it seems reasonable to me to remove
code using the older buffer protocol from GDB.
I have also simplified some of the code via use of the Py_buffer
unique_ptr specialization which I introduced in the two argument
gdb.Value constructor patch series. Therefore, there is a dependency
on patch #1 from that series.
I have tested against both Python 2.7.15 and 3.7.2. I see no
regressions among the non-racy tests. I've also verified that
PyBuffer_Release is being called when the affected functions exit
while running the tests in gdb.python/py-inferior.exp by hand. I've
also tried running valgrind on GDB while running this test, but I'm
puzzled by the results that I'm seeing - I'm seeing no additional
leaks when I comment out the Py_buffer_up lines that I introduced.
That said, I'm not seeing any leaks that obviously originate from
either infpy_write_memory() or infpy_search_memory().
gdb/ChangeLog:
* python/py-inferior.c (infpy_write_memory): Remove non-IS_PY3K
code from these functions. Remove corresponding ifdefs. Use
Py_buffer_up instead of explicit calls to PyBuffer_Release.
Remove gotos and target of gotos.
(infpy_search_memory): Likewise.
Make use of the default gdbarch method for gdbarch_dummy_id.
I have not tested this change but, by inspecting the code, I believe
the default method is equivalent to the code being deleted.
gdb/ChangeLog:
* gdb/hppa-tdep.c (hppa_dummy_id): Delete.
(hppa_gdbarch_init): Don't register deleted functions with
gdbarch.
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.
I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.
gdb/ChangeLog:
* gdb/h8300-tdep.c (h8300_unwind_pc): Delete.
(h8300_unwind_sp): Delete.
(h8300_dummy_id): Delete.
(h8300_gdbarch_init): Don't register deleted functions with
gdbarch.
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.
I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.
gdb/ChangeLog:
* gdb/ft32-tdep.c (ft32_dummy_id): Delete.
(ft32_unwind_pc): Delete.
(ft32_unwind_sp): Delete.
(ft32_gdbarch_init): Don't register deleted functions with
gdbarch.
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.
I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.
gdb/ChangeLog:
* gdb/frv-tdep.c (frv_dummy_id): Delete.
(frv_unwind_pc): Delete.
(frv_unwind_sp): Delete.
(frv_gdbarch_init): Don't register deleted functions with
gdbarch.
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.
This change has been tested with no regressions.
gdb/ChangeLog:
* gdb/riscv-tdep.c (riscv_dummy_id): Delete.
(riscv_unwind_pc): Delete.
(riscv_unwind_sp): Delete.
(riscv_gdbarch_init): Don't register deleted functions with
gdbarch.
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.
I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.
gdb/ChangeLog:
* gdb/csky-tdep.c (csky_dummy_id): Delete.
(csky_unwind_pc): Delete.
(csky_unwind_sp): Delete.
(csky_gdbarch_init): Don't register deleted functions with
gdbarch.
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.
I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.
gdb/ChangeLog:
* gdb/cris-tdep.c (cris_dummy_id): Delete.
(cris_unwind_pc): Delete.
(cris_unwind_sp): Delete.
(cris_gdbarch_init): Don't register deleted functions with
gdbarch.
Make use of the default gdbarch methods for gdbarch_dummy_id,
and gdbarch_unwind_pc.
I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.
gdb/ChangeLog:
* gdb/bfin-tdep.c (bfin_dummy_id): Delete.
(bfin_unwind_pc): Delete.
(bfin_gdbarch_init): Don't register deleted functions with gdbarch.
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.
I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.
gdb/ChangeLog:
* gdb/arm-tdep.c (arm_dummy_id): Delete.
(arm_unwind_pc): Delete.
(arm_unwind_sp): Delete.
(arm_gdbarch_init): Don't register deleted functions with gdbarch.
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.
I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted. The
only difference is that the old ARC specific methods had additional
debugging, however, this was discussed on the mailing list[1] and it
was agreed these methods could be removed.
[1] https://sourceware.org/ml/gdb-patches/2018-12/msg00386.html
gdb/ChangeLog:
* gdb/arc-tdep.c (arc_dummy_id): Delete.
(arc_unwind_pc): Delete.
(arc_unwind_sp): Delete.
(arc_gdbarch_init): Don't register deleted functions with gdbarch.
Make use of the default gdbarch methods for gdbarch_dummy_id, and
gdbarch_unwind_pc.
I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.
gdb/ChangeLog:
* gdb/alpha-tdep.c (alpha_dummy_id): Delete.
(alpha_unwind_pc): Delete.
(alpha_gdbarch_init): Don't register deleted functions with
gdbarch.
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.
I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.
gdb/ChangeLog:
* gdb/aarch64-tdep.c (aarch64_dummy_id): Delete.
(aarch64_unwind_pc): Delete.
(aarch64_unwind_sp): Delete.
(aarch64_gdbarch_init): Don't register deleted functions with
gdbarch.
In 'type_align' when computing the alignment of a structure we should
not consider the alignment of static structure members, these are
usually stored outside of the structure and therefore don't have any
impact on the structures alignment requirements.
I've extended the existing alignment calculating test to compile in
both C and C++ now so that we can create structures with static
members.
gdb/ChangeLog:
* gdbtypes.c (type_align): Don't consider static members when
computing structure alignment.
gdb/testsuite/ChangeLog:
* gdb.base/align.exp: Extend to compile in both C and C++, and add
tests for structs with static members.
This commit restructures the relationship between the type_align
function and the gdbarch_type_align method.
The problem being addressed with this commit is this; previously the
type_align function was structured so that for "basic" types (int,
float, etc) the gdbarch_type_align hook was called, which for
"compound" types (arrays, structs, etc) the common type_align code has
a fixed method for how to extract a "basic" type and would then call
itself on that "basic" type.
The problem is that if an architecture wants to modify the alignment
rules for a "compound" type then this is not currently possible.
In the revised structure, all types pass through the
gdbarch_type_align method. If this method returns 0 then this
indicates that the architecture has no special rules for this type,
and GDB should apply the default rules for alignment. However, the
architecture is free to provide an alignment for any type, both
"basic" and "compound".
After this commit the default alignment rules now all live in the
type_align function, the default_type_align only ever returns 0,
meaning apply the default rules.
I've updated the 3 targets (arc, i386, and nios2) that already
override the gdbarch_type_align method to fit the new scheme.
Tested on X86-64/GNU Linux with no regressions.
gdb/ChangeLog:
* arc-tdep.c (arc_type_align): Provide alignment for basic types,
return 0 for other types.
* arch-utils.c (default_type_align): Always return 0.
* gdbarch.h: Regenerate.
* gdbarch.sh (type_align): Extend comment.
* gdbtypes.c (type_align): Add additional comments, always call
gdbarch_type_align before applying the default rules.
* i386-tdep.c (i386_type_align): Return 0 as the default rule,
generic code will then apply a suitable default.
* nios2-tdep.c (nios2_type_align): Provide alignment for basic
types, return 0 for other types.
Now that the GDB 8.3 branch has been created, we can
bump the version number.
gdb/ChangeLog:
GDB 8.3 branch created (143420fb0d):
* version.in: Bump version to 8.3.50.DATE-git.
When the target description support was added to RISC-V, the register
numbers assigned to the fflags, frm, and fcsr control registers in the
default target descriptions didn't match the register numbers used by
GDB before the target description support was added.
What this means is that if a tools exists in the wild that is using
hard-coded register number, setup to match GDB's old numbering, then
this will have been broken (for fflags, frm, and fcsr) by the move to
target descriptions. QEMU is such a tool.
There are a couple of solutions that could be used to work around this
issue:
- The user can create their own xml description file with the
register numbers setup to match their old tool, then load this by
telling GDB 'set tdesc filename FILENAME'.
- Update their old tool to use the newer default numbering scheme, or
better yet add proper target description support to their tool.
- We could have RISC-V GDB change to maintain the old defaults.
This patch changes GDB back to using the old numbering scheme.
This change is only visible to remote targets that don't supply their
own xml description file and instead rely on GDB's default numbering.
Note that even though 32bit-cpu.xml and 64bit-cpu.xml have changed,
the corresponding .c file has not, this is because the numbering added
to the registers in the xml files is number 0, this doesn't result in
any new C code being generated .
gdb/ChangeLog:
* features/riscv/32bit-cpu.xml: Add register numbers.
* features/riscv/32bit-fpu.c: Regenerate.
* features/riscv/32bit-fpu.xml: Add register numbers.
* features/riscv/64bit-cpu.xml: Add register numbers.
* features/riscv/64bit-fpu.c: Regenerate.
* features/riscv/64bit-fpu.xml: Add register numbers.
gdb/ChangeLog:
* NEWS: Mention two argument form of gdb.Value constructor.
gdb/doc/ChangeLog:
* python.texi (Values From Inferior): Document second form
of Value.__init__.
Provided a buffer BUFOBJ and a type TYPE, construct a gdb.Value object
with type TYPE, where the value's contents are taken from BUFOBJ.
E.g...
(gdb) python import struct
(gdb) python unsigned_int_type=gdb.lookup_type('unsigned int')
(gdb) python b=struct.pack('=I',0xdeadbeef)
(gdb) python v=gdb.Value(b, unsigned_int_type) ; print("%#x" % v)
0xdeadbeef
This two argument form of the gdb.Value constructor may also be used
to obtain gdb values from selected portions of buffers read with
Inferior.read_memory(). The test case (which is in a separate patch)
demonstrates this use case.
gdb/ChangeLog:
* python/py-value.c (convert_buffer_and_type_to_value): New
function.
(valpy_new): Parse arguments via gdb_PyArg_ParseTupleAndKeywords.
Add support for handling an optional second argument. Call
convert_buffer_and_type_to_value as appropriate.
This patch causes PyBuffer_Release() to be called when the associated
buffer goes out of scope. I've been using it as follows:
...
Py_buffer_up buffer_up;
Py_buffer py_buf;
if (PyObject_CheckBuffer (obj)
&& PyObject_GetBuffer (obj, &py_buf, PyBUF_SIMPLE) == 0)
{
/* Got a buffer, py_buf, out of obj. Cause it to released
when it goes out of scope. */
buffer_up.reset (&py_buf);
}
...
This snippet of code was taken directly from an upcoming patch to
python-value.c.
gdb/ChangeLog:
* python/python-internal.h (Py_buffer_deleter): New struct.
(Py_buffer_up): New typedef.
Previously if build_id_verify failed, dwz_bfd was cleared to NULL via
release(), but the BFD object was not destroyed. Use reset() with
nullptr instead to delete the BFD.
gdb/ChangeLog:
* dwarf2read.c (dwarf2_get_dwz_file): Reset dwz_bfd to nullptr
instead of releasing ownership.
When loading dwp files, we create an array of ELF sections indexed by the ELF
section index in the dwp file. The size of this array is calculated by
section_count, as returned by bfd_count_sections, plus 1 (to account for the
null section at index 0). However, when loading the bfd file, strtab/symtab
sections are not added to the list, nor do they increment section_count, so
section_count is actually smaller than the number of ELF sections.
This happens to work when using GNU dwp, which lays out .debug section first,
with sections like .shstrtab coming at the end. Other tools, like llvm-dwp, put
.strtab first, and gdb crashes when loading those dwp files.
For instance, with the current state of gdb, loading a file like this:
$ readelf -SW <file.dwp>
[ 0] <empty>
[ 1] .debug_foo PROGBITS ...
[ 2] .strtab STRTAB ...
... results in section_count = 2 (.debug is the only thing placed into
bfd->sections, so section_count + 1 == 2), and sectp->this_idx = 1 when mapping
over .debug_foo in dwarf2_locate_common_dwp_sections, which passes the
assertion that 1 < 2.
However, using a dwp file produced by llvm-dwp:
$ readelf -SW <file.dwp>
[ 0] <empty>
[ 1] .strtab STRTAB ...
[ 2] .debug_foo PROGBITS ...
... results in section_count = 2 (.debug is the only thing placed into
bfd->sections, so section_count + 1 == 2), and sectp->this_idx = 2 when mapping
over .debug_foo in dwarf2_locate_common_dwp_sections, which fails the assertion
that 2 < 2.
The assertion hit is:
gdb/dwarf2read.c:13009: internal-error: void dwarf2_locate_common_dwp_sections(bfd*, asection*, void*): Assertion `elf_section_nr < dwp_file->num_sections' failed.
This patch changes the calculation of section_count to use elf_numsections,
which should return the actual number of ELF sections.
commit 192b62ce0b ("Use class to manage
BFD reference counts") changed darwin_get_dyld_bfd to use:
+ dyld_bfd.release ();
rather than
- do_cleanups (cleanup);
However, using release here leaks the BFD. Instead, simply assigning
"sub" to "dyld_bfd" achieves what was meant.
gdb/ChangeLog
2019-02-25 Tom Tromey <tromey@adacore.com>
* solib-darwin.c (darwin_get_dyld_bfd): Don't release dyld_bfd.
Back when I proposed the '--readnever' feature, I somehow forgot or
decided not to include the bits related to gcore.in in the original
patch. This patch finally updates the gcore script to invoke GDB
using '--readnever'.
We've been carrying this patch on Fedora GDB for quite some time, and
as expected the corefiles generated by gcore on Fedora don't have
problems, which I think is the best indicator that the it's safe to
generate corefiles using '--readnever'.
gdb/ChangeLog:
2019-02-23 Sergio Durigan Junior <sergiodj@redhat.com>
* gcore.in: Add '--readnever' option when invoking GDB.
When looking for a separate debug file that matches a given build-id,
GDB only looks in the host's debug dir (typically /usr/lib/debug). This
patch makes it look in the sysroot as well. This is to match the
behavior of GDB when using debuglink-based separate debug files,
introduced in :
402d2bfec4 ("Look for separate debug files in debug directories under a sysroot.")
In the following example, my sysroot is "/tmp/sysroot" and I am trying
to load symbols for
/tmp/sysroot/usr/lib/arm-linux-gnueabihf/gconv/EBCDIC-AT-DE.so. This is
the current behavior:
(gdb) file /tmp/sysroot/usr/lib/arm-linux-gnueabihf/gconv/EBCDIC-AT-DE.so
Reading symbols from /tmp/sysroot/usr/lib/arm-linux-gnueabihf/gconv/EBCDIC-AT-DE.so...
Looking for separate debug info (build-id) for /tmp/sysroot/usr/lib/arm-linux-gnueabihf/gconv/EBCDIC-AT-DE.so
Trying /usr/lib/debug/.build-id/f3/d6594d2600e985812cd4ba2ad083ac2aceae22.debug... no, unable to compute real path
<snip>
(No debugging symbols found in /tmp/sysroot/usr/lib/arm-linux-gnueabihf/gconv/EBCDIC-AT-DE.so)
With this patch:
(gdb) file /tmp/sysroot/usr/lib/arm-linux-gnueabihf/gconv/EBCDIC-AT-DE.so
Reading symbols from /tmp/sysroot/usr/lib/arm-linux-gnueabihf/gconv/EBCDIC-AT-DE.so...
Looking for separate debug info (build-id) for /tmp/sysroot/usr/lib/arm-linux-gnueabihf/gconv/EBCDIC-AT-DE.so
Trying /usr/lib/debug/.build-id/f3/d6594d2600e985812cd4ba2ad083ac2aceae22.debug... no, unable to compute real path
Trying /tmp/sysroot/usr/lib/debug/.build-id/f3/d6594d2600e985812cd4ba2ad083ac2aceae22.debug... yes!
Reading symbols from /tmp/sysroot/usr/lib/debug/.build-id/f3/d6594d2600e985812cd4ba2ad083ac2aceae22.debug...
In the original code, there is a suspicious "abfd.release ()" in
build_id_to_debug_bfd, that I don't understand. If a file with the
right name exists but its build-id note doesn't match, we release (leak)
our reference, meaning the file will stay open? I removed it in the new
code, so that the reference is dropped if we end up not using that file.
I tested briefly by corrupting a separate debug file to trigger this
code, nothing exploded.
gdb/ChangeLog:
* build-id.c (build_id_to_debug_bfd_1): New function.
(build_id_to_debug_bfd): Look for separate debug file in
sysroot.
The copyright year that gdbarch.sh places into the generated files
gdbarch.{c,h} wasn't updated at the start of the year. After this
commit the gdbarch.{c,h} files regenerate as the currently are in the
tree.
gdb/ChangeLog:
* gdbarch.sh: Update the copyright year range that is placed into
generated files.
The GCC Guality testsuite within GCC compiles C/C++ files in GCC at
various optimization levels then debugs them in GDB, checking that
program values can be read. This is done within the dejagnu framework.
The new style options in GDB have broken many of the tests due to the
testsuite being unable to process the new control characters. The fix
in Guality is to either to improve the string matching or to disable
styling on the cli or init file (after checking gdb is recent enough
to support styling).
This fix will also need making an any other testsuites in the wild
that use GDB.
An alternative would be to automatically disable styling when using GDB
in batch mode. The reasoning here is that batch mode is only used when
automating GDB and any output will be processed later either with text
processing tools or viewed in text editors, many of these will not
correctly handle the control characters by default. This ensures GDB
continues to work as expected. Anyone who explicitly wants styling in
batch mode can enable it either in the init file or adding to the batch
file - but that would not be the standard use case.
Patch simply disables style after reading the batch command flag, before
reading in the init file or batch file.
gdb/ChangeLog:
* main.c (captured_main_1): Disable styling in batch mode.
symtab_symbol_info has a couple of messages that say "regulation
expression". I think "regular expression" was meant, so this patch
changes it.
gdb/ChangeLog
2019-02-20 Tom Tromey <tom@tromey.com>
* symtab.c (symtab_symbol_info): Fix typos.
gdb/testsuite/ChangeLog
2019-02-20 Tom Tromey <tom@tromey.com>
* gdb.base/info_qt.exp: Update.
While answering a user's question on irc, I realized that the
metasyntactic variables in "help find" are not in upper case. As you
know this is one of my pet quests, so here is a patch to fix this.
Tested on x86-64 Fedora 29.
gdb/ChangeLog
2019-02-20 Tom Tromey <tromey@adacore.com>
* findcmd.c (_initialize_mem_search): Use upper case for
metasyntactic variables.
AArch64 does not define any reggroups. This causes "maintenance print
reggroups" to dump the default set (which is ok).
However, if a new group is added via an xml file, then this now becomes
the only group.
Fixes gdb.xml/tdesc-regs.exp on AArch64.
gdb/ChangeLog:
* aarch64-tdep.c (aarch64_add_reggroups): New function
(aarch64_gdbarch_init): Call aarch64_add_reggroups.
Errors that happen in nested sourced files (when a sourced file sources
another file) lead to a wrong error message, or use-after-free.
For example, if I put this in "a.gdb":
command_that_doesnt_exist
and this in "b.gdb":
source a.gdb
and try to "source b.gdb" in GDB, the result may look like this:
(gdb) source b.gdb
b.gdb:1: Error in sourced command file:
_that_doesnt_exist:1: Error in sourced command file:
Undefined command: "command_that_doesnt_exist". Try "help".
Notice the wrong file name where "a.gdb" should be. The exact result
may differ, depending on the feelings of the memory allocator.
What happens is:
- The "source a.gdb" command is saved by command_line_append_input_line
in command_line_input's static buffer.
- Since we are sourcing a file, the script_from_file function stores the
script name (a.gdb) in the source_file_name global. However, it doesn't
do a copy, it just saves a pointer to command_line_input's static buffer.
- The "command_that_doesnt_exist" command is saved by
command_line_append_input_line in command_line_input's static buffer.
Depending on what xrealloc does, source_file_name may now point to
freed memory, or at the minimum the data it was pointing to was
overwritten.
- When the error is handled in script_from_file, we dererence
source_file_name to print the name of the file in which the error
occured.
To fix it, I made source_file_name an std::string, so that keeps a copy of
the file name instead of pointing to a buffer with a too small
lifetime.
With this patch, the expected filename is printed, and no use-after-free
occurs:
(gdb) source b.gdb
b.gdb:1: Error in sourced command file:
a.gdb:1: Error in sourced command file:
Undefined command: "command_that_doesnt_exist". Try "help".
I passed explicit template parameters to make_scoped_restore
(<std::string, const std::string &>), so that the second parameter is
passed by reference and avoid a copy.
It was not as obvious as I first thought to change gdb.base/source.exp
to test this, because source commands inside sourced files are
interpreted relative to GDB's current working directory, not the
directory of the currently sourced file. As a workaround, I moved the
snippet that tests errors after the snippet that adds the source
directory to the search path. This way, the "source source-error-1.gdb"
line in source-error.exp manages to find the file.
For reference, here is what ASAN reports when use-after-free occurs:
(gdb) source b.gdb
=================================================================
==18498==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c000019847 at pc 0x7f1d3645de8e bp 0x7ffdcb892e50 sp 0x7ffdcb8925c8
READ of size 6 at 0x60c000019847 thread T0
#0 0x7f1d3645de8d in printf_common /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors_format.inc:546
#1 0x7f1d36477175 in __interceptor_vasprintf /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:1525
#2 0x5632eaffa277 in xstrvprintf(char const*, __va_list_tag*) /home/simark/src/binutils-gdb/gdb/common/common-utils.c:122
#3 0x5632eaff96d1 in throw_it /home/simark/src/binutils-gdb/gdb/common/common-exceptions.c:351
#4 0x5632eaff98df in throw_verror(errors, char const*, __va_list_tag*) /home/simark/src/binutils-gdb/gdb/common/common-exceptions.c:379
#5 0x5632eaff9a2a in throw_error(errors, char const*, ...) /home/simark/src/binutils-gdb/gdb/common/common-exceptions.c:394
#6 0x5632eafca21a in script_from_file(_IO_FILE*, char const*) /home/simark/src/binutils-gdb/gdb/cli/cli-script.c:1553
#7 0x5632eaf8a500 in source_script_from_stream /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:569
#8 0x5632eaf8a735 in source_script_with_search /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:605
#9 0x5632eaf8ab20 in source_command /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:664
#10 0x5632eafa8b4a in do_const_cfunc /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:106
#11 0x5632eafb0687 in cmd_func(cmd_list_element*, char const*, int) /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:1892
#12 0x5632ebf3dd87 in execute_command(char const*, int) /home/simark/src/binutils-gdb/gdb/top.c:630
#13 0x5632eb3b25d3 in command_handler(char const*) /home/simark/src/binutils-gdb/gdb/event-top.c:583
#14 0x5632ebf3cf09 in read_command_file(_IO_FILE*) /home/simark/src/binutils-gdb/gdb/top.c:425
#15 0x5632eafca054 in script_from_file(_IO_FILE*, char const*) /home/simark/src/binutils-gdb/gdb/cli/cli-script.c:1547
#16 0x5632eaf8a500 in source_script_from_stream /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:569
#17 0x5632eaf8a735 in source_script_with_search /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:605
#18 0x5632eaf8ab20 in source_command /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:664
#19 0x5632eafa8b4a in do_const_cfunc /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:106
#20 0x5632eafb0687 in cmd_func(cmd_list_element*, char const*, int) /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:1892
#21 0x5632ebf3dd87 in execute_command(char const*, int) /home/simark/src/binutils-gdb/gdb/top.c:630
#22 0x5632eb3b25d3 in command_handler(char const*) /home/simark/src/binutils-gdb/gdb/event-top.c:583
#23 0x5632eb3b2f87 in command_line_handler(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) /home/simark/src/binutils-gdb/gdb/event-top.c:770
#24 0x5632eb3b0fe1 in gdb_rl_callback_handler /home/simark/src/binutils-gdb/gdb/event-top.c:213
#25 0x5632ec1c8729 in rl_callback_read_char /home/simark/src/binutils-gdb/readline/callback.c:220
#26 0x5632eb3b0b8f in gdb_rl_callback_read_char_wrapper_noexcept /home/simark/src/binutils-gdb/gdb/event-top.c:175
#27 0x5632eb3b0da1 in gdb_rl_callback_read_char_wrapper /home/simark/src/binutils-gdb/gdb/event-top.c:192
#28 0x5632eb3b2186 in stdin_event_handler(int, void*) /home/simark/src/binutils-gdb/gdb/event-top.c:511
#29 0x5632eb3aa6a9 in handle_file_event /home/simark/src/binutils-gdb/gdb/event-loop.c:733
#30 0x5632eb3aaf41 in gdb_wait_for_event /home/simark/src/binutils-gdb/gdb/event-loop.c:859
#31 0x5632eb3a88ea in gdb_do_one_event() /home/simark/src/binutils-gdb/gdb/event-loop.c:347
#32 0x5632eb3a89bf in start_event_loop() /home/simark/src/binutils-gdb/gdb/event-loop.c:371
#33 0x5632eb76fbfc in captured_command_loop /home/simark/src/binutils-gdb/gdb/main.c:330
#34 0x5632eb772ea8 in captured_main /home/simark/src/binutils-gdb/gdb/main.c:1176
#35 0x5632eb773071 in gdb_main(captured_main_args*) /home/simark/src/binutils-gdb/gdb/main.c:1192
#36 0x5632eabfe7f9 in main /home/simark/src/binutils-gdb/gdb/gdb.c:32
#37 0x7f1d3554f222 in __libc_start_main (/usr/lib/libc.so.6+0x24222)
#38 0x5632eabfe5dd in _start (/home/simark/build/binutils-gdb/gdb/gdb+0x195d5dd)
0x60c000019847 is located 7 bytes inside of 128-byte region [0x60c000019840,0x60c0000198c0)
freed by thread T0 here:
#0 0x7f1d36502491 in __interceptor_realloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:105
#1 0x5632eaff9f47 in xrealloc /home/simark/src/binutils-gdb/gdb/common/common-utils.c:62
#2 0x5632eaff6b44 in buffer_grow(buffer*, char const*, unsigned long) /home/simark/src/binutils-gdb/gdb/common/buffer.c:40
#3 0x5632eb3b271d in command_line_append_input_line /home/simark/src/binutils-gdb/gdb/event-top.c:614
#4 0x5632eb3b28c6 in handle_line_of_input(buffer*, char const*, int, char const*) /home/simark/src/binutils-gdb/gdb/event-top.c:654
#5 0x5632ebf402a6 in command_line_input(char const*, char const*) /home/simark/src/binutils-gdb/gdb/top.c:1252
#6 0x5632ebf3cee9 in read_command_file(_IO_FILE*) /home/simark/src/binutils-gdb/gdb/top.c:422
#7 0x5632eafca054 in script_from_file(_IO_FILE*, char const*) /home/simark/src/binutils-gdb/gdb/cli/cli-script.c:1547
#8 0x5632eaf8a500 in source_script_from_stream /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:569
#9 0x5632eaf8a735 in source_script_with_search /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:605
#10 0x5632eaf8ab20 in source_command /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:664
#11 0x5632eafa8b4a in do_const_cfunc /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:106
#12 0x5632eafb0687 in cmd_func(cmd_list_element*, char const*, int) /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:1892
#13 0x5632ebf3dd87 in execute_command(char const*, int) /home/simark/src/binutils-gdb/gdb/top.c:630
#14 0x5632eb3b25d3 in command_handler(char const*) /home/simark/src/binutils-gdb/gdb/event-top.c:583
#15 0x5632ebf3cf09 in read_command_file(_IO_FILE*) /home/simark/src/binutils-gdb/gdb/top.c:425
#16 0x5632eafca054 in script_from_file(_IO_FILE*, char const*) /home/simark/src/binutils-gdb/gdb/cli/cli-script.c:1547
#17 0x5632eaf8a500 in source_script_from_stream /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:569
#18 0x5632eaf8a735 in source_script_with_search /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:605
#19 0x5632eaf8ab20 in source_command /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:664
#20 0x5632eafa8b4a in do_const_cfunc /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:106
#21 0x5632eafb0687 in cmd_func(cmd_list_element*, char const*, int) /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:1892
#22 0x5632ebf3dd87 in execute_command(char const*, int) /home/simark/src/binutils-gdb/gdb/top.c:630
#23 0x5632eb3b25d3 in command_handler(char const*) /home/simark/src/binutils-gdb/gdb/event-top.c:583
#24 0x5632eb3b2f87 in command_line_handler(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) /home/simark/src/binutils-gdb/gdb/event-top.c:770
#25 0x5632eb3b0fe1 in gdb_rl_callback_handler /home/simark/src/binutils-gdb/gdb/event-top.c:213
#26 0x5632ec1c8729 in rl_callback_read_char /home/simark/src/binutils-gdb/readline/callback.c:220
#27 0x5632eb3b0b8f in gdb_rl_callback_read_char_wrapper_noexcept /home/simark/src/binutils-gdb/gdb/event-top.c:175
#28 0x5632eb3b0da1 in gdb_rl_callback_read_char_wrapper /home/simark/src/binutils-gdb/gdb/event-top.c:192
#29 0x5632eb3b2186 in stdin_event_handler(int, void*) /home/simark/src/binutils-gdb/gdb/event-top.c:511
previously allocated by thread T0 here:
#0 0x7f1d36502491 in __interceptor_realloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:105
#1 0x5632eaff9f47 in xrealloc /home/simark/src/binutils-gdb/gdb/common/common-utils.c:62
#2 0x5632eaff6b44 in buffer_grow(buffer*, char const*, unsigned long) /home/simark/src/binutils-gdb/gdb/common/buffer.c:40
#3 0x5632eb3b271d in command_line_append_input_line /home/simark/src/binutils-gdb/gdb/event-top.c:614
#4 0x5632eb3b28c6 in handle_line_of_input(buffer*, char const*, int, char const*) /home/simark/src/binutils-gdb/gdb/event-top.c:654
#5 0x5632ebf402a6 in command_line_input(char const*, char const*) /home/simark/src/binutils-gdb/gdb/top.c:1252
#6 0x5632ebf3cee9 in read_command_file(_IO_FILE*) /home/simark/src/binutils-gdb/gdb/top.c:422
#7 0x5632eafca054 in script_from_file(_IO_FILE*, char const*) /home/simark/src/binutils-gdb/gdb/cli/cli-script.c:1547
#8 0x5632eaf8a500 in source_script_from_stream /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:569
#9 0x5632eaf8a735 in source_script_with_search /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:605
#10 0x5632eaf8ab20 in source_command /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:664
#11 0x5632eafa8b4a in do_const_cfunc /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:106
#12 0x5632eafb0687 in cmd_func(cmd_list_element*, char const*, int) /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:1892
#13 0x5632ebf3dd87 in execute_command(char const*, int) /home/simark/src/binutils-gdb/gdb/top.c:630
#14 0x5632eb3b25d3 in command_handler(char const*) /home/simark/src/binutils-gdb/gdb/event-top.c:583
#15 0x5632eb3b2f87 in command_line_handler(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) /home/simark/src/binutils-gdb/gdb/event-top.c:770
#16 0x5632eb3b0fe1 in gdb_rl_callback_handler /home/simark/src/binutils-gdb/gdb/event-top.c:213
#17 0x5632ec1c8729 in rl_callback_read_char /home/simark/src/binutils-gdb/readline/callback.c:220
#18 0x5632eb3b0b8f in gdb_rl_callback_read_char_wrapper_noexcept /home/simark/src/binutils-gdb/gdb/event-top.c:175
#19 0x5632eb3b0da1 in gdb_rl_callback_read_char_wrapper /home/simark/src/binutils-gdb/gdb/event-top.c:192
#20 0x5632eb3b2186 in stdin_event_handler(int, void*) /home/simark/src/binutils-gdb/gdb/event-top.c:511
#21 0x5632eb3aa6a9 in handle_file_event /home/simark/src/binutils-gdb/gdb/event-loop.c:733
#22 0x5632eb3aaf41 in gdb_wait_for_event /home/simark/src/binutils-gdb/gdb/event-loop.c:859
#23 0x5632eb3a88ea in gdb_do_one_event() /home/simark/src/binutils-gdb/gdb/event-loop.c:347
#24 0x5632eb3a89bf in start_event_loop() /home/simark/src/binutils-gdb/gdb/event-loop.c:371
#25 0x5632eb76fbfc in captured_command_loop /home/simark/src/binutils-gdb/gdb/main.c:330
#26 0x5632eb772ea8 in captured_main /home/simark/src/binutils-gdb/gdb/main.c:1176
#27 0x5632eb773071 in gdb_main(captured_main_args*) /home/simark/src/binutils-gdb/gdb/main.c:1192
#28 0x5632eabfe7f9 in main /home/simark/src/binutils-gdb/gdb/gdb.c:32
#29 0x7f1d3554f222 in __libc_start_main (/usr/lib/libc.so.6+0x24222)
SUMMARY: AddressSanitizer: heap-use-after-free /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors_format.inc:546 in printf_common
gdb/ChangeLog:
* top.h (source_file_name): Change to std::string.
* top.c (source_file_name): Likewise.
(command_line_input): Adjust.
* cli/cli-script.c (script_from_file): Adjust.
gdb/testsuite/ChangeLog:
* gdb.base/source.exp: Move "error in sourced script" code to
the end.
* gdb.base/source-error.gdb: Move contents to
source-error-1.gdb. Add new code to source source-error-1.gdb.
* gdb.base/source-error-1.gdb: New file, from previous
source-error.gdb.
While working on the Ada task code, I noticed a few things that could
be cleaned up:
* task_list_valid_p was not set in all cases in ada_build_task_list.
This causes many needless re-fetches of the task list.
* task_list_valid_p can be bool, and various functions can also return
bool.
* Nothing checks the return value of read_known_tasks, so it can be
changed to return void.
* The call to ada_build_task_list in
ravenscar_thread_target::update_thread_list is redundant, because
this is the first thing done by iterate_over_live_ada_tasks.
Tested using the internal AdaCore test suite against a ravenscar
target.
gdb/ChangeLog
2019-02-19 Tom Tromey <tromey@adacore.com>
* ravenscar-thread.c
(ravenscar_thread_target::update_thread_list): Don't call
ada_build_task_list.
* ada-lang.h (ada_build_task_list): Don't declare.
* ada-tasks.c (struct ada_tasks_inferior_data)
<task_list_valid_p>: Now bool.
(read_known_tasks, ada_task_list_changed)
(ada_tasks_invalidate_inferior_data): Update.
(read_known_tasks_array): Return bool.
(read_known_tasks_list): Likewise.
(read_known_tasks): Return void.
(ada_build_task_list): Now static.
The code in type_align (gdbtypes.c) currently hard-codes the rules for
aligning method and member pointers. It would seem better to forward
these types through the gdbarch hook, so that an architecture could
override the alignment of these types if needed.
Only 3 architectures currently override the gdbarch alignment hook,
these are arc, i386, and nio2.
For arc and nios the alignment rules are that alignment is the minimum
of 4-bytes and the type length. As pointers are 4-bytes on these
targets, then (assuming method and members pointers are also 4-bytes)
there should be no change to the alignment after this patch.
For i386 the gdbarch alignment hook overrides for some INT and FLOAT
types only. For method and member pointers we align on the type size
still, so there should be no change to the alignment after this patch.
I tested this on x86-64 GNU Linux with no regressions.
gdb/ChangeLog:
* gdbtypes.c (type_align): Allow alignment of TYPE_CODE_METHODPTR
and TYPE_CODE_MEMBERPTR to be overridden by the gdbarch.
Valgrind reports leaks such as the below.
Fix these leaks by changing ada_tasks_pspace_data_handle
and ada_tasks_inferior_data_handle to use the 'with_cleanup' register variant.
Tested on debian/amd64 natively and under Valgrind.
==26346== 56 bytes in 1 blocks are definitely lost in loss record 631 of 3,249
==26346== at 0x4C2C4CC: operator new(unsigned long) (vg_replace_malloc.c:344)
==26346== by 0x38F911: get_ada_tasks_inferior_data(inferior*) (ada-tasks.c:281)
==26346== by 0x38FA3F: ada_tasks_invalidate_inferior_data (ada-tasks.c:1362)
==26346== by 0x38FA3F: ada_tasks_new_objfile_observer(objfile*) (ada-tasks.c:1411)
==26346== by 0x60CBC5: operator() (functional:2127)
==26346== by 0x60CBC5: notify (observable.h:106)
==26346== by 0x60CBC5: clear_symtab_users(enum_flags<symfile_add_flag>) (symfile.c:2903)
...
==26346== 104 bytes in 1 blocks are definitely lost in loss record 984 of 3,249
==26346== at 0x4C2E0BC: calloc (vg_replace_malloc.c:762)
==26346== by 0x4056F0: xcalloc (common-utils.c:84)
==26346== by 0x38F8AE: xcnew<ada_tasks_pspace_data> (poison.h:122)
==26346== by 0x38F8AE: get_ada_tasks_pspace_data(program_space*) (ada-tasks.c:253)
==26346== by 0x38FA77: ada_tasks_invalidate_pspace_data (ada-tasks.c:1354)
==26346== by 0x38FA77: ada_tasks_new_objfile_observer(objfile*) (ada-tasks.c:1394)
==26346== by 0x60CBC5: operator() (functional:2127)
==26346== by 0x60CBC5: notify (observable.h:106)
...
gdb/ChangeLog
2019-02-18 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* ada-task.c (_initialize_tasks): Use 'with_cleanup' register
variant for ada_tasks_pspace_data_handle and
ada_tasks_inferior_data_handle.
(ada_tasks_pspace_data_cleanup): New function.
(ada_tasks_inferior_data_cleanup): New function.
While working on the previous patch, I noticed that if
macro_source_fullname returned a std::string, then the callers would
be simplified. This patch implements this idea.
gdb/ChangeLog
2019-02-17 Tom Tromey <tom@tromey.com>
* macrotab.h (macro_source_fullname): Return a std::string.
* macrotab.c (macro_include, check_for_redefinition)
(macro_undef, macro_lookup_definition, foreach_macro)
(foreach_macro_in_scope): Update.
(macro_source_fullname): Return a std::string.
* macrocmd.c (show_pp_source_pos): Update.
This adds filename styling to "info macro".
gdb/ChangeLog
2019-02-17 Tom Tromey <tom@tromey.com>
* macrocmd.c (show_pp_source_pos): Style the file names.
gdb/testsuite/ChangeLog
2019-02-17 Tom Tromey <tom@tromey.com>
* gdb.base/style.exp: Use -g3 to compile when possible. Add test
for macro styling.
* gdb.base/style.c (SOME_MACRO): New macro.