[Lldb-commits] [PATCH] D114722: [LLDB] Fix Python GIL-not-held issues

2022-01-19 Thread Sylvestre Ledru via Phabricator via lldb-commits
sylvestre.ledru added a comment.

Seems that it broke apt.llvm.org on ubuntu bionic with Python 3.6:
I reported this issue: https://github.com/llvm/llvm-project/issues/53291


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114722

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


[Lldb-commits] [PATCH] D117559: [lldb] Remove remote testing ability from lldb**-server** tests

2022-01-19 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

Omair can comment on how useful this is for SVE testing.

I do use this to run the memory tagging tests on qemu, we don't have real 
hardware yet. Let me see what extra steps I need to run them within qemu 
instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117559

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


[Lldb-commits] [PATCH] D117559: [lldb] Remove remote testing ability from lldb**-server** tests

2022-01-19 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

Thanks for the info. If you are using it then I think we can come up with 
something would support your use case. TBH, I am kinda surprised this even 
works (are you sure you're running lldb-*server* tests and not just the 
"normal" lldb ones?) -- I haven't seen any patches in this area, so I expected 
it to have bitrotted.

The main thing which is in my way me is the (flaky) forward-connection mode. 
Would it be ok if we used reverse connections here? I am assuming we don't have 
to worry about firewalls with qemu..


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117559

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


[Lldb-commits] [PATCH] D117559: [lldb] Remove remote testing ability from lldb**-server** tests

2022-01-19 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

I'm running 
`lldb/test/API/tools/lldb-server/memory-tagging/TestGdbRemoteMemoryTagging.py`.

If the details matter any...

In qemu:

  $ ./build-cross/bin/lldb-server platform --server --listen 0.0.0.0:54321

On the host:

  $ ./bin/lldb-dotest --platform-name remote-linux --platform-url 
connect://192.168.53.89:54321 --platform-working-dir /tmp/test_lldb -p 
TestGdbRemoteMemoryTagging.py --arch aarch64

I have qemu setup so that any port lldb-server picks should be accessible from 
the host and the VM is just running the usual background linux stuff plus 
lldb-server. Not a lot to use up ports.

Can you remind me what forward/reverse mean here? I guess that forward is us 
telling the remote the port to use, which might already be taken on the remote 
itself. Then reverse is the remote launching the lldb-server on a port it 
chooses, then telling us what it chose. The latter should be fine for my setup.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117559

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


[Lldb-commits] [PATCH] D117559: [lldb] Remove remote testing ability from lldb**-server** tests

2022-01-19 Thread Muhammad Omair Javaid via Phabricator via lldb-commits
omjavaid added a comment.

This doesnt interfere with LLDB tests for SVE. Rather I have not used it in a 
while for SVE tests I ahve using setup similar to to one David has explained 
above.

@labath Do you know if android adb based tests are being run anywhere? Are we 
still maintaining this support and does it work?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117559

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


[Lldb-commits] [lldb] 6ff4af8 - [lldb] Fix D114722 for python<=3.6

2022-01-19 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-01-19T12:49:46+01:00
New Revision: 6ff4af8e182333740a58176a3e9cbc84f6828216

URL: 
https://github.com/llvm/llvm-project/commit/6ff4af8e182333740a58176a3e9cbc84f6828216
DIFF: 
https://github.com/llvm/llvm-project/commit/6ff4af8e182333740a58176a3e9cbc84f6828216.diff

LOG: [lldb] Fix D114722 for python<=3.6

_Py_IsFinalizing was called _Py_Finalizing back then (and it was a
variable instead of a function).

Added: 


Modified: 
lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h

Removed: 




diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
index 13dabb2eff3cd..32020f983f605 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -69,6 +69,28 @@ Expected 
python::As(Expected &&obj) {
   return std::string(utf8.get());
 }
 
+static bool python_is_finalizing() {
+#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 7
+  return _Py_Finalizing != nullptr;
+#else
+  return _Py_IsFinalizing();
+#endif
+}
+
+void PythonObject::Reset() {
+  if (m_py_obj && Py_IsInitialized()) {
+if (python_is_finalizing()) {
+  // Leak m_py_obj rather than crashing the process.
+  // https://docs.python.org/3/c-api/init.html#c.PyGILState_Ensure
+} else {
+  PyGILState_STATE state = PyGILState_Ensure();
+  Py_DECREF(m_py_obj);
+  PyGILState_Release(state);
+}
+  }
+  m_py_obj = nullptr;
+}
+
 Expected PythonObject::AsLongLong() const {
   if (!m_py_obj)
 return nullDeref();

diff  --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h 
b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
index 7dd8a7426f15b..2094f0b3afd21 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -239,19 +239,7 @@ class PythonObject {
 
   ~PythonObject() { Reset(); }
 
-  void Reset() {
-if (m_py_obj && Py_IsInitialized()) {
-  if (_Py_IsFinalizing()) {
-// Leak m_py_obj rather than crashing the process.
-// https://docs.python.org/3/c-api/init.html#c.PyGILState_Ensure
-  } else {
-PyGILState_STATE state = PyGILState_Ensure();
-Py_DECREF(m_py_obj);
-PyGILState_Release(state);
-  }
-}
-m_py_obj = nullptr;
-  }
+  void Reset();
 
   void Dump() const {
 if (m_py_obj)



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


[Lldb-commits] [lldb] 8bfa7a6 - [lldb] Fix NativeThreadLinux to build with older compilers

2022-01-19 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-01-19T12:49:47+01:00
New Revision: 8bfa7a6dcc274bf46ce1587cf51996a3389ceb63

URL: 
https://github.com/llvm/llvm-project/commit/8bfa7a6dcc274bf46ce1587cf51996a3389ceb63
DIFF: 
https://github.com/llvm/llvm-project/commit/8bfa7a6dcc274bf46ce1587cf51996a3389ceb63.diff

LOG: [lldb] Fix NativeThreadLinux to build with older compilers

Added: 


Modified: 
lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp 
b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
index 50d8ce9c161c2..a5187a626c892 100644
--- a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
@@ -549,5 +549,5 @@ NativeThreadLinux::GetSiginfo() const {
   GetProcess().GetSignalInfo(GetID(), siginfo_buf->getBufferStart());
   if (!error.Success())
 return error.ToError();
-  return siginfo_buf;
+  return std::move(siginfo_buf);
 }



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


[Lldb-commits] [lldb] b2a162e - [lldb] Remove the requirement for windows clients to specify -DIMPORT_LIBLLDB

2022-01-19 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-01-19T12:49:47+01:00
New Revision: b2a162e63bd735742fa22ed8d2465095db386bad

URL: 
https://github.com/llvm/llvm-project/commit/b2a162e63bd735742fa22ed8d2465095db386bad
DIFF: 
https://github.com/llvm/llvm-project/commit/b2a162e63bd735742fa22ed8d2465095db386bad.diff

LOG: [lldb] Remove the requirement for windows clients to specify 
-DIMPORT_LIBLLDB

This macro was being used to select the proper import/export annotations
on SB classes. Non-windows clients do not have such requirements.

Instead introduce a new macro (LLDB_IN_LIBLLDB), which signals that
we're compiling liblldb itself (and should use dllexport). The default
(no macro) is to use dllimport. I've moved the macro definition to
SBDefines.h, since it only makes sense when building the API library.

Differential Revision: https://reviews.llvm.org/D117564

Added: 


Modified: 
lldb/include/lldb/API/SBDefines.h
lldb/include/lldb/lldb-defines.h
lldb/source/API/CMakeLists.txt
lldb/tools/driver/CMakeLists.txt
lldb/tools/lldb-vscode/CMakeLists.txt

Removed: 




diff  --git a/lldb/include/lldb/API/SBDefines.h 
b/lldb/include/lldb/API/SBDefines.h
index 3ab10ad8e0619..d0ee09368d029 100644
--- a/lldb/include/lldb/API/SBDefines.h
+++ b/lldb/include/lldb/API/SBDefines.h
@@ -15,6 +15,16 @@
 #include "lldb/lldb-types.h"
 #include "lldb/lldb-versioning.h"
 
+#if defined(_WIN32)
+#if defined(LLDB_IN_LIBLLDB)
+#define LLDB_API __declspec(dllexport)
+#else
+#define LLDB_API __declspec(dllimport)
+#endif
+#else // defined (_WIN32)
+#define LLDB_API
+#endif
+
 // Forward Declarations
 namespace lldb {
 

diff  --git a/lldb/include/lldb/lldb-defines.h 
b/lldb/include/lldb/lldb-defines.h
index 4bf01c3f86c61..339071bbfc318 100644
--- a/lldb/include/lldb/lldb-defines.h
+++ b/lldb/include/lldb/lldb-defines.h
@@ -11,18 +11,6 @@
 
 #include "lldb/lldb-types.h"
 
-#if defined(_WIN32)
-#if defined(EXPORT_LIBLLDB)
-#define LLDB_API __declspec(dllexport)
-#elif defined(IMPORT_LIBLLDB)
-#define LLDB_API __declspec(dllimport)
-#else
-#define LLDB_API
-#endif
-#else // defined (_WIN32)
-#define LLDB_API
-#endif
-
 #if !defined(INT32_MAX)
 #define INT32_MAX 2147483647
 #endif

diff  --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt
index e75cce3ecb070..46307b487a547 100644
--- a/lldb/source/API/CMakeLists.txt
+++ b/lldb/source/API/CMakeLists.txt
@@ -1,7 +1,3 @@
-if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
-  add_definitions( -DEXPORT_LIBLLDB )
-endif()
-
 get_property(LLDB_ALL_PLUGINS GLOBAL PROPERTY LLDB_PLUGINS)
 
 if(LLDB_BUILD_FRAMEWORK)
@@ -165,6 +161,7 @@ set_target_properties(liblldb
   VERSION ${LLDB_VERSION}
 )
 
+target_compile_definitions(liblldb PRIVATE LLDB_IN_LIBLLDB)
 if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
   if (NOT LLDB_EXPORT_ALL_SYMBOLS)
 # If we're not exporting all symbols, we'll want to explicitly set

diff  --git a/lldb/tools/driver/CMakeLists.txt 
b/lldb/tools/driver/CMakeLists.txt
index c31863b205caa..c93cd171b92b4 100644
--- a/lldb/tools/driver/CMakeLists.txt
+++ b/lldb/tools/driver/CMakeLists.txt
@@ -23,10 +23,6 @@ add_lldb_tool(lldb
 Support
   )
 
-if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
-  add_definitions( -DIMPORT_LIBLLDB )
-endif()
-
 add_dependencies(lldb
   LLDBOptionsTableGen
   ${tablegen_deps}

diff  --git a/lldb/tools/lldb-vscode/CMakeLists.txt 
b/lldb/tools/lldb-vscode/CMakeLists.txt
index 4745d50bb2739..b68a4f3f67ab9 100644
--- a/lldb/tools/lldb-vscode/CMakeLists.txt
+++ b/lldb/tools/lldb-vscode/CMakeLists.txt
@@ -1,5 +1,4 @@
 if ( CMAKE_SYSTEM_NAME MATCHES "Windows" OR CMAKE_SYSTEM_NAME MATCHES "NetBSD" 
)
-  add_definitions( -DIMPORT_LIBLLDB )
   list(APPEND extra_libs lldbHost)
 endif ()
 



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


[Lldb-commits] [lldb] 9034245 - [lldb] Introduce SBPlatform::SetSDKRoot

2022-01-19 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-01-19T12:49:47+01:00
New Revision: 903424532f0b018447a00f8a534f362a9b3c246b

URL: 
https://github.com/llvm/llvm-project/commit/903424532f0b018447a00f8a534f362a9b3c246b
DIFF: 
https://github.com/llvm/llvm-project/commit/903424532f0b018447a00f8a534f362a9b3c246b.diff

LOG: [lldb] Introduce SBPlatform::SetSDKRoot

It complements the existing SBDebugger::SetCurrentPlatformSDKRoot and
allows one to set the sysroot of a platform without making it current.

Differential Revision: https://reviews.llvm.org/D117550

Added: 


Modified: 
lldb/bindings/interface/SBPlatform.i
lldb/include/lldb/API/SBPlatform.h
lldb/source/API/SBDebugger.cpp
lldb/source/API/SBPlatform.cpp
lldb/source/Target/Platform.cpp
lldb/test/API/python_api/sbplatform/TestSBPlatform.py

Removed: 




diff  --git a/lldb/bindings/interface/SBPlatform.i 
b/lldb/bindings/interface/SBPlatform.i
index 65615be7a361c..6413784e69e7c 100644
--- a/lldb/bindings/interface/SBPlatform.i
+++ b/lldb/bindings/interface/SBPlatform.i
@@ -177,6 +177,9 @@ public:
 uint32_t
 GetOSUpdateVersion ();
 
+void
+SetSDKRoot(const char *sysroot);
+
 lldb::SBError
 Get (lldb::SBFileSpec &src, lldb::SBFileSpec &dst);
 

diff  --git a/lldb/include/lldb/API/SBPlatform.h 
b/lldb/include/lldb/API/SBPlatform.h
index 98291f18247dc..dcc8a14ff0c1f 100644
--- a/lldb/include/lldb/API/SBPlatform.h
+++ b/lldb/include/lldb/API/SBPlatform.h
@@ -137,6 +137,8 @@ class LLDB_API SBPlatform {
 
   uint32_t GetOSUpdateVersion();
 
+  void SetSDKRoot(const char *sysroot);
+
   SBError Put(SBFileSpec &src, SBFileSpec &dst);
 
   SBError Get(SBFileSpec &src, SBFileSpec &dst);

diff  --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index aa7d4805cf14f..e8d723810fb4b 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -1533,18 +1533,9 @@ bool SBDebugger::SetCurrentPlatformSDKRoot(const char 
*sysroot) {
   LLDB_RECORD_METHOD(bool, SBDebugger, SetCurrentPlatformSDKRoot,
  (const char *), sysroot);
 
-  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
-  if (m_opaque_sp) {
-PlatformSP platform_sp(
-m_opaque_sp->GetPlatformList().GetSelectedPlatform());
-
-if (platform_sp) {
-  if (log && sysroot)
-LLDB_LOGF(log, "SBDebugger::SetCurrentPlatformSDKRoot (\"%s\")",
-  sysroot);
-  platform_sp->SetSDKRootDirectory(ConstString(sysroot));
-  return true;
-}
+  if (SBPlatform platform = GetSelectedPlatform()) {
+platform.SetSDKRoot(sysroot);
+return true;
   }
   return false;
 }

diff  --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp
index 5e314ec8f59b5..5b0f1c3e1e213 100644
--- a/lldb/source/API/SBPlatform.cpp
+++ b/lldb/source/API/SBPlatform.cpp
@@ -513,6 +513,12 @@ uint32_t SBPlatform::GetOSUpdateVersion() {
   return version.getSubminor().getValueOr(UINT32_MAX);
 }
 
+void SBPlatform::SetSDKRoot(const char *sysroot) {
+  LLDB_RECORD_METHOD(void, SBPlatform, SetSDKRoot, (const char *), sysroot);
+  if (PlatformSP platform_sp = GetSP())
+platform_sp->SetSDKRootDirectory(ConstString(sysroot));
+}
+
 SBError SBPlatform::Get(SBFileSpec &src, SBFileSpec &dst) {
   LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Get,
  (lldb::SBFileSpec &, lldb::SBFileSpec &), src, dst);

diff  --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index af5ca0225169f..00e1c16032275 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -428,6 +428,9 @@ void Platform::GetStatus(Stream &strm) {
 strm.Printf(" Connected: %s\n", is_connected ? "yes" : "no");
   }
 
+  if (GetSDKRootDirectory()) {
+strm.Format("   Sysroot: {0}\n", GetSDKRootDirectory());
+  }
   if (GetWorkingDirectory()) {
 strm.Printf("WorkingDir: %s\n", GetWorkingDirectory().GetCString());
   }

diff  --git a/lldb/test/API/python_api/sbplatform/TestSBPlatform.py 
b/lldb/test/API/python_api/sbplatform/TestSBPlatform.py
index b354a6e28a085..f47e0b2660a47 100644
--- a/lldb/test/API/python_api/sbplatform/TestSBPlatform.py
+++ b/lldb/test/API/python_api/sbplatform/TestSBPlatform.py
@@ -20,3 +20,11 @@ def cleanup():
 cmd = lldb.SBPlatformShellCommand(self.getBuildArtifact("a.out"))
 self.assertTrue(plat.Run(cmd).Success())
 self.assertIn("MY_TEST_ENV_VAR=SBPlatformAPICase.test_run", 
cmd.GetOutput())
+
+def test_SetSDKRoot(self):
+plat = lldb.SBPlatform("remote-linux") # arbitrary choice
+self.assertTrue(plat)
+plat.SetSDKRoot(self.getBuildDir())
+self.dbg.SetCurrentPlatform("remote-linux")
+self.expect("platform status",
+substrs=["Sysroot:", self.getBuildDir()])



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https:

[Lldb-commits] [PATCH] D117564: [lldb] Remove the requirement for windows clients to specify -DIMPORT_LIBLLDB

2022-01-19 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb2a162e63bd7: [lldb] Remove the requirement for windows 
clients to specify -DIMPORT_LIBLLDB (authored by labath).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117564

Files:
  lldb/include/lldb/API/SBDefines.h
  lldb/include/lldb/lldb-defines.h
  lldb/source/API/CMakeLists.txt
  lldb/tools/driver/CMakeLists.txt
  lldb/tools/lldb-vscode/CMakeLists.txt


Index: lldb/tools/lldb-vscode/CMakeLists.txt
===
--- lldb/tools/lldb-vscode/CMakeLists.txt
+++ lldb/tools/lldb-vscode/CMakeLists.txt
@@ -1,5 +1,4 @@
 if ( CMAKE_SYSTEM_NAME MATCHES "Windows" OR CMAKE_SYSTEM_NAME MATCHES "NetBSD" 
)
-  add_definitions( -DIMPORT_LIBLLDB )
   list(APPEND extra_libs lldbHost)
 endif ()
 
Index: lldb/tools/driver/CMakeLists.txt
===
--- lldb/tools/driver/CMakeLists.txt
+++ lldb/tools/driver/CMakeLists.txt
@@ -23,10 +23,6 @@
 Support
   )
 
-if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
-  add_definitions( -DIMPORT_LIBLLDB )
-endif()
-
 add_dependencies(lldb
   LLDBOptionsTableGen
   ${tablegen_deps}
Index: lldb/source/API/CMakeLists.txt
===
--- lldb/source/API/CMakeLists.txt
+++ lldb/source/API/CMakeLists.txt
@@ -1,7 +1,3 @@
-if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
-  add_definitions( -DEXPORT_LIBLLDB )
-endif()
-
 get_property(LLDB_ALL_PLUGINS GLOBAL PROPERTY LLDB_PLUGINS)
 
 if(LLDB_BUILD_FRAMEWORK)
@@ -165,6 +161,7 @@
   VERSION ${LLDB_VERSION}
 )
 
+target_compile_definitions(liblldb PRIVATE LLDB_IN_LIBLLDB)
 if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
   if (NOT LLDB_EXPORT_ALL_SYMBOLS)
 # If we're not exporting all symbols, we'll want to explicitly set
Index: lldb/include/lldb/lldb-defines.h
===
--- lldb/include/lldb/lldb-defines.h
+++ lldb/include/lldb/lldb-defines.h
@@ -11,18 +11,6 @@
 
 #include "lldb/lldb-types.h"
 
-#if defined(_WIN32)
-#if defined(EXPORT_LIBLLDB)
-#define LLDB_API __declspec(dllexport)
-#elif defined(IMPORT_LIBLLDB)
-#define LLDB_API __declspec(dllimport)
-#else
-#define LLDB_API
-#endif
-#else // defined (_WIN32)
-#define LLDB_API
-#endif
-
 #if !defined(INT32_MAX)
 #define INT32_MAX 2147483647
 #endif
Index: lldb/include/lldb/API/SBDefines.h
===
--- lldb/include/lldb/API/SBDefines.h
+++ lldb/include/lldb/API/SBDefines.h
@@ -15,6 +15,16 @@
 #include "lldb/lldb-types.h"
 #include "lldb/lldb-versioning.h"
 
+#if defined(_WIN32)
+#if defined(LLDB_IN_LIBLLDB)
+#define LLDB_API __declspec(dllexport)
+#else
+#define LLDB_API __declspec(dllimport)
+#endif
+#else // defined (_WIN32)
+#define LLDB_API
+#endif
+
 // Forward Declarations
 namespace lldb {
 


Index: lldb/tools/lldb-vscode/CMakeLists.txt
===
--- lldb/tools/lldb-vscode/CMakeLists.txt
+++ lldb/tools/lldb-vscode/CMakeLists.txt
@@ -1,5 +1,4 @@
 if ( CMAKE_SYSTEM_NAME MATCHES "Windows" OR CMAKE_SYSTEM_NAME MATCHES "NetBSD" )
-  add_definitions( -DIMPORT_LIBLLDB )
   list(APPEND extra_libs lldbHost)
 endif ()
 
Index: lldb/tools/driver/CMakeLists.txt
===
--- lldb/tools/driver/CMakeLists.txt
+++ lldb/tools/driver/CMakeLists.txt
@@ -23,10 +23,6 @@
 Support
   )
 
-if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
-  add_definitions( -DIMPORT_LIBLLDB )
-endif()
-
 add_dependencies(lldb
   LLDBOptionsTableGen
   ${tablegen_deps}
Index: lldb/source/API/CMakeLists.txt
===
--- lldb/source/API/CMakeLists.txt
+++ lldb/source/API/CMakeLists.txt
@@ -1,7 +1,3 @@
-if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
-  add_definitions( -DEXPORT_LIBLLDB )
-endif()
-
 get_property(LLDB_ALL_PLUGINS GLOBAL PROPERTY LLDB_PLUGINS)
 
 if(LLDB_BUILD_FRAMEWORK)
@@ -165,6 +161,7 @@
   VERSION ${LLDB_VERSION}
 )
 
+target_compile_definitions(liblldb PRIVATE LLDB_IN_LIBLLDB)
 if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
   if (NOT LLDB_EXPORT_ALL_SYMBOLS)
 # If we're not exporting all symbols, we'll want to explicitly set
Index: lldb/include/lldb/lldb-defines.h
===
--- lldb/include/lldb/lldb-defines.h
+++ lldb/include/lldb/lldb-defines.h
@@ -11,18 +11,6 @@
 
 #include "lldb/lldb-types.h"
 
-#if defined(_WIN32)
-#if defined(EXPORT_LIBLLDB)
-#define LLDB_API __declspec(dllexport)
-#elif defined(IMPORT_LIBLLDB)
-#define LLDB_API __declspec(dllimport)
-#else
-#define LLDB_API
-#endif
-#else // defined (_WIN32)
-#define LLDB_API
-#endif
-
 #if !defined(INT32_MAX)
 #define INT32_MAX 2147483647
 #endif
Index: lldb/include/lldb/API/SBDefines

[Lldb-commits] [PATCH] D117550: [lldb] Introduce SBPlatform::SetSDKRoot

2022-01-19 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG903424532f0b: [lldb] Introduce SBPlatform::SetSDKRoot 
(authored by labath).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117550

Files:
  lldb/bindings/interface/SBPlatform.i
  lldb/include/lldb/API/SBPlatform.h
  lldb/source/API/SBDebugger.cpp
  lldb/source/API/SBPlatform.cpp
  lldb/source/Target/Platform.cpp
  lldb/test/API/python_api/sbplatform/TestSBPlatform.py


Index: lldb/test/API/python_api/sbplatform/TestSBPlatform.py
===
--- lldb/test/API/python_api/sbplatform/TestSBPlatform.py
+++ lldb/test/API/python_api/sbplatform/TestSBPlatform.py
@@ -20,3 +20,11 @@
 cmd = lldb.SBPlatformShellCommand(self.getBuildArtifact("a.out"))
 self.assertTrue(plat.Run(cmd).Success())
 self.assertIn("MY_TEST_ENV_VAR=SBPlatformAPICase.test_run", 
cmd.GetOutput())
+
+def test_SetSDKRoot(self):
+plat = lldb.SBPlatform("remote-linux") # arbitrary choice
+self.assertTrue(plat)
+plat.SetSDKRoot(self.getBuildDir())
+self.dbg.SetCurrentPlatform("remote-linux")
+self.expect("platform status",
+substrs=["Sysroot:", self.getBuildDir()])
Index: lldb/source/Target/Platform.cpp
===
--- lldb/source/Target/Platform.cpp
+++ lldb/source/Target/Platform.cpp
@@ -428,6 +428,9 @@
 strm.Printf(" Connected: %s\n", is_connected ? "yes" : "no");
   }
 
+  if (GetSDKRootDirectory()) {
+strm.Format("   Sysroot: {0}\n", GetSDKRootDirectory());
+  }
   if (GetWorkingDirectory()) {
 strm.Printf("WorkingDir: %s\n", GetWorkingDirectory().GetCString());
   }
Index: lldb/source/API/SBPlatform.cpp
===
--- lldb/source/API/SBPlatform.cpp
+++ lldb/source/API/SBPlatform.cpp
@@ -513,6 +513,12 @@
   return version.getSubminor().getValueOr(UINT32_MAX);
 }
 
+void SBPlatform::SetSDKRoot(const char *sysroot) {
+  LLDB_RECORD_METHOD(void, SBPlatform, SetSDKRoot, (const char *), sysroot);
+  if (PlatformSP platform_sp = GetSP())
+platform_sp->SetSDKRootDirectory(ConstString(sysroot));
+}
+
 SBError SBPlatform::Get(SBFileSpec &src, SBFileSpec &dst) {
   LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Get,
  (lldb::SBFileSpec &, lldb::SBFileSpec &), src, dst);
Index: lldb/source/API/SBDebugger.cpp
===
--- lldb/source/API/SBDebugger.cpp
+++ lldb/source/API/SBDebugger.cpp
@@ -1533,18 +1533,9 @@
   LLDB_RECORD_METHOD(bool, SBDebugger, SetCurrentPlatformSDKRoot,
  (const char *), sysroot);
 
-  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
-  if (m_opaque_sp) {
-PlatformSP platform_sp(
-m_opaque_sp->GetPlatformList().GetSelectedPlatform());
-
-if (platform_sp) {
-  if (log && sysroot)
-LLDB_LOGF(log, "SBDebugger::SetCurrentPlatformSDKRoot (\"%s\")",
-  sysroot);
-  platform_sp->SetSDKRootDirectory(ConstString(sysroot));
-  return true;
-}
+  if (SBPlatform platform = GetSelectedPlatform()) {
+platform.SetSDKRoot(sysroot);
+return true;
   }
   return false;
 }
Index: lldb/include/lldb/API/SBPlatform.h
===
--- lldb/include/lldb/API/SBPlatform.h
+++ lldb/include/lldb/API/SBPlatform.h
@@ -137,6 +137,8 @@
 
   uint32_t GetOSUpdateVersion();
 
+  void SetSDKRoot(const char *sysroot);
+
   SBError Put(SBFileSpec &src, SBFileSpec &dst);
 
   SBError Get(SBFileSpec &src, SBFileSpec &dst);
Index: lldb/bindings/interface/SBPlatform.i
===
--- lldb/bindings/interface/SBPlatform.i
+++ lldb/bindings/interface/SBPlatform.i
@@ -177,6 +177,9 @@
 uint32_t
 GetOSUpdateVersion ();
 
+void
+SetSDKRoot(const char *sysroot);
+
 lldb::SBError
 Get (lldb::SBFileSpec &src, lldb::SBFileSpec &dst);
 


Index: lldb/test/API/python_api/sbplatform/TestSBPlatform.py
===
--- lldb/test/API/python_api/sbplatform/TestSBPlatform.py
+++ lldb/test/API/python_api/sbplatform/TestSBPlatform.py
@@ -20,3 +20,11 @@
 cmd = lldb.SBPlatformShellCommand(self.getBuildArtifact("a.out"))
 self.assertTrue(plat.Run(cmd).Success())
 self.assertIn("MY_TEST_ENV_VAR=SBPlatformAPICase.test_run", cmd.GetOutput())
+
+def test_SetSDKRoot(self):
+plat = lldb.SBPlatform("remote-linux") # arbitrary choice
+self.assertTrue(plat)
+plat.SetSDKRoot(self.getBuildDir())
+self.dbg.SetCurrentPlatform("remote-linux")
+self.expect("platform status",
+substrs=["Sysroot:", self.getBuildDir()])
Index: lldb/source/Target/

[Lldb-commits] [PATCH] D117637: Fix build break on CentOS due to gcc 7.3.1

2022-01-19 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

I needed to dust off my old-deps build for another patch, so I also fixed this 
in the process.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117637

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


[Lldb-commits] [PATCH] D117559: [lldb] Remove remote testing ability from lldb**-server** tests

2022-01-19 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

In D117559#3254095 , @DavidSpickett 
wrote:

> I'm running 
> `lldb/test/API/tools/lldb-server/memory-tagging/TestGdbRemoteMemoryTagging.py`.
>
> If the details matter any...
>
> In qemu:
>
>   $ ./build-cross/bin/lldb-server platform --server --listen 0.0.0.0:54321
>
> On the host:
>
>   $ ./bin/lldb-dotest --platform-name remote-linux --platform-url 
> connect://:54321 --platform-working-dir /tmp/test_lldb -p 
> TestGdbRemoteMemoryTagging.py --arch aarch64

Got it. Thanks.

> I have qemu setup so that any port lldb-server picks should be accessible 
> from the host and the VM is just running the usual background linux stuff 
> plus lldb-server. Not a lot to use up ports.

The tricky part is that even individual parallel test runs (if you run the 
whole test suite, not just a single test like you did above) can race with each 
other.

> Can you remind me what forward/reverse mean here? I guess that forward is us 
> telling the remote the port to use, which might already be taken on the 
> remote itself.

Correct.

> Then reverse is the remote launching the lldb-server on a port it chooses, 
> then telling us what it chose.

Not quite. In "reverse mode" it is the client (in this case -- the test suite) 
who is choosing a port and listening on it. lldb-server gets an address and it 
connects to it.

We also have the method which you described (we probably have more connection 
methods than we should). That one is also reliable (though it gets fuzzy with 
IPv6, as then the port number alone does not uniquely identify an endpoint), 
but it has more moving parts, and it is not implemented in the test suite -- 
just in the client, which we don't use for these tests.

One of the goals I am trying to achieve here is actually to be able to test the 
various connection methods at the lldb-server level, but for that I need to 
untangle the connection code from the rest of the test suite setup. And ideally 
I would only support one method (the simplest one) for the remote connections 
and have mark other tests `@skipIfRemote` -- the reason for that is that we'd 
need different code to (e.g.) read the server-selected port from a remote 
machine than we would for the local one, so this would be more of a test of the 
test suite than the server itself.

In D117559#3254148 , @omjavaid wrote:

> This doesnt interfere with LLDB tests for SVE. Rather I have not used it in a 
> while for SVE tests I ahve using setup similar to to one David has explained 
> above.

If you're using the setup that David mentioned, then this would break that.

I am going to try to make a patch to use reverse connect for these tests 
instead.

> @labath Do you know if android adb based tests are being run anywhere? Are we 
> still maintaining this support and does it work?

I would guess "no", but I don't know, really. I created this patch to find that 
out myself. :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117559

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


Re: [Lldb-commits] [PATCH] D117559: [lldb] Remove remote testing ability from lldb**-server** tests

2022-01-19 Thread Omair Javaid via lldb-commits
On Wed, 19 Jan 2022 at 17:53, Pavel Labath via Phabricator <
revi...@reviews.llvm.org> wrote:

> labath added a comment.
>
> In D117559#3254095 ,
> @DavidSpickett wrote:
>
> > I'm running
> `lldb/test/API/tools/lldb-server/memory-tagging/TestGdbRemoteMemoryTagging.py`.
> >
> > If the details matter any...
> >
> > In qemu:
> >
> >   $ ./build-cross/bin/lldb-server platform --server --listen
> 0.0.0.0:54321
> >
> > On the host:
> >
> >   $ ./bin/lldb-dotest --platform-name remote-linux --platform-url
> connect://:54321 --platform-working-dir /tmp/test_lldb -p
> TestGdbRemoteMemoryTagging.py --arch aarch64
>
> Got it. Thanks.
>
> > I have qemu setup so that any port lldb-server picks should be
> accessible from the host and the VM is just running the usual background
> linux stuff plus lldb-server. Not a lot to use up ports.
>
> The tricky part is that even individual parallel test runs (if you run the
> whole test suite, not just a single test like you did above) can race with
> each other.
>
> > Can you remind me what forward/reverse mean here? I guess that forward
> is us telling the remote the port to use, which might already be taken on
> the remote itself.
>
> Correct.
>
> > Then reverse is the remote launching the lldb-server on a port it
> chooses, then telling us what it chose.
>
> Not quite. In "reverse mode" it is the client (in this case -- the test
> suite) who is choosing a port and listening on it. lldb-server gets an
> address and it connects to it.
>
> We also have the method which you described (we probably have more
> connection methods than we should). That one is also reliable (though it
> gets fuzzy with IPv6, as then the port number alone does not uniquely
> identify an endpoint), but it has more moving parts, and it is not
> implemented in the test suite -- just in the client, which we don't use for
> these tests.
>
> One of the goals I am trying to achieve here is actually to be able to
> test the various connection methods at the lldb-server level, but for that
> I need to untangle the connection code from the rest of the test suite
> setup. And ideally I would only support one method (the simplest one) for
> the remote connections and have mark other tests `@skipIfRemote` -- the
> reason for that is that we'd need different code to (e.g.) read the
> server-selected port from a remote machine than we would for the local one,
> so this would be more of a test of the test suite than the server itself.
>
> In D117559#3254148 , @omjavaid
> wrote:
>
> > This doesnt interfere with LLDB tests for SVE. Rather I have not used it
> in a while for SVE tests I ahve using setup similar to to one David has
> explained above.
>
> If you're using the setup that David mentioned, then this would break that.
>
> I am going to try to make a patch to use reverse connect for these tests
> instead.
>
The current set of changes at least dont hurt. I actually tried a test run
with your patch applied before responding.


>
> > @labath Do you know if android adb based tests are being run anywhere?
> Are we still maintaining this support and does it work?
>
> I would guess "no", but I don't know, really. I created this patch to find
> that out myself. :)
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D117559/new/
>
> https://reviews.llvm.org/D117559
>
>
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D117632: Instrument SBAPI with scoped timers

2022-01-19 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

In D117632#3253445 , @jingham wrote:

> I was about to say this shouldn't matter, since most people don't run with 
> timers enabled and the timers should be no-ops when timing is off.  But 
> LLDB_SCOPED_TIMER seems to do a bunch of work even when the timers are 
> disabled.  The work includes "look up the Category in the map of categories, 
> making a new one if not found", get the current time of day and stash that 
> away, and do whatever the Signpost chooses to do on entry & exit.  So this 
> would be adding non-trivial work for everybody for every SB API call.
>
> Is this really necessary?  Seems like you could have LLDB_SCOPED_TIMER do 
> nothing if the Timer::g_display_depth == 0.  That would mean that you 
> wouldn't get timings for the remaining bit of any timers that would have been 
> active when you enabled the timers, but that doesn't seem particularly wrong 
> to me...

The way that timers currently work is that they are always active and measuring 
and can always be retrieved via `log timers dump`. `g_display_depth` (and `log 
timers enable`) only control whether their information gets dumped to stdout.

Apart from that, I don't have any particular opinion on this. I can't say I 
have found the lldb timers particularly useful. I think we could make then 
sufficiently cheap so that they could be added to every SB method (and hidden 
in the LLDB_RECORD_METHOD macro, since we already have it), but if I wanted to 
do some performance analysis, I'd probably use a profiler.


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

https://reviews.llvm.org/D117632

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


[Lldb-commits] [PATCH] D117671: [lldb] Rename MemoryTagManager RemoveNonAddressBits to RemoveTagBits

2022-01-19 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett created this revision.
Herald added a subscriber: kristof.beyls.
DavidSpickett requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This better describes the intent of the method. Which for AArch64
is removing the top byte which includes the memory tags.

It does not include pointer signatures, for those we need to use
the ABI plugin. The rename makes this a little more clear.

It's a bit awkward that the memory tag manager is removing the whole
top byte not just the memory tags but it's an improvement for now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117671

Files:
  lldb/include/lldb/Target/MemoryTagManager.h
  lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/source/Plugins/Process/Utility/MemoryTagManagerAArch64MTE.cpp
  lldb/source/Plugins/Process/Utility/MemoryTagManagerAArch64MTE.h
  lldb/unittests/Process/Utility/MemoryTagManagerAArch64MTETest.cpp

Index: lldb/unittests/Process/Utility/MemoryTagManagerAArch64MTETest.cpp
===
--- lldb/unittests/Process/Utility/MemoryTagManagerAArch64MTETest.cpp
+++ lldb/unittests/Process/Utility/MemoryTagManagerAArch64MTETest.cpp
@@ -247,16 +247,17 @@
   ASSERT_EQ(*got, expected_range);
 }
 
-TEST(MemoryTagManagerAArch64MTETest, RemoveNonAddressBits) {
+TEST(MemoryTagManagerAArch64MTETest, RemoveTagBits) {
   MemoryTagManagerAArch64MTE manager;
 
   ASSERT_EQ(0, 0);
+  // Removes the whole top byte
   ASSERT_EQ((lldb::addr_t)0x00ffeedd11223344,
-manager.RemoveNonAddressBits(0x00ffeedd11223344));
+manager.RemoveTagBits(0x00ffeedd11223344));
   ASSERT_EQ((lldb::addr_t)0x,
-manager.RemoveNonAddressBits(0xFF00));
+manager.RemoveTagBits(0xff00));
   ASSERT_EQ((lldb::addr_t)0x0055,
-manager.RemoveNonAddressBits(0xee55));
+manager.RemoveTagBits(0xee55));
 }
 
 TEST(MemoryTagManagerAArch64MTETest, AddressDiff) {
Index: lldb/source/Plugins/Process/Utility/MemoryTagManagerAArch64MTE.h
===
--- lldb/source/Plugins/Process/Utility/MemoryTagManagerAArch64MTE.h
+++ lldb/source/Plugins/Process/Utility/MemoryTagManagerAArch64MTE.h
@@ -27,7 +27,7 @@
   size_t GetTagSizeInBytes() const override;
 
   lldb::addr_t GetLogicalTag(lldb::addr_t addr) const override;
-  lldb::addr_t RemoveNonAddressBits(lldb::addr_t addr) const override;
+  lldb::addr_t RemoveTagBits(lldb::addr_t addr) const override;
   ptrdiff_t AddressDiff(lldb::addr_t addr1, lldb::addr_t addr2) const override;
 
   TagRange ExpandToGranule(TagRange range) const override;
Index: lldb/source/Plugins/Process/Utility/MemoryTagManagerAArch64MTE.cpp
===
--- lldb/source/Plugins/Process/Utility/MemoryTagManagerAArch64MTE.cpp
+++ lldb/source/Plugins/Process/Utility/MemoryTagManagerAArch64MTE.cpp
@@ -20,7 +20,7 @@
 }
 
 lldb::addr_t
-MemoryTagManagerAArch64MTE::RemoveNonAddressBits(lldb::addr_t addr) const {
+MemoryTagManagerAArch64MTE::RemoveTagBits(lldb::addr_t addr) const {
   // Here we're ignoring the whole top byte. If you've got MTE
   // you must also have TBI (top byte ignore).
   // The other 4 bits could contain other extension bits or
@@ -30,7 +30,7 @@
 
 ptrdiff_t MemoryTagManagerAArch64MTE::AddressDiff(lldb::addr_t addr1,
   lldb::addr_t addr2) const {
-  return RemoveNonAddressBits(addr1) - RemoveNonAddressBits(addr2);
+  return RemoveTagBits(addr1) - RemoveTagBits(addr2);
 }
 
 lldb::addr_t MemoryTagManagerAArch64MTE::GetGranuleSize() const {
@@ -84,7 +84,7 @@
 
   // Region addresses will not have memory tags. So when searching
   // we must use an untagged address.
-  MemoryRegionInfo::RangeType tag_range(RemoveNonAddressBits(addr), len);
+  MemoryRegionInfo::RangeType tag_range(RemoveTagBits(addr), len);
   tag_range = ExpandToGranule(tag_range);
 
   // Make a copy so we can use the original for errors and the final return.
Index: lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
===
--- lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -1365,10 +1365,9 @@
 
   // lldb will align the range it requests but it is not required to by
   // the protocol so we'll do it again just in case.
-  // Remove non address bits too. Ptrace calls may work regardless but that
+  // Remove tag bits too. Ptrace calls may work regardless but that
   // is not a guarantee.
-  MemoryTagManager::TagRange range(details->manager->RemoveNonAddressBits(addr),
-   len);
+  MemoryTagManager::TagRange range(details->manager->RemoveTagBits(addr), len);
   range = details->manager->Expa

[Lldb-commits] [PATCH] D117672: [lldb] Remove non-address bits from addresses given to memory tag commands

2022-01-19 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett created this revision.
DavidSpickett requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Although the memory tag commands use a memory tag manager to handle
addresses, that only removes the top byte.

That top byte is 4 bits of memory tag and 4 free bits, which is more
than it should strictly remove but that's how it is for now.

There are other non-address bit uses like pointer authentication.
To ensure the memory tag manager only has to deal with memory tags,
use the ABI plugin to remove the rest.

The tag access test has been updated to sign all the relevant pointers
and require that we're running on a system with pointer authentication
in addition to memory tagging.

The pointers will look like:
<4 bit user tag><4 bit memory tag>

Note that there is currently no API for reading memory tags. It will
also have to consider this when it arrives.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117672

Files:
  lldb/source/Commands/CommandObjectMemoryTag.cpp
  
lldb/test/API/linux/aarch64/mte_tag_access/TestAArch64LinuxMTEMemoryTagAccess.py
  lldb/test/API/linux/aarch64/mte_tag_access/main.c

Index: lldb/test/API/linux/aarch64/mte_tag_access/main.c
===
--- lldb/test/API/linux/aarch64/mte_tag_access/main.c
+++ lldb/test/API/linux/aarch64/mte_tag_access/main.c
@@ -71,8 +71,9 @@
   // tag
   char *mte_buf_alt_tag = __arm_mte_create_random_tag(mte_buf, ~(1 << 10));
 
-  // lldb should be removing the whole top byte, not just the tags.
-  // So fill 63-60 with something non zero so we'll fail if we only remove tags.
+  // The memory tag manager should be removing the whole top byte, not just the
+  // tags. So fill 63-60 with something non zero so we'll fail if we only remove
+  // tags.
 #define SET_TOP_NIBBLE(ptr, value) \
   (char *)((size_t)(ptr) | ((size_t)((value)&0xf) << 60))
   // mte_buf_alt_tag's nibble > mte_buf to check that lldb isn't just removing
@@ -82,6 +83,15 @@
   mte_buf_2 = SET_TOP_NIBBLE(mte_buf_2, 0xC);
   mte_read_only = SET_TOP_NIBBLE(mte_read_only, 0xD);
 
+// The top level commands should be removing all non-address bits, including
+// pointer signatures. This signs ptr with PAC key A. That signature goes
+// in some bits other than the top byte.
+#define sign_ptr(ptr) __asm__ __volatile__("pacdza %0" : "=r"(ptr) : "r"(ptr))
+  sign_ptr(mte_buf);
+  sign_ptr(mte_buf_alt_tag);
+  sign_ptr(mte_buf_2);
+  sign_ptr(mte_read_only);
+
   // Breakpoint here
   return 0;
 }
Index: lldb/test/API/linux/aarch64/mte_tag_access/TestAArch64LinuxMTEMemoryTagAccess.py
===
--- lldb/test/API/linux/aarch64/mte_tag_access/TestAArch64LinuxMTEMemoryTagAccess.py
+++ lldb/test/API/linux/aarch64/mte_tag_access/TestAArch64LinuxMTEMemoryTagAccess.py
@@ -20,6 +20,11 @@
 if not self.isAArch64MTE():
 self.skipTest('Target must support MTE.')
 
+# Required to check that commands remove non-address bits
+# other than the memory tags.
+if not self.isAArch64PAuth():
+self.skipTest('Target must support pointer authentication')
+
 self.build()
 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
 
Index: lldb/source/Commands/CommandObjectMemoryTag.cpp
===
--- lldb/source/Commands/CommandObjectMemoryTag.cpp
+++ lldb/source/Commands/CommandObjectMemoryTag.cpp
@@ -12,6 +12,7 @@
 #include "lldb/Interpreter/OptionArgParser.h"
 #include "lldb/Interpreter/OptionGroupFormat.h"
 #include "lldb/Interpreter/OptionValueString.h"
+#include "lldb/Target/ABI.h"
 #include "lldb/Target/Process.h"
 
 using namespace lldb;
@@ -85,6 +86,17 @@
 // If this fails the list of regions is cleared, so we don't need to read
 // the return status here.
 process->GetMemoryRegions(memory_regions);
+
+lldb::addr_t logical_tag = tag_manager->GetLogicalTag(start_addr);
+
+// The tag manager only removes tag bits. These addresses may include other
+// non-address bits that must also be ignored.
+ABISP abi = process->GetABI();
+if (abi) {
+  start_addr = abi->FixDataAddress(start_addr);
+  end_addr = abi->FixDataAddress(end_addr);
+}
+
 llvm::Expected tagged_range =
 tag_manager->MakeTaggedRange(start_addr, end_addr, memory_regions);
 
@@ -101,7 +113,6 @@
   return false;
 }
 
-lldb::addr_t logical_tag = tag_manager->GetLogicalTag(start_addr);
 result.AppendMessageWithFormatv("Logical tag: {0:x}", logical_tag);
 result.AppendMessage("Allocation tags:");
 
@@ -231,6 +242,12 @@
 // the return status here.
 process->GetMemoryRegions(memory_regions);
 
+// The tag manager only removes tag bits. These addresses may include other
+// non-address bits that mus

[Lldb-commits] [PATCH] D117490: [lldb] Log prototype

2022-01-19 Thread Pavel Labath via Phabricator via lldb-commits
labath added inline comments.



Comment at: lldb/include/lldb/Utility/Logging.h:19
+enum class LLDBLog : uint32_t {
+  Process = 1u << 1,
+  LLVM_MARK_AS_BITMASK_ENUM(UINT32_MAX)

clayborg wrote:
> Why wouldn't we just add all of the categories in the enum? Are we trying to 
> reduce code changes?
Yes, the full patch would definitely do that. This was just something I quickly 
whipped up to demonstrate how I thought this could work.



Comment at: lldb/include/lldb/Utility/Logging.h:20
+  Process = 1u << 1,
+  LLVM_MARK_AS_BITMASK_ENUM(UINT32_MAX)
+};

clayborg wrote:
> Can we add members here to grab the log channels directly from the LLLDBLog 
> enum? Something like:
> 
> ```
> static Log *GetLogIfAll(LLDBLog mask);
> static Log *GetLogIfAny(LLDBLog mask);
> ```
The idea is that there will be a single (templated) `GetLogIfAny/All` function 
(see Log.h:218), and that one will automatically select (based on the type of 
the enum) the right channel.



Comment at: lldb/include/lldb/Utility/Logging.h:26
 // Log Bits specific to logging in lldb
-#define LIBLLDB_LOG_PROCESS (1u << 1)
-#define LIBLLDB_LOG_THREAD (1u << 2)
-#define LIBLLDB_LOG_DYNAMIC_LOADER (1u << 3)
-#define LIBLLDB_LOG_EVENTS (1u << 4)
-#define LIBLLDB_LOG_BREAKPOINTS (1u << 5)
-#define LIBLLDB_LOG_WATCHPOINTS (1u << 6)
-#define LIBLLDB_LOG_STEP (1u << 7)
-#define LIBLLDB_LOG_EXPRESSIONS (1u << 8)
-#define LIBLLDB_LOG_TEMPORARY (1u << 9)
-#define LIBLLDB_LOG_STATE (1u << 10)
-#define LIBLLDB_LOG_OBJECT (1u << 11)
-#define LIBLLDB_LOG_COMMUNICATION (1u << 12)
-#define LIBLLDB_LOG_CONNECTION (1u << 13)
-#define LIBLLDB_LOG_HOST (1u << 14)
-#define LIBLLDB_LOG_UNWIND (1u << 15)
-#define LIBLLDB_LOG_API (1u << 16)
-#define LIBLLDB_LOG_SCRIPT (1u << 17)
-#define LIBLLDB_LOG_COMMANDS (1U << 18)
-#define LIBLLDB_LOG_TYPES (1u << 19)
-#define LIBLLDB_LOG_SYMBOLS (1u << 20)
-#define LIBLLDB_LOG_MODULES (1u << 21)
-#define LIBLLDB_LOG_TARGET (1u << 22)
-#define LIBLLDB_LOG_MMAP (1u << 23)
-#define LIBLLDB_LOG_OS (1u << 24)
-#define LIBLLDB_LOG_PLATFORM (1u << 25)
-#define LIBLLDB_LOG_SYSTEM_RUNTIME (1u << 26)
-#define LIBLLDB_LOG_JIT_LOADER (1u << 27)
-#define LIBLLDB_LOG_LANGUAGE (1u << 28)
-#define LIBLLDB_LOG_DATAFORMATTERS (1u << 29)
-#define LIBLLDB_LOG_DEMANGLE (1u << 30)
-#define LIBLLDB_LOG_AST (1u << 31)
-#define LIBLLDB_LOG_ALL (UINT32_MAX)
+#define LIBLLDB_LOG_PROCESS ::lldb_private::LLDBLog::Process
+#define LIBLLDB_LOG_THREAD ::lldb_private::LLDBLog(1u << 2)

clayborg wrote:
> Seems like using LLDBLog::Process everywhere instead of LIBLLDB_LOG_PROCESS 
> would be cleaner? Are we just trying to reduce code changes?
Yes, the goal would be do delete these completely, but I'd split this into two 
patch -- first do the functional changes, and then do a search-replace to get 
rid of all the macros.



Comment at: lldb/include/lldb/Utility/Logging.h:64-66
+Log *GetLogIfAllCategoriesSet(LLDBLog mask);
 
+Log *GetLogIfAnyCategoriesSet(LLDBLog mask);

These functions are also just temporary



Comment at: lldb/include/lldb/Utility/Logging.h:70
 
+template <> Log::Channel &LogChannelFor();
 } // namespace lldb_private

This is what ties an enum to a particular channel.



Comment at: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp:17
 
 static constexpr Log::Category g_categories[] = {
+{{"async"}, {"log asynchronous activity"}, uint32_t(GDBR_LOG_ASYNC)},

clayborg wrote:
> Should the Log::Category be templatized with GDBRLog and then we just store 
> GDBRLog enum values instead of uint32_t values?
The problem with that is that it would require templatizing pretty much all of 
the logging code (as it deals with categories in one way or another), but I 
agree that we should at least make the category definitions nice. It should be 
possible to keep templates here, but then convert to integers when we get to 
the core logging code, but i did not want to get entagled in that for the 
prototype.



Comment at: lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp:57
   ProcessSP process_sp(GetProcess());
-  Log *log(GetLogIfAnyCategoriesSet(GDBR_LOG_THREAD));
+  Log *log(GetLogIfAny(GDBR_LOG_THREAD));
   LLDB_LOG(log, "this = {0}, pid = {1}, tid = {2}", this,

clayborg wrote:
> I would love these to be cleaner. Maybe something like:
> ```
> Log *log = GDBRLog.GetLogIfAny(GDBRLog::Thread);
> ```
`Log *log = GetLogIfAny(GDBRLog::Thread);` is the final goal.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117490

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


[Lldb-commits] [PATCH] D117671: [lldb] Rename MemoryTagManager RemoveNonAddressBits to RemoveTagBits

2022-01-19 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a reviewer: omjavaid.
DavidSpickett added a comment.

As promised on https://reviews.llvm.org/D112824.

I hope to get to a point where the tag managers only remove memory tag bits so 
this is a step toward that.




Comment at: lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp:1370
   // is not a guarantee.
-  MemoryTagManager::TagRange 
range(details->manager->RemoveNonAddressBits(addr),
-   len);
+  MemoryTagManager::TagRange range(details->manager->RemoveTagBits(addr), len);
   range = details->manager->ExpandToGranule(range);

The usage in lldb-server is why I have kept it removing the whole top byte to 
keep us in line with: 
https://dri.freedesktop.org/docs/drm/arm64/tagged-address-abi.html

You might wonder if we should remove non-address bits here too but going by 
that standard I think the answer is no.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117671

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


[Lldb-commits] [PATCH] D117676: [LLDB] Port toolchain-msvc.test for Arm/AArch4 Windows

2022-01-19 Thread Muhammad Omair Javaid via Phabricator via lldb-commits
omjavaid created this revision.
omjavaid added a reviewer: JDevlieghere.
Herald added a subscriber: kristof.beyls.
omjavaid requested review of this revision.

This patch updates toolchain-msvc.test to cater for Arm64 windows platform.


https://reviews.llvm.org/D117676

Files:
  lldb/test/Shell/BuildScript/toolchain-msvc.test

Index: lldb/test/Shell/BuildScript/toolchain-msvc.test
===
--- lldb/test/Shell/BuildScript/toolchain-msvc.test
+++ lldb/test/Shell/BuildScript/toolchain-msvc.test
@@ -1,62 +1,62 @@
-REQUIRES: system-windows, msvc
-
-RUN: %build -n --verbose --arch=32 --compiler=msvc --mode=compile-and-link -o %t/foo.exe foobar.c \
-RUN:| FileCheck --check-prefix=X86 %s
-
-RUN: %build -n --verbose --arch=64 --compiler=msvc --mode=compile-and-link -o %t/foo.exe foobar.c \
-RUN:| FileCheck --check-prefix=X64 %s
-
-X86: Script Arguments:
-X86:   Arch: 32
-X86:   Compiler: msvc
-X86:   Outdir: {{.*}}
-X86:   Output: {{.*}}toolchain-msvc.test.tmp\foo.exe
-X86:   Nodefaultlib: False
-X86:   Opt: none
-X86:   Mode: compile
-X86:   Clean: True
-X86:   Verbose: True
-X86:   Dryrun: True
-X86:   Inputs: foobar.c
-X86: Cleaning {{.*}}toolchain-msvc.test.tmp\foobar.ilk
-X86: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe-foobar.obj
-X86: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.pdb
-X86: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe
-X86: compiling foobar.c -> foo.exe-foobar.obj
-X86:   Command Line: {{.*}}\{{[Hh]ost[Xx]64}}\x86\cl.exe
-X86: linking foo.exe-foobar.obj -> foo.exe
-X86:   Command Line: {{.*}}\{{[Hh]ost[Xx]64}}\x86\link.exe
-X86:   Env
-X86: LIB = {{.*}}\ATLMFC\lib\x86
-X86:   {{.*}}\lib\x86
-X86:   {{.*}}\ucrt\x86
-X86:   {{.*}}\um\x86
-X86: PATH = {{.*}}\bin\{{[Hh]ost[Xx]64}}\x64
-
-
-X64: Script Arguments:
-X64:   Arch: 64
-X64:   Compiler: msvc
-X64:   Outdir: {{.*}}
-X64:   Output: {{.*}}toolchain-msvc.test.tmp\foo.exe
-X64:   Nodefaultlib: False
-X64:   Opt: none
-X64:   Mode: compile
-X64:   Clean: True
-X64:   Verbose: True
-X64:   Dryrun: True
-X64:   Inputs: foobar.c
-X64: Cleaning {{.*}}toolchain-msvc.test.tmp\foobar.ilk
-X64: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe-foobar.obj
-X64: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.pdb
-X64: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe
-X64: compiling foobar.c -> foo.exe-foobar.obj
-X64:   Command Line: {{.*}}\{{[Hh]ost[Xx]64}}\x64\cl.exe
-X64: linking foo.exe-foobar.obj -> foo.exe
-X64:   Command Line: {{.*}}\{{[Hh]ost[Xx]64}}\x64\link.exe
-X64:   Env
-X64: LIB = {{.*}}\ATLMFC\lib\x64
-X64:   {{.*}}\lib\x64
-X64:   {{.*}}\ucrt\x64
-X64:   {{.*}}\um\x64
-X64: PATH = {{.*}}\bin\{{[Hh]ost[Xx]64}}\x64
+REQUIRES: system-windows, msvc
+
+RUN: %build -n --verbose --arch=32 --compiler=msvc --mode=compile-and-link -o %t/foo.exe foobar.c \
+RUN:| FileCheck --check-prefix=32BIT %s
+
+RUN: %build -n --verbose --arch=64 --compiler=msvc --mode=compile-and-link -o %t/foo.exe foobar.c \
+RUN:| FileCheck --check-prefix=64BIT %s
+
+32BIT: Script Arguments:
+32BIT:   Arch: 32
+32BIT:   Compiler: msvc
+32BIT:   Outdir: {{.*}}
+32BIT:   Output: {{.*}}toolchain-msvc.test.tmp\foo.exe
+32BIT:   Nodefaultlib: False
+32BIT:   Opt: none
+32BIT:   Mode: compile
+32BIT:   Clean: True
+32BIT:   Verbose: True
+32BIT:   Dryrun: True
+32BIT:   Inputs: foobar.c
+32BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foobar.ilk
+32BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe-foobar.obj
+32BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.pdb
+32BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe
+32BIT: compiling foobar.c -> foo.exe-foobar.obj
+32BIT:   Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x86|arm)}}\cl.exe
+32BIT: linking foo.exe-foobar.obj -> foo.exe
+32BIT:   Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x86|arm)}}\link.exe
+32BIT:   Env
+32BIT: LIB = {{.*}}\ATLMFC\lib\{{(x86|arm)}}
+32BIT:   {{.*}}\lib\{{(x86|arm)}}
+32BIT:   {{.*}}\ucrt\{{(x86|arm)}}
+32BIT:   {{.*}}\um\{{(x86|arm)}}
+32BIT: PATH = {{.*}}\bin\{{[Hh]ost[Xx](64|86)}}\{{(x86|x64)}}
+
+
+64BIT: Script Arguments:
+64BIT:   Arch: 64
+64BIT:   Compiler: msvc
+64BIT:   Outdir: {{.*}}
+64BIT:   Output: {{.*}}toolchain-msvc.test.tmp\foo.exe
+64BIT:   Nodefaultlib: False
+64BIT:   Opt: none
+64BIT:   Mode: compile
+64BIT:   Clean: True
+64BIT:   Verbose: True
+64BIT:   Dryrun: True
+64BIT:   Inputs: foobar.c
+64BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foobar.ilk
+64BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe-foobar.obj
+64BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.pdb
+64BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe
+64BIT: compiling foobar.c -> foo.exe-foobar.obj
+64BIT:   Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x64|arm64)}}\cl.exe
+64BIT: linking foo.exe-foobar.obj -> foo.exe
+64BIT:   Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x64|arm64)}}\link.exe
+64BIT:   Env
+64BIT: LIB = {{.*}}\ATL

[Lldb-commits] [PATCH] D117581: [lldb] Use lldb-server by default on Windows

2022-01-19 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

TBH, I am not really surprised by that. My recollection was that windows 
lldb-server was still missing some features to be a viable replacement, but I 
was hoping that I have recalled incorrectly.

It'd definitely be interesting to see what the missing pieces are.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117581

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


[Lldb-commits] [lldb] 9c4e93c - [LLDB] Adjust compiler-full-path.test for Windows/Arm64

2022-01-19 Thread Muhammad Omair Javaid via lldb-commits

Author: TCWG
Date: 2022-01-19T19:47:03+05:00
New Revision: 9c4e93c71a80e9d6d4e9f1e9f90b14a6126e1f47

URL: 
https://github.com/llvm/llvm-project/commit/9c4e93c71a80e9d6d4e9f1e9f90b14a6126e1f47
DIFF: 
https://github.com/llvm/llvm-project/commit/9c4e93c71a80e9d6d4e9f1e9f90b14a6126e1f47.diff

LOG: [LLDB] Adjust compiler-full-path.test for Windows/Arm64

This patch updates compiler-full-path.test to make sure it passes on
Windows Arm64 platform with MSVC.

Added: 


Modified: 
lldb/test/Shell/BuildScript/compiler-full-path.test

Removed: 




diff  --git a/lldb/test/Shell/BuildScript/compiler-full-path.test 
b/lldb/test/Shell/BuildScript/compiler-full-path.test
index 592024e690eb5..5a781f570bd9e 100644
--- a/lldb/test/Shell/BuildScript/compiler-full-path.test
+++ b/lldb/test/Shell/BuildScript/compiler-full-path.test
@@ -7,5 +7,5 @@ RUN:FileCheck %s --check-prefix=CHECK-MSVC
 CHECK-CLANG: Command Line: /path/to/my/clang
 CHECK-SAME: -o
 
-CHECK-MSVC: Command Line: /path/to/my/x64/cl.exe
+CHECK-MSVC: Command Line: /path/to/my{{(\/|\\)(arm64|x64)(\/|\\)}}cl.exe
 CHECK-SAME: /Fo



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


[Lldb-commits] [PATCH] D117676: [LLDB] Port toolchain-msvc.test for Arm/AArch4 Windows

2022-01-19 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

FWIW, I consider the build.py script a failed experiment. The idea itself was 
not completely bad, but the lack of buy-in from sufficient amount of developers 
meant that it never really had a chance of fulfilling its (rather lofty) goals.

I think it should be removed or at least scaled back significantly. The only 
thing it's really used for these days is to invoke msvc and clang-cl, and I'm 
sure we can achieve the same thing with some lit substitutions as well...


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

https://reviews.llvm.org/D117676

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


[Lldb-commits] [PATCH] D117676: [LLDB] Port toolchain-msvc.test for Arm/AArch4 Windows

2022-01-19 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

To put it in a more constructive light, what I was trying to say that if you 
find yourself spending a lot of time struggling with the script, definitely 
down be afraid to strip it down, change how it works, or remove it completely.


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

https://reviews.llvm.org/D117676

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


[Lldb-commits] [PATCH] D117564: [lldb] Remove the requirement for windows clients to specify -DIMPORT_LIBLLDB

2022-01-19 Thread Nico Weber via Phabricator via lldb-commits
thakis added a comment.

Before this change, it was very easy to build liblldb as a static library (just 
don't define IMPORT_LIBLLDB and EXPORT_LIBLLDB). After this change, this is no 
longer possible on Windows (but it still works fine everywhere else). Is this 
intentional?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117564

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


[Lldb-commits] [PATCH] D117474: [lldb] Make StatsDuration thread-safe

2022-01-19 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

The precision is now limited to microseconds (arbitrary choice that I though 
should be sufficient) whereas previously it was... floating. There are no 
changes besides that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117474

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


[Lldb-commits] [PATCH] D117564: [lldb] Remove the requirement for windows clients to specify -DIMPORT_LIBLLDB

2022-01-19 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

Well.. I wouldn't say it was intentional, but building (lib)lldb as a static 
library is not really supported either.

Like, there's no way to do that from cmake. Some people using other build 
systems do that nonetheless, but it comes with all kinds of strings (regardless 
of the operating system).

So what happens now if you define LLDB_IN_LIBLLDB? Does dllexport explode if 
used in a static library?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117564

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


[Lldb-commits] [lldb] 4f89157 - [lldb] Make StatsDuration thread-safe

2022-01-19 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-01-19T16:42:53+01:00
New Revision: 4f89157b9d73711a7ce20b597f93eb17a3133adf

URL: 
https://github.com/llvm/llvm-project/commit/4f89157b9d73711a7ce20b597f93eb17a3133adf
DIFF: 
https://github.com/llvm/llvm-project/commit/4f89157b9d73711a7ce20b597f93eb17a3133adf.diff

LOG: [lldb] Make StatsDuration thread-safe

std::chrono::duration types are not thread-safe, and they cannot be
concurrently updated from multiple threads. Currently, we were doing
such a thing (only) in the DWARF indexing code
(DWARFUnit::ExtractDIEsRWLocked), but I think it can easily happen that
someone else tries to update another statistic like this without
bothering to check for thread safety.

This patch changes the StatsDuration type from a simple typedef into a
class in its own right. The class stores the duration internally as
std::atomic (so it can be updated atomically), but presents it
to its users as the usual chrono type (duration).

Differential Revision: https://reviews.llvm.org/D117474

Added: 


Modified: 
lldb/include/lldb/Breakpoint/Breakpoint.h
lldb/include/lldb/Core/Module.h
lldb/include/lldb/Symbol/SymbolFile.h
lldb/include/lldb/Target/Statistics.h
lldb/source/Breakpoint/Breakpoint.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
lldb/source/Target/Statistics.cpp

Removed: 




diff  --git a/lldb/include/lldb/Breakpoint/Breakpoint.h 
b/lldb/include/lldb/Breakpoint/Breakpoint.h
index 40435d5c3d0f..113f8c4905e1 100644
--- a/lldb/include/lldb/Breakpoint/Breakpoint.h
+++ b/lldb/include/lldb/Breakpoint/Breakpoint.h
@@ -581,7 +581,7 @@ class Breakpoint : public 
std::enable_shared_from_this,
   llvm::json::Value GetStatistics();
 
   /// Get the time it took to resolve all locations in this breakpoint.
-  StatsDuration GetResolveTime() const { return m_resolve_time; }
+  StatsDuration::Duration GetResolveTime() const { return m_resolve_time; }
 
 protected:
   friend class Target;
@@ -660,7 +660,7 @@ class Breakpoint : public 
std::enable_shared_from_this,
 
   BreakpointName::Permissions m_permissions;
 
-  StatsDuration m_resolve_time{0.0};
+  StatsDuration m_resolve_time;
 
   void SendBreakpointChangedEvent(lldb::BreakpointEventType eventKind);
 

diff  --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h
index d53481a1c720..f6c32586eda8 100644
--- a/lldb/include/lldb/Core/Module.h
+++ b/lldb/include/lldb/Core/Module.h
@@ -1047,11 +1047,11 @@ class Module : public 
std::enable_shared_from_this,
   /// We store a symbol table parse time duration here because we might have
   /// an object file and a symbol file which both have symbol tables. The parse
   /// time for the symbol tables can be aggregated here.
-  StatsDuration m_symtab_parse_time{0.0};
+  StatsDuration m_symtab_parse_time;
   /// We store a symbol named index time duration here because we might have
   /// an object file and a symbol file which both have symbol tables. The parse
   /// time for the symbol tables can be aggregated here.
-  StatsDuration m_symtab_index_time{0.0};
+  StatsDuration m_symtab_index_time;
 
   /// Resolve a file or load virtual address.
   ///

diff  --git a/lldb/include/lldb/Symbol/SymbolFile.h 
b/lldb/include/lldb/Symbol/SymbolFile.h
index 288576b978a7..6cdb2bfb686b 100644
--- a/lldb/include/lldb/Symbol/SymbolFile.h
+++ b/lldb/include/lldb/Symbol/SymbolFile.h
@@ -316,14 +316,14 @@ class SymbolFile : public PluginInterface {
   ///
   /// \returns 0.0 if no information has been parsed or if there is
   /// no computational cost to parsing the debug information.
-  virtual StatsDuration GetDebugInfoParseTime() { return StatsDuration(0.0); }
+  virtual StatsDuration::Duration GetDebugInfoParseTime() { return {}; }
 
   /// Return the time it took to index the debug information in the object
   /// file.
   ///
   /// \returns 0.0 if the file doesn't need to be indexed or if it
   /// hasn't been indexed yet, or a valid duration if it has.
-  virtual StatsDuration GetDebugInfoIndexTime() { return StatsDuration(0.0); }
+  virtual StatsDuration::Duration GetDebugInfoIndexTime() { return {}; }
 
   /// Accessors for the bool that indicates if the debug info index was loaded
   /// from, or saved to the module index cache.

diff  --git a/lldb/include/lldb/Target/Statistics.h 
b/lldb/include/lldb/Target/Statistics.h
index cf4fb83c816e..dbf3554986aa 100644
--- a/lldb/include/lldb/Target/Statistics.h
+++ b/lldb/include/lldb/Target/Statistics.h
@@ -9,20 +9,39 @@
 #ifndef LLDB_TARGET_STATISTICS_H
 #define LLDB_TARGET_STATISTICS_H
 
-#include 
-#include 
-#include 
-
 #include "lldb/Utility/Stream.h"
 #include "lldb/lldb-f

[Lldb-commits] [PATCH] D117474: [lldb] Make StatsDuration thread-safe

2022-01-19 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4f89157b9d73: [lldb] Make StatsDuration thread-safe 
(authored by labath).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117474

Files:
  lldb/include/lldb/Breakpoint/Breakpoint.h
  lldb/include/lldb/Core/Module.h
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/include/lldb/Target/Statistics.h
  lldb/source/Breakpoint/Breakpoint.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
  lldb/source/Target/Statistics.cpp

Index: lldb/source/Target/Statistics.cpp
===
--- lldb/source/Target/Statistics.cpp
+++ lldb/source/Target/Statistics.cpp
@@ -34,7 +34,8 @@
 }
 
 static double elapsed(const StatsTimepoint &start, const StatsTimepoint &end) {
-  StatsDuration elapsed = end.time_since_epoch() - start.time_since_epoch();
+  StatsDuration::Duration elapsed =
+  end.time_since_epoch() - start.time_since_epoch();
   return elapsed.count();
 }
 
@@ -86,7 +87,8 @@
 elapsed(*m_launch_or_attach_time, *m_first_public_stop_time);
 target_metrics_json.try_emplace("firstStopTime", elapsed_time);
   }
-  target_metrics_json.try_emplace("targetCreateTime", m_create_time.count());
+  target_metrics_json.try_emplace("targetCreateTime",
+  m_create_time.get().count());
 
   json::Array breakpoints_array;
   double totalBreakpointResolveTime = 0.0;
@@ -177,8 +179,8 @@
 }
 module_stat.uuid = module->GetUUID().GetAsString();
 module_stat.triple = module->GetArchitecture().GetTriple().str();
-module_stat.symtab_parse_time = module->GetSymtabParseTime().count();
-module_stat.symtab_index_time = module->GetSymtabIndexTime().count();
+module_stat.symtab_parse_time = module->GetSymtabParseTime().get().count();
+module_stat.symtab_index_time = module->GetSymtabIndexTime().get().count();
 Symtab *symtab = module->GetSymtab();
 if (symtab) {
   module_stat.symtab_loaded_from_cache = symtab->GetWasLoadedFromCache();
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
@@ -143,8 +143,8 @@
   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
 
   uint64_t GetDebugInfoSize() override;
-  lldb_private::StatsDuration GetDebugInfoParseTime() override;
-  lldb_private::StatsDuration GetDebugInfoIndexTime() override;
+  lldb_private::StatsDuration::Duration GetDebugInfoParseTime() override;
+  lldb_private::StatsDuration::Duration GetDebugInfoIndexTime() override;
 
 protected:
   enum { kHaveInitializedOSOs = (1 << 0), kNumFlags };
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -1447,8 +1447,8 @@
   return debug_info_size;
 }
 
-StatsDuration SymbolFileDWARFDebugMap::GetDebugInfoParseTime() {
-  StatsDuration elapsed(0.0);
+StatsDuration::Duration SymbolFileDWARFDebugMap::GetDebugInfoParseTime() {
+  StatsDuration::Duration elapsed(0.0);
   ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
 ObjectFile *oso_objfile = oso_dwarf->GetObjectFile();
 if (oso_objfile) {
@@ -1464,8 +1464,8 @@
   return elapsed;
 }
 
-StatsDuration SymbolFileDWARFDebugMap::GetDebugInfoIndexTime() {
-  StatsDuration elapsed(0.0);
+StatsDuration::Duration SymbolFileDWARFDebugMap::GetDebugInfoIndexTime() {
+  StatsDuration::Duration elapsed(0.0);
   ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
 ObjectFile *oso_objfile = oso_dwarf->GetObjectFile();
 if (oso_objfile) {
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -319,10 +319,10 @@
   /// Same as GetLanguage() but reports all C++ versions as C++ (no version).
   static lldb::LanguageType GetLanguageFamily(DWARFUnit &unit);
 
-  lldb_private::StatsDuration GetDebugInfoParseTime() override {
+  lldb_private::StatsDuration::Duration GetDebugInfoParseTime() override {
 return m_parse_time;
   }
-  lldb_private::StatsDuration GetDebugInfoIndexTime() override;
+  lldb_private::StatsDuration::Duration GetDebugInfoIndexTime() override;
 
   lldb_priv

[Lldb-commits] [PATCH] D117564: [lldb] Remove the requirement for windows clients to specify -DIMPORT_LIBLLDB

2022-01-19 Thread Nico Weber via Phabricator via lldb-commits
thakis added a comment.

> So what happens now if you define LLDB_IN_LIBLLDB? Does dllexport explode if 
> used in a static library?

Do you mean define it for all targets, instead of for just liblldb?

If just for liblldb, then the link fails because (e.g.) driver tries to 
dllimport the symbols in liblldb then.

If you mean "define for everything", I haven't checked (since it's inconvenient 
to do).

To be clear, this isn't a huge problem for me, I'll just switch to a dll on 
Windows. The old system just seemed more flexible than the new setup, without 
being more complicated. (Maybe you're planning to do some followup that 
requires this change.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117564

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


[Lldb-commits] [PATCH] D117637: Fix build break on CentOS due to gcc 7.3.1

2022-01-19 Thread M. Zeeshan Siddiqui via Phabricator via lldb-commits
codemzs added a comment.

In D117637#3254195 , @labath wrote:

> I needed to dust off my old-deps build for another patch, so I also fixed 
> this in the process.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117637

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


[Lldb-commits] [PATCH] D117637: Fix build break on CentOS due to gcc 7.3.1

2022-01-19 Thread M. Zeeshan Siddiqui via Phabricator via lldb-commits
codemzs added a comment.

In D117637#3254195 , @labath wrote:

> I needed to dust off my old-deps build for another patch, so I also fixed 
> this in the process.

@labath Have you already committed your change? I need this for our builds that 
are broken.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117637

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


[Lldb-commits] [PATCH] D117564: [lldb] Remove the requirement for windows clients to specify -DIMPORT_LIBLLDB

2022-01-19 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

In D117564#3254798 , @thakis wrote:

>> So what happens now if you define LLDB_IN_LIBLLDB? Does dllexport explode if 
>> used in a static library?
>
> Do you mean define it for all targets, instead of for just liblldb?
>
> If just for liblldb, then the link fails because (e.g.) driver tries to 
> dllimport the symbols in liblldb then.
>
> If you mean "define for everything", I haven't checked (since it's 
> inconvenient to do).

I see. Thanks for explaining.

> To be clear, this isn't a huge problem for me, I'll just switch to a dll on 
> Windows. The old system just seemed more flexible than the new setup, without 
> being more complicated. (Maybe you're planning to do some followup that 
> requires this change.)

The background here is that I found this patch in one of my old WIP branches. 
The next patch in the series was going to define LLDB_API to 
`__attribute__((visibility("default")))` on the non-windows path (and make 
everything else hidden), but I have no idea why I wanted to do that. I mean, it 
does not sounds like an *un*reasonable thing to do, but am not going to do 
unless I find some benefit to it (maybe it saves size?)

This patch, otoh, seemed useful (and it still does) on its own as it removes 
the need for windows users to define some extra macros (for the supported 
configuration, anyway).

Anyway, what would you say if we wrapped this entire LLDB_API-setting block in 
an `#ifndef LLDB_API`? That way, things would still work out-of-the-box in the 
default (supported) configuration, but users who know what they're doing can 
define it to visibility(default), nothing, or whatever else, and that would 
take precedence.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117564

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


[Lldb-commits] [PATCH] D117637: Fix build break on CentOS due to gcc 7.3.1

2022-01-19 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

It's in as 8bfa7a6dcc274bf46ce1587cf51996a3389ceb63 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117637

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


[Lldb-commits] [PATCH] D117564: [lldb] Remove the requirement for windows clients to specify -DIMPORT_LIBLLDB

2022-01-19 Thread Nico Weber via Phabricator via lldb-commits
thakis added a comment.

> The background here is that I found this patch in one of my old WIP branches. 
> The next patch in the series was going to define LLDB_API to 
> `__attribute__((visibility("default")))` on the non-windows path (and make 
> everything else hidden), but I have no idea why I wanted to do that. I mean, 
> it does not sounds like an *un*reasonable thing to do, but am not going to do 
> unless I find some benefit to it (maybe it saves size?)

It'd allow getting rid of the .exports files, which would be nice I suppose.

> Anyway, what would you say if we wrapped this entire LLDB_API-setting block 
> in an `#ifndef LLDB_API`? That way, things would still work out-of-the-box in 
> the default (supported) configuration, but users who know what they're doing 
> can define it to visibility(default), nothing, or whatever else, and that 
> would take precedence.

That sounds like a good idea to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117564

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


[Lldb-commits] [PATCH] D117601: [lldb] Make Python initialization atomic

2022-01-19 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 401267.
JDevlieghere edited the summary of this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

Do private initialization exactly once in ScriptInterpreterPython::Initialize


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

https://reviews.llvm.org/D117601

Files:
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h

Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
@@ -341,7 +341,7 @@
   static bool WatchpointCallbackFunction(void *baton,
  StoppointCallbackContext *context,
  lldb::user_id_t watch_id);
-  static void InitializePrivate();
+  static void Initialize();
 
   class SynchronicityHandler {
   private:
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -85,8 +85,6 @@
   return static_cast(script_interpreter);
 }
 
-static bool g_initialized = false;
-
 namespace {
 
 // Initializing Python is not a straightforward process.  We cannot control
@@ -219,6 +217,28 @@
   PyGILState_STATE m_gil_state = PyGILState_UNLOCKED;
   bool m_was_already_initialized = false;
 };
+
+#if LLDB_USE_PYTHON_SET_INTERRUPT
+/// Saves the current signal handler for the specified signal and restores
+/// it at the end of the current scope.
+struct RestoreSignalHandlerScope {
+  /// The signal handler.
+  struct sigaction m_prev_handler;
+  int m_signal_code;
+  RestoreSignalHandlerScope(int signal_code) : m_signal_code(signal_code) {
+// Initialize sigaction to their default state.
+std::memset(&m_prev_handler, 0, sizeof(m_prev_handler));
+// Don't install a new handler, just read back the old one.
+struct sigaction *new_handler = nullptr;
+int signal_err = ::sigaction(m_signal_code, new_handler, &m_prev_handler);
+lldbassert(signal_err == 0 && "sigaction failed to read handler");
+  }
+  ~RestoreSignalHandlerScope() {
+int signal_err = ::sigaction(m_signal_code, &m_prev_handler, nullptr);
+lldbassert(signal_err == 0 && "sigaction failed to restore old handler");
+  }
+};
+#endif
 } // namespace
 
 void ScriptInterpreterPython::ComputePythonDirForApple(
@@ -333,12 +353,12 @@
 
 void ScriptInterpreterPython::Initialize() {
   static llvm::once_flag g_once_flag;
-
   llvm::call_once(g_once_flag, []() {
 PluginManager::RegisterPlugin(GetPluginNameStatic(),
   GetPluginDescriptionStatic(),
   lldb::eScriptLanguagePython,
   ScriptInterpreterPythonImpl::CreateInstance);
+ScriptInterpreterPythonImpl::Initialize();
   });
 }
 
@@ -415,8 +435,6 @@
   m_active_io_handler(eIOHandlerNone), m_session_is_active(false),
   m_pty_secondary_is_open(false), m_valid_session(true), m_lock_count(0),
   m_command_thread_state(nullptr) {
-  InitializePrivate();
-
   m_scripted_process_interface_up =
   std::make_unique(*this);
 
@@ -3151,36 +3169,7 @@
   return py_lock;
 }
 
-#if LLDB_USE_PYTHON_SET_INTERRUPT
-namespace {
-/// Saves the current signal handler for the specified signal and restores
-/// it at the end of the current scope.
-struct RestoreSignalHandlerScope {
-  /// The signal handler.
-  struct sigaction m_prev_handler;
-  int m_signal_code;
-  RestoreSignalHandlerScope(int signal_code) : m_signal_code(signal_code) {
-// Initialize sigaction to their default state.
-std::memset(&m_prev_handler, 0, sizeof(m_prev_handler));
-// Don't install a new handler, just read back the old one.
-struct sigaction *new_handler = nullptr;
-int signal_err = ::sigaction(m_signal_code, new_handler, &m_prev_handler);
-lldbassert(signal_err == 0 && "sigaction failed to read handler");
-  }
-  ~RestoreSignalHandlerScope() {
-int signal_err = ::sigaction(m_signal_code, &m_prev_handler, nullptr);
-lldbassert(signal_err == 0 && "sigaction failed to restore old handler");
-  }
-};
-} // namespace
-#endif
-
-void ScriptInterpreterPythonImpl::InitializePrivate() {
-  if (g_initialized)
-return;
-
-  g_initialized = true;
-
+void ScriptInterpreterPythonImpl::Initialize() {
   LLDB_SCOPED_TIMER();
 
   // RAII-based initialization which correctly handles multiple-initialization,
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.ll

[Lldb-commits] [PATCH] D117601: [lldb] Make Python initialization atomic

2022-01-19 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp:3154-3176
-#if LLDB_USE_PYTHON_SET_INTERRUPT
-namespace {
-/// Saves the current signal handler for the specified signal and restores
-/// it at the end of the current scope.
-struct RestoreSignalHandlerScope {
-  /// The signal handler.
-  struct sigaction m_prev_handler;

I just moved this into the existing anonymous namespace above.


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

https://reviews.llvm.org/D117601

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


[Lldb-commits] [PATCH] D117632: Instrument SBAPI with scoped timers

2022-01-19 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

Do you actually care about the timers or is this really about getting these 
methods instrumented with signposts on our platform? If it's the latter, I 
think it would make more sense to put that call in the `LLDB_RECORD_*` macros 
(which I'm planning to rename imminently). If this is about instrumenting the 
API, we can use the old reproducer logic to differentiate between calls made 
across the API boundary. Maybe it would make sense to only instrument external 
calls.

If it's just the signposts I'm not worried about performance, there's no way 
that's slower than the old reproducer instrumentation :-)


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

https://reviews.llvm.org/D117632

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


[Lldb-commits] [PATCH] D117601: [lldb] Make Python initialization atomic

2022-01-19 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added a comment.

LG, thanks


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

https://reviews.llvm.org/D117601

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


[Lldb-commits] [lldb] eb5c0ea - [lldb] Initialize Python exactly once

2022-01-19 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-01-19T09:56:55-08:00
New Revision: eb5c0ea681803361a1944c966f4becaa9e22dc1a

URL: 
https://github.com/llvm/llvm-project/commit/eb5c0ea681803361a1944c966f4becaa9e22dc1a
DIFF: 
https://github.com/llvm/llvm-project/commit/eb5c0ea681803361a1944c966f4becaa9e22dc1a.diff

LOG: [lldb] Initialize Python exactly once

We got a few crash reports that showed LLDB initializing Python on two
separate threads. Make sure Python is initialized exactly once.

rdar://87287005

Differential revision: https://reviews.llvm.org/D117601

Added: 


Modified: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 0e01dc52b2513..80e986f18c618 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -85,8 +85,6 @@ static ScriptInterpreterPythonImpl 
*GetPythonInterpreter(Debugger &debugger) {
   return static_cast(script_interpreter);
 }
 
-static bool g_initialized = false;
-
 namespace {
 
 // Initializing Python is not a straightforward process.  We cannot control
@@ -219,6 +217,28 @@ struct InitializePythonRAII {
   PyGILState_STATE m_gil_state = PyGILState_UNLOCKED;
   bool m_was_already_initialized = false;
 };
+
+#if LLDB_USE_PYTHON_SET_INTERRUPT
+/// Saves the current signal handler for the specified signal and restores
+/// it at the end of the current scope.
+struct RestoreSignalHandlerScope {
+  /// The signal handler.
+  struct sigaction m_prev_handler;
+  int m_signal_code;
+  RestoreSignalHandlerScope(int signal_code) : m_signal_code(signal_code) {
+// Initialize sigaction to their default state.
+std::memset(&m_prev_handler, 0, sizeof(m_prev_handler));
+// Don't install a new handler, just read back the old one.
+struct sigaction *new_handler = nullptr;
+int signal_err = ::sigaction(m_signal_code, new_handler, &m_prev_handler);
+lldbassert(signal_err == 0 && "sigaction failed to read handler");
+  }
+  ~RestoreSignalHandlerScope() {
+int signal_err = ::sigaction(m_signal_code, &m_prev_handler, nullptr);
+lldbassert(signal_err == 0 && "sigaction failed to restore old handler");
+  }
+};
+#endif
 } // namespace
 
 void ScriptInterpreterPython::ComputePythonDirForApple(
@@ -333,12 +353,12 @@ llvm::StringRef 
ScriptInterpreterPython::GetPluginDescriptionStatic() {
 
 void ScriptInterpreterPython::Initialize() {
   static llvm::once_flag g_once_flag;
-
   llvm::call_once(g_once_flag, []() {
 PluginManager::RegisterPlugin(GetPluginNameStatic(),
   GetPluginDescriptionStatic(),
   lldb::eScriptLanguagePython,
   ScriptInterpreterPythonImpl::CreateInstance);
+ScriptInterpreterPythonImpl::Initialize();
   });
 }
 
@@ -415,8 +435,6 @@ 
ScriptInterpreterPythonImpl::ScriptInterpreterPythonImpl(Debugger &debugger)
   m_active_io_handler(eIOHandlerNone), m_session_is_active(false),
   m_pty_secondary_is_open(false), m_valid_session(true), m_lock_count(0),
   m_command_thread_state(nullptr) {
-  InitializePrivate();
-
   m_scripted_process_interface_up =
   std::make_unique(*this);
 
@@ -3151,36 +3169,7 @@ ScriptInterpreterPythonImpl::AcquireInterpreterLock() {
   return py_lock;
 }
 
-#if LLDB_USE_PYTHON_SET_INTERRUPT
-namespace {
-/// Saves the current signal handler for the specified signal and restores
-/// it at the end of the current scope.
-struct RestoreSignalHandlerScope {
-  /// The signal handler.
-  struct sigaction m_prev_handler;
-  int m_signal_code;
-  RestoreSignalHandlerScope(int signal_code) : m_signal_code(signal_code) {
-// Initialize sigaction to their default state.
-std::memset(&m_prev_handler, 0, sizeof(m_prev_handler));
-// Don't install a new handler, just read back the old one.
-struct sigaction *new_handler = nullptr;
-int signal_err = ::sigaction(m_signal_code, new_handler, &m_prev_handler);
-lldbassert(signal_err == 0 && "sigaction failed to read handler");
-  }
-  ~RestoreSignalHandlerScope() {
-int signal_err = ::sigaction(m_signal_code, &m_prev_handler, nullptr);
-lldbassert(signal_err == 0 && "sigaction failed to restore old handler");
-  }
-};
-} // namespace
-#endif
-
-void ScriptInterpreterPythonImpl::InitializePrivate() {
-  if (g_initialized)
-return;
-
-  g_initialized = true;
-
+void ScriptInterpreterPythonImpl::Initialize() {
   LLDB_SCOPED_TIMER();
 
   // RAII-based initialization which correctly handles multiple-initialization,

[Lldb-commits] [PATCH] D117601: [lldb] Make Python initialization atomic

2022-01-19 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeb5c0ea68180: [lldb] Initialize Python exactly once 
(authored by JDevlieghere).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D117601?vs=401267&id=401300#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117601

Files:
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
  lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

Index: lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
===
--- lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
+++ lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
@@ -22,7 +22,6 @@
 class TestScriptInterpreterPython : public ScriptInterpreterPythonImpl {
 public:
   using ScriptInterpreterPythonImpl::Initialize;
-  using ScriptInterpreterPythonImpl::InitializePrivate;
 };
 
 void PythonTestSuite::SetUp() {
@@ -31,7 +30,6 @@
   // ScriptInterpreterPython::Initialize() depends on HostInfo being
   // initializedso it can compute the python directory etc.
   TestScriptInterpreterPython::Initialize();
-  TestScriptInterpreterPython::InitializePrivate();
 
   // Although we don't care about concurrency for the purposes of running
   // this test suite, Python requires the GIL to be locked even for
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
@@ -341,7 +341,7 @@
   static bool WatchpointCallbackFunction(void *baton,
  StoppointCallbackContext *context,
  lldb::user_id_t watch_id);
-  static void InitializePrivate();
+  static void Initialize();
 
   class SynchronicityHandler {
   private:
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -85,8 +85,6 @@
   return static_cast(script_interpreter);
 }
 
-static bool g_initialized = false;
-
 namespace {
 
 // Initializing Python is not a straightforward process.  We cannot control
@@ -219,6 +217,28 @@
   PyGILState_STATE m_gil_state = PyGILState_UNLOCKED;
   bool m_was_already_initialized = false;
 };
+
+#if LLDB_USE_PYTHON_SET_INTERRUPT
+/// Saves the current signal handler for the specified signal and restores
+/// it at the end of the current scope.
+struct RestoreSignalHandlerScope {
+  /// The signal handler.
+  struct sigaction m_prev_handler;
+  int m_signal_code;
+  RestoreSignalHandlerScope(int signal_code) : m_signal_code(signal_code) {
+// Initialize sigaction to their default state.
+std::memset(&m_prev_handler, 0, sizeof(m_prev_handler));
+// Don't install a new handler, just read back the old one.
+struct sigaction *new_handler = nullptr;
+int signal_err = ::sigaction(m_signal_code, new_handler, &m_prev_handler);
+lldbassert(signal_err == 0 && "sigaction failed to read handler");
+  }
+  ~RestoreSignalHandlerScope() {
+int signal_err = ::sigaction(m_signal_code, &m_prev_handler, nullptr);
+lldbassert(signal_err == 0 && "sigaction failed to restore old handler");
+  }
+};
+#endif
 } // namespace
 
 void ScriptInterpreterPython::ComputePythonDirForApple(
@@ -333,12 +353,12 @@
 
 void ScriptInterpreterPython::Initialize() {
   static llvm::once_flag g_once_flag;
-
   llvm::call_once(g_once_flag, []() {
 PluginManager::RegisterPlugin(GetPluginNameStatic(),
   GetPluginDescriptionStatic(),
   lldb::eScriptLanguagePython,
   ScriptInterpreterPythonImpl::CreateInstance);
+ScriptInterpreterPythonImpl::Initialize();
   });
 }
 
@@ -415,8 +435,6 @@
   m_active_io_handler(eIOHandlerNone), m_session_is_active(false),
   m_pty_secondary_is_open(false), m_valid_session(true), m_lock_count(0),
   m_command_thread_state(nullptr) {
-  InitializePrivate();
-
   m_scripted_process_interface_up =
   std::make_unique(*this);
 
@@ -3151,36 +3169,7 @@
   return py_lock;
 }
 
-#if LLDB_USE_PYTHON_SET_INTERRUPT
-namespace {
-/// Saves the current signal handler for the specified signal and restores
-/// it at the end of the current scope.
-struct RestoreSignalHandlerScope {
-  /// The signal handler.
-  struct sigaction m_prev_handler;
-  int m_signal_code;
-  RestoreSignalHandlerScope(int signal_code) 

[Lldb-commits] [PATCH] D117632: Instrument SBAPI with scoped timers

2022-01-19 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl abandoned this revision.
aprantl added a comment.

In D117632#3255158 , @JDevlieghere 
wrote:

> Do you actually care about the timers or is this really about getting these 
> methods instrumented with signposts on our platform? If it's the latter, I 
> think it would make more sense to put that call in the `LLDB_RECORD_*` macros 
> (which I'm planning to rename imminently). If this is about instrumenting the 
> API, we can use the old reproducer logic to differentiate between calls made 
> across the API boundary. Maybe it would make sense to only instrument 
> external calls.
>
> If it's just the signposts I'm not worried about performance, there's no way 
> that's slower than the old reproducer instrumentation :-)

That's right, I'm only interested in signposts. I'll put this patch aside for 
now, it would make sense to integrate this functionality into the properly 
renamed macros!


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

https://reviews.llvm.org/D117632

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


[Lldb-commits] [PATCH] D117632: Instrument SBAPI with scoped timers

2022-01-19 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added a comment.

> I'm a little confused about what you want to achieve as well.

With signposts you get a flamegraph of all nested signposted functions, which 
is really intuitive to look at.


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

https://reviews.llvm.org/D117632

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


[Lldb-commits] [PATCH] D117632: Instrument SBAPI with scoped timers

2022-01-19 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere commandeered this revision.
JDevlieghere edited reviewers, added: aprantl; removed: JDevlieghere.
JDevlieghere added a comment.

I can do this after the rename.


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

https://reviews.llvm.org/D117632

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


[Lldb-commits] [PATCH] D117707: siginfo_t synthesis WIP

2022-01-19 Thread Michał Górny via Phabricator via lldb-commits
mgorny created this revision.
mgorny added reviewers: labath, emaste, krytarowski.
mgorny requested review of this revision.

To get some early feedback.


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/Linux/PlatformLinux.cpp
  lldb/source/Plugins/Platform/Linux/PlatformLinux.h
  lldb/source/Target/Platform.cpp

Index: lldb/source/Target/Platform.cpp
===
--- lldb/source/Target/Platform.cpp
+++ lldb/source/Target/Platform.cpp
@@ -2003,3 +2003,7 @@
 
   return 0;
 }
+
+CompilerType Platform::GetSiginfoType(lldb_private::Target &target) {
+  return CompilerType();
+}
Index: lldb/source/Plugins/Platform/Linux/PlatformLinux.h
===
--- lldb/source/Plugins/Platform/Linux/PlatformLinux.h
+++ lldb/source/Plugins/Platform/Linux/PlatformLinux.h
@@ -58,6 +58,8 @@
   unsigned flags, lldb::addr_t fd,
   lldb::addr_t offset) override;
 
+  CompilerType GetSiginfoType(lldb_private::Target &target) override;
+
   std::vector m_supported_architectures;
 };
 
Index: lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
===
--- lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
+++ lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
@@ -14,6 +14,7 @@
 #include 
 #endif
 
+#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "Utility/ARM64_DWARF_Registers.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/PluginManager.h"
@@ -309,3 +310,68 @@
   return args;
 }
 
+CompilerType PlatformLinux::GetSiginfoType(lldb_private::Target &target) {
+  CompilerType type;
+  TypeSystemClang *ast = ScratchTypeSystemClang::GetForTarget(target);
+  if (!ast)
+return type;
+  const ArchSpec &arch = target.GetArchitecture();
+
+  CompilerType int_type = ast->GetBasicType(eBasicTypeInt);
+  CompilerType uint_type = ast->GetBasicType(eBasicTypeUnsignedInt);
+
+  CompilerType &pid_type = int_type;
+  CompilerType &uid_type = uint_type;
+
+  CompilerType siginfo_type = ast->CreateRecordType(
+  nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "__lldb_siginfo_t",
+  clang::TTK_Struct, lldb::eLanguageTypeC);
+  ast->StartTagDeclarationDefinition(siginfo_type);
+  ast->AddFieldToRecordType(siginfo_type, "si_signo", int_type,
+lldb::eAccessPublic, 0);
+
+  // mips has si_code and si_errno swapped
+  switch (arch.GetMachine()) {
+  case llvm::Triple::mips:
+ast->AddFieldToRecordType(siginfo_type, "si_code", int_type,
+  lldb::eAccessPublic, 0);
+ast->AddFieldToRecordType(siginfo_type, "si_errno", int_type,
+  lldb::eAccessPublic, 0);
+break;
+  default:
+ast->AddFieldToRecordType(siginfo_type, "si_errno", int_type,
+  lldb::eAccessPublic, 0);
+ast->AddFieldToRecordType(siginfo_type, "si_code", int_type,
+  lldb::eAccessPublic, 0);
+  }
+
+  // the structure is padded on 64-bit arches to fix alignment
+  if (arch.GetAddressByteSize() == 8)
+ast->AddFieldToRecordType(siginfo_type, "__pad0", int_type,
+  lldb::eAccessPublic, 0);
+
+  CompilerType union_type = ast->CreateRecordType(
+  nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "",
+  clang::TTK_Union, lldb::eLanguageTypeC);
+  ast->StartTagDeclarationDefinition(union_type);
+
+  CompilerType kill_type = ast->CreateRecordType(
+  nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "",
+  clang::TTK_Struct, lldb::eLanguageTypeC);
+  ast->StartTagDeclarationDefinition(kill_type);
+  // TODO: types
+  ast->AddFieldToRecordType(kill_type, "si_pid", pid_type,
+lldb::eAccessPublic, 0);
+  ast->AddFieldToRecordType(kill_type, "si_uid", uid_type,
+lldb::eAccessPublic, 0);
+  ast->CompleteTagDeclarationDefinition(kill_type);
+  ast->AddFieldToRecordType(union_type, "_kill", kill_type,
+lldb::eAccessPublic, 0);
+
+  ast->CompleteTagDeclarationDefinition(union_type);
+  ast->AddFieldToRecordType(siginfo_type, "_sifields", union_type,
+lldb::eAccessPublic, 0);
+
+  ast->CompleteTagDeclarationDefinition(siginfo_type);
+  return siginfo_type;
+}
Index: lldb/source/API/SBPlatform.cpp
===
--- lldb/source/API/SBPlatform.cpp
+++ lldb/source/API/SBPlatform.cpp
@@ -13,6 +13,8 @@
 #include "lldb/API/SBFileSpec.h"
 #include "lldb/API/SBLaunchInfo.h"
 #include "lldb/API/SBPlatform.h"
+#include "lldb/API/SBTarget.h"
+#include "lldb/API/SBType.h"
 #inc

[Lldb-commits] [PATCH] D117707: siginfo_t synthesis WIP

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

My current test program is:

  #!/usr/bin/env python
  
  import lldb
  
  raw_data = 
b'\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00up\n\x00\xe8\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  
  lldb.SBDebugger.Initialize()
  try:
  dbg = lldb.SBDebugger.Create()
  try:
  t = dbg.CreateTarget("/home/mgorny/git/llvm-project/build/a.out")
  assert t
  typ = list(t.FindTypes("siginfo_t"))[0]
  assert typ
  typ2 = t.GetPlatform().GetSiginfoType(t)
  assert typ2
  data = lldb.SBData()
  data2 = lldb.SBData()
  error = lldb.SBError()
  data.SetData(error, raw_data, lldb.eByteOrderLittle, 8)
  print(t.CreateValueFromData("siginfo", data, typ))
  print(t.CreateValueFromData("siginfo2", data, typ2))
  finally:
  lldb.SBDebugger.Destroy(dbg)
  finally:
  lldb.SBDebugger.Terminate()


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

https://reviews.llvm.org/D117707

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


[Lldb-commits] [PATCH] D117707: siginfo_t synthesis WIP

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

Cover more union members.


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/Linux/PlatformLinux.cpp
  lldb/source/Plugins/Platform/Linux/PlatformLinux.h
  lldb/source/Target/Platform.cpp

Index: lldb/source/Target/Platform.cpp
===
--- lldb/source/Target/Platform.cpp
+++ lldb/source/Target/Platform.cpp
@@ -2003,3 +2003,7 @@
 
   return 0;
 }
+
+CompilerType Platform::GetSiginfoType(lldb_private::Target &target) {
+  return CompilerType();
+}
Index: lldb/source/Plugins/Platform/Linux/PlatformLinux.h
===
--- lldb/source/Plugins/Platform/Linux/PlatformLinux.h
+++ lldb/source/Plugins/Platform/Linux/PlatformLinux.h
@@ -58,6 +58,8 @@
   unsigned flags, lldb::addr_t fd,
   lldb::addr_t offset) override;
 
+  CompilerType GetSiginfoType(lldb_private::Target &target) override;
+
   std::vector m_supported_architectures;
 };
 
Index: lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
===
--- lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
+++ lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
@@ -14,6 +14,7 @@
 #include 
 #endif
 
+#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "Utility/ARM64_DWARF_Registers.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/PluginManager.h"
@@ -309,3 +310,126 @@
   return args;
 }
 
+CompilerType PlatformLinux::GetSiginfoType(lldb_private::Target &target) {
+  CompilerType type;
+  TypeSystemClang *ast = ScratchTypeSystemClang::GetForTarget(target);
+  if (!ast)
+return type;
+  const ArchSpec &arch = target.GetArchitecture();
+
+  CompilerType int_type = ast->GetBasicType(eBasicTypeInt);
+  CompilerType uint_type = ast->GetBasicType(eBasicTypeUnsignedInt);
+  CompilerType long_type = ast->GetBasicType(eBasicTypeLong);
+  CompilerType voidp_type = ast->GetBasicType(eBasicTypeVoid).GetPointerType();
+
+  CompilerType &pid_type = int_type;
+  CompilerType &uid_type = uint_type;
+  CompilerType &clock_type = long_type;
+
+  CompilerType sigval_type = ast->CreateRecordType(
+  nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "__lldb_sigval_t",
+  clang::TTK_Union, lldb::eLanguageTypeC);
+  ast->StartTagDeclarationDefinition(sigval_type);
+  ast->AddFieldToRecordType(sigval_type, "sival_int", int_type,
+lldb::eAccessPublic, 0);
+  ast->AddFieldToRecordType(sigval_type, "sival_ptr", voidp_type,
+lldb::eAccessPublic, 0);
+  ast->CompleteTagDeclarationDefinition(sigval_type);
+
+  CompilerType siginfo_type = ast->CreateRecordType(
+  nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "__lldb_siginfo_t",
+  clang::TTK_Struct, lldb::eLanguageTypeC);
+  ast->StartTagDeclarationDefinition(siginfo_type);
+  ast->AddFieldToRecordType(siginfo_type, "si_signo", int_type,
+lldb::eAccessPublic, 0);
+
+  // mips has si_code and si_errno swapped
+  switch (arch.GetMachine()) {
+  case llvm::Triple::mips:
+ast->AddFieldToRecordType(siginfo_type, "si_code", int_type,
+  lldb::eAccessPublic, 0);
+ast->AddFieldToRecordType(siginfo_type, "si_errno", int_type,
+  lldb::eAccessPublic, 0);
+break;
+  default:
+ast->AddFieldToRecordType(siginfo_type, "si_errno", int_type,
+  lldb::eAccessPublic, 0);
+ast->AddFieldToRecordType(siginfo_type, "si_code", int_type,
+  lldb::eAccessPublic, 0);
+  }
+
+  // the structure is padded on 64-bit arches to fix alignment
+  if (arch.GetAddressByteSize() == 8)
+ast->AddFieldToRecordType(siginfo_type, "__pad0", int_type,
+  lldb::eAccessPublic, 0);
+
+  CompilerType union_type = ast->CreateRecordType(
+  nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "",
+  clang::TTK_Union, lldb::eLanguageTypeC);
+  ast->StartTagDeclarationDefinition(union_type);
+
+  CompilerType sub_type = ast->CreateRecordType(
+  nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "",
+  clang::TTK_Struct, lldb::eLanguageTypeC);
+  ast->StartTagDeclarationDefinition(sub_type);
+  ast->AddFieldToRecordType(sub_type, "si_pid", pid_type,
+lldb::eAccessPublic, 0);
+  ast->AddFieldToRecordType(sub_type, "si_uid", uid_type,
+lldb::eAccessPublic, 0);
+  ast->CompleteTagDeclarationDefinition(sub_type);
+  ast->AddFieldToRecordType(union_type,

[Lldb-commits] [PATCH] D117707: siginfo_t synthesis WIP

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

Hmm, maybe for the sub-structs, it'd be better to use 
`TypeSystemClang::CreateStructForIdentifier()`.


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

https://reviews.llvm.org/D117707

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


[Lldb-commits] [PATCH] D117712: [lldb] Disconnect instrumentation from the reproducers

2022-01-19 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: aprantl, labath.
Herald added a subscriber: mgorny.
JDevlieghere requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

Remove the last remaining references to the reproducers from the 
instrumentation.

- ReproducerInstrumentation.cpp -> Instrumentation.cpp
- `LLDB_RECORD_` -> `LLDB_INSTRUMENT`

I was going to with a more SBAPI/LLDB API focussed naming scheme, but D117632 
 made me decide to keep things more generic.


https://reviews.llvm.org/D117712

Files:
  lldb/include/lldb/Utility/Instrumentation.h
  lldb/include/lldb/Utility/ReproducerInstrumentation.h
  lldb/source/API/SBAddress.cpp
  lldb/source/API/SBAttachInfo.cpp
  lldb/source/API/SBBlock.cpp
  lldb/source/API/SBBreakpoint.cpp
  lldb/source/API/SBBreakpointLocation.cpp
  lldb/source/API/SBBreakpointName.cpp
  lldb/source/API/SBBroadcaster.cpp
  lldb/source/API/SBCommandInterpreter.cpp
  lldb/source/API/SBCommandInterpreterRunOptions.cpp
  lldb/source/API/SBCommandReturnObject.cpp
  lldb/source/API/SBCommunication.cpp
  lldb/source/API/SBCompileUnit.cpp
  lldb/source/API/SBData.cpp
  lldb/source/API/SBDebugger.cpp
  lldb/source/API/SBDeclaration.cpp
  lldb/source/API/SBEnvironment.cpp
  lldb/source/API/SBError.cpp
  lldb/source/API/SBEvent.cpp
  lldb/source/API/SBExecutionContext.cpp
  lldb/source/API/SBExpressionOptions.cpp
  lldb/source/API/SBFile.cpp
  lldb/source/API/SBFileSpec.cpp
  lldb/source/API/SBFileSpecList.cpp
  lldb/source/API/SBFrame.cpp
  lldb/source/API/SBFunction.cpp
  lldb/source/API/SBHostOS.cpp
  lldb/source/API/SBInstruction.cpp
  lldb/source/API/SBInstructionList.cpp
  lldb/source/API/SBLanguageRuntime.cpp
  lldb/source/API/SBLaunchInfo.cpp
  lldb/source/API/SBLineEntry.cpp
  lldb/source/API/SBListener.cpp
  lldb/source/API/SBMemoryRegionInfo.cpp
  lldb/source/API/SBMemoryRegionInfoList.cpp
  lldb/source/API/SBModule.cpp
  lldb/source/API/SBModuleSpec.cpp
  lldb/source/API/SBPlatform.cpp
  lldb/source/API/SBProcess.cpp
  lldb/source/API/SBProcessInfo.cpp
  lldb/source/API/SBQueue.cpp
  lldb/source/API/SBQueueItem.cpp
  lldb/source/API/SBReproducer.cpp
  lldb/source/API/SBSection.cpp
  lldb/source/API/SBSourceManager.cpp
  lldb/source/API/SBStream.cpp
  lldb/source/API/SBStringList.cpp
  lldb/source/API/SBStructuredData.cpp
  lldb/source/API/SBSymbol.cpp
  lldb/source/API/SBSymbolContext.cpp
  lldb/source/API/SBSymbolContextList.cpp
  lldb/source/API/SBTarget.cpp
  lldb/source/API/SBThread.cpp
  lldb/source/API/SBThreadCollection.cpp
  lldb/source/API/SBThreadPlan.cpp
  lldb/source/API/SBTrace.cpp
  lldb/source/API/SBType.cpp
  lldb/source/API/SBTypeCategory.cpp
  lldb/source/API/SBTypeEnumMember.cpp
  lldb/source/API/SBTypeFilter.cpp
  lldb/source/API/SBTypeFormat.cpp
  lldb/source/API/SBTypeNameSpecifier.cpp
  lldb/source/API/SBTypeSummary.cpp
  lldb/source/API/SBTypeSynthetic.cpp
  lldb/source/API/SBUnixSignals.cpp
  lldb/source/API/SBValue.cpp
  lldb/source/API/SBValueList.cpp
  lldb/source/API/SBVariablesOptions.cpp
  lldb/source/API/SBWatchpoint.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/source/Utility/CMakeLists.txt
  lldb/source/Utility/Instrumentation.cpp
  lldb/source/Utility/ReproducerInstrumentation.cpp

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


[Lldb-commits] [PATCH] D117632: Instrument SB API with signposts

2022-01-19 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 401369.
JDevlieghere retitled this revision from "Instrument SBAPI with scoped timers" 
to "Instrument SB API with signposts".
JDevlieghere edited the summary of this revision.

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

https://reviews.llvm.org/D117632

Files:
  lldb/include/lldb/Utility/Instrumentation.h
  lldb/source/Utility/Instrumentation.cpp


Index: lldb/source/Utility/Instrumentation.cpp
===
--- lldb/source/Utility/Instrumentation.cpp
+++ lldb/source/Utility/Instrumentation.cpp
@@ -6,6 +6,8 @@
 
//===--===//
 
 #include "lldb/Utility/Instrumentation.h"
+#include "llvm/Support/Signposts.h"
+
 #include 
 #include 
 #include 
@@ -16,6 +18,9 @@
 // Whether we're currently across the API boundary.
 static thread_local bool g_global_boundary = false;
 
+// Instrument SB API calls with singposts when supported.
+static llvm::ManagedStatic g_api_signposts;
+
 Instrumenter::Instrumenter() {
   if (!g_global_boundary) {
 g_global_boundary = true;
@@ -25,19 +30,22 @@
 
 Instrumenter::Instrumenter(llvm::StringRef pretty_func,
std::string &&pretty_args)
-: m_local_boundary(false) {
+: m_pretty_func(pretty_func), m_local_boundary(false) {
   if (!g_global_boundary) {
 g_global_boundary = true;
 m_local_boundary = true;
+g_api_signposts->startInterval(this, m_pretty_func);
   }
   LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), "[{0}] {1} ({2})",
-   m_local_boundary ? "external" : "internal", pretty_func,
+   m_local_boundary ? "external" : "internal", m_pretty_func,
pretty_args);
 }
 
 Instrumenter::~Instrumenter() { UpdateBoundary(); }
 
 void Instrumenter::UpdateBoundary() {
-  if (m_local_boundary)
+  if (m_local_boundary) {
 g_global_boundary = false;
+g_api_signposts->endInterval(this, m_pretty_func);
+  }
 }
Index: lldb/include/lldb/Utility/Instrumentation.h
===
--- lldb/include/lldb/Utility/Instrumentation.h
+++ lldb/include/lldb/Utility/Instrumentation.h
@@ -87,6 +87,8 @@
 private:
   void UpdateBoundary();
 
+  llvm::StringRef m_pretty_func;
+
   /// Whether this function call was the one crossing the API boundary.
   bool m_local_boundary = false;
 };


Index: lldb/source/Utility/Instrumentation.cpp
===
--- lldb/source/Utility/Instrumentation.cpp
+++ lldb/source/Utility/Instrumentation.cpp
@@ -6,6 +6,8 @@
 //===--===//
 
 #include "lldb/Utility/Instrumentation.h"
+#include "llvm/Support/Signposts.h"
+
 #include 
 #include 
 #include 
@@ -16,6 +18,9 @@
 // Whether we're currently across the API boundary.
 static thread_local bool g_global_boundary = false;
 
+// Instrument SB API calls with singposts when supported.
+static llvm::ManagedStatic g_api_signposts;
+
 Instrumenter::Instrumenter() {
   if (!g_global_boundary) {
 g_global_boundary = true;
@@ -25,19 +30,22 @@
 
 Instrumenter::Instrumenter(llvm::StringRef pretty_func,
std::string &&pretty_args)
-: m_local_boundary(false) {
+: m_pretty_func(pretty_func), m_local_boundary(false) {
   if (!g_global_boundary) {
 g_global_boundary = true;
 m_local_boundary = true;
+g_api_signposts->startInterval(this, m_pretty_func);
   }
   LLDB_LOG(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API), "[{0}] {1} ({2})",
-   m_local_boundary ? "external" : "internal", pretty_func,
+   m_local_boundary ? "external" : "internal", m_pretty_func,
pretty_args);
 }
 
 Instrumenter::~Instrumenter() { UpdateBoundary(); }
 
 void Instrumenter::UpdateBoundary() {
-  if (m_local_boundary)
+  if (m_local_boundary) {
 g_global_boundary = false;
+g_api_signposts->endInterval(this, m_pretty_func);
+  }
 }
Index: lldb/include/lldb/Utility/Instrumentation.h
===
--- lldb/include/lldb/Utility/Instrumentation.h
+++ lldb/include/lldb/Utility/Instrumentation.h
@@ -87,6 +87,8 @@
 private:
   void UpdateBoundary();
 
+  llvm::StringRef m_pretty_func;
+
   /// Whether this function call was the one crossing the API boundary.
   bool m_local_boundary = false;
 };
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D117712: [lldb] Disconnect instrumentation from the reproducers

2022-01-19 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

It seems the set of macros could be reduced. If you don't need to generate 
"unique identifiers" for each method, then you can stop worrying about const 
methods, constructors, etc. I think this could boil down to one or two macros...


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

https://reviews.llvm.org/D117712

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


[Lldb-commits] [PATCH] D117632: [lldb] Instrument SB API with signposts

2022-01-19 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl accepted this revision.
aprantl added a comment.
This revision is now accepted and ready to land.

Assuming UpdateBoundary is only called in the destructor this looks nice!




Comment at: lldb/source/Utility/Instrumentation.cpp:21
 
+// Instrument SB API calls with singposts when supported.
+static llvm::ManagedStatic g_api_signposts;

///


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

https://reviews.llvm.org/D117632

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


[Lldb-commits] [PATCH] D117632: [lldb] Instrument SB API with signposts

2022-01-19 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

Yup, at this point I might as well inline it.


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

https://reviews.llvm.org/D117632

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


[Lldb-commits] [PATCH] D117712: [lldb] Disconnect instrumentation from the reproducers

2022-01-19 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

In D117712#3255978 , @labath wrote:

> It seems the set of macros could be reduced. If you don't need to generate 
> "unique identifiers" for each method, then you can stop worrying about const 
> methods, constructors, etc. I think this could boil down to one or two 
> macros...

Yeah, I think we can reduce everything to:

  #define LLDB_INSTRUMENT(...)  
 \
lldb_private::Instrumenter _instrumenter(LLVM_PRETTY_FUNCTION, __VA_ARGS__);

plus a variant that takes no args. The reason it's not part of this patch is 
because it means modifying every single line and I'm lazy^Z^Z^Z^Z not sure when 
I'll have the time for that. Maybe I'll just revive lldb-instr locally and have 
it generate the new macros for me.


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

https://reviews.llvm.org/D117712

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


[Lldb-commits] [PATCH] D117707: siginfo_t synthesis WIP

2022-01-19 Thread Michał Górny via Phabricator via lldb-commits
mgorny updated this revision to Diff 401378.
mgorny added a comment.
Herald added a subscriber: fedor.sergeev.

Use `CreateStructForIdentifier()` whenever possible. Describe the remaining 
union members.

Open question: do we care for 100% correct SPARC support? Given that it has 
different `_sigfault` layout, it adds some complexity while LLDB doesn't seem 
to support SPARC at all.


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/Linux/PlatformLinux.cpp
  lldb/source/Plugins/Platform/Linux/PlatformLinux.h
  lldb/source/Target/Platform.cpp

Index: lldb/source/Target/Platform.cpp
===
--- lldb/source/Target/Platform.cpp
+++ lldb/source/Target/Platform.cpp
@@ -2003,3 +2003,7 @@
 
   return 0;
 }
+
+CompilerType Platform::GetSiginfoType(lldb_private::Target &target) {
+  return CompilerType();
+}
Index: lldb/source/Plugins/Platform/Linux/PlatformLinux.h
===
--- lldb/source/Plugins/Platform/Linux/PlatformLinux.h
+++ lldb/source/Plugins/Platform/Linux/PlatformLinux.h
@@ -58,6 +58,8 @@
   unsigned flags, lldb::addr_t fd,
   lldb::addr_t offset) override;
 
+  CompilerType GetSiginfoType(lldb_private::Target &target) override;
+
   std::vector m_supported_architectures;
 };
 
Index: lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
===
--- lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
+++ lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
@@ -14,6 +14,7 @@
 #include 
 #endif
 
+#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "Utility/ARM64_DWARF_Registers.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/PluginManager.h"
@@ -309,3 +310,183 @@
   return args;
 }
 
+CompilerType PlatformLinux::GetSiginfoType(lldb_private::Target &target) {
+  CompilerType type;
+  TypeSystemClang *ast = ScratchTypeSystemClang::GetForTarget(target);
+  if (!ast)
+return type;
+
+  const ArchSpec &arch = target.GetArchitecture();
+  bool is_64bit = arch.GetAddressByteSize() == 8;
+  bool si_errno_then_code = true;
+  bool si_band_type_is_int = false;
+
+  // TODO: do we actually care about sparc here? lldb doesn't seem to have
+  // any sparc support
+  switch (arch.GetMachine()) {
+  case llvm::Triple::mips:
+  case llvm::Triple::mipsel:
+  case llvm::Triple::mips64:
+  case llvm::Triple::mips64el:
+// mips has si_code and si_errno swapped
+si_errno_then_code = false;
+break;
+  case llvm::Triple::sparc:
+  case llvm::Triple::sparcel:
+  case llvm::Triple::sparcv9:
+// sparc64 uses int for __SI_BAND_TYPE
+if (is_64bit)
+  si_band_type_is_int = true;
+break;
+  default:
+break;
+  }
+
+  // generic types
+  CompilerType int_type = ast->GetBasicType(eBasicTypeInt);
+  CompilerType uint_type = ast->GetBasicType(eBasicTypeUnsignedInt);
+  CompilerType short_type = ast->GetBasicType(eBasicTypeShort);
+  CompilerType long_type = ast->GetBasicType(eBasicTypeLong);
+  CompilerType voidp_type = ast->GetBasicType(eBasicTypeVoid).GetPointerType();
+
+  // platform-specific types
+  CompilerType &pid_type = int_type;
+  CompilerType &uid_type = uint_type;
+  CompilerType &clock_type = long_type;
+  CompilerType &band_type = si_band_type_is_int ? int_type : long_type;
+
+  CompilerType sigval_type = ast->CreateRecordType(
+  nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "__lldb_sigval_t",
+  clang::TTK_Union, lldb::eLanguageTypeC);
+  ast->StartTagDeclarationDefinition(sigval_type);
+  ast->AddFieldToRecordType(sigval_type, "sival_int", int_type,
+lldb::eAccessPublic, 0);
+  ast->AddFieldToRecordType(sigval_type, "sival_ptr", voidp_type,
+lldb::eAccessPublic, 0);
+  ast->CompleteTagDeclarationDefinition(sigval_type);
+
+  CompilerType sigfault_bounds_type = ast->CreateRecordType(
+  nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "",
+  clang::TTK_Union, lldb::eLanguageTypeC);
+  ast->StartTagDeclarationDefinition(sigfault_bounds_type);
+  ast->AddFieldToRecordType(sigfault_bounds_type, "_addr_bnd",
+  ast->CreateStructForIdentifier(ConstString(),
+ {
+ {"_lower", voidp_type},
+ {"_upper", voidp_type},
+ }),
+lldb::eAccessPublic, 0);
+  ast->AddFieldToRecordType(sigfault_bounds_type, "_pkey", uint_type,
+lldb::eAccessPublic, 0);
+  ast->CompleteTagDeclarationDefini

[Lldb-commits] [lldb] 742bfb3 - [lldb] Fix LLDB_FULL_VERSION_STRING

2022-01-19 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-01-19T14:20:22-08:00
New Revision: 742bfb3581e72909dce913cc2d6d77b54777ecdc

URL: 
https://github.com/llvm/llvm-project/commit/742bfb3581e72909dce913cc2d6d77b54777ecdc
DIFF: 
https://github.com/llvm/llvm-project/commit/742bfb3581e72909dce913cc2d6d77b54777ecdc.diff

LOG: [lldb] Fix LLDB_FULL_VERSION_STRING

Currently LLDB_FULL_VERSION_STRING is set to "LLDB_VERSION_STRING"
rather than the content of the CMake variable with that name.

Added: 


Modified: 
lldb/source/Version/CMakeLists.txt

Removed: 




diff  --git a/lldb/source/Version/CMakeLists.txt 
b/lldb/source/Version/CMakeLists.txt
index 4d66761739ae2..73367f2775bde 100644
--- a/lldb/source/Version/CMakeLists.txt
+++ b/lldb/source/Version/CMakeLists.txt
@@ -1,5 +1,5 @@
 if(LLDB_VERSION_STRING)
-  set(LLDB_FULL_VERSION_STRING LLDB_VERSION_STRING)
+  set(LLDB_FULL_VERSION_STRING ${LLDB_VERSION_STRING})
 endif()
 
 # Configure the VCSVersion.inc file.



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


[Lldb-commits] [PATCH] D117707: siginfo_t synthesis WIP

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

Initial PoC unit test — the idea is to verify field offsets and sizes against 
known values taken from real siginfo_t.


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/Linux/PlatformLinux.cpp
  lldb/source/Plugins/Platform/Linux/PlatformLinux.h
  lldb/source/Target/Platform.cpp
  lldb/unittests/Platform/CMakeLists.txt
  lldb/unittests/Platform/PlatformLinuxTest.cpp

Index: lldb/unittests/Platform/PlatformLinuxTest.cpp
===
--- /dev/null
+++ lldb/unittests/Platform/PlatformLinuxTest.cpp
@@ -0,0 +1,73 @@
+//===-- PlatformLinuxTest.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 "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 PlatformLinuxTest : public ::testing::Test {
+public:
+  SubsystemRAII subsystems;
+
+  void SetUp() override {
+llvm::cantFail(Reproducer::Initialize(ReproducerMode::Off, llvm::None));
+platform_linux::PlatformLinux::Initialize();
+  }
+
+  void TearDown() override {
+platform_linux::PlatformLinux::Terminate();
+Reproducer::Terminate();
+  }
+};
+
+} // namespace
+
+TEST_F(PlatformLinuxTest, TestSiginfoType_x86_64) {
+  ArchSpec arch("x86_64-pc-linux");
+
+  PlatformSP platform_sp = platform_linux::PlatformLinux::CreateInstance(true, &arch);
+  Platform::SetHostPlatform(platform_sp);
+
+  DebuggerSP debugger_sp = Debugger::CreateInstance();
+  ASSERT_TRUE(debugger_sp);
+
+  TargetSP target_sp;
+  debugger_sp->GetTargetList().CreateTarget(
+  *debugger_sp, "", arch, eLoadDependentsNo, platform_sp, target_sp);
+  ASSERT_TRUE(target_sp);
+
+  CompilerType siginfo_type = platform_sp->GetSiginfoType(*target_sp);
+  ASSERT_TRUE(siginfo_type);
+
+  CompilerType field_type;
+  uint64_t bit_offset;
+  uint32_t field_index;
+
+
+  field_index = siginfo_type.GetIndexOfFieldWithName("si_signo", &field_type, &bit_offset);
+  EXPECT_NE(field_index, UINT32_MAX);
+  if (field_index != UINT32_MAX) {
+EXPECT_EQ(bit_offset, 0);
+bool is_signed;
+EXPECT_TRUE(field_type.IsIntegerType(is_signed));
+EXPECT_TRUE(is_signed);
+  }
+}
Index: lldb/unittests/Platform/CMakeLists.txt
===
--- lldb/unittests/Platform/CMakeLists.txt
+++ lldb/unittests/Platform/CMakeLists.txt
@@ -1,8 +1,10 @@
 add_lldb_unittest(LLDBPlatformTests
   PlatformAppleSimulatorTest.cpp
   PlatformDarwinTest.cpp
+  PlatformLinuxTest.cpp
 
   LINK_LIBS
+lldbPluginPlatformLinux
 lldbPluginPlatformMacOSX
   LINK_COMPONENTS
 Support
Index: lldb/source/Target/Platform.cpp
===
--- lldb/source/Target/Platform.cpp
+++ lldb/source/Target/Platform.cpp
@@ -2003,3 +2003,7 @@
 
   return 0;
 }
+
+CompilerType Platform::GetSiginfoType(lldb_private::Target &target) {
+  return CompilerType();
+}
Index: lldb/source/Plugins/Platform/Linux/PlatformLinux.h
===
--- lldb/source/Plugins/Platform/Linux/PlatformLinux.h
+++ lldb/source/Plugins/Platform/Linux/PlatformLinux.h
@@ -58,6 +58,8 @@
   unsigned flags, lldb::addr_t fd,
   lldb::addr_t offset) override;
 
+  CompilerType GetSiginfoType(lldb_private::Target &target) override;
+
   std::vector m_supported_architectures;
 };
 
Index: lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
===
--- lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
+++ lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
@@ -14,6 +14,7 @@
 #include 
 #endif
 
+#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "Utility/ARM64_DWARF_Registers.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/PluginManager.h"
@@ -309,3 +310,183 @@
   return args;
 }
 
+CompilerType PlatformLinux::GetSiginfoType(lldb_private::Target &target) {
+  CompilerType type;
+ 

[Lldb-commits] [PATCH] D112825: [lldb] Add MemoryTagMap class

2022-01-19 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112825

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


[Lldb-commits] [PATCH] D117490: [lldb] Log prototype

2022-01-19 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

Very cool


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117490

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


[Lldb-commits] [PATCH] D117712: [lldb] Disconnect instrumentation from the reproducers

2022-01-19 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 401503.
JDevlieghere added a comment.

Simplify macros


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

https://reviews.llvm.org/D117712

Files:
  lldb/include/lldb/Utility/Instrumentation.h
  lldb/include/lldb/Utility/ReproducerInstrumentation.h
  lldb/source/API/SBAddress.cpp
  lldb/source/API/SBAttachInfo.cpp
  lldb/source/API/SBBlock.cpp
  lldb/source/API/SBBreakpoint.cpp
  lldb/source/API/SBBreakpointLocation.cpp
  lldb/source/API/SBBreakpointName.cpp
  lldb/source/API/SBBreakpointOptionCommon.cpp
  lldb/source/API/SBBroadcaster.cpp
  lldb/source/API/SBCommandInterpreter.cpp
  lldb/source/API/SBCommandInterpreterRunOptions.cpp
  lldb/source/API/SBCommandReturnObject.cpp
  lldb/source/API/SBCommunication.cpp
  lldb/source/API/SBCompileUnit.cpp
  lldb/source/API/SBData.cpp
  lldb/source/API/SBDebugger.cpp
  lldb/source/API/SBDeclaration.cpp
  lldb/source/API/SBEnvironment.cpp
  lldb/source/API/SBError.cpp
  lldb/source/API/SBEvent.cpp
  lldb/source/API/SBExecutionContext.cpp
  lldb/source/API/SBExpressionOptions.cpp
  lldb/source/API/SBFile.cpp
  lldb/source/API/SBFileSpec.cpp
  lldb/source/API/SBFileSpecList.cpp
  lldb/source/API/SBFrame.cpp
  lldb/source/API/SBFunction.cpp
  lldb/source/API/SBHostOS.cpp
  lldb/source/API/SBInstruction.cpp
  lldb/source/API/SBInstructionList.cpp
  lldb/source/API/SBLanguageRuntime.cpp
  lldb/source/API/SBLaunchInfo.cpp
  lldb/source/API/SBLineEntry.cpp
  lldb/source/API/SBListener.cpp
  lldb/source/API/SBMemoryRegionInfo.cpp
  lldb/source/API/SBMemoryRegionInfoList.cpp
  lldb/source/API/SBModule.cpp
  lldb/source/API/SBModuleSpec.cpp
  lldb/source/API/SBPlatform.cpp
  lldb/source/API/SBProcess.cpp
  lldb/source/API/SBProcessInfo.cpp
  lldb/source/API/SBQueue.cpp
  lldb/source/API/SBQueueItem.cpp
  lldb/source/API/SBReproducer.cpp
  lldb/source/API/SBSection.cpp
  lldb/source/API/SBSourceManager.cpp
  lldb/source/API/SBStream.cpp
  lldb/source/API/SBStringList.cpp
  lldb/source/API/SBStructuredData.cpp
  lldb/source/API/SBSymbol.cpp
  lldb/source/API/SBSymbolContext.cpp
  lldb/source/API/SBSymbolContextList.cpp
  lldb/source/API/SBTarget.cpp
  lldb/source/API/SBThread.cpp
  lldb/source/API/SBThreadCollection.cpp
  lldb/source/API/SBThreadPlan.cpp
  lldb/source/API/SBTrace.cpp
  lldb/source/API/SBType.cpp
  lldb/source/API/SBTypeCategory.cpp
  lldb/source/API/SBTypeEnumMember.cpp
  lldb/source/API/SBTypeFilter.cpp
  lldb/source/API/SBTypeFormat.cpp
  lldb/source/API/SBTypeNameSpecifier.cpp
  lldb/source/API/SBTypeSummary.cpp
  lldb/source/API/SBTypeSynthetic.cpp
  lldb/source/API/SBUnixSignals.cpp
  lldb/source/API/SBValue.cpp
  lldb/source/API/SBValueList.cpp
  lldb/source/API/SBVariablesOptions.cpp
  lldb/source/API/SBWatchpoint.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/source/Utility/CMakeLists.txt
  lldb/source/Utility/Instrumentation.cpp
  lldb/source/Utility/ReproducerInstrumentation.cpp

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


[Lldb-commits] [PATCH] D117748: [lldb] Revive lldb-instr

2022-01-19 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added a reviewer: labath.
Herald added a subscriber: mgorny.
JDevlieghere requested review of this revision.

I revived `lldb-instr` to update the macros for D117712 
. I think the new macros are simple enough 
that we add them by hand, but this tool can do it automatically for you.


https://reviews.llvm.org/D117748

Files:
  lldb/tools/CMakeLists.txt
  lldb/tools/lldb-instr/CMakeLists.txt
  lldb/tools/lldb-instr/Instrument.cpp

Index: lldb/tools/lldb-instr/Instrument.cpp
===
--- /dev/null
+++ lldb/tools/lldb-instr/Instrument.cpp
@@ -0,0 +1,169 @@
+#include "clang/AST/AST.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
+#include "clang/Frontend/ASTConsumers.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include 
+#include 
+
+using namespace clang;
+using namespace clang::driver;
+using namespace clang::tooling;
+
+static llvm::cl::OptionCategory InstrCategory("LLDB Instrumentation Generator");
+
+class SBVisitor : public RecursiveASTVisitor {
+public:
+  SBVisitor(Rewriter &R, ASTContext &Context)
+  : MyRewriter(R), Context(Context) {}
+
+  bool VisitCXXMethodDecl(CXXMethodDecl *Decl) {
+// Not all decls should be registered. Please refer to that method's
+// comment for details.
+if (ShouldSkip(Decl))
+  return false;
+
+// Print 'bool' instead of '_Bool'.
+PrintingPolicy Policy(Context.getLangOpts());
+Policy.Bool = true;
+
+// Collect the functions parameter types and names.
+std::vector ParamNames;
+for (auto *P : Decl->parameters())
+  ParamNames.push_back(P->getNameAsString());
+
+// Construct the macros.
+std::string Macro;
+if (ParamNames.empty()) {
+  Macro = "LLDB_INSTRUMENT()";
+} else {
+  Macro = "LLDB_INSTRUMENT_VA(" + llvm::join(ParamNames, ", ") + ")";
+}
+
+Stmt *Body = Decl->getBody();
+for (auto &C : Body->children()) {
+  if (C->getBeginLoc().isMacroID()) {
+CharSourceRange Range =
+MyRewriter.getSourceMgr().getExpansionRange(C->getSourceRange());
+MyRewriter.ReplaceText(Range, Macro);
+  } else {
+SourceLocation InsertLoc = Lexer::getLocForEndOfToken(
+Body->getBeginLoc(), 0, MyRewriter.getSourceMgr(),
+MyRewriter.getLangOpts());
+MyRewriter.InsertTextAfter(InsertLoc, Macro);
+  }
+  break;
+}
+
+return true;
+  }
+
+private:
+  /// Determine whether we need to consider the given CXXMethodDecl.
+  ///
+  /// Currently we skip the following cases:
+  ///  1. Decls outside the main source file,
+  ///  2. Decls that are only present in the source file,
+  ///  3. Decls that are not definitions,
+  ///  4. Non-public methods,
+  ///  5. Variadic methods.
+  ///  6. Destructors.
+  bool ShouldSkip(CXXMethodDecl *Decl) {
+// Skip anything outside the main file.
+if (!MyRewriter.getSourceMgr().isInMainFile(Decl->getBeginLoc()))
+  return true;
+
+// Skip if the canonical decl in the current decl. It means that the method
+// is declared in the implementation and is therefore not exposed as part
+// of the API.
+if (Decl == Decl->getCanonicalDecl())
+  return true;
+
+// Skip decls that have no body, i.e. are just declarations.
+Stmt *Body = Decl->getBody();
+if (!Body)
+  return true;
+
+// Skip non-public methods.
+AccessSpecifier AS = Decl->getAccess();
+if (AS != AccessSpecifier::AS_public)
+  return true;
+
+// Skip variadic methods.
+if (Decl->isVariadic())
+  return true;
+
+// Skip destructors.
+if (isa(Decl))
+  return true;
+
+return false;
+  }
+
+  Rewriter &MyRewriter;
+  ASTContext &Context;
+};
+
+class SBConsumer : public ASTConsumer {
+public:
+  SBConsumer(Rewriter &R, ASTContext &Context) : Visitor(R, Context) {}
+
+  // Override the method that gets called for each parsed top-level
+  // declaration.
+  bool HandleTopLevelDecl(DeclGroupRef DR) override {
+for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) {
+  Visitor.TraverseDecl(*b);
+}
+return true;
+  }
+
+private:
+  SBVisitor Visitor;
+};
+
+class SBAction : public ASTFrontendAction {
+public:
+  SBAction() = default;
+
+  bool BeginSourceFileAction(CompilerInstance &CI) override { return true; }
+
+  void EndSourceFileAction() override { MyRewriter.overwriteChangedFiles(); }
+
+  std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
+ StringRef F

[Lldb-commits] [PATCH] D117712: [lldb] Disconnect instrumentation from the reproducers

2022-01-19 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 401505.
JDevlieghere added a comment.

Rebase


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

https://reviews.llvm.org/D117712

Files:
  lldb/include/lldb/Utility/Instrumentation.h
  lldb/include/lldb/Utility/ReproducerInstrumentation.h
  lldb/source/API/SBAddress.cpp
  lldb/source/API/SBAttachInfo.cpp
  lldb/source/API/SBBlock.cpp
  lldb/source/API/SBBreakpoint.cpp
  lldb/source/API/SBBreakpointLocation.cpp
  lldb/source/API/SBBreakpointName.cpp
  lldb/source/API/SBBreakpointOptionCommon.cpp
  lldb/source/API/SBBroadcaster.cpp
  lldb/source/API/SBCommandInterpreter.cpp
  lldb/source/API/SBCommandInterpreterRunOptions.cpp
  lldb/source/API/SBCommandReturnObject.cpp
  lldb/source/API/SBCommunication.cpp
  lldb/source/API/SBCompileUnit.cpp
  lldb/source/API/SBData.cpp
  lldb/source/API/SBDebugger.cpp
  lldb/source/API/SBDeclaration.cpp
  lldb/source/API/SBEnvironment.cpp
  lldb/source/API/SBError.cpp
  lldb/source/API/SBEvent.cpp
  lldb/source/API/SBExecutionContext.cpp
  lldb/source/API/SBExpressionOptions.cpp
  lldb/source/API/SBFile.cpp
  lldb/source/API/SBFileSpec.cpp
  lldb/source/API/SBFileSpecList.cpp
  lldb/source/API/SBFrame.cpp
  lldb/source/API/SBFunction.cpp
  lldb/source/API/SBHostOS.cpp
  lldb/source/API/SBInstruction.cpp
  lldb/source/API/SBInstructionList.cpp
  lldb/source/API/SBLanguageRuntime.cpp
  lldb/source/API/SBLaunchInfo.cpp
  lldb/source/API/SBLineEntry.cpp
  lldb/source/API/SBListener.cpp
  lldb/source/API/SBMemoryRegionInfo.cpp
  lldb/source/API/SBMemoryRegionInfoList.cpp
  lldb/source/API/SBModule.cpp
  lldb/source/API/SBModuleSpec.cpp
  lldb/source/API/SBPlatform.cpp
  lldb/source/API/SBProcess.cpp
  lldb/source/API/SBProcessInfo.cpp
  lldb/source/API/SBQueue.cpp
  lldb/source/API/SBQueueItem.cpp
  lldb/source/API/SBReproducer.cpp
  lldb/source/API/SBSection.cpp
  lldb/source/API/SBSourceManager.cpp
  lldb/source/API/SBStream.cpp
  lldb/source/API/SBStringList.cpp
  lldb/source/API/SBStructuredData.cpp
  lldb/source/API/SBSymbol.cpp
  lldb/source/API/SBSymbolContext.cpp
  lldb/source/API/SBSymbolContextList.cpp
  lldb/source/API/SBTarget.cpp
  lldb/source/API/SBThread.cpp
  lldb/source/API/SBThreadCollection.cpp
  lldb/source/API/SBThreadPlan.cpp
  lldb/source/API/SBTrace.cpp
  lldb/source/API/SBType.cpp
  lldb/source/API/SBTypeCategory.cpp
  lldb/source/API/SBTypeEnumMember.cpp
  lldb/source/API/SBTypeFilter.cpp
  lldb/source/API/SBTypeFormat.cpp
  lldb/source/API/SBTypeNameSpecifier.cpp
  lldb/source/API/SBTypeSummary.cpp
  lldb/source/API/SBTypeSynthetic.cpp
  lldb/source/API/SBUnixSignals.cpp
  lldb/source/API/SBValue.cpp
  lldb/source/API/SBValueList.cpp
  lldb/source/API/SBVariablesOptions.cpp
  lldb/source/API/SBWatchpoint.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/source/Utility/CMakeLists.txt
  lldb/source/Utility/Instrumentation.cpp
  lldb/source/Utility/ReproducerInstrumentation.cpp

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