This is the mail archive of the gdb-patches@sourceware.org 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]
Other format: [Raw text]

Re: [RFA] ax-gdb: Do not treat enums and bools as integers.


>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:

Joel> But the reason why GDB decides to use a 32bit extension is because
Joel> it overrides the symbol's type with a plain integer type in
Joel> ax-gdb.c:gen_usual_unary...

FWIW you can see the bug from C, if you make an enum type and then
compile with -fshort-enums (which IIRC is the default for some targets).

Then:

    (gdb) maintenance agent-eval e
    Scope: 0x400478
    Reg mask: 00
      0  const32 6293576
      5  ref8
      6  end

Here the 'ref8' is correct -- 'e' is a 1-byte variable.

But:

    (gdb) maintenance agent-eval e + 1
    Scope: 0x400478
    Reg mask: 00
      0  const32 6293576
      5  ref32
      6  ext 32
      8  const8 1
     10  add
     11  ext 32
     13  end

Whoops, how did that ref32 get there?

Joel>         * ax-gdb.c (gen_usual_unary): Remove special handling of
Joel>         enum and bool types.

I think it is correct.


Also, I think you can make a test case like this:

    enum EE {
      VALUE = 1
    };

    struct x {
      unsigned char before;
      enum EE e;
      unsigned char after;
    };

    struct x global;

    int main () { } 

Compile with -fshort-enums.

Then:

    (gdb) maint agent-eval global.e + 1
    Scope: 0x400478
    Reg mask: 00
      0  const32 6293576
      5  const8 1
      7  add
      8  ref32
      9  ext 32
     11  const8 1
     13  add
     14  ext 32
     16  end

So, I think you could provoke the wrong answer by setting 'after' to
some non-zero value.

Tom


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