220 Commits

Author SHA1 Message Date
Zachary Turner
4d1149db48 [codeview] Add TypeVisitorCallbackPipeline.
We were kind of hacking this together before by embedding the
ability to forward requests into the TypeDeserializer.  When
we want to start adding more different kinds of visitor callback
interfaces though, this doesn't scale well and is very inflexible.

So introduce the notion of a pipeline, which itself implements
the TypeVisitorCallbacks interface, but which contains an internal
list of other callbacks to invoke in sequence.

Also update the existing uses of CVTypeVisitor to use this new
pipeline class for deserializing records before visiting them
with another visitor.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280293 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-31 21:42:26 +00:00
Zachary Turner
3483f21bbc [CodeView] Decouple record deserialization from visitor dispatch.
Until now, our use case for the visitor has been to take a stream of bytes
representing a type stream, deserialize the records in sequence, and do
something with them, where "something" is determined by how the user
implements a particular set of callbacks on an abstract class.

For actually writing PDBs, however, we want to do the reverse. We have
some kind of description of the list of records in their in-memory format,
and we want to process each one. Perhaps by serializing them to a byte
stream, or perhaps by converting them from one description format (Yaml)
to another (in-memory representation).

This was difficult in the current model because deserialization and
invoking the callbacks were tightly coupled.

With this patch we change this so that TypeDeserializer is itself an
implementation of the particular set of callbacks. This decouples
deserialization from the iteration over a list of records and invocation
of the callbacks.  TypeDeserializer is initialized with another
implementation of the callback interface, so that upon deserialization it
can pass the deserialized record through to the next set of callbacks. In
a sense this is like an implementation of the Decorator design pattern,
where the Deserializer is a decorator.

This will be useful for writing Pdbs from yaml, where we have a
description of the type records in Yaml format. In this case, the visitor
implementation would have each visitation callback method implemented in
such a way as to extract the proper set of fields from the Yaml, and it
could maintain state that builds up a list of these records. Finally at
the end we can pass this information through to another set of callbacks
which serializes them into a byte stream.

Reviewed By: majnemer, ruiu, rnk
Differential Revision: https://reviews.llvm.org/D23177

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277871 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-05 21:45:34 +00:00
Rui Ueyama
6775a0d29b pdbdump: Fix crash bug.
pdbdump calls DbiStreamBuilder::commit through PDBFileBuilder::commit
without calling DbiStreamBuilder::finalize. Because `finalize` initializes
`Header` member, `Header` remained nullptr which caused a crash bug.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277681 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-03 23:43:23 +00:00
Zachary Turner
29b012cdcd [msf] Make FPM reader use MappedBlockStream.
MappedBlockSTream can work with any sequence of block data where
the ordering is specified by a list of block numbers.  So rather
than manually stitch them together in the case of the FPM, reuse
this functionality so that we can treat the FPM as if it were
contiguous.

Reviewed By: ruiu
Differential Revision: https://reviews.llvm.org/D23066

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277609 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-03 16:53:21 +00:00
Zachary Turner
822ef4e420 [msf] Teach LLVM to parse a split Fpm.
The FPM is split at regular intervals across the MSF file, as the MS code
suggests. It turns out that the value of the interval is precisely the
block size. If the block size is 4096, then there are two Fpm pages every
4096 blocks.

So here we teach the PDBFile class to parse a split FPM, and also add more
options when dumping the FPM to display some additional information such
as orphaned pages (pages which the FPM says are allocated, but which
nothing appears to use), use after free pages (pages which the FPM says
are not allocated, but which are referenced by a stream), and multiple use
pages (pages which the FPM says are allocated but are used more than
once).

Reviewed By: ruiu
Differential Revision: https://reviews.llvm.org/D23022

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277388 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-01 21:19:45 +00:00
Rui Ueyama
a8209f7b0e pdbdump: Dump Free Page Map contents.
Differential Revision: https://reviews.llvm.org/D22974

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277216 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-29 21:38:00 +00:00
Zachary Turner
5e117855c3 [msf] Resubmit "Rename Msf -> MSF".
Previously this change was submitted from a Windows machine, so
changes made to the case of filenames and directory names did
not survive the commit, and as a result the CMake source file
names and the on-disk file names did not match on case-sensitive
file systems.

I'm resubmitting this patch from a Linux system, which hopefully
allows the case changes to make it through unfettered.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277213 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-29 20:56:36 +00:00
Zachary Turner
85c3e3ee9c Revert "[msf] Rename Msf to MSF."
This reverts commit 4d1557ffac41e079bcb1abbcf04f512474dcd6fe.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277194 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-29 18:38:47 +00:00
Zachary Turner
4d1557ffac [msf] Rename Msf to MSF.
In a previous patch, it was suggested to use all caps instead of
rolling caps for initialisms, so this patch changes everything
to do this.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277190 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-29 18:24:26 +00:00
Zachary Turner
1749ba17c6 [pdb] Fix an ambiguity when writing size_t on x64 platforms.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277025 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-28 19:29:52 +00:00
Zachary Turner
a5c0a1402c [pdb] Fix some warnings that break -Werror builds.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277021 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-28 19:18:02 +00:00
Zachary Turner
0c7a213a73 [pdb] Refactor library to more clearly separate reading/writing
Reviewed By: amccarth, ruiu
Differential Revision: https://reviews.llvm.org/D22693

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277019 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-28 19:12:28 +00:00
Zachary Turner
0c78d1d159 Get rid of IMsfStreamData class.
This was a pure virtual base class whose purpose was to abstract
away the notion of how you retrieve the layout of a discontiguous
stream of blocks in an Msf file.  This led to too many layers of
abstraction making it difficult to figure out what was going on
and extend things.  Ultimately, a stream's layout is decided by
its length and the array of block numbers that it lives on.  So
rather than have an abstract base class which can return this in
any number of ways, it's more straightforward to simply store them
as fields of a trivial struct, and also to give a more appropriate
name.

This patch does that.  It renames IMsfStreamData to MsfStreamLayout,
and deletes the 2 concrete implementations, DirectoryStreamData
and IndexedStreamData.  MsfStreamLayout is a trivial struct
with the necessary data.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277018 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-28 19:11:09 +00:00
Zachary Turner
428d4aa99f Make PDBFile store an msf::Layout.
Previously it was storing all the fields of an msf::Layout as
separate members.  This is a trivial cleanup to make it store
an msf::Layout directly.  This makes the code more readable
since it becomes clear which fields of PDBFile are actually the
msf specific layout information in a sea of other bookkeeping
fields.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276460 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-22 19:56:33 +00:00
Zachary Turner
9a3129ad49 [pdb] Have builders share a single BumpPtrAllocator.
This makes it easier to have the writable and readable PDB
interfaces share code since the read/write and write-only
interfaces now share a single allocator, you don't have to worry
about a builder building a read only interface and then having
the read-only interface's data become corrupt when the builder
goes out of scope.  Now the allocator is specified explicitly
to all constructors, so all interfaces can share a single allocator
that is scoped appropriately.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276459 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-22 19:56:26 +00:00
Zachary Turner
4ab13f5ec5 [msf] Create LLVMDebugInfoMsf
This provides a better layering of responsibilities among different
aspects of PDB writing code.  Some of the MSF related code was
contained in CodeView, and some was in PDB prior to this.  Further,
we were often saying PDB when we meant MSF, and the two are
actually independent of each other since in theory you can have
other types of data besides PDB data in an MSF.  So, this patch
separates the MSF specific code into its own library, with no
dependencies on anything else, and DebugInfoCodeView and
DebugInfoPDB take dependencies on DebugInfoMsf.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276458 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-22 19:56:05 +00:00
Zachary Turner
44bd3bd7dc [pdb] Move file layout header structs to RawTypes.h
This facilitates code reuse between the builder classes and the
"frozen" read only versions of the classes used for parsing
existing PDB files.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276427 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-22 15:46:46 +00:00
Zachary Turner
6406b60a78 [pdb] Round-trip module & file info to/from YAML.
This implements support for writing compiland and compiland source
file info to a binary PDB.  This is tested by adding support for
dumping these fields from an existing PDB to yaml, reading them
back in, and dumping them again and verifying the values are as
expected.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276426 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-22 15:46:37 +00:00
Zachary Turner
9b30e73d48 [pdb] Teach MsfBuilder and other classes about the Free Page Map.
Block 1 and 2 of an MSF file are bit vectors that represent the
list of blocks allocated and free in the file.  We had been using
these blocks to write stream data and other data, so we mark them
as the free page map now.  We don't yet serialize these pages to
the disk, but at least we make a note of what it is, and avoid
writing random data to them.

Doing this also necessitated cleaning up some of the tests to be
more general and hardcode fewer values, which is nice.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275629 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-15 22:17:19 +00:00
Zachary Turner
93a8d14081 [pdb] Round trip the NameMap data structure to YAML.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275628 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-15 22:17:08 +00:00
Zachary Turner
6be3e7c0e8 [pdb] Use MsfBuilder to handle the writing PDBs.
Previously we would read a PDB, then write some of it back out,
but write the directory, super block, and other pertinent metadata
back out unchanged.  This generates incorrect PDBs since the amount
of data written was not always the same as the amount of data read.

This patch changes things to use the newly introduced `MsfBuilder`
class to write out a correct and accurate set of Msf metadata for
the data *actually* written, which opens up the door for adding and
removing type records, symbol records, and other types of data to
an existing PDB.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275627 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-15 22:16:56 +00:00
Saleem Abdulrasool
db823e2f44 DebugInfo: reorder some initializers
Fix a few initialization ordering warnings from gcc from `-Wreorder`.  NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275615 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-15 21:10:31 +00:00
Zachary Turner
32cf292fd8 [pdb] Introduce MsfBuilder for laying out PDB files.
Reviewed by: ruiu
Differential Revision: https://reviews.llvm.org/D22308

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275611 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-15 20:43:38 +00:00
Rui Ueyama
ce6dd1b341 Re-enable TPI hash verification for enum records.
We didn't read unique names correctly. As a result, we computed
hashes on (non-)unique names instead of unique names.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275150 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-12 03:25:03 +00:00
Zachary Turner
ae108ee909 Refactor the PDB writing to use a builder approach
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275110 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-11 21:45:26 +00:00
Benjamin Kramer
a27e16e477 Give helper classes/functions internal linkage. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275014 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-10 11:28:51 +00:00
David Majnemer
65dccf7884 [pdb] Sanity check the stream map
Some abstractions in LLVM "know" that they are reading in-bounds,
FixedStreamArray, and provide a simple result.  This breaks down if the
stream map is bogus.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275010 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-10 05:32:05 +00:00
David Majnemer
7aa4746755 [llvm-pdbdump] Propagate errors a little more consistently
PDBFile::getBlockData didn't really return any indication that it
failed.  It merely returned an empty buffer.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275009 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-10 03:34:47 +00:00
Zachary Turner
8bf0aed731 [pdb] Round trip the PDB stream between YAML and binary PDB.
This gets writing of the PDB stream working.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274647 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-06 18:05:57 +00:00
Zachary Turner
3dfcaf659a Disable hash verification of enums.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274639 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-06 17:25:12 +00:00
Reid Kleckner
ec8e96efb0 [pdb] Check the display name for <unnamed-tag>, not the linkage name
This issue was encountered on libcmt.pdb, which has a type record that
looks like this:

  Struct (0x1094) {
    TypeLeafKind: LF_STRUCTURE (0x1505)
    MemberCount: 3
    Properties [ (0x200)
      HasUniqueName (0x200)
    ]
    FieldList: <field list> (0x1093)
    DerivedFrom: 0x0
    VShape: 0x0
    SizeOf: 4
    Name: <unnamed-tag>
    LinkageName: .?AU<unnamed-tag>@@
  }

The checks for startswith/endswith "<unnamed-tag>" should look at the
display name, not the linkage name.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274376 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-01 18:43:29 +00:00
Reid Kleckner
1199c8cbc8 [pdb] Avoid reporting an error when the module symbol stream is empty
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274309 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-01 00:37:49 +00:00
Reid Kleckner
5ec7ee3af8 [PDB] Indicate which type record failed hash validation
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274308 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-01 00:37:25 +00:00
Zachary Turner
91d41f9825 [pdb] Re-add code to write PDB files.
Somehow all the functionality to write PDB files got removed,
probably accidentally when uploading the patch perhaps the wrong
one got uploaded.  This re-adds all the code, as well as the
corresponding test.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274248 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-30 17:43:00 +00:00
Reid Kleckner
e97bf81771 [pdb] Treat a stream size of ~0U as 0
My PDBs always have this size for stream 11. Not sure why.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273504 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-22 22:42:24 +00:00
Rui Ueyama
4a94acfea8 [codeview] Add an extra check for TPI hash values.
This patch adds a function that corresponds to `fUDTAnon`
and use that to compute TPI hash values as the reference does.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273139 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-20 07:31:29 +00:00
Reid Kleckner
7abe77ab98 [pdb] Don't error on missing FPO streams
64-bit PDBs never have FPO data. They have xdata instead.

Also improve error recovery of stream summary dumping while I'm here.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273046 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-17 20:38:01 +00:00
Rui Ueyama
6b7e0cc92c [codeview] Use hashBufferV8 to verify all type records.
Differential Revision: http://reviews.llvm.org/D21393

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272930 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-16 18:39:17 +00:00
Zachary Turner
e8d381d02c Resubmit "[pdb] Change type visitor pattern to be dynamic."
There was a regression introduced during type stream merging when
visiting a field list record.  This has been fixed in this patch.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272929 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-16 18:22:27 +00:00
Zachary Turner
575a9fbcc9 Revert "[pdb] Change type visitor pattern to be dynamic."
This reverts commit fb0dd311e1ad945827b8ffd5354f4810e2be1579.

This breaks some llvm-readobj tests.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272927 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-16 18:09:04 +00:00
Zachary Turner
fb0dd311e1 [pdb] Change type visitor pattern to be dynamic.
This allows better catching of compiler errors since we can use
the override keyword to verify that methods are actually
overridden.

Also in this patch I've changed from storing a boolean Error
code everywhere to returning an llvm::Error, to propagate richer
error information up the call stack.

Reviewed By: ruiu, rnk
Differential Revision: http://reviews.llvm.org/D21410

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272926 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-16 18:00:28 +00:00
Rui Ueyama
43c7bd0b82 [codeview] Pass CVRecord to visitTypeBegin callback.
Both parameters to visitTypeBegin are actually members of CVRecord,
so we can just pass CVRecord instead of destructuring it.

Differential Revision: http://reviews.llvm.org/D21435

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272899 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-16 14:47:23 +00:00
Rui Ueyama
70154cb57e [codeview] Remove unused parameter.
Differential Revision: http://reviews.llvm.org/D21433

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272898 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-16 14:41:22 +00:00
Rui Ueyama
a3568c118e Implement pdb::hashBufferV8 hash function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272894 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-16 13:48:16 +00:00
Rui Ueyama
7d0c878650 Remove redundant namespace specifiers.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272889 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-16 13:17:59 +00:00
Rui Ueyama
1d884ca9ef [codeview] Use CVTypeVisitor instead of a hand-written switch-cases.
Differential Revision: http://reviews.llvm.org/D21418

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272888 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-16 13:14:42 +00:00
Rui Ueyama
69d870720c [pdbdump] Verify LF_{CLASS,ENUM,INTERFACE,STRUCTURE,UNION} records.
Differential Revision: http://reviews.llvm.org/D21361

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272815 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-15 18:26:59 +00:00
Rui Ueyama
2c70155651 [pdbdump] Verify TPI hash for LF_ENUM type records.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272728 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-14 22:25:07 +00:00
Zachary Turner
7d35b2d2b1 Resubmit "[pdb] Actually write a PDB to disk from YAML.""
Reviewed By: ruiu
Differential Revision: http://reviews.llvm.org/D21220

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272708 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-14 20:48:36 +00:00
Zachary Turner
bf3c011ba7 Revert "[pdb] Actually write a PDB to disk from YAML."
This reverts commit 879139e1c6577b09df52de56a6bab856a19ed185.

This was committed accidentally when I blindly typed git svn
dcommit instead of the command to generate a patch.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272693 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-14 18:51:35 +00:00