LLDB mainline
ScriptedMetadata.h
Go to the documentation of this file.
1//===-- ScriptedMetadata.h ------------------------------------ -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_UTILITY_SCRIPTEDMETADATA_H
10#define LLDB_UTILITY_SCRIPTEDMETADATA_H
11
16#include "llvm/ADT/Hashing.h"
17
18namespace lldb_private {
20public:
21 ScriptedMetadata(llvm::StringRef class_name,
23 : m_class_name(class_name.str()), m_args_sp(dict_sp) {}
24
25 ScriptedMetadata(const ProcessInfo &process_info) {
26 lldb::ScriptedMetadataSP metadata_sp = process_info.GetScriptedMetadata();
27 if (metadata_sp) {
28 m_class_name = metadata_sp->GetClassName();
29 m_args_sp = metadata_sp->GetArgsSP();
30 m_source_path = metadata_sp->GetSourcePath();
31 }
32 }
33
34 ScriptedMetadata(const ScriptedMetadata &other) = default;
36
37 explicit operator bool() const { return !m_class_name.empty(); }
38
39 llvm::StringRef GetClassName() const { return m_class_name; }
41
42 const FileSpec &GetSourcePath() const { return m_source_path; }
43 void SetSourcePath(const FileSpec &source_path) {
44 m_source_path = source_path;
45 }
46
47 /// Get a unique identifier for this metadata based on its contents.
48 /// The ID is computed from the class name and arguments dictionary,
49 /// not from the pointer address, so two metadata objects with the same
50 /// contents will have the same ID.
51 uint32_t GetHash() const {
52 if (m_class_name.empty())
53 return 0;
54
55 // Hash the class name.
56 llvm::hash_code hash = llvm::hash_value(m_class_name);
57
58 // Hash the arguments dictionary if present.
59 if (m_args_sp) {
60 StreamString ss;
61 m_args_sp->GetDescription(ss);
62 hash = llvm::hash_combine(hash, llvm::hash_value(ss.GetData()));
63 }
64
65 // Return the lower 32 bits of the hash.
66 return static_cast<uint32_t>(hash);
67 }
68
69private:
70 std::string m_class_name;
73};
74} // namespace lldb_private
75
76#endif // LLDB_UTILITY_SCRIPTEDMETADATA_H
A file utility class.
Definition FileSpec.h:56
lldb::ScriptedMetadataSP GetScriptedMetadata() const
Definition ProcessInfo.h:91
void SetSourcePath(const FileSpec &source_path)
ScriptedMetadata(const ProcessInfo &process_info)
const FileSpec & GetSourcePath() const
uint32_t GetHash() const
Get a unique identifier for this metadata based on its contents.
llvm::StringRef GetClassName() const
ScriptedMetadata & operator=(const ScriptedMetadata &other)=default
ScriptedMetadata(const ScriptedMetadata &other)=default
StructuredData::DictionarySP GetArgsSP() const
StructuredData::DictionarySP m_args_sp
ScriptedMetadata(llvm::StringRef class_name, StructuredData::DictionarySP dict_sp)
const char * GetData() const
std::shared_ptr< Dictionary > DictionarySP
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::ScriptedMetadata > ScriptedMetadataSP