From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 9534C3858C53 for ; Tue, 7 Nov 2023 18:03:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9534C3858C53 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9534C3858C53 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699380227; cv=none; b=uS4TFaWUkvxZwh+vJ98fZ8PMetcvXfEfrlzZ5VZFQhSw7a03UIiPDs8V/Z2DpU/Dt8Y8J5o0rKl2AniIC5R7ikP6JY9/x/MyAA7MaW4KG9iZvZF1B/8C+YPVfnjrvMXnYZXLJkSkLHEzptCtlyoY8e3lVtlkXcucjfnRNIiWyOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699380227; c=relaxed/simple; bh=31p5w9Kx8+UdkUjTng6F8sTdjxqdZ/jNvOaNFKn2I/c=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=n1osLE7ZQCSpivFgM98PWrovQ8euTRuKuQfSTAbOeLw8lkSeqSE0LFQeoeNfTXaSdTpxvUKsI5GseE+5puGlsKQWQ3dJKb/sEtdHfjABjmVgcUhptvig+9PLdXs87zHZa5yONLFNzXtNAWwaFUKeMOQEJsYFka6LvwQ3HfWa6xM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699380217; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D3aPK0ik9rjtIebxiZno8SmZSUJwK7CizX+7+6L7zHo=; b=C93kaHxszoumEt9YBAUGEqn3BFY/Szkn7gcPFNz9wlMww2kUAjY4sC8CpZ1XmS8fDUU7z6 Lm+5TQ6HulLlc8VsBblyZmgomhUU4zs0PqDXrPD6onrTMh2BTFYyQQl00aflVy4LjBLicR yosCrecKol4wBg0BfkfJSWoI9fYh+z8= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-455-Mgxa0gCtOkqnSuGAXeNBUQ-1; Tue, 07 Nov 2023 13:03:35 -0500 X-MC-Unique: Mgxa0gCtOkqnSuGAXeNBUQ-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-32cef5f8af5so4248920f8f.1 for ; Tue, 07 Nov 2023 10:03:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699380214; x=1699985014; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D3aPK0ik9rjtIebxiZno8SmZSUJwK7CizX+7+6L7zHo=; b=ngLQ/CCBlW3D2P7CUV6r9RqYtu2tgha9zbzWlIKT3xLH68bnWHqM3RY2r6dC1ThnmM K7SD+M1G9nasuGeuQC2PHB43lG6ToXVCIah/NUaoT2Bj1YSSOLO1LiY2Xpu9UHC9BoJW MGrq4v2bqq1CFV8ujJiFoXZMJv7UnkmKQqzzCFi2gwVJf1Ih/P4iXVzshJNK3CE+qXsA I5k5ewtimppY3VzpyJkrD89RQlpW5oNvYzu1gT/X3g27ygP5xfZRCDO/48l4MeCoogch BEJjnINTserQ+1mD8aUKAS47h2yfBafgHk7DA1/6XYLdtc38FdO1/dW8JzCi1gklKZBa ph6g== X-Gm-Message-State: AOJu0YxCh6giGfkinn1I4CzwDldoQ+79oc7q/Uo8vaf7JdoyQIP/0v1a 2ZJ/4WiR9pajYfpJviYSeoPzFpg8A+qXSrh+C1ZT09I8RNV0gG4jvFuttHg2aadEEEQ5Nr0ur0Q iguPIAVfOZ1MOt2qrgW+f6mvIlukkZHLNBp9hK51b5poFowLV053b3PQMeyliyKqI4SRr9yDbUs 9R7gY4UQ== X-Received: by 2002:a05:6000:1788:b0:32f:7fa3:9fe2 with SMTP id e8-20020a056000178800b0032f7fa39fe2mr3768349wrg.25.1699380214349; Tue, 07 Nov 2023 10:03:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IER4I6u5xoMI8O0x5Ft3gUQksDMB1frPKLMymWrrwIlFOd80HRpQAxDVF7RaO45jDxzYxP9Sg== X-Received: by 2002:a05:6000:1788:b0:32f:7fa3:9fe2 with SMTP id e8-20020a056000178800b0032f7fa39fe2mr3768306wrg.25.1699380213812; Tue, 07 Nov 2023 10:03:33 -0800 (PST) Received: from localhost (105.226.159.143.dyn.plus.net. [143.159.226.105]) by smtp.gmail.com with ESMTPSA id a14-20020adfeece000000b0032fdcbfb093sm2967935wrp.81.2023.11.07.10.03.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 10:03:33 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/3] gdbserver: allow the --debug command line option to take a value Date: Tue, 7 Nov 2023 18:03:22 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Currently, gdbserver has the following command line options related to debugging output: --debug --remote-debug --event-loop-debug This doesn't scale well. If I want an extra debug component we need to add another command line flag. This commit changes --debug to take a list of components, I've then deprecated the --remote-debug and --event-loop-debug options by removing them from the --help output and man page, and by indicating that these options are deprecated in the GDB manual. The currently supported components are: all, threads, remote, and event-loop. The 'threads' component represents the debug we currently get from --debug. And if --debug is used without a component list then the threads component is assumed as the default. Currently the threads component actually includes a lot of output that is not really threads related. In the future I'd like to see this split up and additional components added. The special component 'all' does what you'd expect: enables debug output for all supported components. The component list is parsed left to write, and you can prefix a component with '-' to disable that component, so I can write: target> gdbserver --debug=all,-event-loop to get debug for all components except the event-loop component. In this commit I've only update the command line options, in the next commit I'll update the monitor commands to support a similar interface. --- gdb/NEWS | 7 ++++ gdb/doc/gdb.texinfo | 62 +++++++++++++++++++++++---- gdbserver/server.cc | 100 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 156 insertions(+), 13 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 6022def1037..13cf962dfcf 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -6,6 +6,13 @@ * GDB index now contains information about the main function. This speeds up startup when it is being used for some large binaries. +* New features in the GDB remote stub, GDBserver + + ** The `--debug` option now takes an (optional) list of components + to emit debug for. The currently supported components are all, + threads, event-loop, and remote. This allows the + --event-loop-debug and --remote-debug options to be deprecated. + * Python API ** New function gdb.notify_mi(NAME, DATA), that emits custom diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index db1a82ec838..d3f088f6505 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -23664,11 +23664,47 @@ @pxref{--multi Option in Types of Remote Connnections}. @cindex @option{--debug}, @code{gdbserver} option -The @option{--debug} option tells @code{gdbserver} to display extra -status information about the debugging process. +The @option{--debug[=option1,option2,...]} option tells +@code{gdbserver} to display extra diagnostic information about the +debugging process. The @var{option1}, @var{option2}, etc control for +which areas of @code{gdbserver} additional information will be +displayed, possible values are: + +@table @code +@item all +This enables all available diagnostic output. +@item threads +This enables diagnostic output related to threading. Currently other +general diagnostic output is included in this category, but this could +change in future releases of @code{gdbserver}. +@item event-loop +This enables event-loop specific diagnostic output. +@item remote +This enables diagnostic output relating to the transfer of remote +protocol packets too and from the debugger. +@end table + +@noindent +If no options are passed to @option{--debug} then this is treated as +equivalent to @option{--debug=threads}. This could change in future +releases of @code{gdbserver}. The options passed to @option{--debug} +are processed left to right, and individual options can be prefixed +with the @kbd{-} (minus) character to disable diagnostic output from +this area, so it is possible to use: + +@smallexample + target> gdbserver --debug=all,-event-loop +@end smallexample + +@noindent +In order to enable all diagnostic output except that for the +event-loop. + @cindex @option{--remote-debug}, @code{gdbserver} option -The @option{--remote-debug} option tells @code{gdbserver} to display -remote protocol debug output. +The @option{--remote-debug} option is deprecated, but retained for +backward compatibility. This is equivalent to +@option{--debug=remote}. + @cindex @option{--debug-file}, @code{gdbserver} option @cindex @code{gdbserver}, send all debug output to a single file The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to @@ -50531,16 +50567,24 @@ target> gdbserver --multi @var{comm} @end smallexample -@item --debug +@item --debug@r{[}=option1,option2,...@r{]} Instruct @code{gdbserver} to display extra status information about the debugging process. This option is intended for @code{gdbserver} development and for bug reports to the developers. -@item --remote-debug -Instruct @code{gdbserver} to display remote protocol debug output. -This option is intended for @code{gdbserver} development and for bug reports to -the developers. +Each @var{option} is the name of a component for which debugging +should be enabled. The list of possible options is @option{all}, +@option{threads}, @option{event-loop}, @option{remote}. The special +option @option{all} enables all components. The option list is +processed left to right, and an option can be prefixed with the +@kbd{-} character to disable output for that component, so you could write: + +@smallexample +target> gdbserver --debug=all,-event-loop +@end smallexample + +@noindent to turn on debug output for all components except @option{event-loop}. @item --debug-file=@var{filename} Instruct @code{gdbserver} to send any debug output to the given @var{filename}. diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 5451d43df18..b954507dd6b 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -1335,6 +1335,66 @@ parse_debug_format_options (const char *arg, int is_monitor) return std::string (); } +/* Parse the options to --debug=... + + OPTIONS is the string of debug components which should be enabled (or + disabled), and must not be nullptr. An empty OPTIONS string is valid, + in which case a default set of debug components will be enabled. + + An unknown, or otherwise invalid debug component will result in an + exception being thrown. + + OPTIONS can consist of multiple debug component names separated by a + comma. Debugging for each component will be turned on. The special + component 'all' can be used to enable debugging for all components. + + A component can also be prefixed with '-' to disable debugging of that + component, so a user might use: '--debug=all,-remote', to enable all + debugging, except for the remote (protocol) component. Components are + processed left to write in the OPTIONS list. */ + +static void +parse_debug_options (const char *options) +{ + gdb_assert (options != nullptr); + + /* Empty options means the "default" set. This exists mostly for + backwards compatibility with gdbserver's legacy behaviour. */ + if (*options == '\0') + { + debug_threads = true; + return; + } + + while (*options != '\0') + { + const char *end = strchrnul (options, ','); + + bool set_value = *options != '-'; + if (*options == '-' || *options == '+') + ++options; + + gdb::string_view opt (options, end - options); + + if (opt.size () == 0) + error ("invalid empty debug option"); + + bool is_opt_all = opt == "all"; + + if (is_opt_all || opt == "threads") + debug_threads = set_value; + else if (is_opt_all || opt == "event-loop") + debug_event_loop = (set_value ? debug_event_loop_kind::ALL + : debug_event_loop_kind::OFF); + else if (is_opt_all || opt == "remote") + remote_debug = set_value; + else + error ("unknown debug option '%s'", to_string (opt).c_str ()); + + options = (*end == ',') ? end + 1 : end; + } +} + /* Handle monitor commands not handled by target-specific handlers. */ static void @@ -3449,15 +3509,19 @@ gdbserver_usage (FILE *stream) "\n" "Debug options:\n" "\n" - " --debug Enable general debugging output.\n" + " --debug[=OPT1,OPT2,...]\n" + " Enable debugging output.\n" + " Options:\n" + " all, threads, event-loop, remote\n" + " With no options, 'threads' is assumed.\n" + " Prefix an option with '-' to disable\n" + " debugging of that component.\n" " --debug-format=OPT1[,OPT2,...]\n" " Specify extra content in debugging output.\n" " Options:\n" " all\n" " none\n" " timestamp\n" - " --remote-debug Enable remote protocol debugging output.\n" - " --event-loop-debug Enable event loop debugging output.\n" " --disable-packet=OPT1[,OPT2,...]\n" " Disable support for RSP packets or features.\n" " Options:\n" @@ -3736,8 +3800,32 @@ captured_main (int argc, char *argv[]) /* Consume the "--". */ *next_arg = NULL; } + else if (startswith (*next_arg, "--debug=")) + { + try + { + parse_debug_options ((*next_arg) + sizeof ("--debug=") - 1); + } + catch (const gdb_exception_error &exception) + { + fflush (stdout); + fprintf (stderr, "gdbserver: %s\n", exception.what ()); + exit (1); + } + } else if (strcmp (*next_arg, "--debug") == 0) - debug_threads = true; + { + try + { + parse_debug_options (""); + } + catch (const gdb_exception_error &exception) + { + fflush (stdout); + fprintf (stderr, "gdbserver: %s\n", exception.what ()); + exit (1); + } + } else if (startswith (*next_arg, "--debug-format=")) { std::string error_msg @@ -3750,8 +3838,12 @@ captured_main (int argc, char *argv[]) exit (1); } } + /* This option is retained for backwards compatibility. It is + considered deprecated, and might be removed one day. */ else if (strcmp (*next_arg, "--remote-debug") == 0) remote_debug = true; + /* This option is retained for backwards compatibility. It is + considered deprecated, and might be removed one day. */ else if (strcmp (*next_arg, "--event-loop-debug") == 0) debug_event_loop = debug_event_loop_kind::ALL; else if (startswith (*next_arg, "--debug-file=")) -- 2.25.4