gdbint.pp 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399
  1. {
  2. $Id$
  3. Copyright (c) 1998 by Peter Vreman
  4. Lowlevel GDB interface which communicates directly with libgdb
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit GdbInt;
  12. interface
  13. {$smartlink off}
  14. { this is not needed (PM) $output_format as}
  15. {.$define Debug}
  16. {.$define DebugCommand}
  17. {$define NotImplemented}
  18. { V4.18 is default for now }
  19. { set when starting v5 support PM }
  20. {$ifndef GDB_V5}
  21. {$ifndef GDB_V416}
  22. {$define GDB_V418}
  23. {$endif GDB_V416}
  24. {$endif GDB_V5}
  25. {$ifdef go32v2}
  26. {$undef NotImplemented}
  27. { ifdef GDB_V418 changed to ifndef GDB_V416}
  28. {$ifdef USE_GDB_OBJS}
  29. {$include gdbobjs.inc}
  30. {$else USE_GDB_OBJS}
  31. {$LINKLIB gdb}
  32. {$ifdef GDB_V5}
  33. {$LINKLIB bfd}
  34. {$LINKLIB readline}
  35. {$LINKLIB opcodes}
  36. {$LINKLIB history}
  37. {$LINKLIB iberty}
  38. {$endif GDB_V5}
  39. {$endif ndef USE_GDB_OBJS}
  40. {$LINKLIB dbg}
  41. {$LINKLIB c}
  42. {$endif go32v2}
  43. {$ifdef linux}
  44. {$undef NotImplemented}
  45. {$ifndef GDB_V5}
  46. {$LINKLIB ncurses}
  47. {$endif not GDB_V5}
  48. {$LINKLIB gdb}
  49. {$ifdef GDB_V5}
  50. {$LINKLIB bfd}
  51. {$LINKLIB intl}
  52. {$LINKLIB readline}
  53. {$LINKLIB opcodes}
  54. {$LINKLIB history}
  55. {$LINKLIB iberty}
  56. {$LINKLIB ncurses}
  57. {$LINKLIB m}
  58. {$LINKLIB intl}
  59. {$LINKLIB iberty}
  60. {$endif GDB_V5}
  61. {$LINKLIB c}
  62. {$LINKLIB gcc}
  63. {$endif linux}
  64. {$ifdef win32}
  65. {$undef NotImplemented}
  66. {$ifndef GDB_V5}
  67. {$LINKLIB cygwin}
  68. {$LINKLIB gdb}
  69. {$ifdef USE_TERMCAP}
  70. {$LINKLIB termcap}
  71. {$else not USE_TERMCAP}
  72. {$LINKLIB ncurses}
  73. {$endif not USE_TERMCAP}
  74. {$LINKLIB gcc}
  75. {$LINKLIB c}
  76. {$LINKLIB cygwin}
  77. { all those are maybe not necessary
  78. but at least user32 is required
  79. because of clipboard handling PM }
  80. {$LINKLIB kernel32}
  81. {$LINKLIB user32}
  82. {$else GDB_V5}
  83. {$LINKLIB gdb}
  84. {$LINKLIB bfd}
  85. {$LINKLIB readline}
  86. {$LINKLIB opcodes}
  87. {$LINKLIB intl}
  88. {$LINKLIB iberty}
  89. {$LINKLIB termcap}
  90. {$LINKLIB gcc}
  91. {$LINKLIB cygwin} { alias of libm.a and libc.a }
  92. {$LINKLIB iberty}
  93. {$LINKLIB imagehlp}
  94. {$LINKLIB kernel32}
  95. {$LINKLIB user32}
  96. {$endif GDB_V5}
  97. {$endif win32}
  98. {$ifdef go32v2}
  99. {$define supportexceptions}
  100. {$endif go32v2}
  101. {$ifdef linux}
  102. {$define supportexceptions}
  103. {$endif linux}
  104. {$ifdef NotImplemented}
  105. {$fatal This OS is not yet supported !!!}
  106. {$endif NotImplemented}
  107. {$packrecords C}
  108. type
  109. psyminfo=^tsyminfo;
  110. tsyminfo=record
  111. address : longint;
  112. fname : pchar;
  113. line : longint;
  114. funcname : pchar;
  115. offset : longint;
  116. end;
  117. tframeentry = object
  118. file_name : pchar;
  119. function_name : pchar;
  120. args : pchar;
  121. line_number : longint;
  122. address : longint;
  123. level : longint;
  124. constructor init;
  125. destructor done;
  126. procedure reset;
  127. procedure clear;
  128. end;
  129. pframeentry=^tframeentry;
  130. ppframeentry=^pframeentry;
  131. {$ifndef GDB_V416}
  132. { needed for handles }
  133. {not anymore I textrec.inc}
  134. type
  135. streamtype = (afile,astring);
  136. C_FILE = longint; { at least under DJGPP }
  137. P_C_FILE = ^C_FILE;
  138. {$ifdef GDB_V418}
  139. { GDB_FILE type }
  140. type
  141. PGDB_FILE = ^TGDB_FILE;
  142. TGDB_FILE = record
  143. ts_streamtype : streamtype;
  144. ts_filestream : P_C_FILE;
  145. ts_strbuf : pchar;
  146. ts_buflen : longint;
  147. end;
  148. {$endif GDB_V418}
  149. {$ifdef GDB_V5}
  150. type
  151. pui_file = ^ui_file;
  152. ui_file_flush_ftype = procedure(stream : pui_file);cdecl;
  153. ui_file_write_ftype = procedure(stream : pui_file;buf : pchar;len : longint);cdecl;
  154. ui_file_fputs_ftype = procedure(buf : pchar; stream : pui_file);cdecl;
  155. ui_file_delete_ftype = procedure(stream : pui_file);cdecl;
  156. ui_file_isatty_ftype = function(stream : pui_file) : longbool;cdecl;
  157. ui_file_rewind_ftype = procedure(stream : pui_file);cdecl;
  158. ui_file_put_method_ftype = procedure(var _object; buffer : pchar;length_buffer : longint);cdecl;
  159. ui_file_put_ftype = procedure(stream : pui_file;method : ui_file_put_method_ftype;var context);cdecl;
  160. plongint = ^longint;
  161. ui_file = record
  162. magic : plongint;
  163. to_flush : ui_file_flush_ftype;
  164. to_write : ui_file_write_ftype;
  165. to_fputs : ui_file_fputs_ftype;
  166. to_delete : ui_file_delete_ftype;
  167. to_isatty : ui_file_isatty_ftype;
  168. to_rewind : ui_file_rewind_ftype;
  169. to_put : ui_file_put_ftype;
  170. to_data : pointer;
  171. end;
  172. { used to delete stdio_ui_file gdb_stdout and gdb_stderr }
  173. procedure ui_file_delete(stream : pui_file);cdecl;external;
  174. { used to recreate gdb_stdout and gdb_stderr as memory streams }
  175. function mem_fileopen : pui_file;cdecl;external;
  176. { used to change the write procvar to ours }
  177. procedure set_ui_file_write(stream : pui_file;write : ui_file_write_ftype);cdecl;external;
  178. {$endif GDB_V5}
  179. {$ifdef win32}
  180. type
  181. { from sys/reent.h
  182. real structure is bigger but only std.. are wanted here PM }
  183. REENT = record
  184. err : longint;
  185. stdin,stdout,stderr : P_C_FILE;
  186. end;
  187. PREENT = ^REENT;
  188. var _impure_ptr : PREENT;cvar;external;
  189. {$endif win32}
  190. {$endif not GDB_V416}
  191. type
  192. tgdbbuffer=object
  193. buf : pchar;
  194. size,
  195. idx : longint;
  196. {$ifdef GDB_V418}
  197. link : pgdb_file;
  198. {$endif not GDB_V418}
  199. {$ifdef GDB_V5}
  200. gdb_file : pui_file;
  201. {$endif not GDB_V5}
  202. constructor Init;
  203. destructor Done;
  204. procedure Reset;
  205. procedure Resize(nsize : longint);
  206. procedure Append(p:pchar);
  207. procedure lappend(p:pchar;len : longint);
  208. end;
  209. pgdbinterface=^tgdbinterface;
  210. tgdbinterface=object
  211. gdberrorbuf,
  212. gdboutputbuf : tgdbbuffer;
  213. got_error,
  214. reset_command,
  215. call_reset,
  216. Debuggee_started : boolean;
  217. { frames and frame info while recording a frame }
  218. frames : ppframeentry;
  219. frame_size,
  220. frame_count : longint;
  221. record_frames,
  222. frame_begin_seen : boolean;
  223. frame_level,
  224. command_level,
  225. stop_breakpoint_number,
  226. current_address,
  227. current_line_number,
  228. signal_start,
  229. signal_end,
  230. error_start,
  231. error_end,
  232. function_start,
  233. function_end,
  234. args_start,
  235. args_end,
  236. file_start,
  237. file_end,
  238. line_start,
  239. line_end : longint;
  240. { breakpoint }
  241. last_breakpoint_number,
  242. last_breakpoint_address,
  243. last_breakpoint_line : longint;
  244. last_breakpoint_file : pchar;
  245. invalid_breakpoint_line : boolean;
  246. { init }
  247. constructor init;
  248. destructor done;
  249. { Lowlevel }
  250. function error:boolean;
  251. function error_num:longint;
  252. procedure gdb_command(const s:string);
  253. procedure gdb__init;
  254. procedure gdb_done;
  255. procedure resize_frames;
  256. function add_frameentry:pframeentry;
  257. function get_frameentry(level : longint):pframeentry;
  258. function get_current_frame : longint;
  259. function set_current_frame(level : longint) : boolean;
  260. procedure clear_frames;
  261. { Highlevel }
  262. user_screen_shown,
  263. switch_to_user : boolean;
  264. procedure GetAddrSyminfo(addr:longint;var si:tsyminfo);
  265. procedure SelectSourceline(fn:pchar;line:longint);
  266. procedure StartSession;
  267. procedure BreakSession;
  268. procedure EndSession(code:longint);
  269. procedure DebuggerScreen;
  270. procedure UserScreen;
  271. { Hooks }
  272. procedure DoSelectSourceline(const fn:string;line:longint);virtual;
  273. procedure DoStartSession;virtual;
  274. procedure DoBreakSession;virtual;
  275. procedure DoEndSession(code:longint);virtual;
  276. procedure DoDebuggerScreen;virtual;
  277. procedure DoUserScreen;virtual;
  278. function AllowQuit : boolean;virtual;
  279. end;
  280. function GDBVersion : string;
  281. var
  282. curr_gdb : pgdbinterface;
  283. const
  284. use_gdb_file : boolean = false;
  285. var
  286. gdb_file : text;
  287. inferior_pid : longint;cvar;external;
  288. {$ifdef go32v2}
  289. { needed to be sure %fs contains the DOS memory selector
  290. used in Mem[] code PM }
  291. procedure reload_fs;
  292. {$endif go32v2}
  293. implementation
  294. uses
  295. {$ifdef win32}
  296. initc,
  297. {$endif win32}
  298. {$ifdef linux}
  299. linux,
  300. {$endif}
  301. {$ifdef go32v2}
  302. go32,
  303. dpmiexcp,
  304. initc,
  305. {$endif}
  306. strings;
  307. {*****************************************************************************
  308. Types used by libgdb.a
  309. *****************************************************************************}
  310. {$ifdef go32v2}
  311. type
  312. jmp_buf = dpmi_jmp_buf;
  313. pjmp_buf = pdpmi_jmp_buf;
  314. function setjmp(var rec : jmp_buf) : longint;cdecl;external;
  315. procedure longjmp(var rec : jmp_buf;return_value : longint);cdecl;external;
  316. procedure reload_fs;assembler;
  317. asm
  318. movw dosmemselector,%ax
  319. movw %ax,%fs
  320. end['EAX'];
  321. {$endif}
  322. {$ifdef win32}
  323. type
  324. jmp_buf = record
  325. case byte of
  326. 0 :
  327. { greatest value found in cygwin machine/setjmp.h for i386 }
  328. (unknown_field : array [1..13] of longint;);
  329. 1 :
  330. (eax,ebx,ecx,edx : longint;
  331. esi,edi,ebp,esp,eip : longint;);
  332. end;
  333. pjmp_buf = ^jmp_buf;
  334. function setjmp(var rec : jmp_buf) : longint;cdecl;external;
  335. procedure longjmp(var rec : jmp_buf;return_value : longint);cdecl;external;
  336. {$ifndef supportexceptions}
  337. type
  338. { I don't think FPC would accept that
  339. the funcvar return type is the funcvar type itself ! PM }
  340. SignalHandler = Procedure(Sig : LongInt);cdecl;
  341. function signal(sig : longint;new_signal : SignalHandler) : SignalHandler;cdecl;external;
  342. {define supportexceptions not yet working }
  343. {$endif now exceptions are supported for win32}
  344. {$endif win32}
  345. type
  346. CORE_ADDR = longint;
  347. pCORE_ADDR = ^CORE_ADDR;
  348. pblock = ^block;
  349. tlanguage = (language_unknown,language_auto,language_c,
  350. language_cplus,language_java,language_chill,
  351. language_fortran,language_m2,language_asm,
  352. language_scm,language_pascal,language_objc);
  353. bptype = (bp_breakpoint,bp_hardware_breakpoint,
  354. bp_until,bp_finish,bp_watchpoint,bp_hardware_watchpoint,
  355. bp_read_watchpoint,bp_access_watchpoint,
  356. bp_longjmp,bp_longjmp_resume,bp_step_resume,
  357. bp_through_sigtramp,bp_watchpoint_scope,
  358. bp_call_dummy,bp_shlib_event);
  359. tenable = (disabled,enabled,shlib_disabled);
  360. bpdisp = (del,del_at_next_stop,disable,donttouch);
  361. {$PACKRECORDS 4}
  362. pbreakpoint = ^breakpoint;
  363. breakpoint = record
  364. next : pbreakpoint;
  365. typ : bptype;
  366. enable : tenable;
  367. disposition : bpdisp;
  368. number : longint;
  369. address : CORE_ADDR;
  370. line_number : longint;
  371. source_file : pchar;
  372. silent : byte;
  373. ignore_count : longint;
  374. shadow_contents : array[0..15] of char;
  375. inserted : char;
  376. duplicate : char;
  377. commands : pointer; {^command_line}
  378. frame : CORE_ADDR;
  379. cond : pointer; {^expression}
  380. addr_string : ^char;
  381. language : tlanguage;
  382. input_radix : longint;
  383. cond_string : ^char;
  384. exp_string : ^char;
  385. exp : pointer; {^expression}
  386. exp_valid_block : pblock; {^block;}
  387. val : pointer; {value_ptr;}
  388. val_chain : pointer; {value_ptr;}
  389. related_breakpoint : pbreakpoint;
  390. watchpoint_frame : CORE_ADDR;
  391. thread : longint;
  392. hit_count : longint;
  393. section : pointer; {^asection}
  394. end;
  395. tfreecode=(free_nothing,free_contents,free_linetable);
  396. psymtab = ^symtab;
  397. symtab = record
  398. next : psymtab;
  399. blockvector : pointer; {^blockvector;}
  400. linetable : pointer; {^linetable;}
  401. block_line_section : longint;
  402. primary : longint;
  403. filename : pchar;
  404. dirname : pchar;
  405. free_code : tfreecode;
  406. free_ptr : pchar;
  407. nlines : longint;
  408. line_charpos : ^longint;
  409. language : tlanguage;
  410. Debugformat : pchar;
  411. version : pchar;
  412. fullname : pchar;
  413. objfile : pointer; {^objfile;}
  414. end;
  415. psymtab_and_line = ^symtab_and_line;
  416. symtab_and_line = record
  417. symtab : psymtab;
  418. {$ifndef GDB_V416}
  419. { v4.16 does not have the section field !! }
  420. section : pointer; {^asection;}
  421. {$endif GDB_V416}
  422. line : longint;
  423. pc : CORE_ADDR;
  424. _end : CORE_ADDR;
  425. end;
  426. symtabs_and_lines = record
  427. sals : ^symtab_and_line;
  428. nelts : longint;
  429. end;
  430. psymbol = ^symbol;
  431. pminimal_symbol = ^minimal_symbol;
  432. general_symbol_info = record
  433. (* Name of the symbol. This is a required field. Storage for the name is
  434. allocated on the psymbol_obstack or symbol_obstack for the associated
  435. objfile. *)
  436. _name : pchar;
  437. (* Value of the symbol. Which member of this union to use, and what
  438. it means, depends on what kind of symbol this is and its
  439. SYMBOL_CLASS. See comments there for more details. All of these
  440. are in host byte order (though what they point to might be in
  441. target byte order, e.g. LOC_CONST_BYTES). *)
  442. value : record
  443. case integer of
  444. (* The fact that this is a long not a LONGEST mainly limits the
  445. range of a LOC_CONST. Since LOC_CONST_BYTES exists, I am not
  446. sure that is a big deal. *)
  447. 0 : (ivalue : longint;);
  448. 1 : (block : pblock;);
  449. 2 : (bytes : pchar;);
  450. 3 : (address : CORE_ADDR;);
  451. (* for opaque typedef struct chain *)
  452. 4 : (chain : psymbol;);
  453. end;
  454. (* Since one and only one language can apply, wrap the language specific
  455. information inside a union. *)
  456. (* union
  457. {
  458. struct cplus_specific /* For C++ */
  459. /* and Java */
  460. {
  461. char *demangled_name;
  462. } cplus_specific;
  463. struct chill_specific /* For Chill */
  464. {
  465. char *demangled_name;
  466. } chill_specific;
  467. } language_specific; *)
  468. demangled_name : pchar;
  469. (* Record the source code language that applies to this symbol.
  470. This is used to select one of the fields from the language specific
  471. union above. *)
  472. language : tlanguage;
  473. (* Which section is this symbol in? This is an index into
  474. section_offsets for this objfile. Negative means that the symbol
  475. does not get relocated relative to a section.
  476. Disclaimer: currently this is just used for xcoff, so do not
  477. expect all symbol-reading code to set it correctly (the ELF code
  478. also tries to set it correctly). *)
  479. section : word;
  480. (* The bfd section associated with this symbol. *)
  481. bfd_section : pointer {^asection};
  482. end; { of general_symbol_info record declaration }
  483. tminimal_symbol_type =
  484. (
  485. mst_unknown := 0, (* Unknown type, the default *)
  486. mst_text, (* Generally executable instructions *)
  487. mst_data, (* Generally initialized data *)
  488. mst_bss, (* Generally uninitialized data *)
  489. mst_abs, (* Generally absolute (nonrelocatable) *)
  490. (* GDB uses mst_solib_trampoline for the start address of a shared
  491. library trampoline entry. Breakpoints for shared library functions
  492. are put there if the shared library is not yet loaded.
  493. After the shared library is loaded, lookup_minimal_symbol will
  494. prefer the minimal symbol from the shared library (usually
  495. a mst_text symbol) over the mst_solib_trampoline symbol, and the
  496. breakpoints will be moved to their true address in the shared
  497. library via breakpoint_re_set. *)
  498. mst_solib_trampoline, (* Shared library trampoline code *)
  499. (* For the mst_file* types, the names are only guaranteed to be unique
  500. within a given .o file. *)
  501. mst_file_text, (* Static version of mst_text *)
  502. mst_file_data, (* Static version of mst_data *)
  503. mst_file_bss (* Static version of mst_bss *)
  504. );
  505. namespace_enum = (
  506. (* UNDEF_NAMESPACE is used when a namespace has not been discovered or
  507. none of the following apply. This usually indicates an error either
  508. in the symbol information or in gdbs handling of symbols. *)
  509. UNDEF_NAMESPACE,
  510. (* VAR_NAMESPACE is the usual namespace. In C, this contains variables,
  511. function names, typedef names and enum type values. *)
  512. VAR_NAMESPACE,
  513. (* STRUCT_NAMESPACE is used in C to hold struct, union and enum type names.
  514. Thus, if `struct foo' is used in a C program, it produces a symbol named
  515. `foo' in the STRUCT_NAMESPACE. *)
  516. STRUCT_NAMESPACE,
  517. (* LABEL_NAMESPACE may be used for names of labels (for gotos);
  518. currently it is not used and labels are not recorded at all. *)
  519. LABEL_NAMESPACE,
  520. (* Searching namespaces. These overlap with VAR_NAMESPACE, providing
  521. some granularity with the search_symbols function. *)
  522. (* Everything in VAR_NAMESPACE minus FUNCTIONS_-, TYPES_-, and
  523. METHODS_NAMESPACE *)
  524. VARIABLES_NAMESPACE,
  525. (* All functions -- for some reason not methods, though. *)
  526. FUNCTIONS_NAMESPACE,
  527. (* All defined types *)
  528. TYPES_NAMESPACE,
  529. (* All class methods -- why is this separated out? *)
  530. METHODS_NAMESPACE
  531. );
  532. address_class = (
  533. (* Not used; catches errors *)
  534. LOC_UNDEF,
  535. (* Value is constant int SYMBOL_VALUE, host byteorder *)
  536. LOC_CONST,
  537. (* Value is at fixed address SYMBOL_VALUE_ADDRESS *)
  538. LOC_STATIC,
  539. (* Value is in register. SYMBOL_VALUE is the register number. *)
  540. LOC_REGISTER,
  541. (* It is an argument; the value is at SYMBOL_VALUE offset in arglist. *)
  542. LOC_ARG,
  543. (* Value address is at SYMBOL_VALUE offset in arglist. *)
  544. LOC_REF_ARG,
  545. (* Value is in register number SYMBOL_VALUE. Just like LOC_REGISTER
  546. except this is an argument. Probably the cleaner way to handle
  547. this would be to separate address_class (which would include
  548. separate ARG and LOCAL to deal with FRAME_ARGS_ADDRESS versus
  549. FRAME_LOCALS_ADDRESS), and an is_argument flag.
  550. For some symbol formats (stabs, for some compilers at least),
  551. the compiler generates two symbols, an argument and a register.
  552. In some cases we combine them to a single LOC_REGPARM in symbol
  553. reading, but currently not for all cases (e.g. it's passed on the
  554. stack and then loaded into a register). *)
  555. LOC_REGPARM,
  556. (* Value is in specified register. Just like LOC_REGPARM except the
  557. register holds the address of the argument instead of the argument
  558. itself. This is currently used for the passing of structs and unions
  559. on sparc and hppa. It is also used for call by reference where the
  560. address is in a register, at least by mipsread.c. *)
  561. LOC_REGPARM_ADDR,
  562. (* Value is a local variable at SYMBOL_VALUE offset in stack frame. *)
  563. LOC_LOCAL,
  564. (* Value not used; definition in SYMBOL_TYPE. Symbols in the namespace
  565. STRUCT_NAMESPACE all have this class. *)
  566. LOC_TYPEDEF,
  567. (* Value is address SYMBOL_VALUE_ADDRESS in the code *)
  568. LOC_LABEL,
  569. (* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'.
  570. In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address
  571. of the block. Function names have this class. *)
  572. LOC_BLOCK,
  573. (* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in
  574. target byte order. *)
  575. LOC_CONST_BYTES,
  576. (* Value is arg at SYMBOL_VALUE offset in stack frame. Differs from
  577. LOC_LOCAL in that symbol is an argument; differs from LOC_ARG in
  578. that we find it in the frame (FRAME_LOCALS_ADDRESS), not in the
  579. arglist (FRAME_ARGS_ADDRESS). Added for i960, which passes args
  580. in regs then copies to frame. *)
  581. LOC_LOCAL_ARG,
  582. (* Value is at SYMBOL_VALUE offset from the current value of
  583. register number SYMBOL_BASEREG. This exists mainly for the same
  584. things that LOC_LOCAL and LOC_ARG do; but we need to do this
  585. instead because on 88k DWARF gives us the offset from the
  586. frame/stack pointer, rather than the offset from the "canonical
  587. frame address" used by COFF, stabs, etc., and we don't know how
  588. to convert between these until we start examining prologues.
  589. Note that LOC_BASEREG is much less general than a DWARF expression.
  590. We don't need the generality (at least not yet), and storing a general
  591. DWARF expression would presumably take up more space than the existing
  592. scheme. *)
  593. LOC_BASEREG,
  594. (* Same as LOC_BASEREG but it is an argument. *)
  595. LOC_BASEREG_ARG,
  596. (* Value is at fixed address, but the address of the variable has
  597. to be determined from the minimal symbol table whenever the
  598. variable is referenced.
  599. This happens if debugging information for a global symbol is
  600. emitted and the corresponding minimal symbol is defined
  601. in another object file or runtime common storage.
  602. The linker might even remove the minimal symbol if the global
  603. symbol is never referenced, in which case the symbol remains
  604. unresolved. *)
  605. LOC_UNRESOLVED,
  606. (* Value is at a thread-specific location calculated by a
  607. target-specific method. *)
  608. LOC_THREAD_LOCAL_STATIC,
  609. (* The variable does not actually exist in the program.
  610. The value is ignored. *)
  611. LOC_OPTIMIZED_OUT,
  612. (* The variable is static, but actually lives at * (address).
  613. * I.e. do an extra indirection to get to it.
  614. * This is used on HP-UX to get at globals that are allocated
  615. * in shared libraries, where references from images other
  616. * than the one where the global was allocated are done
  617. * with a level of indirection.
  618. *)
  619. LOC_INDIRECT
  620. );
  621. minimal_symbol = record
  622. (* The general symbol info required for all types of symbols.
  623. The SYMBOL_VALUE_ADDRESS contains the address that this symbol
  624. corresponds to. *)
  625. ginfo : general_symbol_info;
  626. (* The info field is available for caching machine-specific information
  627. so it doesn't have to rederive the info constantly (over a serial line).
  628. It is initialized to zero and stays that way until target-dependent code
  629. sets it. Storage for any data pointed to by this field should be allo-
  630. cated on the symbol_obstack for the associated objfile.
  631. The type would be "void *" except for reasons of compatibility with older
  632. compilers. This field is optional.
  633. Currently, the AMD 29000 tdep.c uses it to remember things it has decoded
  634. from the instructions in the function header, and the MIPS-16 code uses
  635. it to identify 16-bit procedures. *)
  636. info : pchar;
  637. {$ifdef SOFUN_ADDRESS_MAYBE_MISSING}
  638. (* Which source file is this symbol in? Only relevant for mst_file_*. *)
  639. filename : pchar;
  640. {$endif}
  641. (* Classification types for this symbol. These should be taken as "advisory
  642. only", since if gdb can't easily figure out a classification it simply
  643. selects mst_unknown. It may also have to guess when it can't figure out
  644. which is a better match between two types (mst_data versus mst_bss) for
  645. example. Since the minimal symbol info is sometimes derived from the
  646. BFD library's view of a file, we need to live with what information bfd
  647. supplies. *)
  648. minimal_symbol_type : tminimal_symbol_type;
  649. end{ of minimal_symbol};
  650. block = record
  651. (* Addresses in the executable code that are in this block. *)
  652. startaddr,
  653. endaddr : CORE_ADDR ;
  654. (* The symbol that names this block, if the block is the body of a
  655. function; otherwise, zero. *)
  656. _function : psymbol;
  657. (* The `struct block' for the containing block, or 0 if none.
  658. The superblock of a top-level local block (i.e. a function in the
  659. case of C) is the STATIC_BLOCK. The superblock of the
  660. STATIC_BLOCK is the GLOBAL_BLOCK. *)
  661. superblock : pblock;
  662. (* Version of GCC used to compile the function corresponding
  663. to this block, or 0 if not compiled with GCC. When possible,
  664. GCC should be compatible with the native compiler, or if that
  665. is not feasible, the differences should be fixed during symbol
  666. reading. As of 16 Apr 93, this flag is never used to distinguish
  667. between gcc2 and the native compiler.
  668. If there is no function corresponding to this block, this meaning
  669. of this flag is undefined. *)
  670. gcc_compile_flag : byte;
  671. (* Number of local symbols. *)
  672. nsyms : longint;
  673. (* The symbols. If some of them are arguments, then they must be
  674. in the order in which we would like to print them. *)
  675. sym : array [0..0] of psymbol;
  676. end { of block definition };
  677. symbol = record
  678. (* The general symbol info required for all types of symbols. *)
  679. ginfo : general_symbol_info;
  680. (* Data type of value *)
  681. _type : pointer{ptype};
  682. (* Name space code. *)
  683. namespace : namespace_enum;
  684. (* Address class *)
  685. aclass : address_class;
  686. (* Line number of definition. FIXME: Should we really make the assumption
  687. that nobody will try to debug files longer than 64K lines? What about
  688. machine generated programs? *)
  689. line : word;
  690. (* Some symbols require an additional value to be recorded on a per-
  691. symbol basis. Stash those values here. *)
  692. (*union
  693. {
  694. /* Used by LOC_BASEREG and LOC_BASEREG_ARG. */
  695. short basereg;
  696. } *)
  697. aux_value_base_reg : word;
  698. (* Link to a list of aliases for this symbol.
  699. Only a "primary/main symbol may have aliases. *)
  700. aliases : pointer{palias_list};
  701. (* List of ranges where this symbol is active. This is only
  702. used by alias symbols at the current time. *)
  703. ranges : pointer{prange_list};
  704. end;
  705. target_signal = (TARGET_SIGNAL_FIRST := 0,
  706. TARGET_SIGNAL_HUP := 1,TARGET_SIGNAL_INT := 2,
  707. TARGET_SIGNAL_QUIT := 3,TARGET_SIGNAL_ILL := 4,
  708. TARGET_SIGNAL_TRAP := 5,TARGET_SIGNAL_ABRT := 6,
  709. TARGET_SIGNAL_EMT := 7,TARGET_SIGNAL_FPE := 8,
  710. TARGET_SIGNAL_KILL := 9,TARGET_SIGNAL_BUS := 10,
  711. TARGET_SIGNAL_SEGV := 11,TARGET_SIGNAL_SYS := 12,
  712. TARGET_SIGNAL_PIPE := 13,TARGET_SIGNAL_ALRM := 14,
  713. TARGET_SIGNAL_TERM := 15,TARGET_SIGNAL_URG := 16,
  714. TARGET_SIGNAL_STOP := 17,TARGET_SIGNAL_TSTP := 18,
  715. TARGET_SIGNAL_CONT := 19,TARGET_SIGNAL_CHLD := 20,
  716. TARGET_SIGNAL_TTIN := 21,TARGET_SIGNAL_TTOU := 22,
  717. TARGET_SIGNAL_IO := 23,TARGET_SIGNAL_XCPU := 24,
  718. TARGET_SIGNAL_XFSZ := 25,TARGET_SIGNAL_VTALRM := 26,
  719. TARGET_SIGNAL_PROF := 27,TARGET_SIGNAL_WINCH := 28,
  720. TARGET_SIGNAL_LOST := 29,TARGET_SIGNAL_USR1 := 30,
  721. TARGET_SIGNAL_USR2 := 31,TARGET_SIGNAL_PWR := 32,
  722. TARGET_SIGNAL_POLL := 33,TARGET_SIGNAL_WIND := 34,
  723. TARGET_SIGNAL_PHONE := 35,TARGET_SIGNAL_WAITING := 36,
  724. TARGET_SIGNAL_LWP := 37,TARGET_SIGNAL_DANGER := 38,
  725. TARGET_SIGNAL_GRANT := 39,TARGET_SIGNAL_RETRACT := 40,
  726. TARGET_SIGNAL_MSG := 41,TARGET_SIGNAL_SOUND := 42,
  727. TARGET_SIGNAL_SAK := 43,TARGET_SIGNAL_PRIO := 44,
  728. TARGET_SIGNAL_REALTIME_33 := 45,TARGET_SIGNAL_REALTIME_34 := 46,
  729. TARGET_SIGNAL_REALTIME_35 := 47,TARGET_SIGNAL_REALTIME_36 := 48,
  730. TARGET_SIGNAL_REALTIME_37 := 49,TARGET_SIGNAL_REALTIME_38 := 50,
  731. TARGET_SIGNAL_REALTIME_39 := 51,TARGET_SIGNAL_REALTIME_40 := 52,
  732. TARGET_SIGNAL_REALTIME_41 := 53,TARGET_SIGNAL_REALTIME_42 := 54,
  733. TARGET_SIGNAL_REALTIME_43 := 55,TARGET_SIGNAL_REALTIME_44 := 56,
  734. TARGET_SIGNAL_REALTIME_45 := 57,TARGET_SIGNAL_REALTIME_46 := 58,
  735. TARGET_SIGNAL_REALTIME_47 := 59,TARGET_SIGNAL_REALTIME_48 := 60,
  736. TARGET_SIGNAL_REALTIME_49 := 61,TARGET_SIGNAL_REALTIME_50 := 62,
  737. TARGET_SIGNAL_REALTIME_51 := 63,TARGET_SIGNAL_REALTIME_52 := 64,
  738. TARGET_SIGNAL_REALTIME_53 := 65,TARGET_SIGNAL_REALTIME_54 := 66,
  739. TARGET_SIGNAL_REALTIME_55 := 67,TARGET_SIGNAL_REALTIME_56 := 68,
  740. TARGET_SIGNAL_REALTIME_57 := 69,TARGET_SIGNAL_REALTIME_58 := 70,
  741. TARGET_SIGNAL_REALTIME_59 := 71,TARGET_SIGNAL_REALTIME_60 := 72,
  742. TARGET_SIGNAL_REALTIME_61 := 73,TARGET_SIGNAL_REALTIME_62 := 74,
  743. TARGET_SIGNAL_REALTIME_63 := 75,TARGET_SIGNAL_UNKNOWN,
  744. TARGET_SIGNAL_DEFAULT,TARGET_SIGNAL_LAST
  745. );
  746. strata = (dummy_stratum,file_stratum,core_stratum,download_stratum,process_stratum);
  747. ptarget_ops = ^target_ops;
  748. target_ops = record
  749. to_shortname : pchar;
  750. to_longname : pchar;
  751. to_doc : pchar;
  752. to_open : procedure (_para1:pchar; _para2:longint);
  753. to_close : procedure (_para1:longint);
  754. to_attach : procedure (_para1:pchar; _para2:longint);
  755. to_detach : procedure (_para1:pchar; _para2:longint);
  756. to_resume : procedure (_para1:longint; _para2:longint; _para3:target_signal);
  757. to_wait : pointer; {function (_para1:longint; _para2:ptarget_waitstatus):longint;}
  758. to_fetch_registers : procedure (_para1:longint);
  759. to_store_registers : procedure (_para1:longint);
  760. to_prepare_to_store : procedure ;
  761. to_xfer_memory : function (memaddr:CORE_ADDR; myaddr:pchar; len:longint; write:longint; target:ptarget_ops):longint;
  762. to_files_info : procedure (_para1:ptarget_ops);
  763. to_insert_breakpoint : function (_para1:CORE_ADDR; _para2:pchar):longint;
  764. to_remove_breakpoint : function (_para1:CORE_ADDR; _para2:pchar):longint;
  765. to_terminal_init : procedure ;
  766. to_terminal_inferior : procedure ;
  767. to_terminal_ours_for_output : procedure ;
  768. to_terminal_ours : procedure ;
  769. to_terminal_info : procedure (_para1:pchar; _para2:longint);
  770. to_kill : procedure ;
  771. to_load : procedure (_para1:pchar; _para2:longint);
  772. to_lookup_symbol : function (_para1:pchar; _para2:pCORE_ADDR):longint;
  773. to_create_inferior : procedure (_para1:pchar; _para2:pchar; _para3:ppchar);
  774. to_mourn_inferior : procedure ;
  775. to_can_run : function :longint;
  776. to_notice_signals : procedure (pid:longint);
  777. to_thread_alive : function (pid:longint):longint;
  778. to_stop : procedure ;
  779. to_stratum : strata;
  780. DONT_USE : pointer;
  781. to_has_all_memory : longint;
  782. to_has_memory : longint;
  783. to_has_stack : longint;
  784. to_has_registers : longint;
  785. to_has_execution : longint;
  786. to_sections : pointer; {^section_table}
  787. to_sections_end : pointer; {^section_table}
  788. to_magic : longint;
  789. end;
  790. {$PACKRECORDS NORMAL}
  791. {*****************************************************************************
  792. Define external calls to libgdb.a
  793. *****************************************************************************}
  794. var
  795. { external variables }
  796. error_return : jmp_buf;cvar;{$ifndef GDB_V5}external;{$endif}
  797. quit_return : jmp_buf;cvar;{$ifndef GDB_V5}external;{$endif}
  798. create_breakpoint_hook : pointer;cvar;external;
  799. current_target : target_ops;cvar;external;
  800. stop_pc : CORE_ADDR;cvar;external;
  801. { we need also to declare some vars }
  802. watchdog : longint;cvar;public;
  803. gdb_error : longint;cvar;public;
  804. display_time : longbool;cvar;public;
  805. display_space : longbool;cvar;public;
  806. {$ifndef GDB_V416}
  807. { the following are also needed from version 4.18 }
  808. { Whether this is the command line version or not }
  809. tui_version : longint;cvar;public;
  810. { Whether xdb commands will be handled }
  811. xdb_commands : longint;cvar;public;
  812. { Whether dbx commands will be handled }
  813. dbx_commands : longint;cvar;public;
  814. {$ifndef GDB_V5}
  815. var
  816. gdb_stdout : PGDB_FILE;cvar;public;
  817. gdb_stderr : PGDB_FILE;cvar;public;
  818. {$else GDB_V5}
  819. var
  820. gdb_stdout : pui_file;cvar;public;
  821. gdb_stderr : pui_file;cvar;public;
  822. gdb_stdlog : pui_file;cvar;public;
  823. gdb_stdtarg : pui_file;cvar;public;
  824. event_loop_p : longint;cvar;public;
  825. {$endif GDB_V5}
  826. { used for gdb_stdout and gdb_stderr }
  827. function xmalloc(size : longint) : pointer;cdecl;external;
  828. {$endif not GDB_V416}
  829. function find_pc_line(i:CORE_ADDR;l:longint):symtab_and_line;cdecl;external;
  830. function find_pc_function(i:CORE_ADDR):psymbol;cdecl;external;
  831. function lookup_minimal_symbol_by_pc(i : CORE_ADDR):pminimal_symbol;cdecl;external;
  832. procedure gdb_init;cdecl;external;
  833. procedure execute_command(p:pchar;i:longint);cdecl;external;
  834. procedure target_kill;cdecl;external;
  835. procedure target_close(i:longint);cdecl;external;
  836. {*****************************************************************************
  837. Helpers
  838. *****************************************************************************}
  839. procedure Debug(const s:string);
  840. begin
  841. if use_gdb_file then
  842. Writeln(gdb_file,s)
  843. else
  844. Writeln(s);
  845. end;
  846. {*****************************************************************************
  847. TFrameEntry
  848. *****************************************************************************}
  849. constructor tframeentry.init;
  850. begin
  851. Reset;
  852. end;
  853. destructor tframeentry.done;
  854. begin
  855. Clear;
  856. end;
  857. procedure tframeentry.reset;
  858. begin
  859. file_name:=nil;
  860. function_name:=nil;
  861. args:=nil;
  862. line_number:=0;
  863. address:=0;
  864. end;
  865. procedure tframeentry.clear;
  866. begin
  867. if assigned(file_name) then
  868. strdispose(file_name);
  869. if assigned(function_name) then
  870. strdispose(function_name);
  871. if assigned(args) then
  872. strdispose(args);
  873. reset;
  874. end;
  875. {*****************************************************************************
  876. tgdbbuffer
  877. *****************************************************************************}
  878. const
  879. blocksize=2048;
  880. constructor tgdbbuffer.init;
  881. begin
  882. Buf:=nil;
  883. {$ifdef GDB_V418}
  884. link:=nil;
  885. {$endif GDB_V418}
  886. {$ifdef GDB_V5}
  887. gdb_file:=nil;
  888. {$endif GDB_V5}
  889. Size:=0;
  890. Resize(blocksize);
  891. Reset;
  892. end;
  893. destructor tgdbbuffer.done;
  894. begin
  895. if assigned(buf) then
  896. freemem(buf,size);
  897. {$ifdef GDB_V418}
  898. if assigned(link) then
  899. begin
  900. link^.ts_streamtype:=afile;
  901. link^.ts_strbuf:=nil;
  902. link^.ts_buflen:=0;
  903. end;
  904. {$endif GDB_V418}
  905. end;
  906. procedure tgdbbuffer.reset;
  907. begin
  908. idx:=0;
  909. Buf[0]:=#0;
  910. end;
  911. procedure tgdbbuffer.append(p:pchar);
  912. var
  913. len : longint;
  914. begin
  915. if not assigned(p) then
  916. exit;
  917. len:=Strlen(p);
  918. if len+idx>size then
  919. Resize(len+idx);
  920. Move(p^,buf[idx],len);
  921. inc(idx,len);
  922. buf[idx]:=#0;
  923. end;
  924. procedure tgdbbuffer.lappend(p:pchar;len : longint);
  925. begin
  926. if not assigned(p) then
  927. exit;
  928. if len+idx>size then
  929. Resize(len+idx);
  930. Move(p^,buf[idx],len);
  931. inc(idx,len);
  932. buf[idx]:=#0;
  933. end;
  934. procedure tgdbbuffer.resize(nsize : longint);
  935. var
  936. np : pchar;
  937. begin
  938. nsize:=((nsize+blocksize-1) div blocksize)*blocksize;
  939. getmem(np,nsize);
  940. if assigned(buf) then
  941. begin
  942. move(buf^,np^,size);
  943. freemem(buf,size);
  944. end;
  945. buf:=np;
  946. size:=nsize;
  947. {$ifdef GDB_V418}
  948. if assigned(link) then
  949. begin
  950. link^.ts_strbuf:=buf;
  951. link^.ts_buflen:=size;
  952. end;
  953. {$endif GDB_V418}
  954. end;
  955. {*****************************************************************************
  956. Hook calls from libgdb.a
  957. *****************************************************************************}
  958. {$ifdef go32v2}
  959. procedure gdbpas_prev_exception_handler;cdecl;public;
  960. begin
  961. end;
  962. {$endif go32v2}
  963. procedure init_proc;cdecl;public;
  964. begin
  965. end;
  966. procedure annotate_signalled;cdecl;public;
  967. begin
  968. {$ifdef Debug}
  969. Debug('|signalled|');
  970. {$endif}
  971. end;
  972. procedure annotate_signal_name;cdecl;public;
  973. begin
  974. {$ifdef Debug}
  975. Debug('|signal_name|');
  976. with curr_gdb^ do
  977. signal_start:=gdboutputbuf.idx;
  978. {$endif}
  979. end;
  980. procedure annotate_signal_name_end;cdecl;public;
  981. begin
  982. {$ifdef Debug}
  983. Debug('|signal_name_end|');
  984. {$endif}
  985. end;
  986. procedure annotate_signal_string;cdecl;public;
  987. begin
  988. {$ifdef Debug}
  989. Debug('|signal_string|');
  990. {$endif}
  991. end;
  992. procedure annotate_signal_string_end;cdecl;public;
  993. begin
  994. {$ifdef Debug}
  995. Debug('|signal_string_end|');
  996. {$endif}
  997. with curr_gdb^ do
  998. begin
  999. signal_end:=gdboutputbuf.idx;
  1000. {
  1001. signal = (char *)alloca(signal_end-signal_start+1);
  1002. strncpy(signal,gdb_output_buffer+signal_start,signal_end-signal_start);
  1003. signal[signal_end-signal_start] = 0;
  1004. if (user_screen_shown)
  1005. __DebuggerScreen();
  1006. _UserWarning(WARN_SIGNALED,signal);
  1007. __UserScreen();
  1008. else
  1009. _UserWarning(WARN_SIGNALED,signal); }
  1010. call_reset:=true;
  1011. end;
  1012. end;
  1013. procedure annotate_signal;cdecl;public;
  1014. begin
  1015. {$ifdef Debug}
  1016. Debug('|signal|');
  1017. {$endif}
  1018. end;
  1019. procedure annotate_exited(exitstatus:longint);cdecl;public;
  1020. begin
  1021. {$ifdef Debug}
  1022. Debug('|exited|');
  1023. {$endif}
  1024. {#ifdef __DJGPP__
  1025. /* this is very important. The exit code of a djgpp program
  1026. disables interrupts and after this there is no other interrupt
  1027. called, which enables interrupts with the iret. */
  1028. __dpmi_get_and_enable_virtual_interrupt_state();
  1029. #endif }
  1030. {$ifdef go32v2}
  1031. {$asmmode att}
  1032. asm
  1033. movw $0x901,%ax
  1034. int $0x31
  1035. end;
  1036. {$asmmode default}
  1037. reload_fs;
  1038. {$endif def go32v2}
  1039. curr_gdb^.DebuggerScreen;
  1040. { DeleteBreakPoints; }
  1041. curr_gdb^.EndSession(exitstatus);
  1042. end;
  1043. procedure annotate_error;cdecl;public;
  1044. begin
  1045. {$ifdef Debug}
  1046. Debug('|error|');
  1047. {$endif}
  1048. end;
  1049. procedure annotate_error_begin;cdecl;public;
  1050. begin
  1051. {$ifdef Debug}
  1052. Debug('|error begin|');
  1053. {$endif}
  1054. with curr_gdb^ do
  1055. begin
  1056. error_start:=gdboutputbuf.idx+strlen(gdboutputbuf.buf);
  1057. got_error:=true;
  1058. end;
  1059. {$ifdef Debug}
  1060. Debug('|end of error begin|');
  1061. {$endif}
  1062. end;
  1063. procedure annotate_starting;cdecl;public;
  1064. begin
  1065. {$ifdef Debug}
  1066. Debug('|starting|');
  1067. {$endif}
  1068. {$ifdef go32v2}
  1069. reload_fs;
  1070. {$endif go32v2}
  1071. curr_gdb^.UserScreen;
  1072. end;
  1073. procedure annotate_stopped;cdecl;public;
  1074. var
  1075. sym : symtab_and_line;
  1076. fname : pchar;
  1077. begin
  1078. {$ifdef Debug}
  1079. Debug('|stopped|');
  1080. {$endif}
  1081. with curr_gdb^ do
  1082. begin
  1083. {$ifdef go32v2}
  1084. reload_fs;
  1085. {$endif go32v2}
  1086. DebuggerScreen;
  1087. Debuggee_started:=inferior_pid<>0;
  1088. if not Debuggee_started then exit;
  1089. if reset_command then exit;
  1090. sym:=find_pc_line(stop_pc,0);
  1091. if assigned(sym.symtab) then
  1092. fname:=sym.symtab^.filename
  1093. else
  1094. fname:=nil;
  1095. SelectSourceLine(fname,sym.line);
  1096. end;
  1097. end;
  1098. procedure proc_remove_foreign(pid:longint);cdecl;public;
  1099. begin
  1100. end;
  1101. procedure breakpoints_changed;cdecl;public;
  1102. begin
  1103. {$ifdef Debug}
  1104. Debug('|breakpoints_changed|');
  1105. {$endif}
  1106. end;
  1107. { only from version 5.0 }
  1108. procedure annotate_ignore_count_change;cdecl;public;
  1109. begin
  1110. {$ifdef Debug}
  1111. Debug('|annotate_ignore_count_change()|');
  1112. {$endif}
  1113. end;
  1114. procedure annotate_breakpoint(num:longint);cdecl;public;
  1115. begin
  1116. {$ifdef Debug}
  1117. Debug('|breakpoint(%d)|');
  1118. {$endif}
  1119. With Curr_gdb^ do
  1120. stop_breakpoint_number:=num;
  1121. end;
  1122. procedure annotate_watchpoint(num:longint);cdecl;public;
  1123. begin
  1124. {$ifdef Debug}
  1125. Debug('|watchpoint(%d)|');
  1126. {$endif}
  1127. With Curr_gdb^ do
  1128. stop_breakpoint_number:=num;
  1129. end;
  1130. procedure annotate_catchpoint(num:longint);cdecl;public;
  1131. begin
  1132. {$ifdef Debug}
  1133. Debug('|catchpoint(%d)|');
  1134. {$endif}
  1135. With Curr_gdb^ do
  1136. stop_breakpoint_number:=num;
  1137. end;
  1138. procedure annotate_breakpoints_headers;cdecl;public;
  1139. begin
  1140. {$ifdef Debug}
  1141. Debug('|breakpoints_headers|');
  1142. {$endif}
  1143. end;
  1144. procedure annotate_breakpoints_table;cdecl;public;
  1145. begin
  1146. {$ifdef Debug}
  1147. Debug('|breakpoints_table|');
  1148. {$endif}
  1149. end;
  1150. procedure annotate_record;cdecl;public;
  1151. begin
  1152. {$ifdef Debug}
  1153. Debug('|record|');
  1154. {$endif}
  1155. end;
  1156. procedure annotate_breakpoints_table_end;cdecl;public;
  1157. begin
  1158. {$ifdef Debug}
  1159. Debug('|breakpoints_table_end|');
  1160. {$endif}
  1161. end;
  1162. procedure annotate_frames_invalid;cdecl;public;
  1163. begin
  1164. {$ifdef Debug}
  1165. Debug('|frames_invalid|');
  1166. {$endif}
  1167. end;
  1168. procedure annotate_frame_begin(level:longint;pc:CORE_ADDR);cdecl;public;
  1169. begin
  1170. {$ifdef Debug}
  1171. Debug('|frame_begin(%d,%ld)|');
  1172. {$endif}
  1173. with curr_gdb^ do
  1174. begin
  1175. frame_begin_seen:=true;
  1176. frame_level:=level;
  1177. current_address:=pc;
  1178. current_line_number:=-1;
  1179. function_start:=-1;
  1180. function_end:=-1;
  1181. args_start:=-1;
  1182. args_end:=-1;
  1183. file_start:=-1;
  1184. file_end:=-1;
  1185. line_start:=-1;
  1186. line_end:=-1;
  1187. end;
  1188. end;
  1189. procedure annotate_frame_address;cdecl;public;
  1190. begin
  1191. {$ifdef Debug}
  1192. Debug('|frame_address|');
  1193. {$endif}
  1194. end;
  1195. procedure annotate_frame_address_end;cdecl;public;
  1196. begin
  1197. {$ifdef Debug}
  1198. Debug('|frame_address_end|');
  1199. {$endif}
  1200. end;
  1201. procedure annotate_frame_function_name;cdecl;public;
  1202. begin
  1203. {$ifdef Debug}
  1204. Debug('|frame_function_name|');
  1205. {$endif}
  1206. with curr_gdb^ do
  1207. function_start:=gdboutputbuf.idx;
  1208. end;
  1209. procedure annotate_frame_args;cdecl;public;
  1210. begin
  1211. {$ifdef Debug}
  1212. Debug('|frame_args|');
  1213. {$endif}
  1214. with curr_gdb^ do
  1215. begin
  1216. function_end:=gdboutputbuf.idx;
  1217. args_start:=gdboutputbuf.idx;
  1218. end;
  1219. end;
  1220. procedure annotate_frame_source_begin;cdecl;public;
  1221. begin
  1222. {$ifdef Debug}
  1223. Debug('|frame_source_begin|');
  1224. {$endif}
  1225. with curr_gdb^ do
  1226. args_end:=gdboutputbuf.idx;
  1227. end;
  1228. procedure annotate_frame_source_file;cdecl;public;
  1229. begin
  1230. {$ifdef Debug}
  1231. Debug('|frame_source_file|');
  1232. {$endif}
  1233. with curr_gdb^ do
  1234. file_start:=gdboutputbuf.idx;
  1235. end;
  1236. procedure annotate_frame_source_file_end;cdecl;public;
  1237. begin
  1238. {$ifdef Debug}
  1239. Debug('|frame_source_file_end|');
  1240. {$endif}
  1241. with curr_gdb^ do
  1242. file_end:=gdboutputbuf.idx;
  1243. end;
  1244. procedure annotate_frame_source_line;cdecl;public;
  1245. begin
  1246. {$ifdef Debug}
  1247. Debug('|frame_source_line|');
  1248. {$endif}
  1249. with curr_gdb^ do
  1250. line_start:=gdboutputbuf.idx;
  1251. end;
  1252. procedure annotate_frame_source_end;cdecl;public;
  1253. begin
  1254. {$ifdef Debug}
  1255. Debug('|frame_source_end|');
  1256. {$endif}
  1257. with curr_gdb^ do
  1258. line_end:=gdboutputbuf.idx;
  1259. end;
  1260. procedure annotate_frame_where;cdecl;public;
  1261. begin
  1262. {$ifdef Debug}
  1263. Debug('|frame_where|');
  1264. {$endif}
  1265. end;
  1266. procedure annotate_frame_end;cdecl;public;
  1267. var
  1268. fe : pframeentry;
  1269. c : char;
  1270. err : integer;
  1271. begin
  1272. {$ifdef Debug}
  1273. Debug('|frame_end|');
  1274. {$endif}
  1275. with curr_gdb^ do
  1276. begin
  1277. if (not record_frames) or (not frame_begin_seen) then
  1278. exit;
  1279. { This can happen, when the function has no Debugging information }
  1280. if (args_start >= 0) and (args_end < 0) then
  1281. args_end:=gdboutputbuf.idx;
  1282. frame_begin_seen:=false;
  1283. fe:=get_frameentry(frame_level);
  1284. fe^.address:=current_address;
  1285. fe^.level:=frame_level;
  1286. if (function_start>=0) then
  1287. begin
  1288. c:=gdboutputbuf.buf[function_end];
  1289. gdboutputbuf.buf[function_end]:=#0;
  1290. fe^.function_name:=strnew(gdboutputbuf.buf+function_start);
  1291. gdboutputbuf.buf[function_end]:=c;
  1292. end;
  1293. if (file_start>=0) then
  1294. begin
  1295. c:=gdboutputbuf.buf[file_end];
  1296. gdboutputbuf.buf[file_end]:=#0;
  1297. fe^.file_name:=strnew(gdboutputbuf.buf+file_start);
  1298. gdboutputbuf.buf[file_end]:=c;
  1299. end;
  1300. if (args_start>=0) then
  1301. begin
  1302. if (gdboutputbuf.buf[args_end-1]=#10) then
  1303. dec(args_end);
  1304. c:=gdboutputbuf.buf[args_end];
  1305. gdboutputbuf.buf[args_end]:=#0;
  1306. fe^.args:=strnew(gdboutputbuf.buf+args_start);
  1307. gdboutputbuf.buf[args_end]:=c;
  1308. end;
  1309. if (line_start>=0) then
  1310. begin
  1311. c:=gdboutputbuf.buf[line_end];
  1312. gdboutputbuf.buf[line_end]:=#0;
  1313. { sscanf(gdb_output_buffer+line_start,'%d',&fe^.line_number); }
  1314. val(strpas(pchar(@gdboutputbuf.buf[line_start])),fe^.line_number,err);
  1315. gdboutputbuf.buf[line_end]:=c;
  1316. end;
  1317. end;
  1318. end;
  1319. procedure annotate_quit;cdecl;public;
  1320. begin
  1321. {$ifdef Debug}
  1322. Debug('|quit|');
  1323. {$endif}
  1324. end;
  1325. procedure annotate_arg_begin;cdecl;public;
  1326. begin
  1327. {$ifdef Debug}
  1328. Debug('|arg_begin|');
  1329. {$endif}
  1330. end;
  1331. procedure annotate_arg_name_end;cdecl;public;
  1332. begin
  1333. {$ifdef Debug}
  1334. Debug('|arg_name_end|');
  1335. {$endif}
  1336. end;
  1337. procedure annotate_arg_value(typ:pointer);cdecl;public;
  1338. begin
  1339. {$ifdef Debug}
  1340. Debug('|arg_value|');
  1341. {$endif}
  1342. end;
  1343. procedure annotate_arg_end;cdecl;public;
  1344. begin
  1345. {$ifdef Debug}
  1346. Debug('|arg_end|');
  1347. {$endif}
  1348. end;
  1349. procedure annotate_source(filename:pchar;line,character,mid:longint;pc:CORE_ADDR);cdecl;public;
  1350. begin
  1351. {$ifdef Debug}
  1352. Debug('|source|');
  1353. {$endif}
  1354. end;
  1355. procedure annotate_function_call;cdecl;public;
  1356. begin
  1357. {$ifdef Debug}
  1358. Debug('|function_call|');
  1359. {$endif}
  1360. end;
  1361. procedure annotate_signal_handler_caller;cdecl;public;
  1362. begin
  1363. {$ifdef Debug}
  1364. Debug('|signal_handler_caller|');
  1365. {$endif}
  1366. end;
  1367. procedure annotate_array_section_begin(index:longint;elttype:pointer);cdecl;public;
  1368. begin
  1369. {$ifdef Debug}
  1370. Debug('|array_section_begin()|');
  1371. {$endif}
  1372. end;
  1373. procedure annotate_elt_rep(repcount:longint);cdecl;public;
  1374. begin
  1375. {$ifdef Debug}
  1376. Debug('|elt_rep()|');
  1377. {$endif}
  1378. end;
  1379. procedure annotate_elt_rep_end;cdecl;public;
  1380. begin
  1381. {$ifdef Debug}
  1382. Debug('|elt_rep_end|');
  1383. {$endif}
  1384. end;
  1385. procedure annotate_elt;cdecl;public;
  1386. begin
  1387. {$ifdef Debug}
  1388. Debug('|elt|');
  1389. {$endif}
  1390. end;
  1391. procedure annotate_array_section_end;cdecl;public;
  1392. begin
  1393. {$ifdef Debug}
  1394. Debug('|array_section_end|');
  1395. {$endif}
  1396. end;
  1397. procedure annotate_display_begin;cdecl;public;
  1398. begin
  1399. {$ifdef Debug}
  1400. Debug('|display_begin|');
  1401. {$endif}
  1402. end;
  1403. procedure annotate_display_number_end;cdecl;public;
  1404. begin
  1405. {$ifdef Debug}
  1406. Debug('|display_number_end|');
  1407. {$endif}
  1408. end;
  1409. procedure annotate_display_format;cdecl;public;
  1410. begin
  1411. {$ifdef Debug}
  1412. Debug('|display_format|');
  1413. {$endif}
  1414. end;
  1415. procedure annotate_display_expression;cdecl;public;
  1416. begin
  1417. {$ifdef Debug}
  1418. Debug('|display_expression|');
  1419. {$endif}
  1420. end;
  1421. procedure annotate_display_expression_end;cdecl;public;
  1422. begin
  1423. {$ifdef Debug}
  1424. Debug('|display_expression_end|');
  1425. {$endif}
  1426. end;
  1427. procedure annotate_display_value;cdecl;public;
  1428. begin
  1429. {$ifdef Debug}
  1430. Debug('|display_value|');
  1431. {$endif}
  1432. end;
  1433. procedure annotate_display_end;cdecl;public;
  1434. begin
  1435. {$ifdef Debug}
  1436. Debug('|display_end|');
  1437. {$endif}
  1438. end;
  1439. procedure annotate_field (num:longint);cdecl;public;
  1440. begin
  1441. {$ifdef Debug}
  1442. Debug('a_field(%d)');
  1443. {$endif}
  1444. end;
  1445. procedure annotate_field_begin(typ:pointer);cdecl;public;
  1446. begin
  1447. {$ifdef Debug}
  1448. Debug('a_field_begin\n');
  1449. {$endif}
  1450. end;
  1451. procedure annotate_field_name_end;cdecl;public;
  1452. begin
  1453. {$ifdef Debug}
  1454. Debug('a_field_name_end\n');
  1455. {$endif}
  1456. end;
  1457. procedure annotate_field_value;cdecl;public;
  1458. begin
  1459. {$ifdef Debug}
  1460. Debug('a_field_value\n');
  1461. {$endif}
  1462. end;
  1463. procedure annotate_field_end;cdecl;public;
  1464. begin
  1465. {$ifdef Debug}
  1466. Debug('a_field_end\n');
  1467. {$endif}
  1468. end;
  1469. procedure annotate_value_history_begin (histindex:longint;typ:pointer);cdecl;public;
  1470. begin
  1471. {$ifdef Debug}
  1472. Debug('a_value_history_begin(%d)\n');
  1473. {$endif}
  1474. end;
  1475. procedure annotate_value_begin (typ:pointer);cdecl;public;
  1476. begin
  1477. {$ifdef Debug}
  1478. Debug('a_value_begin\n');
  1479. {$endif}
  1480. end;
  1481. procedure annotate_value_history_value;cdecl;public;
  1482. begin
  1483. {$ifdef Debug}
  1484. Debug('a_value_history_value\n');
  1485. {$endif}
  1486. end;
  1487. procedure annotate_value_history_end;cdecl;public;
  1488. begin
  1489. {$ifdef Debug}
  1490. Debug('a_value_history_end\n');
  1491. {$endif}
  1492. end;
  1493. procedure annotate_value_end;cdecl;public;
  1494. begin
  1495. {$ifdef Debug}
  1496. Debug('a_value_end\n');
  1497. {$endif}
  1498. end;
  1499. procedure _initialize_annotate;cdecl;public;
  1500. begin
  1501. end;
  1502. {$ifndef GDB_V5}
  1503. procedure fputs_unfiltered(linebuffer:pchar;stream:pointer);cdecl;public;
  1504. begin
  1505. with curr_gdb^ do
  1506. {$ifdef gdb_v418}
  1507. if stream = gdb_stderr then
  1508. gdberrorbuf.append(linebuffer)
  1509. else
  1510. {$endif gdb_v418}
  1511. gdboutputbuf.append(linebuffer);
  1512. end;
  1513. {$else GDB_V5}
  1514. procedure gdbint_ui_file_write(stream : pui_file; p : pchar; len : longint);cdecl;
  1515. begin
  1516. with curr_gdb^ do
  1517. if stream = gdb_stderr then
  1518. gdberrorbuf.lappend(p,len)
  1519. else if stream = gdb_stdout then
  1520. gdboutputbuf.lappend(p,len)
  1521. else
  1522. begin
  1523. gdberrorbuf.append('Unknown gdb ui_file');
  1524. gdberrorbuf.lappend(p,len);
  1525. end;
  1526. end;
  1527. {$endif GDB_V5}
  1528. procedure CreateBreakPointHook(var b:breakpoint);cdecl;
  1529. var
  1530. sym : symtab_and_line;
  1531. { this procedure is only here to avoid the problems
  1532. with different version of gcc having different stack
  1533. handling:
  1534. on older versions find_pc_line uses just "ret"
  1535. while on newer gcc version "ret $4" is used
  1536. if this call is within the CreateBreakPointHook function
  1537. it changes %esp and thus the registers are
  1538. not restored correctly PM }
  1539. procedure get_pc_line;
  1540. begin
  1541. sym:=find_pc_line(b.address,0);
  1542. end;
  1543. begin
  1544. get_pc_line;
  1545. with curr_gdb^ do
  1546. begin
  1547. last_breakpoint_number:=b.number;
  1548. { function breakpoints have zero as file and as line !!
  1549. but they are valid !! }
  1550. invalid_breakpoint_line:=(b.line_number<>sym.line) and (b.line_number<>0);
  1551. last_breakpoint_address:=b.address;
  1552. last_breakpoint_line:=sym.line;
  1553. if assigned(sym.symtab) then
  1554. last_breakpoint_file:=sym.symtab^.filename
  1555. else
  1556. last_breakpoint_file:=nil;
  1557. end;
  1558. end;
  1559. {*****************************************************************************
  1560. tgdbinterface
  1561. *****************************************************************************}
  1562. constructor tgdbinterface.init;
  1563. begin
  1564. gdboutputbuf.init;
  1565. gdberrorbuf.init;
  1566. record_frames:=true;
  1567. {$ifdef GDB_V418}
  1568. (* GDB_FILE *
  1569. gdb_file_init_astring (n)
  1570. int n;
  1571. should we use xmalloc ?
  1572. gdb could resize the buffer => crash,
  1573. but normally it should not if unfiltered !! PM *)
  1574. gdb_stdout^.ts_streamtype := astring;
  1575. gdb_stdout^.ts_strbuf := gdboutputbuf.buf;
  1576. gdb_stdout^.ts_buflen := gdboutputbuf.size;
  1577. gdboutputbuf.link:=gdb_stdout;
  1578. gdb_stderr^.ts_streamtype := astring;
  1579. gdb_stderr^.ts_strbuf := gdberrorbuf.buf;
  1580. gdb_stderr^.ts_buflen := gdberrorbuf.size;
  1581. gdberrorbuf.link:=gdb_stderr;
  1582. {$endif GDB_V418}
  1583. {$ifdef GDB_V5}
  1584. {$endif GDB_V5}
  1585. gdb__init;
  1586. curr_gdb:=@self;
  1587. command_level:=0;
  1588. { set output mode for GDB }
  1589. { only these values disable filtering
  1590. DONT CHANGE THEM !!! PM }
  1591. gdb_command('set width 0xffffffff');
  1592. gdb_command('set height 0xffffffff');
  1593. { other standard commands used for fpc debugging }
  1594. gdb_command('set print demangle off');
  1595. gdb_command('set gnutarget auto');
  1596. gdb_command('set language auto');
  1597. gdb_command('set print vtbl on');
  1598. gdb_command('set print object on');
  1599. gdb_command('set print null-stop');
  1600. end;
  1601. destructor tgdbinterface.done;
  1602. begin
  1603. clear_frames;
  1604. gdb_done;
  1605. gdboutputbuf.done;
  1606. gdberrorbuf.done;
  1607. end;
  1608. procedure tgdbinterface.gdb__init;
  1609. begin
  1610. gdboutputbuf.reset;
  1611. gdberrorbuf.reset;
  1612. create_breakpoint_hook:=@CreateBreakPointHook;
  1613. end;
  1614. procedure tgdbinterface.gdb_done;
  1615. begin
  1616. if debuggee_started then
  1617. begin
  1618. current_target.to_kill;
  1619. current_target.to_close(1);
  1620. end;
  1621. create_breakpoint_hook:=nil;
  1622. end;
  1623. function tgdbinterface.error:boolean;
  1624. begin
  1625. error:=got_error;
  1626. end;
  1627. function tgdbinterface.error_num:longint;
  1628. begin
  1629. error_num:=gdb_error;
  1630. end;
  1631. var
  1632. top_level_val : longint;
  1633. {$ifdef GDB_V5}
  1634. function catch_errors(func : pointer; command : pchar; from_tty,mask : longint) : longint;cdecl;external;
  1635. function gdbint_execute_command(command : pchar; from_tty,mask : longint) : longint;cdecl;
  1636. begin
  1637. gdbint_execute_command:=1;
  1638. execute_command(command,from_tty);
  1639. gdbint_execute_command:=0;
  1640. end;
  1641. {$endif GDB_V5}
  1642. procedure tgdbinterface.gdb_command(const s:string);
  1643. var
  1644. command : array[0..256] of char;
  1645. {$ifdef GDB_V5}
  1646. mask : longint;
  1647. {$endif GDB_V5}
  1648. s2 : string;
  1649. old_quit_return,
  1650. old_error_return : jmp_buf;
  1651. begin
  1652. inc(command_level);
  1653. move(s[1],command,length(s));
  1654. command[length(s)]:=#0;
  1655. old_quit_return:=quit_return;
  1656. old_error_return:=error_return;
  1657. gdb_error:=0;
  1658. got_error:=false;
  1659. stop_breakpoint_number:=0;
  1660. { Trap quit commands }
  1661. s2:=s;
  1662. while (length(s2)>0) and ((s2[1]=' ') or (s2[1]=#9)) do
  1663. s2:=copy(s2,2,255);
  1664. if (length(s2)>0) and
  1665. (UpCase(s2[1])='Q') and
  1666. ((length(s2)=1) or
  1667. (s2[2]=' ') or
  1668. ((UpCase(s2[2])='U') and
  1669. ((length(s2)=2) or
  1670. (s2[3]=' ') or
  1671. ((UpCase(s2[3])='I') and
  1672. ((length(s2)=3) or
  1673. (s2[4]=' ') or
  1674. ((UpCase(s2[4])='T') and
  1675. ((length(s2)=4) or
  1676. (s2[5]=' ')
  1677. ))))))) then
  1678. begin
  1679. if not AllowQuit then
  1680. exit;
  1681. end;
  1682. {$ifdef DebugCommand}
  1683. Debug('start of handle_gdb_command ('+s+')');
  1684. {$endif}
  1685. top_level_val:=setjmp(error_return);
  1686. if top_level_val=0 then
  1687. begin
  1688. quit_return:=error_return;
  1689. {$ifdef GDB_V5}
  1690. mask:=$ffffffff;
  1691. catch_errors(@gdbint_execute_command,@command,0,mask);
  1692. {$else not GDB_V5}
  1693. execute_command(@command,0);
  1694. {$endif not GDB_V5}
  1695. {$ifdef go32v2}
  1696. reload_fs;
  1697. {$endif go32v2}
  1698. end
  1699. else
  1700. {$ifdef Debug}
  1701. Debug('error longjmp in handle_gdb_command ('+s+')');
  1702. {$endif}
  1703. ;
  1704. {$ifdef DebugCommand}
  1705. Debug('end of handle_gdb_command ('+s+')');
  1706. {$endif}
  1707. quit_return:=old_quit_return;
  1708. error_return:=old_error_return;
  1709. dec(command_level);
  1710. end;
  1711. procedure tgdbinterface.resize_frames;
  1712. var
  1713. i : longint;
  1714. new_frames : ppframeentry;
  1715. begin
  1716. if (frame_count>=frame_size) then
  1717. begin
  1718. getmem(new_frames,sizeof(pointer)*(frame_count+1));
  1719. for i:=0 to frame_size-1 do
  1720. new_frames[i]:=frames[i];
  1721. if assigned(frames) then
  1722. freemem(frames,sizeof(pointer)*frame_size);
  1723. frames:=new_frames;
  1724. frame_size:=frame_count+1;
  1725. for i:=frame_count to frame_size-1 do
  1726. frames[i]:=new(pframeentry,init);
  1727. end;
  1728. end;
  1729. function tgdbinterface.add_frameentry:pframeentry;
  1730. begin
  1731. resize_frames;
  1732. add_frameentry:=frames[frame_count];
  1733. inc(frame_count);
  1734. end;
  1735. function tgdbinterface.get_frameentry(level : longint) : pframeentry;
  1736. begin
  1737. { only climb values one by one PM }
  1738. if level>=frame_count then
  1739. resize_frames;
  1740. get_frameentry:=frames[level];
  1741. frames[level]^.clear;
  1742. if level>=frame_count then
  1743. inc(frame_count);
  1744. end;
  1745. procedure tgdbinterface.clear_frames;
  1746. var
  1747. i : longint;
  1748. begin
  1749. for i:=0 to frame_size-1 do
  1750. dispose(frames[i],done);
  1751. freemem(frames,sizeof(pointer)*Frame_size);
  1752. frame_count:=0;
  1753. frame_size:=0;
  1754. end;
  1755. function tgdbinterface.get_current_frame : longint;
  1756. begin
  1757. record_frames:=false;
  1758. gdb_command('f');
  1759. get_current_frame:=frame_level;
  1760. record_frames:=true;
  1761. end;
  1762. function tgdbinterface.set_current_frame(level : longint) : boolean;
  1763. var
  1764. s : string;
  1765. begin
  1766. record_frames:=false;
  1767. str(level,s);
  1768. gdb_command('f '+s);
  1769. if level=frame_level then
  1770. set_current_frame:=true
  1771. else
  1772. set_current_frame:=false;
  1773. record_frames:=true;
  1774. end;
  1775. {*****************************************************************************
  1776. Highlevel tgdbinterface
  1777. *****************************************************************************}
  1778. procedure tgdbinterface.GetAddrSyminfo(addr:longint;var si:tsyminfo);
  1779. var
  1780. sym : symtab_and_line;
  1781. symbol : psymbol;
  1782. begin
  1783. sym:=find_pc_line(addr,1);
  1784. fillchar(si,sizeof(tsyminfo),0);
  1785. si.address:=addr;
  1786. si.offset:=addr-sym.pc;
  1787. if assigned(sym.symtab) then
  1788. si.fname:=sym.symtab^.filename
  1789. else
  1790. si.fname:=nil;
  1791. si.line:=sym.line;
  1792. symbol:=find_pc_function(addr);
  1793. if assigned(symbol) then
  1794. si.funcname:=symbol^.ginfo._name
  1795. else
  1796. si.funcname:=nil;
  1797. end;
  1798. procedure tgdbinterface.SelectSourceLine(fn:pchar;line:longint);
  1799. begin
  1800. if assigned(fn) then
  1801. DoSelectSourceLine(StrPas(fn),line)
  1802. else
  1803. DoSelectSourceLine('',line);
  1804. end;
  1805. procedure tgdbinterface.StartSession;
  1806. begin
  1807. DoStartSession;
  1808. end;
  1809. procedure tgdbinterface.BreakSession;
  1810. begin
  1811. DoBreakSession;
  1812. end;
  1813. procedure tgdbinterface.EndSession(code:longint);
  1814. begin
  1815. Debuggee_started:=false;
  1816. {$ifdef Go32v2}
  1817. inferior_pid:=0;
  1818. {$endif}
  1819. DoEndSession(code);
  1820. end;
  1821. procedure tgdbinterface.DebuggerScreen;
  1822. begin
  1823. {$ifdef Debug}
  1824. Debug('|DebuggerScreen|');
  1825. {$endif}
  1826. if user_screen_shown then
  1827. DoDebuggerScreen;
  1828. user_screen_shown:=false;
  1829. end;
  1830. procedure tgdbinterface.UserScreen;
  1831. begin
  1832. {$ifdef Debug}
  1833. Debug('|UserScreen|');
  1834. {$endif}
  1835. if switch_to_user then
  1836. begin
  1837. if (not user_screen_shown) then
  1838. DoUserScreen;
  1839. user_screen_shown:=true;
  1840. end;
  1841. end;
  1842. {---------------------------------------
  1843. Default Hooks
  1844. ---------------------------------------}
  1845. procedure tgdbinterface.DoSelectSourceLine(const fn:string;line:longint);
  1846. {$ifdef Debug}
  1847. var
  1848. s : string;
  1849. {$endif}
  1850. begin
  1851. {$ifdef Debug}
  1852. Str(line,S);
  1853. Debug('|SelectSource '+fn+':'+s+'|');
  1854. {$endif}
  1855. end;
  1856. procedure tgdbinterface.DoStartSession;
  1857. begin
  1858. end;
  1859. procedure tgdbinterface.DoBreakSession;
  1860. begin
  1861. end;
  1862. procedure tgdbinterface.DoEndSession(code:longint);
  1863. begin
  1864. end;
  1865. procedure tgdbinterface.DoDebuggerScreen;
  1866. begin
  1867. end;
  1868. procedure tgdbinterface.DoUserScreen;
  1869. begin
  1870. end;
  1871. function tgdbinterface.AllowQuit : boolean;
  1872. begin
  1873. AllowQuit:=true;
  1874. end;
  1875. {$ifdef GDB_V5}
  1876. var
  1877. version : array[0..0] of char;cvar;external;
  1878. procedure error_init;cdecl;external;
  1879. {$else}
  1880. var
  1881. version : pchar;cvar;
  1882. {$endif}
  1883. function GDBVersion : string;
  1884. begin
  1885. GDBVersion:='GDB '+StrPas(version);
  1886. end;
  1887. const next_exit : pointer = nil;
  1888. procedure DoneLibGDB;
  1889. begin
  1890. exitproc:=next_exit;
  1891. {$ifdef GDB_V418}
  1892. if assigned(gdb_stdout) then
  1893. dispose(gdb_stdout);
  1894. gdb_stdout:=nil;
  1895. if assigned(gdb_stderr) then
  1896. dispose(gdb_stderr);
  1897. gdb_stderr:=nil;
  1898. {$endif GDB_V418}
  1899. end;
  1900. {$ifdef go32v2}
  1901. var
  1902. c_environ : ppchar;external name '_environ';
  1903. c_argc : longint;external name '___crt0_argc';
  1904. c_argv : ppchar;external name '___crt0_argv';
  1905. {$endif def go32v2}
  1906. {$ifdef GDB_V418}
  1907. {$ifndef go32v2}
  1908. {$ifndef win32}
  1909. var
  1910. stdout : p_c_file;cvar;external;
  1911. stderr : p_c_file;cvar;external;
  1912. {$endif win32}
  1913. {$else go32v2}
  1914. { the type is not really important
  1915. for external cvars PM
  1916. but the main problem is that stdout and stderr
  1917. and defined as macros under DJGPP !! }
  1918. var
  1919. __dj_stdout : c_file;cvar;external;
  1920. __dj_stderr : c_file;cvar;external;
  1921. {$endif go32v2}
  1922. {$endif not GDB_V418}
  1923. procedure InitLibGDB;
  1924. {$ifdef supportexceptions}
  1925. var
  1926. OldSigInt : SignalHandler;
  1927. {$endif supportexceptions}
  1928. begin
  1929. {$ifdef go32v2}
  1930. c_environ:=system.envp;
  1931. c_argc:=system.argc;
  1932. c_argv:=system.argv;
  1933. {$endif def go32v2}
  1934. {$ifdef supportexceptions}
  1935. {$ifdef go32v2}
  1936. OldSigInt:=Signal(SIGINT,SignalHandler(@SIG_DFL));
  1937. {$else}
  1938. OldSigInt:=Signal(SIGINT,SignalHandler(SIG_DFL));
  1939. {$endif}
  1940. {$endif supportexceptions}
  1941. {$ifdef GDB_V418}
  1942. new(gdb_stdout);
  1943. gdb_stdout^.ts_streamtype := afile;
  1944. {$ifndef go32v2}
  1945. {$ifdef win32}
  1946. gdb_stdout^.ts_filestream := _impure_ptr^.stdout;
  1947. {$else not win32 }
  1948. gdb_stdout^.ts_filestream := stdout;{p_c_file(textrec(output).handle); was wrong PM }
  1949. {$endif not win32 }
  1950. {$else go32v2}
  1951. gdb_stdout^.ts_filestream := @__dj_stdout;
  1952. {$endif go32v2}
  1953. gdb_stdout^.ts_strbuf := nil;
  1954. gdb_stdout^.ts_buflen := 0;
  1955. new(gdb_stderr);
  1956. gdb_stderr^.ts_streamtype := afile;
  1957. {$ifndef go32v2}
  1958. {$ifdef win32}
  1959. gdb_stderr^.ts_filestream := _impure_ptr^.stderr;
  1960. {$else not win32 }
  1961. gdb_stderr^.ts_filestream := stderr;
  1962. {$endif not win32 }
  1963. {$else go32v2}
  1964. gdb_stderr^.ts_filestream := @__dj_stderr;
  1965. {$endif go32v2}
  1966. gdb_stderr^.ts_strbuf := nil;
  1967. gdb_stderr^.ts_buflen := 0;
  1968. {$endif GDB_V418}
  1969. {$ifdef GDB_V5}
  1970. if assigned(gdb_stderr) then
  1971. ui_file_delete(gdb_stderr);
  1972. if assigned(gdb_stdout) then
  1973. ui_file_delete(gdb_stdout);
  1974. gdb_stderr:=mem_fileopen;
  1975. gdb_stdout:=mem_fileopen;
  1976. gdb_stdlog:=gdb_stderr;
  1977. gdb_stdtarg:=gdb_stderr;
  1978. set_ui_file_write(gdb_stdout,@gdbint_ui_file_write);
  1979. set_ui_file_write(gdb_stderr,@gdbint_ui_file_write);
  1980. error_init;
  1981. {$endif GDB_V5}
  1982. next_exit:=exitproc;
  1983. exitproc:=@DoneLibGDB;
  1984. gdb_init;
  1985. {$ifdef supportexceptions}
  1986. Signal(SIGINT,OldSigInt);
  1987. {$endif supportexceptions}
  1988. if setjmp(error_return)=0 then
  1989. begin
  1990. quit_return:=error_return;
  1991. exit;
  1992. end
  1993. else
  1994. begin
  1995. {$ifdef Debug}
  1996. Debug('|LongJump to Init|');
  1997. {$endif}
  1998. {$ifdef go32v2}
  1999. RunError(99);
  2000. {$endif def go32v2}
  2001. end;
  2002. WatchDog:=0;
  2003. end;
  2004. begin
  2005. InitLibGDB;
  2006. end.
  2007. {
  2008. $Log$
  2009. Revision 1.3 2000-10-08 10:07:22 peter
  2010. * merged fixes from Pierre
  2011. Revision 1.2 2000/07/13 11:33:15 michael
  2012. + removed logs
  2013. }