Commit | Line | Data |
---|---|---|
ce3a066d | 1 | /* Target operations for the remote server for GDB. |
9b254dd1 | 2 | Copyright (C) 2002, 2004, 2005, 2007, 2008 Free Software Foundation, Inc. |
ce3a066d DJ |
3 | |
4 | Contributed by MontaVista Software. | |
5 | ||
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
ce3a066d DJ |
11 | (at your option) any later version. |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
ce3a066d DJ |
20 | |
21 | #include "server.h" | |
22 | ||
23 | struct target_ops *the_target; | |
24 | ||
0d62e5e8 DJ |
25 | void |
26 | set_desired_inferior (int use_general) | |
27 | { | |
28 | struct thread_info *found; | |
29 | ||
30 | if (use_general == 1) | |
31 | { | |
32 | found = (struct thread_info *) find_inferior_id (&all_threads, | |
33 | general_thread); | |
34 | } | |
35 | else | |
36 | { | |
37 | found = NULL; | |
38 | ||
39 | /* If we are continuing any (all) thread(s), use step_thread | |
40 | to decide which thread to step and/or send the specified | |
41 | signal to. */ | |
d592fa2f DJ |
42 | if ((step_thread != 0 && step_thread != -1) |
43 | && (cont_thread == 0 || cont_thread == -1)) | |
0d62e5e8 DJ |
44 | found = (struct thread_info *) find_inferior_id (&all_threads, |
45 | step_thread); | |
46 | ||
47 | if (found == NULL) | |
48 | found = (struct thread_info *) find_inferior_id (&all_threads, | |
49 | cont_thread); | |
50 | } | |
51 | ||
52 | if (found == NULL) | |
53 | current_inferior = (struct thread_info *) all_threads.head; | |
54 | else | |
55 | current_inferior = found; | |
56 | } | |
57 | ||
c3e735a6 | 58 | int |
f450004a | 59 | read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len) |
611cb4a5 | 60 | { |
c3e735a6 DJ |
61 | int res; |
62 | res = (*the_target->read_memory) (memaddr, myaddr, len); | |
611cb4a5 | 63 | check_mem_read (memaddr, myaddr, len); |
c3e735a6 | 64 | return res; |
611cb4a5 DJ |
65 | } |
66 | ||
67 | int | |
f450004a DJ |
68 | write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr, |
69 | int len) | |
0d62e5e8 DJ |
70 | { |
71 | /* Lacking cleanups, there is some potential for a memory leak if the | |
72 | write fails and we go through error(). Make sure that no more than | |
73 | one buffer is ever pending by making BUFFER static. */ | |
f450004a | 74 | static unsigned char *buffer = 0; |
0d62e5e8 DJ |
75 | int res; |
76 | ||
77 | if (buffer != NULL) | |
78 | free (buffer); | |
79 | ||
bca929d3 | 80 | buffer = xmalloc (len); |
0d62e5e8 DJ |
81 | memcpy (buffer, myaddr, len); |
82 | check_mem_write (memaddr, buffer, len); | |
83 | res = (*the_target->write_memory) (memaddr, buffer, len); | |
84 | free (buffer); | |
85 | buffer = NULL; | |
86 | ||
87 | return res; | |
88 | } | |
89 | ||
90 | unsigned char | |
91 | mywait (char *statusp, int connected_wait) | |
611cb4a5 | 92 | { |
0d62e5e8 DJ |
93 | unsigned char ret; |
94 | ||
95 | if (connected_wait) | |
96 | server_waiting = 1; | |
97 | ||
98 | ret = (*the_target->wait) (statusp); | |
99 | ||
100 | if (connected_wait) | |
101 | server_waiting = 0; | |
102 | ||
103 | return ret; | |
611cb4a5 DJ |
104 | } |
105 | ||
ce3a066d DJ |
106 | void |
107 | set_target_ops (struct target_ops *target) | |
108 | { | |
bca929d3 | 109 | the_target = (struct target_ops *) xmalloc (sizeof (*the_target)); |
ce3a066d DJ |
110 | memcpy (the_target, target, sizeof (*the_target)); |
111 | } |