<div dir="ltr">BTW - I'm using LLDB_DEBUGSERVER_* as the prefix because there are already some more-specialized environment variables for similar tasks that start with that prefix.  Over time I could see DEBUGSERVER just becoming synonymous with llgs/stub/debug monitor/nub.</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 29, 2014 at 9:59 AM, Todd Fiala <span dir="ltr"><<a href="mailto:todd.fiala@gmail.com" target="_blank">todd.fiala@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>This patch accepts environment variables of the form:</div><div>LLDB_DEBUGSERVER_EXTRA_ARG_n</div><div>
<br></div><div>where n starts with 1, and may continue nearly indefinitely (up through std::numeric_limits<uint32_t>::max()).</div>
<div><br></div><div>The code loops around, starting with 1, until it doesn't find one of the environment variables.  For each one it does find defined, it appends the environment variable's contents to the end of the debugserver/llgs startup command line issued when the stub is started for local debugging.</div>

<div><br></div><div>I am using this to add arbitrary startup commands to the llgs command line for turning on additional logging.  For example:</div><div><br></div><div>export LLDB_DEBUGSERVER_EXTRA_ARG_1="-c"</div>

<div>export LLDB_DEBUGSERVER_EXTRA_ARG_2="log enable -f /tmp/llgs_packets.log gdb-remote packets"</div><div><div>export LLDB_DEBUGSERVER_EXTRA_ARG_3="-c"</div><div>export LLDB_DEBUGSERVER_EXTRA_ARG_4="log enable -f /tmp/llgs_process.log lldb process"</div>

</div><div><br></div><div>Patch follows...</div><div><br></div><div><div>diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp</div><div>
index be90eb2..d67bbdb 100644</div>
<div>--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp</div><div>+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp</div><div>@@ -817,7 +817,25 @@ GDBRemoteCommunication::StartDebugserverProcess (const char *hostname,</div>

<div>             ::snprintf (arg_cstr, sizeof(arg_cstr), "--log-flags=%s", env_debugserver_log_flags);</div><div>             debugserver_args.AppendArgument(arg_cstr);</div><div>         }</div><div>-        </div>

<div>+</div><div>+        // Add additional args, starting with LLDB_DEBUGSERVER_EXTRA_ARG_1 until an env var doesn't come back.</div><div>+        uint32_t env_var_index = 1;</div><div>+        bool has_env_var;</div>

<div>+        do</div><div>+        {</div><div>+            char env_var_name[64];</div><div>+            snprintf (env_var_name, sizeof (env_var_name), "LLDB_DEBUGSERVER_EXTRA_ARG_%" PRIu32, env_var_index++);</div>

<div>+            const char *extra_arg = getenv(env_var_name);</div><div>+            has_env_var = extra_arg != nullptr;</div><div>+</div><div>+            if (has_env_var)</div><div>+            {</div><div>+                debugserver_args.AppendArgument (extra_arg);</div>

<div>+                if (log)</div><div>+                    log->Printf ("GDBRemoteCommunication::%s adding env var %s contents to stub command line (%s)", __FUNCTION__, env_var_name, extra_arg);</div><div>

+            }</div><div>+        } while (has_env_var);</div><div>+</div><div>         // Close STDIN, STDOUT and STDERR. We might need to redirect them</div><div>         // to "/dev/null" if we run into any problems.</div>

<div>         launch_info.AppendCloseFileAction (STDIN_FILENO);</div></div><span class="HOEnZb"><font color="#888888"><div><br></div><div><br></div><div>-- <br></div><div><div dir="ltr">-Todd</div>
</div></font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">-Todd</div>
</div>