gdbint.pp 60 KB

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