gdbint.pp 63 KB

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