Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@redhat.com>
To: Farid Khaidari <khaidari.fg@gmail.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 4/4] gdb/riscv: disassemble an attribute-less object by the description ISA
Date: Sun, 25 Oct 2026 13:50:18 -0700	[thread overview]
Message-ID: <b8351d67-be5e-4793-b19a-6b6d0b9501c0@redhat.com> (raw)
In-Reply-To: <20261022154417.235510-5-khaidari.fg@gmail.com>

Hi Farid,

A nit...

On 10/22/26 8:44 AM, Farid Khaidari wrote:

>  static int
> @@ -4212,6 +4251,37 @@ riscv_print_insn (bfd_vma addr, struct disassemble_info *info)
>    if (s != nullptr)
>      info->section = s->the_bfd_section;
>  
> +  /* An object that records its own ISA is disassembled according to
> +     that ISA.  One that does not, such as a core file loaded without an
> +     executable, is disassembled according to the target description;
> +     libopcodes would otherwise fall back to plain rv64gc.  ARCH_OPTION
> +     must outlive the default_print_insn call below, which parses it.
> +
> +     The user options are read from the gdbarch and appended here.
> +     libopcodes clears INFO->DISASSEMBLER_OPTIONS once it has parsed
> +     them, so the string has to be supplied again for the next
> +     instruction; each parse first resets every option it does not see
> +     back to its default, which is why the user ones have to be
> +     repeated rather than parsed once.  They come last and so take
> +     precedence.  */
> +  std::string arch_option;
> +  auto *di = static_cast<gdb_disassemble_info *> (info->application_data);
> +  if (di != nullptr && !riscv_disasm_bfd_has_isa_attribute (info))
> +    {
> +      gdbarch *arch = di->arch ();
> +      riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (arch);
> +
> +      arch_option = tdep->disassembler_options_arch;
> +
> +      const char *user_options = get_disassembler_options (arch);
> +      if (user_options != nullptr && *user_options != '\0')
> +	{
> +	  arch_option += ',';
> +	  arch_option += user_options;
> +	}
> +      info->disassembler_options = arch_option.c_str ();

This points info->disassembler_options at storage owned by a local
std::string, which is destroyed when riscv_print_insn returns.  It
only works because print_insn_riscv() sets disassembler_options to
NULL after parsing them.  (There is an early return before that, when
riscv_init_disasm_info fails, but that function currently always
returns true.)  Relying on that libopcodes behaviour seems fragile:
if print_insn_riscv ever stops clearing the field, or returns early
before doing so, the next instruction will see a dangling pointer.

Kevin


  reply	other threads:[~2026-10-25 20:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-22 15:44 [PATCH 0/4] gdb/riscv: analyse a core file without the executable Farid Khaidari
2026-10-22 15:44 ` [PATCH 1/4] gdb/riscv: recover FLEN from the NT_FPREGSET note size in core files Farid Khaidari
2026-10-25 20:07   ` Kevin Buettner
2026-10-26 10:01     ` Farid Khaidari
2026-10-22 15:44 ` [PATCH 2/4] gdb/riscv: recover core file ISA features from AT_HWCAP Farid Khaidari
2026-10-22 15:44 ` [PATCH 3/4] gdb/riscv: test the "arch=" disassembler option Farid Khaidari
2026-10-22 15:44 ` [PATCH 4/4] gdb/riscv: disassemble an attribute-less object by the description ISA Farid Khaidari
2026-10-25 20:50   ` Kevin Buettner [this message]
2026-10-26 10:01     ` Farid Khaidari
2026-10-25 20:17 ` [PATCH 0/4] gdb/riscv: analyse a core file without the executable Kevin Buettner
2026-10-26  9:56 ` [PATCH v2 " Farid Khaidari
2026-10-26  9:56   ` [PATCH v2 1/4] gdb/riscv: recover FLEN from the NT_FPREGSET note size in core files Farid Khaidari
2026-10-26  9:56   ` [PATCH v2 2/4] gdb/riscv: recover core file ISA features from AT_HWCAP Farid Khaidari
2026-10-26  9:56   ` [PATCH v2 3/4] gdb/riscv: test the "arch=" disassembler option Farid Khaidari
2026-10-26  9:56   ` [PATCH v2 4/4] gdb/riscv: disassemble an attribute-less object by the description ISA Farid Khaidari
2026-10-27 14:31   ` [PATCH v2 0/4] gdb/riscv: analyse a core file without the executable Farid Khaidari

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b8351d67-be5e-4793-b19a-6b6d0b9501c0@redhat.com \
    --to=kevinb@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=khaidari.fg@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox