[Lldb-commits] [PATCH] D70847: [lldb-vscode] Ensure that target matches the executable file

Anton Kolesov via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 29 03:30:55 PST 2019


anton.kolesov created this revision.
anton.kolesov added a project: LLDB.
Herald added a subscriber: lldb-commits.

Different architectures may use different target processes, so default
"gdb-remote" target process created by lldb-vscode may not work for all
targets. This commit changes behaviour of the request_launch function -
first it assigns an executable file to the debugger, which may create the
new SBTarget instance with a different target process implementation. In
contrast, if executable file is specified inside of the SBLaunchInfo
structure, then this structure is passed to an already existing target and
thus can't force recreation of the target to match a desired process
implementation.

New code has a behavior similar to LLDB MI [1], where typically IDE would
specify target file with -file-exec-and-symbols, and then only do -exec-run
command that would launch the process. In lldb-vscode those two actions are
merged into one request_launch function. Similarly in the interpreter
session, used would first do "file" command, then "process launch"


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70847

Files:
  lldb/tools/lldb-vscode/lldb-vscode.cpp


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===================================================================
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -1346,28 +1346,19 @@
   // Run any initialize LLDB commands the user specified in the launch.json
   g_vsc.RunInitCommands();
 
-  // Grab the current working directory if there is one and set it in the
-  // launch info.
-  const auto cwd = GetString(arguments, "cwd");
-  if (!cwd.empty())
-    g_vsc.launch_info.SetWorkingDirectory(cwd.data());
-
-  // Grab the name of the program we need to debug and set it as the first
-  // argument that will be passed to the program we will debug.
+  // Grab the name of the program we need to debug and create a new target using
+  // the given program as an argument and replace previous dummy target with a
+  // new one. New target might have a different type then the previous one,
+  // based on the ABI or architecture of the file. Settings program path in
+  // LaunchInfo is useless, because launch info will recycle existing target,
+  // which might be incorrect for the selected file.
   llvm::StringRef program = GetString(arguments, "program");
   if (!program.empty()) {
-    lldb::SBFileSpec program_fspec(program.data(), true /*resolve_path*/);
-    g_vsc.launch_info.SetExecutableFile(program_fspec,
-                                        true /*add_as_first_arg*/);
-    const char *target_triple = nullptr;
-    const char *uuid_cstr = nullptr;
-    // Stand alone debug info file if different from executable
-    const char *symfile = nullptr;
-    lldb::SBModule module = g_vsc.target.AddModule(
-        program.data(), target_triple, uuid_cstr, symfile);
-    if (!module.IsValid()) {
-      response["success"] = llvm::json::Value(false);
+    // Create a target that matches the file.
+    g_vsc.target = g_vsc.debugger.CreateTarget(program.data());
 
+    if (!g_vsc.target.IsValid()) {
+      response["success"] = llvm::json::Value(false);
       EmplaceSafeString(
           response, "message",
           llvm::formatv("Could not load program '{0}'.", program).str());
@@ -1376,6 +1367,15 @@
     }
   }
 
+  // Instantiate a launch info instance for the target.
+  g_vsc.launch_info = g_vsc.target.GetLaunchInfo();
+
+  // Grab the current working directory if there is one and set it in the
+  // launch info.
+  const auto cwd = GetString(arguments, "cwd");
+  if (!cwd.empty())
+    g_vsc.launch_info.SetWorkingDirectory(cwd.data());
+
   // Extract any extra arguments and append them to our program arguments for
   // when we launch
   auto args = GetStrings(arguments, "args");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70847.231514.patch
Type: text/x-patch
Size: 2668 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20191129/6faac069/attachment.bin>


More information about the lldb-commits mailing list