This revision was automatically updated to reflect the committed changes.
Closed by commit rL360077: [Driver] Change the way we deal with local lldbinit 
files. (authored by JDevlieghere, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D61577?vs=198210&id=198333#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D61577

Files:
  lldb/trunk/lit/Driver/Inputs/.lldbinit
  lldb/trunk/lit/Driver/LocalLLDBInit.test
  lldb/trunk/lit/helper/toolchain.py
  lldb/trunk/source/Interpreter/CommandInterpreter.cpp
  lldb/trunk/tools/driver/Driver.cpp
  lldb/trunk/tools/driver/Driver.h

Index: lldb/trunk/lit/helper/toolchain.py
===================================================================
--- lldb/trunk/lit/helper/toolchain.py
+++ lldb/trunk/lit/helper/toolchain.py
@@ -40,6 +40,11 @@
                   extra_args=['--no-lldbinit', '-S',
                               os.path.join(config.test_source_root,
                                            'lit-lldb-init')]),
+        ToolSubst('%lldb-init',
+                  command=FindTool('lldb'),
+                  extra_args=['-S',
+                              os.path.join(config.test_source_root,
+                                           'lit-lldb-init')]),
         lldbmi,
         ToolSubst('%debugserver',
                   command=FindTool(dsname),
Index: lldb/trunk/lit/Driver/Inputs/.lldbinit
===================================================================
--- lldb/trunk/lit/Driver/Inputs/.lldbinit
+++ lldb/trunk/lit/Driver/Inputs/.lldbinit
@@ -0,0 +1 @@
+settings set -f frame-format "bogus"
Index: lldb/trunk/lit/Driver/LocalLLDBInit.test
===================================================================
--- lldb/trunk/lit/Driver/LocalLLDBInit.test
+++ lldb/trunk/lit/Driver/LocalLLDBInit.test
@@ -0,0 +1,9 @@
+# RUN: mkdir -p %t.root
+# RUN: cp %S/Inputs/.lldbinit %t.root
+# RUN: cd %t.root
+# RUN: %lldb-init -o 'settings show frame-format' 2>&1 | FileCheck %s --check-prefix=INIT --check-prefix=CHECK
+# RUN: %lldb -o 'settings show frame-format' 2>&1 | FileCheck %s --check-prefix=NOINIT --check-prefix=CHECK
+
+# INIT: There is a .lldbinit file in the current directory which is not being read.
+# NOINIT-NOT: There is a .lldbinit file in the current directory which is not being read.
+# CHECK-NOT: bogus
Index: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
===================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp
@@ -2095,16 +2095,14 @@
                                         CommandReturnObject &result) {
   FileSpec init_file;
   if (in_cwd) {
-    ExecutionContext exe_ctx(GetExecutionContext());
-    Target *target = exe_ctx.GetTargetPtr();
-    if (target) {
+    lldb::TargetPropertiesSP properties = Target::GetGlobalProperties();
+    if (properties) {
       // In the current working directory we don't load any program specific
       // .lldbinit files, we only look for a ".lldbinit" file.
       if (m_skip_lldbinit_files)
         return;
 
-      LoadCWDlldbinitFile should_load =
-          target->TargetProperties::GetLoadCWDlldbinitFile();
+      LoadCWDlldbinitFile should_load = properties->GetLoadCWDlldbinitFile();
       if (should_load == eLoadCWDlldbinitWarn) {
         FileSpec dot_lldb(".lldbinit");
         FileSystem::Instance().Resolve(dot_lldb);
Index: lldb/trunk/tools/driver/Driver.h
===================================================================
--- lldb/trunk/tools/driver/Driver.h
+++ lldb/trunk/tools/driver/Driver.h
@@ -47,24 +47,18 @@
                                 lldb::SBStream &strm);
 
   struct OptionData {
-    void AddLocalLLDBInit();
     void AddInitialCommand(std::string command, CommandPlacement placement,
                            bool is_file, lldb::SBError &error);
 
     struct InitialCmdEntry {
       InitialCmdEntry(std::string contents, bool in_is_file,
-                      bool is_cwd_lldbinit_file_read, bool in_quiet = false)
+                      bool in_quiet = false)
           : contents(std::move(contents)), is_file(in_is_file),
-            source_quietly(in_quiet),
-            is_cwd_lldbinit_file_read(is_cwd_lldbinit_file_read) {}
+            source_quietly(in_quiet) {}
 
       std::string contents;
       bool is_file;
       bool source_quietly;
-
-      /// Remember if this is reading the local lldbinit file so we can skip it
-      /// if not permitted.
-      bool is_cwd_lldbinit_file_read;
     };
 
     std::vector<std::string> m_args;
Index: lldb/trunk/tools/driver/Driver.cpp
===================================================================
--- lldb/trunk/tools/driver/Driver.cpp
+++ lldb/trunk/tools/driver/Driver.cpp
@@ -113,24 +113,6 @@
 
 Driver::~Driver() { g_driver = nullptr; }
 
-void Driver::OptionData::AddLocalLLDBInit() {
-  // If there is a local .lldbinit, add that to the list of things to be
-  // sourced, if the settings permit it.
-  SBFileSpec local_lldbinit(".lldbinit", true);
-  SBFileSpec homedir_dot_lldb = SBHostOS::GetUserHomeDirectory();
-  homedir_dot_lldb.AppendPathComponent(".lldbinit");
-
-  // Only read .lldbinit in the current working directory if it's not the same
-  // as the .lldbinit in the home directory (which is already being read in).
-  if (local_lldbinit.Exists() && strcmp(local_lldbinit.GetDirectory(),
-                                        homedir_dot_lldb.GetDirectory()) != 0) {
-    char path[PATH_MAX];
-    local_lldbinit.GetPath(path, sizeof(path));
-    InitialCmdEntry entry(path, true, true, true);
-    m_after_file_commands.push_back(entry);
-  }
-}
-
 void Driver::OptionData::AddInitialCommand(std::string command,
                                            CommandPlacement placement,
                                            bool is_file, SBError &error) {
@@ -150,17 +132,17 @@
   if (is_file) {
     SBFileSpec file(command.c_str());
     if (file.Exists())
-      command_set->push_back(InitialCmdEntry(command, is_file, false));
+      command_set->push_back(InitialCmdEntry(command, is_file));
     else if (file.ResolveExecutableLocation()) {
       char final_path[PATH_MAX];
       file.GetPath(final_path, sizeof(final_path));
-      command_set->push_back(InitialCmdEntry(final_path, is_file, false));
+      command_set->push_back(InitialCmdEntry(final_path, is_file));
     } else
       error.SetErrorStringWithFormat(
           "file specified in --source (-s) option doesn't exist: '%s'",
           command.c_str());
   } else
-    command_set->push_back(InitialCmdEntry(command, is_file, false));
+    command_set->push_back(InitialCmdEntry(command, is_file));
 }
 
 void Driver::WriteCommandsForSourcing(CommandPlacement placement,
@@ -181,36 +163,6 @@
   for (const auto &command_entry : *command_set) {
     const char *command = command_entry.contents.c_str();
     if (command_entry.is_file) {
-      // If this command_entry is a file to be sourced, and it's the ./.lldbinit
-      // file (the .lldbinit
-      // file in the current working directory), only read it if
-      // target.load-cwd-lldbinit is 'true'.
-      if (command_entry.is_cwd_lldbinit_file_read) {
-        SBStringList strlist = lldb::SBDebugger::GetInternalVariableValue(
-            "target.load-cwd-lldbinit", m_debugger.GetInstanceName());
-        if (strlist.GetSize() == 1 &&
-            strcmp(strlist.GetStringAtIndex(0), "warn") == 0) {
-          FILE *output = m_debugger.GetOutputFileHandle();
-          ::fprintf(
-              output,
-              "There is a .lldbinit file in the current directory which is not "
-              "being read.\n"
-              "To silence this warning without sourcing in the local "
-              ".lldbinit,\n"
-              "add the following to the lldbinit file in your home directory:\n"
-              "    settings set target.load-cwd-lldbinit false\n"
-              "To allow lldb to source .lldbinit files in the current working "
-              "directory,\n"
-              "set the value of this variable to true.  Only do so if you "
-              "understand and\n"
-              "accept the security risk.\n");
-          return;
-        }
-        if (strlist.GetSize() == 1 &&
-            strcmp(strlist.GetStringAtIndex(0), "false") == 0) {
-          return;
-        }
-      }
       bool source_quietly =
           m_option_data.m_source_quietly || command_entry.source_quietly;
       strm.Printf("command source -s %i '%s'\n",
@@ -227,7 +179,6 @@
 // user only wanted help or version information.
 SBError Driver::ProcessArgs(const opt::InputArgList &args, bool &exiting) {
   SBError error;
-  m_option_data.AddLocalLLDBInit();
 
   // This is kind of a pain, but since we make the debugger in the Driver's
   // constructor, we can't know at that point whether we should read in init
@@ -554,6 +505,13 @@
     result.PutOutput(m_debugger.GetOutputFileHandle());
   }
 
+  // Source the local .lldbinit file if it exists and we're allowed to source.
+  // Here we want to always print the return object because it contains the
+  // warning and instructions to load local lldbinit files.
+  sb_interpreter.SourceInitFileInCurrentWorkingDirectory(result);
+  result.PutError(m_debugger.GetErrorFileHandle());
+  result.PutOutput(m_debugger.GetOutputFileHandle());
+
   // We allow the user to specify an exit code when calling quit which we will
   // return when exiting.
   m_debugger.GetCommandInterpreter().AllowExitCodeOnQuit(true);
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to