Rigging a Lazarus/FPC Console Test Harness lazarus / 12-Debugger ---------------------------------------------------------------------- Cfidicus · 2014-02-26 02:00 Lazarus Console Test Harness ---------------------------- Used for testing a console program's source code with Lazarus' GDB debugger under FreeBSD 9.2. # 2014-02-23  by Mark L. Rathbun (A.K.A. Cfidicus) # System: PC-BSD/FreeBSD 9.2-RELEASE-p1 (amd64) #         x86-64-freebsd-gtk 2 #         AMD FX-6100 Six-Core Processor #         7.97 GB RAM #         KDE v. 4.10.5_1, Gnome 2.3.2.1, LXDE 1.0_5 #         Lazarus v 1.0.2, Date: 2014-02-20 #         FPC v 2.6.2 #         SVN Revision: Unknown #         GDB v7.6.1 for FreeBSD program LazConsoleTestHarness; begin   ... end. This program, see attached, was created using Lazarus' console project template which uses TProcess to couch a programmer's console source code. It successfully runs as a console app. Debugging it with gdb in Lazarus requires that a terminal window be opened independently of Lazarus. Keystrokes, including Ctrl-c, performed properly within the console. LIMITATIONS ----------- This debugging arrangement only tested connecting a Lazarus console program being debugged in the Lazarus IDE environment to a free running console.  Only Readln and Writeln statements were tested.  Other coding statements relevant to console programs were not tested, therefore other limitations/problems are not known. SETUP: ------ Ensure that GDB v7.6.1 is installed. In Lazarus IDE's "Run -> Run Parameters -> Use Launching Application" string field, this string (modified from what shipped with Lazarus) was saved and the checkbox checked OFF, and the "Run -> Run Parameters -> Use Display " is also checkbox checked OFF. KDE's konsole was launched, and within it, the command tty was issued to find out which console it was. In this test it was /dev/pts/3 Next, this string was placed in Lazarus' Tools->Options...->Debugger->General ConsoleTty field, and saved. A special, separately compiled console program is launched in konsole running on /dev/pts/3 using this at the commandline:           ./nextcrewl >/dev/pts/3 New Project... -> Console application"). Set breakpoints and step through this source code. Respond to Readln and Readln(s) statements by entering keystrokes in konsole (/dev/pts/3), completed with the ENTER key. RESULTS: -------- Lazarus' GDB hooks into the nextcrewl running on /dev/pts/3 where nextcrewl is displaying "0$ " in konsole and waits for input for its first pass on its Readln statement. While nextrewl is waiting on its Readln statement, GDB hooks to it as a result of starting this program, LazConsoleTestHarness, via RUN, F9, F8, or F7. GDB displays a hook message in konsole, which looks like this: Code: [Select]0$ &"warning: GDB: Failed to set controlling terminal: Operation not  permitted\n Writeln('literal') statements in LazConsoleTestHarness are displayed on /dev/pts/3, completed with a new line (\n).  These cause the display in konsole to look something like this: Code: [Select][mrathbun@kti-a61~/tests]$ ./nextcrewl >/dev/pts/3 /dev/pts/3 Debug Windows > Console output) (This only works, if you remove all the tty settings) Have you checked if that exists/works on Freebsd? (I do not know, I newer tested) Though this build in Window does not have any terminal emulation, just raw in/output. Some of the info  (but nothing that you did not describe in more detail) is also here: http://wiki.lazarus.freepascal.org/Debugger_Console_App ---------------------------------------------------------------------- Cfidicus · 2014-02-26 02:29 Unfortunately, under FreeBSD, Lazarus has no debug window "console output" (Menu: View > Debug Windows > Console output), therefore this technique is necessary. ---------------------------------------------------------------------- Martin_fr · 2014-02-26 03:11 Ah yes. Code: [Select]{$IFDEF linux} {$DEFINE DBG_ENABLE_TERMINAL} {$ENDIF} But it may be worth testing it. The code should be similar. It is all about the IDE creating a tty of its own. If you want, try to define it, maybe it works.