This changes dbxread.c to use the type-safe registry. In a couple of
spots, you'll see that dbx_objfile_data_key.emplace is called but the
result is not used; this is because those functions refer to the key
via the various DBX_* macros.
2019-07-10 Tom Tromey <tromey@adacore.com>
* gdb-stabs.h (struct dbx_symfile_info): Add initializers and
destructor.
(dbx_objfile_data_key): Change type and declare later.
(DBX_SYMFILE_INFO): Rewrite.
* dbxread.c (dbx_objfile_data_key): Change type.
(dbx_symfile_init): Update.
(~dbx_symfile_info): Rename from dbx_free_symfile_info. Update.
(coffstab_build_psymtabs, elfstab_build_psymtabs)
(stabsect_build_psymtabs, _initialize_dbxread): Update.
This changes jit.c to use the type-safe registry. Only one of the
registry keys in jit.c is converted; the other is trickier and so I've
left it be for now.
gdb/ChangeLog
2019-07-10 Tom Tromey <tromey@adacore.com>
* jit.c (jit_program_space_key): Change type. Move lower.
(get_jit_program_space_data): Update.
(jit_program_space_data_cleanup): Remove.
(jit_breakpoint_deleted, free_objfile_data, _initialize_jit):
Update.
(struct jit_program_space_data): Add initializers.
This patch changes py-inferior.c to use gdbpy_ref<> when possible,
reducing the amount of manual reference counting.
Tested on x86-64 Fedora 29.
gdb/ChangeLog
2019-07-10 Tom Tromey <tromey@adacore.com>
* python/python-internal.h (create_thread_object): Return
gdbpy_ref.
* python/py-infthread.c (create_thread_object): Return gdbpy_ref.
* python/py-inferior.c (struct threadlist_entry): Add
constructor.
<thread_obj>: Now a gdbpy_ref.
(thread_to_thread_object): Update.
(add_thread_object): Use new.
(delete_thread_object): Use delete.
(infpy_threads): Update.
(py_free_inferior): Update. Construct "inf_obj" after acquiring
GIL.
In Ada, the term for a cast is "type conversion". AdaCore has been
carrying a local patch to specialize the error message in value_cast,
but it seemed fine to me for this to be part of gdb. This also
removes a dead "return" statement.
gdb/ChangeLog
2019-07-10 Tom Tromey <tromey@adacore.com>
* valops.c (value_cast): Specialize error message for Ada.
I noticed the documentation of breakpoint_1 way way out of date, so this
is an attempt to update it. I have changed the parameter names to
something that seems clearer to me.
gdb/ChangeLog:
* breakpoint.c (breakpoint_1): Update doc and parameter names.
Add Arm to the list of feature target description targets and generate the
relevant C files.
Add arm-m-profile-with-fpa.xml as the feature version of the exisiting
arm-with-m-fpa-layout.xml.
Add extra comments to the Makefile for readability.
New files are not yet used.
gdb/ChangeLog:
* features/Makefile: Use feature target descriptions for Arm.
* features/arm/arm-core.c: Generate new file.
* features/arm/arm-fpa.c: Likewise.
* features/arm/arm-m-profile-with-fpa.xml: Likewise.
* features/arm/arm-m-profile.c: Likewise.
* features/arm/arm-vfpv2.c: Likewise.
* features/arm/arm-vfpv3.c: Likewise.
* features/arm/xscale-iwmmxt.c: Likewise.
* target-descriptions.c (maint_print_c_tdesc_cmd): Add Arm.
define.exp will fail on a GDB which has set a custom prompt to identify
itself. This is because the test resets the prompt to a hard coded
"(gdb)" but then verifies the success of this against the value in
$gdb_prompt, which is set to the custom prompt.
The original approach to fix this involved resetting the prompt to
$gdb_prompt rather than a hard coded "(gdb)". However it was noted during
review that $gdb_prompt is a regular expression rather than a string.
This is problematic because in general the prompt would be reset to a
regular expression rather than an instance of a string accepted by said
regular expression.
The fix used in this commit avoids the above issue by capturing the
literal prompt from running "show prompt" and uses this literal to
restore the previous prompt.
Regression tested with GCC 7.3.0 on x86_64, ppc64le, aarch64.
gdb/testsuite/ChangeLog:
2019-07-10 Richard Bunt <richard.bunt@arm.com>
Stephen Roberts <stephen.roberts@arm.com>
* gdb.base/define.exp: Restore original prompt.
This commit makes "maint info breakpoints" show the internal locations
of C++ exception catchpoints:
(gdb) info breakpoints
Num Type Disp Enb Address What
2 catchpoint keep y exception catch
With multiple locations:
(gdb) maint info breakpoints
Num Type Disp Enb Address What
2 catchpoint keep y exception catch
2.1 y 0x000000000040545f <__cxa_begin_catch+95> inf 1
2.2 y 0x00007ffff71dbe0f <__cxxabiv1::__cxa_begin_catch(void*)+95> inf 1
(gdb)
With a single location:
(gdb) maint info breakpoints 2
Num Type Disp Enb Address What
2 catchpoint keep y exception catch inf 1
2.1 y 0x00007ffff7bc0b7f <__cxa_begin_catch+95> inf 1
With no locations:
(gdb) maint info breakpoints 2
Num Type Disp Enb Address What
2 catchpoint keep y exception catch inf 1
Other catchpoints still show the same way, here a catch signal:
(gdb) info breakpoints
Num Type Disp Enb Address What
3 catchpoint keep y signal "<standard signals>"
(gdb) maint info breakpoints
Num Type Disp Enb Address What
3 catchpoint keep y signal "<standard signals>" inf 1
(gdb)
Note: I considered making the locations be printed from within
breakpoint_ops::print_one(), but gave up given the handling for the
broken MI v2 output:
/* The mi2 broken format: the main breakpoint tuple ends here, the locations
are outside. */
if (!use_fixed_output)
bkpt_tuple_emitter.reset ();
in print_one_breakpoint.
gdb/ChangeLog:
2019-07-09 Pedro Alves <palves@redhat.com>
* break-catch-throw.c (is_exception_catchpoint): New.
* breakpoint.c (print_one_breakpoint_location): New parameter
'raw_loc'. Handle it. Use
is_watchpoint/is_catchpoint/is_exception_catchpoint instead of
looking at the breakpoint's type.
(print_one_breakpoint): If handling "maint info breakpoints", also
print locations of exception catchpoints.
* breakpoint.h (is_exception_catchpoint): Declare.
Currently, with:
(gdb) catch catch
Catchpoint 1 (catch)
(gdb) catch throw
Catchpoint 2 (throw)
(gdb) catch rethrow
Catchpoint 3 (rethrow)
You get:
(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000000000b122af exception catch
2 breakpoint keep y 0x0000000000b1288d exception throw
3 breakpoint keep y 0x0000000000b12931 exception rethrow
I think it doesn't make much sense usability-wise, to show a
catchpoint as a breakpoint. The fact that GDB sets a breakpoint at
some magic address in the C++ run time is an implementation detail,
IMO. And as seen in the previous patch, such a catchpoint can end up
with more than one location/address even, so showing a single address
isn't entirely accurate.
This commit hides the addresses from view, and makes GDB show
"catchpoint" for type as well:
(gdb) info breakpoints
Num Type Disp Enb Address What
1 catchpoint keep y exception catch
2 catchpoint keep y exception throw
3 catchpoint keep y exception rethrow
This comment in the code seems telling:
/* We need to reset 'type' in order for code in breakpoint.c to do
the right thing. */
cp->type = bp_breakpoint;
It kind of suggests that the reason catchpoints end up shown as
breakpoints was that it was easier to implement them that way, rather
than a desired property.
This commit fixes things up to make it possible to have bp_catch
breakpoints have software/hardware breakpoint locations, thus
eliminating the need for that hack:
- redo breakpoint_address_is_meaningful in terms of the location's
type rather than breakpoint type.
- teach bpstat_what about stepping over the catchpoint locations.
- install a allocate_location method for "catch catch/throw/rethrow",
one that forces the location type.
Note that this also reverts the gdb hunk from:
commit 2a8be20359
Commit: Tom Tromey <tom@tromey.com>
CommitDate: Sat Oct 6 22:17:45 2018 -0600
Fix Python gdb.Breakpoint.location crash
because now "catch throw" catchpoints hit the
if (obj->bp->type != bp_breakpoint)
Py_RETURN_NONE;
check above, and, adjusts the testcase to no longer expect to see the
catchpoint in the gdb.breakpoints() list.
(Note: might make sense to do the same to Ada exception catchpoints.)
gdb/ChangeLog:
2019-07-09 Pedro Alves <palves@redhat.com>
* break-catch-throw.c (print_one_exception_catchpoint): Skip the
"addr" field.
(allocate_location_exception_catchpoint): New.
(handle_gnu_v3_exceptions): Don't reset 'type' to bp_breakpoint.
(initialize_throw_catchpoint_ops): Install
allocate_location_exception_catchpoint as allocate_location
method.
* breakpoint.c (bpstat_what) <bp_catch>: Set action to
BPSTAT_WHAT_SINGLE if not stopping and the location's type is not
bp_loc_other.
(breakpoint_address_is_meaningful): Delete.
(bl_address_is_meaningful): New.
(breakpoint_locations_match): Adjust comment.
(bp_location_from_bp_type): New, factored out of...
(bp_location::bp_location(breakpoint *)): ... this.
(bp_location::bp_location(breakpoint *, bp_loc_type)): New,
factored out of...
(bp_location::bp_location(breakpoint *)): ... this. Reimplement.
(bp_loc_is_permanent): Use bl_address_is_meaningful instead of
breakpoint_address_is_meaningful.
(bp_locations_compare): Adjust comment.
(update_global_location_list): Use bl_address_is_meaningful
instead of breakpoint_address_is_meaningful.
* breakpoint.h (bp_location::bp_location(breakpoint *)): New
explicit.
(bp_location::bp_location(breakpoint *, bp_loc_type)): Declare.
* python/py-breakpoint.c (bppy_get_location): No longer check
whether location is null.
gdb/doc/ChangeLog:
2019-07-09 Pedro Alves <palves@redhat.com>
* gdb.texinfo (C++ Exception GDB/MI Catchpoint Commands): Adjust
examples to show type=catchpoint instead of type=breakpoint and an
address.
gdb/testsuite/ChangeLog:
2019-07-09 Pedro Alves <palves@redhat.com>
* gdb.cp/catch-multi-stdlib.exp: Adjust expected "info
breakpoints" output.
* gdb.cp/exception.exp: Adjust expected "info breakpoints" output.
* gdb.python/py-breakpoint.exp: No longer expect that "catch
throw" creates breakpoint.
* gdb.mi/mi-catch-cpp-exceptions.exp (setup_catchpoint): Expect
'type="catchpoint"'.
If you debug current GDB, set a "catch catch/throw/rethrow"
catchpoint, and then do "info breakpoints", the top GDB hits an
internal error:
(top-gdb) catch catch
Catchpoint 1 (catch)
(top-gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y src/gdb/breakpoint.c:6040: internal-error: void print_one_breakpoint_location(breakpoint*, bp_location*, int, bp_location**, int): Assertion `b->loc == NULL || b->loc->next == NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n)
The assertion in question is asserting that a breakpoint with a
print_one method only has one location, and it fails because this
catchpoint ends up with two locations.
Internally, "catch catch" sets a breakpoint at __cxa_begin_catch. If
we do that manually, we see the locations:
(top-gdb) b -qualified __cxa_begin_catch
Breakpoint 2 at 0xb122b0 (2 locations)
(top-gdb) info breakpoints
Num Type Disp Enb Address What
2 breakpoint keep y <MULTIPLE>
2.1 y 0x0000000000b122b0 <__cxa_begin_catch>
2.2 y 0x00007ffff2f4ddb0 in __cxxabiv1::__cxa_begin_catch(void*) at ../../../../libstdc++-v3/libsupc++/eh_catch.cc:41
Note that I had used -qualified. It seems strange that we get a
location for a namespaced symbol, but that happens because the minimal
symbol for that address is indeed called __cxa_begin_catch.
The real issue is that gdb is linked with
-static-libgcc/-static-libstdc++. And then, it _also_ ends up with
shared libstc++ loaded:
(top-gdb) info sharedlibrary stdc++
From To Syms Read Shared Object Library
0x00007ffff2f4b380 0x00007ffff2ffc018 Yes /lib64/libstdc++.so.6
Location 2.2 is set within libstdc++.so.6's range:
(top-gdb) p 0x00007ffff2f4b380 <= 0x00007ffff2f4ddb0 && 0x00007ffff2f4ddb0 < 0x00007ffff2ffc018
$1 = true
So due to -static-lib*, we end up with _two_ copies of the
__cxa_begin_catch code:
(top-gdb) disassemble 0x0000000000b122b0
Dump of assembler code for function __cxa_begin_catch:
0x0000000000b122b0 <+0>: push %rbx
0x0000000000b122b1 <+1>: mov %rdi,%rbx
0x0000000000b122b4 <+4>: callq 0xb11a80 <__cxa_get_globals>
0x0000000000b122b9 <+9>: movabs $0xb8b1aabcbcd4d500,%rdx
...
(top-gdb) disassemble 0x00007ffff2f4ddb0
Dump of assembler code for function __cxxabiv1::__cxa_begin_catch(void*):
0x00007ffff2f4ddb0 <+0>: push %rbx
0x00007ffff2f4ddb1 <+1>: mov %rdi,%rbx
0x00007ffff2f4ddb4 <+4>: callq 0x7ffff2f4a090 <__cxa_get_globals@plt>
0x00007ffff2f4ddb9 <+9>: movabs $0xb8b1aabcbcd4d500,%rdx
...
I think we end up with libstdc++.so.6 loaded because
libsource-highlight.so depends on it.
Irrespective of whether it's a good idea to use
-static-libgcc/-static-libstdc++, GDB should not crash. Since there
are two copies of the code, it seems right to have more than one
location. So the fix is just to remove the assertion.
A testcase is included, which mimics the scenerio described above,
with binary linked with -static-lib{stdc++,gcc} and a shared library
that is linked normally, along with other combinations for good
measure.
gdb/ChangeLog:
2019-07-09 Pedro Alves <palves@redhat.com>
PR c++/15468
* breakpoint.c (print_one_breakpoint_location): Remove
single-location assert.
gdb/testsuite/ChangeLog:
2019-07-09 Pedro Alves <palves@redhat.com>
PR c++/15468
* gdb.cp/except-multi-location-lib.cc: New.
* gdb.cp/except-multi-location-main.cc: New.
* gdb.cp/except-multi-location.exp: New.
wchar_t type must be known to create wide strings.
As this type is predefined when current GDB language is C++,
switch to c++ for the wide strings tests.
Problem analysis and fix by Sergio.
It was observed that in some cases, placing a breakpoint in an
assembler file using filename:line-number syntax would result in the
breakpoint being placed at a different line within the file.
For example, consider this x86-64 assembler:
test:
push %rbp /* Break here. */
mov %rsp, %rbp
nop /* Stops here. */
The user places the breakpoint using file:line notation targeting the
line marked 'Break here', GDB actually stops at the line marked 'Stops
here'.
The reason is that the label 'test' is identified as the likely start
of a function, and the call to symtab.c:skip_prologue_sal causes GDB
to skip forward over the instructions that GDB believes to be part of
the prologue.
I believe however, that when debugging assembler code, where the user
has instruction-by-instruction visibility, if they ask for a specific
line, GDB should (as far as possible) stop on that line, and not
perform any prologue skipping. I don't believe that the behaviour of
higher level languages should change, in these cases skipping the
prologue seems like the correct thing to do.
In order to implement this change I needed to extend our current
tracking of when the user has requested an explicit line number. We
already tracked this in some cases, but not in others (see the changes
in linespec.c). However, once I did this I started to see some
additional failures (in tests gdb.base/break-include.exp
gdb.base/ending-run.exp gdb.mi/mi-break.exp gdb.mi/mi-reverse.exp
gdb.mi/mi-simplerun.exp) where we currently expected a breakpoint
placed at one file and line number to be updated to reference a
different line number, this was fixed by removing some code in
symtab.c:skip_prologue_sal. My concern here is that removing this
check didn't cause anything else to fail.
I have a new test that covers my original case, this is written for
x86-64 as most folk have access to such a target, however, any
architecture that has a prologue scanner can be impacted by this
change.
gdb/ChangeLog:
* linespec.c (decode_digits_list_mode): Set explicit_line to a
bool value.
(decode_digits_ordinary): Set explicit_line field in sal.
* symtab.c (skip_prologue_sal): Don't skip prologue for a
symtab_and_line that was set on an explicit line number in
assembler code. Do always update the recorded symtab and line if
we do skip the prologue.
gdb/testsuite/ChangeLog:
* gdb.arch/amd64-break-on-asm-line.S: New file.
* gdb.arch/amd64-break-on-asm-line.exp: New file.
The explicit_loc parameter in set_breakpoint_location_function is not
useful. This parameter is set from two possible fields of the
symtab_and_line used to create the breakpoint; the explicit_pc field,
and the explicit_line field.
First, the explicit_line field, this is not currently set for any
breakpoint command, so will never be true.
Next, the explicit_pc field. This can be true but will never be true
at the same time that the sal->msymbol field is also true - the
sal->msymbol is only ever set in linespec.c:minsym_found, which
doesn't allow for explicitly setting the pc.
The result of this is that if we are setting a breakpoint on an
msymbol that could turn out to be an ifunc, then we will not also have
either an explicit_pc or an explicit_line, this check can therefore be
removed.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* breakpoint.c (set_breakpoint_location_function): Remove
explicit_loc parameter.
(momentary_breakpoint_from_master): Update call to
set_breakpoint_location_function.
(add_location_to_breakpoint): Likewise.
When we initialise a gdbarch object we perform a check to try and
detect if the user is doing something silly; trying to run an RV64
binary on an RV32 target. To perform this check we compare the xlen
from the target description with the xlen specified in the headers on
the ELF being debugged.
If there is no ELF being debugged then we (currently) try to use the
bfd_arch_info from the gdbarch_info object, which will have been set
to the default architecture if no bfd is currently being debugged.
For RISC-V the default architecture is RV64.
What this means is that if a user tries to connect to an RV32 target
without specifying the BFD to debug then GDB will assume RV64. The
sanity check mentioned above will failed (xlen difference) and GDB
will throw an error. The error causes GDB to disconnect from the
remote target.
After this commit GDB no longer relies on the default bfd
architecture. If the user tries to connect without specifying the bfd
then GDB will simply make use of the xlen extracted from the target
description in order to find or create a suitable gdbarch object.
gdb/ChangeLog:
* riscv-tdep.c (riscv_features_from_gdbarch_info): Don't modify
required features based on default bfd type when no specific bfd
is present.
Without this patch, GDB printf command calls malloc on the target,
writes the convenience var content to the target,
re-reads the content from the target, and then locally printf the string.
This implies inferior calls, and does not work when there is no running
inferior, or when the inferior is a core dump.
With this patch, printf command can printf string convenience variables
without inferior function calls.
Ada string convenience variables can also be printed.
gdb/ChangeLog
2019-07-08 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* NEWS: Mention that GDB printf and eval commands can now print
C-style and Ada-style convenience var strings without
calling the inferior.
* printcmd.c (printf_c_string): Locally print GDB internal var
instead of transiting via the inferior.
(printf_wide_c_string): Likewise.
gdb/testsuite/ChangeLog
2019-07-08 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* gdb.base/printcmds.exp: Test printing C string and
C wide string convenience vars without transiting via the inferior.
Also make test names unique.
When a binary is built using PIE, reloading the file will cause GDB to error
on restart. For example:
gdb ./a.out
(gdb) break main
(gdb) run
(gdb) file ./a.out
(gdb) continue
Will cause GDB to error with:
Continuing.
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x9e0
Command aborted.
This is due to the symbol offsets not being relocated after reloading the file.
Fix is to ensure solib_create_inferior_hook is called, in the same manner as
infrun.c:follow_exec().
Expand the idempotent test to cover PIE scenarios.
gdb/ChangeLog:
* symfile.c (symbol_file_command): Call solib_create_inferior_hook.
gdb/testsuite/ChangeLog:
* gdb.base/break-idempotent.exp: Test both PIE and non PIE.
The TUI uses the "has_break" in two different ways: sometimes as a
boolean, and sometimes as flags.
This patch changes the TUI to be more type-safe here, and fixes the
code. I could not find a bug that this caused, so apparently this is
just cosmetic.
This deletes some code from tui_set_disassem_content. Whenver this is
called, I believe the TUI updates the breakpoint information
afterward, so this assignment is redundant; which is good because it
is also incorrect.
gdb/ChangeLog
2019-07-04 Tom Tromey <tom@tromey.com>
PR tui/24724:
* tui/tui-winsource.c (tui_clear_source_content): Update.
(tui_source_window_base::set_is_exec_point_at): Fix comment.
(tui_update_breakpoint_info): Update.
(tui_set_exec_info_content): Update.
* tui/tui-source.c (tui_set_source_content_nil): Update.
* tui/tui-disasm.c (tui_set_disassem_content): Don't set
has_break.
* tui/tui-data.h (enum tui_bp_flag): New.
(tui_bp_flags): New enum flags type.
(struct tui_source_element) <break_mode>: Change type. Rename
from has_break.
(TUI_BP_ENABLED, TUI_BP_DISABLED, TUI_BP_HIT)
(TUI_BP_CONDITIONAL, TUI_BP_HARDWARE): Don't define. Now enum
constants.
* tui/tui-winsource.h: Fix comment.
Fix a silly bug in commit a26c8de0ee ("Fix early return in
foreach_with_prefix").
That patch made foreach_with_prefix always return after the first
iteration, making ~10k tests disappear from test runs...
This fixes it, and as penance, adds a testcase that exercises all
kinds of different returns possible (ok, error, return, break,
continue). I've written it with regular "foreach", and then switched
to foreach_with_prefix and made sure we get the same results. I put
the testcase in a new gdb.testsuite/ subdir, since this is exercising
the testsuite harness bits. We can move this elsewhere if people
prefer a different place, but I'm going ahead in order to unbreak the
testsuite ASAP.
gdb/testsuite/ChangeLog:
2019-07-04 Pedro Alves <palves@redhat.com>
* lib/gdb.exp (foreach_with_prefix): Don't return early if
body returned ok(0), break(3) or continue(4).
* gdb.testsuite/foreach_with_prefix.exp: New file.
Both targets were using a mixture of defines and hardcoded values.
Add a standard set in arch/arm.h and use throughout, ensuring that
none of the existing sizes change.
No functionality changes.
gdb/ChangeLog:
* aarch32-linux-nat.h (VFP_REGS_SIZE): Remove define.
* aarch64-linux-nat.c (fetch_fpregs_from_thread)
(store_fpregs_to_thread)
(aarch64_linux_nat_target::read_description): Use ARM_VFP3_REGS_SIZE.
* arch/arm.h (IWMMXT_VEC_REGISTER_SIZE, ARM_CORE_REGS_SIZE)
(ARM_FP_REGS_SIZE, ARM_VFP2_REGS_SIZE, ARM_VFP3_REGS_SIZE)
(IWMMXT_REGS_SIZE): Add define.
* arm-linux-nat.c (IWMMXT_REGS_SIZE): Remove define.
(fetch_vfp_regs, store_vfp_regs)
(arm_linux_nat_target::read_description): Use ARM_VFP3_REGS_SIZE.
* arm-tdep.c (arm_register_g_packet_guesses): Use new defines.
gdb/gdbserver/ChangeLog:
* linux-aarch32-low.c (arm_read_description, arm_regsets): Use new
defines.
* linux-arm-low.c (arm_read_description, arm_regsets): Likewise.
Add ARM_ to the front of INT_REGISTER_SIZE, FP_REGISTER_SIZE and
ARM_VFP_REGISTER_SIZE to make it obvious they are for the Arm target.
Move the defines to arch/arm.h
No functionality changes.
gdb/ChangeLog:
* arch/arm-get-next-pcs.c (thumb_get_next_pcs_raw): Use ARM_
defines.
* arch/arm-linux.c (arm_linux_sigreturn_next_pc_offset): Likewise.
* arch/arm.h (INT_REGISTER_SIZE) Rename from...
(ARM_INT_REGISTER_SIZE): ...to this.
(ARM_FP_REGISTER_SIZE) (ARM_VFP_REGISTER_SIZE): Add define.
* arm-linux-tdep.c (ARM_LINUX_JB_ELEMENT_SIZE)
(ARM_LINUX_SIZEOF_GREGSET, arm_linux_supply_gregset)
(arm_linux_collect_gregset, supply_nwfpe_register)
(collect_nwfpe_register, arm_linux_collect_nwfpe): Use ARM_
defines.
* arm-linux-tdep.h (ARM_LINUX_SIZEOF_NWFPE, NWFPE_FPSR_OFFSET)
(NWFPE_FPCR_OFFSET, NWFPE_TAGS_OFFSET): Likewise
* arm-nbsd-tdep.c (ARM_NBSD_JB_ELEMENT_SIZE): Likewise.
* arm-tdep.c (arm_push_dummy_call, arm_extract_return_value)
(arm_return_in_memory, arm_store_return_value)
(arm_get_longjmp_target, arm_register_g_packet_guesses)
(arm_record_ld_st_multiple): Likewise.
* arm-tdep.h (FP_REGISTER_SIZE, VFP_REGISTER_SIZE): Remove.
* arm-wince-tdep.c (ARM_WINCE_JB_ELEMENT_SIZE): Use ARM_ defines.
Both targets define DISPLACED_MODIFIED_INSNS, each with different values.
Add ARM_ and AARCH64_ to the start of the name to prevent confusion.
No functionality changes.
gdb/ChangeLog:
* aarch64-linux-tdep.c (aarch64_linux_init_abi): Use
AARCH64_DISPLACED_MODIFIED_INSNS.
* aarch64-tdep.c (struct aarch64_displaced_step_data)
(aarch64_displaced_step_copy_insn): Likewise.
* aarch64-tdep.h (DISPLACED_MODIFIED_INSNS): Rename from..
(AARCH64_DISPLACED_MODIFIED_INSNS): ...to this.
* arm-linux-tdep.c (arm_linux_cleanup_svc): Use
ARM_DISPLACED_MODIFIED_INSNS.
* arm-tdep.c (arm_gdbarch_init): Likewise.
* arm-tdep.h (DISPLACED_MODIFIED_INSNS): Rename from..
(ARM_DISPLACED_MODIFIED_INSNS): ...to this.
(struct arm_displaced_step_closure): Use
ARM_DISPLACED_MODIFIED_INSNS.
Both the i386, X86_64 and AArch64 builds of gdbserver include a bunch of legacy
xml files, dat files and auto generated C files, when building for unit test.
These tests exists back from when feature target descriptions were added to
prove that the new target descriptions were identical to the original
older versions. The old files are not used for anything other than these tests.
Now that this has been proven, we are not gaining anything by keeping the
original files and tests. Should new functionality be added, it would break
the tests, unless the functionality was backported to the xml. There is no
requirement that we must match the exact xml from N releases ago. It adds
obfuscation, where as the feature target descriptions were meant to simplify
the code.
In addition, there are a bunch of xml and dat files which are completely unused.
This patch removes the selftests and the target descriptions from gdbserver.
Update the unittest to allow 0 tests (note, this failed on other targets that
never had any tests).
gdb/ChangeLog:
* aarch64-tdep.c: Remove xml self tests.
* amd64-linux-tdep.c: Likewise.
* amd64-tdep.c: Likewise.
* i386-linux-tdep.c: Likewise.
* i386-tdep.c: Likewise.
gdb/gdbserver/ChangeLog:
* configure.srv: Remove legacy xml.
* linux-aarch64-low.c (initialize_low_arch): Remove
initialize_low_tdesc call.
* linux-aarch64-tdesc-selftest.c: Remove file.
* linux-aarch64-tdesc.h (initialize_low_tdesc): Remove.
* linux-x86-low.c (initialize_low_arch): Remove
initialize_low_tdesc call.
* linux-x86-tdesc-selftest.c: Remove file.
* linux-x86-tdesc.h (initialize_low_tdesc): Remove.
gdb/testsuite/ChangeLog:
* gdb.server/unittest.exp: Allow 0 unit tests to run.
I noticed that an early return in a foreach_with_prefix block does not
cause the outer scope to return, like:
foreach_with_prefix var {"foo" "bar"} {
return
}
# Control continues here, but it should not.
The problem is that we're missing the usual "return -code" treatment.
This commit fixes it.
gdb/testsuite/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
* lib/gdb.exp (foreach_with_prefix): Use "catch" and
"return -code".
This commit adds a completer for the "pipe" command. It can complete
"pipe"'s options, and the specified GDB command.
To make the completer aware of the "-d" option, this converts the
option processing to use gdb::option.
Tests included.
gdb/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
PR cli/24732
* cli/cli-cmds.c (struct pipe_cmd_opts): New.
(pipe_cmd_option_defs): New.
(make_pipe_cmd_options_def_group): New.
(pipe_command): Use gdb::option::process_options.
(pipe_command_completer): New function.
(_initialize_cli_cmds): Install completer for "pipe" command.
gdb/testsuite/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
PR cli/24732
* gdb.base/shell.exp: Load completion-support.exp.
Adjust expected error output. Add completion tests.
A following patch will add the following to a testcase:
test_gdb_completion_offers_commands "| "
And that tripped on a latent testsuite bug:
(gdb) | PASS: gdb.base/shell.exp: tab complete "| "
^CQuit
(gdb) complete |
| !
| +
PASS: gdb.base/shell.exp: cmd complete "| "
| *** List may be truncated, max-completions reached. ***
(gdb) FAIL: gdb.base/shell.exp: set max-completions 200
set max-completions 200
The issue is that "|" ends up as part of a regexp, and "|" in regexps
has a special meaning...
Fix this with string_to_regexp.
gdb/testsuite/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
* lib/completion-support.exp (test_gdb_complete_cmd_multiple): Use
string_to_regexp.
A following patch will make the "pipe" command use the gdb::option
framework for option processing. However, "pipe"'s only option today
is a string option, "-d DELIM", and gdb::option does not support
string options yet.
This commit adds support for string options, mapped to var_string.
For now, a string is parsed up until the first whitespace. I imagine
that we'll need to add support for quoting so that we could do:
(gdb) cmd -option 'some -string'
without gdb confusing the "-string" for an option.
This doesn't seem important for pipe, so I'm leaving it for another
day.
One thing I'm not happy with, is that the string data is managed as a
raw malloc-allocated char *, which means that we need to xfree it
manually. This is because var_string settings work that way too.
Although with var_string settings we're leaking the strings at gdb
exit, that was never really a problem. For options though, leaking is
undesirable.
I think we should tackle that for both settings and options at the
same time, so for now I'm just managing the malloced data manually.
It's a bit ugly in option_def_and_value, but at least that's hidden
from view.
For testing, this adds a new "-string" option to "maint
test-settings", and then tweaks gdb.base/options.exp to exercise it.
gdb/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
* cli/cli-option.c (union option_value) <string>: New field.
(struct option_def_and_value): Add ctor, move ctor, dtor and
use DISABLE_COPY_AND_ASSIGN.
(option_def_and_value::clear_value): New.
(parse_option, save_option_value_in_ctx, get_val_type_str)
(add_setshow_cmds_for_options): Handle var_string.
* cli-option.h (union option_def::var_address) <string>: New
field.
(struct string_option_def): New.
* maint-test-options.c (struct test_options_opts): Add default
ctor and use DISABLE_COPY_AND_ASSIGN.
<string_opt>: New field.
(test_options_opts::~test_options_opts): New.
(test_options_opts::dump): Also dump "-string".
(test_options_option_defs): Install "string.
gdb/testsuite/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
* gdb.base/options.exp (expect_none, expect_flag, expect_bool)
(expect_integer): Adjust to expect "-string".
(expect_string): New.
(all_options): Expect "-string".
(test-flag, test-boolean): Adjust to expect "-string".
(test-string): New proc.
(top level): Call it.
Currently, gdb::option::complete_options just discards any processed
option argument, because no completer needs that data.
When completing "pipe -d XXX gdbcmd XXX" however, the completer needs
to know about -d's argument (XXX), in order to know where input is
already past the gdb command and the delimiter.
In this commit, the fix for that is the factoring out of the
save_option_value_in_ctx function and calling it in complete_options.
For testing, this makes "maint show test-options-completion-result"
show the processed options too, like what the "maint test-options"
subcommands output when run. Then, of course, gdb.base/options.exp is
adjusted.
Doing this exposed a couple latent bugs, which is what the other gdb
changes in the patch are for:
- in the var_enum case, without the change, we'd end up with a null
enum argument, and print:
"-enum (null)"
- The get_ulongest change is necessary to avoid advancing PP in a
case where we end up throwing an error, e.g., when parsing "11x".
Without the change the operand pointer shown by "maint show
test-options-completion-result" would be left pointing at "x"
instead of "11x".
gdb/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
* cli/cli-option.c (parse_option) <var_enum>: Don't return an
option_value with a null enumeration.
(complete_options): Save the option values in the context.
(save_option_value_in_ctx): New, factored out from ...
(process_options): ... here.
* cli/cli-utils.c (get_ulongest): Don't advance PP until the end
of the function.
* maint-test-options.c (test_options_opts::dump): New, factored
out from ...
(maintenance_test_options_command_mode): ... here.
(maintenance_test_options_command_completion_result): Delete.
(maintenance_test_options_command_completion_text): Update
comment.
(maintenance_show_test_options_completion_result): Change
prototype. Just print
maintenance_test_options_command_completion_text.
(save_completion_result): New.
(maintenance_test_options_completer_mode): Pass options context to
complete_options, and then save a dump.
(_initialize_maint_test_options): Use add_cmd to install "maint
show test-options-completion-result".
gdb/testsuite/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
* gdb.base/options.exp (test-misc, test-flag, test-boolean)
(test-uinteger, test-enum): Adjust res_test_gdb_... calls to pass
the expected output in the success.
Running 'make check-read1 TESTS="gdb.base/options.exp"' revealed a
race in test_gdb_complete_tab_multiple. There's a gdb_test_multiple
call that expects a prompt in the middle of the regexp. That's racy
because gdb_test_multiple includes a built-in FAIL pattern for the
prompt, which may match if gdb is slow enough to produce the rest of
the output after the prompt.
Fix this in the usual way of splitting the matching in two.
gdb/testsuite/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
* lib/completion-support.exp (test_gdb_complete_tab_multiple):
Split one gdb_test_multiple call in two to avoid a race.
( See original discussion and prototype here:
https://sourceware.org/ml/gdb-patches/2019-05/msg00570.html )
(gdb) help with
Temporarily set SETTING to VALUE, run COMMAND, and restore SETTING.
Usage: with SETTING [VALUE] [-- COMMAND]
Usage: w SETTING [VALUE] [-- COMMAND]
With no COMMAND, repeats the last executed command.
SETTING is any setting you can change with the "set" subcommands.
E.g.:
with language pascal -- print obj
with print elements unlimited -- print obj
As can be seen above, the "with" command is just like "set", but
instead of setting the setting permanently, it sets the setting, runs
a command and then restores the setting.
(gdb) p g_s
$1 = {a = 1, b = 2, c = 3}
(gdb) with language ada -- print g_s
$2 = (a => 1, b => 2, c => 3)
Warning: the current language does not match this frame.
(gdb) show language
The current source language is "auto; currently c".
(gdb) with print elements 100 -- with print object on -- print 1
$3 = 1
You can shorten things a bit though, as long as unambiguous. So this:
(gdb) with print elements 100 -- with print object off -- print 1
is the same as:
(gdb) w p el 100 -- w p o 0 -- p 1
Note that the patch adds a "w" alias for "with", as "w" is not
currently taken:
(gdb) w
Ambiguous command "w": watch, wh, whatis, where, while, while-stepping, winheight, ws.
Let me know if you'd prefer to reserve "w" for one of the other
commands above. IMHO, this command will end up being used frequently
enough that it deserves the "w" shorthand.
A nice feature is that this is fully integrated with TAB-completion:
(gdb) with p[TAB]
pagination print prompt python
(gdb) with print [TAB]
address max-depth static-members
array max-symbolic-offset symbol
array-indexes null-stop symbol-filename
asm-demangle object symbol-loading
demangle pascal_static-members thread-events
elements pretty type
entry-values raw union
frame-arguments repeats vtbl
inferior-events sevenbit-strings
(gdb) with print [TAB]
(gdb) with print elements unlimited -- thread apply all -[TAB]
-ascending -c -q -s
(gdb) with print elements unlimited -- print -[TAB]
-address -max-depth -repeats -vtbl
-array -null-stop -static-members
-array-indexes -object -symbol
-elements -pretty -union
The main advantage of this new command compared to command options,
like the new "print -OPT", is that this command works with any
setting, and, it works nicely when you want to override a setting
while running a user-defined command, like:
(gdb) with print pretty -- usercmd
The disadvantage is that it isn't as compact or easy to type. I think
of command options and this command as complementary. I think that
even with this new command, it makes sense to continue developing the
command options in the direction of exposing most-oft-used settings as
command options.
Inspired by Philippe's "/" command proposal, if no command is
specified, then the last command is re-invoked, under the overridden
setting:
(gdb) p g_s
$1 = {a = 1, b = 2, c = 3}
(gdb) with language ada
$2 = (a => 1, b => 2, c => 3)
Warning: the current language does not match this frame.
Note: "with" requires "--" to separate the setting from the command.
It might be possible to do without that, but, I haven't tried it yet,
and I think that this can go in without it. We can always downgrade
to making "--" optional if we manage to make it work.
On to the patch itself, the implementation of the command is simpler
than one might expect. A few details:
- I factored out a bit from pipe_command into repeat_previous
directly, because otherwise I'd need to copy&paste the same code and
same error message in the with command.
- The parse_cli_var_uinteger / parse_cli_var_zuinteger_unlimited /
do_set_command changes are necessary since we can now pass an empty
string as argument.
- do_show_command was split in two, as a FIXME comment suggests, but
for a different reason: we need to get a string version of a "set"
command's value, and we already had code for that in
do_show_command. That code is now factored out to the new
get_setshow_command_value_string function.
- There's a new "maint with" command added too:
(gdb) help maint with
Like "with", but works with "maintenance set" variables.
Usage: maintenance with SETTING [VALUE] [-- COMMAND]
With no COMMAND, repeats the last executed command.
SETTING is any setting you can change with the "maintenance set"
subcommands.
"with" and "maint with" share 99% of the implementation.
This might be useful on its own, but it's also useful for testing,
since with this, we can use the "maint set/show test-settings"
settings for exercising the "with" machinery with all the command
type variants (all enum var_types). This is done in the new
gdb/base/with.exp testcase.
The documentation bits are originally based on Philippe's docs for the
"/" command, hence the attribution in the ChangeLog.
gdb/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
* NEWS (New commands): Mention "with" and "maint with".
* cli/cli-cmds.c (with_command_1, with_command_completer_1)
(with_command, with_command_completer): New.
(pipe_command): Adjust to new repeat_previous
interface.
(_initialize_cli_cmds): Install the "with" command and its "w"
alias.
* cli/cli-cmds.h (with_command_1, with_command_completer_1): New
declarations.
* cli/cli-setshow.c (parse_cli_var_uinteger)
(parse_cli_var_zuinteger_unlimited, do_set_command): Handle empty
argument strings for all var_types.
(get_setshow_command_value_string): New, factored out from ...
(do_show_command): ... this.
* cli/cli-setshow.h: Include <string>.
(get_setshow_command_value_string): Declare.
* command.h (repeat_previous): Now returns const char *. Adjust
comment.
* maint.c: Include "cli/cli-cmds.h".
(maintenance_with_cmd, maintenance_with_cmd_completer): New.
(_initialize_maint_cmds): Register the "maintenance with" command.
* top.c (repeat_previous): Move bits from pipe_command here:
Return the saved command line, if any; error out if there's no
command to relaunch.
gdb/doc/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
Philippe Waroquiers <philippe.waroquiers@skynet.be>
* gdb.texinfo (Command Settings): New node documenting the general
concept of settings, how to change them, and the new "with"
command.
(Maintenance Commands): Document "maint with".
gdb/testsuite/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
* gdb.base/with.c: New file.
* gdb.base/with.exp: New file.
This commit renames "maint test-settings set/show" to "maint set/show
test-settings".
This helps the following patch, which introduce a "maint with" command
what works with all "maint set" settings.
gdb/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
* NEWS (New commands): Mention "maint set/show test-settings"
instead of "maint test-settings".
* maint-test-settings.c (maintenance_test_settings_list): Delete.
(maintenance_test_settings_set_list): Rename to ...
(maintenance_set_test_settings_list): ... this.
(maintenance_test_settings_show_list): Rename to ...
(maintenance_show_test_settings_list): ... this.
(maintenance_test_settings_cmd): Delete.
(maintenance_test_settings_set_cmd): ...
(maintenance_set_test_settings_cmd): ... this.
(maintenance_test_settings_show_cmd): ...
(maintenance_show_test_settings_cmd): ... this.
(maintenance_test_settings_show_value_cmd):
(maintenance_show_test_settings_value_cmd): ... this.
(_initialize_maint_test_settings): No longer install the "maint
test-settings" prefix command. Rename "maint test-settings set"
to "maint set test-settings", and "maint test-settings show" to
"maint show test-settings". Adjust all subcommands.
gdb/doc/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
* gdb.texinfo (Maintenance Commands): Document "maint set/show
test-settings" instead of "maint test-settings set/show".
gdb/testsuite/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
* gdb.base/settings.exp: Replace all references to "maint
test-settings set" with references to "maint set test-settings",
and all references to "maint test-settings show" with references
to "maint show test-settings".
Fix the file's intro comment, and s/test-options/test-settings/.
gdb/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
* maint-test-settings.c: Fix file's intro comment. Replace all
references to "test-options" with references to "test-settings",
in comments.
New tests added later for the incoming "with" command exposed a couple
invalid-default-value bugs in the "maint test-settings" commands:
- var_filename commands don't allow setting the filename to the empty
string (unlike var_optional_filename commands), yet, "maint
test-settings filename"'s control variable was not initialized, so
on startup, "maint test-settings show filename" shows an empty
string.
- "maint test-settings enum"'s control variable was not initialized,
so on startup, "maint test-settings show enum" shows an empty value
instead of a valid enum value.
Both issues are fixed by initializing the control variables.
gdb/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
* maint-test-settings.c (maintenance_test_settings_xxx)
(maintenance_test_settings_yyy, maintenance_test_settings_zzz):
New.
(maintenance_test_settings_enums): Use them.
(maintenance_test_settings_enum): Default to
maintenance_test_settings_xxx.
(_initialize_maint_test_settings): Initialize
MAINTENANCE_TEST_SETTINGS_FILENAME.
gdb/testsuite/ChangeLog:
2019-07-03 Pedro Alves <palves@redhat.com>
* gdb.base/settings.exp (test-string): Adjust expected out when
testing "maint test-settings show filename"
... since nobody uses it.
gdb/ChangeLog:
* breakpoint.h (remove_breakpoints_inf): Change return type to
void, move function documentation here.
* breakpoint.c (remove_breakpoints_inf): Change return type to
void, move function documentation to header.
This makes "info threads" use the gdb::option framework to process
options. There's only one option today (-gid), and it isn't used much
frequently unless you're looking at matching MI output. Still, this
was in the neighborhood of "thread apply" so I had converted it.
The main advantage is that TAB completion now shows you the available
options, and gives you a hint to what the command accepts as operand
argument, including showing a metasyntactic variable:
(gdb) info threads [TAB]
-gid ID
(gdb) help info threads
Display currently known threads.
Usage: info threads [OPTION]... [ID]...
Options:
-gid
Show global thread IDs.
If ID is given, it is a space-separated list of IDs of threads to display.
Otherwise, all threads are displayed.
(gdb)
gdb/ChangeLog:
2019-07-02 Pedro Alves <palves@redhat.com>
* NEWS (Completion improvements): Mention "info threads".
* thread.c (struct info_threads_opts, info_threads_option_defs)
(make_info_threads_options_def_group): New.
(info_threads_command): Use gdb::option::process_options.
(info_threads_command_completer): New.
(_initialize_thread): Use gdb::option::build_help to build the
help text for "info threads".
gdb/testsuite/ChangeLog:
2019-07-02 Pedro Alves <palves@redhat.com>
* gdb.base/options.exp (test-info-threads): New procedure.
(top level): Call it.
... since the implementation is in symfile.c.
At the same time, add some documentation and make sure the first
parameter's name in the declaration matches the definition.
gdb/ChangeLog:
* defs.h (generic_load): Move from here...
* symfile.h (generic_load): ... to here. Rename name parameter
to args.
* symfile.c (generic_load): Add comment.
A static analyzer pointed out that find_vec_in_debug_names will use
the contents of a unique_ptr after it has been destroyed. This patch
fixes the bug by hoisting the declaration into the appropriate
enclosing block.
I'm checking this in as obvious.
gdb/ChangeLog
2019-07-01 Tom Tromey <tromey@adacore.com>
* dwarf2read.c
(dw2_debug_names_iterator::find_vec_in_debug_names): Hoist
declaration of without_params. Fix formatting.
All callers of ada_lookup_symbol pass NULL for the
"is_a_field_of_this" parameter, so remove it.
gdb/ChangeLog
2019-07-01 Tom Tromey <tromey@adacore.com>
* ada-exp.y (find_primitive_type): Update.
* ada-lang.h (ada_lookup_symbol): Update.
* ada-lang.c (ada_lookup_symbol): Remove "is_a_field_of_this"
parameter.
(ada_lookup_encoded_symbol, ada_lookup_symbol_nonlocal): Update.
This bug has been reported on PR breakpoints/24541, but it is possible
to reproduce it easily by running:
make check-gdb TESTS=gdb.base/stap-probe.exp RUNTESTFLAGS='--target_board unix/-m32'
The underlying cause is kind of complex, and involves decisions made
by GCC and the sys/sdt.h header file about how to represent a probe
argument that lives in a register in 32-bit programs. I'll use
Andrew's example on the bug to illustrate the problem.
libstdc++ has a probe named "throw" with two arguments. On i386, the
probe is:
stapsdt 0x00000028 NT_STAPSDT (SystemTap probe descriptors)
Provider: libstdcxx
Name: throw
Location: 0x00072c96, Base: 0x00133d64, Semaphore: 0x00000000
Arguments: 4@%si 4@%di
I.e., the first argument is an unsigned 32-bit value (represented by
the "4@") that lives on %si, and the second argument is an unsigned
32-bit value that lives on %di. Note the discrepancy between the
argument size reported by the probe (32-bit) and the register size
being used to store the value (16-bit).
However, if you take a look at the disassemble of a program that uses
this probe, you will see:
00072c80 <__cxa_throw@@CXXABI_1.3>:
72c80: 57 push %edi
72c81: 56 push %esi
72c82: 53 push %ebx
72c83: 8b 74 24 10 mov 0x10(%esp),%esi
72c87: e8 74 bf ff ff call 6ec00 <__cxa_finalize@plt+0x980>
72c8c: 81 c3 74 e3 10 00 add $0x10e374,%ebx
72c92: 8b 7c 24 14 mov 0x14(%esp),%edi
72c96: 90 nop <----------------- PROBE IS HERE
72c97: e8 d4 a2 ff ff call 6cf70 <__cxa_get_globals@plt>
72c9c: 83 40 04 01 addl $0x1,0x4(%eax)
72ca0: 83 ec 04 sub $0x4,%esp
72ca3: ff 74 24 1c pushl 0x1c(%esp)
72ca7: 57 push %edi
72ca8: 56 push %esi
72ca9: e8 62 a3 ff ff call 6d010 <__cxa_init_primary_exception@plt>
72cae: 8d 70 40 lea 0x40(%eax),%esi
72cb1: c7 00 01 00 00 00 movl $0x1,(%eax)
72cb7: 89 34 24 mov %esi,(%esp)
72cba: e8 61 96 ff ff call 6c320 <_Unwind_RaiseException@plt>
72cbf: 89 34 24 mov %esi,(%esp)
72cc2: e8 c9 84 ff ff call 6b190 <__cxa_begin_catch@plt>
72cc7: e8 d4 b3 ff ff call 6e0a0 <_ZSt9terminatev@plt>
72ccc: 66 90 xchg %ax,%ax
72cce: 66 90 xchg %ax,%ax
Note how the program is actually using %edi, and not %di, to store the
second argument. This is the problem here.
GDB will basically read the probe argument, then read the contents of
%di, and then cast this value to uint32_t, which causes the wrong
value to be obtained. In the gdb.base/stap-probe.exp case, this makes
GDB read the wrong memory location, and not be able to display a test
string. In Andrew's example, this causes GDB to actually stop at a
"catch throw" when it should actually have *not* stopped.
After some discussion with Frank Eigler and Jakub Jelinek, it was
decided that this bug should be fixed on the client side (i.e., the
program that actually reads the probes), and this is why I'm proposing
this patch.
The idea is simple: we will have a gdbarch method, which, for now, is
only used by i386. The generic code that deals with register operands
on gdb/stap-probe.c will call this method if it exists, passing the
current parse information, the register name and its number.
The i386 method will then verify if the register size is greater or
equal than the size reported by the stap probe (the "4@" part). If it
is, we're fine. Otherwise, it will check if we're dealing with any of
the "extendable" registers (like ax, bx, si, di, sp, etc.). If we
are, it will change the register name to include the "e" prefix.
I have tested the patch here in many scenarios, and it fixes Andrew's
bug and also the regressions I mentioned before, on
gdb.base/stap-probe.exp. No regressions where found on other tests.
Comments?
gdb/ChangeLog:
2019-06-27 Sergio Durigan Junior <sergiodj@redhat.com>
PR breakpoints/24541
* gdbarch.c: Regenerate.
* gdbarch.h: Regenerate.
* gdbarch.sh: Add 'stap_adjust_register'.
* i386-tdep.c: Include '<unordered_set>'.
(i386_stap_adjust_register): New function.
(i386_elf_init_abi): Register 'i386_stap_adjust_register'.
* stap-probe.c (stap_parse_register_operand): Call
'gdbarch_stap_adjust_register'.
This bug was originally reported against Fedora GDB:
https://bugzilla.redhat.com/show_bug.cgi?id=1723564
The problem is that GDB will crash in the following scenario:
- PYTHONMALLOC=debug or PYTHONDEVMODE=1 is set.
- The Python debuginfo is installed.
- GDB is used to debug Python.
The crash looks like this:
$ PYTHONMALLOC=debug gdb -args python3 -c pass
GNU gdb (GDB) Fedora 8.3-3.fc30
Reading symbols from python3...
Reading symbols from /usr/lib/debug/usr/bin/python3.7m-3.7.3-3.fc30.x86_64.debug...
(gdb) run
Starting program: /usr/bin/python3 -c pass
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.29-9.fc30.x86_64
Debug memory block at address p=0x5603977bf330: API ''
8098648152243306496 bytes originally requested
The 7 pad bytes at p-7 are not all FORBIDDENBYTE (0xfb):
at p-7: 0x03 *** OUCH
at p-6: 0x00 *** OUCH
at p-5: 0x00 *** OUCH
at p-4: 0x00 *** OUCH
at p-3: 0x00 *** OUCH
at p-2: 0x00 *** OUCH
at p-1: 0x00 *** OUCH
Because memory is corrupted at the start, the count of bytes requested
may be bogus, and checking the trailing pad bytes may segfault.
The 8 pad bytes at tail=0x706483999ad1f330 are Segmentation fault (core dumped)
It's hard to determine what happens, but after doing some
investigation and talking to Victor Stinner I found that GDB should
not use the Python memory allocation functions before the Python
interpreter is initialized (which makes sense). However, we do just
that on python/python.c:do_start_initialization:
...
progsize = strlen (progname.get ());
progname_copy = (wchar_t *) PyMem_Malloc ((progsize + 1) * sizeof (wchar_t));
...
/* Note that Py_SetProgramName expects the string it is passed to
remain alive for the duration of the program's execution, so
it is not freed after this call. */
Py_SetProgramName (progname_copy);
...
Py_Initialize ();
PyEval_InitThreads ();
Upon reading the Python 3 C API documentation, I
found (https://docs.python.org/3.5/c-api/memory.html):
To avoid memory corruption, extension writers should never try to
operate on Python objects with the functions exported by the C
library: malloc(), calloc(), realloc() and free(). This will result in
mixed calls between the C allocator and the Python memory manager with
fatal consequences, because they implement different algorithms and
operate on different heaps. However, one may safely allocate and
release memory blocks with the C library allocator for individual
purposes[...]
And Py_SetProgramName seems like a very simple call that doesn't need
a Python-allocated memory to work on. So I'm proposing this patch,
which simply replaces PyMem_Malloc by xmalloc.
Testing this is more complicated. First, the crash is completely
non-deterministic; I was able to reproduce it 10 times in a row, and
then I wasn't able to reproduce it anymore. I found that if you
completely remove your build directory and rebuild GDB from scratch,
you can reproduce it again confidently. And with my patch, I
confirmed that the bug doesn't manifest even in this situation.
No regressions found.
OK to apply?
gdb/ChangeLog:
2019-06-28 Sergio Durigan Junior <sergiodj@redhat.com>
PR python/24742
https://bugzilla.redhat.com/show_bug.cgi?id=1723564
* python/python.c (do_start_initialization): Use 'xmalloc'
instead of 'PyMem_Malloc'.
We discovered that the Ada support in gdb depends on the order of the
DW_AT_name and DW_AT_linkage_name attributes in the DWARF. In
particular, if they are emitted in the "wrong" order for some system
symbols, "catch exception" will not work.
This patch fixes this problem by arranging to always prefer the
linkage name if both exist. This seems to be what the full symbol
reader already does -- that is, this is another bug arising from
having two different DWARF readers.
Another possible issue here is that gdb still doesn't really preserve
mangled names properly. There's a PR open about this. However, this
seems to be somewhat involved to fix, which is why this patch
continues to work around the bigger issue.
gdb/ChangeLog
2019-06-28 Tom Tromey <tromey@adacore.com>
* dwarf2read.c (partial_die_info::read): Prefer the linkage name
for Ada.
gdb/testsuite/ChangeLog
2019-06-28 Tom Tromey <tromey@adacore.com>
* gdb.dwarf2/ada-linkage-name.c: New file.
* gdb.dwarf2/ada-linkage-name.exp: New file.
After seeing Simon's patch to change arm_per_objfile to use new and
delete, I realized it is now simple to change arm_objfile_data_key to
use the type-safe registry.
gdb/ChangeLog
2019-06-27 Tom Tromey <tromey@adacore.com>
* arm-tdep.c (arm_objfile_data_key): Move lower. Change type to
objfile_key.
(arm_find_mapping_symbol, arm_record_special_symbol)
(_initialize_arm_tdep): Update.
(arm_objfile_data_free): Remove.