119370Spst/* Interface between GDB and target environments, including files and processes 2130809Smarcel 3130809Smarcel Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 4130809Smarcel 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. 5130809Smarcel 619370Spst Contributed by Cygnus Support. Written by John Gilmore. 719370Spst 899002Sobrien This file is part of GDB. 919370Spst 1099002Sobrien This program is free software; you can redistribute it and/or modify 1199002Sobrien it under the terms of the GNU General Public License as published by 1299002Sobrien the Free Software Foundation; either version 2 of the License, or 1399002Sobrien (at your option) any later version. 1419370Spst 1599002Sobrien This program is distributed in the hope that it will be useful, 1699002Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1799002Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1899002Sobrien GNU General Public License for more details. 1919370Spst 2099002Sobrien You should have received a copy of the GNU General Public License 2199002Sobrien along with this program; if not, write to the Free Software 2299002Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 2399002Sobrien Boston, MA 02111-1307, USA. */ 2419370Spst 2519370Spst#if !defined (TARGET_H) 2619370Spst#define TARGET_H 2719370Spst 28130809Smarcelstruct objfile; 29130809Smarcelstruct ui_file; 30130809Smarcelstruct mem_attrib; 31130809Smarcelstruct target_ops; 32130809Smarcel 3319370Spst/* This include file defines the interface between the main part 3419370Spst of the debugger, and the part which is target-specific, or 3519370Spst specific to the communications interface between us and the 3619370Spst target. 3719370Spst 38130809Smarcel A TARGET is an interface between the debugger and a particular 39130809Smarcel kind of file or process. Targets can be STACKED in STRATA, 4019370Spst so that more than one target can potentially respond to a request. 4119370Spst In particular, memory accesses will walk down the stack of targets 4219370Spst until they find a target that is interested in handling that particular 4319370Spst address. STRATA are artificial boundaries on the stack, within 4419370Spst which particular kinds of targets live. Strata exist so that 4519370Spst people don't get confused by pushing e.g. a process target and then 4619370Spst a file target, and wondering why they can't see the current values 4719370Spst of variables any more (the file target is handling them and they 4819370Spst never get to the process target). So when you push a file target, 4919370Spst it goes into the file stratum, which is always below the process 5019370Spst stratum. */ 5119370Spst 5219370Spst#include "bfd.h" 5346289Sdfr#include "symtab.h" 5499002Sobrien#include "dcache.h" 5599002Sobrien#include "memattr.h" 5619370Spst 5799002Sobrienenum strata 5899002Sobrien { 5999002Sobrien dummy_stratum, /* The lowest of the low */ 6099002Sobrien file_stratum, /* Executable files, etc */ 6199002Sobrien core_stratum, /* Core dump files */ 6299002Sobrien download_stratum, /* Downloading of remote targets */ 6399002Sobrien process_stratum, /* Executing processes */ 6499002Sobrien thread_stratum /* Executing threads */ 6599002Sobrien }; 6619370Spst 6799002Sobrienenum thread_control_capabilities 6899002Sobrien { 6999002Sobrien tc_none = 0, /* Default: can't control thread execution. */ 7099002Sobrien tc_schedlock = 1, /* Can lock the thread scheduler. */ 7199002Sobrien tc_switch = 2 /* Can switch the running thread on demand. */ 7299002Sobrien }; 7346289Sdfr 7419370Spst/* Stuff for target_wait. */ 7519370Spst 7619370Spst/* Generally, what has the program done? */ 7799002Sobrienenum target_waitkind 7899002Sobrien { 7999002Sobrien /* The program has exited. The exit status is in value.integer. */ 8099002Sobrien TARGET_WAITKIND_EXITED, 8119370Spst 8299002Sobrien /* The program has stopped with a signal. Which signal is in 8399002Sobrien value.sig. */ 8499002Sobrien TARGET_WAITKIND_STOPPED, 8519370Spst 8699002Sobrien /* The program has terminated with a signal. Which signal is in 8799002Sobrien value.sig. */ 8899002Sobrien TARGET_WAITKIND_SIGNALLED, 8919370Spst 9099002Sobrien /* The program is letting us know that it dynamically loaded something 9199002Sobrien (e.g. it called load(2) on AIX). */ 9299002Sobrien TARGET_WAITKIND_LOADED, 9319370Spst 9499002Sobrien /* The program has forked. A "related" process' ID is in 9599002Sobrien value.related_pid. I.e., if the child forks, value.related_pid 9699002Sobrien is the parent's ID. */ 9746289Sdfr 9899002Sobrien TARGET_WAITKIND_FORKED, 9946289Sdfr 10099002Sobrien /* The program has vforked. A "related" process's ID is in 10199002Sobrien value.related_pid. */ 10246289Sdfr 10399002Sobrien TARGET_WAITKIND_VFORKED, 10446289Sdfr 10599002Sobrien /* The program has exec'ed a new executable file. The new file's 10699002Sobrien pathname is pointed to by value.execd_pathname. */ 10719370Spst 10899002Sobrien TARGET_WAITKIND_EXECD, 10919370Spst 11099002Sobrien /* The program has entered or returned from a system call. On 11199002Sobrien HP-UX, this is used in the hardware watchpoint implementation. 11299002Sobrien The syscall's unique integer ID number is in value.syscall_id */ 11319370Spst 11499002Sobrien TARGET_WAITKIND_SYSCALL_ENTRY, 11599002Sobrien TARGET_WAITKIND_SYSCALL_RETURN, 11619370Spst 11799002Sobrien /* Nothing happened, but we stopped anyway. This perhaps should be handled 11899002Sobrien within target_wait, but I'm not sure target_wait should be resuming the 11999002Sobrien inferior. */ 12099002Sobrien TARGET_WAITKIND_SPURIOUS, 12119370Spst 122130809Smarcel /* An event has occured, but we should wait again. 123130809Smarcel Remote_async_wait() returns this when there is an event 12499002Sobrien on the inferior, but the rest of the world is not interested in 12599002Sobrien it. The inferior has not stopped, but has just sent some output 12699002Sobrien to the console, for instance. In this case, we want to go back 12799002Sobrien to the event loop and wait there for another event from the 12899002Sobrien inferior, rather than being stuck in the remote_async_wait() 12999002Sobrien function. This way the event loop is responsive to other events, 13099002Sobrien like for instance the user typing. */ 13199002Sobrien TARGET_WAITKIND_IGNORE 13299002Sobrien }; 13319370Spst 13499002Sobrienstruct target_waitstatus 13599002Sobrien { 13699002Sobrien enum target_waitkind kind; 13719370Spst 13899002Sobrien /* Forked child pid, execd pathname, exit status or signal number. */ 13999002Sobrien union 14099002Sobrien { 14199002Sobrien int integer; 14299002Sobrien enum target_signal sig; 14399002Sobrien int related_pid; 14499002Sobrien char *execd_pathname; 14599002Sobrien int syscall_id; 14699002Sobrien } 14799002Sobrien value; 14899002Sobrien }; 14919370Spst 15099002Sobrien/* Possible types of events that the inferior handler will have to 15199002Sobrien deal with. */ 15299002Sobrienenum inferior_event_type 15399002Sobrien { 15499002Sobrien /* There is a request to quit the inferior, abandon it. */ 15599002Sobrien INF_QUIT_REQ, 15699002Sobrien /* Process a normal inferior event which will result in target_wait 15799002Sobrien being called. */ 158130809Smarcel INF_REG_EVENT, 15999002Sobrien /* Deal with an error on the inferior. */ 16099002Sobrien INF_ERROR, 16199002Sobrien /* We are called because a timer went off. */ 16299002Sobrien INF_TIMER, 16399002Sobrien /* We are called to do stuff after the inferior stops. */ 16499002Sobrien INF_EXEC_COMPLETE, 16599002Sobrien /* We are called to do some stuff after the inferior stops, but we 16699002Sobrien are expected to reenter the proceed() and 16799002Sobrien handle_inferior_event() functions. This is used only in case of 16899002Sobrien 'step n' like commands. */ 16999002Sobrien INF_EXEC_CONTINUE 17099002Sobrien }; 17119370Spst 17219370Spst/* Return the string for a signal. */ 17399002Sobrienextern char *target_signal_to_string (enum target_signal); 17419370Spst 17519370Spst/* Return the name (SIGHUP, etc.) for a signal. */ 17699002Sobrienextern char *target_signal_to_name (enum target_signal); 17719370Spst 17819370Spst/* Given a name (SIGHUP, etc.), return its signal. */ 17999002Sobrienenum target_signal target_signal_from_name (char *); 18099002Sobrien 181130809Smarcel/* Request the transfer of up to LEN 8-bit bytes of the target's 182130809Smarcel OBJECT. The OFFSET, for a seekable object, specifies the starting 183130809Smarcel point. The ANNEX can be used to provide additional data-specific 184130809Smarcel information to the target. 18546289Sdfr 186130809Smarcel Return the number of bytes actually transfered, zero when no 187130809Smarcel further transfer is possible, and -1 when the transfer is not 188130809Smarcel supported. 189130809Smarcel 190130809Smarcel NOTE: cagney/2003-10-17: The current interface does not support a 191130809Smarcel "retry" mechanism. Instead it assumes that at least one byte will 192130809Smarcel be transfered on each call. 193130809Smarcel 194130809Smarcel NOTE: cagney/2003-10-17: The current interface can lead to 195130809Smarcel fragmented transfers. Lower target levels should not implement 196130809Smarcel hacks, such as enlarging the transfer, in an attempt to compensate 197130809Smarcel for this. Instead, the target stack should be extended so that it 198130809Smarcel implements supply/collect methods and a look-aside object cache. 199130809Smarcel With that available, the lowest target can safely and freely "push" 200130809Smarcel data up the stack. 201130809Smarcel 202130809Smarcel NOTE: cagney/2003-10-17: Unlike the old query and the memory 203130809Smarcel transfer mechanisms, these methods are explicitly parameterized by 204130809Smarcel the target that it should be applied to. 205130809Smarcel 206130809Smarcel NOTE: cagney/2003-10-17: Just like the old query and memory xfer 207130809Smarcel methods, these new methods perform partial transfers. The only 208130809Smarcel difference is that these new methods thought to include "partial" 209130809Smarcel in the name. The old code's failure to do this lead to much 210130809Smarcel confusion and duplication of effort as each target object attempted 211130809Smarcel to locally take responsibility for something it didn't have to 212130809Smarcel worry about. 213130809Smarcel 214130809Smarcel NOTE: cagney/2003-10-17: With a TARGET_OBJECT_KOD object, for 215130809Smarcel backward compatibility with the "target_query" method that this 216130809Smarcel replaced, when OFFSET and LEN are both zero, return the "minimum" 217130809Smarcel buffer size. See "remote.c" for further information. */ 218130809Smarcel 219130809Smarcelenum target_object 220130809Smarcel{ 221130809Smarcel /* Kernel Object Display transfer. See "kod.c" and "remote.c". */ 222130809Smarcel TARGET_OBJECT_KOD, 223130809Smarcel /* AVR target specific transfer. See "avr-tdep.c" and "remote.c". */ 224130809Smarcel TARGET_OBJECT_AVR, 225130809Smarcel /* Transfer up-to LEN bytes of memory starting at OFFSET. */ 226130809Smarcel TARGET_OBJECT_MEMORY, 227130809Smarcel /* Kernel Unwind Table. See "ia64-tdep.c". */ 228130809Smarcel TARGET_OBJECT_UNWIND_TABLE, 229130809Smarcel /* Transfer auxilliary vector. */ 230130809Smarcel TARGET_OBJECT_AUXV, 231130809Smarcel /* StackGhost cookie. See "sparc-tdep.c". */ 232131086Smarcel TARGET_OBJECT_WCOOKIE, 233131086Smarcel /* Dirty registers. See "ia64-tdep.c". */ 234131086Smarcel TARGET_OBJECT_DIRTY 235130809Smarcel 236130809Smarcel /* Possible future objects: TARGET_OBJECT_FILE, TARGET_OBJECT_PROC, ... */ 237130809Smarcel}; 238130809Smarcel 239130809Smarcelextern LONGEST target_read_partial (struct target_ops *ops, 240130809Smarcel enum target_object object, 241130809Smarcel const char *annex, void *buf, 242130809Smarcel ULONGEST offset, LONGEST len); 243130809Smarcel 244130809Smarcelextern LONGEST target_write_partial (struct target_ops *ops, 245130809Smarcel enum target_object object, 246130809Smarcel const char *annex, const void *buf, 247130809Smarcel ULONGEST offset, LONGEST len); 248130809Smarcel 249130809Smarcel/* Wrappers to perform the full transfer. */ 250130809Smarcelextern LONGEST target_read (struct target_ops *ops, 251130809Smarcel enum target_object object, 252130809Smarcel const char *annex, void *buf, 253130809Smarcel ULONGEST offset, LONGEST len); 254130809Smarcel 255130809Smarcelextern LONGEST target_write (struct target_ops *ops, 256130809Smarcel enum target_object object, 257130809Smarcel const char *annex, const void *buf, 258130809Smarcel ULONGEST offset, LONGEST len); 259130809Smarcel 260130809Smarcel/* Wrappers to target read/write that perform memory transfers. They 261130809Smarcel throw an error if the memory transfer fails. 262130809Smarcel 263130809Smarcel NOTE: cagney/2003-10-23: The naming schema is lifted from 264130809Smarcel "frame.h". The parameter order is lifted from get_frame_memory, 265130809Smarcel which in turn lifted it from read_memory. */ 266130809Smarcel 267130809Smarcelextern void get_target_memory (struct target_ops *ops, CORE_ADDR addr, 268130809Smarcel void *buf, LONGEST len); 269130809Smarcelextern ULONGEST get_target_memory_unsigned (struct target_ops *ops, 270130809Smarcel CORE_ADDR addr, int len); 271130809Smarcel 272130809Smarcel 27319370Spst/* If certain kinds of activity happen, target_wait should perform 27419370Spst callbacks. */ 27519370Spst/* Right now we just call (*TARGET_ACTIVITY_FUNCTION) if I/O is possible 27699002Sobrien on TARGET_ACTIVITY_FD. */ 27719370Spstextern int target_activity_fd; 27819370Spst/* Returns zero to leave the inferior alone, one to interrupt it. */ 27999002Sobrienextern int (*target_activity_function) (void); 28019370Spst 28199002Sobrienstruct thread_info; /* fwd decl for parameter list below: */ 28299002Sobrien 28319370Spststruct target_ops 28499002Sobrien { 285130809Smarcel struct target_ops *beneath; /* To the target under this one. */ 28699002Sobrien char *to_shortname; /* Name this target type */ 28799002Sobrien char *to_longname; /* Name for printing */ 28899002Sobrien char *to_doc; /* Documentation. Does not include trailing 28919370Spst newline, and starts with a one-line descrip- 29099002Sobrien tion (probably similar to to_longname). */ 291130809Smarcel /* Per-target scratch pad. */ 292130809Smarcel void *to_data; 293130809Smarcel /* The open routine takes the rest of the parameters from the 294130809Smarcel command, and (if successful) pushes a new target onto the 295130809Smarcel stack. Targets should supply this routine, if only to provide 296130809Smarcel an error message. */ 29799002Sobrien void (*to_open) (char *, int); 298130809Smarcel /* Old targets with a static target vector provide "to_close". 299130809Smarcel New re-entrant targets provide "to_xclose" and that is expected 300130809Smarcel to xfree everything (including the "struct target_ops"). */ 301130809Smarcel void (*to_xclose) (struct target_ops *targ, int quitting); 30299002Sobrien void (*to_close) (int); 30399002Sobrien void (*to_attach) (char *, int); 30499002Sobrien void (*to_post_attach) (int); 30599002Sobrien void (*to_detach) (char *, int); 306130809Smarcel void (*to_disconnect) (char *, int); 30799002Sobrien void (*to_resume) (ptid_t, int, enum target_signal); 30899002Sobrien ptid_t (*to_wait) (ptid_t, struct target_waitstatus *); 30999002Sobrien void (*to_post_wait) (ptid_t, int); 31099002Sobrien void (*to_fetch_registers) (int); 31199002Sobrien void (*to_store_registers) (int); 31299002Sobrien void (*to_prepare_to_store) (void); 31319370Spst 31499002Sobrien /* Transfer LEN bytes of memory between GDB address MYADDR and 31599002Sobrien target address MEMADDR. If WRITE, transfer them to the target, else 31699002Sobrien transfer them from the target. TARGET is the target from which we 31799002Sobrien get this function. 31819370Spst 31999002Sobrien Return value, N, is one of the following: 32019370Spst 32199002Sobrien 0 means that we can't handle this. If errno has been set, it is the 32299002Sobrien error which prevented us from doing it (FIXME: What about bfd_error?). 32319370Spst 32499002Sobrien positive (call it N) means that we have transferred N bytes 32599002Sobrien starting at MEMADDR. We might be able to handle more bytes 32699002Sobrien beyond this length, but no promises. 32719370Spst 32899002Sobrien negative (call its absolute value N) means that we cannot 32999002Sobrien transfer right at MEMADDR, but we could transfer at least 33099002Sobrien something at MEMADDR + N. */ 33119370Spst 33299002Sobrien int (*to_xfer_memory) (CORE_ADDR memaddr, char *myaddr, 333130809Smarcel int len, int write, 33499002Sobrien struct mem_attrib *attrib, 33599002Sobrien struct target_ops *target); 33619370Spst 33799002Sobrien void (*to_files_info) (struct target_ops *); 33899002Sobrien int (*to_insert_breakpoint) (CORE_ADDR, char *); 33999002Sobrien int (*to_remove_breakpoint) (CORE_ADDR, char *); 340130809Smarcel int (*to_can_use_hw_breakpoint) (int, int, int); 341130809Smarcel int (*to_insert_hw_breakpoint) (CORE_ADDR, char *); 342130809Smarcel int (*to_remove_hw_breakpoint) (CORE_ADDR, char *); 343130809Smarcel int (*to_remove_watchpoint) (CORE_ADDR, int, int); 344130809Smarcel int (*to_insert_watchpoint) (CORE_ADDR, int, int); 345130809Smarcel int (*to_stopped_by_watchpoint) (void); 346130809Smarcel int to_have_continuable_watchpoint; 347130809Smarcel CORE_ADDR (*to_stopped_data_address) (void); 348130809Smarcel int (*to_region_size_ok_for_hw_watchpoint) (int); 34999002Sobrien void (*to_terminal_init) (void); 35099002Sobrien void (*to_terminal_inferior) (void); 35199002Sobrien void (*to_terminal_ours_for_output) (void); 35299002Sobrien void (*to_terminal_ours) (void); 353130809Smarcel void (*to_terminal_save_ours) (void); 35499002Sobrien void (*to_terminal_info) (char *, int); 35599002Sobrien void (*to_kill) (void); 35699002Sobrien void (*to_load) (char *, int); 35799002Sobrien int (*to_lookup_symbol) (char *, CORE_ADDR *); 35899002Sobrien void (*to_create_inferior) (char *, char *, char **); 35999002Sobrien void (*to_post_startup_inferior) (ptid_t); 36099002Sobrien void (*to_acknowledge_created_inferior) (int); 36199002Sobrien int (*to_insert_fork_catchpoint) (int); 36299002Sobrien int (*to_remove_fork_catchpoint) (int); 36399002Sobrien int (*to_insert_vfork_catchpoint) (int); 36499002Sobrien int (*to_remove_vfork_catchpoint) (int); 365130809Smarcel int (*to_follow_fork) (int); 36699002Sobrien int (*to_insert_exec_catchpoint) (int); 36799002Sobrien int (*to_remove_exec_catchpoint) (int); 36899002Sobrien int (*to_reported_exec_events_per_exec_call) (void); 36999002Sobrien int (*to_has_exited) (int, int, int *); 37099002Sobrien void (*to_mourn_inferior) (void); 37199002Sobrien int (*to_can_run) (void); 37299002Sobrien void (*to_notice_signals) (ptid_t ptid); 37399002Sobrien int (*to_thread_alive) (ptid_t ptid); 37499002Sobrien void (*to_find_new_threads) (void); 37599002Sobrien char *(*to_pid_to_str) (ptid_t); 37699002Sobrien char *(*to_extra_thread_info) (struct thread_info *); 37799002Sobrien void (*to_stop) (void); 37899002Sobrien void (*to_rcmd) (char *command, struct ui_file *output); 37999002Sobrien struct symtab_and_line *(*to_enable_exception_callback) (enum 38099002Sobrien exception_event_kind, 38199002Sobrien int); 38299002Sobrien struct exception_event_record *(*to_get_current_exception_event) (void); 38399002Sobrien char *(*to_pid_to_exec_file) (int pid); 38499002Sobrien enum strata to_stratum; 38599002Sobrien int to_has_all_memory; 38699002Sobrien int to_has_memory; 38799002Sobrien int to_has_stack; 38899002Sobrien int to_has_registers; 38999002Sobrien int to_has_execution; 39099002Sobrien int to_has_thread_control; /* control thread execution */ 39199002Sobrien struct section_table 39299002Sobrien *to_sections; 39399002Sobrien struct section_table 39499002Sobrien *to_sections_end; 39599002Sobrien /* ASYNC target controls */ 39699002Sobrien int (*to_can_async_p) (void); 39799002Sobrien int (*to_is_async_p) (void); 39899002Sobrien void (*to_async) (void (*cb) (enum inferior_event_type, void *context), 39999002Sobrien void *context); 40099002Sobrien int to_async_mask_value; 401130809Smarcel int (*to_find_memory_regions) (int (*) (CORE_ADDR, 402130809Smarcel unsigned long, 403130809Smarcel int, int, int, 404130809Smarcel void *), 40599002Sobrien void *); 40699002Sobrien char * (*to_make_corefile_notes) (bfd *, int *); 407130809Smarcel 408130809Smarcel /* Return the thread-local address at OFFSET in the 409130809Smarcel thread-local storage for the thread PTID and the shared library 410130809Smarcel or executable file given by OBJFILE. If that block of 411130809Smarcel thread-local storage hasn't been allocated yet, this function 412130809Smarcel may return an error. */ 413130809Smarcel CORE_ADDR (*to_get_thread_local_address) (ptid_t ptid, 414130809Smarcel struct objfile *objfile, 415130809Smarcel CORE_ADDR offset); 416130809Smarcel 417130809Smarcel /* Perform partial transfers on OBJECT. See target_read_partial 418130809Smarcel and target_write_partial for details of each variant. One, and 419130809Smarcel only one, of readbuf or writebuf must be non-NULL. */ 420130809Smarcel LONGEST (*to_xfer_partial) (struct target_ops *ops, 421130809Smarcel enum target_object object, const char *annex, 422130809Smarcel void *readbuf, const void *writebuf, 423130809Smarcel ULONGEST offset, LONGEST len); 424130809Smarcel 42599002Sobrien int to_magic; 42699002Sobrien /* Need sub-structure for target machine related rather than comm related? 42799002Sobrien */ 42899002Sobrien }; 42919370Spst 43019370Spst/* Magic number for checking ops size. If a struct doesn't end with this 43119370Spst number, somebody changed the declaration but didn't change all the 43219370Spst places that initialize one. */ 43319370Spst 43419370Spst#define OPS_MAGIC 3840 43519370Spst 43619370Spst/* The ops structure for our "current" target process. This should 43719370Spst never be NULL. If there is no target, it points to the dummy_target. */ 43819370Spst 43999002Sobrienextern struct target_ops current_target; 44019370Spst 44119370Spst/* Define easy words for doing these operations on our current target. */ 44219370Spst 44319370Spst#define target_shortname (current_target.to_shortname) 44419370Spst#define target_longname (current_target.to_longname) 44519370Spst 446130809Smarcel/* Does whatever cleanup is required for a target that we are no 447130809Smarcel longer going to be calling. QUITTING indicates that GDB is exiting 448130809Smarcel and should not get hung on an error (otherwise it is important to 449130809Smarcel perform clean termination, even if it takes a while). This routine 450130809Smarcel is automatically always called when popping the target off the 451130809Smarcel target stack (to_beneath is undefined). Closing file descriptors 452130809Smarcel and freeing all memory allocated memory are typical things it 453130809Smarcel should do. */ 45419370Spst 455130809Smarcelvoid target_close (struct target_ops *targ, int quitting); 45699002Sobrien 45719370Spst/* Attaches to a process on the target side. Arguments are as passed 45819370Spst to the `attach' command by the user. This routine can be called 45919370Spst when the target is not on the target-stack, if the target_can_run 460130809Smarcel routine returns 1; in that case, it must push itself onto the stack. 46119370Spst Upon exit, the target should be ready for normal operations, and 462130809Smarcel should be ready to deliver the status of the process immediately 46319370Spst (without waiting) to an upcoming target_wait call. */ 46419370Spst 46519370Spst#define target_attach(args, from_tty) \ 46699002Sobrien (*current_target.to_attach) (args, from_tty) 46719370Spst 46846289Sdfr/* The target_attach operation places a process under debugger control, 46946289Sdfr and stops the process. 47046289Sdfr 47146289Sdfr This operation provides a target-specific hook that allows the 47299002Sobrien necessary bookkeeping to be performed after an attach completes. */ 47346289Sdfr#define target_post_attach(pid) \ 47499002Sobrien (*current_target.to_post_attach) (pid) 47546289Sdfr 47619370Spst/* Takes a program previously attached to and detaches it. 47719370Spst The program may resume execution (some targets do, some don't) and will 47819370Spst no longer stop on signals, etc. We better not have left any breakpoints 47919370Spst in the program or it'll die when it hits one. ARGS is arguments 48019370Spst typed by the user (e.g. a signal to send the process). FROM_TTY 48119370Spst says whether to be verbose or not. */ 48219370Spst 48399002Sobrienextern void target_detach (char *, int); 48419370Spst 485130809Smarcel/* Disconnect from the current target without resuming it (leaving it 486130809Smarcel waiting for a debugger). */ 48746289Sdfr 488130809Smarcelextern void target_disconnect (char *, int); 48946289Sdfr 49099002Sobrien/* Resume execution of the target process PTID. STEP says whether to 49119370Spst single-step or to run free; SIGGNAL is the signal to be given to 49219370Spst the target, or TARGET_SIGNAL_0 for no signal. The caller may not 49319370Spst pass TARGET_SIGNAL_DEFAULT. */ 49419370Spst 49599002Sobrien#define target_resume(ptid, step, siggnal) \ 49699002Sobrien do { \ 49799002Sobrien dcache_invalidate(target_dcache); \ 49899002Sobrien (*current_target.to_resume) (ptid, step, siggnal); \ 49999002Sobrien } while (0) 50019370Spst 50199002Sobrien/* Wait for process pid to do something. PTID = -1 to wait for any 50299002Sobrien pid to do something. Return pid of child, or -1 in case of error; 50319370Spst store status through argument pointer STATUS. Note that it is 50499002Sobrien _NOT_ OK to throw_exception() out of target_wait() without popping 50519370Spst the debugging target from the stack; GDB isn't prepared to get back 50619370Spst to the prompt with a debugging target but without the frame cache, 50719370Spst stop_pc, etc., set up. */ 50819370Spst 50999002Sobrien#define target_wait(ptid, status) \ 51099002Sobrien (*current_target.to_wait) (ptid, status) 51119370Spst 51246289Sdfr/* The target_wait operation waits for a process event to occur, and 51346289Sdfr thereby stop the process. 51446289Sdfr 51546289Sdfr On some targets, certain events may happen in sequences. gdb's 51646289Sdfr correct response to any single event of such a sequence may require 51746289Sdfr knowledge of what earlier events in the sequence have been seen. 51846289Sdfr 51946289Sdfr This operation provides a target-specific hook that allows the 52099002Sobrien necessary bookkeeping to be performed to track such sequences. */ 52146289Sdfr 52299002Sobrien#define target_post_wait(ptid, status) \ 52399002Sobrien (*current_target.to_post_wait) (ptid, status) 52446289Sdfr 52599002Sobrien/* Fetch at least register REGNO, or all regs if regno == -1. No result. */ 52619370Spst 52719370Spst#define target_fetch_registers(regno) \ 52899002Sobrien (*current_target.to_fetch_registers) (regno) 52919370Spst 53019370Spst/* Store at least register REGNO, or all regs if REGNO == -1. 53119370Spst It can store as many registers as it wants to, so target_prepare_to_store 53219370Spst must have been previously called. Calls error() if there are problems. */ 53319370Spst 53419370Spst#define target_store_registers(regs) \ 53599002Sobrien (*current_target.to_store_registers) (regs) 53619370Spst 53719370Spst/* Get ready to modify the registers array. On machines which store 53819370Spst individual registers, this doesn't need to do anything. On machines 53919370Spst which store all the registers in one fell swoop, this makes sure 54019370Spst that REGISTERS contains all the registers from the program being 54119370Spst debugged. */ 54219370Spst 54319370Spst#define target_prepare_to_store() \ 54499002Sobrien (*current_target.to_prepare_to_store) () 54519370Spst 54699002Sobrienextern DCACHE *target_dcache; 54719370Spst 54899002Sobrienextern int do_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write, 54999002Sobrien struct mem_attrib *attrib); 55019370Spst 55199002Sobrienextern int target_read_string (CORE_ADDR, char **, int, int *); 55246289Sdfr 55399002Sobrienextern int target_read_memory (CORE_ADDR memaddr, char *myaddr, int len); 55419370Spst 55599002Sobrienextern int target_write_memory (CORE_ADDR memaddr, char *myaddr, int len); 55619370Spst 557130809Smarcelextern int xfer_memory (CORE_ADDR, char *, int, int, 55899002Sobrien struct mem_attrib *, struct target_ops *); 55919370Spst 560130809Smarcelextern int child_xfer_memory (CORE_ADDR, char *, int, int, 56199002Sobrien struct mem_attrib *, struct target_ops *); 56219370Spst 56399002Sobrien/* Make a single attempt at transfering LEN bytes. On a successful 56499002Sobrien transfer, the number of bytes actually transfered is returned and 56599002Sobrien ERR is set to 0. When a transfer fails, -1 is returned (the number 56699002Sobrien of bytes actually transfered is not defined) and ERR is set to a 56799002Sobrien non-zero error indication. */ 56819370Spst 569130809Smarcelextern int target_read_memory_partial (CORE_ADDR addr, char *buf, int len, 570130809Smarcel int *err); 57119370Spst 572130809Smarcelextern int target_write_memory_partial (CORE_ADDR addr, char *buf, int len, 573130809Smarcel int *err); 57499002Sobrien 57599002Sobrienextern char *child_pid_to_exec_file (int); 57699002Sobrien 57799002Sobrienextern char *child_core_file_to_sym_file (char *); 57899002Sobrien 57946289Sdfr#if defined(CHILD_POST_ATTACH) 58099002Sobrienextern void child_post_attach (int); 58146289Sdfr#endif 58246289Sdfr 58399002Sobrienextern void child_post_wait (ptid_t, int); 58446289Sdfr 58599002Sobrienextern void child_post_startup_inferior (ptid_t); 58646289Sdfr 58799002Sobrienextern void child_acknowledge_created_inferior (int); 58846289Sdfr 58999002Sobrienextern int child_insert_fork_catchpoint (int); 59046289Sdfr 59199002Sobrienextern int child_remove_fork_catchpoint (int); 59246289Sdfr 59399002Sobrienextern int child_insert_vfork_catchpoint (int); 59446289Sdfr 59599002Sobrienextern int child_remove_vfork_catchpoint (int); 59646289Sdfr 59799002Sobrienextern void child_acknowledge_created_inferior (int); 59846289Sdfr 599130809Smarcelextern int child_follow_fork (int); 60046289Sdfr 60199002Sobrienextern int child_insert_exec_catchpoint (int); 60246289Sdfr 60399002Sobrienextern int child_remove_exec_catchpoint (int); 60446289Sdfr 60599002Sobrienextern int child_reported_exec_events_per_exec_call (void); 60646289Sdfr 60799002Sobrienextern int child_has_exited (int, int, int *); 60846289Sdfr 60999002Sobrienextern int child_thread_alive (ptid_t); 61046289Sdfr 611130809Smarcel/* From infrun.c. */ 612130809Smarcel 613130809Smarcelextern int inferior_has_forked (int pid, int *child_pid); 614130809Smarcel 615130809Smarcelextern int inferior_has_vforked (int pid, int *child_pid); 616130809Smarcel 617130809Smarcelextern int inferior_has_execd (int pid, char **execd_pathname); 618130809Smarcel 61919370Spst/* From exec.c */ 62019370Spst 62199002Sobrienextern void print_section_info (struct target_ops *, bfd *); 62219370Spst 62319370Spst/* Print a line about the current target. */ 62419370Spst 62519370Spst#define target_files_info() \ 62699002Sobrien (*current_target.to_files_info) (¤t_target) 62719370Spst 628130809Smarcel/* Insert a breakpoint at address ADDR in the target machine. SAVE is 629130809Smarcel a pointer to memory allocated for saving the target contents. It 630130809Smarcel is guaranteed by the caller to be long enough to save the number of 631130809Smarcel breakpoint bytes indicated by BREAKPOINT_FROM_PC. Result is 0 for 632130809Smarcel success, or an errno value. */ 63319370Spst 63419370Spst#define target_insert_breakpoint(addr, save) \ 63599002Sobrien (*current_target.to_insert_breakpoint) (addr, save) 63619370Spst 63719370Spst/* Remove a breakpoint at address ADDR in the target machine. 638130809Smarcel SAVE is a pointer to the same save area 639130809Smarcel that was previously passed to target_insert_breakpoint. 64019370Spst Result is 0 for success, or an errno value. */ 64119370Spst 64219370Spst#define target_remove_breakpoint(addr, save) \ 64399002Sobrien (*current_target.to_remove_breakpoint) (addr, save) 64419370Spst 64519370Spst/* Initialize the terminal settings we record for the inferior, 64619370Spst before we actually run the inferior. */ 64719370Spst 64819370Spst#define target_terminal_init() \ 64999002Sobrien (*current_target.to_terminal_init) () 65019370Spst 65119370Spst/* Put the inferior's terminal settings into effect. 65219370Spst This is preparation for starting or resuming the inferior. */ 65319370Spst 65419370Spst#define target_terminal_inferior() \ 65599002Sobrien (*current_target.to_terminal_inferior) () 65619370Spst 65719370Spst/* Put some of our terminal settings into effect, 65819370Spst enough to get proper results from our output, 65919370Spst but do not change into or out of RAW mode 66019370Spst so that no input is discarded. 66119370Spst 66219370Spst After doing this, either terminal_ours or terminal_inferior 66319370Spst should be called to get back to a normal state of affairs. */ 66419370Spst 66519370Spst#define target_terminal_ours_for_output() \ 66699002Sobrien (*current_target.to_terminal_ours_for_output) () 66719370Spst 66819370Spst/* Put our terminal settings into effect. 66919370Spst First record the inferior's terminal settings 67019370Spst so they can be restored properly later. */ 67119370Spst 67219370Spst#define target_terminal_ours() \ 67399002Sobrien (*current_target.to_terminal_ours) () 67419370Spst 675130809Smarcel/* Save our terminal settings. 676130809Smarcel This is called from TUI after entering or leaving the curses 677130809Smarcel mode. Since curses modifies our terminal this call is here 678130809Smarcel to take this change into account. */ 679130809Smarcel 680130809Smarcel#define target_terminal_save_ours() \ 681130809Smarcel (*current_target.to_terminal_save_ours) () 682130809Smarcel 68319370Spst/* Print useful information about our terminal status, if such a thing 68419370Spst exists. */ 68519370Spst 68619370Spst#define target_terminal_info(arg, from_tty) \ 68799002Sobrien (*current_target.to_terminal_info) (arg, from_tty) 68819370Spst 68919370Spst/* Kill the inferior process. Make it go away. */ 69019370Spst 69119370Spst#define target_kill() \ 69299002Sobrien (*current_target.to_kill) () 69319370Spst 69499002Sobrien/* Load an executable file into the target process. This is expected 69599002Sobrien to not only bring new code into the target process, but also to 69699002Sobrien update GDB's symbol tables to match. */ 69719370Spst 69899002Sobrienextern void target_load (char *arg, int from_tty); 69919370Spst 70019370Spst/* Look up a symbol in the target's symbol table. NAME is the symbol 70199002Sobrien name. ADDRP is a CORE_ADDR * pointing to where the value of the 70299002Sobrien symbol should be returned. The result is 0 if successful, nonzero 70399002Sobrien if the symbol does not exist in the target environment. This 70499002Sobrien function should not call error() if communication with the target 70599002Sobrien is interrupted, since it is called from symbol reading, but should 70699002Sobrien return nonzero, possibly doing a complain(). */ 70719370Spst 70899002Sobrien#define target_lookup_symbol(name, addrp) \ 70999002Sobrien (*current_target.to_lookup_symbol) (name, addrp) 71019370Spst 71199002Sobrien/* Start an inferior process and set inferior_ptid to its pid. 71219370Spst EXEC_FILE is the file to run. 71319370Spst ALLARGS is a string containing the arguments to the program. 71419370Spst ENV is the environment vector to pass. Errors reported with error(). 71519370Spst On VxWorks and various standalone systems, we ignore exec_file. */ 71699002Sobrien 71719370Spst#define target_create_inferior(exec_file, args, env) \ 71899002Sobrien (*current_target.to_create_inferior) (exec_file, args, env) 71919370Spst 72046289Sdfr 72146289Sdfr/* Some targets (such as ttrace-based HPUX) don't allow us to request 72246289Sdfr notification of inferior events such as fork and vork immediately 72346289Sdfr after the inferior is created. (This because of how gdb gets an 72446289Sdfr inferior created via invoking a shell to do it. In such a scenario, 72546289Sdfr if the shell init file has commands in it, the shell will fork and 72646289Sdfr exec for each of those commands, and we will see each such fork 72746289Sdfr event. Very bad.) 72846289Sdfr 72999002Sobrien Such targets will supply an appropriate definition for this function. */ 73099002Sobrien 73199002Sobrien#define target_post_startup_inferior(ptid) \ 73299002Sobrien (*current_target.to_post_startup_inferior) (ptid) 73399002Sobrien 73446289Sdfr/* On some targets, the sequence of starting up an inferior requires 73599002Sobrien some synchronization between gdb and the new inferior process, PID. */ 73699002Sobrien 73746289Sdfr#define target_acknowledge_created_inferior(pid) \ 73899002Sobrien (*current_target.to_acknowledge_created_inferior) (pid) 73946289Sdfr 74099002Sobrien/* On some targets, we can catch an inferior fork or vfork event when 74199002Sobrien it occurs. These functions insert/remove an already-created 74299002Sobrien catchpoint for such events. */ 74399002Sobrien 74446289Sdfr#define target_insert_fork_catchpoint(pid) \ 74599002Sobrien (*current_target.to_insert_fork_catchpoint) (pid) 74646289Sdfr 74746289Sdfr#define target_remove_fork_catchpoint(pid) \ 74899002Sobrien (*current_target.to_remove_fork_catchpoint) (pid) 74946289Sdfr 75046289Sdfr#define target_insert_vfork_catchpoint(pid) \ 75199002Sobrien (*current_target.to_insert_vfork_catchpoint) (pid) 75246289Sdfr 75346289Sdfr#define target_remove_vfork_catchpoint(pid) \ 75499002Sobrien (*current_target.to_remove_vfork_catchpoint) (pid) 75546289Sdfr 756130809Smarcel/* If the inferior forks or vforks, this function will be called at 757130809Smarcel the next resume in order to perform any bookkeeping and fiddling 758130809Smarcel necessary to continue debugging either the parent or child, as 759130809Smarcel requested, and releasing the other. Information about the fork 760130809Smarcel or vfork event is available via get_last_target_status (). 761130809Smarcel This function returns 1 if the inferior should not be resumed 762130809Smarcel (i.e. there is another event pending). */ 76399002Sobrien 764130809Smarcel#define target_follow_fork(follow_child) \ 765130809Smarcel (*current_target.to_follow_fork) (follow_child) 76646289Sdfr 76746289Sdfr/* On some targets, we can catch an inferior exec event when it 76899002Sobrien occurs. These functions insert/remove an already-created 76999002Sobrien catchpoint for such events. */ 77099002Sobrien 77146289Sdfr#define target_insert_exec_catchpoint(pid) \ 77299002Sobrien (*current_target.to_insert_exec_catchpoint) (pid) 77399002Sobrien 77446289Sdfr#define target_remove_exec_catchpoint(pid) \ 77599002Sobrien (*current_target.to_remove_exec_catchpoint) (pid) 77646289Sdfr 77746289Sdfr/* Returns the number of exec events that are reported when a process 77846289Sdfr invokes a flavor of the exec() system call on this target, if exec 77999002Sobrien events are being reported. */ 78099002Sobrien 78146289Sdfr#define target_reported_exec_events_per_exec_call() \ 78299002Sobrien (*current_target.to_reported_exec_events_per_exec_call) () 78346289Sdfr 78446289Sdfr/* Returns TRUE if PID has exited. And, also sets EXIT_STATUS to the 78599002Sobrien exit code of PID, if any. */ 78699002Sobrien 78746289Sdfr#define target_has_exited(pid,wait_status,exit_status) \ 78899002Sobrien (*current_target.to_has_exited) (pid,wait_status,exit_status) 78946289Sdfr 79046289Sdfr/* The debugger has completed a blocking wait() call. There is now 791130809Smarcel some process event that must be processed. This function should 79246289Sdfr be defined by those targets that require the debugger to perform 79399002Sobrien cleanup or internal state changes in response to the process event. */ 79446289Sdfr 79519370Spst/* The inferior process has died. Do what is right. */ 79619370Spst 79719370Spst#define target_mourn_inferior() \ 79899002Sobrien (*current_target.to_mourn_inferior) () 79919370Spst 80019370Spst/* Does target have enough data to do a run or attach command? */ 80119370Spst 80219370Spst#define target_can_run(t) \ 80399002Sobrien ((t)->to_can_run) () 80419370Spst 80519370Spst/* post process changes to signal handling in the inferior. */ 80619370Spst 80799002Sobrien#define target_notice_signals(ptid) \ 80899002Sobrien (*current_target.to_notice_signals) (ptid) 80919370Spst 81019370Spst/* Check to see if a thread is still alive. */ 81119370Spst 81299002Sobrien#define target_thread_alive(ptid) \ 81399002Sobrien (*current_target.to_thread_alive) (ptid) 81419370Spst 81599002Sobrien/* Query for new threads and add them to the thread list. */ 81619370Spst 81799002Sobrien#define target_find_new_threads() \ 81899002Sobrien (*current_target.to_find_new_threads) (); \ 81999002Sobrien 82099002Sobrien/* Make target stop in a continuable fashion. (For instance, under 82199002Sobrien Unix, this should act like SIGSTOP). This function is normally 82299002Sobrien used by GUIs to implement a stop button. */ 82399002Sobrien 82446289Sdfr#define target_stop current_target.to_stop 82519370Spst 82699002Sobrien/* Send the specified COMMAND to the target's monitor 82799002Sobrien (shell,interpreter) for execution. The result of the query is 82899002Sobrien placed in OUTBUF. */ 82999002Sobrien 83099002Sobrien#define target_rcmd(command, outbuf) \ 83199002Sobrien (*current_target.to_rcmd) (command, outbuf) 83299002Sobrien 83399002Sobrien 83446289Sdfr/* Get the symbol information for a breakpointable routine called when 835130809Smarcel an exception event occurs. 83646289Sdfr Intended mainly for C++, and for those 83746289Sdfr platforms/implementations where such a callback mechanism is available, 83846289Sdfr e.g. HP-UX with ANSI C++ (aCC). Some compilers (e.g. g++) support 83999002Sobrien different mechanisms for debugging exceptions. */ 84046289Sdfr 84146289Sdfr#define target_enable_exception_callback(kind, enable) \ 84299002Sobrien (*current_target.to_enable_exception_callback) (kind, enable) 84346289Sdfr 84499002Sobrien/* Get the current exception event kind -- throw or catch, etc. */ 84599002Sobrien 84646289Sdfr#define target_get_current_exception_event() \ 84799002Sobrien (*current_target.to_get_current_exception_event) () 84846289Sdfr 84919370Spst/* Does the target include all of memory, or only part of it? This 85019370Spst determines whether we look up the target chain for other parts of 85119370Spst memory if this target can't satisfy a request. */ 85219370Spst 85319370Spst#define target_has_all_memory \ 85499002Sobrien (current_target.to_has_all_memory) 85519370Spst 85619370Spst/* Does the target include memory? (Dummy targets don't.) */ 85719370Spst 85819370Spst#define target_has_memory \ 85999002Sobrien (current_target.to_has_memory) 86019370Spst 86119370Spst/* Does the target have a stack? (Exec files don't, VxWorks doesn't, until 86219370Spst we start a process.) */ 86399002Sobrien 86419370Spst#define target_has_stack \ 86599002Sobrien (current_target.to_has_stack) 86619370Spst 86719370Spst/* Does the target have registers? (Exec files don't.) */ 86819370Spst 86919370Spst#define target_has_registers \ 87099002Sobrien (current_target.to_has_registers) 87119370Spst 87219370Spst/* Does the target have execution? Can we make it jump (through 87319370Spst hoops), or pop its stack a few times? FIXME: If this is to work that 87419370Spst way, it needs to check whether an inferior actually exists. 87519370Spst remote-udi.c and probably other targets can be the current target 87619370Spst when the inferior doesn't actually exist at the moment. Right now 87719370Spst this just tells us whether this target is *capable* of execution. */ 87819370Spst 87919370Spst#define target_has_execution \ 88099002Sobrien (current_target.to_has_execution) 88119370Spst 88246289Sdfr/* Can the target support the debugger control of thread execution? 88346289Sdfr a) Can it lock the thread scheduler? 88446289Sdfr b) Can it switch the currently running thread? */ 88546289Sdfr 88646289Sdfr#define target_can_lock_scheduler \ 88799002Sobrien (current_target.to_has_thread_control & tc_schedlock) 88846289Sdfr 88946289Sdfr#define target_can_switch_threads \ 89099002Sobrien (current_target.to_has_thread_control & tc_switch) 89146289Sdfr 89299002Sobrien/* Can the target support asynchronous execution? */ 89399002Sobrien#define target_can_async_p() (current_target.to_can_async_p ()) 89419370Spst 89599002Sobrien/* Is the target in asynchronous execution mode? */ 89699002Sobrien#define target_is_async_p() (current_target.to_is_async_p()) 89799002Sobrien 89899002Sobrien/* Put the target in async mode with the specified callback function. */ 89999002Sobrien#define target_async(CALLBACK,CONTEXT) \ 90099002Sobrien (current_target.to_async((CALLBACK), (CONTEXT))) 90199002Sobrien 902130809Smarcel/* This is to be used ONLY within call_function_by_hand(). It provides 903130809Smarcel a workaround, to have inferior function calls done in sychronous 904130809Smarcel mode, even though the target is asynchronous. After 90599002Sobrien target_async_mask(0) is called, calls to target_can_async_p() will 90699002Sobrien return FALSE , so that target_resume() will not try to start the 90799002Sobrien target asynchronously. After the inferior stops, we IMMEDIATELY 90899002Sobrien restore the previous nature of the target, by calling 90999002Sobrien target_async_mask(1). After that, target_can_async_p() will return 910130809Smarcel TRUE. ANY OTHER USE OF THIS FEATURE IS DEPRECATED. 91199002Sobrien 91299002Sobrien FIXME ezannoni 1999-12-13: we won't need this once we move 91399002Sobrien the turning async on and off to the single execution commands, 91499002Sobrien from where it is done currently, in remote_resume(). */ 91599002Sobrien 91699002Sobrien#define target_async_mask_value \ 91799002Sobrien (current_target.to_async_mask_value) 91899002Sobrien 919130809Smarcelextern int target_async_mask (int mask); 92099002Sobrien 92199002Sobrienextern void target_link (char *, CORE_ADDR *); 92299002Sobrien 92319370Spst/* Converts a process id to a string. Usually, the string just contains 92419370Spst `process xyz', but on some systems it may contain 92519370Spst `process xyz thread abc'. */ 92619370Spst 92799002Sobrien#undef target_pid_to_str 92899002Sobrien#define target_pid_to_str(PID) current_target.to_pid_to_str (PID) 92919370Spst 93046289Sdfr#ifndef target_tid_to_str 93146289Sdfr#define target_tid_to_str(PID) \ 93299002Sobrien target_pid_to_str (PID) 93399002Sobrienextern char *normal_pid_to_str (ptid_t ptid); 93446289Sdfr#endif 93546289Sdfr 93699002Sobrien/* Return a short string describing extra information about PID, 93799002Sobrien e.g. "sleeping", "runnable", "running on LWP 3". Null return value 93899002Sobrien is okay. */ 93946289Sdfr 94099002Sobrien#define target_extra_thread_info(TP) \ 94199002Sobrien (current_target.to_extra_thread_info (TP)) 94299002Sobrien 94399002Sobrien/* 94499002Sobrien * New Objfile Event Hook: 94599002Sobrien * 94699002Sobrien * Sometimes a GDB component wants to get notified whenever a new 947130809Smarcel * objfile is loaded. Mainly this is used by thread-debugging 94899002Sobrien * implementations that need to know when symbols for the target 94999002Sobrien * thread implemenation are available. 95099002Sobrien * 95199002Sobrien * The old way of doing this is to define a macro 'target_new_objfile' 95299002Sobrien * that points to the function that you want to be called on every 95399002Sobrien * objfile/shlib load. 95499002Sobrien * 95599002Sobrien * The new way is to grab the function pointer, 'target_new_objfile_hook', 95699002Sobrien * and point it to the function that you want to be called on every 95799002Sobrien * objfile/shlib load. 95899002Sobrien * 95999002Sobrien * If multiple clients are willing to be cooperative, they can each 96099002Sobrien * save a pointer to the previous value of target_new_objfile_hook 96199002Sobrien * before modifying it, and arrange for their function to call the 96299002Sobrien * previous function in the chain. In that way, multiple clients 96399002Sobrien * can receive this notification (something like with signal handlers). 96499002Sobrien */ 96599002Sobrien 96699002Sobrienextern void (*target_new_objfile_hook) (struct objfile *); 96799002Sobrien 96846289Sdfr#ifndef target_pid_or_tid_to_str 96946289Sdfr#define target_pid_or_tid_to_str(ID) \ 97099002Sobrien target_pid_to_str (ID) 97146289Sdfr#endif 97246289Sdfr 97346289Sdfr/* Attempts to find the pathname of the executable file 97446289Sdfr that was run to create a specified process. 97546289Sdfr 97646289Sdfr The process PID must be stopped when this operation is used. 97799002Sobrien 97846289Sdfr If the executable file cannot be determined, NULL is returned. 97946289Sdfr 98046289Sdfr Else, a pointer to a character string containing the pathname 98146289Sdfr is returned. This string should be copied into a buffer by 98246289Sdfr the client if the string will not be immediately used, or if 98399002Sobrien it must persist. */ 98446289Sdfr 98546289Sdfr#define target_pid_to_exec_file(pid) \ 98699002Sobrien (current_target.to_pid_to_exec_file) (pid) 98746289Sdfr 98899002Sobrien/* 98999002Sobrien * Iterator function for target memory regions. 99099002Sobrien * Calls a callback function once for each memory region 'mapped' 99199002Sobrien * in the child process. Defined as a simple macro rather than 992130809Smarcel * as a function macro so that it can be tested for nullity. 99399002Sobrien */ 99419370Spst 99599002Sobrien#define target_find_memory_regions(FUNC, DATA) \ 99699002Sobrien (current_target.to_find_memory_regions) (FUNC, DATA) 99799002Sobrien 99899002Sobrien/* 99999002Sobrien * Compose corefile .note section. 100099002Sobrien */ 100199002Sobrien 100299002Sobrien#define target_make_corefile_notes(BFD, SIZE_P) \ 100399002Sobrien (current_target.to_make_corefile_notes) (BFD, SIZE_P) 100499002Sobrien 1005130809Smarcel/* Thread-local values. */ 1006130809Smarcel#define target_get_thread_local_address \ 1007130809Smarcel (current_target.to_get_thread_local_address) 1008130809Smarcel#define target_get_thread_local_address_p() \ 1009130809Smarcel (target_get_thread_local_address != NULL) 101099002Sobrien 101199002Sobrien/* Hook to call target dependent code just after inferior target process has 101219370Spst started. */ 101319370Spst 101419370Spst#ifndef TARGET_CREATE_INFERIOR_HOOK 101519370Spst#define TARGET_CREATE_INFERIOR_HOOK(PID) 101619370Spst#endif 101719370Spst 101819370Spst/* Hardware watchpoint interfaces. */ 101919370Spst 102019370Spst/* Returns non-zero if we were stopped by a hardware watchpoint (memory read or 102119370Spst write). */ 102219370Spst 102319370Spst#ifndef STOPPED_BY_WATCHPOINT 1024130809Smarcel#define STOPPED_BY_WATCHPOINT(w) \ 1025130809Smarcel (*current_target.to_stopped_by_watchpoint) () 102619370Spst#endif 102719370Spst 1028130809Smarcel/* Non-zero if we have continuable watchpoints */ 1029130809Smarcel 1030130809Smarcel#ifndef HAVE_CONTINUABLE_WATCHPOINT 1031130809Smarcel#define HAVE_CONTINUABLE_WATCHPOINT \ 1032130809Smarcel (current_target.to_have_continuable_watchpoint) 1033130809Smarcel#endif 1034130809Smarcel 103546289Sdfr/* HP-UX supplies these operations, which respectively disable and enable 103646289Sdfr the memory page-protections that are used to implement hardware watchpoints 103799002Sobrien on that platform. See wait_for_inferior's use of these. */ 103899002Sobrien 103946289Sdfr#if !defined(TARGET_DISABLE_HW_WATCHPOINTS) 104046289Sdfr#define TARGET_DISABLE_HW_WATCHPOINTS(pid) 104146289Sdfr#endif 104246289Sdfr 104346289Sdfr#if !defined(TARGET_ENABLE_HW_WATCHPOINTS) 104446289Sdfr#define TARGET_ENABLE_HW_WATCHPOINTS(pid) 104546289Sdfr#endif 104646289Sdfr 1047130809Smarcel/* Provide defaults for hardware watchpoint functions. */ 104819370Spst 1049130809Smarcel/* If the *_hw_beakpoint functions have not been defined 1050130809Smarcel elsewhere use the definitions in the target vector. */ 105119370Spst 105219370Spst/* Returns non-zero if we can set a hardware watchpoint of type TYPE. TYPE is 105319370Spst one of bp_hardware_watchpoint, bp_read_watchpoint, bp_write_watchpoint, or 105419370Spst bp_hardware_breakpoint. CNT is the number of such watchpoints used so far 105519370Spst (including this one?). OTHERTYPE is who knows what... */ 105619370Spst 1057130809Smarcel#ifndef TARGET_CAN_USE_HARDWARE_WATCHPOINT 1058130809Smarcel#define TARGET_CAN_USE_HARDWARE_WATCHPOINT(TYPE,CNT,OTHERTYPE) \ 1059130809Smarcel (*current_target.to_can_use_hw_breakpoint) (TYPE, CNT, OTHERTYPE); 1060130809Smarcel#endif 106119370Spst 106246289Sdfr#if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT) 106346289Sdfr#define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(byte_count) \ 1064130809Smarcel (*current_target.to_region_size_ok_for_hw_watchpoint) (byte_count) 106546289Sdfr#endif 106619370Spst 106746289Sdfr 106846289Sdfr/* Set/clear a hardware watchpoint starting at ADDR, for LEN bytes. TYPE is 0 106946289Sdfr for write, 1 for read, and 2 for read/write accesses. Returns 0 for 107046289Sdfr success, non-zero for failure. */ 107146289Sdfr 1072130809Smarcel#ifndef target_insert_watchpoint 1073130809Smarcel#define target_insert_watchpoint(addr, len, type) \ 1074130809Smarcel (*current_target.to_insert_watchpoint) (addr, len, type) 107519370Spst 1076130809Smarcel#define target_remove_watchpoint(addr, len, type) \ 1077130809Smarcel (*current_target.to_remove_watchpoint) (addr, len, type) 1078130809Smarcel#endif 107919370Spst 108019370Spst#ifndef target_insert_hw_breakpoint 1081130809Smarcel#define target_insert_hw_breakpoint(addr, save) \ 1082130809Smarcel (*current_target.to_insert_hw_breakpoint) (addr, save) 1083130809Smarcel 1084130809Smarcel#define target_remove_hw_breakpoint(addr, save) \ 1085130809Smarcel (*current_target.to_remove_hw_breakpoint) (addr, save) 108619370Spst#endif 108719370Spst 108819370Spst#ifndef target_stopped_data_address 1089130809Smarcel#define target_stopped_data_address() \ 1090130809Smarcel (*current_target.to_stopped_data_address) () 109119370Spst#endif 109219370Spst 109346289Sdfr/* Sometimes gdb may pick up what appears to be a valid target address 109446289Sdfr from a minimal symbol, but the value really means, essentially, 109546289Sdfr "This is an index into a table which is populated when the inferior 109699002Sobrien is run. Therefore, do not attempt to use this as a PC." */ 109799002Sobrien 109846289Sdfr#if !defined(PC_REQUIRES_RUN_BEFORE_USE) 109946289Sdfr#define PC_REQUIRES_RUN_BEFORE_USE(pc) (0) 110046289Sdfr#endif 110146289Sdfr 110246289Sdfr/* This will only be defined by a target that supports catching vfork events, 110346289Sdfr such as HP-UX. 110446289Sdfr 110546289Sdfr On some targets (such as HP-UX 10.20 and earlier), resuming a newly vforked 110646289Sdfr child process after it has exec'd, causes the parent process to resume as 110746289Sdfr well. To prevent the parent from running spontaneously, such targets should 110899002Sobrien define this to a function that prevents that from happening. */ 110946289Sdfr#if !defined(ENSURE_VFORKING_PARENT_REMAINS_STOPPED) 111046289Sdfr#define ENSURE_VFORKING_PARENT_REMAINS_STOPPED(PID) (0) 111146289Sdfr#endif 111246289Sdfr 111346289Sdfr/* This will only be defined by a target that supports catching vfork events, 111446289Sdfr such as HP-UX. 111546289Sdfr 111646289Sdfr On some targets (such as HP-UX 10.20 and earlier), a newly vforked child 111746289Sdfr process must be resumed when it delivers its exec event, before the parent 111899002Sobrien vfork event will be delivered to us. */ 111999002Sobrien 112046289Sdfr#if !defined(RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK) 112146289Sdfr#define RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK() (0) 112246289Sdfr#endif 112346289Sdfr 112419370Spst/* Routines for maintenance of the target structures... 112519370Spst 112619370Spst add_target: Add a target to the list of all possible targets. 112719370Spst 112819370Spst push_target: Make this target the top of the stack of currently used 112999002Sobrien targets, within its particular stratum of the stack. Result 113099002Sobrien is 0 if now atop the stack, nonzero if not on top (maybe 113199002Sobrien should warn user). 113219370Spst 113319370Spst unpush_target: Remove this from the stack of currently used targets, 113499002Sobrien no matter where it is on the list. Returns 0 if no 113599002Sobrien change, 1 if removed from stack. 113619370Spst 113799002Sobrien pop_target: Remove the top thing on the stack of current targets. */ 113819370Spst 113999002Sobrienextern void add_target (struct target_ops *); 114019370Spst 114199002Sobrienextern int push_target (struct target_ops *); 114219370Spst 114399002Sobrienextern int unpush_target (struct target_ops *); 114419370Spst 114599002Sobrienextern void target_preopen (int); 114619370Spst 114799002Sobrienextern void pop_target (void); 114819370Spst 114919370Spst/* Struct section_table maps address ranges to file sections. It is 115019370Spst mostly used with BFD files, but can be used without (e.g. for handling 115119370Spst raw disks, or files not in formats handled by BFD). */ 115219370Spst 115399002Sobrienstruct section_table 115499002Sobrien { 115599002Sobrien CORE_ADDR addr; /* Lowest address in section */ 115699002Sobrien CORE_ADDR endaddr; /* 1+highest address in section */ 115719370Spst 1158130809Smarcel struct bfd_section *the_bfd_section; 115919370Spst 116099002Sobrien bfd *bfd; /* BFD file pointer */ 116199002Sobrien }; 116219370Spst 1163130809Smarcel/* Return the "section" containing the specified address. */ 1164130809Smarcelstruct section_table *target_section_by_addr (struct target_ops *target, 1165130809Smarcel CORE_ADDR addr); 116619370Spst 116719370Spst 116819370Spst/* From mem-break.c */ 116919370Spst 117099002Sobrienextern int memory_remove_breakpoint (CORE_ADDR, char *); 117119370Spst 117299002Sobrienextern int memory_insert_breakpoint (CORE_ADDR, char *); 117319370Spst 117499002Sobrienextern int default_memory_remove_breakpoint (CORE_ADDR, char *); 117599002Sobrien 117699002Sobrienextern int default_memory_insert_breakpoint (CORE_ADDR, char *); 117799002Sobrien 117846289Sdfr 117919370Spst/* From target.c */ 118019370Spst 118199002Sobrienextern void initialize_targets (void); 118246289Sdfr 118399002Sobrienextern void noprocess (void); 118419370Spst 118599002Sobrienextern void find_default_attach (char *, int); 118619370Spst 118799002Sobrienextern void find_default_create_inferior (char *, char *, char **); 118819370Spst 118999002Sobrienextern struct target_ops *find_run_target (void); 119099002Sobrien 119199002Sobrienextern struct target_ops *find_core_target (void); 119299002Sobrien 119399002Sobrienextern struct target_ops *find_target_beneath (struct target_ops *); 119499002Sobrien 1195130809Smarcelextern int target_resize_to_sections (struct target_ops *target, 1196130809Smarcel int num_added); 119799002Sobrien 119899002Sobrienextern void remove_target_sections (bfd *abfd); 119999002Sobrien 120019370Spst 120119370Spst/* Stuff that should be shared among the various remote targets. */ 120219370Spst 120319370Spst/* Debugging level. 0 is off, and non-zero values mean to print some debug 120419370Spst information (higher values, more information). */ 120519370Spstextern int remote_debug; 120619370Spst 120719370Spst/* Speed in bits per second, or -1 which means don't mess with the speed. */ 120819370Spstextern int baud_rate; 120946289Sdfr/* Timeout limit for response from target. */ 121046289Sdfrextern int remote_timeout; 121146289Sdfr 121219370Spst 121319370Spst/* Functions for helping to write a native target. */ 121419370Spst 121519370Spst/* This is for native targets which use a unix/POSIX-style waitstatus. */ 121699002Sobrienextern void store_waitstatus (struct target_waitstatus *, int); 121719370Spst 121899002Sobrien/* Predicate to target_signal_to_host(). Return non-zero if the enum 121999002Sobrien targ_signal SIGNO has an equivalent ``host'' representation. */ 122099002Sobrien/* FIXME: cagney/1999-11-22: The name below was chosen in preference 122199002Sobrien to the shorter target_signal_p() because it is far less ambigious. 122299002Sobrien In this context ``target_signal'' refers to GDB's internal 122399002Sobrien representation of the target's set of signals while ``host signal'' 122499002Sobrien refers to the target operating system's signal. Confused? */ 122519370Spst 122699002Sobrienextern int target_signal_to_host_p (enum target_signal signo); 122799002Sobrien 122899002Sobrien/* Convert between host signal numbers and enum target_signal's. 122999002Sobrien target_signal_to_host() returns 0 and prints a warning() on GDB's 123099002Sobrien console if SIGNO has no equivalent host representation. */ 123199002Sobrien/* FIXME: cagney/1999-11-22: Here ``host'' is used incorrectly, it is 123299002Sobrien refering to the target operating system's signal numbering. 123399002Sobrien Similarly, ``enum target_signal'' is named incorrectly, ``enum 123499002Sobrien gdb_signal'' would probably be better as it is refering to GDB's 123599002Sobrien internal representation of a target operating system's signal. */ 123699002Sobrien 123799002Sobrienextern enum target_signal target_signal_from_host (int); 123899002Sobrienextern int target_signal_to_host (enum target_signal); 123999002Sobrien 124019370Spst/* Convert from a number used in a GDB command to an enum target_signal. */ 124199002Sobrienextern enum target_signal target_signal_from_command (int); 124219370Spst 124346289Sdfr/* Any target can call this to switch to remote protocol (in remote.c). */ 124499002Sobrienextern void push_remote_target (char *name, int from_tty); 124546289Sdfr 124646289Sdfr/* Imported from machine dependent code */ 124746289Sdfr 124846289Sdfr/* Blank target vector entries are initialized to target_ignore. */ 124999002Sobrienvoid target_ignore (void); 125046289Sdfr 125199002Sobrien#endif /* !defined (TARGET_H) */ 1252