gdbint.pp 60 KB

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