gdbint.pp 96 KB

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