xref: /openbsd-src/gnu/usr.bin/binutils/gdb/gdbserver/target.h (revision b725ae7711052a2233e31a66fefb8a752c388d7a)
1*b725ae77Skettenis /* Target operations for the remote server for GDB.
2*b725ae77Skettenis    Copyright 2002, 2003, 2004
3*b725ae77Skettenis    Free Software Foundation, Inc.
4*b725ae77Skettenis 
5*b725ae77Skettenis    Contributed by MontaVista Software.
6*b725ae77Skettenis 
7*b725ae77Skettenis    This file is part of GDB.
8*b725ae77Skettenis 
9*b725ae77Skettenis    This program is free software; you can redistribute it and/or modify
10*b725ae77Skettenis    it under the terms of the GNU General Public License as published by
11*b725ae77Skettenis    the Free Software Foundation; either version 2 of the License, or
12*b725ae77Skettenis    (at your option) any later version.
13*b725ae77Skettenis 
14*b725ae77Skettenis    This program is distributed in the hope that it will be useful,
15*b725ae77Skettenis    but WITHOUT ANY WARRANTY; without even the implied warranty of
16*b725ae77Skettenis    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*b725ae77Skettenis    GNU General Public License for more details.
18*b725ae77Skettenis 
19*b725ae77Skettenis    You should have received a copy of the GNU General Public License
20*b725ae77Skettenis    along with this program; if not, write to the Free Software
21*b725ae77Skettenis    Foundation, Inc., 59 Temple Place - Suite 330,
22*b725ae77Skettenis    Boston, MA 02111-1307, USA.  */
23*b725ae77Skettenis 
24*b725ae77Skettenis #ifndef TARGET_H
25*b725ae77Skettenis #define TARGET_H
26*b725ae77Skettenis 
27*b725ae77Skettenis /* This structure describes how to resume a particular thread (or
28*b725ae77Skettenis    all threads) based on the client's request.  If thread is -1, then
29*b725ae77Skettenis    this entry applies to all threads.  These are generally passed around
30*b725ae77Skettenis    as an array, and terminated by a thread == -1 entry.  */
31*b725ae77Skettenis 
32*b725ae77Skettenis struct thread_resume
33*b725ae77Skettenis {
34*b725ae77Skettenis   int thread;
35*b725ae77Skettenis 
36*b725ae77Skettenis   /* If non-zero, leave this thread stopped.  */
37*b725ae77Skettenis   int leave_stopped;
38*b725ae77Skettenis 
39*b725ae77Skettenis   /* If non-zero, we want to single-step.  */
40*b725ae77Skettenis   int step;
41*b725ae77Skettenis 
42*b725ae77Skettenis   /* If non-zero, send this signal when we resume.  */
43*b725ae77Skettenis   int sig;
44*b725ae77Skettenis };
45*b725ae77Skettenis 
46*b725ae77Skettenis struct target_ops
47*b725ae77Skettenis {
48*b725ae77Skettenis   /* Start a new process.
49*b725ae77Skettenis 
50*b725ae77Skettenis      PROGRAM is a path to the program to execute.
51*b725ae77Skettenis      ARGS is a standard NULL-terminated array of arguments,
52*b725ae77Skettenis      to be passed to the inferior as ``argv''.
53*b725ae77Skettenis 
54*b725ae77Skettenis      Returns the new PID on success, -1 on failure.  Registers the new
55*b725ae77Skettenis      process with the process list.  */
56*b725ae77Skettenis 
57*b725ae77Skettenis   int (*create_inferior) (char *program, char **args);
58*b725ae77Skettenis 
59*b725ae77Skettenis   /* Attach to a running process.
60*b725ae77Skettenis 
61*b725ae77Skettenis      PID is the process ID to attach to, specified by the user
62*b725ae77Skettenis      or a higher layer.  */
63*b725ae77Skettenis 
64*b725ae77Skettenis   int (*attach) (int pid);
65*b725ae77Skettenis 
66*b725ae77Skettenis   /* Kill all inferiors.  */
67*b725ae77Skettenis 
68*b725ae77Skettenis   void (*kill) (void);
69*b725ae77Skettenis 
70*b725ae77Skettenis   /* Detach from all inferiors.  */
71*b725ae77Skettenis 
72*b725ae77Skettenis   void (*detach) (void);
73*b725ae77Skettenis 
74*b725ae77Skettenis   /* Return 1 iff the thread with process ID PID is alive.  */
75*b725ae77Skettenis 
76*b725ae77Skettenis   int (*thread_alive) (int pid);
77*b725ae77Skettenis 
78*b725ae77Skettenis   /* Resume the inferior process.  */
79*b725ae77Skettenis 
80*b725ae77Skettenis   void (*resume) (struct thread_resume *resume_info);
81*b725ae77Skettenis 
82*b725ae77Skettenis   /* Wait for the inferior process to change state.
83*b725ae77Skettenis 
84*b725ae77Skettenis      STATUSP will be filled in with a response code to send to GDB.
85*b725ae77Skettenis 
86*b725ae77Skettenis      Returns the signal which caused the process to stop.  */
87*b725ae77Skettenis 
88*b725ae77Skettenis   unsigned char (*wait) (char *status);
89*b725ae77Skettenis 
90*b725ae77Skettenis   /* Fetch registers from the inferior process.
91*b725ae77Skettenis 
92*b725ae77Skettenis      If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO.  */
93*b725ae77Skettenis 
94*b725ae77Skettenis   void (*fetch_registers) (int regno);
95*b725ae77Skettenis 
96*b725ae77Skettenis   /* Store registers to the inferior process.
97*b725ae77Skettenis 
98*b725ae77Skettenis      If REGNO is -1, store all registers; otherwise, store at least REGNO.  */
99*b725ae77Skettenis 
100*b725ae77Skettenis   void (*store_registers) (int regno);
101*b725ae77Skettenis 
102*b725ae77Skettenis   /* Read memory from the inferior process.  This should generally be
103*b725ae77Skettenis      called through read_inferior_memory, which handles breakpoint shadowing.
104*b725ae77Skettenis 
105*b725ae77Skettenis      Read LEN bytes at MEMADDR into a buffer at MYADDR.
106*b725ae77Skettenis 
107*b725ae77Skettenis      Returns 0 on success and errno on failure.  */
108*b725ae77Skettenis 
109*b725ae77Skettenis   int (*read_memory) (CORE_ADDR memaddr, char *myaddr, int len);
110*b725ae77Skettenis 
111*b725ae77Skettenis   /* Write memory to the inferior process.  This should generally be
112*b725ae77Skettenis      called through write_inferior_memory, which handles breakpoint shadowing.
113*b725ae77Skettenis 
114*b725ae77Skettenis      Write LEN bytes from the buffer at MYADDR to MEMADDR.
115*b725ae77Skettenis 
116*b725ae77Skettenis      Returns 0 on success and errno on failure.  */
117*b725ae77Skettenis 
118*b725ae77Skettenis   int (*write_memory) (CORE_ADDR memaddr, const char *myaddr, int len);
119*b725ae77Skettenis 
120*b725ae77Skettenis   /* Query GDB for the values of any symbols we're interested in.
121*b725ae77Skettenis      This function is called whenever we receive a "qSymbols::"
122*b725ae77Skettenis      query, which corresponds to every time more symbols (might)
123*b725ae77Skettenis      become available.  NULL if we aren't interested in any
124*b725ae77Skettenis      symbols.  */
125*b725ae77Skettenis 
126*b725ae77Skettenis   void (*look_up_symbols) (void);
127*b725ae77Skettenis 
128*b725ae77Skettenis   /* Send a signal to the inferior process, however is appropriate.  */
129*b725ae77Skettenis   void (*send_signal) (int);
130*b725ae77Skettenis 
131*b725ae77Skettenis   /* Read auxiliary vector data from the inferior process.
132*b725ae77Skettenis 
133*b725ae77Skettenis      Read LEN bytes at OFFSET into a buffer at MYADDR.  */
134*b725ae77Skettenis 
135*b725ae77Skettenis   int (*read_auxv) (CORE_ADDR offset, char *myaddr, unsigned int len);
136*b725ae77Skettenis };
137*b725ae77Skettenis 
138*b725ae77Skettenis extern struct target_ops *the_target;
139*b725ae77Skettenis 
140*b725ae77Skettenis void set_target_ops (struct target_ops *);
141*b725ae77Skettenis 
142*b725ae77Skettenis #define create_inferior(program, args) \
143*b725ae77Skettenis   (*the_target->create_inferior) (program, args)
144*b725ae77Skettenis 
145*b725ae77Skettenis #define myattach(pid) \
146*b725ae77Skettenis   (*the_target->attach) (pid)
147*b725ae77Skettenis 
148*b725ae77Skettenis #define kill_inferior() \
149*b725ae77Skettenis   (*the_target->kill) ()
150*b725ae77Skettenis 
151*b725ae77Skettenis #define detach_inferior() \
152*b725ae77Skettenis   (*the_target->detach) ()
153*b725ae77Skettenis 
154*b725ae77Skettenis #define mythread_alive(pid) \
155*b725ae77Skettenis   (*the_target->thread_alive) (pid)
156*b725ae77Skettenis 
157*b725ae77Skettenis #define fetch_inferior_registers(regno) \
158*b725ae77Skettenis   (*the_target->fetch_registers) (regno)
159*b725ae77Skettenis 
160*b725ae77Skettenis #define store_inferior_registers(regno) \
161*b725ae77Skettenis   (*the_target->store_registers) (regno)
162*b725ae77Skettenis 
163*b725ae77Skettenis unsigned char mywait (char *statusp, int connected_wait);
164*b725ae77Skettenis 
165*b725ae77Skettenis int read_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len);
166*b725ae77Skettenis 
167*b725ae77Skettenis int write_inferior_memory (CORE_ADDR memaddr, const char *myaddr, int len);
168*b725ae77Skettenis 
169*b725ae77Skettenis void set_desired_inferior (int id);
170*b725ae77Skettenis 
171*b725ae77Skettenis #endif /* TARGET_H */
172