gdbint.pp 62 KB

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