Author Topic: How to debug a program which contains input from stdin??  (Read 7585 times)

mikeandmore

  • Guest
How to debug a program which contains input from stdin??
« on: January 30, 2007, 02:32:03 am »
like that...
Code
int main(int argc, char* argv[])
{
    int a;
    cin >> a;
    return 0;
}


if i put a breakpoint in the line "return 0",codeblocks will wait until it crash...

ubuntu feisty + gcc 4.1.2 + codeblocks(uni)svn (lastest) + wx2.6.3
« Last Edit: January 30, 2007, 02:34:22 am by mikeandmore »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2814
Re: How to debug a program which contains input from stdin??
« Reply #1 on: January 30, 2007, 04:11:46 am »
I can't even get that example to compile, much less run and debug.

What happened to "using namespace std;"?

mikeandmore

  • Guest
Re: How to debug a program which contains input from stdin??
« Reply #2 on: February 02, 2007, 01:04:07 am »
...i just give a little sample ..... for human read.....
Code
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int a;
    cin >> a;
    return a;
}


Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2814
Re: How to debug a program which contains input from stdin??
« Reply #3 on: February 02, 2007, 01:17:59 am »
...i just give a little sample ..... for human read.....
Code
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int a;
    cin >> a;
    return a;
}


Ok. Currently CB cannot open a linux console when in gdb debugging mode.
It's being worked on.

However, there is a very nice program called CGDB that opens a window with three pseudo terminals for you to debug in.



The top holds the source of your program, the middle takes input/output for your program, and the bottom manages the gdb command and gdb I/O.

Simply compile your program via CB (say MyProggy), then issue the command "cgdb MyProggy" to start the debugger.

You can start cgdb in a terminal/tty/xterm or create a tool in the Tool menu to do it. If done via the Tools menu it will start cgdb with your program as the target with a single click.

You will have to issue gdb commands directly in the bottom window. Such as "b line#" for break, "n" for next line, "s" to step into,"c" to continue, etc.

There's a "man cgdb" that summarizes commands to handle the pseudo terminals, like: esc-T to enter input into the program I/O window; esc-i to re-enter the gdb window etc.

This program is available via source or binary. On ubuntu its available via your synaptic downloader.

You can also google it.

The CB team is actively working to alleviate this situation.

« Last Edit: February 02, 2007, 01:39:22 am by Pecan »