gdbint.pp 64 KB

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