Skip to content

🍒/austria/53e9ee3027db+10222764a9a3+14bd14f9f92f+453f8c87ff20 #4091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

52 changes: 0 additions & 52 deletions lldb/lldb/unittests/Platform/PlatformMacOSXTest.cpp

This file was deleted.

74 changes: 42 additions & 32 deletions lldb/source/Target/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4485,6 +4485,12 @@ class IOHandlerProcessSTDIO : public IOHandler {

~IOHandlerProcessSTDIO() override = default;

void SetIsRunning(bool running) {
std::lock_guard<std::mutex> guard(m_mutex);
SetIsDone(!running);
m_is_running = running;
}

// Each IOHandler gets to run until it is done. It should read data from the
// "in" and place output into "out" and "err and return when done.
void Run() override {
Expand All @@ -4504,49 +4510,52 @@ class IOHandlerProcessSTDIO : public IOHandler {
// FD_ZERO, FD_SET are not supported on windows
#ifndef _WIN32
const int pipe_read_fd = m_pipe.GetReadFileDescriptor();
m_is_running = true;
while (!GetIsDone()) {
SetIsRunning(true);
while (true) {
{
std::lock_guard<std::mutex> guard(m_mutex);
if (GetIsDone())
break;
}

SelectHelper select_helper;
select_helper.FDSetRead(read_fd);
select_helper.FDSetRead(pipe_read_fd);
Status error = select_helper.Select();

if (error.Fail()) {
SetIsDone(true);
} else {
char ch = 0;
size_t n;
if (select_helper.FDIsSetRead(read_fd)) {
n = 1;
if (m_read_file.Read(&ch, n).Success() && n == 1) {
if (m_write_file.Write(&ch, n).Fail() || n != 1)
SetIsDone(true);
} else
SetIsDone(true);
}
if (select_helper.FDIsSetRead(pipe_read_fd)) {
size_t bytes_read;
// Consume the interrupt byte
Status error = m_pipe.Read(&ch, 1, bytes_read);
if (error.Success()) {
switch (ch) {
case 'q':
SetIsDone(true);
break;
case 'i':
if (StateIsRunningState(m_process->GetState()))
m_process->SendAsyncInterrupt();
break;
}
}
if (error.Fail())
break;

char ch = 0;
size_t n;
if (select_helper.FDIsSetRead(read_fd)) {
n = 1;
if (m_read_file.Read(&ch, n).Success() && n == 1) {
if (m_write_file.Write(&ch, n).Fail() || n != 1)
break;
} else
break;
}

if (select_helper.FDIsSetRead(pipe_read_fd)) {
size_t bytes_read;
// Consume the interrupt byte
Status error = m_pipe.Read(&ch, 1, bytes_read);
if (error.Success()) {
if (ch == 'q')
break;
if (ch == 'i')
if (StateIsRunningState(m_process->GetState()))
m_process->SendAsyncInterrupt();
}
}
}
m_is_running = false;
SetIsRunning(false);
#endif
}

void Cancel() override {
std::lock_guard<std::mutex> guard(m_mutex);
SetIsDone(true);
// Only write to our pipe to cancel if we are in
// IOHandlerProcessSTDIO::Run(). We can end up with a python command that
Expand Down Expand Up @@ -4603,7 +4612,8 @@ class IOHandlerProcessSTDIO : public IOHandler {
NativeFile m_write_file; // Write to this file (usually the master pty for
// getting io to debuggee)
Pipe m_pipe;
std::atomic<bool> m_is_running{false};
std::mutex m_mutex;
bool m_is_running = false;
};

void Process::SetSTDIOFileDescriptor(int fd) {
Expand Down
3 changes: 3 additions & 0 deletions lldb/test/API/iohandler/stdio/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CXX_SOURCES := main.cpp

include Makefile.rules
30 changes: 30 additions & 0 deletions lldb/test/API/iohandler/stdio/TestIOHandlerProcessSTDIO.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test.lldbpexpect import PExpectTest

class TestIOHandlerProcessSTDIO(PExpectTest):

mydir = TestBase.compute_mydir(__file__)
NO_DEBUG_INFO_TESTCASE = True

# PExpect uses many timeouts internally and doesn't play well
# under ASAN on a loaded machine..
@skipIfAsan
def test(self):
self.build()
self.launch(executable=self.getBuildArtifact("a.out"))
self.child.sendline("run")

self.child.send("foo\n")
self.child.expect_exact("stdout: foo")

self.child.send("bar\n")
self.child.expect_exact("stdout: bar")

self.child.send("baz\n")
self.child.expect_exact("stdout: baz")

self.child.sendcontrol('d')
self.expect_prompt()
self.quit()
8 changes: 8 additions & 0 deletions lldb/test/API/iohandler/stdio/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <iostream>
#include <string>

int main(int argc, char **argv) {
for (std::string line; std::getline(std::cin, line);)
std::cout << "stdout: " << line << '\n';
return 0;
}