No console window while debugging lazarus / 12-Debugger ---------------------------------------------------------------------- Professor Distorto · 2011-11-15 00:54 Hi, I have a question about gdb 7.1  and Lazarus 0.9.30, which I'm running on a 64-bit Pardus 2011 Linux OS. So I'm trying to learn how to use Lazarus and FPC in general and I wrote a simple program (New->Pascal Program). It compiles fine and when I run it without the debugger it shows a console type window, as it should. Everything works properly. When I try to debug it using gdb however, it runs as well but without that console window! Why is this happening and is there something related to the initialization and settings that I overlooked? Perhaps the console is suppressed? I tried to look everywhere in the countless options for the project and environment, but I couldn't find anything related to that. note: just to be sure I tried to compile a "Console Application" project in contrast to the regular "Program" project but I still get the same result. I tried a "Form" application and I don't get this problem. Please excuse me if the question was answered before, but I couldn't find a lot of info about this on the internet. Thanks in advance! ---------------------------------------------------------------------- Blaazen · 2011-11-15 01:21 QuoteIt compiles fine and when I run it without the debugger it shows a console type window, as it should.I don't know if Lazarus should show some console type window automaticly. However, I use: View -> Debug Windows -> Terminal Output (Ctrl+Alt+O) where you can see output of all your WriteLn, DebugLn commands. This works with debugger (breakpoints works here). You can also use: Run -> Run Parameters ... -> Launching Application This option will launch your program in "xterm", out of debugger. ---------------------------------------------------------------------- Professor Distorto · 2011-11-15 01:37 Hi, thank you very much for the quick response. The problem doesn't relate so much to the absence of a console, but rather to the fact that I can't get general input going on (read, readln, etc..). Otherwise I can do just fine without the console. As funny as it sounds, I don't get this "console" problem on windows, but then again on Windows I cannot debug 64-bit applications for some reason (which is not a problem for now). Regardless, I will try your suggestions and see where I can go from there. ---------------------------------------------------------------------- Martin_fr · 2011-11-15 03:09 On windows there is a known problem. You can either: - use FPC 2.6.0 and you should be able to debug. - Try Stabs, sometimes works, but not sure, if always http://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Win_64_bit As for your linux issue: I do not know what opens the terminal for you. Unlike windows on linux an application does not have it's own terminal, but uses the window of the terminal from which it was started, If double clicked an icon on the desktop, I do not know, but usually there is no terminal. If started from Lazarus (debugger disabled), I wouldn;t expect one (unless configured under "Run" > "Run param". But it may be that on your system TProcess creates the terminal.... If you have a console app or plain program, then Lazarus probably somewhere opens the terminal... And yes in the debugger you are not getting that. In older lazarus, you could start Lazarus from a terminal, and then your program's in/output would be on that console. There were several changes (at different times), and I am not sure which are already in 0.9.30 (including 0.9.30.2) and which are only in 0.9.31 In 0.9.31 you have a console window. It has an input field, but that's only good for readln, not for read. Another option is in the Tools or Environment menu, under "Options" > "debugger" you find an object ispector like grid, that allows to set a "console tty" Open a terminal (outside lazarus), and run "pty" , you get something like /dev/pty1 Enter that as config, and your apps in/output go to that terminal. ---------- The problem with the original solution was that your apps output went into the same stream as the gdb output (which the IDE must read), in some cases this could hang the IDE, as it would not recolonize a token returned by gdb and wait forever. The terminal window is the solution that should be used instead => but it needs still work. (Ideally a full terminal emulation). ---------------------------------------------------------------------- Professor Distorto · 2011-11-16 19:25 WOW! That's a lot of info coming at me in such a short notice!  Especially considering that I started using Linux and Lazarus roughly 1 month ago  So there normally shouldn't be a console window appearing, even in non-debug mode? That's quite strange, but here's a screenshot of what appears when I run my app (see attachment). This is running without any debugger (Environment > Options > Debugger > None). Also notice that I started the application through Lazarus! Appears to be an XTerm terminal application, that handles all the reading/writing. So my question now is, what is the best way to "divert" all the I/O operations through some sort of terminal-like program while debugging, because I still need to do some user interaction you know. ---------------------------------------------------------------------- Martin_fr · 2011-11-16 20:30 Quote from: Professor Distorto on November 16, 2011, 08:25:06 pmSo there normally shouldn't be a console window appearing, even in non- debug mode? That's quite strange, but here's a screenshot of what appears when I run my app (see attachment). Let me clarify this: Under Linux a  console app does not have it's own window like it does under Windows, but outside the debugger Lazarus will run it in xterm or similar. When running in the debugger this wouldn't work, it would debug xterm Quote This is running without any debugger (Environment > Options > Debugger > None). Also notice that I started the application through Lazarus! Appears to be an XTerm terminal application, that handles all the reading/writing. So my question now is, what is the best way to "divert" all the I/O operations through some sort of terminal-like program while debugging, because I still need to do some user interaction you know. Read my last mail: Lazarus 0.9.31 has a console window in the debug window section. But it only allows inputting entire lines with return, not individual chars (unless your app does not mind the return) otherwise see the bit about setting a console tty (that is avail in 0.9.30 ---------------------------------------------------------------------- Professor Distorto · 2011-11-16 21:42 QuoteAnother option is in the Tools or Environment menu, under "Options" > "debugger" you find an object ispector like grid, that allows to set a "console tty" Open a terminal (outside lazarus), and run "pty" , you get something like /dev/pty1 Enter that as config, and your apps in/output go to that terminal. Okay, I opened a "Konsole" terminal and typed in "tty", telling me that the terminal is located at /dev/pts/1. However I do not see the "configuration" options you speak of in Environment > Options > Debugger, i.e. "object ispector like grid, that allows to set a "console tty"" Perhaps I see it and it's there but I don't know which one it is. Care to clarify a little bit more? ---------------------------------------------------------------------- Martin_fr · 2011-11-16 22:22 Ok you are on the right screen, so maybe I got the versions wrong. I only have 0.9.31 running. Maybe that was added later, if so then in 0.9.30 you may be able to see the output of your app, by starting lazarus from console. But that does not allow input... If so you will need to use a snapshot 0.9.31; not 0.9.30.x ---------------------------------------------------------------------- Professor Distorto · 2011-11-16 22:43 QuoteIf so you will need to use a snapshot 0.9.31; not 0.9.30.x Hmm, I think I will stick to the current stable release until this is officially released and just insert "writeln" lines in the code if I want to test something. Pretty unfortunate if I may say so myself, I never liked this type of "debugging"  It's funny because I originally expected more functionality for Linux, since IMO it's a more programming-friendly OS than Windows. In any case, I can't wait for 0.9.31 and I will surely try out the snapshot for feedback purposes! Thanks a lot Martin_fr! EDIT: Still is it possible to add the option of redirecting I/O to an external console from gdb manually using "Debugger_Startup_Options" ? ---------------------------------------------------------------------- Martin_fr · 2011-11-17 00:28 For the output of your app, see either: - the "debug output window" ( "View" > "Debug"), a  mix of gdb and your app - start lazarus from console, and watch that console(not sure, but I think that works / output only) - start your app with output redirect. If you know the input in advance you may be able to redirect that too. Not tested, but maybe you can debug your app as ("Run parameters"):   app >/dev/pty1 /dev/pts/1 3. Entered the following option in "Environment > Options > Debugger > gdb > Debugger_Startup_Options" - "--tty=/dev/pts/1" 4. Ran my application I got the following warning: "&"warning: GDB: Failed to set controlling terminal: Operation not permitted\n"". After this line I got the output of my program, but couldn't do any input. 7. Tried step 4 with the "su" command entered in the terminal. Same result. Interestingly enough I also have the same warning in other IDE's like Code::Blocks. So it must be more debugger related rather than IDE related. Perhaps I should run Lazarus with "sudo" command. Overall I think I'm getting somewhere :-) edit: added a screenshot of my terminal ---------------------------------------------------------------------- Martin_fr · 2011-11-19 19:26 In the "Run" menu "Run param" set the command line param: >/dev/pts/1 run application > local then check the box : "use launching application" and as launching aplication I had "/usr/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh (TargetCmdLine)" , it will pop up a little xterm windows, as well as it happens in windows.