gdbint.pp 97 KB

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