[lldb-dev] How to redirect stdin/out/err to different pty?
eran.ifrah at gmail.com
Sun Mar 23 06:04:32 PDT 2014
Thanks for your pointer Piotr. Here is the code I am using to open a
pseudo-terminal (there is the UI part, which I left out):
memset(__name, 0, sizeof(__name));
m_slave = -1;
if(openpty(&master, &m_slave, __name, NULL, NULL) != 0)
// disable ECHO
struct termios termio;
termio.c_lflag = ICANON;
termio.c_oflag = ONOCR | ONLRET;
tcsetattr(master, TCSANOW, &termio);
m_tty = wxString(__name, wxConvUTF8);
At the end, m_tty contains a string name (e.g. /dev/pts/19 ).
Note that the above code works flawlessly when using it with gdb (i.e. if I
pass this "/dev/pts/19" to gdb's switch -tty=/dev/pts/19 I will get all the
inferior output/err/input to my internal terminal)
However, doing the same with LLDB (using C++ API not the command line ,
i.e. passing "/dev/pts/19" as an argument to SBTarget::Launch(...)) I get
nothing as output...
Also, I am not sure I am following the idea behind replacing the "Launch"
function with my own fork(), looking at the code of Launch() suggests that
it does more than a simple fork...
Any more hints?
On Sat, Mar 22, 2014 at 9:36 PM, Piotr Rak <piotr.rak at gmail.com> wrote:
> It should.
> Have you opened master pseudoterminal like?:
> int fd = posix_openpt(flags); // open("/dev/ptmx") might work here too but
> less portable;
> Depending on target you might need some bizarre ioctls here, but assuming
> you are using Linux/FreeBSD/MacOSX
> you should be fine.
> If you had already master pseudo-terminal file descriptor you can skip
> steps above.
> You can use ptsname for master file descriptor it will return you name of
> slave pseudo-terminal for your master.
> Later you can pass name returned by ptsname(fd) as Launch arguments.
> If above won't work you can try replacing Launch() call with ordinary
> fork, and in child process:
> slavefd = open(slavename, O_RDWR);
> dup2(0, slavefd);
> dup2(1, slavefd);
> dup2(2, slavefd);
> And see if that works alone for you...
> Good luck,
> 2014-03-22 19:29 GMT+01:00 Eran Ifrah <eran.ifrah at gmail.com>:
>> I am trying to use the C++ API with good success so far.
>> I am now at a point where I want to redirect stdin/out/err of the
>> inferior to my application (my application creates a separate pseudo
>> terminal window)
>> Looking at the SBTarget::Launch, I thought that simply passing
>> "/dev/pts/<some-number>" as the 3rd, 4th and 5th argument will do the trick
>> .. well, it did not.
>> I am missing something basic here, can anyone shed some light please? or
>> give an example (better) of how to achieve this?
>> Eran Ifrah
>> Author of codelite, a cross platform open source C/C++ IDE:
>> wxCrafter, a wxWidgets RAD: http://wxcrafter.codelite.org
>> lldb-dev mailing list
>> lldb-dev at cs.uiuc.edu
Author of codelite, a cross platform open source C/C++ IDE:
wxCrafter, a wxWidgets RAD: http://wxcrafter.codelite.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the lldb-dev