aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2022-07-07Fix pedantically invalid DWARF in gdb.trace/unavailable-dwarf-piece.expPedro Alves1-2/+2
The DWARF spec says: Any debugging information entry representing the declaration of an object, module, subprogram or type may have DW_AT_decl_file, DW_AT_decl_line and DW_AT_decl_column attributes, each of whose value is an unsigned integer ^^^^^^^^ constant. Grepping around the DWARF-assembler-based testcases, I noticed that gdb.trace/unavailable-dwarf-piece.exp emits decl_line with DW_FORM_sdata, a signed integer form. This commit tweaks it to use DW_FORM_udata instead. Unsurprisingly, this: $ make check \ TESTS="gdb.trace/unavailable-dwarf-piece.exp" \ RUNTESTFLAGS="--target_board=native-gdbserver" ... still passes cleanly for me after this change. I've noticed this because current llvm-dwarfdump crashed on an ROCm-internal DWARF-assembler-based testcase that incorrectly used signed forms for DW_AT_decl_file/DW_AT_decl_line. The older llvm-dwarfdump found on Ubuntu 20.04 (LLVM 10) reads the line numbers with signed forms as "0" instead of crashing. Here's the before/after fix for gdb.trace/unavailable-dwarf-piece.exp with that llvm-dwarfdump version: $ diff -up before.txt after.txt --- before.txt 2022-07-07 13:21:28.387690334 +0100 +++ after.txt 2022-07-07 13:21:39.379801092 +0100 @@ -18,7 +18,7 @@ DW_AT_name ("s") DW_AT_byte_size (3) DW_AT_decl_file (0) - DW_AT_decl_line (0) + DW_AT_decl_line (1) 0x0000002f: DW_TAG_member DW_AT_name ("a") @@ -41,7 +41,7 @@ DW_AT_name ("t") DW_AT_byte_size (3) DW_AT_decl_file (0) - DW_AT_decl_line (0) + DW_AT_decl_line (1) 0x00000054: DW_TAG_member DW_AT_name ("a") Change-Id: I5c866946356da421ff944019d0eca2607b2b738f
2022-07-07gdb: LoongArch: Fix typos in code commentsTiezhu Yang1-15/+15
"it’s" should be "it's". Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2022-07-07GDB/testsuite: Add coverage for `print -elements' commandMaciej W. Rozycki1-0/+9
We currently have no coverage for the `print -elements ...' command (or `p -elements ...' in the shortened form), so add a couple of test cases mimicking ones using corresponding `set print elements ...' values.
2022-07-07gdb: LoongArch: Implement the push_dummy_call gdbarch methodTiezhu Yang2-0/+598
According to "Procedure Calling Convention" in "LoongArch ELF ABI specification" [1], implement the push_dummy_call gdbarch method as clear as possible. [1] https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_procedure_calling_convention Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2022-07-05[gdb/exp] Fix internal error when printing C++ pointer-to-memberTom de Vries3-1/+66
When running the test-case included with this patch, we run into: ... (gdb) print ptm^M $1 = gdb/gdbtypes.h:695: internal-error: loc_bitpos: \ Assertion `m_loc_kind == FIELD_LOC_KIND_BITPOS' failed.^M ... while printing a c++ pointer-to-member. Fix this by skipping static fields in cp_find_class_member, such that we have: ... (gdb) print ptm^M $1 = &A::i^M ... Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29294
2022-07-05Add gdb.Objfile.is_file attributeTom Tromey4-0/+36
Sometimes an objfile comes from memory and not from a file. It can be useful to be able to check this from Python, so this patch adds a new "is_file" attribute.
2022-07-05Make 'import gdb.events' workTom Tromey6-22/+37
Pierre-Marie noticed that, while gdb.events is a Python module, it can't be imported. This patch changes how this module is created, so that it can be imported, while also ensuring that the module is always visible, just as it was in the past. This new approach required one non-obvious change -- when running gdb.base/warning.exp, where --data-directory is intentionally not found, the event registries can now be nullptr. Consequently, this patch probably also requires https://sourceware.org/pipermail/gdb-patches/2022-June/189796.html Note that this patch obsoletes https://sourceware.org/pipermail/gdb-patches/2022-June/189797.html
2022-07-05gdb: LoongArch: add orig_a0 into register setXi Ruoyao8-3/+19
The basic support for LoongArch has been merged into the upstream Linux kernel since 5.19-rc1 on June 5, 2022. This commit adds orig_a0 which is added into struct user_pt_regs [1] to match the upstream kernel, and then the upstream GDB will work with the upstream kernel. Note that orig_a0 was added into struct user_pt_regs in the development cycle for merging LoongArch port into the upstream Linux kernel, so earlier kernels (notably, the product kernel with version 4.19 used in distros like UOS and Loongnix) don't have it. Inspect arch/loongarch/include/uapi/asm/ptrace.h in the kernel tree to make sure. To build upstream GDB for a kernel lacking orig_a0, it's necessary to revert this commit locally. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/loongarch/include/uapi/asm/ptrace.h#n24 Signed-off-by: Xi Ruoyao <xry111@xry111.site> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2022-07-04[gdb/symtab] Add get/set functions for per_cu->lang/unit_typeTom de Vries5-121/+157
The dwarf2_per_cu_data fields lang and unit_type both have a dont-know initial value (respectively language_unknown and (dwarf_unit_type)0), which allows us to add certain checks, f.i. checking that that a field is not read before written. Add get/set member functions for the two fields as a convenient location to add such checks, make the fields private to enforce using the member functions, and add the m_ prefix. Tested on x86_64-linux.
2022-07-02[gdb/symtab] Fix data race on per_cu->dwarf_versionTom de Vries2-5/+23
When building gdb with -fsanitize=thread and gcc 12, and running test-case gdb.dwarf2/dwz.exp, we run into a data race between thread T2 and the main thread in the same write: ... Write of size 1 at 0x7b200000300c:^M #0 cutu_reader::cutu_reader(dwarf2_per_cu_data*, dwarf2_per_objfile*, \ abbrev_table*, dwarf2_cu*, bool, abbrev_cache*) gdb/dwarf2/read.c:6252 \ (gdb+0x82f3b3)^M ... which is here: ... this_cu->dwarf_version = cu->header.version; ... Both writes are called from the parallel for in dwarf2_build_psymtabs_hard, this one directly: ... #1 process_psymtab_comp_unit gdb/dwarf2/read.c:6774 (gdb+0x8304d7)^M #2 operator() gdb/dwarf2/read.c:7098 (gdb+0x8317be)^M #3 operator() gdbsupport/parallel-for.h:163 (gdb+0x872380)^M ... and this via the PU import: ... #1 cooked_indexer::ensure_cu_exists(cutu_reader*, dwarf2_per_objfile*, \ sect_offset, bool, bool) gdb/dwarf2/read.c:17964 (gdb+0x85c43b)^M #2 cooked_indexer::index_imported_unit(cutu_reader*, unsigned char const*, \ abbrev_info const*) gdb/dwarf2/read.c:18248 (gdb+0x85d8ff)^M #3 cooked_indexer::index_dies(cutu_reader*, unsigned char const*, \ cooked_index_entry const*, bool) gdb/dwarf2/read.c:18302 (gdb+0x85dcdb)^M #4 cooked_indexer::make_index(cutu_reader*) gdb/dwarf2/read.c:18443 \ (gdb+0x85e68a)^M #5 process_psymtab_comp_unit gdb/dwarf2/read.c:6812 (gdb+0x830879)^M #6 operator() gdb/dwarf2/read.c:7098 (gdb+0x8317be)^M #7 operator() gdbsupport/parallel-for.h:171 (gdb+0x8723e2)^M ... Fix this by setting the field earlier, in read_comp_units_from_section. The write in cutu_reader::cutu_reader() is still needed, in case read_comp_units_from_section is not used (run the test-case with say, target board cc-with-gdb-index). Make the write conditional, such that it doesn't trigger if the field is already set by read_comp_units_from_section. Instead, verify that the field already has the value that we're trying to set it to. Move this logic into into a member function set_version (in analogy to the already present member function version) to make sure it's used consistenly, and make the field private in order to enforce access through the member functions, and rename it to m_dwarf_version. While we're at it, make sure that the version is set before read, to avoid say returning true for "per_cu.version () < 5" if "per_cu.version () == 0". Tested on x86_64-linux.
2022-07-02[gdb/testsuite] Fix gdb.base/early-init-file.exp with -fsanitize=threadTom de Vries1-2/+17
When building gdb with -fsanitize=thread, I run into: ... FAIL: gdb.base/early-init-file.exp: check startup version string has style \ version ... due to this: ... warning: Found custom handler for signal 7 (Bus error) preinstalled.^M warning: Found custom handler for signal 8 (Floating point exception) \ preinstalled.^M warning: Found custom handler for signal 11 (Segmentation fault) \ preinstalled.^M Some signal dispositions inherited from the environment (SIG_DFL/SIG_IGN)^M won't be propagated to spawned programs.^M ... appearing before the "GNU gdb (GDB) $version" line. This is similar to the problem fixed by commit f0bbba7886f ("gdb.debuginfod/fetch_src_and_symbols.exp: fix when GDB is built with AddressSanitizer"). In that commit, the problem was fixed by starting gdb with -quiet, but using that would mean the "GNU gdb (GDB) $version" line that we're trying to check would disappear. Fix this instead by updating the regexp to allow the message. Tested on x86_64-linux.
2022-07-01GDB/doc: Remove indentation from `print -elements' completion exampleMaciej W. Rozycki1-0/+1
Remove indentation from the text of the manual after the example here: " Completion will in some cases guide you with a suggestion of what kind of argument an option expects. For example: (gdb) print -elements <TAB><TAB> NUMBER unlimited Here, the option expects a number (e.g., '100'), not literal 'NUMBER'. Such metasyntactical arguments are always presented in uppercase." as this is a continuation of the same paragraph.
2022-07-01GDB/doc: Remove extraneous spaces from completion examplesMaciej W. Rozycki1-6/+6
Completion results are usually different when the operation is applied to a word that is or is not followed by a space. In some cases they are equivalent, however a space would not be produced if completion was used earlier on in the word processed. However in the manual we have completion examples given using a space that actually prevents the example from working. E.g.: (gdb) info bre <TAB> (nothing) and: (gdb) info bre <TAB><TAB> Display all 200 possibilities? (y or n) as it now goes on to propose the entire symbol table, while: (gdb) info bre<TAB> (gdb) info breakpoints does the right thing, but is not what is shown in the manual. In other cases an extraneous space is used that does not correspond to the actual completion pattern shown, which gives an impression of sloppiness. Remove extraneous spaces then from completion examples as appropriate.
2022-06-30GDB: Add `NUMBER' completion to `set' integer commandsMaciej W. Rozycki4-1/+36
Fix a completion consistency issue with `set' commands accepting integer values and the special `unlimited' keyword: (gdb) complete print -elements print -elements NUMBER print -elements unlimited (gdb) vs: (gdb) complete set print elements set print elements unlimited (gdb) (there is a space entered at the end of both commands, not shown here) which also means if you strike <Tab> with `set print elements ' input, it will, annoyingly, complete to `set print elements unlimited' right away rather than showing a choice between `NUMBER' and `unlimited'. Add `NUMBER' then as an available completion for such `set' commands: (gdb) complete set print elements set print elements NUMBER set print elements unlimited (gdb) Adjust the testsuite accordingly. Also document the feature in the Completion section of the manual in addition to the Command Options section already there.
2022-06-30gdb/testsuite: Expand gdb.cp/mb-ctor.exp to test dynamic allocationBruno Larsen2-0/+24
When testing GDB's ability to stop in constructors, gdb.cp/mb-ctor.exp only tested objects allocated on the stack. This commit adds a couple of dynamic allocations and tests if GDB can stop in it as well.
2022-06-30gdb/doc: fix column widths in MI compatibility tableAndrew Burgess1-1/+1
In passing I noticed that the column headings for the table of MI compatibility and breaking changes, were overlapping, at least when the PDF is generated on my machine. I propose giving slightly more space to the two version number columns, this prevents the headers overlapping for me.
2022-06-29GDB/testsuite: Tighten `set print elements' error checkMaciej W. Rozycki1-1/+2
Match the whole error message expected to be given rather than omitting the part about the "unlimited" keyword. There's no point in omitting the missing part first, and second with an upcoming change the part in parentheses will no longer be a fixed string, so doing a full match will ensure the algorithm correctly builds the message expected here. Also avoid any wildcard matches.
2022-06-29GDB: Remove extraneous full stops from `set' command error messagesMaciej W. Rozycki2-9/+9
With errors given for bad commands such as `set annotate' or `set width' we produce an extraneous full stop within parentheses: (gdb) set annotate Argument required (integer to set it to.). (gdb) set width Argument required (integer to set it to, or "unlimited".). (gdb) This is grammatically incorrect, so remove the full stop and adjust the testsuite accordingly.
2022-06-29gdb/doc: improve description of --data-disassemble opcodes outputAndrew Burgess1-2/+4
Extend the description of the MI command --data-disassemble. Specifically, expand the description of the 'opcodes' field to explain how the bytes are formatted.
2022-06-29gdb/arm: Only stack S16..S31 when FPU registers are secureYvan Roux2-1/+17
The FPCCR.TS bit is used to identify if FPU registers are considered non-secure or secure. If they are secure, then callee saved registers (S16 to S31) are stacked on exception entry or otherwise skipped. Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com> Signed-off-by: Yvan Roux <yvan.roux@foss.st.com>
2022-06-29gdb/testsuite: fix gdb.base/break-idempotent.exp on ppcCarl Love1-1/+7
When running the gdb.base/break-idempotent.exp test on ppc, I was seeing some test failures (or rather errors), that looked like this: (gdb) watch local Hardware watchpoint 2: local has_hw_wp_support: Hardware watchpoint detected ERROR: no fileid for gcc2-power8 ERROR: Couldn't send delete breakpoints to GDB. ERROR OCCURED: can't read "gdb_spawn_id": no such variable while executing "expect { -i 1000 -timeout 100 -re ".*A problem internal to GDB has been detected" { fail "$message (GDB internal error)" gdb_internal_erro..." ("uplevel" body line 1) invoked from within What happens is that in break-idempotent.exp we basically do this: if {[prepare_for_testing "failed to prepare" $binfile $srcfile $opts]} { continue } # .... if {![skip_hw_watchpoint_tests]} { test_break $always_inserted "watch" } The problem with this is that skip_hw_watchpoint_tests, includes this: if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] || [istarget "ia64-*-*"] || [istarget "arm*-*-*"] || [istarget "aarch64*-*-*"] || ([istarget "powerpc*-*-linux*"] && [has_hw_wp_support]) || [istarget "s390*-*-*"] } { return 0 } For powerpc only we call has_hw_wp_support. This is a caching proc that runs a test within GDB to detect if we have hardware watchpoint support or not. Unfortunately, to run this test we restart GDB, and when the test has completed, we exit GDB. This means that in break-idempotent.exp, when we call skip_hw_watchpoint_tests for the first time on powerpc, GDB will unexpectedly be exited. When we later call delete_breakpoints we see the errors I reported above. The fix is to call skip_hw_watchpoint_tests early, before we start GDB as part of the break-idempotent.exp script, and store the result in a variable, we can then check this variable in the script as needed. After this change break-idempotent.exp runs fine on powerpc. Co-authored-by: Andrew Burgess <aburgess@redhat.com>
2022-06-28gdb+gdbserver/Linux: avoid reading registers while going through shellPedro Alves3-0/+14
For every stop, Linux GDB and GDBserver save the stopped thread's PC, in lwp->stop_pc. This is done in save_stop_reason, in both gdb/linux-nat.c and gdbserver/linux-low.cc. However, while we're going through the shell after "run", in startup_inferior, we shouldn't be reading registers, as we haven't yet determined the target's architecture -- the shell's architecture may not even be the same as the final inferior's. In gdb/linux-nat.c, lwp->stop_pc is only needed when the thread has stopped for a breakpoint, and since when going through the shell, no breakpoint is going to hit, we could simply teach save_stop_reason to only record the stop pc when the thread stopped for a breakpoint. However, in gdbserver/linux-low.cc, lwp->stop_pc is used in more cases than breakpoint hits (e.g., it's used in tracepoints & the "while-stepping" feature). So to avoid GDB vs GDBserver divergence, we apply the same approach to both implementations. We set a flag in the inferior (process in GDBserver) whenever it is being nursed through the shell, and when that flag is set, save_stop_reason bails out early. While going through the shell, we'll only ever get process exits (normal or signalled), random signals, and exec events, so nothing is lost. Change-Id: If0f01831514d3a74d17efd102875de7d2c6401ad
2022-06-28[gdb/build] Fix gdb build with -fsanitize=thread and gcc 7Tom de Vries1-1/+2
When building gdb with system gcc 7.5.0, I run into: ... gdb/ia64-tdep.c: In function ‘int is_float_or_hfa_type_recurse(type*, type**)’: gdb/ia64-tdep.c:3362:1: error: control reaches end of non-void function \ [-Werror=return-type] ... This is due to PR gcc/81275 - "-fsanitize=thread produce incorrect -Wreturn-type warning", which has been fixed in gcc-8. Work around this by moving the default return outside the switch. Tested on x86_64-linux.
2022-06-28gdb:csky add pseudo regs for float and vector regsJiangshuai Li2-0/+268
In the existing CSKY architecture, there are at most 32 floating and 16 vector registers. Float registers's count can be configured as 16 or 32. In the future, the vector registers's count may be extended to 32. The bit width of floating-point register is 64bits, and the bit width of vector register is 128bit. Special points: in fr0~fr15 and vr0~vr15, each FRx is the lower 64 bits of the corresponding VRx. Here, we will split each floating-point and vector register to 32bits wide, add the corresponding pseudo registers, and finally use them for the dwarf registers. There are 128 pseudo registers in total, s0~s127, including: 1. s0 and s1 correspond to fr0, s4 and s5 correspond to fr1, and so on. Every two separated pseudo registers correspond to a float register. 2. s0, s1, s2 and s3 correspond to vr0; s4, s5, s6 and s7 correspond to vr1, and so on. Every four pseudo registers corresponds to a vector register. Therefore, in s64~s127, there are general registers that are not actually used. This part is to prepare for the expansion of vector registers to 32 Therefore, in s64~s127, half of the registers are actually unused. This part is to prepare for the expansion of the vector register to 32.
2022-06-27gdb/testsuite: update bug numbers from Gnats to bugzillaBruno Larsen2-11/+11
Some tests link to outdated bug numbers when an XFAIL or a KFAIL happen. gdb.base/macscp.exp was referencing bug number 555, and the bug 7660 mentions that it used to be 555 on the Gnats system and seems to relate to the issue at hand. gdb.base/annota1.exp was referencing bug number 1270, and bug 8375 mentions being number 1270 on Gnats, and mentions annota1 specifically, so it seemed pretty obvious.
2022-06-27gdb/arm: Unwind Non-Secure callbacks from SecureYvan Roux1-30/+84
Without this changeset, the unwinding doesn't take into account Non-Secure to Secure stack unwinding enablement status and doesn't choose the proper SP to do the unwinding. This patch only unwinds the stack when Non-Secure to Secure unwinding is enabled, previous SP is set w/r to the current mode (Handler -> msp_s, Thread -> psp_s) and then the Secure stack is unwound. Ensure thumb bit is set in PSR when needed. Also, drop thumb bit from PC if set. Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com> Signed-off-by: Yvan ROUX <yvan.roux@foss.st.com>
2022-06-27[gdb/testsuite] Handle older python in gdb.python/py-send-packet.pyTom de Vries1-2/+6
With python 3.4, I run into: ... Traceback (most recent call last):^M File "<string>", line 1, in <module>^M File "outputs/gdb.python/py-send-packet/py-send-packet.py", line 128, in \ run_set_global_var_test^M res = conn.send_packet(b"X%x,4:\x02\x02\x02\x02" % addr)^M TypeError: Could not convert Python object: b'X%x,4:\x02\x02\x02\x02'.^M Error while executing Python code.^M ... while with python 3.6 this works fine. The type of addr is <class 'gdb.Value'>, so the first thing to try is whether changing it into a string works: ... addr_str = "%x" % addr res = conn.send_packet(b"X%s,4:\x02\x02\x02\x02" % addr_str) ... which gets us the more detailed: ... TypeError: unsupported operand type(s) for %: 'bytes' and 'str' ... Fix this by avoiding the '%' operator in the byte literal, and use instead: ... def xpacket_header (addr): return ("X%x,4:" % addr).encode('ascii') ... res = conn.send_packet(xpacket_header(addr) + b"\x02\x02\x02\x02") ... Tested on x86_64-linux, with python 3.4 and 3.6, and a backported version was tested on the gdb-12-branch in combination with python 2.7.
2022-06-27[gdb/testsuite] Fix gdb.reverse/i387-env-reverse.exp for -pieTom de Vries1-1/+1
When running test-case gdb.reverse/i387-env-reverse.exp for x86_64-linux with target board unix/-m32/-fPIE/-pie, we run into: ... (gdb) PASS: gdb.reverse/i387-env-reverse.exp: push st0 info register eax^M eax 0x56550000 1448411136^M (gdb) FAIL: gdb.reverse/i387-env-reverse.exp: verify eax == 0x8040000 ... The problem is that the tested instruction (fstsw) only sets $ax, not $eax. Fix this by verifying $ax instead of $eax. Tested on x86_64-linux with target boards unix/-m32 and unix/-m32/-fPIE/-pie.
2022-06-27[gdb/testsuite] Enable some test-cases for x86_64 -m32Tom de Vries4-173/+166
When trying to run test-case gdb.reverse/i387-env-reverse.exp for x86_64-linux with target board unix/-m32, it's skipped. Fix this by using is_x86_like_target instead of istarget "i?86-*linux*". This exposes a number of duplicates, fix those by making the test names unique. Likewise in a couple of other test-cases. Tested on x86_64-linux with target boards unix/-m32.
2022-06-27[gdb/testsuite] Workaround unnecessary .s file with gfortran 4.8Tom de Vries1-0/+6
After running test-case gdb.fortran/namelist.exp with gfortran 4.8.5, I'm left with: ... $ git sti On branch master Your branch is up to date with 'origin/master'. Untracked files: (use "git add <file>..." to include in what will be committed) gdb/testsuite/lib/compiler.s nothing added to commit but untracked files present (use "git add" to track) ... We're running into PR gcc/60447, which was fixed in gcc 4.9.0. Workaround this by first copying the source file to the temp dir, such that the .s file is left there instead: ... $ ls build/gdb/testsuite/temp/<runtest pid>/ compiler.c compiler.F90 compiler.s ... Tested on x86_64-linux.
2022-06-27[gdb/testsuite] Skip gdb.fortran/namelist.exp for gfortran 4.8Tom de Vries2-4/+12
The test-case gdb.fortran/namelist.exp uses a gfortran feature (emitting DW_TAG_namelist in the debug info) that has been supported since gfortran 4.9, see PR gcc/37132. Skip the test for gfortran 4.8 and earlier. Do this using gcc_major_version, and update it to be able to handle "gcc_major_version {gfortran-*} f90". Tested on x86_64-linux, with gfortran 4.8.5, 7.5.0, and 12.1.1.
2022-06-27[gdb/symtab] Fix parsing of .debug_str_offsets headerTom de Vries1-7/+57
When running test-case gdb.dwarf2/fission-mix.exp with target board dwarf64 and gcc-12 (defaulting to DWARF5), I run into: ... (gdb) break func2^M Offset from DW_FORM_GNU_str_index or DW_FORM_strx pointing outside of \ .debug_str.dwo section in CU at offset 0x0 [in module fission-mix]^M (gdb) FAIL: gdb.dwarf2/fission-mix.exp: break func2 ... The .debug_str_offsets section has version 5, so as per the standard it has it's own header, with initial length and version: ... Contents of the .debug_str_offsets.dwo section (loaded from fission-mix2.dwo): Length: 0x1c Version: 0x5 Index Offset [String] 0 0 build/gdb/testsuite 1 33 GNU C17 2 8f src/gdb/testsuite/gdb.dwarf2/fission-mix-2.c ... But when trying to read the string offset at index 0 in the table (which is 0), we start reading at offset 8, which points in the header, at the last 4 bytes of the initial length (it's 12 bytes because of 64-bit dwarf), as well at the 2-byte version field and 2 bytes of padding, so we get: ... (gdb) p /x str_offset $1 = 0x500000000 ... which indeed is an offset that doesn't fit in the .debug_str section. The offset 8 is based on reader->cu->header.addr_size: ... static const char * read_dwo_str_index (const struct die_reader_specs *reader, ULONGEST str_index) { ULONGEST str_offsets_base = reader->cu->header.version >= 5 ? reader->cu->header.addr_size : 0; ... which doesn't in look in agreement with the standard. Note that this happens to give the right answer for 32-bit dwarf and addr_size == 8, because then we have header size == (initial length (4) + version (2) + padding (2)) == 8. Conversely, for 32-bit dwarf and addr_size == 4 (target board unix/-m32) we run into a similar problem. It just happens to not trigger the warning, instead we get the wrong strings, like "func2" for DW_AT_producer and "build/gdb/testsuite" for DW_AT_name of the DW_TAG_compile_unit DIE. Fix this by parsing the .debug_str_offsets header in read_dwo_str_index. Add a FIXME that we should not parse this for every call. Tested on x86_64-linux.
2022-06-25Fix corrupt DWARF in dw2-double-set-die-typeTom Tromey1-31/+0
The dw2-double-set-die-type.exp test case caused an AddressSanitizer failure in the new DWARF scanner. The immediate cause was bad DWARF in the test -- in particular, the the sibling attribute here: <2><181>: Abbrev Number: 33 (DW_TAG_subprogram) <182> DW_AT_external : 1 <183> DW_AT_name : address <18b> DW_AT_type : <0x171> <18f> DW_AT_declaration : 1 <190> DW_AT_sibling : <0x1a1> ... <1><1a1>: Abbrev Number: 23 (DW_TAG_pointer_type) <1a2> DW_AT_byte_size : 4 <1a3> DW_AT_type : <0x1a7> ...points to a "sibling" DIE that is at a different child depth. Because this test case doesn't really require sibling attributes, this patch fixes the problem by removing them from the test. Note that gdb is not generally robust against malformed DWARF. Detecting and compensating for this problem would probably be expensive and, IMO, is better left to some (still hypothetical) DWARF linter.
2022-06-25Fix end of CU calculation in cooked_indexer::index_diesTom Tromey1-1/+3
cooked_indexer::index_dies incorrect computes the end of the current CU in the .debug_info. This isn't readily testable without writing intentionally corrupt DWARF, but it's apparent through observation: it is currently based on 'info_ptr', which does not always point to the start of the CU. This patch fixes the expression. Tested on x86-64 Fedora 34.
2022-06-25gdb: LoongArch: Implement loongarch_linux_syscall_next_pc()Tiezhu Yang3-0/+36
When FRAME is at a syscall instruction, return the PC of the next instruction to be executed. Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2022-06-25gdb: LoongArch: Define register numbers and clean up codeTiezhu Yang4-133/+89
This commit defines register numbers of various important registers, we can use them directly in the related code, and also clean up some code to make them more clear and readable. Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2022-06-24Eliminate TUI/CLI observers duplicationPedro Alves2-253/+64
For historical reasons, the CLI and the TUI observers are basically exact duplicates, except for the downcast: cli: struct cli_interp *cli = as_cli_interp (interp); tui: struct interp *tui = as_tui_interp (interp); and how they get at the interpreter's ui_out: cli: cli->cli_uiout tui: tui->interp_ui_out () Since interp_ui_out() is a virtual method that also works for the CLI interpreter, and, both the CLI and the TUI interpreters inherit from the same base class (cli_interp_base), we can convert the CLI observers to cast to cli_interp_base instead and use interp_ui_out() too. With that, the CLI observers will work for the TUI interpreter as well. This lets us completely eliminate the TUI observers. That's what this commit does. Change-Id: Iaf6cf12dfa200ed3ab203a895a72b69dfedbd6e0
2022-06-24Revert "Delete delete_thread_silent"Pedro Alves2-5/+27
Turns out we'll be gaining a new use of this function very soon, the incoming AMDGPU port needs it. Let's add it back, as it isn't really hurting anything. This reverts commit 39b8a8090ed7e8967ceca3655aa5f3a2ae91219d.
2022-06-24gdb/arm: Update the value of active sp when base sp changesYvan Roux1-5/+11
For Arm Cortex-M33 with security extensions, there are 4 different stacks pointers (msp_s, msp_ns, psp_s, psp_ns). When plain "sp" is updated during unwinding of the stack, the active stack pointer of the 4 stack pointers needs to be kept in sync. Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com> Signed-off-by: Yvan Roux <yvan.roux@foss.st.com>
2022-06-24gdb/testsuite: remove unneeded calls to get_compiler_infoAndrew Burgess174-714/+10
It is not necessary to call get_compiler_info before calling test_compiler_info, and, after recent commits that removed setting up the gcc_compiled, true, and false globals from get_compiler_info, there is now no longer any need for any test script to call get_compiler_info directly. As a result every call to get_compiler_info outside of lib/gdb.exp is redundant, and this commit removes them all. There should be no change in what is tested after this commit.
2022-06-24gdb/testsuite: remove global gcc_compiled from gdb.expAndrew Burgess37-177/+54
After this commit the gcc_compiled global is no longer exported from lib/gdb.exp. In theory we could switch over all uses of gcc_compiled to instead call test_compiler_info directly, however, I have instead added a new proc to gdb.exp: 'is_c_compiler_gcc'. I've then updated the testsuite to call this proc instead of using the global. Having a new proc specifically for this task means that we have a single consistent pattern for detecting gcc. By wrapping this logic within a proc that calls test_compiler_info, rather than using the global, means that test scripts don't need to call get_compiler_info before they read the global, simply calling the new proc does everything in one go. As a result I've been able to remove the get_compiler_info calls from all the test scripts that I've touched in this commit. In some of the tests e.g. gdb.dwarf2/*.exp, the $gcc_compiled flag was being checked at the top of the script to decide if the whole script should be skipped or not. In these cases I've called the new proc directly and removed all uses of gcc_compiled. In other cases, e.g. most of the gdb.base scripts, there were many uses of gcc_compiled. In these cases I set a new global gcc_compiled near the top of the script, and leave the rest of the script unchanged. There should be no changes in what is tested after this commit.
2022-06-24Include count of unexpected core files in gdb.sum summaryPedro Alves2-1/+49
If GDB, GDBserver, a testcase program, Valgrind, etc. unexpectedly crash while running the GDB testsuite, and you've setup your machine such that core files are dumped in the current directory instead of being shoved somewhere by abrt, apport, or similar (as you should for proper GDB testing), you'll end up with an unexpected core file in the $build/gdb/testsuite/ directory. It can happen that GDB, GDBserver, etc. even crashes _after_ gdb_exit, during teardown, and thus such a crash won't be noticed by looking at the gdb.sum file at all. This commit aims at improving that, by including a new "unexpected core files" line in the testrun summary. For example, here's what I get on x86-64 Ubuntu 20.04, with this patch: === gdb Summary === # of unexpected core files 12 << new info # of expected passes 107557 # of unexpected failures 35 # of expected failures 77 # of unknown successes 2 # of known failures 114 # of untested testcases 31 # of unsupported tests 139 I have my core pattern setup like this: $ cat /proc/sys/kernel/core_pattern core.%e.%p.%h.%t That's: %e: executable filename %p: pid %h: hostname %t: UNIX time of dump and so I get these core files: $ ls -1 testsuite/core.* testsuite/core.connect-with-no.216191.nelson.1656002431 testsuite/core.connect-with-no.217729.nelson.1656002431 testsuite/core.gdb.194247.nelson.1656002423 testsuite/core.gdb.226014.nelson.1656002435 testsuite/core.gdb.232078.nelson.1656002438 testsuite/core.gdb.352268.nelson.1656002441 testsuite/core.gdb.4152093.nelson.1656002337 testsuite/core.gdb.4154515.nelson.1656002338 testsuite/core.gdb.4156668.nelson.1656002339 testsuite/core.gdb.4158871.nelson.1656002341 testsuite/core.gdb.468495.nelson.1656002444 testsuite/core.vgdb.4192247.nelson.1656002366 where we can see that GDB crashed a number of times, but also Valgrind's vgdb, and a couple testcase programs. Neither of which is good. If your core_pattern is just "core" (but why??), then I guess that you may end up with just a single core file in testsuite/. Still, that is one core file too many. Above, we see a couple cores for "connect-with-no", which are the result of gdb.server/connect-with-no-symbol-file.exp. This is a case mentioned above -- while the program crashed, that happens during testcase teardown, and it goes unnoticed (without this commit) by gdb.sum results. Vis: $ make check TESTS="gdb.server/connect-with-no-symbol-file.exp" ... === gdb Summary === # of unexpected core files 2 # of expected passes 8 ... $ The tests fully passed, but still the testcase program crashed somehow: $ ls -1 testsuite/core.* testsuite/core.connect-with-no.941561.nelson.1656003317 testsuite/core.connect-with-no.941682.nelson.1656003317 Against --target_board=native-extended-gdbserver it's even worse. I get: # of unexpected core files 26 and note that when GDBserver hits an assertion failure, it exits with error, instead of crashing with SIGABRT. I think that should be changed, at least on development builds, but that would be for another patch. After such patch, I suspect the number of unexpected cores will be higher, as there are likely teardown GDBserver assertions that we're not noticing. I decided to put this new info in the "gdb Summary" section, as that's a place people already are used to looking at, either when looking at the tail of gdb.sum, or when diffing gdb.sum files, and we've already extended this section before, to include the count of DUPLICATE and PATH problems, so there's precedent. Implementation-wise, the new line is appended after DejaGnu is finished, with a shell script that is invoked by the Makefile. It is done this way so that serial and parallel testing work the same way. My initial cut at an implementation was in TCL, straight in testsuite/lib/check-test-names.exp, where DUPLICATES and PATH are handled, like so: @@ -148,6 +159,10 @@ namespace eval ::CheckTestNames { $counts(paths,$which) maybe_show_count "# of duplicate test names\t" \ $counts(duplicates,$which) + + set cores [glob -nocomplain -directory $::objdir core*] + maybe_show_count "# of unexpected core files\t" \ + [llength $cores] } But that would only work for serial testing, as in parallel testing, the final gdb.sum is generated by aggregating the results of all the individual gdb.sum files, and dg-extract-results.sh doesn't know about our new summary line. And I don't think that dg-extract-results.sh should be taught about it, since the count of core files is not something that we want to count many times, once per testcase, and then add up the subcounts at the end. Every time we count the core files, we're already counting the final count. I considered using the Tcl implementation in serial mode, and the script approach for parallel testing, but that has the obvious downside of implementing and maintaining the same thing twice. In the end, I settled on the script approach for serial mode too, which requires making the "check-single" rule print the tail end of the gdb.sum file, with a side effect being that if you look at the terminal after a run (instead of at the gdb.sum file), you'll see the "gdb Summary" section twice, once without the unexpected core lines printed, and then another with. IMO, this isn't an issue; when testing in parallel mode, if you look at the terminal after "make -jN check", you'll also see multiple "gdb Summary" sections printed. Change-Id: I190b8d41856d49ad143854b6e3e6ccd7caa04491
2022-06-24Improve core file path detection & put cores in output dirPedro Alves5-54/+117
After a testrun, I noticed that I have some kernel-produced cores for testcase programs, under build/gdb/testsuite/, which shouldn't be there: $ ls -1 testsuite/core.* testsuite/core.annota1.1274351.nelson.1656004407 testsuite/core.annota3.1288474.nelson.1656004414 testsuite/core.exitsignal.1240674.nelson.1656004391 I have my core pattern setup like this: $ cat /proc/sys/kernel/core_pattern core.%e.%p.%h.%t That's: %e: executable filename %p: pid %h: hostname %t: UNIX time of dump so it's easy to tell which program produced the core from the core file name. From above, we can tell that the corresponding testcases are gdb.base/annota1.exp, gdb.base/annota3.exp and gdb.base/exitsignal.exp. At least gdb.base/annota1.exp and gdb.base/annota3.exp have code in them to delete the core file. However, that isn't working for me, because said code only looks for cores named exactly either "core" or "core.PID", and my core_pattern doesn't match that. Another issue I noticed, is that I have not been running gdb.base/bigcore.exp, for a similar reason. I get: Program terminated with signal SIGABRT, Aborted. The program no longer exists. (gdb) PASS: gdb.base/bigcore.exp: signal SIGABRT UNTESTED: gdb.base/bigcore.exp: can't generate a core file But I actually have a core file under the testcase's output dir: $ find . -name "core.*" ./testsuite/outputs/gdb.base/bigcore/core.bigcore.2306705.nelson.1656005213 $ This commit fixes these things, by adding a find_core_file routine that searches core files in a way that works with my core pattern as well. This then also adds a convenience remove_core routine as a wrapper around find_core_file that removes the found core file. In addition, it changes some testcases that expect to have their program dump core, to switch the inferior's cwd to the testcase's output dir, so that the core is dumped there instead of in build/gdb/testsuite/. Some testcases were already doing that, but not all. The idea is that any core file dumped in build/gdb/testsuite/ is an unexpected core file. The next patch will add a count of such unexpected core files to gdb.sum. Another change is that the directory changing is now done with "set cwd" instead of with "cd". "set cwd" only affects the inferior cwd, while "cd" affects GDB's cwd too. By using "set cwd" instead of "cd", if GDB dumps core in these testcases, the GDB core dump will still end up in build/gdb/testsuite/, and can thus be detected as an unexpected core. Change-Id: I45068f21ffd4814350aaa8a3cc65cad5e3107607
2022-06-24gdb: make use of RAII in run_inferior_callAndrew Burgess1-14/+11
In passing I noticed that there are three local variables in run_inferior_call that are used to save, and then restore some state, I think these could all be replaced with a RAII style scoped_restore instead. Of the three locals that I've changed, the only one that I believe is now restored in a different location is ui::async, before this commit the async field was restored after a call to either delete_file_handle or ui_register_input_event_handler, and after this commit, the field is restored before these calls. However, I don't believe that either of these functions depend on the value of the async field, so I believe the commit is fine. Tested on x86-64/Linux passes with no regressions.
2022-06-24Delete delete_thread_silentPedro Alves2-27/+5
delete_thread_silent is no longer used anywhere. Delete it. Change-Id: Iafcec12339861d5ab2e29c14d7b1f884c9e11c0f
2022-06-23Don't declare cli_set_loggingTom Tromey1-5/+0
cli_set_logging is declared but not defined. It's probably a leftover from whenever interpreters were changed to use inheritance. This patch removes the declaration. Tested by grep and rebuilding.
2022-06-23Use PyBool_FromLongTom Tromey3-8/+4
I noticed a few spots that were explicitly creating new references to Py_True or Py_False. It's simpler here to use PyBool_FromLong, so this patch changes all the places I found.
2022-06-22Use std::string for interpreter_pTom Tromey4-31/+15
The global interpreter_p is a manually-managed 'char *'. This patch changes it to be a std::string instead, and removes some erroneous comments.
2022-06-22Move mi_interpreter to mi-interp.hTom Tromey3-51/+51
I noticed that touching interps.h caused a lot of recompilation. I tracked this down to mi-common.h including this file. This patch moves the MI interpreter to mi-interp.h, which cuts down on recompilation when modifying interps.h.
2022-06-22Use unique_xmalloc_ptr in interpTom Tromey2-8/+6
This changes interp::m_name to be a unique_xmalloc_ptr, removing some manual memory management. It also cleans up the initialization of the 'inited' member, and moves the 'private:' and 'public:' keywords to their proper spots.