Difference between revisions of "Debugger Console App"
(Typos/grammar, updated to show applicability for 1.0 and higher, added to Lazarus category) |
|||
Line 1: | Line 1: | ||
== Introduction == | == Introduction == | ||
− | This page contains information | + | This page contains information on how to debug console applications in Lazarus. That is where to find the output (writeln) of your app, and where to type the input (readln). |
This page was written for Lazarus 0.9.30 and above. | This page was written for Lazarus 0.9.30 and above. | ||
Line 7: | Line 7: | ||
== Windows == | == Windows == | ||
− | On Windows the app will open | + | On Windows, the app will open its own console window, just as it would outside the debugger. There is no need to do anything special. |
== Linux == | == Linux == | ||
Line 13: | Line 13: | ||
=== Lazarus 0.9.30 / 0.9.30.2 === | === Lazarus 0.9.30 / 0.9.30.2 === | ||
− | Please see the notes | + | Please see the notes in the[[#Mac]] section. |
− | === Lazarus 0.9.31 === | + | === Lazarus 0.9.31 / 1.0 and higher === |
You can open a console window from the menu: "View" => "Debug Windows" => "Terminal" | You can open a console window from the menu: "View" => "Debug Windows" => "Terminal" | ||
Line 21: | Line 21: | ||
It shows the raw output of your application. Note it has no support for any escape sequences, as some terminals may have. | It shows the raw output of your application. Note it has no support for any escape sequences, as some terminals may have. | ||
− | Anything you type into this window | + | Anything you type into this window will be sent to your app. |
== Mac == | == Mac == | ||
− | Unfortunately there is currently no | + | Unfortunately there is currently no built-in support for debugging console applications. |
Console apps do not have their own terminal, but use the terminal they were started from (the terminal of the shell they were started from). | Console apps do not have their own terminal, but use the terminal they were started from (the terminal of the shell they were started from). | ||
− | When started from within Lazarus, there is no such terminal. You can specify a "starter application" (like xterm) under menu "Run" => "Run parameters". however this only works | + | When started from within Lazarus, there is no such terminal. You can specify a "starter application" (like xterm) under menu "Run" => "Run parameters". however this only works if you start your app without a debugger. '''This does not work for debugging.''' |
− | There are a couple of workarounds. | + | There are a couple of workarounds. |
=== Redirect output to file === | === Redirect output to file === | ||
− | In menu "Run" => "Run parameters" specify in "command line parameters": | + | In menu "Run" => "Run parameters": specify in "command line parameters": |
>/somedir/somefile | >/somedir/somefile | ||
Then outside Lazarus open a shell and run | Then outside Lazarus open a shell and run | ||
− | + | <syntaxhighlight lang="bash"> | |
+ | tail -f /somedir/somefile | ||
+ | </syntaxhighlight> | ||
=== Redirect input and output to a pty (terminal) === | === Redirect input and output to a pty (terminal) === | ||
Line 45: | Line 47: | ||
It should return something like | It should return something like | ||
/dev/pty/2 | /dev/pty/2 | ||
− | The exact value depends on OS and the number of terminals already open. | + | The exact value depends on the OS and the number of terminals already open. |
− | ;Note: The returned value is only valid | + | ;Note: The returned value is only valid as long as the terminal stays open, so if you open a new terminal next time you debug in Lazarus, you need to adapt all settings to the new value. |
− | In menu "Run" => "Run parameters" specify in "command line parameters": | + | In menu "Run" => "Run parameters": specify in "command line parameters": |
>/dev/pty/2 </dev/pty/2 | >/dev/pty/2 </dev/pty/2 | ||
If you want to use the terminal to send input to your app, then you may need to stop the shell in it from reacting to the input (Unless you started a terminal without a shell). | If you want to use the terminal to send input to your app, then you may need to stop the shell in it from reacting to the input (Unless you started a terminal without a shell). | ||
Run something like | Run something like | ||
− | + | <syntaxhighlight lang="bash"> | |
− | Note | + | tail -f /some/empty/file/that/does/not/change |
+ | </syntaxhighlight> | ||
+ | {{Note|This means you still can't use ctrl-c in the input.}} | ||
==== Debugger startup options ==== | ==== Debugger startup options ==== | ||
− | In the global | + | In the global options dialog, on the debugger page, you can specify params given to gdb (do '''not''' use the in/output redirect ">" / "<" here, use something like --args). |
− | It may be possible specify the pty here, but there is currently no further info | + | It may be possible to specify the pty here, but there is currently no further info. |
=== Lazarus 0.9.31 === | === Lazarus 0.9.31 === | ||
− | In the global | + | In the global options dialog, on the debugger page is an entry "ConsoleTty". You can enter the result of "pty" here. Then you do not need to specify any "<" / ">" redirects. |
== See also == | == See also == | ||
Line 72: | Line 76: | ||
[[Category:Debugging]] | [[Category:Debugging]] | ||
+ | [[Category:Lazarus]] |
Revision as of 12:39, 14 March 2013
Introduction
This page contains information on how to debug console applications in Lazarus. That is where to find the output (writeln) of your app, and where to type the input (readln).
This page was written for Lazarus 0.9.30 and above.
Windows
On Windows, the app will open its own console window, just as it would outside the debugger. There is no need to do anything special.
Linux
Lazarus 0.9.30 / 0.9.30.2
Please see the notes in the#Mac section.
Lazarus 0.9.31 / 1.0 and higher
You can open a console window from the menu: "View" => "Debug Windows" => "Terminal"
It shows the raw output of your application. Note it has no support for any escape sequences, as some terminals may have.
Anything you type into this window will be sent to your app.
Mac
Unfortunately there is currently no built-in support for debugging console applications.
Console apps do not have their own terminal, but use the terminal they were started from (the terminal of the shell they were started from). When started from within Lazarus, there is no such terminal. You can specify a "starter application" (like xterm) under menu "Run" => "Run parameters". however this only works if you start your app without a debugger. This does not work for debugging.
There are a couple of workarounds.
Redirect output to file
In menu "Run" => "Run parameters": specify in "command line parameters":
>/somedir/somefile
Then outside Lazarus open a shell and run
tail -f /somedir/somefile
Redirect input and output to a pty (terminal)
Open a terminal outside of Lazarus and run
pty
It should return something like
/dev/pty/2
The exact value depends on the OS and the number of terminals already open.
- Note
- The returned value is only valid as long as the terminal stays open, so if you open a new terminal next time you debug in Lazarus, you need to adapt all settings to the new value.
In menu "Run" => "Run parameters": specify in "command line parameters":
>/dev/pty/2 </dev/pty/2
If you want to use the terminal to send input to your app, then you may need to stop the shell in it from reacting to the input (Unless you started a terminal without a shell). Run something like
tail -f /some/empty/file/that/does/not/change
Debugger startup options
In the global options dialog, on the debugger page, you can specify params given to gdb (do not use the in/output redirect ">" / "<" here, use something like --args).
It may be possible to specify the pty here, but there is currently no further info.
Lazarus 0.9.31
In the global options dialog, on the debugger page is an entry "ConsoleTty". You can enter the result of "pty" here. Then you do not need to specify any "<" / ">" redirects.