aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2021-12-17Move ordinary gdbarch code to arch-utilsTom Tromey4-1028/+488
While I think it makes sense to generate gdbarch.c, at the same time I think it is better for ordinary code to be editable in a C file -- not as a hunk of C code embedded in the generator. This patch moves this sort of code out of gdbarch.sh and gdbarch.c and into arch-utils.c, then has arch-utils.c include gdbarch.c.
2021-12-17Avoid redundant operations in `fortran_array_walker'Maciej W. Rozycki1-3/+4
Move inner dimension's element type determination outside the respective loops in `fortran_array_walker'. The operation is exactly the same with each iteration, so there is no point in redoing it for each element and while a smart compiler might be able to move it outside the loop it is regardless a bad coding style. No functional change.
2021-12-17Initialize `m_ndimensions' in the member initializer listMaciej W. Rozycki1-4/+3
Following our coding convention initialize the `m_ndimensions' member in the member initializer list rather than in the body of the constructor of the `fortran_array_walker' class. No functional change.
2021-12-17gdb/tui: install SIGWINCH only when connected to a TTYLancelot SIX4-3/+105
PR26056 reports that when GDB is connected to non-TTY stdin/stdout, it crashes when it receives a SIGWINCH signal. This can be reproduced as follows: $ gdb/gdb -nx -batch -ex 'run' --args sleep 60 </dev/null 2>&1 | cat # from another terminal: $ kill -WINCH %(pidof gdb) When doing so, the process crashes in a call to rl_resize_terminal: void rl_resize_terminal (void) { _rl_get_screen_size (fileno (rl_instream), 1); ... } The problem is that at this point rl_instream has the value NULL. The rl_instream variable is supposed to be initialized during a call to readline_initialize_everything, which in a normal startup sequence is called under this call chain: tui_interp::init tui_ensure_readline_initialized rl_initialize readline_initialize_everything In tui_interp::init, we have the following sequence: tui_initialize_io (); tui_initialize_win (); // <- Installs SIGWINCH if (gdb_stdout->isatty ()) tui_ensure_readline_initialized (); // <- Initializes rl_instream This function unconditionally installs the SIGWINCH signal handler (this is done by tui_initialize_win), and then if gdb_stdout is a TTY it initializes readline. Therefore, if stdout is not a TTY, SIGWINCH is installed but readline is not initialized. In such situation rl_instream stays NULL, and when GDB receives a SIGWINCH it calls its handler and in fine tries to access rl_instream leading to the crash. This patch proposes to fix this issue by installing the SIGWINCH signal handler only if GDB is connected to a TTY. Given that this initialization it the only task of tui_initialize_win, this patch moves tui_initialize_win just after the call to tui_ensure_readline_initialized. Tested on x86_64-linux. Co-authored-by: Pedro Alves <pedro@palves.net> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26056 Change-Id: I6458acef7b0d9beda2a10715d0345f02361076d9
2021-12-17asan: NULL dereference in bfd_elf_set_group_contentsAlan Modra2-6/+6
* elf-bfd.h (struct output_elf_obj_tdata): Make num_section_syms unsigned. * elf.c (bfd_elf_set_group_contents): Bounds check sec->index and check that entry in elf_section_syms for sec is non-NULL. (_bfd_elf_symbol_from_bfd_symbol): Adjust.
2021-12-17asan: use after free in _bfd_elf_mips_get_relocated_section_contentsAlan Modra1-5/+21
Leaving entries on mips_hi16_list from a previous pass over relocs leads to confusing bugs. * elfxx-mips.c (_bfd_elf_mips_get_relocated_section_contents): Free mips_hi16_list entries on error exit.
2021-12-17asan: abort in wasm_scan_name_function_sectionAlan Modra1-1/+2
Macros like READ_LEB128 in wasm-module.c that alter control flow are evil. Maintainers will break your code if you have hidden ways to reach labels. * wasm-module.c (wasm_scan_name_function_section): Don't attempt to bfd_release NULL.
2021-12-17asan: heap-buffer-overflow in bpf_elf_generic_relocAlan Modra1-8/+9
The bpf reloc howtos are a bit weird, using bitpos to specify an offset from r_offset that is outside the size of the reloc as given by howto.size. That means bfd_get_reloc_size gives the wrong answer for range checking, and thus bfd_reloc_offset_in_range can't be used. * elf64-bpf.c (bpf_elf_generic_reloc): Handle bitpos offset reloc range checking.
2021-12-17ubsan: bfd.c:2519:8: shift exponent 34 is too largeAlan Modra1-2/+2
* bfd.c (bfd_update_compression_header): Avoid integer overflow.
2021-12-17asan: buffer overflow in mmo_get_symbolsAlan Modra1-0/+10
* mmo.c (mmo_get_symbols): Error on symbol name exceeding max length.
2021-12-17asan: buffer overflow in elfnn-aarch64.c get_plt_typeAlan Modra1-3/+5
We can't assume .dynamic is a multiple of ElfNN_External_Dyn, at least not when presented with fuzzed object files. * elfnn-aarch64.c (get_plt_type): Don't access past end of improperly sized .dynamic.
2021-12-17try_build_id_prefix gcc-10 -Wformat-security errorsAlan Modra1-3/+2
dwarf.c:11300:3: error: format not a string literal and no format arguments [-Werror=format-security] 11300 | f += sprintf (f, prefix); PR 28697 * dwarf.c (try_build_id_prefix): Avoid -Wformat-security error.
2021-12-17Automatic date update in version.inGDB Administrator1-1/+1
2021-12-16Fix AVR assembler so that it creates relocs that will work with linker ↵Nick Clifton11-11/+60
relaxation. PR 28686 gas * config/tc-avr.h (tc_fix_adjustable): Define. * config/tc-avr.c (avr_fix_adjustable): New function. * testsuite/gas/all/gas.exp: Skip tests that need adjustable fixups. * testsuite/gas/elf/elf.exp: Likewise. * testsuite/gas/avr/diffreloc_withrelax.d: Adjust expected output. * testsuite/gas/avr/pc-relative-reloc.d: Adjust expected output. ld * testsuite/ld-avr/avr-prop-7.d: Adjust expected output. * testsuite/ld-avr/avr-prop-8.d: Likewise. * testsuite/ld-avr/pr13402.d: Likewise.
2021-12-16When loading separate debug info files, also attempt to locate a file based ↵Nick Clifton4-4/+131
upon the build-id. PR 28697 * dwarf.c (load_build_id_debug_file): New function. (try_build_id_prefix): New function. (check_for_and_load_links): Call load_build_id_debug_file. (debug_displays): Add entry for .note.gnu.build-id. * dwarf.h (enum dwarf_section_display_enum): Add note_gnu_build_id. * testsuite/binutils-all/debuginfod.exp (test_fetch_debuglink): Fix regexp for loads via debuglink section.
2021-12-16arm: Add support for Armv9.1-A to Armv9.3-ARichard Sandiford12-3/+101
This patch adds AArch32 support for -march=armv9.[123]-a. The behaviour of the new options can be expressed using a combination of existing feature flags and tables. The cpu_arch_ver entries for ARM_ARCH_V9_2A and ARM_ARCH_V9_3A are technically redundant but it seemed less surprising to include them anyway. include/ * opcode/arm.h (ARM_ARCH_V9_1A, ARM_ARCH_V9_2A): New macros. (ARM_ARCH_V9_3A): Likewise. gas/ * doc/c-arm.texi: Add armv9.1-a, armv9.2-a and armv9.3-a. * config/tc-arm.c (armv91a_ext_table, armv92a_ext_table): New macros. (armv93a_ext_table): Likewise. (arm_archs): Add armv9.1-a, armv9.2-a and armv9.3-a. (cpu_arch_ver): Add ARM_ARCH_V9_1A, ARM_ARCH_V9_2A and ARM_ARCH_V9_3A. * NEWS: Mention the above. * testsuite/gas/arm/attr-march-armv9_1-a.d: New test. * testsuite/gas/arm/attr-march-armv9_2-a.d: Likewise. * testsuite/gas/arm/attr-march-armv9_3-a.d: Likewise. * testsuite/gas/arm/bfloat16-armv9.1-a.d: Likewise. * testsuite/gas/arm/bfloat16-armv9.2-a.d: Likewise. * testsuite/gas/arm/bfloat16-armv9.3-a.d: Likewise. * testsuite/gas/arm/i8mm-armv9.1-a.d: Likewise. * testsuite/gas/arm/i8mm-armv9.2-a.d: Likewise. * testsuite/gas/arm/i8mm-armv9.3-a.d: Likewise.
2021-12-16arm: Add support for Armv8.7-A and Armv8.8-ARichard Sandiford10-1/+67
This patch adds AArch32 support for -march=armv8.[78]-a. The behaviour of the new options can be expressed using a combination of existing feature flags and tables. The cpu_arch_ver entries are technically redundant but it seemed less surprising to include them anyway. include/ * opcode/arm.h (ARM_ARCH_V8_7A, ARM_ARCH_V8_8A): New macros. gas/ * doc/c-arm.texi: Add armv8.7-a and armv8.8-a. * config/tc-arm.c (armv87a_ext_table, armv88a_ext_table): New macros. (arm_archs): Add armv8.7-a and armv8.8-a. (cpu_arch_ver): Add ARM_ARCH_V8_7A and ARM_ARCH_V8_8A. * NEWS: Mention the above. * testsuite/gas/arm/attr-march-armv8_7-a.d: New test. * testsuite/gas/arm/attr-march-armv8_8-a.d: Likewise. * testsuite/gas/arm/bfloat16-armv8.7-a.d: Likewise. * testsuite/gas/arm/bfloat16-armv8.8-a.d: Likewise. * testsuite/gas/arm/i8mm-armv8.7-a.d: Likewise. * testsuite/gas/arm/i8mm-armv8.8-a.d: Likewise.
2021-12-16aarch64: Add support for Armv9.1-A to Armv9.3-ARichard Sandiford19-42/+157
This patch adds AArch64 support for -march=armv9.[123]-a. The behaviour of the new options can be expressed using a combination of existing feature flags, so we don't need to eat into the vanishing number of spare AARCH64_FEATURE_* bits. Hoewver, it was more convenient to separate out the |s of feature flags so that Armv9.1-A could reuse the set for Armv8.6-A, and so on. include/ * opcode/aarch64.h (AARCH64_ARCH_V8_FEATURES): New macro, split out from... (AARCH64_ARCH_V8): ...here. (AARCH64_ARCH_V8_1_FEATURES): New macro, split out from... (AARCH64_ARCH_V8_1): ...here. (AARCH64_ARCH_V8_2_FEATURES): New macro, split out from... (AARCH64_ARCH_V8_2): ...here. (AARCH64_ARCH_V8_3_FEATURES): New macro, split out from... (AARCH64_ARCH_V8_3): ...here. (AARCH64_ARCH_V8_4_FEATURES): New macro, split out from... (AARCH64_ARCH_V8_4): ...here. (AARCH64_ARCH_V8_5_FEATURES): New macro, split out from... (AARCH64_ARCH_V8_5): ...here. (AARCH64_ARCH_V8_6_FEATURES): New macro, split out from... (AARCH64_ARCH_V8_6): ...here. (AARCH64_ARCH_V8_7_FEATURES): New macro, split out from... (AARCH64_ARCH_V8_7): ...here. (AARCH64_ARCH_V8_8_FEATURES): New macro, split out from... (AARCH64_ARCH_V8_8): ...here. (AARCH64_ARCH_V9_FEATURES): New macro, split out from... (AARCH64_ARCH_V9): ...here. (AARCH64_ARCH_V9_1_FEATURES, AARCH64_ARCH_V9_1): New macros. (AARCH64_ARCH_V9_2_FEATURES, AARCH64_ARCH_V9_2): New macros. (AARCH64_ARCH_V9_3_FEATURES, AARCH64_ARCH_V9_3): New macros. gas/ * doc/c-aarch64.texi: Add armv9.1-a, armv9-2-a and armv9.3-a. * config/tc-aarch64.c (aarch64_archs): Likewise. * NEWS: Mention the above. * testsuite/gas/aarch64/armv9_invalid.d, testsuite/gas/aarch64/armv9_invalid.s, testsuite/gas/aarch64/armv9_invalid.l: New test. * testsuite/gas/aarch64/armv9_1.d, testsuite/gas/aarch64/armv9_1.s: Likewise. * testsuite/gas/aarch64/armv9_1_invalid.d, testsuite/gas/aarch64/armv9_1_invalid.s, testsuite/gas/aarch64/armv9_1_invalid.l: Likewise. * testsuite/gas/aarch64/armv9_2.d, testsuite/gas/aarch64/armv9_2.s: Likewise. * testsuite/gas/aarch64/armv9_2_invalid.d, testsuite/gas/aarch64/armv9_2_invalid.s, testsuite/gas/aarch64/armv9_2_invalid.l: Likewise. * testsuite/gas/aarch64/armv9_3.d, testsuite/gas/aarch64/armv9_3.s: Likewise.
2021-12-16RISC-V: Support svinval extension with frozen version 1.0.Nelson Chu6-0/+47
According to the privileged spec, there are five new instructions for svinval extension. Two of them (HINVAL.VVMA and HINVAL.GVMA) need to enable the hypervisor extension. But there is no implementation of hypervisor extension in mainline for now, so let's consider the related issues later. 31..25 24..20 19..15 14..12 11...7 6..2 1..0 sinval.vma 0001011 rs2 rs1 000 00000 11100 11 sfence.w.inval 0001100 00000 00000 000 00000 11100 11 sfence.inval.ir 0001100 00001 00000 000 00000 11100 11 hinval.vvma 0010011 rs2 rs1 000 00000 11100 11 hinval.gvma 0110011 rs2 rs1 000 00000 11100 11 This patch is cherry-picked from the riscv integration branch since the svinval extension is frozen for now. Besides, we fix the funct7 encodings of hinval.vvma and hinval.gvma, from 0x0011011 and 0x0111011 to 0x0010011 and 0x0110011. bfd/ * elfxx-riscv.c (riscv_supported_std_s_ext): Added svinval. (riscv_multi_subset_supports): Handle INSN_CLASS_SVINVAL. gas/ * testsuite/gas/riscv/svinval.d: New testcase. * testsuite/gas/riscv/svinval.s: Likewise. include/ * opcode/riscv-opc.h: Added encodings for svinval. * opcode/riscv.h (enum riscv_insn_class): Added INSN_CLASS_SVINVAL. opcodes/ * riscv-opc.c (riscv_opcodes): Added svinval instructions.
2021-12-16sim: mips/or1k: drop redundant arg to bitsize macroMike Frysinger4-6/+4
These are just using the default behavior for the 3rd arg, so drop it to make it more clear. This also makes them match all other ports that only use the first 2 arguments.
2021-12-16bfd: unify texi generation rulesMike Frysinger2-184/+74
The logic between these rules are extremely similar, so unify them into a single variable by leveraging make $@ and $< variables. Also add automake silent rule support while we're here.
2021-12-16sim: fix mingw builds with replacement gnulib openMike Frysinger1-2/+2
The header shuffling in here broke the workaround for gnulib defining "open". Move it back before the sim-specific includes to fix. This is because the callback struct in the headers has an "open" member and this file tries to call that.
2021-12-16Adjust compare_link_order for unstable qsortSandra Loosemore1-5/+6
In a cross toolchain for nios2-elf target and x86_64-w64-mingw32 host using binutils 2.37, we observed a failure that didn't show up on x86_64-linux-gnu host: testcase pr25490-5.s was failing with C:\path\to\nios2-elf-ld.exe: looping in map_segments FAIL: __patchable_function_entries section 5 * ldelfgen.c (compare_link_order): Don't use section id in sorting. Keep original ordering instead. Update comments.
2021-12-16Re: Fix an undefined behaviour in the BFD library's DWARF parserAlan Modra1-4/+4
Using an unsigned int cast (to 32 bits) on a pointer difference (of possibly 64 bits) is wrong. Even though it will work on all real object files, the fuzzers will eventually find this hole. PR 28687 * dwarf1.c (parse_die): Cast pointer difference to size_t. Catch another possible pointer overflow.
2021-12-15gdb: re-format with black 21.12b0Simon Marchi1-1/+0
Run black 21.12b0 on gdb/, there is a single whitespace change. I will update the wiki [1] in parallel to bump the version of black to 21.12b0. [1] https://sourceware.org/gdb/wiki/Internals%20GDB-Python-Coding-Standards Change-Id: Ib3b859e3506c74a4f15d16f1e44ef402de3b98e2
2021-12-15gdb: re-format with black 21.9b0Simon Marchi3-11/+19
Run black 21.9b0 on gdb/ (this is the version currently mentioned on the wiki [1], the subsequent commit will bump that version). [1] https://sourceware.org/gdb/wiki/Internals%20GDB-Python-Coding-Standards Change-Id: I5ceaab42c42428e053e2572df172aa42a88f0f86
2021-12-16Automatic date update in version.inGDB Administrator1-1/+1
2021-12-16PR28691, validate dwarf attribute formAlan Modra1-56/+128
PR28691 is a fuzzing PR that triggers a non-problem of "output changes per run" with PIEs and/or different compilers. I've closed similar PRs before as wontfix, but I guess there will be no end of this type of PR. The trigger is an attribute that usually takes one of the offset/constant reference DW_FORMs being given an indexed string DW_FORM. The bfd reader doesn't support indexed strings and returns an error string instead. The address of the string varies with PIE runs and/or compiler, and we allow that address to appear in output. Fix this by validating integer attribute forms, as we do for string form attributes. PR 28691 * dwarf2.c (is_str_attr): Rename to.. (is_str_form): ..this. Change param type. Update calls. (is_int_form): New function. (read_attribute_value): Handle DW_FORM_addrx2. (find_abstract_instance): Validate form when using attr.u.val. (scan_unit_for_symbols, parse_comp_unit): Likewise.
2021-12-15New --enable-threading configure option to control use of threads in ↵Luis Machado5-6/+99
GDB/GDBserver Add the --enable-threading configure option so multithreading can be disabled at configure time. This is useful for statically-linked builds of GDB/GDBserver, since the thread library doesn't play well with that setup. If you try to run a statically-linked GDB built with threading, it will crash when setting up the number of worker threads. This new option is also convenient when debugging GDB in a system with lots of threads, where the thread discovery code in GDB will emit too many messages, like so: [New Thread 0xfffff74d3a50 (LWP 2625599)] If you have X threads, that message will be repeated X times. The default for --enable-threading is "yes".
2021-12-15Fix an undefined behaviour in the BFD library's DWARF parser.Nikita Popov2-4/+7
PR 28687 * dwarf1.c (parse_die): Fix undefined behaviour in range tests.
2021-12-15PR28694, Out-of-bounds write in stab_xcoff_builtin_typeAlan Modra1-44/+43
PR 28694 * stabs.c (stab_xcoff_builtin_type): Make typenum unsigned. Negate typenum earlier, simplifying bounds checking. Correct off-by-one indexing. Adjust switch cases.
2021-12-15Automatic date update in version.inGDB Administrator1-1/+1
2021-12-15loongarch32 build failure on 32-bit hostAlan Modra1-1/+1
gas/config/tc-loongarch.c: In function ‘assember_macro_helper’: gas/config/tc-loongarch.c:915:28: error: right shift count >= width of type [-Werror=shift-count-overflow] 915 | hi32 = insn->args[1] >> 32; | ^~ One possible fix is to make offsetT a 64-bit type for loongarch32. This also makes bfd/targmatch.h (generated from bfd/config.bfd) consistent since the loongarch32 match is inside #ifdef BFD64. * config.bfd (loongarch32-*): Set want64.
2021-12-15loongarch64 build failure on 32-bit hostAlan Modra1-6/+6
gas/config/tc-loongarch.c: In function ‘loongarch_args_parser_can_match_arg_helper’: gas/config/tc-loongarch.c:661:13: error: cast from pointer to integer of different size [-Werror=pointer -to-int-cast] 661 | imm = (offsetT) str_hash_find (r_htab, arg); | ^ Cast it to the correct size int, relying on normal integer promotions if offsetT is larger than a pointer. * config/tc-loongarch.c (loongarch_args_parser_can_match_arg_helper): Cast return from str_hash_find to intptr_t, not offsetT.
2021-12-15XCOFF C_STSYM test failure on 32-bit hostAlan Modra2-7/+8
This test was failing here and on another similar symbol: [ 4](sec 1)(fl 0x00)(ty 0)(scl 143) (nx 0) 0x05d1745d11745d21 .bs where correct output is [ 4](sec 1)(fl 0x00)(ty 0)(scl 143) (nx 0) 0x000000000000000a .bs The problem is caused by a 32-bit host pointer being sign-extended when stored into a 64-bit bfd_vma, and then that value not being trimmed back to 32 bits when used. The following belt-and-braces patch fixes both the store and subsequent reads. * coffcode.h (coff_slurp_symbol_table): Do not sign extend when storing a host pointer to syment.n_value. * coffgen.c (coff_get_symbol_info): Cast syment.n_value to a bfd_hostptr_t before using in arithmetic. (coff_print_symbol): Likewise.
2021-12-14gdbserver/tracepoint.cc: use snprintf in gdb_agent_socket_initSimon Marchi1-2/+2
If we modify tracepoint.cc to try to use a too long unix socket name, for example by modifying SOCK_DIR to be: #define SOCK_DIR "/tmp/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut/salut" ... trying to start an application with libinproctrace.so loaded crashes: $ LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.6:./libinproctrace.so /bin/ls /home/smarchi/src/binutils-gdb/gdbserver/../gdbsupport/common-utils.cc:69: A problem internal to GDBserver in-process agent has been detected. xsnprintf: Assertion `ret < size' failed. Looking at the rest of the socket initialization code, the intent seems to be that if something goes wrong, we warn but let the program execute. So crashing on this failed assertions seems against the intent. Commit 6cebaf6e1ae4 ("use xsnprintf instead of snprintf.") changed this code to use xsnprintf instead of snprintf, introducing this assertion. Before that, snprintf would return a value bigger that UNIX_PATH_MAX and the "if" after would catch it and emit a warning, which is exactly what we want. That change was done because LynxOS didn't have snprintf. Since LynxOS isn't supported anymore, we can simply revert to use snprintf there. With this patch, we get a warning (printed by the caller of gdb_agent_socket_init), but the program keeps executing: $ LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.6:./libinproctrace.so /bin/ls ipa: could not create sync socket ... Change-Id: I78bca52d5dc3145335abeae45a42052701e3f5dd
2021-12-14gdbserver/tracepoint.cc: work around -Wstringop-truncation errorSimon Marchi1-2/+7
When building gdb with on AArch64 with g++ 11.1.0 (and some preceding versions too), -O2 and -fsanitize=address, I get this error. CXX tracepoint-ipa.o cc1plus: warning: command-line option ‘-Wmissing-prototypes’ is valid for C/ObjC but not for C++ In file included from /usr/include/string.h:519, from ../gnulib/import/string.h:41, from /home/simark/src/binutils-gdb/gdbserver/../gdbsupport/common-defs.h:95, from /home/simark/src/binutils-gdb/gdbserver/server.h:22, from /home/simark/src/binutils-gdb/gdbserver/tracepoint.cc:19: In function ‘char* strncpy(char*, const char*, size_t)’, inlined from ‘int init_named_socket(const char*)’ at /home/simark/src/binutils-gdb/gdbserver/tracepoint.cc:6902:11, inlined from ‘int gdb_agent_socket_init()’ at /home/simark/src/binutils-gdb/gdbserver/tracepoint.cc:6953:26, inlined from ‘void* gdb_agent_helper_thread(void*)’ at /home/simark/src/binutils-gdb/gdbserver/tracepoint.cc:7204:41: /usr/include/bits/string_fortified.h:95:34: error: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be truncated copying 107 bytes from a string of length 107 [-Werror=stringop-truncation] 95 | return __builtin___strncpy_chk (__dest, __src, __len, | ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ 96 | __glibc_objsize (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~ Note that _FORTIFY_SOURCE changes the message a bit, but I get a similar error if I use -D_FORTIFY_SOURCE=0. I am pretty sure it's spurious and might be related to this GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88780 From what I can see, we are copying from a static 108 bytes long buffer (the global array agent_socket_name) to a 108 bytes long array, sockaddr_un::sun_path. I don't see anything wrong. Still, it would make things easier if we didn't see this error. Change the code to check that the source string length is smaller than the destination buffer (including space for the NULL byte) and use strcpy. For anybody who would like to try to reproduce, the full command line is: g++ -I. -I/home/simark/src/binutils-gdb/gdbserver -I/home/simark/src/binutils-gdb/gdbserver/../gdb/regformats -I/home/simark/src/binutils-gdb/gdbserver/.. -I/home/simark/src/binutils-gdb/gdbserver/../include -I/home/simark/src/binutils-gdb/gdbserver/../gdb -I/home/simark/src/binutils-gdb/gdbserver/../gnulib/import -I../gnulib/import -I/home/simark/src/binutils-gdb/gdbserver/.. -I.. -pthread -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-variable -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable -Wno-sign-compare -Wno-error=maybe-uninitialized -Wno-mismatched-tags -Wsuggest-override -Wimplicit-fallthrough=3 -Wduplicated-cond -Wshadow=local -Wdeprecated-copy -Wdeprecated-copy-dtor -Wredundant-move -Wmissing-declarations -Wmissing-prototypes -Wstrict-null-sentinel -Wformat -Wformat-nonliteral -Werror -DGDBSERVER -DCONFIG_UST_GDB_INTEGRATION -Drpl_strerror_r=strerror_r -Drpl_free=free -fPIC -DIN_PROCESS_AGENT -fvisibility=hidden -g3 -O2 -fsanitize=address -c -o tracepoint-ipa.o -MT tracepoint-ipa.o -MMD -MP -MF ./.deps/tracepoint-ipa.Tpo /home/simark/src/binutils-gdb/gdbserver/tracepoint.cc Change-Id: I18e86c0487feead7e7677e69398405e7057cf464
2021-12-14bfd: fix -Wunused errors with clang 13+Simon Marchi12-87/+9
Clang 13 and 14 produce some -Wunused-but-set-{variable,parameter} for situations where gcc doesn't. In particular, when a variable is set and then used in a way to update its own value. For example, if `i` is only used in this way: int i = 2; i++; i = i + 1; gcc won't warn, but clang will. Fix all such errors found in an --enable-targets=all build. It would be important for somebody who knows what they're doing to just make sure that these variables can indeed be deleted, and that there a no cases where it's a bug, and the variable should actually be used. The first instance of this error fix by this patch is: CC elf32-score.lo /home/simark/src/binutils-gdb/bfd/elf32-score.c:450:11: error: variable 'relocation' set but not used [-Werror,-Wunused-but-set-variable] bfd_vma relocation; ^ Change-Id: I2f233ce20352645cf388aff3dfa08a651d21a6b6
2021-12-14gdb/mi: rename build_table to add_builtin_mi_commandsAndrew Burgess1-2/+2
Just give the function build_table a more descriptive name. There should be no user visible changes after this commit.
2021-12-14gdb/mi: rename mi_cmd to mi_commandJan Vrany4-23/+23
Just give this class a new name, more inline with the name of the sub-classes. I've also updated mi_cmd_up to mi_command_up in mi-cmds.c inline with this new naming scheme. There should be no user visible changes after this commit.
2021-12-14gdb/mi: use separate classes for different types of MI commandJan Vrany6-99/+181
This commit changes the infrastructure in mi-cmds.{c,h} to add new sub-classes for the different types of MI command. Instances of these sub-classes are then created and added into mi_cmd_table. The existing mi_cmd class becomes the abstract base class, this has an invoke method and takes care of the suppress notifications handling, before calling a do_invoke virtual method which is implemented by all of the sub-classes. There's currently two different sub-classes, one of pure MI commands, and a second for MI commands that delegate to CLI commands. There should be no user visible changes after this commit.
2021-12-14gdb/mi: int to bool conversion in mi_execute_cli_commandAndrew Burgess1-9/+13
Change an argument of mi_execute_cli_command from int to bool. Update the callers to take this into account. Within mi_execute_cli_command, update a comparison of a pointer to 0 with a comparison to nullptr, and add an assert, if we are not using the argument string then the string should be nullptr. Also removed a cryptic 'gdb_????' comment, which isn't really helpful. There should be no user visible changes after this commit.
2021-12-14gdb/mi: use std::map for MI commands in mi-cmds.cJan Vrany1-248/+230
This changes the hashmap used in mi-cmds.c from a custom structure to std::map. Not only is replacing a custom container with a standard one an improvement, but using std::map will make it easier to dynamically add commands; which is something that is planned for a later series, where we will allow MI commands to be implemented in Python. There should be no user visible changes after this commit.
2021-12-14gdb/mi: rename mi_lookup to mi_cmd_lookupJan Vrany4-6/+8
Lets give this function a more descriptive name. I've also improved the comments in the header and source files. There should be no user visible changes after this commit.
2021-12-14RISC-V: Added ld testcases for the medlow and medany code models.Nelson Chu20-0/+280
There are two linker scripts, code-model-01.ld and code-model-02.ld, which are corresponding to the two different memory layouts, * code-model-01.ld: the text section is in the 32-bit address range, but the data section is far away from the text section, which means the data section is over the 32-bit address range. * code-model-02.ld: the text section is over the 32-bit address range, but the data section is placed nearly zero address. We use the two linker scripts, to test the current medlow and medany behaviors of GNU ld, including the weak symbol references and the relaxations behaviors. Besides, these testcases also show the limits of the current medlow and medany code models, that is - we may get the truncated to fit errors when linking with the above two linker scripts. ld/ * testsuite/ld-riscv-elf/code-model-01.ld: New testcases to test the behaviors of the current medlow and medany code models. * testsuite/ld-riscv-elf/code-model-02.ld: Likewise. * testsuite/ld-riscv-elf/code-model-medany-01.d: Likewise. * testsuite/ld-riscv-elf/code-model-medany-02.d: Likewise. * testsuite/ld-riscv-elf/code-model-medany-weakref-01.d: Likewise. * testsuite/ld-riscv-elf/code-model-medany-weakref-02.d: Likewise. * testsuite/ld-riscv-elf/code-model-medlow-01.d: Likewise. * testsuite/ld-riscv-elf/code-model-medlow-02.d: Likewise. * testsuite/ld-riscv-elf/code-model-medlow-weakref-01.d: Likewise. * testsuite/ld-riscv-elf/code-model-medlow-weakref-02.d: Likewise. * testsuite/ld-riscv-elf/code-model-relax-medany-01.d: Likewise. * testsuite/ld-riscv-elf/code-model-relax-medany-02.d: Likewise. * testsuite/ld-riscv-elf/code-model-relax-medany-weakref-01.d: Likewise. * testsuite/ld-riscv-elf/code-model-relax-medany-weakref-02.d: Likewise. * testsuite/ld-riscv-elf/code-model-relax-medlow-01.d: Likewise. * testsuite/ld-riscv-elf/code-model-relax-medlow-02.d: Likewise. * testsuite/ld-riscv-elf/code-model-relax-medlow-weakref-01.d: Likewise. * testsuite/ld-riscv-elf/code-model-relax-medlow-weakref-02.d: Likewise. * testsuite/ld-riscv-elf/code-model.s: Likewise. * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
2021-12-14Automatic date update in version.inGDB Administrator1-1/+1
2021-12-13x86: Adjust linker tests for --disable-separate-codeH.J. Lu8-15/+15
Adjust linker tests for linker configured with --disable-separate-code: 1. Update expected outputs. 2. Pass -z max-page-size=0x1000 -z separate-code" to linker. * testsuite/ld-i386/report-reloc-1.l: Updated. * testsuite/ld-x86-64/report-reloc-1.l: Likewise. * testsuite/ld-x86-64/pe-x86-64.exp: Pass "-z max-page-size=0x1000 -z separate-code" to linker. * testsuite/ld-x86-64/pr19609-4e.d: Likewise. * testsuite/ld-x86-64/pr19609-6a.d: Likewise. * testsuite/ld-x86-64/pr19609-6b.d: Likewise. * testsuite/ld-x86-64/pr19609-7b.d: Likewise. * testsuite/ld-x86-64/pr19609-7d.d: Likewise.
2021-12-13gdb: Powerpc mark xfail in gdb.base/catch-syscall.expCarl Love1-6/+31
Powerpc is not reporting the Catchpoint 1 (returned from syscall execve), .... as expected. The issue appears to be with the kernel not returning the expected result. This patch marks the test failure as an xfail. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28623
2021-12-13gdb: improve reuse of value contents when fetching array elementsAndrew Burgess3-9/+118
While working on a Python script, which was interacting with a remote target, I noticed some weird slowness in GDB. In my program I had a structure something like this: struct foo_t { int array[5]; }; struct foo_t global_foo; Then in the Python script I was fetching a complete copy of global foo, like: val = gdb.parse_and_eval('global_foo') val.fetch_lazy() Then I would work with items in foo_t.array, like: print(val['array'][1]) I called the fetch_lazy method specifically because I knew I was going to end up accessing almost all of the contents of val, and so I wanted GDB to do a single remote protocol call to fetch all the contents in one go, rather than trying to do lazy fetches for a couple of bytes at a time. What I observed was that, after the fetch_lazy call, GDB does, correctly, fetch the entire contents of global_foo, including all of the contents of array, however, when I access val.array[1], GDB still goes and fetches the value of this element from the remote target. What's going on is that in valarith.c, in value_subscript, for C like languages, we always end up treating the array value as a pointer, and then doing value_ptradd, and value_ind, the second of these calls always returns a lazy value. My guess is that this approach allows us to handle indexing off the end of an array, when working with zero element arrays, or when indexing a raw pointer as an array. And, I agree, that in these cases, where, even when the original value is non-lazy, we still will not have the content of the array loaded, we should be using the value_ind approach. However, for cases where we do have the array contents loaded, and we do know the bounds of the array, I think we should be using value_subscripted_rvalue, which is what we use for non C like languages. One problem I did run into, exposed by gdb.base/charset.exp, was that value_subscripted_rvalue stripped typedefs from the element type of the array, which means the value returned will not have the same type as an element of the array, but would be the raw, non-typedefed, type. In charset.exp we got back an 'int' instead of a 'wchar_t' (which is a typedef of 'int'), and this impacts how we print the value. Removing typedefs from the resulting value just seems wrong, so I got rid of that, and I don't see any test regressions. With this change in place, my original Python script is now doing no additional memory accesses, and its performance increases about 10x!
2021-12-13gdb: update gdb-gdb.py.in for latest changes to struct fieldAndrew Burgess3-20/+191
This commit updates uses of 'loc' and 'loc_kind' to 'm_loc' and 'm_loc_kind' respectively, in gdb-gdb.py.in, which is required after this commit: commit cd3f655cc7a55437a05aa8e7b1fcc9051b5fe404 Date: Thu Sep 30 22:38:29 2021 -0400 gdb: add accessors for field (and call site) location I have also incorporated this change: https://sourceware.org/pipermail/gdb-patches/2021-September/182171.html Which means we print 'm_name' instead of 'name' when displaying the 'm_name' member variable. Finally, I have also added support for the new TYPE_SPECIFIC_INT fields, which were added with this commit: commit 20a5fcbd5b28cca88511ac5a9ad5e54251e8fa6d Date: Wed Sep 23 09:39:24 2020 -0600 Handle bit offset and bit size in base types I updated the gdb.gdb/python-helper.exp test to cover all of these changes.