gdbint.pp 62 KB

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