1 /* Generic GNU/Linux target using traditional ptrace register access.
3 Copyright (C) 1988-2018 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/>. */
21 #include "linux-nat-trad.h"
23 #include "nat/gdb_ptrace.h"
24 #include "inf-ptrace.h"
26 /* Fetch register REGNUM from the inferior. */
29 linux_nat_trad_target::fetch_register (struct regcache
*regcache
, int regnum
)
31 struct gdbarch
*gdbarch
= regcache
->arch ();
38 /* This isn't really an address, but ptrace thinks of it as one. */
39 addr
= register_u_offset (gdbarch
, regnum
, 0);
40 if (addr
== (CORE_ADDR
)-1
41 || gdbarch_cannot_fetch_register (gdbarch
, regnum
))
43 regcache_raw_supply (regcache
, regnum
, NULL
);
47 pid
= get_ptrace_pid (regcache_get_ptid (regcache
));
49 size
= register_size (gdbarch
, regnum
);
50 gdb_assert ((size
% sizeof (PTRACE_TYPE_RET
)) == 0);
51 buf
= (PTRACE_TYPE_RET
*) alloca (size
);
53 /* Read the register contents from the inferior a chunk at a time. */
54 for (i
= 0; i
< size
/ sizeof (PTRACE_TYPE_RET
); i
++)
57 buf
[i
] = ptrace (PT_READ_U
, pid
, (PTRACE_TYPE_ARG3
)(uintptr_t)addr
, 0);
59 error (_("Couldn't read register %s (#%d): %s."),
60 gdbarch_register_name (gdbarch
, regnum
),
61 regnum
, safe_strerror (errno
));
63 addr
+= sizeof (PTRACE_TYPE_RET
);
65 regcache_raw_supply (regcache
, regnum
, buf
);
68 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
72 linux_nat_trad_target::fetch_registers (struct regcache
*regcache
, int regnum
)
76 regnum
< gdbarch_num_regs (regcache
->arch ());
78 fetch_register (regcache
, regnum
);
80 fetch_register (regcache
, regnum
);
83 /* Store register REGNUM into the inferior. */
86 linux_nat_trad_target::store_register (const struct regcache
*regcache
,
89 struct gdbarch
*gdbarch
= regcache
->arch ();
96 /* This isn't really an address, but ptrace thinks of it as one. */
97 addr
= register_u_offset (gdbarch
, regnum
, 1);
98 if (addr
== (CORE_ADDR
)-1
99 || gdbarch_cannot_store_register (gdbarch
, regnum
))
102 pid
= get_ptrace_pid (regcache_get_ptid (regcache
));
104 size
= register_size (gdbarch
, regnum
);
105 gdb_assert ((size
% sizeof (PTRACE_TYPE_RET
)) == 0);
106 buf
= (PTRACE_TYPE_RET
*) alloca (size
);
108 /* Write the register contents into the inferior a chunk at a time. */
109 regcache_raw_collect (regcache
, regnum
, buf
);
110 for (i
= 0; i
< size
/ sizeof (PTRACE_TYPE_RET
); i
++)
113 ptrace (PT_WRITE_U
, pid
, (PTRACE_TYPE_ARG3
)(uintptr_t)addr
, buf
[i
]);
115 error (_("Couldn't write register %s (#%d): %s."),
116 gdbarch_register_name (gdbarch
, regnum
),
117 regnum
, safe_strerror (errno
));
119 addr
+= sizeof (PTRACE_TYPE_RET
);
123 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
124 this for all registers. */
127 linux_nat_trad_target::store_registers (struct regcache
*regcache
, int regnum
)
131 regnum
< gdbarch_num_regs (regcache
->arch ());
133 store_register (regcache
, regnum
);
135 store_register (regcache
, regnum
);
This page took 0.032307 seconds and 4 git commands to generate.