gdbint.pp 61 KB

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