[Lldb-commits] [PATCH] D31784: Correct environ parsing on NetBSD

Kamil Rytarowski via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 6 13:13:36 PDT 2017

krytarowski created this revision.
krytarowski added a project: LLDB.

This replaces old code in Host::GetEnvironment for NetBSD
with the version from Linux. This makes parsing environment
variables correctly. It also fixes programs that depend on the
variables like curses(3) applications.

Long term this function should be moved to Process Plugin,
as currently env variables are not available with remote

Other BSDs might want to catch up after this change.

Tested with NetBSD top(1).

Sponsored by <The NetBSD Foundation>




Index: source/Host/netbsd/Host.cpp
--- source/Host/netbsd/Host.cpp
+++ source/Host/netbsd/Host.cpp
@@ -52,15 +52,12 @@
 using namespace lldb_private;
 size_t Host::GetEnvironment(StringList &env) {
-  char *v;
-  char **var = environ;
-  for (; var != NULL && *var != NULL; ++var) {
-    v = ::strchr(*var, (int)'-');
-    if (v == NULL)
-      continue;
-    env.AppendString(v);
-  }
-  return env.GetSize();
+  char **host_env = environ;
+  char *env_entry;
+  size_t i;
+  for (i = 0; (env_entry = host_env[i]) != NULL; ++i)
+    env.AppendString(env_entry);
+  return i;
 static bool GetNetBSDProcessArgs(const ProcessInstanceInfoMatch *match_info_ptr,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31784.94421.patch
Type: text/x-patch
Size: 733 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20170406/4d4c2b30/attachment.bin>

More information about the lldb-commits mailing list