Add translations for various sub-directories
[binutils-gdb.git] / gdb / nat / x86-linux.c
blobad3ed3c2289e0193be90ca6b9da5af80df77d086
1 /* Native-dependent code for GNU/Linux x86 (i386 and x86-64).
3 Copyright (C) 1999-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "x86-linux.h"
21 #include "x86-linux-dregs.h"
22 #include "nat/gdb_ptrace.h"
23 #include <sys/user.h>
25 /* Per-thread arch-specific data we want to keep. */
27 struct arch_lwp_info
29 /* Non-zero if our copy differs from what's recorded in the
30 thread. */
31 int debug_registers_changed;
34 /* See nat/x86-linux.h. */
36 void
37 lwp_set_debug_registers_changed (struct lwp_info *lwp, int value)
39 if (lwp_arch_private_info (lwp) == NULL)
40 lwp_set_arch_private_info (lwp, XCNEW (struct arch_lwp_info));
42 lwp_arch_private_info (lwp)->debug_registers_changed = value;
45 /* See nat/x86-linux.h. */
47 int
48 lwp_debug_registers_changed (struct lwp_info *lwp)
50 struct arch_lwp_info *info = lwp_arch_private_info (lwp);
52 /* NULL means either that this is the main thread still going
53 through the shell, or that no watchpoint has been set yet.
54 The debug registers are unchanged in either case. */
55 if (info == NULL)
56 return 0;
58 return info->debug_registers_changed;
61 /* See nat/x86-linux.h. */
63 void
64 x86_linux_new_thread (struct lwp_info *lwp)
66 lwp_set_debug_registers_changed (lwp, 1);
69 /* See nat/x86-linux.h. */
71 void
72 x86_linux_delete_thread (struct arch_lwp_info *arch_lwp)
74 xfree (arch_lwp);
77 /* See nat/x86-linux.h. */
79 void
80 x86_linux_prepare_to_resume (struct lwp_info *lwp)
82 x86_linux_update_debug_registers (lwp);
85 #ifdef __x86_64__
86 /* Value of CS segment register:
87 64bit process: 0x33
88 32bit process: 0x23 */
89 #define AMD64_LINUX_USER64_CS 0x33
91 /* Value of DS segment register:
92 LP64 process: 0x0
93 X32 process: 0x2b */
94 #define AMD64_LINUX_X32_DS 0x2b
95 #endif
97 /* See nat/x86-linux.h. */
99 x86_linux_arch_size
100 x86_linux_ptrace_get_arch_size (int tid)
102 #ifdef __x86_64__
103 unsigned long cs;
104 unsigned long ds;
106 /* Get CS register. */
107 errno = 0;
108 cs = ptrace (PTRACE_PEEKUSER, tid,
109 offsetof (struct user_regs_struct, cs), 0);
110 if (errno != 0)
111 perror_with_name (_("Couldn't get CS register"));
113 bool is_64bit = cs == AMD64_LINUX_USER64_CS;
115 /* Get DS register. */
116 errno = 0;
117 ds = ptrace (PTRACE_PEEKUSER, tid,
118 offsetof (struct user_regs_struct, ds), 0);
119 if (errno != 0)
120 perror_with_name (_("Couldn't get DS register"));
122 bool is_x32 = ds == AMD64_LINUX_X32_DS;
124 return x86_linux_arch_size (is_64bit, is_x32);
125 #else
126 return x86_linux_arch_size (false, false);
127 #endif