gdbint.pp 74 KB

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