gdbint.pp 68 KB

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