[Lldb-commits] [lldb] r166186 - in /lldb/trunk: include/lldb/Host/FileSpec.h include/lldb/Target/TargetList.h source/API/SBDebugger.cpp source/Commands/CommandObjectProcess.cpp source/Commands/CommandObjectTarget.cpp source/Host/common/FileSpec.cpp source/Host/common/Host.cpp source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp source/Plugins/Platform/Linux/PlatformLinux.cpp source/Plugins/Platform/MacOSX/PlatformDarwin.cpp source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp source/Target/TargetList.cpp

Greg Clayton gclayton at apple.com
Thu Oct 18 09:33:34 PDT 2012


Author: gclayton
Date: Thu Oct 18 11:33:33 2012
New Revision: 166186

URL: http://llvm.org/viewvc/llvm-project?rev=166186&view=rev
Log:
<rdar://problem/12462048>
<rdar://problem/12068650>

More fixes to how we handle paths that are used to create a target.

This modification centralizes the location where and how what the user specifies gets resolved. Prior to this fix, the TargetList::CreateTarget variants took a FileSpec object which meant everyone had the opportunity to resolve the path their own way. Now both CreateTarget variants take a "const char *use_exe_path" which allows the TargetList::CreateTarget to centralize where the resolving happens and "do the right thing".



Modified:
    lldb/trunk/include/lldb/Host/FileSpec.h
    lldb/trunk/include/lldb/Target/TargetList.h
    lldb/trunk/source/API/SBDebugger.cpp
    lldb/trunk/source/Commands/CommandObjectProcess.cpp
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Host/common/FileSpec.cpp
    lldb/trunk/source/Host/common/Host.cpp
    lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
    lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
    lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
    lldb/trunk/source/Target/TargetList.cpp

Modified: lldb/trunk/include/lldb/Host/FileSpec.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/FileSpec.h?rev=166186&r1=166185&r2=166186&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/FileSpec.h (original)
+++ lldb/trunk/include/lldb/Host/FileSpec.h Thu Oct 18 11:33:33 2012
@@ -342,6 +342,17 @@
     bool
     IsSourceImplementationFile () const;
 
+    //------------------------------------------------------------------
+    /// Returns true if the filespec represents path that is relative
+    /// path to the current working directory.
+    ///
+    /// @return
+    ///     \b true if the filespec represents a current working
+    ///     directory relative path, \b false otherwise.
+    //------------------------------------------------------------------
+    bool
+    IsRelativeToCurrentWorkingDirectory () const;
+    
     TimeValue
     GetModificationTime () const;
 

Modified: lldb/trunk/include/lldb/Target/TargetList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/TargetList.h?rev=166186&r1=166185&r2=166186&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/TargetList.h (original)
+++ lldb/trunk/include/lldb/Target/TargetList.h Thu Oct 18 11:33:33 2012
@@ -98,7 +98,7 @@
     //------------------------------------------------------------------
     Error
     CreateTarget (Debugger &debugger,
-                  const FileSpec& file_spec,
+                  const char *user_exe_path,
                   const char *triple_cstr,
                   bool get_dependent_modules,
                   const OptionGroupPlatform *platform_options,
@@ -112,7 +112,7 @@
     //------------------------------------------------------------------
     Error
     CreateTarget (Debugger &debugger,
-                  const FileSpec& file_spec,
+                  const char *user_exe_path,
                   const ArchSpec& arch,
                   bool get_dependent_modules,
                   lldb::PlatformSP &platform_sp,

Modified: lldb/trunk/source/API/SBDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=166186&r1=166185&r2=166186&view=diff
==============================================================================
--- lldb/trunk/source/API/SBDebugger.cpp (original)
+++ lldb/trunk/source/API/SBDebugger.cpp Thu Oct 18 11:33:33 2012
@@ -511,12 +511,11 @@
     if (m_opaque_sp)
     {
         sb_error.Clear();
-        FileSpec filename_spec (filename, true);
         OptionGroupPlatform platform_options (false);
         platform_options.SetPlatformName (platform_name);
         
         sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, 
-                                                                    filename_spec, 
+                                                                    filename, 
                                                                     target_triple, 
                                                                     add_dependent_modules, 
                                                                     &platform_options,
@@ -554,10 +553,9 @@
     TargetSP target_sp;
     if (m_opaque_sp)
     {
-        FileSpec file_spec (filename, true);
         const bool add_dependent_modules = true;
         Error error (m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, 
-                                                                file_spec, 
+                                                                filename, 
                                                                 target_triple, 
                                                                 add_dependent_modules, 
                                                                 NULL,
@@ -584,12 +582,11 @@
     TargetSP target_sp;
     if (m_opaque_sp)
     {
-        FileSpec file (filename, true);
         Error error;
         const bool add_dependent_modules = true;
 
-        error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, 
-                                                           file, 
+        error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
+                                                           filename, 
                                                            arch_cstr, 
                                                            add_dependent_modules, 
                                                            NULL, 
@@ -618,14 +615,13 @@
     TargetSP target_sp;
     if (m_opaque_sp)
     {
-        FileSpec file (filename, true);
         ArchSpec arch = Target::GetDefaultArchitecture ();
         Error error;
         const bool add_dependent_modules = true;
 
         PlatformSP platform_sp(m_opaque_sp->GetPlatformList().GetSelectedPlatform());
         error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, 
-                                                           file, 
+                                                           filename, 
                                                            arch, 
                                                            add_dependent_modules, 
                                                            platform_sp,

Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=166186&r1=166185&r2=166186&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Thu Oct 18 11:33:33 2012
@@ -521,11 +521,10 @@
         {
             // If there isn't a current target create one.
             TargetSP new_target_sp;
-            FileSpec emptyFileSpec;
             Error error;
             
             error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(), 
-                                                                              emptyFileSpec,
+                                                                              NULL,
                                                                               NULL, 
                                                                               false,
                                                                               NULL, // No platform options
@@ -1022,10 +1021,9 @@
         if (!target_sp)
         {
             // If there isn't a current target create one.
-            FileSpec emptyFileSpec;
             
             error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(), 
-                                                                              emptyFileSpec,
+                                                                              NULL,
                                                                               NULL, 
                                                                               false,
                                                                               NULL, // No platform options

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=166186&r1=166185&r2=166186&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Thu Oct 18 11:33:33 2012
@@ -221,17 +221,12 @@
         {
             const char *file_path = command.GetArgumentAtIndex(0);
             Timer scoped_timer(__PRETTY_FUNCTION__, "(lldb) target create '%s'", file_path);
-            FileSpec file_spec;
-            
-            if (file_path)
-                file_spec.SetFile (file_path, true);
-
             TargetSP target_sp;
             Debugger &debugger = m_interpreter.GetDebugger();
             const char *arch_cstr = m_arch_option.GetArchitectureName();
             const bool get_dependent_files = true;
             Error error (debugger.GetTargetList().CreateTarget (debugger,
-                                                                file_spec,
+                                                                file_path,
                                                                 arch_cstr,
                                                                 get_dependent_files,
                                                                 &m_platform_options,
@@ -1241,14 +1236,11 @@
 }
 
 static uint32_t
-DumpCompileUnitLineTable
-(
- CommandInterpreter &interpreter,
- Stream &strm,
- Module *module,
- const FileSpec &file_spec,
- bool load_addresses
- )
+DumpCompileUnitLineTable (CommandInterpreter &interpreter,
+                          Stream &strm,
+                          Module *module,
+                          const FileSpec &file_spec,
+                          bool load_addresses)
 {
     uint32_t num_matches = 0;
     if (module)

Modified: lldb/trunk/source/Host/common/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSpec.cpp?rev=166186&r1=166185&r2=166186&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/FileSpec.cpp (original)
+++ lldb/trunk/source/Host/common/FileSpec.cpp Thu Oct 18 11:33:33 2012
@@ -996,4 +996,28 @@
     return false;
 }
 
+bool
+FileSpec::IsRelativeToCurrentWorkingDirectory () const
+{
+    const char *directory = m_directory.GetCString();
+    if (directory && directory[0])
+    {
+        // If the path doesn't start with '/' or '~', return true
+        switch (directory[0])
+        {
+        case '/':
+        case '~':
+            return false;
+        default:
+            return true;
+        }
+    }
+    else if (m_filename)
+    {
+        // No directory, just a basename, return true
+        return true;
+    }
+    return false;
+}
+
 

Modified: lldb/trunk/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=166186&r1=166185&r2=166186&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Host.cpp (original)
+++ lldb/trunk/source/Host/common/Host.cpp Thu Oct 18 11:33:33 2012
@@ -1247,7 +1247,7 @@
         if (!arch.IsValid())
             arch = Host::GetArchitecture ();
         Error err = debugger.GetTargetList().CreateTarget(debugger, 
-                                                          FileSpec(), 
+                                                          NULL,
                                                           arch.GetTriple().getTriple().c_str(),
                                                           false, 
                                                           NULL, 

Modified: lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp?rev=166186&r1=166185&r2=166186&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp Thu Oct 18 11:33:33 2012
@@ -498,11 +498,10 @@
         if (target == NULL)
         {
             TargetSP new_target_sp;
-            FileSpec emptyFileSpec;
             ArchSpec emptyArchSpec;
 
             error = debugger.GetTargetList().CreateTarget (debugger,
-                                                           emptyFileSpec,
+                                                           NULL,
                                                            emptyArchSpec,
                                                            false,
                                                            m_remote_platform_sp,

Modified: lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp?rev=166186&r1=166185&r2=166186&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp Thu Oct 18 11:33:33 2012
@@ -408,11 +408,10 @@
         if (target == NULL)
         {
             TargetSP new_target_sp;
-            FileSpec emptyFileSpec;
             ArchSpec emptyArchSpec;
 
             error = debugger.GetTargetList().CreateTarget (debugger,
-                                                           emptyFileSpec,
+                                                           NULL,
                                                            emptyArchSpec,
                                                            false,
                                                            m_remote_platform_sp,

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=166186&r1=166185&r2=166186&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Thu Oct 18 11:33:33 2012
@@ -533,10 +533,9 @@
         if (target == NULL)
         {
             TargetSP new_target_sp;
-            FileSpec emptyFileSpec;
             
             error = debugger.GetTargetList().CreateTarget (debugger,
-                                                           emptyFileSpec,
+                                                           NULL,
                                                            NULL, 
                                                            false,
                                                            NULL,

Modified: lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp?rev=166186&r1=166185&r2=166186&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp Thu Oct 18 11:33:33 2012
@@ -368,10 +368,9 @@
                 if (target == NULL)
                 {
                     TargetSP new_target_sp;
-                    FileSpec emptyFileSpec;
                     
                     error = debugger.GetTargetList().CreateTarget (debugger,
-                                                                   emptyFileSpec,
+                                                                   NULL,
                                                                    NULL, 
                                                                    false,
                                                                    NULL,

Modified: lldb/trunk/source/Target/TargetList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/TargetList.cpp?rev=166186&r1=166185&r2=166186&view=diff
==============================================================================
--- lldb/trunk/source/Target/TargetList.cpp (original)
+++ lldb/trunk/source/Target/TargetList.cpp Thu Oct 18 11:33:33 2012
@@ -57,7 +57,7 @@
 
 Error
 TargetList::CreateTarget (Debugger &debugger,
-                          const FileSpec& file,
+                          const char *user_exe_path,
                           const char *triple_cstr,
                           bool get_dependent_files,
                           const OptionGroupPlatform *platform_options,
@@ -112,39 +112,25 @@
         platform_arch = arch;
 
     error = TargetList::CreateTarget (debugger,
-                                      file,
+                                      user_exe_path,
                                       platform_arch,
                                       get_dependent_files,
                                       platform_sp,
                                       target_sp);
-
-    if (target_sp)
-    {
-        if (file.GetDirectory())
-        {
-            FileSpec file_dir;
-            file_dir.GetDirectory() = file.GetDirectory();
-            target_sp->GetExecutableSearchPaths ().Append (file_dir);
-        }
-    }
     return error;
 }
 
 Error
-TargetList::CreateTarget
-(
-    Debugger &debugger,
-    const FileSpec& file,
-    const ArchSpec& specified_arch,
-    bool get_dependent_files,
-    PlatformSP &platform_sp,
-    TargetSP &target_sp
-)
+TargetList::CreateTarget (Debugger &debugger,
+                          const char *user_exe_path,
+                          const ArchSpec& specified_arch,
+                          bool get_dependent_files,
+                          PlatformSP &platform_sp,
+                          TargetSP &target_sp)
 {
     Timer scoped_timer (__PRETTY_FUNCTION__,
-                        "TargetList::CreateTarget (file = '%s/%s', arch = '%s')",
-                        file.GetDirectory().AsCString(),
-                        file.GetFilename().AsCString(),
+                        "TargetList::CreateTarget (file = '%s', arch = '%s')",
+                        user_exe_path,
                         specified_arch.GetArchitectureName());
     Error error;
 
@@ -168,12 +154,28 @@
 
     if (!arch.IsValid())
         arch = specified_arch;
-    
 
+    FileSpec file (user_exe_path, false);
     if (file)
     {
+        if (file.IsRelativeToCurrentWorkingDirectory())
+        {
+            // Ignore paths that start with "./" and "../"
+            if (!((user_exe_path[0] == '.' && user_exe_path[1] == '/') ||
+                  (user_exe_path[0] == '.' && user_exe_path[1] == '.' && user_exe_path[2] == '/')))
+            {
+                char cwd[PATH_MAX];
+                if (getcwd (cwd, sizeof(cwd)))
+                {
+                    std::string cwd_user_exe_path (cwd);
+                    cwd_user_exe_path += '/';
+                    cwd_user_exe_path += user_exe_path;
+                    file.SetFile(cwd_user_exe_path.c_str(), false);
+                }
+            }
+        }
+
         ModuleSP exe_module_sp;
-        FileSpec resolved_file(file);
         if (platform_sp)
         {
             FileSpecList executable_search_paths (Target::GetDefaultExecutableSearchPaths());
@@ -217,9 +219,22 @@
 
     if (target_sp)
     {
+        if (user_exe_path)
+        {
+            // Use exactly what the user typed as the first argument when we exec or posix_spawn
+            target_sp->SetArg0 (user_exe_path);
+        }
+        if (file.GetDirectory())
+        {
+            FileSpec file_dir;
+            file_dir.GetDirectory() = file.GetDirectory();
+            target_sp->GetExecutableSearchPaths ().Append (file_dir);
+        }
         Mutex::Locker locker(m_target_list_mutex);
         m_selected_target_idx = m_target_list.size();
         m_target_list.push_back(target_sp);
+        
+        
     }
 
     return error;





More information about the lldb-commits mailing list