target.h revision 130803
1168404Spjd/* Target operations for the remote server for GDB.
2168404Spjd   Copyright 2002, 2003, 2004
3168404Spjd   Free Software Foundation, Inc.
4168404Spjd
5168404Spjd   Contributed by MontaVista Software.
6168404Spjd
7168404Spjd   This file is part of GDB.
8168404Spjd
9168404Spjd   This program is free software; you can redistribute it and/or modify
10168404Spjd   it under the terms of the GNU General Public License as published by
11168404Spjd   the Free Software Foundation; either version 2 of the License, or
12168404Spjd   (at your option) any later version.
13168404Spjd
14168404Spjd   This program is distributed in the hope that it will be useful,
15168404Spjd   but WITHOUT ANY WARRANTY; without even the implied warranty of
16168404Spjd   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17168404Spjd   GNU General Public License for more details.
18168404Spjd
19168404Spjd   You should have received a copy of the GNU General Public License
20168404Spjd   along with this program; if not, write to the Free Software
21168404Spjd   Foundation, Inc., 59 Temple Place - Suite 330,
22219089Spjd   Boston, MA 02111-1307, USA.  */
23325534Savg
24246586Sdelphij#ifndef TARGET_H
25255750Sdelphij#define TARGET_H
26296519Smav
27168404Spjd/* This structure describes how to resume a particular thread (or
28168404Spjd   all threads) based on the client's request.  If thread is -1, then
29219089Spjd   this entry applies to all threads.  These are generally passed around
30219089Spjd   as an array, and terminated by a thread == -1 entry.  */
31168404Spjd
32168404Spjdstruct thread_resume
33185029Spjd{
34168404Spjd  int thread;
35168404Spjd
36185029Spjd  /* If non-zero, leave this thread stopped.  */
37168404Spjd  int leave_stopped;
38168404Spjd
39185029Spjd  /* If non-zero, we want to single-step.  */
40168404Spjd  int step;
41168404Spjd
42168404Spjd  /* If non-zero, send this signal when we resume.  */
43168404Spjd  int sig;
44168404Spjd};
45168404Spjd
46168404Spjdstruct target_ops
47168404Spjd{
48168404Spjd  /* Start a new process.
49185029Spjd
50168404Spjd     PROGRAM is a path to the program to execute.
51209962Smm     ARGS is a standard NULL-terminated array of arguments,
52209962Smm     to be passed to the inferior as ``argv''.
53209962Smm
54209962Smm     Returns the new PID on success, -1 on failure.  Registers the new
55209962Smm     process with the process list.  */
56209962Smm
57209962Smm  int (*create_inferior) (char *program, char **args);
58209962Smm
59185029Spjd  /* Attach to a running process.
60185029Spjd
61168404Spjd     PID is the process ID to attach to, specified by the user
62185029Spjd     or a higher layer.  */
63168404Spjd
64168404Spjd  int (*attach) (int pid);
65185029Spjd
66185029Spjd  /* Kill all inferiors.  */
67168404Spjd
68185029Spjd  void (*kill) (void);
69185029Spjd
70185029Spjd  /* Detach from all inferiors.  */
71185029Spjd
72185029Spjd  void (*detach) (void);
73185029Spjd
74255750Sdelphij  /* Return 1 iff the thread with process ID PID is alive.  */
75289422Smav
76289422Smav  int (*thread_alive) (int pid);
77301010Sallanjude
78289422Smav  /* Resume the inferior process.  */
79289422Smav
80185029Spjd  void (*resume) (struct thread_resume *resume_info);
81185029Spjd
82168404Spjd  /* Wait for the inferior process to change state.
83219089Spjd
84219089Spjd     STATUSP will be filled in with a response code to send to GDB.
85219089Spjd
86219089Spjd     Returns the signal which caused the process to stop.  */
87219089Spjd
88219089Spjd  unsigned char (*wait) (char *status);
89219089Spjd
90289422Smav  /* Fetch registers from the inferior process.
91289422Smav
92289422Smav     If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO.  */
93289422Smav
94289422Smav  void (*fetch_registers) (int regno);
95289422Smav
96301010Sallanjude  /* Store registers to the inferior process.
97289422Smav
98289422Smav     If REGNO is -1, store all registers; otherwise, store at least REGNO.  */
99289422Smav
100219089Spjd  void (*store_registers) (int regno);
101219089Spjd
102219089Spjd  /* Read memory from the inferior process.  This should generally be
103185029Spjd     called through read_inferior_memory, which handles breakpoint shadowing.
104185029Spjd
105185029Spjd     Read LEN bytes at MEMADDR into a buffer at MYADDR.
106185029Spjd
107185029Spjd     Returns 0 on success and errno on failure.  */
108185029Spjd
109185029Spjd  int (*read_memory) (CORE_ADDR memaddr, char *myaddr, int len);
110185029Spjd
111185029Spjd  /* Write memory to the inferior process.  This should generally be
112185029Spjd     called through write_inferior_memory, which handles breakpoint shadowing.
113185029Spjd
114185029Spjd     Write LEN bytes from the buffer at MYADDR to MEMADDR.
115185029Spjd
116185029Spjd     Returns 0 on success and errno on failure.  */
117219089Spjd
118246586Sdelphij  int (*write_memory) (CORE_ADDR memaddr, const char *myaddr, int len);
119185029Spjd
120185029Spjd  /* Query GDB for the values of any symbols we're interested in.
121168404Spjd     This function is called whenever we receive a "qSymbols::"
122185029Spjd     query, which corresponds to every time more symbols (might)
123185029Spjd     become available.  NULL if we aren't interested in any
124185029Spjd     symbols.  */
125185029Spjd
126185029Spjd  void (*look_up_symbols) (void);
127168404Spjd
128224174Smm  /* Send a signal to the inferior process, however is appropriate.  */
129224174Smm  void (*send_signal) (int);
130224174Smm
131224174Smm  /* Read auxiliary vector data from the inferior process.
132243560Smm
133224174Smm     Read LEN bytes at OFFSET into a buffer at MYADDR.  */
134224174Smm
135224174Smm  int (*read_auxv) (CORE_ADDR offset, char *myaddr, unsigned int len);
136185029Spjd};
137185029Spjd
138185029Spjdextern struct target_ops *the_target;
139185029Spjd
140185029Spjdvoid set_target_ops (struct target_ops *);
141185029Spjd
142201143Sdelphij#define create_inferior(program, args) \
143185029Spjd  (*the_target->create_inferior) (program, args)
144185029Spjd
145168404Spjd#define myattach(pid) \
146185029Spjd  (*the_target->attach) (pid)
147185029Spjd
148185029Spjd#define kill_inferior() \
149185029Spjd  (*the_target->kill) ()
150185029Spjd
151185029Spjd#define detach_inferior() \
152168404Spjd  (*the_target->detach) ()
153185029Spjd
154185029Spjd#define mythread_alive(pid) \
155185029Spjd  (*the_target->thread_alive) (pid)
156185029Spjd
157185029Spjd#define fetch_inferior_registers(regno) \
158185029Spjd  (*the_target->fetch_registers) (regno)
159168404Spjd
160185029Spjd#define store_inferior_registers(regno) \
161185029Spjd  (*the_target->store_registers) (regno)
162185029Spjd
163185029Spjdunsigned char mywait (char *statusp, int connected_wait);
164185029Spjd
165185029Spjdint read_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len);
166185029Spjd
167185029Spjdint write_inferior_memory (CORE_ADDR memaddr, const char *myaddr, int len);
168185029Spjd
169185029Spjdvoid set_desired_inferior (int id);
170185029Spjd
171185029Spjd#endif /* TARGET_H */
172185029Spjd