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 45B2C3858C2C for ; Fri, 8 Jul 2022 10:20:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 45B2C3858C2C Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-510-l_50HQKxMD6NeixwxGyZGA-1; Fri, 08 Jul 2022 06:20:25 -0400 X-MC-Unique: l_50HQKxMD6NeixwxGyZGA-1 Received: by mail-wm1-f69.google.com with SMTP id f16-20020a1c6a10000000b003a2d92ab4d8so743166wmc.7 for ; Fri, 08 Jul 2022 03:20:25 -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:subject:in-reply-to:references:date :message-id:mime-version; bh=r0kV45t93x6mNqNa3izDSv5NC5CWFJ1xFwYGJo1Go80=; b=19YIjuXQmqQ6733+glnOzFVOXRO8o9X9h8xeGZVO5gpUmNZJfIfAXhAPczvYDXO3VT buxxkPP4l189c1orNYC2+Xx8GsZ9LsSrYndBKUF4dOnwg/hGV5ERIUT39N9lKRcZSHoQ fRC6IGhpK19MyVyI7ceBCtMfMMH8UuMcv5KlTMuY1cEsssLelg7V6/0QjdMAjvrfS9mY Mb/RzmS4s8a78q4m4rS6SdT9JQpbHQWn2BL0sUsVTr6EHu9w5irLcbk66GtAu+jsvPbD ciy10vrWcFF8mDOYEVrAI1q4TPHraThwL/Ri/0qfsaVrGNF7f8VEMjpEe8jLm7lraTVf Qo8A== X-Gm-Message-State: AJIora+qI/4w001t+NEbv+/gFsj/pMuOtpOOlADydGgUJ7cU22NZ2vSi znHpNduHpT7E41ruAXZad41+pVU/e9ypQcHqbf0YnRCwWLclpWc/IE9H7E0XH2nn0LRoSK0sctU litsC5du2UUBqd181Bw== X-Received: by 2002:a05:6000:2cb:b0:21d:7760:778c with SMTP id o11-20020a05600002cb00b0021d7760778cmr2623279wry.329.1657275624322; Fri, 08 Jul 2022 03:20:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sAyPLtUjXCRqI4J5LRd+H0xeMfZCA82tsISoMZ+k4TMr4F6SNKTb4MfcE4a3AT+Bt8EPdwKg== X-Received: by 2002:a05:6000:2cb:b0:21d:7760:778c with SMTP id o11-20020a05600002cb00b0021d7760778cmr2623260wry.329.1657275624083; Fri, 08 Jul 2022 03:20:24 -0700 (PDT) Received: from localhost (15.72.115.87.dyn.plus.net. [87.115.72.15]) by smtp.gmail.com with ESMTPSA id l13-20020a5d560d000000b0021d7fa77710sm5934517wrv.92.2022.07.08.03.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jul 2022 03:20:23 -0700 (PDT) From: Andrew Burgess To: Nick Clifton , binutils@sourceware.org Subject: Re: [PATCH] libopcodes/s390: add support for disassembler styling In-Reply-To: <5870a0d3-3d7a-a1b2-96c7-a387a895bb7a@redhat.com> References: <20220707102509.1267936-1-aburgess@redhat.com> <5870a0d3-3d7a-a1b2-96c7-a387a895bb7a@redhat.com> Date: Fri, 08 Jul 2022 11:20:22 +0100 Message-ID: <87v8s7ucrd.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jul 2022 10:20:29 -0000 Nick Clifton via Binutils writes: > Hi Andrew, > >> This commit adds disassembler style to the libopcodes s390 >> disassembler. > > Don't you also need to set "info->created_styled_output = true;" > in opcodes/disassemble.c:disassemble_init_for_target() ? Ahh, yes. Thank you. That flag isn't actually used by anyone yet, but it will be once the GDB patches land - at which point I would have spotted this oversight. Here's the updated patch. Thanks, Andrew --- commit 3496742a2558bf585edcd2c46bfb97989595dd35 Author: Andrew Burgess Date: Tue Jul 5 14:17:14 2022 +0100 libopcodes/s390: add support for disassembler styling This commit adds disassembler style to the libopcodes s390 disassembler. This conversion was pretty straight forward, I just converted the fprintf_func calls to fprintf_styled_func calls and added an appropriate style. For testing the new styling I just assembled then disassembled the source files in gas/testsuite/gas/s390 and manually checked that the styling looked reasonable. If the user does not request styled output from objdump, then there should be no change in the disassembler output after this commit. diff --git a/opcodes/disassemble.c b/opcodes/disassemble.c index 9c0dacaf391..bd37f042b31 100644 --- a/opcodes/disassemble.c +++ b/opcodes/disassemble.c @@ -721,6 +721,7 @@ disassemble_init_for_target (struct disassemble_info * info) #ifdef ARCH_s390 case bfd_arch_s390: disassemble_init_s390 (info); + info->created_styled_output = true; break; #endif #ifdef ARCH_nds32 diff --git a/opcodes/s390-dis.c b/opcodes/s390-dis.c index 03715ed5f0b..df44efb95ab 100644 --- a/opcodes/s390-dis.c +++ b/opcodes/s390-dis.c @@ -186,7 +186,8 @@ s390_print_insn_with_opcode (bfd_vma memaddr, char separator; /* Mnemonic. */ - info->fprintf_func (info->stream, "%s", opcode->name); + info->fprintf_styled_func (info->stream, dis_style_mnemonic, + "%s", opcode->name); /* Operands. */ separator = '\t'; @@ -222,24 +223,60 @@ s390_print_insn_with_opcode (bfd_vma memaddr, } if (flags & S390_OPERAND_GPR) - info->fprintf_func (info->stream, "%c%%r%u", separator, val.u); + { + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_register, + "%%r%u", val.u); + } else if (flags & S390_OPERAND_FPR) - info->fprintf_func (info->stream, "%c%%f%u", separator, val.u); + { + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_register, + "%%f%u", val.u); + } else if (flags & S390_OPERAND_VR) - info->fprintf_func (info->stream, "%c%%v%i", separator, val.u); + { + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_register, + "%%v%i", val.u); + } else if (flags & S390_OPERAND_AR) - info->fprintf_func (info->stream, "%c%%a%u", separator, val.u); + { + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_register, + "%%a%u", val.u); + } else if (flags & S390_OPERAND_CR) - info->fprintf_func (info->stream, "%c%%c%u", separator, val.u); + { + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_register, + "%%c%u", val.u); + } else if (flags & S390_OPERAND_PCREL) { - info->fprintf_func (info->stream, "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); info->print_address_func (memaddr + val.i + val.i, info); } else if (flags & S390_OPERAND_SIGNED) - info->fprintf_func (info->stream, "%c%i", separator, val.i); + { + enum disassembler_style style; + + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + style = ((flags & S390_OPERAND_DISP) + ? dis_style_address_offset : dis_style_immediate); + info->fprintf_styled_func (info->stream, style, "%i", val.i); + } else { + enum disassembler_style style; + if (flags & S390_OPERAND_OR1) val.u &= ~1; if (flags & S390_OPERAND_OR2) @@ -251,14 +288,18 @@ s390_print_insn_with_opcode (bfd_vma memaddr, && val.u == 0 && opindex[1] == 0) break; - info->fprintf_func (info->stream, "%c%u", separator, val.u); + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + style = ((flags & S390_OPERAND_DISP) + ? dis_style_address_offset : dis_style_immediate); + info->fprintf_styled_func (info->stream, style, "%u", val.u); } if (flags & S390_OPERAND_DISP) separator = '('; else if (flags & S390_OPERAND_BASE) { - info->fprintf_func (info->stream, ")"); + info->fprintf_styled_func (info->stream, dis_style_text, ")"); separator = ','; } else @@ -361,19 +402,33 @@ print_insn_s390 (bfd_vma memaddr, struct disassemble_info *info) value = (value << 8) + (unsigned int) buffer[1]; value = (value << 8) + (unsigned int) buffer[2]; value = (value << 8) + (unsigned int) buffer[3]; - info->fprintf_func (info->stream, ".long\t0x%08x", value); + info->fprintf_styled_func (info->stream, dis_style_assembler_directive, + ".long"); + info->fprintf_styled_func (info->stream, dis_style_text, + "\t"); + info->fprintf_styled_func (info->stream, dis_style_immediate, + "0x%08x", value); return 4; case 2: value = (unsigned int) buffer[0]; value = (value << 8) + (unsigned int) buffer[1]; - info->fprintf_func (info->stream, ".short\t0x%04x", value); + info->fprintf_styled_func (info->stream, dis_style_assembler_directive, + ".short"); + info->fprintf_styled_func (info->stream, dis_style_text, + "\t"); + info->fprintf_styled_func (info->stream, dis_style_immediate, + "0x%04x", value); return 2; default: - info->fprintf_func (info->stream, ".byte\t0x%02x", - (unsigned int) buffer[0]); + info->fprintf_styled_func (info->stream, dis_style_assembler_directive, + ".byte"); + info->fprintf_styled_func (info->stream, dis_style_text, + "\t"); + info->fprintf_styled_func (info->stream, dis_style_immediate, + "0x%02x", (unsigned int) buffer[0]); for (i = 1; i < bytes_to_dump; i++) - info->fprintf_func (info->stream, ",0x%02x", - (unsigned int) buffer[i]); + info->fprintf_styled_func (info->stream, dis_style_immediate, + "0x%02x", (unsigned int) buffer[i]); return bytes_to_dump; } return 0;