aboutsummaryrefslogtreecommitdiff
path: root/gdb/nat
AgeCommit message (Collapse)AuthorFilesLines
2024-01-12Update copyright year range in header of all files managed by GDBAndrew Burgess52-52/+52
This commit is the result of the following actions: - Running gdb/copyright.py to update all of the copyright headers to include 2024, - Manually updating a few files the copyright.py script told me to update, these files had copyright headers embedded within the file, - Regenerating gdbsupport/Makefile.in to refresh it's copyright date, - Using grep to find other files that still mentioned 2023. If these files were updated last year from 2022 to 2023 then I've updated them this year to 2024. I'm sure I've probably missed some dates. Feel free to fix them up as you spot them.
2023-12-14gdb: change regcache interface to use array_viewSimon Marchi1-8/+12
Change most of regcache (and base classes) to use array_view when possible, instead of raw pointers. By propagating the use of array_view further, it enables having some runtime checks to make sure the what we read from or write to regcaches has the expected length (such as the one in the `copy(array_view, array_view)` function. It also integrates well when connecting with other APIs already using gdb::array_view. Add some overloads of the methods using raw pointers to avoid having to change all call sites at once (which is both a lot of work and risky). I tried to do this change in small increments, but since many of these functions use each other, it ended up simpler to do it in one shot than having a lot of intermediary / transient changes. This change extends into gdbserver as well, because there is some part of the regcache interface that is shared. Changing the reg_buffer_common interface to use array_view caused some build failures in nat/aarch64-scalable-linux-ptrace.c. That file currently "takes advantage" of the fact that reg_buffer_common::{raw_supply,raw_collect} operates on `void *`, which IMO is dangerous. It uses raw_supply/raw_collect directly on uint64_t's, which I guess is fine because it is expected that native code will have the same endianness as the debugged process. To accomodate that, add some overloads of raw_collect and raw_supply that work on uint64_t. This file also uses raw_collect and raw_supply on `char` pointers. Change it to use `gdb_byte` pointers instead. Add overloads of raw_collect and raw_supply that work on `gdb_byte *` and make an array_view on the fly using the register's size. Those call sites could be converted to use array_view with not much work, in which case these overloads could be removed, but I didn't want to do it in this patch, to avoid starting to dig in arch-specific code. During development, I inadvertently changed reg_buffer::raw_compare's behavior to not accept an offset equal to the register size. This behavior (effectively comparing 0 bytes, returning true) change was caught by the AArch64 SME core tests. Add a selftest to make sure that this raw_compare behavior is preserved in the future. Change-Id: I9005f04114543ddff738949e12d85a31855304c2 Reviewed-By: John Baldwin <jhb@FreeBSD.org>
2023-12-14gdb: use reg_buffer_common throughout gdbsupport/common-regcache.hSimon Marchi2-4/+2
Right now, gdbsupport/common-regcache.h contains two abstractons for a regcache. An opaque type `regcache` (gdb and gdbserver both have their own regcache that is the concrete version of this) and an abstract base class `reg_buffer_common`, that is the base of regcaches on both sides. These abstractions allow code to be written for both gdb and gdbserver, for instance in the gdb/arch sub-directory. However, having two different abstractions is impractical. If some common code has a regcache, and wants to use an operation defined on reg_buffer_common, it can't. It would be better to have just one. Change all instances of `regcache *` in gdbsupport/common-regcache.h to be `reg_buffer_common *`, then fix fallouts. Implementations in gdb and gdbserver now need to down-cast (using gdb::checked_static_cast) from reg_buffer_common to their concrete regcache type. Some of them could be avoided by changing free functions (like regcache_register_size) to be virtual methods on reg_buffer_common. I tried it, it seems to work, but I did not include it in this series to avoid adding unnecessary changes. Change-Id: Ia5503adb6b5509a0f4604bd2a68b4642cc5283fd Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-12-01Use gdb_dir_up in linux_proc_attach_tgid_threadsTom Tromey1-6/+3
This changes linux_proc_attach_tgid_threads to use gdb_dir_up. This makes it robust against exceptions. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-12-01Minor cleanup in linux_proc_attach_tgid_threadsTom Tromey1-1/+1
linux_proc_attach_tgid_threads computes a file name, and then re-computes it for a warning. It is better to reuse the already-computed name here. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-11-29Remove gdb_static_assertTom Tromey1-5/+5
C++17 makes the second parameter to static_assert optional, so we can remove gdb_static_assert now.
2023-11-29Use C++17 [[fallthrough]] attributeTom Tromey3-5/+4
This changes gdb to use the C++17 [[fallthrough]] attribute rather than special comments. This was mostly done by script, but I neglected a few spellings and so also fixed it up by hand. I suspect this fixes the bug mentioned below, by switching to a standard approach that, presumably, clang supports. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23159 Approved-By: John Baldwin <jhb@FreeBSD.org> Approved-By: Luis Machado <luis.machado@arm.com> Approved-By: Pedro Alves <pedro@palves.net>
2023-11-28[gdb] Fix segfault in for_each_block, part 2Tom de Vries1-0/+2
The previous commit describes PR gdb/30547, a segfault when running test-case gdb.base/vfork-follow-parent.exp on powerpc64 (likewise on s390x). The root cause for the segmentation fault is that linux_is_uclinux gives an incorrect result: it returns true instead of false. So, why does linux_is_uclinux: ... int linux_is_uclinux (void) { CORE_ADDR dummy; return (target_auxv_search (AT_NULL, &dummy) > 0 && target_auxv_search (AT_PAGESZ, &dummy) == 0); ... return true? This is because ppc_linux_target_wordsize returns 4 instead of 8, causing ppc_linux_nat_target::auxv_parse to misinterpret the auxv vector. So, why does ppc_linux_target_wordsize: ... int ppc_linux_target_wordsize (int tid) { int wordsize = 4; /* Check for 64-bit inferior process. This is the case when the host is 64-bit, and in addition the top bit of the MSR register is set. */ long msr; errno = 0; msr = (long) ptrace (PTRACE_PEEKUSER, tid, PT_MSR * 8, 0); if (errno == 0 && ppc64_64bit_inferior_p (msr)) wordsize = 8; return wordsize; } ... return 4? Specifically, we get this result because because tid == 0, so we get errno == ESRCH. The tid == 0 is caused by the switch_to_no_thread in handle_vfork_child_exec_or_exit: ... /* Switch to no-thread while running clone_program_space, so that clone_program_space doesn't want to read the selected frame of a dead process. */ scoped_restore_current_thread restore_thread; switch_to_no_thread (); inf->pspace = new program_space (maybe_new_address_space ()); ... but moving the maybe_new_address_space call to before that gives us the same result. The tid is no longer 0, but we still get ESRCH because the thread has exited. Fix this in handle_vfork_child_exec_or_exit by doing the maybe_new_address_space call in the context of the vfork parent. Tested on top of trunk on x86_64-linux and ppc64le-linux. Tested on top of gdb-14-branch on ppc64-linux. Co-Authored-By: Simon Marchi <simon.marchi@polymtl.ca> PR gdb/30547 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30547
2023-11-27Introduce throw_winerror_with_nameTom Tromey1-4/+2
This introduces throw_winerror_with_name, a Windows analog of perror_with_name, and changes various places in gdb to call it. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30770
2023-11-21gdb: Replace gdb::optional with std::optionalLancelot Six3-9/+9
Since GDB now requires C++17, we don't need the internally maintained gdb::optional implementation. This patch does the following replacing: - gdb::optional -> std::optional - gdb::in_place -> std::in_place - #include "gdbsupport/gdb_optional.h" -> #include <optional> This change has mostly been done automatically. One exception is gdbsupport/thread-pool.* which did not use the gdb:: prefix as it already lives in the gdb namespace. Change-Id: I19a92fa03e89637bab136c72e34fd351524f65e9 Approved-By: Tom Tromey <tom@tromey.com> Approved-By: Pedro Alves <pedro@palves.net>
2023-11-21gdb: Use C++17's std::make_unique instead of gdb::make_uniqueLancelot Six1-2/+2
gdb::make_unique is a wrapper around std::make_unique when compiled with C++17. Now that C++17 is required, use std::make_unique directly in the codebase, and remove gdb::make_unique. Change-Id: I80b615e46e4b7c097f09d78e579a9bdce00254ab Approved-By: Tom Tromey <tom@tromey.com> Approved-By: Pedro Alves <pedro@palves.net
2023-11-06Remove EXTERN_C and related definesTom Tromey1-1/+1
common-defs.h has a few defines that I suspect were used during the transition to C++. These aren't needed any more, so remove them. Tested by rebuilding. Approved-By: Simon Marchi <simon.marchi@efficios.com> Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-10-25gdb/nat/aarch64-scalable-linux-ptrace.h: Don't include itselfThiago Jung Bauermann1-1/+0
GCC doesn't complain, but it's still wrong.
2023-10-16nat/x86-cpuid.h: Remove non-x86 fallbacksJohn Baldwin1-22/+0
This header is only suitable for use on x86 hosts and is only included there, so these fallbacks should not be needed. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-10-13[aarch64] Use SVE_VQ_BYTES instead of __SVE_VQ_BYTESLuis Machado1-4/+4
__SVE_VQ_BYTES is only available if SVE definitions are available in the system's headers, and this is not true for all systems. For this purpose, we define SVE_VQ_BYTES. This patch fixes the name of the constant being used.
2023-10-04sme2: Enable SME2 for AArch64 gdb on LinuxLuis Machado2-0/+160
SME2 defines a new 512-bit register named ZT0, and it is only available if SME is also supported. The ZT0 state is valid only if the SVCR ZA bit is enabled. Otherwise its contents are empty (0). The target description is dynamic and gets generated at runtime based on the availability of the feature. Validated under Fast Models. Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2023-10-04sme: Signal frame supportLuis Machado1-1/+4
Teach gdb about the ZA/SSVE state on signal frames and how to restore the contents of the registers. There is a new ZA_MAGIC context that the Linux Kernel uses to communicate the ZA register state to gdb. The SVE_MAGIC context has also been adjusted to contain a flag indicating whether it is a SVE or SSVE state. Regression-tested on aarch64-linux Ubuntu 22.04/20.04. Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2023-10-04sme: Enable SME registers and pseudo-registersLuis Machado3-34/+703
The SME (Scalable Matrix Extension) [1] exposes a new matrix register ZA with variable sizes. It also exposes a new mode called streaming mode. Similarly to SVE, the ZA register size is dictated by a vector length, but the SME vector length is called streaming vetor length. The total size for ZA in a given moment is svl x svl. In streaming mode, the SVE registers have their sizes based on svl rather than the regular vector length (vl). The feature detection is controlled by the HWCAP2_SME bit, but actual support should be validated by attempting a ptrace call for one of the new register sets: NT_ARM_ZA and NT_ARM_SSVE. Due to its large size, the ZA register is exposed as a vector of bytes, but we introduce a number of pseudo-registers that gives various different views into the ZA contents. These can be arranged in a couple categories: tiles and tile slices. Tiles are matrices the same size or smaller than ZA. Tile slices are vectors which map to ZA's rows/columns in different ways. A new dynamic target description is provided containing the ZA register, the SVG register and the SVCR register. The size of ZA, like the SVE vector registers, is based on the vector length register SVG (VG for SVE). This patch enables SME register support for gdb. [1] https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/scalable-matrix-extension-armv9-a-architecture Co-Authored-By: Ezra Sitorus <ezra.sitorus@arm.com> Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2023-10-04refactor: Simplify SVE interface to read/write registersLuis Machado2-82/+147
This is a patch in preparation to upcoming patches enabling SME support. It attempts to simplify the gdb/gdbserver shared interface used to read/write SVE registers. Where the current code makes use of unique_ptr, allocating a new buffer by hand and passing a buffer around, this patch makes that code use gdb::byte_vector and passes a reference to this byte vector to the functions, allowing the functions to have ready access to the size of the buffer. It also shares a bit more code between gdb and gdbserver, in particular around handling of ptrace get/set requests for SVE. I think gdbserver could be refactored to handle register reads/writes more like gdb's native layer as opposed to letting the generic linux-low layer do the ptrace calls. This is not very flexible and assumes one size for the responses. If you have something like NT_ARM_SVE, where you can have either FPSIMD or SVE contents, it doesn't work that well. I didn't want to change that interface right now as it is a bit too much work and touches all the targets, some of which I can't easily test. Hence the reason why the buffer the generic linux-now passes down to linux-aarch64-low is unused or ignored. No user-visible changes should happen as part of this refactor other than a slightly reworded warning message. While doing the refactor, I also noticed what seems to be a mistake in checking if the register cache contains active (non-zero) SVE data. For instance, the original code did something like this in aarch64_sve_regs_copy_from_reg_buf: has_sve_state |= reg_buf->raw_compare (AARCH64_SVE_Z0_REGNUM + i reg, sizeof (__int128_t)); "reg" is a zeroed-out buffer that we compare the Z register contents past the first 128 bits. The problem here is that raw_compare returns 1 if the contents compare the same, which means has_sve_state will be true. But if we compared the Z register contents to 0, it means we *do not* have SVE state, and therefore has_sve_state should be false. The consequence of this mistake is that we convert the initial FPSIMD-formatted data we get from ptrace for the NT_ARM_SVE register set to a SVE-formatted one. In the end, this doesn't cause user-visible differences because the values of both the Z and V registers will still be the same. But the logic is not correct. I used the opportunity to fix this, and it gets tested later on by the additional SME tests. I do plan on submitting some SVE-specific tests to make sure we have a bit more coverage in GDB's testsuite. Regression-tested on aarch64-linux Ubuntu 22.04/20.04. Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2023-10-04refactor: Rename SVE-specific filesLuis Machado3-17/+22
In preparation to the SME support patches, rename the SVE-specific files to something a bit more meaningful that can be shared with the SME code. In this case, I've renamed the "sve" in the names to "scalable". No functional changes. Regression-tested on aarch64-linux Ubuntu 22.04/20.04. Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
2023-09-28gdb/x86: use size of XSAVE area of enabled featuresSimon Marchi1-3/+3
Since commit b42405a1594 ("gdb: Update x86 Linux architectures to support XSAVE layouts."), the test gdb.base/gcore.exp fails on my AMD Ryzen 3700X machine: FAIL: gdb.base/gcore.exp: corefile restored all registers The test gets the register state (saves the output of "info all-registers"), saves a core with the "gcore" command, loads the core, and checks the register state against the one previously saved. The problem is that when reading registers from the core file, the last half of ymm registers is unavailable: (gdb) print $ymm0.v32_int8 $1 = {0, -77, -23, -9, -1, 127, 0, 0, 0, -77, -23, -9, -1, 127, 0, 0, <unavailable> <repeats 16 times>} One strange thing with this machine is that the bitset of state components supported by XCR0 is 0x207, meaning "x87 | SSE | AVX | PKRU", but XCR0 at runtime is 0x7, meaning "x87 | SSE | AVX". So, PKRU appears to be supported by the processor, but disabled by the kernel. I didn't find why yet. From CPUID leaf EAX=0Dh, ECX=00h, GDB can get: - from EBX: max size of the XSAVE area required by features currently enabled in XCR0. On my machine, it's 0x340 (832). - from ECX: max size of the XSAVE area required by all features supported by XCR0. On my machine, it's 0x380 (896). At runtime, GDB uses ECX (max size required by all supported features) to fill the x86_xsave_layout::sizeof_xsave. So, when writing the core file note for the XSAVE state, it writes a note of size 896, even though it doesn't write the PKRU state. When loading back the core, GDB tries to figure out the layout of the XSAVE area based on what features are enabled in XCR0 and the size of the note (the size of the XSAVE area). Since my combination of XCR0 and size of XSAVE area doesn't match any combination known by GDB, GDB falls back to a gdbarch supporting only x87 and SSE. This patch changes GDB to populate the x86_xsave_layout::sizeof_xsave field (and consequently the size of the XSAVE state note in core files) using EBX, the size of the XSAVE area required by currently enabled features in XCR0. This makes i387_guess_xsave_layout recognize my case with this condition: else if (HAS_AVX (xcr0) && xsave_size == 832) { /* Intel and AMD CPUs supporting AVX. */ layout.avx_offset = 576; } In other words, just as if my machine didn't support PKRU at all. Another reason why I think this change makes sense is that XSAVE state notes in kernel-generated cores on this machine have size 832. So this change makes GDB-generated cores more similar to kernel-generated ones, reducing the diversity of XSAVE state notes that GDB needs to be able to figure out. Note that if PKRU was enabled on my machine, then the effective XSAVE area size would be 896 bytes. We would need to add a case in i387_guess_xsave_layout for that combination, since there is no currently. But I don't have a way to test that right now, since I don't know why PKRU is disabled. Relevant review note from John Baldwin: One further note is that the Linux x86 arches use x86_xsave_length() to infer ("guess") the size of the XSAVE register set that the Linux kernel writes out in core dumps. On FreeBSD x86 arches, GDB is able to query this size directly from the kernel via ptrace. My use of ECX for this guess earlier was just not the best guess. In the case that the kernel enables all of the available features, then ECX and EBX have the same values, so this only matters for a system where the kernel has enabled a subset of available XSAVE extensions. Change-Id: If64f30307f3a2e5ca3e1fd1cb7379ea840805a85 Reviewed-By: John Baldwin <jhb@FreeBSD.org>
2023-09-20Remove explanatory comments from includesTom Tromey3-3/+3
I noticed a comment by an include and remembered that I think these don't really provide much value -- sometimes they are just editorial, and sometimes they are obsolete. I think it's better to just remove them. Tested by rebuilding. Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-09-11gdb: c++ify btrace_target_infoMarkus Metzger2-130/+89
Following the example of private_thread_info and private_inferior, turn struct btrace_target_info into a small class hierarchy. Also merge btrace_tinfo_bts with btrace_tinfo_pt and inline into linux_btrace_target_info. Fixes PR gdb/30751.
2023-08-29[gdb/build] Fix C inclusion of nat/x86-cpuid.hTom de Vries1-0/+12
When running test-case gdb.arch/i386-avx512.exp, I run into: ... gdb compile failed, In file included from gdb.arch/i386-avx512.c:20:0: src/gdb/nat/x86-cpuid.h: In function 'x86_cpuid_count': src/gdb/nat/x86-cpuid.h:63:16: error: \ 'nullptr' undeclared (first use in this function) if (__eax == nullptr) ^~~~~~~ src/gdb/nat/x86-cpuid.h:63:16: note: each \ undeclared identifier is reported only once for each function it appears in === gdb Summary === # of untested testcases 1 ... This is due to commit e85aad4ae76 ("nat/x86-cpuid.h: Add x86_cpuid_count wrapper around __get_cpuid_count"), which introduced the nullptr check. The header file gdb/nat/x86-cpuid.h is a file that is included in the build and compiled as a C++ file, but also in the testsuite and compiled as a C file. Fix this by replacing nullptr with (void *)0. Tested on x86_64-linux. Co-Authored-By: Kevin Buettner <kevinb@redhat.com> Approved-by: Kevin Buettner <kevinb@redhat.com>
2023-08-28x86 nat: Add helper functions to save the XSAVE layout for the host.John Baldwin2-0/+102
x86_xsave_length returns the total length of the XSAVE state area standard format as queried from CPUID. x86_fetch_xsave_layout uses CPUID to query the offsets of XSAVE extended regions from the running host. The total length of the XSAVE state area can either be supplied by the caller if known (e.g. from FreeBSD's PT_GETXSTATEINFO) or it can be queried from the running host using x86_xsave_length. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-08-28nat/x86-cpuid.h: Add x86_cpuid_count wrapper around __get_cpuid_count.John Baldwin1-0/+32
Approved-By: Simon Marchi <simon.marchi@efficios.com>
2023-06-20Use std::string in linux-osdata.cTom Tromey1-36/+15
I found some code in linux-osdata that manually managed a string. Replacing this with std::string simplifies it. Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-06-05[gdb] Fix more typosTom de Vries1-1/+1
Fix some more typos: - distinquish -> distinguish - actualy -> actually - singe -> single - frash -> frame - chid -> child - dissassembler -> disassembler - uninitalized -> uninitialized - precontidion -> precondition - regsiters -> registers - marge -> merge - sate -> state - garanteed -> guaranteed - explictly -> explicitly - prefices (nonstandard plural) -> prefixes - bondary -> boundary - formated -> formatted - ithe -> the - arrav -> array - coresponding -> corresponding - owend -> owned - fials -> fails - diasm -> disasm - ture -> true - tpye -> type There's one code change, the name of macro SIG_CODE_BONDARY_FAULT changed to SIG_CODE_BOUNDARY_FAULT. Tested on x86_64-linux.
2023-06-03[gdb] Fix typosTom de Vries3-3/+3
Fix a few typos: - implemention -> implementation - convertion(s) -> conversion(s) - backlashes -> backslashes - signoring -> ignoring - (un)ambigious -> (un)ambiguous - occured -> occurred - hidding -> hiding - temporarilly -> temporarily - immediatelly -> immediately - sillyness -> silliness - similiar -> similar - porkuser -> pokeuser - thats -> that - alway -> always - supercede -> supersede - accomodate -> accommodate - aquire -> acquire - priveleged -> privileged - priviliged -> privileged - priviledges -> privileges - privilige -> privilege - recieve -> receive - (p)refered -> (p)referred - succesfully -> successfully - successfuly -> successfully - responsability -> responsibility - wether -> whether - wich -> which - disasbleable -> disableable - descriminant -> discriminant - construcstor -> constructor - underlaying -> underlying - underyling -> underlying - structureal -> structural - appearences -> appearances - terciarily -> tertiarily - resgisters -> registers - reacheable -> reachable - likelyhood -> likelihood - intepreter -> interpreter - disassemly -> disassembly - covnersion -> conversion - conviently -> conveniently - atttribute -> attribute - struction -> struct - resonable -> reasonable - popupated -> populated - namespaxe -> namespace - intialize -> initialize - identifer(s) -> identifier(s) - expection -> exception - exectuted -> executed - dungerous -> dangerous - dissapear -> disappear - completly -> completely - (inter)changable -> (inter)changeable - beakpoint -> breakpoint - automativ -> automatic - alocating -> allocating - agressive -> aggressive - writting -> writing - reguires -> requires - registed -> registered - recuding -> reducing - opeartor -> operator - ommitted -> omitted - modifing -> modifying - intances -> instances - imbedded -> embedded - gdbaarch -> gdbarch - exection -> execution - direcive -> directive - demanged -> demangled - decidely -> decidedly - argments -> arguments - agrument -> argument - amespace -> namespace - targtet -> target - supress(ed) -> suppress(ed) - startum -> stratum - squence -> sequence - prompty -> prompt - overlow -> overflow - memember -> member - languge -> language - geneate -> generate - funcion -> function - exising -> existing - dinking -> syncing - destroh -> destroy - clenaed -> cleaned - changep -> changedp (name of variable) - arround -> around - aproach -> approach - whould -> would - symobl -> symbol - recuse -> recurse - outter -> outer - freeds -> frees - contex -> context Tested on x86_64-linux. Reviewed-By: Tom Tromey <tom@tromey.com>
2023-06-02[AArch64] Fix architecture debug version constant thinkosLuis Machado1-2/+2
Caught this during emulator testing. Fix the constants. They should be 0xa and 0xb as opposed to 0x10 and 0x11. There was a thinko while defining them. Obvious enough. Tested on aarch64-linux Ubuntu 20.04/22.04.
2023-04-26Add new debug architecture versionLuis Machado2-0/+4
Teach gdb about a new debug architecture version for AArch64 (0x11). No user-visible changes. Regression-tested on aarch64-linux Ubuntu 20.04/22.04. Signed-off-by: Luis Machado <luis.machado@arm.com>
2023-04-14debug registers: Add missing debug version entry for FEAT_Debugv8p8Luis Machado2-0/+3
The Arm Architecture Reference Manual defines debug version 0b1010 for FEAT_Debugv8p8. This is used to identify valid hardware debug registers. gdb currently only knows about versions up to FEAT_Debugv8p4. This patch teaches gdb about this new version. No visible changes should happen as consequence of this patch, but in the future gdb will be able to identify debug registers in newer hardware. Regression-tested on aarch64-linux Ubuntu 20.04/22.04.
2023-04-03[aarch64] tpidr2: Fix erroneous detection logic for TPIDR2Luis Machado1-7/+7
The detection logic for TPIDR2 was implemented incorrectly. Originally the detection was supposed to be through a ptrace error code, but in reality, for backwards compatibility, the detection should be based on the size of the returned iovec. For instance, if a target supports both TPIDR and TPIDR2, ptrace will return a iovec size of 16. If a target only supports TPIDR and not TPIDR2, it will return a iovec size of 8, even if we asked for 16 bytes. This patch fixes this issue in code that is shared between gdb and gdbserver, therefore both gdb and gdbserver are fixed. Tested on AArch64/Linux Ubuntu 20.04.
2023-02-24Remove struct bufferTom Tromey3-4/+0
I've long wanted to remove 'struct buffer', and thanks to Simon's earlier patch, I was finally able to do so. My feeling has been that gdb already has several decent structures available for growing strings: std::string of course, but also obstack and even objalloc from BFD and dyn-string from libiberty. The previous patches in this series removed all the uses of struct buffer, so this one can remove the code and the remaining #includes.
2023-01-01Update copyright year range in header of all files managed by GDBJoel Brobecker50-50/+50
This commit is the result of running the gdb/copyright.py script, which automated the update of the copyright year range for all source files managed by the GDB project to be updated to include year 2023.
2022-12-23Fix MinGW build using mingw.org's MinGWEli Zaretskii1-1/+5
This allows to build GDB even though the default value of _WIN32_WINNT is lower than the one needed to expose some new APIs used here, and leave the test for their actual support to run time. * gdb/nat/windows-nat.c (EXTENDED_STARTUPINFO_PRESENT): Define if not defined. (create_process_wrapper): Use 'gdb_lpproc_thread_attribute_list' instead of 'PPROC_THREAD_ATTRIBUTE_LIST' (which might not be defined at compile time). This fixes compilation error using mingw.org's MinGW.
2022-12-16gdb: convert linux-osdata.c from buffer to std::stringSimon Marchi1-139/+148
Replace the use of struct buffer in linux-osdata.c with std::string. There is no change in the logic, so there should be no user-visible change. Change-Id: I27f53165d401650bbd0bebe8ed88221e25545b3f Approved-By: Pedro Alves <pedro@palves.net>
2022-12-09[aarch64] Add TPIDR2 register support for LinuxLuis Machado2-0/+25
With the AArch64 Scalable Matrix Extension we have a new TPIDR2 register, and it will be added to the existing NT_ARM_TLS register set. Kernel patches are being reviewed here: https://lore.kernel.org/linux-arm-kernel/20220818170111.351889-1-broonie@kernel.org/ From GDB's perspective, we handle it in a similar way to the existing TPIDR register. But we need to consider cases of systems that only have TPIDR and systems that have both TPIDR and TPIDR2. With that in mind, the following patch adds the required code to support TPIDR2 and turns the org.gnu.gdb.aarch64.tls feature into a dynamically-generated target description as opposed to a static target description containing only TPIDR. That means we can remove the gdb/features/aarch64-tls.xml file and replace the existing gdb/features/aarch64-tls.c auto-generated file with a new file that dynamically generates the target description containing either TPIDR alone or TPIDR and TPIDR2. In the future, when *BSD's start to support this register, they can just enable it as is being done for the AArch64 Linux target. The core file read/write code has been updated to support TPIDR2 as well. On GDBserver's side, there is a small change to the find_regno function to expose a non-throwing version of it. It always seemed strange to me how find_regno causes the whole operation to abort if it doesn't find a particular register name. The patch moves code from find_regno into find_regno_no_throw and makes find_regno call find_regno_no_throw instead. This allows us to do register name lookups to find a particular register number without risking erroring out if nothing is found. The patch also adjusts the feature detection code for aarch64-fbsd, since the infrastructure is shared amongst all aarch64 targets. I haven't added code to support TPIDR2 in aarch64-fbsd though, as I'm not sure when/if that will happen.
2022-11-08gdb/linux-nat: get core count using /sys/devices/system/cpu/possibleSimon Marchi1-4/+66
I get this test failure on my CI; FAIL: gdb.base/info-os.exp: get process list The particularity of this setup is that builds are done in containers who are allocated 4 CPUs on a machine that has 40. The code in nat/linux-osdata.c fails to properly fetch the core number for each task. linux_xfer_osdata_processes uses `sysconf (_SC_NPROCESSORS_ONLN)`, which returns 4, so it allocates an array of 4 integers. However, the core numbers read from /proc/pid/task/tid/stat, by function linux_common_core_of_thread, returns a value anywhere between 0 and 39. The core numbers above 3 are therefore ignored, many processes end up with no core value, and the regexp in the test doesn't match (it requires an integer as the core field). The way this the CPUs are exposed to the container is that the container sees 40 CPUs "present" and "possible", but only 4 arbitrary CPUs actually online: root@ci-node-jammy-amd64-04-08:~# cat /sys/devices/system/cpu/present 0-39 root@ci-node-jammy-amd64-04-08:~# cat /sys/devices/system/cpu/online 5,11,24,31 root@ci-node-jammy-amd64-04-08:~# cat /sys/devices/system/cpu/possible 0-39 The solution proposed in this patch is to find out the number of possible CPUs using /sys/devices/system/cpu/possible. In practice, this will probably always contain `0-N`, where N is the number of CPUs, minus one. But the documentation [1] doesn't such guarantee, so I'll assume that it can contain a more complex range list such as `2,4-31,32-63`, like the other files in that directory can have. The solution is to iterate over these numbers to find the highest possible CPU id, and use that that value plus one as the size of the array to allocate. [1] https://www.kernel.org/doc/Documentation/admin-guide/cputopology.rst Change-Id: I7abce2e43b000c1327fa94cd7b99d46e49d7ccf3
2022-11-08gdbsupport, gdb: add read_text_file_to_string, use it in ↵Simon Marchi1-31/+21
linux_common_core_of_thread I would like to add more code to nat/linux-osdata.c that reads an entire file from /proc or /sys and processes it as a string afterwards. I would like to avoid duplicating the somewhat error-prone code that reads an entire file to a buffer. I think we should have a utility function that does that. Add read_file_to_string to gdbsupport/filestuff.{c,h}, and make linux_common_core_of_thread use it. I want to make the new function return an std::string, and because strtok doesn't play well with std::string (it requires a `char *`, std::string::c_str returns a `const char *`), change linux_common_core_of_thread to use std::string methods instead. Approved-By: Tom Tromey <tom@tromey.com> Change-Id: I1793fda72a82969c28b944a84acb953f74c9230a
2022-11-02Fix Cygwin build after bcb9251fJon Turney1-1/+1
Absent _UNICODE being defined (which gdb's Makefile doesn't do), windows.h will always define STARTUPINFO is as STARTUPINFOA, so this cast isn't correct when create_process expects a STARTUPINFOW parameter (i.e. in a Cygwin build). Instead write this as &info_ex.StartupInfo (which is always of the correct type).
2022-10-28gdb, btrace: fix family and model computationMarkus Metzger1-2/+4
In gdb/nat/linux-btrace.c:btrace_this_cpu() we initialize the cpu structure given to the libipt btrace decoder. We only consider the extended model field for family 0x6 and forget about family 0xf and we don't consider the extended family field. Fix it.
2022-10-19internal_error: remove need to pass __FILE__/__LINE__Pedro Alves4-27/+16
Currently, every internal_error call must be passed __FILE__/__LINE__ explicitly, like: internal_error (__FILE__, __LINE__, "foo %d", var); The need to pass in explicit __FILE__/__LINE__ is there probably because the function predates widespread and portable variadic macros availability. We can use variadic macros nowadays, and in fact, we already use them in several places, including the related gdb_assert_not_reached. So this patch renames the internal_error function to something else, and then reimplements internal_error as a variadic macro that expands __FILE__/__LINE__ itself. The result is that we now should call internal_error like so: internal_error ("foo %d", var); Likewise for internal_warning. The patch adjusts all calls sites. 99% of the adjustments were done with a perl/sed script. The non-mechanical changes are in gdbsupport/errors.h, gdbsupport/gdb_assert.h, and gdb/gdbarch.py. Approved-By: Simon Marchi <simon.marchi@efficios.com> Change-Id: Ia6f372c11550ca876829e8fd85048f4502bdcf06
2022-08-16Use strwinerror in gdb/windows-nat.cTom Tromey1-8/+14
When working on windows-nat.c, it's useful to see an error message in addition to the error number given by GetLastError. This patch moves strwinerror from gdbserver to gdbsupport, and then updates windows-nat.c to use it. A couple of minor changes to strwinerror (constify the return type and use the ARRAY_SIZE macro) are also included.
2022-07-08gdb: initialize the data_head variable to eliminate compilation warningsEnze Li1-1/+1
On a machine with gcc 12, I get this warning: CXX nat/linux-btrace.o In function ‘btrace_error linux_read_bts(btrace_data_bts*, btrace_target_info*, btrace_read_type)’, inlined from ‘btrace_error linux_read_btrace(btrace_data*, btrace_target_info*, btrace_read_type)’ at ../gdb/nat/linux-btrace.c:935:29: ../gdb/nat/linux-btrace.c:865:21: warning: ‘data_head’ may be used uninitialized [-Wmaybe-uninitialized] 865 | pevent->last_head = data_head; | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~ ../gdb/nat/linux-btrace.c: In function ‘btrace_error linux_read_btrace(btrace_data*, btrace_target_info*, btrace_read_type)’: ../gdb/nat/linux-btrace.c:792:9: note: ‘data_head’ was declared here 792 | __u64 data_head, data_tail; | ^~~~~~~~~ Fix this by initializing the 'data_head' variable. Tested by rebuilding on x86_64 openSUSE Tumbleweed with gcc 12.
2022-06-12Trivial fixes to Cygwin build after 8fea1a81Jon Turney1-1/+1
* Remove a stray semicolon * Restore dropped nullptr program argument in use of create_process() under CYGWIN
2022-06-12Simplify cygwin_buf_tJon Turney1-2/+1
Prior to c6ca3dab dropping support for Cygwin 1.5, cygwin_buf_t was defined as char for Cygwin 1.5. After that, it's always wchar_t, so just use that.
2022-06-07Use subclasses of windows_process_infoTom Tromey1-6/+6
This changes windows_process_info to use virtual methods for its callbacks, and then changes the two clients of this code to subclass this class to implement the methods. I considered using CRTP here, but that would require making the new structures visible to the compilation of of nat/windows-nat.c. This seemed like a bit of a pain, so I didn't do it. This change then lets us change all the per-inferior globals to be members of the new subclass. Note that there can still only be a single inferior -- currently there's a single global of the new type. This is just another step toward possibly implementing multi-inferior for Windows. It's possible this could be cleaned up further... ideally I'd like to move more of the data into the base class. However, because gdb supports Cygwin and gdbserver does not, and because I don't have a way to build or test Cygwin, larger refactorings are difficult.
2022-06-07Allow ASLR to be disabled on WindowsTom Tromey2-4/+149
On Windows, it is possible to disable ASLR when creating a process. This patch adds code to do this, and hooks it up to gdb's existing disable-randomization feature. Because the Windows documentation cautions that this isn't available on all versions of Windows, the CreateProcess wrapper function is updated to make the attempt, and then fall back to the current approach if it fails.
2022-06-07Introduce wrapper for CreateProcessTom Tromey2-0/+66
This is a small refactoring that introduces a wrapper for the Windows CreateProcess function. This is done to make the next patch a bit simpler.