gdbint.pp 62 KB

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