<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Hello Greg,</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Thanks for the input. It still does not work ( I rewrote my terminal code to look similar to lldb's <span style="font-size:12.727272033691406px;font-family:arial,sans-serif">PseudoTerminal, and it is still not working)</span></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">To simplify things, I tried some basic things with the <b>command line</b> tool 'lldb':</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 created a file ~/.lldbinit with the following content:<br>

</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="verdana, sans-serif">eran@eran-linux: ~/llvm/build/bin $ cat ~/.lldbinit </font></div>

<div class="gmail_default"><font face="verdana, sans-serif">settings set target.output-path /tmp/dbg.out</font></div><div class="gmail_default"><font face="verdana, sans-serif">eran@eran-linux: ~/llvm/build/bin $</font></div>

<div class="gmail_default"><font face="verdana, sans-serif"><br></font></div></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">I then ran lldb while having tail -f /tmp/dbg.out& in another terminal to see if the stdout is being redirected</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">Now, this is the interesting part:</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">

In the first run when the file /tmp/dbg.out was empty - the redirection worked (tail showed the debuggee stdout)</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">In the second run (and later) - nothing was written to the file</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">However, if I truncate the file using the below command:</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">$ > /tmp/dbg.out</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">and run lldb again - I see the stdout again - but same as before only for the first time (i.e. as long as the file is empty the stdout was redirected)</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">The next thing I tried was to use a terminal name for redirection:</div>

<div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-size:small"><span style="font-family:verdana,sans-serif">- Open a new terminal and type `</span><font face="courier new, monospace">tty</font><font face="verdana, sans-serif">` (in my case it gave </font><span style="font-family:'courier new',monospace">/dev/pts/19 )</span><br>

</div><div class="gmail_default" style="font-size:small"><span style="font-family:verdana,sans-serif">- Edit the ~/.lldbinit: </span><font face="courier new, monospace">settings set target.output-path /dev/pts/19</font></div>

<div class="gmail_default" style="font-size:small"><span style="font-family:verdana,sans-serif">- Start lldb and verify that the setting is set properly by running: </span><font face="courier new, monospace">settings show target.output-path</font></div>

<div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">- Run the program under lldb - the output is not redirected (i.e. it is show in the same console where I ran lldb)</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">Any ideas?</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">

P.S. </div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Sorry if this looks like a voodoo, but this is what I am getting here... ;)</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">Eran</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">


<br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Mar 24, 2014 at 6:46 PM, Greg Clayton <span dir="ltr"><<a href="mailto:gclayton@apple.com" target="_blank">gclayton@apple.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Check out the PseudoTerminal class in trunk/source/Utility/PseudoTerminal.cpp.<br>
<br>
See the function named PseudoTerminal::OpenFirstAvailableMaster(...). You must call posix_openpt, grantpt, and unlockpt. I am guessing that because you aren't calling grantpt and granting access to the slave you are failing to be able to use the slave in your child process.<br>


<span class="HOEnZb"><font color="#888888"><br>
Greg Clayton<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Mar 23, 2014, at 11:32 AM, Eran Ifrah <<a href="mailto:eran.ifrah@gmail.com">eran.ifrah@gmail.com</a>> wrote:<br>
<br>
> Sure, thanks for the help so far<br>
> Eran<br>
><br>
><br>
> On Sun, Mar 23, 2014 at 8:31 PM, Piotr Rak <<a href="mailto:piotr.rak@gmail.com">piotr.rak@gmail.com</a>> wrote:<br>
> I am sorry, but nothing obvious comes to me right now, probably you'll need to wait for Monday, when people more familiar with lldb will be able to help you debug this problem.<br>
><br>
><br>
> 2014-03-23 16:07 GMT+01:00 Eran Ifrah <<a href="mailto:eran.ifrah@gmail.com">eran.ifrah@gmail.com</a>>:<br>
><br>
><br>
><br>
><br>
> On Sun, Mar 23, 2014 at 4:29 PM, Piotr Rak <<a href="mailto:piotr.rak@gmail.com">piotr.rak@gmail.com</a>> wrote:<br>
> Sorry I misinformed you about posix_spawn - it is not true for Linux and FreeBSD at least, it will use ordinary fork.<br>
><br>
><br>
> 2014-03-23 15:23 GMT+01:00 Piotr Rak <<a href="mailto:piotr.rak@gmail.com">piotr.rak@gmail.com</a>>:<br>
><br>
><br>
> Hi,<br>
><br>
> 2014-03-23 14:04 GMT+01:00 Eran Ifrah <<a href="mailto:eran.ifrah@gmail.com">eran.ifrah@gmail.com</a>>:<br>
><br>
> 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):<br>
><br>
>     char __name[128];<br>
>     memset(__name, 0, sizeof(__name));<br>
><br>
>     int master(-1);<br>
>     m_slave = -1;<br>
>     if(openpty(&master, &m_slave, __name, NULL, NULL) != 0)<br>
>         return wxT("");<br>
><br>
>     // disable ECHO<br>
>     struct termios termio;<br>
>     tcgetattr(master, &termio);<br>
>     termio.c_lflag = ICANON;<br>
>     termio.c_oflag = ONOCR | ONLRET;<br>
>     tcsetattr(master, TCSANOW, &termio);<br>
><br>
>     m_tty = wxString(__name, wxConvUTF8);<br>
><br>
> At the end, m_tty contains a string name (e.g. /dev/pts/19 ).<br>
> 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)<br>


><br>
> 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...<br>
><br>
> Looks sane to me.<br>
><br>
> 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...<br>
><br>
><br>
> That was my idea to debug issue if nothing else helps.<br>
> Or rather bisect on which side it really is, sorry if I did not make it clear...<br>
> So I was trying suggest replacing SBTarget::Launch with fork,  write to child stdout/err, and see if that works alone....<br>
><br>
> SBTarget::Launch is usually actually posix_spawn right now, it uses posix_spawnattr_addopen to open descriptors for your specified paths, and should open it 3 times - given current implementation - even it is just one file.<br>


><br>
> Have you inspected SBProcess and SBError returned by SBTarget::Launch?<br>
><br>
> I checked IsValid() on both and its OK for both. I can actually run "next" Continue etc and seems to be working. Its just that I can't seem to redirect the stdout/err to my own console.<br>
><br>
><br>
> Do you see your inferior process is indeed launching, just not displaying anything?<br>
> Yes, ps -ef shows the debugee<br>
><br>
> Do you have an option to check if those terminals are actually being opened (like examining /proc/<pid>/fd for linux)?<br>
> The terminal is opened. Like I mentioned in my previous email, using the _same_ code with gdb works<br>
> I also have a standalone terminal application which I wrote which is also using the same set of classes all of the are working for couple of years now without any problems<br>
><br>
> I also tried this:<br>
> I typed in my konsole 'tty' and used that as the input for Launch - it also seems to have no effect<br>
><br>
><br>
><br>
> Good luck,<br>
> /Piotr<br>
><br>
> Any more hints?<br>
> Eran<br>
><br>
><br>
><br>
> On Sat, Mar 22, 2014 at 9:36 PM, Piotr Rak <<a href="mailto:piotr.rak@gmail.com">piotr.rak@gmail.com</a>> wrote:<br>
> Hi,<br>
><br>
> It should.<br>
> Have you opened master pseudoterminal like?:<br>
><br>
> int fd = posix_openpt(flags); // open("/dev/ptmx") might work here too but less portable;<br>
> grantpt(fd);<br>
> unlockpt(fd);<br>
><br>
> Depending on target you might need some bizarre ioctls here, but assuming you are using Linux/FreeBSD/MacOSX<br>
> you should be fine.<br>
><br>
> If you had already master pseudo-terminal file descriptor you can skip steps above.<br>
><br>
> You can use ptsname for master file descriptor it will return you name of slave pseudo-terminal for your master.<br>
> Later you can pass name returned by ptsname(fd) as Launch arguments.<br>
><br>
> If above won't work you can try replacing Launch() call with ordinary fork, and in child process:<br>
><br>
> slavefd = open(slavename, O_RDWR);<br>
><br>
> dup2(0, slavefd);<br>
> dup2(1, slavefd);<br>
> dup2(2, slavefd);<br>
><br>
> And see if that works alone for you...<br>
><br>
> Good luck,<br>
> /Piotr<br>
><br>
><br>
> 2014-03-22 19:29 GMT+01:00 Eran Ifrah <<a href="mailto:eran.ifrah@gmail.com">eran.ifrah@gmail.com</a>>:<br>
> Hello,<br>
><br>
> I am trying to use the C++ API with good success so far.<br>
> 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)<br>
><br>
> 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.<br>
> I am missing something basic here, can anyone shed some light please? or give an example (better) of how to achieve this?<br>
><br>
> Thanks!<br>
><br>
> --<br>
> 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>
> wxCrafter, a wxWidgets RAD: <a href="http://wxcrafter.codelite.org" target="_blank">http://wxcrafter.codelite.org</a><br>
><br>
> _______________________________________________<br>
> lldb-dev mailing list<br>
> <a href="mailto:lldb-dev@cs.uiuc.edu">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>
><br>
><br>
><br>
><br>
> --<br>
> 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>
> wxCrafter, a wxWidgets RAD: <a href="http://wxcrafter.codelite.org" target="_blank">http://wxcrafter.codelite.org</a><br>
><br>
><br>
><br>
><br>
><br>
> --<br>
> 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>
> wxCrafter, a wxWidgets RAD: <a href="http://wxcrafter.codelite.org" target="_blank">http://wxcrafter.codelite.org</a><br>
><br>
><br>
><br>
><br>
> --<br>
> 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>
> wxCrafter, a wxWidgets RAD: <a href="http://wxcrafter.codelite.org" target="_blank">http://wxcrafter.codelite.org</a><br>
> _______________________________________________<br>
> lldb-dev mailing list<br>
> <a href="mailto:lldb-dev@cs.uiuc.edu">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>
</div></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>