<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">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):</div>
<div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">
<br></div><div class="gmail_default"><div class="gmail_default"><font face="courier new, monospace"> char __name[128];</font></div><div class="gmail_default"><font face="courier new, monospace"> memset(__name, 0, sizeof(__name));</font></div>
<div class="gmail_default"><font face="courier new, monospace"><br></font></div><div class="gmail_default"><font face="courier new, monospace"> int master(-1);</font></div><div class="gmail_default"><font face="courier new, monospace"> m_slave = -1;</font></div>
<div class="gmail_default"><font face="courier new, monospace"> if(openpty(&master, &m_slave, __name, NULL, NULL) != 0)</font></div><div class="gmail_default"><font face="courier new, monospace"> return wxT("");</font></div>
<div class="gmail_default"><font face="courier new, monospace"><br></font></div><div class="gmail_default"><font face="courier new, monospace"> // disable ECHO</font></div><div class="gmail_default"><font face="courier new, monospace"> struct termios termio;</font></div>
<div class="gmail_default"><font face="courier new, monospace"> tcgetattr(master, &termio);</font></div><div class="gmail_default"><font face="courier new, monospace"> termio.c_lflag = ICANON;</font></div><div class="gmail_default">
<font face="courier new, monospace"> termio.c_oflag = ONOCR | ONLRET;</font></div><div class="gmail_default"><font face="courier new, monospace"> tcsetattr(master, TCSANOW, &termio);</font></div><div class="gmail_default">
<font face="courier new, monospace"><br></font></div><div class="gmail_default"><font face="courier new, monospace"> m_tty = wxString(__name, wxConvUTF8);</font></div><div class="gmail_default"><font face="courier new, monospace"><br>
</font></div><div class="gmail_default"><font face="verdana, sans-serif">At the end, m_tty contains a string name (e.g. /dev/pts/19 ).</font></div><div class="gmail_default"><font face="verdana, sans-serif">Note that the above code works flawlessly when using it with gdb (i.e. i</font><font face="verdana, sans-serif">f I pass this "</font><span style="font-family:verdana,sans-serif">/dev/pts/19" to gdb's switch -tty=/dev/pts/19 I will get all the inferior output/err/input to my internal terminal)</span></div>
<div class="gmail_default"><span style="font-family:verdana,sans-serif"><br></span></div><div class="gmail_default"><span style="font-family:verdana,sans-serif">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...</span></div>
<div class="gmail_default"><span style="font-family:verdana,sans-serif"><br></span></div><div class="gmail_default"><span style="font-family:verdana,sans-serif">Also, I</span><span style="font-family:verdana,sans-serif"> 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...</span></div>
<div class="gmail_default"><span style="font-family:verdana,sans-serif"><br></span></div><div class="gmail_default"><span style="font-family:verdana,sans-serif">Any more hints?</span></div><div class="gmail_default"><span style="font-family:verdana,sans-serif">Eran</span></div>
<div class="gmail_default"><span style="font-family:verdana,sans-serif"><br></span></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Mar 22, 2014 at 9:36 PM, Piotr Rak <span dir="ltr"><<a href="mailto:piotr.rak@gmail.com" target="_blank">piotr.rak@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>It should.</div><div>Have you opened master pseudoterminal like?:</div><div><br>
</div>
<div>int fd = posix_openpt(flags); // open("/dev/ptmx") might work here too but less portable;</div>
<div>grantpt(fd);</div><div>unlockpt(fd);</div><div><br></div><div><div>Depending on target you might need some bizarre ioctls here, but assuming you are using Linux/FreeBSD/MacOSX</div><div>you should be fine.</div><div>
<br></div></div><div>If you had already master pseudo-terminal file descriptor you can skip steps above.</div><div><br></div><div>You can use ptsname for master file descriptor it will return you name of slave pseudo-terminal for your master.<br>
</div><div>Later you can pass name returned by ptsname(fd) as Launch arguments.</div><div><br></div><div>If above won't work you can try replacing Launch() call with ordinary fork, and in child process:</div><div><br>
</div><div>slavefd = open(slavename, O_RDWR);</div><div><br></div><div>dup2(0, slavefd);</div><div>dup2(1, slavefd);</div><div>dup2(2, slavefd);</div><div><br></div><div>And see if that works alone for you...</div><div><br>
</div><div>Good luck,</div><div>/Piotr</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-03-22 19:29 GMT+01:00 Eran Ifrah <span dir="ltr"><<a href="mailto:eran.ifrah@gmail.com" target="_blank">eran.ifrah@gmail.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">
Hello,</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">
<br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">
I am trying to use the C++ API with good success so far.</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">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)</div>
<div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">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.</div>
<div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">I am missing something basic here, can anyone shed some light please? or give an example (better) of how to achieve this? </div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">
<br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Thanks!<span><font color="#888888"><br></font></span></div><span><font color="#888888"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">
<br></div><div>-- <br></div><div dir="ltr">
Eran Ifrah<br>Author of codelite, a cross platform open source C/C++ IDE: <a href="http://www.codelite.org" target="_blank">http://www.codelite.org</a><br><div>wxCrafter, a wxWidgets RAD: http://<a href="http://wxcrafter.codelite.org" target="_blank">wxcrafter.codelite.org</a></div>
</div>
</font></span></div>
<br></div></div>_______________________________________________<br>
lldb-dev mailing list<br>
<a href="mailto:lldb-dev@cs.uiuc.edu" target="_blank">lldb-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Eran Ifrah<br>Author of codelite, a cross platform open source C/C++ IDE: <a href="http://www.codelite.org" target="_blank">http://www.codelite.org</a><br>
<div>wxCrafter, a wxWidgets RAD: http://<a href="http://wxcrafter.codelite.org" target="_blank">wxcrafter.codelite.org</a></div></div>
</div>