[Lldb-commits] [lldb] r322187 - Another attempt to fix FreeBsd build

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Jan 10 05:53:40 PST 2018


Author: labath
Date: Wed Jan 10 05:53:40 2018
New Revision: 322187

URL: http://llvm.org/viewvc/llvm-project?rev=322187&view=rev
Log:
Another attempt to fix FreeBsd build

the previous fix did not work because of different const qualifications
on the envp pointer.

This should resolve that (and remove a couple of const_casts in the
process).

Modified:
    lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
    lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
    lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp?rev=322187&r1=322186&r2=322187&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp Wed Jan 10 05:53:40 2018
@@ -407,7 +407,7 @@ Status ProcessFreeBSD::DoLaunch(Module *
 
   m_monitor = new ProcessMonitor(
       this, module, launch_info.GetArguments().GetConstArgumentVector(),
-      launch_info.GetEnvironment().getEnvp(), stdin_file_spec, stdout_file_spec,
+      launch_info.GetEnvironment(), stdin_file_spec, stdout_file_spec,
       stderr_file_spec, working_dir, launch_info, error);
 
   m_module = module;

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp?rev=322187&r1=322186&r2=322187&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp Wed Jan 10 05:53:40 2018
@@ -38,10 +38,6 @@
 #include "ProcessFreeBSD.h"
 #include "ProcessMonitor.h"
 
-extern "C" {
-extern char **environ;
-}
-
 using namespace lldb;
 using namespace lldb_private;
 
@@ -695,13 +691,14 @@ ProcessMonitor::OperationArgs::~Operatio
 
 ProcessMonitor::LaunchArgs::LaunchArgs(ProcessMonitor *monitor,
                                        lldb_private::Module *module,
-                                       char const **argv, char const **envp,
+                                       char const **argv, Environment env,
                                        const FileSpec &stdin_file_spec,
                                        const FileSpec &stdout_file_spec,
                                        const FileSpec &stderr_file_spec,
                                        const FileSpec &working_dir)
-    : OperationArgs(monitor), m_module(module), m_argv(argv), m_envp(envp),
-      m_stdin_file_spec(stdin_file_spec), m_stdout_file_spec(stdout_file_spec),
+    : OperationArgs(monitor), m_module(module), m_argv(argv),
+      m_env(std::move(env)), m_stdin_file_spec(stdin_file_spec),
+      m_stdout_file_spec(stdout_file_spec),
       m_stderr_file_spec(stderr_file_spec), m_working_dir(working_dir) {}
 
 ProcessMonitor::LaunchArgs::~LaunchArgs() {}
@@ -726,7 +723,7 @@ ProcessMonitor::AttachArgs::~AttachArgs(
 /// on the Operation class for more info as to why this is needed.
 ProcessMonitor::ProcessMonitor(
     ProcessFreeBSD *process, Module *module, const char *argv[],
-    const char *envp[], const FileSpec &stdin_file_spec,
+    Environment env, const FileSpec &stdin_file_spec,
     const FileSpec &stdout_file_spec, const FileSpec &stderr_file_spec,
     const FileSpec &working_dir,
     const lldb_private::ProcessLaunchInfo & /* launch_info */,
@@ -736,7 +733,7 @@ ProcessMonitor::ProcessMonitor(
   using namespace std::placeholders;
 
   std::unique_ptr<LaunchArgs> args(
-      new LaunchArgs(this, module, argv, envp, stdin_file_spec,
+      new LaunchArgs(this, module, argv, std::move(env), stdin_file_spec,
                      stdout_file_spec, stderr_file_spec, working_dir));
 
   sem_init(&m_operation_pending, 0, 0);
@@ -837,7 +834,6 @@ bool ProcessMonitor::Launch(LaunchArgs *
   ProcessMonitor *monitor = args->m_monitor;
   ProcessFreeBSD &process = monitor->GetProcess();
   const char **argv = args->m_argv;
-  const char **envp = args->m_envp;
   const FileSpec &stdin_file_spec = args->m_stdin_file_spec;
   const FileSpec &stdout_file_spec = args->m_stdout_file_spec;
   const FileSpec &stderr_file_spec = args->m_stderr_file_spec;
@@ -849,8 +845,8 @@ bool ProcessMonitor::Launch(LaunchArgs *
   ::pid_t pid;
 
   // Propagate the environment if one is not supplied.
-  if (envp == NULL || envp[0] == NULL)
-    envp = const_cast<const char **>(environ);
+  Environment::Envp envp =
+      (args->m_env.empty() ? Host::GetEnvironment() : args->m_env).getEnvp();
 
   if ((pid = terminal.Fork(err_str, err_len)) == -1) {
     args->m_error.SetErrorToGenericError();
@@ -908,8 +904,7 @@ bool ProcessMonitor::Launch(LaunchArgs *
       exit(eChdirFailed);
 
     // Execute.  We should never return.
-    execve(argv[0], const_cast<char *const *>(argv),
-           const_cast<char *const *>(envp));
+    execve(argv[0], const_cast<char *const *>(argv), envp);
     exit(eExecFailed);
   }
 

Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h?rev=322187&r1=322186&r2=322187&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h Wed Jan 10 05:53:40 2018
@@ -48,7 +48,7 @@ public:
   /// Launches an inferior process ready for debugging.  Forms the
   /// implementation of Process::DoLaunch.
   ProcessMonitor(ProcessFreeBSD *process, lldb_private::Module *module,
-                 char const *argv[], char const *envp[],
+                 char const *argv[], lldb_private::Environment env,
                  const lldb_private::FileSpec &stdin_file_spec,
                  const lldb_private::FileSpec &stdout_file_spec,
                  const lldb_private::FileSpec &stderr_file_spec,
@@ -219,7 +219,7 @@ private:
   /// launching a child process.
   struct LaunchArgs : OperationArgs {
     LaunchArgs(ProcessMonitor *monitor, lldb_private::Module *module,
-               char const **argv, char const **envp,
+               char const **argv, lldb_private::Environment env,
                const lldb_private::FileSpec &stdin_file_spec,
                const lldb_private::FileSpec &stdout_file_spec,
                const lldb_private::FileSpec &stderr_file_spec,
@@ -229,7 +229,7 @@ private:
 
     lldb_private::Module *m_module; // The executable image to launch.
     char const **m_argv;            // Process arguments.
-    char const **m_envp;            // Process environment.
+    lldb_private::Environment m_env;                // Process environment.
     const lldb_private::FileSpec m_stdin_file_spec; // Redirect stdin or empty.
     const lldb_private::FileSpec
         m_stdout_file_spec; // Redirect stdout or empty.




More information about the lldb-commits mailing list