Commit Graph

1115 Commits

Author SHA1 Message Date
Martin KaFai Lau 68645f7fac btf: Add BTF support
This patch introduces BPF Type Format (BTF).

BTF (BPF Type Format) is the meta data format which describes
the data types of BPF program/map.  Hence, it basically focus
on the C programming language which the modern BPF is primary
using.  The first use case is to provide a generic pretty print
capability for a BPF map.

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-07-25 14:42:06 -03:00
Arnaldo Carvalho de Melo 81466af0d4 pahole: Show the file where a struct was used
To help with using just that object file, avoiding processing big files
such as vmlinux, e.g.:

  $ pahole -I vmlinux
<SNIP>
  /* Used at: /home/acme/git/perf/init/main.c */
  /* <1f4a5> /home/acme/git/perf/arch/x86/include/asm/orc_types.h:85 */
  struct orc_entry {
          s16                        sp_offset;            /*     0     2 */
          s16                        bp_offset;            /*     2     2 */
          unsigned int               sp_reg:4;             /*     4:28  4 */
          unsigned int               bp_reg:4;             /*     4:24  4 */
          unsigned int               type:2;               /*     4:22  4 */

          /* size: 6, cachelines: 1, members: 5 */
          /* padding: 65534 */
          /* bit_padding: 22 bits */
          /* last cacheline: 6 bytes */

          /* BRAIN FART ALERT! 6 != 8 + 0(holes), diff = -2 */
  };
<SNIP>

So I noticed that BFA, need to work on it, to make the testing process
faster, better not process vmlinux.o, instead, do:

  $ pahole -C orc_entry ${kernel_build_dir}/init/main.o

Much faster, as main.o is much smaller than the vmlinux file.

Now to fix the processing of 'struct orc_entry'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-12-15 15:30:38 -03:00
Arnaldo Carvalho de Melo 2dd87be78b dwarves_fprintf: Show offsets at union members
In complex structs with multiple complex unions figuring out the offset
for a given union member is difficult, as one needs to figure out the
union, go to the end of it to see the offset.

So just turn struct_member__fprintf() into class_member__fprintf() and
pass a 'union_member' boolean to share all the aspects of struct and
union members, just not advancing the offset when processing union
members.

This way, for instance, the Linux kernel's 'struct page' goes from:

struct page {
	long unsigned int          flags;                /*     0     8 */
	union {
		struct address_space * mapping;          /*     8     8 */
		void *             s_mem;                /*     8     8 */
		atomic_t           compound_mapcount;    /*     8     4 */
	};                                               /*     8     8 */
	union {
		long unsigned int  index;                /*    16     8 */
		void *             freelist;             /*    16     8 */
	};                                               /*    16     8 */
	union {
		long unsigned int  counters;             /*    24     8 */
		struct {
			union {
				atomic_t _mapcount;      /*    24     4 */
				unsigned int active;     /*    24     4 */
				struct {
					unsigned int inuse:16; /*    24:16  4 */
					unsigned int objects:15; /*    24: 1  4 */
					unsigned int frozen:1; /*    24: 0  4 */
				};                       /*    24     4 */
				int units;               /*    24     4 */
			};                               /*    24     4 */
			atomic_t   _refcount;            /*    28     4 */
		};                                       /*    24     8 */
	};                                               /*    24     8 */
	union {
		struct list_head   lru;                  /*    32    16 */
		struct dev_pagemap * pgmap;              /*    32     8 */
		struct {
			struct page * next;              /*    32     8 */
			int        pages;                /*    40     4 */
			int        pobjects;             /*    44     4 */
		};                                       /*    32    16 */
		struct callback_head callback_head;      /*    32    16 */
		struct {
			long unsigned int compound_head; /*    32     8 */
			unsigned int compound_dtor;      /*    40     4 */
			unsigned int compound_order;     /*    44     4 */
		};                                       /*    32    16 */
		struct {
			long unsigned int __pad;         /*    32     8 */
			pgtable_t  pmd_huge_pte;         /*    40     8 */
		};                                       /*    32    16 */
	};                                               /*    32    16 */
	union {
		long unsigned int  private;              /*    48     8 */
		spinlock_t         ptl;                  /*    48     4 */
		struct kmem_cache * slab_cache;          /*    48     8 */
	};                                               /*    48     8 */
	struct mem_cgroup *        mem_cgroup;           /*    56     8 */

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

To:

struct page {
	long unsigned int          flags;                /*     0     8 */
	union {
		struct address_space * mapping;          /*     8     8 */
		void *             s_mem;                /*     8     8 */
		atomic_t           compound_mapcount;    /*     8     4 */
	};                                               /*     8     8 */
	union {
		long unsigned int  index;                /*    16     8 */
		void *             freelist;             /*    16     8 */
	};                                               /*    16     8 */
	union {
		long unsigned int  counters;             /*    24     8 */
		struct {
			union {
				atomic_t _mapcount;      /*    24     4 */
				unsigned int active;     /*    24     4 */
				struct {
					unsigned int inuse:16; /*    24:16  4 */
					unsigned int objects:15; /*    24: 1  4 */
					unsigned int frozen:1; /*    24: 0  4 */
				};                       /*    24     4 */
				int units;               /*    24     4 */
			};                               /*    24     4 */
			atomic_t   _refcount;            /*    28     4 */
		};                                       /*    24     8 */
	};                                               /*    24     8 */
	union {
		struct list_head   lru;                  /*    32    16 */
		struct dev_pagemap * pgmap;              /*    32     8 */
		struct {
			struct page * next;              /*    32     8 */
			int        pages;                /*    40     4 */
			int        pobjects;             /*    44     4 */
		};                                       /*    32    16 */
		struct callback_head callback_head;      /*    32    16 */
		struct {
			long unsigned int compound_head; /*    32     8 */
			unsigned int compound_dtor;      /*    40     4 */
			unsigned int compound_order;     /*    44     4 */
		};                                       /*    32    16 */
		struct {
			long unsigned int __pad;         /*    32     8 */
			pgtable_t  pmd_huge_pte;         /*    40     8 */
		};                                       /*    32    16 */
	};                                               /*    32    16 */
	union {
		long unsigned int  private;              /*    48     8 */
		spinlock_t         ptl;                  /*    48     4 */
		struct kmem_cache * slab_cache;          /*    48     8 */
	};                                               /*    48     8 */
	struct mem_cgroup *        mem_cgroup;           /*    56     8 */

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

Suggested-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-12-15 13:33:10 -03:00
Arnaldo Carvalho de Melo 66cf3983e1 README.DEBUG: Add an extra step to make the instructions cut'n'exec
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-12-14 14:15:54 -03:00
Arnaldo Carvalho de Melo 2a092d6145 dwarves: Fix cus__load_files() success return value
If we processed at least one file we should return 0 to mean success.

Fixes: 02a456f5f5 ("pahole: Search and use running kernel vmlinux when no file is passed")
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-12-14 14:14:56 -03:00
Arnaldo Carvalho de Melo 02a456f5f5 pahole: Search and use running kernel vmlinux when no file is passed
Seems like a nice shortcut for kernel hackers, and one that makes sure
the right vmlinux file is used, as it reads the running kernel build id
from /sys/kernel/notes and then searches the well known path for vmlinux
files:

vmlinux
/boot/vmlinux
/boot/vmlinux-4.14.0+
/usr/lib/debug/boot/vmlinux-`uname -r`
/lib/modules/`uname -r`/build/vmlinux
/usr/lib/debug/lib/modules/`uname -r`/vmlinux
/usr/lib/debug/boot/vmlinux-`uname -r`.debug

To find one with a matching build id (.notes ELF section, then
nhdr->n_type == NT_GNU_BUILD_ID), just like the Linux kernel 'perf
tools', where this code comes from, with some minor modifications to
cope with not having symbol_conf, symfs, etc.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-11-24 11:24:16 -03:00
Arnaldo Carvalho de Melo 5f057919a0 man-pages: Add entry for --hex
Flavio needed this and found it only after some head scratching, add it.

Someone could help here by looking at other missing entries in the man
page, getting it in synch with 'pahole --help' ;-)

Reported-by: Flavio Leitner <fbl@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-09-05 10:13:06 -03:00
Arnaldo Carvalho de Melo 4f34f23413 v1.11 - New Release
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-06-28 16:03:46 -03:00
Arnaldo Carvalho de Melo 5a57eb0741 man-pages: Update URL to the dwarves paper
The ghostprotocols.net domain is busted for a while, point to the
more permanent OLS proceedings pdf hosted at kernel.org.

Reported-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-02-01 10:42:59 -03:00
Arnaldo Carvalho de Melo b52386d041 dwarves_fprintf: Find holes when expanding types
When --expand_types/-E is used we go on expanding internal types, and
when doing that for structs we were not looking for holes in them, only
on the main struct, fix it.

With that we can see these extra holes in a expanded Linux kernel's
'struct task_struct':

@@ -46,6 +46,9 @@
 			struct list_head * prev;                                         /*   176     8 */
 		} group_node; /*   168    16 */
 		unsigned int       on_rq;                                                /*   184     4 */
+
+		/* XXX 4 bytes hole, try to pack */
+
 		/* --- cacheline 3 boundary (192 bytes) --- */
 		/* typedef u64 */ long long unsigned int exec_start;                     /*   192     8 */
 		/* typedef u64 */ long long unsigned int sum_exec_runtime;               /*   200     8 */
@@ -86,9 +89,15 @@
 		} statistics; /*   232   216 */
 		/* --- cacheline 7 boundary (448 bytes) --- */
 		int                depth;                                                /*   448     4 */
+
+		/* XXX 4 bytes hole, try to pack */
+
 		struct sched_entity * parent;                                            /*   456     8 */
 		struct cfs_rq *    cfs_rq;                                               /*   464     8 */
 		struct cfs_rq *    my_q;                                                 /*   472     8 */
+
+		/* XXX 32 bytes hole, try to pack */
+
 		/* --- cacheline 8 boundary (512 bytes) --- */
 		struct sched_avg {
 			/* typedef u64 */ long long unsigned int last_update_time;       /*   512     8 */
@@ -153,6 +162,9 @@
 			struct hrtimer_clock_base * base;                                /*   768     8 */
 			/* typedef u8 */ unsigned char state;                            /*   776     1 */
 			/* typedef u8 */ unsigned char is_rel;                           /*   777     1 */
+
+			/* XXX 2 bytes hole, try to pack */
+
 			int        start_pid;                                            /*   780     4 */
 			void *     start_site;                                           /*   784     8 */
 			char       start_comm[16];                                       /*   792    16 */
@@ -197,6 +209,9 @@
 	} tasks; /*   912    16 */
 	struct plist_node {
 		int                prio;                                                 /*   928     4 */
+
+		/* XXX 4 bytes hole, try to pack */
+
 		struct list_head {
 			struct list_head * next;                                         /*   936     8 */
 			struct list_head * prev;                                         /*   944     8 */
@@ -258,12 +273,18 @@
 				/* typedef u32 */ unsigned int val;                      /*  1136     4 */
 				/* typedef u32 */ unsigned int flags;                    /*  1140     4 */
 				/* typedef u32 */ unsigned int bitset;                   /*  1144     4 */
+
+				/* XXX 4 bytes hole, try to pack */
+
 				/* --- cacheline 18 boundary (1152 bytes) --- */
 				/* typedef u64 */ long long unsigned int time;           /*  1152     8 */
 				u32 * uaddr2;                                            /*  1160     8 */
 			} futex;                                                         /*          40 */
 			struct {
 				/* typedef clockid_t -> __kernel_clockid_t */ int clockid; /*  1128     4 */
+
+				/* XXX 4 bytes hole, try to pack */
+
 				struct timespec * rmtp;                                  /*  1136     8 */
 				struct compat_timespec * compat_rmtp;                    /*  1144     8 */
 				/* typedef u64 */ long long unsigned int expires;        /*  1152     8 */
@@ -426,6 +447,9 @@
 	unsigned int               sessionid;                                            /*  1804     4 */
 	struct seccomp {
 		int                mode;                                                 /*  1808     4 */
+
+		/* XXX 4 bytes hole, try to pack */
+
 		struct seccomp_filter * filter;                                          /*  1816     8 */
 	} seccomp; /*  1808    16 */
 	/* typedef u32 */ unsigned int               parent_exec_id;                     /*  1824     4 */
@@ -602,6 +626,9 @@
 		long unsigned int  backtrace[12];                                        /*  2472    96 */
 		/* --- cacheline 40 boundary (2560 bytes) was 8 bytes ago --- */
 		unsigned int       count;                                                /*  2568     4 */
+
+		/* XXX 4 bytes hole, try to pack */
+
 		long unsigned int  time;                                                 /*  2576     8 */
 		long unsigned int  max;                                                  /*  2584     8 */
 	} latency_record[32]; /*  2472  3840 */
@@ -686,12 +713,18 @@
 		long unsigned int * io_bitmap_ptr;                                       /*  6600     8 */
 		long unsigned int  iopl;                                                 /*  6608     8 */
 		unsigned int       io_bitmap_max;                                        /*  6616     4 */
+
+		/* XXX 36 bytes hole, try to pack */
+
 		/* --- cacheline 104 boundary (6656 bytes) --- */
 		struct fpu {
 			unsigned int last_cpu;                                           /*  6656     4 */
 			unsigned char fpstate_active;                                    /*  6660     1 */
 			unsigned char fpregs_active;                                     /*  6661     1 */
 			unsigned char counter;                                           /*  6662     1 */
+
+			/* XXX 57 bytes hole, try to pack */
+
 			/* --- cacheline 105 boundary (6720 bytes) --- */
 			union fpregs_state {
 				struct fregs_state {
@@ -751,6 +784,9 @@
 					/* typedef u8 */ unsigned char no_update;        /*  6831     1 */
 					/* typedef u8 */ unsigned char rm;               /*  6832     1 */
 					/* typedef u8 */ unsigned char alimit;           /*  6833     1 */
+
+					/* XXX 6 bytes hole, try to pack */
+
 					struct math_emu_info * info;                     /*  6840     8 */
 					/* typedef u32 */ unsigned int entry_eip;        /*  6848     4 */
 				} soft; /*         136 */

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-06-30 16:30:28 -03:00
Arnaldo Carvalho de Melo 103e89bb25 dwarves_fprintf: Find holes on structs embedded in other structs
Take 'struct task_struct' in the Linux kernel, these fields:

        /* --- cacheline 2 boundary (128 bytes) --- */
        struct sched_entity        se;                   /*   128   448 */

        /* XXX last struct has 24 bytes of padding */

        /* --- cacheline 9 boundary (576 bytes) --- */
        struct sched_rt_entity     rt;                   /*   576    48 */

The sched_entity struct has 24 bytes of padding, and that info would
only appear when printing 'struct task_struct' if class__find_holes()
had previously been run on 'struct sched_entity' which wasn't always the
case, make sure that happens.

This results in this extra stat being printed for 'struct task_struct':

	/* paddings: 4, sum paddings: 38 */

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-06-30 16:18:11 -03:00
Arnaldo Carvalho de Melo ab97c07a7e dwarves_fprintf: Fixup cacheline boundary printing on expanded structs
A diff for 'pahole -EC task_struct vmlinux' should clarify what this fixes:

  [acme@jouet linux]$ diff -u /tmp/before.c /tmp/after.c | head -30
  --- /tmp/before.c	2016-06-29 17:00:38.082647281 -0300
  +++ /tmp/a.c	2016-06-29 17:03:36.913124779 -0300
  @@ -43,8 +43,8 @@
 			struct list_head * prev;                                         /*   176     8 */
 		} group_node; /*   168    16 */
 		unsigned int       on_rq;                                                /*   184     4 */
  +		/* --- cacheline 3 boundary (192 bytes) --- */
 		/* typedef u64 */ long long unsigned int exec_start;                     /*   192     8 */
  -		/* --- cacheline 1 boundary (64 bytes) was 4 bytes ago --- */
 		/* typedef u64 */ long long unsigned int sum_exec_runtime;               /*   200     8 */
 		/* typedef u64 */ long long unsigned int vruntime;                       /*   208     8 */
 		/* typedef u64 */ long long unsigned int prev_sum_exec_runtime;          /*   216     8 */
  @@ -53,40 +53,40 @@
 			/* typedef u64 */ long long unsigned int wait_start;             /*   232     8 */
 			/* typedef u64 */ long long unsigned int wait_max;               /*   240     8 */
 			/* typedef u64 */ long long unsigned int wait_count;             /*   248     8 */
  +			/* --- cacheline 4 boundary (256 bytes) --- */
 			/* typedef u64 */ long long unsigned int wait_sum;               /*   256     8 */
 			/* typedef u64 */ long long unsigned int iowait_count;           /*   264     8 */
 			/* typedef u64 */ long long unsigned int iowait_sum;             /*   272     8 */
 			/* typedef u64 */ long long unsigned int sleep_start;            /*   280     8 */
 			/* typedef u64 */ long long unsigned int sleep_max;              /*   288     8 */
  -			/* --- cacheline 1 boundary (64 bytes) --- */
 			/* typedef s64 */ long long int sum_sleep_runtime;               /*   296     8 */
 			/* typedef u64 */ long long unsigned int block_start;            /*   304     8 */
 			/* typedef u64 */ long long unsigned int block_max;              /*   312     8 */
  +			/* --- cacheline 5 boundary (320 bytes) --- */
 			/* typedef u64 */ long long unsigned int exec_max;               /*   320     8 */
 			/* typedef u64 */ long long unsigned int slice_max;              /*   328     8 */
 			/* typedef u64 */ long long unsigned int nr_migrations_cold;     /*   336     8 */
  [acme@jouet linux]$

I.e. the boundary detection was being reset at each expanded struct, do the math globally,
using the member offset, that was already done globally and correctly.

Reported-and-Tested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-06-29 17:27:51 -03:00
Arnaldo Carvalho de Melo 046ad67af3 dwarves_fprintf: Shorten class__fprintf() sig
That conf_fprintf can be elided as it is always NULL for the root call,
i.e. only when expanding types is that it will be called recursively.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-06-29 16:19:20 -03:00
Arnaldo Carvalho de Melo 44130bf70e dwarves: Update e-mail address
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-06-28 14:24:41 -03:00
Arnaldo Carvalho de Melo 327757975b dwarf_loader: Add URL for template tags description
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-05-19 10:31:21 -03:00
Arnaldo Carvalho de Melo f4d5e21fd1 dwarf_loader: Tidy up template tags usage
We need to get it under some ifdefs to avoid breaking the build in
distros where these tags are not defined.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-05-19 10:28:59 -03:00
Arnaldo Carvalho de Melo e12bf99999 dwarf_loader: Do not hash unsupported tags
This causes a segfault:

    at /home/teuf/freesoftware/pahole/dwarf_loader.c:141
    at /home/teuf/freesoftware/pahole/dwarf_loader.c:170
    cu=0x66bc70) at /home/teuf/freesoftware/pahole/dwarf_loader.c:1535
    at /home/teuf/freesoftware/pahole/dwarf_loader.c:1552
    fn=0x7ffff79cd160 <__FUNCTION__.8133> "die__process_class")
    at /home/teuf/freesoftware/pahole/dwarf_loader.c:1593
    at /home/teuf/freesoftware/pahole/dwarf_loader.c:1288

We're not supposed to hash those unsupported tags, so just check for it and
avoid hashing.

Reported-by: Christophe Fergeau <cfergeau@redhat.com>
Cc: Dodji Seketeli <dodji@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-05-19 10:23:11 -03:00
Arnaldo Carvalho de Melo 3afcfbec9e dwarf_loader: Add DW_TAG_GNU_formal_parameter_pack stub in process_function
Template support is a big TODO entry...

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-05-19 10:21:17 -03:00
Arnaldo Carvalho de Melo 55d9b20dba dwarf_loader: Ignore DW_TAG_dwarf_procedure when processing functions
We have no use for these location expressions yet...

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-05-19 10:09:06 -03:00
Arnaldo Carvalho de Melo 45618c7ec1 dwarf_loader: Initial support for DW_TAG_unspecified_type
Still need to check what to fprintf for this, but at least have it in
the type lists so that we can find it.

Reported-by: Christophe Fergeau <cfergeau@redhat.com>
Cc: Dodji Seketeli <dodji@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-05-17 10:05:34 -03:00
Arnaldo Carvalho de Melo 658a238b98 dwarf_loader: Stop emitting warnings about DW_TAG_call_site
No tool in this suite has any use for that, so just leave the comments
and pointers to the documentation for these tags and stop bothering the
user.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-05-06 15:20:16 -03:00
Arnaldo Carvalho de Melo 0fbb39291d dwarf_loader: Add support for DW_TAG_restrict_type
I.e. supporting the 'restrict' keyword, emitted by recent compilers:

  [acme@jouet pahole]$ pfunct -P ~/bin/perf |& grep -w restrict
  inline int vprintf(const char  * restrict  __fmt, struct __va_list_tag * __ap);
  inline size_t fread(void * restrict  __ptr, size_t __size, size_t __n, FILE * restrict  __stream);
  inline int vfprintf(FILE * restrict  __stream, const char  * restrict  __fmt, struct __va_list_tag * __ap);
  inline int vasprintf(char * * restrict  __ptr, const char  * restrict  __fmt, struct __va_list_tag * __ap);
  inline char * realpath(const char  * restrict  __name, char * restrict  __resolved);
  inline ssize_t readlink(const char  * restrict  __path, char * restrict  __buf, size_t __len);
  inline char * strcat(char * restrict  __dest, const char  * restrict  __src);
  inline char * fgets(char * restrict  __s, int __n, FILE * restrict  __stream);
  inline int snprintf(char * restrict  __s, size_t __n, const char  * restrict  __fmt, ...);
  inline int sprintf(char * restrict  __s, const char  * restrict  __fmt, ...);
  inline char * strcpy(char * restrict  __dest, const char  * restrict  __src);
  inline int asprintf(char * * restrict  __ptr, const char  * restrict  __fmt, ...);
  inline char * strncpy(char * restrict  __dest, const char  * restrict  __src, size_t __len);
  inline int fprintf(FILE * restrict  __stream, const char  * restrict  __fmt, ...);
  inline int vsnprintf(char * restrict  __s, size_t __n, const char  * restrict  __fmt, struct __va_list_tag * __ap);
  inline int printf(const char  * restrict  __fmt, ...);
  [acme@jouet pahole]$

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-05-06 15:02:17 -03:00
Arnaldo Carvalho de Melo 9df42c6826 dwarves: Initial support for rvalue_reference_type
Need to read more on http://www.artima.com/cppsource/rvalue.html, but
handling it mostly like DW_TAG_typedef so that at least references to it
are resolved, we can get its byte size, etc.

FIXME: look at the vtable parameters, some are resolving to "(null)".

Reported-by: Benjamin Kosnik <bkoz@redhat.com>
Reported-by: Mark Wieelard <mjw@redhat.com>
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=962571
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-03-15 16:37:48 -03:00
Arnaldo Carvalho de Melo 8af5ccd86d dwarves: Use cus__fprintf_load_files_err() in the remaining tools
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-03-15 14:29:57 -03:00
Arnaldo Carvalho de Melo 10515a7c4d dwarves: Introduce cus__fprintf_load_files_err()
Out of code in pdwtags and pahole, will be used in the other tools.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-03-15 14:25:58 -03:00
Arnaldo Carvalho de Melo 0e64636350 pahole: Show more informative message when errno is properly set on error
$ cat foo
  cat: foo: No such file or directory

Before:

  $ pahole foo
  pahole: No debugging information found

After:

  $ pahole foo
  pahole: foo: No such file or directory

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-03-15 12:59:37 -03:00
Arnaldo Carvalho de Melo 2566cc2c87 pdwtags: Show proper error messages for files it can't handle
Before it would print no message, only update its exit status, now:

  $ cat foo
  cat: foo: No such file or directory
  $ pdwtags foo
  pdwtags: foo: No such file or directory
  $ pdwtags /dev/null
  ctf__new: cannot get elf header.
  pdwtags: /dev/null: Invalid argument
  $

Reported-by: Eric Blake <eblake@redhat.com>
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=949034
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-03-15 12:29:38 -03:00
Arnaldo Carvalho de Melo 9f3f67e786 dwarves: Fix cus__load_files() error return
Silly bug, it was trying to return a negative index stating what file
had problems in the provided array, but if the first had problems it was
return -0, duh, fix it by returning the first as 1, etc.

With this, calling 'pdwtags non-existent-file' would return no errors
via $?.

Next csets will provide proper error messages, using what is in errno
and this index to tell what file has problems.

Reported-by: Eric Blake <eblake@redhat.com>
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=949034
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-03-15 12:24:38 -03:00
Arnaldo Carvalho de Melo ae3a2720c3 dutil: Add ____ilog2_NaN declaration to silence compiler warning
To deal with unrepresentable constant logarithms we end up causing a
build error, provide the declaration so that the compiler shut up.

Taken, as the other related code, from the Linux kernel sources.

For reference, the warning:

  [ 40%] Building C object CMakeFiles/dwarves_reorganize.dir/dwarves_reorganize.o
  /home/acme/git/pahole/dwarves_reorganize.c: In function ‘class__demote_bitfields’:
  /home/acme/git/pahole/dwarves_reorganize.c:536:168: warning: implicit declaration of function ‘____ilog2_NaN’ [-Wimplicit-function-declaration]

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-03-15 11:42:16 -03:00
Arnaldo Carvalho de Melo 0b81b5ad47 Update version in CMakeLists.txt
The current release is v1.10, but CMakeLists.txt had just v1.9, fix it.

Reported-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-11-20 12:19:06 -03:00
Arnaldo Carvalho de Melo 79536f4f95 cmake: Use INTERFACE_LINK_LIBRARIES
LINK_INTERFACE_LIBRARIES was deprecated.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-09-16 11:31:40 -03:00
Arnaldo Carvalho de Melo 1decb1bc4a dwarf_loader: Check cu__find_type_by_ref result
In class_member__dwarf_recode_bitfield, making it more robust, as
now we're in the process of supporting DW_TAG_partial_unit, where
some types seem to be in some ther unit and thus not being found
at the moment.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-06-05 15:10:39 -03:00
Arnaldo Carvalho de Melo 956343d05a Add instructions on how to build with debug info
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-06-02 16:04:04 -03:00
Arnaldo Carvalho de Melo e71353c3fa dwarf_loader: Ignore DW_TAG_dwarf_procedure
It just about having a location expression that is referenced by other
tags to save space, since we don't have use for loc exprs so far, just
ignore it instead of spamming the user with "tag not supported"
warnings.

First seen on binaries generated by gcc 4.9

Reported-by: Diego Elio Pettenò <flameeyes@flameeyes.eu>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2014-11-19 18:15:26 -03:00
Arnaldo Carvalho de Melo 1896959072 dwarves_fprintf: Add the missing GNU_ suffix to DWARF_TAG_ created by the GNU project
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2014-11-19 18:07:50 -03:00
Arnaldo Carvalho de Melo d973b1d5da dwarf_fprintf: Handle DW_TAG_GNU_call_site{_parameter}
Reported-by: Diego Elio Pettenò <flameeyes@flameeyes.eu>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2014-11-19 18:06:41 -03:00
Arnaldo Carvalho de Melo c23eab4b12 dwarf_loader: Print unknown tags as an hex number
So that we can look up at /usr/include/dwarf.h for new tags, like.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2014-11-19 17:51:11 -03:00
Mark Wielaard 943a0de067 dwarves_fprintf: DW_TAG_mutable_type doesn't exist.
DW_TAG_mutable_type was a mistake in an early DWARFv3 draft and was
removed in the final version.

http://dwarfstd.org/ShowIssue.php?issue=050223.1

Signed-off-by: Mark Wielaard <mjw@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2014-07-03 12:34:48 -03:00
Masatake YAMATO a8e562a157 dwarf_loader: Use obstack_zalloc when allocating tag
obstack_alloc was used in __tag__alloc to allocate tag object. As the
result some fields of the tag object are not initialized.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2014-07-03 12:32:16 -03:00
Arnaldo Carvalho de Melo fd3838ae9a dwarves: Stop using 'self'
As Thomas Gleixner wisely pointed out, using 'self' is stoopid, it
doesn't convey useful information, so use sensible names

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2014-01-06 16:46:50 -03:00
Arnaldo Carvalho de Melo 5ecf1aab9e dwarf_loader: Support DW_FORM_data{4,8} for reading class member offsets
Finally found really _large_ structs, like this one in the Linux kernel:

[acme@zoo pahole]$ pahole -C cmp_data /home/acme/git/build/v3.11.0-rc3+/kernel/power/swap.o
struct cmp_data {
	struct task_struct *       thr;                  /*     0     8 */
	atomic_t                   ready;                /*     8     4 */
	atomic_t                   stop;                 /*    12     4 */
	int                        ret;                  /*    16     4 */

	/* XXX 4 bytes hole, try to pack */

	wait_queue_head_t          go;                   /*    24    24 */
	wait_queue_head_t          done;                 /*    48    24 */
	/* --- cacheline 1 boundary (64 bytes) was 8 bytes ago --- */
	size_t                     unc_len;              /*    72     8 */
	size_t                     cmp_len;              /*    80     8 */
	unsigned char              unc[131072];          /*    88 131072 */
	/* --- cacheline 2049 boundary (131136 bytes) was 24 bytes ago --- */
	unsigned char              cmp[143360];          /* 131160 143360 */
	/* --- cacheline 4289 boundary (274496 bytes) was 24 bytes ago --- */
	unsigned char              wrk[16384];           /* 274520 16384 */
	/* --- cacheline 4545 boundary (290880 bytes) was 24 bytes ago --- */

	/* size: 290904, cachelines: 4546, members: 11 */
	/* sum members: 290900, holes: 1, sum holes: 4 */
	/* last cacheline: 24 bytes */
};

The last two members have offsets that takes more than a u16, using
DW_FORM_data4. For extra future proof reasons, add DW_FORM_data8 too ;-)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2013-08-15 15:06:48 -03:00
Arnaldo Carvalho de Melo c4ccdd5ae6 dwarves_reorganize: Fix member type fixup
See the patch itself for the explanation.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2013-08-15 14:56:22 -03:00
Arnaldo Carvalho de Melo e31fda3063 dwarves_reorganize: Fixup calculation of bytes needed for bitfield
The changeset:

	commit f043528
	Author: Arnaldo Carvalho de Melo <acme@redhat.com>
	Date:   Sun Aug 16 12:26:33 2009 -0300

	    dwarves_reorganize: Fix class__demote_bitfields, we need power of
	two bytes

Had a correct changeset description, but an incorrect implementation, it
was not rouding up to the next power of two, but to the next multiple of
2, i.e. when a bitfield has 2 bits, it was deciding it needed 2 bytes,
not 1.

Fix it by copying the roundup_power_of_two code from the Linux kernel,
mostly by David Howells <dhowells@redhat.com>.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2013-08-15 14:17:21 -03:00
Cody P Schafer 1e461ec7e0 dwarves_fprintf: Fix printf types on 64bit linux
Signed-off-by: Cody P Schafer <cody@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2013-03-20 15:56:38 -03:00
Arnaldo Carvalho de Melo 222f0067a9 dwarves_fprintf: Don't ignore virtual data members
When computing the size of a class, leave, caused problems in
some cases, links to the reports are in the comments.

Reported-by: Nicolas <nikos42@gmail.com>
Suggested-by: Mark Wielaard <mjw@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2013-03-20 10:38:03 -03:00
Cody P Schafer e512e3f9b3 dwarves: Update git url
Signed-off-by: Cody P Schafer <cody@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2013-03-20 09:45:47 -03:00
Arnaldo Carvalho de Melo 8c6378fd88 dwarves: Support static class data members
Fixes the following BFA:

[acme@sandy pahole]$ pahole brainfart.o
class ios_base {
	enum _Ios_Openmodeconst    in;                   /*     0     4 */
	typedef enum _Ios_Fmtflags fmtflags;

	/* size: 1, cachelines: 1, members: 1 */
	/* padding: 65533 */
	/* last cacheline: 1 bytes */

	/* BRAIN FART ALERT! 1 != 4 + 0(holes), diff = -3 */

};

That now produces:

[acme@sandy pahole]$ build/pahole brainfart.o
class ios_base {
	static enum _Ios_Openmodeconst    in = 8;        /*     0     0 */
	typedef enum _Ios_Fmtflags fmtflags;

	/* size: 1, cachelines: 0, members: 0, static members: 1 */
	/* last cacheline: 1 bytes */
};
[acme@sandy pahole]$

Reported-by: Nicolas <nikos42@gmail.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2012-08-20 14:42:17 -03:00
Arnaldo Carvalho de Melo a54515fa6e dwarves: Stop using 'self'
As Thomas Gleixner wisely pointed out, using 'self' is stupid, it
doesn't convey useful information, so use sensible names.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2012-08-17 18:47:15 -03:00
Arnaldo Carvalho de Melo 6035b0d91f rpm: Add missing BuildRequires: zlib-devel
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2012-08-16 14:59:38 -03:00
Arnaldo Carvalho de Melo be7b691756 dwarf_loader: Don't stop processing after finding unsupported tag
After emitting a warning that a tag is not supported __die__process_tag
was returning NULL, making die__process_unit think that the problem
was insufficient memory.

Introduce a global variable 'unsupported_tag' and return it instead,
that way die__process_unit can distinguish ENOMEM from unsupported tags.

Reported-by: Thiago Macieira <thiago.macieira@intel.com>
Tested-by: Thiago Macieira <thiago.macieira@intel.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2012-08-16 14:55:14 -03:00