target.h 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583
  1. /* Interface between GDB and target environments, including files and processes
  2. Copyright (C) 1990-2022 Free Software Foundation, Inc.
  3. Contributed by Cygnus Support. Written by John Gilmore.
  4. This file is part of GDB.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #if !defined (TARGET_H)
  16. #define TARGET_H
  17. struct objfile;
  18. struct ui_file;
  19. struct mem_attrib;
  20. struct target_ops;
  21. struct bp_location;
  22. struct bp_target_info;
  23. struct regcache;
  24. struct trace_state_variable;
  25. struct trace_status;
  26. struct uploaded_tsv;
  27. struct uploaded_tp;
  28. struct static_tracepoint_marker;
  29. struct traceframe_info;
  30. struct expression;
  31. struct dcache_struct;
  32. struct inferior;
  33. #include "infrun.h" /* For enum exec_direction_kind. */
  34. #include "breakpoint.h" /* For enum bptype. */
  35. #include "gdbsupport/scoped_restore.h"
  36. #include "gdbsupport/refcounted-object.h"
  37. #include "target-section.h"
  38. /* This include file defines the interface between the main part
  39. of the debugger, and the part which is target-specific, or
  40. specific to the communications interface between us and the
  41. target.
  42. A TARGET is an interface between the debugger and a particular
  43. kind of file or process. Targets can be STACKED in STRATA,
  44. so that more than one target can potentially respond to a request.
  45. In particular, memory accesses will walk down the stack of targets
  46. until they find a target that is interested in handling that particular
  47. address. STRATA are artificial boundaries on the stack, within
  48. which particular kinds of targets live. Strata exist so that
  49. people don't get confused by pushing e.g. a process target and then
  50. a file target, and wondering why they can't see the current values
  51. of variables any more (the file target is handling them and they
  52. never get to the process target). So when you push a file target,
  53. it goes into the file stratum, which is always below the process
  54. stratum.
  55. Note that rather than allow an empty stack, we always have the
  56. dummy target at the bottom stratum, so we can call the target
  57. methods without checking them. */
  58. #include "target/target.h"
  59. #include "target/resume.h"
  60. #include "target/wait.h"
  61. #include "target/waitstatus.h"
  62. #include "bfd.h"
  63. #include "symtab.h"
  64. #include "memattr.h"
  65. #include "gdbsupport/gdb_signals.h"
  66. #include "btrace.h"
  67. #include "record.h"
  68. #include "command.h"
  69. #include "disasm-flags.h"
  70. #include "tracepoint.h"
  71. #include "gdbsupport/break-common.h" /* For enum target_hw_bp_type. */
  72. enum strata
  73. {
  74. dummy_stratum, /* The lowest of the low */
  75. file_stratum, /* Executable files, etc */
  76. process_stratum, /* Executing processes or core dump files */
  77. thread_stratum, /* Executing threads */
  78. record_stratum, /* Support record debugging */
  79. arch_stratum, /* Architecture overrides */
  80. debug_stratum /* Target debug. Must be last. */
  81. };
  82. enum thread_control_capabilities
  83. {
  84. tc_none = 0, /* Default: can't control thread execution. */
  85. tc_schedlock = 1, /* Can lock the thread scheduler. */
  86. };
  87. /* The structure below stores information about a system call.
  88. It is basically used in the "catch syscall" command, and in
  89. every function that gives information about a system call.
  90. It's also good to mention that its fields represent everything
  91. that we currently know about a syscall in GDB. */
  92. struct syscall
  93. {
  94. /* The syscall number. */
  95. int number;
  96. /* The syscall name. */
  97. const char *name;
  98. };
  99. /* Return a pretty printed form of TARGET_OPTIONS. */
  100. extern std::string target_options_to_string (target_wait_flags target_options);
  101. /* Possible types of events that the inferior handler will have to
  102. deal with. */
  103. enum inferior_event_type
  104. {
  105. /* Process a normal inferior event which will result in target_wait
  106. being called. */
  107. INF_REG_EVENT,
  108. /* We are called to do stuff after the inferior stops. */
  109. INF_EXEC_COMPLETE,
  110. };
  111. /* Target objects which can be transfered using target_read,
  112. target_write, et cetera. */
  113. enum target_object
  114. {
  115. /* AVR target specific transfer. See "avr-tdep.c" and "remote.c". */
  116. TARGET_OBJECT_AVR,
  117. /* Transfer up-to LEN bytes of memory starting at OFFSET. */
  118. TARGET_OBJECT_MEMORY,
  119. /* Memory, avoiding GDB's data cache and trusting the executable.
  120. Target implementations of to_xfer_partial never need to handle
  121. this object, and most callers should not use it. */
  122. TARGET_OBJECT_RAW_MEMORY,
  123. /* Memory known to be part of the target's stack. This is cached even
  124. if it is not in a region marked as such, since it is known to be
  125. "normal" RAM. */
  126. TARGET_OBJECT_STACK_MEMORY,
  127. /* Memory known to be part of the target code. This is cached even
  128. if it is not in a region marked as such. */
  129. TARGET_OBJECT_CODE_MEMORY,
  130. /* Kernel Unwind Table. See "ia64-tdep.c". */
  131. TARGET_OBJECT_UNWIND_TABLE,
  132. /* Transfer auxilliary vector. */
  133. TARGET_OBJECT_AUXV,
  134. /* StackGhost cookie. See "sparc-tdep.c". */
  135. TARGET_OBJECT_WCOOKIE,
  136. /* Target memory map in XML format. */
  137. TARGET_OBJECT_MEMORY_MAP,
  138. /* Flash memory. This object can be used to write contents to
  139. a previously erased flash memory. Using it without erasing
  140. flash can have unexpected results. Addresses are physical
  141. address on target, and not relative to flash start. */
  142. TARGET_OBJECT_FLASH,
  143. /* Available target-specific features, e.g. registers and coprocessors.
  144. See "target-descriptions.c". ANNEX should never be empty. */
  145. TARGET_OBJECT_AVAILABLE_FEATURES,
  146. /* Currently loaded libraries, in XML format. */
  147. TARGET_OBJECT_LIBRARIES,
  148. /* Currently loaded libraries specific for SVR4 systems, in XML format. */
  149. TARGET_OBJECT_LIBRARIES_SVR4,
  150. /* Currently loaded libraries specific to AIX systems, in XML format. */
  151. TARGET_OBJECT_LIBRARIES_AIX,
  152. /* Get OS specific data. The ANNEX specifies the type (running
  153. processes, etc.). The data being transfered is expected to follow
  154. the DTD specified in features/osdata.dtd. */
  155. TARGET_OBJECT_OSDATA,
  156. /* Extra signal info. Usually the contents of `siginfo_t' on unix
  157. platforms. */
  158. TARGET_OBJECT_SIGNAL_INFO,
  159. /* The list of threads that are being debugged. */
  160. TARGET_OBJECT_THREADS,
  161. /* Collected static trace data. */
  162. TARGET_OBJECT_STATIC_TRACE_DATA,
  163. /* Traceframe info, in XML format. */
  164. TARGET_OBJECT_TRACEFRAME_INFO,
  165. /* Load maps for FDPIC systems. */
  166. TARGET_OBJECT_FDPIC,
  167. /* Darwin dynamic linker info data. */
  168. TARGET_OBJECT_DARWIN_DYLD_INFO,
  169. /* OpenVMS Unwind Information Block. */
  170. TARGET_OBJECT_OPENVMS_UIB,
  171. /* Branch trace data, in XML format. */
  172. TARGET_OBJECT_BTRACE,
  173. /* Branch trace configuration, in XML format. */
  174. TARGET_OBJECT_BTRACE_CONF,
  175. /* The pathname of the executable file that was run to create
  176. a specified process. ANNEX should be a string representation
  177. of the process ID of the process in question, in hexadecimal
  178. format. */
  179. TARGET_OBJECT_EXEC_FILE,
  180. /* FreeBSD virtual memory mappings. */
  181. TARGET_OBJECT_FREEBSD_VMMAP,
  182. /* FreeBSD process strings. */
  183. TARGET_OBJECT_FREEBSD_PS_STRINGS,
  184. /* Possible future objects: TARGET_OBJECT_FILE, ... */
  185. };
  186. /* Possible values returned by target_xfer_partial, etc. */
  187. enum target_xfer_status
  188. {
  189. /* Some bytes are transferred. */
  190. TARGET_XFER_OK = 1,
  191. /* No further transfer is possible. */
  192. TARGET_XFER_EOF = 0,
  193. /* The piece of the object requested is unavailable. */
  194. TARGET_XFER_UNAVAILABLE = 2,
  195. /* Generic I/O error. Note that it's important that this is '-1',
  196. as we still have target_xfer-related code returning hardcoded
  197. '-1' on error. */
  198. TARGET_XFER_E_IO = -1,
  199. /* Keep list in sync with target_xfer_status_to_string. */
  200. };
  201. /* Return the string form of STATUS. */
  202. extern const char *
  203. target_xfer_status_to_string (enum target_xfer_status status);
  204. typedef enum target_xfer_status
  205. target_xfer_partial_ftype (struct target_ops *ops,
  206. enum target_object object,
  207. const char *annex,
  208. gdb_byte *readbuf,
  209. const gdb_byte *writebuf,
  210. ULONGEST offset,
  211. ULONGEST len,
  212. ULONGEST *xfered_len);
  213. enum target_xfer_status
  214. raw_memory_xfer_partial (struct target_ops *ops, gdb_byte *readbuf,
  215. const gdb_byte *writebuf, ULONGEST memaddr,
  216. LONGEST len, ULONGEST *xfered_len);
  217. /* Request that OPS transfer up to LEN addressable units of the target's
  218. OBJECT. When reading from a memory object, the size of an addressable unit
  219. is architecture dependent and can be found using
  220. gdbarch_addressable_memory_unit_size. Otherwise, an addressable unit is 1
  221. byte long. BUF should point to a buffer large enough to hold the read data,
  222. taking into account the addressable unit size. The OFFSET, for a seekable
  223. object, specifies the starting point. The ANNEX can be used to provide
  224. additional data-specific information to the target.
  225. Return the number of addressable units actually transferred, or a negative
  226. error code (an 'enum target_xfer_error' value) if the transfer is not
  227. supported or otherwise fails. Return of a positive value less than
  228. LEN indicates that no further transfer is possible. Unlike the raw
  229. to_xfer_partial interface, callers of these functions do not need
  230. to retry partial transfers. */
  231. extern LONGEST target_read (struct target_ops *ops,
  232. enum target_object object,
  233. const char *annex, gdb_byte *buf,
  234. ULONGEST offset, LONGEST len);
  235. struct memory_read_result
  236. {
  237. memory_read_result (ULONGEST begin_, ULONGEST end_,
  238. gdb::unique_xmalloc_ptr<gdb_byte> &&data_)
  239. : begin (begin_),
  240. end (end_),
  241. data (std::move (data_))
  242. {
  243. }
  244. ~memory_read_result () = default;
  245. memory_read_result (memory_read_result &&other) = default;
  246. DISABLE_COPY_AND_ASSIGN (memory_read_result);
  247. /* First address that was read. */
  248. ULONGEST begin;
  249. /* Past-the-end address. */
  250. ULONGEST end;
  251. /* The data. */
  252. gdb::unique_xmalloc_ptr<gdb_byte> data;
  253. };
  254. extern std::vector<memory_read_result> read_memory_robust
  255. (struct target_ops *ops, const ULONGEST offset, const LONGEST len);
  256. /* Request that OPS transfer up to LEN addressable units from BUF to the
  257. target's OBJECT. When writing to a memory object, the addressable unit
  258. size is architecture dependent and can be found using
  259. gdbarch_addressable_memory_unit_size. Otherwise, an addressable unit is 1
  260. byte long. The OFFSET, for a seekable object, specifies the starting point.
  261. The ANNEX can be used to provide additional data-specific information to
  262. the target.
  263. Return the number of addressable units actually transferred, or a negative
  264. error code (an 'enum target_xfer_status' value) if the transfer is not
  265. supported or otherwise fails. Return of a positive value less than
  266. LEN indicates that no further transfer is possible. Unlike the raw
  267. to_xfer_partial interface, callers of these functions do not need to
  268. retry partial transfers. */
  269. extern LONGEST target_write (struct target_ops *ops,
  270. enum target_object object,
  271. const char *annex, const gdb_byte *buf,
  272. ULONGEST offset, LONGEST len);
  273. /* Similar to target_write, except that it also calls PROGRESS with
  274. the number of bytes written and the opaque BATON after every
  275. successful partial write (and before the first write). This is
  276. useful for progress reporting and user interaction while writing
  277. data. To abort the transfer, the progress callback can throw an
  278. exception. */
  279. LONGEST target_write_with_progress (struct target_ops *ops,
  280. enum target_object object,
  281. const char *annex, const gdb_byte *buf,
  282. ULONGEST offset, LONGEST len,
  283. void (*progress) (ULONGEST, void *),
  284. void *baton);
  285. /* Wrapper to perform a full read of unknown size. OBJECT/ANNEX will be read
  286. using OPS. The return value will be uninstantiated if the transfer fails or
  287. is not supported.
  288. This method should be used for objects sufficiently small to store
  289. in a single xmalloc'd buffer, when no fixed bound on the object's
  290. size is known in advance. Don't try to read TARGET_OBJECT_MEMORY
  291. through this function. */
  292. extern gdb::optional<gdb::byte_vector> target_read_alloc
  293. (struct target_ops *ops, enum target_object object, const char *annex);
  294. /* Read OBJECT/ANNEX using OPS. The result is a NUL-terminated character vector
  295. (therefore usable as a NUL-terminated string). If an error occurs or the
  296. transfer is unsupported, the return value will be uninstantiated. Empty
  297. objects are returned as allocated but empty strings. Therefore, on success,
  298. the returned vector is guaranteed to have at least one element. A warning is
  299. issued if the result contains any embedded NUL bytes. */
  300. extern gdb::optional<gdb::char_vector> target_read_stralloc
  301. (struct target_ops *ops, enum target_object object, const char *annex);
  302. /* See target_ops->to_xfer_partial. */
  303. extern target_xfer_partial_ftype target_xfer_partial;
  304. /* Wrappers to target read/write that perform memory transfers. They
  305. throw an error if the memory transfer fails.
  306. NOTE: cagney/2003-10-23: The naming schema is lifted from
  307. "frame.h". The parameter order is lifted from get_frame_memory,
  308. which in turn lifted it from read_memory. */
  309. extern void get_target_memory (struct target_ops *ops, CORE_ADDR addr,
  310. gdb_byte *buf, LONGEST len);
  311. extern ULONGEST get_target_memory_unsigned (struct target_ops *ops,
  312. CORE_ADDR addr, int len,
  313. enum bfd_endian byte_order);
  314. struct thread_info; /* fwd decl for parameter list below: */
  315. /* The type of the callback to the to_async method. */
  316. typedef void async_callback_ftype (enum inferior_event_type event_type,
  317. void *context);
  318. /* Normally target debug printing is purely type-based. However,
  319. sometimes it is necessary to override the debug printing on a
  320. per-argument basis. This macro can be used, attribute-style, to
  321. name the target debug printing function for a particular method
  322. argument. FUNC is the name of the function. The macro's
  323. definition is empty because it is only used by the
  324. make-target-delegates script. */
  325. #define TARGET_DEBUG_PRINTER(FUNC)
  326. /* These defines are used to mark target_ops methods. The script
  327. make-target-delegates scans these and auto-generates the base
  328. method implementations. There are four macros that can be used:
  329. 1. TARGET_DEFAULT_IGNORE. There is no argument. The base method
  330. does nothing. This is only valid if the method return type is
  331. 'void'.
  332. 2. TARGET_DEFAULT_NORETURN. The argument is a function call, like
  333. 'tcomplain ()'. The base method simply makes this call, which is
  334. assumed not to return.
  335. 3. TARGET_DEFAULT_RETURN. The argument is a C expression. The
  336. base method returns this expression's value.
  337. 4. TARGET_DEFAULT_FUNC. The argument is the name of a function.
  338. make-target-delegates does not generate a base method in this case,
  339. but instead uses the argument function as the base method. */
  340. #define TARGET_DEFAULT_IGNORE()
  341. #define TARGET_DEFAULT_NORETURN(ARG)
  342. #define TARGET_DEFAULT_RETURN(ARG)
  343. #define TARGET_DEFAULT_FUNC(ARG)
  344. /* Each target that can be activated with "target TARGET_NAME" passes
  345. the address of one of these objects to add_target, which uses the
  346. object's address as unique identifier, and registers the "target
  347. TARGET_NAME" command using SHORTNAME as target name. */
  348. struct target_info
  349. {
  350. /* Name of this target. */
  351. const char *shortname;
  352. /* Name for printing. */
  353. const char *longname;
  354. /* Documentation. Does not include trailing newline, and starts
  355. with a one-line description (probably similar to longname). */
  356. const char *doc;
  357. };
  358. struct target_ops
  359. : public refcounted_object
  360. {
  361. /* Return this target's stratum. */
  362. virtual strata stratum () const = 0;
  363. /* To the target under this one. */
  364. target_ops *beneath () const;
  365. /* Free resources associated with the target. Note that singleton
  366. targets, like e.g., native targets, are global objects, not
  367. heap allocated, and are thus only deleted on GDB exit. The
  368. main teardown entry point is the "close" method, below. */
  369. virtual ~target_ops () {}
  370. /* Return a reference to this target's unique target_info
  371. object. */
  372. virtual const target_info &info () const = 0;
  373. /* Name this target type. */
  374. const char *shortname () const
  375. { return info ().shortname; }
  376. const char *longname () const
  377. { return info ().longname; }
  378. /* Close the target. This is where the target can handle
  379. teardown. Heap-allocated targets should delete themselves
  380. before returning. */
  381. virtual void close ();
  382. /* Attaches to a process on the target side. Arguments are as
  383. passed to the `attach' command by the user. This routine can
  384. be called when the target is not on the target-stack, if the
  385. target_ops::can_run method returns 1; in that case, it must push
  386. itself onto the stack. Upon exit, the target should be ready
  387. for normal operations, and should be ready to deliver the
  388. status of the process immediately (without waiting) to an
  389. upcoming target_wait call. */
  390. virtual bool can_attach ();
  391. virtual void attach (const char *, int);
  392. virtual void post_attach (int)
  393. TARGET_DEFAULT_IGNORE ();
  394. /* Detaches from the inferior. Note that on targets that support
  395. async execution (i.e., targets where it is possible to detach
  396. from programs with threads running), the target is responsible
  397. for removing breakpoints from the program before the actual
  398. detach, otherwise the program dies when it hits one. */
  399. virtual void detach (inferior *, int)
  400. TARGET_DEFAULT_IGNORE ();
  401. virtual void disconnect (const char *, int)
  402. TARGET_DEFAULT_NORETURN (tcomplain ());
  403. virtual void resume (ptid_t,
  404. int TARGET_DEBUG_PRINTER (target_debug_print_step),
  405. enum gdb_signal)
  406. TARGET_DEFAULT_NORETURN (noprocess ());
  407. /* Ensure that all resumed threads are committed to the target.
  408. See the description of
  409. process_stratum_target::commit_resumed_state for more
  410. details. */
  411. virtual void commit_resumed ()
  412. TARGET_DEFAULT_IGNORE ();
  413. /* See target_wait's description. Note that implementations of
  414. this method must not assume that inferior_ptid on entry is
  415. pointing at the thread or inferior that ends up reporting an
  416. event. The reported event could be for some other thread in
  417. the current inferior or even for a different process of the
  418. current target. inferior_ptid may also be null_ptid on
  419. entry. */
  420. virtual ptid_t wait (ptid_t, struct target_waitstatus *,
  421. target_wait_flags options)
  422. TARGET_DEFAULT_FUNC (default_target_wait);
  423. virtual void fetch_registers (struct regcache *, int)
  424. TARGET_DEFAULT_IGNORE ();
  425. virtual void store_registers (struct regcache *, int)
  426. TARGET_DEFAULT_NORETURN (noprocess ());
  427. virtual void prepare_to_store (struct regcache *)
  428. TARGET_DEFAULT_NORETURN (noprocess ());
  429. virtual void files_info ()
  430. TARGET_DEFAULT_IGNORE ();
  431. virtual int insert_breakpoint (struct gdbarch *,
  432. struct bp_target_info *)
  433. TARGET_DEFAULT_NORETURN (noprocess ());
  434. virtual int remove_breakpoint (struct gdbarch *,
  435. struct bp_target_info *,
  436. enum remove_bp_reason)
  437. TARGET_DEFAULT_NORETURN (noprocess ());
  438. /* Returns true if the target stopped because it executed a
  439. software breakpoint. This is necessary for correct background
  440. execution / non-stop mode operation, and for correct PC
  441. adjustment on targets where the PC needs to be adjusted when a
  442. software breakpoint triggers. In these modes, by the time GDB
  443. processes a breakpoint event, the breakpoint may already be
  444. done from the target, so GDB needs to be able to tell whether
  445. it should ignore the event and whether it should adjust the PC.
  446. See adjust_pc_after_break. */
  447. virtual bool stopped_by_sw_breakpoint ()
  448. TARGET_DEFAULT_RETURN (false);
  449. /* Returns true if the above method is supported. */
  450. virtual bool supports_stopped_by_sw_breakpoint ()
  451. TARGET_DEFAULT_RETURN (false);
  452. /* Returns true if the target stopped for a hardware breakpoint.
  453. Likewise, if the target supports hardware breakpoints, this
  454. method is necessary for correct background execution / non-stop
  455. mode operation. Even though hardware breakpoints do not
  456. require PC adjustment, GDB needs to be able to tell whether the
  457. hardware breakpoint event is a delayed event for a breakpoint
  458. that is already gone and should thus be ignored. */
  459. virtual bool stopped_by_hw_breakpoint ()
  460. TARGET_DEFAULT_RETURN (false);
  461. /* Returns true if the above method is supported. */
  462. virtual bool supports_stopped_by_hw_breakpoint ()
  463. TARGET_DEFAULT_RETURN (false);
  464. virtual int can_use_hw_breakpoint (enum bptype, int, int)
  465. TARGET_DEFAULT_RETURN (0);
  466. virtual int ranged_break_num_registers ()
  467. TARGET_DEFAULT_RETURN (-1);
  468. virtual int insert_hw_breakpoint (struct gdbarch *,
  469. struct bp_target_info *)
  470. TARGET_DEFAULT_RETURN (-1);
  471. virtual int remove_hw_breakpoint (struct gdbarch *,
  472. struct bp_target_info *)
  473. TARGET_DEFAULT_RETURN (-1);
  474. /* Documentation of what the two routines below are expected to do is
  475. provided with the corresponding target_* macros. */
  476. virtual int remove_watchpoint (CORE_ADDR, int,
  477. enum target_hw_bp_type, struct expression *)
  478. TARGET_DEFAULT_RETURN (-1);
  479. virtual int insert_watchpoint (CORE_ADDR, int,
  480. enum target_hw_bp_type, struct expression *)
  481. TARGET_DEFAULT_RETURN (-1);
  482. virtual int insert_mask_watchpoint (CORE_ADDR, CORE_ADDR,
  483. enum target_hw_bp_type)
  484. TARGET_DEFAULT_RETURN (1);
  485. virtual int remove_mask_watchpoint (CORE_ADDR, CORE_ADDR,
  486. enum target_hw_bp_type)
  487. TARGET_DEFAULT_RETURN (1);
  488. virtual bool stopped_by_watchpoint ()
  489. TARGET_DEFAULT_RETURN (false);
  490. virtual bool have_steppable_watchpoint ()
  491. TARGET_DEFAULT_RETURN (false);
  492. virtual bool stopped_data_address (CORE_ADDR *)
  493. TARGET_DEFAULT_RETURN (false);
  494. virtual bool watchpoint_addr_within_range (CORE_ADDR, CORE_ADDR, int)
  495. TARGET_DEFAULT_FUNC (default_watchpoint_addr_within_range);
  496. /* Documentation of this routine is provided with the corresponding
  497. target_* macro. */
  498. virtual int region_ok_for_hw_watchpoint (CORE_ADDR, int)
  499. TARGET_DEFAULT_FUNC (default_region_ok_for_hw_watchpoint);
  500. virtual bool can_accel_watchpoint_condition (CORE_ADDR, int, int,
  501. struct expression *)
  502. TARGET_DEFAULT_RETURN (false);
  503. virtual int masked_watch_num_registers (CORE_ADDR, CORE_ADDR)
  504. TARGET_DEFAULT_RETURN (-1);
  505. /* Return 1 for sure target can do single step. Return -1 for
  506. unknown. Return 0 for target can't do. */
  507. virtual int can_do_single_step ()
  508. TARGET_DEFAULT_RETURN (-1);
  509. virtual bool supports_terminal_ours ()
  510. TARGET_DEFAULT_RETURN (false);
  511. virtual void terminal_init ()
  512. TARGET_DEFAULT_IGNORE ();
  513. virtual void terminal_inferior ()
  514. TARGET_DEFAULT_IGNORE ();
  515. virtual void terminal_save_inferior ()
  516. TARGET_DEFAULT_IGNORE ();
  517. virtual void terminal_ours_for_output ()
  518. TARGET_DEFAULT_IGNORE ();
  519. virtual void terminal_ours ()
  520. TARGET_DEFAULT_IGNORE ();
  521. virtual void terminal_info (const char *, int)
  522. TARGET_DEFAULT_FUNC (default_terminal_info);
  523. virtual void kill ()
  524. TARGET_DEFAULT_NORETURN (noprocess ());
  525. virtual void load (const char *, int)
  526. TARGET_DEFAULT_NORETURN (tcomplain ());
  527. /* Start an inferior process and set inferior_ptid to its pid.
  528. EXEC_FILE is the file to run.
  529. ALLARGS is a string containing the arguments to the program.
  530. ENV is the environment vector to pass. Errors reported with error().
  531. On VxWorks and various standalone systems, we ignore exec_file. */
  532. virtual bool can_create_inferior ();
  533. virtual void create_inferior (const char *, const std::string &,
  534. char **, int);
  535. virtual int insert_fork_catchpoint (int)
  536. TARGET_DEFAULT_RETURN (1);
  537. virtual int remove_fork_catchpoint (int)
  538. TARGET_DEFAULT_RETURN (1);
  539. virtual int insert_vfork_catchpoint (int)
  540. TARGET_DEFAULT_RETURN (1);
  541. virtual int remove_vfork_catchpoint (int)
  542. TARGET_DEFAULT_RETURN (1);
  543. virtual void follow_fork (inferior *, ptid_t, target_waitkind, bool, bool)
  544. TARGET_DEFAULT_FUNC (default_follow_fork);
  545. virtual int insert_exec_catchpoint (int)
  546. TARGET_DEFAULT_RETURN (1);
  547. virtual int remove_exec_catchpoint (int)
  548. TARGET_DEFAULT_RETURN (1);
  549. virtual void follow_exec (inferior *, ptid_t, const char *)
  550. TARGET_DEFAULT_IGNORE ();
  551. virtual int set_syscall_catchpoint (int, bool, int,
  552. gdb::array_view<const int>)
  553. TARGET_DEFAULT_RETURN (1);
  554. virtual void mourn_inferior ()
  555. TARGET_DEFAULT_FUNC (default_mourn_inferior);
  556. /* Note that can_run is special and can be invoked on an unpushed
  557. target. Targets defining this method must also define
  558. to_can_async_p and to_supports_non_stop. */
  559. virtual bool can_run ();
  560. /* Documentation of this routine is provided with the corresponding
  561. target_* macro. */
  562. virtual void pass_signals (gdb::array_view<const unsigned char> TARGET_DEBUG_PRINTER (target_debug_print_signals))
  563. TARGET_DEFAULT_IGNORE ();
  564. /* Documentation of this routine is provided with the
  565. corresponding target_* function. */
  566. virtual void program_signals (gdb::array_view<const unsigned char> TARGET_DEBUG_PRINTER (target_debug_print_signals))
  567. TARGET_DEFAULT_IGNORE ();
  568. virtual bool thread_alive (ptid_t ptid)
  569. TARGET_DEFAULT_RETURN (false);
  570. virtual void update_thread_list ()
  571. TARGET_DEFAULT_IGNORE ();
  572. virtual std::string pid_to_str (ptid_t)
  573. TARGET_DEFAULT_FUNC (default_pid_to_str);
  574. virtual const char *extra_thread_info (thread_info *)
  575. TARGET_DEFAULT_RETURN (NULL);
  576. virtual const char *thread_name (thread_info *)
  577. TARGET_DEFAULT_RETURN (NULL);
  578. virtual thread_info *thread_handle_to_thread_info (const gdb_byte *,
  579. int,
  580. inferior *inf)
  581. TARGET_DEFAULT_RETURN (NULL);
  582. /* See target_thread_info_to_thread_handle. */
  583. virtual gdb::byte_vector thread_info_to_thread_handle (struct thread_info *)
  584. TARGET_DEFAULT_RETURN (gdb::byte_vector ());
  585. virtual void stop (ptid_t)
  586. TARGET_DEFAULT_IGNORE ();
  587. virtual void interrupt ()
  588. TARGET_DEFAULT_IGNORE ();
  589. virtual void pass_ctrlc ()
  590. TARGET_DEFAULT_FUNC (default_target_pass_ctrlc);
  591. virtual void rcmd (const char *command, struct ui_file *output)
  592. TARGET_DEFAULT_FUNC (default_rcmd);
  593. virtual char *pid_to_exec_file (int pid)
  594. TARGET_DEFAULT_RETURN (NULL);
  595. virtual void log_command (const char *)
  596. TARGET_DEFAULT_IGNORE ();
  597. virtual const target_section_table *get_section_table ()
  598. TARGET_DEFAULT_RETURN (default_get_section_table ());
  599. /* Provide default values for all "must have" methods. */
  600. virtual bool has_all_memory () { return false; }
  601. virtual bool has_memory () { return false; }
  602. virtual bool has_stack () { return false; }
  603. virtual bool has_registers () { return false; }
  604. virtual bool has_execution (inferior *inf) { return false; }
  605. /* Control thread execution. */
  606. virtual thread_control_capabilities get_thread_control_capabilities ()
  607. TARGET_DEFAULT_RETURN (tc_none);
  608. virtual bool attach_no_wait ()
  609. TARGET_DEFAULT_RETURN (0);
  610. /* This method must be implemented in some situations. See the
  611. comment on 'can_run'. */
  612. virtual bool can_async_p ()
  613. TARGET_DEFAULT_RETURN (false);
  614. virtual bool is_async_p ()
  615. TARGET_DEFAULT_RETURN (false);
  616. virtual void async (int)
  617. TARGET_DEFAULT_NORETURN (tcomplain ());
  618. virtual int async_wait_fd ()
  619. TARGET_DEFAULT_NORETURN (noprocess ());
  620. /* Return true if the target has pending events to report to the
  621. core. If true, then GDB avoids resuming the target until all
  622. pending events are consumed, so that multiple resumptions can
  623. be coalesced as an optimization. Most targets can't tell
  624. whether they have pending events without calling target_wait,
  625. so we default to returning false. The only downside is that a
  626. potential optimization is missed. */
  627. virtual bool has_pending_events ()
  628. TARGET_DEFAULT_RETURN (false);
  629. virtual void thread_events (int)
  630. TARGET_DEFAULT_IGNORE ();
  631. /* This method must be implemented in some situations. See the
  632. comment on 'can_run'. */
  633. virtual bool supports_non_stop ()
  634. TARGET_DEFAULT_RETURN (false);
  635. /* Return true if the target operates in non-stop mode even with
  636. "set non-stop off". */
  637. virtual bool always_non_stop_p ()
  638. TARGET_DEFAULT_RETURN (false);
  639. /* find_memory_regions support method for gcore */
  640. virtual int find_memory_regions (find_memory_region_ftype func, void *data)
  641. TARGET_DEFAULT_FUNC (dummy_find_memory_regions);
  642. /* make_corefile_notes support method for gcore */
  643. virtual gdb::unique_xmalloc_ptr<char> make_corefile_notes (bfd *, int *)
  644. TARGET_DEFAULT_FUNC (dummy_make_corefile_notes);
  645. /* get_bookmark support method for bookmarks */
  646. virtual gdb_byte *get_bookmark (const char *, int)
  647. TARGET_DEFAULT_NORETURN (tcomplain ());
  648. /* goto_bookmark support method for bookmarks */
  649. virtual void goto_bookmark (const gdb_byte *, int)
  650. TARGET_DEFAULT_NORETURN (tcomplain ());
  651. /* Return the thread-local address at OFFSET in the
  652. thread-local storage for the thread PTID and the shared library
  653. or executable file given by LOAD_MODULE_ADDR. If that block of
  654. thread-local storage hasn't been allocated yet, this function
  655. may throw an error. LOAD_MODULE_ADDR may be zero for statically
  656. linked multithreaded inferiors. */
  657. virtual CORE_ADDR get_thread_local_address (ptid_t ptid,
  658. CORE_ADDR load_module_addr,
  659. CORE_ADDR offset)
  660. TARGET_DEFAULT_NORETURN (generic_tls_error ());
  661. /* Request that OPS transfer up to LEN addressable units of the target's
  662. OBJECT. When reading from a memory object, the size of an addressable
  663. unit is architecture dependent and can be found using
  664. gdbarch_addressable_memory_unit_size. Otherwise, an addressable unit is
  665. 1 byte long. The OFFSET, for a seekable object, specifies the
  666. starting point. The ANNEX can be used to provide additional
  667. data-specific information to the target.
  668. Return the transferred status, error or OK (an
  669. 'enum target_xfer_status' value). Save the number of addressable units
  670. actually transferred in *XFERED_LEN if transfer is successful
  671. (TARGET_XFER_OK) or the number unavailable units if the requested
  672. data is unavailable (TARGET_XFER_UNAVAILABLE). *XFERED_LEN
  673. smaller than LEN does not indicate the end of the object, only
  674. the end of the transfer; higher level code should continue
  675. transferring if desired. This is handled in target.c.
  676. The interface does not support a "retry" mechanism. Instead it
  677. assumes that at least one addressable unit will be transfered on each
  678. successful call.
  679. NOTE: cagney/2003-10-17: The current interface can lead to
  680. fragmented transfers. Lower target levels should not implement
  681. hacks, such as enlarging the transfer, in an attempt to
  682. compensate for this. Instead, the target stack should be
  683. extended so that it implements supply/collect methods and a
  684. look-aside object cache. With that available, the lowest
  685. target can safely and freely "push" data up the stack.
  686. See target_read and target_write for more information. One,
  687. and only one, of readbuf or writebuf must be non-NULL. */
  688. virtual enum target_xfer_status xfer_partial (enum target_object object,
  689. const char *annex,
  690. gdb_byte *readbuf,
  691. const gdb_byte *writebuf,
  692. ULONGEST offset, ULONGEST len,
  693. ULONGEST *xfered_len)
  694. TARGET_DEFAULT_RETURN (TARGET_XFER_E_IO);
  695. /* Return the limit on the size of any single memory transfer
  696. for the target. */
  697. virtual ULONGEST get_memory_xfer_limit ()
  698. TARGET_DEFAULT_RETURN (ULONGEST_MAX);
  699. /* Returns the memory map for the target. A return value of NULL
  700. means that no memory map is available. If a memory address
  701. does not fall within any returned regions, it's assumed to be
  702. RAM. The returned memory regions should not overlap.
  703. The order of regions does not matter; target_memory_map will
  704. sort regions by starting address. For that reason, this
  705. function should not be called directly except via
  706. target_memory_map.
  707. This method should not cache data; if the memory map could
  708. change unexpectedly, it should be invalidated, and higher
  709. layers will re-fetch it. */
  710. virtual std::vector<mem_region> memory_map ()
  711. TARGET_DEFAULT_RETURN (std::vector<mem_region> ());
  712. /* Erases the region of flash memory starting at ADDRESS, of
  713. length LENGTH.
  714. Precondition: both ADDRESS and ADDRESS+LENGTH should be aligned
  715. on flash block boundaries, as reported by 'to_memory_map'. */
  716. virtual void flash_erase (ULONGEST address, LONGEST length)
  717. TARGET_DEFAULT_NORETURN (tcomplain ());
  718. /* Finishes a flash memory write sequence. After this operation
  719. all flash memory should be available for writing and the result
  720. of reading from areas written by 'to_flash_write' should be
  721. equal to what was written. */
  722. virtual void flash_done ()
  723. TARGET_DEFAULT_NORETURN (tcomplain ());
  724. /* Describe the architecture-specific features of the current
  725. inferior.
  726. Returns the description found, or nullptr if no description was
  727. available.
  728. If some target features differ between threads, the description
  729. returned by read_description (and the resulting gdbarch) won't
  730. accurately describe all threads. In this case, the
  731. thread_architecture method can be used to obtain gdbarches that
  732. accurately describe each thread. */
  733. virtual const struct target_desc *read_description ()
  734. TARGET_DEFAULT_RETURN (NULL);
  735. /* Build the PTID of the thread on which a given task is running,
  736. based on LWP and THREAD. These values are extracted from the
  737. task Private_Data section of the Ada Task Control Block, and
  738. their interpretation depends on the target. */
  739. virtual ptid_t get_ada_task_ptid (long lwp, ULONGEST thread)
  740. TARGET_DEFAULT_FUNC (default_get_ada_task_ptid);
  741. /* Read one auxv entry from *READPTR, not reading locations >= ENDPTR.
  742. Return 0 if *READPTR is already at the end of the buffer.
  743. Return -1 if there is insufficient buffer for a whole entry.
  744. Return 1 if an entry was read into *TYPEP and *VALP. */
  745. virtual int auxv_parse (gdb_byte **readptr,
  746. gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
  747. TARGET_DEFAULT_FUNC (default_auxv_parse);
  748. /* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the
  749. sequence of bytes in PATTERN with length PATTERN_LEN.
  750. The result is 1 if found, 0 if not found, and -1 if there was an error
  751. requiring halting of the search (e.g. memory read error).
  752. If the pattern is found the address is recorded in FOUND_ADDRP. */
  753. virtual int search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
  754. const gdb_byte *pattern, ULONGEST pattern_len,
  755. CORE_ADDR *found_addrp)
  756. TARGET_DEFAULT_FUNC (default_search_memory);
  757. /* Can target execute in reverse? */
  758. virtual bool can_execute_reverse ()
  759. TARGET_DEFAULT_RETURN (false);
  760. /* The direction the target is currently executing. Must be
  761. implemented on targets that support reverse execution and async
  762. mode. The default simply returns forward execution. */
  763. virtual enum exec_direction_kind execution_direction ()
  764. TARGET_DEFAULT_FUNC (default_execution_direction);
  765. /* Does this target support debugging multiple processes
  766. simultaneously? */
  767. virtual bool supports_multi_process ()
  768. TARGET_DEFAULT_RETURN (false);
  769. /* Does this target support enabling and disabling tracepoints while a trace
  770. experiment is running? */
  771. virtual bool supports_enable_disable_tracepoint ()
  772. TARGET_DEFAULT_RETURN (false);
  773. /* Does this target support disabling address space randomization? */
  774. virtual bool supports_disable_randomization ()
  775. TARGET_DEFAULT_FUNC (find_default_supports_disable_randomization);
  776. /* Does this target support the tracenz bytecode for string collection? */
  777. virtual bool supports_string_tracing ()
  778. TARGET_DEFAULT_RETURN (false);
  779. /* Does this target support evaluation of breakpoint conditions on its
  780. end? */
  781. virtual bool supports_evaluation_of_breakpoint_conditions ()
  782. TARGET_DEFAULT_RETURN (false);
  783. /* Does this target support native dumpcore API? */
  784. virtual bool supports_dumpcore ()
  785. TARGET_DEFAULT_RETURN (false);
  786. /* Generate the core file with native target API. */
  787. virtual void dumpcore (const char *filename)
  788. TARGET_DEFAULT_IGNORE ();
  789. /* Does this target support evaluation of breakpoint commands on its
  790. end? */
  791. virtual bool can_run_breakpoint_commands ()
  792. TARGET_DEFAULT_RETURN (false);
  793. /* Determine current architecture of thread PTID.
  794. The target is supposed to determine the architecture of the code where
  795. the target is currently stopped at. The architecture information is
  796. used to perform decr_pc_after_break adjustment, and also to determine
  797. the frame architecture of the innermost frame. ptrace operations need to
  798. operate according to target_gdbarch (). */
  799. virtual struct gdbarch *thread_architecture (ptid_t)
  800. TARGET_DEFAULT_RETURN (NULL);
  801. /* Determine current address space of thread PTID. */
  802. virtual struct address_space *thread_address_space (ptid_t)
  803. TARGET_DEFAULT_RETURN (NULL);
  804. /* Target file operations. */
  805. /* Return true if the filesystem seen by the current inferior
  806. is the local filesystem, false otherwise. */
  807. virtual bool filesystem_is_local ()
  808. TARGET_DEFAULT_RETURN (true);
  809. /* Open FILENAME on the target, in the filesystem as seen by INF,
  810. using FLAGS and MODE. If INF is NULL, use the filesystem seen
  811. by the debugger (GDB or, for remote targets, the remote stub).
  812. If WARN_IF_SLOW is nonzero, print a warning message if the file
  813. is being accessed over a link that may be slow. Return a
  814. target file descriptor, or -1 if an error occurs (and set
  815. *TARGET_ERRNO). */
  816. virtual int fileio_open (struct inferior *inf, const char *filename,
  817. int flags, int mode, int warn_if_slow,
  818. int *target_errno);
  819. /* Write up to LEN bytes from WRITE_BUF to FD on the target.
  820. Return the number of bytes written, or -1 if an error occurs
  821. (and set *TARGET_ERRNO). */
  822. virtual int fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
  823. ULONGEST offset, int *target_errno);
  824. /* Read up to LEN bytes FD on the target into READ_BUF.
  825. Return the number of bytes read, or -1 if an error occurs
  826. (and set *TARGET_ERRNO). */
  827. virtual int fileio_pread (int fd, gdb_byte *read_buf, int len,
  828. ULONGEST offset, int *target_errno);
  829. /* Get information about the file opened as FD and put it in
  830. SB. Return 0 on success, or -1 if an error occurs (and set
  831. *TARGET_ERRNO). */
  832. virtual int fileio_fstat (int fd, struct stat *sb, int *target_errno);
  833. /* Close FD on the target. Return 0, or -1 if an error occurs
  834. (and set *TARGET_ERRNO). */
  835. virtual int fileio_close (int fd, int *target_errno);
  836. /* Unlink FILENAME on the target, in the filesystem as seen by
  837. INF. If INF is NULL, use the filesystem seen by the debugger
  838. (GDB or, for remote targets, the remote stub). Return 0, or
  839. -1 if an error occurs (and set *TARGET_ERRNO). */
  840. virtual int fileio_unlink (struct inferior *inf,
  841. const char *filename,
  842. int *target_errno);
  843. /* Read value of symbolic link FILENAME on the target, in the
  844. filesystem as seen by INF. If INF is NULL, use the filesystem
  845. seen by the debugger (GDB or, for remote targets, the remote
  846. stub). Return a string, or an empty optional if an error
  847. occurs (and set *TARGET_ERRNO). */
  848. virtual gdb::optional<std::string> fileio_readlink (struct inferior *inf,
  849. const char *filename,
  850. int *target_errno);
  851. /* Implement the "info proc" command. Returns true if the target
  852. actually implemented the command, false otherwise. */
  853. virtual bool info_proc (const char *, enum info_proc_what);
  854. /* Tracepoint-related operations. */
  855. /* Prepare the target for a tracing run. */
  856. virtual void trace_init ()
  857. TARGET_DEFAULT_NORETURN (tcomplain ());
  858. /* Send full details of a tracepoint location to the target. */
  859. virtual void download_tracepoint (struct bp_location *location)
  860. TARGET_DEFAULT_NORETURN (tcomplain ());
  861. /* Is the target able to download tracepoint locations in current
  862. state? */
  863. virtual bool can_download_tracepoint ()
  864. TARGET_DEFAULT_RETURN (false);
  865. /* Send full details of a trace state variable to the target. */
  866. virtual void download_trace_state_variable (const trace_state_variable &tsv)
  867. TARGET_DEFAULT_NORETURN (tcomplain ());
  868. /* Enable a tracepoint on the target. */
  869. virtual void enable_tracepoint (struct bp_location *location)
  870. TARGET_DEFAULT_NORETURN (tcomplain ());
  871. /* Disable a tracepoint on the target. */
  872. virtual void disable_tracepoint (struct bp_location *location)
  873. TARGET_DEFAULT_NORETURN (tcomplain ());
  874. /* Inform the target info of memory regions that are readonly
  875. (such as text sections), and so it should return data from
  876. those rather than look in the trace buffer. */
  877. virtual void trace_set_readonly_regions ()
  878. TARGET_DEFAULT_NORETURN (tcomplain ());
  879. /* Start a trace run. */
  880. virtual void trace_start ()
  881. TARGET_DEFAULT_NORETURN (tcomplain ());
  882. /* Get the current status of a tracing run. */
  883. virtual int get_trace_status (struct trace_status *ts)
  884. TARGET_DEFAULT_RETURN (-1);
  885. virtual void get_tracepoint_status (struct breakpoint *tp,
  886. struct uploaded_tp *utp)
  887. TARGET_DEFAULT_NORETURN (tcomplain ());
  888. /* Stop a trace run. */
  889. virtual void trace_stop ()
  890. TARGET_DEFAULT_NORETURN (tcomplain ());
  891. /* Ask the target to find a trace frame of the given type TYPE,
  892. using NUM, ADDR1, and ADDR2 as search parameters. Returns the
  893. number of the trace frame, and also the tracepoint number at
  894. TPP. If no trace frame matches, return -1. May throw if the
  895. operation fails. */
  896. virtual int trace_find (enum trace_find_type type, int num,
  897. CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
  898. TARGET_DEFAULT_RETURN (-1);
  899. /* Get the value of the trace state variable number TSV, returning
  900. 1 if the value is known and writing the value itself into the
  901. location pointed to by VAL, else returning 0. */
  902. virtual bool get_trace_state_variable_value (int tsv, LONGEST *val)
  903. TARGET_DEFAULT_RETURN (false);
  904. virtual int save_trace_data (const char *filename)
  905. TARGET_DEFAULT_NORETURN (tcomplain ());
  906. virtual int upload_tracepoints (struct uploaded_tp **utpp)
  907. TARGET_DEFAULT_RETURN (0);
  908. virtual int upload_trace_state_variables (struct uploaded_tsv **utsvp)
  909. TARGET_DEFAULT_RETURN (0);
  910. virtual LONGEST get_raw_trace_data (gdb_byte *buf,
  911. ULONGEST offset, LONGEST len)
  912. TARGET_DEFAULT_NORETURN (tcomplain ());
  913. /* Get the minimum length of instruction on which a fast tracepoint
  914. may be set on the target. If this operation is unsupported,
  915. return -1. If for some reason the minimum length cannot be
  916. determined, return 0. */
  917. virtual int get_min_fast_tracepoint_insn_len ()
  918. TARGET_DEFAULT_RETURN (-1);
  919. /* Set the target's tracing behavior in response to unexpected
  920. disconnection - set VAL to 1 to keep tracing, 0 to stop. */
  921. virtual void set_disconnected_tracing (int val)
  922. TARGET_DEFAULT_IGNORE ();
  923. virtual void set_circular_trace_buffer (int val)
  924. TARGET_DEFAULT_IGNORE ();
  925. /* Set the size of trace buffer in the target. */
  926. virtual void set_trace_buffer_size (LONGEST val)
  927. TARGET_DEFAULT_IGNORE ();
  928. /* Add/change textual notes about the trace run, returning true if
  929. successful, false otherwise. */
  930. virtual bool set_trace_notes (const char *user, const char *notes,
  931. const char *stopnotes)
  932. TARGET_DEFAULT_RETURN (false);
  933. /* Return the processor core that thread PTID was last seen on.
  934. This information is updated only when:
  935. - update_thread_list is called
  936. - thread stops
  937. If the core cannot be determined -- either for the specified
  938. thread, or right now, or in this debug session, or for this
  939. target -- return -1. */
  940. virtual int core_of_thread (ptid_t ptid)
  941. TARGET_DEFAULT_RETURN (-1);
  942. /* Verify that the memory in the [MEMADDR, MEMADDR+SIZE) range
  943. matches the contents of [DATA,DATA+SIZE). Returns 1 if there's
  944. a match, 0 if there's a mismatch, and -1 if an error is
  945. encountered while reading memory. */
  946. virtual int verify_memory (const gdb_byte *data,
  947. CORE_ADDR memaddr, ULONGEST size)
  948. TARGET_DEFAULT_FUNC (default_verify_memory);
  949. /* Return the address of the start of the Thread Information Block
  950. a Windows OS specific feature. */
  951. virtual bool get_tib_address (ptid_t ptid, CORE_ADDR *addr)
  952. TARGET_DEFAULT_NORETURN (tcomplain ());
  953. /* Send the new settings of write permission variables. */
  954. virtual void set_permissions ()
  955. TARGET_DEFAULT_IGNORE ();
  956. /* Look for a static tracepoint marker at ADDR, and fill in MARKER
  957. with its details. Return true on success, false on failure. */
  958. virtual bool static_tracepoint_marker_at (CORE_ADDR,
  959. static_tracepoint_marker *marker)
  960. TARGET_DEFAULT_RETURN (false);
  961. /* Return a vector of all tracepoints markers string id ID, or all
  962. markers if ID is NULL. */
  963. virtual std::vector<static_tracepoint_marker>
  964. static_tracepoint_markers_by_strid (const char *id)
  965. TARGET_DEFAULT_NORETURN (tcomplain ());
  966. /* Return a traceframe info object describing the current
  967. traceframe's contents. This method should not cache data;
  968. higher layers take care of caching, invalidating, and
  969. re-fetching when necessary. */
  970. virtual traceframe_info_up traceframe_info ()
  971. TARGET_DEFAULT_NORETURN (tcomplain ());
  972. /* Ask the target to use or not to use agent according to USE.
  973. Return true if successful, false otherwise. */
  974. virtual bool use_agent (bool use)
  975. TARGET_DEFAULT_NORETURN (tcomplain ());
  976. /* Is the target able to use agent in current state? */
  977. virtual bool can_use_agent ()
  978. TARGET_DEFAULT_RETURN (false);
  979. /* Enable branch tracing for TP using CONF configuration.
  980. Return a branch trace target information struct for reading and for
  981. disabling branch trace. */
  982. virtual struct btrace_target_info *enable_btrace (thread_info *tp,
  983. const struct btrace_config *conf)
  984. TARGET_DEFAULT_NORETURN (tcomplain ());
  985. /* Disable branch tracing and deallocate TINFO. */
  986. virtual void disable_btrace (struct btrace_target_info *tinfo)
  987. TARGET_DEFAULT_NORETURN (tcomplain ());
  988. /* Disable branch tracing and deallocate TINFO. This function is similar
  989. to to_disable_btrace, except that it is called during teardown and is
  990. only allowed to perform actions that are safe. A counter-example would
  991. be attempting to talk to a remote target. */
  992. virtual void teardown_btrace (struct btrace_target_info *tinfo)
  993. TARGET_DEFAULT_NORETURN (tcomplain ());
  994. /* Read branch trace data for the thread indicated by BTINFO into DATA.
  995. DATA is cleared before new trace is added. */
  996. virtual enum btrace_error read_btrace (struct btrace_data *data,
  997. struct btrace_target_info *btinfo,
  998. enum btrace_read_type type)
  999. TARGET_DEFAULT_NORETURN (tcomplain ());
  1000. /* Get the branch trace configuration. */
  1001. virtual const struct btrace_config *btrace_conf (const struct btrace_target_info *)
  1002. TARGET_DEFAULT_RETURN (NULL);
  1003. /* Current recording method. */
  1004. virtual enum record_method record_method (ptid_t ptid)
  1005. TARGET_DEFAULT_RETURN (RECORD_METHOD_NONE);
  1006. /* Stop trace recording. */
  1007. virtual void stop_recording ()
  1008. TARGET_DEFAULT_IGNORE ();
  1009. /* Print information about the recording. */
  1010. virtual void info_record ()
  1011. TARGET_DEFAULT_IGNORE ();
  1012. /* Save the recorded execution trace into a file. */
  1013. virtual void save_record (const char *filename)
  1014. TARGET_DEFAULT_NORETURN (tcomplain ());
  1015. /* Delete the recorded execution trace from the current position
  1016. onwards. */
  1017. virtual bool supports_delete_record ()
  1018. TARGET_DEFAULT_RETURN (false);
  1019. virtual void delete_record ()
  1020. TARGET_DEFAULT_NORETURN (tcomplain ());
  1021. /* Query if the record target is currently replaying PTID. */
  1022. virtual bool record_is_replaying (ptid_t ptid)
  1023. TARGET_DEFAULT_RETURN (false);
  1024. /* Query if the record target will replay PTID if it were resumed in
  1025. execution direction DIR. */
  1026. virtual bool record_will_replay (ptid_t ptid, int dir)
  1027. TARGET_DEFAULT_RETURN (false);
  1028. /* Stop replaying. */
  1029. virtual void record_stop_replaying ()
  1030. TARGET_DEFAULT_IGNORE ();
  1031. /* Go to the begin of the execution trace. */
  1032. virtual void goto_record_begin ()
  1033. TARGET_DEFAULT_NORETURN (tcomplain ());
  1034. /* Go to the end of the execution trace. */
  1035. virtual void goto_record_end ()
  1036. TARGET_DEFAULT_NORETURN (tcomplain ());
  1037. /* Go to a specific location in the recorded execution trace. */
  1038. virtual void goto_record (ULONGEST insn)
  1039. TARGET_DEFAULT_NORETURN (tcomplain ());
  1040. /* Disassemble SIZE instructions in the recorded execution trace from
  1041. the current position.
  1042. If SIZE < 0, disassemble abs (SIZE) preceding instructions; otherwise,
  1043. disassemble SIZE succeeding instructions. */
  1044. virtual void insn_history (int size, gdb_disassembly_flags flags)
  1045. TARGET_DEFAULT_NORETURN (tcomplain ());
  1046. /* Disassemble SIZE instructions in the recorded execution trace around
  1047. FROM.
  1048. If SIZE < 0, disassemble abs (SIZE) instructions before FROM; otherwise,
  1049. disassemble SIZE instructions after FROM. */
  1050. virtual void insn_history_from (ULONGEST from, int size,
  1051. gdb_disassembly_flags flags)
  1052. TARGET_DEFAULT_NORETURN (tcomplain ());
  1053. /* Disassemble a section of the recorded execution trace from instruction
  1054. BEGIN (inclusive) to instruction END (inclusive). */
  1055. virtual void insn_history_range (ULONGEST begin, ULONGEST end,
  1056. gdb_disassembly_flags flags)
  1057. TARGET_DEFAULT_NORETURN (tcomplain ());
  1058. /* Print a function trace of the recorded execution trace.
  1059. If SIZE < 0, print abs (SIZE) preceding functions; otherwise, print SIZE
  1060. succeeding functions. */
  1061. virtual void call_history (int size, record_print_flags flags)
  1062. TARGET_DEFAULT_NORETURN (tcomplain ());
  1063. /* Print a function trace of the recorded execution trace starting
  1064. at function FROM.
  1065. If SIZE < 0, print abs (SIZE) functions before FROM; otherwise, print
  1066. SIZE functions after FROM. */
  1067. virtual void call_history_from (ULONGEST begin, int size, record_print_flags flags)
  1068. TARGET_DEFAULT_NORETURN (tcomplain ());
  1069. /* Print a function trace of an execution trace section from function BEGIN
  1070. (inclusive) to function END (inclusive). */
  1071. virtual void call_history_range (ULONGEST begin, ULONGEST end, record_print_flags flags)
  1072. TARGET_DEFAULT_NORETURN (tcomplain ());
  1073. /* True if TARGET_OBJECT_LIBRARIES_SVR4 may be read with a
  1074. non-empty annex. */
  1075. virtual bool augmented_libraries_svr4_read ()
  1076. TARGET_DEFAULT_RETURN (false);
  1077. /* Those unwinders are tried before any other arch unwinders. If
  1078. SELF doesn't have unwinders, it should delegate to the
  1079. "beneath" target. */
  1080. virtual const struct frame_unwind *get_unwinder ()
  1081. TARGET_DEFAULT_RETURN (NULL);
  1082. virtual const struct frame_unwind *get_tailcall_unwinder ()
  1083. TARGET_DEFAULT_RETURN (NULL);
  1084. /* Prepare to generate a core file. */
  1085. virtual void prepare_to_generate_core ()
  1086. TARGET_DEFAULT_IGNORE ();
  1087. /* Cleanup after generating a core file. */
  1088. virtual void done_generating_core ()
  1089. TARGET_DEFAULT_IGNORE ();
  1090. /* Returns true if the target supports memory tagging, false otherwise. */
  1091. virtual bool supports_memory_tagging ()
  1092. TARGET_DEFAULT_RETURN (false);
  1093. /* Return the allocated memory tags of type TYPE associated with
  1094. [ADDRESS, ADDRESS + LEN) in TAGS.
  1095. LEN is the number of bytes in the memory range. TAGS is a vector of
  1096. bytes containing the tags found in the above memory range.
  1097. It is up to the architecture/target to interpret the bytes in the TAGS
  1098. vector and read the tags appropriately.
  1099. Returns true if fetching the tags succeeded and false otherwise. */
  1100. virtual bool fetch_memtags (CORE_ADDR address, size_t len,
  1101. gdb::byte_vector &tags, int type)
  1102. TARGET_DEFAULT_NORETURN (tcomplain ());
  1103. /* Write the allocation tags of type TYPE contained in TAGS to the memory
  1104. range [ADDRESS, ADDRESS + LEN).
  1105. LEN is the number of bytes in the memory range. TAGS is a vector of
  1106. bytes containing the tags to be stored to the memory range.
  1107. It is up to the architecture/target to interpret the bytes in the TAGS
  1108. vector and store them appropriately.
  1109. Returns true if storing the tags succeeded and false otherwise. */
  1110. virtual bool store_memtags (CORE_ADDR address, size_t len,
  1111. const gdb::byte_vector &tags, int type)
  1112. TARGET_DEFAULT_NORETURN (tcomplain ());
  1113. };
  1114. /* Deleter for std::unique_ptr. See comments in
  1115. target_ops::~target_ops and target_ops::close about heap-allocated
  1116. targets. */
  1117. struct target_ops_deleter
  1118. {
  1119. void operator() (target_ops *target)
  1120. {
  1121. target->close ();
  1122. }
  1123. };
  1124. /* A unique pointer for target_ops. */
  1125. typedef std::unique_ptr<target_ops, target_ops_deleter> target_ops_up;
  1126. /* Decref a target and close if, if there are no references left. */
  1127. extern void decref_target (target_ops *t);
  1128. /* A policy class to interface gdb::ref_ptr with target_ops. */
  1129. struct target_ops_ref_policy
  1130. {
  1131. static void incref (target_ops *t)
  1132. {
  1133. t->incref ();
  1134. }
  1135. static void decref (target_ops *t)
  1136. {
  1137. decref_target (t);
  1138. }
  1139. };
  1140. /* A gdb::ref_ptr pointer to a target_ops. */
  1141. typedef gdb::ref_ptr<target_ops, target_ops_ref_policy> target_ops_ref;
  1142. /* Native target backends call this once at initialization time to
  1143. inform the core about which is the target that can respond to "run"
  1144. or "attach". Note: native targets are always singletons. */
  1145. extern void set_native_target (target_ops *target);
  1146. /* Get the registered native target, if there's one. Otherwise return
  1147. NULL. */
  1148. extern target_ops *get_native_target ();
  1149. /* Type that manages a target stack. See description of target stacks
  1150. and strata at the top of the file. */
  1151. class target_stack
  1152. {
  1153. public:
  1154. target_stack () = default;
  1155. DISABLE_COPY_AND_ASSIGN (target_stack);
  1156. /* Push a new target into the stack of the existing target
  1157. accessors, possibly superseding some existing accessor. */
  1158. void push (target_ops *t);
  1159. /* Remove a target from the stack, wherever it may be. Return true
  1160. if it was removed, false otherwise. */
  1161. bool unpush (target_ops *t);
  1162. /* Returns true if T is pushed on the target stack. */
  1163. bool is_pushed (target_ops *t) const
  1164. { return at (t->stratum ()) == t; }
  1165. /* Return the target at STRATUM. */
  1166. target_ops *at (strata stratum) const { return m_stack[stratum]; }
  1167. /* Return the target at the top of the stack. */
  1168. target_ops *top () const { return at (m_top); }
  1169. /* Find the next target down the stack from the specified target. */
  1170. target_ops *find_beneath (const target_ops *t) const;
  1171. private:
  1172. /* The stratum of the top target. */
  1173. enum strata m_top {};
  1174. /* The stack, represented as an array, with one slot per stratum.
  1175. If no target is pushed at some stratum, the corresponding slot is
  1176. null. */
  1177. target_ops *m_stack[(int) debug_stratum + 1] {};
  1178. };
  1179. /* Return the dummy target. */
  1180. extern target_ops *get_dummy_target ();
  1181. /* Define easy words for doing these operations on our current target. */
  1182. extern const char *target_shortname ();
  1183. /* Does whatever cleanup is required for a target that we are no
  1184. longer going to be calling. This routine is automatically always
  1185. called after popping the target off the target stack - the target's
  1186. own methods are no longer available through the target vector.
  1187. Closing file descriptors and freeing all memory allocated memory are
  1188. typical things it should do. */
  1189. void target_close (struct target_ops *targ);
  1190. /* Find the correct target to use for "attach". If a target on the
  1191. current stack supports attaching, then it is returned. Otherwise,
  1192. the default run target is returned. */
  1193. extern struct target_ops *find_attach_target (void);
  1194. /* Find the correct target to use for "run". If a target on the
  1195. current stack supports creating a new inferior, then it is
  1196. returned. Otherwise, the default run target is returned. */
  1197. extern struct target_ops *find_run_target (void);
  1198. /* Some targets don't generate traps when attaching to the inferior,
  1199. or their target_attach implementation takes care of the waiting.
  1200. These targets must set to_attach_no_wait. */
  1201. extern bool target_attach_no_wait ();
  1202. /* The target_attach operation places a process under debugger control,
  1203. and stops the process.
  1204. This operation provides a target-specific hook that allows the
  1205. necessary bookkeeping to be performed after an attach completes. */
  1206. extern void target_post_attach (int pid);
  1207. /* Display a message indicating we're about to attach to a given
  1208. process. */
  1209. extern void target_announce_attach (int from_tty, int pid);
  1210. /* Display a message indicating we're about to detach from the current
  1211. inferior process. */
  1212. extern void target_announce_detach (int from_tty);
  1213. /* Takes a program previously attached to and detaches it.
  1214. The program may resume execution (some targets do, some don't) and will
  1215. no longer stop on signals, etc. We better not have left any breakpoints
  1216. in the program or it'll die when it hits one. FROM_TTY says whether to be
  1217. verbose or not. */
  1218. extern void target_detach (inferior *inf, int from_tty);
  1219. /* Disconnect from the current target without resuming it (leaving it
  1220. waiting for a debugger). */
  1221. extern void target_disconnect (const char *, int);
  1222. /* Resume execution (or prepare for execution) of a target thread,
  1223. process or all processes. STEP says whether to hardware
  1224. single-step or to run free; SIGGNAL is the signal to be given to
  1225. the target, or GDB_SIGNAL_0 for no signal. The caller may not pass
  1226. GDB_SIGNAL_DEFAULT. A specific PTID means `step/resume only this
  1227. process id'. A wildcard PTID (all threads, or all threads of
  1228. process) means `step/resume INFERIOR_PTID, and let other threads
  1229. (for which the wildcard PTID matches) resume with their
  1230. 'thread->suspend.stop_signal' signal (usually GDB_SIGNAL_0) if it
  1231. is in "pass" state, or with no signal if in "no pass" state.
  1232. In order to efficiently handle batches of resumption requests,
  1233. targets may implement this method such that it records the
  1234. resumption request, but defers the actual resumption to the
  1235. target_commit_resume method implementation. See
  1236. target_commit_resume below. */
  1237. extern void target_resume (ptid_t ptid, int step, enum gdb_signal signal);
  1238. /* Ensure that all resumed threads are committed to the target.
  1239. See the description of process_stratum_target::commit_resumed_state
  1240. for more details. */
  1241. extern void target_commit_resumed ();
  1242. /* For target_read_memory see target/target.h. */
  1243. /* The default target_ops::to_wait implementation. */
  1244. extern ptid_t default_target_wait (struct target_ops *ops,
  1245. ptid_t ptid,
  1246. struct target_waitstatus *status,
  1247. target_wait_flags options);
  1248. /* Return true if the target has pending events to report to the core.
  1249. See target_ops::has_pending_events(). */
  1250. extern bool target_has_pending_events ();
  1251. /* Fetch at least register REGNO, or all regs if regno == -1. No result. */
  1252. extern void target_fetch_registers (struct regcache *regcache, int regno);
  1253. /* Store at least register REGNO, or all regs if REGNO == -1.
  1254. It can store as many registers as it wants to, so target_prepare_to_store
  1255. must have been previously called. Calls error() if there are problems. */
  1256. extern void target_store_registers (struct regcache *regcache, int regs);
  1257. /* Get ready to modify the registers array. On machines which store
  1258. individual registers, this doesn't need to do anything. On machines
  1259. which store all the registers in one fell swoop, this makes sure
  1260. that REGISTERS contains all the registers from the program being
  1261. debugged. */
  1262. extern void target_prepare_to_store (regcache *regcache);
  1263. /* Determine current address space of thread PTID. */
  1264. struct address_space *target_thread_address_space (ptid_t);
  1265. /* Implement the "info proc" command. This returns one if the request
  1266. was handled, and zero otherwise. It can also throw an exception if
  1267. an error was encountered while attempting to handle the
  1268. request. */
  1269. int target_info_proc (const char *, enum info_proc_what);
  1270. /* Returns true if this target can disable address space randomization. */
  1271. int target_supports_disable_randomization (void);
  1272. /* Returns true if this target can enable and disable tracepoints
  1273. while a trace experiment is running. */
  1274. extern bool target_supports_enable_disable_tracepoint ();
  1275. extern bool target_supports_string_tracing ();
  1276. /* Returns true if this target can handle breakpoint conditions
  1277. on its end. */
  1278. extern bool target_supports_evaluation_of_breakpoint_conditions ();
  1279. /* Does this target support dumpcore API? */
  1280. extern bool target_supports_dumpcore ();
  1281. /* Generate the core file with target API. */
  1282. extern void target_dumpcore (const char *filename);
  1283. /* Returns true if this target can handle breakpoint commands
  1284. on its end. */
  1285. extern bool target_can_run_breakpoint_commands ();
  1286. /* Read a string from target memory at address MEMADDR. The string
  1287. will be at most LEN bytes long (note that excess bytes may be read
  1288. in some cases -- but these will not be returned). Returns nullptr
  1289. on error. */
  1290. extern gdb::unique_xmalloc_ptr<char> target_read_string
  1291. (CORE_ADDR memaddr, int len, int *bytes_read = nullptr);
  1292. /* For target_read_memory see target/target.h. */
  1293. extern int target_read_raw_memory (CORE_ADDR memaddr, gdb_byte *myaddr,
  1294. ssize_t len);
  1295. extern int target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len);
  1296. extern int target_read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len);
  1297. /* For target_write_memory see target/target.h. */
  1298. extern int target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr,
  1299. ssize_t len);
  1300. /* Fetches the target's memory map. If one is found it is sorted
  1301. and returned, after some consistency checking. Otherwise, NULL
  1302. is returned. */
  1303. std::vector<mem_region> target_memory_map (void);
  1304. /* Erases all flash memory regions on the target. */
  1305. void flash_erase_command (const char *cmd, int from_tty);
  1306. /* Erase the specified flash region. */
  1307. void target_flash_erase (ULONGEST address, LONGEST length);
  1308. /* Finish a sequence of flash operations. */
  1309. void target_flash_done (void);
  1310. /* Describes a request for a memory write operation. */
  1311. struct memory_write_request
  1312. {
  1313. memory_write_request (ULONGEST begin_, ULONGEST end_,
  1314. gdb_byte *data_ = nullptr, void *baton_ = nullptr)
  1315. : begin (begin_), end (end_), data (data_), baton (baton_)
  1316. {}
  1317. /* Begining address that must be written. */
  1318. ULONGEST begin;
  1319. /* Past-the-end address. */
  1320. ULONGEST end;
  1321. /* The data to write. */
  1322. gdb_byte *data;
  1323. /* A callback baton for progress reporting for this request. */
  1324. void *baton;
  1325. };
  1326. /* Enumeration specifying different flash preservation behaviour. */
  1327. enum flash_preserve_mode
  1328. {
  1329. flash_preserve,
  1330. flash_discard
  1331. };
  1332. /* Write several memory blocks at once. This version can be more
  1333. efficient than making several calls to target_write_memory, in
  1334. particular because it can optimize accesses to flash memory.
  1335. Moreover, this is currently the only memory access function in gdb
  1336. that supports writing to flash memory, and it should be used for
  1337. all cases where access to flash memory is desirable.
  1338. REQUESTS is the vector of memory_write_request.
  1339. PRESERVE_FLASH_P indicates what to do with blocks which must be
  1340. erased, but not completely rewritten.
  1341. PROGRESS_CB is a function that will be periodically called to provide
  1342. feedback to user. It will be called with the baton corresponding
  1343. to the request currently being written. It may also be called
  1344. with a NULL baton, when preserved flash sectors are being rewritten.
  1345. The function returns 0 on success, and error otherwise. */
  1346. int target_write_memory_blocks
  1347. (const std::vector<memory_write_request> &requests,
  1348. enum flash_preserve_mode preserve_flash_p,
  1349. void (*progress_cb) (ULONGEST, void *));
  1350. /* Print a line about the current target. */
  1351. extern void target_files_info ();
  1352. /* Insert a breakpoint at address BP_TGT->placed_address in
  1353. the target machine. Returns 0 for success, and returns non-zero or
  1354. throws an error (with a detailed failure reason error code and
  1355. message) otherwise. */
  1356. extern int target_insert_breakpoint (struct gdbarch *gdbarch,
  1357. struct bp_target_info *bp_tgt);
  1358. /* Remove a breakpoint at address BP_TGT->placed_address in the target
  1359. machine. Result is 0 for success, non-zero for error. */
  1360. extern int target_remove_breakpoint (struct gdbarch *gdbarch,
  1361. struct bp_target_info *bp_tgt,
  1362. enum remove_bp_reason reason);
  1363. /* Return true if the target stack has a non-default
  1364. "terminal_ours" method. */
  1365. extern bool target_supports_terminal_ours (void);
  1366. /* Kill the inferior process. Make it go away. */
  1367. extern void target_kill (void);
  1368. /* Load an executable file into the target process. This is expected
  1369. to not only bring new code into the target process, but also to
  1370. update GDB's symbol tables to match.
  1371. ARG contains command-line arguments, to be broken down with
  1372. buildargv (). The first non-switch argument is the filename to
  1373. load, FILE; the second is a number (as parsed by strtoul (..., ...,
  1374. 0)), which is an offset to apply to the load addresses of FILE's
  1375. sections. The target may define switches, or other non-switch
  1376. arguments, as it pleases. */
  1377. extern void target_load (const char *arg, int from_tty);
  1378. /* On some targets, we can catch an inferior fork or vfork event when
  1379. it occurs. These functions insert/remove an already-created
  1380. catchpoint for such events. They return 0 for success, 1 if the
  1381. catchpoint type is not supported and -1 for failure. */
  1382. extern int target_insert_fork_catchpoint (int pid);
  1383. extern int target_remove_fork_catchpoint (int pid);
  1384. extern int target_insert_vfork_catchpoint (int pid);
  1385. extern int target_remove_vfork_catchpoint (int pid);
  1386. /* Call the follow_fork method on the current target stack.
  1387. This function is called when the inferior forks or vforks, to perform any
  1388. bookkeeping and fiddling necessary to continue debugging either the parent,
  1389. the child or both. */
  1390. void target_follow_fork (inferior *inf, ptid_t child_ptid,
  1391. target_waitkind fork_kind, bool follow_child,
  1392. bool detach_fork);
  1393. /* Handle the target-specific bookkeeping required when the inferior makes an
  1394. exec call.
  1395. The current inferior at the time of the call is the inferior that did the
  1396. exec. FOLLOW_INF is the inferior in which execution continues post-exec.
  1397. If "follow-exec-mode" is "same", FOLLOW_INF is the same as the current
  1398. inferior, meaning that execution continues with the same inferior. If
  1399. "follow-exec-mode" is "new", FOLLOW_INF is a different inferior, meaning
  1400. that execution continues in a new inferior.
  1401. On exit, the target must leave FOLLOW_INF as the current inferior. */
  1402. void target_follow_exec (inferior *follow_inf, ptid_t ptid,
  1403. const char *execd_pathname);
  1404. /* On some targets, we can catch an inferior exec event when it
  1405. occurs. These functions insert/remove an already-created
  1406. catchpoint for such events. They return 0 for success, 1 if the
  1407. catchpoint type is not supported and -1 for failure. */
  1408. extern int target_insert_exec_catchpoint (int pid);
  1409. extern int target_remove_exec_catchpoint (int pid);
  1410. /* Syscall catch.
  1411. NEEDED is true if any syscall catch (of any kind) is requested.
  1412. If NEEDED is false, it means the target can disable the mechanism to
  1413. catch system calls because there are no more catchpoints of this type.
  1414. ANY_COUNT is nonzero if a generic (filter-less) syscall catch is
  1415. being requested. In this case, SYSCALL_COUNTS should be ignored.
  1416. SYSCALL_COUNTS is an array of ints, indexed by syscall number. An
  1417. element in this array is nonzero if that syscall should be caught.
  1418. This argument only matters if ANY_COUNT is zero.
  1419. Return 0 for success, 1 if syscall catchpoints are not supported or -1
  1420. for failure. */
  1421. extern int target_set_syscall_catchpoint
  1422. (int pid, bool needed, int any_count,
  1423. gdb::array_view<const int> syscall_counts);
  1424. /* The debugger has completed a blocking wait() call. There is now
  1425. some process event that must be processed. This function should
  1426. be defined by those targets that require the debugger to perform
  1427. cleanup or internal state changes in response to the process event. */
  1428. /* For target_mourn_inferior see target/target.h. */
  1429. /* Does target have enough data to do a run or attach command? */
  1430. extern int target_can_run ();
  1431. /* Set list of signals to be handled in the target.
  1432. PASS_SIGNALS is an array indexed by target signal number
  1433. (enum gdb_signal). For every signal whose entry in this array is
  1434. non-zero, the target is allowed -but not required- to skip reporting
  1435. arrival of the signal to the GDB core by returning from target_wait,
  1436. and to pass the signal directly to the inferior instead.
  1437. However, if the target is hardware single-stepping a thread that is
  1438. about to receive a signal, it needs to be reported in any case, even
  1439. if mentioned in a previous target_pass_signals call. */
  1440. extern void target_pass_signals
  1441. (gdb::array_view<const unsigned char> pass_signals);
  1442. /* Set list of signals the target may pass to the inferior. This
  1443. directly maps to the "handle SIGNAL pass/nopass" setting.
  1444. PROGRAM_SIGNALS is an array indexed by target signal
  1445. number (enum gdb_signal). For every signal whose entry in this
  1446. array is non-zero, the target is allowed to pass the signal to the
  1447. inferior. Signals not present in the array shall be silently
  1448. discarded. This does not influence whether to pass signals to the
  1449. inferior as a result of a target_resume call. This is useful in
  1450. scenarios where the target needs to decide whether to pass or not a
  1451. signal to the inferior without GDB core involvement, such as for
  1452. example, when detaching (as threads may have been suspended with
  1453. pending signals not reported to GDB). */
  1454. extern void target_program_signals
  1455. (gdb::array_view<const unsigned char> program_signals);
  1456. /* Check to see if a thread is still alive. */
  1457. extern int target_thread_alive (ptid_t ptid);
  1458. /* Sync the target's threads with GDB's thread list. */
  1459. extern void target_update_thread_list (void);
  1460. /* Make target stop in a continuable fashion. (For instance, under
  1461. Unix, this should act like SIGSTOP). Note that this function is
  1462. asynchronous: it does not wait for the target to become stopped
  1463. before returning. If this is the behavior you want please use
  1464. target_stop_and_wait. */
  1465. extern void target_stop (ptid_t ptid);
  1466. /* Interrupt the target. Unlike target_stop, this does not specify
  1467. which thread/process reports the stop. For most target this acts
  1468. like raising a SIGINT, though that's not absolutely required. This
  1469. function is asynchronous. */
  1470. extern void target_interrupt ();
  1471. /* Pass a ^C, as determined to have been pressed by checking the quit
  1472. flag, to the target, as if the user had typed the ^C on the
  1473. inferior's controlling terminal while the inferior was in the
  1474. foreground. Remote targets may take the opportunity to detect the
  1475. remote side is not responding and offer to disconnect. */
  1476. extern void target_pass_ctrlc (void);
  1477. /* The default target_ops::to_pass_ctrlc implementation. Simply calls
  1478. target_interrupt. */
  1479. extern void default_target_pass_ctrlc (struct target_ops *ops);
  1480. /* Send the specified COMMAND to the target's monitor
  1481. (shell,interpreter) for execution. The result of the query is
  1482. placed in OUTBUF. */
  1483. extern void target_rcmd (const char *command, struct ui_file *outbuf);
  1484. /* Does the target include memory? (Dummy targets don't.) */
  1485. extern int target_has_memory ();
  1486. /* Does the target have a stack? (Exec files don't, VxWorks doesn't, until
  1487. we start a process.) */
  1488. extern int target_has_stack ();
  1489. /* Does the target have registers? (Exec files don't.) */
  1490. extern int target_has_registers ();
  1491. /* Does the target have execution? Can we make it jump (through
  1492. hoops), or pop its stack a few times? This means that the current
  1493. target is currently executing; for some targets, that's the same as
  1494. whether or not the target is capable of execution, but there are
  1495. also targets which can be current while not executing. In that
  1496. case this will become true after to_create_inferior or
  1497. to_attach. INF is the inferior to use; nullptr means to use the
  1498. current inferior. */
  1499. extern bool target_has_execution (inferior *inf = nullptr);
  1500. /* Can the target support the debugger control of thread execution?
  1501. Can it lock the thread scheduler? */
  1502. extern bool target_can_lock_scheduler ();
  1503. /* Controls whether async mode is permitted. */
  1504. extern bool target_async_permitted;
  1505. /* Can the target support asynchronous execution? */
  1506. extern bool target_can_async_p ();
  1507. /* An overload of the above that can be called when the target is not yet
  1508. pushed, this calls TARGET::can_async_p directly. */
  1509. extern bool target_can_async_p (struct target_ops *target);
  1510. /* Is the target in asynchronous execution mode? */
  1511. extern bool target_is_async_p ();
  1512. /* Enables/disabled async target events. */
  1513. extern void target_async (int enable);
  1514. /* Enables/disables thread create and exit events. */
  1515. extern void target_thread_events (int enable);
  1516. /* Whether support for controlling the target backends always in
  1517. non-stop mode is enabled. */
  1518. extern enum auto_boolean target_non_stop_enabled;
  1519. /* Is the target in non-stop mode? Some targets control the inferior
  1520. in non-stop mode even with "set non-stop off". Always true if "set
  1521. non-stop" is on. */
  1522. extern bool target_is_non_stop_p ();
  1523. /* Return true if at least one inferior has a non-stop target. */
  1524. extern bool exists_non_stop_target ();
  1525. extern exec_direction_kind target_execution_direction ();
  1526. /* Converts a process id to a string. Usually, the string just contains
  1527. `process xyz', but on some systems it may contain
  1528. `process xyz thread abc'. */
  1529. extern std::string target_pid_to_str (ptid_t ptid);
  1530. extern std::string normal_pid_to_str (ptid_t ptid);
  1531. /* Return a short string describing extra information about PID,
  1532. e.g. "sleeping", "runnable", "running on LWP 3". Null return value
  1533. is okay. */
  1534. extern const char *target_extra_thread_info (thread_info *tp);
  1535. /* Return the thread's name, or NULL if the target is unable to determine it.
  1536. The returned value must not be freed by the caller.
  1537. You likely don't want to call this function, but use the thread_name
  1538. function instead, which prefers the user-given thread name, if set. */
  1539. extern const char *target_thread_name (struct thread_info *);
  1540. /* Given a pointer to a thread library specific thread handle and
  1541. its length, return a pointer to the corresponding thread_info struct. */
  1542. extern struct thread_info *target_thread_handle_to_thread_info
  1543. (const gdb_byte *thread_handle, int handle_len, struct inferior *inf);
  1544. /* Given a thread, return the thread handle, a target-specific sequence of
  1545. bytes which serves as a thread identifier within the program being
  1546. debugged. */
  1547. extern gdb::byte_vector target_thread_info_to_thread_handle
  1548. (struct thread_info *);
  1549. /* Attempts to find the pathname of the executable file
  1550. that was run to create a specified process.
  1551. The process PID must be stopped when this operation is used.
  1552. If the executable file cannot be determined, NULL is returned.
  1553. Else, a pointer to a character string containing the pathname
  1554. is returned. This string should be copied into a buffer by
  1555. the client if the string will not be immediately used, or if
  1556. it must persist. */
  1557. extern char *target_pid_to_exec_file (int pid);
  1558. /* See the to_thread_architecture description in struct target_ops. */
  1559. extern gdbarch *target_thread_architecture (ptid_t ptid);
  1560. /*
  1561. * Iterator function for target memory regions.
  1562. * Calls a callback function once for each memory region 'mapped'
  1563. * in the child process. Defined as a simple macro rather than
  1564. * as a function macro so that it can be tested for nullity.
  1565. */
  1566. extern int target_find_memory_regions (find_memory_region_ftype func,
  1567. void *data);
  1568. /*
  1569. * Compose corefile .note section.
  1570. */
  1571. extern gdb::unique_xmalloc_ptr<char> target_make_corefile_notes (bfd *bfd,
  1572. int *size_p);
  1573. /* Bookmark interfaces. */
  1574. extern gdb_byte *target_get_bookmark (const char *args, int from_tty);
  1575. extern void target_goto_bookmark (const gdb_byte *arg, int from_tty);
  1576. /* Hardware watchpoint interfaces. */
  1577. /* GDB's current model is that there are three "kinds" of watchpoints,
  1578. with respect to when they trigger and how you can move past them.
  1579. Those are: continuable, steppable, and non-steppable.
  1580. Continuable watchpoints are like x86's -- those trigger after the
  1581. memory access's side effects are fully committed to memory. I.e.,
  1582. they trap with the PC pointing at the next instruction already.
  1583. Continuing past such a watchpoint is doable by just normally
  1584. continuing, hence the name.
  1585. Both steppable and non-steppable watchpoints trap before the memory
  1586. access. I.e, the PC points at the instruction that is accessing
  1587. the memory. So GDB needs to single-step once past the current
  1588. instruction in order to make the access effective and check whether
  1589. the instruction's side effects change the watched expression.
  1590. Now, in order to step past that instruction, depending on
  1591. architecture and target, you can have two situations:
  1592. - steppable watchpoints: you can single-step with the watchpoint
  1593. still armed, and the watchpoint won't trigger again.
  1594. - non-steppable watchpoints: if you try to single-step with the
  1595. watchpoint still armed, you'd trap the watchpoint again and the
  1596. thread wouldn't make any progress. So GDB needs to temporarily
  1597. remove the watchpoint in order to step past it.
  1598. If your target/architecture does not signal that it has either
  1599. steppable or non-steppable watchpoints via either
  1600. target_have_steppable_watchpoint or
  1601. gdbarch_have_nonsteppable_watchpoint, GDB assumes continuable
  1602. watchpoints. */
  1603. /* Returns true if we were stopped by a hardware watchpoint (memory read or
  1604. write). Only the INFERIOR_PTID task is being queried. */
  1605. extern bool target_stopped_by_watchpoint ();
  1606. /* Returns true if the target stopped because it executed a
  1607. software breakpoint instruction. */
  1608. extern bool target_stopped_by_sw_breakpoint ();
  1609. extern bool target_supports_stopped_by_sw_breakpoint ();
  1610. extern bool target_stopped_by_hw_breakpoint ();
  1611. extern bool target_supports_stopped_by_hw_breakpoint ();
  1612. /* True if we have steppable watchpoints */
  1613. extern bool target_have_steppable_watchpoint ();
  1614. /* Provide defaults for hardware watchpoint functions. */
  1615. /* If the *_hw_beakpoint functions have not been defined
  1616. elsewhere use the definitions in the target vector. */
  1617. /* Returns positive if we can set a hardware watchpoint of type TYPE.
  1618. Returns negative if the target doesn't have enough hardware debug
  1619. registers available. Return zero if hardware watchpoint of type
  1620. TYPE isn't supported. TYPE is one of bp_hardware_watchpoint,
  1621. bp_read_watchpoint, bp_write_watchpoint, or bp_hardware_breakpoint.
  1622. CNT is the number of such watchpoints used so far, including this
  1623. one. OTHERTYPE is the number of watchpoints of other types than
  1624. this one used so far. */
  1625. extern int target_can_use_hardware_watchpoint (bptype type, int cnt,
  1626. int othertype);
  1627. /* Returns the number of debug registers needed to watch the given
  1628. memory region, or zero if not supported. */
  1629. extern int target_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len);
  1630. extern int target_can_do_single_step ();
  1631. /* Set/clear a hardware watchpoint starting at ADDR, for LEN bytes.
  1632. TYPE is 0 for write, 1 for read, and 2 for read/write accesses.
  1633. COND is the expression for its condition, or NULL if there's none.
  1634. Returns 0 for success, 1 if the watchpoint type is not supported,
  1635. -1 for failure. */
  1636. extern int target_insert_watchpoint (CORE_ADDR addr, int len,
  1637. target_hw_bp_type type, expression *cond);
  1638. extern int target_remove_watchpoint (CORE_ADDR addr, int len,
  1639. target_hw_bp_type type, expression *cond);
  1640. /* Insert a new masked watchpoint at ADDR using the mask MASK.
  1641. RW may be hw_read for a read watchpoint, hw_write for a write watchpoint
  1642. or hw_access for an access watchpoint. Returns 0 for success, 1 if
  1643. masked watchpoints are not supported, -1 for failure. */
  1644. extern int target_insert_mask_watchpoint (CORE_ADDR, CORE_ADDR,
  1645. enum target_hw_bp_type);
  1646. /* Remove a masked watchpoint at ADDR with the mask MASK.
  1647. RW may be hw_read for a read watchpoint, hw_write for a write watchpoint
  1648. or hw_access for an access watchpoint. Returns 0 for success, non-zero
  1649. for failure. */
  1650. extern int target_remove_mask_watchpoint (CORE_ADDR, CORE_ADDR,
  1651. enum target_hw_bp_type);
  1652. /* Insert a hardware breakpoint at address BP_TGT->placed_address in
  1653. the target machine. Returns 0 for success, and returns non-zero or
  1654. throws an error (with a detailed failure reason error code and
  1655. message) otherwise. */
  1656. extern int target_insert_hw_breakpoint (gdbarch *gdbarch,
  1657. bp_target_info *bp_tgt);
  1658. extern int target_remove_hw_breakpoint (gdbarch *gdbarch,
  1659. bp_target_info *bp_tgt);
  1660. /* Return number of debug registers needed for a ranged breakpoint,
  1661. or -1 if ranged breakpoints are not supported. */
  1662. extern int target_ranged_break_num_registers (void);
  1663. /* Return non-zero if target knows the data address which triggered this
  1664. target_stopped_by_watchpoint, in such case place it to *ADDR_P. Only the
  1665. INFERIOR_PTID task is being queried. */
  1666. #define target_stopped_data_address(target, addr_p) \
  1667. (target)->stopped_data_address (addr_p)
  1668. /* Return non-zero if ADDR is within the range of a watchpoint spanning
  1669. LENGTH bytes beginning at START. */
  1670. #define target_watchpoint_addr_within_range(target, addr, start, length) \
  1671. (target)->watchpoint_addr_within_range (addr, start, length)
  1672. /* Return non-zero if the target is capable of using hardware to evaluate
  1673. the condition expression. In this case, if the condition is false when
  1674. the watched memory location changes, execution may continue without the
  1675. debugger being notified.
  1676. Due to limitations in the hardware implementation, it may be capable of
  1677. avoiding triggering the watchpoint in some cases where the condition
  1678. expression is false, but may report some false positives as well.
  1679. For this reason, GDB will still evaluate the condition expression when
  1680. the watchpoint triggers. */
  1681. extern bool target_can_accel_watchpoint_condition (CORE_ADDR addr, int len,
  1682. int type, expression *cond);
  1683. /* Return number of debug registers needed for a masked watchpoint,
  1684. -1 if masked watchpoints are not supported or -2 if the given address
  1685. and mask combination cannot be used. */
  1686. extern int target_masked_watch_num_registers (CORE_ADDR addr, CORE_ADDR mask);
  1687. /* Target can execute in reverse? */
  1688. extern bool target_can_execute_reverse ();
  1689. extern const struct target_desc *target_read_description (struct target_ops *);
  1690. extern ptid_t target_get_ada_task_ptid (long lwp, ULONGEST tid);
  1691. /* Main entry point for searching memory. */
  1692. extern int target_search_memory (CORE_ADDR start_addr,
  1693. ULONGEST search_space_len,
  1694. const gdb_byte *pattern,
  1695. ULONGEST pattern_len,
  1696. CORE_ADDR *found_addrp);
  1697. /* Target file operations. */
  1698. /* Return true if the filesystem seen by the current inferior
  1699. is the local filesystem, zero otherwise. */
  1700. extern bool target_filesystem_is_local ();
  1701. /* Open FILENAME on the target, in the filesystem as seen by INF,
  1702. using FLAGS and MODE. If INF is NULL, use the filesystem seen by
  1703. the debugger (GDB or, for remote targets, the remote stub). Return
  1704. a target file descriptor, or -1 if an error occurs (and set
  1705. *TARGET_ERRNO). If WARN_IF_SLOW is true, print a warning message
  1706. if the file is being accessed over a link that may be slow. */
  1707. extern int target_fileio_open (struct inferior *inf,
  1708. const char *filename, int flags,
  1709. int mode, bool warn_if_slow,
  1710. int *target_errno);
  1711. /* Write up to LEN bytes from WRITE_BUF to FD on the target.
  1712. Return the number of bytes written, or -1 if an error occurs
  1713. (and set *TARGET_ERRNO). */
  1714. extern int target_fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
  1715. ULONGEST offset, int *target_errno);
  1716. /* Read up to LEN bytes FD on the target into READ_BUF.
  1717. Return the number of bytes read, or -1 if an error occurs
  1718. (and set *TARGET_ERRNO). */
  1719. extern int target_fileio_pread (int fd, gdb_byte *read_buf, int len,
  1720. ULONGEST offset, int *target_errno);
  1721. /* Get information about the file opened as FD on the target
  1722. and put it in SB. Return 0 on success, or -1 if an error
  1723. occurs (and set *TARGET_ERRNO). */
  1724. extern int target_fileio_fstat (int fd, struct stat *sb,
  1725. int *target_errno);
  1726. /* Close FD on the target. Return 0, or -1 if an error occurs
  1727. (and set *TARGET_ERRNO). */
  1728. extern int target_fileio_close (int fd, int *target_errno);
  1729. /* Unlink FILENAME on the target, in the filesystem as seen by INF.
  1730. If INF is NULL, use the filesystem seen by the debugger (GDB or,
  1731. for remote targets, the remote stub). Return 0, or -1 if an error
  1732. occurs (and set *TARGET_ERRNO). */
  1733. extern int target_fileio_unlink (struct inferior *inf,
  1734. const char *filename,
  1735. int *target_errno);
  1736. /* Read value of symbolic link FILENAME on the target, in the
  1737. filesystem as seen by INF. If INF is NULL, use the filesystem seen
  1738. by the debugger (GDB or, for remote targets, the remote stub).
  1739. Return a null-terminated string allocated via xmalloc, or NULL if
  1740. an error occurs (and set *TARGET_ERRNO). */
  1741. extern gdb::optional<std::string> target_fileio_readlink
  1742. (struct inferior *inf, const char *filename, int *target_errno);
  1743. /* Read target file FILENAME, in the filesystem as seen by INF. If
  1744. INF is NULL, use the filesystem seen by the debugger (GDB or, for
  1745. remote targets, the remote stub). The return value will be -1 if
  1746. the transfer fails or is not supported; 0 if the object is empty;
  1747. or the length of the object otherwise. If a positive value is
  1748. returned, a sufficiently large buffer will be allocated using
  1749. xmalloc and returned in *BUF_P containing the contents of the
  1750. object.
  1751. This method should be used for objects sufficiently small to store
  1752. in a single xmalloc'd buffer, when no fixed bound on the object's
  1753. size is known in advance. */
  1754. extern LONGEST target_fileio_read_alloc (struct inferior *inf,
  1755. const char *filename,
  1756. gdb_byte **buf_p);
  1757. /* Read target file FILENAME, in the filesystem as seen by INF. If
  1758. INF is NULL, use the filesystem seen by the debugger (GDB or, for
  1759. remote targets, the remote stub). The result is NUL-terminated and
  1760. returned as a string, allocated using xmalloc. If an error occurs
  1761. or the transfer is unsupported, NULL is returned. Empty objects
  1762. are returned as allocated but empty strings. A warning is issued
  1763. if the result contains any embedded NUL bytes. */
  1764. extern gdb::unique_xmalloc_ptr<char> target_fileio_read_stralloc
  1765. (struct inferior *inf, const char *filename);
  1766. /* Invalidate the target associated with open handles that were open
  1767. on target TARG, since we're about to close (and maybe destroy) the
  1768. target. The handles remain open from the client's perspective, but
  1769. trying to do anything with them other than closing them will fail
  1770. with EIO. */
  1771. extern void fileio_handles_invalidate_target (target_ops *targ);
  1772. /* Tracepoint-related operations. */
  1773. extern void target_trace_init ();
  1774. extern void target_download_tracepoint (bp_location *location);
  1775. extern bool target_can_download_tracepoint ();
  1776. extern void target_download_trace_state_variable (const trace_state_variable &tsv);
  1777. extern void target_enable_tracepoint (bp_location *loc);
  1778. extern void target_disable_tracepoint (bp_location *loc);
  1779. extern void target_trace_start ();
  1780. extern void target_trace_set_readonly_regions ();
  1781. extern int target_get_trace_status (trace_status *ts);
  1782. extern void target_get_tracepoint_status (breakpoint *tp, uploaded_tp *utp);
  1783. extern void target_trace_stop ();
  1784. extern int target_trace_find (trace_find_type type, int num, CORE_ADDR addr1,
  1785. CORE_ADDR addr2, int *tpp);
  1786. extern bool target_get_trace_state_variable_value (int tsv, LONGEST *val);
  1787. extern int target_save_trace_data (const char *filename);
  1788. extern int target_upload_tracepoints (uploaded_tp **utpp);
  1789. extern int target_upload_trace_state_variables (uploaded_tsv **utsvp);
  1790. extern LONGEST target_get_raw_trace_data (gdb_byte *buf, ULONGEST offset,
  1791. LONGEST len);
  1792. extern int target_get_min_fast_tracepoint_insn_len ();
  1793. extern void target_set_disconnected_tracing (int val);
  1794. extern void target_set_circular_trace_buffer (int val);
  1795. extern void target_set_trace_buffer_size (LONGEST val);
  1796. extern bool target_set_trace_notes (const char *user, const char *notes,
  1797. const char *stopnotes);
  1798. extern bool target_get_tib_address (ptid_t ptid, CORE_ADDR *addr);
  1799. extern void target_set_permissions ();
  1800. extern bool target_static_tracepoint_marker_at
  1801. (CORE_ADDR addr, static_tracepoint_marker *marker);
  1802. extern std::vector<static_tracepoint_marker>
  1803. target_static_tracepoint_markers_by_strid (const char *marker_id);
  1804. extern traceframe_info_up target_traceframe_info ();
  1805. extern bool target_use_agent (bool use);
  1806. extern bool target_can_use_agent ();
  1807. extern bool target_augmented_libraries_svr4_read ();
  1808. extern bool target_supports_memory_tagging ();
  1809. extern bool target_fetch_memtags (CORE_ADDR address, size_t len,
  1810. gdb::byte_vector &tags, int type);
  1811. extern bool target_store_memtags (CORE_ADDR address, size_t len,
  1812. const gdb::byte_vector &tags, int type);
  1813. /* Command logging facility. */
  1814. extern void target_log_command (const char *p);
  1815. extern int target_core_of_thread (ptid_t ptid);
  1816. /* See to_get_unwinder in struct target_ops. */
  1817. extern const struct frame_unwind *target_get_unwinder (void);
  1818. /* See to_get_tailcall_unwinder in struct target_ops. */
  1819. extern const struct frame_unwind *target_get_tailcall_unwinder (void);
  1820. /* This implements basic memory verification, reading target memory
  1821. and performing the comparison here (as opposed to accelerated
  1822. verification making use of the qCRC packet, for example). */
  1823. extern int simple_verify_memory (struct target_ops* ops,
  1824. const gdb_byte *data,
  1825. CORE_ADDR memaddr, ULONGEST size);
  1826. /* Verify that the memory in the [MEMADDR, MEMADDR+SIZE) range matches
  1827. the contents of [DATA,DATA+SIZE). Returns 1 if there's a match, 0
  1828. if there's a mismatch, and -1 if an error is encountered while
  1829. reading memory. Throws an error if the functionality is found not
  1830. to be supported by the current target. */
  1831. int target_verify_memory (const gdb_byte *data,
  1832. CORE_ADDR memaddr, ULONGEST size);
  1833. /* Routines for maintenance of the target structures...
  1834. add_target: Add a target to the list of all possible targets.
  1835. This only makes sense for targets that should be activated using
  1836. the "target TARGET_NAME ..." command.
  1837. push_target: Make this target the top of the stack of currently used
  1838. targets, within its particular stratum of the stack. Result
  1839. is 0 if now atop the stack, nonzero if not on top (maybe
  1840. should warn user).
  1841. unpush_target: Remove this from the stack of currently used targets,
  1842. no matter where it is on the list. Returns 0 if no
  1843. change, 1 if removed from stack. */
  1844. /* Type of callback called when the user activates a target with
  1845. "target TARGET_NAME". The callback routine takes the rest of the
  1846. parameters from the command, and (if successful) pushes a new
  1847. target onto the stack. */
  1848. typedef void target_open_ftype (const char *args, int from_tty);
  1849. /* Add the target described by INFO to the list of possible targets
  1850. and add a new command 'target $(INFO->shortname)'. Set COMPLETER
  1851. as the command's completer if not NULL. */
  1852. extern void add_target (const target_info &info,
  1853. target_open_ftype *func,
  1854. completer_ftype *completer = NULL);
  1855. /* Adds a command ALIAS for the target described by INFO and marks it
  1856. deprecated. This is useful for maintaining backwards compatibility
  1857. when renaming targets. */
  1858. extern void add_deprecated_target_alias (const target_info &info,
  1859. const char *alias);
  1860. /* A unique_ptr helper to unpush a target. */
  1861. struct target_unpusher
  1862. {
  1863. void operator() (struct target_ops *ops) const;
  1864. };
  1865. /* A unique_ptr that unpushes a target on destruction. */
  1866. typedef std::unique_ptr<struct target_ops, target_unpusher> target_unpush_up;
  1867. extern void target_pre_inferior (int);
  1868. extern void target_preopen (int);
  1869. /* Does whatever cleanup is required to get rid of all pushed targets. */
  1870. extern void pop_all_targets (void);
  1871. /* Like pop_all_targets, but pops only targets whose stratum is at or
  1872. above STRATUM. */
  1873. extern void pop_all_targets_at_and_above (enum strata stratum);
  1874. /* Like pop_all_targets, but pops only targets whose stratum is
  1875. strictly above ABOVE_STRATUM. */
  1876. extern void pop_all_targets_above (enum strata above_stratum);
  1877. extern CORE_ADDR target_translate_tls_address (struct objfile *objfile,
  1878. CORE_ADDR offset);
  1879. /* Return the "section" containing the specified address. */
  1880. const struct target_section *target_section_by_addr (struct target_ops *target,
  1881. CORE_ADDR addr);
  1882. /* Return the target section table this target (or the targets
  1883. beneath) currently manipulate. */
  1884. extern const target_section_table *target_get_section_table
  1885. (struct target_ops *target);
  1886. /* Default implementation of get_section_table for dummy_target. */
  1887. extern const target_section_table *default_get_section_table ();
  1888. /* From mem-break.c */
  1889. extern int memory_remove_breakpoint (struct target_ops *,
  1890. struct gdbarch *, struct bp_target_info *,
  1891. enum remove_bp_reason);
  1892. extern int memory_insert_breakpoint (struct target_ops *,
  1893. struct gdbarch *, struct bp_target_info *);
  1894. /* Convenience template use to add memory breakpoints support to a
  1895. target. */
  1896. template <typename BaseTarget>
  1897. struct memory_breakpoint_target : public BaseTarget
  1898. {
  1899. int insert_breakpoint (struct gdbarch *gdbarch,
  1900. struct bp_target_info *bp_tgt) override
  1901. { return memory_insert_breakpoint (this, gdbarch, bp_tgt); }
  1902. int remove_breakpoint (struct gdbarch *gdbarch,
  1903. struct bp_target_info *bp_tgt,
  1904. enum remove_bp_reason reason) override
  1905. { return memory_remove_breakpoint (this, gdbarch, bp_tgt, reason); }
  1906. };
  1907. /* Check whether the memory at the breakpoint's placed address still
  1908. contains the expected breakpoint instruction. */
  1909. extern int memory_validate_breakpoint (struct gdbarch *gdbarch,
  1910. struct bp_target_info *bp_tgt);
  1911. extern int default_memory_remove_breakpoint (struct gdbarch *,
  1912. struct bp_target_info *);
  1913. extern int default_memory_insert_breakpoint (struct gdbarch *,
  1914. struct bp_target_info *);
  1915. /* From target.c */
  1916. extern void initialize_targets (void);
  1917. extern void noprocess (void) ATTRIBUTE_NORETURN;
  1918. extern void target_require_runnable (void);
  1919. /* Find the target at STRATUM. If no target is at that stratum,
  1920. return NULL. */
  1921. struct target_ops *find_target_at (enum strata stratum);
  1922. /* Read OS data object of type TYPE from the target, and return it in XML
  1923. format. The return value follows the same rules as target_read_stralloc. */
  1924. extern gdb::optional<gdb::char_vector> target_get_osdata (const char *type);
  1925. /* Stuff that should be shared among the various remote targets. */
  1926. /* Timeout limit for response from target. */
  1927. extern int remote_timeout;
  1928. /* Set the show memory breakpoints mode to show, and return a
  1929. scoped_restore to restore it back to the current value. */
  1930. extern scoped_restore_tmpl<int>
  1931. make_scoped_restore_show_memory_breakpoints (int show);
  1932. extern bool may_write_registers;
  1933. extern bool may_write_memory;
  1934. extern bool may_insert_breakpoints;
  1935. extern bool may_insert_tracepoints;
  1936. extern bool may_insert_fast_tracepoints;
  1937. extern bool may_stop;
  1938. extern void update_target_permissions (void);
  1939. /* Imported from machine dependent code. */
  1940. /* See to_enable_btrace in struct target_ops. */
  1941. extern struct btrace_target_info *
  1942. target_enable_btrace (thread_info *tp, const struct btrace_config *);
  1943. /* See to_disable_btrace in struct target_ops. */
  1944. extern void target_disable_btrace (struct btrace_target_info *btinfo);
  1945. /* See to_teardown_btrace in struct target_ops. */
  1946. extern void target_teardown_btrace (struct btrace_target_info *btinfo);
  1947. /* See to_read_btrace in struct target_ops. */
  1948. extern enum btrace_error target_read_btrace (struct btrace_data *,
  1949. struct btrace_target_info *,
  1950. enum btrace_read_type);
  1951. /* See to_btrace_conf in struct target_ops. */
  1952. extern const struct btrace_config *
  1953. target_btrace_conf (const struct btrace_target_info *);
  1954. /* See to_stop_recording in struct target_ops. */
  1955. extern void target_stop_recording (void);
  1956. /* See to_save_record in struct target_ops. */
  1957. extern void target_save_record (const char *filename);
  1958. /* Query if the target supports deleting the execution log. */
  1959. extern int target_supports_delete_record (void);
  1960. /* See to_delete_record in struct target_ops. */
  1961. extern void target_delete_record (void);
  1962. /* See to_record_method. */
  1963. extern enum record_method target_record_method (ptid_t ptid);
  1964. /* See to_record_is_replaying in struct target_ops. */
  1965. extern int target_record_is_replaying (ptid_t ptid);
  1966. /* See to_record_will_replay in struct target_ops. */
  1967. extern int target_record_will_replay (ptid_t ptid, int dir);
  1968. /* See to_record_stop_replaying in struct target_ops. */
  1969. extern void target_record_stop_replaying (void);
  1970. /* See to_goto_record_begin in struct target_ops. */
  1971. extern void target_goto_record_begin (void);
  1972. /* See to_goto_record_end in struct target_ops. */
  1973. extern void target_goto_record_end (void);
  1974. /* See to_goto_record in struct target_ops. */
  1975. extern void target_goto_record (ULONGEST insn);
  1976. /* See to_insn_history. */
  1977. extern void target_insn_history (int size, gdb_disassembly_flags flags);
  1978. /* See to_insn_history_from. */
  1979. extern void target_insn_history_from (ULONGEST from, int size,
  1980. gdb_disassembly_flags flags);
  1981. /* See to_insn_history_range. */
  1982. extern void target_insn_history_range (ULONGEST begin, ULONGEST end,
  1983. gdb_disassembly_flags flags);
  1984. /* See to_call_history. */
  1985. extern void target_call_history (int size, record_print_flags flags);
  1986. /* See to_call_history_from. */
  1987. extern void target_call_history_from (ULONGEST begin, int size,
  1988. record_print_flags flags);
  1989. /* See to_call_history_range. */
  1990. extern void target_call_history_range (ULONGEST begin, ULONGEST end,
  1991. record_print_flags flags);
  1992. /* See to_prepare_to_generate_core. */
  1993. extern void target_prepare_to_generate_core (void);
  1994. /* See to_done_generating_core. */
  1995. extern void target_done_generating_core (void);
  1996. #endif /* !defined (TARGET_H) */