From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 65n5BzbyMmWQOTMAWB0awg (envelope-from ) for ; Fri, 20 Oct 2023 17:33:42 -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=LLnv1/jE; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 1291E1E091; Fri, 20 Oct 2023 17:33:42 -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 ECA8C1E091 for ; Fri, 20 Oct 2023 17:33:39 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3FF5F3861813 for ; Fri, 20 Oct 2023 21:33:39 +0000 (GMT) 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 7357B3858C00 for ; Fri, 20 Oct 2023 21:33:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7357B3858C00 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 7357B3858C00 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=1697837606; cv=none; b=gV7mwsP2uL3VlbCuCUdpakjVrm0wdrGNjkBUZ//R+eg+QFbGr5hMg4YTF3J9Iu62AQCiyp3pz6Mx+/5um53MWK8BShRIz4A+fZa3MgSqtf7RFRKjYGfqRkT2xU/PWp2ATNsBQ6wjS7FA8A/CKbideMmMEfS8LwxpxHoPBHOxaPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697837606; c=relaxed/simple; bh=kup6C77OO5uQ6SoNyQDc/55JNcl/mMOtvVqGup4sQR8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Gk8+H/b8dBUhYAAxmfBXW9AXFclRJoHAMXjwJKDEvZQxymZLuFKnJRgdZdMZeKX0Dm1rQbv0hSzW+ocOPOKswUr3BQ9Rh0jxURzQp5tJ27rz1bAziWKxWMMlAqgVVSh3uk91edrhZba9p4as1A5Mqo1yvJX28UiwpmiLWwtoccs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697837605; 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=Qldg4qee9aJfnxf2VWKvnvNQIIj8sVTB+2BFrIIXgRg=; b=LLnv1/jEI1k2PcMNnmFmiyjvIoJGAwX+cOi5xs7yyj8Q6F8wOWK12AXaQ3ZmORDZ9Lxxg7 buIwucjkaEpBNOTydYvYP8VrCrMPQk57FjEEmpF8Y1vRlQzwL4CxpWhDkA3upeK4K8cJyZ PBTY3Rbg9H5lEjt2NAOVaTLWLZuOLzs= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-296-wrQgFgtsNcS9GSwSzDfRTg-1; Fri, 20 Oct 2023 17:33:23 -0400 X-MC-Unique: wrQgFgtsNcS9GSwSzDfRTg-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-77892a3d8f3so147872585a.3 for ; Fri, 20 Oct 2023 14:33:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697837603; x=1698442403; 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=Qldg4qee9aJfnxf2VWKvnvNQIIj8sVTB+2BFrIIXgRg=; b=qXF+L6XI3fgCBrCjYoIMv4Qfa0FlSdwCMOLs0b2bt0150efa/CVqmmeJKQ0I42DP9e npwluC4p5OFmB59o4rd2j6jsvzsfTex10Za2uIz09xOv+GZV54EUNKXpPG4/jmgh0NfW gC7e5P6Licfitc6exAv2npotjxbcPHQgveK61TOjO//tY526pSoyBs/788hLpfWCQ6sP 1Pmod2AQNXHM7GasrRh6JE6cGlDLTrqXJNyNN2MyQwkmGxoeOAQHNLMW2IrqHGk3hw6G hzwNbt75+SHSNsFrLtEB4fqlOo4zK/mk79rP8rzS9k6RUo+3bzvVRmE319jgwvhe9Wqp 9s3g== X-Gm-Message-State: AOJu0YwDPpImusMggd3G+6uYR55ZVqu3lP/HYmHc4QAjpUGz2Ho25U9G WnofWbE6fKZsU/tB0GV6BNB96oXiWGxPciQ8T2102CY4m06KGyy0g0EysQxWQNERCur1X/OE/Hu XD9f9QLdrFmlZf62m4/FP4g2esPIi1/+kHtPy+iCnY8njJhrbJB06h7KF0M3Vof2Xbv5UNlW8HE VdzRgzvQ== X-Received: by 2002:a37:e316:0:b0:778:9886:71cc with SMTP id y22-20020a37e316000000b00778988671ccmr2941012qki.19.1697837602978; Fri, 20 Oct 2023 14:33:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEdTj1ummfNyX46pbY9Vx5/qjM8RunwJ5P6OboASWnQzkDtUOC7YC2UzJvruXwHkttT3G46EA== X-Received: by 2002:a37:e316:0:b0:778:9886:71cc with SMTP id y22-20020a37e316000000b00778988671ccmr2940995qki.19.1697837602548; Fri, 20 Oct 2023 14:33:22 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id o10-20020a05620a22ca00b0076cc4610d0asm910182qki.85.2023.10.20.14.33.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 14:33:22 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 3/3] gdb: add a custom command completer for disassemble command Date: Fri, 20 Oct 2023 22:33:11 +0100 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_H3, 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 Add a new command completer function for the disassemble command. There are two things that this completion function changes. First, after the previous commit, the new function calls skip_over_slash_fmt, which means that hitting tab after entering a /OPT flag now inserts a space ready to start typing the address to disassemble at: (gdb) disassemble /r (gdb) disassemble /r But also, we now get symbol completion after a /OPT option set, previously this would do nothing: (gdb) disassemble /r mai But now: (gdb) disassemble /r mai (gdb) disassemble /r main Which was my main motivation for working on this commit. However, I have made a second change in the completion function. Currently, the disassemble command calls the generic location_completer function, however, the disassemble docs say: Note that the 'disassemble' command's address arguments are specified using expressions in your programming language (*note Expressions: Expressions.), not location specs (*note Location Specifications::). So, for example, if you want to disassemble function 'bar' in file 'foo.c', you must type 'disassemble 'foo.c'::bar' and not 'disassemble foo.c:bar'. And indeed, if I try: (gdb) disassemble hello.c:main No symbol "hello" in current context. (gdb) disassemble hello.c::main No symbol "hello" in current context. (gdb) disassemble 'hello.c'::main Dump of assembler code for function main: ... snip ... But, if I do this: (gdb) disassemble hell (gdb) disassemble hello.c: which is a consequence of using the location_completer function. So in this commit, after calling skip_over_slash_fmt, I forward the bulk of the disassemble command completion to expression_completer. Now when I try this: (gdb) disassemble hell gives nothing, which I think is an improvement. There is one slight disappointment, if I do: (gdb) disassemble 'hell I still get nothing. I had hoped that this would expand to: 'hello.c':: but I guess this is a limitation of the current expression_completer implementation, however, I don't think this is a regression, the previous expansion was just wrong. Fixing expression_completer is out of scope for this commit. I've added some disassembler command completion tests, and also a test that disassembling using 'FILE'::FUNC syntax works, as I don't think that is tested anywhere. --- gdb/cli/cli-cmds.c | 16 +++++++++++++- gdb/testsuite/gdb.base/completion.exp | 30 +++++++++++++++++++++++++++ gdb/testsuite/gdb.disasm/basics.exp | 4 ++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 90989588bab..fd93e5b4ccb 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -1698,6 +1698,20 @@ disassemble_command (const char *arg, int from_tty) print_disassembly (gdbarch, name, low, high, block, flags); } +/* Command completion for the disassemble command. */ + +static void +disassemble_command_completer (struct cmd_list_element *ignore, + completion_tracker &tracker, + const char *text, const char * /* word */) +{ + if (skip_over_slash_fmt (tracker, &text)) + return; + + const char *word = advance_to_expression_complete_word_point (tracker, text); + expression_completer (ignore, tracker, text, word); +} + static void make_command (const char *arg, int from_tty) { @@ -2855,7 +2869,7 @@ Note that the address is interpreted as an expression, not as a location\n\ like in the \"break\" command.\n\ So, for example, if you want to disassemble function bar in file foo.c\n\ you must type \"disassemble 'foo.c'::bar\" and not \"disassemble foo.c:bar\".")); - set_cmd_completer (c, location_completer); + set_cmd_completer_handle_brkchars (c, disassemble_command_completer); c = add_com ("make", class_support, make_command, _("\ Run the ``make'' program using the rest of the line as arguments.")); diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp index 4686e6f8f34..15937810d2f 100644 --- a/gdb/testsuite/gdb.base/completion.exp +++ b/gdb/testsuite/gdb.base/completion.exp @@ -975,3 +975,33 @@ test_gdb_complete_unique "xxx_yyy_" "xxx_yyy_zzz" gdb_test_no_output "alias set aaa_bbb_ccc=set debug" gdb_test_no_output "maint deprecate set aaa_bbb_ccc" test_gdb_complete_unique "set aaa_bbb_" "set aaa_bbb_ccc" + +# Test command completion for the disassemble command. +test_gdb_complete_unique \ + "disassemble multi_line_if" \ + "disassemble multi_line_if_conditional" + +test_gdb_complete_multiple "disassemble " \ + "multi_li" "ne_" { + "multi_line_if_conditional" + "multi_line_while_conditional" + } + +foreach_with_prefix spc { " " "" } { + test_gdb_complete_none "disassemble${spc}/" + + foreach_with_prefix flg { "r" "b" "rb" "s" "m" "ms" } { + test_gdb_complete_unique "disassemble${spc}/${flg}" \ + "disassemble${spc}/${flg}" + + test_gdb_complete_unique \ + "disassemble${spc}/${flg} multi_line_if" \ + "disassemble${spc}/${flg} multi_line_if_conditional" + + test_gdb_complete_multiple "disassemble${spc}/${flg} " \ + "multi_li" "ne_" { + "multi_line_if_conditional" + "multi_line_while_conditional" + } + } +} diff --git a/gdb/testsuite/gdb.disasm/basics.exp b/gdb/testsuite/gdb.disasm/basics.exp index 78df18d9e96..3dfc16e04cf 100644 --- a/gdb/testsuite/gdb.disasm/basics.exp +++ b/gdb/testsuite/gdb.disasm/basics.exp @@ -37,3 +37,7 @@ gdb_test "disassemble /rb main" \ "Cannot specify both /r and /b\\." gdb_test "disassemble /br main" \ "Cannot specify both /r and /b\\." + +# Check disassembly using 'FILE'::FUNC syntax. +gdb_test "disassemble '$srcfile'::main" \ + "Dump of assembler code for function main:.*End of assembler dump\\." -- 2.25.4