gdbint.pp 56 KB

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