1 /* Target operations for the remote server for GDB.
2 Copyright (C) 2002, 2004, 2005, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
5 Contributed by MontaVista Software.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 struct target_ops *the_target;
27 set_desired_inferior (int use_general)
29 struct thread_info *found;
32 found = find_thread_ptid (general_thread);
37 /* If we are continuing any (all) thread(s), use step_thread
38 to decide which thread to step and/or send the specified
40 if ((!ptid_equal (step_thread, null_ptid)
41 && !ptid_equal (step_thread, minus_one_ptid))
42 && (ptid_equal (cont_thread, null_ptid)
43 || ptid_equal (cont_thread, minus_one_ptid)))
44 found = find_thread_ptid (step_thread);
47 found = find_thread_ptid (cont_thread);
51 current_inferior = (struct thread_info *) all_threads.head;
53 current_inferior = found;
57 read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
60 res = (*the_target->read_memory) (memaddr, myaddr, len);
61 check_mem_read (memaddr, myaddr, len);
66 write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
69 /* Lacking cleanups, there is some potential for a memory leak if the
70 write fails and we go through error(). Make sure that no more than
71 one buffer is ever pending by making BUFFER static. */
72 static unsigned char *buffer = 0;
78 buffer = xmalloc (len);
79 memcpy (buffer, myaddr, len);
80 check_mem_write (memaddr, buffer, len);
81 res = (*the_target->write_memory) (memaddr, buffer, len);
89 mywait (ptid_t ptid, struct target_waitstatus *ourstatus, int options,
97 ret = (*the_target->wait) (ptid, ourstatus, options);
99 if (ourstatus->kind == TARGET_WAITKIND_EXITED)
101 "\nChild exited with status %d\n", ourstatus->value.sig);
102 else if (ourstatus->kind == TARGET_WAITKIND_SIGNALLED)
103 fprintf (stderr, "\nChild terminated with signal = 0x%x (%s)\n",
104 target_signal_to_host (ourstatus->value.sig),
105 target_signal_to_name (ourstatus->value.sig));
114 start_non_stop (int nonstop)
116 if (the_target->start_non_stop == NULL)
124 return (*the_target->start_non_stop) (nonstop);
128 set_target_ops (struct target_ops *target)
130 the_target = (struct target_ops *) xmalloc (sizeof (*the_target));
131 memcpy (the_target, target, sizeof (*the_target));
134 /* Convert pid to printable format. */
137 target_pid_to_str (ptid_t ptid)
141 if (ptid_equal (ptid, minus_one_ptid))
142 snprintf (buf, sizeof (buf), "<all threads>");
143 else if (ptid_equal (ptid, null_ptid))
144 snprintf (buf, sizeof (buf), "<null thread>");
145 else if (ptid_get_tid (ptid) != 0)
146 snprintf (buf, sizeof (buf), "Thread %d.0x%lx",
147 ptid_get_pid (ptid), ptid_get_tid (ptid));
148 else if (ptid_get_lwp (ptid) != 0)
149 snprintf (buf, sizeof (buf), "LWP %d.%ld",
150 ptid_get_pid (ptid), ptid_get_lwp (ptid));
152 snprintf (buf, sizeof (buf), "Process %d",
153 ptid_get_pid (ptid));