This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ping: [gcc patch] libcc1: '@' GDB array operator


On Thu, Jun 04, 2015 at 10:36:46AM +0200, Manuel López-Ibáñez wrote:
> On 4 June 2015 at 09:36, Jan Kratochvil <jan.kratochvil@redhat.com> wrote:
> > On Thu, 04 Jun 2015 09:24:36 +0200, Manuel López-Ibáñez wrote:
> >> On 3 June 2015 at 22:58, Jan Kratochvil <jan.kratochvil@redhat.com> wrote:
> > These two expressions are equivalent for all operations except of sizeof():
> >         pointer
> >         (*pointer@ANYTHING)
> >
> 
> Sure, but is this case really that important? After all, the user can
> type just 'pointer' and in this case @ANYTHING does not matter at all.
> In the case of sizeof(), the user can also use sizeof(*pointer) *
> ANYTHING.
> 
> Moreover, one can always do:
> 
> (gdb) p a[0]@5
> $10 = "somet"
> (gdb) p $10 + 5
> $11 = 0x80484c5 <a+5> "ignoeisopjffaldjkñfqñlkjfel"
> 
> My understanding is that there is nothing one can get by means of @
> that one cannot get with standard C, except for printing a memory
> region, and for that purpose one only needs to parse LHS@RHS and only
> one @ makes sense within the same print command. Again, I may be
> unaware of other uses of @, but no case shown so far has convinced me
> otherwise.

Even for printing, can't you just use a standard C/C++ construct instead
(perhaps violating aliasing rule, but that shouldn't be an issue in gdb)?

int
main ()
{
  int a[] = { 1, 2, 3, 4, 5 };
  char b[] = "abcdefg";
  return 0;
}

(gdb) p *(int (*)[4])&a[0]
$1 = {1, 2, 3, 4}
(gdb) p *(char (*)[4])&b[1]
$2 = "bcde"

Though, admittedly that is more typing than a[0]@4 or b[1]@4 .
If you want to parse @, supposedly you want to transform it during parsing
to the taking address, cast to pointer to an array and finally
dereferencing, perhaps with ref_all pointer.

	Jakub


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