1# Nonsensical program used to generate example DWARF package files with type 2# units, location lists, range lists, and macros. 3 4# = foobar.h = 5 6struct Foo 7{ 8 int a, b; 9 int foo (); 10}; 11 12struct Bar 13{ 14 long a, b; 15 long bar (); 16}; 17 18#define FROB(x) ((x) ^ 0x2a2a2a2a) 19#define FRY(x) ((x) * 0x100000001b3) 20 21inline long 22fibonacci (unsigned int n) 23{ 24 if (n == 0) 25 return 0; 26 else 27 { 28 long a = 0; 29 long b = 1; 30 for (unsigned int i = 2; i < n; i++) 31 { 32 long tmp = a + b; 33 a = b; 34 b = tmp; 35 } 36 return b; 37 } 38} 39 40# = foo.cc = 41 42#include "foobar.h" 43 44#define ZERO() (1 - 1) 45 46int 47x_x (int x) 48{ 49 for (int i = x; i > ZERO(); i--) 50 x *= x; 51 return x; 52} 53 54int 55Foo::foo () 56{ 57 int x = a; 58 if (a > b) 59 x -= b; 60 return FROB (x_x (x)); 61} 62 63# = bar.cc = 64 65#include "foobar.h" 66 67#define ONE 1 68 69long 70Bar::bar () 71{ 72 if (a == b) 73 return ONE; 74 else 75 return a > b ? b : a; 76} 77 78# = main.cc = 79 80#include "foobar.h" 81 82#define MAIN_ARGS int argc, char **argv 83 84int 85main(MAIN_ARGS) 86{ 87 struct Foo myfoo { argc, FROB (argc) }; 88 struct Bar mybar { fibonacci (argc), FRY (argc) }; 89 return myfoo.foo() + mybar.bar(); 90} 91 92# Built with GCC at commit 80048aa13a6b ("debug/111409 - don't generate COMDAT 93# macro sections for split DWARF"). 94$ g++ -gdwarf-5 -gsplit-dwarf -fdebug-types-section -g3 -O2 foo.cc bar.cc main.cc -o testfile-dwp-5 95# GNU dwp as of binutils 2.41 only supports DWARF 4. 96$ llvm-dwp -e testfile-dwp-5 -o testfile-dwp-5.dwp 97 98$ g++ -gdwarf-4 -gsplit-dwarf -fdebug-types-section -g3 -O2 foo.cc bar.cc main.cc -o testfile-dwp-4 99$ dwp -e testfile-dwp-4 100 101$ g++ -gdwarf-4 -gstrict-dwarf -gsplit-dwarf -fdebug-types-section -g3 -O2 foo.cc bar.cc main.cc -o testfile-dwp-4-strict 102$ dwp -e testfile-dwp-4-strict 103