aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/raw_pdb/src/PDB_ModuleInfoStream.h
blob: 4fef0fe3b9d88f2f95145a1d98e13e421892d933 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright 2011-2022, Molecular Matters GmbH <[email protected]>
// See LICENSE.txt for licensing details (2-clause BSD License: https://opensource.org/licenses/BSD-2-Clause)

#pragma once

#include "Foundation/PDB_Macros.h"
#include "Foundation/PDB_ArrayView.h"
#include "PDB_CoalescedMSFStream.h"
#include "PDB_ModuleSymbolStream.h"
#include "PDB_ModuleLineStream.h"

namespace PDB
{
	class PDB_NO_DISCARD DirectMSFStream;

	class PDB_NO_DISCARD ModuleInfoStream
	{
	public:
		class PDB_NO_DISCARD Module
		{
		public:
			Module(void) PDB_NO_EXCEPT;
			explicit Module(const DBI::ModuleInfo* info, const char* name, size_t nameLength, const char* objectName, size_t objectNameLength) PDB_NO_EXCEPT;

			PDB_DEFAULT_MOVE(Module);

			// Returns whether the module has a symbol stream.
			PDB_NO_DISCARD bool HasSymbolStream(void) const PDB_NO_EXCEPT;

			// Returns whether the module has a line stream.
			PDB_NO_DISCARD bool HasLineStream(void) const PDB_NO_EXCEPT;

			// Creates a symbol stream for the module.
			PDB_NO_DISCARD ModuleSymbolStream CreateSymbolStream(const RawFile& file) const PDB_NO_EXCEPT;

			// Create a line stream for the module
			PDB_NO_DISCARD ModuleLineStream CreateLineStream(const RawFile& file) const PDB_NO_EXCEPT;


			// Returns the PDB module info.
			PDB_NO_DISCARD inline const DBI::ModuleInfo* GetInfo(void) const PDB_NO_EXCEPT
			{
				return m_info;
			}

			// Returns the name of the module.
			PDB_NO_DISCARD inline ArrayView<char> GetName(void) const PDB_NO_EXCEPT
			{
				return ArrayView<char>(m_name, m_nameLength);
			}

			// Returns the name of the object file of the module.
			PDB_NO_DISCARD inline ArrayView<char> GetObjectName(void) const PDB_NO_EXCEPT
			{
				return ArrayView<char>(m_objectName, m_objectNameLength);
			}

		private:
			// the module info is stored in variable-length arrays inside the stream, so rather than store an array directly,
			// we need to store pointers to the individual data items inside the stream.
			const DBI::ModuleInfo* m_info;

			// the module name, e.g. the path to an object file or import library such as "Import:kernel32.dll"
			const char* m_name;
			size_t m_nameLength;
			
			// the name of the object file. either the same as the module name, or the path to the archive that contained the module
			const char* m_objectName;
			size_t m_objectNameLength;

			PDB_DISABLE_COPY(Module);
		};

		ModuleInfoStream(void) PDB_NO_EXCEPT;
		ModuleInfoStream(ModuleInfoStream&& other) PDB_NO_EXCEPT;
		ModuleInfoStream& operator=(ModuleInfoStream&& other) PDB_NO_EXCEPT;

		explicit ModuleInfoStream(const DirectMSFStream& directStream, uint32_t size, uint32_t offset) PDB_NO_EXCEPT;

		~ModuleInfoStream(void) PDB_NO_EXCEPT;

		// Tries to find the linker module corresponding to the linker, i.e. the module named "* Linker *".
		PDB_NO_DISCARD const Module* FindLinkerModule(void) const PDB_NO_EXCEPT;

		// Returns the module with the given index.
		PDB_NO_DISCARD inline const Module& GetModule(uint32_t index) const PDB_NO_EXCEPT
		{
			return m_modules[index];
		}

		// Returns a view of all modules in the info stream.
		PDB_NO_DISCARD inline ArrayView<Module> GetModules(void) const PDB_NO_EXCEPT
		{
			return ArrayView<Module>(m_modules, m_moduleCount);
		}

	private:
		CoalescedMSFStream m_stream;
		Module* m_modules;
		size_t m_moduleCount;

		PDB_DISABLE_COPY(ModuleInfoStream);
	};
}