Skip to content

Commit 6ab4cd9

Browse files
author
git apple-llvm automerger
committed
Merge commit 'ffb36e4f5665' from apple/stable/20200714 into swift/main
2 parents 36c69f4 + ffb36e4 commit 6ab4cd9

File tree

20 files changed

+403
-161
lines changed

20 files changed

+403
-161
lines changed

lldb/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ if(POLICY CMP0075)
77
cmake_policy(SET CMP0075 NEW)
88
endif()
99

10+
if(POLICY CMP0077)
11+
cmake_policy(SET CMP0077 NEW)
12+
endif()
13+
1014
# Add path for custom modules.
1115
set(CMAKE_MODULE_PATH
1216
${CMAKE_MODULE_PATH}

lldb/include/lldb/Interpreter/CommandInterpreter.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,8 @@ class CommandInterpreter : public Broadcaster,
541541
bool SaveTranscript(CommandReturnObject &result,
542542
llvm::Optional<std::string> output_file = llvm::None);
543543

544+
FileSpec GetCurrentSourceDir();
545+
544546
protected:
545547
friend class Debugger;
546548

@@ -627,7 +629,13 @@ class CommandInterpreter : public Broadcaster,
627629
ChildrenTruncatedWarningStatus m_truncation_warning; // Whether we truncated
628630
// children and whether
629631
// the user has been told
632+
633+
// FIXME: Stop using this to control adding to the history and then replace
634+
// this with m_command_source_dirs.size().
630635
uint32_t m_command_source_depth;
636+
/// A stack of directory paths. When not empty, the last one is the directory
637+
/// of the file that's currently sourced.
638+
std::vector<FileSpec> m_command_source_dirs;
631639
std::vector<uint32_t> m_command_source_flags;
632640
CommandInterpreterRunResult m_result;
633641

lldb/include/lldb/Interpreter/ScriptInterpreter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,8 @@ class ScriptInterpreter : public PluginInterface {
507507
virtual bool
508508
LoadScriptingModule(const char *filename, bool init_session,
509509
lldb_private::Status &error,
510-
StructuredData::ObjectSP *module_sp = nullptr);
510+
StructuredData::ObjectSP *module_sp = nullptr,
511+
FileSpec extra_search_dir = {});
511512

512513
virtual bool IsReservedWord(const char *word) { return false; }
513514

lldb/source/Commands/CommandObjectCommands.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,9 @@ class CommandObjectCommandsScriptImport : public CommandObjectParsed {
12501250
case 'r':
12511251
// NO-OP
12521252
break;
1253+
case 'c':
1254+
relative_to_command_file = true;
1255+
break;
12531256
default:
12541257
llvm_unreachable("Unimplemented option");
12551258
}
@@ -1258,11 +1261,13 @@ class CommandObjectCommandsScriptImport : public CommandObjectParsed {
12581261
}
12591262

12601263
void OptionParsingStarting(ExecutionContext *execution_context) override {
1264+
relative_to_command_file = false;
12611265
}
12621266

12631267
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
12641268
return llvm::makeArrayRef(g_script_import_options);
12651269
}
1270+
bool relative_to_command_file = false;
12661271
};
12671272

12681273
bool DoExecute(Args &command, CommandReturnObject &result) override {
@@ -1272,6 +1277,17 @@ class CommandObjectCommandsScriptImport : public CommandObjectParsed {
12721277
return false;
12731278
}
12741279

1280+
FileSpec source_dir = {};
1281+
if (m_options.relative_to_command_file) {
1282+
source_dir = GetDebugger().GetCommandInterpreter().GetCurrentSourceDir();
1283+
if (!source_dir) {
1284+
result.AppendError("command script import -c can only be specified "
1285+
"from a command file");
1286+
result.SetStatus(eReturnStatusFailed);
1287+
return false;
1288+
}
1289+
}
1290+
12751291
for (auto &entry : command.entries()) {
12761292
Status error;
12771293

@@ -1286,7 +1302,7 @@ class CommandObjectCommandsScriptImport : public CommandObjectParsed {
12861302
// more)
12871303
m_exe_ctx.Clear();
12881304
if (GetDebugger().GetScriptInterpreter()->LoadScriptingModule(
1289-
entry.c_str(), init_session, error)) {
1305+
entry.c_str(), init_session, error, nullptr, source_dir)) {
12901306
result.SetStatus(eReturnStatusSuccessFinishNoResult);
12911307
} else {
12921308
result.AppendErrorWithFormat("module importing failed: %s",

lldb/source/Commands/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,10 @@ let Command = "script import" in {
716716
Desc<"Allow the script to be loaded even if it was already loaded before. "
717717
"This argument exists for backwards compatibility, but reloading is always "
718718
"allowed, whether you specify it or not.">;
719+
def relative_to_command_file : Option<"relative-to-command-file", "c">,
720+
Group<1>, Desc<"Resolve non-absolute paths relative to the location of the "
721+
"current command file. This argument can only be used when the command is "
722+
"being sourced from a file.">;
719723
}
720724

721725
let Command = "script add" in {

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,11 +2556,15 @@ void CommandInterpreter::HandleCommandsFromFile(
25562556
debugger.SetAsyncExecution(false);
25572557

25582558
m_command_source_depth++;
2559+
m_command_source_dirs.push_back(cmd_file.CopyByRemovingLastPathComponent());
25592560

25602561
debugger.RunIOHandlerSync(io_handler_sp);
25612562
if (!m_command_source_flags.empty())
25622563
m_command_source_flags.pop_back();
2564+
2565+
m_command_source_dirs.pop_back();
25632566
m_command_source_depth--;
2567+
25642568
result.SetStatus(eReturnStatusSuccessFinishNoResult);
25652569
debugger.SetAsyncExecution(old_async_execution);
25662570
}
@@ -2966,6 +2970,12 @@ bool CommandInterpreter::SaveTranscript(
29662970
return true;
29672971
}
29682972

2973+
FileSpec CommandInterpreter::GetCurrentSourceDir() {
2974+
if (m_command_source_dirs.empty())
2975+
return {};
2976+
return m_command_source_dirs.back();
2977+
}
2978+
29692979
void CommandInterpreter::GetLLDBCommandsFromIOHandler(
29702980
const char *prompt, IOHandlerDelegate &delegate, void *baton) {
29712981
Debugger &debugger = GetDebugger();

lldb/source/Interpreter/ScriptInterpreter.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ void ScriptInterpreter::CollectDataForWatchpointCommandCallback(
4747
"This script interpreter does not support watchpoint callbacks.");
4848
}
4949

50-
bool ScriptInterpreter::LoadScriptingModule(
51-
const char *filename, bool init_session, lldb_private::Status &error,
52-
StructuredData::ObjectSP *module_sp) {
50+
bool ScriptInterpreter::LoadScriptingModule(const char *filename,
51+
bool init_session,
52+
lldb_private::Status &error,
53+
StructuredData::ObjectSP *module_sp,
54+
FileSpec extra_search_dir) {
5355
error.SetErrorString(
5456
"This script interpreter does not support importing modules.");
5557
return false;

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

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,28 +1183,6 @@ AppleObjCRuntimeV2::GetClassDescriptorFromISA(ObjCISA isa) {
11831183
return class_descriptor_sp;
11841184
}
11851185

1186-
static std::pair<bool, ConstString> ObjCGetClassNameRaw(
1187-
AppleObjCRuntime::ObjCISA isa,
1188-
Process *process) {
1189-
StreamString expr_string;
1190-
std::string input = std::to_string(isa);
1191-
expr_string.Printf("(const char *)objc_debug_class_getNameRaw(%s)",
1192-
input.c_str());
1193-
1194-
ValueObjectSP result_sp;
1195-
EvaluateExpressionOptions eval_options;
1196-
eval_options.SetLanguage(lldb::eLanguageTypeObjC);
1197-
eval_options.SetResultIsInternal(true);
1198-
eval_options.SetGenerateDebugInfo(true);
1199-
eval_options.SetTimeout(process->GetUtilityExpressionTimeout());
1200-
auto eval_result = process->GetTarget().EvaluateExpression(
1201-
expr_string.GetData(),
1202-
process->GetThreadList().GetSelectedThread()->GetSelectedFrame().get(),
1203-
result_sp, eval_options);
1204-
ConstString type_name(result_sp->GetSummaryAsCString());
1205-
return std::make_pair(eval_result == eExpressionCompleted, type_name);
1206-
}
1207-
12081186
ObjCLanguageRuntime::ClassDescriptorSP
12091187
AppleObjCRuntimeV2::GetClassDescriptor(ValueObject &valobj) {
12101188
ClassDescriptorSP objc_class_sp;
@@ -1240,10 +1218,7 @@ AppleObjCRuntimeV2::GetClassDescriptor(ValueObject &valobj) {
12401218
return objc_class_sp;
12411219

12421220
objc_class_sp = GetClassDescriptorFromISA(isa);
1243-
1244-
if (objc_class_sp)
1245-
return objc_class_sp;
1246-
else {
1221+
if (isa && !objc_class_sp) {
12471222
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS |
12481223
LIBLLDB_LOG_TYPES));
12491224
LLDB_LOGF(log,
@@ -1252,13 +1227,6 @@ AppleObjCRuntimeV2::GetClassDescriptor(ValueObject &valobj) {
12521227
"not in class descriptor cache 0x%" PRIx64,
12531228
isa_pointer, isa);
12541229
}
1255-
1256-
ClassDescriptorSP descriptor_sp(new ClassDescriptorV2(*this, isa, nullptr));
1257-
auto resolved = ObjCGetClassNameRaw(isa, process);
1258-
if (resolved.first == true) {
1259-
AddClass(isa, descriptor_sp, resolved.second.AsCString());
1260-
objc_class_sp = descriptor_sp;
1261-
}
12621230
return objc_class_sp;
12631231
}
12641232

lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void ScriptInterpreterLua::ExecuteInterpreterLoop() {
124124

125125
bool ScriptInterpreterLua::LoadScriptingModule(
126126
const char *filename, bool init_session, lldb_private::Status &error,
127-
StructuredData::ObjectSP *module_sp) {
127+
StructuredData::ObjectSP *module_sp, FileSpec extra_search_dir) {
128128

129129
FileSystem::Instance().Collect(filename);
130130
if (llvm::Error e = m_lua->LoadModule(filename)) {

lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class ScriptInterpreterLua : public ScriptInterpreter {
2525

2626
void ExecuteInterpreterLoop() override;
2727

28-
bool
29-
LoadScriptingModule(const char *filename, bool init_session,
30-
lldb_private::Status &error,
31-
StructuredData::ObjectSP *module_sp = nullptr) override;
28+
bool LoadScriptingModule(const char *filename, bool init_session,
29+
lldb_private::Status &error,
30+
StructuredData::ObjectSP *module_sp = nullptr,
31+
FileSpec extra_search_dir = {}) override;
3232

3333
// Static Functions
3434
static void Initialize();

0 commit comments

Comments
 (0)