summaryrefslogtreecommitdiffstats
path: root/lldb/source
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/API/SBFileSpec.cpp6
-rw-r--r--lldb/source/API/SBHostOS.cpp16
-rw-r--r--lldb/source/Interpreter/CommandInterpreter.cpp42
-rw-r--r--lldb/source/Target/Target.cpp18
4 files changed, 77 insertions, 5 deletions
diff --git a/lldb/source/API/SBFileSpec.cpp b/lldb/source/API/SBFileSpec.cpp
index dd7435de1b5..23bc5bc8eb6 100644
--- a/lldb/source/API/SBFileSpec.cpp
+++ b/lldb/source/API/SBFileSpec.cpp
@@ -211,3 +211,9 @@ SBFileSpec::GetDescription (SBStream &description) const
strm.PutCString (path);
return true;
}
+
+void
+SBFileSpec::AppendPathComponent (const char *fn)
+{
+ m_opaque_ap->AppendPathComponent (fn);
+}
diff --git a/lldb/source/API/SBHostOS.cpp b/lldb/source/API/SBHostOS.cpp
index 008ca4d9672..cd3cff3b2e9 100644
--- a/lldb/source/API/SBHostOS.cpp
+++ b/lldb/source/API/SBHostOS.cpp
@@ -17,6 +17,9 @@
#include "lldb/Host/HostThread.h"
#include "lldb/Host/ThreadLauncher.h"
+#include "llvm/Support/Path.h"
+#include "llvm/ADT/SmallVector.h"
+
using namespace lldb;
using namespace lldb_private;
@@ -53,6 +56,19 @@ SBHostOS::GetLLDBPath (lldb::PathType path_type)
return sb_fspec;
}
+SBFileSpec
+SBHostOS::GetUserHomeDirectory ()
+{
+ SBFileSpec sb_fspec;
+
+ llvm::SmallString<64> home_dir_path;
+ llvm::sys::path::home_directory (home_dir_path);
+ FileSpec homedir (home_dir_path.c_str(), true);
+
+ sb_fspec.SetFileSpec (homedir);
+ return sb_fspec;
+}
+
lldb::thread_t
SBHostOS::ThreadCreate
(
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index bab12462489..e31b3367720 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -2319,12 +2319,44 @@ CommandInterpreter::SourceInitFile (bool in_cwd, CommandReturnObject &result)
FileSpec init_file;
if (in_cwd)
{
- // 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;
+ ExecutionContext exe_ctx(GetExecutionContext());
+ Target *target = exe_ctx.GetTargetPtr();
+ if (target)
+ {
+ // 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;
- init_file.SetFile ("./.lldbinit", true);
+ LoadCWDlldbinitFile should_load = target->TargetProperties::GetLoadCWDlldbinitFile ();
+ if (should_load == eLoadCWDlldbinitWarn)
+ {
+ FileSpec dot_lldb (".lldbinit", true);
+ llvm::SmallString<64> home_dir_path;
+ llvm::sys::path::home_directory (home_dir_path);
+ FileSpec homedir_dot_lldb (home_dir_path.c_str(), false);
+ homedir_dot_lldb.AppendPathComponent (".lldbinit");
+ homedir_dot_lldb.ResolvePath ();
+ if (dot_lldb.Exists ()
+ && dot_lldb.GetDirectory() != homedir_dot_lldb.GetDirectory())
+ {
+ result.AppendErrorWithFormat (
+ "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.");
+ result.SetStatus (eReturnStatusFailed);
+ return;
+ }
+ }
+ else if (should_load == eLoadCWDlldbinitTrue)
+ {
+ init_file.SetFile ("./.lldbinit", true);
+ }
+ }
}
else
{
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 88083e0d342..7d3543cd524 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -3363,6 +3363,15 @@ g_load_script_from_sym_file_values[] =
};
static OptionEnumValueElement
+g_load_current_working_dir_lldbinit_values[] =
+{
+ { eLoadCWDlldbinitTrue, "true", "Load .lldbinit files from current directory"},
+ { eLoadCWDlldbinitFalse, "false", "Do not load .lldbinit files from current directory"},
+ { eLoadCWDlldbinitWarn, "warn", "Warn about loading .lldbinit files from current directory"},
+ { 0, nullptr, nullptr }
+};
+
+static OptionEnumValueElement
g_memory_module_load_level_values[] =
{
{ eMemoryModuleLoadLevelMinimal, "minimal" , "Load minimal information when loading modules from memory. Currently this setting loads sections only."},
@@ -3418,6 +3427,7 @@ g_properties[] =
{ "hex-immediate-style" , OptionValue::eTypeEnum , false, Disassembler::eHexStyleC, nullptr, g_hex_immediate_style_values, "Which style to use for printing hexadecimal disassembly values." },
{ "use-fast-stepping" , OptionValue::eTypeBoolean , false, true, nullptr, nullptr, "Use a fast stepping algorithm based on running from branch to branch rather than instruction single-stepping." },
{ "load-script-from-symbol-file" , OptionValue::eTypeEnum , false, eLoadScriptFromSymFileWarn, nullptr, g_load_script_from_sym_file_values, "Allow LLDB to load scripting resources embedded in symbol files when available." },
+ { "load-cwd-lldbinit" , OptionValue::eTypeEnum , false, eLoadCWDlldbinitWarn, nullptr, g_load_current_working_dir_lldbinit_values, "Allow LLDB to .lldbinit files from the current directory automatically." },
{ "memory-module-load-level" , OptionValue::eTypeEnum , false, eMemoryModuleLoadLevelComplete, nullptr, g_memory_module_load_level_values,
"Loading modules from memory can be slow as reading the symbol tables and other data can take a long time depending on your connection to the debug target. "
"This setting helps users control how much information gets loaded when loading modules from memory."
@@ -3465,6 +3475,7 @@ enum
ePropertyHexImmediateStyle,
ePropertyUseFastStepping,
ePropertyLoadScriptFromSymbolFile,
+ ePropertyLoadCWDlldbinitFile,
ePropertyMemoryModuleLoadLevel,
ePropertyDisplayExpressionsInCrashlogs,
ePropertyTrapHandlerNames,
@@ -3945,6 +3956,13 @@ TargetProperties::GetLoadScriptFromSymbolFile () const
return (LoadScriptFromSymFile)m_collection_sp->GetPropertyAtIndexAsEnumeration(nullptr, idx, g_properties[idx].default_uint_value);
}
+LoadCWDlldbinitFile
+TargetProperties::GetLoadCWDlldbinitFile () const
+{
+ const uint32_t idx = ePropertyLoadCWDlldbinitFile;
+ return (LoadCWDlldbinitFile) m_collection_sp->GetPropertyAtIndexAsEnumeration(nullptr, idx, g_properties[idx].default_uint_value);
+}
+
Disassembler::HexImmediateStyle
TargetProperties::GetHexImmediateStyle () const
{
OpenPOWER on IntegriCloud