JDevlieghere created this revision.
JDevlieghere added reviewers: davide, labath, jingham, clayborg, mgorny.
JDevlieghere added a project: LLDB.
Herald added a subscriber: teemperor.

When invoking lldb on the command line with a binary, lldb will construct a 
command stream to create the target.

  $ lldb ./foo
  (lldb) target create "./foo"
  Current executable set to './foo' (x86_64).

This poses a problem for reproducers when the path to the binary is a relative 
path. When the reproducer is replayed form a different location, the path gets 
resolved to a different absolute path, unknown to the VFS.

This patch changes the behavior of the driver to resolve the target's path 
before constructing the `target create` command.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D65611

Files:
  lldb/lit/Driver/TestTarget.test
  
lldb/packages/Python/lldbsuite/test/lang/objc/objc-dynamic-value/TestObjCDynamicValue.py
  lldb/tools/driver/Driver.cpp


Index: lldb/tools/driver/Driver.cpp
===================================================================
--- lldb/tools/driver/Driver.cpp
+++ lldb/tools/driver/Driver.cpp
@@ -533,14 +533,22 @@
   if (!m_option_data.m_repl) {
     const size_t num_args = m_option_data.m_args.size();
     if (num_args > 0) {
+      char target_path[128];
       char arch_name[64];
+
+      // Resolve target.
+      SBFileSpec target(m_option_data.m_args[0].c_str());
+      target.ResolveExecutableLocation();
+      target.GetPath(target_path, sizeof(target_path));
+
       if (lldb::SBDebugger::GetDefaultArchitecture(arch_name,
-                                                   sizeof(arch_name)))
+                                                   sizeof(arch_name))) {
         commands_stream.Printf("target create --arch=%s %s", arch_name,
-                               EscapeString(m_option_data.m_args[0]).c_str());
-      else
+                               EscapeString(target_path).c_str());
+      } else {
         commands_stream.Printf("target create %s",
-                               EscapeString(m_option_data.m_args[0]).c_str());
+                               EscapeString(target_path).c_str());
+      }
 
       if (!m_option_data.m_core_file.empty()) {
         commands_stream.Printf(" --core %s",
Index: 
lldb/packages/Python/lldbsuite/test/lang/objc/objc-dynamic-value/TestObjCDynamicValue.py
===================================================================
--- 
lldb/packages/Python/lldbsuite/test/lang/objc/objc-dynamic-value/TestObjCDynamicValue.py
+++ 
lldb/packages/Python/lldbsuite/test/lang/objc/objc-dynamic-value/TestObjCDynamicValue.py
@@ -35,7 +35,6 @@
 
     @skipUnlessDarwin
     @add_test_categories(['pyapi'])
-    @expectedFailureDarwin("llvm.org/pr20271 rdar://18684107")
     def test_get_objc_dynamic_vals(self):
         """Test fetching ObjC dynamic values."""
         if self.getArchitecture() == 'i386':
Index: lldb/lit/Driver/TestTarget.test
===================================================================
--- /dev/null
+++ lldb/lit/Driver/TestTarget.test
@@ -0,0 +1,7 @@
+# Make sure lldb resolves the target path.
+# RUN: mkdir -p %t/foo
+# RUN: cd %t/foo
+# RUN: %clang %p/Inputs/hello.c -g -o a.out
+# RUN: %lldb -b a.out | FileCheck %s
+
+# CHECK: target create "{{.*}}foo{{[/\\\\]+}}a.out"


Index: lldb/tools/driver/Driver.cpp
===================================================================
--- lldb/tools/driver/Driver.cpp
+++ lldb/tools/driver/Driver.cpp
@@ -533,14 +533,22 @@
   if (!m_option_data.m_repl) {
     const size_t num_args = m_option_data.m_args.size();
     if (num_args > 0) {
+      char target_path[128];
       char arch_name[64];
+
+      // Resolve target.
+      SBFileSpec target(m_option_data.m_args[0].c_str());
+      target.ResolveExecutableLocation();
+      target.GetPath(target_path, sizeof(target_path));
+
       if (lldb::SBDebugger::GetDefaultArchitecture(arch_name,
-                                                   sizeof(arch_name)))
+                                                   sizeof(arch_name))) {
         commands_stream.Printf("target create --arch=%s %s", arch_name,
-                               EscapeString(m_option_data.m_args[0]).c_str());
-      else
+                               EscapeString(target_path).c_str());
+      } else {
         commands_stream.Printf("target create %s",
-                               EscapeString(m_option_data.m_args[0]).c_str());
+                               EscapeString(target_path).c_str());
+      }
 
       if (!m_option_data.m_core_file.empty()) {
         commands_stream.Printf(" --core %s",
Index: lldb/packages/Python/lldbsuite/test/lang/objc/objc-dynamic-value/TestObjCDynamicValue.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lang/objc/objc-dynamic-value/TestObjCDynamicValue.py
+++ lldb/packages/Python/lldbsuite/test/lang/objc/objc-dynamic-value/TestObjCDynamicValue.py
@@ -35,7 +35,6 @@
 
     @skipUnlessDarwin
     @add_test_categories(['pyapi'])
-    @expectedFailureDarwin("llvm.org/pr20271 rdar://18684107")
     def test_get_objc_dynamic_vals(self):
         """Test fetching ObjC dynamic values."""
         if self.getArchitecture() == 'i386':
Index: lldb/lit/Driver/TestTarget.test
===================================================================
--- /dev/null
+++ lldb/lit/Driver/TestTarget.test
@@ -0,0 +1,7 @@
+# Make sure lldb resolves the target path.
+# RUN: mkdir -p %t/foo
+# RUN: cd %t/foo
+# RUN: %clang %p/Inputs/hello.c -g -o a.out
+# RUN: %lldb -b a.out | FileCheck %s
+
+# CHECK: target create "{{.*}}foo{{[/\\\\]+}}a.out"
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to