gdbint.pp 59 KB

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