gdbint.pp 56 KB

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