""" Test basics of linux core file debugging. """ import shutil import struct import os import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil class LinuxCoreTestCase(TestBase): NO_DEBUG_INFO_TESTCASE = True _aarch64_pid = 37688 _aarch64_pac_pid = 387 _i386_pid = 32306 _x86_64_pid = 32259 _s390x_pid = 1045 _ppc64le_pid = 28147 _riscv64_gpr_fpr_pid = 1089 _riscv64_gpr_only_pid = 97 _loongarch64_pid = 456735 _aarch64_regions = 4 _i386_regions = 4 _x86_64_regions = 5 _s390x_regions = 2 _ppc64le_regions = 2 _riscv64_regions = 4 _loongarch64_regions = 4 @skipIfLLVMTargetMissing("AArch64") def test_aarch64(self): """Test that lldb can read the process information from an aarch64 linux core file.""" self.do_test("linux-aarch64", self._aarch64_pid, self._aarch64_regions, "a.out") @skipIfLLVMTargetMissing("X86") def test_i386(self): """Test that lldb can read the process information from an i386 linux core file.""" self.do_test("linux-i386", self._i386_pid, self._i386_regions, "a.out") @skipIfLLVMTargetMissing("PowerPC") def test_ppc64le(self): """Test that lldb can read the process information from an ppc64le linux core file.""" self.do_test( "linux-ppc64le", self._ppc64le_pid, self._ppc64le_regions, "linux-ppc64le.ou", ) @skipIfLLVMTargetMissing("X86") def test_x86_64(self): """Test that lldb can read the process information from an x86_64 linux core file.""" self.do_test("linux-x86_64", self._x86_64_pid, self._x86_64_regions, "a.out") @skipIfLLVMTargetMissing("SystemZ") def test_s390x(self): """Test that lldb can read the process information from an s390x linux core file.""" self.do_test("linux-s390x", self._s390x_pid, self._s390x_regions, "a.out") @skipIfLLVMTargetMissing("RISCV") def test_riscv64_gpr_fpr(self): """Test that lldb can read the process information from an riscv64 linux core file.""" self.do_test( "linux-riscv64.gpr_fpr", self._riscv64_gpr_fpr_pid, self._riscv64_regions, "a.out", ) @skipIfLLVMTargetMissing("RISCV") def test_riscv64_gpr_only(self): """Test that lldb can read the process information from an riscv64 linux core file made for a RV64IMAC target, having no FP-registers.""" self.do_test( "linux-riscv64.gpr_only", self._riscv64_gpr_only_pid, self._riscv64_regions, "a.out", ) @skipIfLLVMTargetMissing("LoongArch") def test_loongarch64(self): """Test that lldb can read the process information from an loongarch64 linux core file.""" self.do_test( "linux-loongarch64", self._loongarch64_pid, self._loongarch64_regions, "a.out", ) @skipIfLLVMTargetMissing("X86") def test_same_pid_running(self): """Test that we read the information from the core correctly even if we have a running process with the same PID around""" exe_file = self.getBuildArtifact("linux-x86_64-pid.out") core_file = self.getBuildArtifact("linux-x86_64-pid.core") shutil.copyfile("linux-x86_64.out", exe_file) shutil.copyfile("linux-x86_64.core", core_file) with open(core_file, "r+b") as f: # These are offsets into the NT_PRSTATUS and NT_PRPSINFO structures in the note # segment of the core file. If you update the file, these offsets may need updating # as well. (Notes can be viewed with readelf --notes.) for pid_offset in [0x1C4, 0x320]: f.seek(pid_offset) self.assertEqual(struct.unpack("