diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -2016,12 +2016,15 @@ // there wasn't an equivalent module in the list already, and if there was, // let's remove it. if (module_sp) { + bool isExecutable = false; ObjectFile *objfile = module_sp->GetObjectFile(); if (objfile) { switch (objfile->GetType()) { + case ObjectFile::eTypeExecutable: /// A normal executable + isExecutable = true; + LLVM_FALLTHROUGH; case ObjectFile::eTypeCoreFile: /// A core file that has a checkpoint of /// a program's execution state - case ObjectFile::eTypeExecutable: /// A normal executable case ObjectFile::eTypeDynamicLinker: /// The platform's dynamic linker /// executable case ObjectFile::eTypeObjectFile: /// An intermediate object file @@ -2084,6 +2087,16 @@ } else { m_images.Append(module_sp, notify); } + + // Ensure that architecture of the Target matches that of the + // executable file. Otherwise Target might use a "default" platform + // that can't actually debug the executable. For example, if the Target + // is created and by default assumes that it should use "gdb-remote" + // process, however executable has an architecture that requires a + // different Process class - without explicitly set executable module + // Target would attempt to use "gdb-remote" created initially. + if (isExecutable) + SetExecutableModule(module_sp, eLoadDependentsNo); } else module_sp.reset(); }