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 4B54A385829F for ; Thu, 30 Nov 2023 19:25:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B54A385829F 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 4B54A385829F 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=1701372341; cv=none; b=cnhhfIL1Tt3zTQ373XUyYmO/Ki/pkDRFUgKlYSNyByoKYiYwn5n9ge25O12Gqp4Wx5n3/eyv73sMSXOQvfC7rQEwoz7O5keMDWXfVr5jghu/XGCEMAijzl0bKZUwKOSCit7ekDkndtUw7AnHARLFJMw16/myniu3n5Z8GeKVcqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701372341; c=relaxed/simple; bh=LmsqKn1UVCcH5cmrWTbI3zGAJ/EwV13ZWvVThHCJQvo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=mzTuSr/gfAF0Tsq0JrEVPei+zIqbqBm05UeXjATiRN3THAqzj+z5vSlkUUwUYQ7b5VmdLvk8ynZVU8u4i2WAJtgpHo62b7T2rf1PEvATl2yPn638YsjD8/ukfCrcFeZz3OUjDjOuAx1ecp14NfaJNj4smSh4vmfj0FC5YhncEWM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701372339; 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=EmPOC+JO3U3Qe4mDHVFSEjp3HLFJc/1IDqiwrJGM2UQ=; b=FJ8UePnr1/hFSfxhERFUHqyXwrEcuDsOMVHKwtRjnBn2andCi+XGazfGW2AmTgnPd2+xfP 19tvUbuVZAw4CnImJQfXJyWwCwLMnrVGwGn1srZ7bM0zUPAbXFQ5lGD+EQjoZl8nnpGi3F xpoV/4r1FIgz/vw9q1yXd9rrtnegwi4= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-156-V3rfD4utM7i9CD2T4fPGrQ-1; Thu, 30 Nov 2023 14:25:37 -0500 X-MC-Unique: V3rfD4utM7i9CD2T4fPGrQ-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-9fffa4c4f28so124942666b.3 for ; Thu, 30 Nov 2023 11:25:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701372335; x=1701977135; 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=EmPOC+JO3U3Qe4mDHVFSEjp3HLFJc/1IDqiwrJGM2UQ=; b=sF7mUwPrdY4EjeoKqbVxVqZz0MWogKGsRWW5qLMyBEmVWUqNPIi2EIe8cG6vkAxm5D eJVfiqhigoVkmbn1figr51vJjEzTpIstHGAnUbytP8OBEp7P8odAftRszubUf42u2q86 w9Kb/+PmHwIcLZNvQtb4Ms3oRY1EnJPVtYaXmoAmfXfdxm1bGPJcGOGV/SjY2tFBlxNB wCa8RkVUnKDMjuoJH/5IiJVW1299sZ4Em04rHKN0F2phVwTXz31fKJX0h+ikbxoAmGg8 6aTxEYpbtQCFjZc1iSr/gb839qM4ABw37EUIB4sFizVrHIJ3I1mTM4Cfk4vZSchLFrPW RG9A== X-Gm-Message-State: AOJu0YzmGpsUMI5x8kd0SEsIGZb38Kw53NSqmyclXteGr3PmRMVRJt9J GBb4vU+GareKs0W8bLUxnzblavfSTVWOKyZXWMBsMvtHwVfyvdk78kXXFn+4U8rt/TzO2GCv/47 Jw7Faa/jNnE6I5VcLIJQyiC3CmpNbqBWejBva7nULTnapcbw3qIxKXj/+B7XwUIl0fyfENoG5Wy +bU7GOZA== X-Received: by 2002:a17:906:6b82:b0:a18:e27a:6f05 with SMTP id l2-20020a1709066b8200b00a18e27a6f05mr32721ejr.22.1701372334999; Thu, 30 Nov 2023 11:25:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGIG9/QYq3zb3gXi1MKoNuYGGrwQgEqQiAMzRX3/vHDcXeIimttWUxgFDjGkIBwyhRPKjkS0w== X-Received: by 2002:a17:907:6d05:b0:a18:bd8b:c850 with SMTP id sa5-20020a1709076d0500b00a18bd8bc850mr2994ejc.2.1701369894531; Thu, 30 Nov 2023 10:44:54 -0800 (PST) Received: from localhost (92.40.185.184.threembb.co.uk. [92.40.185.184]) by smtp.gmail.com with ESMTPSA id lj16-20020a170906f9d000b00a0c9024828asm966003ejb.68.2023.11.30.10.44.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 10:44:54 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 3/3] gdbserver: allow for general 'monitor set debug COMPONENT VALUE' use Date: Thu, 30 Nov 2023 18:44:18 +0000 Message-Id: <6b7bbefbcee3e19a87c46f7bc13e453ec10509a4.1701369189.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=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_ABUSEAT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SBL_CSS,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 updates the monitor command to allow for general: (gdb) monitor set debug COMPONENT off|on style commands. Just like with the previous commit, the COMPONENT can be any one of all, 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. I guess there's no reason why we couldn't allow component grouping within the monitor command, but (to me) what I have here seemed more in the spirit of GDB's existing 'set debug ...' commands. If people want it then we can always add component grouping later. Notice in the above that I use 'off' and 'on' instead of '0' and '1', which is what the 'monitor set debug' command used to use. The 0/1 can still be used, but I now advertise off/on in all the docs and help text, again, this feels more inline with GDB's existing boolean settings. I have removed the two existing monitor commands: monitor set remote-debug 0|1 monitor set event-loop-debug 0|1 These are replaced by: monitor set debug remote off|on monitor set debug event-loop off|on respectively. --- gdb/NEWS | 8 ++ gdb/doc/gdb.texinfo | 30 +++-- gdb/testsuite/gdb.server/server-mon.exp | 25 +++- gdbserver/server.cc | 159 +++++++++++++++++++----- 4 files changed, 179 insertions(+), 43 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 94d1fd8ea8d..c8166f08218 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -48,6 +48,14 @@ show remote thread-options-packet supported components are: all, threads, event-loop, and remote. If no components are given then threads is assumed. + ** The 'monitor set remote-debug' and 'monitor set event-loop-debug' + command have been removed. + + ** The 'monitor set debug 0|1' command has been extended to take a + component name, e.g.: 'monitor set debug COMPONENT off|on'. + Possible component names are: all, threads, event-loop, and + remote. + * 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 9e46eba4ac9..20621a0f7ee 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -23805,15 +23805,31 @@ @item monitor help List the available monitor commands. -@item monitor set debug 0 -@itemx monitor set debug 1 -Disable or enable general debugging messages. - -@item monitor set remote-debug 0 -@itemx monitor set remote-debug 1 -Disable or enable specific debugging messages associated with the remote +@item monitor set debug off +Disable all internal logging from gdbserver. + +@item monitor set debug on +Enable some general logging from within gdbserver. Currently this is +equivalent to @kbd{monitor set debug threads on}, but this might +change in future releases of gdbserver. + +@item monitor set debug threads off +@itemx monitor set debug threads on +Disable or enable specific logging messages associated thread handling +in gdbserver. Currently this category also includes additional output +not specifically related to thread handling, this could change in +future releases of gdbserver. + +@item monitor set debug remote off +@itemx monitor set debug remote on +Disable or enable specific logging messages associated with the remote protocol (@pxref{Remote Protocol}). +@item monitor set debug event-loop off +@itemx monitor set debug event-loop on +Disable or enable specific logging 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..65f5961ca8a 100644 --- a/gdb/testsuite/gdb.server/server-mon.exp +++ b/gdb/testsuite/gdb.server/server-mon.exp @@ -44,10 +44,27 @@ gdb_test_multiple "monitor help" "monitor help" { 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 remote-debug 1" "Protocol debug output enabled\\." -gdb_test "monitor set remote-debug 0" "Protocol debug output disabled\\." +gdb_test "monitor set debug 1" "General debug output enabled\\." +gdb_test "monitor set debug 0" "All debug output disabled\\." +gdb_test "monitor set debug on" "General debug output enabled\\." +gdb_test "monitor set debug off" "All 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 remote on" "Debug output for 'remote' enabled\\." +gdb_test "monitor set debug remote off" "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 event-loop on" "Debug output for 'event-loop' enabled\\." +gdb_test "monitor set debug event-loop off" "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 debug threads on" "Debug output for 'threads' enabled\\." +gdb_test "monitor set debug threads off" "Debug output for 'threads' disabled\\." +gdb_test "monitor set debug all 1" "Debug output for 'all' enabled\\." +gdb_test "monitor set debug all 0" "Debug output for 'all' disabled\\." +gdb_test "monitor set debug all on" "Debug output for 'all' enabled\\." +gdb_test "monitor set debug all off" "Debug output for 'all' disabled\\." + gdb_test "monitor set debug-format all" \ "All extra debug format options enabled\\." gdb_test "monitor set debug-format none" \ diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 3cb71a861d5..c4dcb83a79b 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -1143,14 +1143,15 @@ static void monitor_show_help (void) { monitor_output ("The following monitor commands are supported:\n"); - monitor_output (" set debug <0|1>\n"); + monitor_output (" set debug on\n"); monitor_output (" Enable general debugging messages\n"); + monitor_output (" set debug off\n"); + monitor_output (" Disable all debugging messages\n"); + monitor_output (" set debug COMPONENT \n"); + monitor_output (" Enable debugging messages for COMPONENT, which is\n"); + monitor_output (" one of: all, 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"); @@ -1575,50 +1576,144 @@ parse_debug_options (const char *options) } } -/* Handle monitor commands not handled by target-specific handlers. */ +/* Called from the 'monitor' command handler, to handle general 'set debug' + monitor commands with one of the formats: -static void -handle_monitor_command (char *mon, char *own_buf) + set debug COMPONENT VALUE + set debug VALUE + + In both of these command formats VALUE can be 'on', 'off', '1', or '0' + with 1/0 being equivalent to on/off respectively. + + In the no-COMPONENT version of the command, if VALUE is 'on' (or '1') + then the component 'threads' is assumed, this is for backward + compatibility, but maybe in the future we might find a better "default" + set of debug flags to enable. + + In the no-COMPONENT version of the command, if VALUE is 'off' (or '0') + then all debugging is turned off. + + Otherwise, COMPONENT must be one of the known debug components, and that + component is either enabled or disabled as appropriate. + + The string MON contains either 'COMPONENT VALUE' or just the 'VALUE' for + the second command format, the 'set debug ' has been stripped off + already. + + 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) { - if (strcmp (mon, "set debug 1") == 0) + mon = skip_spaces (mon); + + if (*mon == '\0') + return "No debug component name found.\n"; + + /* Find the first word within MON. This is either the component name, + or the value if no component has been given. */ + const char *end = skip_to_space (mon); + std::string component (mon, end - mon); + if (component.find (',') != component.npos || component[0] == '-' + || component[0] == '+') + return "Invalid character found in debug component name.\n"; + + /* In ACTION_STR we create a string that will be passed to the + parse_debug_options string. This will be either '+COMPONENT' or + '-COMPONENT' depending on whether we want to enable or disable + COMPONENT. */ + std::string action_str; + + /* If parse_debug_options succeeds, then MSG will be returned to the user + as the output of the monitor command. */ + std::string msg; + + /* Check for 'set debug off', this disables all debug output. */ + if (component == "0" || component == "off") { - debug_threads = true; - monitor_output ("Debug output enabled.\n"); + action_str = "-all"; + msg = "All debug output disabled.\n"; } - else if (strcmp (mon, "set debug 0") == 0) + /* Check for 'set debug on', this disables a general set of debug. */ + else if (component == "1" || component == "on") { - debug_threads = false; - monitor_output ("Debug output disabled.\n"); + action_str = "+threads"; + msg = "General debug output enabled.\n"; } - else if (strcmp (mon, "set debug-hw-points 1") == 0) + /* Otherwise we should have 'set debug COMPONENT VALUE'. Extract the two + parts and validate. */ + else { - show_debug_regs = 1; - monitor_output ("H/W point debugging output enabled.\n"); + /* Figure out the value the user passed. */ + const char *value_start = skip_spaces (end); + if (*value_start == '\0') + return "Missing value for 'set debug' command.\n"; + + const char *after_value = skip_to_space (value_start); + if (*skip_spaces (after_value) != '\0') + return "junk found at end of 'set debug' command value"; + + std::string value (value_start, after_value - value_start); + + /* Check VALUE to see if we are enabling, or disabling. */ + bool enable; + if (value == "0" || value == "off") + enable = false; + else if (value == "1" || value == "on") + enable = true; + else + string_printf ("Invalid value '%s' for set debug.\n", value.c_str ()); + + action_str = std::string (enable ? "+" : "-") + component; + msg = string_printf ("Debug output for '%s' %s.\n", component.c_str (), + enable ? "enabled" : "disabled"); } - else if (strcmp (mon, "set debug-hw-points 0") == 0) + + gdb_assert (!msg.empty ()); + gdb_assert (!action_str.empty ()); + + try { - show_debug_regs = 0; - monitor_output ("H/W point debugging output disabled.\n"); + parse_debug_options (action_str.c_str ()); + monitor_output (msg.c_str ()); } - else if (strcmp (mon, "set remote-debug 1") == 0) + catch (const gdb_exception_error &exception) { - remote_debug = true; - monitor_output ("Protocol debug output enabled.\n"); + return string_printf ("Error: %s\n", exception.what ()); } - else if (strcmp (mon, "set remote-debug 0") == 0) + + return {}; +} + +/* Handle monitor commands not handled by target-specific handlers. */ + +static void +handle_monitor_command (char *mon, char *own_buf) +{ + if (startswith (mon, "set debug ")) { - remote_debug = false; - monitor_output ("Protocol debug output disabled.\n"); + 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 event-loop-debug 1") == 0) + else if (strcmp (mon, "set debug-hw-points 1") == 0) { - debug_event_loop = debug_event_loop_kind::ALL; - monitor_output ("Event loop debug output enabled.\n"); + show_debug_regs = 1; + monitor_output ("H/W point debugging output enabled.\n"); } - else if (strcmp (mon, "set event-loop-debug 0") == 0) + else if (strcmp (mon, "set debug-hw-points 0") == 0) { - debug_event_loop = debug_event_loop_kind::OFF; - monitor_output ("Event loop debug output disabled.\n"); + show_debug_regs = 0; + monitor_output ("H/W point debugging output disabled.\n"); } else if (startswith (mon, "set debug-format ")) { -- 2.25.4