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 57C4F385843E for ; Mon, 4 Apr 2022 21:46:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 57C4F385843E 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-151-CAsyJGUNMfuD-gjP0zQaYg-1; Mon, 04 Apr 2022 17:46:37 -0400 X-MC-Unique: CAsyJGUNMfuD-gjP0zQaYg-1 Received: by mail-wm1-f69.google.com with SMTP id t2-20020a7bc3c2000000b003528fe59cb9so278616wmj.5 for ; Mon, 04 Apr 2022 14:46:37 -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:mime-version :content-transfer-encoding; bh=e2rsvtaT6WiRnYNUdNvoEBjBYAnUlpBCYjIvHeen1Ek=; b=xcRvXCSDpvxwPCKvGHPzsuEabVkIniL8ssAEmmAtlgSc1pC5zDeX6kTOSU5ubZfPdx kLiNfqkIQVICjaKM6v3QAn7UrPOBWmXSM0fJoqP2/ZI1N4bRRNAZAEiXNkqXO32ZMDbT vfDl4WLni0afhr/EEbvkYBP8F99vMUzI1MbqMiXcWr9GkZXcdaQfzlWpfIvCg1BT1utF 9yJuATO0xvncR1sKQcg2vzFrNPRg0+GD90kLDaA9rkIRLw6pnuOm/9a3OSpjHBBHWKbn XQ8RDToNJHt+728qi2/A1E42D1nBo4eoD0i+lg7Lh1Jj6mc8hBOiJ9U/5J3fxv9J8ft/ Pg0A== X-Gm-Message-State: AOAM5313utBvAG9cDSbzFg0Ejggfog0TgPA4/xBRZEwrWZUWn3UY/JMd HSdM2GinYgZV4ZAjbZBlfDf1Ii5zbCNoySeSHMmhUNdmHw01FB+mmuf8wEXMUX4HqRSyXIuEO8m NVFvZwhNqi5xPua7fLI/2sXiJiD/Pb5UAyvOE0R6dMro9s7NgQBnKVDyTl7imM5JHnyQeSHHa1w == X-Received: by 2002:a05:600c:4ec8:b0:38c:90fb:d3bf with SMTP id g8-20020a05600c4ec800b0038c90fbd3bfmr83543wmq.0.1649108796336; Mon, 04 Apr 2022 14:46:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNghMGD97j6KC6BZac1AxIbiSlzc8Ykpq6HhCfwBHFOkjoN0EybKckuHoTq0jreIHwQUwaaw== X-Received: by 2002:a05:600c:4ec8:b0:38c:90fb:d3bf with SMTP id g8-20020a05600c4ec800b0038c90fbd3bfmr83520wmq.0.1649108795958; Mon, 04 Apr 2022 14:46:35 -0700 (PDT) Received: from localhost (host86-169-131-113.range86-169.btcentralplus.com. [86.169.131.113]) by smtp.gmail.com with ESMTPSA id h10-20020a05600c144a00b0038ccc75a6adsm160879wmi.37.2022.04.04.14.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 14:46:35 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PUSHED] sim: fixes for libopcodes styled disassembler Date: Mon, 4 Apr 2022 22:46:32 +0100 Message-Id: <20220404214632.1103903-1-aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 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.2 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_H4, 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 21:46:41 -0000 I've gone ahead and pushed the patch below without review, despite it being non-trivial. I stupidly managed to break several sim targets, and I wanted to undo the breakage asap. Despite being quite large, I hope nothing in here is too controversial. However, if there is any feedback, do please leave it and I'll be happy to fix any issues in a follow up patch. Sorry for the breakage, and thank you for your understanding. Andrew --- In commit: commit 60a3da00bd5407f07d64dff82a4dae98230dfaac Date: Sat Jan 22 11:38:18 2022 +0000 objdump/opcodes: add syntax highlighting to disassembler output I broke several sim/ targets by forgetting to update their uses of the libopcodes disassembler to take account of the new styled printing. These should all be fixed by this commit. I've not tried to add actual styled output to the simulator traces, instead, the styled print routines just ignore the style and print the output unstyled. --- sim/arm/wrapper.c | 15 ++++++++++++++- sim/common/cgen-trace.c | 19 ++++++++++++++++++- sim/common/cgen-trace.h | 1 + sim/common/sim-trace.c | 14 +++++++++++++- sim/cris/sim-if.c | 3 ++- sim/erc32/interf.c | 3 ++- sim/erc32/sis.c | 18 +++++++++++++++++- sim/erc32/sis.h | 3 +++ sim/m32c/trace.c | 14 +++++++++++++- sim/rl78/trace.c | 14 +++++++++++++- sim/rx/trace.c | 14 +++++++++++++- 11 files changed, 109 insertions(+), 9 deletions(-) diff --git a/sim/arm/wrapper.c b/sim/arm/wrapper.c index ab56bc4e7b8..c97bae89dad 100644 --- a/sim/arm/wrapper.c +++ b/sim/arm/wrapper.c @@ -76,6 +76,19 @@ op_printf (char *buf, const char *fmt, ...) return ret; } +static int ATTRIBUTE_PRINTF (3, 4) +op_styled_printf (char *buf, enum disassembler_style style, + const char *fmt, ...) +{ + int ret; + va_list ap; + + va_start (ap, fmt); + ret = vsprintf (opbuf + strlen (opbuf), fmt, ap); + va_end (ap); + return ret; +} + static int sim_dis_read (bfd_vma memaddr ATTRIBUTE_UNUSED, bfd_byte * ptr, @@ -321,7 +334,7 @@ sim_create_inferior (SIM_DESC sd ATTRIBUTE_UNUSED, } memset (& info, 0, sizeof (info)); - INIT_DISASSEMBLE_INFO (info, stdout, op_printf); + INIT_DISASSEMBLE_INFO (info, stdout, op_printf, op_styled_printf); info.read_memory_func = sim_dis_read; info.arch = bfd_get_arch (abfd); info.mach = bfd_get_mach (abfd); diff --git a/sim/common/cgen-trace.c b/sim/common/cgen-trace.c index 149ea8a127c..12f6126d43f 100644 --- a/sim/common/cgen-trace.c +++ b/sim/common/cgen-trace.c @@ -320,6 +320,22 @@ sim_disasm_sprintf (SFILE *f, const char *format, ...) return n; } +/* sprintf to a "stream" with styling. */ + +int +sim_disasm_styled_sprintf (SFILE *f, enum disassembler_style style, + const char *format, ...) +{ + int n; + va_list args; + + va_start (args, format); + vsprintf (f->current, format, args); + f->current += n = strlen (f->current); + va_end (args); + return n; +} + /* Memory read support for an opcodes disassembler. */ int @@ -383,7 +399,8 @@ sim_cgen_disassemble_insn (SIM_CPU *cpu, const CGEN_INSN *insn, sfile.buffer = sfile.current = buf; INIT_DISASSEMBLE_INFO (disasm_info, (FILE *) &sfile, - (fprintf_ftype) sim_disasm_sprintf); + (fprintf_ftype) sim_disasm_sprintf, + (fprintf_styled_ftype) sim_disasm_styled_sprintf); disasm_info.endian = (bfd_big_endian (STATE_PROG_BFD (sd)) ? BFD_ENDIAN_BIG : bfd_little_endian (STATE_PROG_BFD (sd)) ? BFD_ENDIAN_LITTLE diff --git a/sim/common/cgen-trace.h b/sim/common/cgen-trace.h index 84b4935f148..3e2b4a9e9d7 100644 --- a/sim/common/cgen-trace.h +++ b/sim/common/cgen-trace.h @@ -78,6 +78,7 @@ typedef struct { /* String printer for the disassembler. */ extern int sim_disasm_sprintf (SFILE *, const char *, ...) ATTRIBUTE_PRINTF_2; +extern int sim_disasm_styled_sprintf (SFILE *, enum disassembler_style, const char *, ...) ATTRIBUTE_PRINTF_3; /* For opcodes based disassemblers. */ #ifdef __BFD_H_SEEN__ diff --git a/sim/common/sim-trace.c b/sim/common/sim-trace.c index 0b63bdb07b6..952c3514087 100644 --- a/sim/common/sim-trace.c +++ b/sim/common/sim-trace.c @@ -906,6 +906,18 @@ dis_printf (SIM_CPU *cpu, const char *fmt, ...) return 0; } +static int ATTRIBUTE_PRINTF (3, 4) +dis_styled_printf (SIM_CPU *cpu, enum disassembler_style style, + const char *fmt, ...) +{ + SIM_DESC sd = CPU_STATE (cpu); + va_list ap; + va_start (ap, fmt); + trace_vprintf (sd, cpu, fmt, ap); + va_end (ap); + return 0; +} + void trace_disasm (SIM_DESC sd, sim_cpu *cpu, address_word addr) { @@ -922,7 +934,7 @@ trace_disasm (SIM_DESC sd, sim_cpu *cpu, address_word addr) bfd_big_endian (trace_data->dis_bfd), bfd_get_mach (trace_data->dis_bfd), trace_data->dis_bfd); - INIT_DISASSEMBLE_INFO (*info, cpu, dis_printf); + INIT_DISASSEMBLE_INFO (*info, cpu, dis_printf, dis_styled_printf); info->read_memory_func = dis_read; info->arch = bfd_get_arch (bfd); info->mach = bfd_get_mach (bfd); diff --git a/sim/cris/sim-if.c b/sim/cris/sim-if.c index c72edc752b6..3589f5bfdce 100644 --- a/sim/cris/sim-if.c +++ b/sim/cris/sim-if.c @@ -1017,7 +1017,8 @@ cris_disassemble_insn (SIM_CPU *cpu, sfile.buffer = sfile.current = buf; INIT_DISASSEMBLE_INFO (disasm_info, (FILE *) &sfile, - (fprintf_ftype) sim_disasm_sprintf); + (fprintf_ftype) sim_disasm_sprintf, + (fprintf_styled_ftype) sim_disasm_styled_sprintf); disasm_info.endian = BFD_ENDIAN_LITTLE; disasm_info.read_memory_func = sim_disasm_read_memory; disasm_info.memory_error_func = sim_disasm_perror_memory; diff --git a/sim/erc32/interf.c b/sim/erc32/interf.c index d04d07c08c8..78dec6f4b9b 100644 --- a/sim/erc32/interf.c +++ b/sim/erc32/interf.c @@ -244,7 +244,8 @@ sim_open (SIM_OPEN_KIND kind, struct host_callback_struct *callback, #ifdef F_GETFL termsave = fcntl(0, F_GETFL, 0); #endif - INIT_DISASSEMBLE_INFO(dinfo, stdout,(fprintf_ftype)fprintf); + INIT_DISASSEMBLE_INFO(dinfo, stdout,(fprintf_ftype)fprintf, + fprintf_styled); #ifdef HOST_LITTLE_ENDIAN dinfo.endian = BFD_ENDIAN_LITTLE; #else diff --git a/sim/erc32/sis.c b/sim/erc32/sis.c index 66a27d07506..12eb21f15a7 100644 --- a/sim/erc32/sis.c +++ b/sim/erc32/sis.c @@ -138,6 +138,21 @@ run_sim(struct pstate *sregs, uint64_t icount, int dis) return TIME_OUT; } +int +fprintf_styled (void *stream, enum disassembler_style style, + const char *fmt, ...) +{ + int ret; + FILE *out = (FILE *) stream; + va_list args; + + va_start (args, fmt); + ret = vfprintf (out, fmt, args); + va_end (args); + + return ret; +} + int main(int argc, char **argv) { @@ -212,7 +227,8 @@ main(int argc, char **argv) #endif sregs.freq = freq; - INIT_DISASSEMBLE_INFO(dinfo, stdout, (fprintf_ftype) fprintf); + INIT_DISASSEMBLE_INFO(dinfo, stdout, (fprintf_ftype) fprintf, + (fprintf_styled_ftype) fprintf_styled); #ifdef HOST_LITTLE_ENDIAN dinfo.endian = BFD_ENDIAN_LITTLE; #else diff --git a/sim/erc32/sis.h b/sim/erc32/sis.h index 33f16c77ca4..3a276670402 100644 --- a/sim/erc32/sis.h +++ b/sim/erc32/sis.h @@ -18,6 +18,7 @@ #include "sim/sim.h" #include #include +#include "dis-asm.h" #if HOST_BYTE_ORDER == BIG_ENDIAN #define HOST_BIG_ENDIAN @@ -203,6 +204,8 @@ extern void init_regs (struct pstate *sregs); /* interf.c */ extern int run_sim (struct pstate *sregs, uint64_t icount, int dis); +extern int fprintf_styled (void *stream, enum disassembler_style style, + const char *fmt, ...) ATTRIBUTE_PRINTF (3, 4); /* float.c */ extern int get_accex (void); diff --git a/sim/m32c/trace.c b/sim/m32c/trace.c index 571df1a1e2a..f5171c298c5 100644 --- a/sim/m32c/trace.c +++ b/sim/m32c/trace.c @@ -101,6 +101,18 @@ op_printf (char *buf, char *fmt, ...) return ret; } +static int +op_styled_printf (char *buf, enum disassembler_style style, char *fmt, ...) +{ + int ret; + va_list ap; + + va_start (ap, fmt); + ret = vsprintf (opbuf + strlen (opbuf), fmt, ap); + va_end (ap); + return ret; +} + static bfd *current_bfd; void @@ -210,7 +222,7 @@ sim_disasm_one (void) { initted = 1; memset (&info, 0, sizeof (info)); - INIT_DISASSEMBLE_INFO (info, stdout, op_printf); + INIT_DISASSEMBLE_INFO (info, stdout, op_printf, op_styled_printf); info.read_memory_func = sim_dis_read; info.arch = bfd_get_arch (current_bfd); info.mach = bfd_get_mach (current_bfd); diff --git a/sim/rl78/trace.c b/sim/rl78/trace.c index df75d793f69..a485c4c004d 100644 --- a/sim/rl78/trace.c +++ b/sim/rl78/trace.c @@ -104,6 +104,18 @@ op_printf (char *buf, char *fmt, ...) return ret; } +static int +op_styled_printf (char *buf, enum disassembler_style style, char *fmt, ...) +{ + int ret; + va_list ap; + + va_start (ap, fmt); + ret = vsprintf (opbuf + strlen (opbuf), fmt, ap); + va_end (ap); + return ret; +} + static bfd * current_bfd = NULL; static asymbol ** symtab = NULL; static int symcount = 0; @@ -205,7 +217,7 @@ sim_get_current_source_location (const char ** pfilename, initted = 1; memset (& info, 0, sizeof (info)); - INIT_DISASSEMBLE_INFO (info, stdout, op_printf); + INIT_DISASSEMBLE_INFO (info, stdout, op_printf, op_styled_printf); info.read_memory_func = sim_dis_read; info.arch = bfd_get_arch (current_bfd); info.mach = bfd_get_mach (current_bfd); diff --git a/sim/rx/trace.c b/sim/rx/trace.c index 6e9a266ca3a..df83dc14a1b 100644 --- a/sim/rx/trace.c +++ b/sim/rx/trace.c @@ -109,6 +109,18 @@ op_printf (char *buf, char *fmt, ...) return ret; } +static int ATTRIBUTE_PRINTF (3, 4) +op_styled_printf (char *buf, enum disassembler_style style, char *fmt, ...) +{ + int ret; + va_list ap; + + va_start (ap, fmt); + ret = vsprintf (opbuf + strlen (opbuf), fmt, ap); + va_end (ap); + return ret; +} + static bfd * current_bfd = NULL; static asymbol ** symtab = NULL; static int symcount = 0; @@ -209,7 +221,7 @@ sim_get_current_source_location (const char ** pfilename, initted = 1; memset (& info, 0, sizeof (info)); - INIT_DISASSEMBLE_INFO (info, stdout, op_printf); + INIT_DISASSEMBLE_INFO (info, stdout, op_printf, op_styled_printf); info.read_memory_func = sim_dis_read; info.arch = bfd_get_arch (current_bfd); info.mach = bfd_get_mach (current_bfd); -- 2.25.4