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.129.124]) by sourceware.org (Postfix) with ESMTPS id B2BC73856266 for ; Thu, 23 Jun 2022 16:05:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B2BC73856266 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-487--bL_AYRyNeyU7x5hjYFnvQ-1; Thu, 23 Jun 2022 12:05:28 -0400 X-MC-Unique: -bL_AYRyNeyU7x5hjYFnvQ-1 Received: by mail-wr1-f71.google.com with SMTP id l9-20020adfa389000000b0021b8b489336so3446103wrb.13 for ; Thu, 23 Jun 2022 09:05:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8WPCi5hoIOfwshgy2bmEe5AMmxNCAosyL67SLILpAd8=; b=P8GJ9dfxCsVpLYaJn/JDIJELvFcbFoqp4PiQuP46jWTd+GGc/VTdwrAGhgEnddm/5u 8Vk7cePp/OIPpBBYXgDgy8ZNGSrCrGk3Jz/fC+gOxxatpOGeDthMga8lv3JB4JZYm5RZ PENQ2ZA0jj52/qWGl14wCyeMx4wCtGgZKj6n1uF210b1WKoXm65BalK2xOA5/feTEbhA bVc5okLjwBzhdpLRsR3+VlsiVEJP8Xi+6Yk/uqpZhrOLgYgXmv5B/JAah90XpBxD0Z9/ pomuh34KEXxWbYACbPUpx2WoiR1nttxGtmIyzZ92Bc8ioWcEZLB1bnw4v1b3cCARxPvk hk+g== X-Gm-Message-State: AJIora/Ti+z13EAhHn3Ly7hp/ox2qtGSge4dLrXE1F4WDF6451yRqg3h O0GfF3rO3BdI3ImIRV/IvomGW2P2ltRrtXMLG+Z3LqtzXN9UrkIGClhUa7XOOjpmc1tdRZaMIQx HrWv6WCIsqitx/p7qzw50M/Q9v4BXZd1EN0grOyvoCUeUVIGDGd3SJf5lQ6EY8/IY5ln8NqnXvQ == X-Received: by 2002:a1c:7c18:0:b0:3a0:39b1:3403 with SMTP id x24-20020a1c7c18000000b003a039b13403mr48655wmc.84.1656000326688; Thu, 23 Jun 2022 09:05:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uZL1Wt4Gk8DqM4KIj71mhRDuEZxuSQD0FB+M76j3nicdriQHwWHJa+51V6aoBhn/0bryYNCQ== X-Received: by 2002:a1c:7c18:0:b0:3a0:39b1:3403 with SMTP id x24-20020a1c7c18000000b003a039b13403mr48627wmc.84.1656000326356; Thu, 23 Jun 2022 09:05:26 -0700 (PDT) Received: from localhost ([195.213.152.79]) by smtp.gmail.com with ESMTPSA id c17-20020a05600c0ad100b003973ea7e725sm5291058wmr.0.2022.06.23.09.05.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jun 2022 09:05:25 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/9] gdb/testsuite: new test for -data-disassemble opcodes format Date: Thu, 23 Jun 2022 17:05:09 +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=-13.0 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_LOW, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2022 16:05:32 -0000 Add another test for the output of MI command -data-disassemble. The new check validates the format of the 'opcodes' field, specifically, this test checks that the field contains a series of bytes, separated by a single space. We also check that the bytes are in the correct order, that is, the first byte is from the lowest address, and subsequent bytes are from increasing addresses. The motivation for this test (besides more tests being generally good) is that I plan to make changes to how opcode bytes are displayed in the disassembler output, and I want to ensure that I don't break any existing MI behaviour. There should be no user visible changes to GDB after this commit. --- gdb/testsuite/gdb.mi/mi-disassemble.exp | 83 +++++++++++++++++++++++++ gdb/testsuite/lib/mi-support.exp | 27 ++++++++ 2 files changed, 110 insertions(+) diff --git a/gdb/testsuite/gdb.mi/mi-disassemble.exp b/gdb/testsuite/gdb.mi/mi-disassemble.exp index 2d3e8e216b1..b7c52472c84 100644 --- a/gdb/testsuite/gdb.mi/mi-disassemble.exp +++ b/gdb/testsuite/gdb.mi/mi-disassemble.exp @@ -239,6 +239,88 @@ proc test_disassembly_bogus_args {} { } +# Check the format of the opcode bytes. +proc test_disassembly_opcode_format {} { + # First, we need to find a multi-byte instruction that we can + # then disassemble using the MI command. + set longest_insn_bytes "" + set longest_insn_addr "" + gdb_test_multiple "disassemble /r main" "" { + -re "^disassemble /r main\r\n" { + exp_continue + } + + -re "^&\"disassemble /r main.n\"\r\n" { + exp_continue + } + + -re "^~\"Dump of assembler code for function \[^\r\n\]+\r\n" { + exp_continue + } + + -re "^~\".. ($::hex) <\[^>\]+>:\\\\t(\[^\\\\\]+)\\\\t\[^\r\n\]+\r\n" { + set addr $expect_out(1,string) + set bytes $expect_out(2,string) + if { [string length $bytes] > [string length $longest_insn_bytes] } { + set longest_insn_addr $addr + set longest_insn_bytes $bytes + } + exp_continue + } + + -re "^~\"End of assembler dump\[^\r\n\]+\r\n" { + exp_continue + } + + -re "^\\^done\r\n$::mi_gdb_prompt$" { + gdb_assert { ![string equal $longest_insn_bytes ""] } \ + "found the bytes string for a longest instruction" + gdb_assert { ![string equal $longest_insn_addr ""] } \ + "found the address for a longest instruction" + } + } + + verbose -log "Longest instruction at ${longest_insn_addr} with bytes '${longest_insn_bytes}'" + + # Check that the instruction bytes that we found above consists of + # a series of individual bytes separated by a whitespace. Also, + # we check that the bytes reported match what can be found in the + # inferior memory. + set split_bytes [split $longest_insn_bytes " "] + set is_bad false + set addr $longest_insn_addr + set idx 0 + foreach b $split_bytes { + if { [string length $b] != 2 } { + set is_bad true + } + + # Load the actual byte value from memory, and check it matches + # the opcode byte reported in the disassembler output. + set addr 0x[format %x [expr $longest_insn_addr + $idx]] + set actual [format %02x [mi_get_valueof "/x" "*((unsigned char *) $addr)" "XX"]] + gdb_assert [string equal $actual "$b"] \ + "byte at $addr matches" + + incr idx + } + gdb_assert { !$is_bad } "check length of each byte" + set check_bytes [join $split_bytes " "] + gdb_assert { [string equal $check_bytes $longest_insn_bytes] } \ + "bytes are separated by a single space" + + # Figure out an end address at which to stop the disassembly. + set byte_count [llength $split_bytes] + set end_addr 0x[format %x [expr $longest_insn_addr + $byte_count]] + set start_addr $longest_insn_addr + + verbose -log "Instruction is ${byte_count} bytes, end address ${end_addr}" + + mi_gdb_test "321-data-disassemble -s $start_addr -e $end_addr -- 2" \ + "321\\^done,asm_insns=\\\[\{address=\"$start_addr\",func-name=\"main\",offset=\"$::decimal\",opcodes=\"$longest_insn_bytes\",inst=\".*\"\}\]" \ + "data-disassemble checking the opcodes bytes format" +} + mi_clean_restart $binfile mi_runto_main test_disassembly_only @@ -248,6 +330,7 @@ test_disassembly_mixed_with_opcodes test_disassembly_bogus_args test_disassembly_lines_limit test_disassembly_mixed_lines_limit +test_disassembly_opcode_format mi_gdb_exit return 0 diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp index e578a7e6f9b..2af12461ec5 100644 --- a/gdb/testsuite/lib/mi-support.exp +++ b/gdb/testsuite/lib/mi-support.exp @@ -2783,3 +2783,30 @@ proc mi_is_target_remote {} { return [gdb_is_target_remote_prompt "$mi_gdb_prompt"] } + +# Retrieve the value of EXP in the inferior, represented in format +# specified in FMT (using "printFMT"). DEFAULT is used as fallback if +# print fails. TEST is the test message to use. It can be omitted, +# in which case a test message is built from EXP. +# +# This is an MI version of gdb_valueof. + +proc mi_get_valueof { fmt exp default {test ""} } { + global mi_gdb_prompt + + if {$test == "" } { + set test "get valueof \"${exp}\"" + } + + set val ${default} + gdb_test_multiple "print${fmt} ${exp}" "$test" { + -re "~\"\\$\[0-9\]* = (\[^\r\n\]*)\\\\n\"\r\n\\^done\r\n$mi_gdb_prompt$" { + set val $expect_out(1,string) + pass "$test" + } + timeout { + fail "$test (timeout)" + } + } + return ${val} +} -- 2.25.4