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 85FC83858C83 for ; Mon, 7 Feb 2022 10:00:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 85FC83858C83 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-635-JMBH8UX-PKKGQW283rxp9w-1; Mon, 07 Feb 2022 05:00:29 -0500 X-MC-Unique: JMBH8UX-PKKGQW283rxp9w-1 Received: by mail-wm1-f71.google.com with SMTP id f26-20020a7bc8da000000b0037bd7f39dbbso62652wml.3 for ; Mon, 07 Feb 2022 02:00:28 -0800 (PST) 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:in-reply-to:references:date :message-id:mime-version; bh=UgjtDYV0qLBwXkTas9XLf1IIH+E9WikDSwpmnegE5Lg=; b=CCb0vConaTGBTq/Wp4bjbenecO0gROM7o0v3yrUOEg2IRZC32ua2SD4Fm8UkibZotB uMFPBCgymmHS8v082y7ZVx86TTF0pCpdfBp0VSCQHaY486mT52LfAq3IDkbpTplxFNzl wgmKiP0ihOYMU/FBE1vVFIfsXEe9e/3jv0DlcBwtbVxIgtjSJ06IL8pmRbw86avkilBU bsi36lx1OijTI6BowBGIsYzziE2QOX2fODa/SParzK8WzVfYXzb3aiwaI3iarqHh7VsE fJ0gzlqgEcC6a4usBG6frv2oYnxzRaf6dD0YIpOZw19L++3pfhp/YFOgv2VUmXLcXRS7 eX+Q== X-Gm-Message-State: AOAM530Zl/e6uA/itpk1eKFvNOFEfs8kPukIyiCTRVmDO8icpBgZTLTo lmnwCh9uOqxrb3Tq7MSzdt040k3EDkwRni8UFLWFWZOQF5084ptKedOdA3bsYHdOJAFjUI2Dl9k nwKNGVaCdWj32s0hKn/CUh2IonPJiIQjvc62uyV/TZbuMaoMirxBcDnz9xt9hnyXHeOVXnczxXA == X-Received: by 2002:adf:f90c:: with SMTP id b12mr9108846wrr.97.1644228027679; Mon, 07 Feb 2022 02:00:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJzNQ2EiaaSX+gMcB9VAveFDySs/rKOshbZQYGkFKB1C5ZYmUJ50W02IUhuVZuwm8E6c5NlX8w== X-Received: by 2002:adf:f90c:: with SMTP id b12mr9108826wrr.97.1644228027399; Mon, 07 Feb 2022 02:00:27 -0800 (PST) Received: from localhost (host86-134-151-224.range86-134.btcentralplus.com. [86.134.151.224]) by smtp.gmail.com with ESMTPSA id b4sm2124487wrw.100.2022.02.07.02.00.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 02:00:27 -0800 (PST) From: Andrew Burgess To: Joel Brobecker via Gdb-patches , Andrew Burgess via Gdb-patches Cc: Joel Brobecker Subject: Re: [PATCH] gdb/disasm: combine the no printing disassembler setup code In-Reply-To: References: <20220204231539.3524354-1-aburgess@redhat.com> Date: Mon, 07 Feb 2022 10:00:25 +0000 Message-ID: <87bkzj9eti.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_LOW, 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, 07 Feb 2022 10:00:36 -0000 Joel Brobecker via Gdb-patches writes: > Hi Andrew, > >> We have three places in gdb where we initialise a disassembler that >> will not print anything (used for figuring out the length of >> instructions, or collecting other information from the disassembler). >> >> Each of these places has its own stub function to act as a print like >> callback, the stub function is identical in each case, and just does >> nothing. >> >> In this commit I create a new function to initialise a disassembler >> that doesn't print anything, and have all three locations use this new >> function. There's now only one non-printing stub function. >> >> There should be no user visible changes after this commit. > > I took a look at the patch, and it looks good to me. Thanks, pushed. Andrew > >> --- >> gdb/arc-tdep.c | 10 ++-------- >> gdb/disasm.c | 17 ++++++++++++----- >> gdb/disasm.h | 6 ++++++ >> gdb/s12z-tdep.c | 10 +++------- >> 4 files changed, 23 insertions(+), 20 deletions(-) >> >> diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c >> index 90ec323d05e..297f83b8650 100644 >> --- a/gdb/arc-tdep.c >> +++ b/gdb/arc-tdep.c >> @@ -1306,19 +1306,13 @@ arc_is_in_prologue (struct gdbarch *gdbarch, const struct arc_instruction &insn, >> return false; >> } >> >> -/* Copy of gdb_buffered_insn_length_fprintf from disasm.c. */ >> - >> -static int ATTRIBUTE_PRINTF (2, 3) >> -arc_fprintf_disasm (void *stream, const char *format, ...) >> -{ >> - return 0; >> -} >> +/* See arc-tdep.h. */ >> >> struct disassemble_info >> arc_disassemble_info (struct gdbarch *gdbarch) >> { >> struct disassemble_info di; >> - init_disassemble_info (&di, &null_stream, arc_fprintf_disasm); >> + init_disassemble_info_for_no_printing (&di); >> di.arch = gdbarch_bfd_arch_info (gdbarch)->arch; >> di.mach = gdbarch_bfd_arch_info (gdbarch)->mach; >> di.endian = gdbarch_byte_order (gdbarch); >> diff --git a/gdb/disasm.c b/gdb/disasm.c >> index 5cd1f5adbd2..8f04fe6438d 100644 >> --- a/gdb/disasm.c >> +++ b/gdb/disasm.c >> @@ -891,16 +891,23 @@ gdb_insn_length (struct gdbarch *gdbarch, CORE_ADDR addr) >> return gdb_print_insn (gdbarch, addr, &null_stream, NULL); >> } >> >> -/* fprintf-function for gdb_buffered_insn_length. This function is a >> - nop, we don't want to print anything, we just want to compute the >> - length of the insn. */ >> +/* An fprintf-function for use by the disassembler when we know we don't >> + want to print anything. Always returns success. */ >> >> static int ATTRIBUTE_PRINTF (2, 3) >> -gdb_buffered_insn_length_fprintf (void *stream, const char *format, ...) >> +gdb_disasm_null_printf (void *stream, const char *format, ...) >> { >> return 0; >> } >> >> +/* See disasm.h. */ >> + >> +void >> +init_disassemble_info_for_no_printing (struct disassemble_info *dinfo) >> +{ >> + init_disassemble_info (dinfo, nullptr, gdb_disasm_null_printf); >> +} >> + >> /* Initialize a struct disassemble_info for gdb_buffered_insn_length. >> Upon return, *DISASSEMBLER_OPTIONS_HOLDER owns the string pointed >> to by DI.DISASSEMBLER_OPTIONS. */ >> @@ -912,7 +919,7 @@ gdb_buffered_insn_length_init_dis (struct gdbarch *gdbarch, >> CORE_ADDR addr, >> std::string *disassembler_options_holder) >> { >> - init_disassemble_info (di, NULL, gdb_buffered_insn_length_fprintf); >> + init_disassemble_info_for_no_printing (di); >> >> /* init_disassemble_info installs buffer_read_memory, etc. >> so we don't need to do that here. >> diff --git a/gdb/disasm.h b/gdb/disasm.h >> index d739b57d898..359fb6a67fd 100644 >> --- a/gdb/disasm.h >> +++ b/gdb/disasm.h >> @@ -174,4 +174,10 @@ extern char *get_disassembler_options (struct gdbarch *gdbarch); >> >> extern void set_disassembler_options (const char *options); >> >> +/* Setup DINFO with its output function and output stream setup so that >> + nothing is printed while disassembling. */ >> + >> +extern void init_disassemble_info_for_no_printing >> + (struct disassemble_info *dinfo); >> + >> #endif >> diff --git a/gdb/s12z-tdep.c b/gdb/s12z-tdep.c >> index 3f9740f0dfe..659adf4f505 100644 >> --- a/gdb/s12z-tdep.c >> +++ b/gdb/s12z-tdep.c >> @@ -140,19 +140,15 @@ s12z_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int num) >> >> /* Support functions for frame handling. */ >> >> -/* Copy of gdb_buffered_insn_length_fprintf from disasm.c. */ >> >> -static int ATTRIBUTE_PRINTF (2, 3) >> -s12z_fprintf_disasm (void *stream, const char *format, ...) >> -{ >> - return 0; >> -} >> +/* Return a disassemble_info initialized for s12z disassembly, however, >> + the disassembler will not actually print anything. */ >> >> static struct disassemble_info >> s12z_disassemble_info (struct gdbarch *gdbarch) >> { >> struct disassemble_info di; >> - init_disassemble_info (&di, &null_stream, s12z_fprintf_disasm); >> + init_disassemble_info_for_no_printing (&di); >> di.arch = gdbarch_bfd_arch_info (gdbarch)->arch; >> di.mach = gdbarch_bfd_arch_info (gdbarch)->mach; >> di.endian = gdbarch_byte_order (gdbarch); >> -- >> 2.25.4 >> > > -- > Joel