gdbint.pp 62 KB

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