public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Cc: Andrew Burgess <andrew.burgess@embecosm.com>
Subject: Re: [PATCHv2] gdb/python: add gdb.Architecture.format_address
Date: Fri, 4 Mar 2022 10:22:03 -0500	[thread overview]
Message-ID: <286a1f88-1e4e-b2f1-1503-d8ddbb420452@polymtl.ca> (raw)
In-Reply-To: <20220304105031.2706582-1-aburgess@redhat.com>

> @@ -391,6 +416,12 @@ group GROUP-NAME." },
>      METH_NOARGS,
>      "register_groups () -> Iterator.\n\
>  Return an iterator over all of the register groups in this architecture." },
> +  { "format_address", (PyCFunction) archpy_format_address,
> +    METH_VARARGS | METH_KEYWORDS,
> +    "format_address (ADDRESS) -> String.\n\
> +Format ADDRESS, an address within the currently selected inferior's\n\
> +address space, as a string.  The format of the returned string is\n\

I didn't have much time to think about this, but I was just wondering if
there would be a way to avoid relying on the currently selected
inferior.

My understanding is that this function depends on both an architecture,
for formatting the number part of the address, and an inferior for the symbolic
part of the the address.  Or is it a program space instead of inferior?

So the possibilities I see are, to let the user specify both:

  arch_obj.format_address(addr, inf_obj)
  arch_obj.format_address(addr, pspace_obj)
  inf_obj.format_address(addr, arch_obj)
  pspace_obj.format_address(addr, arch_obj)
  gdb.format_address(addr, inf_obj, arch_obj)
  gdb.format_address(addr, pspace_obj, arch_obj)

Putting the format_address on one of the objects (arch, inf, pspace)
seems strange, because it's not a arch-specific operation more than it
is an inf-specific (or pspace-specific operation).  So I'm more leaning
towards gdb.format_address.

And even if the user can pass in objects, we can offer sensible defaults
that will make format_address use "the current things".  Let's say that
format_address is declared as:

  def format_address(addr, pspace_obj=None, arch_obj=None)

If pspace_obj is None, we can fetch it from the currently selected
inferior.  And same for arch_obj.

Also, maybe that doing:

  format_address(addr, inf_obj)

could be a shortcut for:

  format_address(addr, inf_obj.progspace, inf_obj.architecture())

Not sure about that one though.

Simon

  reply	other threads:[~2022-03-04 15:22 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-11 16:17 [PATCH] " Andrew Burgess
2022-02-11 18:54 ` Eli Zaretskii
2022-02-21 17:27   ` Andrew Burgess
2022-02-21 18:02     ` Eli Zaretskii
2022-02-22 13:56       ` Andrew Burgess
2022-02-22 14:48         ` Eli Zaretskii
2022-02-23 14:20           ` Andrew Burgess
2022-03-03 16:49             ` Andrew Burgess
2022-03-03 18:35         ` Craig Blackmore
2022-03-04 10:51           ` Andrew Burgess
2022-03-04 10:50 ` [PATCHv2] " Andrew Burgess
2022-03-04 15:22   ` Simon Marchi [this message]
2022-03-07 12:33   ` [PATCHv3] gdb/python: add gdb.format_address function Andrew Burgess
2022-03-21 17:53     ` Andrew Burgess
2022-03-21 18:23     ` Simon Marchi
2022-03-22 13:19       ` Andrew Burgess
2022-03-23 12:14         ` Simon Marchi
2022-03-23 15:30           ` Andrew Burgess
2022-03-28 21:59             ` Simon Marchi
2022-03-29 13:38               ` Andrew Burgess

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=286a1f88-1e4e-b2f1-1503-d8ddbb420452@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=aburgess@redhat.com \
    --cc=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).