gdbint.pp 62 KB

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