gdbint.pp 76 KB

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