Skip to content

Commit 9a4bce7

Browse files
committed
FindTypes should find "struct TypeName" as well as "TypeName".
This fixes a bug introduced by r291559. The Module's FindType was passing the original name not the basename in the case where it didn't find any separators. I also added a testcase for this. <rdar://problem/31159173> llvm-svn: 298331
1 parent dc205b3 commit 9a4bce7

File tree

4 files changed

+96
-1
lines changed

4 files changed

+96
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
LEVEL = ../../../make
2+
C_SOURCES := main.c
3+
include $(LEVEL)/Makefile.rules
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
Make sure FindTypes finds struct types with the struct prefix.
3+
"""
4+
5+
from __future__ import print_function
6+
7+
8+
import os
9+
import time
10+
import re
11+
import lldb
12+
import lldbsuite.test.lldbutil as lldbutil
13+
from lldbsuite.test.lldbtest import *
14+
15+
16+
class TestFindTypesOnStructType(TestBase):
17+
18+
mydir = TestBase.compute_mydir(__file__)
19+
20+
# If your test case doesn't stress debug info, the
21+
# set this to true. That way it won't be run once for
22+
# each debug info format.
23+
NO_DEBUG_INFO_TESTCASE = True
24+
25+
def test_find_types_struct_type(self):
26+
"""Make sure FindTypes actually finds 'struct typename' not just 'typename'."""
27+
self.build()
28+
self.do_test()
29+
30+
def setUp(self):
31+
# Call super's setUp().
32+
TestBase.setUp(self)
33+
34+
def do_test(self):
35+
"""Make sure FindTypes actually finds 'struct typename' not just 'typename'."""
36+
exe = os.path.join(os.getcwd(), "a.out")
37+
38+
# Create a target by the debugger.
39+
target = self.dbg.CreateTarget(exe)
40+
self.assertTrue(target, VALID_TARGET)
41+
42+
# Make sure this works with struct
43+
type_list = target.FindTypes("struct mytype")
44+
self.assertEqual(type_list.GetSize(), 1, "Found one instance of the type with struct")
45+
46+
# Make sure this works without the struct:
47+
type_list = target.FindTypes("mytype")
48+
self.assertEqual(type_list.GetSize(), 1, "Found one instance of the type without struct")
49+
50+
# Make sure it works with union
51+
type_list = target.FindTypes("union myunion")
52+
self.assertEqual(type_list.GetSize(), 1, "Found one instance of the type with union")
53+
54+
# Make sure this works without the union:
55+
type_list = target.FindTypes("myunion")
56+
self.assertEqual(type_list.GetSize(), 1, "Found one instance of the type without union")
57+
58+
# Make sure it works with typedef
59+
type_list = target.FindTypes("typedef MyType")
60+
self.assertEqual(type_list.GetSize(), 1, "Found one instance of the type with typedef")
61+
62+
# Make sure this works without the typedef:
63+
type_list = target.FindTypes("MyType")
64+
self.assertEqual(type_list.GetSize(), 1, "Found one instance of the type without typedef")
65+
66+
67+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
struct mytype {
4+
int c;
5+
int d;
6+
};
7+
8+
union myunion {
9+
int num;
10+
char *str;
11+
};
12+
13+
typedef struct mytype MyType;
14+
15+
int main()
16+
{
17+
struct mytype v;
18+
MyType *v_ptr = &v;
19+
20+
union myunion u = {5};
21+
v.c = u.num;
22+
v.d = 10;
23+
return v.c + v.d;
24+
}
25+

lldb/source/Core/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ size_t Module::FindTypes(
10321032
// The "type_name_cstr" will have been modified if we have a valid type
10331033
// class
10341034
// prefix (like "struct", "class", "union", "typedef" etc).
1035-
FindTypes_Impl(sc, ConstString(type_name_cstr), nullptr, append,
1035+
FindTypes_Impl(sc, ConstString(type_basename), nullptr, append,
10361036
max_matches, searched_symbol_files, typesmap);
10371037
typesmap.RemoveMismatchedTypes(type_class);
10381038
num_matches = typesmap.GetSize();

0 commit comments

Comments
 (0)