[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits


@@ -0,0 +1,770 @@
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Core/ModuleSpec.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Section.h"
+#include "lldb/Core/StreamFile.h"
+#include "lldb/Interpreter/OptionValueProperties.h"
+#include "lldb/Symbol/LocateSymbolFile.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Target/OperatingSystem.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlanRunToAddress.h"
+#include "lldb/Utility/DataBuffer.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+
+#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
+
+#include "DynamicLoaderFreeBSDKernel.h"
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+LLDB_PLUGIN_DEFINE(DynamicLoaderFreeBSDKernel)
+
+void DynamicLoaderFreeBSDKernel::Initialize() {
+  PluginManager::RegisterPlugin(GetPluginNameStatic(),
+GetPluginDescriptionStatic(), CreateInstance,
+DebuggerInit);
+}
+
+void DynamicLoaderFreeBSDKernel::Terminate() {
+  PluginManager::UnregisterPlugin(CreateInstance);
+}
+
+llvm::StringRef DynamicLoaderFreeBSDKernel::GetPluginDescriptionStatic() {
+  return "The Dynamic Loader Plugin For FreeBSD Kernel";
+}
+
+static bool is_kernel(Module *module) {
+  if (!module)
+return false;
+
+  ObjectFile *objfile = module->GetObjectFile();
+  if (!objfile)
+return false;
+  if (objfile->GetType() != ObjectFile::eTypeExecutable)
+return false;
+  if (objfile->GetStrata() != ObjectFile::eStrataUnknown &&
+  objfile->GetStrata() != ObjectFile::eStrataUser)
+return false;
+
+  return true;
+}
+
+static bool is_kmod(Module *module) {
+  if (!module)
+return false;
+  if (!module->GetObjectFile())
+return false;
+  ObjectFile *objfile = module->GetObjectFile();
+  if (objfile->GetType() != ObjectFile::eTypeObjectFile &&
+  objfile->GetType() != ObjectFile::eTypeSharedLibrary)
+return false;
+
+  return true;
+}
+
+static bool is_reloc(Module *module) {
+  if (!module)
+return false;
+  if (!module->GetObjectFile())
+return false;
+  ObjectFile *objfile = module->GetObjectFile();
+  if (objfile->GetType() != ObjectFile::eTypeObjectFile)
+return false;
+
+  return true;
+}
+
+// Instantiate Function of the FreeBSD Kernel Dynamic Loader Plugin called when
+// Register the Plugin
+DynamicLoader *
+DynamicLoaderFreeBSDKernel::CreateInstance(lldb_private::Process *process,
+   bool force) {
+  // Check the environment when the plugin is not force loaded
+  Log *log = GetLog(LLDBLog::DynamicLoader);
+  LLDB_LOGF(log, "DynamicLoaderFreeBSDKernel::CreateInstance: "
+ "Try to create instance");
+  if (!force) {
+Module *exec = process->GetTarget().GetExecutableModulePointer();
+// Check if the target is kernel
+if (exec && !is_kernel(exec)) {
+  return nullptr;
+}
+
+const llvm::Triple &triple_ref =
+process->GetTarget().GetArchitecture().GetTriple();
+if (!triple_ref.isOSFreeBSD()) {
+  return nullptr;
+}
+  }
+
+  // At this point we have checked the target is a FreeBSD kernel and all we
+  // have to do is to find the kernel address
+  const addr_t kernel_address = FindFreeBSDKernel(process);
+
+  if (CheckForKernelImageAtAddress(process, kernel_address).IsValid())
+return new DynamicLoaderFreeBSDKernel(process, kernel_address);
+
+  return nullptr;
+}
+
+addr_t
+DynamicLoaderFreeBSDKernel::FindFreeBSDKernel(lldb_private::Process *process) {
+  addr_t kernel_addr = process->GetImageInfoAddress();
+  if (kernel_addr == LLDB_INVALID_ADDRESS)
+kernel_addr = FindKernelAtLoadAddress(process);
+  return kernel_addr;
+}
+
+// Get the kernel address if the kernel is not loaded with a slide
+addr_t DynamicLoaderFreeBSDKernel::FindKernelAtLoadAddress(
+lldb_private::Process *process) {
+  Module *exe_module = process->GetTarget().GetExecutableModulePointer();
+
+  if (!is_kernel(exe_module))
+return LLDB_INVALID_ADDRESS;
+
+  ObjectFile *exe_objfile = exe_module->GetObjectFile();
+
+  if (!exe_objfile->GetBaseAddress().IsValid())
+return LLDB_INVALID_ADDRESS;
+
+  if (CheckForKernelImageAtAddress(
+  process, exe_objfile->GetBaseAddress().GetFileAddress())
+  .IsValid())
+return exe_objfile->GetBaseAddress().GetFileAddress();
+
+  return LLDB_INVALID_ADDRESS;
+}
+
+// Read ELF header from memry and return
+bool DynamicLoaderFreeBSDKernel::ReadELFHeader(Process *process,
+   lldb::addr_t addr,
+   llvm::ELF::Elf32_Ehdr &header,
+

[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast edited 
https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] add stop-at-main option to process launch (PR #67019)

2023-09-26 Thread José Lira Junior via lldb-commits

https://github.com/junior-jl resolved 
https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] add stop-at-main option to process launch (PR #67019)

2023-09-26 Thread José Lira Junior via lldb-commits


@@ -38,7 +38,18 @@ Status CommandOptionsProcessLaunch::SetOptionValue(
   case 's': // Stop at program entry point
 launch_info.GetFlags().Set(eLaunchFlagStopAtEntry);
 break;
-
+  case 'm': // Stop at main function
+  {
+TargetSP target_sp =
+execution_context ? execution_context->GetTargetSP() : TargetSP();
+BreakpointSP bp_sp = target_sp->CreateBreakpoint(
+nullptr, nullptr, "main", eFunctionNameTypeAuto, eLanguageTypeUnknown,

junior-jl wrote:

Okay. I'll resolve this part by using `eFunctionNameTypeFull` as you discussed 
with Jim.

https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] add stop-at-main option to process launch (PR #67019)

2023-09-26 Thread José Lira Junior via lldb-commits


@@ -38,7 +38,18 @@ Status CommandOptionsProcessLaunch::SetOptionValue(
   case 's': // Stop at program entry point
 launch_info.GetFlags().Set(eLaunchFlagStopAtEntry);
 break;
-
+  case 'm': // Stop at main function
+  {
+TargetSP target_sp =
+execution_context ? execution_context->GetTargetSP() : TargetSP();
+BreakpointSP bp_sp = target_sp->CreateBreakpoint(
+nullptr, nullptr, "main", eFunctionNameTypeAuto, eLanguageTypeUnknown,

junior-jl wrote:

> We should add a new API to the Language plugin: 
> Language::GetUserEntrypointName() and then this code should iterate over all 
> the supported languages building up a unique list of entry point names using 
> this API. At present there's going to be one: "main" repeated many times but 
> I think Walter promised us another one soon...

About this, Walter had proposed the following: "I'd suggest adding a virtual 
method GetMainSymbol to the Language.h interface, which could be implemented by 
each language plugin.". I guess it's a good approach. What are your thoughts?

https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] add stop-at-main option to process launch (PR #67019)

2023-09-26 Thread José Lira Junior via lldb-commits


@@ -38,7 +38,18 @@ Status CommandOptionsProcessLaunch::SetOptionValue(
   case 's': // Stop at program entry point
 launch_info.GetFlags().Set(eLaunchFlagStopAtEntry);
 break;
-
+  case 'm': // Stop at main function
+  {
+TargetSP target_sp =
+execution_context ? execution_context->GetTargetSP() : TargetSP();
+BreakpointSP bp_sp = target_sp->CreateBreakpoint(
+nullptr, nullptr, "main", eFunctionNameTypeAuto, eLanguageTypeUnknown,

junior-jl wrote:

> It's also a good idea to add a shared library filter instead of the first 
> `nullptr` in the code above, and specify the main executable. You know the 
> entry point has to be in the main executable, and so it would be inefficient 
> to search the whole world for this breakpoint. It could also end up not being 
> what you want, because some other shared library might call a function named 
> "main" as part of it's shared library loading code (which happens before the 
> language's entry point) so you would in fact stop too early.

I see. Something like this?

```cpp
ModuleSP main_module_sp = target_sp->GetExecutableModule();
FileSpecList shared_lib_filter;
shared_lib_filter.Append(main_module_sp->GetFileSpec());
BreakpointSP bp_sp = target_sp->CreateBreakpoint(
&shared_lib_filter, nullptr, "main", eFunctionNameTypeFull, 
eLanguageTypeUnknown,
0, eLazyBoolNo, false, false);
```

https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] add stop-at-main option to process launch (PR #67019)

2023-09-26 Thread José Lira Junior via lldb-commits


@@ -675,6 +675,8 @@ let Command = "platform shell" in {
 let Command = "process launch" in {
   def process_launch_stop_at_entry : Option<"stop-at-entry", "s">,
 Desc<"Stop at the entry point of the program when launching a process.">;
+  def process_launch_stop_at_main : Option<"stop-at-main", "m">,
+Desc<"Stop at the main function of the program when launching a process.">;

junior-jl wrote:

Okay. I'll change this. Should I keep 'm' as the short option?

https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast updated 
https://github.com/llvm/llvm-project/pull/67106

>From f8ed3ed64be0a451542a4ec71f254dc9038b2d19 Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Fri, 22 Sep 2023 18:11:07 +0800
Subject: [PATCH 1/3] feat: add DynamicLoaderFreeBSDKernel

---
 .../Plugins/DynamicLoader/CMakeLists.txt  |   1 +
 .../FreeBSD-Kernel/CMakeLists.txt |  13 +
 .../DynamicLoaderFreeBSDKernel.cpp| 770 ++
 .../DynamicLoaderFreeBSDKernel.h  | 165 
 .../FreeBSDKernel/ProcessFreeBSDKernel.cpp|   4 +-
 5 files changed, 951 insertions(+), 2 deletions(-)
 create mode 100644 
lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/CMakeLists.txt
 create mode 100644 
lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 create mode 100644 
lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.h

diff --git a/lldb/source/Plugins/DynamicLoader/CMakeLists.txt 
b/lldb/source/Plugins/DynamicLoader/CMakeLists.txt
index f357fea02efbe68..30607159acdc088 100644
--- a/lldb/source/Plugins/DynamicLoader/CMakeLists.txt
+++ b/lldb/source/Plugins/DynamicLoader/CMakeLists.txt
@@ -1,4 +1,5 @@
 add_subdirectory(Darwin-Kernel)
+add_subdirectory(FreeBSD-Kernel)
 add_subdirectory(MacOSX-DYLD)
 add_subdirectory(POSIX-DYLD)
 add_subdirectory(Static)
diff --git a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/CMakeLists.txt 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/CMakeLists.txt
new file mode 100644
index 000..76daf0a327cf97b
--- /dev/null
+++ b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/CMakeLists.txt
@@ -0,0 +1,13 @@
+add_lldb_library(lldbPluginDynamicLoaderFreeBSDKernel PLUGIN
+  DynamicLoaderFreeBSDKernel.cpp
+
+  LINK_LIBS
+lldbBreakpoint
+lldbCore
+lldbHost
+lldbInterpreter
+lldbSymbol
+lldbTarget
+lldbUtility
+lldbPluginObjectFileELF
+  )
diff --git 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
new file mode 100644
index 000..d5eb891f0060bea
--- /dev/null
+++ 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -0,0 +1,770 @@
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Core/ModuleSpec.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Section.h"
+#include "lldb/Core/StreamFile.h"
+#include "lldb/Interpreter/OptionValueProperties.h"
+#include "lldb/Symbol/LocateSymbolFile.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Target/OperatingSystem.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlanRunToAddress.h"
+#include "lldb/Utility/DataBuffer.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+
+#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
+
+#include "DynamicLoaderFreeBSDKernel.h"
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+LLDB_PLUGIN_DEFINE(DynamicLoaderFreeBSDKernel)
+
+void DynamicLoaderFreeBSDKernel::Initialize() {
+  PluginManager::RegisterPlugin(GetPluginNameStatic(),
+GetPluginDescriptionStatic(), CreateInstance,
+DebuggerInit);
+}
+
+void DynamicLoaderFreeBSDKernel::Terminate() {
+  PluginManager::UnregisterPlugin(CreateInstance);
+}
+
+llvm::StringRef DynamicLoaderFreeBSDKernel::GetPluginDescriptionStatic() {
+  return "The Dynamic Loader Plugin For FreeBSD Kernel";
+}
+
+static bool is_kernel(Module *module) {
+  if (!module)
+return false;
+
+  ObjectFile *objfile = module->GetObjectFile();
+  if (!objfile)
+return false;
+  if (objfile->GetType() != ObjectFile::eTypeExecutable)
+return false;
+  if (objfile->GetStrata() != ObjectFile::eStrataUnknown &&
+  objfile->GetStrata() != ObjectFile::eStrataUser)
+return false;
+
+  return true;
+}
+
+static bool is_kmod(Module *module) {
+  if (!module)
+return false;
+  if (!module->GetObjectFile())
+return false;
+  ObjectFile *objfile = module->GetObjectFile();
+  if (objfile->GetType() != ObjectFile::eTypeObjectFile &&
+  objfile->GetType() != ObjectFile::eTypeSharedLibrary)
+return false;
+
+  return true;
+}
+
+static bool is_reloc(Module *module) {
+  if (!module)
+return false;
+  if (!module->GetObjectFile())
+return false;
+  ObjectFile *objfile = module->GetObjectFile();
+  if (objfile->GetType() != ObjectFile::eTypeObjectFile)
+return false;
+
+  return true;
+}
+
+// Instantiate Function of the FreeBSD Kernel Dynamic Loader Plugin called when
+// Register the Plugin
+DynamicLoader *
+DynamicLoaderFreeBSDKernel::CreateInstance(lldb_private::Process *proce

[Lldb-commits] [lldb] [lldb] add stop-at-main option to process launch (PR #67019)

2023-09-26 Thread José Lira Junior via lldb-commits


@@ -38,7 +38,18 @@ Status CommandOptionsProcessLaunch::SetOptionValue(
   case 's': // Stop at program entry point
 launch_info.GetFlags().Set(eLaunchFlagStopAtEntry);
 break;
-
+  case 'm': // Stop at main function
+  {
+TargetSP target_sp =
+execution_context ? execution_context->GetTargetSP() : TargetSP();
+BreakpointSP bp_sp = target_sp->CreateBreakpoint(
+nullptr, nullptr, "main", eFunctionNameTypeAuto, eLanguageTypeUnknown,

junior-jl wrote:

> If you find more than one name, there's a Target::CreateBreakpoint overload 
> that takes a `const char *func_names[]` - that you can use to make one 
> portmanteau breakpoint for all the entry point names.

Is this meant for scenarios where a program is written in more than one 
programming language?

https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast updated 
https://github.com/llvm/llvm-project/pull/67106

>From f8ed3ed64be0a451542a4ec71f254dc9038b2d19 Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Fri, 22 Sep 2023 18:11:07 +0800
Subject: [PATCH 1/3] feat: add DynamicLoaderFreeBSDKernel

---
 .../Plugins/DynamicLoader/CMakeLists.txt  |   1 +
 .../FreeBSD-Kernel/CMakeLists.txt |  13 +
 .../DynamicLoaderFreeBSDKernel.cpp| 770 ++
 .../DynamicLoaderFreeBSDKernel.h  | 165 
 .../FreeBSDKernel/ProcessFreeBSDKernel.cpp|   4 +-
 5 files changed, 951 insertions(+), 2 deletions(-)
 create mode 100644 
lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/CMakeLists.txt
 create mode 100644 
lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 create mode 100644 
lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.h

diff --git a/lldb/source/Plugins/DynamicLoader/CMakeLists.txt 
b/lldb/source/Plugins/DynamicLoader/CMakeLists.txt
index f357fea02efbe68..30607159acdc088 100644
--- a/lldb/source/Plugins/DynamicLoader/CMakeLists.txt
+++ b/lldb/source/Plugins/DynamicLoader/CMakeLists.txt
@@ -1,4 +1,5 @@
 add_subdirectory(Darwin-Kernel)
+add_subdirectory(FreeBSD-Kernel)
 add_subdirectory(MacOSX-DYLD)
 add_subdirectory(POSIX-DYLD)
 add_subdirectory(Static)
diff --git a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/CMakeLists.txt 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/CMakeLists.txt
new file mode 100644
index 000..76daf0a327cf97b
--- /dev/null
+++ b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/CMakeLists.txt
@@ -0,0 +1,13 @@
+add_lldb_library(lldbPluginDynamicLoaderFreeBSDKernel PLUGIN
+  DynamicLoaderFreeBSDKernel.cpp
+
+  LINK_LIBS
+lldbBreakpoint
+lldbCore
+lldbHost
+lldbInterpreter
+lldbSymbol
+lldbTarget
+lldbUtility
+lldbPluginObjectFileELF
+  )
diff --git 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
new file mode 100644
index 000..d5eb891f0060bea
--- /dev/null
+++ 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -0,0 +1,770 @@
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Core/ModuleSpec.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Section.h"
+#include "lldb/Core/StreamFile.h"
+#include "lldb/Interpreter/OptionValueProperties.h"
+#include "lldb/Symbol/LocateSymbolFile.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Target/OperatingSystem.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlanRunToAddress.h"
+#include "lldb/Utility/DataBuffer.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+
+#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
+
+#include "DynamicLoaderFreeBSDKernel.h"
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+LLDB_PLUGIN_DEFINE(DynamicLoaderFreeBSDKernel)
+
+void DynamicLoaderFreeBSDKernel::Initialize() {
+  PluginManager::RegisterPlugin(GetPluginNameStatic(),
+GetPluginDescriptionStatic(), CreateInstance,
+DebuggerInit);
+}
+
+void DynamicLoaderFreeBSDKernel::Terminate() {
+  PluginManager::UnregisterPlugin(CreateInstance);
+}
+
+llvm::StringRef DynamicLoaderFreeBSDKernel::GetPluginDescriptionStatic() {
+  return "The Dynamic Loader Plugin For FreeBSD Kernel";
+}
+
+static bool is_kernel(Module *module) {
+  if (!module)
+return false;
+
+  ObjectFile *objfile = module->GetObjectFile();
+  if (!objfile)
+return false;
+  if (objfile->GetType() != ObjectFile::eTypeExecutable)
+return false;
+  if (objfile->GetStrata() != ObjectFile::eStrataUnknown &&
+  objfile->GetStrata() != ObjectFile::eStrataUser)
+return false;
+
+  return true;
+}
+
+static bool is_kmod(Module *module) {
+  if (!module)
+return false;
+  if (!module->GetObjectFile())
+return false;
+  ObjectFile *objfile = module->GetObjectFile();
+  if (objfile->GetType() != ObjectFile::eTypeObjectFile &&
+  objfile->GetType() != ObjectFile::eTypeSharedLibrary)
+return false;
+
+  return true;
+}
+
+static bool is_reloc(Module *module) {
+  if (!module)
+return false;
+  if (!module->GetObjectFile())
+return false;
+  ObjectFile *objfile = module->GetObjectFile();
+  if (objfile->GetType() != ObjectFile::eTypeObjectFile)
+return false;
+
+  return true;
+}
+
+// Instantiate Function of the FreeBSD Kernel Dynamic Loader Plugin called when
+// Register the Plugin
+DynamicLoader *
+DynamicLoaderFreeBSDKernel::CreateInstance(lldb_private::Process *proce

[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast updated 
https://github.com/llvm/llvm-project/pull/67106

>From f8ed3ed64be0a451542a4ec71f254dc9038b2d19 Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Fri, 22 Sep 2023 18:11:07 +0800
Subject: [PATCH 1/3] feat: add DynamicLoaderFreeBSDKernel

---
 .../Plugins/DynamicLoader/CMakeLists.txt  |   1 +
 .../FreeBSD-Kernel/CMakeLists.txt |  13 +
 .../DynamicLoaderFreeBSDKernel.cpp| 770 ++
 .../DynamicLoaderFreeBSDKernel.h  | 165 
 .../FreeBSDKernel/ProcessFreeBSDKernel.cpp|   4 +-
 5 files changed, 951 insertions(+), 2 deletions(-)
 create mode 100644 
lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/CMakeLists.txt
 create mode 100644 
lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 create mode 100644 
lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.h

diff --git a/lldb/source/Plugins/DynamicLoader/CMakeLists.txt 
b/lldb/source/Plugins/DynamicLoader/CMakeLists.txt
index f357fea02efbe68..30607159acdc088 100644
--- a/lldb/source/Plugins/DynamicLoader/CMakeLists.txt
+++ b/lldb/source/Plugins/DynamicLoader/CMakeLists.txt
@@ -1,4 +1,5 @@
 add_subdirectory(Darwin-Kernel)
+add_subdirectory(FreeBSD-Kernel)
 add_subdirectory(MacOSX-DYLD)
 add_subdirectory(POSIX-DYLD)
 add_subdirectory(Static)
diff --git a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/CMakeLists.txt 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/CMakeLists.txt
new file mode 100644
index 000..76daf0a327cf97b
--- /dev/null
+++ b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/CMakeLists.txt
@@ -0,0 +1,13 @@
+add_lldb_library(lldbPluginDynamicLoaderFreeBSDKernel PLUGIN
+  DynamicLoaderFreeBSDKernel.cpp
+
+  LINK_LIBS
+lldbBreakpoint
+lldbCore
+lldbHost
+lldbInterpreter
+lldbSymbol
+lldbTarget
+lldbUtility
+lldbPluginObjectFileELF
+  )
diff --git 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
new file mode 100644
index 000..d5eb891f0060bea
--- /dev/null
+++ 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -0,0 +1,770 @@
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Core/ModuleSpec.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Section.h"
+#include "lldb/Core/StreamFile.h"
+#include "lldb/Interpreter/OptionValueProperties.h"
+#include "lldb/Symbol/LocateSymbolFile.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Target/OperatingSystem.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlanRunToAddress.h"
+#include "lldb/Utility/DataBuffer.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+
+#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
+
+#include "DynamicLoaderFreeBSDKernel.h"
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+LLDB_PLUGIN_DEFINE(DynamicLoaderFreeBSDKernel)
+
+void DynamicLoaderFreeBSDKernel::Initialize() {
+  PluginManager::RegisterPlugin(GetPluginNameStatic(),
+GetPluginDescriptionStatic(), CreateInstance,
+DebuggerInit);
+}
+
+void DynamicLoaderFreeBSDKernel::Terminate() {
+  PluginManager::UnregisterPlugin(CreateInstance);
+}
+
+llvm::StringRef DynamicLoaderFreeBSDKernel::GetPluginDescriptionStatic() {
+  return "The Dynamic Loader Plugin For FreeBSD Kernel";
+}
+
+static bool is_kernel(Module *module) {
+  if (!module)
+return false;
+
+  ObjectFile *objfile = module->GetObjectFile();
+  if (!objfile)
+return false;
+  if (objfile->GetType() != ObjectFile::eTypeExecutable)
+return false;
+  if (objfile->GetStrata() != ObjectFile::eStrataUnknown &&
+  objfile->GetStrata() != ObjectFile::eStrataUser)
+return false;
+
+  return true;
+}
+
+static bool is_kmod(Module *module) {
+  if (!module)
+return false;
+  if (!module->GetObjectFile())
+return false;
+  ObjectFile *objfile = module->GetObjectFile();
+  if (objfile->GetType() != ObjectFile::eTypeObjectFile &&
+  objfile->GetType() != ObjectFile::eTypeSharedLibrary)
+return false;
+
+  return true;
+}
+
+static bool is_reloc(Module *module) {
+  if (!module)
+return false;
+  if (!module->GetObjectFile())
+return false;
+  ObjectFile *objfile = module->GetObjectFile();
+  if (objfile->GetType() != ObjectFile::eTypeObjectFile)
+return false;
+
+  return true;
+}
+
+// Instantiate Function of the FreeBSD Kernel Dynamic Loader Plugin called when
+// Register the Plugin
+DynamicLoader *
+DynamicLoaderFreeBSDKernel::CreateInstance(lldb_private::Process *proce

[Lldb-commits] [lldb] [lldb][Commands] Check that modules reports that they're loaded (PR #66144)

2023-09-26 Thread Chelsea Cassanova via lldb-commits

https://github.com/chelcassanova edited 
https://github.com/llvm/llvm-project/pull/66144
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast resolved 
https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast resolved 
https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast resolved 
https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast resolved 
https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast resolved 
https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast resolved 
https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast resolved 
https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast resolved 
https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast unresolved 
https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast unresolved 
https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast resolved 
https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast resolved 
https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast resolved 
https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast resolved 
https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

aokblast wrote:

I fix all mentioned issue and test on both x86-64 and arm64.
Hope everyone can give it a review.
Thanks!

https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add SetValueFromCString API to SyntheticFronend (PR #67309)

2023-09-26 Thread via lldb-commits

jimingham wrote:

This part of the change seems straightforward, if the synthetic child provider 
can set a value it will have to have this API...

But yes, if there are a bunch of patches that build on one another, if they 
aren't too big one patch that shows the functionality is easier to understand, 
or put a few substantial patches up but mark them as depending on the previous 
ones,  so we can get the big picture.

Jim
 

> On Sep 25, 2023, at 11:07 PM, Pavel Kosov ***@***.***> wrote:
> 
> 
> @kpdev commented on this pull request.
> 
> In lldb/include/lldb/DataFormatters/TypeSynthetic.h 
> :
> 
> > +  virtual bool SetValueFromCString(const char *value_str, Status &error) {
> +return false;
> +  }
> +
> It will be used in the following patches (it is the first, two more to come). 
> But maybe it is better to use one big patch with all changes?
> 
> —
> Reply to this email directly, view it on GitHub 
> , or 
> unsubscribe 
> .
> You are receiving this because you are on a team that was mentioned.
> 



https://github.com/llvm/llvm-project/pull/67309
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] add stop-at-main option to process launch (PR #67019)

2023-09-26 Thread via lldb-commits
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


jimingham wrote:



> On Sep 26, 2023, at 7:55 AM, José Lira Junior ***@***.***> wrote:
> 
> 
> @junior-jl commented on this pull request.
> 
> In lldb/source/Commands/CommandOptionsProcessLaunch.cpp 
> :
> 
> > @@ -38,7 +38,18 @@ Status CommandOptionsProcessLaunch::SetOptionValue(
>case 's': // Stop at program entry point
>  launch_info.GetFlags().Set(eLaunchFlagStopAtEntry);
>  break;
> -
> +  case 'm': // Stop at main function
> +  {
> +TargetSP target_sp =
> +execution_context ? execution_context->GetTargetSP() : TargetSP();
> +BreakpointSP bp_sp = target_sp->CreateBreakpoint(
> +nullptr, nullptr, "main", eFunctionNameTypeAuto, 
> eLanguageTypeUnknown,
> If you find more than one name, there's a Target::CreateBreakpoint overload 
> that takes a const char *func_names[] - that you can use to make one 
> portmanteau breakpoint for all the entry point names.
> 
> Is this meant for scenarios where a program is written in more than one 
> programming language?
> 
Right.  Mixing programming languages in a single executable is pretty common 
these days, so we need to support that scenario.

You either have to be able to figure out from the executable that "the main 
entry point for this code is implemented by language X and so I know which 
symbol to set a breakpoint on" or you just set a breakpoint on all the entry 
points you know and let which ones find BreakpointLocations or get hit tell you 
the answer to that question.  The latter method is easier to implement, and 
maybe the only way if there's nothing telling you which language contributed 
the "main" function.

Jim


> —
> Reply to this email directly, view it on GitHub 
> , or 
> unsubscribe 
> .
> You are receiving this because you were mentioned.
> 



https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread Greg Clayton via lldb-commits

https://github.com/clayborg commented:

Just one header file header to be fixed and this looks good to me. I will let 
other FreeBSD folks do the final approval since I don't work on FreeBSD.

https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread Greg Clayton via lldb-commits


@@ -0,0 +1,172 @@
+//===-- DynamicLoaderFreeBSDKernel.h
+//--===//

clayborg wrote:

Fix this comment line to be a single line and also include the C++ stuff for 
editors:
```
//===-- DynamicLoaderFreeBSDKernel.h ---*- C++ -*-===//
```

https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread Greg Clayton via lldb-commits

https://github.com/clayborg edited 
https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] add stop-at-main option to process launch (PR #67019)

2023-09-26 Thread via lldb-commits
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


jimingham wrote:

Yes that's right.  Normally what happens in program execution is the main 
executable gets loaded along with the dynamic loader, and then the loader runs, 
leading the program through several rounds of shared library loading (that can 
be a lot of shared libraries these days) and THEN runs the user entry point.  
Adding this filter means that we won't try to resolve a "main" breakpoint in 
every one of those shared libraries.

Jim

> On Sep 26, 2023, at 7:39 AM, José Lira Junior ***@***.***> wrote:
> 
> 
> @junior-jl commented on this pull request.
> 
> In lldb/source/Commands/CommandOptionsProcessLaunch.cpp 
> :
> 
> > @@ -38,7 +38,18 @@ Status CommandOptionsProcessLaunch::SetOptionValue(
>case 's': // Stop at program entry point
>  launch_info.GetFlags().Set(eLaunchFlagStopAtEntry);
>  break;
> -
> +  case 'm': // Stop at main function
> +  {
> +TargetSP target_sp =
> +execution_context ? execution_context->GetTargetSP() : TargetSP();
> +BreakpointSP bp_sp = target_sp->CreateBreakpoint(
> +nullptr, nullptr, "main", eFunctionNameTypeAuto, 
> eLanguageTypeUnknown,
> It's also a good idea to add a shared library filter instead of the first 
> nullptr in the code above, and specify the main executable. You know the 
> entry point has to be in the main executable, and so it would be inefficient 
> to search the whole world for this breakpoint. It could also end up not being 
> what you want, because some other shared library might call a function named 
> "main" as part of it's shared library loading code (which happens before the 
> language's entry point) so you would in fact stop too early.
> 
> I see. Something like this?
> 
> ModuleSP main_module_sp = target_sp->GetExecutableModule();
> FileSpecList shared_lib_filter;
> shared_lib_filter.Append(main_module_sp->GetFileSpec());
> BreakpointSP bp_sp = target_sp->CreateBreakpoint(
> &shared_lib_filter, nullptr, "main", eFunctionNameTypeFull, 
> eLanguageTypeUnknown,
> 0, eLazyBoolNo, false, false);
> —
> Reply to this email directly, view it on GitHub 
> , or 
> unsubscribe 
> .
> You are receiving this because you were mentioned.
> 



https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][DWARFASTParserClang] Resolve nested types when parsing structures (PR #66879)

2023-09-26 Thread Vlad Serebrennikov via lldb-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/66879

>From 72f83fb2944829c60bd6f12a079bfba95da4f6e7 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Thu, 14 Sep 2023 09:46:53 +0300
Subject: [PATCH 1/3] Implementation (migrated from Phabricator)

---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 15 +--
 .../SymbolFile/DWARF/DWARFASTParserClang.h|  2 +-
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 37fb16d4e0351c9..fc340da8eba0763 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2150,14 +2150,14 @@ bool DWARFASTParserClang::CompleteRecordType(const 
DWARFDIE &die,
 
 std::vector> bases;
 // Parse members and base classes first
-std::vector member_function_dies;
+std::vector member_function_and_type_dies;
 
 DelayedPropertyList delayed_properties;
-ParseChildMembers(die, clang_type, bases, member_function_dies,
+ParseChildMembers(die, clang_type, bases, member_function_and_type_dies,
   delayed_properties, default_accessibility, layout_info);
 
-// Now parse any methods if there were any...
-for (const DWARFDIE &die : member_function_dies)
+// Now parse any methods or nested types if there were any...
+for (const DWARFDIE &die : member_function_and_type_dies)
   dwarf->ResolveType(die);
 
 if (type_is_objc_object_or_interface) {
@@ -3153,7 +3153,7 @@ void DWARFASTParserClang::ParseSingleMember(
 bool DWARFASTParserClang::ParseChildMembers(
 const DWARFDIE &parent_die, CompilerType &class_clang_type,
 std::vector> &base_classes,
-std::vector &member_function_dies,
+std::vector &member_function_and_type_dies,
 DelayedPropertyList &delayed_properties,
 const AccessType default_accessibility,
 ClangASTImporter::LayoutInfo &layout_info) {
@@ -3189,8 +3189,11 @@ bool DWARFASTParserClang::ParseChildMembers(
   break;
 
 case DW_TAG_subprogram:
+case DW_TAG_enumeration_type:
+case DW_TAG_structure_type:
+case DW_TAG_union_type:
   // Let the type parsing code handle this one for us.
-  member_function_dies.push_back(die);
+  member_function_and_type_dies.push_back(die);
   break;
 
 case DW_TAG_inheritance:
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
index 88bfc490e890744..d4218959e61a8fa 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -157,7 +157,7 @@ class DWARFASTParserClang : public DWARFASTParser {
   bool ParseChildMembers(
   const DWARFDIE &die, lldb_private::CompilerType &class_compiler_type,
   std::vector> &base_classes,
-  std::vector &member_function_dies,
+  std::vector &member_function_and_type_dies,
   DelayedPropertyList &delayed_properties,
   const lldb::AccessType default_accessibility,
   lldb_private::ClangASTImporter::LayoutInfo &layout_info);

>From 4a4aa7ad35124414aafdb7db44c89e51f498aa83 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 20 Sep 2023 12:32:44 +0300
Subject: [PATCH 2/3] Add an incomplete unit test

---
 .../DWARF/DWARFASTParserClangTests.cpp| 93 +++
 1 file changed, 93 insertions(+)

diff --git a/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp 
b/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
index 20a085741f73d00..d47f9b636ec15eb 100644
--- a/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
+++ b/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
@@ -462,3 +462,96 @@ TEST_F(DWARFASTParserClangTests, 
TestDefaultTemplateParamParsing) {
 }
   }
 }
+
+TEST_F(DWARFASTParserClangTests, EnsureNestedTypesOfTypeAreParsed) {
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_str:
+- Info
+- B
+- C
+- Mask
+- Enum
+  debug_abbrev:
+- Table:
+- Code:0x1
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_yes
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Code:0x2
+  Tag: DW_TAG_structure_type
+  Children:DW_CHILDREN_yes
+  Attributes:
+- Attribute:   DW_AT_name
+  Form:DW_FORM_strp
+- Code:0x3
+  Tag: DW_TAG_union_type
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_name
+  Form:  

[Lldb-commits] [lldb] [lldb] add stop-at-main option to process launch (PR #67019)

2023-09-26 Thread via lldb-commits
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


jimingham wrote:



> On Sep 26, 2023, at 7:29 AM, José Lira Junior ***@***.***> wrote:
> 
> 
> @junior-jl commented on this pull request.
> 
> In lldb/source/Commands/CommandOptionsProcessLaunch.cpp 
> :
> 
> > @@ -38,7 +38,18 @@ Status CommandOptionsProcessLaunch::SetOptionValue(
>case 's': // Stop at program entry point
>  launch_info.GetFlags().Set(eLaunchFlagStopAtEntry);
>  break;
> -
> +  case 'm': // Stop at main function
> +  {
> +TargetSP target_sp =
> +execution_context ? execution_context->GetTargetSP() : TargetSP();
> +BreakpointSP bp_sp = target_sp->CreateBreakpoint(
> +nullptr, nullptr, "main", eFunctionNameTypeAuto, 
> eLanguageTypeUnknown,
> We should add a new API to the Language plugin: 
> Language::GetUserEntrypointName() and then this code should iterate over all 
> the supported languages building up a unique list of entry point names using 
> this API. At present there's going to be one: "main" repeated many times but 
> I think Walter promised us another one soon...
> 
> About this, Walter had proposed the following: "I'd suggest adding a virtual 
> method GetMainSymbol to the Language.h interface, which could be implemented 
> by each language plugin.". I guess it's a good approach. What are your 
> thoughts?
> 

Right, that's also what I was suggesting.  W.r.t. Walter's suggestion, I still 
think it's better to use a generic term (I suggested GetUserEntrypointName) 
rather than explicitly using  the word "main", which is the C name for this 
feature...  Greg suggested making this change to the option name as well 
earlier in this thread.

Jim

> —
> Reply to this email directly, view it on GitHub 
> , or 
> unsubscribe 
> .
> You are receiving this because you were mentioned.
> 



https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread Alex Langford via lldb-commits


@@ -0,0 +1,770 @@
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Core/ModuleSpec.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Section.h"
+#include "lldb/Core/StreamFile.h"
+#include "lldb/Interpreter/OptionValueProperties.h"
+#include "lldb/Symbol/LocateSymbolFile.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Target/OperatingSystem.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlanRunToAddress.h"
+#include "lldb/Utility/DataBuffer.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+
+#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
+
+#include "DynamicLoaderFreeBSDKernel.h"
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+LLDB_PLUGIN_DEFINE(DynamicLoaderFreeBSDKernel)
+
+void DynamicLoaderFreeBSDKernel::Initialize() {
+  PluginManager::RegisterPlugin(GetPluginNameStatic(),
+GetPluginDescriptionStatic(), CreateInstance,
+DebuggerInit);
+}
+
+void DynamicLoaderFreeBSDKernel::Terminate() {
+  PluginManager::UnregisterPlugin(CreateInstance);
+}
+
+llvm::StringRef DynamicLoaderFreeBSDKernel::GetPluginDescriptionStatic() {
+  return "The Dynamic Loader Plugin For FreeBSD Kernel";
+}
+
+static bool is_kernel(Module *module) {
+  if (!module)
+return false;
+
+  ObjectFile *objfile = module->GetObjectFile();
+  if (!objfile)
+return false;
+  if (objfile->GetType() != ObjectFile::eTypeExecutable)
+return false;
+  if (objfile->GetStrata() != ObjectFile::eStrataUnknown &&
+  objfile->GetStrata() != ObjectFile::eStrataUser)
+return false;
+
+  return true;
+}
+
+static bool is_kmod(Module *module) {
+  if (!module)
+return false;
+  if (!module->GetObjectFile())
+return false;
+  ObjectFile *objfile = module->GetObjectFile();
+  if (objfile->GetType() != ObjectFile::eTypeObjectFile &&
+  objfile->GetType() != ObjectFile::eTypeSharedLibrary)
+return false;
+
+  return true;
+}
+
+static bool is_reloc(Module *module) {
+  if (!module)
+return false;
+  if (!module->GetObjectFile())
+return false;
+  ObjectFile *objfile = module->GetObjectFile();
+  if (objfile->GetType() != ObjectFile::eTypeObjectFile)
+return false;
+
+  return true;
+}
+
+// Instantiate Function of the FreeBSD Kernel Dynamic Loader Plugin called when
+// Register the Plugin
+DynamicLoader *
+DynamicLoaderFreeBSDKernel::CreateInstance(lldb_private::Process *process,
+   bool force) {
+  // Check the environment when the plugin is not force loaded
+  Log *log = GetLog(LLDBLog::DynamicLoader);
+  LLDB_LOGF(log, "DynamicLoaderFreeBSDKernel::CreateInstance: "
+ "Try to create instance");
+  if (!force) {
+Module *exec = process->GetTarget().GetExecutableModulePointer();
+// Check if the target is kernel
+if (exec && !is_kernel(exec)) {
+  return nullptr;
+}
+
+const llvm::Triple &triple_ref =
+process->GetTarget().GetArchitecture().GetTriple();
+if (!triple_ref.isOSFreeBSD()) {
+  return nullptr;
+}
+  }
+
+  // At this point we have checked the target is a FreeBSD kernel and all we
+  // have to do is to find the kernel address
+  const addr_t kernel_address = FindFreeBSDKernel(process);
+
+  if (CheckForKernelImageAtAddress(process, kernel_address).IsValid())
+return new DynamicLoaderFreeBSDKernel(process, kernel_address);
+
+  return nullptr;
+}
+
+addr_t
+DynamicLoaderFreeBSDKernel::FindFreeBSDKernel(lldb_private::Process *process) {
+  addr_t kernel_addr = process->GetImageInfoAddress();
+  if (kernel_addr == LLDB_INVALID_ADDRESS)
+kernel_addr = FindKernelAtLoadAddress(process);
+  return kernel_addr;
+}
+
+// Get the kernel address if the kernel is not loaded with a slide
+addr_t DynamicLoaderFreeBSDKernel::FindKernelAtLoadAddress(
+lldb_private::Process *process) {
+  Module *exe_module = process->GetTarget().GetExecutableModulePointer();
+
+  if (!is_kernel(exe_module))
+return LLDB_INVALID_ADDRESS;
+
+  ObjectFile *exe_objfile = exe_module->GetObjectFile();
+
+  if (!exe_objfile->GetBaseAddress().IsValid())
+return LLDB_INVALID_ADDRESS;
+
+  if (CheckForKernelImageAtAddress(
+  process, exe_objfile->GetBaseAddress().GetFileAddress())
+  .IsValid())
+return exe_objfile->GetBaseAddress().GetFileAddress();
+
+  return LLDB_INVALID_ADDRESS;
+}
+
+// Read ELF header from memry and return
+bool DynamicLoaderFreeBSDKernel::ReadELFHeader(Process *process,
+   lldb::addr_t addr,
+   llvm::ELF::Elf32_Ehdr &header,
+

[Lldb-commits] [lldb] [clang-tidy] Add performance-move-smart-pointer-contents check. (PR #66139)

2023-09-26 Thread via lldb-commits

pizzud wrote:

Extracted the shared_ptr parts to 
https://github.com/llvm/llvm-project/pull/67467. I'll continue the unique_ptr 
portion here and respond to those comments later today.

https://github.com/llvm/llvm-project/pull/66139
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Implement thread local storage for linux (PR #67470)

2023-09-26 Thread via lldb-commits

https://github.com/jeffreytan81 created 
https://github.com/llvm/llvm-project/pull/67470

None

>From 5e8b4a44bf48216785f5ecb412e145a7ac4d3a55 Mon Sep 17 00:00:00 2001
From: jeffreytan81 
Date: Tue, 26 Sep 2023 11:04:08 -0700
Subject: [PATCH] Implement thread local storage for linux

---
 lldb/include/lldb/Target/RegisterContext.h|  2 +
 lldb/include/lldb/lldb-defines.h  |  1 +
 .../POSIX-DYLD/DYLDRendezvous.cpp | 11 ++---
 .../POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp | 49 +++
 .../Utility/RegisterInfos_x86_64_with_base.h  | 13 +
 .../GDBRemoteCommunicationServerLLGS.cpp  |  2 +
 lldb/source/Target/RegisterContext.cpp|  6 +++
 lldb/source/Target/Thread.cpp |  6 ++-
 lldb/source/Utility/Args.cpp  |  1 +
 .../API/lang/c/tls_globals/TestTlsGlobals.py  |  5 +-
 10 files changed, 65 insertions(+), 31 deletions(-)

diff --git a/lldb/include/lldb/Target/RegisterContext.h 
b/lldb/include/lldb/Target/RegisterContext.h
index de0efd982daaa71..b2626928f142604 100644
--- a/lldb/include/lldb/Target/RegisterContext.h
+++ b/lldb/include/lldb/Target/RegisterContext.h
@@ -144,6 +144,8 @@ class RegisterContext : public 
std::enable_shared_from_this,
 
   uint64_t GetPC(uint64_t fail_value = LLDB_INVALID_ADDRESS);
 
+  uint64_t GetThreadPointer(uint64_t fail_value = LLDB_INVALID_ADDRESS);
+
   /// Get an address suitable for symbolication.
   /// When symbolicating -- computing line, block, function --
   /// for a function in the middle of the stack, using the return
diff --git a/lldb/include/lldb/lldb-defines.h b/lldb/include/lldb/lldb-defines.h
index ce7fd6f3754516e..aaf0b04e4fb86e9 100644
--- a/lldb/include/lldb/lldb-defines.h
+++ b/lldb/include/lldb/lldb-defines.h
@@ -71,6 +71,7 @@
   11 // The register that would contain pointer size or less argument 7 (if 
any)
 #define LLDB_REGNUM_GENERIC_ARG8   
\
   12 // The register that would contain pointer size or less argument 8 (if 
any)
+#define LLDB_REGNUM_GENERIC_TP 13 // Thread pointer
 /// Invalid value definitions
 #define LLDB_INVALID_STOP_ID 0
 #define LLDB_INVALID_ADDRESS UINT64_MAX
diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp 
b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
index 68e4ac0cc4007c4..cb174d31b86dfe6 100644
--- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
+++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
@@ -710,16 +710,13 @@ bool DYLDRendezvous::FindMetadata(const char *name, 
PThreadField field,
   target.GetImages().FindSymbolsWithNameAndType(ConstString(name),
 eSymbolTypeAny, list);
   if (list.IsEmpty())
-  return false;
-
-  Address address = list[0].symbol->GetAddress();
-  addr_t addr = address.GetLoadAddress(&target);
-  if (addr == LLDB_INVALID_ADDRESS)
 return false;
 
+  Address address = list[0].symbol->GetAddress();
+  address.SetOffset(address.GetOffset() + field * sizeof(uint32_t));
   Status error;
-  value = (uint32_t)m_process->ReadUnsignedIntegerFromMemory(
-  addr + field * sizeof(uint32_t), sizeof(uint32_t), 0, error);
+  value =
+  target.ReadUnsignedIntegerFromMemory(address, sizeof(uint32_t), 0, 
error);
   if (error.Fail())
 return false;
 
diff --git 
a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp 
b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
index b4b38a88e1b9c7a..85d7ae9dac75d1e 100644
--- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -420,6 +420,11 @@ void DynamicLoaderPOSIXDYLD::RefreshModules() {
   if (!m_rendezvous.Resolve())
 return;
 
+  // The rendezvous class doesn't enumerate the main module, so track that
+  // ourselves here.
+  ModuleSP executable = GetTargetExecutable();
+  m_loaded_modules[executable] = m_rendezvous.GetLinkMapAddress();
+
   DYLDRendezvous::iterator I;
   DYLDRendezvous::iterator E;
 
@@ -727,41 +732,66 @@ lldb::addr_t
 DynamicLoaderPOSIXDYLD::GetThreadLocalData(const lldb::ModuleSP module_sp,
const lldb::ThreadSP thread,
lldb::addr_t tls_file_addr) {
+  Log *log = GetLog(LLDBLog::DynamicLoader);
   auto it = m_loaded_modules.find(module_sp);
-  if (it == m_loaded_modules.end())
+  if (it == m_loaded_modules.end()) {
+LLDB_LOGF(
+log, "GetThreadLocalData error: module(%s) not found in loaded 
modules",
+module_sp->GetObjectName().AsCString());
 return LLDB_INVALID_ADDRESS;
+  }
 
   addr_t link_map = it->second;
-  if (link_map == LLDB_INVALID_ADDRESS)
+  if (link_map == LLDB_INVALID_ADDRESS || link_map == 0) {
+LLDB_LOGF(log,
+  "GetThreadLocalData error: invalid link map address=0x%" PRIx64,
+  link_m

[Lldb-commits] [lldb] [lldb] Implement thread local storage for linux (PR #67470)

2023-09-26 Thread Nikita Popov via lldb-commits

https://github.com/nikic edited https://github.com/llvm/llvm-project/pull/67470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [clang-tidy] Add performance-move-smart-pointer-contents check. (PR #66139)

2023-09-26 Thread via lldb-commits

https://github.com/pizzud updated 
https://github.com/llvm/llvm-project/pull/66139

>From b699129b21c95571410a809d16fdf8cfcf1526c5 Mon Sep 17 00:00:00 2001
From: David Pizzuto 
Date: Tue, 12 Sep 2023 13:24:48 -0700
Subject: [PATCH 1/3] [clang-tidy] Add performance-move-smart-pointer-contents
 check.

This check detects moves of the contents of a smart pointer as opposed to the
smart pointer itself. For unique_ptr this is a performance issue, as the 
underlying
type is presumably not cheap to move, but for shared_ptr it's actually dangerous
as other code that also has access to the shared_ptr is probably not expecting 
the
move.

The set of "unique" and "shared" pointer classes are configurable via options to
allow individual projects to add additional classes of each type.
---
 .../clang-tidy/performance/CMakeLists.txt |   1 +
 .../MoveSmartPointerContentsCheck.cpp |  80 
 .../MoveSmartPointerContentsCheck.h   |  39 ++
 .../performance/PerformanceTidyModule.cpp |   3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../move-smart-pointer-contents.rst   |  23 
 .../move-smart-pointer-contents.cpp   | 119 ++
 8 files changed, 271 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/performance/MoveSmartPointerContentsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/performance/MoveSmartPointerContentsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/performance/move-smart-pointer-contents.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/performance/move-smart-pointer-contents.cpp

diff --git a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
index 81128ff086021ed..35435a951c0717b 100644
--- a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
@@ -14,6 +14,7 @@ add_clang_library(clangTidyPerformanceModule
   InefficientVectorOperationCheck.cpp
   MoveConstArgCheck.cpp
   MoveConstructorInitCheck.cpp
+  MoveSmartPointerContentsCheck.cpp
   NoAutomaticMoveCheck.cpp
   NoIntToPtrCheck.cpp
   NoexceptDestructorCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/performance/MoveSmartPointerContentsCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/MoveSmartPointerContentsCheck.cpp
new file mode 100644
index 000..8c1170641e5c718
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/performance/MoveSmartPointerContentsCheck.cpp
@@ -0,0 +1,80 @@
+//===--- MoveSmartPointerContentsCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include 
+
+#include "MoveSmartPointerContentsCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+MoveSmartPointerContentsCheck::MoveSmartPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  UniquePointerClasses(utils::options::parseStringList(
+  Options.get("UniquePointerClasses", "std::unique_ptr"))),
+  IsAUniquePointer(namedDecl(hasAnyName(UniquePointerClasses))),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "std::shared_ptr"))),
+  IsASharedPointer(namedDecl(hasAnyName(SharedPointerClasses))) {}
+
+void MoveSmartPointerContentsCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "UniquePtrClasses",
+utils::options::serializeStringList(UniquePointerClasses));
+  Options.store(Opts, "SharedPtrClasses",
+utils::options::serializeStringList(SharedPointerClasses));
+}
+
+void MoveSmartPointerContentsCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("std::move"))),
+  hasArgument(0, cxxOperatorCallExpr(hasOperatorName("*"),
+ 
hasDeclaration(cxxMethodDecl(ofClass(IsAUniquePointer.bind("unique_op")))   
+  .bind("unique_call"),
+  this);
+
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("std::move"))),
+  hasArgument(0, cxxOperatorCallExpr(hasOperatorName("*"),
+ 
hasDeclaration(cxxMethodDecl(ofClass(IsASharedPointer.bind("shared_op")))   
+  .bind("shared_call"),
+  this);
+}
+  
+void MoveSmartPointerCont

[Lldb-commits] [lldb] [clang-tidy] Add performance-move-smart-pointer-contents check. (PR #66139)

2023-09-26 Thread via lldb-commits

https://github.com/pizzud resolved 
https://github.com/llvm/llvm-project/pull/66139
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [clang-tidy] Add performance-move-smart-pointer-contents check. (PR #66139)

2023-09-26 Thread via lldb-commits


@@ -0,0 +1,23 @@
+.. title:: clang-tidy - performance-move-smart-pointer-contents
+
+performance-move-smart-pointer-contents
+===
+
+Given a smart pointer containing a movable type, such as a

pizzud wrote:

Done.

https://github.com/llvm/llvm-project/pull/66139
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement thread local storage for linux (PR #67470)

2023-09-26 Thread via lldb-commits

https://github.com/jeffreytan81 edited 
https://github.com/llvm/llvm-project/pull/67470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement thread local storage for linux (PR #67470)

2023-09-26 Thread via lldb-commits

https://github.com/jeffreytan81 ready_for_review 
https://github.com/llvm/llvm-project/pull/67470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement thread local storage for linux (PR #67470)

2023-09-26 Thread via lldb-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
50abfc4298980fc219c7d70ca2567c61e856b614..5e8b4a44bf48216785f5ecb412e145a7ac4d3a55
 lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py
``





View the diff from darker here.


``diff
--- TestTlsGlobals.py   2023-09-26 18:04:08.00 +
+++ TestTlsGlobals.py   2023-09-26 18:18:10.469169 +
@@ -36,13 +36,11 @@
 )
 
 # TLS works differently on Windows, this would need to be implemented
 # separately.
 @skipIfWindows
-@skipIf(
-oslist=no_match([lldbplatformutil.getDarwinOSTriples(), "linux"])
-)
+@skipIf(oslist=no_match([lldbplatformutil.getDarwinOSTriples(), "linux"]))
 def test(self):
 """Test thread-local storage."""
 self.build()
 exe = self.getBuildArtifact("a.out")
 target = self.dbg.CreateTarget(exe)

``




https://github.com/llvm/llvm-project/pull/67470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [clang-tidy] Add performance-move-smart-pointer-contents check. (PR #66139)

2023-09-26 Thread via lldb-commits

https://github.com/pizzud resolved 
https://github.com/llvm/llvm-project/pull/66139
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [clang-tidy] Add performance-move-smart-pointer-contents check. (PR #66139)

2023-09-26 Thread via lldb-commits

https://github.com/pizzud updated 
https://github.com/llvm/llvm-project/pull/66139

>From b699129b21c95571410a809d16fdf8cfcf1526c5 Mon Sep 17 00:00:00 2001
From: David Pizzuto 
Date: Tue, 12 Sep 2023 13:24:48 -0700
Subject: [PATCH 1/2] [clang-tidy] Add performance-move-smart-pointer-contents
 check.

This check detects moves of the contents of a smart pointer as opposed to the
smart pointer itself. For unique_ptr this is a performance issue, as the 
underlying
type is presumably not cheap to move, but for shared_ptr it's actually dangerous
as other code that also has access to the shared_ptr is probably not expecting 
the
move.

The set of "unique" and "shared" pointer classes are configurable via options to
allow individual projects to add additional classes of each type.
---
 .../clang-tidy/performance/CMakeLists.txt |   1 +
 .../MoveSmartPointerContentsCheck.cpp |  80 
 .../MoveSmartPointerContentsCheck.h   |  39 ++
 .../performance/PerformanceTidyModule.cpp |   3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../move-smart-pointer-contents.rst   |  23 
 .../move-smart-pointer-contents.cpp   | 119 ++
 8 files changed, 271 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/performance/MoveSmartPointerContentsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/performance/MoveSmartPointerContentsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/performance/move-smart-pointer-contents.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/performance/move-smart-pointer-contents.cpp

diff --git a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
index 81128ff086021ed..35435a951c0717b 100644
--- a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
@@ -14,6 +14,7 @@ add_clang_library(clangTidyPerformanceModule
   InefficientVectorOperationCheck.cpp
   MoveConstArgCheck.cpp
   MoveConstructorInitCheck.cpp
+  MoveSmartPointerContentsCheck.cpp
   NoAutomaticMoveCheck.cpp
   NoIntToPtrCheck.cpp
   NoexceptDestructorCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/performance/MoveSmartPointerContentsCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/MoveSmartPointerContentsCheck.cpp
new file mode 100644
index 000..8c1170641e5c718
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/performance/MoveSmartPointerContentsCheck.cpp
@@ -0,0 +1,80 @@
+//===--- MoveSmartPointerContentsCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include 
+
+#include "MoveSmartPointerContentsCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+MoveSmartPointerContentsCheck::MoveSmartPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  UniquePointerClasses(utils::options::parseStringList(
+  Options.get("UniquePointerClasses", "std::unique_ptr"))),
+  IsAUniquePointer(namedDecl(hasAnyName(UniquePointerClasses))),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "std::shared_ptr"))),
+  IsASharedPointer(namedDecl(hasAnyName(SharedPointerClasses))) {}
+
+void MoveSmartPointerContentsCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "UniquePtrClasses",
+utils::options::serializeStringList(UniquePointerClasses));
+  Options.store(Opts, "SharedPtrClasses",
+utils::options::serializeStringList(SharedPointerClasses));
+}
+
+void MoveSmartPointerContentsCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("std::move"))),
+  hasArgument(0, cxxOperatorCallExpr(hasOperatorName("*"),
+ 
hasDeclaration(cxxMethodDecl(ofClass(IsAUniquePointer.bind("unique_op")))   
+  .bind("unique_call"),
+  this);
+
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("std::move"))),
+  hasArgument(0, cxxOperatorCallExpr(hasOperatorName("*"),
+ 
hasDeclaration(cxxMethodDecl(ofClass(IsASharedPointer.bind("shared_op")))   
+  .bind("shared_call"),
+  this);
+}
+  
+void MoveSmartPointerCont

[Lldb-commits] [lldb] [clang-tidy] Add performance-move-smart-pointer-contents check. (PR #66139)

2023-09-26 Thread via lldb-commits

https://github.com/pizzud resolved 
https://github.com/llvm/llvm-project/pull/66139
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [clang-tidy] Add performance-move-smart-pointer-contents check. (PR #66139)

2023-09-26 Thread via lldb-commits

pizzud wrote:

After looking at the various comments (thanks all!) it feels like the consensus 
was:
- don't suggest fixes (done)
- move shared_ptr out to its own check (done in #67467 )
- be more precise in both language and implementation

Is there a reasonable way to detect expensive moves? Looking for 
trivially-moveable seems like a decent start, but it's hard to know when a 
given instance of a type may be large (eg long strings).

https://github.com/llvm/llvm-project/pull/66139
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement thread local storage for linux (PR #67470)

2023-09-26 Thread via lldb-commits

https://github.com/jeffreytan81 updated 
https://github.com/llvm/llvm-project/pull/67470

>From 5e8b4a44bf48216785f5ecb412e145a7ac4d3a55 Mon Sep 17 00:00:00 2001
From: jeffreytan81 
Date: Tue, 26 Sep 2023 11:04:08 -0700
Subject: [PATCH 1/2] Implement thread local storage for linux

---
 lldb/include/lldb/Target/RegisterContext.h|  2 +
 lldb/include/lldb/lldb-defines.h  |  1 +
 .../POSIX-DYLD/DYLDRendezvous.cpp | 11 ++---
 .../POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp | 49 +++
 .../Utility/RegisterInfos_x86_64_with_base.h  | 13 +
 .../GDBRemoteCommunicationServerLLGS.cpp  |  2 +
 lldb/source/Target/RegisterContext.cpp|  6 +++
 lldb/source/Target/Thread.cpp |  6 ++-
 lldb/source/Utility/Args.cpp  |  1 +
 .../API/lang/c/tls_globals/TestTlsGlobals.py  |  5 +-
 10 files changed, 65 insertions(+), 31 deletions(-)

diff --git a/lldb/include/lldb/Target/RegisterContext.h 
b/lldb/include/lldb/Target/RegisterContext.h
index de0efd982daaa71..b2626928f142604 100644
--- a/lldb/include/lldb/Target/RegisterContext.h
+++ b/lldb/include/lldb/Target/RegisterContext.h
@@ -144,6 +144,8 @@ class RegisterContext : public 
std::enable_shared_from_this,
 
   uint64_t GetPC(uint64_t fail_value = LLDB_INVALID_ADDRESS);
 
+  uint64_t GetThreadPointer(uint64_t fail_value = LLDB_INVALID_ADDRESS);
+
   /// Get an address suitable for symbolication.
   /// When symbolicating -- computing line, block, function --
   /// for a function in the middle of the stack, using the return
diff --git a/lldb/include/lldb/lldb-defines.h b/lldb/include/lldb/lldb-defines.h
index ce7fd6f3754516e..aaf0b04e4fb86e9 100644
--- a/lldb/include/lldb/lldb-defines.h
+++ b/lldb/include/lldb/lldb-defines.h
@@ -71,6 +71,7 @@
   11 // The register that would contain pointer size or less argument 7 (if 
any)
 #define LLDB_REGNUM_GENERIC_ARG8   
\
   12 // The register that would contain pointer size or less argument 8 (if 
any)
+#define LLDB_REGNUM_GENERIC_TP 13 // Thread pointer
 /// Invalid value definitions
 #define LLDB_INVALID_STOP_ID 0
 #define LLDB_INVALID_ADDRESS UINT64_MAX
diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp 
b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
index 68e4ac0cc4007c4..cb174d31b86dfe6 100644
--- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
+++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
@@ -710,16 +710,13 @@ bool DYLDRendezvous::FindMetadata(const char *name, 
PThreadField field,
   target.GetImages().FindSymbolsWithNameAndType(ConstString(name),
 eSymbolTypeAny, list);
   if (list.IsEmpty())
-  return false;
-
-  Address address = list[0].symbol->GetAddress();
-  addr_t addr = address.GetLoadAddress(&target);
-  if (addr == LLDB_INVALID_ADDRESS)
 return false;
 
+  Address address = list[0].symbol->GetAddress();
+  address.SetOffset(address.GetOffset() + field * sizeof(uint32_t));
   Status error;
-  value = (uint32_t)m_process->ReadUnsignedIntegerFromMemory(
-  addr + field * sizeof(uint32_t), sizeof(uint32_t), 0, error);
+  value =
+  target.ReadUnsignedIntegerFromMemory(address, sizeof(uint32_t), 0, 
error);
   if (error.Fail())
 return false;
 
diff --git 
a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp 
b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
index b4b38a88e1b9c7a..85d7ae9dac75d1e 100644
--- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -420,6 +420,11 @@ void DynamicLoaderPOSIXDYLD::RefreshModules() {
   if (!m_rendezvous.Resolve())
 return;
 
+  // The rendezvous class doesn't enumerate the main module, so track that
+  // ourselves here.
+  ModuleSP executable = GetTargetExecutable();
+  m_loaded_modules[executable] = m_rendezvous.GetLinkMapAddress();
+
   DYLDRendezvous::iterator I;
   DYLDRendezvous::iterator E;
 
@@ -727,41 +732,66 @@ lldb::addr_t
 DynamicLoaderPOSIXDYLD::GetThreadLocalData(const lldb::ModuleSP module_sp,
const lldb::ThreadSP thread,
lldb::addr_t tls_file_addr) {
+  Log *log = GetLog(LLDBLog::DynamicLoader);
   auto it = m_loaded_modules.find(module_sp);
-  if (it == m_loaded_modules.end())
+  if (it == m_loaded_modules.end()) {
+LLDB_LOGF(
+log, "GetThreadLocalData error: module(%s) not found in loaded 
modules",
+module_sp->GetObjectName().AsCString());
 return LLDB_INVALID_ADDRESS;
+  }
 
   addr_t link_map = it->second;
-  if (link_map == LLDB_INVALID_ADDRESS)
+  if (link_map == LLDB_INVALID_ADDRESS || link_map == 0) {
+LLDB_LOGF(log,
+  "GetThreadLocalData error: invalid link map address=0x%" PRIx64,
+  link_map

[Lldb-commits] [lldb] [lldb] add stop-at-main option to process launch (PR #67019)

2023-09-26 Thread José Lira Junior via lldb-commits

https://github.com/junior-jl updated 
https://github.com/llvm/llvm-project/pull/67019

From 11270775865a8415e00b4d899703f84717344967 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20L=2E=20Junior?= 
Date: Thu, 21 Sep 2023 11:12:58 -0300
Subject: [PATCH 1/5] [lldb] add command start

---
 lldb/source/Commands/CMakeLists.txt   |   1 +
 lldb/source/Commands/CommandObjectStart.cpp   | 102 ++
 lldb/source/Commands/CommandObjectStart.h |  32 ++
 .../source/Interpreter/CommandInterpreter.cpp |   2 +
 4 files changed, 137 insertions(+)
 create mode 100644 lldb/source/Commands/CommandObjectStart.cpp
 create mode 100644 lldb/source/Commands/CommandObjectStart.h

diff --git a/lldb/source/Commands/CMakeLists.txt 
b/lldb/source/Commands/CMakeLists.txt
index 6a36c5376d5c574..54c62e0f5284beb 100644
--- a/lldb/source/Commands/CMakeLists.txt
+++ b/lldb/source/Commands/CMakeLists.txt
@@ -30,6 +30,7 @@ add_lldb_library(lldbCommands NO_PLUGIN_DEPENDENCIES
   CommandObjectSession.cpp
   CommandObjectSettings.cpp
   CommandObjectSource.cpp
+  CommandObjectStart.cpp
   CommandObjectStats.cpp
   CommandObjectTarget.cpp
   CommandObjectThread.cpp
diff --git a/lldb/source/Commands/CommandObjectStart.cpp 
b/lldb/source/Commands/CommandObjectStart.cpp
new file mode 100644
index 000..7406143c50fec1b
--- /dev/null
+++ b/lldb/source/Commands/CommandObjectStart.cpp
@@ -0,0 +1,102 @@
+//===-- CommandObjectStart.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CommandObjectStart.h"
+#include "lldb/Interpreter/CommandObject.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+// Constructor for CommandObjectStart
+CommandObjectStart::CommandObjectStart(CommandInterpreter &interpreter)
+: CommandObjectParsed(
+  interpreter, "start",
+  "Launches the process and pauses execution at main function",
+  "start args [optional args]") {
+  // Define command arguments
+  CommandArgumentData pause_location{eArgTypeName, eArgRepeatPlain};
+  m_arguments.push_back({pause_location});
+}
+
+CommandObjectStart::~CommandObjectStart() = default;
+
+// Execute the 'start' command
+bool CommandObjectStart::DoExecute(Args &command, CommandReturnObject &result) 
{
+  // Check if the 'first' subcommand is specified
+  bool pause_at_first_instruction = false;
+
+  if (command.GetArgumentCount() == 1 &&
+  strcmp(command.GetArgumentAtIndex(0), "first") == 0) {
+pause_at_first_instruction = true;
+  }
+
+  // Get the current selected target
+  TargetSP target_sp = GetDebugger().GetSelectedTarget();
+  if (!target_sp) {
+result.AppendError("No target selected.\n");
+return false;
+  }
+
+  // Create the breakpoint at main or the first instruction
+  BreakpointSP bp_sp;
+  if (pause_at_first_instruction) {
+ModuleSP exe_module_sp = target_sp->GetExecutableModule();
+ObjectFile *object = exe_module_sp->GetObjectFile();
+Address address = object->GetEntryPointAddress();
+
+if (!address.IsValid()) {
+  result.AppendError("Failed to get the entry point address");
+  result.SetStatus(eReturnStatusFailed);
+  return false;
+}
+
+bp_sp = target_sp->CreateBreakpoint(address, false, false);
+
+  } else {
+// Create a breakpoint at the main function
+bp_sp = target_sp->CreateBreakpoint(
+nullptr, nullptr, "main", eFunctionNameTypeAuto, eLanguageTypeUnknown,
+0, eLazyBoolNo, false, false);
+  }
+
+  if (!bp_sp) {
+result.AppendError("Breakpoint creation failed.\n");
+result.SetStatus(eReturnStatusFailed);
+return false;
+  } else {
+result.GetOutputStream().Printf("Breakpoint created%s.\n",
+pause_at_first_instruction
+? " at first instruction"
+: " in main function");
+result.SetStatus(eReturnStatusSuccessFinishResult);
+  }
+
+  // Construct the process launch info
+  ProcessLaunchInfo launch_info;
+  launch_info.SetShell(HostInfo::GetDefaultShell());
+  ModuleSP exe_module_sp = target_sp->GetExecutableModule();
+  if (!exe_module_sp) {
+result.AppendError("No executable module found.\n");
+return false;
+  }
+
+  launch_info.SetExecutableFile(exe_module_sp->GetPlatformFileSpec(), true);
+  // Launch the process
+  StreamString stream;
+  Status error = target_sp->Launch(launch_info, &stream);
+
+  if (error.Success()) {
+result.SetStatus(eReturnStatusSuccessFinishResult);
+result.GetOutputStream().Printf("Process launched successfully.\n");
+  } else {
+result.AppendErrorWithFormat("Process launch failed: %s\n",
+ error.AsC

[Lldb-commits] [lldb] [lldb] add stop-at-main option to process launch (PR #67019)

2023-09-26 Thread José Lira Junior via lldb-commits

junior-jl wrote:

This is the case in the current commit. I was trying to implement this with 
SmallSet and const char* to use the overload you mentioned, Jim, but I was 
having trouble with it, specially because I needed to hard code a 'max number 
of languages'. So I used the overload that takes a std::vector. 
Let me know if that's not good. 

```cpp
case 'm': // Stop at user entry point
  {
TargetSP target_sp =
execution_context ? execution_context->GetTargetSP() : TargetSP();
ModuleSP main_module_sp = target_sp->GetExecutableModule();
FileSpecList shared_lib_filter;
shared_lib_filter.Append(main_module_sp->GetFileSpec());
std::vector entryPointNames;
for (LanguageType lang_type : Language::GetSupportedLanguages()) {
  Language *lang = Language::FindPlugin(lang_type);
  if (lang) {
std::string entryPointName = lang->GetUserEntryPointName();
if (!entryPointName.empty()) {
  entryPointNames.push_back(entryPointName);
}
  }
}
BreakpointSP bp_sp = target_sp->CreateBreakpoint(
/*containingModules=*/&shared_lib_filter,
/*containingSourceFiles=*/nullptr, 
/*func_names=*/entryPointNames,
/*func_name_type_mask=*/eFunctionNameTypeFull,
/*language=*/eLanguageTypeUnknown,
/*offset=*/0, /*skip_prologue=*/eLazyBoolNo, /*internal=*/false,
/*hardware=*/false);
if (!bp_sp)
  error.SetErrorString("Breakpoint creation failed.\n");
bp_sp->SetOneShot(true);
break;
  }
```

https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] add stop-at-main option to process launch (PR #67019)

2023-09-26 Thread José Lira Junior via lldb-commits

junior-jl wrote:

Also, I just noticed that `clang-format` did some minor changes to 
`Language.h`. Please, let me know if I need to revert those.

https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] add stop-at-main option to process launch (PR #67019)

2023-09-26 Thread José Lira Junior via lldb-commits

https://github.com/junior-jl resolved 
https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] add stop-at-main option to process launch (PR #67019)

2023-09-26 Thread José Lira Junior via lldb-commits

https://github.com/junior-jl resolved 
https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] add stop-at-main option to process launch (PR #67019)

2023-09-26 Thread via lldb-commits
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff eb31208be15326e6e6523611e6d3d8fdabbbc127 
d87cc70c4e702132f2e1cc86c8746e75f2814809 -- lldb/include/lldb/Target/Language.h 
lldb/source/Commands/CommandOptionsProcessLaunch.cpp 
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h 
lldb/source/Plugins/Language/ObjC/ObjCLanguage.h 
lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h 
b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
index 8da28e530059..4303a8defde2 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
@@ -104,7 +104,7 @@ public:
   }
 
   const char *GetUserEntryPointName() const override { return "main"; }
-  
+
   std::unique_ptr GetTypeScavenger() override;
   lldb::TypeCategoryImplSP GetFormatters() override;
 
diff --git a/lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h 
b/lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
index 74d503d1ffcf..177bb3517557 100644
--- a/lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
+++ b/lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
@@ -28,7 +28,7 @@ public:
   }
 
   const char *GetUserEntryPointName() const override { return "main"; }
-  
+
   llvm::StringRef GetNilReferenceSummaryString() override { return "nil"; }
 
   bool IsSourceFile(llvm::StringRef file_path) const override;

``




https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] add stop-at-main option to process launch (PR #67019)

2023-09-26 Thread José Lira Junior via lldb-commits

https://github.com/junior-jl updated 
https://github.com/llvm/llvm-project/pull/67019

From 11270775865a8415e00b4d899703f84717344967 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20L=2E=20Junior?= 
Date: Thu, 21 Sep 2023 11:12:58 -0300
Subject: [PATCH 1/6] [lldb] add command start

---
 lldb/source/Commands/CMakeLists.txt   |   1 +
 lldb/source/Commands/CommandObjectStart.cpp   | 102 ++
 lldb/source/Commands/CommandObjectStart.h |  32 ++
 .../source/Interpreter/CommandInterpreter.cpp |   2 +
 4 files changed, 137 insertions(+)
 create mode 100644 lldb/source/Commands/CommandObjectStart.cpp
 create mode 100644 lldb/source/Commands/CommandObjectStart.h

diff --git a/lldb/source/Commands/CMakeLists.txt 
b/lldb/source/Commands/CMakeLists.txt
index 6a36c5376d5c574..54c62e0f5284beb 100644
--- a/lldb/source/Commands/CMakeLists.txt
+++ b/lldb/source/Commands/CMakeLists.txt
@@ -30,6 +30,7 @@ add_lldb_library(lldbCommands NO_PLUGIN_DEPENDENCIES
   CommandObjectSession.cpp
   CommandObjectSettings.cpp
   CommandObjectSource.cpp
+  CommandObjectStart.cpp
   CommandObjectStats.cpp
   CommandObjectTarget.cpp
   CommandObjectThread.cpp
diff --git a/lldb/source/Commands/CommandObjectStart.cpp 
b/lldb/source/Commands/CommandObjectStart.cpp
new file mode 100644
index 000..7406143c50fec1b
--- /dev/null
+++ b/lldb/source/Commands/CommandObjectStart.cpp
@@ -0,0 +1,102 @@
+//===-- CommandObjectStart.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CommandObjectStart.h"
+#include "lldb/Interpreter/CommandObject.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+// Constructor for CommandObjectStart
+CommandObjectStart::CommandObjectStart(CommandInterpreter &interpreter)
+: CommandObjectParsed(
+  interpreter, "start",
+  "Launches the process and pauses execution at main function",
+  "start args [optional args]") {
+  // Define command arguments
+  CommandArgumentData pause_location{eArgTypeName, eArgRepeatPlain};
+  m_arguments.push_back({pause_location});
+}
+
+CommandObjectStart::~CommandObjectStart() = default;
+
+// Execute the 'start' command
+bool CommandObjectStart::DoExecute(Args &command, CommandReturnObject &result) 
{
+  // Check if the 'first' subcommand is specified
+  bool pause_at_first_instruction = false;
+
+  if (command.GetArgumentCount() == 1 &&
+  strcmp(command.GetArgumentAtIndex(0), "first") == 0) {
+pause_at_first_instruction = true;
+  }
+
+  // Get the current selected target
+  TargetSP target_sp = GetDebugger().GetSelectedTarget();
+  if (!target_sp) {
+result.AppendError("No target selected.\n");
+return false;
+  }
+
+  // Create the breakpoint at main or the first instruction
+  BreakpointSP bp_sp;
+  if (pause_at_first_instruction) {
+ModuleSP exe_module_sp = target_sp->GetExecutableModule();
+ObjectFile *object = exe_module_sp->GetObjectFile();
+Address address = object->GetEntryPointAddress();
+
+if (!address.IsValid()) {
+  result.AppendError("Failed to get the entry point address");
+  result.SetStatus(eReturnStatusFailed);
+  return false;
+}
+
+bp_sp = target_sp->CreateBreakpoint(address, false, false);
+
+  } else {
+// Create a breakpoint at the main function
+bp_sp = target_sp->CreateBreakpoint(
+nullptr, nullptr, "main", eFunctionNameTypeAuto, eLanguageTypeUnknown,
+0, eLazyBoolNo, false, false);
+  }
+
+  if (!bp_sp) {
+result.AppendError("Breakpoint creation failed.\n");
+result.SetStatus(eReturnStatusFailed);
+return false;
+  } else {
+result.GetOutputStream().Printf("Breakpoint created%s.\n",
+pause_at_first_instruction
+? " at first instruction"
+: " in main function");
+result.SetStatus(eReturnStatusSuccessFinishResult);
+  }
+
+  // Construct the process launch info
+  ProcessLaunchInfo launch_info;
+  launch_info.SetShell(HostInfo::GetDefaultShell());
+  ModuleSP exe_module_sp = target_sp->GetExecutableModule();
+  if (!exe_module_sp) {
+result.AppendError("No executable module found.\n");
+return false;
+  }
+
+  launch_info.SetExecutableFile(exe_module_sp->GetPlatformFileSpec(), true);
+  // Launch the process
+  StreamString stream;
+  Status error = target_sp->Launch(launch_info, &stream);
+
+  if (error.Success()) {
+result.SetStatus(eReturnStatusSuccessFinishResult);
+result.GetOutputStream().Printf("Process launched successfully.\n");
+  } else {
+result.AppendErrorWithFormat("Process launch failed: %s\n",
+ error.AsC

[Lldb-commits] [lldb] [lldb] add stop-at-user-entry option to process launch (PR #67019)

2023-09-26 Thread José Lira Junior via lldb-commits

https://github.com/junior-jl edited 
https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement thread local storage for linux (PR #67470)

2023-09-26 Thread Greg Clayton via lldb-commits


@@ -71,6 +71,7 @@
   11 // The register that would contain pointer size or less argument 7 (if 
any)
 #define LLDB_REGNUM_GENERIC_ARG8   
\
   12 // The register that would contain pointer size or less argument 8 (if 
any)
+#define LLDB_REGNUM_GENERIC_TP 13 // Thread pointer

clayborg wrote:

Need more header doc here describing what I said above.

https://github.com/llvm/llvm-project/pull/67470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement thread local storage for linux (PR #67470)

2023-09-26 Thread Greg Clayton via lldb-commits

https://github.com/clayborg requested changes to this pull request.

Looks good, we just need to add header documentation for the new generic thread 
pointer register and in the RegisterContext.h describing what this registers. 
See inlined comments.

https://github.com/llvm/llvm-project/pull/67470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement thread local storage for linux (PR #67470)

2023-09-26 Thread Greg Clayton via lldb-commits


@@ -144,6 +144,8 @@ class RegisterContext : public 
std::enable_shared_from_this,
 
   uint64_t GetPC(uint64_t fail_value = LLDB_INVALID_ADDRESS);
 
+  uint64_t GetThreadPointer(uint64_t fail_value = LLDB_INVALID_ADDRESS);

clayborg wrote:

Need some header documention here unless we have it elsewhere describing that 
if there is a regsister that points to thread specific data, like TLS data and 
other thread specific stuff, this is the register.

https://github.com/llvm/llvm-project/pull/67470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement thread local storage for linux (PR #67470)

2023-09-26 Thread Greg Clayton via lldb-commits

https://github.com/clayborg edited 
https://github.com/llvm/llvm-project/pull/67470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement thread local storage for linux (PR #67470)

2023-09-26 Thread Greg Clayton via lldb-commits


@@ -710,16 +710,13 @@ bool DYLDRendezvous::FindMetadata(const char *name, 
PThreadField field,
   target.GetImages().FindSymbolsWithNameAndType(ConstString(name),
 eSymbolTypeAny, list);
   if (list.IsEmpty())
-  return false;
-
-  Address address = list[0].symbol->GetAddress();
-  addr_t addr = address.GetLoadAddress(&target);
-  if (addr == LLDB_INVALID_ADDRESS)
 return false;
 
+  Address address = list[0].symbol->GetAddress();
+  address.SetOffset(address.GetOffset() + field * sizeof(uint32_t));
   Status error;
-  value = (uint32_t)m_process->ReadUnsignedIntegerFromMemory(
-  addr + field * sizeof(uint32_t), sizeof(uint32_t), 0, error);
+  value =
+  target.ReadUnsignedIntegerFromMemory(address, sizeof(uint32_t), 0, 
error);

clayborg wrote:

Make a comment here as to why we read from the target like "Read from target 
memory as this allows us to try process memory and fallback to reading from 
read only sections from the object files. Here we are reading read only data 
from libpthread.so to find data in the thread specific area for the data we 
want and this won't be saved into process memory due to it being read only.

https://github.com/llvm/llvm-project/pull/67470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] add stop-at-user-entry option to process launch (PR #67019)

2023-09-26 Thread Greg Clayton via lldb-commits
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -38,7 +39,36 @@ Status CommandOptionsProcessLaunch::SetOptionValue(
   case 's': // Stop at program entry point
 launch_info.GetFlags().Set(eLaunchFlagStopAtEntry);
 break;
-
+  case 'm': // Stop at user entry point
+  {
+TargetSP target_sp =
+execution_context ? execution_context->GetTargetSP() : TargetSP();
+ModuleSP main_module_sp = target_sp->GetExecutableModule();
+FileSpecList shared_lib_filter;
+shared_lib_filter.Append(main_module_sp->GetFileSpec());
+std::vector entryPointNames;

clayborg wrote:

Do we end up with many duplicate entries in the std::vector after iterating 
over all languages? If so you can use a `std::set` so we can 
dedupe the names, then before you set the breakpoint convert the 
`std::set` into a `std::vector` with:
```
std::vector entryPointNames(entryPointNameSet.begin(), 
entryPointNameSet.end());
```

https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] add stop-at-user-entry option to process launch (PR #67019)

2023-09-26 Thread Greg Clayton via lldb-commits
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -675,6 +675,8 @@ let Command = "platform shell" in {
 let Command = "process launch" in {
   def process_launch_stop_at_entry : Option<"stop-at-entry", "s">,
 Desc<"Stop at the entry point of the program when launching a process.">;
+  def process_launch_stop_at_main : Option<"stop-at-user-entry", "m">,
+Desc<"Stop at the user entry point when launching a process.">;

clayborg wrote:

It would be fine to mention "main" here something like:
```
Desc<"Stop at the user entry point when launching a process. For C based 
languages this will be the 'main' function, but this might differ for other 
languages.">;
```

https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] add stop-at-user-entry option to process launch (PR #67019)

2023-09-26 Thread Greg Clayton via lldb-commits
=?utf-8?q?Jos=C3=A9?= L. Junior ,
=?utf-8?q?Jos=C3=A9?= L. Junior ,
=?utf-8?q?Jos=C3=A9?= L. Junior ,
=?utf-8?q?Jos=C3=A9?= L. Junior ,
=?utf-8?q?Jos=C3=A9?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -38,7 +39,36 @@ Status CommandOptionsProcessLaunch::SetOptionValue(
   case 's': // Stop at program entry point
 launch_info.GetFlags().Set(eLaunchFlagStopAtEntry);
 break;
-
+  case 'm': // Stop at user entry point
+  {
+TargetSP target_sp =
+execution_context ? execution_context->GetTargetSP() : TargetSP();
+ModuleSP main_module_sp = target_sp->GetExecutableModule();
+FileSpecList shared_lib_filter;
+shared_lib_filter.Append(main_module_sp->GetFileSpec());
+std::vector entryPointNames;
+for (LanguageType lang_type : Language::GetSupportedLanguages()) {
+  Language *lang = Language::FindPlugin(lang_type);
+  if (lang) {
+std::string entryPointName = lang->GetUserEntryPointName();
+if (!entryPointName.empty()) {
+  entryPointNames.push_back(entryPointName);
+}

clayborg wrote:

No parens on single line if statements per llvm coding guidelines

https://github.com/llvm/llvm-project/pull/67019
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-vscode] Display a more descriptive summary for containers and pointers (PR #65514)

2023-09-26 Thread David Blaikie via lldb-commits


@@ -132,6 +132,84 @@ std::vector GetStrings(const 
llvm::json::Object *obj,
   return strs;
 }
 
+/// Create a short summary for a container that contains the summary of its
+/// first children, so that the user can get a glimpse of its contents at a
+/// glance.
+static std::optional
+GetSyntheticSummaryForContainer(lldb::SBValue &v) {
+  if (v.TypeIsPointerType() || !v.MightHaveChildren())
+return std::nullopt;
+  /// As this operation can be potentially slow, we limit the total time spent
+  /// fetching children to a few ms.
+  const auto max_evaluation_time = std::chrono::milliseconds(10);
+  /// We don't want to generate a extremely long summary string, so we limit 
its
+  /// length.
+  const size_t max_length = 32;
+
+  auto start = std::chrono::steady_clock::now();
+  std::string summary;
+  llvm::raw_string_ostream os(summary);
+  os << "{";
+
+  llvm::StringRef separator = "";
+
+  for (size_t i = 0, e = v.GetNumChildren(); i < e; ++i) {

dwblaikie wrote:

Thanks for the context - how's all this compare to other debuggers? (like 
Visual Studio, for example - what's it show by default for the types?)

https://github.com/llvm/llvm-project/pull/65514
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D159101: [RISC-V] Add RISC-V ABI plugin

2023-09-26 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda accepted this revision.
jasonmolenda added a comment.
This revision is now accepted and ready to land.

This looks good to me, thanks for reviving this and finishing it up.  We should 
land before phabracator is flash frozen, we can iterate issues are found in the 
future.




Comment at: lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.h:13
+// Other libraries and framework includes
+#include 
+

I don't see this used anywhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159101

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


[Lldb-commits] [lldb] [libc++] Implement ranges::contains_subrange (PR #66963)

2023-09-26 Thread via lldb-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/66963

>From 5a2c930770cf548c5e3f3451e76b48cb067e6762 Mon Sep 17 00:00:00 2001
From: Zijun Zhao 
Date: Wed, 13 Sep 2023 14:26:01 -0700
Subject: [PATCH 1/4] [libc++] Implement ranges::contains_subrange

---
 libcxx/include/CMakeLists.txt |   1 +
 .../__algorithm/ranges_contains_subrange.h| 145 +
 libcxx/include/algorithm  |  14 +
 ...obust_against_copying_projections.pass.cpp |   4 +
 .../ranges.contains_subrange.pass.cpp | 293 ++
 .../niebloid.compile.pass.cpp |   3 +
 6 files changed, 460 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains_subrange.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..b096259f85f6ac8 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -104,6 +104,7 @@ set(files
   __algorithm/ranges_any_of.h
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
+  __algorithm/ranges_contains_subrange.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains_subrange.h 
b/libcxx/include/__algorithm/ranges_contains_subrange.h
new file mode 100644
index 000..16de6c29cb2a1a4
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains_subrange.h
@@ -0,0 +1,145 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+
+#include <__algorithm/ranges_starts_with.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains_subrange {
+struct __fn {
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred,
+class _Proj1,
+class _Proj2,
+class _Offset>
+  static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred& __pred,
+  _Proj1& __proj1,
+  _Proj2& __proj2,
+  _Offset __offset) {
+if (__offset < 0)
+  return false;
+else {
+  for (; __offset >= 0; __offset--, __first1++) {
+auto result = ranges::starts_with(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+std::ref(__pred),
+std::ref(__proj1),
+std::ref(__proj2));
+if (result)
+  return true;
+  }
+  return false;
+}
+  }
+
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred  = ranges::equal_to,
+class _Proj1 = identity,
+class _Proj2 = identity>
+requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred __pred   = {},
+  _Proj1 __proj1 = {},
+  _Proj2 __proj2 = {}) const {
+auto __n1 = ranges::distance(__first1, __last1);
+auto __n2 = ranges::distance(__first2, __last2);
+auto __offset = __n1 - __n2;
+
+return __contains_subrange_fn_impl(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+__pred,
+__proj1,
+__proj2,
+std::move(__offset));
+  }
+
+  template 
+requires indirectly_comparable, iterator_t<_Range2>, 
_Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 
__proj1 = {}, _Proj2 __proj2 = {}) const {
+auto __n1 = 0;
+auto __n2 = 0;
+
+if cons

[Lldb-commits] [lldb] [libc++] Implement ranges::contains_subrange (PR #66963)

2023-09-26 Thread via lldb-commits

https://github.com/ZijunZhaoCCK resolved 
https://github.com/llvm/llvm-project/pull/66963
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [libc++] Implement ranges::contains_subrange (PR #66963)

2023-09-26 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 2f2319cf2406d9830a331cbf015881c55ae78806 
5f33fa63e76b5d0c066773113447749c3428aa99 -- 
libcxx/include/__algorithm/ranges_contains_subrange.h 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
 
b/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
index fd4d858b255d..e9c300e5bb20 100644
--- 
a/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
+++ 
b/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp
@@ -51,7 +51,8 @@ static_assert(HasContainsSubrangeSubrangeIt);
 
 template >
 concept HasContainsSubrangeR = requires(Range1&& range1, Range2&& range2) {
-std::ranges::contains_subrange(std::forward(range1), 
std::forward(range2)); };
+  std::ranges::contains_subrange(std::forward(range1), 
std::forward(range2));
+};
 
 static_assert(HasContainsSubrangeR>);
 static_assert(HasContainsSubrangeR);
@@ -68,27 +69,26 @@ static std::vector comparable_data;
 
 template 
 constexpr void test_iterators() {
-  {  // simple tests
-int a[] = {1, 2, 3, 4, 5, 6};
-int p[] = {3, 4, 5};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
+  { // simple tests
+int a[]   = {1, 2, 3, 4, 5, 6};
+int p[]   = {3, 4, 5};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
 {
   [[maybe_unused]] std::same_as decltype(auto) ret =
-std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
+  std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
   assert(ret);
 }
 {
-  [[maybe_unused]] std::same_as decltype(auto) ret =
-std::ranges::contains_subrange(whole, subrange);
+  [[maybe_unused]] std::same_as decltype(auto) ret = 
std::ranges::contains_subrange(whole, subrange);
   assert(ret);
 }
   }
 
   { // no match
-int a[] = {1, 2, 3, 4, 5, 6};
-int p[] = {3, 4, 2};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
+int a[]   = {1, 2, 3, 4, 5, 6};
+int p[]   = {3, 4, 2};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
 {
   bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
@@ -101,9 +101,9 @@ constexpr void test_iterators() {
   }
 
   { // range consists of just one element
-int a[] = {3};
-int p[] = {3, 4, 2};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 1)));
+int a[]   = {3};
+int p[]   = {3, 4, 2};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 1)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
 {
   bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
@@ -116,9 +116,9 @@ constexpr void test_iterators() {
   }
 
   { // subrange consists of just one element
-int a[] = {23, 1, 20, 3, 54, 2};
-int p[] = {3};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
+int a[]   = {23, 1, 20, 3, 54, 2};
+int p[]   = {3};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 1)));
 {
   bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
@@ -131,9 +131,9 @@ constexpr void test_iterators() {
   }
 
   { // range has zero length
-int a[] = {};
-int p[] = {3, 4, 2};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
+int a[]   = {};
+int p[]   = {3, 4, 2};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
 {
   bool ret = std::ranges::contains_subrange(whole.begin(), whole.end(), 
subrange.begin(), subrange.end());
@@ -146,9 +146,9 @@ constexpr void test_iterators() {
   }
 
   { // subrange has zero length
-int a[] = {3, 4, 2};
-int p[] = {};
-auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 3)));
+int a[]   = {3, 4, 2};
+int p[]   = {};
+auto whole= std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 3)));
 auto subrange = std::ranges::subrange(Iter2(p), Sent2(Iter2(p)));
 {
 

[Lldb-commits] [lldb] [lldb] Implement thread local storage for linux (PR #67470)

2023-09-26 Thread via lldb-commits

https://github.com/jeffreytan81 updated 
https://github.com/llvm/llvm-project/pull/67470

>From 5e8b4a44bf48216785f5ecb412e145a7ac4d3a55 Mon Sep 17 00:00:00 2001
From: jeffreytan81 
Date: Tue, 26 Sep 2023 11:04:08 -0700
Subject: [PATCH 1/3] Implement thread local storage for linux

---
 lldb/include/lldb/Target/RegisterContext.h|  2 +
 lldb/include/lldb/lldb-defines.h  |  1 +
 .../POSIX-DYLD/DYLDRendezvous.cpp | 11 ++---
 .../POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp | 49 +++
 .../Utility/RegisterInfos_x86_64_with_base.h  | 13 +
 .../GDBRemoteCommunicationServerLLGS.cpp  |  2 +
 lldb/source/Target/RegisterContext.cpp|  6 +++
 lldb/source/Target/Thread.cpp |  6 ++-
 lldb/source/Utility/Args.cpp  |  1 +
 .../API/lang/c/tls_globals/TestTlsGlobals.py  |  5 +-
 10 files changed, 65 insertions(+), 31 deletions(-)

diff --git a/lldb/include/lldb/Target/RegisterContext.h 
b/lldb/include/lldb/Target/RegisterContext.h
index de0efd982daaa71..b2626928f142604 100644
--- a/lldb/include/lldb/Target/RegisterContext.h
+++ b/lldb/include/lldb/Target/RegisterContext.h
@@ -144,6 +144,8 @@ class RegisterContext : public 
std::enable_shared_from_this,
 
   uint64_t GetPC(uint64_t fail_value = LLDB_INVALID_ADDRESS);
 
+  uint64_t GetThreadPointer(uint64_t fail_value = LLDB_INVALID_ADDRESS);
+
   /// Get an address suitable for symbolication.
   /// When symbolicating -- computing line, block, function --
   /// for a function in the middle of the stack, using the return
diff --git a/lldb/include/lldb/lldb-defines.h b/lldb/include/lldb/lldb-defines.h
index ce7fd6f3754516e..aaf0b04e4fb86e9 100644
--- a/lldb/include/lldb/lldb-defines.h
+++ b/lldb/include/lldb/lldb-defines.h
@@ -71,6 +71,7 @@
   11 // The register that would contain pointer size or less argument 7 (if 
any)
 #define LLDB_REGNUM_GENERIC_ARG8   
\
   12 // The register that would contain pointer size or less argument 8 (if 
any)
+#define LLDB_REGNUM_GENERIC_TP 13 // Thread pointer
 /// Invalid value definitions
 #define LLDB_INVALID_STOP_ID 0
 #define LLDB_INVALID_ADDRESS UINT64_MAX
diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp 
b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
index 68e4ac0cc4007c4..cb174d31b86dfe6 100644
--- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
+++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
@@ -710,16 +710,13 @@ bool DYLDRendezvous::FindMetadata(const char *name, 
PThreadField field,
   target.GetImages().FindSymbolsWithNameAndType(ConstString(name),
 eSymbolTypeAny, list);
   if (list.IsEmpty())
-  return false;
-
-  Address address = list[0].symbol->GetAddress();
-  addr_t addr = address.GetLoadAddress(&target);
-  if (addr == LLDB_INVALID_ADDRESS)
 return false;
 
+  Address address = list[0].symbol->GetAddress();
+  address.SetOffset(address.GetOffset() + field * sizeof(uint32_t));
   Status error;
-  value = (uint32_t)m_process->ReadUnsignedIntegerFromMemory(
-  addr + field * sizeof(uint32_t), sizeof(uint32_t), 0, error);
+  value =
+  target.ReadUnsignedIntegerFromMemory(address, sizeof(uint32_t), 0, 
error);
   if (error.Fail())
 return false;
 
diff --git 
a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp 
b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
index b4b38a88e1b9c7a..85d7ae9dac75d1e 100644
--- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -420,6 +420,11 @@ void DynamicLoaderPOSIXDYLD::RefreshModules() {
   if (!m_rendezvous.Resolve())
 return;
 
+  // The rendezvous class doesn't enumerate the main module, so track that
+  // ourselves here.
+  ModuleSP executable = GetTargetExecutable();
+  m_loaded_modules[executable] = m_rendezvous.GetLinkMapAddress();
+
   DYLDRendezvous::iterator I;
   DYLDRendezvous::iterator E;
 
@@ -727,41 +732,66 @@ lldb::addr_t
 DynamicLoaderPOSIXDYLD::GetThreadLocalData(const lldb::ModuleSP module_sp,
const lldb::ThreadSP thread,
lldb::addr_t tls_file_addr) {
+  Log *log = GetLog(LLDBLog::DynamicLoader);
   auto it = m_loaded_modules.find(module_sp);
-  if (it == m_loaded_modules.end())
+  if (it == m_loaded_modules.end()) {
+LLDB_LOGF(
+log, "GetThreadLocalData error: module(%s) not found in loaded 
modules",
+module_sp->GetObjectName().AsCString());
 return LLDB_INVALID_ADDRESS;
+  }
 
   addr_t link_map = it->second;
-  if (link_map == LLDB_INVALID_ADDRESS)
+  if (link_map == LLDB_INVALID_ADDRESS || link_map == 0) {
+LLDB_LOGF(log,
+  "GetThreadLocalData error: invalid link map address=0x%" PRIx64,
+  link_map

[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast resolved 
https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits

https://github.com/aokblast updated 
https://github.com/llvm/llvm-project/pull/67106

>From f8ed3ed64be0a451542a4ec71f254dc9038b2d19 Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Fri, 22 Sep 2023 18:11:07 +0800
Subject: [PATCH 1/4] feat: add DynamicLoaderFreeBSDKernel

---
 .../Plugins/DynamicLoader/CMakeLists.txt  |   1 +
 .../FreeBSD-Kernel/CMakeLists.txt |  13 +
 .../DynamicLoaderFreeBSDKernel.cpp| 770 ++
 .../DynamicLoaderFreeBSDKernel.h  | 165 
 .../FreeBSDKernel/ProcessFreeBSDKernel.cpp|   4 +-
 5 files changed, 951 insertions(+), 2 deletions(-)
 create mode 100644 
lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/CMakeLists.txt
 create mode 100644 
lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 create mode 100644 
lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.h

diff --git a/lldb/source/Plugins/DynamicLoader/CMakeLists.txt 
b/lldb/source/Plugins/DynamicLoader/CMakeLists.txt
index f357fea02efbe68..30607159acdc088 100644
--- a/lldb/source/Plugins/DynamicLoader/CMakeLists.txt
+++ b/lldb/source/Plugins/DynamicLoader/CMakeLists.txt
@@ -1,4 +1,5 @@
 add_subdirectory(Darwin-Kernel)
+add_subdirectory(FreeBSD-Kernel)
 add_subdirectory(MacOSX-DYLD)
 add_subdirectory(POSIX-DYLD)
 add_subdirectory(Static)
diff --git a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/CMakeLists.txt 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/CMakeLists.txt
new file mode 100644
index 000..76daf0a327cf97b
--- /dev/null
+++ b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/CMakeLists.txt
@@ -0,0 +1,13 @@
+add_lldb_library(lldbPluginDynamicLoaderFreeBSDKernel PLUGIN
+  DynamicLoaderFreeBSDKernel.cpp
+
+  LINK_LIBS
+lldbBreakpoint
+lldbCore
+lldbHost
+lldbInterpreter
+lldbSymbol
+lldbTarget
+lldbUtility
+lldbPluginObjectFileELF
+  )
diff --git 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
new file mode 100644
index 000..d5eb891f0060bea
--- /dev/null
+++ 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -0,0 +1,770 @@
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Core/ModuleSpec.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Section.h"
+#include "lldb/Core/StreamFile.h"
+#include "lldb/Interpreter/OptionValueProperties.h"
+#include "lldb/Symbol/LocateSymbolFile.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Target/OperatingSystem.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Target/ThreadPlanRunToAddress.h"
+#include "lldb/Utility/DataBuffer.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+
+#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
+
+#include "DynamicLoaderFreeBSDKernel.h"
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+
+LLDB_PLUGIN_DEFINE(DynamicLoaderFreeBSDKernel)
+
+void DynamicLoaderFreeBSDKernel::Initialize() {
+  PluginManager::RegisterPlugin(GetPluginNameStatic(),
+GetPluginDescriptionStatic(), CreateInstance,
+DebuggerInit);
+}
+
+void DynamicLoaderFreeBSDKernel::Terminate() {
+  PluginManager::UnregisterPlugin(CreateInstance);
+}
+
+llvm::StringRef DynamicLoaderFreeBSDKernel::GetPluginDescriptionStatic() {
+  return "The Dynamic Loader Plugin For FreeBSD Kernel";
+}
+
+static bool is_kernel(Module *module) {
+  if (!module)
+return false;
+
+  ObjectFile *objfile = module->GetObjectFile();
+  if (!objfile)
+return false;
+  if (objfile->GetType() != ObjectFile::eTypeExecutable)
+return false;
+  if (objfile->GetStrata() != ObjectFile::eStrataUnknown &&
+  objfile->GetStrata() != ObjectFile::eStrataUser)
+return false;
+
+  return true;
+}
+
+static bool is_kmod(Module *module) {
+  if (!module)
+return false;
+  if (!module->GetObjectFile())
+return false;
+  ObjectFile *objfile = module->GetObjectFile();
+  if (objfile->GetType() != ObjectFile::eTypeObjectFile &&
+  objfile->GetType() != ObjectFile::eTypeSharedLibrary)
+return false;
+
+  return true;
+}
+
+static bool is_reloc(Module *module) {
+  if (!module)
+return false;
+  if (!module->GetObjectFile())
+return false;
+  ObjectFile *objfile = module->GetObjectFile();
+  if (objfile->GetType() != ObjectFile::eTypeObjectFile)
+return false;
+
+  return true;
+}
+
+// Instantiate Function of the FreeBSD Kernel Dynamic Loader Plugin called when
+// Register the Plugin
+DynamicLoader *
+DynamicLoaderFreeBSDKernel::CreateInstance(lldb_private::Process *proce

[Lldb-commits] [lldb] [lldb][FreeBSD] Add dynamic loader handle class for FreeBSD Kernel (PR #67106)

2023-09-26 Thread via lldb-commits


@@ -0,0 +1,172 @@
+//===-- DynamicLoaderFreeBSDKernel.h
+//--===//

aokblast wrote:

Fix it

https://github.com/llvm/llvm-project/pull/67106
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Implement thread local storage for linux (PR #67470)

2023-09-26 Thread Greg Clayton via lldb-commits

https://github.com/clayborg approved this pull request.

Looks good!

https://github.com/llvm/llvm-project/pull/67470
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add SetValueFromCString API to SyntheticFronend (PR #67309)

2023-09-26 Thread Pavel Kosov via lldb-commits

kpdev wrote:

> This part of the change seems straightforward, if the synthetic child 
> provider can set a value it will have to have this API... But yes, if there 
> are a bunch of patches that build on one another, if they aren't too big one 
> patch that shows the functionality is easier to understand, or put a few 
> substantial patches up but mark them as depending on the previous ones, so we 
> can get the big picture. Jim

Ok, will prepare them

https://github.com/llvm/llvm-project/pull/67309
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add SetValueFromCString API to SyntheticFronend (PR #67309)

2023-09-26 Thread Pavel Kosov via lldb-commits

kpdev wrote:

> Getting the SyntheticFrontEnd to try updating the synthetic value is a good 
> addition. But I'm not sure that ValueObject should be the one that should 
> provide access directly to the FrontEnd? Why isn't it enough to have the 
> ValueObjectSynthetic's SetValueFromCString do this? If you have decided to 
> pull the Non-synthetic value (and so are accessing the ValueObjectVariable 
> directly, would you expect to have the synthetic value do an update? When 
> would something that is a ValueObject but not a ValueObjectSynthetic really 
> want to update the value using the SyntheticFrontEnd?


@jimingham In my understanding, the situation is looks like this:

When somebody wants to update a value from lldb API, then SBValue's 
`SetValueFromCString` method should be used,  which in turn calls 
ValueObjectVariable / ValueObjectRegister / etc.'s method `SetValueFromCString` 
- all of them currently working only with `Scalar`s, which represent addresses 
for structured values (e.g., std::string in our case) in the process that we 
debug.

I do not see a common way to update aggregate types in ValueObject* since it 
can represent any type of data, but if we have defined synthetic children for 
the concrete structure we want to update, then we can explicitly define there 
how to update it.

So, in case of std::string we can't simply copy a new c-string value to a 
location of an old c-string value; we have to destroy the old string (free 
memory) and create a new one. It can be done in expression evaluation for 
example.

I might misunderstand something in this problem, if so - please point me the 
right way. 

https://github.com/llvm/llvm-project/pull/67309
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits