[Lldb-commits] [lldb] r298331 - FindTypes should find "struct TypeName" as well as "TypeName".
Jim Ingham via lldb-commits
lldb-commits at lists.llvm.org
Mon Mar 20 19:13:51 PDT 2017
Author: jingham
Date: Mon Mar 20 21:13:50 2017
New Revision: 298331
URL: http://llvm.org/viewvc/llvm-project?rev=298331&view=rev
Log:
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>
Added:
lldb/trunk/packages/Python/lldbsuite/test/lang/c/find_struct_type/
lldb/trunk/packages/Python/lldbsuite/test/lang/c/find_struct_type/Makefile
lldb/trunk/packages/Python/lldbsuite/test/lang/c/find_struct_type/TestFindStructTypes.py
lldb/trunk/packages/Python/lldbsuite/test/lang/c/find_struct_type/main.c
Modified:
lldb/trunk/source/Core/Module.cpp
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/c/find_struct_type/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/find_struct_type/Makefile?rev=298331&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/c/find_struct_type/Makefile (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/find_struct_type/Makefile Mon Mar 20 21:13:50 2017
@@ -0,0 +1,3 @@
+LEVEL = ../../../make
+C_SOURCES := main.c
+include $(LEVEL)/Makefile.rules
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/c/find_struct_type/TestFindStructTypes.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/find_struct_type/TestFindStructTypes.py?rev=298331&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/c/find_struct_type/TestFindStructTypes.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/find_struct_type/TestFindStructTypes.py Mon Mar 20 21:13:50 2017
@@ -0,0 +1,67 @@
+"""
+Make sure FindTypes finds struct types with the struct prefix.
+"""
+
+from __future__ import print_function
+
+
+import os
+import time
+import re
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+
+class TestFindTypesOnStructType(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ # If your test case doesn't stress debug info, the
+ # set this to true. That way it won't be run once for
+ # each debug info format.
+ NO_DEBUG_INFO_TESTCASE = True
+
+ def test_find_types_struct_type(self):
+ """Make sure FindTypes actually finds 'struct typename' not just 'typename'."""
+ self.build()
+ self.do_test()
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+
+ def do_test(self):
+ """Make sure FindTypes actually finds 'struct typename' not just 'typename'."""
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ # Create a target by the debugger.
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # Make sure this works with struct
+ type_list = target.FindTypes("struct mytype")
+ self.assertEqual(type_list.GetSize(), 1, "Found one instance of the type with struct")
+
+ # Make sure this works without the struct:
+ type_list = target.FindTypes("mytype")
+ self.assertEqual(type_list.GetSize(), 1, "Found one instance of the type without struct")
+
+ # Make sure it works with union
+ type_list = target.FindTypes("union myunion")
+ self.assertEqual(type_list.GetSize(), 1, "Found one instance of the type with union")
+
+ # Make sure this works without the union:
+ type_list = target.FindTypes("myunion")
+ self.assertEqual(type_list.GetSize(), 1, "Found one instance of the type without union")
+
+ # Make sure it works with typedef
+ type_list = target.FindTypes("typedef MyType")
+ self.assertEqual(type_list.GetSize(), 1, "Found one instance of the type with typedef")
+
+ # Make sure this works without the typedef:
+ type_list = target.FindTypes("MyType")
+ self.assertEqual(type_list.GetSize(), 1, "Found one instance of the type without typedef")
+
+
+
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/c/find_struct_type/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/find_struct_type/main.c?rev=298331&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/c/find_struct_type/main.c (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/find_struct_type/main.c Mon Mar 20 21:13:50 2017
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <stdlib.h>
+struct mytype {
+ int c;
+ int d;
+};
+
+union myunion {
+ int num;
+ char *str;
+};
+
+typedef struct mytype MyType;
+
+int main()
+{
+ struct mytype v;
+ MyType *v_ptr = &v;
+
+ union myunion u = {5};
+ v.c = u.num;
+ v.d = 10;
+ return v.c + v.d;
+}
+
Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=298331&r1=298330&r2=298331&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Mon Mar 20 21:13:50 2017
@@ -1032,7 +1032,7 @@ size_t Module::FindTypes(
// The "type_name_cstr" will have been modified if we have a valid type
// class
// prefix (like "struct", "class", "union", "typedef" etc).
- FindTypes_Impl(sc, ConstString(type_name_cstr), nullptr, append,
+ FindTypes_Impl(sc, ConstString(type_basename), nullptr, append,
max_matches, searched_symbol_files, typesmap);
typesmap.RemoveMismatchedTypes(type_class);
num_matches = typesmap.GetSize();
More information about the lldb-commits
mailing list