[Lldb-commits] [lldb] r249117 - Teach 'type lookup' to pull types from clang modules; also add a test case
Enrico Granata via lldb-commits
lldb-commits at lists.llvm.org
Thu Oct 1 18:23:12 PDT 2015
Author: enrico
Date: Thu Oct 1 20:23:11 2015
New Revision: 249117
URL: http://llvm.org/viewvc/llvm-project?rev=249117&view=rev
Log:
Teach 'type lookup' to pull types from clang modules; also add a test case
Added:
lldb/trunk/test/functionalities/type_lookup/
lldb/trunk/test/functionalities/type_lookup/Makefile
lldb/trunk/test/functionalities/type_lookup/TestTypeLookup.py
lldb/trunk/test/functionalities/type_lookup/main.m
Modified:
lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp
Modified: lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp?rev=249117&r1=249116&r2=249117&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp (original)
+++ lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp Thu Oct 1 20:23:11 2015
@@ -708,34 +708,57 @@ ObjCLanguage::GetTypeScavenger ()
{
bool result = false;
- Process* process = exe_scope->CalculateProcess().get();
- if (process)
+ Target* target = exe_scope->CalculateTarget().get();
+ if (target)
{
- const bool create_on_demand = false;
- auto objc_runtime = process->GetObjCLanguageRuntime(create_on_demand);
- if (objc_runtime)
+ if (auto clang_modules_decl_vendor = target->GetClangModulesDeclVendor())
{
- auto decl_vendor = objc_runtime->GetDeclVendor();
- if (decl_vendor)
+ std::vector <clang::NamedDecl*> decls;
+ ConstString key_cs(key);
+
+ if (clang_modules_decl_vendor->FindDecls(key_cs, false, UINT32_MAX, decls) > 0 &&
+ decls.size() > 0)
{
- std::vector<clang::NamedDecl *> decls;
- ConstString name(key);
- decl_vendor->FindDecls(name, true, UINT32_MAX, decls);
- for (auto decl : decls)
+ CompilerType module_type = ClangASTContext::GetTypeForDecl(decls.front());
+ result = true;
+ std::unique_ptr<Language::TypeScavenger::Result> result(new ObjCScavengerResult(module_type));
+ results.insert(std::move(result));
+ }
+ }
+ }
+
+ if (!result)
+ {
+ Process* process = exe_scope->CalculateProcess().get();
+ if (process)
+ {
+ const bool create_on_demand = false;
+ auto objc_runtime = process->GetObjCLanguageRuntime(create_on_demand);
+ if (objc_runtime)
+ {
+ auto decl_vendor = objc_runtime->GetDeclVendor();
+ if (decl_vendor)
{
- if (decl)
+ std::vector<clang::NamedDecl *> decls;
+ ConstString name(key);
+ decl_vendor->FindDecls(name, true, UINT32_MAX, decls);
+ for (auto decl : decls)
{
- if (CompilerType candidate = ClangASTContext::GetTypeForDecl(decl))
+ if (decl)
{
- result = true;
- std::unique_ptr<Language::TypeScavenger::Result> result(new ObjCScavengerResult(candidate));
- results.insert(std::move(result));
+ if (CompilerType candidate = ClangASTContext::GetTypeForDecl(decl))
+ {
+ result = true;
+ std::unique_ptr<Language::TypeScavenger::Result> result(new ObjCScavengerResult(candidate));
+ results.insert(std::move(result));
+ }
}
}
}
}
}
}
+
return result;
}
Added: lldb/trunk/test/functionalities/type_lookup/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/type_lookup/Makefile?rev=249117&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/type_lookup/Makefile (added)
+++ lldb/trunk/test/functionalities/type_lookup/Makefile Thu Oct 1 20:23:11 2015
@@ -0,0 +1,9 @@
+LEVEL = ../../make
+
+OBJC_SOURCES := main.m
+
+CFLAGS_EXTRAS += -w
+
+include $(LEVEL)/Makefile.rules
+
+LDFLAGS += -framework Foundation
Added: lldb/trunk/test/functionalities/type_lookup/TestTypeLookup.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/type_lookup/TestTypeLookup.py?rev=249117&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/type_lookup/TestTypeLookup.py (added)
+++ lldb/trunk/test/functionalities/type_lookup/TestTypeLookup.py Thu Oct 1 20:23:11 2015
@@ -0,0 +1,46 @@
+"""
+Test type lookup command.
+"""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+import datetime
+import lldbutil
+
+class TypeLookupTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number to break at.
+ self.line = line_number('main.m', '// break here')
+
+ @skipUnlessDarwin
+ def test_type_lookup(self):
+ """Test type lookup command."""
+ self.build()
+ self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
+
+ lldbutil.run_break_set_by_file_and_line (self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
+
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # The stop reason of the thread should be breakpoint.
+ self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+ substrs = ['stopped',
+ 'stop reason = breakpoint'])
+
+ self.expect('type lookup NoSuchType', substrs=['@interface'], matching=False)
+ self.expect('type lookup NSURL', substrs=['NSURL'])
+ self.expect('type lookup NSArray', substrs=['NSArray'])
+ self.expect('type lookup NSObject', substrs=['NSObject', 'isa'])
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
Added: lldb/trunk/test/functionalities/type_lookup/main.m
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/type_lookup/main.m?rev=249117&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/type_lookup/main.m (added)
+++ lldb/trunk/test/functionalities/type_lookup/main.m Thu Oct 1 20:23:11 2015
@@ -0,0 +1,16 @@
+//===-- main.m ------------------------------------------------*- ObjC -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#import <Foundation/Foundation.h>
+
+int main (int argc, const char * argv[])
+{
+ return 0; // break here
+}
+
More information about the lldb-commits
mailing list