aboutsummaryrefslogtreecommitdiff
path: root/gdb/nat
AgeCommit message (Collapse)AuthorFilesLines
2023-10-26gdb/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-13Use 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.
2022-06-02Fix Cygwin build after 0578e87fJon Turney1-1/+1
Fix Cygwin build after 0578e87f ("Remove some globals from nat/windows-nat.c"). Update code under ifdef __CYGWIN__ for globals moved to members of struct windows_process_info.
2022-06-02Fix Cygwin build after fcab5839Jon Turney1-1/+8
Fix Cygwin build after fcab5839 ("Implement pid_to_exec_file for Windows in gdbserver"). That change moves code from gdb/windows-nat.c to gdb/nat/windows-nat.c, but doesn't add the required typedefs and includes for parts of that code under ifdef __CYGWIN__.
2022-05-13Implement pid_to_exec_file for Windows in gdbserverTom Tromey2-0/+107
I noticed that gdbserver did not implement pid_to_exec_file for Windows, while gdb did implement it. This patch moves the code to nat/windows-nat.c, so that it can be shared. This makes the gdbserver implementation trivial.
2022-05-13Remove windows_process_info::idTom Tromey1-1/+0
I noticed that windows_process_info::id is only used by gdbserver, and not really necessary. This patch removes it.
2022-05-13Constify target_pid_to_exec_fileTom Tromey2-2/+2
This changes target_pid_to_exec_file and target_ops::pid_to_exec_file to return a "const char *". I couldn't build many of these targets, but did examine the code by hand -- also, as this only affects the return type, it's normally pretty safe. This brings gdb and gdbserver a bit closer, and allows for the removal of a const_cast as well.
2022-04-28Remove "typedef enum ..."Tom Tromey2-3/+3
I noticed a few spots in GDB that use "typedef enum". However, in C++ this isn't as useful, as the tag is automatically entered as a typedef. This patch removes most uses of "typedef enum" -- the exceptions being in some nat-* code I can't compile, and glibc_thread_db.h, which I think is more or less a copy of some C code from elsewhere. Tested by rebuilding.
2022-04-26Handle encoding failures in Windows thread namesTom Tromey1-5/+16
Internally at AdaCore, we noticed that the new Windows thread name code could fail. First, it might return a zero-length string, but in gdb conventions it should return nullptr instead. Second, an encoding failure could wind up showing replacement characters to the user; this is confusing and not useful; it's better to recognize such errors and simply discard the name. This patch makes both of these changes.
2022-04-14Use GetThreadDescription on WindowsTom Tromey2-0/+42
Windows 10 introduced SetThreadDescription and GetThreadDescription, a simpler way to set a thread's name. This changes gdb and gdbserver to use this convention when it is available. This is part of PR win32/29050. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29050
2022-04-14Share handle_ms_vc_exception with gdbserverTom Tromey2-11/+49
Currently, gdb's native Windows target implements the exception-based approach for setting thread names, but gdbserver does not. This patch moves handle_ms_vc_exception to the shared nat/windows-nat.c code, as preparation for adding this support to gdbserver.
2022-04-14Fix possible Cygwin build problemTom Tromey1-0/+4
I noticed that nat/windows-nat.c checks __USEWIDE, but nothing sets it there -- I forgot to copy over the definition when making this file. This patch tries to fix the problem. I don't have a Cygwin setup, so I don't know whether this is sufficient, but it's probably necessary.
2022-04-14Fix regression on Windows with WOW64Tom Tromey1-1/+5
Internally at AdaCore, we recently started testing a 64-bit gdb debugging 32-bit processes. This failed with gdb head, but not with gdb 11. The tests fail like this: Starting program: [...].exe warning: Could not load shared library symbols for WOW64_IMAGE_SECTION. Do you need "set solib-search-path" or "set sysroot"? warning: Could not load shared library symbols for WOW64_IMAGE_SECTION. Do you need "set solib-search-path" or "set sysroot"? warning: Could not load shared library symbols for NOT_AN_IMAGE. Do you need "set solib-search-path" or "set sysroot"? warning: Could not load shared library symbols for NOT_AN_IMAGE. Do you need "set solib-search-path" or "set sysroot"? After some debugging and bisecting, to my surprise the bug was introduced by commit 183be222 ("gdb, gdbserver: make target_waitstatus safe"). The problem occurs in handle_exception. Previously the code did: - ourstatus->kind = TARGET_WAITKIND_STOPPED; [...] case EXCEPTION_BREAKPOINT: [...] - ourstatus->kind = TARGET_WAITKIND_SPURIOUS; [...] /* FALLTHROUGH */ case STATUS_WX86_BREAKPOINT: DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_BREAKPOINT"); - ourstatus->value.sig = GDB_SIGNAL_TRAP; [...] - last_sig = ourstatus->value.sig; However, in the new code, the fallthrough case does: + ourstatus->set_stopped (GDB_SIGNAL_TRAP); ... which changes the 'kind' in 'ourstatus' after falling through. This patch rearranges the 'last_sig' setting to more closely match what was done before (this is probably not strictly needed but also seemed harmless), and removes the fall-through in the 'ignore_first_breakpoint' case when __x86_64__ is defined.
2022-04-04Remove some globals from nat/windows-nat.cTom Tromey2-138/+135
nat/windows-nat.c has a number of globals that it uses to communicate with its clients (gdb and gdbserver). However, if we ever want the Windows ports to be multi-inferior, globals won't work. This patch takes a step toward that by moving most nat/windows-nat.c globals into a new struct windows_process_info. Many functions are converted to be methods on this object. A couple of globals remain, as they are needed to truly be global due to the way that the Windows debugging APIs work. The clients still have a global for the current process. That is, this patch is a step toward the end goal, but doesn't implement the goal itself.
2022-04-04Remove windows_thread_info destructorTom Tromey2-6/+0
windows_thread_info declares and defines a destructor, but this doesn't need to be explicit.