gdbint.pp 59 KB

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