1*99451b44SJordan Rupprecht //===-- main.cpp ------------------------------------------------*- C++ -*-===// 2*99451b44SJordan Rupprecht // 3*99451b44SJordan Rupprecht // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*99451b44SJordan Rupprecht // See https://llvm.org/LICENSE.txt for license information. 5*99451b44SJordan Rupprecht // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*99451b44SJordan Rupprecht // 7*99451b44SJordan Rupprecht //===----------------------------------------------------------------------===// 8*99451b44SJordan Rupprecht 9*99451b44SJordan Rupprecht // I made this example after noting that I was unable to display an unsized 10*99451b44SJordan Rupprecht // static class array. It turns out that gcc 4.2 will emit DWARF that correctly 11*99451b44SJordan Rupprecht // describes the PointType, but it will incorrectly emit debug info for the 12*99451b44SJordan Rupprecht // "g_points" array where the following things are wrong: 13*99451b44SJordan Rupprecht // - the DW_TAG_array_type won't have a subrange info 14*99451b44SJordan Rupprecht // - the DW_TAG_variable for "g_points" won't have a valid byte size, so even 15*99451b44SJordan Rupprecht // though we know the size of PointType, we can't infer the actual size 16*99451b44SJordan Rupprecht // of the array by dividing the size of the variable by the number of 17*99451b44SJordan Rupprecht // elements. 18*99451b44SJordan Rupprecht 19*99451b44SJordan Rupprecht #include <stdio.h> 20*99451b44SJordan Rupprecht 21*99451b44SJordan Rupprecht typedef struct PointType 22*99451b44SJordan Rupprecht { 23*99451b44SJordan Rupprecht int x, y; 24*99451b44SJordan Rupprecht } PointType; 25*99451b44SJordan Rupprecht 26*99451b44SJordan Rupprecht class A 27*99451b44SJordan Rupprecht { 28*99451b44SJordan Rupprecht public: 29*99451b44SJordan Rupprecht static PointType g_points[]; 30*99451b44SJordan Rupprecht }; 31*99451b44SJordan Rupprecht 32*99451b44SJordan Rupprecht PointType A::g_points[] = 33*99451b44SJordan Rupprecht { 34*99451b44SJordan Rupprecht { 1, 2 }, 35*99451b44SJordan Rupprecht { 11, 22 } 36*99451b44SJordan Rupprecht }; 37*99451b44SJordan Rupprecht 38*99451b44SJordan Rupprecht static PointType g_points[] = 39*99451b44SJordan Rupprecht { 40*99451b44SJordan Rupprecht { 3, 4 }, 41*99451b44SJordan Rupprecht { 33, 44 } 42*99451b44SJordan Rupprecht }; 43*99451b44SJordan Rupprecht 44*99451b44SJordan Rupprecht int 45*99451b44SJordan Rupprecht main (int argc, char const *argv[]) 46*99451b44SJordan Rupprecht { 47*99451b44SJordan Rupprecht const char *hello_world = "Hello, world!"; 48*99451b44SJordan Rupprecht printf ("A::g_points[1].x = %i\n", A::g_points[1].x); // Set break point at this line. 49*99451b44SJordan Rupprecht printf ("::g_points[1].x = %i\n", g_points[1].x); 50*99451b44SJordan Rupprecht printf ("%s\n", hello_world); 51*99451b44SJordan Rupprecht return 0; 52*99451b44SJordan Rupprecht } 53