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_INTERPRETER_SCRIPTEDMETADATA_H
10#define LLDB_INTERPRETER_SCRIPTEDMETADATA_H
11
15#include "llvm/ADT/Hashing.h"
16
17namespace lldb_private {
19public:
20 ScriptedMetadata(llvm::StringRef class_name,
22 : m_class_name(class_name.data()), m_args_sp(dict_sp) {}
23
24 ScriptedMetadata(const ProcessInfo &process_info) {
25 lldb::ScriptedMetadataSP metadata_sp = process_info.GetScriptedMetadata();
26 if (metadata_sp) {
27 m_class_name = metadata_sp->GetClassName();
28 m_args_sp = metadata_sp->GetArgsSP();
29 }
30 }
31
34
35 explicit operator bool() const { return !m_class_name.empty(); }
36
37 llvm::StringRef GetClassName() const { return m_class_name; }
39
40 /// Get a unique identifier for this metadata based on its contents.
41 /// The ID is computed from the class name and arguments dictionary,
42 /// not from the pointer address, so two metadata objects with the same
43 /// contents will have the same ID.
44 uint32_t GetID() const {
45 if (m_class_name.empty())
46 return 0;
47
48 // Hash the class name.
49 llvm::hash_code hash = llvm::hash_value(m_class_name);
50
51 // Hash the arguments dictionary if present.
52 if (m_args_sp) {
53 StreamString ss;
54 m_args_sp->GetDescription(ss);
55 hash = llvm::hash_combine(hash, llvm::hash_value(ss.GetData()));
56 }
57
58 // Return the lower 32 bits of the hash.
59 return static_cast<uint32_t>(hash);
60 }
61
62private:
63 std::string m_class_name;
65};
66} // namespace lldb_private
67
68#endif // LLDB_INTERPRETER_SCRIPTEDMETADATA_H
lldb::ScriptedMetadataSP GetScriptedMetadata() const
Definition ProcessInfo.h:93
ScriptedMetadata(const ProcessInfo &process_info)
llvm::StringRef GetClassName() const
uint32_t GetID() const
Get a unique identifier for this metadata based on its contents.
StructuredData::DictionarySP GetArgsSP() const
StructuredData::DictionarySP m_args_sp
ScriptedMetadata(llvm::StringRef class_name, StructuredData::DictionarySP dict_sp)
ScriptedMetadata(const ScriptedMetadata &other)
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