This is the mail archive of the gdb-patches@sourceware.cygnus.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: RFA: print addresses that are longer than pointers, take two


On Apr 27,  1:01pm, Jim Blandy wrote:

> This also rewrites the mask generation in a way which I think is
> overflow-free, without needing to pull the wool over the compiler's
> eyes.
[...]
> ! 	if (TYPE_CODE (type) != TYPE_CODE_PTR)
> ! 	  /* When building the mask, avoid shifts larger or equal than
> ! 	       the width of a CORE_ADDR.  */
> ! 	  addr &= ((((CORE_ADDR) 1 << (TARGET_PTR_BIT - 1)) - 1) << 1) + 1;

It's not really the compiler that needs the wool pulled over it's eyes,
it's the architecture.  Shift instructions are notorious for
behaving differently on different architectures when presented with
shift operands that are out of bounds.

E.g, on ia32, if you do

  long val = 1;
  int shift = 33;
  long result = val << shift;

the value of ``result'' is 2.  Whereas on PowerPC, the value of ``result''
is 0.

For this reason, my first thought was that your code could have
problems.  But after thinking about it a some more I remembered that
it is a fundamental assumption in gdb that the length in bits of a
CORE_ADDR is greater than or equal to TARGET_PTR_BIT.  Which means
that the amount being shifted will never be greater or equal to the
length of bits in a CORE_ADDR.  (I like the sneaky way that you
subtract 1 from TARGET_PTR_BIT to narrowly avoid the problem.)

I'm not the maintainer of this code, but it looks okay to me.

Kevin

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]