[Lldb-commits] [PATCH] Add arbitrary command line flags to llgs/debugserver startup for local debugging
Todd Fiala
todd.fiala at gmail.com
Tue Jul 29 10:02:45 PDT 2014
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.
On Tue, Jul 29, 2014 at 9:59 AM, Todd Fiala <todd.fiala at gmail.com> wrote:
> This patch accepts environment variables of the form:
> LLDB_DEBUGSERVER_EXTRA_ARG_n
>
> where n starts with 1, and may continue nearly indefinitely (up through
> std::numeric_limits<uint32_t>::max()).
>
> 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.
>
> I am using this to add arbitrary startup commands to the llgs command line
> for turning on additional logging. For example:
>
> export LLDB_DEBUGSERVER_EXTRA_ARG_1="-c"
> export LLDB_DEBUGSERVER_EXTRA_ARG_2="log enable -f /tmp/llgs_packets.log
> gdb-remote packets"
> export LLDB_DEBUGSERVER_EXTRA_ARG_3="-c"
> export LLDB_DEBUGSERVER_EXTRA_ARG_4="log enable -f /tmp/llgs_process.log
> lldb process"
>
> Patch follows...
>
> diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
> b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
> index be90eb2..d67bbdb 100644
> --- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
> +++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
> @@ -817,7 +817,25 @@ GDBRemoteCommunication::StartDebugserverProcess
> (const char *hostname,
> ::snprintf (arg_cstr, sizeof(arg_cstr), "--log-flags=%s",
> env_debugserver_log_flags);
> debugserver_args.AppendArgument(arg_cstr);
> }
> -
> +
> + // Add additional args, starting with
> LLDB_DEBUGSERVER_EXTRA_ARG_1 until an env var doesn't come back.
> + uint32_t env_var_index = 1;
> + bool has_env_var;
> + do
> + {
> + char env_var_name[64];
> + snprintf (env_var_name, sizeof (env_var_name),
> "LLDB_DEBUGSERVER_EXTRA_ARG_%" PRIu32, env_var_index++);
> + const char *extra_arg = getenv(env_var_name);
> + has_env_var = extra_arg != nullptr;
> +
> + if (has_env_var)
> + {
> + debugserver_args.AppendArgument (extra_arg);
> + if (log)
> + log->Printf ("GDBRemoteCommunication::%s adding env
> var %s contents to stub command line (%s)", __FUNCTION__, env_var_name,
> extra_arg);
> + }
> + } while (has_env_var);
> +
> // Close STDIN, STDOUT and STDERR. We might need to redirect them
> // to "/dev/null" if we run into any problems.
> launch_info.AppendCloseFileAction (STDIN_FILENO);
>
>
> --
> -Todd
>
--
-Todd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20140729/c8c74534/attachment.html>
More information about the lldb-commits
mailing list