[lldb-dev] How to redirect stdin/out/err to different pty?
Eran Ifrah
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):
char __name[128];
memset(__name, 0, sizeof(__name));
int master(-1);
m_slave = -1;
if(openpty(&master, &m_slave, __name, NULL, NULL) != 0)
return wxT("");
// disable ECHO
struct termios termio;
tcgetattr(master, &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?
Eran
On Sat, Mar 22, 2014 at 9:36 PM, Piotr Rak <piotr.rak at gmail.com> wrote:
> Hi,
>
> It should.
> Have you opened master pseudoterminal like?:
>
> int fd = posix_openpt(flags); // open("/dev/ptmx") might work here too but
> less portable;
> grantpt(fd);
> unlockpt(fd);
>
> 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,
> /Piotr
>
>
> 2014-03-22 19:29 GMT+01:00 Eran Ifrah <eran.ifrah at gmail.com>:
>
>> Hello,
>>
>> 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?
>>
>> Thanks!
>>
>> --
>> Eran Ifrah
>> Author of codelite, a cross platform open source C/C++ IDE:
>> http://www.codelite.org
>> wxCrafter, a wxWidgets RAD: http://wxcrafter.codelite.org
>>
>> _______________________________________________
>> lldb-dev mailing list
>> lldb-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev
>>
>>
>
--
Eran Ifrah
Author of codelite, a cross platform open source C/C++ IDE:
http://www.codelite.org
wxCrafter, a wxWidgets RAD: http://wxcrafter.codelite.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20140323/e02959cc/attachment.html>
More information about the lldb-dev
mailing list