anton.kolesov updated this revision to Diff 232512. anton.kolesov retitled this revision from "[lldb-vscode] Ensure that target matches the executable file" to "[lldb] Set executable module when adding modules to the Target". anton.kolesov edited the summary of this revision. anton.kolesov added a comment.
Reimplement the solution based on a comment from Greg. Tested with testsuite on Linux for x64 - there are no changes in test results. Also manually tested with a proprietary process plugin - currently it is not possible to run existing testsuite with that plugin because it targets embedded systems which has no `cwd`, `exit()` or environment. I also attemted to test this against Windows hosts and targets. The change, apparently, resolves that launch capability on Windows, however setting of breakpoints doesn't work - it is only possible to stop application on entry, and on resume it will run till the end. Among the existing lldb-vscode tests some of them depend on <unistd.h> unavailable on windows, others fail because of the breakpoints that don't work. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D70847/new/ https://reviews.llvm.org/D70847 Files: lldb/source/Target/Target.cpp Index: lldb/source/Target/Target.cpp =================================================================== --- lldb/source/Target/Target.cpp +++ 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(); }
Index: lldb/source/Target/Target.cpp =================================================================== --- lldb/source/Target/Target.cpp +++ 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(); }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits