Files
clang-p2996/lldb/test/API/lang/cpp/class_static/main.cpp
Jim Ingham 22667e3220 Fix regex & startsWith name lookup in SBTarget::FindGlobalVariables
There were two bugs here.

eMatchTypeStartsWith searched for "symbol_name" by adding ".*" to the
end of the symbol name and treating that as a regex, which isn't
actually a regex for "starts with". The ".*" is in fact a no-op.  When
we finally get to comparing the name, we compare against whatever form
of the name was in the accelerator table. But for C++ that might be
the mangled name. We should also try demangled names here, since most
users are going the see demangled not mangled names.  I fixed these
two bugs and added a bunch of tests for FindGlobalVariables.

This change is in the DWARF parser code, so there may be a similar bug
in PDB, but the test for this was already skipped for Windows, so I
don't know about this.

You might theoretically need to do this Mangled comparison in

DWARFMappedHash::MemoryTable::FindByName

except when we have names we always chop them before looking them up
so I couldn't see any code paths that fail without that change. So I
didn't add that to this patch.

Differential Revision: https://reviews.llvm.org/D151940
2023-06-01 16:15:06 -07:00

59 lines
1.4 KiB
C++

// I made this example after noting that I was unable to display an unsized
// static class array. It turns out that gcc 4.2 will emit DWARF that correctly
// describes the PointType, but it will incorrectly emit debug info for the
// "g_points" array where the following things are wrong:
// - the DW_TAG_array_type won't have a subrange info
// - the DW_TAG_variable for "g_points" won't have a valid byte size, so even
// though we know the size of PointType, we can't infer the actual size
// of the array by dividing the size of the variable by the number of
// elements.
#include <stdio.h>
typedef struct PointType
{
int x, y;
} PointType;
class A
{
public:
static PointType g_points[];
};
// Make sure similar names don't confuse us:
class AA
{
public:
static PointType g_points[];
};
PointType A::g_points[] =
{
{ 1, 2 },
{ 11, 22 }
};
static PointType g_points[] =
{
{ 3, 4 },
{ 33, 44 }
};
PointType AA::g_points[] =
{
{ 5, 6 },
{ 55, 66 }
};
int
main (int argc, char const *argv[])
{
const char *hello_world = "Hello, world!";
printf ("A::g_points[1].x = %i\n", A::g_points[1].x); // Set break point at this line.
printf ("AA::g_points[1].x = %i\n", AA::g_points[1].x);
printf ("::g_points[1].x = %i\n", g_points[1].x);
printf ("%s\n", hello_world);
return 0;
}