Commit Graph

316 Commits

Author SHA1 Message Date
Joel Brobecker
4a94e36819 Automatic Copyright Year update after running gdb/copyright.py
This commit brings all the changes made by running gdb/copyright.py
as per GDB's Start of New Year Procedure.

For the avoidance of doubt, all changes in this commits were
performed by the script.
2022-01-01 19:13:23 +04:00
Luis Machado
8a7cd1ebd7 [AArch64] Fix typo in error messages
Fix mispelling of PROT_ME to PROT_MTE in the error messages.
2021-12-21 15:05:52 -03:00
Tom de Vries
a92d031d7e [gdb/build] Fix x86_64 x32 build
A build error on x86_64 with x32 abi was reported here (
https://sourceware.org/pipermail/gdb/2021-November/049787.html ):
...
gdb/nat/amd64-linux-siginfo.c:280:42: error: \
  'struct compat_x32_siginfo_t::<unnamed union>::<unnamed>' has no member \
  named 'si_addr_bnd'
280 | #define cpt_si_lower _sifields._sigfault.si_addr_bnd._lower
| ^~~~~~~~~~~
gdb/nat/amd64-linux-siginfo.c:337:38: note: in expansion of macro 'cpt_si_lower'
337 | to->cpt_si_lower = from_ptrace.cpt_si_lower;
| ^~~~~~~~~~~~
...

The problem is that code added in commit d3d7d1ba3b "[gdb/tdep] Handle
si_addr_bnd in compat_siginfo_from_siginfo" doesn't compile on an x86_64 x32
setup, because compat_x32_siginfo_t doesn't have the si_addr_bnd fields.

Fix this conservatively by disabling the code for x32.

Tested on x86_64-linux.
2021-11-22 12:21:46 +01:00
Sergei Trofimovich
486f9e20e0 gdb/nat/linux-osdata.c: fix build on gcc-12 (string overfow)
On gcc-12 build fails as:

    ../../gdbserver/../gdb/nat/linux-osdata.c: In function 'void linux_xfer_osdata_processes(buffer*)':
    ../../gdbserver/../gdb/nat/linux-osdata.c:330:39: error:
      '__builtin___sprintf_chk' may write a terminating nul past the end of the destination [-Werror=format-overflow=]
      330 |                 sprintf (core_str, "%d", i);
          |                                       ^

It's an off-by-one case in an infeasible scenario for negative
huge core count. The change switches to std::string for memory
handling.

Tested by running 'info os processes' and checking CPU cores column.
2021-11-17 08:13:18 +00:00
Tom Tromey
0b03c6f03d Fix build on rhES5
The rhES5 build failed due to an upstream import a while back.  The
bug here is that, while the 'personality' function exists,
ADDR_NO_RANDOMIZE is only defined in <linux/personality.h>, not
<sys/personality.h>.

However, <linux/personality.h> does not declare the 'personality'
function, and <sys/personality.h> and <linux/personality.h> cannot
both be included.

This patch restores one of the removed configure checks and updates
the code to check it.

We had this as a local patch at AdaCore, because it seemed like there
was no interest upstream.  However, now it turns out that this fixes
PR build/28555, so I'm sending it now.
2021-11-09 08:21:18 -07:00
Simon Marchi
183be22290 gdb, gdbserver: make target_waitstatus safe
I stumbled on a bug caused by the fact that a code path read
target_waitstatus::value::sig (expecting it to contain a gdb_signal
value) while target_waitstatus::kind was TARGET_WAITKIND_FORKED.  This
meant that the active union field was in fact
target_waitstatus::value::related_pid, and contained a ptid.  The read
signal value was therefore garbage, and that caused GDB to crash soon
after.  Or, since that GDB was built with ubsan, this nice error
message:

    /home/simark/src/binutils-gdb/gdb/linux-nat.c:1271:12: runtime error: load of value 2686365, which is not a valid value for type 'gdb_signal'

Despite being a large-ish change, I think it would be nice to make
target_waitstatus safe against that kind of bug.  As already done
elsewhere (e.g. dynamic_prop), validate that the type of value read from
the union matches what is supposed to be the active field.

 - Make the kind and value of target_waitstatus private.
 - Make the kind initialized to TARGET_WAITKIND_IGNORE on
   target_waitstatus construction.  This is what most users appear to do
   explicitly.
 - Add setters, one for each kind.  Each setter takes as a parameter the
   data associated to that kind, if any.  This makes it impossible to
   forget to attach the associated data.
 - Add getters, one for each associated data type.  Each getter
   validates that the data type fetched by the user matches the wait
   status kind.
 - Change "integer" to "exit_status", "related_pid" to "child_ptid",
   just because that's more precise terminology.
 - Fix all users.

That last point is semi-mechanical.  There are a lot of obvious changes,
but some less obvious ones.  For example, it's not possible to set the
kind at some point and the associated data later, as some users did.
But in any case, the intent of the code should not change in this patch.

This was tested on x86-64 Linux (unix, native-gdbserver and
native-extended-gdbserver boards).  It was built-tested on x86-64
FreeBSD, NetBSD, MinGW and macOS.  The rest of the changes to native
files was done as a best effort.  If I forgot any place to update in
these files, it should be easy to fix (unless the change happens to
reveal an actual bug).

Change-Id: I0ae967df1ff6e28de78abbe3ac9b4b2ff4ad03b7
2021-10-21 16:13:56 -04:00
Andrew Pinski
add3db9182 Fix ARMv8.4 for hw watchpoint and breakpoint
Just like my previoius patch for ARMv8.1 and v8.2 (49ecef2a7d),
this adds ARMv8.4 debug arch as being compatible for hw watchpoint
and breakpoints.
2021-10-21 19:02:02 +00:00
Andrew Pinski
f81ce492b2 Refactor code slightly in nat/aarch64-linux-hw-point.c (aarch64_linux_get_debug_reg_capacity)
Since the two locations which check the debug arch are the same code currently, it is
a good idea to factor it out to a new function and just use that function from
aarch64_linux_get_debug_reg_capacity. This is also the first step to support
ARMv8.4 debug arch.
2021-10-21 19:02:01 +00:00
Simon Marchi
13084383e8 gdbsupport: make gdb_open_cloexec return scoped_fd
Make gdb_open_cloexec return a scoped_fd, to encourage using automatic
management of the file descriptor closing.  Except in the most trivial
cases, I changed the callers to just release the fd, which retains their
existing behavior.  That will allow the transition to using scoped_fd
more to go gradually, one caller at a time.

Change-Id: Ife022b403f96e71d5ebb4f1056ef6251b30fe554
2021-09-30 15:21:48 -04:00
Tom Tromey
184ea2f731 Remove defaulted 'tid' parameter to ptid_t constructor
I wanted to find, and potentially modify, all the spots where the
'tid' parameter to the ptid_t constructor was used.  So, I temporarily
removed this parameter and then rebuilt.

In order to make it simpler to search through the "real" (nonzero)
uses of this parameter, something I knew I'd have to do multiple
times, I removed any ", 0" from constructor calls.

Co-Authored-By: John Baldwin <jhb@FreeBSD.org>
2021-09-23 09:30:54 -06:00
Tom Tromey
7a2813c00b Use CORE_ADDR as return type from x86_dr_low_get_addr
On a Windows build locally, watchpoints started failing.  I tracked
this down to x86_dr_low_get_addr returning an 'unsigned long'... in
this particular build, this is a 32-bit type, but the inferior is a
64-bit program.

This patch fixes the problem by changing the return type.  No other
change is required, because this matches the function pointer in
struct x86_dr_low_type.
2021-09-03 11:30:46 -06:00
Simon Marchi
11bd012ed2 gdb: make inferior::m_cwd an std::string
Same idea as the previous patch, but for m_cwd.

To keep things consistent across the board, change get_inferior_cwd as
well, which is shared with GDBserver.  So update the related GDBserver
code too.

Change-Id: Ia2c047fda738d45f3d18bc999eb67ceb8400ce4e
2021-07-23 15:38:54 -04:00
Simon Marchi
85460c161d gdb: convert nat/x86-dregs.c macros to functions
I'm debugging why GDB crashes on OpenBSD/amd64, turns out it's because
x86_dr_low.get_status is nullptr.  It would have been useful to be able
to break on x86_dr_low_get_status, so I thought it would be a good
reason to convert these function-like macros into functions.

Change-Id: Ic200b50ef8455b4697bc518da0fa2bb704cf4721
2021-07-17 22:45:40 -04:00
Pedro Alves
c57eb1a269 nat/amd64-linux-siginfo.c: Remove typedefs
Since GDB is written in C++ now, we don't need struct/union typedefs
any more.  Remove them from nat/amd64-linux-siginfo.c.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <pedro@palves.net>

	* nat/amd64-linux-siginfo.c (union nat_sigval): Rename to ...
	(nat_sigval_t): ... this and remove typedef of same name.
	(struct nat_siginfo): Rename to ...
	(nat_siginfo_t): ... this and remove typedef of same name.
	(struct compat_sigval): Rename to ...
	(compat_sigval_t): ... this and remove typedef of same name.
	(struct compat_siginfo): Rename to ...
	(compat_siginfo_t): ... this and remove typedef of same name.
	(struct compat_x32_siginfo): Rename to ...
	(compat_x32_siginfo_t): ... this and remove typedef of same name.
	(amd64_linux_siginfo_fixup_common): Adjust.
2021-06-07 23:22:39 +01:00
Pedro Alves
d8ca8e9fac nat/amd64-linux-siginfo.c: Move align attribute from typedef to struct
Compiling GDB with current git Clang (future 13) fails with (among
other problems), this issue:

 $ make nat/amd64-linux-siginfo.o
   CXX    nat/amd64-linux-siginfo.o
 src/gdb/nat/amd64-linux-siginfo.c:590:35: warning: passing 4-byte aligned argument to 8-byte aligned parameter 1 of 'compat_x32_siginfo_from_siginfo' may result in an unaligned pointer access [-Walign-mismatch]
	 compat_x32_siginfo_from_siginfo ((struct compat_x32_siginfo *) inf,
					  ^
 1 warning generated.

The problem is that:

  - The flagged code is casting to "struct compat_x32_siginfo" pointer
    directly instead of to a pointer to the compat_x32_siginfo_t
    typedef.  The called function is declared with a
    compat_x32_siginfo_t typedef pointer parameter.

  - Only the typedef has the __aligned__ attribute.

Fix this by moving the attribute to the struct, so both struct and
typedef have the same alignment.

The next patch removes the typedefs.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <pedro@palves.net>

	* nat/amd64-linux-siginfo.c (compat_x32_siginfo_t): Move
	__attribute__ __aligned__ from the typedef to the struct.
2021-06-07 23:22:07 +01:00
Simon Marchi
24b21115f5 gdb: fix tab after space indentation issues
I spotted some indentation issues where we had some spaces followed by
tabs at beginning of line, that I wanted to fix.  So while at it, I did
a quick grep to find and fix all I could find.

gdb/ChangeLog:

	* Fix tab after space indentation issues throughout.

Change-Id: I1acb414dd9c593b474ae2b8667496584df4316fd
2021-05-27 15:18:49 -04:00
Simon Marchi
01add95bed gdb: fix some indentation issues
I wrote a small script to spot a pattern of indentation mistakes I saw
happened in breakpoint.c.  And while at it I ran it on all files and
fixed what I found.  No behavior changes intended, just indentation and
addition / removal of curly braces.

gdb/ChangeLog:

	* Fix some indentation mistakes throughout.

gdbserver/ChangeLog:

	* Fix some indentation mistakes throughout.

Change-Id: Ia01990c26c38e83a243d8f33da1d494f16315c6e
2021-05-27 15:01:28 -04:00
Tom Tromey
5917321695 Fix ubsan build
I tried a build using the undefined behavior sanitizer, and gcc gave
this error:

In file included from /usr/include/string.h:495,
                 from ../gnulib/import/string.h:41,
                 from ../../binutils-gdb/gdb/../gdbsupport/common-defs.h:95,
                 from ../../binutils-gdb/gdb/nat/linux-osdata.c:20:
In function 'char* strncpy(char*, const char*, size_t)',
    inlined from 'void time_from_time_t(char*, int, TIME_T)' at ../../binutils-gdb/gdb/nat/linux-osdata.c:923:15,
    inlined from 'void time_from_time_t(char*, int, TIME_T)' at ../../binutils-gdb/gdb/nat/linux-osdata.c:911:1,
    inlined from 'void linux_xfer_osdata_sem(buffer*)' at ../../binutils-gdb/gdb/nat/linux-osdata.c:1082:22:
/usr/include/bits/string_fortified.h:106:34: error: 'char* __builtin_strncpy(char*, const char*, long unsigned int)' specified bound 32 equals destination size [-Werror=stringop-truncation]

This patch fixes the problem by subtracting one from the length
parameter to strncpy.

I changed a couple of other similar functions -- gcc does not warn
about these, but I didn't see any substantial difference between the
different cases, and I think these are just latent warnings, to be
triggered in the future by a change to inlining heuristics.

gdb/ChangeLog
2021-05-17  Tom Tromey  <tromey@adacore.com>

	* nat/linux-osdata.c (user_from_uid, time_from_time_t)
	(group_from_gid): Subtract one from strncpy length.
2021-05-17 13:06:05 -06:00
Simon Marchi
31aceaef1c gdb, gdbserver: make status_to_str display the signal name
I was looking at some "set debug lin-lwp" logs, and saw that a thread
received the "Child exited" signal.  It took me a moment to realize that
this was SIGCHLD.  I then thought that it would be nice for
status_to_str to show the signal name (SIGCHLD) in addition to the
description "Child exited", since people are much more used to referring
to signals using their names.

Fortunately, libiberty contains a handy function to get the signal name
from the signal number, strsigno, use that.

The output of "set debug lin-lwp" now looks like:

    [linux-nat] linux_nat_wait_1: waitpid 1209631 received SIGTRAP - Trace/breakpoint trap (stopped)

gdb/ChangeLog:

	* nat/linux-waitpid.c (status_to_str): Show signal name.

Change-Id: I8ad9b1e744dd64461fd87b08d5c29f9ef97c4691
2021-05-10 12:13:36 -04:00
Simon Marchi
8d06918ff5 gdb, gdbserver: make status_to_str return std::string
Instead of using a static buffer.  This is safer, and we don't really
mind about any extra dynamic allocation here, since it's only used for
debug purposes.

gdb/ChangeLog:

	* nat/linux-waitpid.c (status_to_str): Return std::string.
	* nat/linux-waitpid.h (status_to_str): Likewise.
	* linux-nat.c (linux_nat_post_attach_wait): Adjust.
	(linux_nat_target::attach): Adjust.
	(linux_handle_extended_wait): Adjust.
	(wait_lwp): Adjust.
	(stop_wait_callback): Adjust.
	(linux_nat_filter_event): Adjust.
	(linux_nat_wait_1): Adjust.
	* nat/linux-waitpid.c (status_to_str): Adjust.
	* nat/linux-waitpid.h (status_to_str): Adjust.

gdbserver/ChangeLog:

	* linux-low.cc (linux_process_target::wait_for_event_filtered):
	Adjust to status_to_str returning std::string.

Change-Id: Ia8aead70270438a5690f243e6faafff6c38ff757
2021-05-08 21:07:20 -04:00
Pedro Alves
4655f8509f Don't run personality syscall at configure time; don't check it at all
Currently, in order to tell whether support for disabling address
space randomization on Linux is available, GDB checks if the
personality syscall works, at configure time.  I.e., it does a run
test, instead of a compile/link test:

  AC_RUN_IFELSE([PERSONALITY_TEST],
		[have_personality=true],
		[have_personality=false],

This is a bit bogus, because the machine the build is done on may not
(and is when you consider distro gdbs) be the machine that eventually
runs gdb.  It would be better if this were a compile/link test
instead, and then at runtime, GDB coped with the personality syscall
failing.  Actually, GDB already copes.

One environment where this is problematic is building GDB in a Docker
container -- by default, Docker runs the container with seccomp, with
a profile that disables the personality syscall.  You can tell Docker
to use a less restricted seccomp profile, but I think we should just
fix it in GDB.

"man 2 personality" says:

       This system call first appeared in Linux 1.1.20 (and thus first
       in a stable kernel release with Linux 1.2.0); library support
       was added in glibc 2.3.

...

       ADDR_NO_RANDOMIZE (since Linux 2.6.12)
              With this flag set, disable address-space-layout randomization.

glibc 2.3 was released in 2002.
Linux 2.6.12 was released in 2005.

The original patch that added the configure checks was submitted in
2008.  The first version of the patch that was submitted to the list
called personality from common code:

 https://sourceware.org/pipermail/gdb-patches/2008-June/058204.html

and then was moved to Linux-specific code:

 https://sourceware.org/pipermail/gdb-patches/2008-June/058209.html

Since HAVE_PERSONALITY is only checked in Linux code, and
ADDR_NO_RANDOMIZE exists for over 15 years, I propose just completely
removing the configure checks.

If for some odd reason, some remotely modern system still needs a
configure check, then we can revert this commit but drop the
AC_RUN_IFELSE in favor of always doing the AC_LINK_IFELSE
cross-compile fallback.

gdb/ChangeLog:

	* linux-nat.c (linux_nat_target::supports_disable_randomization):
	Remove references to HAVE_PERSONALITY.
	* nat/linux-personality.c: Remove references to HAVE_PERSONALITY.
	(maybe_disable_address_space_randomization)
	(~maybe_disable_address_space_randomizatio): Remove references to
	HAVE_PERSONALITY.
	* config.in, configure: Regenerate.

gdbserver/ChangeLog:

	* linux-low.cc:
	(linux_process_target::supports_disable_randomization): Remove
	reference to HAVE_PERSONALITY.
	* config.in, configure: Regenerate.

gdbsupport/ChangeLog:

	* common.m4 (personality test): Remove.
2021-05-08 13:45:36 +01:00
Tom Tromey
1bee48c7ad Make get_image_name static
The only callers of get_image_name are nat/windows-nat.c, so make it
static.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

	* nat/windows-nat.h (get_image_name): Don't declare.
	* nat/windows-nat.c (get_image_name): Now static.
2021-04-30 10:22:24 -06:00
Tom Tromey
e228ef975e Share DLL code between gdb and gdbserver
This moves the new DLL-loading code into nat/windows-nat.c, and
changes both gdb and gdbserver to use the shared code.  One
client-provided callback, handle_load_dll, is changed to allow the
code to be shared.  This callback was actually never called from
nat/windows-nat.c; maybe I had planned to share more here and then
didn't finish... I'm not sure.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (windows_nat::handle_load_dll): Update.
	(windows_nat_target::get_windows_debug_event): Call
	dll_loaded_event.
	(windows_add_all_dlls, windows_add_dll): Move to
	nat/windows-nat.c.
	* nat/windows-nat.h (handle_load_dll): Change parameters.
	(dll_loaded_event, windows_add_all_dlls): Declare.
	* nat/windows-nat.c (windows_add_dll, windows_add_all_dlls): Move
	from windows-nat.c.
	(dll_loaded_event): New function.

gdbserver/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

	* win32-low.cc (do_initial_child_stuff): Update.
	(windows_nat::handle_load_dll): Rename from win32_add_one_solib.
	Change parameter type.
	(win32_add_dll, win32_add_all_dlls)
	(windows_nat::handle_load_dll): Remove.
	(get_child_debug_event): Call dll_loaded_event.
2021-04-30 10:22:24 -06:00
Tom Tromey
de07187290 Use nat/windows-nat function indirection code
This changes gdbserver to use the function indirection code that was
just moved into nat/windows-nat.[ch].  One additional function is used
by gdbserver that was not used by gdb.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

	* nat/windows-nat.h (GenerateConsoleCtrlEvent): New define.
	(GenerateConsoleCtrlEvent_ftype, GenerateConsoleCtrlEvent):
	Declare.
	* nat/windows-nat.c (GenerateConsoleCtrlEvent): Define.
	(initialize_loadable): Initialize GenerateConsoleCtrlEvent.

gdbserver/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

	* win32-low.cc (GETPROCADDRESS): Remove.
	(winapi_DebugActiveProcessStop, winapi_DebugSetProcessKillOnExit)
	(winapi_DebugBreakProcess, winapi_GenerateConsoleCtrlEvent)
	(winapi_Wow64SetThreadContext, win32_Wow64GetThreadContext)
	(win32_Wow64SetThreadContext): Remove.
	(win32_set_thread_context, do_initial_child_stuff)
	(win32_process_target::attach, win32_process_target::detach):
	Update.
	(winapi_EnumProcessModules, winapi_EnumProcessModulesEx)
	(winapi_GetModuleInformation, winapi_GetModuleInformationA):
	Remove.
	(win32_EnumProcessModules, win32_EnumProcessModulesEx)
	(win32_GetModuleInformation, win32_GetModuleInformationA):
	Remove.
	(load_psapi): Remove.
	(win32_add_dll, win32_process_target::request_interrupt): Update.
	(initialize_low): Call initialize_loadable.
2021-04-30 10:22:24 -06:00
Tom Tromey
9e439f0098 Move function indirection code to nat/windows-nat
gdb and gdbserver both look for functions in some Windows DLLs at
runtime.  This patch moves this code out of gdb and into
nat/windows-nat, so it can be shared by both programs.

gdb/ChangeLog
2021-04-30  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c: Move code to nat/windows-nat.[ch].
	(_initialize_windows_nat): Call initialize_loadable.
	* nat/windows-nat.h (AdjustTokenPrivileges)
	(DebugActiveProcessStop, DebugBreakProcess)
	(DebugSetProcessKillOnExit, EnumProcessModules)
	(EnumProcessModulesEx, GetModuleInformation)
	(GetModuleFileNameExA, GetModuleFileNameExW)
	(LookupPrivilegeValueA, OpenProcessToken, GetConsoleFontSize)
	(GetCurrentConsoleFont, Wow64SuspendThread)
	(Wow64GetThreadContext, Wow64SetThreadContext)
	(Wow64GetThreadSelectorEntry): Move from windows-nat.c.
	(AdjustTokenPrivileges_ftype)
	(DebugActiveProcessStop_ftype, DebugBreakProcess_ftype)
	(DebugSetProcessKillOnExit_ftype, EnumProcessModules_ftype)
	(EnumProcessModulesEx_ftype, GetModuleInformation_ftype)
	(GetModuleFileNameExA_ftype, GetModuleFileNameExW_ftype)
	(LookupPrivilegeValueA_ftype, OpenProcessToken_ftype)
	(GetConsoleFontSize_ftype)
	(GetCurrentConsoleFont_ftype, Wow64SuspendThread_ftype)
	(Wow64GetThreadContext_ftype, Wow64SetThreadContext_ftype)
	(Wow64GetThreadSelectorEntry_ftype): Likewise.
	(initialize_loadable): Declare.
	* nat/windows-nat.c (AdjustTokenPrivileges)
	(DebugActiveProcessStop, DebugBreakProcess)
	(DebugSetProcessKillOnExit, EnumProcessModules)
	(EnumProcessModulesEx, GetModuleInformation, GetModuleFileNameExA)
	(GetModuleFileNameExW, LookupPrivilegeValueA, OpenProcessToken)
	(GetCurrentConsoleFont, GetConsoleFontSize, Wow64SuspendThread)
	(Wow64GetThreadContext, Wow64SetThreadContext)
	(Wow64GetThreadSelectorEntry): Define.
	(bad, bad_GetCurrentConsoleFont, bad_GetConsoleFontSize): Move
	from windows-nat.c.
	(initialize_loadable): Likewise, and rename.
2021-04-30 10:22:24 -06:00
Simon Marchi
d471748373 gdb, gdbserver: remove WinCE support code
The support for WinCE was removed with commit 84b300de36 ("gdbserver:
remove support for ARM/WinCE").  There is some leftover code for WinCE
support, guarded by the _WIN32_WCE macro, which I didn't know of at the
time.

I didn't remove the _WIN32_WCE references in the tests, because in
theory we still support the WinCE architecture in GDB (when debugging
remotely).  So someone could run a test with that (although I'd be
really surprised).

gdb/ChangeLog:

	* nat/windows-nat.c: Remove all code guarded by _WIN32_WCE.
	* nat/windows-nat.h: Likewise.

gdbserver/ChangeLog:

	* win32-low.cc: Remove all code guarded by _WIN32_WCE.
	* win32-low.h: Likewise.

Change-Id: I7a871b897e2135dc195b10690bff2a01d9fac05a
2021-04-12 11:10:57 -04:00
Luis Machado
1ef6a59696 [AArch64] Fix include order for MTE
Similarly to commit 665af52ec2, fix a build
failure seen with an updated glibc, due to the enum/constant mismatch.

The old include file order eventually makes asm/ptrace.h get included before
sys/ptrace.h.

This patch fixes it. Seems fairly obvious and I'll push it shortly.

gdb/ChangeLog:

2021-04-09  Luis Machado  <luis.machado@linaro.org>

	* nat/aarch64-mte-linux-ptrace.c: Update include file order.
2021-04-09 11:36:55 -03:00
Luis Machado
4601818e8c AArch64: Implement memory tagging target methods for AArch64
The patch implements the memory tagging target hooks for AArch64, so we
can handle MTE.

gdb/ChangeLog:

2021-03-24  Luis Machado  <luis.machado@linaro.org>

	* Makefile.in (ALL_64_TARGET_OBS): Add arch/aarch64-mte-linux.o.
	(HFILES_NO_SRCDIR): Add arch/aarch64-mte-linux.h and
	nat/aarch64-mte-linux-ptrace.h.
	* aarch64-linux-nat.c: Include nat/aarch64-mte-linux-ptrace.h.
	(aarch64_linux_nat_target) <supports_memory_tagging>: New method
	override.
	<fetch_memtags>: New method override.
	<store_memtags>: New method override.
	(aarch64_linux_nat_target::supports_memory_tagging): New method.
	(aarch64_linux_nat_target::fetch_memtags): New method.
	(aarch64_linux_nat_target::store_memtags): New method.
	* arch/aarch64-mte-linux.c: New file.
	* arch/aarch64-mte-linux.h: Include gdbsupport/common-defs.h.
	(AARCH64_MTE_GRANULE_SIZE): Define.
	(aarch64_memtag_type): New enum.
	(aarch64_mte_get_tag_granules): New prototype.
	* configure.nat (NATDEPFILES): Add nat/aarch64-mte-linux-ptrace.o.
	* configure.tgt (aarch64*-*-linux*): Add arch/aarch64-mte-linux.o.
	* nat/aarch64-mte-linux-ptrace.c: New file.
	* nat/aarch64-mte-linux-ptrace.h: New file.
2021-03-24 14:53:56 -03:00
Luis Machado
3f3bd8b8c1 AArch64: Add MTE ptrace requests
This patch adds the required ptrace request definitions into a new include
file that will be used by the next patches.

They are PTRACE_PEEKMTETAGS and PTRACE_POKEMTETAGS.

gdb/ChangeLog:

2021-03-24  Luis Machado  <luis.machado@linaro.org>

	* Makefile.in (HFILES_NO_SRCDIR): Add nat/aarch64-mte-linux-ptrace.h.
	* nat/aarch64-mte-linux-ptrace.h: New file.
2021-03-24 14:53:30 -03:00
Kevin Buettner
0f977b7715 Add comment regarding include order of <sys/ptrace.h> and <asm/ptrace.h>
I added the same comment for nat/aarch64-linux-hw-point.c yesterday.
Christian suggested adding the comment for the other file that I had
identified as including both <sys/ptrace.h> and <asm/ptrace.h>.

I searched the sources in gdb/, but found no other files which include
both of these headers.

If possible, I would prefer to see us use <sys/ptrace.h> when possible,
however, from past experience, I've found that this file does not always
contain all of the constants, etc. required by the particular source
file.

gdb/ChangeLog:

	* nat/aarch64-sve-linux-ptrace.h: Add comment regarding include
	order for <sys/ptrace.h> and <asm/ptrace.h>.
2021-02-25 15:30:32 -07:00
Kevin Buettner
268c77c1b0 Add comment regarding include order of <sys/ptrace.h> and <asm/ptrace.h>
gdb/ChangeLog:

	* nat/aarch64-linux-hw-point.c: Add comment regarding include
	order for <sys/ptrace.h> and <asm/ptrace.h>.
2021-02-24 14:35:07 -07:00
Kevin Buettner
665af52ec2 Fix aarch64-linux-hw-point.c build problem
Due to a recent glibc header file change, the file
nat/aarch64-linux-hw-point.c no longer builds on Fedora rawhide.

An enum for PTRACE_SYSEMU is now provided by <sys/ptrace.h>.  In the
past, PTRACE_SYSEMU was defined only in <asm/ptrace.h>.  This is
what it looks like...

In <asm/ptrace.h>:

 #define PTRACE_SYSEMU		  31

In <sys/ptrace.h>:

enum __ptrace_request
{
  ...
  PTRACE_SYSEMU = 31,
 #define PT_SYSEMU PTRACE_SYSEMU

  ...
}

When <asm/ptrace.h> and <sys/ptrace.h> are both included in a source
file, we run into the following build problem when the former is
included before the latter:

In file included from nat/aarch64-linux-hw-point.c:26:
/usr/include/sys/ptrace.h:86:3: error: expected identifier before numeric constant
   86 |   PTRACE_SYSEMU = 31,
      |   ^~~~~~~~~~~~~

(There are more errors after this one too.)

The file builds without error when <asm/ptrace.h> is included after
<sys/ptrace.h>.  I found that this is already done in
nat/aarch64-sve-linux-ptrace.h (which is included by
nat/aarch64-linux-ptrace.c).

I've tested this change on Fedora rawhide and Fedora 33, both
running on an aarch64 machine.

gdb/ChangeLog:

	* nat/aarch64-linux-hw-point.c: Include <asm/ptrace.h> after
	<sys/ptrace.h>.
2021-02-24 12:54:39 -07:00
Kevin Buettner
8488c357ce amd64-linux-siginfo.c: Adjust include order to avoid gnulib error
On Fedora rawhide, after updating to glibc-2.33, I'm seeing the
following build failure:

  CXX    nat/amd64-linux-siginfo.o
In file included from /usr/include/bits/sigstksz.h:24,
                 from /usr/include/signal.h:315,
                 from ../gnulib/import/signal.h:52,
                 from /ironwood1/sourceware-git/rawhide-gnulib/bld/../../worktree-gnulib/gdbserver/../gdb/nat/amd64-linux-siginfo.c:20:
../gnulib/import/unistd.h:663:3: error: #error "Please include config.h first."
  663 |  #error "Please include config.h first."
      |   ^~~~~

glibc-2.33 has changed signal.h to now include <bits/sigstksz.h> which,
in turn, includes <unistd.h>. For a gdb build, this causes the gnulib
version of unistd.h to be pulled in first.  The build failure shown
above happens because gnulib's config.h has not been included before
the include of <signal.h>.

The fix is simple - we just rearrange the order of the header file
includes to make sure that gdbsupport/commondefs.h is included before
attempting to include signal.h.  Note that gdbsupport/commondefs.h
includes <gnulib/config.h>.

Build and regression tested on Fedora 33.  On Fedora rawhide, GDB
builds again.

gdb/ChangeLog:

	* nat/amd64-linux-siginfo.c: Include "gdbsupport/common-defs.h"
	(which in turn includes <gnulib/config.h>) before include
	of <signal.h>.
2021-02-18 22:56:56 -07:00
Tom Tromey
4ef367bffd Use debug_prefixed_printf_cond in windows-nat.c
This changes windows-nat.c and nat/windows-nat.c to use the new
debug_prefixed_printf_cond facility.  I tried this out on a Windows
build and I think it makes the output look a little nicer.

2021-01-26  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (DEBUG_EXEC, DEBUG_EVENTS, DEBUG_MEM)
	(DEBUG_EXCEPT): Use debug_prefixed_printf_cond.
	(windows_init_thread_list, windows_nat::handle_load_dll)
	(windows_nat::handle_unload_dll, windows_nat_target::resume)
	(windows_nat_target::resume)
	(windows_nat_target::get_windows_debug_event)
	(windows_nat_target::interrupt, windows_xfer_memory)
	(windows_nat_target::close): Update.
	* nat/windows-nat.c (DEBUG_EVENTS): Use
	debug_prefixed_printf_cond.
	(matching_pending_stop, fetch_pending_stop)
	(continue_last_debug_event): Update.
2021-01-26 08:49:38 -07:00
Simon Marchi
6bd434d6ca gdb: make some variables static
I'm trying to enable clang's -Wmissing-variable-declarations warning.
This patch fixes all the obvious spots where we can simply add "static"
(at least, found when building on x86-64 Linux).

gdb/ChangeLog:

	* aarch64-linux-tdep.c (aarch64_linux_record_tdep): Make static.
	* aarch64-tdep.c (tdesc_aarch64_list, aarch64_prologue_unwind,
	aarch64_stub_unwind, aarch64_normal_base, ): Make static.
	* arm-linux-tdep.c (arm_prologue_unwind): Make static.
	* arm-tdep.c (struct frame_unwind): Make static.
	* auto-load.c (auto_load_safe_path_vec): Make static.
	* csky-tdep.c (csky_stub_unwind): Make static.
	* gdbarch.c (gdbarch_data_registry): Make static.
	* gnu-v2-abi.c (gnu_v2_abi_ops): Make static.
	* i386-netbsd-tdep.c (i386nbsd_mc_reg_offset): Make static.
	* i386-tdep.c (i386_frame_setup_skip_insns,
	i386_tramp_chain_in_reg_insns, i386_tramp_chain_on_stack_insns):
	Make static.
	* infrun.c (observer_mode): Make static.
	* linux-nat.c (sigchld_action): Make static.
	* linux-thread-db.c (thread_db_list): Make static.
	* maint-test-options.c (maintenance_test_options_list):
	* mep-tdep.c (mep_csr_registers): Make static.
	* mi/mi-cmds.c (struct mi_cmd_stats): Remove struct type name.
	(stats): Make static.
	* nat/linux-osdata.c (struct osdata_type): Make static.
	* ppc-netbsd-tdep.c (ppcnbsd_reg_offsets): Make static.
	* progspace.c (last_program_space_num): Make static.
	* python/py-param.c (struct parm_constant): Remove struct type
	name.
	(parm_constants): Make static.
	* python/py-record-btrace.c (btpy_list_methods): Make static.
	* python/py-record.c (recpy_gap_type): Make static.
	* record.c (record_goto_cmdlist): Make static.
	* regcache.c (regcache_descr_handle): Make static.
	* registry.h (DEFINE_REGISTRY): Make definition static.
	* symmisc.c (std_in, std_out, std_err): Make static.
	* top.c (previous_saved_command_line): Make static.
	* tracepoint.c (trace_user, trace_notes, trace_stop_notes): Make
	static.
	* unittests/command-def-selftests.c (nr_duplicates,
	nr_invalid_prefixcmd, lists): Make static.
	* unittests/observable-selftests.c (test_notification): Make
	static.
	* unittests/optional/assignment/1.cc (counter): Make static.
	* unittests/optional/assignment/2.cc (counter): Make static.
	* unittests/optional/assignment/3.cc (counter): Make static.
	* unittests/optional/assignment/4.cc (counter): Make static.
	* unittests/optional/assignment/5.cc (counter): Make static.
	* unittests/optional/assignment/6.cc (counter): Make static.

gdbserver/ChangeLog:

	* ax.cc (bytecode_address_table): Make static.
	* debug.cc (debug_file): Make static.
	* linux-low.cc (stopping_threads): Make static.
	(step_over_bkpt): Make static.
	* linux-x86-low.cc (amd64_emit_ops, i386_emit_ops): Make static.
	* tracepoint.cc (stop_tracing_bkpt, flush_trace_buffer_bkpt,
	alloced_trace_state_variables, trace_buffer_ctrl,
	tracing_start_time, tracing_stop_time, tracing_user_name,
	tracing_notes, tracing_stop_note): Make static.

Change-Id: Ic1d8034723b7802502bda23770893be2338ab020
2021-01-20 20:55:05 -05:00
Tom de Vries
d3d7d1ba3b [gdb/tdep] Handle si_addr_bnd in compat_siginfo_from_siginfo
When running test-case gdb.arch/i386-mpx-sigsegv.exp with target board
unix/-m32, we run into:
...
(gdb) continue^M
Continuing.^M
Saw a #BR! status 1 at 0x8048c2d^M
^M
Program received signal SIGSEGV, Segmentation fault^M
Upper bound violation while accessing address 0x0804c15c^M
Bounds: [lower = 0x00000000, upper = 0x00000000].^M
0x08048a4f in lower (p=0x804c160, a=0x804c180, b=0x804c1a0, c=0x804c1c0, \
  d=0x804c1e0, len=1) at i386-mpx-sigsegv.c:79^M
79        value = *(p - len);^M
(gdb) FAIL: gdb.arch/i386-mpx-sigsegv.exp: MPX signal segv Lower: 0
...

The problem is that lower and upper in the Bounds message are 0x0, which is
caused by $_siginfo._sifields._sigfault._addr_bnd.{_lower,_upper} evaluating
to 0x0.

Fix this by copying the si_lower/si_upper fields in
compat_siginfo_from_siginfo.

Tested on x86_64-linux, with target board unix/-m32.

gdb/ChangeLog:

2021-01-18  Tom de Vries  <tdevries@suse.de>

	PR tdep/27172
	* nat/amd64-linux-siginfo.c (cpt_si_lower, cpt_si_upper, SEGV_BNDERR):
	New macro.
	(compat_siginfo_from_siginfo): Copy cpt_si_lower and cpt_si_upper
	for SEGV_BNDERR.
2021-01-18 09:32:38 +01:00
Joel Brobecker
3666a04883 Update copyright year range in all GDB files
This commits the result of running gdb/copyright.py as per our Start
of New Year procedure...

gdb/ChangeLog

        Update copyright year range in copyright header of all GDB files.
2021-01-01 12:12:21 +04:00
Luis Machado
6afcd2d416 [AArch64] SVE/FPSIMD fixup for big endian
The FPSIMD dump in signal frames and ptrace FPSIMD dump in the SVE context
structure follows the target endianness, whereas the SVE dumps are
endianness-independent (LE).

Therefore, when the system is in BE mode, we need to reverse the bytes
for the FPSIMD data.

Given the V registers are larger than 64-bit, I've added a way for value
bytes to be set, as opposed to passing a 64-bit fixed quantity. This fits
nicely with the unwinding *_got_bytes function and makes the trad-frame
more flexible and capable of saving larger registers.

The memory for the bytes is allocated via the frame obstack, so it gets freed
after we're done inspecting the frame.

gdb/ChangeLog:

2020-12-10  Luis Machado  <luis.machado@linaro.org>

	* aarch64-linux-tdep.c (aarch64_linux_restore_vreg) New function.
	(aarch64_linux_sigframe_init): Call aarch64_linux_restore_vreg.
	* aarch64-tdep.h (V_REGISTER_SIZE): Move to ...
	* arch/aarch64.h: ... here.
	* nat/aarch64-sve-linux-ptrace.c: Include endian.h.
	(aarch64_maybe_swab128): New function.
	(aarch64_sve_regs_copy_to_reg_buf)
	(aarch64_sve_regs_copy_from_reg_buf): Adjust FPSIMD entries.
	* trad-frame.c (trad_frame_reset_saved_regs): Initialize
	the data field.
	(TF_REG_VALUE_BYTES): New enum value.
	(trad_frame_value_bytes_p): New function.
	(trad_frame_set_value_bytes): New function.
	(trad_frame_set_reg_value_bytes): New function.
	(trad_frame_get_prev_register): Handle register values saved as bytes.
	* trad-frame.h (trad_frame_set_reg_value_bytes): New prototype.
	(struct trad_frame_saved_reg) <data>: New field.
	(trad_frame_set_value_bytes): New prototype.
	(trad_frame_value_bytes_p): New prototype.
2020-12-10 11:45:08 -03:00
Simon Marchi
dda83cd783 gdb, gdbserver, gdbsupport: fix leading space vs tabs issues
Many spots incorrectly use only spaces for indentation (for example,
there are a lot of spots in ada-lang.c).  I've always found it awkward
when I needed to edit one of these spots: do I keep the original wrong
indentation, or do I fix it?  What if the lines around it are also
wrong, do I fix them too?  I probably don't want to fix them in the same
patch, to avoid adding noise to my patch.

So I propose to fix as much as possible once and for all (hopefully).

One typical counter argument for this is that it makes code archeology
more difficult, because git-blame will show this commit as the last
change for these lines.  My counter counter argument is: when
git-blaming, you often need to do "blame the file at the parent commit"
anyway, to go past some other refactor that touched the line you are
interested in, but is not the change you are looking for.  So you
already need a somewhat efficient way to do this.

Using some interactive tool, rather than plain git-blame, makes this
trivial.  For example, I use "tig blame <file>", where going back past
the commit that changed the currently selected line is one keystroke.
It looks like Magit in Emacs does it too (though I've never used it).
Web viewers of Github and Gitlab do it too.  My point is that it won't
really make archeology more difficult.

The other typical counter argument is that it will cause conflicts with
existing patches.  That's true... but it's a one time cost, and those
are not conflicts that are difficult to resolve.  I have also tried "git
rebase --ignore-whitespace", it seems to work well.  Although that will
re-introduce the faulty indentation, so one needs to take care of fixing
the indentation in the patch after that (which is easy).

gdb/ChangeLog:

	* aarch64-linux-tdep.c: Fix indentation.
	* aarch64-ravenscar-thread.c: Fix indentation.
	* aarch64-tdep.c: Fix indentation.
	* aarch64-tdep.h: Fix indentation.
	* ada-lang.c: Fix indentation.
	* ada-lang.h: Fix indentation.
	* ada-tasks.c: Fix indentation.
	* ada-typeprint.c: Fix indentation.
	* ada-valprint.c: Fix indentation.
	* ada-varobj.c: Fix indentation.
	* addrmap.c: Fix indentation.
	* addrmap.h: Fix indentation.
	* agent.c: Fix indentation.
	* aix-thread.c: Fix indentation.
	* alpha-bsd-nat.c: Fix indentation.
	* alpha-linux-tdep.c: Fix indentation.
	* alpha-mdebug-tdep.c: Fix indentation.
	* alpha-nbsd-tdep.c: Fix indentation.
	* alpha-obsd-tdep.c: Fix indentation.
	* alpha-tdep.c: Fix indentation.
	* amd64-bsd-nat.c: Fix indentation.
	* amd64-darwin-tdep.c: Fix indentation.
	* amd64-linux-nat.c: Fix indentation.
	* amd64-linux-tdep.c: Fix indentation.
	* amd64-nat.c: Fix indentation.
	* amd64-obsd-tdep.c: Fix indentation.
	* amd64-tdep.c: Fix indentation.
	* amd64-windows-tdep.c: Fix indentation.
	* annotate.c: Fix indentation.
	* arc-tdep.c: Fix indentation.
	* arch-utils.c: Fix indentation.
	* arch/arm-get-next-pcs.c: Fix indentation.
	* arch/arm.c: Fix indentation.
	* arm-linux-nat.c: Fix indentation.
	* arm-linux-tdep.c: Fix indentation.
	* arm-nbsd-tdep.c: Fix indentation.
	* arm-pikeos-tdep.c: Fix indentation.
	* arm-tdep.c: Fix indentation.
	* arm-tdep.h: Fix indentation.
	* arm-wince-tdep.c: Fix indentation.
	* auto-load.c: Fix indentation.
	* auxv.c: Fix indentation.
	* avr-tdep.c: Fix indentation.
	* ax-gdb.c: Fix indentation.
	* ax-general.c: Fix indentation.
	* bfin-linux-tdep.c: Fix indentation.
	* block.c: Fix indentation.
	* block.h: Fix indentation.
	* blockframe.c: Fix indentation.
	* bpf-tdep.c: Fix indentation.
	* break-catch-sig.c: Fix indentation.
	* break-catch-syscall.c: Fix indentation.
	* break-catch-throw.c: Fix indentation.
	* breakpoint.c: Fix indentation.
	* breakpoint.h: Fix indentation.
	* bsd-uthread.c: Fix indentation.
	* btrace.c: Fix indentation.
	* build-id.c: Fix indentation.
	* buildsym-legacy.h: Fix indentation.
	* buildsym.c: Fix indentation.
	* c-typeprint.c: Fix indentation.
	* c-valprint.c: Fix indentation.
	* c-varobj.c: Fix indentation.
	* charset.c: Fix indentation.
	* cli/cli-cmds.c: Fix indentation.
	* cli/cli-decode.c: Fix indentation.
	* cli/cli-decode.h: Fix indentation.
	* cli/cli-script.c: Fix indentation.
	* cli/cli-setshow.c: Fix indentation.
	* coff-pe-read.c: Fix indentation.
	* coffread.c: Fix indentation.
	* compile/compile-cplus-types.c: Fix indentation.
	* compile/compile-object-load.c: Fix indentation.
	* compile/compile-object-run.c: Fix indentation.
	* completer.c: Fix indentation.
	* corefile.c: Fix indentation.
	* corelow.c: Fix indentation.
	* cp-abi.h: Fix indentation.
	* cp-namespace.c: Fix indentation.
	* cp-support.c: Fix indentation.
	* cp-valprint.c: Fix indentation.
	* cris-linux-tdep.c: Fix indentation.
	* cris-tdep.c: Fix indentation.
	* darwin-nat-info.c: Fix indentation.
	* darwin-nat.c: Fix indentation.
	* darwin-nat.h: Fix indentation.
	* dbxread.c: Fix indentation.
	* dcache.c: Fix indentation.
	* disasm.c: Fix indentation.
	* dtrace-probe.c: Fix indentation.
	* dwarf2/abbrev.c: Fix indentation.
	* dwarf2/attribute.c: Fix indentation.
	* dwarf2/expr.c: Fix indentation.
	* dwarf2/frame.c: Fix indentation.
	* dwarf2/index-cache.c: Fix indentation.
	* dwarf2/index-write.c: Fix indentation.
	* dwarf2/line-header.c: Fix indentation.
	* dwarf2/loc.c: Fix indentation.
	* dwarf2/macro.c: Fix indentation.
	* dwarf2/read.c: Fix indentation.
	* dwarf2/read.h: Fix indentation.
	* elfread.c: Fix indentation.
	* eval.c: Fix indentation.
	* event-top.c: Fix indentation.
	* exec.c: Fix indentation.
	* exec.h: Fix indentation.
	* expprint.c: Fix indentation.
	* f-lang.c: Fix indentation.
	* f-typeprint.c: Fix indentation.
	* f-valprint.c: Fix indentation.
	* fbsd-nat.c: Fix indentation.
	* fbsd-tdep.c: Fix indentation.
	* findvar.c: Fix indentation.
	* fork-child.c: Fix indentation.
	* frame-unwind.c: Fix indentation.
	* frame-unwind.h: Fix indentation.
	* frame.c: Fix indentation.
	* frv-linux-tdep.c: Fix indentation.
	* frv-tdep.c: Fix indentation.
	* frv-tdep.h: Fix indentation.
	* ft32-tdep.c: Fix indentation.
	* gcore.c: Fix indentation.
	* gdb_bfd.c: Fix indentation.
	* gdbarch.sh: Fix indentation.
	* gdbarch.c: Re-generate
	* gdbarch.h: Re-generate.
	* gdbcore.h: Fix indentation.
	* gdbthread.h: Fix indentation.
	* gdbtypes.c: Fix indentation.
	* gdbtypes.h: Fix indentation.
	* glibc-tdep.c: Fix indentation.
	* gnu-nat.c: Fix indentation.
	* gnu-nat.h: Fix indentation.
	* gnu-v2-abi.c: Fix indentation.
	* gnu-v3-abi.c: Fix indentation.
	* go32-nat.c: Fix indentation.
	* guile/guile-internal.h: Fix indentation.
	* guile/scm-cmd.c: Fix indentation.
	* guile/scm-frame.c: Fix indentation.
	* guile/scm-iterator.c: Fix indentation.
	* guile/scm-math.c: Fix indentation.
	* guile/scm-ports.c: Fix indentation.
	* guile/scm-pretty-print.c: Fix indentation.
	* guile/scm-value.c: Fix indentation.
	* h8300-tdep.c: Fix indentation.
	* hppa-linux-nat.c: Fix indentation.
	* hppa-linux-tdep.c: Fix indentation.
	* hppa-nbsd-nat.c: Fix indentation.
	* hppa-nbsd-tdep.c: Fix indentation.
	* hppa-obsd-nat.c: Fix indentation.
	* hppa-tdep.c: Fix indentation.
	* hppa-tdep.h: Fix indentation.
	* i386-bsd-nat.c: Fix indentation.
	* i386-darwin-nat.c: Fix indentation.
	* i386-darwin-tdep.c: Fix indentation.
	* i386-dicos-tdep.c: Fix indentation.
	* i386-gnu-nat.c: Fix indentation.
	* i386-linux-nat.c: Fix indentation.
	* i386-linux-tdep.c: Fix indentation.
	* i386-nto-tdep.c: Fix indentation.
	* i386-obsd-tdep.c: Fix indentation.
	* i386-sol2-nat.c: Fix indentation.
	* i386-tdep.c: Fix indentation.
	* i386-tdep.h: Fix indentation.
	* i386-windows-tdep.c: Fix indentation.
	* i387-tdep.c: Fix indentation.
	* i387-tdep.h: Fix indentation.
	* ia64-libunwind-tdep.c: Fix indentation.
	* ia64-libunwind-tdep.h: Fix indentation.
	* ia64-linux-nat.c: Fix indentation.
	* ia64-linux-tdep.c: Fix indentation.
	* ia64-tdep.c: Fix indentation.
	* ia64-tdep.h: Fix indentation.
	* ia64-vms-tdep.c: Fix indentation.
	* infcall.c: Fix indentation.
	* infcmd.c: Fix indentation.
	* inferior.c: Fix indentation.
	* infrun.c: Fix indentation.
	* iq2000-tdep.c: Fix indentation.
	* language.c: Fix indentation.
	* linespec.c: Fix indentation.
	* linux-fork.c: Fix indentation.
	* linux-nat.c: Fix indentation.
	* linux-tdep.c: Fix indentation.
	* linux-thread-db.c: Fix indentation.
	* lm32-tdep.c: Fix indentation.
	* m2-lang.c: Fix indentation.
	* m2-typeprint.c: Fix indentation.
	* m2-valprint.c: Fix indentation.
	* m32c-tdep.c: Fix indentation.
	* m32r-linux-tdep.c: Fix indentation.
	* m32r-tdep.c: Fix indentation.
	* m68hc11-tdep.c: Fix indentation.
	* m68k-bsd-nat.c: Fix indentation.
	* m68k-linux-nat.c: Fix indentation.
	* m68k-linux-tdep.c: Fix indentation.
	* m68k-tdep.c: Fix indentation.
	* machoread.c: Fix indentation.
	* macrocmd.c: Fix indentation.
	* macroexp.c: Fix indentation.
	* macroscope.c: Fix indentation.
	* macrotab.c: Fix indentation.
	* macrotab.h: Fix indentation.
	* main.c: Fix indentation.
	* mdebugread.c: Fix indentation.
	* mep-tdep.c: Fix indentation.
	* mi/mi-cmd-catch.c: Fix indentation.
	* mi/mi-cmd-disas.c: Fix indentation.
	* mi/mi-cmd-env.c: Fix indentation.
	* mi/mi-cmd-stack.c: Fix indentation.
	* mi/mi-cmd-var.c: Fix indentation.
	* mi/mi-cmds.c: Fix indentation.
	* mi/mi-main.c: Fix indentation.
	* mi/mi-parse.c: Fix indentation.
	* microblaze-tdep.c: Fix indentation.
	* minidebug.c: Fix indentation.
	* minsyms.c: Fix indentation.
	* mips-linux-nat.c: Fix indentation.
	* mips-linux-tdep.c: Fix indentation.
	* mips-nbsd-tdep.c: Fix indentation.
	* mips-tdep.c: Fix indentation.
	* mn10300-linux-tdep.c: Fix indentation.
	* mn10300-tdep.c: Fix indentation.
	* moxie-tdep.c: Fix indentation.
	* msp430-tdep.c: Fix indentation.
	* namespace.h: Fix indentation.
	* nat/fork-inferior.c: Fix indentation.
	* nat/gdb_ptrace.h: Fix indentation.
	* nat/linux-namespaces.c: Fix indentation.
	* nat/linux-osdata.c: Fix indentation.
	* nat/netbsd-nat.c: Fix indentation.
	* nat/x86-dregs.c: Fix indentation.
	* nbsd-nat.c: Fix indentation.
	* nbsd-tdep.c: Fix indentation.
	* nios2-linux-tdep.c: Fix indentation.
	* nios2-tdep.c: Fix indentation.
	* nto-procfs.c: Fix indentation.
	* nto-tdep.c: Fix indentation.
	* objfiles.c: Fix indentation.
	* objfiles.h: Fix indentation.
	* opencl-lang.c: Fix indentation.
	* or1k-tdep.c: Fix indentation.
	* osabi.c: Fix indentation.
	* osabi.h: Fix indentation.
	* osdata.c: Fix indentation.
	* p-lang.c: Fix indentation.
	* p-typeprint.c: Fix indentation.
	* p-valprint.c: Fix indentation.
	* parse.c: Fix indentation.
	* ppc-linux-nat.c: Fix indentation.
	* ppc-linux-tdep.c: Fix indentation.
	* ppc-nbsd-nat.c: Fix indentation.
	* ppc-nbsd-tdep.c: Fix indentation.
	* ppc-obsd-nat.c: Fix indentation.
	* ppc-ravenscar-thread.c: Fix indentation.
	* ppc-sysv-tdep.c: Fix indentation.
	* ppc64-tdep.c: Fix indentation.
	* printcmd.c: Fix indentation.
	* proc-api.c: Fix indentation.
	* producer.c: Fix indentation.
	* producer.h: Fix indentation.
	* prologue-value.c: Fix indentation.
	* prologue-value.h: Fix indentation.
	* psymtab.c: Fix indentation.
	* python/py-arch.c: Fix indentation.
	* python/py-bpevent.c: Fix indentation.
	* python/py-event.c: Fix indentation.
	* python/py-event.h: Fix indentation.
	* python/py-finishbreakpoint.c: Fix indentation.
	* python/py-frame.c: Fix indentation.
	* python/py-framefilter.c: Fix indentation.
	* python/py-inferior.c: Fix indentation.
	* python/py-infthread.c: Fix indentation.
	* python/py-objfile.c: Fix indentation.
	* python/py-prettyprint.c: Fix indentation.
	* python/py-registers.c: Fix indentation.
	* python/py-signalevent.c: Fix indentation.
	* python/py-stopevent.c: Fix indentation.
	* python/py-stopevent.h: Fix indentation.
	* python/py-threadevent.c: Fix indentation.
	* python/py-tui.c: Fix indentation.
	* python/py-unwind.c: Fix indentation.
	* python/py-value.c: Fix indentation.
	* python/py-xmethods.c: Fix indentation.
	* python/python-internal.h: Fix indentation.
	* python/python.c: Fix indentation.
	* ravenscar-thread.c: Fix indentation.
	* record-btrace.c: Fix indentation.
	* record-full.c: Fix indentation.
	* record.c: Fix indentation.
	* reggroups.c: Fix indentation.
	* regset.h: Fix indentation.
	* remote-fileio.c: Fix indentation.
	* remote.c: Fix indentation.
	* reverse.c: Fix indentation.
	* riscv-linux-tdep.c: Fix indentation.
	* riscv-ravenscar-thread.c: Fix indentation.
	* riscv-tdep.c: Fix indentation.
	* rl78-tdep.c: Fix indentation.
	* rs6000-aix-tdep.c: Fix indentation.
	* rs6000-lynx178-tdep.c: Fix indentation.
	* rs6000-nat.c: Fix indentation.
	* rs6000-tdep.c: Fix indentation.
	* rust-lang.c: Fix indentation.
	* rx-tdep.c: Fix indentation.
	* s12z-tdep.c: Fix indentation.
	* s390-linux-tdep.c: Fix indentation.
	* score-tdep.c: Fix indentation.
	* ser-base.c: Fix indentation.
	* ser-mingw.c: Fix indentation.
	* ser-uds.c: Fix indentation.
	* ser-unix.c: Fix indentation.
	* serial.c: Fix indentation.
	* sh-linux-tdep.c: Fix indentation.
	* sh-nbsd-tdep.c: Fix indentation.
	* sh-tdep.c: Fix indentation.
	* skip.c: Fix indentation.
	* sol-thread.c: Fix indentation.
	* solib-aix.c: Fix indentation.
	* solib-darwin.c: Fix indentation.
	* solib-frv.c: Fix indentation.
	* solib-svr4.c: Fix indentation.
	* solib.c: Fix indentation.
	* source.c: Fix indentation.
	* sparc-linux-tdep.c: Fix indentation.
	* sparc-nbsd-tdep.c: Fix indentation.
	* sparc-obsd-tdep.c: Fix indentation.
	* sparc-ravenscar-thread.c: Fix indentation.
	* sparc-tdep.c: Fix indentation.
	* sparc64-linux-tdep.c: Fix indentation.
	* sparc64-nbsd-tdep.c: Fix indentation.
	* sparc64-obsd-tdep.c: Fix indentation.
	* sparc64-tdep.c: Fix indentation.
	* stabsread.c: Fix indentation.
	* stack.c: Fix indentation.
	* stap-probe.c: Fix indentation.
	* stubs/ia64vms-stub.c: Fix indentation.
	* stubs/m32r-stub.c: Fix indentation.
	* stubs/m68k-stub.c: Fix indentation.
	* stubs/sh-stub.c: Fix indentation.
	* stubs/sparc-stub.c: Fix indentation.
	* symfile-mem.c: Fix indentation.
	* symfile.c: Fix indentation.
	* symfile.h: Fix indentation.
	* symmisc.c: Fix indentation.
	* symtab.c: Fix indentation.
	* symtab.h: Fix indentation.
	* target-float.c: Fix indentation.
	* target.c: Fix indentation.
	* target.h: Fix indentation.
	* tic6x-tdep.c: Fix indentation.
	* tilegx-linux-tdep.c: Fix indentation.
	* tilegx-tdep.c: Fix indentation.
	* top.c: Fix indentation.
	* tracefile-tfile.c: Fix indentation.
	* tracepoint.c: Fix indentation.
	* tui/tui-disasm.c: Fix indentation.
	* tui/tui-io.c: Fix indentation.
	* tui/tui-regs.c: Fix indentation.
	* tui/tui-stack.c: Fix indentation.
	* tui/tui-win.c: Fix indentation.
	* tui/tui-winsource.c: Fix indentation.
	* tui/tui.c: Fix indentation.
	* typeprint.c: Fix indentation.
	* ui-out.h: Fix indentation.
	* unittests/copy_bitwise-selftests.c: Fix indentation.
	* unittests/memory-map-selftests.c: Fix indentation.
	* utils.c: Fix indentation.
	* v850-tdep.c: Fix indentation.
	* valarith.c: Fix indentation.
	* valops.c: Fix indentation.
	* valprint.c: Fix indentation.
	* valprint.h: Fix indentation.
	* value.c: Fix indentation.
	* value.h: Fix indentation.
	* varobj.c: Fix indentation.
	* vax-tdep.c: Fix indentation.
	* windows-nat.c: Fix indentation.
	* windows-tdep.c: Fix indentation.
	* xcoffread.c: Fix indentation.
	* xml-syscall.c: Fix indentation.
	* xml-tdesc.c: Fix indentation.
	* xstormy16-tdep.c: Fix indentation.
	* xtensa-config.c: Fix indentation.
	* xtensa-linux-nat.c: Fix indentation.
	* xtensa-linux-tdep.c: Fix indentation.
	* xtensa-tdep.c: Fix indentation.

gdbserver/ChangeLog:

	* ax.cc: Fix indentation.
	* dll.cc: Fix indentation.
	* inferiors.h: Fix indentation.
	* linux-low.cc: Fix indentation.
	* linux-nios2-low.cc: Fix indentation.
	* linux-ppc-ipa.cc: Fix indentation.
	* linux-ppc-low.cc: Fix indentation.
	* linux-x86-low.cc: Fix indentation.
	* linux-xtensa-low.cc: Fix indentation.
	* regcache.cc: Fix indentation.
	* server.cc: Fix indentation.
	* tracepoint.cc: Fix indentation.

gdbsupport/ChangeLog:

	* common-exceptions.h: Fix indentation.
	* event-loop.cc: Fix indentation.
	* fileio.cc: Fix indentation.
	* filestuff.cc: Fix indentation.
	* gdb-dlfcn.cc: Fix indentation.
	* gdb_string_view.h: Fix indentation.
	* job-control.cc: Fix indentation.
	* signals.cc: Fix indentation.

Change-Id: I4bad7ae6be0fbe14168b8ebafb98ffe14964a695
2020-11-02 10:28:45 -05:00
Pedro Alves
d744f0f965 gdb::handle_eintr, remove need to specify return type
This eliminates the need to specify the return type when using
handle_eintr.  We let the compiler deduce it for us.

Also, use lowercase for function parameter names.  Uppercase should
only be used on template parameters.

gdb/ChangeLog:

	* nat/linux-waitpid.c: Include "gdbsupport/eintr.h".
	(my_waitpid): Use gdb::handle_eintr.

gdbserver/ChangeLog:

	* netbsd-low.cc (netbsd_waitpid, netbsd_process_target::kill)
	(netbsd_qxfer_libraries_svr4): Use gdb::handle_eintr without
	explicit type.

gdbsupport/ChangeLog:

	* eintr.h (handle_eintr): Replace Ret template parameter with
	ErrorValType.  Use it as type of the failure value.  Deduce the
	function's return type using decltype.  Use lowercase for function
	parameter names.
2020-10-26 18:57:40 +00:00
Kamil Rytarowski
4641551a7a Correct logical error in NetBSD's read_memory and write_memory
In case of repeated ptrace PT_IO call and returning the value of
transferred bytes equal to 0, do not return without setting
xfered_len.

gdb/ChangeLog:

        * nat/netbsd-nat.c (write_memory, read_memory): Update.
2020-10-07 15:15:54 +02:00
Kamil Rytarowski
91e5e8db33 Add common write_memory and read_memory NetBSD routines
Instead of sharing the native-only code with all BSDs with slightly
different semantics of the kernels, share the NetBSD-only behavior beteen
the NetBSD native and gdbserver setup.

NetBSD does not differentiate the address space I and D in the
operations (contrary to OpenBSD). NetBSD handles EACCES that integrates
with NetBSD specific PaX MPROTECT error handling.

Add a verbose message in the native client that an operation could be
cancelled due to PaX MPROTECT setup.

gdb/ChangeLog:

       * nat/netbsd-nat.c (write_memory, read_memory): Add.
       * nat/netbsd-nat.h (write_memory, read_memory): Likewise.
       * nbsd-nat.c (nbsd_nat_target::xfer_partial): Update.

gdbserver/ChangeLog:

       * netbsd-low.cc (netbsd_process_target::read_memory)
       (netbsd_process_target::write_memory): Update.
2020-10-07 14:52:25 +02:00
Hannes Domani
99bb393f1d Handle 64bit breakpoints of WOW64 processes as SIGINT
When a WOW64 process triggers a breakpoint exception in 64bit code (which
happens when a 64bit gdb calls DebugBreakProcess for a 32bit target),
gdb ignores the breakpoint (because Wow64GetThreadContext can only report
the pc of 32bit code, and there is not int3 at this location).

But if these 64bit breakpoint exceptions are handled as SIGINT, gdb
doesn't check for int3, and always stops the target.

gdb/ChangeLog:

2020-09-23  Hannes Domani  <ssbssa@yahoo.de>

	* nat/windows-nat.c (handle_exception): Handle 64bit breakpoints
	in WOW64 processes as SIGINT.
	* nat/windows-nat.h: Make wow64_process a shared variable.
	* windows-nat.c: Remove static wow64_process variable.

gdbserver/ChangeLog:

2020-09-23  Hannes Domani  <ssbssa@yahoo.de>

	* win32-low.cc: Remove local wow64_process variable.
	* win32-low.h: Remove local wow64_process variable.
2020-09-24 19:01:22 +02:00
Kamil Rytarowski
f404573e4f Avoid double free in startup_inferior
Do not free the last execd pathname as it will be used in
prepare_resume_reply(), after attaching a client side.

gdb/ChangeLog:

	* fork-inferior.c (startup_inferior): Avoid double free.
2020-09-10 15:39:19 +02:00
Kamil Rytarowski
1ccb2c170c Add a common utility function to read and write siginfo_t in inferior
gdb/ChangeLog:

        * netbsd-nat.h (netbsd_nat::qxfer_siginfo): Add.
        * netbsd-nat.c (netbsd_nat::qxfer_siginfo): Likewise.
2020-09-10 15:38:57 +02:00
Kamil Rytarowski
feedfcc773 Add netbsd_nat::enable_proc_events in gdb/nat
Add generic function to enable debugger events in a process.

gdb/ChangeLog:

        * netbsd-nat.h (netbsd_nat::enable_proc_events): Add.
	* netbsd-nat.c: Include <sys/ptrace.h>.
	* (netbsd_nat::enable_proc_events): Add.
2020-09-10 15:38:23 +02:00
Kamil Rytarowski
c489f8c6e6 Add gdb/nat common functions for listing threads
Add netbsd_nat::netbsd_thread_lister a generic thread lister, used
internally in netbsd-nat.c, copied from gdb/nbsd-nat.c.

Add public extern functions for listing threads:
 * netbsd_nat::thread_alive
 * netbsd_nat::thread_name
 * netbsd_nat::for_each_thread

gdb/ChangeLog:

	* netbsd-nat.h: Include "gdbsupport/function-view.h".
	* (netbsd_nat::thread_alive, netbsd_nat::thread_name)
	(netbsd_nat::for_each_thread): Add.
	* netbsd-nat.c: Include "gdbsupport/common-defs.h" and
	"gdbsupport/common-debug.h".
	* (netbsd_nat::netbsd_thread_lister)
	(netbsd_nat::thread_alive, netbsd_nat::thread_name)
	(netbsd_nat::for_each_thread): Add.
2020-09-10 15:37:52 +02:00
Kamil Rytarowski
330662f684 Add netbsd_nat::pid_to_exec_file
gdb/ChangeLog:

        * netbsd-nat.h: Include <unistd.h>.
        * (netbsd_nat::pid_to_exec_file): Add.
        * netbsd-nat.c: Include <sys/types.h> and <sys/sysctl.h>.
        * (netbsd_nat::pid_to_exec_file) Add.
2020-09-10 15:37:32 +02:00
Kamil Rytarowski
99cf6da66a Register a placeholder for NetBSD shared functions in gdb/nat
gdb/ChangeLog:

	* netbsd-nat.h: New file.
	* netbsd-nat.c: Likewise.
2020-09-10 15:35:51 +02:00
Luis Machado
cc308722fb [AArch64] Fix incorrectly-defined SVE macro
The kernel has fixed this here:

https://lore.kernel.org/patchwork/patch/1029011/

We should do the same for GDB, which is still carrying an incorrect
definition of the macro.  As stated in the kernel patch thread, this doesn't
actually change things because, luckily, the structs are of the same size.

gdb/ChangeLog:

2020-08-10  Luis Machado  <luis.machado@linaro.org>

	* nat/aarch64-sve-linux-sigcontext.h (SVE_PT_REGS_OFFSET): Use
	struct user_sve_header instead of struct sve_context.
2020-08-10 11:50:53 -03:00