When running gdb.dwarf2/nonvar-access.exp with board readnow, we have:
...
FAIL: gdb.dwarf2/nonvar-access.exp: print/x def_implicit_s
...
and 12 more similar failures.
I've tracked this down to the range of main being hardcoded to
[_main, _main+0x10000) in the dwarf assembly:
...
DW_TAG_subprogram {
{name main}
{DW_AT_external 1 flag}
{low_pc [gdb_target_symbol main] DW_FORM_addr}
{high_pc [gdb_target_symbol main]+0x10000 DW_FORM_addr}
} {
...
which overlaps with the .debug_info for the elf-init.c CU (containing
__libc_csu_init and __libc_csu_fini).
Fix this by using function_range to find the actual range of main.
Tested on x86_64-linux.
gdb/testsuite/ChangeLog:
2019-06-11 Tom de Vries <tdevries@suse.de>
PR testsuite/24521
* gdb.dwarf2/nonvar-access.exp: Fix main high_pc.
When extracting an array slice we should give up if the array is
not-allocated or not-associated. For Fortran, at least in gfortran
compiled code, the upper and lower bounds are undefined if the array
is not allocated or not associated, in which case performing checks
against these bounds will result in undefined behaviour.
Better then to throw an error if we try to slice such an array. This
changes the error message that the user will receive in these
cases (if they got an error message before). Previously they may have
gotten "slice out of range" now they'll get "array not allocated" or
"array not associated".
gdb/ChangeLog:
* valops.c (value_slice): Check for not allocated or not
associated values.
gdb/testsuite/ChangeLog:
* gdb.fortran/vla-sizeof.exp: Update expected results.
When compiling gdb with '-lasan -fsanitizer=address' and running tests with:
- export ASAN_OPTIONS="detect_leaks=0:alloc_dealloc_mismatch=0",
- target board cc-with-gdb-index,
- the "[gdb/testsuite] Fix gdb.base/break-probes.exp with native-gdbserver"
commit reverted to avoid running into PR24617,
we get with gdb.arch/amd64-init-x87-values.exp:
...
==31229==ERROR: AddressSanitizer: heap-buffer-overflow on address \
0x62500098c93c at pc 0x000000bcc748 bp 0x7ffe39487660 sp 0x7ffe39487658
READ of size 1 at 0x62500098c93c thread T0
#0 0xbcc747 in cp_find_first_component_aux src/gdb/cp-support.c:999
#1 0xbcc6e9 in cp_find_first_component(char const*) \
src/gdb/cp-support.c:977
#2 0xcc2cf3 in mapped_index_base::build_name_components() \
src/gdb/dwarf2read.c:4499
#3 0xcc3322 in dw2_expand_symtabs_matching_symbol src/gdb/dwarf2read.c:4552
#4 0xcc817f in dw2_expand_symtabs_matching src/gdb/dwarf2read.c:5228
#5 0xfe8f48 in iterate_over_all_matching_symtabs src/gdb/linespec.c:1147
#6 0x1003506 in add_matching_symbols_to_info src/gdb/linespec.c:4413
#7 0xffe21b in find_function_symbols src/gdb/linespec.c:3886
#8 0xffe4a2 in find_linespec_symbols src/gdb/linespec.c:3914
#9 0xfee3ad in linespec_parse_basic src/gdb/linespec.c:1865
#10 0xff5128 in parse_linespec src/gdb/linespec.c:2655
#11 0xff8872 in event_location_to_sals src/gdb/linespec.c:3150
#12 0xff90a8 in decode_line_full(event_location const*, int, \
program_space*, symtab*, int, linespec_result*, \
char const*, char const*) src/gdb/linespec.c:3230
#13 0x9ce449 in parse_breakpoint_sals src/gdb/breakpoint.c:9057
#14 0x9ea022 in create_sals_from_location_default src/gdb/breakpoint.c:13708
#15 0x9e2c1f in bkpt_create_sals_from_location src/gdb/breakpoint.c:12514
#16 0x9cff06 in create_breakpoint(gdbarch*, event_location const*, \
char const*, int, char const*, int, int, bptype, int, \
auto_boolean, breakpoint_ops const*, int, int, int, \
unsigned int) src/gdb/breakpoint.c:9238
#17 0x9d114a in break_command_1 src/gdb/breakpoint.c:9402
#18 0x9d1b60 in break_command(char const*, int) src/gdb/breakpoint.c:9473
#19 0xac96aa in do_const_cfunc src/gdb/cli/cli-decode.c:106
#20 0xad0e5a in cmd_func(cmd_list_element*, char const*, int) \
src/gdb/cli/cli-decode.c:1892
#21 0x15226f6 in execute_command(char const*, int) src/gdb/top.c:630
#22 0xddde37 in command_handler(char const*) src/gdb/event-top.c:586
#23 0xdde7c1 in command_line_handler(std::unique_ptr<char, \
gdb::xfree_deleter<char> >&&) src/gdb/event-top.c:773
#24 0xddc9e8 in gdb_rl_callback_handler src/gdb/event-top.c:217
#25 0x16f2198 in rl_callback_read_char src/readline/callback.c:220
#26 0xddc5a1 in gdb_rl_callback_read_char_wrapper_noexcept \
src/gdb/event-top.c:175
#27 0xddc773 in gdb_rl_callback_read_char_wrapper src/gdb/event-top.c:192
#28 0xddd9f5 in stdin_event_handler(int, void*) src/gdb/event-top.c:514
#29 0xdd7d8f in handle_file_event src/gdb/event-loop.c:731
#30 0xdd8607 in gdb_wait_for_event src/gdb/event-loop.c:857
#31 0xdd629c in gdb_do_one_event() src/gdb/event-loop.c:321
#32 0xdd6344 in start_event_loop() src/gdb/event-loop.c:370
#33 0x10a7715 in captured_command_loop src/gdb/main.c:331
#34 0x10aa548 in captured_main src/gdb/main.c:1173
#35 0x10aa5d8 in gdb_main(captured_main_args*) src/gdb/main.c:1188
#36 0x87bd35 in main src/gdb/gdb.c:32
#37 0x7f16e1434f89 in __libc_start_main (/lib64/libc.so.6+0x20f89)
#38 0x87bb49 in _start (build/gdb/gdb+0x87bb49)
0x62500098c93c is located 0 bytes to the right of 8252-byte region \
[0x62500098a900,0x62500098c93c)
allocated by thread T0 here:
#0 0x7f16e359a600 in malloc (/usr/lib64/libasan.so.5+0xeb600)
#1 0x1742ddf in bfd_malloc src/bfd/libbfd.c:275
#2 0x1738824 in bfd_get_full_section_contents src/bfd/compress.c:253
#3 0xe30044 in gdb_bfd_map_section(bfd_section*, unsigned long*) \
src/gdb/gdb_bfd.c:704
#4 0xcb56bf in dwarf2_read_section(objfile*, dwarf2_section_info*) \
src/gdb/dwarf2read.c:2539
#5 0xd5bcd0 in get_gdb_index_contents_from_section<dwarf2_per_objfile> \
src/gdb/dwarf2read.c:6217
#6 0xd7fc7d in gdb::function_view<gdb::array_view<unsigned char const> \
(...) const src/gdb/common/function-view.h:284
#7 0xd7fddd in gdb::function_view<gdb::array_view<unsigned char const> \
(...) src/gdb/common/function-view.h:278
#8 0xd730cf in gdb::function_view<gdb::array_view<unsigned char const> \
(...) const src/gdb/common/function-view.h:247
#9 0xcbc7ee in dwarf2_read_gdb_index src/gdb/dwarf2read.c:3582
#10 0xcce731 in dwarf2_initialize_objfile(objfile*, dw_index_kind*) \
src/gdb/dwarf2read.c:6297
#11 0xdb88c4 in elf_symfile_read src/gdb/elfread.c:1256
#12 0x141262a in read_symbols src/gdb/symfile.c:798
#13 0x14140a7 in syms_from_objfile_1 src/gdb/symfile.c:1000
#14 0x1414393 in syms_from_objfile src/gdb/symfile.c:1017
#15 0x1414fb7 in symbol_file_add_with_addrs src/gdb/symfile.c:1124
#16 0x14159b7 in symbol_file_add_from_bfd(bfd*, char const*, \
enum_flags<symfile_add_flag>, std::vector<other_sections, \
std::allocator<other_sections> >*, \
enum_flags<objfile_flag>, objfile*) src/gdb/symfile.c:1203
#17 0x1415b6c in symbol_file_add(char const*,
enum_flags<symfile_add_flag>, std::vector<other_sections, \
std::allocator<other_sections> >*, \
enum_flags<objfile_flag>) src/gdb/symfile.c:1216
#18 0x1415f2f in symbol_file_add_main_1 src/gdb/symfile.c:1240
#19 0x1418599 in symbol_file_command(char const*, int) \
src/gdb/symfile.c:1675
#20 0xde2fa6 in file_command src/gdb/exec.c:433
#21 0xac96aa in do_const_cfunc src/gdb/cli/cli-decode.c:106
#22 0xad0e5a in cmd_func(cmd_list_element*, char const*, int) \
src/gdb/cli/cli-decode.c:1892
#23 0x15226f6 in execute_command(char const*, int) src/gdb/top.c:630
#24 0xddde37 in command_handler(char const*) src/gdb/event-top.c:586
#25 0xdde7c1 in command_line_handler(std::unique_ptr<char, \
gdb::xfree_deleter<char> >&&) src/gdb/event-top.c:773
#26 0xddc9e8 in gdb_rl_callback_handler src/gdb/event-top.c:217
#27 0x16f2198 in rl_callback_read_char src/readline/callback.c:220
#28 0xddc5a1 in gdb_rl_callback_read_char_wrapper_noexcept \
src/gdb/event-top.c:175
#29 0xddc773 in gdb_rl_callback_read_char_wrapper src/gdb/event-top.c:192
SUMMARY: AddressSanitizer: heap-buffer-overflow src/gdb/cp-support.c:999 in \
cp_find_first_component_aux
Shadow bytes around the buggy address:
0x0c4a801298d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c4a801298e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c4a801298f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c4a80129900: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c4a80129910: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c4a80129920: 00 00 00 00 00 00 00[04]fa fa fa fa fa fa fa fa
0x0c4a80129930: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c4a80129940: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c4a80129950: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c4a80129960: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c4a80129970: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==31229==ABORTING
...
The problem happens as follows.
The executable amd64-init-x87-values gets an index (due to target board
cc-with-gdb-index), which looks as follows:
...
Hex dump of section '.gdb_index':
0x00000000 08000000 18000000 28000000 28000000 ........(...(...
0x00000010 3c000000 3c200000 00000000 00000000 <...< ..........
0x00000020 2e000000 00000000 d4004000 00000000 ..........@.....
0x00000030 db004000 00000000 00000000 00000000 ..@.............
0x00000040 00000000 00000000 00000000 00000000 ................
0x00000050 00000000 00000000 00000000 00000000 ................
... more zeroes ...
0x00002010 00000000 00000000 00000000 00000000 ................
0x00002020 00000000 00000000 00000000 00000000 ................
0x00002030 00000000 00000000 00000000 ............
...
The structure of this index is:
...
header : [0x0, 0x18) : size 0x18
culist : [0x18 ,0x28) : size 0x10
typesculist : [0x28, 0x28) : size 0x0
adress area : [0x28, 0x3c) : size 0x14
symbol table : [0x3c, 0x203c) : size 0x2000
constant pool: [0x203c, 0x203c): size 0x0
EOF : 0x203c
...
Note that the symbol table consists entirely of empty slots (where an empty
slot is a pair of 32-bit zeroes), and that the constant pool is empty.
The problem happens here in mapped_index_base::build_name_components:
...
auto count = this->symbol_name_count ();
for (offset_type idx = 0; idx < count; idx++)
{
if (this->symbol_name_slot_invalid (idx))
continue;
const char *name = this->symbol_name_at (idx);
...
when accessing the slot at idx == 0 in the symbol table,
symbol_name_slot_invalid returns false so we calculate name, which is
calculated using 'constant_pool + symbol_table[idx].name', which means we get
name == constant_pool. And given that the constant pool is empty, name now
points past the memory allocated for the index, and when we access name[0] for
the first time in cp_find_first_component_aux, we run into the
heap-buffer-overflow.
Fix this by fixing the definition of symbol_name_slot_invalid:
...
- return bucket.name == 0 && bucket.vec;
+ return bucket.name == 0 && bucket.vec == 0;
...
Tested on x86_64-linux.
gdb/ChangeLog:
2019-06-10 Tom de Vries <tdevries@suse.de>
PR gdb/24618
* dwarf2read.c (struct mapped_index::symbol_name_slot_invalid): Make
sure an empty slot (defined by a 32-bit zero pair) is recognized as
invalid.
When compiling gdb with '-lasan -fsanitizer=address' and running tests with
'export ASAN_OPTIONS="detect_leaks=0:alloc_dealloc_mismatch=0"', I run into:
...
ERROR: GDB process no longer exists
UNRESOLVED: gdb.linespec/cpls-abi-tag.exp: \
test_abi_tag: completion: at tag: tab complete "b test_abi_tag_function[abi:"
...
In more detail:
...
==3637==ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address \
0x7fff5952bbdd at pc 0x000000fe5c57 bp 0x7fff5952af30 sp 0x7fff5952af28
READ of size 1 at 0x7fff5952bbdd thread T0
#0 0xfe5c56 in linespec_lexer_lex_string src/gdb/linespec.c:727
#1 0xfe7473 in linespec_lexer_lex_one src/gdb/linespec.c:946
#2 0xfe799d in linespec_lexer_consume_token src/gdb/linespec.c:982
#3 0xff446d in parse_linespec src/gdb/linespec.c:2564
#4 0xff78be in linespec_complete(completion_tracker&, char const*, \
symbol_name_match_type) src/gdb/linespec.c:2961
#5 0xb9299c in complete_address_and_linespec_locations \
src/gdb/completer.c:573
#6 0xb93e90 in location_completer(cmd_list_element*, completion_tracker&, \
char const*, char const*) src/gdb/completer.c:919
#7 0xb940c5 in location_completer_handle_brkchars src/gdb/completer.c:956
#8 0xb957ec in complete_line_internal_normal_command \
src/gdb/completer.c:1208
#9 0xb96507 in complete_line_internal_1 src/gdb/completer.c:1430
#10 0xb965c2 in complete_line_internal src/gdb/completer.c:1449
#11 0xb98630 in gdb_completion_word_break_characters_throw \
src/gdb/completer.c:1862
#12 0xb98838 in gdb_completion_word_break_characters() \
src/gdb/completer.c:1897
#13 0x16c6362 in _rl_find_completion_word src/readline/complete.c:943
#14 0x16ca8d0 in rl_complete_internal src/readline/complete.c:1843
#15 0x16c460c in rl_complete src/readline/complete.c:408
#16 0x16b3368 in _rl_dispatch_subseq src/readline/readline.c:774
#17 0x16b3092 in _rl_dispatch src/readline/readline.c:724
#18 0x16b2939 in readline_internal_char src/readline/readline.c:552
#19 0x16f1fb0 in rl_callback_read_char src/readline/callback.c:201
#20 0xddc5a1 in gdb_rl_callback_read_char_wrapper_noexcept \
src/gdb/event-top.c:175
#21 0xddc773 in gdb_rl_callback_read_char_wrapper src/gdb/event-top.c:192
#22 0xddd9f5 in stdin_event_handler(int, void*) src/gdb/event-top.c:514
#23 0xdd7d8f in handle_file_event src/gdb/event-loop.c:731
#24 0xdd8607 in gdb_wait_for_event src/gdb/event-loop.c:857
#25 0xdd629c in gdb_do_one_event() src/gdb/event-loop.c:321
#26 0xdd6344 in start_event_loop() src/gdb/event-loop.c:370
#27 0x10a7715 in captured_command_loop src/gdb/main.c:331
#28 0x10aa548 in captured_main src/gdb/main.c:1173
#29 0x10aa5d8 in gdb_main(captured_main_args*) src/gdb/main.c:1188
#30 0x87bd35 in main src/gdb/gdb.c:32
#31 0x7fb0364c6f89 in __libc_start_main (/lib64/libc.so.6+0x20f89)
#32 0x87bb49 in _start (build/gdb/gdb+0x87bb49)
Address 0x7fff5952bbdd is located in stack of thread T0 at offset 557 in frame
#0 0xb93702 in location_completer(cmd_list_element*, completion_tracker&, \
char const*, char const*) src/gdb/completer.c:831
This frame has 4 object(s):
[32, 40) 'copy'
[96, 104) 'location'
[160, 168) 'text'
[224, 256) 'completion_info' <== Memory access at offset 557 overflows \
this variable
HINT: this may be a false positive if your program uses some custom stack \
unwind mechanism or swapcontext
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: dynamic-stack-buffer-overflow \
src/gdb/linespec.c:727 in linespec_lexer_lex_string
Shadow bytes around the buggy address:
0x10006b29d720: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10006b29d730: 00 00 00 00 00 00 f1 f1 f1 f1 00 f2 f2 f2 f2 f2
0x10006b29d740: f2 f2 00 f2 f2 f2 f2 f2 f2 f2 00 f2 f2 f2 f2 f2
0x10006b29d750: f2 f2 00 00 00 00 f3 f3 f3 f3 00 00 00 00 00 00
0x10006b29d760: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x10006b29d770: 00 00 00 00 ca ca ca ca 00 00 00[05]cb cb cb cb
0x10006b29d780: 00 00 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1
0x10006b29d790: 00 f2 f2 f2 f2 f2 f2 f2 00 f2 f2 f2 f3 f3 f3 f3
0x10006b29d7a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10006b29d7b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10006b29d7c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==3637==ABORTING
...
The problem happens in linespec_lexer_lex_string when lexing
"b test_abi_tag_function[abi:\0" (using a notation where we make the implicit
terminating \0 explicit).
We arrrive here with (PARSER_STREAM (parser)) == ":\0":
...
/* Do not tokenize ABI tags such as "[abi:cxx11]". */
else if (PARSER_STREAM (parser) - start > 4
&& startswith (PARSER_STREAM (parser) - 4, "[abi"))
++(PARSER_STREAM (parser));
...
and consume ':', after which we end up here and consume '\0':
...
/* Advance the stream. */
++(PARSER_STREAM (parser));
...
after which (PARSER_STREAM (parser)) points past the end of the string.
Fix this by removing the first "++(PARSER_STREAM (parser))", and add an assert
to the second one to detect moving past the end-of-string.
Build and tested on x86_64-linux.
gdb/ChangeLog:
2019-06-10 Tom de Vries <tdevries@suse.de>
PR gdb/24611
* linespec.c (linespec_lexer_lex_string): Remove incorrect
"++(PARSER_STREAM (parser))" for "[abi"-prefixed colon. Add assert.
The commit "[gdb/symtab] Fix language of duplicate static minimal symbol"
introduces a performance regression, when loading a cc1 executable build with
-O0 -g and gcc 7.4.0. The performance regression, measured in 'real' time is
about 175%.
The slower execution comes from the fact that the fix in symbol_set_names
makes the call to symbol_find_demangled_name unconditional.
Fix this by reverting the commit, and redoing the fix as follows.
Recapturing the original problem, the first time symbol_set_names is called
with gsymbol.language == lang_auto and linkage_name == "_ZL3foov", the name is
not present in the per_bfd->demangled_names_hash hash table, so
symbol_find_demangled_name is called to demangle the name, after which the
mangled/demangled pair is added to the hashtable. The call to
symbol_find_demangled_name also sets gsymbol.language to lang_cplus.
The second time symbol_set_names is called with gsymbol.language == lang_auto
and linkage_name == "_ZL3foov", the name is present in the hash table, so the
demangled name from the hash table is used. However, the language of the
symbol remains lang_auto.
Fix this by adding a field language in struct demangled_name_entry, and using
the field in symbol_set_names to set the language of gsymbol, if necessary.
Tested on x86_64-linux.
gdb/ChangeLog:
2019-06-10 Tom de Vries <tdevries@suse.de>
PR symtab/24545
* symtab.c (struct demangled_name_entry): Add language field.
(symbol_set_names): Revert "[gdb/symtab] Fix language of duplicate
static minimal symbol". Set and use language field.
I noticed that the "catch assert" help text erroneously claimed to
accept an argument, and while fixing this I went ahead and added
"Usage" text and made other minor updates to the commands in
ada-lang.c.
Tested on x86-64 Fedora 29.
gdb/ChangeLog
2019-06-10 Tom Tromey <tromey@adacore.com>
* ada-lang.c (_initialize_ada_language): Update help text.
ARI pointed out that a recent patch introduced a call to "warning"
with a string that ended in a newline:
https://sourceware.org/ml/gdb-patches/2019-06/msg00000.html
This is generally forbidden, I believe, because warning adds its own
newline.
This patch removes all of the trailing newlines I was able to find. I
searched for 'warning (.*\\n"' and then fixed the ones where the
newline appeared at the end of the string (some had internal
newlines).
Tested on x86-64 Fedora 29.
gdb/ChangeLog
2019-06-10 Tom Tromey <tromey@adacore.com>
* m32c-tdep.c (m32c_m16c_address_to_pointer): Don't end warning
with a newline.
* guile/guile.c (handle_boot_error): Don't end warning with a
newline.
* cli/cli-cmds.c (exit_status_set_internal_vars): Don't end
warning with a newline.
* s12z-tdep.c (s12z_skip_prologue): Don't end warning with a
newline.
(s12z_frame_cache): Likewise.
* dwarf-index-cache.c (index_cache::store): Don't end warning with
a newline.
* solib-svr4.c (disable_probes_interface): Don't end warning with
a newline.
* nat/fork-inferior.c (fork_inferior): Don't end warning with a
newline.
* python/python.c (do_finish_initialization): Don't end warning
with a newline.
gdb/gdbserver/ChangeLog
2019-06-10 Tom Tromey <tromey@adacore.com>
* remote-utils.c (look_up_one_symbol, relocate_instruction): Don't
end warning with a newline.
* linux-s390-low.c (s390_get_wordsize): Don't end warning with a
newline.
* thread-db.c (attach_thread): Don't end warning with a newline.
(thread_db_notice_clone): Likewise.
* tracepoint.c (gdb_agent_helper_thread): Don't end warning with a
newline.
* linux-x86-low.c (x86_get_min_fast_tracepoint_insn_len): Don't
end warning with a newline.
PR 24650
* elf.c (elfcore_make_auxv_note_section): New function.
(elfcore_grok_note): Use it.
(elfcore_grok_freebsd_note): Likewise.
(elfcore_grok_openbsd_note): Likewise.
(elfcore_grok_netbsd_note): Likewise. Plus add support for
NT_NETBSDCORE_AUXV notes.
A few spots in py-breakpoint.c acquire the GIL manually. However,
because these spots generate events, and because events are expected
to be arbitrary gdb-flavored Python code, it's important to use
gdbpy_enter instead, in order to ensure that the other gdb-related
Python globals are set correctly.
This patch makes this change. Tested on x86-64 Fedora 29.
gdb/ChangeLog
2019-06-10 Tom Tromey <tom@tromey.com>
* python/py-breakpoint.c (gdbpy_breakpoint_created)
(gdbpy_breakpoint_deleted, gdbpy_breakpoint_modified): Use
gdbpy_enter.
I noticed that elfread.c always allocates a dbx_symfile_info, even
though this is only ever needed in the unusual case of reading stabs
in ELF.
This patch moves the allocation into dbxread.c, and applies the same
treatment to similar code in coffread.c.
Regression tested on x86-64 Fedora 29.
gdb/ChangeLog
2019-06-10 Tom Tromey <tromey@adacore.com>
* elfread.c (elf_read_minimal_symbols): Don't set the dbx objfile
data.
(elf_new_init): Don't call stabsread_new_init.
* dbxread.c (coffstab_build_psymtabs): Set dbx objfile data.
(elfstab_build_psymtabs): Likewise. Call stabsread_new_init.
* coffread.c (coff_symfile_init): Don't set the dbx objfile data.
DW_AT_main_subprogram is supported in normal mode in read_partial_die, but not
in -readnow mode.
Fix this by adding support for DW_AT_main_subprogram in read_func_scope.
Tested on x86_64-linux with native and RFC target board readnow (
https://sourceware.org/ml/gdb-patches/2019-05/msg00073.html ).
gdb/ChangeLog:
2019-06-10 Tom de Vries <tdevries@suse.de>
PR symtab/16264
PR symtab/24517
* dwarf2read.c (read_func_scope): Handle DW_AT_main_subprogram.
Mention in the description of the `-rpath' LD option the restrictions
the option has with respect to searching link-time dependencies of
shared objects referred in the link. Previously these restrictions were
only documented along with the `-rpath-link' option, which may not be
the place one would consider when looking for the semantics of `-rpath'.
Copy the relevant part of the `-rpath-link' option description then,
splitting the now overlong paragraph into three, for legibility.
ld/
* ld.texi (Options): Also document `-rpath' option restrictions
in the description of the option itself.
Not all platforms have it. Use libiberty xstrndup() instead.
(The include of libiberty.h happens in an unusual place due to the
requirements of synchronization of most source files between this
project and another that does not use libiberty. It serves to pull
libiberty.h in for all source files in libctf/, which does the trick.)
Tested on x86_64-pc-linux-gnu, x86_64-unknown-freebsd12.0,
sparc-sun-solaris2.11, i686-pc-cygwin, i686-w64-mingw32.
libctf/
* ctf-decls.h: Include <libiberty.h>.
* ctf-lookup.c (ctf_lookup_by_name): Call xstrndup(), not strndup().
Unsigned long will always be adequate (the only cases involving an
ssize_t are cases in which no error can be generated, or in which
negative output would require a seriously corrupted file: the latter has
been rewritten on a branch in any case).
Tested on x86_64-pc-linux-gnu, x86_64-unknown-freebsd12.0,
sparc-sun-solaris2.11, i686-pc-cygwin, i686-w64-mingw32.
libctf/
* ctf-dump.c (ctf_dump_format_type): Cast size_t's used in printf()s.
(ctf_dump_objts): Likewise.
(ctf_dump_funcs): Likewise.
(ctf_dump_member): Likewise.
(ctf_dump_str): Likewise.
Tested on x86_64-pc-linux-gnu, x86_64-unknown-freebsd12.0,
sparc-sun-solaris2.11, i686-pc-cygwin, i686-w64-mingw32.
libctf/
* ctf-archive.c (arc_mmap_header): Mark fd as potentially unused.
* ctf-subr.c (ctf_data_protect): Mark both args as potentially unused.
When source file path is relative to the build directory (which
is considered a good practice and is enforced in certain buildsystems,
such as meson), gdb only applies substitute-path to the build directory
path. Then gdb appends the source file path to the rewritten build
directory path, and tries to access that.
This fails if either two of the following conditions are true:
a) The user didn't specify substitute-path for the build directory.
This is highly likely, since path substitution for build directories
is not documented anywhere, and since gdb does not tell[0] the user
the path to the build directory, just the source file path.
b) The source file path changed.
This can also easily happen, since a source path that is relative
to the build directory can include any number of directory names
that are not part of the program source tree (starting with the
name of the root directory of the source tree). Gdb will not apply
substitute-path to that relative path, thus there is no way for
the user to tell gdb about these changes.
This commit changes the code to apply substitute-path to all filenames,
both relative and absolute. This way it is possible to do things like:
set substitute-path ../foobar-1.0 /src/my/foobar-1.0
which is completely in line with the user expectations.
This might break unusual cases where build directory path is also
relative (is that even possible?) and happens to match the path
to the source directory (i.e. happens to match a substitution rule).
[0]: There's a "maintenance info symtabs" command that does show the names
of the build directories, but normal users are not required to
know or use that.
gdb/ChangeLog
2019-06-06 Руслан Ижбулатов <lrn1986@gmail.com>
* source.c (find_and_open_source): Also rewrite relative file
names.
Currently "maint time" will print the amount of time a command took.
Sometimes, though, it's useful to have a timestamp as well -- for
example if one is correlating a gdb log with some other log.
This patch adds a timestamp to the start and end of each command when
this setting is in effect.
This also removes a "//" comment and changes scoped_command_stats to
use DISABLE_COPY_AND_ASSIGN; two minor things I noticed while working
on the patch.
Tested on x86-64 Fedora 29.
gdb/ChangeLog
2019-06-06 Tom Tromey <tromey@adacore.com>
* maint.h (class scoped_command_stats): Use
DISABLE_COPY_AND_ASSIGN.
<print_time>: New method.
* maint.c (scoped_command_stats, ~scoped_command_stats): Call
print_time.
(scoped_command_stats::print_time): New method.
gdb/testsuite/ChangeLog
2019-06-06 Tom Tromey <tromey@adacore.com>
* gdb.base/maint.exp: Expect command started/finished output.
If the new GNU property section was being created by the linker
(this will happen only if none of the inputs have any GNU property
section but the command line to the linker forces a bti with
--force-bti), the alignment of the section and hence the program
header of PT_GNU_PROPERTY type was not being set correctly. This
patch fixes this issue.
bfd/ChangeLog:
2019-06-06 Sudakshina Das <sudi.das@arm.com>
* elfxx-aarch64.c (_bfd_aarch64_elf_link_setup_gnu_properties): Set
alignment of the new gnu property section.
ld/ChangeLog:
2019-06-06 Sudakshina Das <sudi.das@arm.com>
* testsuite/ld-aarch64/aarch64-elf.exp: Add new tests.
* testsuite/ld-aarch64/property-bti-pac4-a.d: New test.
* testsuite/ld-aarch64/property-bti-pac4-b.d: New test.
* testsuite/ld-aarch64/property-bti-pac4.s: New test.
Too many platforms don't support it, and we can always safely use %lu or
%li anyway, because the only uses are in debugging output.
libctf/
* ctf-archive.c (ctf_arc_write): Eschew %zi format specifier.
(ctf_arc_open_by_offset): Likewise.
* ctf-create.c (ctf_add_type): Likewise.
Remove the use of 'I' within some comments in a recently added test.
gdb/testsuite/ChangeLog:
* gdb.arch/riscv-unwind-long-insn-6.s: Remove use of 'I' in
comment.
* gdb.arch/riscv-unwind-long-insn-8.s: Likewise.
If the RISC-V prologue scanner finds a 6 or 8 byte instruction we
currently throw an internal error, which is not great for the user.
A mechanism already exists in the prologue scanner to leave
instructions marked as unknown so that we can stop the prologue scan
without raising an error, this is used for all 2 and 4 byte
instructions that are not part of the small set the prologue scanner
actually understands.
This commit changes GDB so that all 6 and 8 byte instructions are
marked as unknown, rather than causing an error.
gdb/ChangeLog:
* riscv-tdep.c (riscv_insn::decode): Gracefully ignore
instructions of lengths 6 or 8 bytes.
gdb/testsuite/ChangeLog:
* gdb.arch/riscv-unwind-long-insn-6.s: New file.
* gdb.arch/riscv-unwind-long-insn-8.s: New file.
* gdb.arch/riscv-unwind-long-insn.c: New file.
* gdb.arch/riscv-unwind-long-insn.exp: New file.
Adds an utility function to make it shorter to write the common case
of wrapping an xstrdup with a unique_xmalloc_ptr, and uses it
throughout.
Note: I tried to put this in common/common-utils.h near skip_spaces,
etc. but that is included in common/common-defs.h before
common/gdb_unique_ptr.h is included, so it would fail to compile
because gdb::unique_xmalloc_ptr isn't defined at that point yet. I
tried moving the gdb_unique_ptr.h inclusion before common-utils.h, but
that doesn't work because gdb_unique_ptr.h depends on common-utils.h
for xfree.
gdb/ChangeLog:
2019-06-04 Pedro Alves <palves@redhat.com>
* common/gdb_unique_ptr.h (make_unique_xstrdup): New.
* ada-lang.c (catch_ada_completer): Use make_unique_xstrdup.
* breakpoint.c (condition_completer): Likewise.
* cli/cli-dump.c (scan_expression): Likewise.
* common/filestuff.c (mkdir_recursive): Likewise.
* common/gdb_tilde_expand.c (gdb_tilde_expand_up)
* common/pathstuff.c (gdb_realpath, gdb_realpath_keepfile)
(gdb_abspath): Likewise.
* compile/compile-cplus-types.c
(compile_cplus_instance::decl_name): Likewise.
* completer.c (complete_explicit_location):
(signal_completer, reg_or_group_completer_1): Likewise.
* cp-support.c (cp_remove_params_if_any): Likewise.
* fbsd-tdep.c (fbsd_core_vnode_path): Likewise.
* guile/scm-safe-call.c (gdbscm_safe_eval_string): Likewise.
* infcmd.c (strip_bg_char): Likewise.
* linespec.c (copy_token_string): Likewise.
* mi/mi-main.c (output_cores): Likewise.
* psymtab.c (psymtab_search_name):
* symfile.c (test_set_ext_lang_command): Likewise.
* target.c (target_fileio_read_stralloc): Likewise.
* tui/tui-regs.c (tui_reggroup_completer): Likewise.
* value.c (complete_internalvar): Likewise.
gdb/gdbserver/ChangeLog:
2019-06-04 Pedro Alves <palves@redhat.com>
* server.c (captured_main): Use make_unique_xstrdup.
On x86-64 Fedora 29, I tried to build a mingw-hosted gdb that targets
ppc-linux. You can do this with:
../binutils-gdb/configure --host=i686-w64-mingw32 --target=ppc-linux \
--disable-{binutils,gas,gold,gprof,ld}
The build failed with these errors in libctf:
In file included from ../../binutils-gdb/libctf/ctf-create.c:20:
../../binutils-gdb/libctf/ctf-create.c: In function 'ctf_add_encoded':
../../binutils-gdb/libctf/ctf-create.c:803:59: error: 'NBBY' undeclared (first use in this function)
dtd->dtd_data.ctt_size = clp2 (P2ROUNDUP (ep->cte_bits, NBBY) / NBBY);
^~~~
../../binutils-gdb/libctf/ctf-impl.h:254:42: note: in definition of macro 'P2ROUNDUP'
#define P2ROUNDUP(x, align) (-(-(x) & -(align)))
^~~~~
../../binutils-gdb/libctf/ctf-create.c:803:59: note: each undeclared identifier is reported only once for each function it appears in
dtd->dtd_data.ctt_size = clp2 (P2ROUNDUP (ep->cte_bits, NBBY) / NBBY);
^~~~
../../binutils-gdb/libctf/ctf-impl.h:254:42: note: in definition of macro 'P2ROUNDUP'
#define P2ROUNDUP(x, align) (-(-(x) & -(align)))
^~~~~
../../binutils-gdb/libctf/ctf-create.c: In function 'ctf_add_slice':
../../binutils-gdb/libctf/ctf-create.c:862:59: error: 'NBBY' undeclared (first use in this function)
dtd->dtd_data.ctt_size = clp2 (P2ROUNDUP (ep->cte_bits, NBBY) / NBBY);
^~~~
../../binutils-gdb/libctf/ctf-impl.h:254:42: note: in definition of macro 'P2ROUNDUP'
#define P2ROUNDUP(x, align) (-(-(x) & -(align)))
^~~~~
../../binutils-gdb/libctf/ctf-create.c: In function 'ctf_add_member_offset':
../../binutils-gdb/libctf/ctf-create.c:1341:21: error: 'NBBY' undeclared (first use in this function)
off += lsize * NBBY;
^~~~
../../binutils-gdb/libctf/ctf-create.c: In function 'ctf_add_type':
../../binutils-gdb/libctf/ctf-create.c:1822:16: warning: unknown conversion type character 'z' in format [-Wformat=]
ctf_dprintf ("Conflict for type %s against ID %lx: "
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../binutils-gdb/libctf/ctf-create.c:1823:35: note: format string is defined here
"union size differs, old %zi, new %zi\n",
^
../../binutils-gdb/libctf/ctf-create.c:1822:16: warning: unknown conversion type character 'z' in format [-Wformat=]
ctf_dprintf ("Conflict for type %s against ID %lx: "
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../binutils-gdb/libctf/ctf-create.c:1823:44: note: format string is defined here
"union size differs, old %zi, new %zi\n",
^
../../binutils-gdb/libctf/ctf-create.c:1822:16: warning: too many arguments for format [-Wformat-extra-args]
ctf_dprintf ("Conflict for type %s against ID %lx: "
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This patch fixes the actual errors in here. I did not try to fix the
printf warnings, though I think someone ought to.
Ok?
libctf/ChangeLog
2019-06-04 Tom Tromey <tromey@adacore.com>
* ctf-create.c (ctf_add_encoded, ctf_add_slice)
(ctf_add_member_offset): Use CHAR_BIT, not NBBY.
If VEX.vvvv and EVEX.vvvv are reserved, they must be all 1s, which are
all 0s in inverted form. Add check for unused VEX.vvvv and EVEX.vvvv
when disassembling VEX and EVEX instructions.
gas/
PR binutils/24626
* testsuite/gas/i386/disassem.s: Add tests for reserved VEX.vvvv
and EVEX.vvvv.
* testsuite/gas/i386/x86-64-disassem.s: Likewise.
* testsuite/gas/i386/disassem.d: Updated.
* testsuite/gas/i386/x86-64-disassem.d: Likewise.
opcodes/
PR binutils/24626
* i386-dis.c (print_insn): Check for unused VEX.vvvv and
EVEX.vvvv when disassembling VEX and EVEX instructions.
(OP_VEX): Set vex.register_specifier to 0 after readding
vex.register_specifier.
(OP_Vex_2src_1): Likewise.
(OP_Vex_2src_2): Likewise.
(OP_LWP_E): Likewise.
(OP_EX_Vex): Don't check vex.register_specifier.
(OP_XMM_Vex): Likewise.
(Not tested on any such platforms, since I don't have access to any at
the moment. Testing encouraged.)
libctf/
* configure.ac: Check for O_CLOEXEC.
* ctf-decls.h (O_CLOEXEC): Define (to 0), if need be.
* config.h.in: Regenerate.
We cannot just look for any declaration of qsort_r, because some
operating systems have a qsort_r that has a different prototype
but which still has a pair of pointers in the right places (the last two
args are interchanged): so use AC_LINK_IFELSE to check for both
known variants of qsort_r(), and swap their args into a consistent order
in a suitable inline function. (The code for this is taken almost
unchanged from gnulib.)
(Now we are not using AC_LIBOBJ any more, we can use a better name for
the qsort_r replacement as well.)
libctf/
* qsort_r.c: Rename to...
* ctf-qsort_r.c: ... this.
(_quicksort): Define to ctf_qsort_r.
* ctf-decls.h (qsort_r): Remove.
(ctf_qsort_r): Add.
(struct ctf_qsort_arg): New, transport the real ARG and COMPAR.
(ctf_qsort_compar_thunk): Rearrange the arguments to COMPAR.
* Makefile.am (libctf_a_LIBADD): Remove.
(libctf_a_SOURCES): New, add ctf-qsort_r.c.
* ctf-archive.c (ctf_arc_write): Call ctf_qsort_r, not qsort_r.
* ctf-create.c (ctf_update): Likewise.
* configure.ac: Check for BSD versus GNU qsort_r signature.
* Makefile.in: Regenerate.
* config.h.in: Likewise.
* configure: Likewise.
This stops the file format from depending on the size of the host int.
(It does mean that we cannot encode enums with a value > 2^32 on
platforms with an int > 2^32: this will be fixed in the next format
revision.)
include/
* ctf.h (ctf_enum.cte_value): Fix type to int32_t.
This allows users of the Python API to find the objfile where a type
was defined.
gdb/ChangeLog:
gdb/ChangeLog
2019-06-04 Christian Biesinger <cbiesinger@google.com>
Add objfile property to gdb.Type.
* gdb/NEWS: Mention Python API addition.
* gdb/python/py-type.c (typy_get_objfile): New method.
gdb/doc/ChangeLog
2019-06-04 Christian Biesinger <cbiesinger@google.com>
* gdb/doc/python.texi: Document new gdb.Type.objfile property.
gdb/testsuite/ChangeLog
2019-06-04 Christian Biesinger <cbiesinger@google.com>
* gdb/testsuite/gdb.python/py-type.exp: Test for new
gdb.Type.objfile property.