This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: ping: [gcc patch] libcc1: '@' GDB array operator
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Manuel López-Ibáñez <lopezibanez at gmail dot com>
- Cc: Jan Kratochvil <jan dot kratochvil at redhat dot com>, Jeff Law <law at redhat dot com>, Gcc Patch List <gcc-patches at gcc dot gnu dot org>, Phil Muldoon <pmuldoon at redhat dot com>, Alexandre Oliva <aoliva at redhat dot com>, Tom Tromey <tom at tromey dot com>
- Date: Thu, 4 Jun 2015 10:55:59 +0200
- Subject: Re: ping: [gcc patch] libcc1: '@' GDB array operator
- Authentication-results: sourceware.org; auth=none
- References: <556F430F dot 7060807 at gmail dot com> <556F155C dot 1030300 at redhat dot com> <20150603205742 dot GA5676 at host1 dot jankratochvil dot net> <CAESRpQBK-DgFLe+NM6OrVZ3LuRMH50XyTwHu4XM6wJaQvKks_w at mail dot gmail dot com> <20150604073608 dot GA1294 at host1 dot jankratochvil dot net> <CAESRpQB5nTe_zdkOy1LSOVdd-Ws=oJ2DW4UcHt0gY_aGLVhy7w at mail dot gmail dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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