[Lldb-commits] [PATCH] D134877: [lldb] Get rid of __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS

2022-09-30 Thread serge via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG81fc5f7909a4: [lldb] Get rid of __STDC_LIMIT_MACROS and 
__STDC_CONSTANT_MACROS (authored by serge-sans-paille).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134877

Files:
  lldb/bindings/CMakeLists.txt
  lldb/bindings/interfaces.swig


Index: lldb/bindings/interfaces.swig
===
--- lldb/bindings/interfaces.swig
+++ lldb/bindings/interfaces.swig
@@ -1,8 +1,5 @@
 /* Various liblldb typedefs that SWIG needs to know about.  */
 #define __extension__ /* Undefine GCC keyword to make Swig happy when 
processing glibc's stdint.h. */
-/* The ISO C99 standard specifies that in C++ implementations limit macros such
-   as INT32_MAX should only be defined if __STDC_LIMIT_MACROS is. */
-#define __STDC_LIMIT_MACROS
 %include "stdint.i"
 
 %include "lldb/lldb-defines.h"
Index: lldb/bindings/CMakeLists.txt
===
--- lldb/bindings/CMakeLists.txt
+++ lldb/bindings/CMakeLists.txt
@@ -26,8 +26,6 @@
   -features autodoc
   -I${LLDB_SOURCE_DIR}/include
   -I${CMAKE_CURRENT_SOURCE_DIR}
-  -D__STDC_LIMIT_MACROS
-  -D__STDC_CONSTANT_MACROS
   ${DARWIN_EXTRAS}
 )
 


Index: lldb/bindings/interfaces.swig
===
--- lldb/bindings/interfaces.swig
+++ lldb/bindings/interfaces.swig
@@ -1,8 +1,5 @@
 /* Various liblldb typedefs that SWIG needs to know about.  */
 #define __extension__ /* Undefine GCC keyword to make Swig happy when processing glibc's stdint.h. */
-/* The ISO C99 standard specifies that in C++ implementations limit macros such
-   as INT32_MAX should only be defined if __STDC_LIMIT_MACROS is. */
-#define __STDC_LIMIT_MACROS
 %include "stdint.i"
 
 %include "lldb/lldb-defines.h"
Index: lldb/bindings/CMakeLists.txt
===
--- lldb/bindings/CMakeLists.txt
+++ lldb/bindings/CMakeLists.txt
@@ -26,8 +26,6 @@
   -features autodoc
   -I${LLDB_SOURCE_DIR}/include
   -I${CMAKE_CURRENT_SOURCE_DIR}
-  -D__STDC_LIMIT_MACROS
-  -D__STDC_CONSTANT_MACROS
   ${DARWIN_EXTRAS}
 )
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 81fc5f7 - [lldb] Get rid of __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS

2022-09-30 Thread via lldb-commits

Author: serge-sans-paille
Date: 2022-09-30T09:05:17+02:00
New Revision: 81fc5f7909a4ef5a8d4b5da2a10f77f7cb01ba63

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

LOG: [lldb] Get rid of __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS

C++11 made the use of these macro obsolete, see 
https://sourceware.org/bugzilla/show_bug.cgi?id=15366

As a side effect this prevents https://github.com/swig/swig/issues/2193.

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

Added: 


Modified: 
lldb/bindings/CMakeLists.txt
lldb/bindings/interfaces.swig

Removed: 




diff  --git a/lldb/bindings/CMakeLists.txt b/lldb/bindings/CMakeLists.txt
index c8aa0bcf96817..9eed2f1e62999 100644
--- a/lldb/bindings/CMakeLists.txt
+++ b/lldb/bindings/CMakeLists.txt
@@ -26,8 +26,6 @@ set(SWIG_COMMON_FLAGS
   -features autodoc
   -I${LLDB_SOURCE_DIR}/include
   -I${CMAKE_CURRENT_SOURCE_DIR}
-  -D__STDC_LIMIT_MACROS
-  -D__STDC_CONSTANT_MACROS
   ${DARWIN_EXTRAS}
 )
 

diff  --git a/lldb/bindings/interfaces.swig b/lldb/bindings/interfaces.swig
index fb75513a0df1b..d984711bbd8a2 100644
--- a/lldb/bindings/interfaces.swig
+++ b/lldb/bindings/interfaces.swig
@@ -1,8 +1,5 @@
 /* Various liblldb typedefs that SWIG needs to know about.  */
 #define __extension__ /* Undefine GCC keyword to make Swig happy when 
processing glibc's stdint.h. */
-/* The ISO C99 standard specifies that in C++ implementations limit macros such
-   as INT32_MAX should only be defined if __STDC_LIMIT_MACROS is. */
-#define __STDC_LIMIT_MACROS
 %include "stdint.i"
 
 %include "lldb/lldb-defines.h"



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


[Lldb-commits] [PATCH] D134873: [LLDB] Add "process status" as equivalent of GDB's "frame" command

2022-09-30 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett updated this revision to Diff 464185.
DavidSpickett added a comment.

- Add "frame select" and short "f" version on the lldb side.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134873

Files:
  lldb/docs/use/map.rst


Index: lldb/docs/use/map.rst
===
--- lldb/docs/use/map.rst
+++ lldb/docs/use/map.rst
@@ -410,6 +410,20 @@

  
 
+ 
+   Show the current frame and 
source line.
+ 
+ 
+   
+  (gdb) frame
+   
+   
+  (lldb) frame select
+  (lldb) f
+  (lldb) process status
+   
+ 
+
   

 


Index: lldb/docs/use/map.rst
===
--- lldb/docs/use/map.rst
+++ lldb/docs/use/map.rst
@@ -410,6 +410,20 @@

  
 
+ 
+   Show the current frame and source line.
+ 
+ 
+   
+  (gdb) frame
+   
+   
+  (lldb) frame select
+  (lldb) f
+  (lldb) process status
+   
+ 
+
   

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


[Lldb-commits] [lldb] fe17e02 - [lldb][Windows] Always call SetExecutableModule on debugger connected

2022-09-30 Thread Martin Storsjö via lldb-commits

Author: Alvin Wong
Date: 2022-09-30T13:51:56+03:00
New Revision: fe17e026959cc263c12fafa3a8e9e83503f9a18b

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

LOG: [lldb][Windows] Always call SetExecutableModule on debugger connected

In `ProcessWindows::OnDebuggerConnected` (triggered from
`CREATE_PROCESS_DEBUG_EVENT`), we should always call
`Target::SetExecutableModule` regardless of whether LLDB has already
preloaded the executable modules. `SetExecutableModule` has the side
effect of clearing the module list of the Target, which help make sure
that module #0 is the executable module and the rest of the modules are
listed according to the DLL load order in the process (technically this
has no real consequences but it seems to make more sense anyway.) It
also fixes an issue where the modules preloaded by LLDB will be
duplicated when the debuggee process actually loads the DLL.

Reviewed By: labath

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

Added: 
lldb/test/Shell/Target/Inputs/main.c
lldb/test/Shell/Target/Inputs/shlib.c
lldb/test/Shell/Target/dependent-modules-nodupe-windows.test

Modified: 
lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
index e3d04c9f34491..a84dd62357de7 100644
--- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -653,28 +653,26 @@ void ProcessWindows::OnDebuggerConnected(lldb::addr_t 
image_base) {
   LLDB_LOG(log, "Debugger connected to process {0}.  Image base = {1:x}",
debugger->GetProcess().GetProcessId(), image_base);
 
-  ModuleSP module = GetTarget().GetExecutableModule();
-  if (!module) {
-// During attach, we won't have the executable module, so find it now.
-const DWORD pid = debugger->GetProcess().GetProcessId();
-const std::string file_name = GetProcessExecutableName(pid);
-if (file_name.empty()) {
-  return;
-}
-
-FileSpec executable_file(file_name);
-FileSystem::Instance().Resolve(executable_file);
-ModuleSpec module_spec(executable_file);
-Status error;
-module =
-GetTarget().GetOrCreateModule(module_spec, true /* notify */, &error);
-if (!module) {
-  return;
-}
+  ModuleSP module;
+  // During attach, we won't have the executable module, so find it now.
+  const DWORD pid = debugger->GetProcess().GetProcessId();
+  const std::string file_name = GetProcessExecutableName(pid);
+  if (file_name.empty()) {
+return;
+  }
 
-GetTarget().SetExecutableModule(module, eLoadDependentsNo);
+  FileSpec executable_file(file_name);
+  FileSystem::Instance().Resolve(executable_file);
+  ModuleSpec module_spec(executable_file);
+  Status error;
+  module =
+  GetTarget().GetOrCreateModule(module_spec, true /* notify */, &error);
+  if (!module) {
+return;
   }
 
+  GetTarget().SetExecutableModule(module, eLoadDependentsNo);
+
   if (auto dyld = GetDynamicLoader())
 dyld->OnLoadModule(module, ModuleSpec(), image_base);
 

diff  --git a/lldb/test/Shell/Target/Inputs/main.c 
b/lldb/test/Shell/Target/Inputs/main.c
new file mode 100644
index 0..761410b1b52fe
--- /dev/null
+++ b/lldb/test/Shell/Target/Inputs/main.c
@@ -0,0 +1,2 @@
+__declspec(dllimport) void exportFunc(void);
+int main() { exportFunc(); }

diff  --git a/lldb/test/Shell/Target/Inputs/shlib.c 
b/lldb/test/Shell/Target/Inputs/shlib.c
new file mode 100644
index 0..b0a8d463fb663
--- /dev/null
+++ b/lldb/test/Shell/Target/Inputs/shlib.c
@@ -0,0 +1 @@
+__declspec(dllexport) void exportFunc(void) {}

diff  --git a/lldb/test/Shell/Target/dependent-modules-nodupe-windows.test 
b/lldb/test/Shell/Target/dependent-modules-nodupe-windows.test
new file mode 100644
index 0..52e46cd0c9b21
--- /dev/null
+++ b/lldb/test/Shell/Target/dependent-modules-nodupe-windows.test
@@ -0,0 +1,24 @@
+# REQUIRES: system-windows
+
+# Checks that dependent modules preloaded by LLDB are not duplicated when the
+# process actually loads the DLL.
+
+# RUN: %clang_host -g0 -O0 -shared %S/Inputs/shlib.c -o %t.shlib.dll \
+# RUN: %if windows-msvc %{-Wl,-implib:%t.shlib.lib%} \
+# RUN: %else %{-Wl,--out-implib=%t.shlib.lib%}
+# RUN: %clang_host -g0 -O0 %S/Inputs/main.c %t.shlib.lib -o %t.main.exe
+# RUN: %lldb -b -o "#before" -o "target modules list" -o "b main" -o run \
+# RUN:   -o "#after" -o "target modules list" %t.main.exe | FileCheck %s
+
+# CHECK-LABEL: #before
+# CHECK-NEXT: target modules list
+# CHECK-NEXT: .main.exe
+# CHECK-NEXT: .shlib.dll
+
+# CHECK-LABEL: #after
+# CHECK-NEXT: target modules

[Lldb-commits] [PATCH] D134636: [lldb][Windows] Always call SetExecutableModule on debugger connected

2022-09-30 Thread Martin Storsjö via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfe17e026959c: [lldb][Windows] Always call 
SetExecutableModule on debugger connected (authored by alvinhochun, committed 
by mstorsjo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134636

Files:
  lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
  lldb/test/Shell/Target/Inputs/main.c
  lldb/test/Shell/Target/Inputs/shlib.c
  lldb/test/Shell/Target/dependent-modules-nodupe-windows.test


Index: lldb/test/Shell/Target/dependent-modules-nodupe-windows.test
===
--- /dev/null
+++ lldb/test/Shell/Target/dependent-modules-nodupe-windows.test
@@ -0,0 +1,24 @@
+# REQUIRES: system-windows
+
+# Checks that dependent modules preloaded by LLDB are not duplicated when the
+# process actually loads the DLL.
+
+# RUN: %clang_host -g0 -O0 -shared %S/Inputs/shlib.c -o %t.shlib.dll \
+# RUN: %if windows-msvc %{-Wl,-implib:%t.shlib.lib%} \
+# RUN: %else %{-Wl,--out-implib=%t.shlib.lib%}
+# RUN: %clang_host -g0 -O0 %S/Inputs/main.c %t.shlib.lib -o %t.main.exe
+# RUN: %lldb -b -o "#before" -o "target modules list" -o "b main" -o run \
+# RUN:   -o "#after" -o "target modules list" %t.main.exe | FileCheck %s
+
+# CHECK-LABEL: #before
+# CHECK-NEXT: target modules list
+# CHECK-NEXT: .main.exe
+# CHECK-NEXT: .shlib.dll
+
+# CHECK-LABEL: #after
+# CHECK-NEXT: target modules list
+# CHECK-NEXT: .main.exe
+# CHECK-NEXT: ntdll.dll
+# CHECK-NEXT: kernel32.dll
+# CHECK:  .shlib.dll
+# CHECK-NOT:  .shlib.dll
Index: lldb/test/Shell/Target/Inputs/shlib.c
===
--- /dev/null
+++ lldb/test/Shell/Target/Inputs/shlib.c
@@ -0,0 +1 @@
+__declspec(dllexport) void exportFunc(void) {}
Index: lldb/test/Shell/Target/Inputs/main.c
===
--- /dev/null
+++ lldb/test/Shell/Target/Inputs/main.c
@@ -0,0 +1,2 @@
+__declspec(dllimport) void exportFunc(void);
+int main() { exportFunc(); }
Index: lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
===
--- lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -653,28 +653,26 @@
   LLDB_LOG(log, "Debugger connected to process {0}.  Image base = {1:x}",
debugger->GetProcess().GetProcessId(), image_base);
 
-  ModuleSP module = GetTarget().GetExecutableModule();
-  if (!module) {
-// During attach, we won't have the executable module, so find it now.
-const DWORD pid = debugger->GetProcess().GetProcessId();
-const std::string file_name = GetProcessExecutableName(pid);
-if (file_name.empty()) {
-  return;
-}
-
-FileSpec executable_file(file_name);
-FileSystem::Instance().Resolve(executable_file);
-ModuleSpec module_spec(executable_file);
-Status error;
-module =
-GetTarget().GetOrCreateModule(module_spec, true /* notify */, &error);
-if (!module) {
-  return;
-}
+  ModuleSP module;
+  // During attach, we won't have the executable module, so find it now.
+  const DWORD pid = debugger->GetProcess().GetProcessId();
+  const std::string file_name = GetProcessExecutableName(pid);
+  if (file_name.empty()) {
+return;
+  }
 
-GetTarget().SetExecutableModule(module, eLoadDependentsNo);
+  FileSpec executable_file(file_name);
+  FileSystem::Instance().Resolve(executable_file);
+  ModuleSpec module_spec(executable_file);
+  Status error;
+  module =
+  GetTarget().GetOrCreateModule(module_spec, true /* notify */, &error);
+  if (!module) {
+return;
   }
 
+  GetTarget().SetExecutableModule(module, eLoadDependentsNo);
+
   if (auto dyld = GetDynamicLoader())
 dyld->OnLoadModule(module, ModuleSpec(), image_base);
 


Index: lldb/test/Shell/Target/dependent-modules-nodupe-windows.test
===
--- /dev/null
+++ lldb/test/Shell/Target/dependent-modules-nodupe-windows.test
@@ -0,0 +1,24 @@
+# REQUIRES: system-windows
+
+# Checks that dependent modules preloaded by LLDB are not duplicated when the
+# process actually loads the DLL.
+
+# RUN: %clang_host -g0 -O0 -shared %S/Inputs/shlib.c -o %t.shlib.dll \
+# RUN: %if windows-msvc %{-Wl,-implib:%t.shlib.lib%} \
+# RUN: %else %{-Wl,--out-implib=%t.shlib.lib%}
+# RUN: %clang_host -g0 -O0 %S/Inputs/main.c %t.shlib.lib -o %t.main.exe
+# RUN: %lldb -b -o "#before" -o "target modules list" -o "b main" -o run \
+# RUN:   -o "#after" -o "target modules list" %t.main.exe | FileCheck %s
+
+# CHECK-LABEL: #before
+# CHECK-NEXT: target modules list
+# CHECK-NEXT: .main.exe
+# CHECK-NEXT: .shlib.dll
+
+#

[Lldb-commits] [PATCH] D134906: Have MemoryCache cache addresses that were unreadable, so duplicate read attempts can be suppressed

2022-09-30 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a reviewer: DavidSpickett.
DavidSpickett added a comment.

Seems like a valid thing to do.

Is it a problem that maybe you read from address N to N+100 and the problem 
address is actually at N+50, not N? I think you might be handling that already 
but I didn't read all the logic just your additions. Maybe not an issue because 
a lot of this is done in pages of memory, unlikely to be a <10 byte gap where 
something fails (and you can manually flush the cache if that somehow happens).

> In this case, the elements often have the value 0, so lldb is trying to read 
> memory at address 0, which fails, and the number of reads is quite large.

In this environment I guess they don't have a dynamic loader to have set the 
ranges? So in Mac OS userspace, this wouldn't be a problem because the zero 
page would be marked as always invalid, but they don't have that luxury.

And there's nothing stopping a bare metal program from mapping memory at 0, so 
one can't just say 0 means invalid 100% of the time.

> doesn't address the fact that m_invalid_ranges is intended to track 
> inaccessible memory that is invariant during the process lifetime.

Please add this as a comment, will be good to know if/when there are two lists 
involved.




Comment at: lldb/source/Target/Memory.cpp:157
+  if (IsAddressUnreadable(addr)) {
+error.SetErrorStringWithFormat("memory read failed for 0x%" PRIx64, addr);
+return 0;

Should this be more specific like "failed because we know this is unreadable" 
or "has previously failed to read"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134906

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


[Lldb-commits] [PATCH] D134873: [LLDB] Add "frame select" as equivalent of GDB's "frame" command

2022-09-30 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

Thanks for the suggestion @jingham , does this look good to you?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134873

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


[Lldb-commits] [PATCH] D132734: [lldb] Fix member access in GetExpressionPath

2022-09-30 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG14642dc7405e: [lldb] Fix member access in GetExpressionPath 
(authored by tonkosi, committed by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132734

Files:
  lldb/source/Core/ValueObject.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/test/API/python_api/expression_path/Makefile
  lldb/test/API/python_api/expression_path/TestExpressionPath.py
  lldb/test/API/python_api/expression_path/main.cpp

Index: lldb/test/API/python_api/expression_path/main.cpp
===
--- /dev/null
+++ lldb/test/API/python_api/expression_path/main.cpp
@@ -0,0 +1,34 @@
+struct StructA {
+  int x;
+  int y;
+};
+
+struct StructB {
+  int x;
+  StructA &a_ref;
+  StructA *&a_ptr_ref;
+};
+
+struct StructC : public StructB {
+  int y;
+
+  StructC(int x, StructA &a_ref, StructA *&a_ref_ptr, int y)
+  : StructB{x, a_ref, a_ref_ptr}, y(y) {}
+};
+
+int main() {
+  StructA a{1, 2};
+  StructA *a_ptr = &a;
+
+  StructB b{3, a, a_ptr};
+  StructB *b_ptr = &b;
+  StructB &b_ref = b;
+  StructB *&b_ptr_ref = b_ptr;
+
+  StructC c(4, a, a_ptr, 5);
+  StructC *c_ptr = &c;
+  StructC &c_ref = c;
+  StructC *&c_ptr_ref = c_ptr;
+
+  return 0; // Set breakpoint here
+}
\ No newline at end of file
Index: lldb/test/API/python_api/expression_path/TestExpressionPath.py
===
--- /dev/null
+++ lldb/test/API/python_api/expression_path/TestExpressionPath.py
@@ -0,0 +1,119 @@
+"""Test that SBFrame::GetExpressionPath construct valid expressions"""
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class SBValueGetExpressionPathTest(TestBase):
+NO_DEBUG_INFO_TESTCASE = True
+
+def path(self, value):
+"""Constructs the expression path given the SBValue"""
+if not value:
+return None
+stream = lldb.SBStream()
+if not value.GetExpressionPath(stream):
+return None
+return stream.GetData()
+
+def test_expression_path(self):
+"""Test that SBFrame::GetExpressionPath construct valid expressions"""
+self.build()
+self.setTearDownCleanup()
+
+exe = self.getBuildArtifact("a.out")
+
+# Create the target
+target = self.dbg.CreateTarget(exe)
+self.assertTrue(target, VALID_TARGET)
+
+# Set the breakpoints
+breakpoint = target.BreakpointCreateBySourceRegex(
+'Set breakpoint here', lldb.SBFileSpec("main.cpp"))
+self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT)
+
+# Launch the process, and do not stop at the entry point.
+process = target.LaunchSimple(
+None, None, self.get_process_working_directory())
+
+self.assertTrue(process, PROCESS_IS_VALID)
+
+# Frame #0 should be at our breakpoint.
+threads = lldbutil.get_threads_stopped_at_breakpoint(
+process, breakpoint)
+
+self.assertEquals(len(threads), 1)
+self.thread = threads[0]
+self.frame = self.thread.frames[0]
+self.assertTrue(self.frame, "Frame 0 is valid.")
+
+# Find "b" variables in frame
+b = self.frame.FindVariable("b")
+bp = self.frame.FindVariable("b_ptr")
+br = self.frame.FindVariable("b_ref")
+bpr = self.frame.FindVariable("b_ptr_ref")
+# Check expression paths
+self.assertEqual(self.path(b), "b")
+self.assertEqual(self.path(bp), "b_ptr")
+self.assertEqual(self.path(br), "b_ref")
+self.assertEqual(self.path(bpr), "b_ptr_ref")
+
+# Dereference "b" pointers
+bp_deref = bp.Dereference()
+bpr_deref = bpr.Dereference()  # a pointer
+bpr_deref2 = bpr_deref.Dereference()  # two Dereference() calls to get object
+# Check expression paths
+self.assertEqual(self.path(bp_deref), "*(b_ptr)")
+self.assertEqual(self.path(bpr_deref), "b_ptr_ref")
+self.assertEqual(self.path(bpr_deref2), "*(b_ptr_ref)")
+
+# Access "b" members and check expression paths
+self.assertEqual(self.path(b.GetChildMemberWithName("x")), "b.x")
+self.assertEqual(self.path(bp.GetChildMemberWithName("x")), "b_ptr->x")
+self.assertEqual(self.path(br.GetChildMemberWithName("x")), "b_ref.x")
+self.assertEqual(self.path(bp_deref.GetChildMemberWithName("x")), "(*(b_ptr)).x")
+self.assertEqual(self.path(bpr_deref.GetChildMemberWithName("x")), "b_ptr_ref->x")
+self.assertEqual(self.path(bpr_deref2.GetChildMemberWithName("x")), "(*(b_ptr_ref)).x")
+# TODO: Uncomment once accessing members on pointer references is supported.
+# self.assertEqual(self.path(bpr.Ge

[Lldb-commits] [lldb] 14642dc - [lldb] Fix member access in GetExpressionPath

2022-09-30 Thread Andy Yankovsky via lldb-commits

Author: Tonko Sabolčec
Date: 2022-09-30T11:25:07Z
New Revision: 14642dc7405ebd93a46dda1f2dba616395660715

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

LOG: [lldb] Fix member access in GetExpressionPath

This change fixes two issues in ValueObject::GetExpressionPath method:

 1. Accessing members of struct references used to produce expression
paths such as "str.&str.member" (instead of the expected
"str.member"). This is fixed by assigning the flag tha the child
value is a dereference when calling Dereference() on references
and adjusting logic in expression path creation.

 2. If the parent of member access is dereference, the produced
expression path was "*(ptr).member". This is incorrect, since it
dereferences the member instead of the pointer. This is fixed by
wrapping dereference expression into parenthesis, resulting with
"(*(ptr)).member".

Reviewed By: werat, clayborg

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

Added: 
lldb/test/API/python_api/expression_path/Makefile
lldb/test/API/python_api/expression_path/TestExpressionPath.py
lldb/test/API/python_api/expression_path/main.cpp

Modified: 
lldb/source/Core/ValueObject.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Removed: 




diff  --git a/lldb/source/Core/ValueObject.cpp 
b/lldb/source/Core/ValueObject.cpp
index 19d86bee40e1f..ece787bdbe4c0 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -273,8 +273,6 @@ CompilerType ValueObject::MaybeCalculateCompleteType() {
   return compiler_type;
 }
 
-
-
 DataExtractor &ValueObject::GetDataExtractor() {
   UpdateValueIfNeeded(false);
   return m_data;
@@ -409,8 +407,9 @@ ValueObject::GetChildAtIndexPath(llvm::ArrayRef 
idxs,
   return root;
 }
 
-lldb::ValueObjectSP ValueObject::GetChildAtIndexPath(
-  llvm::ArrayRef> idxs, size_t *index_of_error) {
+lldb::ValueObjectSP
+ValueObject::GetChildAtIndexPath(llvm::ArrayRef> idxs,
+ size_t *index_of_error) {
   if (idxs.size() == 0)
 return GetSP();
   ValueObjectSP root(GetSP());
@@ -1185,9 +1184,10 @@ bool ValueObject::DumpPrintableRepresentation(
   {
 Status error;
 lldb::WritableDataBufferSP buffer_sp;
-std::pair read_string = ReadPointedString(
-buffer_sp, error, 0, (custom_format == eFormatVectorOfChar) ||
- (custom_format == eFormatCharArray));
+std::pair read_string =
+ReadPointedString(buffer_sp, error, 0,
+  (custom_format == eFormatVectorOfChar) ||
+  (custom_format == eFormatCharArray));
 lldb_private::formatters::StringPrinter::
 ReadBufferAndDumpToStreamOptions options(*this);
 options.SetData(DataExtractor(
@@ -1552,8 +1552,7 @@ bool ValueObject::GetDeclaration(Declaration &decl) {
   return false;
 }
 
-void ValueObject::AddSyntheticChild(ConstString key,
-ValueObject *valobj) {
+void ValueObject::AddSyntheticChild(ConstString key, ValueObject *valobj) {
   m_synthetic_children[key] = valobj;
 }
 
@@ -1924,64 +1923,96 @@ void ValueObject::GetExpressionPath(Stream &s,
 return;
   }
 
-  const bool is_deref_of_parent = IsDereferenceOfParent();
+  // Checks whether a value is dereference of a non-reference parent.
+  // This is used to determine whether to print a dereference operation (*).
+  auto is_deref_of_non_reference = [](ValueObject *value) {
+if (value == nullptr)
+  return false;
+ValueObject *value_parent = value->GetParent();
+if (value_parent) {
+  CompilerType parent_compiler_type = value_parent->GetCompilerType();
+  if (parent_compiler_type) {
+const uint32_t parent_type_info = parent_compiler_type.GetTypeInfo();
+if (parent_type_info & eTypeIsReference)
+  return false;
+  }
+}
+return value->IsDereferenceOfParent();
+  };
+
+  ValueObject *parent = GetParent();
 
-  if (is_deref_of_parent &&
+  if (is_deref_of_non_reference(this) &&
   epformat == eGetExpressionPathFormatDereferencePointers) {
 // this is the original format of GetExpressionPath() producing code like
 // *(a_ptr).memberName, which is entirely fine, until you put this into
 // StackFrame::GetValueForVariableExpressionPath() which prefers to see
-// a_ptr->memberName. the eHonorPointers mode is meant to produce strings
-// in this latter format
+// a_ptr->memberName. The eHonorPointers mode is meant to produce strings
+// in this latter format.
 s.PutCString("*(");
+if (parent)
+  parent->GetExpressionPath(s, epformat);
+s.PutChar(')');
+return;
   }
 
-  V

[Lldb-commits] [lldb] f0a25fe - [lldb] Fix 'error: non-const lvalue...' caused by SWIG 4.1.0

2022-09-30 Thread via lldb-commits

Author: Jitka Plesnikova
Date: 2022-09-30T14:37:29+02:00
New Revision: f0a25fe0b746f56295d5c02116ba28d2f965c175

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

LOG: [lldb] Fix 'error: non-const lvalue...' caused by SWIG 4.1.0

Fix the failure caused by change in SwigValueWraper for C++11 and later
for improved move semantics in SWIG commit.

https://github.com/swig/swig/commit/d1055f4b3d51cb8060893f8036846ac743302dab

Added: 


Modified: 
lldb/bindings/python/python-typemaps.swig

Removed: 




diff  --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index 203be803d2ebd..11f68d59ae7be 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -435,7 +435,7 @@ template <> bool SetNumberFromPyObject(double 
&number, PyObject *obj) {
 
 %typemap(out) lldb::FileSP {
   $result = nullptr;
-  lldb::FileSP &sp = $1;
+  const lldb::FileSP &sp = $1;
   if (sp) {
 PythonFile pyfile = unwrapOrSetPythonException(PythonFile::FromFile(*sp));
 if (!pyfile.IsValid())



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


[Lldb-commits] [PATCH] D134962: [LLDB] Change pointer to ref in EmulateInstruction::ReadRegister methods

2022-09-30 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett created this revision.
Herald added subscribers: atanasyan, jrtc27.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

ReadRegister and ReadRegisterAsUnsigned are always passed valid pointers,
so the parameter should be a ref to make the intent clear.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134962

Files:
  lldb/include/lldb/Core/EmulateInstruction.h
  lldb/source/Core/EmulateInstruction.cpp
  lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
  lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
  lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp
  lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp

Index: lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp
===
--- lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp
+++ lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp
@@ -1160,7 +1160,7 @@
 uint8_t buffer[RegisterValue::kMaxRegisterByteSize];
 Status error;
 
-if (!ReadRegister(&(*reg_info_base), data_src))
+if (!ReadRegister(*reg_info_base, data_src))
   return false;
 
 if (data_src.GetAsMemoryData(&(*reg_info_src), buffer,
Index: lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp
===
--- lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp
+++ lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp
@@ -1266,7 +1266,7 @@
 uint8_t buffer[RegisterValue::kMaxRegisterByteSize];
 Status error;
 
-if (!ReadRegister(&(*reg_info_base), data_src))
+if (!ReadRegister(*reg_info_base, data_src))
   return false;
 
 if (data_src.GetAsMemoryData(&(*reg_info_src), buffer,
@@ -1526,7 +1526,7 @@
 uint8_t buffer[RegisterValue::kMaxRegisterByteSize];
 Status error;
 
-if (!ReadRegister(&(*reg_info_base), data_src))
+if (!ReadRegister(*reg_info_base, data_src))
   return false;
 
 if (data_src.GetAsMemoryData(®_info_src, buffer, reg_info_src.byte_size,
@@ -1608,7 +1608,7 @@
 uint8_t buffer[RegisterValue::kMaxRegisterByteSize];
 Status error;
 
-if (!ReadRegister(&(*reg_info_base), data_src))
+if (!ReadRegister(*reg_info_base, data_src))
   return false;
 
 if (data_src.GetAsMemoryData(&(*reg_info_src), buffer,
Index: lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
===
--- lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
+++ lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
@@ -824,7 +824,7 @@
 context_t2.SetRegisterToRegisterPlusOffset(*reg_info_Rt2, *reg_info_base,
size);
 
-if (!ReadRegister(&(*reg_info_Rt), data_Rt))
+if (!ReadRegister(*reg_info_Rt, data_Rt))
   return false;
 
 if (data_Rt.GetAsMemoryData(&(*reg_info_Rt), buffer, reg_info_Rt->byte_size,
@@ -834,7 +834,7 @@
 if (!WriteMemory(context_t, address + 0, buffer, reg_info_Rt->byte_size))
   return false;
 
-if (!ReadRegister(&(*reg_info_Rt2), data_Rt2))
+if (!ReadRegister(*reg_info_Rt2, data_Rt2))
   return false;
 
 if (data_Rt2.GetAsMemoryData(&(*reg_info_Rt2), buffer,
@@ -995,7 +995,7 @@
 context.SetRegisterToRegisterPlusOffset(*reg_info_Rt, *reg_info_base,
 postindex ? 0 : offset);
 
-if (!ReadRegister(&(*reg_info_Rt), data_Rt))
+if (!ReadRegister(*reg_info_Rt, data_Rt))
   return false;
 
 if (data_Rt.GetAsMemoryData(&(*reg_info_Rt), buffer, reg_info_Rt->byte_size,
Index: lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
===
--- lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
+++ lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
@@ -2620,7 +2620,7 @@
   GetRegisterInfo(eRegisterKindDWARF, start_reg + d + i);
   context.SetRegisterToRegisterPlusOffset(*dwarf_reg, *sp_reg, addr - sp);
   // uint64_t to accommodate 64-bit registers.
-  uint64_t reg_value = ReadRegisterUnsigned(&(*dwarf_reg), 0, &success);
+  uint64_t reg_value = ReadRegisterUnsigned(*dwarf_reg, 0, &success);
   if (!success)
 return false;
   if (!MemAWrite(context, addr, reg_value, reg_byte_size))
Index: lldb/source/Core/EmulateInstruction.cpp
===
--- lldb/source/Core/EmulateInstruction.cpp
+++ lldb/source/Core/EmulateInstruction.cpp
@@ -72,10 +72,10 @@
 
 EmulateInstruction::EmulateInstruction(const ArchSpec &arch) : m_arch(arch) {}
 
-bool EmulateInstruction::ReadRegister(const RegisterInfo *reg_info,
+bool EmulateInstruction::

[Lldb-commits] [PATCH] D134963: [LLDB] Switch to RegisterInfo& for EmulateInstruction::WriteRegister

2022-09-30 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett created this revision.
Herald added subscribers: atanasyan, jrtc27.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

WriteRegister and WriteRegisterUnsigned were never pased nullptr,
and only one of them appeared to handle it. Switch to ref to make
the intent clear.

Depends on D134962 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134963

Files:
  lldb/include/lldb/Core/EmulateInstruction.h
  lldb/source/Core/EmulateInstruction.cpp
  lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
  lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
  lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp
  lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp

Index: lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp
===
--- lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp
+++ lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp
@@ -1217,7 +1217,7 @@
 Context context;
 context.type = eContextRegisterLoad;
 
-return WriteRegister(context, &(*reg_info_src), data_src);
+return WriteRegister(context, *reg_info_src, data_src);
   }
 
   return false;
Index: lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp
===
--- lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp
+++ lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp
@@ -1321,7 +1321,7 @@
 context.type = eContextPopRegisterOffStack;
 context.SetAddress(address);
 
-return WriteRegister(context, &(*reg_info_src), data_src);
+return WriteRegister(context, *reg_info_src, data_src);
   }
 
   return false;
@@ -1661,7 +1661,7 @@
 context.type = eContextPopRegisterOffStack;
 context.SetAddress(base_address);
 
-return WriteRegister(context, &(*reg_info_src), data_src);
+return WriteRegister(context, *reg_info_src, data_src);
   }
 
   return false;
@@ -1723,7 +1723,7 @@
 context.type = eContextPopRegisterOffStack;
 context.SetAddress(base_address + (i * 4));
 
-if (!WriteRegister(context, &(*reg_info_dst), data_dst))
+if (!WriteRegister(context, *reg_info_dst, data_dst))
   return false;
   }
 
Index: lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
===
--- lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
+++ lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
@@ -876,7 +876,7 @@
 if (!vector && is_signed && !data_Rt.SignExtend(datasize))
   return false;
 
-if (!WriteRegister(context_t, &(*reg_info_Rt), data_Rt))
+if (!WriteRegister(context_t, *reg_info_Rt, data_Rt))
   return false;
 
 if (!rt_unknown) {
@@ -893,7 +893,7 @@
 if (!vector && is_signed && !data_Rt2.SignExtend(datasize))
   return false;
 
-if (!WriteRegister(context_t2, &(*reg_info_Rt2), data_Rt2))
+if (!WriteRegister(context_t2, *reg_info_Rt2, data_Rt2))
   return false;
   } break;
 
@@ -910,7 +910,7 @@
   context.type = eContextAdjustStackPointer;
 else
   context.type = eContextAdjustBaseRegister;
-WriteRegisterUnsigned(context, &(*reg_info_base), wb_address);
+WriteRegisterUnsigned(context, *reg_info_base, wb_address);
   }
   return true;
 }
@@ -1023,7 +1023,7 @@
   error) == 0)
   return false;
 
-if (!WriteRegister(context, &(*reg_info_Rt), data_Rt))
+if (!WriteRegister(context, *reg_info_Rt, data_Rt))
   return false;
 break;
   default:
@@ -1040,7 +1040,7 @@
   context.type = eContextAdjustBaseRegister;
 context.SetImmediateSigned(offset);
 
-if (!WriteRegisterUnsigned(context, &(*reg_info_base), address))
+if (!WriteRegisterUnsigned(context, *reg_info_base, address))
   return false;
   }
   return true;
Index: lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
===
--- lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
+++ lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
@@ -2713,7 +2713,7 @@
   data = MemARead(context, addr, reg_byte_size, 0, &success);
   if (!success)
 return false;
-  if (!WriteRegisterUnsigned(context, &(*dwarf_reg), data))
+  if (!WriteRegisterUnsigned(context, *dwarf_reg, data))
 return false;
   addr += reg_byte_size;
 }
Index: lldb/source/Core/EmulateInstruction.cpp
===
--- lldb/source/Core/EmulateInstruction.cpp
+++ lldb/source/Core/EmulateInstruction.cpp
@@ -112,10 +112,10 @@
 }
 
 bool EmulateInstruction::WriteRegister(const Context &

[Lldb-commits] [lldb] a314a36 - [lldb] Fix deprecation warning for using std::iterator

2022-09-30 Thread Nico Weber via lldb-commits

Author: Nico Weber
Date: 2022-09-30T10:19:08-04:00
New Revision: a314a36aaa1d3bb27a2102820ff636f7cd0940eb

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

LOG: [lldb] Fix deprecation warning for using std::iterator

std::iterator was deprecated in C++17.

No behavior change.

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

Added: 


Modified: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
index e1d0efa844c34..e8492079af88a 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -14,6 +14,8 @@
 #include "DWARFDeclContext.h"
 #include "DWARFUnit.h"
 
+#include "llvm/ADT/iterator.h"
+
 using namespace lldb_private;
 using namespace lldb_private::dwarf;
 
@@ -24,7 +26,9 @@ namespace {
 /// convenience, the starting die is included in the sequence as the first
 /// item.
 class ElaboratingDIEIterator
-: public std::iterator {
+: public llvm::iterator_facade_base<
+  ElaboratingDIEIterator, std::input_iterator_tag, DWARFDIE,
+  std::ptr
diff _t, DWARFDIE *, DWARFDIE *> {
 
   // The operating invariant is: top of m_worklist contains the "current" item
   // and the rest of the list are items yet to be visited. An empty worklist
@@ -62,11 +66,6 @@ class ElaboratingDIEIterator
 Next();
 return *this;
   }
-  ElaboratingDIEIterator operator++(int) {
-ElaboratingDIEIterator I = *this;
-Next();
-return I;
-  }
 
   friend bool operator==(const ElaboratingDIEIterator &a,
  const ElaboratingDIEIterator &b) {
@@ -74,10 +73,6 @@ class ElaboratingDIEIterator
   return a.m_worklist.empty() == b.m_worklist.empty();
 return a.m_worklist.back() == b.m_worklist.back();
   }
-  friend bool operator!=(const ElaboratingDIEIterator &a,
- const ElaboratingDIEIterator &b) {
-return !(a == b);
-  }
 };
 
 llvm::iterator_range



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


[Lldb-commits] [PATCH] D134844: [lldb] Fix deprecation warning for using std::iterator

2022-09-30 Thread Nico Weber via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa314a36aaa1d: [lldb] Fix deprecation warning for using 
std::iterator (authored by thakis).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134844

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp


Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -14,6 +14,8 @@
 #include "DWARFDeclContext.h"
 #include "DWARFUnit.h"
 
+#include "llvm/ADT/iterator.h"
+
 using namespace lldb_private;
 using namespace lldb_private::dwarf;
 
@@ -24,7 +26,9 @@
 /// convenience, the starting die is included in the sequence as the first
 /// item.
 class ElaboratingDIEIterator
-: public std::iterator {
+: public llvm::iterator_facade_base<
+  ElaboratingDIEIterator, std::input_iterator_tag, DWARFDIE,
+  std::ptrdiff_t, DWARFDIE *, DWARFDIE *> {
 
   // The operating invariant is: top of m_worklist contains the "current" item
   // and the rest of the list are items yet to be visited. An empty worklist
@@ -62,11 +66,6 @@
 Next();
 return *this;
   }
-  ElaboratingDIEIterator operator++(int) {
-ElaboratingDIEIterator I = *this;
-Next();
-return I;
-  }
 
   friend bool operator==(const ElaboratingDIEIterator &a,
  const ElaboratingDIEIterator &b) {
@@ -74,10 +73,6 @@
   return a.m_worklist.empty() == b.m_worklist.empty();
 return a.m_worklist.back() == b.m_worklist.back();
   }
-  friend bool operator!=(const ElaboratingDIEIterator &a,
- const ElaboratingDIEIterator &b) {
-return !(a == b);
-  }
 };
 
 llvm::iterator_range


Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -14,6 +14,8 @@
 #include "DWARFDeclContext.h"
 #include "DWARFUnit.h"
 
+#include "llvm/ADT/iterator.h"
+
 using namespace lldb_private;
 using namespace lldb_private::dwarf;
 
@@ -24,7 +26,9 @@
 /// convenience, the starting die is included in the sequence as the first
 /// item.
 class ElaboratingDIEIterator
-: public std::iterator {
+: public llvm::iterator_facade_base<
+  ElaboratingDIEIterator, std::input_iterator_tag, DWARFDIE,
+  std::ptrdiff_t, DWARFDIE *, DWARFDIE *> {
 
   // The operating invariant is: top of m_worklist contains the "current" item
   // and the rest of the list are items yet to be visited. An empty worklist
@@ -62,11 +66,6 @@
 Next();
 return *this;
   }
-  ElaboratingDIEIterator operator++(int) {
-ElaboratingDIEIterator I = *this;
-Next();
-return I;
-  }
 
   friend bool operator==(const ElaboratingDIEIterator &a,
  const ElaboratingDIEIterator &b) {
@@ -74,10 +73,6 @@
   return a.m_worklist.empty() == b.m_worklist.empty();
 return a.m_worklist.back() == b.m_worklist.back();
   }
-  friend bool operator!=(const ElaboratingDIEIterator &a,
- const ElaboratingDIEIterator &b) {
-return !(a == b);
-  }
 };
 
 llvm::iterator_range
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


lldb-commits@lists.llvm.org

2022-09-30 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett created this revision.
Herald added subscribers: atanasyan, jrtc27, kbarton, nemanjai, sdardis.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Most of the paths to this never passed nullptr intentionally. Those
that possibly could have were assuming it was not null elsehwere,
so would have crashed.

I've added asserts in those cases.

At least one case was relying on GetAsMemoryData to return an error
when it was given nullptr. So I've hoisted that error setting code
out into the caller.

Depends on D134963 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134965

Files:
  lldb/include/lldb/Utility/RegisterValue.h
  lldb/source/Host/common/NativeRegisterContext.cpp
  lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp
  lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp
  lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp
  lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp
  lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
  lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
  lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp
  lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp
  lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp
  lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp
  lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
  lldb/source/Plugins/Instruction/MIPS/EmulateInstructionMIPS.cpp
  lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp
  lldb/source/Target/RegisterContext.cpp
  lldb/source/Utility/RegisterValue.cpp

Index: lldb/source/Utility/RegisterValue.cpp
===
--- lldb/source/Utility/RegisterValue.cpp
+++ lldb/source/Utility/RegisterValue.cpp
@@ -35,21 +35,16 @@
   return data.SetData(GetBytes(), GetByteSize(), GetByteOrder()) > 0;
 }
 
-uint32_t RegisterValue::GetAsMemoryData(const RegisterInfo *reg_info, void *dst,
+uint32_t RegisterValue::GetAsMemoryData(const RegisterInfo ®_info, void *dst,
 uint32_t dst_len,
 lldb::ByteOrder dst_byte_order,
 Status &error) const {
-  if (reg_info == nullptr) {
-error.SetErrorString("invalid register info argument.");
-return 0;
-  }
-
   // ReadRegister should have already been called on this object prior to
   // calling this.
   if (GetType() == eTypeInvalid) {
 // No value has been read into this object...
 error.SetErrorStringWithFormat(
-"invalid register value type for register %s", reg_info->name);
+"invalid register value type for register %s", reg_info.name);
 return 0;
   }
 
@@ -58,7 +53,7 @@
 return 0;
   }
 
-  const uint32_t src_len = reg_info->byte_size;
+  const uint32_t src_len = reg_info.byte_size;
 
   // Extract the register data into a data extractor
   DataExtractor reg_data;
@@ -76,7 +71,7 @@
dst_byte_order); // dst byte order
   if (bytes_copied == 0)
 error.SetErrorStringWithFormat(
-"failed to copy data for register write of %s", reg_info->name);
+"failed to copy data for register write of %s", reg_info.name);
 
   return bytes_copied;
 }
Index: lldb/source/Target/RegisterContext.cpp
===
--- lldb/source/Target/RegisterContext.cpp
+++ lldb/source/Target/RegisterContext.cpp
@@ -368,37 +368,41 @@
 Status RegisterContext::WriteRegisterValueToMemory(
 const RegisterInfo *reg_info, lldb::addr_t dst_addr, uint32_t dst_len,
 const RegisterValue ®_value) {
-  uint8_t dst[RegisterValue::kMaxRegisterByteSize];
-
   Status error;
-
   ProcessSP process_sp(m_thread.GetProcess());
-  if (process_sp) {
 
-// TODO: we might need to add a parameter to this function in case the byte
-// order of the memory data doesn't match the process. For now we are
-// assuming they are the same.
+  if (!process_sp) {
+error.SetErrorString("invalid process");
+return error;
+  }
+
+  if (reg_info == nullptr) {
+error.SetErrorString("Invalid register info argument.");
+return error;
+  }
 
-const uint32_t bytes_copied = reg_value.GetAsMemoryData(
-reg_info, dst, dst_len, process_sp->GetByteOrder(), error);
-
-if (error.Success()) {
-  if (bytes_copied == 0) {
-error.SetErrorString("byte copy failed.");
-  } else {
-const uint32_t bytes_written =
-process_sp->WriteMemory(dst_addr, dst, bytes_copied, error);
-if (bytes_written != bytes_copied) {
-  if (error.Success()) {
-// This might happen if we read _some_ bytes but not all
-error.SetErrorStringWithFormat("only wrote %u of %u bytes",
-   bytes_written, bytes_copied

[Lldb-commits] [PATCH] D132734: [lldb] Fix member access in GetExpressionPath

2022-09-30 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added a comment.

Hi @tonkosi! I think your patch broke the macOS bot: 
https://green.lab.llvm.org/green/job/lldb-cmake/47258/console

  Failed Tests (5):
lldb-api :: commands/frame/diagnose/array/TestArray.py
lldb-api :: commands/frame/diagnose/bad-reference/TestBadReference.py
lldb-api :: 
commands/frame/diagnose/complicated-expression/TestComplicatedExpression.py
lldb-api :: 
commands/frame/diagnose/dereference-argument/TestDiagnoseDereferenceArgument.py
lldb-api :: 
commands/frame/diagnose/dereference-this/TestDiagnoseDereferenceThis.py

Let me know if you need help reproducing and fixing these issues, otherwise 
I'll have to revert your patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132734

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


[Lldb-commits] [lldb] fb30324 - Revert "[lldb] Fix member access in GetExpressionPath"

2022-09-30 Thread Andy Yankovsky via lldb-commits

Author: Andy Yankovsky
Date: 2022-09-30T15:26:09Z
New Revision: fb30324a5d535b911b41aa09b1429ca3a88c7fee

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

LOG: Revert "[lldb] Fix member access in GetExpressionPath"

This reverts commit 14642dc74

Broke the tests on macOS -- https://reviews.llvm.org/D132734#3827245

Added: 


Modified: 
lldb/source/Core/ValueObject.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Removed: 
lldb/test/API/python_api/expression_path/Makefile
lldb/test/API/python_api/expression_path/TestExpressionPath.py
lldb/test/API/python_api/expression_path/main.cpp



diff  --git a/lldb/source/Core/ValueObject.cpp 
b/lldb/source/Core/ValueObject.cpp
index ece787bdbe4c0..19d86bee40e1f 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -273,6 +273,8 @@ CompilerType ValueObject::MaybeCalculateCompleteType() {
   return compiler_type;
 }
 
+
+
 DataExtractor &ValueObject::GetDataExtractor() {
   UpdateValueIfNeeded(false);
   return m_data;
@@ -407,9 +409,8 @@ ValueObject::GetChildAtIndexPath(llvm::ArrayRef 
idxs,
   return root;
 }
 
-lldb::ValueObjectSP
-ValueObject::GetChildAtIndexPath(llvm::ArrayRef> idxs,
- size_t *index_of_error) {
+lldb::ValueObjectSP ValueObject::GetChildAtIndexPath(
+  llvm::ArrayRef> idxs, size_t *index_of_error) {
   if (idxs.size() == 0)
 return GetSP();
   ValueObjectSP root(GetSP());
@@ -1184,10 +1185,9 @@ bool ValueObject::DumpPrintableRepresentation(
   {
 Status error;
 lldb::WritableDataBufferSP buffer_sp;
-std::pair read_string =
-ReadPointedString(buffer_sp, error, 0,
-  (custom_format == eFormatVectorOfChar) ||
-  (custom_format == eFormatCharArray));
+std::pair read_string = ReadPointedString(
+buffer_sp, error, 0, (custom_format == eFormatVectorOfChar) ||
+ (custom_format == eFormatCharArray));
 lldb_private::formatters::StringPrinter::
 ReadBufferAndDumpToStreamOptions options(*this);
 options.SetData(DataExtractor(
@@ -1552,7 +1552,8 @@ bool ValueObject::GetDeclaration(Declaration &decl) {
   return false;
 }
 
-void ValueObject::AddSyntheticChild(ConstString key, ValueObject *valobj) {
+void ValueObject::AddSyntheticChild(ConstString key,
+ValueObject *valobj) {
   m_synthetic_children[key] = valobj;
 }
 
@@ -1923,96 +1924,64 @@ void ValueObject::GetExpressionPath(Stream &s,
 return;
   }
 
-  // Checks whether a value is dereference of a non-reference parent.
-  // This is used to determine whether to print a dereference operation (*).
-  auto is_deref_of_non_reference = [](ValueObject *value) {
-if (value == nullptr)
-  return false;
-ValueObject *value_parent = value->GetParent();
-if (value_parent) {
-  CompilerType parent_compiler_type = value_parent->GetCompilerType();
-  if (parent_compiler_type) {
-const uint32_t parent_type_info = parent_compiler_type.GetTypeInfo();
-if (parent_type_info & eTypeIsReference)
-  return false;
-  }
-}
-return value->IsDereferenceOfParent();
-  };
-
-  ValueObject *parent = GetParent();
+  const bool is_deref_of_parent = IsDereferenceOfParent();
 
-  if (is_deref_of_non_reference(this) &&
+  if (is_deref_of_parent &&
   epformat == eGetExpressionPathFormatDereferencePointers) {
 // this is the original format of GetExpressionPath() producing code like
 // *(a_ptr).memberName, which is entirely fine, until you put this into
 // StackFrame::GetValueForVariableExpressionPath() which prefers to see
-// a_ptr->memberName. The eHonorPointers mode is meant to produce strings
-// in this latter format.
+// a_ptr->memberName. the eHonorPointers mode is meant to produce strings
+// in this latter format
 s.PutCString("*(");
-if (parent)
-  parent->GetExpressionPath(s, epformat);
-s.PutChar(')');
-return;
   }
 
-  const bool is_deref_of_parent = IsDereferenceOfParent();
-  bool is_parent_deref_of_non_reference = false;
-  bool print_obj_access = false;
-  bool print_ptr_access = false;
-
-  if (!IsBaseClass() && !is_deref_of_parent) {
-ValueObject *non_base_class_parent = GetNonBaseClassParent();
-if (non_base_class_parent && !non_base_class_parent->GetName().IsEmpty()) {
-  CompilerType non_base_class_parent_compiler_type =
-  non_base_class_parent->GetCompilerType();
-  if (non_base_class_parent_compiler_type) {
-if (parent && parent->IsDereferenceOfParent() &&
-epformat == eGetExpressionPathFormatHonorPointers) {
-

[Lldb-commits] [PATCH] D132734: [lldb] Fix member access in GetExpressionPath

2022-09-30 Thread Andy Yankovsky via Phabricator via lldb-commits
werat reopened this revision.
werat added a comment.
This revision is now accepted and ready to land.

In D132734#3827245 , @mib wrote:

> Let me know if you need help reproducing and fixing these issues, otherwise 
> I'll have to revert your patch.

Sorry for the breaking the tests. We won't be able to look into this until next 
week, I've reverted the change for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132734

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


[Lldb-commits] [PATCH] D132734: [lldb] Fix member access in GetExpressionPath

2022-09-30 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added a comment.

In D132734#3827361 , @werat wrote:

> In D132734#3827245 , @mib wrote:
>
>> Let me know if you need help reproducing and fixing these issues, otherwise 
>> I'll have to revert your patch.
>
> Sorry for the breaking the tests. We won't be able to look into this until 
> next week, I've reverted the change for now.

Thank you @werat


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132734

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


[Lldb-commits] [PATCH] D134927: Make the sanitizer Notify callbacks asynchronous

2022-09-30 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.

LGTM




Comment at: 
lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp:302-309
   bool internal = true;
   bool hardware = false;
   Breakpoint *breakpoint =
   process_sp->GetTarget()
   .CreateBreakpoint(symbol_address, internal, hardware)
   .get();
   breakpoint->SetCallback(InstrumentationRuntimeASan::NotifyBreakpointHit, 
this,

Might be nice spell this out explicitly, like we do for the `internal` and 
`hardware` arguments to `CreateBreakpoint`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134927

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


[Lldb-commits] [PATCH] D134011: [lldb] Fix parentheses placement in GetExpressionPath

2022-09-30 Thread Dave Lee via Phabricator via lldb-commits
kastiglione abandoned this revision.
kastiglione added a subscriber: tonkosi.
kastiglione added a comment.

This was already being worked on in D132734  
by @tonkosi


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134011

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


[Lldb-commits] [PATCH] D134882: [lldb] Move breakpoint hit reset code to Target::CreateProcess

2022-09-30 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

The WillXXX have the virtue that they are at least self-documenting "Before you 
do XXX this will be called."  As it stands somebody working on Target could be 
forgiven for thinking Target::CreateProcess was just a convenience method, and 
redo it somewhere inline.  If we are going to require CreateProcess as the only 
way to do this, we should at least state that somewhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134882

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


[Lldb-commits] [PATCH] D134906: Have MemoryCache cache addresses that were unreadable, so duplicate read attempts can be suppressed

2022-09-30 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

LGTM

I didn't see a more appropriate datatype than SmallSet in the llvm collection.

I wondered about the same thing Dave asked - should the errors mention that 
this failed because we checked a negative cache - but I think that would be 
more confusing than helpful to lldb users.  If we wanted to track these 
decisions it would be more appropriate to log them, but I'm not sure even that 
is necessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134906

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


[Lldb-commits] [PATCH] D134991: [lldb] Add diagnostics

2022-09-30 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, clayborg, DavidSpickett, jingham, mib.
Herald added a project: All.
JDevlieghere requested review of this revision.

Around this time last year, I said on the mailing list [1] that I wanted to to 
transform the reproducers into something that resembles a sysdiagnose on Apple 
platforms: a collection of files containing a variety of information to help 
diagnose bugs or troubleshoot issues. This patch adds that framework. Based on 
lessons learned from the reproducers, I've intentionally tried to keep it small 
and simple. Different parts of LLDB can register callbacks (this is necessary 
for layering purposes) that will get called when the diagnostics should be 
generated.

For this patch, it's hooked up to Greg's statistics, but I have a bunch more 
things in the pipeline. With the minimal implementation in this patch, when the 
command line LLDB crashes, it dump the JSON statistics into a temp directory 
and ask the user to attach them to their bug report.

  LLDB diagnostics written to 
/var/folders/6v/6zkjmd45211_1vxrtbnl0dj0gn/T/diagnostics-ea34d4
  Please include the directory content when filing a bug report

[1] https://lists.llvm.org/pipermail/lldb-dev/2021-September/017045.html


https://reviews.llvm.org/D134991

Files:
  lldb/include/lldb/API/SBDebugger.h
  lldb/include/lldb/Target/Statistics.h
  lldb/include/lldb/Utility/Diagnostics.h
  lldb/source/API/SBDebugger.cpp
  lldb/source/Core/Debugger.cpp
  lldb/source/Initialization/SystemInitializerCommon.cpp
  lldb/source/Target/Statistics.cpp
  lldb/source/Utility/Diagnostics.cpp
  lldb/tools/driver/Driver.cpp

Index: lldb/tools/driver/Driver.cpp
===
--- lldb/tools/driver/Driver.cpp
+++ lldb/tools/driver/Driver.cpp
@@ -788,6 +788,10 @@
<< '\n';
 return 1;
   }
+
+  // Setup LLDB signal handlers once the debugger has been initialized.
+  SBDebugger::PrintDiagnosticsOnError();
+
   SBHostOS::ThreadCreated("");
 
   signal(SIGINT, sigint_handler);
Index: lldb/source/Utility/Diagnostics.cpp
===
--- lldb/source/Utility/Diagnostics.cpp
+++ lldb/source/Utility/Diagnostics.cpp
@@ -10,13 +10,13 @@
 #include "lldb/Utility/LLDBAssert.h"
 
 #include "llvm/Support/Error.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace lldb_private;
+using namespace lldb;
 using namespace llvm;
 
-static const constexpr size_t g_log_messages = 100;
-
 void Diagnostics::Initialize() {
   lldbassert(!InstanceImpl() && "Already initialized.");
   InstanceImpl().emplace();
@@ -34,19 +34,48 @@
 
 Diagnostics &Diagnostics::Instance() { return *InstanceImpl(); }
 
-Diagnostics::Diagnostics()
-: m_always_on_log_handler(
-  std::make_shared(g_log_messages)) {
-  uint32_t log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
-  Log::EnableLogChannel(m_always_on_log_handler, log_options, "lldb",
-{"always-on"}, llvm::outs());
+Diagnostics::Diagnostics() {}
+
+Diagnostics::~Diagnostics() {}
+
+void Diagnostics::AddCallback(Callback callback) {
+  std::lock_guard guard(m_callbacks_mutex);
+  m_callbacks.push_back(callback);
 }
 
-Diagnostics::~Diagnostics() {
-  Log::DisableLogChannel("lldb", {"always-on"}, llvm::nulls());
+void Diagnostics::RemoveCallback(Callback callback) {
+  std::lock_guard guard(m_callbacks_mutex);
+  m_callbacks.erase(
+  std::remove(m_callbacks.begin(), m_callbacks.end(), callback),
+  m_callbacks.end());
 }
 
-bool Diagnostics::Dump(llvm::raw_ostream &stream) {
-  m_always_on_log_handler->Dump(stream);
+bool Diagnostics::Dump(raw_ostream &stream) {
+  SmallString<128> diagnostics_dir;
+  std::error_code ec =
+  sys::fs::createUniqueDirectory("diagnostics", diagnostics_dir);
+  if (ec) {
+stream << "unable to create diagnostic dir: "
+   << toString(errorCodeToError(ec)) << '\n';
+return false;
+  }
+
+  Error error = Create(FileSpec(diagnostics_dir.str()));
+  if (error) {
+stream << toString(std::move(error)) << '\n';
+return false;
+  }
+
+  stream << "LLDB diagnostics written to " << diagnostics_dir << "\n";
+  stream << "Please include the directory content when filing a bug report\n";
+
   return true;
 }
+
+Error Diagnostics::Create(const FileSpec &dir) {
+  for (Callback c : m_callbacks) {
+if (Error err = c(dir))
+  return err;
+  }
+  return Error::success();
+}
Index: lldb/source/Target/Statistics.cpp
===
--- lldb/source/Target/Statistics.cpp
+++ lldb/source/Target/Statistics.cpp
@@ -14,6 +14,7 @@
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Target/UnixSignals.h"
+#include "lldb/Utility/Diagnostics.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -275,3 +276,29 @@
   };
   return std::mov

[Lldb-commits] [PATCH] D134991: [lldb] Add diagnostics

2022-09-30 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 464395.
JDevlieghere added a comment.

Fix baseline


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

https://reviews.llvm.org/D134991

Files:
  lldb/include/lldb/API/SBDebugger.h
  lldb/include/lldb/Target/Statistics.h
  lldb/include/lldb/Utility/Diagnostics.h
  lldb/include/lldb/Utility/Log.h
  lldb/source/API/SBDebugger.cpp
  lldb/source/Core/Debugger.cpp
  lldb/source/Initialization/SystemInitializerCommon.cpp
  lldb/source/Target/Statistics.cpp
  lldb/source/Utility/CMakeLists.txt
  lldb/source/Utility/Diagnostics.cpp
  lldb/tools/driver/Driver.cpp

Index: lldb/tools/driver/Driver.cpp
===
--- lldb/tools/driver/Driver.cpp
+++ lldb/tools/driver/Driver.cpp
@@ -788,6 +788,10 @@
<< '\n';
 return 1;
   }
+
+  // Setup LLDB signal handlers once the debugger has been initialized.
+  SBDebugger::PrintDiagnosticsOnError();
+
   SBHostOS::ThreadCreated("");
 
   signal(SIGINT, sigint_handler);
Index: lldb/source/Utility/Diagnostics.cpp
===
--- /dev/null
+++ lldb/source/Utility/Diagnostics.cpp
@@ -0,0 +1,81 @@
+//===-- Diagnostics.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 "lldb/Utility/Diagnostics.h"
+#include "lldb/Utility/LLDBAssert.h"
+
+#include "llvm/Support/Error.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace lldb_private;
+using namespace lldb;
+using namespace llvm;
+
+void Diagnostics::Initialize() {
+  lldbassert(!InstanceImpl() && "Already initialized.");
+  InstanceImpl().emplace();
+}
+
+void Diagnostics::Terminate() {
+  lldbassert(InstanceImpl() && "Already terminated.");
+  InstanceImpl().reset();
+}
+
+Optional &Diagnostics::InstanceImpl() {
+  static Optional g_diagnostics;
+  return g_diagnostics;
+}
+
+Diagnostics &Diagnostics::Instance() { return *InstanceImpl(); }
+
+Diagnostics::Diagnostics() {}
+
+Diagnostics::~Diagnostics() {}
+
+void Diagnostics::AddCallback(Callback callback) {
+  std::lock_guard guard(m_callbacks_mutex);
+  m_callbacks.push_back(callback);
+}
+
+void Diagnostics::RemoveCallback(Callback callback) {
+  std::lock_guard guard(m_callbacks_mutex);
+  m_callbacks.erase(
+  std::remove(m_callbacks.begin(), m_callbacks.end(), callback),
+  m_callbacks.end());
+}
+
+bool Diagnostics::Dump(raw_ostream &stream) {
+  SmallString<128> diagnostics_dir;
+  std::error_code ec =
+  sys::fs::createUniqueDirectory("diagnostics", diagnostics_dir);
+  if (ec) {
+stream << "unable to create diagnostic dir: "
+   << toString(errorCodeToError(ec)) << '\n';
+return false;
+  }
+
+  Error error = Create(FileSpec(diagnostics_dir.str()));
+  if (error) {
+stream << toString(std::move(error)) << '\n';
+return false;
+  }
+
+  stream << "LLDB diagnostics written to " << diagnostics_dir << "\n";
+  stream << "Please include the directory content when filing a bug report\n";
+
+  return true;
+}
+
+Error Diagnostics::Create(const FileSpec &dir) {
+  for (Callback c : m_callbacks) {
+if (Error err = c(dir))
+  return err;
+  }
+  return Error::success();
+}
Index: lldb/source/Utility/CMakeLists.txt
===
--- lldb/source/Utility/CMakeLists.txt
+++ lldb/source/Utility/CMakeLists.txt
@@ -35,6 +35,7 @@
   DataBufferLLVM.cpp
   DataEncoder.cpp
   DataExtractor.cpp
+  Diagnostics.cpp
   Environment.cpp
   Event.cpp
   FileSpec.cpp
Index: lldb/source/Target/Statistics.cpp
===
--- lldb/source/Target/Statistics.cpp
+++ lldb/source/Target/Statistics.cpp
@@ -14,6 +14,7 @@
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Target/UnixSignals.h"
+#include "lldb/Utility/Diagnostics.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -275,3 +276,29 @@
   };
   return std::move(global_stats);
 }
+
+void Stats::Initialize() { Diagnostics::Instance().AddCallback(Stats::Dump); }
+
+void Stats::Terminate() { Diagnostics::Instance().RemoveCallback(Stats::Dump); }
+
+llvm::Error Stats::Dump(const FileSpec &dir) {
+  for (size_t debugger_idx = 0; debugger_idx < Debugger::GetNumDebuggers();
+   debugger_idx++) {
+DebuggerSP debugger_sp(Debugger::GetDebuggerAtIndex(debugger_idx));
+if (!debugger_sp)
+  continue;
+
+std::string filename =
+(Twine("debugger-") + Twine(debugger_idx) + Twine("-stats.json")).str();
+FileSpec stat_file = dir.CopyByAppendingPathComponent(filename);
+
+std::error_code ec;
+

[Lldb-commits] [PATCH] D134991: [lldb] Add diagnostics

2022-09-30 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 464396.

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

https://reviews.llvm.org/D134991

Files:
  lldb/include/lldb/API/SBDebugger.h
  lldb/include/lldb/Target/Statistics.h
  lldb/include/lldb/Utility/Diagnostics.h
  lldb/include/lldb/Utility/Log.h
  lldb/source/API/SBDebugger.cpp
  lldb/source/Core/Debugger.cpp
  lldb/source/Initialization/SystemInitializerCommon.cpp
  lldb/source/Target/Statistics.cpp
  lldb/source/Utility/CMakeLists.txt
  lldb/source/Utility/Diagnostics.cpp
  lldb/tools/driver/Driver.cpp

Index: lldb/tools/driver/Driver.cpp
===
--- lldb/tools/driver/Driver.cpp
+++ lldb/tools/driver/Driver.cpp
@@ -788,6 +788,10 @@
<< '\n';
 return 1;
   }
+
+  // Setup LLDB signal handlers once the debugger has been initialized.
+  SBDebugger::PrintDiagnosticsOnError();
+
   SBHostOS::ThreadCreated("");
 
   signal(SIGINT, sigint_handler);
Index: lldb/source/Utility/Diagnostics.cpp
===
--- /dev/null
+++ lldb/source/Utility/Diagnostics.cpp
@@ -0,0 +1,81 @@
+//===-- Diagnostics.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 "lldb/Utility/Diagnostics.h"
+#include "lldb/Utility/LLDBAssert.h"
+
+#include "llvm/Support/Error.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace lldb_private;
+using namespace lldb;
+using namespace llvm;
+
+void Diagnostics::Initialize() {
+  lldbassert(!InstanceImpl() && "Already initialized.");
+  InstanceImpl().emplace();
+}
+
+void Diagnostics::Terminate() {
+  lldbassert(InstanceImpl() && "Already terminated.");
+  InstanceImpl().reset();
+}
+
+Optional &Diagnostics::InstanceImpl() {
+  static Optional g_diagnostics;
+  return g_diagnostics;
+}
+
+Diagnostics &Diagnostics::Instance() { return *InstanceImpl(); }
+
+Diagnostics::Diagnostics() {}
+
+Diagnostics::~Diagnostics() {}
+
+void Diagnostics::AddCallback(Callback callback) {
+  std::lock_guard guard(m_callbacks_mutex);
+  m_callbacks.push_back(callback);
+}
+
+void Diagnostics::RemoveCallback(Callback callback) {
+  std::lock_guard guard(m_callbacks_mutex);
+  m_callbacks.erase(
+  std::remove(m_callbacks.begin(), m_callbacks.end(), callback),
+  m_callbacks.end());
+}
+
+bool Diagnostics::Dump(raw_ostream &stream) {
+  SmallString<128> diagnostics_dir;
+  std::error_code ec =
+  sys::fs::createUniqueDirectory("diagnostics", diagnostics_dir);
+  if (ec) {
+stream << "unable to create diagnostic dir: "
+   << toString(errorCodeToError(ec)) << '\n';
+return false;
+  }
+
+  Error error = Create(FileSpec(diagnostics_dir.str()));
+  if (error) {
+stream << toString(std::move(error)) << '\n';
+return false;
+  }
+
+  stream << "LLDB diagnostics written to " << diagnostics_dir << "\n";
+  stream << "Please include the directory content when filing a bug report\n";
+
+  return true;
+}
+
+Error Diagnostics::Create(const FileSpec &dir) {
+  for (Callback c : m_callbacks) {
+if (Error err = c(dir))
+  return err;
+  }
+  return Error::success();
+}
Index: lldb/source/Utility/CMakeLists.txt
===
--- lldb/source/Utility/CMakeLists.txt
+++ lldb/source/Utility/CMakeLists.txt
@@ -35,6 +35,7 @@
   DataBufferLLVM.cpp
   DataEncoder.cpp
   DataExtractor.cpp
+  Diagnostics.cpp
   Environment.cpp
   Event.cpp
   FileSpec.cpp
Index: lldb/source/Target/Statistics.cpp
===
--- lldb/source/Target/Statistics.cpp
+++ lldb/source/Target/Statistics.cpp
@@ -14,6 +14,7 @@
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Target/UnixSignals.h"
+#include "lldb/Utility/Diagnostics.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -275,3 +276,29 @@
   };
   return std::move(global_stats);
 }
+
+void Stats::Initialize() { Diagnostics::Instance().AddCallback(Stats::Dump); }
+
+void Stats::Terminate() { Diagnostics::Instance().RemoveCallback(Stats::Dump); }
+
+llvm::Error Stats::Dump(const FileSpec &dir) {
+  for (size_t debugger_idx = 0; debugger_idx < Debugger::GetNumDebuggers();
+   debugger_idx++) {
+DebuggerSP debugger_sp(Debugger::GetDebuggerAtIndex(debugger_idx));
+if (!debugger_sp)
+  continue;
+
+std::string filename =
+(Twine("debugger-") + Twine(debugger_idx) + Twine("-stats.json")).str();
+FileSpec stat_file = dir.CopyByAppendingPathComponent(filename);
+
+std::error_code ec;
+raw_fd_ostream stats_stream(stat_file.Get

[Lldb-commits] [PATCH] D134927: Make the sanitizer Notify callbacks asynchronous

2022-09-30 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

I had to fix one other thing.  I had arbitrarily made the decision that if an 
internal breakpoint was hit while running an expression we should stop before 
running its callbacks.  At the time we only had internal breakpoints with sync 
callbacks (again mostly dynamic loader plugins) so there wasn't really an 
example to reason on.  But with these sanitizer ones now async, we can hit this 
issue.  The problem with hitting a breakpoint while running an expression is 
that those breakpoint commands could run the target in arbitrary ways, which 
could hit this breakpoint, and then call other commands, etc, and right now the 
Command Interpreter can only be invoked recursively with some care, so I outlaw 
that.  But I think it's better for internal breakpoints to let their callbacks 
run, and leave it up to the callback how it wants to do its business.  In the 
case of the sanitizers, they just don't run their reports if there's a 
sanitizer issue while calling a function, in other cases we're just reading 
memory, etc.

So I added that change to StopInfo, and updated the patch.  I'll let it sit for 
a bit in case anyone wants to have a look.  I also made variables for the 
"false" I was passing to SetCallback as Jonas suggested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134927

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


[Lldb-commits] [PATCH] D134927: Make the sanitizer Notify callbacks asynchronous

2022-09-30 Thread Jim Ingham via Phabricator via lldb-commits
jingham updated this revision to Diff 464442.
jingham added a comment.

Handled hitting the sanitizer breakpoint while calling a function in 
StopInfoBreakpoint.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134927

Files:
  lldb/include/lldb/Breakpoint/Breakpoint.h
  lldb/source/Plugins/InstrumentationRuntime/ASan/InstrumentationRuntimeASan.cpp
  
lldb/source/Plugins/InstrumentationRuntime/MainThreadChecker/InstrumentationRuntimeMainThreadChecker.cpp
  lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
  
lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp
  lldb/source/Target/StopInfo.cpp
  lldb/test/API/functionalities/ubsan/basic/TestUbsanBasic.py
  lldb/test/API/functionalities/ubsan/basic/main.c

Index: lldb/test/API/functionalities/ubsan/basic/main.c
===
--- lldb/test/API/functionalities/ubsan/basic/main.c
+++ lldb/test/API/functionalities/ubsan/basic/main.c
@@ -1,4 +1,16 @@
 int main() {
   int data[4];
-  return *(int *)(((char *)&data[0]) + 2); // align line
+  int result = *(int *)(((char *)&data[0]) + 2); // align line
+
+  int *p = data + 5;  // Index 5 out of bounds for type 'int [4]'
+  *p = data + 5;
+  *p = data + 5;
+  *p = data + 5;
+  *p = data + 5;
+  *p = data + 5;
+  *p = data + 5;
+  *p = data + 5;
+  *p = data + 5;
+
+  return 0;
 }
Index: lldb/test/API/functionalities/ubsan/basic/TestUbsanBasic.py
===
--- lldb/test/API/functionalities/ubsan/basic/TestUbsanBasic.py
+++ lldb/test/API/functionalities/ubsan/basic/TestUbsanBasic.py
@@ -86,4 +86,9 @@
 self.assertEqual(os.path.basename(data["filename"]), "main.c")
 self.assertEqual(data["line"], self.line_align)
 
-self.runCmd("continue")
+for count in range(0,8):
+process.Continue()
+stop_reason = thread.GetStopReason()
+self.assertEqual(stop_reason, lldb.eStopReasonInstrumentation,
+ "Round {0} wasn't instrumentation".format(count))
+
Index: lldb/source/Target/StopInfo.cpp
===
--- lldb/source/Target/StopInfo.cpp
+++ lldb/source/Target/StopInfo.cpp
@@ -362,29 +362,21 @@
" not running commands to avoid recursion.");
 bool ignoring_breakpoints =
 process->GetIgnoreBreakpointsInExpressions();
-if (ignoring_breakpoints) {
-  m_should_stop = false;
-  // Internal breakpoints will always stop.
-  for (size_t j = 0; j < num_owners; j++) {
-lldb::BreakpointLocationSP bp_loc_sp =
-bp_site_sp->GetOwnerAtIndex(j);
-if (bp_loc_sp->GetBreakpoint().IsInternal()) {
-  m_should_stop = true;
-  break;
-}
-  }
-} else {
-  m_should_stop = true;
+// Internal breakpoints should be allowed to do their job, we
+// can make sure they don't do anything that would cause recursive
+// command execution:
+if (!m_was_all_internal) {
+  m_should_stop = !ignoring_breakpoints;
+  LLDB_LOGF(log,
+"StopInfoBreakpoint::PerformAction - in expression, "
+"continuing: %s.",
+m_should_stop ? "true" : "false");
+  Debugger::ReportWarning(
+  "hit breakpoint while running function, skipping commands "
+  "and conditions to prevent recursion",
+process->GetTarget().GetDebugger().GetID());
+  return;
 }
-LLDB_LOGF(log,
-  "StopInfoBreakpoint::PerformAction - in expression, "
-  "continuing: %s.",
-  m_should_stop ? "true" : "false");
-Debugger::ReportWarning(
-"hit breakpoint while running function, skipping commands and "
-"conditions to prevent recursion",
-process->GetTarget().GetDebugger().GetID());
-return;
   }
 
   StoppointCallbackContext context(event_ptr, exe_ctx, false);
Index: lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp
===
--- lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp
+++ lldb/source/Plugins/InstrumentationRuntime/UBSan/InstrumentationRuntimeUBSan.cpp
@@ -275,8 +275,9 @@
   .CreateBreakpoint(symbol_address, /*internal=*/true,
 /*hardware=*/false)
   .get();
+  const bool sync = false;
   breakpoint->SetCallback(InstrumentationRuntimeUBSan::

[Lldb-commits] [PATCH] D134922: [lldb] Remove scoped timer from high firing and fast running SymbolFileDWARF::FindFunctions

2022-09-30 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.

Probably because it just queries `m_index`.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134922

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


[Lldb-commits] [PATCH] D134920: [lldb] Remove scoped timer from high firing and fast running ExtractUnitDIENoDwoIfNeeded

2022-09-30 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.

Yeah, it does not look like there would be a lot of time spent in here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134920

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