From: Andrew Burgess <aburgess@redhat.com>
To: Simon Marchi <simark@simark.ca>, gdb-patches@sourceware.org
Cc: Andrew Burgess <andrew.burgess@embecosm.com>
Subject: Re: [PATCHv4 1/5] gdb: add new base class to gdb_disassembler
Date: Tue, 03 May 2022 17:13:04 +0100 [thread overview]
Message-ID: <87o80emw6n.fsf@redhat.com> (raw)
In-Reply-To: <0a8f29f9-a8f9-e178-6c89-90ff38be7596@simark.ca>
Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
>> From: Andrew Burgess <andrew.burgess@embecosm.com>
>>
>> The motivation for this change is an upcoming Python disassembler API
>> that I would like to add. As part of that change I need to create a
>> new disassembler like class that contains a disassemble_info and a
>> gdbarch. The management of these two objects is identical to how we
>> manage these objects within gdb_disassembler, so it might be tempting
>> for my new class to inherit from gdb_disassembler.
>>
>> The problem however, is that gdb_disassembler has a tight connection
>> between its constructor, and its print_insn method. In the
>> constructor the ui_file* that is passed in is replaced with a member
>> variable string_file*, and then in print_insn, the contents of the
>> member variable string_file are printed to the original ui_file*.
>>
>> What this means is that the gdb_disassembler class has a tight
>> coupling between its constructor and print_insn; the class just isn't
>> intended to be used in a situation where print_insn is not going to be
>> called, which is how my (upcoming) sub-class would need to operate.
>>
>> My solution then, is to separate out the management of the
>> disassemble_info and gdbarch into a new gdb_disassemble_info class,
>> and make this class a parent of gdb_disassembler.
>>
>> In arm-tdep.c and mips-tdep.c, where we used to cast the
>> disassemble_info->application_data to a gdb_disassembler, we can now
>> cast to a gdb_disassemble_info as we only need to access the gdbarch
>> information.
>>
>> Now, my new Python disassembler sub-class will still want to print
>> things to an output stream, and so we will want access to the
>> dis_asm_fprintf functionality for printing.
>>
>> However, rather than move this printing code into the
>> gdb_disassemble_info base class, I have added yet another level of
>> hierarchy, a gdb_printing_disassembler, thus the class structure is
>> now:
>>
>> struct gdb_disassemble_info {};
>> struct gdb_printing_disassembler : public gdb_disassemble_info {};
>> struct gdb_disassembler : public gdb_printing_disassembler {};
>
> I can't explain it very well, but it seems a little strange to make the
> other classes inherit from gdb_disassemble_info. From the name (and the
> code), I understand that gdb_disassemble_info purely holds the data
> necessary for the disassemblers to do their job. So this is not really
> an IS-A relationship, but more a HAS-A. So I would think composition
> would be more natural (i.e. gdb_printing_disassembler would have a field
> of type gdb_disassemble_info).
I understand exactly where you're unease comes from, and I had the same
feeling. The problem I think is the name of these things.
So we used to have two classes 'gdb_disassembler' which is really a
wrapper around the libopcodes 'disassemble_info'.
Then we had 'gdb_pretty_print_disassembler' which had-a
gdb_disassembler.
In one of my original versions of this patch I added just
gdb_disassemble_info as a base class, then gdb_disassembler inherited
from that.
At some point the patch expanded, and the new classes took the
*_disassembler suffix rather than the *_disassemble_info suffix, which
was maybe a mistake.
So the classes you listed above, gdb_printing_disassembler and
gdb_disassembler, really are specialisations of gdb_disassemble_info,
but maybe this would all be better if I renamed all these things to
use a _disassemble_info suffix?
Thanks,
Andrew
>
> But with the callbacks we pass to struct disassemble_info (such as
> fprintf_func and fprintf_styled_func), what is data and what is behavior
> gets a little blurry.
>
> It doesn't matter much in the end, I'm fine with what you have. And it
> can always be refactored later.
>
>> +gdb_disassemble_info::gdb_disassemble_info
>> + (struct gdbarch *gdbarch, struct ui_file *stream,
>> + read_memory_ftype read_memory_func, memory_error_ftype memory_error_func,
>> + print_address_ftype print_address_func, fprintf_ftype fprintf_func,
>> + fprintf_styled_ftype fprintf_styled_func)
>> + : m_gdbarch (gdbarch)
>> {
>> - init_disassemble_info (&m_di, &m_buffer, dis_asm_fprintf,
>> - dis_asm_styled_fprintf);
>> + gdb_assert (fprintf_func != nullptr);
>> + gdb_assert (fprintf_styled_func != nullptr);
>> + init_disassemble_info (&m_di, stream, fprintf_func,
>> + fprintf_styled_func);
>> m_di.flavour = bfd_target_unknown_flavour;
>> - m_di.memory_error_func = dis_asm_memory_error;
>> - m_di.print_address_func = dis_asm_print_address;
>> - /* NOTE: cagney/2003-04-28: The original code, from the old Insight
>> - disassembler had a local optimization here. By default it would
>> - access the executable file, instead of the target memory (there
>> - was a growing list of exceptions though). Unfortunately, the
>> - heuristic was flawed. Commands like "disassemble &variable"
>> - didn't work as they relied on the access going to the target.
>> - Further, it has been superseeded by trust-read-only-sections
>> - (although that should be superseeded by target_trust..._p()). */
>> - m_di.read_memory_func = read_memory_func;
>> + if (memory_error_func != nullptr)
>> + m_di.memory_error_func = memory_error_func;
>> + if (print_address_func != nullptr)
>> + m_di.print_address_func = print_address_func;
>> + if (read_memory_func != nullptr)
>> + m_di.read_memory_func = read_memory_func;
>
> Are the nullptr checks needed? Are these fields initially nullptr, or
> they have some other value?
>
>
>> +struct gdb_disassemble_info
>> +{
>> + DISABLE_COPY_AND_ASSIGN (gdb_disassemble_info);
>>
>> - /* Return the gdbarch of gdb_disassembler. */
>> + /* Return the gdbarch we are disassembing for. */
>
> disassembing -> disassembling
>
> Simon
next prev parent reply other threads:[~2022-05-03 16:13 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-13 21:59 [PATCH 0/5] Add Python API for the disassembler Andrew Burgess
2021-10-13 21:59 ` [PATCH 1/5] gdb: make disassembler fprintf callback a static member function Andrew Burgess
2021-10-20 20:40 ` Tom Tromey
2021-10-22 12:51 ` Andrew Burgess
2021-10-13 21:59 ` [PATCH 2/5] gdb/python: new gdb.architecture_names function Andrew Burgess
2021-10-14 6:52 ` Eli Zaretskii
2021-10-22 12:51 ` Andrew Burgess
2021-10-20 20:40 ` Tom Tromey
2021-10-22 13:02 ` Simon Marchi
2021-10-22 17:34 ` Andrew Burgess
2021-10-22 18:42 ` Simon Marchi
2021-10-13 21:59 ` [PATCH 3/5] gdb/python: move gdb.Membuf support into a new file Andrew Burgess
2021-10-20 20:42 ` Tom Tromey
2021-10-22 12:52 ` Andrew Burgess
2021-10-13 21:59 ` [PATCH 4/5] gdb: add extension language print_insn hook Andrew Burgess
2021-10-20 21:06 ` Tom Tromey
2021-10-13 21:59 ` [PATCH 5/5] gdb/python: implement the print_insn extension language hook Andrew Burgess
2021-10-14 7:12 ` Eli Zaretskii
2021-10-22 17:47 ` Andrew Burgess
2021-10-22 18:33 ` Eli Zaretskii
2021-10-22 13:30 ` Simon Marchi
2022-03-23 22:41 ` [PATCHv2 0/3] Add Python API for the disassembler Andrew Burgess
2022-03-23 22:41 ` [PATCHv2 1/3] gdb: add new base class to gdb_disassembler Andrew Burgess
2022-03-23 22:41 ` [PATCHv2 2/3] gdb: add extension language print_insn hook Andrew Burgess
2022-03-23 22:41 ` [PATCHv2 3/3] gdb/python: implement the print_insn extension language hook Andrew Burgess
2022-03-24 7:10 ` Eli Zaretskii
2022-03-24 19:51 ` Andrew Burgess
2022-04-04 22:19 ` [PATCHv3 0/6] Add Python API for the disassembler Andrew Burgess
2022-04-04 22:19 ` [PATCHv3 1/6] gdb: move gdb_disassembly_flag into a new disasm-flags.h file Andrew Burgess
2022-04-05 14:32 ` Tom Tromey
2022-04-06 12:18 ` Andrew Burgess
2022-04-04 22:19 ` [PATCHv3 2/6] gdb: add new base class to gdb_disassembler Andrew Burgess
2022-04-04 22:19 ` [PATCHv3 3/6] gdb: add extension language print_insn hook Andrew Burgess
2022-04-04 22:19 ` [PATCHv3 4/6] gdb/python: implement the print_insn extension language hook Andrew Burgess
2022-04-05 12:04 ` Eli Zaretskii
2022-04-04 22:19 ` [PATCHv3 5/6] gdb: refactor the non-printing disassemblers Andrew Burgess
2022-04-04 22:19 ` [PATCHv3 6/6] gdb: unify two dis_asm_read_memory functions in disasm.c Andrew Burgess
2022-04-25 9:15 ` [PATCHv4 0/5] Add Python API for the disassembler Andrew Burgess
2022-04-25 9:15 ` [PATCHv4 1/5] gdb: add new base class to gdb_disassembler Andrew Burgess
2022-05-03 13:34 ` Simon Marchi
2022-05-03 16:13 ` Andrew Burgess [this message]
2022-05-05 17:39 ` Andrew Burgess
2022-04-25 9:15 ` [PATCHv4 2/5] gdb: add extension language print_insn hook Andrew Burgess
2022-05-03 13:42 ` Simon Marchi
2022-04-25 9:15 ` [PATCHv4 3/5] gdb/python: implement the print_insn extension language hook Andrew Burgess
2022-04-25 11:26 ` Eli Zaretskii
2022-05-03 14:55 ` Simon Marchi
2022-05-05 18:17 ` Andrew Burgess
2022-05-24 1:16 ` Simon Marchi
2022-05-24 8:30 ` Andrew Burgess
2022-05-25 10:37 ` Andrew Burgess
2022-04-25 9:15 ` [PATCHv4 4/5] gdb: refactor the non-printing disassemblers Andrew Burgess
2022-04-25 9:15 ` [PATCHv4 5/5] gdb: unify two dis_asm_read_memory functions in disasm.c Andrew Burgess
2022-05-03 10:12 ` [PATCHv4 0/5] Add Python API for the disassembler Andrew Burgess
2022-05-06 17:17 ` [PATCHv5 " Andrew Burgess
2022-05-06 17:17 ` [PATCHv5 1/5] gdb: add new base class to gdb_disassembler Andrew Burgess
2022-05-06 17:17 ` [PATCHv5 2/5] gdb: add extension language print_insn hook Andrew Burgess
2022-05-06 17:17 ` [PATCHv5 3/5] gdb/python: implement the print_insn extension language hook Andrew Burgess
2022-05-06 18:11 ` Eli Zaretskii
2022-05-18 10:08 ` Andrew Burgess
2022-05-18 12:08 ` Eli Zaretskii
2022-05-23 8:59 ` Andrew Burgess
2022-05-23 11:23 ` Eli Zaretskii
2022-05-06 17:17 ` [PATCHv5 4/5] gdb: refactor the non-printing disassemblers Andrew Burgess
2022-05-06 17:17 ` [PATCHv5 5/5] gdb: unify two dis_asm_read_memory functions in disasm.c Andrew Burgess
2022-05-25 10:49 ` [PATCHv6 0/6] Add Python API for the disassembler Andrew Burgess
2022-05-25 10:49 ` [PATCHv6 1/6] gdb/python: convert gdbpy_err_fetch to use gdbpy_ref Andrew Burgess
2022-05-25 10:49 ` [PATCHv6 2/6] gdb: add new base class to gdb_disassembler Andrew Burgess
2022-05-25 10:49 ` [PATCHv6 3/6] gdb: add extension language print_insn hook Andrew Burgess
2022-05-25 10:49 ` [PATCHv6 4/6] gdb/python: implement the print_insn extension language hook Andrew Burgess
2022-05-25 13:32 ` Eli Zaretskii
2022-05-25 10:49 ` [PATCHv6 5/6] gdb: refactor the non-printing disassemblers Andrew Burgess
2022-05-25 10:49 ` [PATCHv6 6/6] gdb: unify two dis_asm_read_memory functions in disasm.c Andrew Burgess
2022-06-15 9:04 ` [PUSHED 0/6] Add Python API for the disassembler Andrew Burgess
2022-06-15 9:04 ` [PUSHED 1/6] gdb/python: convert gdbpy_err_fetch to use gdbpy_ref Andrew Burgess
2022-06-15 9:04 ` [PUSHED 2/6] gdb: add new base class to gdb_disassembler Andrew Burgess
2022-06-15 9:04 ` [PUSHED 3/6] gdb: add extension language print_insn hook Andrew Burgess
2022-06-15 9:04 ` [PUSHED 4/6] gdb/python: implement the print_insn extension language hook Andrew Burgess
2022-06-15 9:04 ` [PUSHED 5/6] gdb: refactor the non-printing disassemblers Andrew Burgess
2022-06-15 9:04 ` [PUSHED 6/6] gdb: unify two dis_asm_read_memory functions in disasm.c 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=87o80emw6n.fsf@redhat.com \
--to=aburgess@redhat.com \
--cc=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
--cc=simark@simark.ca \
/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).