gdbint.pp 60 KB

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