| 1 | /* Target operations for the remote server for GDB. |
| 2 | Copyright (C) 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc. |
| 3 | |
| 4 | Contributed by MontaVista Software. |
| 5 | |
| 6 | This file is part of GDB. |
| 7 | |
| 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 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 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. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; if not, write to the Free Software |
| 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 | Boston, MA 02110-1301, USA. */ |
| 22 | |
| 23 | #ifndef TARGET_H |
| 24 | #define TARGET_H |
| 25 | |
| 26 | /* This structure describes how to resume a particular thread (or |
| 27 | all threads) based on the client's request. If thread is -1, then |
| 28 | this entry applies to all threads. These are generally passed around |
| 29 | as an array, and terminated by a thread == -1 entry. */ |
| 30 | |
| 31 | struct thread_resume |
| 32 | { |
| 33 | unsigned long thread; |
| 34 | |
| 35 | /* If non-zero, leave this thread stopped. */ |
| 36 | int leave_stopped; |
| 37 | |
| 38 | /* If non-zero, we want to single-step. */ |
| 39 | int step; |
| 40 | |
| 41 | /* If non-zero, send this signal when we resume. */ |
| 42 | int sig; |
| 43 | }; |
| 44 | |
| 45 | struct target_ops |
| 46 | { |
| 47 | /* Start a new process. |
| 48 | |
| 49 | PROGRAM is a path to the program to execute. |
| 50 | ARGS is a standard NULL-terminated array of arguments, |
| 51 | to be passed to the inferior as ``argv''. |
| 52 | |
| 53 | Returns the new PID on success, -1 on failure. Registers the new |
| 54 | process with the process list. */ |
| 55 | |
| 56 | int (*create_inferior) (char *program, char **args); |
| 57 | |
| 58 | /* Attach to a running process. |
| 59 | |
| 60 | PID is the process ID to attach to, specified by the user |
| 61 | or a higher layer. */ |
| 62 | |
| 63 | int (*attach) (unsigned long pid); |
| 64 | |
| 65 | /* Kill all inferiors. */ |
| 66 | |
| 67 | void (*kill) (void); |
| 68 | |
| 69 | /* Detach from all inferiors. */ |
| 70 | |
| 71 | void (*detach) (void); |
| 72 | |
| 73 | /* Return 1 iff the thread with process ID PID is alive. */ |
| 74 | |
| 75 | int (*thread_alive) (unsigned long pid); |
| 76 | |
| 77 | /* Resume the inferior process. */ |
| 78 | |
| 79 | void (*resume) (struct thread_resume *resume_info); |
| 80 | |
| 81 | /* Wait for the inferior process to change state. |
| 82 | |
| 83 | STATUS will be filled in with a response code to send to GDB. |
| 84 | |
| 85 | Returns the signal which caused the process to stop, in the |
| 86 | remote protocol numbering (e.g. TARGET_SIGNAL_STOP), or the |
| 87 | exit code as an integer if *STATUS is 'W'. */ |
| 88 | |
| 89 | unsigned char (*wait) (char *status); |
| 90 | |
| 91 | /* Fetch registers from the inferior process. |
| 92 | |
| 93 | If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO. */ |
| 94 | |
| 95 | void (*fetch_registers) (int regno); |
| 96 | |
| 97 | /* Store registers to the inferior process. |
| 98 | |
| 99 | If REGNO is -1, store all registers; otherwise, store at least REGNO. */ |
| 100 | |
| 101 | void (*store_registers) (int regno); |
| 102 | |
| 103 | /* Read memory from the inferior process. This should generally be |
| 104 | called through read_inferior_memory, which handles breakpoint shadowing. |
| 105 | |
| 106 | Read LEN bytes at MEMADDR into a buffer at MYADDR. |
| 107 | |
| 108 | Returns 0 on success and errno on failure. */ |
| 109 | |
| 110 | int (*read_memory) (CORE_ADDR memaddr, unsigned char *myaddr, int len); |
| 111 | |
| 112 | /* Write memory to the inferior process. This should generally be |
| 113 | called through write_inferior_memory, which handles breakpoint shadowing. |
| 114 | |
| 115 | Write LEN bytes from the buffer at MYADDR to MEMADDR. |
| 116 | |
| 117 | Returns 0 on success and errno on failure. */ |
| 118 | |
| 119 | int (*write_memory) (CORE_ADDR memaddr, const unsigned char *myaddr, |
| 120 | int len); |
| 121 | |
| 122 | /* Query GDB for the values of any symbols we're interested in. |
| 123 | This function is called whenever we receive a "qSymbols::" |
| 124 | query, which corresponds to every time more symbols (might) |
| 125 | become available. NULL if we aren't interested in any |
| 126 | symbols. */ |
| 127 | |
| 128 | void (*look_up_symbols) (void); |
| 129 | |
| 130 | /* Send a signal to the inferior process, however is appropriate. */ |
| 131 | void (*send_signal) (int); |
| 132 | |
| 133 | /* Read auxiliary vector data from the inferior process. |
| 134 | |
| 135 | Read LEN bytes at OFFSET into a buffer at MYADDR. */ |
| 136 | |
| 137 | int (*read_auxv) (CORE_ADDR offset, unsigned char *myaddr, |
| 138 | unsigned int len); |
| 139 | |
| 140 | /* Insert and remove a hardware watchpoint. |
| 141 | Returns 0 on success, -1 on failure and 1 on unsupported. |
| 142 | The type is coded as follows: |
| 143 | 2 = write watchpoint |
| 144 | 3 = read watchpoint |
| 145 | 4 = access watchpoint |
| 146 | */ |
| 147 | |
| 148 | int (*insert_watchpoint) (char type, CORE_ADDR addr, int len); |
| 149 | int (*remove_watchpoint) (char type, CORE_ADDR addr, int len); |
| 150 | |
| 151 | /* Returns 1 if target was stopped due to a watchpoint hit, 0 otherwise. */ |
| 152 | |
| 153 | int (*stopped_by_watchpoint) (void); |
| 154 | |
| 155 | /* Returns the address associated with the watchpoint that hit, if any; |
| 156 | returns 0 otherwise. */ |
| 157 | |
| 158 | CORE_ADDR (*stopped_data_address) (void); |
| 159 | |
| 160 | /* Reports the text, data offsets of the executable. This is |
| 161 | needed for uclinux where the executable is relocated during load |
| 162 | time. */ |
| 163 | |
| 164 | int (*read_offsets) (CORE_ADDR *text, CORE_ADDR *data); |
| 165 | |
| 166 | /* Fetch the address associated with a specific thread local storage |
| 167 | area, determined by the specified THREAD, OFFSET, and LOAD_MODULE. |
| 168 | Stores it in *ADDRESS and returns zero on success; otherwise returns |
| 169 | an error code. A return value of -1 means this system does not |
| 170 | support the operation. */ |
| 171 | |
| 172 | int (*get_tls_address) (struct thread_info *thread, CORE_ADDR offset, |
| 173 | CORE_ADDR load_module, CORE_ADDR *address); |
| 174 | }; |
| 175 | |
| 176 | extern struct target_ops *the_target; |
| 177 | |
| 178 | void set_target_ops (struct target_ops *); |
| 179 | |
| 180 | #define create_inferior(program, args) \ |
| 181 | (*the_target->create_inferior) (program, args) |
| 182 | |
| 183 | #define myattach(pid) \ |
| 184 | (*the_target->attach) (pid) |
| 185 | |
| 186 | #define kill_inferior() \ |
| 187 | (*the_target->kill) () |
| 188 | |
| 189 | #define detach_inferior() \ |
| 190 | (*the_target->detach) () |
| 191 | |
| 192 | #define mythread_alive(pid) \ |
| 193 | (*the_target->thread_alive) (pid) |
| 194 | |
| 195 | #define fetch_inferior_registers(regno) \ |
| 196 | (*the_target->fetch_registers) (regno) |
| 197 | |
| 198 | #define store_inferior_registers(regno) \ |
| 199 | (*the_target->store_registers) (regno) |
| 200 | |
| 201 | unsigned char mywait (char *statusp, int connected_wait); |
| 202 | |
| 203 | int read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len); |
| 204 | |
| 205 | int write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr, |
| 206 | int len); |
| 207 | |
| 208 | void set_desired_inferior (int id); |
| 209 | |
| 210 | #endif /* TARGET_H */ |