[Lldb-commits] [lldb] 2634ec6 - [lldb] "target create" shouldn't save target if the command failed

2020-12-12 Thread Tatyana Krasnukha via lldb-commits

Author: Tatyana Krasnukha
Date: 2020-12-12T16:40:58+03:00
New Revision: 2634ec6ce9007f2406545ca28b4c72961f1e8f67

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

LOG: [lldb] "target create" shouldn't save target if the command failed

TargetList::CreateTarget automatically adds created target to the list, however,
CommandObjectTargetCreate does some additional preparation after creating a 
target
and which can fail. The command should remove created target if it failed. Since
the function has many ways to return, scope guard does this work safely.

Changes to the TargetList make target adding and selection more transparent.

Other changes remove unnecessary SetSelectedTarget after CreateTarget.

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

Added: 


Modified: 
lldb/include/lldb/Target/TargetList.h
lldb/source/API/SBDebugger.cpp
lldb/source/Commands/CommandObjectProcess.cpp
lldb/source/Commands/CommandObjectTarget.cpp
lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
lldb/source/Target/Platform.cpp
lldb/source/Target/TargetList.cpp
lldb/source/Target/TraceSessionFileParser.cpp
lldb/unittests/Process/ProcessEventDataTest.cpp
lldb/unittests/Thread/ThreadTest.cpp

Removed: 




diff  --git a/lldb/include/lldb/Target/TargetList.h 
b/lldb/include/lldb/Target/TargetList.h
index 94b25f65863a..903ca4bcefbc 100644
--- a/lldb/include/lldb/Target/TargetList.h
+++ b/lldb/include/lldb/Target/TargetList.h
@@ -173,7 +173,9 @@ class TargetList : public Broadcaster {
 
   uint32_t SignalIfRunning(lldb::pid_t pid, int signo);
 
-  uint32_t SetSelectedTarget(Target *target);
+  void SetSelectedTarget(uint32_t index);
+
+  void SetSelectedTarget(const lldb::TargetSP &target);
 
   lldb::TargetSP GetSelectedTarget();
 
@@ -185,17 +187,21 @@ class TargetList : public Broadcaster {
   uint32_t m_selected_target_idx;
 
 private:
-  Status CreateTargetInternal(Debugger &debugger, llvm::StringRef 
user_exe_path,
-  llvm::StringRef triple_str,
-  LoadDependentFiles load_dependent_files,
-  const OptionGroupPlatform *platform_options,
-  lldb::TargetSP &target_sp);
-
-  Status CreateTargetInternal(Debugger &debugger, llvm::StringRef 
user_exe_path,
-  const ArchSpec &arch,
-  LoadDependentFiles get_dependent_modules,
-  lldb::PlatformSP &platform_sp,
-  lldb::TargetSP &target_sp);
+  static Status CreateTargetInternal(
+  Debugger &debugger, llvm::StringRef user_exe_path,
+  llvm::StringRef triple_str, LoadDependentFiles load_dependent_files,
+  const OptionGroupPlatform *platform_options, lldb::TargetSP &target_sp);
+
+  static Status CreateTargetInternal(Debugger &debugger,
+ llvm::StringRef user_exe_path,
+ const ArchSpec &arch,
+ LoadDependentFiles get_dependent_modules,
+ lldb::PlatformSP &platform_sp,
+ lldb::TargetSP &target_sp);
+
+  void AddTargetInternal(lldb::TargetSP target_sp, bool do_select);
+
+  void SetSelectedTargetInternal(uint32_t index);
 
   TargetList(const TargetList &) = delete;
   const TargetList &operator=(const TargetList &) = delete;

diff  --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index a5bf457e90f9..dc1cc91c705c 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -811,10 +811,8 @@ SBTarget SBDebugger::CreateTargetWithFileAndArch(const 
char *filename,
 add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, 
nullptr,
 target_sp);
 
-if (error.Success()) {
-  m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp.get());
+if (error.Success())
   sb_target.SetSP(target_sp);
-}
   }
 
   LLDB_LOGF(log,
@@ -840,10 +838,8 @@ SBTarget SBDebugger::CreateTarget(const char *filename) {
 add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, 
nullptr,
 target_sp);
 
-if (error.Success()) {
-  m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp.get());
+if (error.Success())
   sb_target.SetSP(target_sp);
-}
   }
   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
   LLDB_LOGF(log,
@@ -998,7 +994,7 @@ void SBDebugger::SetSelectedTarget(SBTarget &sb_target) {
 
   TargetSP target_sp(sb_target.GetSP());
   if (m_opaque_sp) {
-m_opaque_sp

[Lldb-commits] [lldb] 7832d7e - [lldb] Modernize TargetList for-loops, NFC

2020-12-12 Thread Tatyana Krasnukha via lldb-commits

Author: Tatyana Krasnukha
Date: 2020-12-12T16:40:58+03:00
New Revision: 7832d7e95ace589b2275bafe701ccb377a16b1b2

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

LOG: [lldb] Modernize TargetList for-loops, NFC

Replace loops with standard algorithms or range-based loops.

Added: 


Modified: 
lldb/source/Target/TargetList.cpp

Removed: 




diff  --git a/lldb/source/Target/TargetList.cpp 
b/lldb/source/Target/TargetList.cpp
index bbef3b63ba42..5bb6ca2a73e9 100644
--- a/lldb/source/Target/TargetList.cpp
+++ b/lldb/source/Target/TargetList.cpp
@@ -405,80 +405,76 @@ Status TargetList::CreateTargetInternal(Debugger 
&debugger,
 
 bool TargetList::DeleteTarget(TargetSP &target_sp) {
   std::lock_guard guard(m_target_list_mutex);
-  collection::iterator pos, end = m_target_list.end();
+  auto it = std::find(m_target_list.begin(), m_target_list.end(), target_sp);
+  if (it == m_target_list.end())
+return false;
 
-  for (pos = m_target_list.begin(); pos != end; ++pos) {
-if (pos->get() == target_sp.get()) {
-  m_target_list.erase(pos);
-  return true;
-}
-  }
-  return false;
+  m_target_list.erase(it);
+  return true;
 }
 
 TargetSP TargetList::FindTargetWithExecutableAndArchitecture(
 const FileSpec &exe_file_spec, const ArchSpec *exe_arch_ptr) const {
   std::lock_guard guard(m_target_list_mutex);
-  TargetSP target_sp;
-  collection::const_iterator pos, end = m_target_list.end();
-  for (pos = m_target_list.begin(); pos != end; ++pos) {
-Module *exe_module = (*pos)->GetExecutableModulePointer();
-
-if (exe_module) {
-  if (FileSpec::Match(exe_file_spec, exe_module->GetFileSpec())) {
-if (exe_arch_ptr) {
-  if (!exe_arch_ptr->IsCompatibleMatch(exe_module->GetArchitecture()))
-continue;
-}
-target_sp = *pos;
-break;
-  }
-}
-  }
-  return target_sp;
+  auto it = std::find_if(m_target_list.begin(), m_target_list.end(),
+  [&exe_file_spec, exe_arch_ptr](const TargetSP &item) {
+Module *exe_module = item->GetExecutableModulePointer();
+if (!exe_module ||
+!FileSpec::Match(exe_file_spec, exe_module->GetFileSpec()))
+  return false;
+
+return !exe_arch_ptr ||
+   exe_arch_ptr->IsCompatibleMatch(exe_module->GetArchitecture());
+  });
+
+  if (it != m_target_list.end())
+return *it;
+
+  return TargetSP();
 }
 
 TargetSP TargetList::FindTargetWithProcessID(lldb::pid_t pid) const {
   std::lock_guard guard(m_target_list_mutex);
-  TargetSP target_sp;
-  collection::const_iterator pos, end = m_target_list.end();
-  for (pos = m_target_list.begin(); pos != end; ++pos) {
-Process *process = (*pos)->GetProcessSP().get();
-if (process && process->GetID() == pid) {
-  target_sp = *pos;
-  break;
-}
-  }
-  return target_sp;
+  auto it = std::find_if(m_target_list.begin(), m_target_list.end(),
+  [pid](const TargetSP &item) {
+auto *process_ptr = item->GetProcessSP().get();
+return process_ptr && (process_ptr->GetID() == pid);
+  });
+
+  if (it != m_target_list.end())
+return *it;
+
+  return TargetSP();
 }
 
 TargetSP TargetList::FindTargetWithProcess(Process *process) const {
   TargetSP target_sp;
-  if (process) {
-std::lock_guard guard(m_target_list_mutex);
-collection::const_iterator pos, end = m_target_list.end();
-for (pos = m_target_list.begin(); pos != end; ++pos) {
-  if (process == (*pos)->GetProcessSP().get()) {
-target_sp = *pos;
-break;
-  }
-}
-  }
+  if (!process)
+return target_sp;
+
+  std::lock_guard guard(m_target_list_mutex);
+  auto it = std::find_if(m_target_list.begin(), m_target_list.end(),
+  [process](const TargetSP &item) {
+return item->GetProcessSP().get() == process;
+  });
+
+  if (it != m_target_list.end())
+target_sp = *it;
+
   return target_sp;
 }
 
 TargetSP TargetList::GetTargetSP(Target *target) const {
   TargetSP target_sp;
-  if (target) {
-std::lock_guard guard(m_target_list_mutex);
-collection::const_iterator pos, end = m_target_list.end();
-for (pos = m_target_list.begin(); pos != end; ++pos) {
-  if (target == (*pos).get()) {
-target_sp = *pos;
-break;
-  }
-}
-  }
+  if (!target)
+return target_sp;
+
+  std::lock_guard guard(m_target_list_mutex);
+  auto it = std::find_if(m_target_list.begin(), m_target_list.end(),
+  [target](const TargetSP &item) { return item.get() == target; });
+  if (it != m_target_list.end())
+target_sp = *it;
+
   return target_sp;
 }
 
@@ -509,14 +505,11 @@ uint32_t TargetList::SignalIfRunning(lldb::pid_t pid, int 
signo) {
   if (pid == LLDB_INVALID_PROCESS_ID) {
 // Signal all processes with sig

[Lldb-commits] [lldb] a01b26f - [lldb] Make CommandInterpreter's execution context the same as debugger's one.

2020-12-12 Thread Tatyana Krasnukha via lldb-commits

Author: Tatyana Krasnukha
Date: 2020-12-12T16:40:59+03:00
New Revision: a01b26fb51c710a3a8ef88cc83b0701461f5b9ab

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

LOG: [lldb] Make CommandInterpreter's execution context the same as debugger's 
one.

Currently, the interpreter's context is not updated until a command is executed.
This has resulted in the behavior of SB-interface functions and some commands
depends on previous user actions. The interpreter's context can stay 
uninitialized,
point to a currently selected target, or point to one of previously selected 
targets.

This patch removes any usages of CommandInterpreter::UpdateExecutionContext.
CommandInterpreter::HandleCommand* functions still may override context 
temporarily,
but now they always restore it before exiting. CommandInterpreter saves 
overriden
contexts to the stack, that makes nesting commands possible.

Added test reproduces one of the issues. Without this fix, the last assertion 
fails
because interpreter's execution context is empty until running "target list", 
so,
the value of the global property was updated instead of process's local 
instance.

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

Added: 
lldb/test/API/python_api/debugger/Makefile
lldb/test/API/python_api/debugger/main.cpp

Modified: 
lldb/include/lldb/Interpreter/CommandInterpreter.h
lldb/source/API/SBCommandInterpreter.cpp
lldb/source/Breakpoint/BreakpointOptions.cpp
lldb/source/Commands/CommandObjectCommands.cpp
lldb/source/Commands/CommandObjectExpression.cpp
lldb/source/Commands/CommandObjectProcess.cpp
lldb/source/Commands/CommandObjectRegexCommand.cpp
lldb/source/Commands/CommandObjectSettings.cpp
lldb/source/Commands/CommandObjectWatchpointCommand.cpp
lldb/source/Core/IOHandlerCursesGUI.cpp
lldb/source/Interpreter/CommandInterpreter.cpp
lldb/source/Target/Target.cpp
lldb/test/API/python_api/debugger/TestDebuggerAPI.py

Removed: 




diff  --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h 
b/lldb/include/lldb/Interpreter/CommandInterpreter.h
index d35f7e22b9ea..40b649411f7f 100644
--- a/lldb/include/lldb/Interpreter/CommandInterpreter.h
+++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h
@@ -24,7 +24,9 @@
 #include "lldb/Utility/StringList.h"
 #include "lldb/lldb-forward.h"
 #include "lldb/lldb-private.h"
+
 #include 
+#include 
 
 namespace lldb_private {
 class CommandInterpreter;
@@ -245,7 +247,7 @@ class CommandInterpreter : public Broadcaster,
 
   CommandInterpreter(Debugger &debugger, bool synchronous_execution);
 
-  ~CommandInterpreter() override;
+  ~CommandInterpreter() override = default;
 
   // These two functions fill out the Broadcaster interface:
 
@@ -300,10 +302,11 @@ class CommandInterpreter : public Broadcaster,
   CommandReturnObject &result);
 
   bool HandleCommand(const char *command_line, LazyBool add_to_history,
- CommandReturnObject &result,
- ExecutionContext *override_context = nullptr,
- bool repeat_on_empty_command = true,
- bool no_context_switching = false);
+ const ExecutionContext &override_context,
+ CommandReturnObject &result);
+
+  bool HandleCommand(const char *command_line, LazyBool add_to_history,
+ CommandReturnObject &result);
 
   bool WasInterrupted() const;
 
@@ -312,9 +315,7 @@ class CommandInterpreter : public Broadcaster,
   /// \param[in] commands
   ///The list of commands to execute.
   /// \param[in,out] context
-  ///The execution context in which to run the commands. Can be nullptr in
-  ///which case the default
-  ///context will be used.
+  ///The execution context in which to run the commands.
   /// \param[in] options
   ///This object holds the options used to control when to stop, whether to
   ///execute commands,
@@ -324,8 +325,13 @@ class CommandInterpreter : public Broadcaster,
   ///safely,
   ///and failed with some explanation if we aborted executing the commands
   ///at some point.
-  void HandleCommands(const StringList &commands, ExecutionContext *context,
-  CommandInterpreterRunOptions &options,
+  void HandleCommands(const StringList &commands,
+  const ExecutionContext &context,
+  const CommandInterpreterRunOptions &options,
+  CommandReturnObject &result);
+
+  void HandleCommands(const StringList &commands,
+  const CommandInterpreterRunOptions &options,
   CommandReturnObject &result);
 
   /// Execute a list of commands from a file.
@@ -333,9 +339,7 @

[Lldb-commits] [PATCH] D93052: "target create" shouldn't save target if the command failed

2020-12-12 Thread Tatyana Krasnukha via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2634ec6ce900: [lldb] "target create" 
shouldn't save target if the command failed (authored by 
tatyana-krasnukha).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93052

Files:
  lldb/include/lldb/Target/TargetList.h
  lldb/source/API/SBDebugger.cpp
  lldb/source/Commands/CommandObjectProcess.cpp
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
  lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
  lldb/source/Target/Platform.cpp
  lldb/source/Target/TargetList.cpp
  lldb/source/Target/TraceSessionFileParser.cpp
  lldb/unittests/Process/ProcessEventDataTest.cpp
  lldb/unittests/Thread/ThreadTest.cpp

Index: lldb/unittests/Thread/ThreadTest.cpp
===
--- lldb/unittests/Thread/ThreadTest.cpp
+++ lldb/unittests/Thread/ThreadTest.cpp
@@ -83,16 +83,11 @@
 } // namespace
 
 TargetSP CreateTarget(DebuggerSP &debugger_sp, ArchSpec &arch) {
-  Status error;
   PlatformSP platform_sp;
   TargetSP target_sp;
-  error = debugger_sp->GetTargetList().CreateTarget(
+  debugger_sp->GetTargetList().CreateTarget(
   *debugger_sp, "", arch, eLoadDependentsNo, platform_sp, target_sp);
 
-  if (target_sp) {
-debugger_sp->GetTargetList().SetSelectedTarget(target_sp.get());
-  }
-
   return target_sp;
 }
 
Index: lldb/unittests/Process/ProcessEventDataTest.cpp
===
--- lldb/unittests/Process/ProcessEventDataTest.cpp
+++ lldb/unittests/Process/ProcessEventDataTest.cpp
@@ -112,16 +112,11 @@
 typedef std::shared_ptr EventSP;
 
 TargetSP CreateTarget(DebuggerSP &debugger_sp, ArchSpec &arch) {
-  Status error;
   PlatformSP platform_sp;
   TargetSP target_sp;
-  error = debugger_sp->GetTargetList().CreateTarget(
+  debugger_sp->GetTargetList().CreateTarget(
   *debugger_sp, "", arch, eLoadDependentsNo, platform_sp, target_sp);
 
-  if (target_sp) {
-debugger_sp->GetTargetList().SetSelectedTarget(target_sp.get());
-  }
-
   return target_sp;
 }
 
Index: lldb/source/Target/TraceSessionFileParser.cpp
===
--- lldb/source/Target/TraceSessionFileParser.cpp
+++ lldb/source/Target/TraceSessionFileParser.cpp
@@ -123,8 +123,6 @@
   ParsedProcess parsed_process;
   parsed_process.target_sp = target_sp;
 
-  m_debugger.GetTargetList().SetSelectedTarget(target_sp.get());
-
   ProcessSP process_sp = target_sp->CreateProcess(
   /*listener*/ nullptr, "trace",
   /*crash_file*/ nullptr,
Index: lldb/source/Target/TargetList.cpp
===
--- lldb/source/Target/TargetList.cpp
+++ lldb/source/Target/TargetList.cpp
@@ -48,9 +48,13 @@
 LoadDependentFiles load_dependent_files,
 const OptionGroupPlatform *platform_options,
 TargetSP &target_sp) {
-  return CreateTargetInternal(debugger, user_exe_path, triple_str,
-  load_dependent_files, platform_options,
-  target_sp);
+  auto result = TargetList::CreateTargetInternal(
+  debugger, user_exe_path, triple_str, load_dependent_files,
+  platform_options, target_sp);
+
+  if (target_sp && result.Success())
+AddTargetInternal(target_sp, /*do_select*/ true);
+  return result;
 }
 
 Status TargetList::CreateTarget(Debugger &debugger,
@@ -58,8 +62,13 @@
 const ArchSpec &specified_arch,
 LoadDependentFiles load_dependent_files,
 PlatformSP &platform_sp, TargetSP &target_sp) {
-  return CreateTargetInternal(debugger, user_exe_path, specified_arch,
-  load_dependent_files, platform_sp, target_sp);
+  auto result = TargetList::CreateTargetInternal(
+  debugger, user_exe_path, specified_arch, load_dependent_files,
+  platform_sp, target_sp);
+
+  if (target_sp && result.Success())
+AddTargetInternal(target_sp, /*do_select*/ true);
+  return result;
 }
 
 Status TargetList::CreateTargetInternal(
@@ -388,9 +397,6 @@
 target_sp->AppendExecutableSearchPaths(file_dir);
   }
 
-  std::lock_guard guard(m_target_list_mutex);
-  m_selected_target_idx = m_target_list.size();
-  m_target_list.push_back(target_sp);
   // Now prime this from the dummy target:
   target_sp->PrimeFromDummyTarget(debugger.GetDummyTarget());
 
@@ -552,18 +558,29 @@
   return UINT32_MAX;
 }
 
-uint32_t TargetList::SetSelectedTarget(Target *target) {
+void TargetList::AddTargetInternal(TargetSP target_sp, bool do_select) {
+  lldbassert(std::find(m_target_list.begin(), m_target_list.end(),

[Lldb-commits] [PATCH] D92164: Make CommandInterpreter's execution context the same as debugger's one.

2020-12-12 Thread Tatyana Krasnukha via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa01b26fb51c7: [lldb] Make CommandInterpreter's 
execution context the same as debugger's one. (authored by 
tatyana-krasnukha).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92164

Files:
  lldb/include/lldb/Interpreter/CommandInterpreter.h
  lldb/source/API/SBCommandInterpreter.cpp
  lldb/source/Breakpoint/BreakpointOptions.cpp
  lldb/source/Commands/CommandObjectCommands.cpp
  lldb/source/Commands/CommandObjectExpression.cpp
  lldb/source/Commands/CommandObjectProcess.cpp
  lldb/source/Commands/CommandObjectRegexCommand.cpp
  lldb/source/Commands/CommandObjectSettings.cpp
  lldb/source/Commands/CommandObjectWatchpointCommand.cpp
  lldb/source/Core/IOHandlerCursesGUI.cpp
  lldb/source/Interpreter/CommandInterpreter.cpp
  lldb/source/Target/Target.cpp
  lldb/test/API/python_api/debugger/Makefile
  lldb/test/API/python_api/debugger/TestDebuggerAPI.py
  lldb/test/API/python_api/debugger/main.cpp

Index: lldb/test/API/python_api/debugger/main.cpp
===
--- /dev/null
+++ lldb/test/API/python_api/debugger/main.cpp
@@ -0,0 +1,9 @@
+// This simple program is to test the lldb Python API SBDebugger.
+
+int func(int val) {
+return val - 1;
+}
+
+int main (int argc, char const *argv[]) {
+return func(argc);
+}
Index: lldb/test/API/python_api/debugger/TestDebuggerAPI.py
===
--- lldb/test/API/python_api/debugger/TestDebuggerAPI.py
+++ lldb/test/API/python_api/debugger/TestDebuggerAPI.py
@@ -43,3 +43,54 @@
 target = lldb.SBTarget()
 self.assertFalse(target.IsValid())
 self.dbg.DeleteTarget(target)
+
+def test_debugger_internal_variable(self):
+"""Ensure that SBDebugger reachs the same instance of properties
+   regardless CommandInterpreter's context initialization"""
+self.build()
+exe = self.getBuildArtifact("a.out")
+
+# Create a target by the debugger.
+target = self.dbg.CreateTarget(exe)
+self.assertTrue(target, VALID_TARGET)
+
+property_name = "target.process.memory-cache-line-size"
+
+def get_cache_line_size():
+value_list = lldb.SBStringList()
+value_list = self.dbg.GetInternalVariableValue(property_name,
+   self.dbg.GetInstanceName())
+
+self.assertEqual(value_list.GetSize(), 1)
+try:
+return int(value_list.GetStringAtIndex(0))
+except ValueError as error:
+self.fail("Value is not a number: " + error)
+
+# Get global property value while there are no processes.
+global_cache_line_size = get_cache_line_size()
+
+# Run a process via SB interface. CommandInterpreter's execution context
+# remains empty.
+error = lldb.SBError()
+launch_info = lldb.SBLaunchInfo(None)
+launch_info.SetLaunchFlags(lldb.eLaunchFlagStopAtEntry)
+process = target.Launch(launch_info, error)
+self.assertTrue(process, PROCESS_IS_VALID)
+
+# This should change the value of a process's local property.
+new_cache_line_size = global_cache_line_size + 512
+error = self.dbg.SetInternalVariable(property_name,
+ str(new_cache_line_size),
+ self.dbg.GetInstanceName())
+self.assertTrue(error.Success(),
+property_name + " value was changed successfully")
+
+# Check that it was set actually.
+self.assertEqual(get_cache_line_size(), new_cache_line_size)
+
+# Run any command to initialize CommandInterpreter's execution context.
+self.runCmd("target list")
+
+# Test the local property again, is it set to new_cache_line_size?
+self.assertEqual(get_cache_line_size(), new_cache_line_size)
Index: lldb/test/API/python_api/debugger/Makefile
===
--- /dev/null
+++ lldb/test/API/python_api/debugger/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -3351,7 +3351,7 @@
   // Force Async:
   bool old_async = debugger.GetAsyncExecution();
   debugger.SetAsyncExecution(true);
-  debugger.GetCommandInterpreter().HandleCommands(GetCommands(), &exc_ctx,
+  debugger.GetCommandInterpreter().HandleCommands(GetCommands(), exc_ctx,
   options, result);
   debugger.SetAsyncExecution(old_async);
   lldb::ReturnStatus status = result.GetStatus();
Index: lldb/sourc

[Lldb-commits] [PATCH] D92187: [lldb] [POSIX-DYLD] Add libraries from initial rendezvous brkpt hit

2020-12-12 Thread Michał Górny via Phabricator via lldb-commits
mgorny updated this revision to Diff 311412.
mgorny added a comment.

Another fix: we should only unload duplicate ld.so if it's actually a 
duplicate, i.e. the path differs. Otherwise, we've ended up unloading the only 
copy.


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

https://reviews.llvm.org/D92187

Files:
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
  lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h
  lldb/source/Plugins/Process/FreeBSDRemote/NativeProcessFreeBSD.cpp
  lldb/test/API/api/multithreaded/TestMultithreaded.py
  
lldb/test/API/functionalities/breakpoint/global_constructor/TestBreakpointInGlobalConstructor.py
  lldb/test/API/functionalities/memory-region/TestMemoryRegion.py
  lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
  
lldb/test/API/tools/lldb-server/libraries-svr4/TestGdbRemoteLibrariesSvr4Support.py
  lldb/test/Shell/Unwind/thread-step-out-ret-addr-check.test

Index: lldb/test/Shell/Unwind/thread-step-out-ret-addr-check.test
===
--- lldb/test/Shell/Unwind/thread-step-out-ret-addr-check.test
+++ lldb/test/Shell/Unwind/thread-step-out-ret-addr-check.test
@@ -3,7 +3,6 @@
 
 # REQUIRES: target-x86_64
 # UNSUPPORTED: system-windows
-# XFAIL: system-freebsd
 
 # RUN: %clang_host %p/Inputs/call-asm.c -x assembler-with-cpp %p/Inputs/thread-step-out-ret-addr-check.s -o %t
 # RUN: not %lldb %t -s %s -b 2>&1 | FileCheck %s
Index: lldb/test/API/tools/lldb-server/libraries-svr4/TestGdbRemoteLibrariesSvr4Support.py
===
--- lldb/test/API/tools/lldb-server/libraries-svr4/TestGdbRemoteLibrariesSvr4Support.py
+++ lldb/test/API/tools/lldb-server/libraries-svr4/TestGdbRemoteLibrariesSvr4Support.py
@@ -120,7 +120,7 @@
 
 @llgs_test
 @skipUnlessPlatform(["linux", "android", "freebsd", "netbsd"])
-@expectedFailureAll(oslist=["freebsd", "netbsd"])
+@expectedFailureNetBSD
 def test_libraries_svr4_load_addr(self):
 self.setup_test()
 self.libraries_svr4_has_correct_load_addr()
Index: lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
===
--- lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
+++ lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
@@ -843,7 +843,6 @@
 self.qMemoryRegionInfo_is_supported()
 
 @llgs_test
-@expectedFailureAll(oslist=["freebsd"])
 def test_qMemoryRegionInfo_is_supported_llgs(self):
 self.init_llgs_test()
 self.build()
@@ -908,7 +907,6 @@
 self.qMemoryRegionInfo_reports_code_address_as_executable()
 
 @skipIfWindows # No pty support to test any inferior output
-@expectedFailureAll(oslist=["freebsd"])
 @llgs_test
 def test_qMemoryRegionInfo_reports_code_address_as_executable_llgs(self):
 self.init_llgs_test()
@@ -975,7 +973,6 @@
 self.qMemoryRegionInfo_reports_stack_address_as_readable_writeable()
 
 @skipIfWindows # No pty support to test any inferior output
-@expectedFailureAll(oslist=["freebsd"])
 @llgs_test
 def test_qMemoryRegionInfo_reports_stack_address_as_readable_writeable_llgs(
 self):
@@ -1042,7 +1039,6 @@
 self.qMemoryRegionInfo_reports_heap_address_as_readable_writeable()
 
 @skipIfWindows # No pty support to test any inferior output
-@expectedFailureAll(oslist=["freebsd"])
 @llgs_test
 def test_qMemoryRegionInfo_reports_heap_address_as_readable_writeable_llgs(
 self):
Index: lldb/test/API/functionalities/memory-region/TestMemoryRegion.py
===
--- lldb/test/API/functionalities/memory-region/TestMemoryRegion.py
+++ lldb/test/API/functionalities/memory-region/TestMemoryRegion.py
@@ -23,7 +23,6 @@
 'main.cpp',
 '// Run here before printing memory regions')
 
-@expectedFailureAll(oslist=["freebsd"])
 def test(self):
 self.build()
 
Index: lldb/test/API/functionalities/breakpoint/global_constructor/TestBreakpointInGlobalConstructor.py
===
--- lldb/test/API/functionalities/breakpoint/global_constructor/TestBreakpointInGlobalConstructor.py
+++ lldb/test/API/functionalities/breakpoint/global_constructor/TestBreakpointInGlobalConstructor.py
@@ -15,7 +15,6 @@
 mydir = TestBase.compute_mydir(__file__)
 NO_DEBUG_INFO_TESTCASE = True
 
-@expectedFailureAll(oslist=["freebsd"], bugnumber='llvm.org/pr48373')
 @expectedFailureNetBSD
 def test(self):
 self.build()
Index: lldb/test/API/api/multithreaded/TestMultithreaded.py
===
--- lldb/test/API/api/multithreaded/TestMultithreaded.py
+++ lldb/test/API/api/multithreaded/TestMultithreaded.py
@@ -31,7 +31,6 @@
 @skipIfNoSBHeaders
 # cla