Recent

Author Topic: readln problem on linux and gdb for console applications  (Read 12341 times)

vagk77

  • Guest
readln problem on linux and gdb for console applications
« on: December 31, 2005, 09:01:48 pm »
I have the problem below in linux. In windows it works.
I am trying to debug console applications with lazarus.
I know i cannot use the run parameters and execute on an external xterm with the gdb in linux.
So I run lazarus from console and watch the output there.
I can debug alright and see the output of writeln but when I have a readln in my program and it stops there it cannot proceed
I assume that the input I give from console to the readln conflicts and maybe goes to the lazarus IDE and not to my running console application. So I stuck here.
Does anyone know for a workaround to use readln and gdb for console applications in linux?
I am a teacher in a public school and I want to use lazarus in a teaching course and I want to show the debugger as well!!
[/b]

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: readln problem on linux and gdb for console applications
« Reply #1 on: January 01, 2006, 12:19:09 am »
Quote
I know i cannot use the run parameters and execute on an external xterm with the gdb in linux.


Why can't you? I have already done it and it works well. Of course, using the IDE is the prefered way (the easier way), but it works from the console too!

You just need to set a breakpoint for fpc_raiseexception and it will stop on all pascal exceptions. =)

Works pretty well.

Lazarus documentation can be found here: http://wiki.lazarus.freepascal.org/index.php/Lazarus_Documentation
And there is a page showing how to create a backtrace with gdb from the console and thus with ReadLn working here: http://wiki.lazarus.freepascal.org/index.php/Creating_a_Backtrace_with_GDB

Fell free to explore the wiki and even contribute if you wish so =)

Quote
I am a teacher in a public school and I want to use lazarus in a teaching course and I want to show the debugger as well!!


good to know people like the IDE!

And Happy New Year!!

Anonymous

  • Guest
RE: Re: readln problem on linux and gdb for console applicat
« Reply #2 on: January 05, 2006, 12:30:23 am »
First of all thank you for your answer

From freepascal in console I managed to run my program in the debugger.
Although I have some problems - the text is mixed somehow
I also managed to run it from gdb alone with gdb commands following your advice for fpc_raiseexception (it also execute without it as well)
Whenever The command is a writeln I see in the console messages like the following
along with the writeln output
[TDebugManager.OnDebuggerChangeState] state: dsPause
[TDebugManager.OnDebuggerChangeState] state: dsRun

but when it reaches a readln and I go to  console write sth and press enter it doesn't do a thing.
The same happens when I run normally and I don't use the debugger stepping,  so I can't even execute a program for console using lazarus this way
The only way I can execute console programs but without the debugger is to goto run/run parameters and check use launching application.
I want to use lazarus for my course just like I used delphi. Pressing F7-F8 in the source window and see the results in the console from which I started lazarus. Write sth in the console for readln and go back to the other window pressing F7-F8 to continue.

I prefer freepascal and lazarus from delphi for a lot of reasons. The main is that they are compatible with the programs I wrote in TurboPascal 7, sth that delphi isn't and ofcourse because they will continue to develop and grow better unlike kylix.
Right now i am stuck here. The thing that frustrates me is that in windows the debugger works in lazarus but I dislike teaching in windows.
If you have any other suggestions I would appreciate! Thanks!

valton

  • Newbie
  • Posts: 1
Re: readln problem on linux and gdb for console applications
« Reply #3 on: September 05, 2006, 10:11:14 am »
Quote from: "sekel"
Quote
I know i cannot use the run parameters and execute on an external xterm with the gdb in linux.


Why can't you? I have already done it and it works well. Of course, using the IDE is the prefered way (the easier way), but it works from the console too!

You just need to set a breakpoint for fpc_raiseexception and it will stop on all pascal exceptions. =)

Works pretty well.


hi, I am also teaching Pascal using Lazarus and I wish to teach the use of Lazarus debugger. For console application, until now I only managed to use it when debugging the program in the terminal where Lazarus was launched. It does not work when a external terminal is used for the application (via the run parameters). Although breakpoints are set, nothing happens, the application actually does not run and I get the following messages in the launch term:
[Debugger] Console output: ~"(no debugging symbols found)\n"
and
[Debugger] Log output: &"No source file named TP1.lpr.\n"
TGDBMIDebugger.ProcessResult Error: ,msg="No source file named TP1.lpr."

Is there a reason for that? How do you set breakpoints fo fpc_raiseexception?

Thanks in advance, in the name of the whole team!

Solene

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2583
RE: Re: readln problem on linux and gdb for console applicat
« Reply #4 on: September 05, 2006, 10:55:48 am »
Readln input and running apps through an external app is not supported for debugging.
ReadLn isn't supported because for the lazarus debugger there is no difference in passing text to the app or passing text to gdb, since both use the same stdin.
External apps arent supported because it doesn't work, and it has a very low priority to find out why.
The reason:
Lazarus is meant as gui tool for gui apps. gui apps usually don't read from stdin.

Quote

How do you set breakpoints fo fpc_raiseexception?

if you run gdb from the console, you can set a breakpoint by:
Code: [Select]
br FPC_RAISEEXCEPTION
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: readln problem on linux and gdb for console applications
« Reply #5 on: September 05, 2006, 12:45:55 pm »
Quote from: "valton"
For console application, until now I only managed to use it when debugging the program in the terminal where Lazarus was launched.


For console applications use the GNU Debugger. It´s executable is called gdb(.exe) and is distributed with Lazarus on Windows.

To use it, make sure gdb is on your PATH environment variable. On Windows it will be located at: C:\Lazarus\pp\bin\i386-win32

So you would write this on the DOS prompt after compiling the software:

PATH=C:\Lazarus\pp\bin\i386-win32

gdb myexecutable.exe

> break fpc_raiseexception

> run

When you hit an exception, write this to create a backtrace and find where it was:

> bt

 

TinyPortal © 2005-2018