From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id yPuxEVjyMmWQOTMAWB0awg (envelope-from ) for ; Fri, 20 Oct 2023 17:34:16 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HZnK8wMc; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 45B851E0C1; Fri, 20 Oct 2023 17:34:16 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 36DAD1E091 for ; Fri, 20 Oct 2023 17:34:14 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C756A385E00A for ; Fri, 20 Oct 2023 21:34:13 +0000 (GMT) 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 5C93A385F021 for ; Fri, 20 Oct 2023 21:33:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C93A385F021 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 5C93A385F021 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=1697837617; cv=none; b=PUW5PnIFJLRuDTcFNqbwmFhU2IRdM3hpGhFn/LHLprt3HFB9GnznJXplHcKKuZWXqr/0D61yUBstrE/zZVvAiYmur02oxkYsjntug/1ZA8oV/Du4U35bk+A2r/gJXswzeYb9CVNxnIvqEBAnMowssDr/Q7HgTtO7lLJefUbpxIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697837617; c=relaxed/simple; bh=Dcm7HuVlfVeEaIvaFNnfABY9lEjaDC8T/ZuL1gknfIk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=FojPN3dilNUTxycOlsZaqMyRH7/oTQqlKhOg/V+gsftUbtCon5ti3mJL/UvfHnofnr+H4PSvwurXuGOukA3U+ZLkueNflidz/ohe/X5G37+pA8AfRHLUQ6bo49l55iV+bPvape6DcQtuOyVH7YAfDeaP6zDDCAMCnNW+YM0ZwAo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697837615; 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=lp8l1qng7TTKQkfq3gFbW7tkAzaKAOIUtkWgyJbVQ8Y=; b=HZnK8wMcyZKtPhvtS7OHJCy1B4BRaYOkEAfWM3Y8dwxDzjlOzVXEIp3iO5vNrrSgCflRnm Zz45RaAKrZ9ECI3HsXz1i5wleIgZQjhTT5baxLFFBpVVJ17cyM7fj9tAipsP4w91QGNZsz Kjj5TmY580RsY2/8C15E5a1BZd30PGo= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-339-X8HZP13dMJ24ZbqV4G1yXw-1; Fri, 20 Oct 2023 17:33:18 -0400 X-MC-Unique: X8HZP13dMJ24ZbqV4G1yXw-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-41cb4d6744bso12957341cf.0 for ; Fri, 20 Oct 2023 14:33:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697837598; x=1698442398; 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=lp8l1qng7TTKQkfq3gFbW7tkAzaKAOIUtkWgyJbVQ8Y=; b=NyoWtGRUeXJ85g6lasN8Kr/mZ+st8BR6CnxglCC8lRApKTh1R7PvazJ97RMOV/jzrc F3QHytS3TPlQ5MR8Lwcqcs2Tu2pU2cwwe9qAQBthS6Raw+hZX3Xl5nwgCHBvg+Mz3RB0 77jb8QvS6V6MZ3uWMfbUWDKV3HmP8ro2O3+4Ju5+1UAmar+NArBfTtLDVKp/YCanL0so fpWZf40G98rQitviY8B2XTHFgdM1YzRCaaHzMTrRXm+j09Fihova3HCGjgkfAG78/nQc cINWT96Ayi0QowYYiKuXRG/dlPk0fPU6Y7MLnArHGxkbaAZOTVocJrYJuS4DvrUHK2d5 TxRg== X-Gm-Message-State: AOJu0YzsjtQeURbZOSBjo13YnOZ0z6RfRy+xyoTcrYoGyKNvBRXB2HoY GGVEyZWAAWDzHTMcycPJg677utx8MWzpHIoZYpNNVHPGue0ki258xeAO83nO1NeXuzbCc8W8bKn CAEIVHbF17oXgtaNyPDrHyM42XNU8gzDfx88C3BUKcbuMozIqjeAYxTAhZ/+4vZXVQaQhn1Dn2a xiKX85Gw== X-Received: by 2002:a05:622a:174b:b0:419:6391:6c07 with SMTP id l11-20020a05622a174b00b0041963916c07mr3355907qtk.28.1697837597929; Fri, 20 Oct 2023 14:33:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFmIrea4GTpHql5LYHovrzvLoRGQ6haKPnUkUPNhOX6/spLE7mvbaBvP6f8NGBFLXNU5HL2xg== X-Received: by 2002:a05:622a:174b:b0:419:6391:6c07 with SMTP id l11-20020a05622a174b00b0041963916c07mr3355889qtk.28.1697837597362; Fri, 20 Oct 2023 14:33:17 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id fv18-20020a05622a4a1200b004182037f655sm895776qtb.14.2023.10.20.14.33.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 14:33:17 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/3] gdb: error if /r and /b are used with disassemble command Date: Fri, 20 Oct 2023 22:33:09 +0100 Message-Id: <90a53b19bd317ff337041c495f338a2b0b5ad727.1697837538.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, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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+public-inbox=simark.ca@sourceware.org The disassembler gained a new /b flag in this commit: commit d4ce49b7ac077a9882d6a5e689e260300045ca88 Date: Tue Jun 21 20:23:35 2022 +0100 gdb: disassembler opcode display formatting The /b and /r flags result in the instruction opcodes displayed in different formats, so it's not possible to have both at the same time. Currently the /b flag overrides the /r flag. We have a similar situation with the /m and /s flags, but here, if the user tries to use both flags then they will get an error. I think the error is clearer, so in this commit I propose that we add an error if /r and /b are both used. Obviously this change breaks backwards compatibility. I don't have a compelling argument for why we should make the change beyond my feeling that it was a mistake not to add this error from the start, and that the new behaviour is better. --- gdb/NEWS | 7 ++++++ gdb/cli/cli-cmds.c | 4 +++ gdb/doc/gdb.texinfo | 20 ++++++++++----- gdb/testsuite/gdb.disasm/basics.c | 22 ++++++++++++++++ gdb/testsuite/gdb.disasm/basics.exp | 39 +++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 gdb/testsuite/gdb.disasm/basics.c create mode 100644 gdb/testsuite/gdb.disasm/basics.exp diff --git a/gdb/NEWS b/gdb/NEWS index 08d779010f0..4dd00d6fa01 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. +* Changed commands + +disassemble + Attempting to use both the 'r' and 'b' flags with the disassemble + command will now give an error. Previously the 'b' flag would + always override the 'r' flag. + * Python API ** New function gdb.notify_mi(NAME, DATA), that emits custom diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 8cadd637151..90989588bab 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -1644,6 +1644,10 @@ disassemble_command (const char *arg, int from_tty) == (DISASSEMBLY_SOURCE_DEPRECATED | DISASSEMBLY_SOURCE)) error (_("Cannot specify both /m and /s.")); + if ((flags & (DISASSEMBLY_RAW_INSN | DISASSEMBLY_RAW_BYTES)) + == (DISASSEMBLY_RAW_INSN | DISASSEMBLY_RAW_BYTES)) + error (_("Cannot specify both /r and /b.")); + if (! p || ! *p) { flags |= DISASSEMBLY_OMIT_FNAME; diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index db1a82ec838..2cd565ed5b4 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -10060,12 +10060,20 @@ instructions. It can also print mixed source+disassembly by specifying the @code{/m} or @code{/s} modifier and print the raw instructions in hex as well as in symbolic form by specifying the @code{/r} or @code{/b} -modifier. The default memory range is the function surrounding the -program counter of the selected frame. A single argument to this -command is a program counter value; @value{GDBN} dumps the function -surrounding this value. When two arguments are given, they should be -separated by a comma, possibly surrounded by whitespace. The arguments -specify a range of addresses to dump, in one of two forms: +modifier. + +Only one of @code{/m} and @code{/s} can be used, attempting to use +both flag will give an error. + +Only one of @code{/r} and @code{/b} can be used, attempting to use +both flag will give an error. + +The default memory range is the function surrounding the program +counter of the selected frame. A single argument to this command is a +program counter value; @value{GDBN} dumps the function surrounding +this value. When two arguments are given, they should be separated by +a comma, possibly surrounded by whitespace. The arguments specify a +range of addresses to dump, in one of two forms: @table @code @item @var{start},@var{end} diff --git a/gdb/testsuite/gdb.disasm/basics.c b/gdb/testsuite/gdb.disasm/basics.c new file mode 100644 index 00000000000..002b411fd37 --- /dev/null +++ b/gdb/testsuite/gdb.disasm/basics.c @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright (C) 2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.disasm/basics.exp b/gdb/testsuite/gdb.disasm/basics.exp new file mode 100644 index 00000000000..78df18d9e96 --- /dev/null +++ b/gdb/testsuite/gdb.disasm/basics.exp @@ -0,0 +1,39 @@ +# Copyright (C) 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Some basic tests of the disassemble command. Tests in this script +# should be architecture independent. + +standard_testfile + +if { [prepare_for_testing "failed to prepare" $testfile ${srcfile}] == -1 } { + return -1 +} + +if ![runto_main] { + return -1 +} + +# Check the '/s' and '/m' flags can't be used together. +gdb_test "disassemble /sm main" \ + "Cannot specify both /m and /s\\." +gdb_test "disassemble /ms main" \ + "Cannot specify both /m and /s\\." + +# Check the '/r' and '/b' flags can't be used together. +gdb_test "disassemble /rb main" \ + "Cannot specify both /r and /b\\." +gdb_test "disassemble /br main" \ + "Cannot specify both /r and /b\\." -- 2.25.4