gdbint.pp 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292
  1. {
  2. $Id$
  3. Copyright (c) 1998 by Peter Vreman
  4. Lowlevel GDB interface which communicates directly with libgdb
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit GdbInt;
  12. {$smartlink off}
  13. interface
  14. { this is not needed (PM) $output_format as}
  15. {.$define Debug}
  16. {.$define DebugCommand}
  17. {$define NotImplemented}
  18. {$ifdef go32v2}
  19. {$undef NotImplemented}
  20. { ifdef GDB_V418 changed to ifndef GDB_V416}
  21. {$ifdef USE_GDB_OBJS}
  22. {$include gdbobjs.inc}
  23. {$else USE_GDB_OBJS}
  24. {$LINKLIB gdb}
  25. {$endif ndef USE_GDB_OBJS}
  26. {$LINKLIB dbg}
  27. {$LINKLIB c}
  28. {$endif go32v2}
  29. {$ifdef linux}
  30. {$undef NotImplemented}
  31. {$LINKLIB ncurses}
  32. {$LINKLIB gdb}
  33. {$LINKLIB c}
  34. {$LINKLIB gcc}
  35. {$endif linux}
  36. {$ifdef win32}
  37. {$undef NotImplemented}
  38. {$LINKLIB cygwin}
  39. {$LINKLIB gdb}
  40. {$ifdef USE_TERMCAP}
  41. {$LINKLIB termcap}
  42. {$else not USE_TERMCAP}
  43. {$LINKLIB ncurses}
  44. {$endif not USE_TERMCAP}
  45. {$LINKLIB gcc}
  46. {$LINKLIB c}
  47. {$LINKLIB cygwin}
  48. { all those are maybe not necessary
  49. but at least user32 is required
  50. because of clipboard handling PM }
  51. {$LINKLIB kernel32}
  52. {$LINKLIB user32}
  53. {$endif win32}
  54. {$ifdef go32v2}
  55. {$define supportexceptions}
  56. {$endif go32v2}
  57. {$ifdef linux}
  58. {$define supportexceptions}
  59. {$endif linux}
  60. {$ifdef NotImplemented}
  61. {$fatal This OS is not yet supported !!!}
  62. {$endif NotImplemented}
  63. type
  64. psyminfo=^tsyminfo;
  65. tsyminfo=record
  66. address : longint;
  67. fname : pchar;
  68. line : longint;
  69. funcname : pchar;
  70. offset : longint;
  71. end;
  72. tframeentry = object
  73. file_name : pchar;
  74. function_name : pchar;
  75. args : pchar;
  76. line_number : longint;
  77. address : longint;
  78. level : longint;
  79. constructor init;
  80. destructor done;
  81. procedure reset;
  82. procedure clear;
  83. end;
  84. pframeentry=^tframeentry;
  85. ppframeentry=^pframeentry;
  86. {$ifndef GDB_V416}
  87. { needed for handles }
  88. {not anymore I textrec.inc}
  89. { GDB_FILE type }
  90. type
  91. streamtype = (afile,astring);
  92. C_FILE = longint; { at least under DJGPP }
  93. P_C_FILE = ^C_FILE;
  94. PGDB_FILE = ^TGDB_FILE;
  95. TGDB_FILE = record
  96. ts_streamtype : streamtype;
  97. ts_filestream : P_C_FILE;
  98. ts_strbuf : pchar;
  99. ts_buflen : longint;
  100. end;
  101. {$ifdef win32}
  102. { from sys/reent.h
  103. real structure is bigger but only std.. are wanted here PM }
  104. REENT = record
  105. err : longint;
  106. stdin,stdout,stderr : P_C_FILE;
  107. end;
  108. PREENT = ^REENT;
  109. var _impure_ptr : PREENT;cvar;external;
  110. {$endif win32}
  111. {$endif not GDB_V416}
  112. type
  113. tgdbbuffer=object
  114. buf : pchar;
  115. size,
  116. idx : longint;
  117. {$ifndef GDB_V416}
  118. link : pgdb_file;
  119. {$endif not GDB_V416}
  120. constructor Init;
  121. destructor Done;
  122. procedure Reset;
  123. procedure Resize(nsize : longint);
  124. procedure Append(p:pchar);
  125. end;
  126. pgdbinterface=^tgdbinterface;
  127. tgdbinterface=object
  128. gdberrorbuf,
  129. gdboutputbuf : tgdbbuffer;
  130. got_error,
  131. reset_command,
  132. call_reset,
  133. Debuggee_started : boolean;
  134. { frames and frame info while recording a frame }
  135. frames : ppframeentry;
  136. frame_size,
  137. frame_count : longint;
  138. record_frames,
  139. frame_begin_seen : boolean;
  140. frame_level,
  141. command_level,
  142. stop_breakpoint_number,
  143. current_address,
  144. current_line_number,
  145. signal_start,
  146. signal_end,
  147. error_start,
  148. error_end,
  149. function_start,
  150. function_end,
  151. args_start,
  152. args_end,
  153. file_start,
  154. file_end,
  155. line_start,
  156. line_end : longint;
  157. { breakpoint }
  158. last_breakpoint_number,
  159. last_breakpoint_address,
  160. last_breakpoint_line : longint;
  161. last_breakpoint_file : pchar;
  162. invalid_breakpoint_line : boolean;
  163. { init }
  164. constructor init;
  165. destructor done;
  166. { Lowlevel }
  167. function error:boolean;
  168. function error_num:longint;
  169. procedure gdb_command(const s:string);
  170. procedure gdb__init;
  171. procedure gdb_done;
  172. procedure resize_frames;
  173. function add_frameentry:pframeentry;
  174. function get_frameentry(level : longint):pframeentry;
  175. function get_current_frame : longint;
  176. function set_current_frame(level : longint) : boolean;
  177. procedure clear_frames;
  178. { Highlevel }
  179. user_screen_shown,
  180. switch_to_user : boolean;
  181. procedure GetAddrSyminfo(addr:longint;var si:tsyminfo);
  182. procedure SelectSourceline(fn:pchar;line:longint);
  183. procedure StartSession;
  184. procedure BreakSession;
  185. procedure EndSession(code:longint);
  186. procedure DebuggerScreen;
  187. procedure UserScreen;
  188. { Hooks }
  189. procedure DoSelectSourceline(const fn:string;line:longint);virtual;
  190. procedure DoStartSession;virtual;
  191. procedure DoBreakSession;virtual;
  192. procedure DoEndSession(code:longint);virtual;
  193. procedure DoDebuggerScreen;virtual;
  194. procedure DoUserScreen;virtual;
  195. function AllowQuit : boolean;virtual;
  196. end;
  197. function GDBVersion : string;
  198. var
  199. curr_gdb : pgdbinterface;
  200. const
  201. use_gdb_file : boolean = false;
  202. var
  203. gdb_file : text;
  204. inferior_pid : longint;cvar;external;
  205. {$ifdef go32v2}
  206. { needed to be sure %fs contains the DOS memory selector
  207. used in Mem[] code PM }
  208. procedure reload_fs;
  209. {$endif go32v2}
  210. implementation
  211. uses
  212. {$ifdef win32}
  213. initc,
  214. {$endif win32}
  215. {$ifdef linux}
  216. linux,
  217. {$endif}
  218. {$ifdef go32v2}
  219. go32,
  220. dpmiexcp,
  221. initc,
  222. {$endif}
  223. strings;
  224. {*****************************************************************************
  225. Types used by libgdb.a
  226. *****************************************************************************}
  227. {$ifdef go32v2}
  228. type
  229. jmp_buf = dpmi_jmp_buf;
  230. pjmp_buf = pdpmi_jmp_buf;
  231. function setjmp(var rec : jmp_buf) : longint;cdecl;external;
  232. procedure longjmp(var rec : jmp_buf;return_value : longint);cdecl;external;
  233. procedure reload_fs;assembler;
  234. asm
  235. movw dosmemselector,%ax
  236. movw %ax,%fs
  237. end['EAX'];
  238. {$endif}
  239. {$ifdef win32}
  240. function setjmp(var rec : jmp_buf) : longint;cdecl;external;
  241. procedure longjmp(var rec : jmp_buf;return_value : longint);cdecl;external;
  242. {$ifndef supportexceptions}
  243. type
  244. { I don't think FPC would accept that
  245. the funcvar return type is the funcvar type itself ! PM }
  246. SignalHandler = Procedure(Sig : LongInt);cdecl;
  247. function signal(sig : longint;new_signal : SignalHandler) : SignalHandler;cdecl;external;
  248. {define supportexceptions not yet working }
  249. {$endif now exceptions are supported for win32}
  250. {$endif win32}
  251. type
  252. CORE_ADDR = longint;
  253. pCORE_ADDR = ^CORE_ADDR;
  254. pblock = ^block;
  255. tlanguage = (language_unknown,language_auto,language_c,
  256. language_cplus,language_java,language_chill,
  257. language_fortran,language_m2,language_asm,
  258. language_scm,language_pascal,language_objc);
  259. bptype = (bp_breakpoint,bp_hardware_breakpoint,
  260. bp_until,bp_finish,bp_watchpoint,bp_hardware_watchpoint,
  261. bp_read_watchpoint,bp_access_watchpoint,
  262. bp_longjmp,bp_longjmp_resume,bp_step_resume,
  263. bp_through_sigtramp,bp_watchpoint_scope,
  264. bp_call_dummy,bp_shlib_event);
  265. tenable = (disabled,enabled,shlib_disabled);
  266. bpdisp = (del,del_at_next_stop,disable,donttouch);
  267. {$PACKRECORDS 4}
  268. pbreakpoint = ^breakpoint;
  269. breakpoint = record
  270. next : pbreakpoint;
  271. typ : bptype;
  272. enable : tenable;
  273. disposition : bpdisp;
  274. number : longint;
  275. address : CORE_ADDR;
  276. line_number : longint;
  277. source_file : pchar;
  278. silent : byte;
  279. ignore_count : longint;
  280. shadow_contents : array[0..15] of char;
  281. inserted : char;
  282. duplicate : char;
  283. commands : pointer; {^command_line}
  284. frame : CORE_ADDR;
  285. cond : pointer; {^expression}
  286. addr_string : ^char;
  287. language : tlanguage;
  288. input_radix : longint;
  289. cond_string : ^char;
  290. exp_string : ^char;
  291. exp : pointer; {^expression}
  292. exp_valid_block : pblock; {^block;}
  293. val : pointer; {value_ptr;}
  294. val_chain : pointer; {value_ptr;}
  295. related_breakpoint : pbreakpoint;
  296. watchpoint_frame : CORE_ADDR;
  297. thread : longint;
  298. hit_count : longint;
  299. section : pointer; {^asection}
  300. end;
  301. tfreecode=(free_nothing,free_contents,free_linetable);
  302. psymtab = ^symtab;
  303. symtab = record
  304. next : psymtab;
  305. blockvector : pointer; {^blockvector;}
  306. linetable : pointer; {^linetable;}
  307. block_line_section : longint;
  308. primary : longint;
  309. filename : pchar;
  310. dirname : pchar;
  311. free_code : tfreecode;
  312. free_ptr : pchar;
  313. nlines : longint;
  314. line_charpos : ^longint;
  315. language : tlanguage;
  316. Debugformat : pchar;
  317. version : pchar;
  318. fullname : pchar;
  319. objfile : pointer; {^objfile;}
  320. end;
  321. psymtab_and_line = ^symtab_and_line;
  322. symtab_and_line = record
  323. symtab : psymtab;
  324. {$ifndef GDB_V416}
  325. { v4.16 does not have the section field !! }
  326. section : pointer; {^asection;}
  327. {$endif GDB_V416}
  328. line : longint;
  329. pc : CORE_ADDR;
  330. _end : CORE_ADDR;
  331. end;
  332. symtabs_and_lines = record
  333. sals : ^symtab_and_line;
  334. nelts : longint;
  335. end;
  336. psymbol = ^symbol;
  337. pminimal_symbol = ^minimal_symbol;
  338. general_symbol_info = record
  339. (* Name of the symbol. This is a required field. Storage for the name is
  340. allocated on the psymbol_obstack or symbol_obstack for the associated
  341. objfile. *)
  342. _name : pchar;
  343. (* Value of the symbol. Which member of this union to use, and what
  344. it means, depends on what kind of symbol this is and its
  345. SYMBOL_CLASS. See comments there for more details. All of these
  346. are in host byte order (though what they point to might be in
  347. target byte order, e.g. LOC_CONST_BYTES). *)
  348. value : record
  349. case integer of
  350. (* The fact that this is a long not a LONGEST mainly limits the
  351. range of a LOC_CONST. Since LOC_CONST_BYTES exists, I'm not
  352. sure that is a big deal. *)
  353. 0 : (ivalue : longint;);
  354. 1 : (block : pblock;);
  355. 2 : (bytes : pchar;);
  356. 3 : (address : CORE_ADDR;);
  357. (* for opaque typedef struct chain *)
  358. 4 : (chain : psymbol;);
  359. end;
  360. (* Since one and only one language can apply, wrap the language specific
  361. information inside a union. *)
  362. (* union
  363. {
  364. struct cplus_specific /* For C++ */
  365. /* and Java */
  366. {
  367. char *demangled_name;
  368. } cplus_specific;
  369. struct chill_specific /* For Chill */
  370. {
  371. char *demangled_name;
  372. } chill_specific;
  373. } language_specific; *)
  374. demangled_name : pchar;
  375. (* Record the source code language that applies to this symbol.
  376. This is used to select one of the fields from the language specific
  377. union above. *)
  378. language : tlanguage;
  379. (* Which section is this symbol in? This is an index into
  380. section_offsets for this objfile. Negative means that the symbol
  381. does not get relocated relative to a section.
  382. Disclaimer: currently this is just used for xcoff, so don't
  383. expect all symbol-reading code to set it correctly (the ELF code
  384. also tries to set it correctly). *)
  385. section : word;
  386. (* The bfd section associated with this symbol. *)
  387. bfd_section : pointer {^asection};
  388. end; { of general_symbol_info record declaration }
  389. tminimal_symbol_type =
  390. (
  391. mst_unknown := 0, (* Unknown type, the default *)
  392. mst_text, (* Generally executable instructions *)
  393. mst_data, (* Generally initialized data *)
  394. mst_bss, (* Generally uninitialized data *)
  395. mst_abs, (* Generally absolute (nonrelocatable) *)
  396. (* GDB uses mst_solib_trampoline for the start address of a shared
  397. library trampoline entry. Breakpoints for shared library functions
  398. are put there if the shared library is not yet loaded.
  399. After the shared library is loaded, lookup_minimal_symbol will
  400. prefer the minimal symbol from the shared library (usually
  401. a mst_text symbol) over the mst_solib_trampoline symbol, and the
  402. breakpoints will be moved to their true address in the shared
  403. library via breakpoint_re_set. *)
  404. mst_solib_trampoline, (* Shared library trampoline code *)
  405. (* For the mst_file* types, the names are only guaranteed to be unique
  406. within a given .o file. *)
  407. mst_file_text, (* Static version of mst_text *)
  408. mst_file_data, (* Static version of mst_data *)
  409. mst_file_bss (* Static version of mst_bss *)
  410. );
  411. namespace_enum = (
  412. (* UNDEF_NAMESPACE is used when a namespace has not been discovered or
  413. none of the following apply. This usually indicates an error either
  414. in the symbol information or in gdb's handling of symbols. *)
  415. UNDEF_NAMESPACE,
  416. (* VAR_NAMESPACE is the usual namespace. In C, this contains variables,
  417. function names, typedef names and enum type values. *)
  418. VAR_NAMESPACE,
  419. (* STRUCT_NAMESPACE is used in C to hold struct, union and enum type names.
  420. Thus, if `struct foo' is used in a C program, it produces a symbol named
  421. `foo' in the STRUCT_NAMESPACE. *)
  422. STRUCT_NAMESPACE,
  423. (* LABEL_NAMESPACE may be used for names of labels (for gotos);
  424. currently it is not used and labels are not recorded at all. *)
  425. LABEL_NAMESPACE,
  426. (* Searching namespaces. These overlap with VAR_NAMESPACE, providing
  427. some granularity with the search_symbols function. *)
  428. (* Everything in VAR_NAMESPACE minus FUNCTIONS_-, TYPES_-, and
  429. METHODS_NAMESPACE *)
  430. VARIABLES_NAMESPACE,
  431. (* All functions -- for some reason not methods, though. *)
  432. FUNCTIONS_NAMESPACE,
  433. (* All defined types *)
  434. TYPES_NAMESPACE,
  435. (* All class methods -- why is this separated out? *)
  436. METHODS_NAMESPACE
  437. );
  438. address_class = (
  439. (* Not used; catches errors *)
  440. LOC_UNDEF,
  441. (* Value is constant int SYMBOL_VALUE, host byteorder *)
  442. LOC_CONST,
  443. (* Value is at fixed address SYMBOL_VALUE_ADDRESS *)
  444. LOC_STATIC,
  445. (* Value is in register. SYMBOL_VALUE is the register number. *)
  446. LOC_REGISTER,
  447. (* It's an argument; the value is at SYMBOL_VALUE offset in arglist. *)
  448. LOC_ARG,
  449. (* Value address is at SYMBOL_VALUE offset in arglist. *)
  450. LOC_REF_ARG,
  451. (* Value is in register number SYMBOL_VALUE. Just like LOC_REGISTER
  452. except this is an argument. Probably the cleaner way to handle
  453. this would be to separate address_class (which would include
  454. separate ARG and LOCAL to deal with FRAME_ARGS_ADDRESS versus
  455. FRAME_LOCALS_ADDRESS), and an is_argument flag.
  456. For some symbol formats (stabs, for some compilers at least),
  457. the compiler generates two symbols, an argument and a register.
  458. In some cases we combine them to a single LOC_REGPARM in symbol
  459. reading, but currently not for all cases (e.g. it's passed on the
  460. stack and then loaded into a register). *)
  461. LOC_REGPARM,
  462. (* Value is in specified register. Just like LOC_REGPARM except the
  463. register holds the address of the argument instead of the argument
  464. itself. This is currently used for the passing of structs and unions
  465. on sparc and hppa. It is also used for call by reference where the
  466. address is in a register, at least by mipsread.c. *)
  467. LOC_REGPARM_ADDR,
  468. (* Value is a local variable at SYMBOL_VALUE offset in stack frame. *)
  469. LOC_LOCAL,
  470. (* Value not used; definition in SYMBOL_TYPE. Symbols in the namespace
  471. STRUCT_NAMESPACE all have this class. *)
  472. LOC_TYPEDEF,
  473. (* Value is address SYMBOL_VALUE_ADDRESS in the code *)
  474. LOC_LABEL,
  475. (* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'.
  476. In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address
  477. of the block. Function names have this class. *)
  478. LOC_BLOCK,
  479. (* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in
  480. target byte order. *)
  481. LOC_CONST_BYTES,
  482. (* Value is arg at SYMBOL_VALUE offset in stack frame. Differs from
  483. LOC_LOCAL in that symbol is an argument; differs from LOC_ARG in
  484. that we find it in the frame (FRAME_LOCALS_ADDRESS), not in the
  485. arglist (FRAME_ARGS_ADDRESS). Added for i960, which passes args
  486. in regs then copies to frame. *)
  487. LOC_LOCAL_ARG,
  488. (* Value is at SYMBOL_VALUE offset from the current value of
  489. register number SYMBOL_BASEREG. This exists mainly for the same
  490. things that LOC_LOCAL and LOC_ARG do; but we need to do this
  491. instead because on 88k DWARF gives us the offset from the
  492. frame/stack pointer, rather than the offset from the "canonical
  493. frame address" used by COFF, stabs, etc., and we don't know how
  494. to convert between these until we start examining prologues.
  495. Note that LOC_BASEREG is much less general than a DWARF expression.
  496. We don't need the generality (at least not yet), and storing a general
  497. DWARF expression would presumably take up more space than the existing
  498. scheme. *)
  499. LOC_BASEREG,
  500. (* Same as LOC_BASEREG but it is an argument. *)
  501. LOC_BASEREG_ARG,
  502. (* Value is at fixed address, but the address of the variable has
  503. to be determined from the minimal symbol table whenever the
  504. variable is referenced.
  505. This happens if debugging information for a global symbol is
  506. emitted and the corresponding minimal symbol is defined
  507. in another object file or runtime common storage.
  508. The linker might even remove the minimal symbol if the global
  509. symbol is never referenced, in which case the symbol remains
  510. unresolved. *)
  511. LOC_UNRESOLVED,
  512. (* Value is at a thread-specific location calculated by a
  513. target-specific method. *)
  514. LOC_THREAD_LOCAL_STATIC,
  515. (* The variable does not actually exist in the program.
  516. The value is ignored. *)
  517. LOC_OPTIMIZED_OUT,
  518. (* The variable is static, but actually lives at * (address).
  519. * I.e. do an extra indirection to get to it.
  520. * This is used on HP-UX to get at globals that are allocated
  521. * in shared libraries, where references from images other
  522. * than the one where the global was allocated are done
  523. * with a level of indirection.
  524. *)
  525. LOC_INDIRECT
  526. );
  527. minimal_symbol = record
  528. (* The general symbol info required for all types of symbols.
  529. The SYMBOL_VALUE_ADDRESS contains the address that this symbol
  530. corresponds to. *)
  531. ginfo : general_symbol_info;
  532. (* The info field is available for caching machine-specific information
  533. so it doesn't have to rederive the info constantly (over a serial line).
  534. It is initialized to zero and stays that way until target-dependent code
  535. sets it. Storage for any data pointed to by this field should be allo-
  536. cated on the symbol_obstack for the associated objfile.
  537. The type would be "void *" except for reasons of compatibility with older
  538. compilers. This field is optional.
  539. Currently, the AMD 29000 tdep.c uses it to remember things it has decoded
  540. from the instructions in the function header, and the MIPS-16 code uses
  541. it to identify 16-bit procedures. *)
  542. info : pchar;
  543. {$ifdef SOFUN_ADDRESS_MAYBE_MISSING}
  544. (* Which source file is this symbol in? Only relevant for mst_file_*. *)
  545. filename : pchar;
  546. {$endif}
  547. (* Classification types for this symbol. These should be taken as "advisory
  548. only", since if gdb can't easily figure out a classification it simply
  549. selects mst_unknown. It may also have to guess when it can't figure out
  550. which is a better match between two types (mst_data versus mst_bss) for
  551. example. Since the minimal symbol info is sometimes derived from the
  552. BFD library's view of a file, we need to live with what information bfd
  553. supplies. *)
  554. minimal_symbol_type : tminimal_symbol_type;
  555. end{ of minimal_symbol};
  556. block = record
  557. (* Addresses in the executable code that are in this block. *)
  558. startaddr,
  559. endaddr : CORE_ADDR ;
  560. (* The symbol that names this block, if the block is the body of a
  561. function; otherwise, zero. *)
  562. _function : psymbol;
  563. (* The `struct block' for the containing block, or 0 if none.
  564. The superblock of a top-level local block (i.e. a function in the
  565. case of C) is the STATIC_BLOCK. The superblock of the
  566. STATIC_BLOCK is the GLOBAL_BLOCK. *)
  567. superblock : pblock;
  568. (* Version of GCC used to compile the function corresponding
  569. to this block, or 0 if not compiled with GCC. When possible,
  570. GCC should be compatible with the native compiler, or if that
  571. is not feasible, the differences should be fixed during symbol
  572. reading. As of 16 Apr 93, this flag is never used to distinguish
  573. between gcc2 and the native compiler.
  574. If there is no function corresponding to this block, this meaning
  575. of this flag is undefined. *)
  576. gcc_compile_flag : byte;
  577. (* Number of local symbols. *)
  578. nsyms : longint;
  579. (* The symbols. If some of them are arguments, then they must be
  580. in the order in which we would like to print them. *)
  581. sym : array [0..0] of psymbol;
  582. end { of block definition };
  583. symbol = record
  584. (* The general symbol info required for all types of symbols. *)
  585. ginfo : general_symbol_info;
  586. (* Data type of value *)
  587. _type : pointer{ptype};
  588. (* Name space code. *)
  589. namespace : namespace_enum;
  590. (* Address class *)
  591. aclass : address_class;
  592. (* Line number of definition. FIXME: Should we really make the assumption
  593. that nobody will try to debug files longer than 64K lines? What about
  594. machine generated programs? *)
  595. line : word;
  596. (* Some symbols require an additional value to be recorded on a per-
  597. symbol basis. Stash those values here. *)
  598. (*union
  599. {
  600. /* Used by LOC_BASEREG and LOC_BASEREG_ARG. */
  601. short basereg;
  602. } *)
  603. aux_value_base_reg : word;
  604. (* Link to a list of aliases for this symbol.
  605. Only a "primary/main symbol may have aliases. *)
  606. aliases : pointer{palias_list};
  607. (* List of ranges where this symbol is active. This is only
  608. used by alias symbols at the current time. *)
  609. ranges : pointer{prange_list};
  610. end;
  611. target_signal = (TARGET_SIGNAL_FIRST := 0,
  612. TARGET_SIGNAL_HUP := 1,TARGET_SIGNAL_INT := 2,
  613. TARGET_SIGNAL_QUIT := 3,TARGET_SIGNAL_ILL := 4,
  614. TARGET_SIGNAL_TRAP := 5,TARGET_SIGNAL_ABRT := 6,
  615. TARGET_SIGNAL_EMT := 7,TARGET_SIGNAL_FPE := 8,
  616. TARGET_SIGNAL_KILL := 9,TARGET_SIGNAL_BUS := 10,
  617. TARGET_SIGNAL_SEGV := 11,TARGET_SIGNAL_SYS := 12,
  618. TARGET_SIGNAL_PIPE := 13,TARGET_SIGNAL_ALRM := 14,
  619. TARGET_SIGNAL_TERM := 15,TARGET_SIGNAL_URG := 16,
  620. TARGET_SIGNAL_STOP := 17,TARGET_SIGNAL_TSTP := 18,
  621. TARGET_SIGNAL_CONT := 19,TARGET_SIGNAL_CHLD := 20,
  622. TARGET_SIGNAL_TTIN := 21,TARGET_SIGNAL_TTOU := 22,
  623. TARGET_SIGNAL_IO := 23,TARGET_SIGNAL_XCPU := 24,
  624. TARGET_SIGNAL_XFSZ := 25,TARGET_SIGNAL_VTALRM := 26,
  625. TARGET_SIGNAL_PROF := 27,TARGET_SIGNAL_WINCH := 28,
  626. TARGET_SIGNAL_LOST := 29,TARGET_SIGNAL_USR1 := 30,
  627. TARGET_SIGNAL_USR2 := 31,TARGET_SIGNAL_PWR := 32,
  628. TARGET_SIGNAL_POLL := 33,TARGET_SIGNAL_WIND := 34,
  629. TARGET_SIGNAL_PHONE := 35,TARGET_SIGNAL_WAITING := 36,
  630. TARGET_SIGNAL_LWP := 37,TARGET_SIGNAL_DANGER := 38,
  631. TARGET_SIGNAL_GRANT := 39,TARGET_SIGNAL_RETRACT := 40,
  632. TARGET_SIGNAL_MSG := 41,TARGET_SIGNAL_SOUND := 42,
  633. TARGET_SIGNAL_SAK := 43,TARGET_SIGNAL_PRIO := 44,
  634. TARGET_SIGNAL_REALTIME_33 := 45,TARGET_SIGNAL_REALTIME_34 := 46,
  635. TARGET_SIGNAL_REALTIME_35 := 47,TARGET_SIGNAL_REALTIME_36 := 48,
  636. TARGET_SIGNAL_REALTIME_37 := 49,TARGET_SIGNAL_REALTIME_38 := 50,
  637. TARGET_SIGNAL_REALTIME_39 := 51,TARGET_SIGNAL_REALTIME_40 := 52,
  638. TARGET_SIGNAL_REALTIME_41 := 53,TARGET_SIGNAL_REALTIME_42 := 54,
  639. TARGET_SIGNAL_REALTIME_43 := 55,TARGET_SIGNAL_REALTIME_44 := 56,
  640. TARGET_SIGNAL_REALTIME_45 := 57,TARGET_SIGNAL_REALTIME_46 := 58,
  641. TARGET_SIGNAL_REALTIME_47 := 59,TARGET_SIGNAL_REALTIME_48 := 60,
  642. TARGET_SIGNAL_REALTIME_49 := 61,TARGET_SIGNAL_REALTIME_50 := 62,
  643. TARGET_SIGNAL_REALTIME_51 := 63,TARGET_SIGNAL_REALTIME_52 := 64,
  644. TARGET_SIGNAL_REALTIME_53 := 65,TARGET_SIGNAL_REALTIME_54 := 66,
  645. TARGET_SIGNAL_REALTIME_55 := 67,TARGET_SIGNAL_REALTIME_56 := 68,
  646. TARGET_SIGNAL_REALTIME_57 := 69,TARGET_SIGNAL_REALTIME_58 := 70,
  647. TARGET_SIGNAL_REALTIME_59 := 71,TARGET_SIGNAL_REALTIME_60 := 72,
  648. TARGET_SIGNAL_REALTIME_61 := 73,TARGET_SIGNAL_REALTIME_62 := 74,
  649. TARGET_SIGNAL_REALTIME_63 := 75,TARGET_SIGNAL_UNKNOWN,
  650. TARGET_SIGNAL_DEFAULT,TARGET_SIGNAL_LAST
  651. );
  652. strata = (dummy_stratum,file_stratum,core_stratum,download_stratum,process_stratum);
  653. ptarget_ops = ^target_ops;
  654. target_ops = record
  655. to_shortname : pchar;
  656. to_longname : pchar;
  657. to_doc : pchar;
  658. to_open : procedure (_para1:pchar; _para2:longint);
  659. to_close : procedure (_para1:longint);
  660. to_attach : procedure (_para1:pchar; _para2:longint);
  661. to_detach : procedure (_para1:pchar; _para2:longint);
  662. to_resume : procedure (_para1:longint; _para2:longint; _para3:target_signal);
  663. to_wait : pointer; {function (_para1:longint; _para2:ptarget_waitstatus):longint;}
  664. to_fetch_registers : procedure (_para1:longint);
  665. to_store_registers : procedure (_para1:longint);
  666. to_prepare_to_store : procedure ;
  667. to_xfer_memory : function (memaddr:CORE_ADDR; myaddr:pchar; len:longint; write:longint; target:ptarget_ops):longint;
  668. to_files_info : procedure (_para1:ptarget_ops);
  669. to_insert_breakpoint : function (_para1:CORE_ADDR; _para2:pchar):longint;
  670. to_remove_breakpoint : function (_para1:CORE_ADDR; _para2:pchar):longint;
  671. to_terminal_init : procedure ;
  672. to_terminal_inferior : procedure ;
  673. to_terminal_ours_for_output : procedure ;
  674. to_terminal_ours : procedure ;
  675. to_terminal_info : procedure (_para1:pchar; _para2:longint);
  676. to_kill : procedure ;
  677. to_load : procedure (_para1:pchar; _para2:longint);
  678. to_lookup_symbol : function (_para1:pchar; _para2:pCORE_ADDR):longint;
  679. to_create_inferior : procedure (_para1:pchar; _para2:pchar; _para3:ppchar);
  680. to_mourn_inferior : procedure ;
  681. to_can_run : function :longint;
  682. to_notice_signals : procedure (pid:longint);
  683. to_thread_alive : function (pid:longint):longint;
  684. to_stop : procedure ;
  685. to_stratum : strata;
  686. DONT_USE : pointer;
  687. to_has_all_memory : longint;
  688. to_has_memory : longint;
  689. to_has_stack : longint;
  690. to_has_registers : longint;
  691. to_has_execution : longint;
  692. to_sections : pointer; {^section_table}
  693. to_sections_end : pointer; {^section_table}
  694. to_magic : longint;
  695. end;
  696. {$PACKRECORDS NORMAL}
  697. {*****************************************************************************
  698. Define external calls to libgdb.a
  699. *****************************************************************************}
  700. var
  701. { external variables }
  702. error_return : jmp_buf;cvar;external;
  703. quit_return : jmp_buf;cvar;external;
  704. create_breakpoint_hook : pointer;cvar;external;
  705. current_target : target_ops;cvar;external;
  706. stop_pc : CORE_ADDR;cvar;external;
  707. { we need also to declare some vars }
  708. watchdog : longint;cvar;public;
  709. gdb_error : longint;cvar;public;
  710. display_time : longbool;cvar;public;
  711. display_space : longbool;cvar;public;
  712. {$ifndef GDB_V416}
  713. { the following are also needed from version 4.18 }
  714. { Whether this is the command line version or not }
  715. tui_version : longint;cvar;public;
  716. { Whether xdb commands will be handled }
  717. xdb_commands : longint;cvar;public;
  718. { Whether dbx commands will be handled }
  719. dbx_commands : longint;cvar;public;
  720. var
  721. gdb_stdout : PGDB_FILE;cvar;public;
  722. gdb_stderr : PGDB_FILE;cvar;public;
  723. { used for gdb_stdout and gdb_stderr }
  724. function xmalloc(size : longint) : pointer;cdecl;external;
  725. {$endif not GDB_V416}
  726. function find_pc_line(i:CORE_ADDR;l:longint):symtab_and_line;cdecl;external;
  727. function find_pc_function(i:CORE_ADDR):psymbol;cdecl;external;
  728. function lookup_minimal_symbol_by_pc(i : CORE_ADDR):pminimal_symbol;cdecl;external;
  729. procedure gdb_init;cdecl;external;
  730. procedure execute_command(p:pchar;i:longint);cdecl;external;
  731. procedure target_kill;cdecl;external;
  732. procedure target_close(i:longint);cdecl;external;
  733. {*****************************************************************************
  734. Helpers
  735. *****************************************************************************}
  736. procedure Debug(const s:string);
  737. begin
  738. if use_gdb_file then
  739. Writeln(gdb_file,s)
  740. else
  741. Writeln(s);
  742. end;
  743. {*****************************************************************************
  744. TFrameEntry
  745. *****************************************************************************}
  746. constructor tframeentry.init;
  747. begin
  748. Reset;
  749. end;
  750. destructor tframeentry.done;
  751. begin
  752. Clear;
  753. end;
  754. procedure tframeentry.reset;
  755. begin
  756. file_name:=nil;
  757. function_name:=nil;
  758. args:=nil;
  759. line_number:=0;
  760. address:=0;
  761. end;
  762. procedure tframeentry.clear;
  763. begin
  764. if assigned(file_name) then
  765. strdispose(file_name);
  766. if assigned(function_name) then
  767. strdispose(function_name);
  768. if assigned(args) then
  769. strdispose(args);
  770. reset;
  771. end;
  772. {*****************************************************************************
  773. tgdbbuffer
  774. *****************************************************************************}
  775. const
  776. blocksize=2048;
  777. constructor tgdbbuffer.init;
  778. begin
  779. Buf:=nil;
  780. {$ifndef GDB_V416}
  781. link:=nil;
  782. {$endif not GDB_V416}
  783. Size:=0;
  784. Resize(blocksize);
  785. Reset;
  786. end;
  787. destructor tgdbbuffer.done;
  788. begin
  789. if assigned(buf) then
  790. freemem(buf,size);
  791. {$ifndef GDB_V416}
  792. if assigned(link) then
  793. begin
  794. link^.ts_streamtype:=afile;
  795. link^.ts_strbuf:=nil;
  796. link^.ts_buflen:=0;
  797. end;
  798. {$endif not GDB_V416}
  799. end;
  800. procedure tgdbbuffer.reset;
  801. begin
  802. idx:=0;
  803. Buf[0]:=#0;
  804. end;
  805. procedure tgdbbuffer.append(p:pchar);
  806. var
  807. len : longint;
  808. begin
  809. if not assigned(p) then
  810. exit;
  811. len:=Strlen(p);
  812. if len+idx>size then
  813. Resize(len+idx);
  814. Move(p^,buf[idx],len);
  815. inc(idx,len);
  816. buf[idx]:=#0;
  817. end;
  818. procedure tgdbbuffer.resize(nsize : longint);
  819. var
  820. np : pchar;
  821. begin
  822. nsize:=((nsize+blocksize-1) div blocksize)*blocksize;
  823. getmem(np,nsize);
  824. if assigned(buf) then
  825. begin
  826. move(buf^,np^,size);
  827. freemem(buf,size);
  828. end;
  829. buf:=np;
  830. size:=nsize;
  831. {$ifndef GDB_V416}
  832. if assigned(link) then
  833. begin
  834. link^.ts_strbuf:=buf;
  835. link^.ts_buflen:=size;
  836. end;
  837. {$endif not GDB_V416}
  838. end;
  839. {*****************************************************************************
  840. Hook calls from libgdb.a
  841. *****************************************************************************}
  842. {$ifdef go32v2}
  843. procedure gdbpas_prev_exception_handler;cdecl;public;
  844. begin
  845. end;
  846. {$endif go32v2}
  847. procedure init_proc;cdecl;public;
  848. begin
  849. end;
  850. procedure annotate_signalled;cdecl;public;
  851. begin
  852. {$ifdef Debug}
  853. Debug('|signalled|');
  854. {$endif}
  855. end;
  856. procedure annotate_signal_name;cdecl;public;
  857. begin
  858. {$ifdef Debug}
  859. Debug('|signal_name|');
  860. with curr_gdb^ do
  861. signal_start:=gdboutputbuf.idx;
  862. {$endif}
  863. end;
  864. procedure annotate_signal_name_end;cdecl;public;
  865. begin
  866. {$ifdef Debug}
  867. Debug('|signal_name_end|');
  868. {$endif}
  869. end;
  870. procedure annotate_signal_string;cdecl;public;
  871. begin
  872. {$ifdef Debug}
  873. Debug('|signal_string|');
  874. {$endif}
  875. end;
  876. procedure annotate_signal_string_end;cdecl;public;
  877. begin
  878. {$ifdef Debug}
  879. Debug('|signal_string_end|');
  880. {$endif}
  881. with curr_gdb^ do
  882. begin
  883. signal_end:=gdboutputbuf.idx;
  884. {
  885. signal = (char *)alloca(signal_end-signal_start+1);
  886. strncpy(signal,gdb_output_buffer+signal_start,signal_end-signal_start);
  887. signal[signal_end-signal_start] = 0;
  888. if (user_screen_shown)
  889. __DebuggerScreen();
  890. _UserWarning(WARN_SIGNALED,signal);
  891. __UserScreen();
  892. else
  893. _UserWarning(WARN_SIGNALED,signal); }
  894. call_reset:=true;
  895. end;
  896. end;
  897. procedure annotate_signal;cdecl;public;
  898. begin
  899. {$ifdef Debug}
  900. Debug('|signal|');
  901. {$endif}
  902. end;
  903. procedure annotate_exited(exitstatus:longint);cdecl;public;
  904. begin
  905. {$ifdef Debug}
  906. Debug('|exited|');
  907. {$endif}
  908. {#ifdef __DJGPP__
  909. /* this is very important. The exit code of a djgpp program
  910. disables interrupts and after this there is no other interrupt
  911. called, which enables interrupts with the iret. */
  912. __dpmi_get_and_enable_virtual_interrupt_state();
  913. #endif }
  914. {$ifdef go32v2}
  915. {$asmmode att}
  916. asm
  917. movw $0x901,%ax
  918. int $0x31
  919. end;
  920. {$asmmode default}
  921. reload_fs;
  922. {$endif def go32v2}
  923. curr_gdb^.DebuggerScreen;
  924. { DeleteBreakPoints; }
  925. curr_gdb^.EndSession(exitstatus);
  926. end;
  927. procedure annotate_error;cdecl;public;
  928. begin
  929. {$ifdef Debug}
  930. Debug('|error|');
  931. {$endif}
  932. end;
  933. procedure annotate_error_begin;cdecl;public;
  934. begin
  935. {$ifdef Debug}
  936. Debug('|error begin|');
  937. {$endif}
  938. with curr_gdb^ do
  939. begin
  940. error_start:=gdboutputbuf.idx+strlen(gdboutputbuf.buf);
  941. got_error:=true;
  942. end;
  943. {$ifdef Debug}
  944. Debug('|end of error begin|');
  945. {$endif}
  946. end;
  947. procedure annotate_starting;cdecl;public;
  948. begin
  949. {$ifdef Debug}
  950. Debug('|starting|');
  951. {$endif}
  952. {$ifdef go32v2}
  953. reload_fs;
  954. {$endif go32v2}
  955. curr_gdb^.UserScreen;
  956. end;
  957. procedure annotate_stopped;cdecl;public;
  958. var
  959. sym : symtab_and_line;
  960. fname : pchar;
  961. begin
  962. {$ifdef Debug}
  963. Debug('|stopped|');
  964. {$endif}
  965. with curr_gdb^ do
  966. begin
  967. {$ifdef go32v2}
  968. reload_fs;
  969. {$endif go32v2}
  970. DebuggerScreen;
  971. Debuggee_started:=inferior_pid<>0;
  972. if not Debuggee_started then exit;
  973. if reset_command then exit;
  974. sym:=find_pc_line(stop_pc,0);
  975. if assigned(sym.symtab) then
  976. fname:=sym.symtab^.filename
  977. else
  978. fname:=nil;
  979. SelectSourceLine(fname,sym.line);
  980. end;
  981. end;
  982. procedure proc_remove_foreign(pid:longint);cdecl;public;
  983. begin
  984. end;
  985. procedure breakpoints_changed;cdecl;public;
  986. begin
  987. {$ifdef Debug}
  988. Debug('|breakpoints_changed|');
  989. {$endif}
  990. end;
  991. procedure annotate_breakpoint(num:longint);cdecl;public;
  992. begin
  993. {$ifdef Debug}
  994. Debug('|breakpoint(%d)|');
  995. {$endif}
  996. With Curr_gdb^ do
  997. stop_breakpoint_number:=num;
  998. end;
  999. procedure annotate_watchpoint(num:longint);cdecl;public;
  1000. begin
  1001. {$ifdef Debug}
  1002. Debug('|watchpoint(%d)|');
  1003. {$endif}
  1004. With Curr_gdb^ do
  1005. stop_breakpoint_number:=num;
  1006. end;
  1007. procedure annotate_catchpoint(num:longint);cdecl;public;
  1008. begin
  1009. {$ifdef Debug}
  1010. Debug('|catchpoint(%d)|');
  1011. {$endif}
  1012. With Curr_gdb^ do
  1013. stop_breakpoint_number:=num;
  1014. end;
  1015. procedure annotate_breakpoints_headers;cdecl;public;
  1016. begin
  1017. {$ifdef Debug}
  1018. Debug('|breakpoints_headers|');
  1019. {$endif}
  1020. end;
  1021. procedure annotate_breakpoints_table;cdecl;public;
  1022. begin
  1023. {$ifdef Debug}
  1024. Debug('|breakpoints_table|');
  1025. {$endif}
  1026. end;
  1027. procedure annotate_record;cdecl;public;
  1028. begin
  1029. {$ifdef Debug}
  1030. Debug('|record|');
  1031. {$endif}
  1032. end;
  1033. procedure annotate_breakpoints_table_end;cdecl;public;
  1034. begin
  1035. {$ifdef Debug}
  1036. Debug('|breakpoints_table_end|');
  1037. {$endif}
  1038. end;
  1039. procedure annotate_frames_invalid;cdecl;public;
  1040. begin
  1041. {$ifdef Debug}
  1042. Debug('|frames_invalid|');
  1043. {$endif}
  1044. end;
  1045. procedure annotate_frame_begin(level:longint;pc:CORE_ADDR);cdecl;public;
  1046. begin
  1047. {$ifdef Debug}
  1048. Debug('|frame_begin(%d,%ld)|');
  1049. {$endif}
  1050. with curr_gdb^ do
  1051. begin
  1052. frame_begin_seen:=true;
  1053. frame_level:=level;
  1054. current_address:=pc;
  1055. current_line_number:=-1;
  1056. function_start:=-1;
  1057. function_end:=-1;
  1058. args_start:=-1;
  1059. args_end:=-1;
  1060. file_start:=-1;
  1061. file_end:=-1;
  1062. line_start:=-1;
  1063. line_end:=-1;
  1064. end;
  1065. end;
  1066. procedure annotate_frame_address;cdecl;public;
  1067. begin
  1068. {$ifdef Debug}
  1069. Debug('|frame_address|');
  1070. {$endif}
  1071. end;
  1072. procedure annotate_frame_address_end;cdecl;public;
  1073. begin
  1074. {$ifdef Debug}
  1075. Debug('|frame_address_end|');
  1076. {$endif}
  1077. end;
  1078. procedure annotate_frame_function_name;cdecl;public;
  1079. begin
  1080. {$ifdef Debug}
  1081. Debug('|frame_function_name|');
  1082. {$endif}
  1083. with curr_gdb^ do
  1084. function_start:=gdboutputbuf.idx;
  1085. end;
  1086. procedure annotate_frame_args;cdecl;public;
  1087. begin
  1088. {$ifdef Debug}
  1089. Debug('|frame_args|');
  1090. {$endif}
  1091. with curr_gdb^ do
  1092. begin
  1093. function_end:=gdboutputbuf.idx;
  1094. args_start:=gdboutputbuf.idx;
  1095. end;
  1096. end;
  1097. procedure annotate_frame_source_begin;cdecl;public;
  1098. begin
  1099. {$ifdef Debug}
  1100. Debug('|frame_source_begin|');
  1101. {$endif}
  1102. with curr_gdb^ do
  1103. args_end:=gdboutputbuf.idx;
  1104. end;
  1105. procedure annotate_frame_source_file;cdecl;public;
  1106. begin
  1107. {$ifdef Debug}
  1108. Debug('|frame_source_file|');
  1109. {$endif}
  1110. with curr_gdb^ do
  1111. file_start:=gdboutputbuf.idx;
  1112. end;
  1113. procedure annotate_frame_source_file_end;cdecl;public;
  1114. begin
  1115. {$ifdef Debug}
  1116. Debug('|frame_source_file_end|');
  1117. {$endif}
  1118. with curr_gdb^ do
  1119. file_end:=gdboutputbuf.idx;
  1120. end;
  1121. procedure annotate_frame_source_line;cdecl;public;
  1122. begin
  1123. {$ifdef Debug}
  1124. Debug('|frame_source_line|');
  1125. {$endif}
  1126. with curr_gdb^ do
  1127. line_start:=gdboutputbuf.idx;
  1128. end;
  1129. procedure annotate_frame_source_end;cdecl;public;
  1130. begin
  1131. {$ifdef Debug}
  1132. Debug('|frame_source_end|');
  1133. {$endif}
  1134. with curr_gdb^ do
  1135. line_end:=gdboutputbuf.idx;
  1136. end;
  1137. procedure annotate_frame_where;cdecl;public;
  1138. begin
  1139. {$ifdef Debug}
  1140. Debug('|frame_where|');
  1141. {$endif}
  1142. end;
  1143. procedure annotate_frame_end;cdecl;public;
  1144. var
  1145. fe : pframeentry;
  1146. c : char;
  1147. err : integer;
  1148. begin
  1149. {$ifdef Debug}
  1150. Debug('|frame_end|');
  1151. {$endif}
  1152. with curr_gdb^ do
  1153. begin
  1154. if (not record_frames) or (not frame_begin_seen) then
  1155. exit;
  1156. { This can happen, when the function has no Debugging information }
  1157. if (args_start >= 0) and (args_end < 0) then
  1158. args_end:=gdboutputbuf.idx;
  1159. frame_begin_seen:=false;
  1160. fe:=get_frameentry(frame_level);
  1161. fe^.address:=current_address;
  1162. fe^.level:=frame_level;
  1163. if (function_start>=0) then
  1164. begin
  1165. c:=gdboutputbuf.buf[function_end];
  1166. gdboutputbuf.buf[function_end]:=#0;
  1167. fe^.function_name:=strnew(gdboutputbuf.buf+function_start);
  1168. gdboutputbuf.buf[function_end]:=c;
  1169. end;
  1170. if (file_start>=0) then
  1171. begin
  1172. c:=gdboutputbuf.buf[file_end];
  1173. gdboutputbuf.buf[file_end]:=#0;
  1174. fe^.file_name:=strnew(gdboutputbuf.buf+file_start);
  1175. gdboutputbuf.buf[file_end]:=c;
  1176. end;
  1177. if (args_start>=0) then
  1178. begin
  1179. if (gdboutputbuf.buf[args_end-1]=#10) then
  1180. dec(args_end);
  1181. c:=gdboutputbuf.buf[args_end];
  1182. gdboutputbuf.buf[args_end]:=#0;
  1183. fe^.args:=strnew(gdboutputbuf.buf+args_start);
  1184. gdboutputbuf.buf[args_end]:=c;
  1185. end;
  1186. if (line_start>=0) then
  1187. begin
  1188. c:=gdboutputbuf.buf[line_end];
  1189. gdboutputbuf.buf[line_end]:=#0;
  1190. { sscanf(gdb_output_buffer+line_start,'%d',&fe^.line_number); }
  1191. val(strpas(pchar(@gdboutputbuf.buf[line_start])),fe^.line_number,err);
  1192. gdboutputbuf.buf[line_end]:=c;
  1193. end;
  1194. end;
  1195. end;
  1196. procedure annotate_quit;cdecl;public;
  1197. begin
  1198. {$ifdef Debug}
  1199. Debug('|quit|');
  1200. {$endif}
  1201. end;
  1202. procedure annotate_arg_begin;cdecl;public;
  1203. begin
  1204. {$ifdef Debug}
  1205. Debug('|arg_begin|');
  1206. {$endif}
  1207. end;
  1208. procedure annotate_arg_name_end;cdecl;public;
  1209. begin
  1210. {$ifdef Debug}
  1211. Debug('|arg_name_end|');
  1212. {$endif}
  1213. end;
  1214. procedure annotate_arg_value(typ:pointer);cdecl;public;
  1215. begin
  1216. {$ifdef Debug}
  1217. Debug('|arg_value|');
  1218. {$endif}
  1219. end;
  1220. procedure annotate_arg_end;cdecl;public;
  1221. begin
  1222. {$ifdef Debug}
  1223. Debug('|arg_end|');
  1224. {$endif}
  1225. end;
  1226. procedure annotate_source(filename:pchar;line,character,mid:longint;pc:CORE_ADDR);cdecl;public;
  1227. begin
  1228. {$ifdef Debug}
  1229. Debug('|source|');
  1230. {$endif}
  1231. end;
  1232. procedure annotate_function_call;cdecl;public;
  1233. begin
  1234. {$ifdef Debug}
  1235. Debug('|function_call|');
  1236. {$endif}
  1237. end;
  1238. procedure annotate_signal_handler_caller;cdecl;public;
  1239. begin
  1240. {$ifdef Debug}
  1241. Debug('|signal_handler_caller|');
  1242. {$endif}
  1243. end;
  1244. procedure annotate_array_section_begin(index:longint;elttype:pointer);cdecl;public;
  1245. begin
  1246. {$ifdef Debug}
  1247. Debug('|array_section_begin()|');
  1248. {$endif}
  1249. end;
  1250. procedure annotate_elt_rep(repcount:longint);cdecl;public;
  1251. begin
  1252. {$ifdef Debug}
  1253. Debug('|elt_rep()|');
  1254. {$endif}
  1255. end;
  1256. procedure annotate_elt_rep_end;cdecl;public;
  1257. begin
  1258. {$ifdef Debug}
  1259. Debug('|elt_rep_end|');
  1260. {$endif}
  1261. end;
  1262. procedure annotate_elt;cdecl;public;
  1263. begin
  1264. {$ifdef Debug}
  1265. Debug('|elt|');
  1266. {$endif}
  1267. end;
  1268. procedure annotate_array_section_end;cdecl;public;
  1269. begin
  1270. {$ifdef Debug}
  1271. Debug('|array_section_end|');
  1272. {$endif}
  1273. end;
  1274. procedure annotate_display_begin;cdecl;public;
  1275. begin
  1276. {$ifdef Debug}
  1277. Debug('|display_begin|');
  1278. {$endif}
  1279. end;
  1280. procedure annotate_display_number_end;cdecl;public;
  1281. begin
  1282. {$ifdef Debug}
  1283. Debug('|display_number_end|');
  1284. {$endif}
  1285. end;
  1286. procedure annotate_display_format;cdecl;public;
  1287. begin
  1288. {$ifdef Debug}
  1289. Debug('|display_format|');
  1290. {$endif}
  1291. end;
  1292. procedure annotate_display_expression;cdecl;public;
  1293. begin
  1294. {$ifdef Debug}
  1295. Debug('|display_expression|');
  1296. {$endif}
  1297. end;
  1298. procedure annotate_display_expression_end;cdecl;public;
  1299. begin
  1300. {$ifdef Debug}
  1301. Debug('|display_expression_end|');
  1302. {$endif}
  1303. end;
  1304. procedure annotate_display_value;cdecl;public;
  1305. begin
  1306. {$ifdef Debug}
  1307. Debug('|display_value|');
  1308. {$endif}
  1309. end;
  1310. procedure annotate_display_end;cdecl;public;
  1311. begin
  1312. {$ifdef Debug}
  1313. Debug('|display_end|');
  1314. {$endif}
  1315. end;
  1316. procedure annotate_field (num:longint);cdecl;public;
  1317. begin
  1318. {$ifdef Debug}
  1319. Debug('a_field(%d)');
  1320. {$endif}
  1321. end;
  1322. procedure annotate_field_begin(typ:pointer);cdecl;public;
  1323. begin
  1324. {$ifdef Debug}
  1325. Debug('a_field_begin\n');
  1326. {$endif}
  1327. end;
  1328. procedure annotate_field_name_end;cdecl;public;
  1329. begin
  1330. {$ifdef Debug}
  1331. Debug('a_field_name_end\n');
  1332. {$endif}
  1333. end;
  1334. procedure annotate_field_value;cdecl;public;
  1335. begin
  1336. {$ifdef Debug}
  1337. Debug('a_field_value\n');
  1338. {$endif}
  1339. end;
  1340. procedure annotate_field_end;cdecl;public;
  1341. begin
  1342. {$ifdef Debug}
  1343. Debug('a_field_end\n');
  1344. {$endif}
  1345. end;
  1346. procedure annotate_value_history_begin (histindex:longint;typ:pointer);cdecl;public;
  1347. begin
  1348. {$ifdef Debug}
  1349. Debug('a_value_history_begin(%d)\n');
  1350. {$endif}
  1351. end;
  1352. procedure annotate_value_begin (typ:pointer);cdecl;public;
  1353. begin
  1354. {$ifdef Debug}
  1355. Debug('a_value_begin\n');
  1356. {$endif}
  1357. end;
  1358. procedure annotate_value_history_value;cdecl;public;
  1359. begin
  1360. {$ifdef Debug}
  1361. Debug('a_value_history_value\n');
  1362. {$endif}
  1363. end;
  1364. procedure annotate_value_history_end;cdecl;public;
  1365. begin
  1366. {$ifdef Debug}
  1367. Debug('a_value_history_end\n');
  1368. {$endif}
  1369. end;
  1370. procedure annotate_value_end;cdecl;public;
  1371. begin
  1372. {$ifdef Debug}
  1373. Debug('a_value_end\n');
  1374. {$endif}
  1375. end;
  1376. procedure _initialize_annotate;cdecl;public;
  1377. begin
  1378. end;
  1379. procedure fputs_unfiltered(linebuffer:pchar;stream:pointer);cdecl;public;
  1380. begin
  1381. with curr_gdb^ do
  1382. {$ifndef gdb_v416}
  1383. if stream = gdb_stderr then
  1384. gdberrorbuf.append(linebuffer)
  1385. else
  1386. {$endif not gdb_v416}
  1387. gdboutputbuf.append(linebuffer);
  1388. end;
  1389. procedure CreateBreakPointHook(var b:breakpoint);cdecl;
  1390. var
  1391. sym : symtab_and_line;
  1392. begin
  1393. sym:=find_pc_line(b.address,0);
  1394. with curr_gdb^ do
  1395. begin
  1396. last_breakpoint_number:=b.number;
  1397. { function breakpoints have zero as file and as line !!
  1398. but they are valid !! }
  1399. invalid_breakpoint_line:=(b.line_number<>sym.line) and (b.line_number<>0);
  1400. last_breakpoint_address:=b.address;
  1401. last_breakpoint_line:=sym.line;
  1402. if assigned(sym.symtab) then
  1403. last_breakpoint_file:=sym.symtab^.filename
  1404. else
  1405. last_breakpoint_file:=nil;
  1406. end;
  1407. end;
  1408. {*****************************************************************************
  1409. tgdbinterface
  1410. *****************************************************************************}
  1411. constructor tgdbinterface.init;
  1412. begin
  1413. gdboutputbuf.init;
  1414. gdberrorbuf.init;
  1415. record_frames:=true;
  1416. {$ifndef GDB_V416}
  1417. (* GDB_FILE *
  1418. gdb_file_init_astring (n)
  1419. int n;
  1420. should we use xmalloc ?
  1421. gdb could resize the buffer => crash,
  1422. but normally it should not if unfiltered !! PM *)
  1423. gdb_stdout^.ts_streamtype := astring;
  1424. gdb_stdout^.ts_strbuf := gdboutputbuf.buf;
  1425. gdb_stdout^.ts_buflen := gdboutputbuf.size;
  1426. gdboutputbuf.link:=gdb_stdout;
  1427. gdb_stderr^.ts_streamtype := astring;
  1428. gdb_stderr^.ts_strbuf := gdberrorbuf.buf;
  1429. gdb_stderr^.ts_buflen := gdberrorbuf.size;
  1430. gdberrorbuf.link:=gdb_stderr;
  1431. {$endif not GDB_V416}
  1432. gdb__init;
  1433. curr_gdb:=@self;
  1434. command_level:=0;
  1435. { set output mode for GDB }
  1436. { only these values disable filtering
  1437. DONT CHANGE THEM !!! PM }
  1438. gdb_command('set width 0xffffffff');
  1439. gdb_command('set height 0xffffffff');
  1440. { other standard commands used for fpc debugging }
  1441. gdb_command('set print demangle off');
  1442. gdb_command('set gnutarget auto');
  1443. gdb_command('set language auto');
  1444. gdb_command('set print vtbl on');
  1445. gdb_command('set print object on');
  1446. gdb_command('set print null-stop');
  1447. end;
  1448. destructor tgdbinterface.done;
  1449. begin
  1450. clear_frames;
  1451. gdb_done;
  1452. gdboutputbuf.done;
  1453. gdberrorbuf.done;
  1454. end;
  1455. procedure tgdbinterface.gdb__init;
  1456. begin
  1457. gdboutputbuf.reset;
  1458. gdberrorbuf.reset;
  1459. create_breakpoint_hook:=@CreateBreakPointHook;
  1460. end;
  1461. procedure tgdbinterface.gdb_done;
  1462. begin
  1463. if debuggee_started then
  1464. begin
  1465. current_target.to_kill;
  1466. current_target.to_close(1);
  1467. end;
  1468. create_breakpoint_hook:=nil;
  1469. end;
  1470. function tgdbinterface.error:boolean;
  1471. begin
  1472. error:=got_error;
  1473. end;
  1474. function tgdbinterface.error_num:longint;
  1475. begin
  1476. error_num:=gdb_error;
  1477. end;
  1478. var
  1479. top_level_val : longint;
  1480. procedure tgdbinterface.gdb_command(const s:string);
  1481. var
  1482. command : array[0..256] of char;
  1483. s2 : string;
  1484. old_quit_return,
  1485. old_error_return : jmp_buf;
  1486. begin
  1487. inc(command_level);
  1488. move(s[1],command,length(s));
  1489. command[length(s)]:=#0;
  1490. old_quit_return:=quit_return;
  1491. old_error_return:=error_return;
  1492. gdb_error:=0;
  1493. got_error:=false;
  1494. stop_breakpoint_number:=0;
  1495. { Trap quit commands }
  1496. s2:=s;
  1497. while (length(s2)>0) and ((s2[1]=' ') or (s2[1]=#9)) do
  1498. s2:=copy(s2,2,255);
  1499. if (length(s2)>0) and
  1500. (UpCase(s2[1])='Q') and
  1501. ((length(s2)=1) or
  1502. (s2[2]=' ') or
  1503. ((UpCase(s2[2])='U') and
  1504. ((length(s2)=2) or
  1505. (s2[3]=' ') or
  1506. ((UpCase(s2[3])='I') and
  1507. ((length(s2)=3) or
  1508. (s2[4]=' ') or
  1509. ((UpCase(s2[4])='T') and
  1510. ((length(s2)=4) or
  1511. (s2[5]=' ')
  1512. ))))))) then
  1513. begin
  1514. if not AllowQuit then
  1515. exit;
  1516. end;
  1517. {$ifdef DebugCommand}
  1518. Debug('start of handle_gdb_command ('+s+')');
  1519. {$endif}
  1520. top_level_val:=setjmp(error_return);
  1521. if top_level_val=0 then
  1522. begin
  1523. quit_return:=error_return;
  1524. execute_command(@command,0);
  1525. {$ifdef go32v2}
  1526. reload_fs;
  1527. {$endif go32v2}
  1528. end
  1529. else
  1530. {$ifdef Debug}
  1531. Debug('error longjmp in handle_gdb_command ('+s+')');
  1532. {$endif}
  1533. ;
  1534. {$ifdef DebugCommand}
  1535. Debug('end of handle_gdb_command ('+s+')');
  1536. {$endif}
  1537. quit_return:=old_quit_return;
  1538. error_return:=old_error_return;
  1539. dec(command_level);
  1540. end;
  1541. procedure tgdbinterface.resize_frames;
  1542. var
  1543. i : longint;
  1544. new_frames : ppframeentry;
  1545. begin
  1546. if (frame_count>=frame_size) then
  1547. begin
  1548. getmem(new_frames,sizeof(pointer)*(frame_count+1));
  1549. for i:=0 to frame_size-1 do
  1550. new_frames[i]:=frames[i];
  1551. if assigned(frames) then
  1552. freemem(frames,sizeof(pointer)*frame_size);
  1553. frames:=new_frames;
  1554. frame_size:=frame_count+1;
  1555. for i:=frame_count to frame_size-1 do
  1556. frames[i]:=new(pframeentry,init);
  1557. end;
  1558. end;
  1559. function tgdbinterface.add_frameentry:pframeentry;
  1560. begin
  1561. resize_frames;
  1562. add_frameentry:=frames[frame_count];
  1563. inc(frame_count);
  1564. end;
  1565. function tgdbinterface.get_frameentry(level : longint) : pframeentry;
  1566. begin
  1567. { only climb values one by one PM }
  1568. if level>=frame_count then
  1569. resize_frames;
  1570. get_frameentry:=frames[level];
  1571. frames[level]^.clear;
  1572. if level>=frame_count then
  1573. inc(frame_count);
  1574. end;
  1575. procedure tgdbinterface.clear_frames;
  1576. var
  1577. i : longint;
  1578. begin
  1579. for i:=0 to frame_size-1 do
  1580. dispose(frames[i],done);
  1581. freemem(frames,sizeof(pointer)*Frame_size);
  1582. frame_count:=0;
  1583. frame_size:=0;
  1584. end;
  1585. function tgdbinterface.get_current_frame : longint;
  1586. begin
  1587. record_frames:=false;
  1588. gdb_command('f');
  1589. get_current_frame:=frame_level;
  1590. record_frames:=true;
  1591. end;
  1592. function tgdbinterface.set_current_frame(level : longint) : boolean;
  1593. var
  1594. s : string;
  1595. begin
  1596. record_frames:=false;
  1597. str(level,s);
  1598. gdb_command('f '+s);
  1599. if level=frame_level then
  1600. set_current_frame:=true
  1601. else
  1602. set_current_frame:=false;
  1603. record_frames:=true;
  1604. end;
  1605. {*****************************************************************************
  1606. Highlevel tgdbinterface
  1607. *****************************************************************************}
  1608. procedure tgdbinterface.GetAddrSyminfo(addr:longint;var si:tsyminfo);
  1609. var
  1610. sym : symtab_and_line;
  1611. symbol : psymbol;
  1612. begin
  1613. sym:=find_pc_line(addr,1);
  1614. fillchar(si,sizeof(tsyminfo),0);
  1615. si.address:=addr;
  1616. si.offset:=addr-sym.pc;
  1617. if assigned(sym.symtab) then
  1618. si.fname:=sym.symtab^.filename
  1619. else
  1620. si.fname:=nil;
  1621. si.line:=sym.line;
  1622. symbol:=find_pc_function(addr);
  1623. if assigned(symbol) then
  1624. si.funcname:=symbol^.ginfo._name
  1625. else
  1626. si.funcname:=nil;
  1627. end;
  1628. procedure tgdbinterface.SelectSourceLine(fn:pchar;line:longint);
  1629. begin
  1630. if assigned(fn) then
  1631. DoSelectSourceLine(StrPas(fn),line)
  1632. else
  1633. DoSelectSourceLine('',line);
  1634. end;
  1635. procedure tgdbinterface.StartSession;
  1636. begin
  1637. DoStartSession;
  1638. end;
  1639. procedure tgdbinterface.BreakSession;
  1640. begin
  1641. DoBreakSession;
  1642. end;
  1643. procedure tgdbinterface.EndSession(code:longint);
  1644. begin
  1645. Debuggee_started:=false;
  1646. {$ifdef Go32v2}
  1647. inferior_pid:=0;
  1648. {$endif}
  1649. DoEndSession(code);
  1650. end;
  1651. procedure tgdbinterface.DebuggerScreen;
  1652. begin
  1653. {$ifdef Debug}
  1654. Debug('|DebuggerScreen|');
  1655. {$endif}
  1656. if user_screen_shown then
  1657. DoDebuggerScreen;
  1658. user_screen_shown:=false;
  1659. end;
  1660. procedure tgdbinterface.UserScreen;
  1661. begin
  1662. {$ifdef Debug}
  1663. Debug('|UserScreen|');
  1664. {$endif}
  1665. if switch_to_user then
  1666. begin
  1667. if (not user_screen_shown) then
  1668. DoUserScreen;
  1669. user_screen_shown:=true;
  1670. end;
  1671. end;
  1672. {---------------------------------------
  1673. Default Hooks
  1674. ---------------------------------------}
  1675. procedure tgdbinterface.DoSelectSourceLine(const fn:string;line:longint);
  1676. {$ifdef Debug}
  1677. var
  1678. s : string;
  1679. {$endif}
  1680. begin
  1681. {$ifdef Debug}
  1682. Str(line,S);
  1683. Debug('|SelectSource '+fn+':'+s+'|');
  1684. {$endif}
  1685. end;
  1686. procedure tgdbinterface.DoStartSession;
  1687. begin
  1688. end;
  1689. procedure tgdbinterface.DoBreakSession;
  1690. begin
  1691. end;
  1692. procedure tgdbinterface.DoEndSession(code:longint);
  1693. begin
  1694. end;
  1695. procedure tgdbinterface.DoDebuggerScreen;
  1696. begin
  1697. end;
  1698. procedure tgdbinterface.DoUserScreen;
  1699. begin
  1700. end;
  1701. function tgdbinterface.AllowQuit : boolean;
  1702. begin
  1703. AllowQuit:=true;
  1704. end;
  1705. var
  1706. version : pchar;cvar;
  1707. function GDBVersion : string;
  1708. begin
  1709. GDBVersion:='GDB '+StrPas(version);
  1710. end;
  1711. const next_exit : pointer = nil;
  1712. procedure DoneLibGDB;
  1713. begin
  1714. exitproc:=next_exit;
  1715. {$ifndef GDB_V416}
  1716. if assigned(gdb_stdout) then
  1717. dispose(gdb_stdout);
  1718. gdb_stdout:=nil;
  1719. if assigned(gdb_stderr) then
  1720. dispose(gdb_stderr);
  1721. gdb_stderr:=nil;
  1722. {$endif not GDB_V416}
  1723. end;
  1724. {$ifndef GDB_V416}
  1725. {$ifndef go32v2}
  1726. {$ifndef win32}
  1727. var
  1728. stdout : p_c_file;cvar;external;
  1729. stderr : p_c_file;cvar;external;
  1730. {$endif win32}
  1731. {$else go32v2}
  1732. { the type is not really important
  1733. for external cvars PM
  1734. but the main problem is that stdout and stderr
  1735. and defined as macros under DJGPP !! }
  1736. var
  1737. __dj_stdout : c_file;cvar;external;
  1738. __dj_stderr : c_file;cvar;external;
  1739. {$endif go32v2}
  1740. {$endif not GDB_V416}
  1741. procedure InitLibGDB;
  1742. {$ifdef supportexceptions}
  1743. var
  1744. OldSigInt : SignalHandler;
  1745. {$endif supportexceptions}
  1746. begin
  1747. {$ifdef supportexceptions}
  1748. {$ifdef go32v2}
  1749. OldSigInt:=Signal(SIGINT,SignalHandler(@SIG_DFL));
  1750. {$else}
  1751. OldSigInt:=Signal(SIGINT,SignalHandler(SIG_DFL));
  1752. {$endif}
  1753. {$endif supportexceptions}
  1754. {$ifndef GDB_V416}
  1755. new(gdb_stdout);
  1756. gdb_stdout^.ts_streamtype := afile;
  1757. {$ifndef go32v2}
  1758. {$ifdef win32}
  1759. gdb_stdout^.ts_filestream := _impure_ptr^.stdout;
  1760. {$else not win32 }
  1761. gdb_stdout^.ts_filestream := stdout;{p_c_file(textrec(output).handle); was wrong PM }
  1762. {$endif not win32 }
  1763. {$else go32v2}
  1764. gdb_stdout^.ts_filestream := @__dj_stdout;
  1765. {$endif go32v2}
  1766. gdb_stdout^.ts_strbuf := nil;
  1767. gdb_stdout^.ts_buflen := 0;
  1768. new(gdb_stderr);
  1769. gdb_stderr^.ts_streamtype := afile;
  1770. {$ifndef go32v2}
  1771. {$ifdef win32}
  1772. gdb_stderr^.ts_filestream := _impure_ptr^.stderr;
  1773. {$else not win32 }
  1774. gdb_stderr^.ts_filestream := stderr;
  1775. {$endif not win32 }
  1776. {$else go32v2}
  1777. gdb_stderr^.ts_filestream := @__dj_stderr;
  1778. {$endif go32v2}
  1779. gdb_stderr^.ts_strbuf := nil;
  1780. gdb_stderr^.ts_buflen := 0;
  1781. {$endif not GDB_V416}
  1782. next_exit:=exitproc;
  1783. exitproc:=@DoneLibGDB;
  1784. gdb_init;
  1785. {$ifdef supportexceptions}
  1786. Signal(SIGINT,OldSigInt);
  1787. {$endif supportexceptions}
  1788. if setjmp(error_return)=0 then
  1789. begin
  1790. quit_return:=error_return;
  1791. exit;
  1792. end
  1793. else
  1794. begin
  1795. {$ifdef Debug}
  1796. Debug('|LongJump to Init|');
  1797. {$endif}
  1798. {$ifdef go32v2}
  1799. RunError(99);
  1800. {$endif def go32v2}
  1801. end;
  1802. WatchDog:=0;
  1803. end;
  1804. begin
  1805. InitLibGDB;
  1806. end.
  1807. {
  1808. $Log$
  1809. Revision 1.7 2000-07-11 08:12:18 pierre
  1810. * avoid smartlinking
  1811. Revision 1.6 2000/04/14 05:37:33 pierre
  1812. * call DoSelectSourceLine even if fn is empty
  1813. Revision 1.5 2000/03/07 10:39:59 pierre
  1814. + inferior_pid moved to interface
  1815. Revision 1.4 2000/02/06 22:32:45 pierre
  1816. + Get_current_frame and Set_current_frame
  1817. Revision 1.3 2000/01/10 11:14:42 peter
  1818. * fixed crash in getaddrsyminfo with symfync=nil
  1819. Revision 1.2 1999/11/26 14:50:40 pierre
  1820. * shell32 lib is not needed in gdbint unit
  1821. Revision 1.1 1999/11/24 23:36:32 peter
  1822. * moved to packages dir
  1823. Revision 1.16 1999/11/09 22:58:08 pierre
  1824. + symbol structure for function name
  1825. Revision 1.15 1999/11/03 09:35:06 peter
  1826. * linux updates
  1827. Revision 1.14 1999/10/08 15:22:53 pierre
  1828. * library order fixes
  1829. + GDB 4.18 default now
  1830. Revision 1.13 1999/10/04 21:26:05 pierre
  1831. * Conditional stuff clarified
  1832. Revision 1.12 1999/09/28 23:42:06 pierre
  1833. + win32 support changes
  1834. Revision 1.11 1999/09/07 09:17:52 pierre
  1835. * frames better recorded
  1836. * some v4.18 specific suff changed
  1837. Revision 1.10 1999/08/31 16:16:14 pierre
  1838. * setting height and width to unlimited was wrong
  1839. Revision 1.9 1999/08/24 21:29:29 pierre
  1840. + reload_fs after C code calling
  1841. Revision 1.8 1999/08/23 09:17:22 pierre
  1842. + Errors to gdberrorbuf
  1843. Revision 1.7 1999/07/12 14:52:57 peter
  1844. * ifdef 418 added
  1845. Revision 1.6 1999/07/12 13:08:18 pierre
  1846. + added GDBVersion function
  1847. * tries to intercept quit command from GDB Window
  1848. + AllowQuit method
  1849. Revision 1.5 1999/07/11 00:16:29 pierre
  1850. + stuff for v4.18 for DJGPP
  1851. Revision 1.4 1999/07/07 13:12:59 peter
  1852. * @sig_fdl for go32v2
  1853. Revision 1.3 1999/07/05 13:05:49 michael
  1854. + Fixed default handler
  1855. Revision 1.2 1999/06/29 12:18:34 pierre
  1856. * new procvar syntax fix
  1857. Revision 1.1 1999/05/22 13:43:00 peter
  1858. * moved
  1859. Revision 1.16 1999/02/11 13:03:26 pierre
  1860. Problem with last commit
  1861. + added virtuals CommandBegin and CommandEnd
  1862. + added command_level for TGDBInterface
  1863. Revision 1.15 1999/02/10 09:00:41 pierre
  1864. * duplicate call_reset removed
  1865. * frames allocation and freeing corrected
  1866. + GetError and GetOutput pchar function added
  1867. + stop_breakpoint_number to know why the program stopped
  1868. (used for watches)
  1869. Revision 1.14 1999/02/08 17:35:08 pierre
  1870. + added Run made TraceStep TraceNext Continue virtual
  1871. Revision 1.13 1999/02/08 13:59:59 pierre
  1872. - removed second debugger_started in TGDBController
  1873. + StartTrace and Reset made virtual to be able to
  1874. change CmResetDebugger state in IDE
  1875. Revision 1.12 1999/02/08 11:37:11 pierre
  1876. + added procargs var and SetArgs method
  1877. Revision 1.11 1999/02/05 17:17:45 pierre
  1878. * invalid_line renamed invalid_breakpoint_line
  1879. Revision 1.10 1999/02/05 08:35:38 pierre
  1880. * removed libgdb for cond USE_GDB_OBJS
  1881. Revision 1.9 1999/02/04 16:33:35 pierre
  1882. + gdb_file and use_gdb_file added for debug writing
  1883. Revision 1.8 1999/02/04 14:35:00 pierre
  1884. * small go32v2 fixes
  1885. Revision 1.7 1999/02/03 15:57:38 pierre
  1886. * typo error
  1887. Revision 1.6 1999/02/03 15:03:07 pierre
  1888. + added error_num function
  1889. Revision 1.5 1999/02/03 15:01:00 pierre
  1890. * a symtab_and_line record changes from v4.16 to v4.17
  1891. Revision 1.4 1999/01/22 18:05:41 pierre
  1892. * change dir sep from to / for dos
  1893. Revision 1.3 1999/01/22 10:23:50 peter
  1894. * small update to get it working with the IDE
  1895. Revision 1.2 1999/01/18 11:00:34 pierre
  1896. * frames was not initialized
  1897. Revision 1.1 1998/10/07 15:57:38 peter
  1898. * initial version
  1899. Revision 1.1 1998/10/07 15:48:20 peter
  1900. * initial version
  1901. }