* * *

Author Topic: No console window while debugging  (Read 2102 times)

Professor Distorto

  • New member
  • *
  • Posts: 7
No console window while debugging
« on: November 15, 2011, 01:54:03 am »
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

  • Hero Member
  • *****
  • Posts: 835
Re: No console window while debugging
« Reply #1 on: November 15, 2011, 02:21:42 am »
Quote
It 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.
Lazarus 0.9.31 r37217M FPC 2.5.1 r21251 x86_64-linux-qt/gtk2

Professor Distorto

  • New member
  • *
  • Posts: 7
Re: No console window while debugging
« Reply #2 on: November 15, 2011, 02:37:50 am »
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

  • Hero Member
  • *****
  • Posts: 1218
Re: No console window while debugging
« Reply #3 on: November 15, 2011, 04:09:02 am »
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

  • New member
  • *
  • Posts: 7
Re: No console window while debugging
« Reply #4 on: November 16, 2011, 08:25:06 pm »
WOW!
That's a lot of info coming at me in such a short notice!  :o Especially considering that I started using Linux and Lazarus roughly 1 month ago  :D
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

  • Hero Member
  • *****
  • Posts: 1218
Re: No console window while debugging
« Reply #5 on: November 16, 2011, 09:30:36 pm »
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).
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

  • New member
  • *
  • Posts: 7
Re: No console window while debugging
« Reply #6 on: November 16, 2011, 10:42:56 pm »
Quote
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.

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

  • Hero Member
  • *****
  • Posts: 1218
Re: No console window while debugging
« Reply #7 on: November 16, 2011, 11:22:15 pm »
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

  • New member
  • *
  • Posts: 7
Re: No console window while debugging
« Reply #8 on: November 16, 2011, 11:43:47 pm »
Quote
If 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" ?
« Last Edit: November 16, 2011, 11:47:22 pm by Professor Distorto »

Martin_fr

  • Hero Member
  • *****
  • Posts: 1218
Re: No console window while debugging
« Reply #9 on: November 17, 2011, 01:28:43 am »
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/pty1

Another option I never tried or looked into is the "debugger startup options" (from that config page)
It may be possible to somehow pass a command to gdb do redirect the console-tty. the gdb command is:
   set-inferior-tty  /dev/pty1
or whatever the actual pty is.

Not sure if it can be set via the gdb commandline. Never tried.


0.9.30.2 is about to be released. But it has none of the improvements. Its bug fixes only.

Professor Distorto

  • New member
  • *
  • Posts: 7
Re: No console window while debugging
« Reply #10 on: November 19, 2011, 07:09:28 pm »
Hi again!
I did following:
1. Opened a new Konsole terminal
2. Entered "tty" command to find out where it's mounted. Since it's the only terminal open >/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
« Last Edit: November 19, 2011, 07:21:45 pm by Professor Distorto »

Martin_fr

  • Hero Member
  • *****
  • Posts: 1218
Re: No console window while debugging
« Reply #11 on: November 19, 2011, 08:26:56 pm »
In the "Run" menu "Run param" set the command line param:
>/dev/pts/1 </dev/pts/1

Also make sure bash (or whatever shell you use) isnt reading from that terminal. Try running "tail -f emptyfile"

though here I need to press enter in order for any of my input to get through

Professor Distorto

  • New member
  • *
  • Posts: 7
Re: No console window while debugging
« Reply #12 on: November 19, 2011, 09:50:50 pm »
Wow you're right! The program WAS indeed running and the I/O was redirected to the terminal. The problem was that it doesn't echo back the input. And yes, BASH is running as well which interferes with the program.
I used Ctrl + J to input new lines. I will try "tail" command as you said.

BTW I saw the option "-Sccn" in the xterm manual; I guess with this option it is possible to open a XTerm as a slave? I tried it and it does that, but I cannot get the pty handle for it (bash is off I guess).

Martin_fr

  • Hero Member
  • *****
  • Posts: 1218
Re: No console window while debugging
« Reply #13 on: November 19, 2011, 11:29:30 pm »
Good to hear.

I am not an expert on xterm, so I don't know the answers to that.

As I said before, the goal is for Lazarus to have a build in console window. It is started in 0.9.30, but input is currently limited to normal keys, like a-z, 0-9, space, tab, backspace, return.
Yet missing support for cursor keys, F keys,... Basically it has no ANSI (escape sequences) support yet.

Same limit for output, no ANSI.

maheffa32

  • Newbie
  • Posts: 1
Re: No console window while debugging
« Reply #14 on: March 01, 2012, 10:39:51 am »
I just went to run> 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.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads