From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1386) id C966B3858D37; Fri, 21 Apr 2023 10:10:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C966B3858D37 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jan Beulich To: bfd-cvs@sourceware.org Subject: [binutils-gdb] x86: move fetch error handling into a helper function X-Act-Checkin: binutils-gdb X-Git-Author: Jan Beulich X-Git-Refname: refs/heads/master X-Git-Oldrev: ae272fb8a57bb03dcc8ff800bb1b861bdc79933f X-Git-Newrev: 4bcbe86c25a61afd70106af466e73e4462c25d0b Message-Id: <20230421101035.C966B3858D37@sourceware.org> Date: Fri, 21 Apr 2023 10:10:35 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Apr 2023 10:10:35 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D4bcbe86c25a6= 1afd70106af466e73e4462c25d0b commit 4bcbe86c25a61afd70106af466e73e4462c25d0b Author: Jan Beulich Date: Fri Apr 21 12:07:26 2023 +0200 x86: move fetch error handling into a helper function =20 ... such that it can be used from other than the setjmp() error handling path. =20 Since I'd like the function's parameter to be pointer-to-const, two other functions need respective constification then, too (along with needing to be forward-declared). Diff: --- opcodes/i386-dis.c | 63 ++++++++++++++++++++++++++++++--------------------= ---- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c index d6b0fdd4ba3..d731175cab6 100644 --- a/opcodes/i386-dis.c +++ b/opcodes/i386-dis.c @@ -116,6 +116,11 @@ static void MOVSXD_Fixup (instr_info *, int, int); static void DistinctDest_Fixup (instr_info *, int, int); static void PREFETCHI_Fixup (instr_info *, int, int); =20 +static void ATTRIBUTE_PRINTF_3 i386_dis_printf (const instr_info *, + enum disassembler_style, + const char *, ...); +static const char *prefix_name (const instr_info *, int, int); + /* This character is used to encode style information within the output buffers. See oappend_insert_style for more details. */ #define STYLE_MARKER_CHAR '\002' @@ -324,6 +329,33 @@ fetch_data (struct disassemble_info *info, bfd_byte *a= ddr) return 1; } =20 +static int +fetch_error (const instr_info *ins) +{ + /* Getting here means we tried for data but didn't get it. That + means we have an incomplete instruction of some sort. Just + print the first byte as a prefix or a .byte pseudo-op. */ + const struct dis_private *priv =3D ins->info->private_data; + const char *name =3D NULL; + + if (ins->codep <=3D priv->the_buffer) + return -1; + + if (ins->prefixes || ins->fwait_prefix >=3D 0 || (ins->rex & REX_OPCODE)) + name =3D prefix_name (ins, priv->the_buffer[0], priv->orig_sizeflag); + if (name !=3D NULL) + i386_dis_printf (ins, dis_style_mnemonic, "%s", name); + else + { + /* Just print the first byte as a .byte instruction. */ + i386_dis_printf (ins, dis_style_assembler_directive, ".byte "); + i386_dis_printf (ins, dis_style_immediate, "%#x", + (unsigned int) priv->the_buffer[0]); + } + + return 1; +} + /* Possible values for prefix requirement. */ #define PREFIX_IGNORED_SHIFT 16 #define PREFIX_IGNORED_REPZ (PREFIX_REPZ << PREFIX_IGNORED_SHIFT) @@ -9007,7 +9039,7 @@ ckprefix (instr_info *ins) prefix byte. */ =20 static const char * -prefix_name (instr_info *ins, int pref, int sizeflag) +prefix_name (const instr_info *ins, int pref, int sizeflag) { static const char *rexes [16] =3D { @@ -9608,7 +9640,7 @@ oappend_register (instr_info *ins, const char *s) used in the next fprintf_styled_func call. */ =20 static void ATTRIBUTE_PRINTF_3 -i386_dis_printf (instr_info *ins, enum disassembler_style style, +i386_dis_printf (const instr_info *ins, enum disassembler_style style, const char *fmt, ...) { va_list ap; @@ -9836,32 +9868,7 @@ print_insn (bfd_vma pc, disassemble_info *info, int = intel_syntax) } =20 if (OPCODES_SIGSETJMP (priv.bailout) !=3D 0) - { - /* Getting here means we tried for data but didn't get it. That - means we have an incomplete instruction of some sort. Just - print the first byte as a prefix or a .byte pseudo-op. */ - if (ins.codep > priv.the_buffer) - { - const char *name =3D NULL; - - if (ins.prefixes || ins.fwait_prefix >=3D 0 || (ins.rex & REX_OPCODE)) - name =3D prefix_name (&ins, priv.the_buffer[0], priv.orig_sizeflag); - if (name !=3D NULL) - i386_dis_printf (&ins, dis_style_mnemonic, "%s", name); - else - { - /* Just print the first byte as a .byte instruction. */ - i386_dis_printf (&ins, dis_style_assembler_directive, - ".byte "); - i386_dis_printf (&ins, dis_style_immediate, "0x%x", - (unsigned int) priv.the_buffer[0]); - } - - return 1; - } - - return -1; - } + return fetch_error (&ins); =20 sizeflag =3D priv.orig_sizeflag;