gdbint.pp 62 KB

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