[Lldb-commits] [PATCH] D117928: [lldb] Disable tests for x86 that uses write command on XMM registers

2022-01-22 Thread Michał Górny via Phabricator via lldb-commits
mgorny added a comment.

Ok, so to summarize: there's some CPU families where setting `xmm2..xmm9` via 
ptrace doesn't work for some reason? That's quite weird. Could it be an `xsave` 
bug perhaps?

FWICS the corresponding read test passes, so apparently setting them directly 
within the program works.

Could you tell us what CPU exactly is this? Ideally paste `/proc/cpuinfo`. I'm 
pretty sure this test passed successfully on my old Athlon64 that definitely 
didn't have AVX (or SSE3). Unfortunately, I can't retest it anymore since it 
died almost 2 years ago.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117928/new/

https://reviews.llvm.org/D117928

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D117707: [lldb] [Platform] Support synthesizing siginfo_t

2022-01-22 Thread Michał Górny via Phabricator via lldb-commits
mgorny updated this revision to Diff 402193.
mgorny added a comment.

Combine the tests for various 32-bit and 64-bit arches, as they have the same 
offset-size pairs. Instead of repeating them, just iterate over the list of 
arches.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117707/new/

https://reviews.llvm.org/D117707

Files:
  lldb/bindings/interface/SBPlatform.i
  lldb/include/lldb/API/SBPlatform.h
  lldb/include/lldb/API/SBType.h
  lldb/include/lldb/Target/Platform.h
  lldb/source/API/SBPlatform.cpp
  lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
  lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h
  lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
  lldb/source/Plugins/Platform/Linux/PlatformLinux.h
  lldb/source/Target/Platform.cpp
  lldb/unittests/Platform/CMakeLists.txt
  lldb/unittests/Platform/PlatformSiginfoTest.cpp
  lldb/unittests/Platform/tools/generate_siginfo.c

Index: lldb/unittests/Platform/tools/generate_siginfo.c
===
--- /dev/null
+++ lldb/unittests/Platform/tools/generate_siginfo.c
@@ -0,0 +1,82 @@
+//===-- generate_siginfo_linux.c --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include 
+#include 
+#include 
+
+siginfo_t siginfo;
+
+#define P(member)  \
+  printf("   {\"%s\", %zd, %zd},\n", #member,   \
+ offsetof(siginfo_t, member), sizeof(siginfo.member));
+
+// undef annoying "POSIX friendliness" macros
+#undef si_pid
+#undef si_uid
+#undef si_overrun
+#undef si_status
+#undef si_utime
+#undef si_stime
+#undef si_addr
+#undef si_addr_lsb
+#undef si_band
+#undef si_fd
+
+int main() {
+  printf("  ExpectFields(siginfo_type,\n");
+  printf("   {\n");
+
+  P(si_signo);
+  P(si_errno);
+  P(si_code);
+
+#if defined(__GLIBC__)
+  P(_sifields._kill.si_pid);
+  P(_sifields._kill.si_uid);
+  P(_sifields._timer.si_tid);
+  P(_sifields._timer.si_overrun);
+  P(_sifields._timer.si_sigval);
+  P(_sifields._rt.si_pid);
+  P(_sifields._rt.si_uid);
+  P(_sifields._rt.si_sigval);
+  P(_sifields._sigchld.si_pid);
+  P(_sifields._sigchld.si_uid);
+  P(_sifields._sigchld.si_status);
+  P(_sifields._sigchld.si_utime);
+  P(_sifields._sigchld.si_stime);
+  P(_sifields._sigfault.si_addr);
+  P(_sifields._sigfault.si_addr_lsb);
+  P(_sifields._sigfault._bounds._addr_bnd._lower);
+  P(_sifields._sigfault._bounds._addr_bnd._upper);
+  P(_sifields._sigfault._bounds._pkey);
+  P(_sifields._sigpoll.si_band);
+  P(_sifields._sigpoll.si_fd);
+  P(_sifields._sigsys._call_addr);
+  P(_sifields._sigsys._syscall);
+  P(_sifields._sigsys._arch);
+#endif // defined(__GLIBC__)
+
+#if defined(__FreeBSD__)
+  // these are top-level fields on FreeBSD
+  P(si_pid);
+  P(si_uid);
+  P(si_status);
+  P(si_addr);
+  P(si_value);
+  P(_reason._fault._trapno);
+  P(_reason._timer._timerid);
+  P(_reason._timer._overrun);
+  P(_reason._mesgq._mqd);
+  P(_reason._poll._band);
+#endif // defined(__FreeBSD__)
+
+  printf("   });\n");
+
+  return 0;
+}
Index: lldb/unittests/Platform/PlatformSiginfoTest.cpp
===
--- /dev/null
+++ lldb/unittests/Platform/PlatformSiginfoTest.cpp
@@ -0,0 +1,230 @@
+//===-- PlatformSiginfoTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "gtest/gtest.h"
+
+#include 
+#include 
+
+#include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h"
+#include "Plugins/Platform/Linux/PlatformLinux.h"
+#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
+
+#include "TestingSupport/SubsystemRAII.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Utility/ArchSpec.h"
+#include "lldb/Utility/Reproducer.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::repro;
+
+namespace {
+class PlatformSiginfoTest : public ::testing::Test {
+  SubsystemRAII subsystems;
+  PlatformSP platform_sp;
+  DebuggerSP debugger_sp;
+  TargetSP target_sp;
+
+public:
+  CompilerType siginfo_type;
+
+  void SetUp() override {
+llvm::cantFail(Reproducer::Initialize(ReproducerMode::Off, llvm::None));
+platform_freebsd::PlatformFreeBSD::Initialize();
+platform_linux::PlatformLinux::Initialize();
+  }
+
+  void TearDown() override {
+platform_linux::PlatformLinux::Termi

[Lldb-commits] [PATCH] D117707: [lldb] [Platform] Support synthesizing siginfo_t

2022-01-22 Thread Michał Górny via Phabricator via lldb-commits
mgorny updated this revision to Diff 402208.
mgorny added a comment.

Add NetBSD.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117707/new/

https://reviews.llvm.org/D117707

Files:
  lldb/bindings/interface/SBPlatform.i
  lldb/include/lldb/API/SBPlatform.h
  lldb/include/lldb/API/SBType.h
  lldb/include/lldb/Target/Platform.h
  lldb/source/API/SBPlatform.cpp
  lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
  lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h
  lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
  lldb/source/Plugins/Platform/Linux/PlatformLinux.h
  lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp
  lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.h
  lldb/source/Target/Platform.cpp
  lldb/unittests/Platform/CMakeLists.txt
  lldb/unittests/Platform/PlatformSiginfoTest.cpp
  lldb/unittests/Platform/tools/generate_siginfo.c

Index: lldb/unittests/Platform/tools/generate_siginfo.c
===
--- /dev/null
+++ lldb/unittests/Platform/tools/generate_siginfo.c
@@ -0,0 +1,112 @@
+//===-- generate_siginfo_linux.c --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include 
+#include 
+#include 
+
+siginfo_t siginfo;
+
+#define P(member)  \
+  printf("   {\"%s\", %zd, %zd},\n", #member,   \
+ offsetof(siginfo_t, member), sizeof(siginfo.member));
+
+// undef annoying "POSIX friendliness" macros
+#undef si_pid
+#undef si_uid
+#undef si_overrun
+#undef si_status
+#undef si_utime
+#undef si_stime
+#undef si_addr
+#undef si_addr_lsb
+#undef si_band
+#undef si_fd
+
+int main() {
+  printf("  ExpectFields(siginfo_type,\n");
+  printf("   {\n");
+
+#if !defined(__NetBSD__)
+  P(si_signo);
+  P(si_errno);
+  P(si_code);
+
+#if defined(__GLIBC__)
+  P(_sifields._kill.si_pid);
+  P(_sifields._kill.si_uid);
+  P(_sifields._timer.si_tid);
+  P(_sifields._timer.si_overrun);
+  P(_sifields._timer.si_sigval);
+  P(_sifields._rt.si_pid);
+  P(_sifields._rt.si_uid);
+  P(_sifields._rt.si_sigval);
+  P(_sifields._sigchld.si_pid);
+  P(_sifields._sigchld.si_uid);
+  P(_sifields._sigchld.si_status);
+  P(_sifields._sigchld.si_utime);
+  P(_sifields._sigchld.si_stime);
+  P(_sifields._sigfault.si_addr);
+  P(_sifields._sigfault.si_addr_lsb);
+  P(_sifields._sigfault._bounds._addr_bnd._lower);
+  P(_sifields._sigfault._bounds._addr_bnd._upper);
+  P(_sifields._sigfault._bounds._pkey);
+  P(_sifields._sigpoll.si_band);
+  P(_sifields._sigpoll.si_fd);
+  P(_sifields._sigsys._call_addr);
+  P(_sifields._sigsys._syscall);
+  P(_sifields._sigsys._arch);
+#endif // defined(__GLIBC__)
+
+#if defined(__FreeBSD__)
+  // these are top-level fields on FreeBSD
+  P(si_pid);
+  P(si_uid);
+  P(si_status);
+  P(si_addr);
+  P(si_value);
+  P(_reason._fault._trapno);
+  P(_reason._timer._timerid);
+  P(_reason._timer._overrun);
+  P(_reason._mesgq._mqd);
+  P(_reason._poll._band);
+#endif // defined(__FreeBSD__)
+
+#else // defined(__NetBSD__)
+
+  P(_info._signo);
+  P(_info._code);
+  P(_info._errno);
+  P(_info._reason._rt._pid);
+  P(_info._reason._rt._uid);
+  P(_info._reason._rt._value);
+  P(_info._reason._child._pid);
+  P(_info._reason._child._uid);
+  P(_info._reason._child._status);
+  P(_info._reason._child._utime);
+  P(_info._reason._child._stime);
+  P(_info._reason._fault._addr);
+  P(_info._reason._fault._trap);
+  P(_info._reason._fault._trap2);
+  P(_info._reason._fault._trap3);
+  P(_info._reason._poll._band);
+  P(_info._reason._poll._fd);
+  P(_info._reason._syscall._sysnum);
+  P(_info._reason._syscall._retval);
+  P(_info._reason._syscall._error);
+  P(_info._reason._syscall._args);
+  P(_info._reason._ptrace_state._pe_report_event);
+  P(_info._reason._ptrace_state._option._pe_other_pid);
+  P(_info._reason._ptrace_state._option._pe_lwp);
+
+#endif // defined(__NetBSD__)
+
+  printf("   });\n");
+
+  return 0;
+}
Index: lldb/unittests/Platform/PlatformSiginfoTest.cpp
===
--- /dev/null
+++ lldb/unittests/Platform/PlatformSiginfoTest.cpp
@@ -0,0 +1,311 @@
+//===-- PlatformSiginfoTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "gtest/gtest.h"
+
+#include 
+#include 
+
+#include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h"
+#include "Plugins/Platform/Linux/Pla

[Lldb-commits] [PATCH] D117928: [lldb] Disable tests for x86 that uses write command on XMM registers

2022-01-22 Thread Luís Ferreira via Phabricator via lldb-commits
ljmf00 added a comment.

In D117928#3263319 , @mgorny wrote:

> Ok, so to summarize: there's some CPU families where setting `xmm2..xmm9` via 
> ptrace doesn't work for some reason? That's quite weird. Could it be an 
> `xsave` bug perhaps?

Exactly. `ptrace` with `NT_FPREGSET` doesn't work properly but `NT_X86_XSTATE` 
does. It makes sense to me that the presence of AVX triggers this, since, from 
my inspection of the LLDB code, there is a fallback system on `ReadRegisterSet` 
that tries to use `ptrace` with `NT_X86_XSTATE` and fallbacks to `NT_FPREGSET` 
if it fails. The call made with `NT_X86_XSTATE` gives me different output on 
`strace`:

  ptrace(PTRACE_SETREGSET, 213817, NT_X86_XSTATE, {iov_base=0x97dcd4a0, 
iov_len=1088}) = 0
  ptrace(PTRACE_GETREGSET, 213817, NT_X86_XSTATE, {iov_base=0x97dcd4a0, 
iov_len=1088}) = 0



> FWICS the corresponding read test passes, so apparently setting them directly 
> within the program works.

Yes, I can confirm that. Writing directly to registers is fine and reading them 
only triggers `PTRACE_GETREGSET` so, it is reading fine. The problem is when 
`ptrace` is called with `PTRACE_SETREGSET`.
Inspecting the kernel source code I see that `NT_FPREGSET` is triggered by 
`xfpregs_set` 
https://github.com/torvalds/linux/blob/master/arch/x86/kernel/fpu/regset.c#L89 
. That `memset` seems very suspicious here. Blaming the source code, seems to 
be before Linux v5.16 .

This makes sense to me since I use Arch with the latest kernel, and a lot of 
people use LTS versions or outdated versions due to Ubuntu/Debian (according to 
Wikipedia, unstable Debian uses Linux 5.10.46). I will downgrade the kernel and 
try to reproduce this. Ultimately, I can try to recompile the kernel without 
that `memset` and see what happens. I can't find a logical reason in my brain 
other than wrong offsets? If I didn't calculate it wrongly, the range of bytes 
is the same size. Would be cool if anyone have any knowledge of the kernel and 
explain this to me.

> Could you tell us what CPU exactly is this? Ideally paste `/proc/cpuinfo`. 
> I'm pretty sure this test passed successfully on my old Athlon64 that 
> definitely didn't have AVX (or SSE3). Unfortunately, I can't retest it 
> anymore since it died almost 2 years ago.

Is `lscpu` enough? See https://termbin.com/c2pt .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117928/new/

https://reviews.llvm.org/D117928

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D117928: [lldb] Disable tests for x86 that uses write command on XMM registers

2022-01-22 Thread Michał Górny via Phabricator via lldb-commits
mgorny added a comment.

Thank you. Yes, please test on an older kernel, in case it's specifically a 
kernel regression.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117928/new/

https://reviews.llvm.org/D117928

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits