gdbint.pp 60 KB

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