I believe I may have found a way to provide a console for Linux GDB users.
The steps are:
- Create an Xterm
- Note the /dev/pts/# for that xterm
- Redirect the program I/O to that xterm
Proof of concept:
In a terminal window, issue the who command and note the second colume.
Mine shows:
Now start an Xterm. Issue it as "Xterm &" to keep your current terminal active.
And issue the "who" again. Note the new pts number representing the new tty /dev/pts/{some new number}
Mine looks like: /dev/pts/1
Issue a line of text to that tty. Like: echo "This is a test" >/dev/pts/1
Note that the output appears on the newly opened Xterm.
Now for Input. From terminal number 1, issue the command "cat </dev/pts/1".
From the new Xterm issue a couple of Ctrl-J to clear whoever is waiting for input, then you should see your typed chars redirected from New Xterm to the old terminal.
To get out of the situation, Ctrl-C on the old terminal.
Now for gdb: compile the following pgm as a Linux console pgm, making sure to use -g flag. I named my pgm "conio".
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
int upstring(char *value);
int main()
{
char value[81]={'\0'};
int upper_count;
cout << "Please type in a String (max. 80 characters): ";
cin.getline(value, 80);
upper_count=upstring(value);
cout << upper_count << " characters are converted" << endl;
cout << "The new string is now: " << value << endl;
return EXIT_SUCCESS;
}
int upstring(char *value)
{
int i=0;
while(*value)
{
if(islower(*value))
{
*value=toupper(*value);
i++;
}
value++;
}
return(i);
}
Run the pgm in terminal 1 like:
gdb consio
run </dev/pts/1 >/dev/pts/1
The gdb I/O stays in its own terminal, and the users I/O is redirected to the new Xterm.
The input is a bit problematic. I have to use Ctrl-J's to end a user input line in the Xterm (not a carriage return) and the prompt existing before the program started has to be cleared or else bash sees the input as a "bad command".
Also, chars dont seem to echo at the Xterm when the user is typing them in.
I think these problems might be solved with escape sequences redirected to the new Xterm.
But I'm no Xterm guru. Just hacking here.
The redirection on the run command can also be done with a "set inferior-tty /dev/pts/1" gdb command.
The point here? That the debugger plugin could control an Xterm console for the Linux user just as it does for Windows users.
Would some of you *nix guru's comment on this?
References:
http://developer.berlios.de/bugs/?func=detailbug&bug_id=7336&group_id=5358http://forums.codeblocks.org/index.php?topic=2958.0