/* GNU/Linux/x86-64 specific low level interface, for the remote server
for GDB.
- Copyright (C) 2002-2017 Free Software Foundation, Inc.
+ Copyright (C) 2002-2019 Free Software Foundation, Inc.
This file is part of GDB.
#include "linux-low.h"
#include "i387-fp.h"
#include "x86-low.h"
-#include "x86-xstate.h"
+#include "gdbsupport/x86-xstate.h"
#include "nat/gdb_ptrace.h"
#ifdef __x86_64__
#include "elf/common.h"
#endif
-#include "agent.h"
+#include "gdbsupport/agent.h"
#include "tdesc.h"
#include "tracepoint.h"
#include "ax.h"
#include <sys/reg.h>
#include <sys/procfs.h>
-#include "nat/gdb_ptrace.h"
#include <sys/uio.h>
#ifndef PTRACE_GET_THREAD_AREA
#endif
{
- struct lwp_info *lwp = find_lwp_pid (pid_to_ptid (lwpid));
+ struct lwp_info *lwp = find_lwp_pid (ptid_t (lwpid));
struct thread_info *thr = get_lwp_thread (lwp);
struct regcache *regcache = get_thread_regcache (thr, 1);
unsigned int desc[4];
collect_register_by_name (regcache, "orig_eax",
((char *) buf) + ORIG_EAX * REGSIZE);
+
+#ifdef __x86_64__
+ /* Sign extend EAX value to avoid potential syscall restart
+ problems.
+
+ See amd64_linux_collect_native_gregset() in gdb/amd64-linux-nat.c
+ for a detailed explanation. */
+ if (register_size (regcache->tdesc, 0) == 4)
+ {
+ void *ptr = ((gdb_byte *) buf
+ + i386_regmap[find_regno (regcache->tdesc, "eax")]);
+
+ *(int64_t *) ptr = *(int32_t *) ptr;
+ }
+#endif
}
static void
return info;
}
+/* Called when a process is being deleted. */
+
+static void
+x86_linux_delete_process (struct arch_process_info *info)
+{
+ xfree (info);
+}
+
/* Target routine for linux_new_fork. */
static void
if (machine == EM_X86_64)
{
#ifdef __x86_64__
- if (is_elf64)
- {
- if (xcr0_features)
- {
- switch (xcr0 & X86_XSTATE_ALL_MASK)
- {
- case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
- return tdesc_amd64_avx_mpx_avx512_pku_linux;
-
- case X86_XSTATE_AVX_AVX512_MASK:
- return tdesc_amd64_avx_avx512_linux;
-
- case X86_XSTATE_AVX_MPX_MASK:
- return tdesc_amd64_avx_mpx_linux;
-
- case X86_XSTATE_MPX_MASK:
- return tdesc_amd64_mpx_linux;
-
- case X86_XSTATE_AVX_MASK:
- return tdesc_amd64_avx_linux;
+ const target_desc *tdesc = NULL;
- default:
- return tdesc_amd64_linux;
- }
- }
- else
- return tdesc_amd64_linux;
- }
- else
+ if (xcr0_features)
{
- if (xcr0_features)
- {
- switch (xcr0 & X86_XSTATE_ALL_MASK)
- {
- case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
- /* No x32 MPX and PKU, fall back to avx_avx512. */
- return tdesc_x32_avx_avx512_linux;
-
- case X86_XSTATE_AVX_AVX512_MASK:
- return tdesc_x32_avx_avx512_linux;
-
- case X86_XSTATE_MPX_MASK: /* No MPX on x32. */
- case X86_XSTATE_AVX_MASK:
- return tdesc_x32_avx_linux;
-
- default:
- return tdesc_x32_linux;
- }
- }
- else
- return tdesc_x32_linux;
+ tdesc = amd64_linux_read_description (xcr0 & X86_XSTATE_ALL_MASK,
+ !is_elf64);
}
+
+ if (tdesc == NULL)
+ tdesc = amd64_linux_read_description (X86_XSTATE_SSE_MASK, !is_elf64);
+ return tdesc;
#endif
}
else
gdb_assert_not_reached ("failed to return tdesc");
}
-/* Callback for find_inferior. Stops iteration when a thread with a
- given PID is found. */
-
-static int
-same_process_callback (struct inferior_list_entry *entry, void *data)
-{
- int pid = *(int *) data;
-
- return (ptid_get_pid (entry->id) == pid);
-}
-
-/* Callback for for_each_inferior. Calls the arch_setup routine for
- each process. */
-
-static void
-x86_arch_setup_process_callback (struct inferior_list_entry *entry)
-{
- int pid = ptid_get_pid (entry->id);
-
- /* Look up any thread of this processes. */
- current_thread
- = (struct thread_info *) find_inferior (&all_threads,
- same_process_callback, &pid);
-
- the_low_target.arch_setup ();
-}
-
/* Update all the target description of all processes; a new GDB
connected, and it may or not support xml target descriptions. */
release the current regcache objects. */
regcache_release ();
- for_each_inferior (&all_processes, x86_arch_setup_process_callback);
+ for_each_process ([] (process_info *proc) {
+ int pid = proc->pid;
+
+ /* Look up any thread of this process. */
+ current_thread = find_any_thread_of_pid (pid);
+
+ the_low_target.arch_setup ();
+ });
current_thread = saved_thread;
}
mention that something has gone awry. */
if (!warned_about_fast_tracepoints)
{
- warning ("4-byte fast tracepoints not available; %s\n", errbuf);
+ warning ("4-byte fast tracepoints not available; %s", errbuf);
warned_about_fast_tracepoints = 1;
}
return 5;
const struct target_desc *tdesc = regcache->tdesc;
#ifdef __x86_64__
- if (tdesc == tdesc_amd64_linux || tdesc == tdesc_amd64_linux_no_xml
- || tdesc == tdesc_x32_linux)
- return X86_TDESC_SSE;
- if (tdesc == tdesc_amd64_avx_linux || tdesc == tdesc_x32_avx_linux)
- return X86_TDESC_AVX;
- if (tdesc == tdesc_amd64_mpx_linux)
- return X86_TDESC_MPX;
- if (tdesc == tdesc_amd64_avx_mpx_linux)
- return X86_TDESC_AVX_MPX;
- if (tdesc == tdesc_amd64_avx_mpx_avx512_pku_linux || tdesc == tdesc_x32_avx_avx512_linux)
- return X86_TDESC_AVX_MPX_AVX512_PKU;
- if (tdesc == tdesc_amd64_avx_avx512_linux)
- return X86_TDESC_AVX_AVX512;
+ return amd64_get_ipa_tdesc_idx (tdesc);
#endif
if (tdesc == tdesc_i386_linux_no_xml)
/* need to fix up i386 siginfo if host is amd64 */
x86_siginfo_fixup,
x86_linux_new_process,
+ x86_linux_delete_process,
x86_linux_new_thread,
+ x86_linux_delete_thread,
x86_linux_new_fork,
x86_linux_prepare_to_resume,
x86_linux_process_qsupported,
{
/* Initialize the Linux target descriptions. */
#ifdef __x86_64__
- init_registers_amd64_linux ();
- init_registers_amd64_avx_linux ();
- init_registers_amd64_mpx_linux ();
- init_registers_amd64_avx_mpx_linux ();
- init_registers_amd64_avx_avx512_linux ();
- init_registers_amd64_avx_mpx_avx512_pku_linux ();
-
- init_registers_x32_linux ();
- init_registers_x32_avx_linux ();
- init_registers_x32_avx_avx512_linux ();
-
- tdesc_amd64_linux_no_xml = XNEW (struct target_desc);
- copy_target_description (tdesc_amd64_linux_no_xml, tdesc_amd64_linux);
+ tdesc_amd64_linux_no_xml = allocate_target_description ();
+ copy_target_description (tdesc_amd64_linux_no_xml,
+ amd64_linux_read_description (X86_XSTATE_SSE_MASK,
+ false));
tdesc_amd64_linux_no_xml->xmltarget = xmltarget_amd64_linux_no_xml;
#endif
-#if GDB_SELF_TEST
- initialize_low_tdesc ();
-#endif
-
- tdesc_i386_linux_no_xml = XNEW (struct target_desc);
+ tdesc_i386_linux_no_xml = allocate_target_description ();
copy_target_description (tdesc_i386_linux_no_xml,
i386_linux_read_description (X86_XSTATE_SSE_MASK));
tdesc_i386_linux_no_xml->xmltarget = xmltarget_i386_linux_no_xml;