Skip to content

SIGSEGV when lldb eval executes code in the inferior #178

@andrurogerz

Description

@andrurogerz

There are two lldb test cases that consistently fail when run against ds2 on Linux and Android:

TestStateAfterExpression.TestStopReasonAfterExpression.test_thread_state_after_expr_dwarf
TestStateAfterExpression.TestStopReasonAfterExpression.test_thread_state_after_expr_dwo
TestExpressionInSyscall.ExprSyscallTestCase.test_setpgid_dwarf
TestExpressionInSyscall.ExprSyscallTestCase.test_setpgid_dwo

The failure log from the test indicates there was an unexpected SIGSEGV signal in the inferior:

======================================================================
FAIL: test_setpgid_dwarf (TestExpressionInSyscall.ExprSyscallTestCase.test_setpgid_dwarf)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/andrew/src/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 1769, in test_method
    return attrvalue(self)
           ^^^^^^^^^^^^^^^
  File "/home/andrew/src/llvm/llvm-project/lldb/test/API/commands/expression/expr-in-syscall/TestExpressionInSyscall.py", line 17, in test_setpgid
    self.expr_syscall()
  File "/home/andrew/src/llvm/llvm-project/lldb/test/API/commands/expression/expr-in-syscall/TestExpressionInSyscall.py", line 68, in expr_syscall
    self.expect_expr("(int)getpid()", result_value=str(process.GetProcessID()))
  File "/home/andrew/src/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 2525, in expect_expr
    value_check.check_value(self, eval_result, str(eval_result))
  File "/home/andrew/src/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 299, in check_value
    test_base.assertSuccess(val.GetError())
  File "/home/andrew/src/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 2560, in assertSuccess
    self.fail(self._formatMessage(msg, "'{}' is not success".format(error)))
AssertionError: 'error: Execution was interrupted, reason: signal SIGSEGV.
The process has been returned to the state before expression evaluation.
' is not success
Config=x86_64-/home/andrew/Android/Sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/bin/clang

The common behavior of these test cases is that they issue an lldb eval command that executes code in the inferior process. The issue can be reproduced without running the tests by issuing eval command while attached to any debug target with a command that has to execute code such as (int)getpid() or '(int) printf("Hello\n")'. However, it only fails if the process is in a certain state. If you just break at main and run the eval call, it won't happen. But if you interrupt a process with ctrl-C while threads are blocked in a syscall, the issue does repro. Most likely there's an issue with register save/restore, which is hinted at by this PTRACE_REGSET failure that is logged in the ds2 output (when run with with -d):

[367667][long int ds2::Host::POSIX::PTrace::wrapPtrace(CommandType, pid_t, AddrType, DataType, int) [with CommandType = __ptrace_request; AddrType = int; DataType = iovec*; pid_t = int]] DEBUG  : ran ptrace command PTRACE_SETREGSET on pid 367671, returned EFAULT                  

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions