[PATCH 0/1] Handle printing pointer modifiers correctly

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

 



As I said in previous messages, I have become a huge fan of pahole. I've
been working with it rather closely and noticed some, well, oddities in
how pointer modifiers are printed and wanted to help by attempting to
provide a fix. 

Assume that we have a C (named, say, modifier.c) with the contents:

struct S {
  volatile int * volatile W;
  const int * const X;
  const int * volatile Y;
  volatile int * const Z;
  int ** const A;
  int * const * B;
  int * volatile * C;
  const int * volatile * D;
};

struct S global_s;

int main() {
	return 0;
}

If we compile it with
gcc -gbtf -g -O0 -o modifier modifier.c

... we can ask what gdb thinks about the types:

$ gdb modifier
(gdb) ptype global_s
type = struct S {
    volatile int * volatile W;
    const int * const X;
    const int * volatile Y;
    volatile int * const Z;
    int ** const A;
    int * const *B;
    int * volatile *C;
    const int * volatile *D;
}

With pahole (compiled from master), we get the following output:
$ ../build/pahole -F btf --compile modifier
struct S {
	volatile volatile int  *   W;                    /*     0     8 */
	const const int  *         X;                    /*     8     8 */
	volatile const int  *      Y;                    /*    16     8 */
	const volatile int  *      Z;                    /*    24     8 */
	const int * *              A;                    /*    32     8 */
	int * const *              B;                    /*    40     8 */
	volatile int *  *          C;                    /*    48     8 */
	volatile const int  *  *   D;                    /*    56     8 */

	/* size: 64, cachelines: 1, members: 8 */
};

$ ../build/pahole -F dwarf --compile modifier
struct S {
	volatile volatile int  *   W;                    /*     0     8 */
	const const int  *         X;                    /*     8     8 */
	volatile const int  *      Y;                    /*    16     8 */
	const volatile int  *      Z;                    /*    24     8 */
	const int * *              A;                    /*    32     8 */
	int * const *              B;                    /*    40     8 */
	volatile int *  *          C;                    /*    48     8 */
	volatile const int  *  *   D;                    /*    56     8 */

	/* size: 64, cachelines: 1, members: 8 */
};

This is not quite right. With the fix (attached) applied, we instead get
output that looks arguably correct:

$ ../build/pahole -F btf --compile modifier
struct S {
	volatile int  * volatile   W;                    /*     0     8 */
	const int  * const         X;                    /*     8     8 */
	const int  * volatile      Y;                    /*    16     8 */
	volatile int  * const      Z;                    /*    24     8 */
	int * * const              A;                    /*    32     8 */
	int * const  *             B;                    /*    40     8 */
	int * volatile  *          C;                    /*    48     8 */
	const int  * volatile  *   D;                    /*    56     8 */

	/* size: 64, cachelines: 1, members: 8 */
};

$ ../build/pahole -F dwarf --compile modifierstruct S {
	volatile int  * volatile   W;                    /*     0     8 */
	const int  * const         X;                    /*     8     8 */
	const int  * volatile      Y;                    /*    16     8 */
	volatile int  * const      Z;                    /*    24     8 */
	int * * const              A;                    /*    32     8 */
	int * const  *             B;                    /*    40     8 */
	int * volatile  *          C;                    /*    48     8 */
	const int  * volatile  *   D;                    /*    56     8 */

	/* size: 64, cachelines: 1, members: 8 */
};

I hope that this is helpful.

If the patch is useful but needs changes, please let me know! I would be
glad to make any changes to fit the codebase.

Thank you for all that you do to keep pahole going!

Will


Will Hawkins (1):
  dwarves_fprintf: Handle pointer modifiers correctly

 dwarves_fprintf.c | 57 ++++++++++++++---------------------------------
 1 file changed, 17 insertions(+), 40 deletions(-)

-- 
2.45.2





[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux