gdbint.pp 62 KB

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