1 /* Target operations for the remote server for GDB.
2 Copyright (C) 2002-2013 Free Software Foundation, Inc.
4 Contributed by MontaVista Software.
6 This file is part of GDB.
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
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "tracepoint.h"
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
);
34 found
= find_thread_ptid (cont_thread
);
37 current_inferior
= (struct thread_info
*) all_threads
.head
;
39 current_inferior
= found
;
43 read_inferior_memory (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
)
46 res
= (*the_target
->read_memory
) (memaddr
, myaddr
, len
);
47 check_mem_read (memaddr
, myaddr
, len
);
52 write_inferior_memory (CORE_ADDR memaddr
, const unsigned char *myaddr
,
55 /* Lacking cleanups, there is some potential for a memory leak if the
56 write fails and we go through error(). Make sure that no more than
57 one buffer is ever pending by making BUFFER static. */
58 static unsigned char *buffer
= 0;
64 buffer
= xmalloc (len
);
65 memcpy (buffer
, myaddr
, len
);
66 check_mem_write (memaddr
, buffer
, myaddr
, len
);
67 res
= (*the_target
->write_memory
) (memaddr
, buffer
, len
);
75 mywait (ptid_t ptid
, struct target_waitstatus
*ourstatus
, int options
,
83 ret
= (*the_target
->wait
) (ptid
, ourstatus
, options
);
85 /* We don't expose _LOADED events to gdbserver core. See the
86 `dlls_changed' global. */
87 if (ourstatus
->kind
== TARGET_WAITKIND_LOADED
)
88 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
90 /* If GDB is connected through TCP/serial, then GDBserver will most
91 probably be running on its own terminal/console, so it's nice to
92 print there why is GDBserver exiting. If however, GDB is
93 connected through stdio, then there's no need to spam the GDB
94 console with this -- the user will already see the exit through
95 regular GDB output, in that same terminal. */
96 if (!remote_connection_is_stdio ())
98 if (ourstatus
->kind
== TARGET_WAITKIND_EXITED
)
100 "\nChild exited with status %d\n", ourstatus
->value
.integer
);
101 else if (ourstatus
->kind
== TARGET_WAITKIND_SIGNALLED
)
102 fprintf (stderr
, "\nChild terminated with signal = 0x%x (%s)\n",
103 gdb_signal_to_host (ourstatus
->value
.sig
),
104 gdb_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 xsnprintf (buf
, sizeof (buf
), "<all threads>");
143 else if (ptid_equal (ptid
, null_ptid
))
144 xsnprintf (buf
, sizeof (buf
), "<null thread>");
145 else if (ptid_get_tid (ptid
) != 0)
146 xsnprintf (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 xsnprintf (buf
, sizeof (buf
), "LWP %d.%ld",
150 ptid_get_pid (ptid
), ptid_get_lwp (ptid
));
152 xsnprintf (buf
, sizeof (buf
), "Process %d",
153 ptid_get_pid (ptid
));
159 kill_inferior (int pid
)
161 gdb_agent_about_to_close (pid
);
163 return (*the_target
->kill
) (pid
);