1130803Smarcel/* Target operations for the remote server for GDB.
2130803Smarcel   Copyright 2002, 2003, 2004
3130803Smarcel   Free Software Foundation, Inc.
4130803Smarcel
5130803Smarcel   Contributed by MontaVista Software.
6130803Smarcel
7130803Smarcel   This file is part of GDB.
8130803Smarcel
9130803Smarcel   This program is free software; you can redistribute it and/or modify
10130803Smarcel   it under the terms of the GNU General Public License as published by
11130803Smarcel   the Free Software Foundation; either version 2 of the License, or
12130803Smarcel   (at your option) any later version.
13130803Smarcel
14130803Smarcel   This program is distributed in the hope that it will be useful,
15130803Smarcel   but WITHOUT ANY WARRANTY; without even the implied warranty of
16130803Smarcel   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17130803Smarcel   GNU General Public License for more details.
18130803Smarcel
19130803Smarcel   You should have received a copy of the GNU General Public License
20130803Smarcel   along with this program; if not, write to the Free Software
21130803Smarcel   Foundation, Inc., 59 Temple Place - Suite 330,
22130803Smarcel   Boston, MA 02111-1307, USA.  */
23130803Smarcel
24130803Smarcel#ifndef TARGET_H
25130803Smarcel#define TARGET_H
26130803Smarcel
27130803Smarcel/* This structure describes how to resume a particular thread (or
28130803Smarcel   all threads) based on the client's request.  If thread is -1, then
29130803Smarcel   this entry applies to all threads.  These are generally passed around
30130803Smarcel   as an array, and terminated by a thread == -1 entry.  */
31130803Smarcel
32130803Smarcelstruct thread_resume
33130803Smarcel{
34130803Smarcel  int thread;
35130803Smarcel
36130803Smarcel  /* If non-zero, leave this thread stopped.  */
37130803Smarcel  int leave_stopped;
38130803Smarcel
39130803Smarcel  /* If non-zero, we want to single-step.  */
40130803Smarcel  int step;
41130803Smarcel
42130803Smarcel  /* If non-zero, send this signal when we resume.  */
43130803Smarcel  int sig;
44130803Smarcel};
45130803Smarcel
46130803Smarcelstruct target_ops
47130803Smarcel{
48130803Smarcel  /* Start a new process.
49130803Smarcel
50130803Smarcel     PROGRAM is a path to the program to execute.
51130803Smarcel     ARGS is a standard NULL-terminated array of arguments,
52130803Smarcel     to be passed to the inferior as ``argv''.
53130803Smarcel
54130803Smarcel     Returns the new PID on success, -1 on failure.  Registers the new
55130803Smarcel     process with the process list.  */
56130803Smarcel
57130803Smarcel  int (*create_inferior) (char *program, char **args);
58130803Smarcel
59130803Smarcel  /* Attach to a running process.
60130803Smarcel
61130803Smarcel     PID is the process ID to attach to, specified by the user
62130803Smarcel     or a higher layer.  */
63130803Smarcel
64130803Smarcel  int (*attach) (int pid);
65130803Smarcel
66130803Smarcel  /* Kill all inferiors.  */
67130803Smarcel
68130803Smarcel  void (*kill) (void);
69130803Smarcel
70130803Smarcel  /* Detach from all inferiors.  */
71130803Smarcel
72130803Smarcel  void (*detach) (void);
73130803Smarcel
74130803Smarcel  /* Return 1 iff the thread with process ID PID is alive.  */
75130803Smarcel
76130803Smarcel  int (*thread_alive) (int pid);
77130803Smarcel
78130803Smarcel  /* Resume the inferior process.  */
79130803Smarcel
80130803Smarcel  void (*resume) (struct thread_resume *resume_info);
81130803Smarcel
82130803Smarcel  /* Wait for the inferior process to change state.
83130803Smarcel
84130803Smarcel     STATUSP will be filled in with a response code to send to GDB.
85130803Smarcel
86130803Smarcel     Returns the signal which caused the process to stop.  */
87130803Smarcel
88130803Smarcel  unsigned char (*wait) (char *status);
89130803Smarcel
90130803Smarcel  /* Fetch registers from the inferior process.
91130803Smarcel
92130803Smarcel     If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO.  */
93130803Smarcel
94130803Smarcel  void (*fetch_registers) (int regno);
95130803Smarcel
96130803Smarcel  /* Store registers to the inferior process.
97130803Smarcel
98130803Smarcel     If REGNO is -1, store all registers; otherwise, store at least REGNO.  */
99130803Smarcel
100130803Smarcel  void (*store_registers) (int regno);
101130803Smarcel
102130803Smarcel  /* Read memory from the inferior process.  This should generally be
103130803Smarcel     called through read_inferior_memory, which handles breakpoint shadowing.
104130803Smarcel
105130803Smarcel     Read LEN bytes at MEMADDR into a buffer at MYADDR.
106130803Smarcel
107130803Smarcel     Returns 0 on success and errno on failure.  */
108130803Smarcel
109130803Smarcel  int (*read_memory) (CORE_ADDR memaddr, char *myaddr, int len);
110130803Smarcel
111130803Smarcel  /* Write memory to the inferior process.  This should generally be
112130803Smarcel     called through write_inferior_memory, which handles breakpoint shadowing.
113130803Smarcel
114130803Smarcel     Write LEN bytes from the buffer at MYADDR to MEMADDR.
115130803Smarcel
116130803Smarcel     Returns 0 on success and errno on failure.  */
117130803Smarcel
118130803Smarcel  int (*write_memory) (CORE_ADDR memaddr, const char *myaddr, int len);
119130803Smarcel
120130803Smarcel  /* Query GDB for the values of any symbols we're interested in.
121130803Smarcel     This function is called whenever we receive a "qSymbols::"
122130803Smarcel     query, which corresponds to every time more symbols (might)
123130803Smarcel     become available.  NULL if we aren't interested in any
124130803Smarcel     symbols.  */
125130803Smarcel
126130803Smarcel  void (*look_up_symbols) (void);
127130803Smarcel
128130803Smarcel  /* Send a signal to the inferior process, however is appropriate.  */
129130803Smarcel  void (*send_signal) (int);
130130803Smarcel
131130803Smarcel  /* Read auxiliary vector data from the inferior process.
132130803Smarcel
133130803Smarcel     Read LEN bytes at OFFSET into a buffer at MYADDR.  */
134130803Smarcel
135130803Smarcel  int (*read_auxv) (CORE_ADDR offset, char *myaddr, unsigned int len);
136130803Smarcel};
137130803Smarcel
138130803Smarcelextern struct target_ops *the_target;
139130803Smarcel
140130803Smarcelvoid set_target_ops (struct target_ops *);
141130803Smarcel
142130803Smarcel#define create_inferior(program, args) \
143130803Smarcel  (*the_target->create_inferior) (program, args)
144130803Smarcel
145130803Smarcel#define myattach(pid) \
146130803Smarcel  (*the_target->attach) (pid)
147130803Smarcel
148130803Smarcel#define kill_inferior() \
149130803Smarcel  (*the_target->kill) ()
150130803Smarcel
151130803Smarcel#define detach_inferior() \
152130803Smarcel  (*the_target->detach) ()
153130803Smarcel
154130803Smarcel#define mythread_alive(pid) \
155130803Smarcel  (*the_target->thread_alive) (pid)
156130803Smarcel
157130803Smarcel#define fetch_inferior_registers(regno) \
158130803Smarcel  (*the_target->fetch_registers) (regno)
159130803Smarcel
160130803Smarcel#define store_inferior_registers(regno) \
161130803Smarcel  (*the_target->store_registers) (regno)
162130803Smarcel
163130803Smarcelunsigned char mywait (char *statusp, int connected_wait);
164130803Smarcel
165130803Smarcelint read_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len);
166130803Smarcel
167130803Smarcelint write_inferior_memory (CORE_ADDR memaddr, const char *myaddr, int len);
168130803Smarcel
169130803Smarcelvoid set_desired_inferior (int id);
170130803Smarcel
171130803Smarcel#endif /* TARGET_H */
172