gdbint.pp 62 KB

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