diff --git a/lldb/source/Plugins/Process/Linux/Procfs.cpp b/lldb/source/Plugins/Process/Linux/Procfs.cpp index d3bd396fbaeab..4349a2b1adb9d 100644 --- a/lldb/source/Plugins/Process/Linux/Procfs.cpp +++ b/lldb/source/Plugins/Process/Linux/Procfs.cpp @@ -74,7 +74,7 @@ lldb_private::process_linux::GetAvailableLogicalCoreIDs() { llvm::Expected lldb_private::process_linux::GetPtraceScope() { ErrorOr> ptrace_scope_file = getProcFile("sys/kernel/yama/ptrace_scope"); - if (!*ptrace_scope_file) + if (!ptrace_scope_file) return errorCodeToError(ptrace_scope_file.getError()); // The contents should be something like "1\n". Trim it so we get "1". StringRef buffer = (*ptrace_scope_file)->getBuffer().trim(); diff --git a/lldb/unittests/Process/Linux/ProcfsTests.cpp b/lldb/unittests/Process/Linux/ProcfsTests.cpp index e7af1f469c2bf..534e3e132ec62 100644 --- a/lldb/unittests/Process/Linux/ProcfsTests.cpp +++ b/lldb/unittests/Process/Linux/ProcfsTests.cpp @@ -104,7 +104,7 @@ TEST(Perf, RealLogicalCoreIDs) { ASSERT_GT((int)cpu_ids->size(), 0) << "We must see at least one core"; } -TEST(Perf, RealPtraceScope) { +TEST(Perf, RealPtraceScopeWhenExist) { // We first check we can read /proc/sys/kernel/yama/ptrace_scope auto buffer_or_error = errorOrToExpected(getProcFile("sys/kernel/yama/ptrace_scope")); @@ -120,6 +120,21 @@ TEST(Perf, RealPtraceScope) { << "Sensible values of ptrace_scope are between 0 and 3"; } +TEST(Perf, RealPtraceScopeWhenNotExist) { + // We first check we can NOT read /proc/sys/kernel/yama/ptrace_scope + auto buffer_or_error = + errorOrToExpected(getProcFile("sys/kernel/yama/ptrace_scope")); + if (buffer_or_error) + GTEST_SKIP() << "In order for this test to run, " + "/proc/sys/kernel/yama/ptrace_scope should not exist"; + consumeError(buffer_or_error.takeError()); + + // At this point we should fail parsing the ptrace_scope value. + Expected ptrace_scope = GetPtraceScope(); + ASSERT_FALSE((bool)ptrace_scope); + consumeError(ptrace_scope.takeError()); +} + #ifdef LLVM_ENABLE_THREADING TEST(Support, getProcFile_Tid) { auto BufferOrError = getProcFile(getpid(), llvm::get_threadid(), "comm");