[SymbolFilePDB] Fix null array access when parsing the type of a function without any arguments, i.e. 'int main()' and add support to test it

Summary:
- Fix a null array access bug. This happens when creating the lldb type for a function that has no argument.
- Implement SymbolFilePDB::ParseTypes method. Using `lldb-test symbols` will show all supported types in the target.
- Create lldb types for variadic function, PDBSymbolTypePointer, PDBSymbolTypeBuiltin
- The underlying builtin type for PDBSymbolTypeEnum is always `Int`, correct it with the very first enumerator's encoding if any. This is more accurate when the underlying type is not signed or another integer type.
- Fix a bug when the compiler type is not created based on PDB_BuiltinType. For example, basic type `long` is of same width as `int` in a 32-bit target, and the compiler type of former one will be represented by the one generated for latter if using the default method. Introduce a static function GetBuiltinTypeForPDBEncodingAndBitSize to correct this issue.
- Basic type `long double` and `double` have the same bit size in MSVC and there is no information in a PDB to distinguish them. The compiler type of the former one is represented by the latter's.
- There is no line information about typedef, enum etc in a PDB and the source and line information for them are not shown.
- There is no information about scoped enumeration. The compiler type is represented as an unscoped one.

Reviewers: zturner, lldb-commits

Reviewed By: zturner

Subscribers: majnemer, llvm-commits

Differential Revision: https://reviews.llvm.org/D42434

llvm-svn: 323255
diff --git a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
index 7b7c237..d008292 100644
--- a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
@@ -20,6 +20,7 @@
 #include "lldb/Symbol/SymbolContext.h"
 #include "lldb/Symbol/SymbolVendor.h"
 #include "lldb/Symbol/TypeMap.h"
+#include "lldb/Symbol/TypeList.h"
 #include "lldb/Utility/RegularExpression.h"
 
 #include "llvm/DebugInfo/PDB/GenericError.h"
@@ -318,8 +319,33 @@
 }
 
 size_t SymbolFilePDB::ParseTypes(const lldb_private::SymbolContext &sc) {
-  // TODO: Implement this
-  return size_t();
+  lldbassert(sc.module_sp.get());
+  size_t num_added = 0;
+  auto results_up = m_session_up->getGlobalScope()->findAllChildren();
+  if (!results_up)
+    return 0;
+  while (auto symbol_up = results_up->getNext()) {
+    switch (symbol_up->getSymTag()) {
+    case PDB_SymType::Enum:
+    case PDB_SymType::UDT:
+    case PDB_SymType::Typedef:
+      break;
+    default:
+      continue;
+    }
+
+    auto type_uid = symbol_up->getSymIndexId();
+    if (m_types.find(type_uid) != m_types.end())
+      continue;
+
+    // This should cause the type to get cached and stored in the `m_types`
+    // lookup.
+    if (!ResolveTypeUID(symbol_up->getSymIndexId()))
+      continue;
+
+    ++num_added;
+  }
+  return num_added;
 }
 
 size_t
@@ -349,8 +375,11 @@
     return nullptr;
 
   lldb::TypeSP result = pdb->CreateLLDBTypeFromPDBType(*pdb_type);
-  if (result.get())
+  if (result.get()) {
     m_types.insert(std::make_pair(type_uid, result));
+    auto type_list = GetTypeList();
+    type_list->Insert(result);
+  }
   return result.get();
 }
 
@@ -649,7 +678,9 @@
   return 0;
 }
 
-lldb_private::TypeList *SymbolFilePDB::GetTypeList() { return nullptr; }
+lldb_private::TypeList *SymbolFilePDB::GetTypeList() {
+  return m_obj_file->GetModule()->GetTypeList();
+}
 
 size_t SymbolFilePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope,
                                uint32_t type_mask,