Re: [patch] ia64: Fix breakpoints memory shadow

Jan Kratochvil
2008-10-30T22:06:52Z

Hi Joel,

On Wed, 29 Oct 2008 22:02:42 +0100, Joel Brobecker wrote:
> I understand the overall idea, but I don't understand the logic behind
> saving BUNDLE_LEN - 2 bytes (14 bytes, then) of the bundle at bundle
> address + slotnum. It looks like this introduces extra complexity.
>
> Instead, would it be possible to save the entire bundle, when
> inserting the breakpoint? When comes time to remove it, we would
> only need to read the whole bundle, extract the original insn from
> our saved bundle, and then push it back into the target bundle.

I agree your proposal would be better but we have to comply with the current
`struct bp_target_info' layout which is being intepreted outside of
ia64-tdep.c - in breakpoint_restore_shadows.

If we would like to store the whole bundle to SHADOW_CONTENTS we would have to
store already the base address (`address & ~0x0f') into PLACED_ADDRESS. In
such case there is no other place where to store SLOTNUM (`adress & 0x0f',
value in the range <0..2>). We need to know SLOTNUM in
ia64_memory_remove_breakpoint.

ia64 16-byte bundle layout:
| 5 bits | slot 0 with 41 bits | slot 1 with 41 bits | slot 2 with 41 bits |

(A) The current way of the patch:
original PC placed_address placed_size required covered
== bp_tgt->shadow_len required \subset covered
0xABCDE0 0xABCDE0 0xE <0x0...0x5> <0x0..0xD>
0xABCDE1 0xABCDE1 0xE <0x5...0xA> <0x1..0xE>
0xABCDE2 0xABCDE2 0xE <0xA...0xF> <0x2..0xF>

(B) Another way would be (converting `original PC' -> `placed_address' in
ia64_breakpoint_from_pc):
original PC placed_address placed_size required covered
== bp_tgt->shadow_len
0xABCDE0 0xABCDE0 0x6 <0x0...0x5> <0x0..0x5>
0xABCDE1 0xABCDE5 0x6 <0x5...0xA> <0x5..0xA>
0xABCDE2 0xABCDEA 0x6 <0xA...0xF> <0xA..0xF>

`objdump -d' and some other tools show a bit unjustified offsets:
original PC byte where starts the instruction objdump offset
0xABCDE0 0xABCDE0 0xABCDE0
0xABCDE1 0xABCDE5 0xABCDE6
0xABCDE2 0xABCDEA 0xABCDEC

I can freely change the current (A) way for (B) but I found the code easier
this way. (B) would be more minimal/effective but sure it does not matter.

> > +# We need to start the inferior to place the breakpoints in the memory at all.
> > +if { [gdb_start_cmd] < 0 } {
> > + untested start
> > + return -1
> > +}
> > +gdb_test "" "main \\(\\) at .*" "start"
>
> Why not use runto_main here?

I will change it in the final patch together with a note in gdb.base/start.exp
that it is there to test gdb_start_cmd, not to start a program.

Thanks,
Jan