gdbint.pp 88 KB

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