[Lldb-commits] [PATCH] D123092: [LLDB][NativePDB] Fix inline line info in line table

2022-04-05 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

As unusual, I don't understand pdbs, but the resulting line table seems 
reasonable.

I don't think we can assert this level of detail in a compilation-based test 
though. Could you put these checks into the non-"live" version of the test?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123092

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


[Lldb-commits] [PATCH] D123073: [lldb] Change CreateMemoryInstance to take a WritableDataBuffer

2022-04-05 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added a comment.
This revision is now accepted and ready to land.

cool. thanks.


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

https://reviews.llvm.org/D123073

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


[Lldb-commits] [PATCH] D122991: [lldb][intelpt] Remove `IntelPTInstruction` and move methods to `DecodedThread`

2022-04-05 Thread Alisamar Husain via Phabricator via lldb-commits
zrthxn updated this revision to Diff 420401.
zrthxn marked 12 inline comments as done.
zrthxn added a comment.

Address all comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122991

Files:
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
  lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/test/API/commands/trace/TestTraceDumpInfo.py
  lldb/test/API/commands/trace/TestTraceLoad.py

Index: lldb/test/API/commands/trace/TestTraceLoad.py
===
--- lldb/test/API/commands/trace/TestTraceLoad.py
+++ lldb/test/API/commands/trace/TestTraceLoad.py
@@ -38,8 +38,10 @@
 thread #1: tid = 3842849
   Raw trace size: 4 KiB
   Total number of instructions: 21
-  Total approximate memory usage: 0.98 KiB
-  Average memory usage per instruction: 48.00 bytes'''])
+  Total approximate memory usage: 0.27 KiB
+  Average memory usage per instruction: 13.00 bytes
+
+  Number of TSC decoding errors: 0'''])
 
 def testLoadInvalidTraces(self):
 src_dir = self.getSourceDir()
Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py
===
--- lldb/test/API/commands/trace/TestTraceDumpInfo.py
+++ lldb/test/API/commands/trace/TestTraceDumpInfo.py
@@ -40,7 +40,7 @@
 thread #1: tid = 3842849
   Raw trace size: 4 KiB
   Total number of instructions: 21
-  Total approximate memory usage: 0.98 KiB
-  Average memory usage per instruction: 48.00 bytes
+  Total approximate memory usage: 0.27 KiB
+  Average memory usage per instruction: 13.00 bytes
 
   Number of TSC decoding errors: 0'''])
Index: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
===
--- lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
+++ lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
@@ -112,7 +112,7 @@
   }
   s << "\n";
   DecodedThreadSP decoded_trace_sp = Decode(thread);
-  size_t insn_len = decoded_trace_sp->GetInstructions().size();
+  size_t insn_len = decoded_trace_sp->GetInstructionsCount();
   size_t mem_used = decoded_trace_sp->CalculateApproximateMemoryUsage();
 
   s.Format("  Raw trace size: {0} KiB\n", *raw_size / 1024);
Index: lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
===
--- lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
+++ lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
@@ -20,14 +20,14 @@
 TraceCursorIntelPT::TraceCursorIntelPT(ThreadSP thread_sp,
DecodedThreadSP decoded_thread_sp)
 : TraceCursor(thread_sp), m_decoded_thread_sp(decoded_thread_sp) {
-  assert(!m_decoded_thread_sp->GetInstructions().empty() &&
+  assert(m_decoded_thread_sp->GetInstructionsCount() > 0 &&
  "a trace should have at least one instruction or error");
-  m_pos = m_decoded_thread_sp->GetInstructions().size() - 1;
+  m_pos = m_decoded_thread_sp->GetInstructionsCount() - 1;
   m_tsc_range = m_decoded_thread_sp->CalculateTscRange(m_pos);
 }
 
 size_t TraceCursorIntelPT::GetInternalInstructionSize() {
-  return m_decoded_thread_sp->GetInstructions().size();
+  return m_decoded_thread_sp->GetInstructionsCount();
 }
 
 bool TraceCursorIntelPT::Next() {
@@ -78,8 +78,8 @@
   return std::abs(dist);
 }
   };
-  
-	int64_t dist = FindDistanceAndSetPos();
+
+  int64_t dist = FindDistanceAndSetPos();
   m_tsc_range = m_decoded_thread_sp->CalculateTscRange(m_pos);
   return dist;
 }
@@ -93,7 +93,7 @@
 }
 
 lldb::addr_t TraceCursorIntelPT::GetLoadAddress() {
-  return m_decoded_thread_sp->GetInstructions()[m_pos].GetLoadAddress();
+  return m_decoded_thread_sp->GetInstructionLoadAddress(m_pos);
 }
 
 Optional
@@ -109,10 +109,5 @@
 
 TraceInstructionControlFlowType
 TraceCursorIntelPT::GetInstructionControlFlowType() {
-  lldb::addr_t next_load_address =
-  m_pos + 1 < GetInternalInstructionSize()
-  ? m_decoded_thread_sp->GetInstructions()[m_pos + 1].GetLoadAddress()
-  : LLDB_INVALID_ADDRESS;
-  return m_decoded_thread_sp->GetInstructions()[m_pos].GetControlFlowType(
-  next_load_address);
+  return m_decoded_thread_sp->GetInstructionControlFlowType(m_pos);
 }
Index: lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
===
--- lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
+++ lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
@@ -51,61 +51,6 @@
   lldb::addr_t m_address;
 };
 
-/// \class IntelPTInstruction
-/// An instruction obtained from decoding a trace. It is either an actual
-/// instruction or an error indicating a gap in the trace.
-///
-/// Gaps in the trace can come in a few flavors:
-///   - tracing gaps (e.g. tracing wa

[Lldb-commits] [PATCH] D122856: [lldb] Refactor DataBuffer so we can map files as read-only

2022-04-05 Thread Pavel Labath via Phabricator via lldb-commits
labath added inline comments.



Comment at: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:361
   // Update the data to contain the entire file if it doesn't already
   if (data_sp->GetByteSize() < length) {
+data_sp = MapFileDataWritable(*file, length, file_offset);

JDevlieghere wrote:
> labath wrote:
> > I guess this should be done unconditionally now.
> No, I tried doing that actually and it broke a bunch of unit tests. I can 
> take a look at it later this week if you think this is important. 
Right, I think I know what's going on. The unit tests use a (relatively new) 
object file feature where you can construct an ObjectFile instance without a 
backing file by providing all of its data upfront.

I think it is important to have a story for all entry points into the ELF code, 
since that is what makes the cast in `ApplyRelocations` sound. There are 
several ways to handle this. In my order of preference, they would be:
- In the file backed case, the initial 512-byte buffer will be heap-based 
(hence, effectively writable). If it is acceptable (and statically type-safe) 
to make the the buffer for the buffer-backed case writable, then we could 
change the `CreateInstance` prototype to take a `WritableDataBuffer`. Only the 
full mappings done by individual subclasses would be read-only. The only 
(non-test) use case for this feature is for some mach-o shenanigans so you'd be 
best qualified to determine if this would work.
- If we can be sure that the buffer-backed buffer is always writable, but we 
cannot enforce that in the type system, then we could add a comment documenting 
that the buffers dynamic type must be writable in one does not provide a 
backing file.
- Failing all that, we could have ObjectFileELF make a heap copy of the 
incoming data buffer in the buffer-backed case. Since there's no production use 
case for buffer-backed ELF files I think that should be fine. We could also 
have the ELF class refuse to open such files, but that would mean changing the 
unit tests back to using temporary files, which would make me sad.


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

https://reviews.llvm.org/D122856

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


[Lldb-commits] [lldb] 331150a - [lldb] Move host platform implementations into the base class

2022-04-05 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-04-05T11:22:37+02:00
New Revision: 331150a47dd5b26758293d73c5df3aa1b61ecad9

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

LOG: [lldb] Move host platform implementations into the base class

About half of our host platform code was implemented in the Platform
class, while the rest was it RemoteAwarePlatform. Most of the time, this
did not matter, as nearly all our platforms are also
RemoteAwarePlatforms. It makes a difference for PlatformQemu, which
descends directly from the base class (as it is local-only).

This patch moves all host code paths into the base class, and marks
PlatformQemu as a "host" platform so it can make use of them (it sounds
slightly strange, but that is consistent with what the apple simulator
platforms are doing). Not all of the host implementations make sense for
this platform, but it can always override those that don't.

I add some basic tests using the platform file apis to exercise this
functionality.

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

Added: 
lldb/test/API/qemu/TestQemuAPI.py

Modified: 
lldb/include/lldb/Target/Platform.h
lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.h
lldb/source/Target/Platform.cpp
lldb/source/Target/RemoteAwarePlatform.cpp

Removed: 




diff  --git a/lldb/include/lldb/Target/Platform.h 
b/lldb/include/lldb/Target/Platform.h
index eee7e3116beea..6501675cafbfe 100644
--- a/lldb/include/lldb/Target/Platform.h
+++ b/lldb/include/lldb/Target/Platform.h
@@ -278,7 +278,7 @@ class Platform : public PluginInterface {
 
   virtual bool SetRemoteWorkingDirectory(const FileSpec &working_dir);
 
-  virtual UserIDResolver &GetUserIDResolver() = 0;
+  virtual UserIDResolver &GetUserIDResolver();
 
   /// Locate a file for a platform.
   ///
@@ -516,34 +516,20 @@ class Platform : public PluginInterface {
 
   virtual lldb::user_id_t OpenFile(const FileSpec &file_spec,
File::OpenOptions flags, uint32_t mode,
-   Status &error) {
-return UINT64_MAX;
-  }
+   Status &error);
 
-  virtual bool CloseFile(lldb::user_id_t fd, Status &error) { return false; }
+  virtual bool CloseFile(lldb::user_id_t fd, Status &error);
 
-  virtual lldb::user_id_t GetFileSize(const FileSpec &file_spec) {
-return UINT64_MAX;
-  }
+  virtual lldb::user_id_t GetFileSize(const FileSpec &file_spec);
 
   virtual void AutoCompleteDiskFileOrDirectory(CompletionRequest &request,
bool only_dir) {}
 
   virtual uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst,
-uint64_t dst_len, Status &error) {
-error.SetErrorStringWithFormatv(
-"Platform::ReadFile() is not supported in the {0} platform",
-GetPluginName());
-return -1;
-  }
+uint64_t dst_len, Status &error);
 
   virtual uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset,
- const void *src, uint64_t src_len, Status &error) 
{
-error.SetErrorStringWithFormatv(
-"Platform::WriteFile() is not supported in the {0} platform",
-GetPluginName());
-return -1;
-  }
+ const void *src, uint64_t src_len, Status &error);
 
   virtual Status GetFile(const FileSpec &source, const FileSpec &destination);
 

diff  --git a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.h 
b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.h
index 509b2558c8f90..0dd0e2f6f2b9b 100644
--- a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.h
+++ b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.h
@@ -60,7 +60,7 @@ class PlatformQemuUser : public Platform {
   static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
   static void DebuggerInitialize(Debugger &debugger);
 
-  PlatformQemuUser() : Platform(/*is_host=*/false) {}
+  PlatformQemuUser() : Platform(/*is_host=*/true) {}
 };
 
 } // namespace lldb_private

diff  --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index 74e3e38953608..cd71dae41cd4e 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -19,6 +19,7 @@
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Core/StreamFile.h"
+#include "lldb/Host/FileCache.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Host/HostInfo.h"
@@ -790,6 +791,56 @@ Status Platform::SetFilePermissions(const FileSpec 
&file_spec,
   }
 }
 
+user_id_t Platform::OpenFile(const FileSpec &file_spec,
+   File::OpenOptions flags, uint32_t mode,
+

[Lldb-commits] [lldb] 4384c96 - [lldb/linux] Handle main thread exits

2022-04-05 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-04-05T11:22:37+02:00
New Revision: 4384c96fe7eb5ceb5f2c1ece4a73c22a18bac19f

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

LOG: [lldb/linux] Handle main thread exits

This patch handles the situation where the main thread exits (through
the SYS_exit syscall). In this case, the process as a whole continues
running until all of the other threads exit, or one of them issues an
exit_group syscall.

The patch consists of two changes:
- a moderate redesign of the handling of thread exit (WIFEXITED) events.
  Previously, we were removing (forgetting) a thread once we received
  the WIFEXITED (or WIFSIGNALED) event. This was problematic for the
  main thread, since the main thread WIFEXITED event (which is better thought
  of as a process-wide event) gets reported only after the entire process
  exits. This resulted in deadlocks, where we were waiting for the
  process to stop (because we still considered the main thread "live").

  This patch changes the logic such that the main thread is removed as
  soon as its PTRACE_EVENT_EXIT (the pre-exit) event is received. At
  this point we can consider the thread gone (for most purposes). As a
  corrolary, I needed to add special logic to catch process-wide exit
  events in the cases where we don't have the main thread around.

- The second part of the patch is the removal of the assumptions that
  the main thread is always available. This generally meant replacing
  the uses of GetThreadByID(process_id) with GetCurrentThread() in
  various process-wide operations (such as memory reads).

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

Added: 
lldb/test/API/functionalities/thread/main_thread_exit/Makefile
lldb/test/API/functionalities/thread/main_thread_exit/TestMainThreadExit.py
lldb/test/API/functionalities/thread/main_thread_exit/main.cpp

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

Removed: 




diff  --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp 
b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index 4bc5711453939..3d8715050ae0a 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -447,13 +447,7 @@ void NativeProcessLinux::MonitorCallback(NativeThreadLinux 
&thread,
 // This is a thread that exited.  Ensure we're not tracking it anymore.
 StopTrackingThread(thread);
 
-if (is_main_thread) {
-  // The main thread exited.  We're done monitoring.  Report to delegate.
-  SetExitStatus(status, true);
-
-  // Notify delegate that our process has exited.
-  SetState(StateType::eStateExited, true);
-}
+assert(!is_main_thread && "Main thread exits handled elsewhere");
 return;
   }
 
@@ -611,6 +605,13 @@ void NativeProcessLinux::MonitorSIGTRAP(const siginfo_t 
&info,
 }
 ResumeThread(thread, state, LLDB_INVALID_SIGNAL_NUMBER);
 
+if (is_main_thread) {
+  // Main thread report the read (WIFEXITED) event only after all threads 
in
+  // the process exit, so we need to stop tracking it here instead of in
+  // MonitorCallback
+  StopTrackingThread(thread);
+}
+
 break;
   }
 
@@ -1177,11 +1178,11 @@ Status NativeProcessLinux::PopulateMemoryRegionCache() {
 
   // Linux kernel since 2.6.14 has /proc/{pid}/smaps
   // if CONFIG_PROC_PAGE_MONITOR is enabled
-  auto BufferOrError = getProcFile(GetID(), "smaps");
+  auto BufferOrError = getProcFile(GetID(), GetCurrentThreadID(), "smaps");
   if (BufferOrError)
 ParseLinuxSMapRegions(BufferOrError.get()->getBuffer(), callback);
   else {
-BufferOrError = getProcFile(GetID(), "maps");
+BufferOrError = getProcFile(GetID(), GetCurrentThreadID(), "maps");
 if (!BufferOrError) {
   m_supports_mem_region = LazyBool::eLazyBoolNo;
   return BufferOrError.getError();
@@ -1232,7 +1233,7 @@ NativeProcessLinux::Syscall(llvm::ArrayRef 
args) {
 
   addr_t exe_addr = region_it->first.GetRange().GetRangeBase();
 
-  NativeThreadLinux &thread = *GetThreadByID(GetID());
+  NativeThreadLinux &thread = *GetCurrentThread();
   assert(thread.GetState() == eStateStopped);
   NativeRegisterContextLinux ®_ctx = thread.GetRegisterContext();
 
@@ -1384,8 +1385,9 @@ Status NativeProcessLinux::ReadMemoryTags(int32_t type, 
lldb::addr_t addr,
 tags_iovec.iov_len = num_tags;
 
 Status error = NativeProcessLinux::PtraceWrapper(
-details->ptrace_read_req, GetID(), reinterpret_cast(read_addr),
-static_cast(&tags_iovec), 0, nullptr);
+details->ptrace_read_req, GetCurrentThreadID(),
+reinterpret_cast(read_addr), static_cast(&tags_iovec),
+0, nullptr);
 
 if (error.Fail()) {
   // Discard partial read

[Lldb-commits] [lldb] e67cee0 - [lldb] Avoid duplicate vdso modules when opening core files

2022-04-05 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-04-05T11:22:37+02:00
New Revision: e67cee09499cbf386334115a627cd4fbe19cb01c

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

LOG: [lldb] Avoid duplicate vdso modules when opening core files

When opening core files (and also in some other situations) we could end
up with two vdso modules. This could happen because the vdso module is
very special, and over the years, we have accumulated various ways to
load it.

In D10800, we added one mechanism for loading it, which took the form of
a generic load-from-memory capability. Unfortunately loading an elf file
from memory is not possible (because the loader never loads the entire
file), and our attempts to do so were causing crashes. So, in D34352, we
partially reverted D10800 and implemented a custom mechanism specific to
the vdso.

Unfortunately, enough of D10800 remained such that, under the right
circumstances, it could end up loading a second (non-functional) copy of
the vdso module. This happened when the process plugin did not support
the extended MemoryRegionInfo query (added in D22219, to workaround a
different bug), which meant that the loader plugin was not able to
recognise that the linux-vdso.so.1 module (this is how the loader calls
it) is in fact the same as the [vdso] module (the name used in
/proc/$PID/maps) we loaded before. This typically happened in a core
file, as they don't store this kind of information.

This patch fixes the issue by completing the revert of D10800 -- the
memory loading code is removed completely. It also reduces the scope of
the hackaround introduced in D22219 -- it isn't completely sound and is
only relevant for fairly old (but still supported) versions of android.

I added the memory loading logic to the wasm dynamic loader, which has
since appeared and is relying on this feature (it even has a test). As
far as I can tell loading wasm modules from memory is possible and
reliable. MachO memory loading is not affected by this patch, as it uses
a completely different code path.

Since the scenarios/patches I described came without test cases, I have
created two new gdb-client tests cases for them. They're not
particularly readable, but right now, this is the best way we can
simulate the behavior (bugs) of a particular dynamic linker.

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

Added: 
lldb/test/API/functionalities/gdb_remote_client/TestGdbClientModuleLoad.py
lldb/test/API/functionalities/gdb_remote_client/module_load.yaml

Modified: 
lldb/include/lldb/Target/DynamicLoader.h
lldb/packages/Python/lldbsuite/test/gdbclientutils.py
lldb/source/Core/DynamicLoader.cpp
lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h
lldb/source/Plugins/DynamicLoader/wasm-DYLD/DynamicLoaderWasmDYLD.cpp
lldb/source/Plugins/DynamicLoader/wasm-DYLD/DynamicLoaderWasmDYLD.h
lldb/test/API/functionalities/gdb_remote_client/TestWasm.py

Removed: 




diff  --git a/lldb/include/lldb/Target/DynamicLoader.h 
b/lldb/include/lldb/Target/DynamicLoader.h
index 84ad0f11fabb5..4f07045f86457 100644
--- a/lldb/include/lldb/Target/DynamicLoader.h
+++ b/lldb/include/lldb/Target/DynamicLoader.h
@@ -263,6 +263,8 @@ class DynamicLoader : public PluginInterface {
 protected:
   // Utility methods for derived classes
 
+  lldb::ModuleSP FindModuleViaTarget(const FileSpec &file);
+
   /// Checks to see if the target module has changed, updates the target
   /// accordingly and returns the target executable module.
   lldb::ModuleSP GetTargetExecutable();

diff  --git a/lldb/packages/Python/lldbsuite/test/gdbclientutils.py 
b/lldb/packages/Python/lldbsuite/test/gdbclientutils.py
index 78854bb9dae87..68ac0e07b4a14 100644
--- a/lldb/packages/Python/lldbsuite/test/gdbclientutils.py
+++ b/lldb/packages/Python/lldbsuite/test/gdbclientutils.py
@@ -66,8 +66,9 @@ def hex_decode_bytes(hex_bytes):
 """
 out = ""
 hex_len = len(hex_bytes)
+i = 0
 while i < hex_len - 1:
-out += chr(int(hex_bytes[i:i + 2]), 16)
+out += chr(int(hex_bytes[i:i + 2], 16))
 i += 2
 return out
 
@@ -178,6 +179,8 @@ def respond(self, packet):
 return self.qGetWorkingDir()
 if packet == "qOffsets":
 return self.qOffsets();
+if packet == "qProcessInfo":
+return self.qProcessInfo()
 if packet == "qsProcessInfo":
 return self.qsProcessInfo()
 if packet.startswith("qfProcessInfo"):
@@ -214,6 +217,9 @@ def qGetWorkingDir(self):
 def qOffsets(self):
 return ""
 
+def qProcessInfo(self):
+return ""
+
 def qHostInfo(self):
 return "ptrsize:8;endian:little;"
 


[Lldb-commits] [PATCH] D122898: [lldb] Move host platform implementations into the base class

2022-04-05 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG331150a47dd5: [lldb] Move host platform implementations into 
the base class (authored by labath).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122898

Files:
  lldb/include/lldb/Target/Platform.h
  lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.h
  lldb/source/Target/Platform.cpp
  lldb/source/Target/RemoteAwarePlatform.cpp
  lldb/test/API/qemu/TestQemuAPI.py

Index: lldb/test/API/qemu/TestQemuAPI.py
===
--- /dev/null
+++ lldb/test/API/qemu/TestQemuAPI.py
@@ -0,0 +1,28 @@
+from __future__ import print_function
+import lldb
+import os
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+
+
+@skipIfRemote
+class TestQemuAPI(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_file_api(self):
+qemu = lldb.SBPlatform("qemu-user")
+host = lldb.SBPlatform.GetHostPlatform()
+
+target = self.getBuildArtifact("target.c")
+main_c = lldb.SBFileSpec(self.getSourcePath("main.c"))
+
+self.assertSuccess(qemu.Put(main_c, lldb.SBFileSpec(target)))
+self.assertTrue(os.path.exists(target))
+self.assertEqual(qemu.GetFilePermissions(target),
+host.GetFilePermissions(target))
+
+self.assertSuccess(qemu.MakeDirectory(
+self.getBuildArtifact("target_dir")))
+self.assertTrue(os.path.isdir(self.getBuildArtifact("target_dir")))
Index: lldb/source/Target/RemoteAwarePlatform.cpp
===
--- lldb/source/Target/RemoteAwarePlatform.cpp
+++ lldb/source/Target/RemoteAwarePlatform.cpp
@@ -10,7 +10,6 @@
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleList.h"
 #include "lldb/Core/ModuleSpec.h"
-#include "lldb/Host/FileCache.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Host/HostInfo.h"
@@ -180,14 +179,12 @@
 llvm::StringRef shell, llvm::StringRef command, const FileSpec &working_dir,
 int *status_ptr, int *signo_ptr, std::string *command_output,
 const Timeout &timeout) {
-  if (IsHost())
-return Host::RunShellCommand(shell, command, working_dir, status_ptr,
- signo_ptr, command_output, timeout);
   if (m_remote_platform_sp)
 return m_remote_platform_sp->RunShellCommand(shell, command, working_dir,
  status_ptr, signo_ptr,
  command_output, timeout);
-  return Status("unable to run a remote command without a platform");
+  return Platform::RunShellCommand(shell, command, working_dir, status_ptr,
+   signo_ptr, command_output, timeout);
 }
 
 Status RemoteAwarePlatform::MakeDirectory(const FileSpec &file_spec,
@@ -216,16 +213,12 @@
 lldb::user_id_t RemoteAwarePlatform::OpenFile(const FileSpec &file_spec,
   File::OpenOptions flags,
   uint32_t mode, Status &error) {
-  if (IsHost())
-return FileCache::GetInstance().OpenFile(file_spec, flags, mode, error);
   if (m_remote_platform_sp)
 return m_remote_platform_sp->OpenFile(file_spec, flags, mode, error);
   return Platform::OpenFile(file_spec, flags, mode, error);
 }
 
 bool RemoteAwarePlatform::CloseFile(lldb::user_id_t fd, Status &error) {
-  if (IsHost())
-return FileCache::GetInstance().CloseFile(fd, error);
   if (m_remote_platform_sp)
 return m_remote_platform_sp->CloseFile(fd, error);
   return Platform::CloseFile(fd, error);
@@ -234,8 +227,6 @@
 uint64_t RemoteAwarePlatform::ReadFile(lldb::user_id_t fd, uint64_t offset,
void *dst, uint64_t dst_len,
Status &error) {
-  if (IsHost())
-return FileCache::GetInstance().ReadFile(fd, offset, dst, dst_len, error);
   if (m_remote_platform_sp)
 return m_remote_platform_sp->ReadFile(fd, offset, dst, dst_len, error);
   return Platform::ReadFile(fd, offset, dst, dst_len, error);
@@ -244,20 +235,12 @@
 uint64_t RemoteAwarePlatform::WriteFile(lldb::user_id_t fd, uint64_t offset,
 const void *src, uint64_t src_len,
 Status &error) {
-  if (IsHost())
-return FileCache::GetInstance().WriteFile(fd, offset, src, src_len, error);
   if (m_remote_platform_sp)
 return m_remote_platform_sp->WriteFile(fd, offset, src, src_len, error);
   return Platform::WriteFile(fd, offset, src, src_len, error);
 }
 
 lldb::user_id_t RemoteAwarePlatform::GetFileSize(const FileSpec &file_spec) {
-  if (IsHost()) {
-uint64_t Size;
-if (llvm::sys::fs::file_size(file_spec.GetPath(), 

[Lldb-commits] [PATCH] D122716: [lldb/linux] Handle main thread exits

2022-04-05 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4384c96fe7eb: [lldb/linux] Handle main thread exits 
(authored by labath).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122716

Files:
  lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/test/API/functionalities/thread/main_thread_exit/Makefile
  lldb/test/API/functionalities/thread/main_thread_exit/TestMainThreadExit.py
  lldb/test/API/functionalities/thread/main_thread_exit/main.cpp

Index: lldb/test/API/functionalities/thread/main_thread_exit/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/main_thread_exit/main.cpp
@@ -0,0 +1,23 @@
+#include 
+
+#ifdef __linux__
+#include 
+#include 
+
+void exit_thread(int result) { syscall(SYS_exit, result); }
+#else
+#error Needs OS-specific implementation
+#endif
+
+int call_me() { return 12345; }
+
+void thread() {
+  std::this_thread::sleep_for(
+  std::chrono::seconds(10)); // Let the main thread exit.
+  exit_thread(42);   // break here
+}
+
+int main() {
+  std::thread(thread).detach();
+  exit_thread(47);
+}
Index: lldb/test/API/functionalities/thread/main_thread_exit/TestMainThreadExit.py
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/main_thread_exit/TestMainThreadExit.py
@@ -0,0 +1,31 @@
+"""
+Test handling of the situation where the main thread exits but the other threads
+in the process keep running.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+import lldbsuite.test.lldbutil as lldbutil
+
+
+class ThreadExitTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+NO_DEBUG_INFO_TESTCASE = True
+
+# Needs os-specific implementation in the inferior
+@skipIf(oslist=no_match(["linux"]))
+def test(self):
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// break here",
+lldb.SBFileSpec("main.cpp"))
+
+# There should be one (non-main) thread left
+self.assertEquals(self.process().GetNumThreads(), 1)
+
+# Ensure we can evaluate_expressions in this state
+self.expect_expr("call_me()", result_value="12345")
+
+self.runCmd("continue")
+self.assertEquals(self.process().GetExitStatus(), 47)
Index: lldb/test/API/functionalities/thread/main_thread_exit/Makefile
===
--- /dev/null
+++ lldb/test/API/functionalities/thread/main_thread_exit/Makefile
@@ -0,0 +1,3 @@
+ENABLE_THREADS := YES
+CXX_SOURCES := main.cpp
+include Makefile.rules
Index: lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
===
--- lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -447,13 +447,7 @@
 // This is a thread that exited.  Ensure we're not tracking it anymore.
 StopTrackingThread(thread);
 
-if (is_main_thread) {
-  // The main thread exited.  We're done monitoring.  Report to delegate.
-  SetExitStatus(status, true);
-
-  // Notify delegate that our process has exited.
-  SetState(StateType::eStateExited, true);
-}
+assert(!is_main_thread && "Main thread exits handled elsewhere");
 return;
   }
 
@@ -611,6 +605,13 @@
 }
 ResumeThread(thread, state, LLDB_INVALID_SIGNAL_NUMBER);
 
+if (is_main_thread) {
+  // Main thread report the read (WIFEXITED) event only after all threads in
+  // the process exit, so we need to stop tracking it here instead of in
+  // MonitorCallback
+  StopTrackingThread(thread);
+}
+
 break;
   }
 
@@ -1177,11 +1178,11 @@
 
   // Linux kernel since 2.6.14 has /proc/{pid}/smaps
   // if CONFIG_PROC_PAGE_MONITOR is enabled
-  auto BufferOrError = getProcFile(GetID(), "smaps");
+  auto BufferOrError = getProcFile(GetID(), GetCurrentThreadID(), "smaps");
   if (BufferOrError)
 ParseLinuxSMapRegions(BufferOrError.get()->getBuffer(), callback);
   else {
-BufferOrError = getProcFile(GetID(), "maps");
+BufferOrError = getProcFile(GetID(), GetCurrentThreadID(), "maps");
 if (!BufferOrError) {
   m_supports_mem_region = LazyBool::eLazyBoolNo;
   return BufferOrError.getError();
@@ -1232,7 +1233,7 @@
 
   addr_t exe_addr = region_it->first.GetRange().GetRangeBase();
 
-  NativeThreadLinux &thread = *GetThreadByID(GetID());
+  NativeThreadLinux &thread = *GetCurrentThread();
   assert(thread.GetState() == eStateStopped);
   NativeRegisterContextLinux ®_ctx = thread.GetRegisterContext();
 
@@ -1384,8 +1385,9 @@
 tags_iovec.iov_len = num_tags;
 
 Status error = NativeProcessLinux::PtraceWrapper(
-details->ptrace_read_req, GetID(), reinterp

[Lldb-commits] [PATCH] D122660: [lldb] Avoid duplicate vdso modules when opening core files

2022-04-05 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe67cee09499c: [lldb] Avoid duplicate vdso modules when 
opening core files (authored by labath).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122660

Files:
  lldb/include/lldb/Target/DynamicLoader.h
  lldb/packages/Python/lldbsuite/test/gdbclientutils.py
  lldb/source/Core/DynamicLoader.cpp
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h
  lldb/source/Plugins/DynamicLoader/wasm-DYLD/DynamicLoaderWasmDYLD.cpp
  lldb/source/Plugins/DynamicLoader/wasm-DYLD/DynamicLoaderWasmDYLD.h
  lldb/test/API/functionalities/gdb_remote_client/TestGdbClientModuleLoad.py
  lldb/test/API/functionalities/gdb_remote_client/TestWasm.py
  lldb/test/API/functionalities/gdb_remote_client/module_load.yaml

Index: lldb/test/API/functionalities/gdb_remote_client/module_load.yaml
===
--- /dev/null
+++ lldb/test/API/functionalities/gdb_remote_client/module_load.yaml
@@ -0,0 +1,53 @@
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_X86_64
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+Address: 0x
+AddressAlign:0x4
+Content: "c3c3c3c3"
+  - Name:.data
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC ]
+Address: 0x1000
+AddressAlign:0x4
+Size:0x28
+  - Name:.dynamic
+Type:SHT_DYNAMIC
+Flags:   [ SHF_WRITE, SHF_ALLOC ]
+AddressAlign:0x8
+Entries:
+  - Tag: DT_DEBUG
+Value:   0xdead
+
+ProgramHeaders:
+  - Type: PT_LOAD
+Flags: [ PF_X, PF_R ]
+VAddr: 0x
+Align: 0x4
+FirstSec: .text
+LastSec:  .text
+  - Type: PT_LOAD
+Flags: [ PF_R, PF_W ]
+VAddr: 0x1000
+Align: 0x4
+FirstSec: .data
+LastSec:  .dynamic
+  - Type:PT_DYNAMIC
+Flags:   [ PF_W, PF_R ]
+VAddr:   0x1028
+FirstSec:.dynamic
+LastSec: .dynamic
+DynamicSymbols:
+  - Name:_r_debug
+Type:STT_OBJECT
+Section: .data
+Binding: STB_GLOBAL
+Value:   0x0
+Size:0x28
+
Index: lldb/test/API/functionalities/gdb_remote_client/TestWasm.py
===
--- lldb/test/API/functionalities/gdb_remote_client/TestWasm.py
+++ lldb/test/API/functionalities/gdb_remote_client/TestWasm.py
@@ -32,8 +32,6 @@
 MockGDBServerResponder.__init__(self)
 
 def respond(self, packet):
-if packet == "qProcessInfo":
-return self.qProcessInfo()
 if packet[0:13] == "qRegisterInfo":
 return self.qRegisterInfo(packet[13:])
 return MockGDBServerResponder.respond(self, packet)
Index: lldb/test/API/functionalities/gdb_remote_client/TestGdbClientModuleLoad.py
===
--- /dev/null
+++ lldb/test/API/functionalities/gdb_remote_client/TestGdbClientModuleLoad.py
@@ -0,0 +1,133 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+from lldbsuite.test.gdbclientutils import *
+from lldbsuite.test.lldbgdbclient import GDBRemoteTestBase
+from lldbsuite.support import seven
+
+class MyResponder(MockGDBServerResponder):
+"""
+A responder which simulates a process with a single shared library loaded.
+Its parameters allow configuration of various properties of the library.
+"""
+
+def __init__(self, testcase, triple, library_name, auxv_entry, region_info):
+MockGDBServerResponder.__init__(self)
+self.testcase = testcase
+self._triple = triple
+self._library_name = library_name
+self._auxv_entry = auxv_entry
+self._region_info = region_info
+
+def qSupported(self, client_supported):
+return (super().qSupported(client_supported) +
+";qXfer:auxv:read+;qXfer:libraries-svr4:read+")
+
+def qXferRead(self, obj, annex, offset, length):
+if obj == "features" and annex == "target.xml":
+return """
+
+  i386:x86-64
+  
+
+  
+""", False
+elif obj == "auxv":
+# 0x09 = AT_ENTRY, which lldb uses to compute the load bias of the
+# main binary.
+return hex_decode_bytes(self._auxv_entry +
+"0900ee00"), False
+elif obj == "libraries-svr4":
+  

[Lldb-commits] [PATCH] D122975: parallelize module loading in DynamicLoaderPOSIXDYLD()

2022-04-05 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

In D122975#3426731 , @llunak wrote:

> In D122975#3426575 , @labath wrote:
>
>> I'd like to understand what is the precise thing that you're trying to 
>> optimise. If there is like a single hot piece of code that we want to 
>> optimise, then we might be able to come up with an different approach (a'la 
>> PrefetchModuleSpecs) to achieve the same thing.
>
> The scenario is a repeated lldb start with index cache enabled (and so 
> everything necessary cached), the debugged app is debug build of LibreOffice 
> Calc (~100 medium-sized C++ libraries). 90% of the CPU time is spent in 
> LoadFromCache() calls, because 70% of the CPU time is spent in ConstString 
> (and that's after my ConstString optimizations). I don't think there's any 
> other way to make it faster other than parallelizing it, although 
> parallelizing only LoadFromCache() should be enough and I'd expect that to be 
> limited enough to be safe if you expect the lldb codebase is not generally 
> thread-safe. In this patch I parallelized higher because it was simple to do 
> it up there, and I don't know how to easily get at all the LoadFromCache() 
> calls (especially the one called from SymbolFileDWARFDebugMap is relatively 
> deep). If you know how to parallelize only that, that works for me too.

OK, got it. So, for this case, I think the best approach would be to extract 
and paralelize the `PreloadSymbols` calls. They are not deep (=> relatively 
easy to extract), optional (they are just a performance optimization, so 
nothing will break if they're skipped), and completely isolated (they only 
access data from the single module).

In fact we already have a sort of an existing place to do this kind of group 
module actions. The reason that the `ModulesDidLoad` (line 621) call does not 
happen inside `GetOrCreateModule` is because we want to send just one load 
event instead of spamming the user with potentially hundreds of messages. I 
don't think it would be unreasonable to move the `PreloadSymbols` call from to 
`ModulesDidLoad`.

Of course, we still need to figure out the parallelization story.

In D122975#3427243 , @llunak wrote:

> In D122975#3427008 , @clayborg 
> wrote:
>
>> I had tried something similar with the thread pools when trying to 
>> parallelize similar stuff. The solution I made was to have a global thread 
>> pool for the entire LLDB process, but then the LLVM thread pool stuff needed 
>> to be modified to handle different groups of threads where work could be 
>> added to a queue and then users can wait on the queue. The queues then need 
>> to be managed by the thread pool code. Queues could also be serial queues or 
>> concurrent queues. I never completed the patch, but just wanted to pass 
>> along the ideas I had used. So instead of adding everything to a separate 
>> pool, the main thread pool could take queues. The code for your code above 
>> would look something like:
>
> I got a similar idea too, but I think it wouldn't work here in this 
> threadpool-within-threadpool situation. If you limit the total number of 
> threads, then the "outer" tasks could allocate all the threads and would 
> deadlock on "inner" tasks waiting for threads (and if you don't limit threads 
> then there's no need to bother). That's why I came up with the semaphore 
> idea, as that would require threads to acquire slots and "outer" tasks could 
> temporarily release them when spawning "inner" tasks (I didn't consider 
> pending threads to be a problem, but if it is, then the supposed ThreadPool 
> queues presumably could do that somehow too).

Pending/suspended threads are less of a problem then threads actively 
contending for cpu time, but still less than ideal. On my machine I could end 
up with over 2k threads. At 8MB per thread, that's 16GB just for stack (most of 
it probably unused, but still...). And some machines have more (sometimes a lot 
more) CPUs than I do.

Properly implementing thread pools is tricky, and I don't consider myself an 
expert, but I think that, instead of using semaphores, you could detect that 
the case when `wait()` is being called from inside a thread pool thread, and 
then, instead of passively waiting for the task to finish, start eagerly 
evaluating it on the same thread.

I'm pretty sure I didn't come up with this idea, so it's possible that 
something like this is already implemented in llvm, and I got the idea from 
there.

> But if lldb code is not considered thread-safe to parallelize the module 
> loading at this level, then this is all irrelevant. If it's required to 
> parallelize only cache loading, then that removes the 
> threadpool-within-threadpool situation. I don't know if I understand the code 
> enough to try that though.

Yeah, I'd rather avoid parallelizing the logic for populating the targ

[Lldb-commits] [PATCH] D122975: parallelize module loading in DynamicLoaderPOSIXDYLD()

2022-04-05 Thread Luboš Luňák via Phabricator via lldb-commits
llunak added a comment.

In D122975#3428876 , @labath wrote:

> OK, got it. So, for this case, I think the best approach would be to extract 
> and paralelize the `PreloadSymbols` calls. They are not deep (=> relatively 
> easy to extract), optional (they are just a performance optimization, so 
> nothing will break if they're skipped), and completely isolated (they only 
> access data from the single module).



> In fact we already have a sort of an existing place to do this kind of group 
> module actions. The reason that the `ModulesDidLoad` (line 621) call does not 
> happen inside `GetOrCreateModule` is because we want to send just one load 
> event instead of spamming the user with potentially hundreds of messages. I 
> don't think it would be unreasonable to move the `PreloadSymbols` call from 
> to `ModulesDidLoad`.

I've meanwhile had a closer look at the relevant functions and I've come to a 
similar conclusion (minus the `ModulesDidLoad` part). I think 
`GetOrCreateModule` currently does call `ModulesDidLoad` for each module, but 
that should be easy to change (and `PreloadSymbols` comes from 
7fca8c0757a5ee5f290844376c7f8c5f3c1ffcfe , which means the function should be 
fine being moved there). I'll have a go at this.

> Pending/suspended threads are less of a problem then threads actively 
> contending for cpu time, but still less than ideal. On my machine I could end 
> up with over 2k threads. At 8MB per thread, that's 16GB just for stack (most 
> of it probably unused, but still...). And some machines have more (sometimes 
> a lot more) CPUs than I do.
>
> Properly implementing thread pools is tricky, and I don't consider myself an 
> expert, but I think that, instead of using semaphores, you could detect that 
> the case when `wait()` is being called from inside a thread pool thread, and 
> then, instead of passively waiting for the task to finish, start eagerly 
> evaluating it on the same thread.
>
> I'm pretty sure I didn't come up with this idea, so it's possible that 
> something like this is already implemented in llvm, and I got the idea from 
> there.

Those 16GB would be address space, most of which wouldn't be memory. I'm not an 
expert on that, but that's why I didn't consider it to be a problem, e.g. 
sanitizers allocate way more address space. But ok, I can adjust ThreadPool to 
be reusable for different groups of tasks. I've thought of the processing 
`wait` idea too, ThreadPool currently can't do that, but I think it should be 
easy to add.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122975

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


[Lldb-commits] [PATCH] D123128: don't extra notify ModulesDidLoad() from LoadModuleAtAddress()

2022-04-05 Thread Luboš Luňák via Phabricator via lldb-commits
llunak created this revision.
llunak added a reviewer: jasonmolenda.
llunak added a project: LLDB.
Herald added a subscriber: JDevlieghere.
Herald added a project: All.
llunak requested review of this revision.
Herald added a subscriber: lldb-commits.

Places calling LoadModuleAddress() already call ModulesDidLoad() after a loop 
calling LoadModuleAtAddress(), so it's not necessary to call it from there, and 
the batched ModulesDidLoad() may be more efficient than this place calling it 
one after one.

This also makes the ModuleLoadedNotifys test pass on Linux now that the 
duplicates no longer bring down the average of modules notified per call.

This change is a prerequisite for parallelizing PreloadSymbols() in D122975 
.

Note that this patch could have been shorter if I simply changed 
LoadModuleAtAddress() to always pass false for `notify` (all callers currently 
call ModulesDidLoad() afterwards) and added a note to LoadModuleAtAddress() 
docs about it, but I don't know if that's a good design choice. I can change 
the patch to be that way if you want.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123128

Files:
  lldb/include/lldb/Target/DynamicLoader.h
  lldb/source/Core/DynamicLoader.cpp
  lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
  
lldb/test/API/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py

Index: lldb/test/API/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py
===
--- lldb/test/API/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py
+++ lldb/test/API/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py
@@ -16,10 +16,10 @@
 mydir = TestBase.compute_mydir(__file__)
 NO_DEBUG_INFO_TESTCASE = True
 
-# DynamicLoaderDarwin should batch up notifications about
-# newly added/removed libraries.  Other DynamicLoaders may
+# At least DynamicLoaderDarwin and DynamicLoaderPOSIXDYLD should batch up
+# notifications about newly added/removed libraries.  Other DynamicLoaders may
 # not be written this way.
-@skipUnlessDarwin
+@skipUnlessPlatform(["linux"]+lldbplatformutil.getDarwinOSTriples())
 
 def setUp(self):
 # Call super's setUp().
@@ -107,6 +107,7 @@
 # binaries in batches.  Check that we got back more than 1 solib per event.  
 # In practice on Darwin today, we get back two events for a do-nothing c 
 # program: a.out and dyld, and then all the rest of the system libraries.
+# On Linux we get events for ld.so, [vdso], the binary and then all libraries.
 
-avg_solibs_added_per_event = int(float(total_solibs_added) / float(total_modules_added_events))
+avg_solibs_added_per_event = round(float(total_solibs_added) / float(total_modules_added_events))
 self.assertGreater(avg_solibs_added_per_event, 1)
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
===
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -396,7 +396,7 @@
   lldb::ModuleSP LoadModuleAtAddress(const FileSpec &file,
  lldb::addr_t link_map,
  lldb::addr_t base_addr,
- bool value_is_offset);
+ bool value_is_offset, bool notify);
 
   Status UpdateAutomaticSignalFiltering() override;
 
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -4548,13 +4548,14 @@
 lldb::ModuleSP ProcessGDBRemote::LoadModuleAtAddress(const FileSpec &file,
  lldb::addr_t link_map,
  lldb::addr_t base_addr,
- bool value_is_offset) {
+ bool value_is_offset,
+ bool notify) {
   DynamicLoader *loader = GetDynamicLoader();
   if (!loader)
 return nullptr;
 
-  return loader->LoadModuleAtAddress(file, link_map, base_addr,
- value_is_offset);
+  return loader->LoadModuleAtAddress(file, link_map, base_addr, value_is_offset,
+ notify);
 }
 
 llvm::Error ProcessGDBRemote::LoadModules() {
@@ -4586,8 +4587,8 @@

[Lldb-commits] [PATCH] D122975: parallelize calling of Module::PreloadSymbols()

2022-04-05 Thread Luboš Luňák via Phabricator via lldb-commits
llunak updated this revision to Diff 420492.
llunak retitled this revision from "parallelize module loading in  
DynamicLoaderPOSIXDYLD()" to "parallelize calling of Module::PreloadSymbols()".
llunak edited the summary of this revision.
llunak added a reviewer: jingham.
llunak added a comment.

Ok, parallelizing of only Module::PreloadSymbols() was simpler than I expected 
and it also works, so I've reworked the patch to do that.

This change now requires D123128  and also 
adding the grouping ability to ThreadPool, which I haven't done yet.


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

https://reviews.llvm.org/D122975

Files:
  lldb/source/Target/Target.cpp


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -62,6 +62,7 @@
 
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SetVector.h"
+#include "llvm/Support/ThreadPool.h"
 
 #include 
 #include 
@@ -1623,6 +1624,17 @@
 void Target::ModulesDidLoad(ModuleList &module_list) {
   const size_t num_images = module_list.GetSize();
   if (m_valid && num_images) {
+if (GetPreloadSymbols()) {
+  // Try to preload symbols in parallel.
+  llvm::ThreadPool pool(llvm::optimal_concurrency(num_images));
+  auto preload_symbols_fn = [&](size_t idx) {
+ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
+module_sp->PreloadSymbols();
+  };
+  for (size_t idx = 0; idx < num_images; ++idx)
+pool.async(preload_symbols_fn, idx);
+  pool.wait();
+}
 for (size_t idx = 0; idx < num_images; ++idx) {
   ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
   LoadScriptingResourceForModule(module_sp, this);
@@ -2170,11 +2182,6 @@
   });
 }
 
-// Preload symbols outside of any lock, so hopefully we can do this for
-// each library in parallel.
-if (GetPreloadSymbols())
-  module_sp->PreloadSymbols();
-
 llvm::SmallVector replaced_modules;
 for (ModuleSP &old_module_sp : old_modules) {
   if (m_images.GetIndexForModule(old_module_sp.get()) !=


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -62,6 +62,7 @@
 
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SetVector.h"
+#include "llvm/Support/ThreadPool.h"
 
 #include 
 #include 
@@ -1623,6 +1624,17 @@
 void Target::ModulesDidLoad(ModuleList &module_list) {
   const size_t num_images = module_list.GetSize();
   if (m_valid && num_images) {
+if (GetPreloadSymbols()) {
+  // Try to preload symbols in parallel.
+  llvm::ThreadPool pool(llvm::optimal_concurrency(num_images));
+  auto preload_symbols_fn = [&](size_t idx) {
+ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
+module_sp->PreloadSymbols();
+  };
+  for (size_t idx = 0; idx < num_images; ++idx)
+pool.async(preload_symbols_fn, idx);
+  pool.wait();
+}
 for (size_t idx = 0; idx < num_images; ++idx) {
   ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
   LoadScriptingResourceForModule(module_sp, this);
@@ -2170,11 +2182,6 @@
   });
 }
 
-// Preload symbols outside of any lock, so hopefully we can do this for
-// each library in parallel.
-if (GetPreloadSymbols())
-  module_sp->PreloadSymbols();
-
 llvm::SmallVector replaced_modules;
 for (ModuleSP &old_module_sp : old_modules) {
   if (m_images.GetIndexForModule(old_module_sp.get()) !=
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D120810: [lldb] Remove the global platform list

2022-04-05 Thread Pavel Labath via Phabricator via lldb-commits
labath updated this revision to Diff 420507.
labath added a comment.

Reopening, since the last attempt was quite some time ago, and the rebase was
non-trivial.

Functionally, there are no real changes. The one-liner in dotest.py is somewhat
interesting, as it was necessary for (emu|simu)lator platform tests (which don't
have a connection url) to work. Previously, these worked even without setting
lldb.selected_platform, as they would get picked up from the global platform
list, but with this patch, they would become completely orphaned, and uneligible
for automatic selection.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120810

Files:
  lldb/include/lldb/Target/Platform.h
  lldb/packages/Python/lldbsuite/test/dotest.py
  lldb/source/API/SBDebugger.cpp
  lldb/source/API/SBPlatform.cpp
  lldb/source/Interpreter/OptionGroupPlatform.cpp
  lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
  lldb/source/Plugins/Platform/POSIX/CMakeLists.txt
  lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  lldb/source/Plugins/Platform/Windows/CMakeLists.txt
  lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
  lldb/source/Plugins/Platform/gdb-server/CMakeLists.txt
  lldb/source/Target/Platform.cpp
  lldb/source/Target/Process.cpp
  lldb/source/Target/Target.cpp
  lldb/source/Target/TargetList.cpp
  lldb/test/API/python_api/debugger/TestDebuggerAPI.py
  lldb/test/API/python_api/debugger/elf.yaml
  lldb/test/API/python_api/debugger/macho.yaml
  lldb/test/API/python_api/sbplatform/TestSBPlatform.py
  lldb/unittests/Platform/PlatformTest.cpp

Index: lldb/unittests/Platform/PlatformTest.cpp
===
--- lldb/unittests/Platform/PlatformTest.cpp
+++ lldb/unittests/Platform/PlatformTest.cpp
@@ -21,7 +21,6 @@
 class TestPlatform : public PlatformPOSIX {
 public:
   TestPlatform() : PlatformPOSIX(false) {}
-  using Platform::Clear;
 };
 
 class PlatformArm : public TestPlatform {
@@ -75,67 +74,66 @@
 
 class PlatformTest : public ::testing::Test {
   SubsystemRAII subsystems;
-  void SetUp() override { TestPlatform::Clear(); }
+
+protected:
+  PlatformList list;
+
+  void SetHostPlatform(const PlatformSP &platform_sp) {
+Platform::SetHostPlatform(platform_sp);
+ASSERT_EQ(Platform::GetHostPlatform(), platform_sp);
+list.Append(platform_sp, /*set_selected=*/true);
+  }
 };
 
 TEST_F(PlatformTest, GetPlatformForArchitecturesHost) {
-  const PlatformSP host_platform_sp = std::make_shared();
-  Platform::SetHostPlatform(host_platform_sp);
-  ASSERT_EQ(Platform::GetHostPlatform(), host_platform_sp);
+  SetHostPlatform(std::make_shared());
 
   const std::vector archs = {ArchSpec("arm64-apple-ps4"),
ArchSpec("arm64e-apple-ps4")};
   std::vector candidates;
 
   // The host platform matches all architectures.
-  PlatformSP platform_sp =
-  Platform::GetPlatformForArchitectures(archs, {}, {}, candidates);
+  PlatformSP platform_sp = list.GetOrCreate(archs, {}, candidates);
   ASSERT_TRUE(platform_sp);
-  EXPECT_EQ(platform_sp, host_platform_sp);
+  EXPECT_EQ(platform_sp, Platform::GetHostPlatform());
 }
 
 TEST_F(PlatformTest, GetPlatformForArchitecturesSelected) {
-  const PlatformSP host_platform_sp = std::make_shared();
-  Platform::SetHostPlatform(host_platform_sp);
-  ASSERT_EQ(Platform::GetHostPlatform(), host_platform_sp);
+  SetHostPlatform(std::make_shared());
 
   const std::vector archs = {ArchSpec("arm64-apple-ps4"),
ArchSpec("arm64e-apple-ps4")};
   std::vector candidates;
 
-  // The host platform matches no architectures. No selected platform.
-  PlatformSP platform_sp =
-  Platform::GetPlatformForArchitectures(archs, {}, {}, candidates);
+  // The host platform matches no architectures.
+  PlatformSP platform_sp = list.GetOrCreate(archs, {}, candidates);
   ASSERT_FALSE(platform_sp);
 
   // The selected platform matches all architectures.
   const PlatformSP selected_platform_sp = std::make_shared();
-  platform_sp = Platform::GetPlatformForArchitectures(
-  archs, {}, selected_platform_sp, candidates);
+  list.Append(selected_platform_sp, /*set_selected=*/true);
+  platform_sp = list.GetOrCreate(archs, {}, candidates);
   ASSERT_TRUE(platform_sp);
   EXPECT_EQ(platform_sp, selected_platform_sp);
 }
 
 TEST_F(PlatformTest, GetPlatformForArchitecturesSelectedOverHost) {
-  const PlatformSP host_platform_sp = std::make_shared();
-  Platform::SetHostPlatform(host_platform_sp);
-  ASSERT_EQ(Platform::GetHostPlatform(), host_platform_sp);
+  SetHostPlatform(std::make_shared());
 
   const std::vector archs = {ArchSpec("arm64-apple-ps4"),
ArchSpec("x86_64-apple-ps4")};
   std::vector candidates;
 
-  // The host platform matches one architecture. No selected platform.
-  PlatformSP platform_sp =
-  Platf

[Lldb-commits] [PATCH] D123128: don't extra notify ModulesDidLoad() from LoadModuleAtAddress()

2022-04-05 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

> Note that this patch could have been shorter if I simply changed 
> LoadModuleAtAddress() to always pass false for notify (all callers currently 
> call ModulesDidLoad() afterwards) and added a note to LoadModuleAtAddress() 
> docs about it, but I don't know if that's a good design choice.

That would definitely be better.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123128

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


[Lldb-commits] [PATCH] D123025: [lldb-vscode] Implement stderr/stdout on win32 and redirect lldb log to VSCode

2022-04-05 Thread Michael Hept via Phabricator via lldb-commits
nidefawl updated this revision to Diff 420531.
nidefawl added a comment.

Reorder OS check to remove negation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123025

Files:
  lldb/tools/lldb-vscode/OutputRedirector.cpp
  lldb/tools/lldb-vscode/lldb-vscode.cpp

Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -65,11 +65,6 @@
 #define PATH_MAX MAX_PATH
 #endif
 typedef int socklen_t;
-constexpr const char *dev_null_path = "nul";
-
-#else
-constexpr const char *dev_null_path = "/dev/null";
-
 #endif
 
 using namespace lldb_vscode;
@@ -1446,23 +1441,13 @@
 //   }]
 // }
 void request_initialize(const llvm::json::Object &request) {
-  g_vsc.debugger = lldb::SBDebugger::Create(true /*source_init_files*/);
+  auto log_cb = [](const char *buf, void *baton) -> void {
+g_vsc.SendOutput(OutputType::Console, llvm::StringRef{buf});
+  };
+  g_vsc.debugger =
+  lldb::SBDebugger::Create(true /*source_init_files*/, log_cb, nullptr);
   g_vsc.progress_event_thread = std::thread(ProgressEventThreadFunction);
 
-  // Create an empty target right away since we might get breakpoint requests
-  // before we are given an executable to launch in a "launch" request, or a
-  // executable when attaching to a process by process ID in a "attach"
-  // request.
-  FILE *out = llvm::sys::RetryAfterSignal(nullptr, fopen, dev_null_path, "w");
-  if (out) {
-// Set the output and error file handles to redirect into nothing otherwise
-// if any code in LLDB prints to the debugger file handles, the output and
-// error file handles are initialized to STDOUT and STDERR and any output
-// will kill our debug session.
-g_vsc.debugger.SetOutputFileHandle(out, true);
-g_vsc.debugger.SetErrorFileHandle(out, false);
-  }
-
   // Start our event thread so we can receive events from the debugger, target,
   // process and more.
   g_vsc.event_thread = std::thread(EventThreadFunction);
@@ -3147,18 +3132,25 @@
 /// \return
 /// A fd pointing to the original stdout.
 int SetupStdoutStderrRedirection() {
-  int new_stdout_fd = dup(fileno(stdout));
-  auto stdout_err_redirector_callback = [&](llvm::StringRef data) {
-g_vsc.SendOutput(OutputType::Console, data);
+  int stdoutfd = fileno(stdout);
+  int new_stdout_fd = dup(stdoutfd);
+  auto output_callback_stderr = [](llvm::StringRef data) {
+g_vsc.SendOutput(OutputType::Stderr, data);
   };
-
-  for (int fd : {fileno(stdout), fileno(stderr)}) {
-if (llvm::Error err = RedirectFd(fd, stdout_err_redirector_callback)) {
-  std::string error_message = llvm::toString(std::move(err));
-  if (g_vsc.log)
-*g_vsc.log << error_message << std::endl;
-  stdout_err_redirector_callback(error_message);
-}
+  auto output_callback_stdout = [](llvm::StringRef data) {
+g_vsc.SendOutput(OutputType::Stdout, data);
+  };
+  if (llvm::Error err = RedirectFd(stdoutfd, output_callback_stdout)) {
+std::string error_message = llvm::toString(std::move(err));
+if (g_vsc.log)
+  *g_vsc.log << error_message << std::endl;
+output_callback_stderr(error_message);
+  }
+  if (llvm::Error err = RedirectFd(fileno(stderr), output_callback_stderr)) {
+std::string error_message = llvm::toString(std::move(err));
+if (g_vsc.log)
+  *g_vsc.log << error_message << std::endl;
+output_callback_stderr(error_message);
   }
 
   /// used only by TestVSCode_redirection_to_console.py
Index: lldb/tools/lldb-vscode/OutputRedirector.cpp
===
--- lldb/tools/lldb-vscode/OutputRedirector.cpp
+++ lldb/tools/lldb-vscode/OutputRedirector.cpp
@@ -6,20 +6,27 @@
 //
 //===--===/
 
-#if !defined(_WIN32)
+#if defined(_WIN32)
+#include 
+#include 
+#else
 #include 
 #endif
 
 #include "OutputRedirector.h"
+#include "llvm/ADT/StringRef.h"
 
 using namespace llvm;
 
 namespace lldb_vscode {
 
 Error RedirectFd(int fd, std::function callback) {
-#if !defined(_WIN32)
   int new_fd[2];
+#if defined(_WIN32)
+  if (_pipe(new_fd, 4096, O_TEXT) == -1) {
+#else
   if (pipe(new_fd) == -1) {
+#endif
 int error = errno;
 return createStringError(inconvertibleErrorCode(),
  "Couldn't create new pipe for fd %d. %s", fd,
@@ -45,11 +52,10 @@
   continue;
 break;
   }
-  callback(StringRef(buffer, bytes_count).str());
+  callback(StringRef(buffer, bytes_count));
 }
   });
   t.detach();
-#endif
   return Error::success();
 }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D123025: [lldb-vscode] Implement stderr/stdout on win32 and redirect lldb log to VSCode

2022-04-05 Thread Michael Hept via Phabricator via lldb-commits
nidefawl marked 2 inline comments as done.
nidefawl added inline comments.



Comment at: lldb/tools/lldb-vscode/OutputRedirector.cpp:55
   }
-  callback(StringRef(buffer, bytes_count).str());
+  callback(StringRef(buffer, bytes_count));
 }

mstorsjo wrote:
> This change looks unrelated (although I'm not familiar with this piece of 
> code), although it's probably correct
The reference to the StringRef is never stored, so this avoids a copy. 
VSCode::SendOutput takes a StringRef and explicitly converts it to std::string 
before emplacing it in the json message.



Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:1444-1449
+  auto log_cb = [](const char *buf, void *baton) -> void {
+g_vsc.SendOutput(OutputType::Console, llvm::StringRef{buf});
+  };
+  g_vsc.debugger =
+  lldb::SBDebugger::Create(true /*source_init_files*/, log_cb, nullptr);
   g_vsc.progress_event_thread = std::thread(ProgressEventThreadFunction);

wallace wrote:
> could you test by creating a .lldbinit file with garbage so that the debugger 
> prints error messages during initialization, and then make sure that they are 
> properly redirected to the console of the IDE?
Yes, I can see the error messages in the VSCode debugger console. Both on 
windows and linux.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123025

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


[Lldb-commits] [PATCH] D122856: [lldb] Refactor DataBuffer so we can map files as read-only

2022-04-05 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 420540.
JDevlieghere marked an inline comment as done.
JDevlieghere added a comment.

I don't really like the idea of making the argument to createInstance writable. 
That seems like an implementation detail. Instead I added a virtual method 
IsWritable() to the DataBuffer and an assert to ObjectFileELF that ensures we 
always have a writable buffer.

@labath: does that cover your concerns?


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

https://reviews.llvm.org/D122856

Files:
  lldb/include/lldb/Core/ValueObject.h
  lldb/include/lldb/Host/FileSystem.h
  lldb/include/lldb/Symbol/CompactUnwindInfo.h
  lldb/include/lldb/Symbol/ObjectFile.h
  lldb/include/lldb/Target/ProcessStructReader.h
  lldb/include/lldb/Target/RegisterCheckpoint.h
  lldb/include/lldb/Target/RegisterContext.h
  lldb/include/lldb/Target/RegisterContextUnwind.h
  lldb/include/lldb/Utility/DataBuffer.h
  lldb/include/lldb/Utility/DataBufferHeap.h
  lldb/include/lldb/Utility/DataBufferLLVM.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/Commands/CommandObjectMemory.cpp
  lldb/source/Core/SourceManager.cpp
  lldb/source/Core/ValueObject.cpp
  lldb/source/DataFormatters/StringPrinter.cpp
  lldb/source/DataFormatters/TypeFormat.cpp
  lldb/source/Expression/IRExecutionUnit.cpp
  lldb/source/Host/common/FileSystem.cpp
  lldb/source/Host/common/Host.cpp
  lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp
  lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp
  lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
  lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
  lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp
  lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp
  lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp
  lldb/source/Plugins/Language/ObjC/CF.cpp
  lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
  lldb/source/Plugins/Language/ObjC/NSSet.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
  
lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
  lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
  lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.h
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.h
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.h
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.h
  lldb/source/Plugins/Process/Utility/RegisterContextDummy.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDummy.h
  lldb/source/Plugins/Process/Utility/RegisterContextHistory.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextHistory.h
  lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextMemory.h
  lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_32.cpp
  lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp
  lldb/source/Symbol/ObjectFile.cpp
  lldb/source/Target/Platform.cpp
  lldb/source/Target/RegisterContextUnwind.cpp

[Lldb-commits] [PATCH] D122991: [lldb][intelpt] Remove `IntelPTInstruction` and move methods to `DecodedThread`

2022-04-05 Thread walter erquinigo via Phabricator via lldb-commits
wallace requested changes to this revision.
wallace added a comment.
This revision now requires changes to proceed.

just remove a small comment and good to go!




Comment at: lldb/source/Plugins/Trace/intel-pt/DecodedThread.h:143-146
+  /// \param[in] next_load_address
+  /// The address of the next instruction in the trace or \b
+  /// LLDB_INVALID_ADDRESS if not available.
   ///

remove this


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122991

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


[Lldb-commits] [PATCH] D122991: [lldb][intelpt] Remove `IntelPTInstruction` and move methods to `DecodedThread`

2022-04-05 Thread Alisamar Husain via Phabricator via lldb-commits
zrthxn updated this revision to Diff 420543.
zrthxn marked an inline comment as done.
zrthxn added a comment.

Removed unnecessary comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122991

Files:
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
  lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/test/API/commands/trace/TestTraceDumpInfo.py
  lldb/test/API/commands/trace/TestTraceLoad.py

Index: lldb/test/API/commands/trace/TestTraceLoad.py
===
--- lldb/test/API/commands/trace/TestTraceLoad.py
+++ lldb/test/API/commands/trace/TestTraceLoad.py
@@ -38,8 +38,10 @@
 thread #1: tid = 3842849
   Raw trace size: 4 KiB
   Total number of instructions: 21
-  Total approximate memory usage: 0.98 KiB
-  Average memory usage per instruction: 48.00 bytes'''])
+  Total approximate memory usage: 0.27 KiB
+  Average memory usage per instruction: 13.00 bytes
+
+  Number of TSC decoding errors: 0'''])
 
 def testLoadInvalidTraces(self):
 src_dir = self.getSourceDir()
Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py
===
--- lldb/test/API/commands/trace/TestTraceDumpInfo.py
+++ lldb/test/API/commands/trace/TestTraceDumpInfo.py
@@ -40,7 +40,7 @@
 thread #1: tid = 3842849
   Raw trace size: 4 KiB
   Total number of instructions: 21
-  Total approximate memory usage: 0.98 KiB
-  Average memory usage per instruction: 48.00 bytes
+  Total approximate memory usage: 0.27 KiB
+  Average memory usage per instruction: 13.00 bytes
 
   Number of TSC decoding errors: 0'''])
Index: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
===
--- lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
+++ lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
@@ -112,7 +112,7 @@
   }
   s << "\n";
   DecodedThreadSP decoded_trace_sp = Decode(thread);
-  size_t insn_len = decoded_trace_sp->GetInstructions().size();
+  size_t insn_len = decoded_trace_sp->GetInstructionsCount();
   size_t mem_used = decoded_trace_sp->CalculateApproximateMemoryUsage();
 
   s.Format("  Raw trace size: {0} KiB\n", *raw_size / 1024);
Index: lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
===
--- lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
+++ lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
@@ -20,14 +20,14 @@
 TraceCursorIntelPT::TraceCursorIntelPT(ThreadSP thread_sp,
DecodedThreadSP decoded_thread_sp)
 : TraceCursor(thread_sp), m_decoded_thread_sp(decoded_thread_sp) {
-  assert(!m_decoded_thread_sp->GetInstructions().empty() &&
+  assert(m_decoded_thread_sp->GetInstructionsCount() > 0 &&
  "a trace should have at least one instruction or error");
-  m_pos = m_decoded_thread_sp->GetInstructions().size() - 1;
+  m_pos = m_decoded_thread_sp->GetInstructionsCount() - 1;
   m_tsc_range = m_decoded_thread_sp->CalculateTscRange(m_pos);
 }
 
 size_t TraceCursorIntelPT::GetInternalInstructionSize() {
-  return m_decoded_thread_sp->GetInstructions().size();
+  return m_decoded_thread_sp->GetInstructionsCount();
 }
 
 bool TraceCursorIntelPT::Next() {
@@ -78,8 +78,8 @@
   return std::abs(dist);
 }
   };
-  
-	int64_t dist = FindDistanceAndSetPos();
+
+  int64_t dist = FindDistanceAndSetPos();
   m_tsc_range = m_decoded_thread_sp->CalculateTscRange(m_pos);
   return dist;
 }
@@ -93,7 +93,7 @@
 }
 
 lldb::addr_t TraceCursorIntelPT::GetLoadAddress() {
-  return m_decoded_thread_sp->GetInstructions()[m_pos].GetLoadAddress();
+  return m_decoded_thread_sp->GetInstructionLoadAddress(m_pos);
 }
 
 Optional
@@ -109,10 +109,5 @@
 
 TraceInstructionControlFlowType
 TraceCursorIntelPT::GetInstructionControlFlowType() {
-  lldb::addr_t next_load_address =
-  m_pos + 1 < GetInternalInstructionSize()
-  ? m_decoded_thread_sp->GetInstructions()[m_pos + 1].GetLoadAddress()
-  : LLDB_INVALID_ADDRESS;
-  return m_decoded_thread_sp->GetInstructions()[m_pos].GetControlFlowType(
-  next_load_address);
+  return m_decoded_thread_sp->GetInstructionControlFlowType(m_pos);
 }
Index: lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
===
--- lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
+++ lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
@@ -51,61 +51,6 @@
   lldb::addr_t m_address;
 };
 
-/// \class IntelPTInstruction
-/// An instruction obtained from decoding a trace. It is either an actual
-/// instruction or an error indicating a gap in the trace.
-///
-/// Gaps in the trace can come in a few flavors:
-///   - tracing gaps (e.g. trac

[Lldb-commits] [PATCH] D122991: [lldb][intelpt] Remove `IntelPTInstruction` and move methods to `DecodedThread`

2022-04-05 Thread walter erquinigo via Phabricator via lldb-commits
wallace accepted this revision.
wallace added a comment.
This revision is now accepted and ready to land.

great job!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122991

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


[Lldb-commits] [PATCH] D123025: [lldb-vscode] Implement stderr/stdout on win32 and redirect lldb log to VSCode

2022-04-05 Thread walter erquinigo via Phabricator via lldb-commits
wallace accepted this revision.
wallace added a comment.
This revision is now accepted and ready to land.

thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123025

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


[Lldb-commits] [PATCH] D123025: [lldb-vscode] Implement stderr/stdout on win32 and redirect lldb log to VSCode

2022-04-05 Thread walter erquinigo via Phabricator via lldb-commits
wallace added a comment.

Let me know if you need help upstreaming this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123025

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


[Lldb-commits] [lldb] d849959 - [lldb][intelpt] Remove `IntelPTInstruction` and move methods to `DecodedThread`

2022-04-05 Thread Alisamar Husain via lldb-commits

Author: Alisamar Husain
Date: 2022-04-05T22:01:36+05:30
New Revision: d849959071c8478841a9e7b1bb625e00b848f1c7

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

LOG: [lldb][intelpt] Remove `IntelPTInstruction` and move methods to 
`DecodedThread`

This is to reduce the size of the trace further and has appreciable results.

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

Added: 


Modified: 
lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
lldb/test/API/commands/trace/TestTraceDumpInfo.py
lldb/test/API/commands/trace/TestTraceLoad.py

Removed: 




diff  --git a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp 
b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
index 994d068810f1e..a4bf0c725f7e6 100644
--- a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
@@ -35,38 +35,37 @@ void IntelPTError::log(llvm::raw_ostream &OS) const {
   OS << "error: " << libipt_error_message;
 }
 
-IntelPTInstruction::IntelPTInstruction() {
-  m_pt_insn.ip = LLDB_INVALID_ADDRESS;
-  m_pt_insn.iclass = ptic_error;
-  m_is_error = true;
+Optional DecodedThread::GetRawTraceSize() const {
+  return m_raw_trace_size;
 }
 
-bool IntelPTInstruction::IsError() const { return m_is_error; }
-
-lldb::addr_t IntelPTInstruction::GetLoadAddress() const { return m_pt_insn.ip; 
}
-
-size_t IntelPTInstruction::GetMemoryUsage() {
-  return sizeof(IntelPTInstruction);
+size_t DecodedThread::GetInstructionsCount() const {
+  return m_instruction_ips.size();
 }
 
-Optional DecodedThread::GetRawTraceSize() const {
-  return m_raw_trace_size;
+lldb::addr_t DecodedThread::GetInstructionLoadAddress(size_t insn_index) const 
{
+  return m_instruction_ips[insn_index];
 }
 
 TraceInstructionControlFlowType
-IntelPTInstruction::GetControlFlowType(lldb::addr_t next_load_address) const {
-  if (IsError())
+DecodedThread::GetInstructionControlFlowType(size_t insn_index) const {
+  if (IsInstructionAnError(insn_index))
 return (TraceInstructionControlFlowType)0;
 
   TraceInstructionControlFlowType mask =
   eTraceInstructionControlFlowTypeInstruction;
 
-  switch (m_pt_insn.iclass) {
+  lldb::addr_t load_address = m_instruction_ips[insn_index];
+  uint8_t insn_byte_size = m_instruction_sizes[insn_index];
+  pt_insn_class iclass = m_instruction_classes[insn_index];
+
+  switch (iclass) {
   case ptic_cond_jump:
   case ptic_jump:
   case ptic_far_jump:
 mask |= eTraceInstructionControlFlowTypeBranch;
-if (m_pt_insn.ip + m_pt_insn.size != next_load_address)
+if (insn_index + 1 < m_instruction_ips.size() &&
+load_address + insn_byte_size != m_instruction_ips[insn_index + 1])
   mask |= eTraceInstructionControlFlowTypeTakenBranch;
 break;
   case ptic_return:
@@ -92,14 +91,16 @@ void DecodedThread::RecordTscForLastInstruction(uint64_t 
tsc) {
 // get a first valid TSC not in position 0. We can safely force these error
 // instructions to use the first valid TSC, so that all the trace has TSCs.
 size_t start_index =
-m_instruction_timestamps.empty() ? 0 : m_instructions.size() - 1;
+m_instruction_timestamps.empty() ? 0 : m_instruction_ips.size() - 1;
 m_instruction_timestamps.emplace(start_index, tsc);
 m_last_tsc = tsc;
   }
 }
 
 void DecodedThread::AppendInstruction(const pt_insn &insn) {
-  m_instructions.emplace_back(insn);
+  m_instruction_ips.emplace_back(insn.ip);
+  m_instruction_sizes.emplace_back(insn.size);
+  m_instruction_classes.emplace_back(insn.iclass);
 }
 
 void DecodedThread::AppendInstruction(const pt_insn &insn, uint64_t tsc) {
@@ -108,8 +109,10 @@ void DecodedThread::AppendInstruction(const pt_insn &insn, 
uint64_t tsc) {
 }
 
 void DecodedThread::AppendError(llvm::Error &&error) {
-  m_errors.try_emplace(m_instructions.size(), toString(std::move(error)));
-  m_instructions.emplace_back();
+  m_errors.try_emplace(m_instruction_ips.size(), toString(std::move(error)));
+  m_instruction_ips.emplace_back(LLDB_INVALID_ADDRESS);
+  m_instruction_sizes.emplace_back(0);
+  m_instruction_classes.emplace_back(pt_insn_class::ptic_unknown);
 }
 
 void DecodedThread::AppendError(llvm::Error &&error, uint64_t tsc) {
@@ -130,10 +133,6 @@ const DecodedThread::LibiptErrors 
&DecodedThread::GetTscErrors() const {
   return m_tsc_errors;
 }
 
-ArrayRef DecodedThread::GetInstructions() const {
-  return makeArrayRef(m_instructions);
-}
-
 Optional
 DecodedThread::CalculateTscRange(size_t insn_index) const {
   auto it = m_instruction_timestamps.upper_bound(insn_index);
@@ -144,7 +143,7 @@ DecodedThrea

[Lldb-commits] [PATCH] D122991: [lldb][intelpt] Remove `IntelPTInstruction` and move methods to `DecodedThread`

2022-04-05 Thread Alisamar Husain via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd849959071c8: [lldb][intelpt] Remove `IntelPTInstruction` 
and move methods to `DecodedThread` (authored by zrthxn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122991

Files:
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
  lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/test/API/commands/trace/TestTraceDumpInfo.py
  lldb/test/API/commands/trace/TestTraceLoad.py

Index: lldb/test/API/commands/trace/TestTraceLoad.py
===
--- lldb/test/API/commands/trace/TestTraceLoad.py
+++ lldb/test/API/commands/trace/TestTraceLoad.py
@@ -38,8 +38,10 @@
 thread #1: tid = 3842849
   Raw trace size: 4 KiB
   Total number of instructions: 21
-  Total approximate memory usage: 0.98 KiB
-  Average memory usage per instruction: 48.00 bytes'''])
+  Total approximate memory usage: 0.27 KiB
+  Average memory usage per instruction: 13.00 bytes
+
+  Number of TSC decoding errors: 0'''])
 
 def testLoadInvalidTraces(self):
 src_dir = self.getSourceDir()
Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py
===
--- lldb/test/API/commands/trace/TestTraceDumpInfo.py
+++ lldb/test/API/commands/trace/TestTraceDumpInfo.py
@@ -40,7 +40,7 @@
 thread #1: tid = 3842849
   Raw trace size: 4 KiB
   Total number of instructions: 21
-  Total approximate memory usage: 0.98 KiB
-  Average memory usage per instruction: 48.00 bytes
+  Total approximate memory usage: 0.27 KiB
+  Average memory usage per instruction: 13.00 bytes
 
   Number of TSC decoding errors: 0'''])
Index: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
===
--- lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
+++ lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
@@ -112,7 +112,7 @@
   }
   s << "\n";
   DecodedThreadSP decoded_trace_sp = Decode(thread);
-  size_t insn_len = decoded_trace_sp->GetInstructions().size();
+  size_t insn_len = decoded_trace_sp->GetInstructionsCount();
   size_t mem_used = decoded_trace_sp->CalculateApproximateMemoryUsage();
 
   s.Format("  Raw trace size: {0} KiB\n", *raw_size / 1024);
Index: lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
===
--- lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
+++ lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
@@ -20,14 +20,14 @@
 TraceCursorIntelPT::TraceCursorIntelPT(ThreadSP thread_sp,
DecodedThreadSP decoded_thread_sp)
 : TraceCursor(thread_sp), m_decoded_thread_sp(decoded_thread_sp) {
-  assert(!m_decoded_thread_sp->GetInstructions().empty() &&
+  assert(m_decoded_thread_sp->GetInstructionsCount() > 0 &&
  "a trace should have at least one instruction or error");
-  m_pos = m_decoded_thread_sp->GetInstructions().size() - 1;
+  m_pos = m_decoded_thread_sp->GetInstructionsCount() - 1;
   m_tsc_range = m_decoded_thread_sp->CalculateTscRange(m_pos);
 }
 
 size_t TraceCursorIntelPT::GetInternalInstructionSize() {
-  return m_decoded_thread_sp->GetInstructions().size();
+  return m_decoded_thread_sp->GetInstructionsCount();
 }
 
 bool TraceCursorIntelPT::Next() {
@@ -78,8 +78,8 @@
   return std::abs(dist);
 }
   };
-  
-	int64_t dist = FindDistanceAndSetPos();
+
+  int64_t dist = FindDistanceAndSetPos();
   m_tsc_range = m_decoded_thread_sp->CalculateTscRange(m_pos);
   return dist;
 }
@@ -93,7 +93,7 @@
 }
 
 lldb::addr_t TraceCursorIntelPT::GetLoadAddress() {
-  return m_decoded_thread_sp->GetInstructions()[m_pos].GetLoadAddress();
+  return m_decoded_thread_sp->GetInstructionLoadAddress(m_pos);
 }
 
 Optional
@@ -109,10 +109,5 @@
 
 TraceInstructionControlFlowType
 TraceCursorIntelPT::GetInstructionControlFlowType() {
-  lldb::addr_t next_load_address =
-  m_pos + 1 < GetInternalInstructionSize()
-  ? m_decoded_thread_sp->GetInstructions()[m_pos + 1].GetLoadAddress()
-  : LLDB_INVALID_ADDRESS;
-  return m_decoded_thread_sp->GetInstructions()[m_pos].GetControlFlowType(
-  next_load_address);
+  return m_decoded_thread_sp->GetInstructionControlFlowType(m_pos);
 }
Index: lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
===
--- lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
+++ lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
@@ -51,61 +51,6 @@
   lldb::addr_t m_address;
 };
 
-/// \class IntelPTInstruction
-/// An instruction obtained from decoding a trace. It is either an actual
-/// instruction or an error indicating a gap in the trace.
-///
-/// Gaps in

[Lldb-commits] [lldb] 73714a3 - [lldb] Fix undefined behavior: left shift of negative value

2022-04-05 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-04-05T09:37:31-07:00
New Revision: 73714a3c603c1e0656f138ad8b6ef2c4740c95f3

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

LOG: [lldb] Fix undefined behavior: left shift of negative value

Fix undefined behavior in AppleObjCRuntimeV2 where we were left shifting
a signed value. This also removes redundant casts of unobfuscated to
uint64_t which it already is.

rdar://91242879

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

Added: 


Modified: 

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index f3deafd3e2b68..e6e12a631088a 100644
--- 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -2762,11 +2762,10 @@ 
AppleObjCRuntimeV2::TaggedPointerVendorRuntimeAssisted::GetClassDescriptor(
   }
 
   uint64_t data_payload =
-  (((uint64_t)unobfuscated << m_objc_debug_taggedpointer_payload_lshift) >>
+  ((unobfuscated << m_objc_debug_taggedpointer_payload_lshift) >>
m_objc_debug_taggedpointer_payload_rshift);
   int64_t data_payload_signed =
-  ((int64_t)((int64_t)unobfuscated
- << m_objc_debug_taggedpointer_payload_lshift) >>
+  ((int64_t)(unobfuscated << m_objc_debug_taggedpointer_payload_lshift) >>
m_objc_debug_taggedpointer_payload_rshift);
   return ClassDescriptorSP(new ClassDescriptorV2Tagged(
   actual_class_descriptor_sp, data_payload, data_payload_signed));



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


[Lldb-commits] [PATCH] D123098: [lldb] Fix undefined behavior: left shift of negative value

2022-04-05 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG73714a3c603c: [lldb] Fix undefined behavior: left shift of 
negative value (authored by JDevlieghere).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D123098?vs=420342&id=420556#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123098

Files:
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp


Index: 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
===
--- 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -2762,11 +2762,10 @@
   }
 
   uint64_t data_payload =
-  (((uint64_t)unobfuscated << m_objc_debug_taggedpointer_payload_lshift) >>
+  ((unobfuscated << m_objc_debug_taggedpointer_payload_lshift) >>
m_objc_debug_taggedpointer_payload_rshift);
   int64_t data_payload_signed =
-  ((int64_t)((int64_t)unobfuscated
- << m_objc_debug_taggedpointer_payload_lshift) >>
+  ((int64_t)(unobfuscated << m_objc_debug_taggedpointer_payload_lshift) >>
m_objc_debug_taggedpointer_payload_rshift);
   return ClassDescriptorSP(new ClassDescriptorV2Tagged(
   actual_class_descriptor_sp, data_payload, data_payload_signed));


Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -2762,11 +2762,10 @@
   }
 
   uint64_t data_payload =
-  (((uint64_t)unobfuscated << m_objc_debug_taggedpointer_payload_lshift) >>
+  ((unobfuscated << m_objc_debug_taggedpointer_payload_lshift) >>
m_objc_debug_taggedpointer_payload_rshift);
   int64_t data_payload_signed =
-  ((int64_t)((int64_t)unobfuscated
- << m_objc_debug_taggedpointer_payload_lshift) >>
+  ((int64_t)(unobfuscated << m_objc_debug_taggedpointer_payload_lshift) >>
m_objc_debug_taggedpointer_payload_rshift);
   return ClassDescriptorSP(new ClassDescriptorV2Tagged(
   actual_class_descriptor_sp, data_payload, data_payload_signed));
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 8c3a6fe - Fix a mistyping introduced with the new container command.

2022-04-05 Thread Jim Ingham via lldb-commits

Author: Jim Ingham
Date: 2022-04-05T09:42:05-07:00
New Revision: 8c3a6fe37fc36537b939ea75a59fb2d5963246fb

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

LOG: Fix a mistyping introduced with the new container command.

I also added a call to help in the test which was crashing before
the test, and not after.

Added: 


Modified: 
lldb/source/Interpreter/CommandInterpreter.cpp
lldb/test/API/commands/command/container/TestContainerCommands.py

Removed: 




diff  --git a/lldb/source/Interpreter/CommandInterpreter.cpp 
b/lldb/source/Interpreter/CommandInterpreter.cpp
index f9ba5c3d2a2ea..760a33ac09295 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -1445,7 +1445,7 @@ void CommandInterpreter::GetHelp(CommandReturnObject 
&result,
 result.AppendMessage("Current user-defined container commands:");
 result.AppendMessage("");
 max_len = FindLongestCommandWord(m_user_mw_dict);
-for (pos = m_user_dict.begin(); pos != m_user_mw_dict.end(); ++pos) {
+for (pos = m_user_mw_dict.begin(); pos != m_user_mw_dict.end(); ++pos) {
   OutputFormattedHelpText(result.GetOutputStream(), pos->first, "--",
   pos->second->GetHelp(), max_len);
 }

diff  --git a/lldb/test/API/commands/command/container/TestContainerCommands.py 
b/lldb/test/API/commands/command/container/TestContainerCommands.py
index 3bfb3ec62ad63..7fcb361d50da0 100644
--- a/lldb/test/API/commands/command/container/TestContainerCommands.py
+++ b/lldb/test/API/commands/command/container/TestContainerCommands.py
@@ -69,7 +69,9 @@ def container_add(self):
 self.expect("test-multi test-multi-sub welcome friend", "Used the new 
command class",
 substrs=["Hello friend, welcome again to LLDB"])
 self.expect("apropos welcome", "welcome should show up in apropos", 
substrs=["A docstring for the second Welcome"])
-
+self.expect("help test-multi test-multi-sub welcome", "welcome should 
show up in help", substrs=["A docstring for the second Welcome"])
+self.expect("help", "test-multi should show up in help", 
substrs=["test-multi"])
+
 # Now switch the default and make sure we can now delete w/o the 
overwrite option:
 self.runCmd("settings set interpreter.require-overwrite 0")
 self.runCmd("command script add -c welcome.WelcomeCommand test-multi 
test-multi-sub welcome")



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


[Lldb-commits] [lldb] e90d8f0 - [lldb] Improve documentation for some of the platform functions

2022-04-05 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-04-05T09:47:32-07:00
New Revision: e90d8f024b2b6789c1a9fed3b854c45a2db36adc

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

LOG: [lldb] Improve documentation for some of the platform functions

Improve the documentation for the platform functions that take a process
host architecture as input.

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

Added: 


Modified: 
lldb/include/lldb/Target/Platform.h

Removed: 




diff  --git a/lldb/include/lldb/Target/Platform.h 
b/lldb/include/lldb/Target/Platform.h
index 6501675cafbfe..3b02f44a7fe21 100644
--- a/lldb/include/lldb/Target/Platform.h
+++ b/lldb/include/lldb/Target/Platform.h
@@ -94,6 +94,24 @@ class Platform : public PluginInterface {
   /// attaching to processes unless another platform is specified.
   static lldb::PlatformSP GetHostPlatform();
 
+  /// Get the platform for the given architecture. See Platform::Create for how
+  /// a platform is chosen for a given architecture.
+  ///
+  /// \param[in] arch
+  /// The architecture for which we are getting a platform.
+  ///
+  /// \param[in] process_host_arch
+  /// The process host architecture if it's known. An invalid ArchSpec
+  /// represents that the process host architecture is unknown.
+  ///
+  /// \param[out] platform_arch_ptr
+  /// The architecture which was used to pick the returned platform. This
+  /// can be 
diff erent from the input architecture if we're looking for a
+  /// compatible match instead of an exact match.
+  ///
+  /// \return
+  /// Return the platform that matches the input architecture or the
+  /// default (invalid) platform if none could be found.
   static lldb::PlatformSP
   GetPlatformForArchitecture(const ArchSpec &arch,
  const ArchSpec &process_host_arch = {},
@@ -111,6 +129,26 @@ class Platform : public PluginInterface {
   /// candidates output argument 
diff erentiates between either no platforms
   /// supporting the given architecture or multiple platforms supporting the
   /// given architecture.
+  ///
+  /// \param[in] arch
+  /// The architecture for which we are getting a platform.
+  ///
+  /// \param[in] process_host_arch
+  /// The process host architecture if it's known. An invalid ArchSpec
+  /// represents that the process host architecture is unknown.
+  ///
+  /// \param[in] selected_platform_sp
+  /// The currently selected platform.
+  ///
+  /// \param[out] candidates
+  /// A list of candidate platforms in case multiple platforms could
+  /// support the given list of architectures. If no platforms match the
+  /// given architecture the list will be empty.
+  ///
+  /// \return
+  /// Return the platform that matches the input architectures or the
+  /// default (invalid) platform if no platforms support the given
+  /// architectures or multiple platforms support the given architecture.
   static lldb::PlatformSP
   GetPlatformForArchitectures(std::vector archs,
   const ArchSpec &process_host_arch,
@@ -331,6 +369,10 @@ class Platform : public PluginInterface {
 
   /// Get the platform's supported architectures in the order in which they
   /// should be searched.
+  ///
+  /// \param[in] process_host_arch
+  /// The process host architecture if it's known. An invalid ArchSpec
+  /// represents that the process host architecture is unknown.
   virtual std::vector
   GetSupportedArchitectures(const ArchSpec &process_host_arch) = 0;
 



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


[Lldb-commits] [PATCH] D122767: [lldb] Improve documentation for some of the platform functions

2022-04-05 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe90d8f024b2b: [lldb] Improve documentation for some of the 
platform functions (authored by JDevlieghere).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122767

Files:
  lldb/include/lldb/Target/Platform.h


Index: lldb/include/lldb/Target/Platform.h
===
--- lldb/include/lldb/Target/Platform.h
+++ lldb/include/lldb/Target/Platform.h
@@ -94,6 +94,24 @@
   /// attaching to processes unless another platform is specified.
   static lldb::PlatformSP GetHostPlatform();
 
+  /// Get the platform for the given architecture. See Platform::Create for how
+  /// a platform is chosen for a given architecture.
+  ///
+  /// \param[in] arch
+  /// The architecture for which we are getting a platform.
+  ///
+  /// \param[in] process_host_arch
+  /// The process host architecture if it's known. An invalid ArchSpec
+  /// represents that the process host architecture is unknown.
+  ///
+  /// \param[out] platform_arch_ptr
+  /// The architecture which was used to pick the returned platform. This
+  /// can be different from the input architecture if we're looking for a
+  /// compatible match instead of an exact match.
+  ///
+  /// \return
+  /// Return the platform that matches the input architecture or the
+  /// default (invalid) platform if none could be found.
   static lldb::PlatformSP
   GetPlatformForArchitecture(const ArchSpec &arch,
  const ArchSpec &process_host_arch = {},
@@ -111,6 +129,26 @@
   /// candidates output argument differentiates between either no platforms
   /// supporting the given architecture or multiple platforms supporting the
   /// given architecture.
+  ///
+  /// \param[in] arch
+  /// The architecture for which we are getting a platform.
+  ///
+  /// \param[in] process_host_arch
+  /// The process host architecture if it's known. An invalid ArchSpec
+  /// represents that the process host architecture is unknown.
+  ///
+  /// \param[in] selected_platform_sp
+  /// The currently selected platform.
+  ///
+  /// \param[out] candidates
+  /// A list of candidate platforms in case multiple platforms could
+  /// support the given list of architectures. If no platforms match the
+  /// given architecture the list will be empty.
+  ///
+  /// \return
+  /// Return the platform that matches the input architectures or the
+  /// default (invalid) platform if no platforms support the given
+  /// architectures or multiple platforms support the given architecture.
   static lldb::PlatformSP
   GetPlatformForArchitectures(std::vector archs,
   const ArchSpec &process_host_arch,
@@ -331,6 +369,10 @@
 
   /// Get the platform's supported architectures in the order in which they
   /// should be searched.
+  ///
+  /// \param[in] process_host_arch
+  /// The process host architecture if it's known. An invalid ArchSpec
+  /// represents that the process host architecture is unknown.
   virtual std::vector
   GetSupportedArchitectures(const ArchSpec &process_host_arch) = 0;
 


Index: lldb/include/lldb/Target/Platform.h
===
--- lldb/include/lldb/Target/Platform.h
+++ lldb/include/lldb/Target/Platform.h
@@ -94,6 +94,24 @@
   /// attaching to processes unless another platform is specified.
   static lldb::PlatformSP GetHostPlatform();
 
+  /// Get the platform for the given architecture. See Platform::Create for how
+  /// a platform is chosen for a given architecture.
+  ///
+  /// \param[in] arch
+  /// The architecture for which we are getting a platform.
+  ///
+  /// \param[in] process_host_arch
+  /// The process host architecture if it's known. An invalid ArchSpec
+  /// represents that the process host architecture is unknown.
+  ///
+  /// \param[out] platform_arch_ptr
+  /// The architecture which was used to pick the returned platform. This
+  /// can be different from the input architecture if we're looking for a
+  /// compatible match instead of an exact match.
+  ///
+  /// \return
+  /// Return the platform that matches the input architecture or the
+  /// default (invalid) platform if none could be found.
   static lldb::PlatformSP
   GetPlatformForArchitecture(const ArchSpec &arch,
  const ArchSpec &process_host_arch = {},
@@ -111,6 +129,26 @@
   /// candidates output argument differentiates between either no platforms
   /// supporting the given architecture or multiple platforms supporting the
   /// given architecture.
+  ///
+  /// \param[in] arch
+  /// The architecture 

[Lldb-commits] [PATCH] D123025: [lldb-vscode] Implement stderr/stdout on win32 and redirect lldb log to VSCode

2022-04-05 Thread Michael Hept via Phabricator via lldb-commits
nidefawl added a comment.

In D123025#3429896 , @wallace wrote:

> Let me know if you need help upstreaming this patch.

Yes I needs some help. 
This is my first contribution. I don't have commit access.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123025

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


[Lldb-commits] [PATCH] D123025: [lldb-vscode] Implement stderr/stdout on win32 and redirect lldb log to VSCode

2022-04-05 Thread walter erquinigo via Phabricator via lldb-commits
wallace added a comment.

ok! I'll commit it for you


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123025

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


[Lldb-commits] [PATCH] D122856: [lldb] Refactor DataBuffer so we can map files as read-only

2022-04-05 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 420589.
JDevlieghere added a comment.
Herald added a subscriber: mgorny.

- Copy the buffer if ObjectFileELF didn't map it
- Use LLVM style RTTI


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

https://reviews.llvm.org/D122856

Files:
  lldb/include/lldb/Core/ValueObject.h
  lldb/include/lldb/Host/FileSystem.h
  lldb/include/lldb/Symbol/CompactUnwindInfo.h
  lldb/include/lldb/Symbol/ObjectFile.h
  lldb/include/lldb/Target/ProcessStructReader.h
  lldb/include/lldb/Target/RegisterCheckpoint.h
  lldb/include/lldb/Target/RegisterContext.h
  lldb/include/lldb/Target/RegisterContextUnwind.h
  lldb/include/lldb/Utility/DataBuffer.h
  lldb/include/lldb/Utility/DataBufferHeap.h
  lldb/include/lldb/Utility/DataBufferLLVM.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/Commands/CommandObjectMemory.cpp
  lldb/source/Core/SourceManager.cpp
  lldb/source/Core/ValueObject.cpp
  lldb/source/DataFormatters/StringPrinter.cpp
  lldb/source/DataFormatters/TypeFormat.cpp
  lldb/source/Expression/IRExecutionUnit.cpp
  lldb/source/Host/common/FileSystem.cpp
  lldb/source/Host/common/Host.cpp
  lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp
  lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp
  lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
  lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
  lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp
  lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp
  lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp
  lldb/source/Plugins/Language/ObjC/CF.cpp
  lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
  lldb/source/Plugins/Language/ObjC/NSSet.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
  
lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
  lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
  lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.h
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.h
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.h
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.h
  lldb/source/Plugins/Process/Utility/RegisterContextDummy.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDummy.h
  lldb/source/Plugins/Process/Utility/RegisterContextHistory.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextHistory.h
  lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextMemory.h
  lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_32.cpp
  lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp
  lldb/source/Symbol/ObjectFile.cpp
  lldb/source/Target/Platform.cpp
  lldb/source/Target/RegisterContextUnwind.cpp
  lldb/source/Utility/DataBufferHeap.cpp
  lldb/source/Utility/DataBufferLLVM.cpp
  lldb/unittests/Utility/CMakeLists.txt
  lldb/unittests/Utility/DataBufferTest.cpp

Index: lldb/unittests/Utility/DataBufferTest.cpp
=

[Lldb-commits] [lldb] 9bcaf6d - [lldb-vscode] Implement stderr/stdout on win32 and redirect lldb log to VSCode

2022-04-05 Thread Walter Erquinigo via lldb-commits

Author: Walter Erquinigo
Date: 2022-04-05T11:54:03-07:00
New Revision: 9bcaf6ddfe34943e6ae6a319097524c117908913

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

LOG: [lldb-vscode] Implement stderr/stdout on win32 and redirect lldb log to 
VSCode

This patch implements stderr/stdout forwarding on windows.
This was previously not implemented in D99974.
I added separate callbacks so the output can be sent to the different channels 
VSCode provides (OutputType::Stdout, OutputType::Stderr, OutputType::Console).

This patch also passes a log callback handler to SBDebugger::Create to be able 
to see logging output when it is enabled.

Since the output is now redirect on early startup I removed the calls to 
SetOutputFileHandle/SetErrorFileHandle, which set them to /dev/null.

I send the output of stderr/stdout/lldb log to OutputType::Console

Reviewed By: wallace

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

Added: 


Modified: 
lldb/tools/lldb-vscode/OutputRedirector.cpp
lldb/tools/lldb-vscode/lldb-vscode.cpp

Removed: 




diff  --git a/lldb/tools/lldb-vscode/OutputRedirector.cpp 
b/lldb/tools/lldb-vscode/OutputRedirector.cpp
index 7432a828d045b..9243915f7d787 100644
--- a/lldb/tools/lldb-vscode/OutputRedirector.cpp
+++ b/lldb/tools/lldb-vscode/OutputRedirector.cpp
@@ -6,20 +6,27 @@
 //
 //===--===/
 
-#if !defined(_WIN32)
+#if defined(_WIN32)
+#include 
+#include 
+#else
 #include 
 #endif
 
 #include "OutputRedirector.h"
+#include "llvm/ADT/StringRef.h"
 
 using namespace llvm;
 
 namespace lldb_vscode {
 
 Error RedirectFd(int fd, std::function callback) {
-#if !defined(_WIN32)
   int new_fd[2];
+#if defined(_WIN32)
+  if (_pipe(new_fd, 4096, O_TEXT) == -1) {
+#else
   if (pipe(new_fd) == -1) {
+#endif
 int error = errno;
 return createStringError(inconvertibleErrorCode(),
  "Couldn't create new pipe for fd %d. %s", fd,
@@ -45,11 +52,10 @@ Error RedirectFd(int fd, 
std::function callback) {
   continue;
 break;
   }
-  callback(StringRef(buffer, bytes_count).str());
+  callback(StringRef(buffer, bytes_count));
 }
   });
   t.detach();
-#endif
   return Error::success();
 }
 

diff  --git a/lldb/tools/lldb-vscode/lldb-vscode.cpp 
b/lldb/tools/lldb-vscode/lldb-vscode.cpp
index 83a9762df6040..869c125ec0340 100644
--- a/lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ b/lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -65,11 +65,6 @@
 #define PATH_MAX MAX_PATH
 #endif
 typedef int socklen_t;
-constexpr const char *dev_null_path = "nul";
-
-#else
-constexpr const char *dev_null_path = "/dev/null";
-
 #endif
 
 using namespace lldb_vscode;
@@ -1446,23 +1441,13 @@ void request_modules(const llvm::json::Object &request) 
{
 //   }]
 // }
 void request_initialize(const llvm::json::Object &request) {
-  g_vsc.debugger = lldb::SBDebugger::Create(true /*source_init_files*/);
+  auto log_cb = [](const char *buf, void *baton) -> void {
+g_vsc.SendOutput(OutputType::Console, llvm::StringRef{buf});
+  };
+  g_vsc.debugger =
+  lldb::SBDebugger::Create(true /*source_init_files*/, log_cb, nullptr);
   g_vsc.progress_event_thread = std::thread(ProgressEventThreadFunction);
 
-  // Create an empty target right away since we might get breakpoint requests
-  // before we are given an executable to launch in a "launch" request, or a
-  // executable when attaching to a process by process ID in a "attach"
-  // request.
-  FILE *out = llvm::sys::RetryAfterSignal(nullptr, fopen, dev_null_path, "w");
-  if (out) {
-// Set the output and error file handles to redirect into nothing otherwise
-// if any code in LLDB prints to the debugger file handles, the output and
-// error file handles are initialized to STDOUT and STDERR and any output
-// will kill our debug session.
-g_vsc.debugger.SetOutputFileHandle(out, true);
-g_vsc.debugger.SetErrorFileHandle(out, false);
-  }
-
   // Start our event thread so we can receive events from the debugger, target,
   // process and more.
   g_vsc.event_thread = std::thread(EventThreadFunction);
@@ -3147,18 +3132,25 @@ void redirection_test() {
 /// \return
 /// A fd pointing to the original stdout.
 int SetupStdoutStderrRedirection() {
-  int new_stdout_fd = dup(fileno(stdout));
-  auto stdout_err_redirector_callback = [&](llvm::StringRef data) {
-g_vsc.SendOutput(OutputType::Console, data);
+  int stdoutfd = fileno(stdout);
+  int new_stdout_fd = dup(stdoutfd);
+  auto output_callback_stderr = [](llvm::StringRef data) {
+g_vsc.SendOutput(OutputType::Stderr, data);
   };
-
-  for (int fd : {fileno(stdout), fileno(stderr)}) {
-if (llvm::Error err = RedirectFd(fd, stdout_err_redirector_

[Lldb-commits] [PATCH] D123025: [lldb-vscode] Implement stderr/stdout on win32 and redirect lldb log to VSCode

2022-04-05 Thread Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9bcaf6ddfe34: [lldb-vscode] Implement stderr/stdout on win32 
and redirect lldb log to VSCode (authored by Walter Erquinigo 
).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123025

Files:
  lldb/tools/lldb-vscode/OutputRedirector.cpp
  lldb/tools/lldb-vscode/lldb-vscode.cpp

Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -65,11 +65,6 @@
 #define PATH_MAX MAX_PATH
 #endif
 typedef int socklen_t;
-constexpr const char *dev_null_path = "nul";
-
-#else
-constexpr const char *dev_null_path = "/dev/null";
-
 #endif
 
 using namespace lldb_vscode;
@@ -1446,23 +1441,13 @@
 //   }]
 // }
 void request_initialize(const llvm::json::Object &request) {
-  g_vsc.debugger = lldb::SBDebugger::Create(true /*source_init_files*/);
+  auto log_cb = [](const char *buf, void *baton) -> void {
+g_vsc.SendOutput(OutputType::Console, llvm::StringRef{buf});
+  };
+  g_vsc.debugger =
+  lldb::SBDebugger::Create(true /*source_init_files*/, log_cb, nullptr);
   g_vsc.progress_event_thread = std::thread(ProgressEventThreadFunction);
 
-  // Create an empty target right away since we might get breakpoint requests
-  // before we are given an executable to launch in a "launch" request, or a
-  // executable when attaching to a process by process ID in a "attach"
-  // request.
-  FILE *out = llvm::sys::RetryAfterSignal(nullptr, fopen, dev_null_path, "w");
-  if (out) {
-// Set the output and error file handles to redirect into nothing otherwise
-// if any code in LLDB prints to the debugger file handles, the output and
-// error file handles are initialized to STDOUT and STDERR and any output
-// will kill our debug session.
-g_vsc.debugger.SetOutputFileHandle(out, true);
-g_vsc.debugger.SetErrorFileHandle(out, false);
-  }
-
   // Start our event thread so we can receive events from the debugger, target,
   // process and more.
   g_vsc.event_thread = std::thread(EventThreadFunction);
@@ -3147,18 +3132,25 @@
 /// \return
 /// A fd pointing to the original stdout.
 int SetupStdoutStderrRedirection() {
-  int new_stdout_fd = dup(fileno(stdout));
-  auto stdout_err_redirector_callback = [&](llvm::StringRef data) {
-g_vsc.SendOutput(OutputType::Console, data);
+  int stdoutfd = fileno(stdout);
+  int new_stdout_fd = dup(stdoutfd);
+  auto output_callback_stderr = [](llvm::StringRef data) {
+g_vsc.SendOutput(OutputType::Stderr, data);
   };
-
-  for (int fd : {fileno(stdout), fileno(stderr)}) {
-if (llvm::Error err = RedirectFd(fd, stdout_err_redirector_callback)) {
-  std::string error_message = llvm::toString(std::move(err));
-  if (g_vsc.log)
-*g_vsc.log << error_message << std::endl;
-  stdout_err_redirector_callback(error_message);
-}
+  auto output_callback_stdout = [](llvm::StringRef data) {
+g_vsc.SendOutput(OutputType::Stdout, data);
+  };
+  if (llvm::Error err = RedirectFd(stdoutfd, output_callback_stdout)) {
+std::string error_message = llvm::toString(std::move(err));
+if (g_vsc.log)
+  *g_vsc.log << error_message << std::endl;
+output_callback_stderr(error_message);
+  }
+  if (llvm::Error err = RedirectFd(fileno(stderr), output_callback_stderr)) {
+std::string error_message = llvm::toString(std::move(err));
+if (g_vsc.log)
+  *g_vsc.log << error_message << std::endl;
+output_callback_stderr(error_message);
   }
 
   /// used only by TestVSCode_redirection_to_console.py
Index: lldb/tools/lldb-vscode/OutputRedirector.cpp
===
--- lldb/tools/lldb-vscode/OutputRedirector.cpp
+++ lldb/tools/lldb-vscode/OutputRedirector.cpp
@@ -6,20 +6,27 @@
 //
 //===--===/
 
-#if !defined(_WIN32)
+#if defined(_WIN32)
+#include 
+#include 
+#else
 #include 
 #endif
 
 #include "OutputRedirector.h"
+#include "llvm/ADT/StringRef.h"
 
 using namespace llvm;
 
 namespace lldb_vscode {
 
 Error RedirectFd(int fd, std::function callback) {
-#if !defined(_WIN32)
   int new_fd[2];
+#if defined(_WIN32)
+  if (_pipe(new_fd, 4096, O_TEXT) == -1) {
+#else
   if (pipe(new_fd) == -1) {
+#endif
 int error = errno;
 return createStringError(inconvertibleErrorCode(),
  "Couldn't create new pipe for fd %d. %s", fd,
@@ -45,11 +52,10 @@
   continue;
 break;
   }
-  callback(StringRef(buffer, bytes_count).str());
+  callback(StringRef(buffer, bytes_count));
 }
   });
   t.detach();
-#endif
   return Error::success();
 }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org

[Lldb-commits] [PATCH] D120810: [lldb] Remove the global platform list

2022-04-05 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

Still LGTM. Apologies for the new rebase conflict introduced by e90d8f024b2b 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120810

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


[Lldb-commits] [PATCH] D122856: [lldb] Refactor DataBuffer so we can map files as read-only

2022-04-05 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added a comment.
This revision is now accepted and ready to land.

Looks good. Thanks for your patience.




Comment at: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:2636-2638
+  assert(llvm::isa(data_buffer_sp.get()));
+  WritableDataBuffer *data_buffer =
+  static_cast(data_buffer_sp.get());

use llvm::cast instead.


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

https://reviews.llvm.org/D122856

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


[Lldb-commits] [lldb] ee39417 - Refine memory buffer for importing shared cache objc class list

2022-04-05 Thread Jason Molenda via lldb-commits

Author: Jason Molenda
Date: 2022-04-05T12:49:40-07:00
New Revision: ee394177e6b797917e4d8e0d786d84046599d2c5

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

LOG: Refine memory buffer for importing shared cache objc class list

In https://reviews.llvm.org/D118972 I increased this buffer to be
big enough to import 261,144 classes but this is a lot more than
we currently have, an allocating a too-large buffer can add memory
pressure even if it's only for a short time.  Reduce the size of
this memory buffer to big enough to import 163,840 classes.  I'll
probably move to a scheme where we read the objc classes in chunks,
with a smaller buffer and multiple inferior function calls.

rdar://91275493

Added: 


Modified: 

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index e6e12a631088a..32d3527ea10c6 100644
--- 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -2010,7 +2010,8 @@ 
AppleObjCRuntimeV2::SharedCacheClassInfoExtractor::UpdateISAToDescriptorMap() {
 return DescriptorMapUpdateResult::Fail();
 
   // The number of entries to pre-allocate room for.
-  const uint32_t max_num_classes = 256 * 1024;
+  // Each entry is (addrsize + 4) bytes
+  const uint32_t max_num_classes = 163840;
 
   UtilityFunction *get_class_info_code = GetClassInfoUtilityFunction(exe_ctx);
   if (!get_class_info_code) {



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


[Lldb-commits] [PATCH] D122975: parallelize calling of Module::PreloadSymbols()

2022-04-05 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

After applying this patch I started seeing data races reported by TSan when 
running the shell tests (`check-lldb-shell`). It seems to happen to different 
tests on different runs but the backtraces are the same.

  WARNING: ThreadSanitizer: data race (pid=40880)
Read of size 1 at 0x0001139ae0a8 by thread T3 (mutexes: write M4094, write 
M119908344493401136):
  #0 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseOperatorEncoding() ItaniumDemangle.h:3033 
(liblldb.15.0.0git.dylib:arm64+0x555e668)
  #1 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseOperatorName(llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::NameState*) ItaniumDemangle.h:3060 
(liblldb.15.0.0git.dylib:arm64+0x55628dc)
  #2 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseUnqualifiedName(llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::NameState*, llvm::itanium_demangle::Node*, 
llvm::itanium_demangle::ModuleName*) ItaniumDemangle.h:2803 
(liblldb.15.0.0git.dylib:arm64+0x5559ff0)
  #3 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseName(llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::NameState*) ItaniumDemangle.h:2666 
(liblldb.15.0.0git.dylib:arm64+0x5556c08)
  #4 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseEncoding() ItaniumDemangle.h:5038 
(liblldb.15.0.0git.dylib:arm64+0x555108c)
  #5 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parse() ItaniumDemangle.h:5449 
(liblldb.15.0.0git.dylib:arm64+0x554b9b0)
  #6 llvm::ItaniumPartialDemangler::partialDemangle(char const*) 
ItaniumDemangle.cpp:385 (liblldb.15.0.0git.dylib:arm64+0x554c2a0)
  #7 
lldb_private::RichManglingContext::FromItaniumName(lldb_private::ConstString) 
RichManglingContext.cpp:42 (liblldb.15.0.0git.dylib:arm64+0x2df084)
  #8 
lldb_private::Mangled::GetRichManglingInfo(lldb_private::RichManglingContext&, 
bool (*)(llvm::StringRef, lldb_private::Mangled::ManglingScheme)) 
Mangled.cpp:217 (liblldb.15.0.0git.dylib:arm64+0x2bfec4)
  #9 lldb_private::Symtab::InitNameIndexes() Symtab.cpp:331 
(liblldb.15.0.0git.dylib:arm64+0x41aaa0)
  #10 lldb_private::Symtab::PreloadSymbols() Symtab.cpp:456 
(liblldb.15.0.0git.dylib:arm64+0x41ba4c)
  #11 lldb_private::Module::PreloadSymbols() Module.cpp:1378 
(liblldb.15.0.0git.dylib:arm64+0x2c74d4)
  #12 
std::__1::__function::__func, 
std::__1::allocator >, void ()>::operator()() function.h:352 
(liblldb.15.0.0git.dylib:arm64+0x4d73e0)
  #13 
std::__1::__function::__func)::'lambda'(), 
std::__1::allocator)::'lambda'()>, void ()>::operator()() function.h:352 
(liblldb.15.0.0git.dylib:arm64+0x4d6920)
  #14 void* 
llvm::thread::ThreadProxy 
>(void*) thread.h:60 (liblldb.15.0.0git.dylib:arm64+0x9daa0c)
  
Previous write of size 1 at 0x0001139ae0a8 by thread T6 (mutexes: write 
M26458652249517616, write M208572962157285296):
  #0 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseOperatorEncoding() ItaniumDemangle.h:3034 
(liblldb.15.0.0git.dylib:arm64+0x555e720)
  #1 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseOperatorName(llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::NameState*) ItaniumDemangle.h:3060 
(liblldb.15.0.0git.dylib:arm64+0x55628dc)
  #2 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseUnqualifiedName(llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::NameState*, llvm::itanium_demangle::Node*, 
llvm::itanium_demangle::ModuleName*) ItaniumDemangle.h:2803 
(liblldb.15.0.0git.dylib:arm64+0x5559ff0)
  #3 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseName(llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::NameState*) ItaniumDemangle.h:2666 
(liblldb.15.0.0git.dylib:arm64+0x5556c08)
  #4 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parseEncoding() ItaniumDemangle.h:5038 
(liblldb.15.0.0git.dylib:arm64+0x555108c)
  #5 
llvm::itanium_demangle::AbstractManglingParser, (anonymous 
namespace)::DefaultAllocator>::parse() ItaniumDemangle.h:5449 
(liblldb.15.0.0git.dylib:arm64+0x554b9b0)
  #6 llvm::ItaniumPartialDemangler::partialDemangle(char const*) 
ItaniumDemangle.cpp:385 (liblldb.15.0.0git.dylib:arm64+0x554c2a0)
  #7 
lldb_private::RichManglingContext::FromItaniumName(lldb_private::ConstString) 
RichManglingContext.cpp:42 (liblldb.15.0.0git.dy

[Lldb-commits] [lldb] f2ea125 - [lldb] Change CreateMemoryInstance to take a WritableDataBuffer

2022-04-05 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-04-05T13:46:41-07:00
New Revision: f2ea125ea09d9e4512fa08a89eac5e0069d83738

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

LOG: [lldb] Change CreateMemoryInstance to take a WritableDataBuffer

Change the CreateMemoryInstance interface to take a WritableDataBuffer.

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

Added: 


Modified: 
lldb/include/lldb/Symbol/ObjectFile.h
lldb/include/lldb/lldb-private-interfaces.h
lldb/source/Core/Module.cpp
lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp
lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h
lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.h
lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.h
lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.h
lldb/source/Symbol/ObjectFile.cpp

Removed: 




diff  --git a/lldb/include/lldb/Symbol/ObjectFile.h 
b/lldb/include/lldb/Symbol/ObjectFile.h
index 73202a2d6ec55..c61e3c138944a 100644
--- a/lldb/include/lldb/Symbol/ObjectFile.h
+++ b/lldb/include/lldb/Symbol/ObjectFile.h
@@ -116,10 +116,10 @@ class ObjectFile : public 
std::enable_shared_from_this,
   /// more than one architecture or object.
   ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr,
  lldb::offset_t file_offset, lldb::offset_t length,
- const lldb::DataBufferSP &data_sp, lldb::offset_t data_offset);
+ lldb::DataBufferSP data_sp, lldb::offset_t data_offset);
 
   ObjectFile(const lldb::ModuleSP &module_sp, const lldb::ProcessSP 
&process_sp,
- lldb::addr_t header_addr, lldb::DataBufferSP &data_sp);
+ lldb::addr_t header_addr, lldb::DataBufferSP data_sp);
 
   /// Destructor.
   ///
@@ -183,7 +183,7 @@ class ObjectFile : public 
std::enable_shared_from_this,
   static lldb::ObjectFileSP FindPlugin(const lldb::ModuleSP &module_sp,
const lldb::ProcessSP &process_sp,
lldb::addr_t header_addr,
-   lldb::DataBufferSP &file_data_sp);
+   lldb::WritableDataBufferSP 
file_data_sp);
 
   static size_t
   GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset,

diff  --git a/lldb/include/lldb/lldb-private-interfaces.h 
b/lldb/include/lldb/lldb-private-interfaces.h
index 33b902b378f18..426fede9a7433 100644
--- a/lldb/include/lldb/lldb-private-interfaces.h
+++ b/lldb/include/lldb/lldb-private-interfaces.h
@@ -51,7 +51,7 @@ typedef ObjectFile *(*ObjectFileCreateInstance)(const 
lldb::ModuleSP &module_sp,
 lldb::offset_t file_offset,
 lldb::offset_t length);
 typedef ObjectFile *(*ObjectFileCreateMemoryInstance)(
-const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp,
+const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
 const lldb::ProcessSP &process_sp, lldb::addr_t offset);
 typedef bool (*ObjectFileSaveCore)(const lldb::ProcessSP &process_sp,
const FileSpec &outfile,

diff  --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index 8dbbac7187edd..3adfefb6e37d7 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -304,15 +304,15 @@ ObjectFile *Module::GetMemoryObjectFile(const 
lldb::ProcessSP &process_sp,
 std::lock_guard guard(m_mutex);
 if (process_sp) {
   m_did_load_objfile = true;
-  auto data_up = std::make_unique(size_to_read, 0);
+  std::shared_ptr data_sp =
+  std::make_shared(size_to_read, 0);
   Status readmem_error;
   const size_t bytes_read =
-  process_sp->ReadMemory(header_addr, data_up->GetBytes(),
- data_up->GetByteSize(), readmem_error);
+  process_sp->ReadMemory(header_addr, data_sp->GetBytes(),
+ data_sp->GetByteSize(), readmem_error);
   if (bytes_read < size_to_read)
-data_up->SetByteSize(

[Lldb-commits] [lldb] fc54427 - [lldb] Refactor DataBuffer so we can map files as read-only

2022-04-05 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-04-05T13:46:37-07:00
New Revision: fc54427e76c89e567390dd4a1d64a65568f4ec26

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

LOG: [lldb] Refactor DataBuffer so we can map files as read-only

Currently, all data buffers are assumed to be writable. This is a
problem on macOS where it's not allowed to load unsigned binaries in
memory as writable. To be more precise, MAP_RESILIENT_CODESIGN and
MAP_RESILIENT_MEDIA need to be set for mapped (unsigned) binaries on our
platform.

Binaries are mapped through FileSystem::CreateDataBuffer which returns a
DataBufferLLVM. The latter is backed by a llvm::WritableMemoryBuffer
because every DataBuffer in LLDB is considered to be writable. In order
to use a read-only llvm::MemoryBuffer I had to split our abstraction
around it.

This patch distinguishes between a DataBuffer (read-only) and
WritableDataBuffer (read-write) and updates LLDB to use the appropriate
one.

rdar://74890607

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

Added: 
lldb/unittests/Utility/DataBufferTest.cpp

Modified: 
lldb/include/lldb/Core/ValueObject.h
lldb/include/lldb/Host/FileSystem.h
lldb/include/lldb/Symbol/CompactUnwindInfo.h
lldb/include/lldb/Symbol/ObjectFile.h
lldb/include/lldb/Target/ProcessStructReader.h
lldb/include/lldb/Target/RegisterCheckpoint.h
lldb/include/lldb/Target/RegisterContext.h
lldb/include/lldb/Target/RegisterContextUnwind.h
lldb/include/lldb/Utility/DataBuffer.h
lldb/include/lldb/Utility/DataBufferHeap.h
lldb/include/lldb/Utility/DataBufferLLVM.h
lldb/include/lldb/lldb-forward.h
lldb/source/Commands/CommandObjectMemory.cpp
lldb/source/Core/SourceManager.cpp
lldb/source/Core/ValueObject.cpp
lldb/source/DataFormatters/StringPrinter.cpp
lldb/source/DataFormatters/TypeFormat.cpp
lldb/source/Expression/IRExecutionUnit.cpp
lldb/source/Host/common/FileSystem.cpp
lldb/source/Host/common/Host.cpp
lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp
lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp
lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp
lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp
lldb/source/Plugins/Language/ObjC/CF.cpp
lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
lldb/source/Plugins/Language/ObjC/NSSet.cpp

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp

lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.h
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.h
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.h
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.h
lldb/source/Plugins/Process/Utility/RegisterContextDummy.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDummy.h
lldb/source/Plugins/Process/Utility/RegisterContextHistory.cpp
lldb/source/Plugins/Process/Utility/RegisterContextHistory.h
lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp
lldb/source/Plugins/Process/Utility/RegisterContextMemory.h
lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp
lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.cpp
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.h
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.cpp
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.h
lldb/source/Plugins

[Lldb-commits] [PATCH] D123073: [lldb] Change CreateMemoryInstance to take a WritableDataBuffer

2022-04-05 Thread Jonas Devlieghere 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 rGf2ea125ea09d: [lldb] Change CreateMemoryInstance to take a 
WritableDataBuffer (authored by JDevlieghere).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D123073?vs=420293&id=420626#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123073

Files:
  lldb/include/lldb/Symbol/ObjectFile.h
  lldb/include/lldb/lldb-private-interfaces.h
  lldb/source/Core/Module.cpp
  lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp
  lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
  lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
  lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
  lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
  lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.h
  lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
  lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.h
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
  lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
  lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.h
  lldb/source/Symbol/ObjectFile.cpp

Index: lldb/source/Symbol/ObjectFile.cpp
===
--- lldb/source/Symbol/ObjectFile.cpp
+++ lldb/source/Symbol/ObjectFile.cpp
@@ -35,7 +35,7 @@
 static ObjectFileSP
 CreateObjectFromContainer(const lldb::ModuleSP &module_sp, const FileSpec *file,
   lldb::offset_t file_offset, lldb::offset_t file_size,
-  DataBufferSP &data_sp, lldb::offset_t &data_offset) {
+  DataBufferSP data_sp, lldb::offset_t &data_offset) {
   ObjectContainerCreateInstance callback;
   for (uint32_t idx = 0;
(callback = PluginManager::GetObjectContainerCreateCallbackAtIndex(
@@ -152,7 +152,7 @@
 ObjectFileSP ObjectFile::FindPlugin(const lldb::ModuleSP &module_sp,
 const ProcessSP &process_sp,
 lldb::addr_t header_addr,
-DataBufferSP &data_sp) {
+WritableDataBufferSP data_sp) {
   ObjectFileSP object_file_sp;
 
   if (module_sp) {
@@ -241,8 +241,7 @@
 ObjectFile::ObjectFile(const lldb::ModuleSP &module_sp,
const FileSpec *file_spec_ptr,
lldb::offset_t file_offset, lldb::offset_t length,
-   const lldb::DataBufferSP &data_sp,
-   lldb::offset_t data_offset)
+   lldb::DataBufferSP data_sp, lldb::offset_t data_offset)
 : ModuleChild(module_sp),
   m_file(), // This file could be different from the original module's file
   m_type(eTypeInvalid), m_strata(eStrataInvalid),
@@ -265,7 +264,7 @@
 
 ObjectFile::ObjectFile(const lldb::ModuleSP &module_sp,
const ProcessSP &process_sp, lldb::addr_t header_addr,
-   DataBufferSP &header_data_sp)
+   DataBufferSP header_data_sp)
 : ModuleChild(module_sp), m_file(), m_type(eTypeInvalid),
   m_strata(eStrataInvalid), m_file_offset(0), m_length(0), m_data(),
   m_process_wp(process_sp), m_memory_addr(header_addr), m_sections_up(),
Index: lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.h
===
--- lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.h
+++ lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.h
@@ -35,7 +35,7 @@
  lldb::offset_t file_offset, lldb::offset_t length);
 
   static ObjectFile *CreateMemoryInstance(const lldb::ModuleSP &module_sp,
-  lldb::DataBufferSP data_sp,
+  lldb::WritableDataBufferSP data_sp,
   const lldb::ProcessSP &process_sp,
   lldb::addr_t header_addr);
 
@@ -111,11 +111,11 @@
   llvm::Optional GetExternalDebugInfoFileSpec();
 
 private:
-  ObjectFileWasm(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
+  ObjectFileWasm(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp,
  lldb::offset_t data_offset, const FileSpec *file,
  lldb::offset_t offset, lldb::offset_t length);
   ObjectFileWasm(const lldb::ModuleSP &module_sp,
- lldb::DataBufferSP &header_data_sp,
+ lldb::WritableDataBufferSP header_data_sp,
 

[Lldb-commits] [PATCH] D122856: [lldb] Refactor DataBuffer so we can map files as read-only

2022-04-05 Thread Jonas Devlieghere 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 rGfc54427e76c8: [lldb] Refactor DataBuffer so we can map files 
as read-only (authored by JDevlieghere).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D122856?vs=420589&id=420625#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122856

Files:
  lldb/include/lldb/Core/ValueObject.h
  lldb/include/lldb/Host/FileSystem.h
  lldb/include/lldb/Symbol/CompactUnwindInfo.h
  lldb/include/lldb/Symbol/ObjectFile.h
  lldb/include/lldb/Target/ProcessStructReader.h
  lldb/include/lldb/Target/RegisterCheckpoint.h
  lldb/include/lldb/Target/RegisterContext.h
  lldb/include/lldb/Target/RegisterContextUnwind.h
  lldb/include/lldb/Utility/DataBuffer.h
  lldb/include/lldb/Utility/DataBufferHeap.h
  lldb/include/lldb/Utility/DataBufferLLVM.h
  lldb/include/lldb/lldb-forward.h
  lldb/source/Commands/CommandObjectMemory.cpp
  lldb/source/Core/SourceManager.cpp
  lldb/source/Core/ValueObject.cpp
  lldb/source/DataFormatters/StringPrinter.cpp
  lldb/source/DataFormatters/TypeFormat.cpp
  lldb/source/Expression/IRExecutionUnit.cpp
  lldb/source/Host/common/FileSystem.cpp
  lldb/source/Host/common/Host.cpp
  lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp
  lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp
  lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp
  lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp
  lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp
  lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp
  lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp
  lldb/source/Plugins/Language/ObjC/CF.cpp
  lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
  lldb/source/Plugins/Language/ObjC/NSSet.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
  
lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
  lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
  lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.h
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.h
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.h
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.h
  lldb/source/Plugins/Process/Utility/RegisterContextDummy.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextDummy.h
  lldb/source/Plugins/Process/Utility/RegisterContextHistory.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextHistory.h
  lldb/source/Plugins/Process/Utility/RegisterContextMemory.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextMemory.h
  lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_powerpc.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_s390x.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_32.cpp
  lldb/source/Plugins/Process/minidump/RegisterContextMinidump_x86_64.cpp
  lldb/source/Symbol/ObjectFile.cpp
  lldb/source/Target/Platform.cpp
  lldb/source/Target/RegisterContextUnwind.cpp
  lldb/source/Utility/DataBuffer

[Lldb-commits] [lldb] a722dea - [lldb] Update reinterpret_cast in linux/Host.cpp

2022-04-05 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-04-05T13:52:07-07:00
New Revision: a722dea4af7743a76701bb582ded88fe0e188c14

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

LOG: [lldb] Update reinterpret_cast in linux/Host.cpp

Fixes error: reinterpret_cast from type ‘const uint8_t*’ {aka ‘const
unsigned char*’} to type ‘char*’ casts away qualifiers

Added: 


Modified: 
lldb/source/Host/linux/Host.cpp

Removed: 




diff  --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index 6342dee59532a..2196b8ed5a3f1 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -133,10 +133,11 @@ static ArchSpec GetELFProcessCPUType(llvm::StringRef 
exe_path) {
   if (!buffer_sp)
 return ArchSpec();
 
-  uint8_t exe_class = llvm::object::getElfArchType(
-  {reinterpret_cast(buffer_sp->GetBytes()),
-   size_t(buffer_sp->GetByteSize())})
-  .first;
+  uint8_t exe_class =
+  llvm::object::getElfArchType(
+  {reinterpret_cast(buffer_sp->GetBytes()),
+   size_t(buffer_sp->GetByteSize())})
+  .first;
 
   switch (exe_class) {
   case llvm::ELF::ELFCLASS32:



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


[Lldb-commits] [PATCH] D122975: parallelize calling of Module::PreloadSymbols()

2022-04-05 Thread Luboš Luňák via Phabricator via lldb-commits
llunak added a comment.

In D122975#3430613 , @JDevlieghere 
wrote:

> After applying this patch I started seeing data races reported by TSan when 
> running the shell tests (`check-lldb-shell`). It seems to happen to different 
> tests on different runs but the backtraces are the same.

That's some debug code using a static bool. I take it D123158 
 takes care of it?


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

https://reviews.llvm.org/D122975

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


[Lldb-commits] [lldb] c2f6460 - [lldb] Update the NativeRegisterContext to take a WritableMemoryBuffer

2022-04-05 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-04-05T14:19:01-07:00
New Revision: c2f6460145175d265cd1a7ad7906b778bb11fa3d

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

LOG: [lldb] Update the NativeRegisterContext to take a WritableMemoryBuffer

Added: 


Modified: 
lldb/include/lldb/Host/common/NativeRegisterContext.h
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm.cpp
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm.h
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.h
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_mips64.cpp
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_mips64.h
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_powerpc.cpp
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_powerpc.h
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_x86_64.cpp
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_x86_64.h
lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.h
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_s390x.cpp
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_s390x.h
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.h
lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp
lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.h

lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_WoW64.cpp

lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_WoW64.h

lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_arm.cpp

lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_arm.h

lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_arm64.cpp

lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_arm64.h

lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_i386.cpp

lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_i386.h

lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_x86_64.cpp

lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_x86_64.h
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp

Removed: 




diff  --git a/lldb/include/lldb/Host/common/NativeRegisterContext.h 
b/lldb/include/lldb/Host/common/NativeRegisterContext.h
index f7568fe31b80d..0a7647d780803 100644
--- a/lldb/include/lldb/Host/common/NativeRegisterContext.h
+++ b/lldb/include/lldb/Host/common/NativeRegisterContext.h
@@ -51,7 +51,7 @@ class NativeRegisterContext
   virtual Status WriteRegister(const RegisterInfo *reg_info,
const RegisterValue ®_value) = 0;
 
-  virtual Status ReadAllRegisterValues(lldb::DataBufferSP &data_sp) = 0;
+  virtual Status ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) = 
0;
 
   virtual Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) = 0;
 

diff  --git 
a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm.cpp 
b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm.cpp
index c4ee3773eaeb0..117d7084f7051 100644
--- a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm.cpp
@@ -140,7 +140,7 @@ Status NativeRegisterContextFreeBSD_arm::WriteRegister(
 }
 
 Status NativeRegisterContextFreeBSD_arm::ReadAllRegisterValues(
-lldb::DataBufferSP &data_sp) {
+lldb::WritableDataBufferSP &data_sp) {
   Status error;
 
   error = ReadRegisterSet(RegisterInfoPOSIX_arm::GPRegSet);

diff  --git 
a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm.h 
b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm.h
index 4be75b958fc16..89ffa617294aa 100644
--- a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm.h
+++ b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm.h
@@ -44,7 +44,7 @@ class Na

[Lldb-commits] [lldb] ed9a14f - [lldb] Add missing const to NativeRegisterContextLinux_x86_64

2022-04-05 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-04-05T14:26:50-07:00
New Revision: ed9a14f912c034c6a7177d4bc8a2d41a22b3e129

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

LOG: [lldb] Add missing const to NativeRegisterContextLinux_x86_64

Fixes error: invalid conversion from ‘const uint8_t*’ {aka ‘const
unsigned char*’} to ‘uint8_t*’ {aka ‘unsigned char*’}

Added: 


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

Removed: 




diff  --git 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
index f6562fc290e46..d8b8f50b6de7c 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp
@@ -780,7 +780,7 @@ Status 
NativeRegisterContextLinux_x86_64::WriteAllRegisterValues(
 return error;
   }
 
-  uint8_t *src = data_sp->GetBytes();
+  const uint8_t *src = data_sp->GetBytes();
   if (src == nullptr) {
 error.SetErrorStringWithFormat("NativeRegisterContextLinux_x86_64::%s "
"DataBuffer::GetBytes() returned a null "



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


[Lldb-commits] [lldb] b7bf5a7 - [lldb] Add missing const to NativeRegisterContextLinux_arm

2022-04-05 Thread Benjamin Kramer via lldb-commits

Author: Benjamin Kramer
Date: 2022-04-05T23:39:08+02:00
New Revision: b7bf5a7a7ef4181813ea682a8f9dac56f25c3141

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

LOG: [lldb] Add missing const to NativeRegisterContextLinux_arm

Added: 


Modified: 
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
index 7db0d9eec6d24..10ffe49f6b4e8 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp
@@ -231,7 +231,7 @@ Status 
NativeRegisterContextLinux_arm::WriteAllRegisterValues(
 return error;
   }
 
-  uint8_t *src = data_sp->GetBytes();
+  const uint8_t *src = data_sp->GetBytes();
   if (src == nullptr) {
 error.SetErrorStringWithFormat("NativeRegisterContextLinux_arm::%s "
"DataBuffer::GetBytes() returned a null "

diff  --git 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
index dccd8049c03dc..cee727877a13d 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
@@ -524,7 +524,7 @@ Status 
NativeRegisterContextLinux_arm64::WriteAllRegisterValues(
 return error;
   }
 
-  uint8_t *src = data_sp->GetBytes();
+  const uint8_t *src = data_sp->GetBytes();
   if (src == nullptr) {
 error.SetErrorStringWithFormat("NativeRegisterContextLinux_arm64::%s "
"DataBuffer::GetBytes() returned a null "



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


[Lldb-commits] [lldb] 470eb5c - [lldb] Add more missing consts in NativeRegisterContexts

2022-04-05 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-04-05T14:43:39-07:00
New Revision: 470eb5c29bb12c7af723301c0ea4b8969eab34ae

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

LOG: [lldb] Add more missing consts in NativeRegisterContexts

Added: 


Modified: 
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm.cpp
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_mips64.cpp
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_powerpc.cpp
lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_x86_64.cpp
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp
lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm.cpp 
b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm.cpp
index 117d7084f7051..2c50176643878 100644
--- a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm.cpp
@@ -177,7 +177,7 @@ Status 
NativeRegisterContextFreeBSD_arm::WriteAllRegisterValues(
 return error;
   }
 
-  uint8_t *src = data_sp->GetBytes();
+  const uint8_t *src = data_sp->GetBytes();
   if (src == nullptr) {
 error.SetErrorStringWithFormat("NativeRegisterContextFreeBSD_arm::%s "
"DataBuffer::GetBytes() returned a null "

diff  --git 
a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp 
b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp
index 638ec16dd884f..9db5970af653e 100644
--- a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp
@@ -186,7 +186,7 @@ Status 
NativeRegisterContextFreeBSD_arm64::WriteAllRegisterValues(
 return error;
   }
 
-  uint8_t *src = data_sp->GetBytes();
+  const uint8_t *src = data_sp->GetBytes();
   if (src == nullptr) {
 error.SetErrorStringWithFormat("NativeRegisterContextFreeBSD_arm64::%s "
"DataBuffer::GetBytes() returned a null "

diff  --git 
a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_mips64.cpp 
b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_mips64.cpp
index 4b9e34082e2cf..83664b5869609 100644
--- 
a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_mips64.cpp
+++ 
b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_mips64.cpp
@@ -213,7 +213,7 @@ Status 
NativeRegisterContextFreeBSD_mips64::WriteAllRegisterValues(
 return error;
   }
 
-  uint8_t *src = data_sp->GetBytes();
+  const uint8_t *src = data_sp->GetBytes();
   if (src == nullptr) {
 error.SetErrorStringWithFormat("NativeRegisterContextFreeBSD_mips64::%s "
"DataBuffer::GetBytes() returned a null "

diff  --git 
a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_powerpc.cpp 
b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_powerpc.cpp
index 54a2582b0f083..ee125e5e68811 100644
--- 
a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_powerpc.cpp
+++ 
b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_powerpc.cpp
@@ -264,7 +264,7 @@ Status 
NativeRegisterContextFreeBSD_powerpc::WriteAllRegisterValues(
 return error;
   }
 
-  uint8_t *src = data_sp->GetBytes();
+  const uint8_t *src = data_sp->GetBytes();
   if (src == nullptr) {
 error.SetErrorStringWithFormat("NativeRegisterContextFreeBSD_powerpc::%s "
"DataBuffer::GetBytes() returned a null "

diff  --git 
a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_x86_64.cpp 
b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_x86_64.cpp
index 09d31db321067..b69cfa7d5d837 100644
--- 
a/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_x86_64.cpp
+++ 
b/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_x86_64.cpp
@@ -571,7 +571,7 @@ Status 
NativeRegisterContextFreeBSD_x86_64::WriteAllRegisterValues(
 return error;
   }
 
-  uint8_t *src = data_sp->GetBytes();
+  const uint8_t *src = data_sp->GetBytes();
   if (src == nullptr) {
 error.SetErrorStringWithFormat("NativeRegisterContextFreeBSD_x86_64::%s "
"DataBuffer::GetBytes() returned a null "

diff  --git 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp
index adf76bbb

[Lldb-commits] [PATCH] D121631: Introduce new symbol on-demand for debug info

2022-04-05 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

So we added documentation on this feature explaining who will want to enable 
this feature and also describe exactly when and how debug info will get 
enabled. Does anyone else have objections or comments to make? If we need to 
setup a meeting to discuss, please chime in, or leave some review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121631

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


[Lldb-commits] [lldb] b6087ba - Disable LLDB index cache for .o files with no UUID.

2022-04-05 Thread Greg Clayton via lldb-commits

Author: Greg Clayton
Date: 2022-04-05T15:14:36-07:00
New Revision: b6087ba769c612c031b84e6673c438fe44a46c6a

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

LOG: Disable LLDB index cache for .o files with no UUID.

After enabling the LLDB index cache in production we discovered that some 
distributed build systems play with the modification times of any .o files that 
were downloaded from the build cache. This was causing the LLDB index cache to 
read the wrong cache file for files that didn't have a UUID as all of the 
modfication times were set to the same value by the build system. When new .o 
files were downloaded, the only unique identifier was the mod time which were 
all the same, and we would load an older cache for the updated .o file. So 
disabling caching of files that have no UUIDs for now until we can create a 
more solid solution.

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

Added: 


Modified: 
lldb/include/lldb/Core/DataFileCache.h
lldb/source/Core/DataFileCache.cpp
lldb/test/API/functionalities/module_cache/bsd/TestModuleCacheBSD.py
lldb/unittests/SymbolFile/DWARF/DWARFIndexCachingTest.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/DataFileCache.h 
b/lldb/include/lldb/Core/DataFileCache.h
index 6f7de679f8679..cf794078ff9e3 100644
--- a/lldb/include/lldb/Core/DataFileCache.h
+++ b/lldb/include/lldb/Core/DataFileCache.h
@@ -119,22 +119,22 @@ struct CacheSignature {
 m_obj_mod_time = llvm::None;
   }
 
-  /// Return true if any of the signature member variables have valid values.
-  bool IsValid() const {
-return m_uuid.hasValue() || m_mod_time.hasValue() ||
-   m_obj_mod_time.hasValue();
-  }
+  /// Return true only if the CacheSignature is valid.
+  ///
+  /// Cache signatures are considered valid only if there is a UUID in the file
+  /// that can uniquely identify the file. Some build systems play with
+  /// modification times of file so we can not trust them without using valid
+  /// unique idenifier like the UUID being valid.
+  bool IsValid() const { return m_uuid.hasValue(); }
 
   /// Check if two signatures are the same.
-  bool operator!=(const CacheSignature &rhs) {
-if (m_uuid != rhs.m_uuid)
-  return true;
-if (m_mod_time != rhs.m_mod_time)
-  return true;
-if (m_obj_mod_time != rhs.m_obj_mod_time)
-  return true;
-return false;
+  bool operator==(const CacheSignature &rhs) const {
+return m_uuid == rhs.m_uuid && m_mod_time == rhs.m_mod_time &&
+   m_obj_mod_time == rhs.m_obj_mod_time;
   }
+
+  /// Check if two signatures 
diff er.
+  bool operator!=(const CacheSignature &rhs) const { return !(*this == rhs); }
   /// Encode this object into a data encoder object.
   ///
   /// This allows this object to be serialized to disk. The CacheSignature
@@ -149,7 +149,7 @@ struct CacheSignature {
   ///   True if a signature was encoded, and false if there were no member
   ///   variables that had value. False indicates this data should not be
   ///   cached to disk because we were unable to encode a valid signature.
-  bool Encode(DataEncoder &encoder);
+  bool Encode(DataEncoder &encoder) const;
 
   /// Decode a serialized version of this object from data.
   ///

diff  --git a/lldb/source/Core/DataFileCache.cpp 
b/lldb/source/Core/DataFileCache.cpp
index f9b632f34e417..5f8568fdb54f2 100644
--- a/lldb/source/Core/DataFileCache.cpp
+++ b/lldb/source/Core/DataFileCache.cpp
@@ -199,7 +199,7 @@ enum SignatureEncoding {
   eSignatureEnd = 255u,
 };
 
-bool CacheSignature::Encode(DataEncoder &encoder) {
+bool CacheSignature::Encode(DataEncoder &encoder) const {
   if (!IsValid())
 return false; // Invalid signature, return false!
 
@@ -240,10 +240,14 @@ bool CacheSignature::Decode(const 
lldb_private::DataExtractor &data,
 case eSignatureObjectModTime: {
   uint32_t mod_time = data.GetU32(offset_ptr);
   if (mod_time > 0)
-m_mod_time = mod_time;
+m_obj_mod_time = mod_time;
 } break;
 case eSignatureEnd:
-  return true;
+  // The definition of is valid changed to only be valid if the UUID is
+  // valid so make sure that if we attempt to decode an old cache file
+  // that we will fail to decode the cache file if the signature isn't
+  // considered valid.
+  return IsValid();
 default:
   break;
 }

diff  --git 
a/lldb/test/API/functionalities/module_cache/bsd/TestModuleCacheBSD.py 
b/lldb/test/API/functionalities/module_cache/bsd/TestModuleCacheBSD.py
index 5f6104f41c3c0..fdd7d7904f833 100644
--- a/lldb/test/API/functionalities/module_cache/bsd/TestModuleCacheBSD.py
+++ b/lldb/test/API/functionalities/module_cache/bsd/TestModuleCacheBSD.py
@@ -41,6 +41,25 @@ def get_module_cache_files(self, 

[Lldb-commits] [PATCH] D120948: Disable LLDB index cache for .o files with no UUID.

2022-04-05 Thread Greg Clayton via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb6087ba769c6: Disable LLDB index cache for .o files with no 
UUID. (authored by clayborg).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120948

Files:
  lldb/include/lldb/Core/DataFileCache.h
  lldb/source/Core/DataFileCache.cpp
  lldb/test/API/functionalities/module_cache/bsd/TestModuleCacheBSD.py
  lldb/unittests/SymbolFile/DWARF/DWARFIndexCachingTest.cpp

Index: lldb/unittests/SymbolFile/DWARF/DWARFIndexCachingTest.cpp
===
--- lldb/unittests/SymbolFile/DWARF/DWARFIndexCachingTest.cpp
+++ lldb/unittests/SymbolFile/DWARF/DWARFIndexCachingTest.cpp
@@ -196,3 +196,75 @@
   DIERef(llvm::None, DIERef::Section::DebugInfo, ++die_offset));
   EncodeDecode(set);
 }
+
+static void EncodeDecode(const CacheSignature &object, ByteOrder byte_order,
+ bool encode_result) {
+  const uint8_t addr_size = 8;
+  DataEncoder encoder(byte_order, addr_size);
+  EXPECT_EQ(encode_result, object.Encode(encoder));
+  if (!encode_result)
+return;
+  llvm::ArrayRef bytes = encoder.GetData();
+  DataExtractor data(bytes.data(), bytes.size(), byte_order, addr_size);
+  offset_t data_offset = 0;
+  CacheSignature decoded_object;
+  EXPECT_TRUE(decoded_object.Decode(data, &data_offset));
+  EXPECT_EQ(object, decoded_object);
+}
+
+static void EncodeDecode(const CacheSignature &object, bool encode_result) {
+  EncodeDecode(object, eByteOrderLittle, encode_result);
+  EncodeDecode(object, eByteOrderBig, encode_result);
+}
+
+TEST(DWARFIndexCachingTest, CacheSignatureTests) {
+  CacheSignature sig;
+  // A cache signature is only considered valid if it has a UUID.
+  sig.m_mod_time = 0x12345678;
+  EXPECT_FALSE(sig.IsValid());
+  EncodeDecode(sig, /*encode_result=*/false);
+  sig.Clear();
+
+  sig.m_obj_mod_time = 0x12345678;
+  EXPECT_FALSE(sig.IsValid());
+  EncodeDecode(sig, /*encode_result=*/false);
+  sig.Clear();
+
+  sig.m_uuid = UUID::fromData("@\x00\x11\x22\x33\x44\x55\x66\x77", 8);
+  EXPECT_TRUE(sig.IsValid());
+  EncodeDecode(sig, /*encode_result=*/true);
+  sig.m_mod_time = 0x12345678;
+  EXPECT_TRUE(sig.IsValid());
+  EncodeDecode(sig, /*encode_result=*/true);
+  sig.m_obj_mod_time = 0x456789ab;
+  EXPECT_TRUE(sig.IsValid());
+  EncodeDecode(sig, /*encode_result=*/true);
+  sig.m_mod_time = llvm::None;
+  EXPECT_TRUE(sig.IsValid());
+  EncodeDecode(sig, /*encode_result=*/true);
+
+  // Recent changes do not allow cache signatures with only a modification time
+  // or object modification time, so make sure if we try to decode such a cache
+  // file that we fail. This verifies that if we try to load an previously
+  // valid cache file where the signature is insufficient, that we will fail to
+  // decode and load these cache files.
+  DataEncoder encoder(eByteOrderLittle, /*addr_size=*/8);
+  encoder.AppendU8(2); // eSignatureModTime
+  encoder.AppendU32(0x12345678);
+  encoder.AppendU8(255); // eSignatureEnd
+
+  llvm::ArrayRef bytes = encoder.GetData();
+  DataExtractor data(bytes.data(), bytes.size(), eByteOrderLittle,
+ /*addr_size=*/8);
+  offset_t data_offset = 0;
+
+  // Make sure we fail to decode a CacheSignature with only a mod time
+  EXPECT_FALSE(sig.Decode(data, &data_offset));
+
+  // Change the signature data to contain only a eSignatureObjectModTime and
+  // make sure decoding fails as well.
+  encoder.PutU8(/*offset=*/0, 3); // eSignatureObjectModTime
+  data_offset = 0;
+  EXPECT_FALSE(sig.Decode(data, &data_offset));
+
+}
Index: lldb/test/API/functionalities/module_cache/bsd/TestModuleCacheBSD.py
===
--- lldb/test/API/functionalities/module_cache/bsd/TestModuleCacheBSD.py
+++ lldb/test/API/functionalities/module_cache/bsd/TestModuleCacheBSD.py
@@ -41,6 +41,25 @@
 @skipUnlessDarwin
 def test(self):
 """
+This test has been modified to make sure .o files that don't have
+UUIDs are not cached after discovering build systems that play with
+modification times of .o files that the modification times are not
+unique enough to ensure the .o file within the .a file are the right
+files as this was causing older cache files to be accepted for new
+updated .o files.
+
+ELF .o files do calculate a UUID from the contents of the file,
+which is expensive, but no one loads .o files into a debug sessions
+when using ELF files. Mach-o .o files do not have UUID values and do
+no calculate one as they _are_ used during debug sessions when no
+dSYM file is generated. If we can find a way to uniquely and cheaply
+create UUID values for mach-o .o files in the future, this test will
+be updated to test th

[Lldb-commits] [lldb] 70984dd - [lldb] Update ReadAllRegisterValues in RegisterContextWindows

2022-04-05 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-04-05T15:15:48-07:00
New Revision: 70984dd40a425927876518ff4e0bd9b6b790bec2

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

LOG: [lldb] Update ReadAllRegisterValues in RegisterContextWindows

Added: 


Modified: 
lldb/source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp
lldb/source/Plugins/Process/Windows/Common/RegisterContextWindows.h

Removed: 




diff  --git 
a/lldb/source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp
index b443df1e7cbd1..25b67bec3e3cf 100644
--- a/lldb/source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp
@@ -37,7 +37,7 @@ void RegisterContextWindows::InvalidateAllRegisters() {
 }
 
 bool RegisterContextWindows::ReadAllRegisterValues(
-lldb::DataBufferSP &data_sp) {
+lldb::WritableDataBufferSP &data_sp) {
 
   if (!CacheAllRegisterValues())
 return false;

diff  --git 
a/lldb/source/Plugins/Process/Windows/Common/RegisterContextWindows.h 
b/lldb/source/Plugins/Process/Windows/Common/RegisterContextWindows.h
index 9ae0402282543..ac412d74f9fa0 100644
--- a/lldb/source/Plugins/Process/Windows/Common/RegisterContextWindows.h
+++ b/lldb/source/Plugins/Process/Windows/Common/RegisterContextWindows.h
@@ -26,7 +26,7 @@ class RegisterContextWindows : public 
lldb_private::RegisterContext {
   // Subclasses must override these functions
   void InvalidateAllRegisters() override;
 
-  bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override;
+  bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override;
 
   bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
 



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


[Lldb-commits] [PATCH] D123092: [LLDB][NativePDB] Fix inline line info in line table

2022-04-05 Thread Zequan Wu via Phabricator via lldb-commits
zequanwu planned changes to this revision.
zequanwu added a comment.

Plan to apply similar change in D123151 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123092

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


[Lldb-commits] [lldb] 0cf21a7 - [lldb/source/Utility/DataExtractor.cpp] Update for `llvm::MD5::MD5Result` API change

2022-04-05 Thread Argyrios Kyrtzidis via lldb-commits

Author: Argyrios Kyrtzidis
Date: 2022-04-05T21:47:45-07:00
New Revision: 0cf21a7e0c820dc68628c39b2dc8115d3c2b86b2

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

LOG: [lldb/source/Utility/DataExtractor.cpp] Update for `llvm::MD5::MD5Result` 
API change

Added: 


Modified: 
lldb/source/Utility/DataExtractor.cpp

Removed: 




diff  --git a/lldb/source/Utility/DataExtractor.cpp 
b/lldb/source/Utility/DataExtractor.cpp
index 50f2985da6fe0..a0cd945b7445c 100644
--- a/lldb/source/Utility/DataExtractor.cpp
+++ b/lldb/source/Utility/DataExtractor.cpp
@@ -1042,5 +1042,5 @@ void 
DataExtractor::Checksum(llvm::SmallVectorImpl &dest,
   md5.final(result);
 
   dest.clear();
-  dest.append(result.Bytes.begin(), result.Bytes.end());
+  dest.append(result.begin(), result.end());
 }



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