gdbint.pp 60 KB

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