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 599893858C53 for ; Mon, 4 Apr 2022 22:20:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 599893858C53 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-578-YN9JUbsFPoG9_CP-eeNTkQ-1; Mon, 04 Apr 2022 18:20:14 -0400 X-MC-Unique: YN9JUbsFPoG9_CP-eeNTkQ-1 Received: by mail-wm1-f69.google.com with SMTP id n21-20020a05600c4f9500b0038e3b0aa367so316735wmq.1 for ; Mon, 04 Apr 2022 15:20:14 -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=v9zmDa4PjeeDvN8BR1fgIpmZUc+aP6TlHUOFTa+KbFo=; b=rerWVJgK8pFqTTX1cr7nkzruAmQl7/SNi5iRDzlB4kwUajXjr1Ge90xKnREZjVVm10 gDfTHkLoGEsqu/tG4fbQokhCqlsyQo+/zCFU6TZvOwNvAwPQ4kW3UfvsocjtYOdpJfkO RfHDCJHtHfRewgxhYhIkjTVMOptTJ8ujnXDXP6SWl7Du4FYB7I1mNAmVe6OPoyRMVGEw JB+VsT4fW8SEI4h6Zf5waou+DIMDNC5Tjosj/qGbo/REWQ68FLrI0/Ic6HzCBlBezJ1Y sKhd2qpOU0ETtTAPdu9PhAXLuxGYp3rPwUD3qTlX6A2NqIlanRCRbl8/TSHKuh7cuqY2 mVEg== X-Gm-Message-State: AOAM530iin/5HfOyCTI4y96UJUr1eGt4+zv6y4efbi3Y8Y/+c4Ljl85T rTX4Dcu1FBoyRUOzDgRJG9+9AnBK4VY6L3dGOSru0YpYJJWFTgAH+EdsXvHeYN2rBczr6KSKgkV eiVUhjqVuzZrDggO0/AYijBqG1Zruk2ZnPep24k2LcFR2mOOCZU+eEbxcd8IuHNmb+VPqzrN4Og == X-Received: by 2002:adf:e591:0:b0:206:1202:214 with SMTP id l17-20020adfe591000000b0020612020214mr289387wrm.342.1649110812292; Mon, 04 Apr 2022 15:20:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytUf3pW3myZeAR5HyOFameo80hbt8W2e/bQxS2Vt4Ihs3RVhi6+8Xumt6qqqQwO9heDw0T7A== X-Received: by 2002:adf:e591:0:b0:206:1202:214 with SMTP id l17-20020adfe591000000b0020612020214mr289370wrm.342.1649110812020; Mon, 04 Apr 2022 15:20:12 -0700 (PDT) Received: from localhost (host86-169-131-113.range86-169.btcentralplus.com. [86.169.131.113]) by smtp.gmail.com with ESMTPSA id p18-20020a1c5452000000b0038e70261309sm257697wmi.1.2022.04.04.15.20.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 15:20:11 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 6/6] gdb: unify two dis_asm_read_memory functions in disasm.c Date: Mon, 4 Apr 2022 23:19:59 +0100 Message-Id: <9dce7f0010c5f26e07193fb56dda01465e715d90.1649110564.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=-12.1 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, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Mon, 04 Apr 2022 22:20:17 -0000 After the recent restructuring of the disassembler code, GDB has ended up with two identical class static functions, both called dis_asm_read_memory, with identical implementations. My first thought was to move these out of their respective classes, and just make them global functions, then I'd only need a single copy. And maybe that's the right way to go. But I disliked that by doing that I loose the encapsulation of the method with the corresponding disassembler class. So, instead, I placed the static method into its own class, and had both the gdb_non_printing_memory_disassembler and gdb_disassembler classes inherit from this new class as an additional base-class. In terms of code generated, I don't think there's any significant difference with this approach, but I think this better reflects how the function is closely tied to the disassembler. There should be no user visible changes after this commit. --- gdb/disasm.c | 16 +++------------- gdb/disasm.h | 29 +++++++++++++++++------------ 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/gdb/disasm.c b/gdb/disasm.c index 1dfa141b10b..563cef8b845 100644 --- a/gdb/disasm.c +++ b/gdb/disasm.c @@ -132,9 +132,9 @@ line_has_code_p (htab_t table, struct symtab *symtab, int line) /* Wrapper of target_read_code. */ int -gdb_disassembler::dis_asm_read_memory (bfd_vma memaddr, gdb_byte *myaddr, - unsigned int len, - struct disassemble_info *info) +gdb_disassembler_memory_reader::dis_asm_read_memory + (bfd_vma memaddr, gdb_byte *myaddr, unsigned int len, + struct disassemble_info *info) { return target_read_code (memaddr, myaddr, len); } @@ -1014,16 +1014,6 @@ gdb_non_printing_disassembler::null_fprintf_styled_func return 0; } -/* See disasm.h. */ - -int -gdb_non_printing_memory_disassembler::dis_asm_read_memory - (bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, - struct disassemble_info *dinfo) -{ - return target_read_code (memaddr, myaddr, length); -} - /* A non-printing disassemble_info management class. The disassemble_info setup by this class will not print anything to the output stream (there is no output stream), and the instruction to be disassembled will be diff --git a/gdb/disasm.h b/gdb/disasm.h index 6c1d7673b01..5d1112cf0d6 100644 --- a/gdb/disasm.h +++ b/gdb/disasm.h @@ -165,31 +165,39 @@ struct gdb_non_printing_disassembler : public gdb_disassemble_info ATTRIBUTE_PRINTF(3,4); }; +/* This is a helper class, for use as an additional base-class, by some of + the disassembler classes below. This class just defines a static method + for reading from target memory, which can then be used by the various + disassembler sub-classes. */ + +struct gdb_disassembler_memory_reader +{ + /* Implements the read_memory_func disassemble_info callback. */ + static int dis_asm_read_memory (bfd_vma memaddr, gdb_byte *myaddr, + unsigned int len, + struct disassemble_info *info); +}; + /* A non-printing disassemble_info management class. The disassemble_info setup by this class will not print anything to the output stream (there is no output stream), and the instruction to be disassembled will be read from target memory. */ struct gdb_non_printing_memory_disassembler - : public gdb_non_printing_disassembler + : public gdb_non_printing_disassembler, + private gdb_disassembler_memory_reader { /* Constructor. GDBARCH is the architecture to disassemble for. */ gdb_non_printing_memory_disassembler (struct gdbarch *gdbarch) :gdb_non_printing_disassembler (gdbarch, dis_asm_read_memory) { /* Nothing. */ } - -private: - - /* Implements the read_memory_func disassemble_info callback. */ - static int dis_asm_read_memory (bfd_vma memaddr, gdb_byte *myaddr, - unsigned int len, - struct disassemble_info *info); }; /* A dissassembler class that provides 'print_insn', a method for disassembling a single instruction to the output stream. */ -struct gdb_disassembler : public gdb_printing_disassembler +struct gdb_disassembler : public gdb_printing_disassembler, + private gdb_disassembler_memory_reader { gdb_disassembler (struct gdbarch *gdbarch, struct ui_file *file) : gdb_disassembler (gdbarch, file, dis_asm_read_memory) @@ -239,9 +247,6 @@ struct gdb_disassembler : public gdb_printing_disassembler (currently just to addresses and symbols) as it goes. */ static bool use_ext_lang_colorization_p; - static int dis_asm_read_memory (bfd_vma memaddr, gdb_byte *myaddr, - unsigned int len, - struct disassemble_info *info); static void dis_asm_memory_error (int err, bfd_vma memaddr, struct disassemble_info *info); static void dis_asm_print_address (bfd_vma addr, -- 2.25.4