Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@imgtec.com>
To: Yao Qi <qiyaoltc@gmail.com>
Cc: <binutils@sourceware.org>, <gdb-patches@sourceware.org>
Subject: Re: [PATCH 2/6] Delegate opcodes to select disassembler in GDB
Date: Tue, 01 Aug 2017 16:31:00 -0000	[thread overview]
Message-ID: <alpine.DEB.2.00.1707071750060.3339@tp.orcam.me.uk> (raw)
In-Reply-To: <867ezk5hea.fsf@gmail.com>

On Fri, 7 Jul 2017, Yao Qi wrote:

> >  I can see the assumption from the assertion itself, but what is its 
> > purpose?
> >
> 
> The purpose of this assert is to check that the disassemble_info passed
> to opcodes is correctly got from the executable.

 What is there in opcodes that needs guarding with the assertion though, 
i.e. will anything break if the `disassemble_info' passed is not exactly 
one obtained from the executable?

 I'd at least imagine a need for the user to be able to explicitly 
override the disassembler's machine via `set architecture ...', e.g. to 
get a meaningful disassembly of code that has been built with a temporary 
instruction set override for encodings that are not included in the ISA 
recorded in ELF file structures.

> >  Do you think it would be possible as a part of your disassembler rework 
> > to make the symbol table available to libopcodes?  Then the hack currently 
> > present in `gdb_print_insn_mips' could go.  I remember looking into it a 
> > while ago and concluding it would be somewhat tricky because the symbol 
> > table format expected by libopcodes is not the same that we use in
> > GDB.
> 
> We can pass the symbol table to opcodes, so it can choose the right
> disassembler.  However, current GDB uses both symbol and address to
> determine some address is in a MIPS16 or microMIPS function (done by
> mips_pc_is_mips16, mips_pc_is_micromips).  If we want to use symbol
> table to tell the address is in microMIPS or MIPS16, and GDB can't find
> a symbol for a given address, I suppose we need to create a fake
> symbol, and pass it to disassembler.  Why don't we teach GDB
> unconditionally create a fake symbol with the right bits set in order to
> meet the check in mips-dis.c:is_compressed_mode_p?
> arm-tdep.c:gdb_print_insn_arm has already do so to disassemble Thumb
> instructions.

 We also need symbols for other purposes, specifically telling code and 
data apart in PLT entries, jump tables and constant pools, so a fake 
symbol won't address all cases.  Ideally we'd present output corresponding 
to that produced with `objdump -d', with a way for the user to request 
`objdump -D' equivalent if disassembly of what is supposed to be data is 
required.

> What do you think of the patch below?  IMO, change in
> is_compressed_mode_p fixes a bug on usage of info->num_symbols vs.
> info->symtab_size.  I can't test this patch.

 There is no bug, as it's `info->num_symbols' that tells the disassembler 
the number of symbols starting from `info->symtab_pos' in the symbol table 
affecting the location requested.  Any further symbols are irrelevant (the 
symbol table is sorted by the increasing address, so those will be beyond 
the location disassembled).  You also need to set `info->num_symbols' to 1 
if you're only passing a single symbol in the first place; it's a part of 
this internal API.

 The setting of BSF_SYNTHETIC might be dangerous as code elsewhere assumes 
it's only set for PLT symbols.  Right now it affects `is_mips16_plt_tail', 
causing it to crash, because with your change `asym.section' remains null 
and that function effectively accesses `asym.section->vma'.  I feel uneasy 
about papering it over by adding a check for the section being non-null 
there, I think we need to look for a better solution as this is getting 
too fragile IMO.

 So given that this is a grave regression I think short-term we just need 
to remove the offending assertion checks.

 NB for the purpose of validation I have now bisected the actual 
regression to commit 6394c606997f ("Don't use print_insn_XXX in GDB"), 
rather than commit 39503f82427e ("Delegate opcodes to select disassembler 
in GDB") where the assertion check has been introduced.  There is also 
commit 003ca0fd2286 ("Refactor disassembler selection") on the opcodes' 
side, causing assertion failures triggering once the checks in GDB have 
been removed.  I'll be following up with a fix right away.

 Also in the course of this investigation I have discovered a grave 
regression in compressed breakpoint handling.  I'll be posting a fix 
separately.

  Maciej


  reply	other threads:[~2017-08-01 16:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-16 10:49 [PATCH 0/6] Unify the disassembler selection in gdb and objdump Yao Qi
2017-05-16 10:48 ` [PATCH 4/6] Use disassble.c:disassembler select rl78 disassembler Yao Qi
2017-05-16 10:48 ` [PATCH 5/6] Use disassble.c:disassembler select rs6000 disassembler Yao Qi
2017-05-16 10:48 ` [PATCH 2/6] Delegate opcodes to select disassembler in GDB Yao Qi
2017-06-30  0:19   ` Maciej W. Rozycki
2017-06-30  7:38     ` Yao Qi
2017-07-05 23:53       ` Maciej W. Rozycki
2017-07-07 16:41         ` Yao Qi
2017-08-01 16:31           ` Maciej W. Rozycki [this message]
2017-05-16 10:49 ` [PATCH 3/6] Use disassble.c:disassembler select h8300 disassembler Yao Qi
2017-05-16 10:49 ` [PATCH 1/6] Refactor disassembler selection Yao Qi
2017-05-16 10:49 ` [RFC 6/6] Move print_insn_XXX to an opcodes internal header Yao Qi
2017-05-17  3:00 ` [PATCH 0/6] Unify the disassembler selection in gdb and objdump Alan Modra
2017-05-24 16:26   ` Yao Qi
2017-05-23  9:19 ` Pedro Alves

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=alpine.DEB.2.00.1707071750060.3339@tp.orcam.me.uk \
    --to=macro@imgtec.com \
    --cc=binutils@sourceware.org \
    --cc=gdb-patches@sourceware.org \
    --cc=qiyaoltc@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