emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GDB and compiler-operations


From: Tom Tromey
Subject: Re: GDB and compiler-operations
Date: Fri, 07 Sep 2018 13:59:41 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.50 (gnu/linux)

>>>>> "Stefan" == Stefan Monnier <address@hidden> writes:

Stefan> Along the way I discovered that while `sizeof` works great, `offsetof`
Stefan> gives me an error:
Stefan>     No symbol "offsetof" in current context.
Stefan> any idea why this is (and how to fix it)?

Other people answered the why.  To fix it you have two options.

One, define an offsetof macro:

(gdb) macro define offsetof(type, field) ((int) (((type *) 0)->field))

The gdb C expression parser will automatically use macros you define
interactively.


Two, instead of using offsetof to inspect a type, upgrade to a newish
(8.1 or better) gdb and use "ptype/o":

    (gdb) ptype/o struct Lisp_Vector
    /* offset    |  size */  type = struct Lisp_Vector {
    /*    0      |     8 */    union vectorlike_header {
    /*                 8 */        ptrdiff_t size;
    /*                 1 */        char gcaligned;

                                   /* total size (bytes):    8 */
                               } header;
    /*    8      |     0 */    Lisp_Object contents[];

                               /* total size (bytes):    8 */
                             }

The output here is modeled on the pahole utility.

If you can't upgrade gdb, there's a "pahole.py" script out there that
adds a pahole command to gdb instead.  I can email it if you really
need it, but some distros installed it by default.  So you could just
try "(gdb) pahole struct Lisp_Vector".

Tom



reply via email to

[Prev in Thread] Current Thread [Next in Thread]