gdbint.pp 60 KB

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