Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(878)

Side by Side Diff: gdb/nacl-tdep.c

Issue 10832095: Prevent traps after rsp modification (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@master
Patch Set: allow any instruction before rsp sandboxing Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Target-dependent code for NaCl. 1 /* Target-dependent code for NaCl.
2 2
3 Copyright (C) 2001, 2003-2012 Free Software Foundation, Inc. 3 Copyright (C) 2001, 2003-2012 Free Software Foundation, Inc.
4 4
5 This file is part of GDB. 5 This file is part of GDB.
6 6
7 This program is free software; you can redistribute it and/or modify 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 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 9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 GNU General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 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/>. */ 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 19
20 #include "defs.h" 20 #include "defs.h"
21 #include "amd64-linux-tdep.h" 21 #include "amd64-linux-tdep.h"
22 #include "i386-linux-tdep.h" 22 #include "i386-linux-tdep.h"
23 #include "linux-tdep.h" 23 #include "linux-tdep.h"
24 #include "amd64-tdep.h" 24 #include "amd64-tdep.h"
25 #include "nacl-manifest.h" 25 #include "nacl-manifest.h"
26 #include "symtab.h" 26 #include "symtab.h"
27 #include "solib-svr4.h" 27 #include "solib-svr4.h"
28 #include "frame.h" 28 #include "frame.h"
29 #include "osabi.h" 29 #include "osabi.h"
30 #include "disasm.h"
31 #include "breakpoint.h"
32 #include "target.h"
30 33
31 static void 34 static void
32 nacl_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) 35 nacl_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
33 { 36 {
34 /* NaCl uses SVR4-style shared libraries. */ 37 /* NaCl uses SVR4-style shared libraries. */
35 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); 38 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
36 set_solib_svr4_map_so_name (gdbarch, nacl_manifest_find); 39 set_solib_svr4_map_so_name (gdbarch, nacl_manifest_find);
37 set_gdbarch_process_record (gdbarch, i386_process_record); 40 set_gdbarch_process_record (gdbarch, i386_process_record);
38 } 41 }
39 42
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 lmo.l_addr_offset = 0; 95 lmo.l_addr_offset = 0;
93 lmo.l_name_offset = 8; 96 lmo.l_name_offset = 8;
94 lmo.l_ld_offset = 12; 97 lmo.l_ld_offset = 12;
95 lmo.l_next_offset = 16; 98 lmo.l_next_offset = 16;
96 lmo.l_prev_offset = 20; 99 lmo.l_prev_offset = 20;
97 } 100 }
98 101
99 return lmp; 102 return lmp;
100 } 103 }
101 104
105 static CORE_ADDR
106 amd64_nacl_skip_rsp_sandboxing (CORE_ADDR addr)
107 {
108 gdb_byte buf[3];
109 if (target_read_memory (addr, buf, sizeof(buf)) == 0)
110 {
111 /* 4c 01 fc add %r15,%rsp */
112 if (buf[0] == 0x4c && buf[1] == 0x01 && buf[2] == 0xfc)
113 {
114 return addr + 3;
115 }
116 }
117 return addr;
118 }
119
120 static CORE_ADDR
121 amd64_nacl_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR addr)
122 {
123 return amd64_nacl_skip_rsp_sandboxing (addr);
124 }
125
126 static int
127 amd64_nacl_software_single_step (struct frame_info *frame)
128 {
129 struct gdbarch *gdbarch;
130 CORE_ADDR pc;
131 CORE_ADDR bp_pc;
132
133 gdbarch = get_frame_arch (frame);
134 pc = get_frame_register_unsigned (frame, gdbarch_pc_regnum (gdbarch));
135
136 /* Check if next instruction is rsp sandboxing. If yes, assume current
137 instruction is rsp modification. */
138 pc += gdb_insn_length (gdbarch, pc);
139 bp_pc = amd64_nacl_skip_rsp_sandboxing (pc);
140 if (bp_pc != pc)
141 {
142 insert_single_step_breakpoint (gdbarch,
143 get_frame_address_space (frame),
144 bp_pc);
145 return 1;
146 }
147
148 return 0;
149 }
150
102 static void 151 static void
103 amd64_nacl_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) 152 amd64_nacl_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
104 { 153 {
105 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 154 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
106 linux_init_abi (info, gdbarch); 155 linux_init_abi (info, gdbarch);
107 amd64_init_abi (info, gdbarch); 156 amd64_init_abi (info, gdbarch);
108 tdep->tdesc = tdesc_amd64_linux; 157 tdep->tdesc = tdesc_amd64_linux;
109 set_solib_svr4_fetch_link_map_offsets (gdbarch, 158 set_solib_svr4_fetch_link_map_offsets (gdbarch,
110 amd64_nacl_fetch_link_map_offsets); 159 amd64_nacl_fetch_link_map_offsets);
111 nacl_init_abi (info, gdbarch); 160 nacl_init_abi (info, gdbarch);
(...skipping 11 matching lines...) Expand all
123 172
124 /* TODO(eaeltsin): we might use address size instead of pointer size to 173 /* TODO(eaeltsin): we might use address size instead of pointer size to
125 distinguish between i386 and x86_64... At least address size is not 174 distinguish between i386 and x86_64... At least address size is not
126 a property of the data model. */ 175 a property of the data model. */
127 set_gdbarch_addr_bit (gdbarch, 64); 176 set_gdbarch_addr_bit (gdbarch, 64);
128 177
129 /* How to extract addresses from registers. */ 178 /* How to extract addresses from registers. */
130 set_gdbarch_addr_bits_remove (gdbarch, amd64_nacl_addr_bits_remove); 179 set_gdbarch_addr_bits_remove (gdbarch, amd64_nacl_addr_bits_remove);
131 set_gdbarch_unwind_pc (gdbarch, amd64_nacl_unwind_pc); 180 set_gdbarch_unwind_pc (gdbarch, amd64_nacl_unwind_pc);
132 set_gdbarch_unwind_sp (gdbarch, amd64_nacl_unwind_sp); 181 set_gdbarch_unwind_sp (gdbarch, amd64_nacl_unwind_sp);
182
183 /* Where to set breakpoints. */
184 set_gdbarch_adjust_breakpoint_address (gdbarch,
185 amd64_nacl_adjust_breakpoint_address);
186 set_gdbarch_software_single_step (gdbarch, amd64_nacl_software_single_step);
133 } 187 }
134 188
135 /* Provide a prototype to silence -Wmissing-prototypes. */ 189 /* Provide a prototype to silence -Wmissing-prototypes. */
136 extern void _initialize_nacl_tdep (void); 190 extern void _initialize_nacl_tdep (void);
137 191
138 void 192 void
139 _initialize_nacl_tdep (void) 193 _initialize_nacl_tdep (void)
140 { 194 {
141 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64, 195 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
142 GDB_OSABI_NACL, amd64_nacl_init_abi); 196 GDB_OSABI_NACL, amd64_nacl_init_abi);
143 197
144 gdbarch_register_osabi (bfd_arch_i386, 0, 198 gdbarch_register_osabi (bfd_arch_i386, 0,
145 GDB_OSABI_NACL, i386_nacl_init_abi); 199 GDB_OSABI_NACL, i386_nacl_init_abi);
146 } 200 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698