gdbint.pp 63 KB

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