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.133.124]) by sourceware.org (Postfix) with ESMTPS id 3B3493858C5E for ; Tue, 7 Nov 2023 18:03:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3B3493858C5E 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 3B3493858C5E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699380226; cv=none; b=LB4pU1MxAV1z3og7uaqfamPSGKY9tJetcv1Mm0eig7wqnubnoruRlOH0uB/HDNojzjH0br71tCYiMCcS2zU2zq3Xp55oorJkuNPWjk9Atf7TXyCmIuRjC2Mgdz8j1+BXeLx40clCG80aSk3tP9lNXUJbDFNfQ9/hzvtncn4xja4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699380226; c=relaxed/simple; bh=vNNW8As2adnEbSai34JEz1cMnYs1K3aJlBF5FcR2PzE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=gJIWQaZTfcoZ0Ux7CyPsl8/OLFhDIKMCk04vNw2FBmrvLMNgMlBYvyH02u/ISdNQ/yV20KCS+YTUYeiUa/02+OyT791ZYwRjM9jgm6VaH2Ney6zFKLEawWpsEDnCDvEcnqf8CQT/4ZRNcLQelEHMosazKTo5mCBg6WZsrhronAM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699380218; 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=rZ1xZ6w1KpUkPfxs2a/lpswXr7NIfluQw1CXaRYSpf8=; b=W2HHcJU9nCJzXVgG56nEXf5txyk2Yv6lXf4enT920h6Tj2yHaoI7KJXClNa8gHYhmP9cLy CJZBiel6fpf2mmF14V00Mh2612Q6/AmVBuIllwMHzmt9kjISCiSpdThISxCKRYG/abioa7 nT9hf64GwRdHDT0lEbsqmq0zk9s4Stc= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-26-rcRzEo_LPuGNPZt0nYW8cA-1; Tue, 07 Nov 2023 13:03:37 -0500 X-MC-Unique: rcRzEo_LPuGNPZt0nYW8cA-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-32fd35e1693so1292869f8f.1 for ; Tue, 07 Nov 2023 10:03:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699380216; x=1699985016; 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=rZ1xZ6w1KpUkPfxs2a/lpswXr7NIfluQw1CXaRYSpf8=; b=Xhbw2Wq88WC/JxBytOeHIMUay6gAnueqaalBPyYI5d/xZylO5AeXKz8Bu6QxYe1y6T 5aPUt8eToagM2EdJr3ILTBJz+Srh6bXM1xD/3ynexISPH9wNLZqJ1nUSutDgLsd46ZV7 XV6w9eBIe4SG6NkcBPwbtvA3XfP7kmcNALJSicmHH1G0rdwwiDNp2F0g3hsbCJLUe57j 6F7QUagjpq0ybaQ0+w8S1DwTz/dGBYivvBccpF03tn8p8i8gtnt2O6M21O/ntdmRqfS8 siz5XUTcVLtCL5o8/9ewjRFLI3+jdu+ALCMfj/7ppUBS9M3aMXjfdKQTF0usPWI53uU6 8bDw== X-Gm-Message-State: AOJu0YzMbRgUXfw57k+YcUMDLAHkPjd8pvOyLDmVLGOLgrTTxcPlIxJC lp2lfg0vdLsDaFHp6b6krNYVw8CzI91LVokJOctgd97v1N0PAWkeK8jqDuUAweQNc1vlBKInlwq C6sUjS8DqJS4Ugh4yotVRz0TBwOVeC23Fz8dOl12oq96BUgcAoNfBellcJBlWauIMuWbMGWVFIF ITHNsOjA== X-Received: by 2002:a05:600c:4e4c:b0:409:2825:6dd5 with SMTP id e12-20020a05600c4e4c00b0040928256dd5mr3047412wmq.13.1699380215810; Tue, 07 Nov 2023 10:03:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IHWYQI+qbA1C917yIMv2POymAFMbKHRHbKKeRAZAimoBDLlcEf0CJF3cJu/edwLzFu3rHM+rA== X-Received: by 2002:a05:600c:4e4c:b0:409:2825:6dd5 with SMTP id e12-20020a05600c4e4c00b0040928256dd5mr3047388wmq.13.1699380215269; Tue, 07 Nov 2023 10:03:35 -0800 (PST) Received: from localhost (105.226.159.143.dyn.plus.net. [143.159.226.105]) by smtp.gmail.com with ESMTPSA id f18-20020a5d58f2000000b0032f983f7306sm2960676wrd.78.2023.11.07.10.03.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 10:03:34 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 3/3] gdbserver: allow for general 'monitor set debug COMPONENT VALUE' use Date: Tue, 7 Nov 2023 18:03:23 +0000 Message-Id: <9257bb42888e44e8d7d63f562babdd404fd766b0.1699379375.git.aburgess@redhat.com> 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.6 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_H3,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: Building on the last commit, which added a general --debug=COMPONENT option to the gdbserver command line, this commit extends the monitor command to allow for general: (gdb) monitor set debug COMPONENT 0|1 style commands. Just like with the previous commit, the COMPONENT can be any one of threads, remote, event-loop, and correspond to the same set of global debug flags. While on the command line it is possible to do: --debug=remote,event-loop,threads the components have to be entered one at a time with the monitor command, and also, the 'all' component (see previous commit) is not supported. This makes the monitor command usage similar to how GDB's normal 'set debug ...' commands work. I've retained the existing monitor command for backwards compatibility, though I have removed them from the monitor help output. --- gdb/doc/gdb.texinfo | 16 ++++- gdb/testsuite/gdb.server/server-mon.exp | 6 ++ gdbserver/server.cc | 79 +++++++++++++++++++++++-- 3 files changed, 95 insertions(+), 6 deletions(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index d3f088f6505..87993ac924a 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -23804,11 +23804,23 @@ @itemx monitor set debug 1 Disable or enable general debugging messages. -@item monitor set remote-debug 0 -@itemx monitor set remote-debug 1 +@item monitor set debug threads 0 +@itemx monitor set debug threads 1 +Disable or enable specific debugging messages associated thread +handling in gdbserver. Currently this category also includes +additional debug output not specifically related to thread handling, +this could change in future releases of gdbserver. + +@item monitor set debug remote 0 +@itemx monitor set debug remote 1 Disable or enable specific debugging messages associated with the remote protocol (@pxref{Remote Protocol}). +@item monitor set debug event-loop 0 +@itemx monitor set debug event-loop 1 +Disable or enable specific debugging messages associated with +gdbserver's event-loop. + @item monitor set debug-file filename @itemx monitor set debug-file Send any debug output to the given file, or to stderr. diff --git a/gdb/testsuite/gdb.server/server-mon.exp b/gdb/testsuite/gdb.server/server-mon.exp index 728cc84a9e0..b2ad07254be 100644 --- a/gdb/testsuite/gdb.server/server-mon.exp +++ b/gdb/testsuite/gdb.server/server-mon.exp @@ -46,6 +46,12 @@ gdb_test "monitor" "Unknown monitor command.*Protocol error.*" gdb_test "monitor set debug 1" "Debug output enabled\\." gdb_test "monitor set debug 0" "Debug output disabled\\." +gdb_test "monitor set debug remote 1" "Debug output for 'remote' enabled\\." +gdb_test "monitor set debug remote 0" "Debug output for 'remote' disabled\\." +gdb_test "monitor set debug event-loop 1" "Debug output for 'event-loop' enabled\\." +gdb_test "monitor set debug event-loop 0" "Debug output for 'event-loop' disabled\\." +gdb_test "monitor set debug threads 1" "Debug output for 'threads' enabled\\." +gdb_test "monitor set debug threads 0" "Debug output for 'threads' disabled\\." gdb_test "monitor set remote-debug 1" "Protocol debug output enabled\\." gdb_test "monitor set remote-debug 0" "Protocol debug output disabled\\." gdb_test "monitor set debug-format all" \ diff --git a/gdbserver/server.cc b/gdbserver/server.cc index b954507dd6b..46625ce5556 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -1024,12 +1024,11 @@ monitor_show_help (void) monitor_output ("The following monitor commands are supported:\n"); monitor_output (" set debug <0|1>\n"); monitor_output (" Enable general debugging messages\n"); + monitor_output (" set debug COMPONENT <0|1>\n"); + monitor_output (" Enable debugging messages for COMPONENT, which is\n"); + monitor_output (" one of: threads, remote, event-loop.\n"); monitor_output (" set debug-hw-points <0|1>\n"); monitor_output (" Enable h/w breakpoint/watchpoint debugging messages\n"); - monitor_output (" set remote-debug <0|1>\n"); - monitor_output (" Enable remote protocol debugging messages\n"); - monitor_output (" set event-loop-debug <0|1>\n"); - monitor_output (" Enable event loop debugging messages\n"); monitor_output (" set debug-format option1[,option2,...]\n"); monitor_output (" Add additional information to debugging messages\n"); monitor_output (" Options: all, none, timestamp\n"); @@ -1395,6 +1394,66 @@ parse_debug_options (const char *options) } } +/* Called from the 'monitor' command handler, to handle general 'set debug' + commands with the format: 'set debug COMPONENT VALUE' where VALUE is + either '0' or '1', and COMPONENT is the name of a supported debug + component, see parse_debug_options for the supported components. MON + should point to the 'COMPONENT VALUE' part of the string, the 'set + debug' should already have been stripped off. + + Return a string containing an error message if something goes wrong, + this error can be returned as part of the monitor command output. If + everything goes correctly then the debug global will have been updated, + and an empty string is returned. */ + +static std::string +handle_general_monitor_debug (const char *mon) +{ + mon = skip_spaces (mon); + + if (*mon == '\0') + return "No debug component name found.\n"; + + /* Skip to next space. */ + const char *end = skip_to_space (mon); + std::string component (mon, end - mon); + if (component == "all") + return "Component 'all' is not supported.\n"; + if (component.find (',') != component.npos || component[0] == '-' + || component[0] == '+') + return "Invalid character found in debug component name.\n"; + + /* Skip any spaces. */ + const char *value = skip_spaces (end); + + /* Check next character is either '0' or '1'. */ + if (*value != '0' && *value != '1') + return "Invalid value for set debug.\n"; + bool enable = *value == '1'; + const char *after_value = skip_spaces (value + 1); + if (*after_value != '\0') + return "junk found at end of set debug command"; + + /* Build a string with either a '+' or '-' prefix and pass this to + parse_debug_options. */ + std::string action_str = std::string (enable ? "+" : "-") + component; + + try + { + parse_debug_options (action_str.c_str ()); + std::string msg = string_printf ("Debug output for '%s' %s.\n", + component.c_str (), + enable ? "enabled" : "disabled"); + monitor_output (msg.c_str ()); + } + catch (const gdb_exception_error &exception) + { + return string_printf ("Error: %s\n", exception.what ()); + } + + return {}; +} + /* Handle monitor commands not handled by target-specific handlers. */ static void @@ -1410,6 +1469,18 @@ handle_monitor_command (char *mon, char *own_buf) debug_threads = false; monitor_output ("Debug output disabled.\n"); } + else if (startswith (mon, "set debug ")) + { + std::string error_msg + = handle_general_monitor_debug (mon + sizeof ("set debug ") - 1); + + if (!error_msg.empty ()) + { + monitor_output (error_msg.c_str ()); + monitor_show_help (); + write_enn (own_buf); + } + } else if (strcmp (mon, "set debug-hw-points 1") == 0) { show_debug_regs = 1; -- 2.25.4