From patchwork Thu Nov 30 18:44:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 81054 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D3445384DEDE for ; Thu, 30 Nov 2023 19:26:08 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 DCCE2386193E for ; Thu, 30 Nov 2023 19:25:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DCCE2386193E 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 DCCE2386193E 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=1701372355; cv=none; b=Nf/zIcc4CCsyjadf5m0FROGUlB+9RmmWvR1gf1clBopnvnyeqLN0RXtgnmMcvqtiLlwH2ALzDf/BQX6Bm788vsX45Gf2vYEbyLxZy1sE1ED15lzJTNXg1+i+i+2nPq8xfpVXMxr1OdD3czDSQlxyTT6twtYwmjHD93uZ4aSTQ74= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701372355; c=relaxed/simple; bh=uQqkkrThMtHCvpRkhMg4uoLwtt1TaD7TaB9Wd6t6dSQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=RXIYC+WCk8x0mX8R1B3la+XHTQRvnyk79Am97XX+DK/RbWQ5F+hx6pdSnDQs3e+hKd/NvdV2fp5rlRMnbgyRidqYiUfqP5nmALS/ysxtiP9Jc0OPemu8o0wgF3tys+mD8lKSWq+x7/tUvt1xKYlPqFpo/f9j+fktIkRkcY4oIaE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701372353; 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=pELvjGzEbtx8j7dOBvD4Votsye8CaS65xEmlyW3F5A0=; b=TwyfSxZtFyvikp3D4RtBhylJMKq7jGYDV1pTLpCvdZLRBRaayTL9ynxd+HkDhtu01tiF/0 541sqp//XBGyNXKqskdTul+SIIYLCRwsanm+5dUwkZ00C2FsX16mMl0lRtslk7dMGdQ+Is YD9fSJFZdoD/YMENPzaa2vnv0TcRErc= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-593-SBYhXHk0PT6acQ194hnANA-1; Thu, 30 Nov 2023 14:25:51 -0500 X-MC-Unique: SBYhXHk0PT6acQ194hnANA-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-54554ea191bso961272a12.2 for ; Thu, 30 Nov 2023 11:25:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701372350; x=1701977150; 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=pELvjGzEbtx8j7dOBvD4Votsye8CaS65xEmlyW3F5A0=; b=eg/E1g9O4EJfYTGcT2e5cFsakqZSA8V3yBbR9UGOhii0xZrczbtDC+TBAv/swUFbjR biRauYMbLx1RcgmuzcGEyFNlzjD/9H8Wk/Bg/JAcPQ86NMs68MhVHA9FXhkgyWVF1UC4 81SnLydS3tltEhrzXKkfYRdiElPBSn8C+g6G5J5E7eUPud39NoXnUL5Vb00GRY41Qhis YIOx7i2rd8GDfbAH1HNz+ke888KUsDIM2FS/S4WEFwCundLPMcKFGtkrH4ECoSkmttfE LiBVQZkuVmLRt58CWmimi2BRLRbybOy3p52jEDQXcYEiqFWfNuzcF4X1y5KkvFnjgnnp VMPg== X-Gm-Message-State: AOJu0YzGkq4AafjcH6wLKibS11WTN3o9+JA5VFiq4xdtr3I6txEZ/cko 9jl/SjbUNZVzc2gNpydKDTLlo2LXWHCmquqi18YmFZcbp33xxP0MlD2f0vVoy68VVFsB+wKz9W8 FsunmIrssdVeFXHfwrpNT6oobk81wqpjBM8pn38Ir9P65QczVGdUWtBwpvG5cGboiLLFdv6gxoK ByjqXEzA== X-Received: by 2002:a50:8e4f:0:b0:547:b96:1172 with SMTP id 15-20020a508e4f000000b005470b961172mr15125edx.28.1701372350452; Thu, 30 Nov 2023 11:25:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IEFcc5yQlkrgF4kQQeZckPFpnwSK3Pi3iMXGpaLN8Fbt3LvygPVtwyWNZU8Yra0hnqSvGYZBA== X-Received: by 2002:a2e:9e47:0:b0:2c9:d863:2c27 with SMTP id g7-20020a2e9e47000000b002c9d8632c27mr5954ljk.80.1701369884774; Thu, 30 Nov 2023 10:44:44 -0800 (PST) Received: from localhost (92.40.185.184.threembb.co.uk. [92.40.185.184]) by smtp.gmail.com with ESMTPSA id gs20-20020a170906f19400b00a18374ade6bsm963988ejb.67.2023.11.30.10.44.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 10:44:44 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 1/3] gdb: fix GDB_DEBUG and GDBSERVER_DEBUG Makefile variables Date: Thu, 30 Nov 2023 18:44:16 +0000 Message-Id: <3f3ed68b36767340010dc080dbf3c35fbe6f2af6.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 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_H4, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org The gdb/testsuite/README file documents GDB_DEBUG and GDBSERVER_DEBUG flags, which can be passed to make in order to enable debugging within GDB or gdbserver respectively. However, when I do: make check-gdb GDB_DEBUG=infrun I don't see the corresponding debug feature within GDB being enabled. Nor does: make check-gdb GDBSERVER_DEBUG=debug \ RUNTESTFLAGS="--target_board=native-extended-gdbserver" Appear to enable gdbserver debugging. I tracked this down to the GDB_DEBUG and GDBSERVER_DEBUG flags being missing from the TARGET_FLAGS_TO_PASS variable in gdb/Makefile. This variable already contains lots of testing related flags, like RUNTESTFLAGS and TESTS, so I think it makes sense to add GDB_DEBUG and GDBSERVER_DEBUG here too. With this done, this debug feature is now working as expected. --- gdb/Makefile.in | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 3510577f090..0886c0e8495 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -993,7 +993,10 @@ TARGET_FLAGS_TO_PASS = \ "RUNTEST=$(RUNTEST)" \ "RUNTESTFLAGS=$(RUNTESTFLAGS)" \ "FORCE_PARALLEL=$(FORCE_PARALLEL)" \ - "TESTS=$(TESTS)" + "TESTS=$(TESTS)" \ + "GDB_DEBUG=$(GDB_DEBUG)" \ + "GDBSERVER_DEBUG=$(GDBSERVER_DEBUG)" \ + # All source files that go into linking GDB. From patchwork Thu Nov 30 18:44:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 81051 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 62722385B527 for ; Thu, 30 Nov 2023 19:17:19 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 D6F863858D37 for ; Thu, 30 Nov 2023 19:17:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D6F863858D37 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 D6F863858D37 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=1701371825; cv=none; b=F0ATJ5LcUg5XmHM8rS1jNBpBYCavIjvhN1b/Pyn2hUW5QU82NsYw+PQ5VpB8hbTB6wnO36oGqvhbvWG9c34hpa0gnMIv4s8oM7fD8wQPqTQKa1nJqc9rENORKS5pJsYgj8ApZh9gZGn9k/2Q4TgEvsRHC0zJtsE89WMiu5LqTyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701371825; c=relaxed/simple; bh=QgPHcbYOX/A2PBKNsijPoxfVRhHu1Vjjs1d5JrR09OA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=apQawpPTtH7eodDmlsdrEfnFI1hD8KDw2z5K+zRGStiidrauxOkSNMeLrAO8Q2XFpv28xL+G3/qJz9tELq6YFJ3unHRHRE5fOXaJmeUIVzUwIzui6n6EdODBr1KdmOIWUaskgnkhp+Hbe3cnBMUnQSJQ/oX73ASHGm0nQ9EQ4h4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701371823; 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=IFe+AJrWmSxm6MpiTr7Wm92picAdnYSo1xIVGm0XvQ0=; b=WGLE0W723YfKghBcEXf8gh9+0qiVIVfDtIcT/Koa6lfgDbMjAn86uaJvbA4DyoESYSz1Hv VyC5RKlab0OpOccwVStgKE3AUktqckgXYn3im/atiQO84xlBTapJvCwCZF4OOvFehw9JbZ r8t/pkOMyk4+rZDuJWrfPvuJ2htfc/E= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-614-JcqHPosJNM2OJig1Eve6nQ-1; Thu, 30 Nov 2023 14:17:02 -0500 X-MC-Unique: JcqHPosJNM2OJig1Eve6nQ-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-54af5527a17so1029688a12.3 for ; Thu, 30 Nov 2023 11:17:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701371820; x=1701976620; 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=IFe+AJrWmSxm6MpiTr7Wm92picAdnYSo1xIVGm0XvQ0=; b=X4NRJWmfuFHDp35aXxExj3/5bwPLSAiz3pH1onW41b+cyspbs5MBzA5R7HWaeZWVnR AlsWwjqudNWOHRTS/zUaiN1SveVJ72ix/pOZDASFgye0J1Lb/kHWLeccY5p1ewhqkKcZ 3B4j1FkfEC4Gg0zS9gOblaY3G8t31iMOMoJtRMs7PtqL6+mW9pRCzfaUAwwuw4fJif1A D2HhW//nJ+wprIzCe2AC0LmQ1p9MdP5NJ67yqX1an2hAyR10gRixmy6wEq44ROmoi2yW GJGshXwGq0NnHkS+RZ4x6eP0RlpigbmxAPpyQgSheRN8vpwN33DLlRxJqSSF47HGYPIk x/0w== X-Gm-Message-State: AOJu0Yw1SmkJN3yTeT+xhXqqg/zXw2QyIO33VIiOODgplOZzdTLFgV9N QtkzbZ8h+/srSQ7KK0o692Y8qKfUHAlicXC5F8EJLloYYaUqp2BI4kvdcJo2xeh2NSQ4ERAZ+rD mau++BIyKjIpYcySB8zsRSUzDna/s8gRjbmlQXmPqhVRWUDjGrvs68oXxh99pgV3LAh7KdmKUZ8 008Ne+Rg== X-Received: by 2002:a50:d090:0:b0:54b:c6bf:9d83 with SMTP id v16-20020a50d090000000b0054bc6bf9d83mr16608edd.35.1701371819823; Thu, 30 Nov 2023 11:16:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEG66LjP3kL8U0S8A/Hoom+9Lie+DouL0289fO6HqfVG/fRMitg4cQV4uzd7QkK94cMZzkVQ== X-Received: by 2002:a19:5e12:0:b0:50b:d764:803d with SMTP id s18-20020a195e12000000b0050bd764803dmr9318lfb.112.1701369887869; Thu, 30 Nov 2023 10:44:47 -0800 (PST) Received: from localhost (92.40.185.184.threembb.co.uk. [92.40.185.184]) by smtp.gmail.com with ESMTPSA id oz23-20020a170906cd1700b009ff77c2e1dasm958036ejb.167.2023.11.30.10.44.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 10:44:47 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Eli Zaretskii Subject: [PATCHv2 2/3] gdbserver: allow the --debug command line option to take a value Date: Thu, 30 Nov 2023 18:44:17 +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 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org 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 I need to add another command line flag. This commit changes --debug to take a list of components. The currently supported components are: all, threads, remote, and event-loop. The 'threads' component represents the debug we currently get from the --debug option. 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 split this up into some new, separate components. But that is not part of this commit, or even this series. The special component 'all' does what you'd expect: enables debug output from 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. I've removed the existing --remote-debug and --event-loop-debug command line options, these are equivalent to --debug=remote and --debug=event-loop respectively, or --debug=remote,event-loop to enable both components. 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. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 10 +++ gdb/doc/gdb.texinfo | 70 ++++++++++++++++---- gdbserver/server.cc | 158 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 216 insertions(+), 22 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 1073e38dfc6..94d1fd8ea8d 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -38,6 +38,16 @@ set remote thread-options-packet show remote thread-options-packet Set/show the use of the thread options packet. +* New features in the GDB remote stub, GDBserver + + ** The --remote-debug and --event-loop-debug command line options + have been removed. + + ** The --debug command line option now takes an optional comma + separated list of components to emit debug for. The currently + supported components are: all, threads, event-loop, and remote. + If no components are given then threads is assumed. + * 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 e4c00143fd1..9e46eba4ac9 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -23674,11 +23674,42 @@ @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. -@cindex @option{--remote-debug}, @code{gdbserver} option -The @option{--remote-debug} option tells @code{gdbserver} to display -remote protocol debug output. +The @option{--debug[=option1,option2,@dots{}]} option tells +@code{gdbserver} to display extra diagnostic information about the +debugging process. The options (@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 related 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{--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 @@ -50667,16 +50698,27 @@ target> gdbserver --multi @var{comm} @end smallexample -@item --debug -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 --debug@r{[}=option1,option2,@dots{}@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}. +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}. @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 f91f70d2aa9..3cb71a861d5 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -1457,6 +1457,124 @@ parse_debug_format_options (const char *arg, int is_monitor) return std::string (); } +/* A wrapper to enable, or disable a debug flag. These are debug flags + that control the debug output from gdbserver, that developers might + want, this is not something most end users will need. */ + +struct debug_opt +{ + /* NAME is the name of this debug option, this should be a simple string + containing no whitespace, starting with a letter from isalpha(), and + contain only isalnum() characters and '_' underscore and '-' hyphen. + + SETTER is a callback function used to set the debug variable. This + callback will be passed true to enable the debug setting, or false to + disable the debug setting. */ + debug_opt (const char *name, std::function setter) + : m_name (name), + m_setter (setter) + { + gdb_assert (isalpha (*name)); + } + + /* Called to enable or disable the debug setting. */ + void set (bool enable) const + { + m_setter (enable); + } + + /* Return the name of this debug option. */ + const char *name () const + { return m_name; } + +private: + /* The name of this debug option. */ + const char *m_name; + + /* The callback to update the debug setting. */ + std::function m_setter; +}; + +/* The set of all debug options that gdbserver supports. These are the + options that can be passed to the command line '--debug=...' flag, or to + the monitor command 'monitor set debug ...'. */ + +static std::vector all_debug_opt { + {"threads", [] (bool enable) + { + debug_threads = enable; + }}, + {"remote", [] (bool enable) + { + remote_debug = enable; + }}, + {"event-loop", [] (bool enable) + { + debug_event_loop = (enable ? debug_event_loop_kind::ALL + : debug_event_loop_kind::OFF); + }} +}; + +/* 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') + options = "+threads"; + + while (*options != '\0') + { + const char *end = strchrnul (options, ','); + + bool enable = *options != '-'; + if (*options == '-' || *options == '+') + ++options; + + std::string opt (options, end - options); + + if (opt.size () == 0) + error ("invalid empty debug option"); + + bool is_opt_all = opt == "all"; + + bool found = false; + for (const auto &debug_opt : all_debug_opt) + if (is_opt_all || opt == debug_opt.name ()) + { + debug_opt.set (enable); + found = true; + if (!is_opt_all) + break; + } + + if (!found) + error ("unknown debug option '%s'", opt.c_str ()); + + options = (*end == ',') ? end + 1 : end; + } +} + /* Handle monitor commands not handled by target-specific handlers. */ static void @@ -3583,15 +3701,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" @@ -3870,8 +3992,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 @@ -3884,10 +4030,6 @@ captured_main (int argc, char *argv[]) exit (1); } } - else if (strcmp (*next_arg, "--remote-debug") == 0) - remote_debug = true; - else if (strcmp (*next_arg, "--event-loop-debug") == 0) - debug_event_loop = debug_event_loop_kind::ALL; else if (startswith (*next_arg, "--debug-file=")) debug_set_output ((*next_arg) + sizeof ("--debug-file=") -1); else if (strcmp (*next_arg, "--disable-packet") == 0) From patchwork Thu Nov 30 18:44:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 81053 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 899FA38618ED for ; Thu, 30 Nov 2023 19:25:56 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org 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. Reviewed-By: Eli Zaretskii --- 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 ")) {