-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[GSYM] Callsites: Add data format support and loading from YAML #109781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ac48f2c
[GSYM] Callsites: Add data format support and loading from YAML
fe23779
Address Feedback nr.1
cd7c30a
Address feedback nr.2
087cdea
Address Feedback Nr 2.1
d7cff1b
Address [Some] Feedback Nr 3 - Rest pending YAML format
cc1d314
Switch to relative return offsets
32f7987
Fix lit test
584fdf9
Address Feedback Nr 4
d5bd6d5
Fix Formatting
fda812c
Address Feedback Nr 5
ae391a2
Address Feedback Nr.6
4e7d719
Address Feedback Nr.7
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| //===- CallSiteInfo.h -------------------------------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_DEBUGINFO_GSYM_CALLSITEINFO_H | ||
| #define LLVM_DEBUGINFO_GSYM_CALLSITEINFO_H | ||
|
|
||
| #include "llvm/ADT/DenseMap.h" | ||
| #include "llvm/ADT/StringRef.h" | ||
| #include "llvm/ADT/StringSet.h" | ||
alx32 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include "llvm/DebugInfo/GSYM/ExtractRanges.h" | ||
alx32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #include "llvm/Support/YAMLParser.h" | ||
alx32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #include <string> | ||
| #include <unordered_map> | ||
alx32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #include <vector> | ||
|
|
||
| namespace llvm { | ||
| class DataExtractor; | ||
| class raw_ostream; | ||
| class StringTableBuilder; | ||
alx32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| class CachedHashStringRef; | ||
alx32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| namespace yaml { | ||
| struct CallSiteYAML; | ||
| struct FunctionYAML; | ||
alx32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| struct FunctionsYAML; | ||
| } // namespace yaml | ||
|
|
||
| namespace gsym { | ||
| class FileWriter; | ||
| struct FunctionInfo; | ||
| struct CallSiteInfo { | ||
| enum Flags : uint8_t { | ||
alx32 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| None = 0, | ||
| // This flag specifies that the call site can only call a function within | ||
| // the same link unit as the call site. | ||
| InternalCall = 1 << 0, | ||
| // This flag specifies that the call site can only call a function outside | ||
| // the link unit that the call site is in. | ||
| ExternalCall = 1 << 1, | ||
| }; | ||
|
|
||
| /// The return address of the call site. | ||
| uint64_t ReturnAddress; | ||
alx32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// Offsets into the string table for function names regex patterns. | ||
| std::vector<uint32_t> MatchRegex; | ||
alx32 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// Bitwise OR of CallSiteInfo::Flags values | ||
| uint8_t Flags = CallSiteInfo::Flags::None; | ||
|
|
||
| /// Decode a CallSiteInfo object from a binary data stream. | ||
| /// | ||
| /// \param Data The binary stream to read the data from. | ||
| /// \param Offset The current offset within the data stream. | ||
| /// \param BaseAddr The base address for decoding (unused here but included | ||
| /// for consistency). | ||
alx32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// | ||
| /// \returns A CallSiteInfo or an error describing the issue. | ||
| static llvm::Expected<CallSiteInfo> | ||
| decode(DataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr); | ||
|
|
||
| /// Encode this CallSiteInfo object into a FileWriter stream. | ||
| /// | ||
| /// \param O The binary stream to write the data to. | ||
| /// \returns An error object that indicates success or failure. | ||
| llvm::Error encode(FileWriter &O) const; | ||
| }; | ||
|
|
||
| struct CallSiteInfoCollection { | ||
| std::vector<CallSiteInfo> CallSites; | ||
|
|
||
| /// Decode a CallSiteInfoCollection object from a binary data stream. | ||
| /// | ||
| /// \param Data The binary stream to read the data from. | ||
| /// \param BaseAddr The base address for decoding (unused here but included | ||
alx32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// for consistency). | ||
| /// | ||
| /// \returns A CallSiteInfoCollection or an error describing the issue. | ||
| static llvm::Expected<CallSiteInfoCollection> decode(DataExtractor &Data, | ||
| uint64_t BaseAddr); | ||
|
|
||
| /// Encode this CallSiteInfoCollection object into a FileWriter stream. | ||
| /// | ||
| /// \param O The binary stream to write the data to. | ||
| /// \returns An error object that indicates success or failure. | ||
| llvm::Error encode(FileWriter &O) const; | ||
| }; | ||
|
|
||
| bool operator==(const CallSiteInfoCollection &LHS, | ||
| const CallSiteInfoCollection &RHS); | ||
|
|
||
| bool operator==(const CallSiteInfo &LHS, const CallSiteInfo &RHS); | ||
alx32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| class CallSiteInfoLoader { | ||
| public: | ||
| /// Constructor that initializes the CallSiteInfoLoader with necessary data | ||
| /// structures. | ||
| /// | ||
| /// \param StringOffsetMap A reference to a DenseMap that maps existing string | ||
| /// offsets to CachedHashStringRef. \param StrTab A reference to a | ||
alx32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// StringTableBuilder used for managing looking up and creating new strings. | ||
| /// \param StringStorage A reference to a StringSet for storing the data for | ||
| /// generated strings. | ||
| CallSiteInfoLoader(DenseMap<uint64_t, CachedHashStringRef> &StringOffsetMap, | ||
| StringTableBuilder &StrTab, StringSet<> &StringStorage) | ||
| : StringOffsetMap(StringOffsetMap), StrTab(StrTab), | ||
| StringStorage(StringStorage) {} | ||
|
|
||
| /// Loads call site information from a YAML file and populates the provided | ||
| /// FunctionInfo vector. | ||
| /// | ||
alx32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// This method reads the specified YAML file, parses its content, and updates | ||
| /// the `Funcs` vector with call site information based on the YAML data. | ||
| /// | ||
| /// \param Funcs A reference to a vector of FunctionInfo objects to be | ||
| /// populated. | ||
| /// \param YAMLFile A StringRef representing the path to the YAML | ||
| /// file to be loaded. | ||
| /// | ||
alx32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// \returns An `llvm::Error` indicating success or describing any issues | ||
| /// encountered during the loading process. | ||
| llvm::Error loadYAML(std::vector<FunctionInfo> &Funcs, StringRef YAMLFile); | ||
alx32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
alx32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private: | ||
| /// Retrieves an existing string from the StringOffsetMap using the provided | ||
| /// offset. | ||
| /// | ||
| /// \param offset A 32-bit unsigned integer representing the offset of the | ||
| /// string. | ||
| /// | ||
| /// \returns A StringRef corresponding to the string for the given offset. | ||
| /// | ||
| /// \note This method asserts that the offset exists in the StringOffsetMap. | ||
| StringRef stringFromOffset(uint32_t offset) const; | ||
alx32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// Obtains the offset corresponding to a given string in the StrTab. If the | ||
| /// string does not already exist, it is created. | ||
| /// | ||
| /// \param str A StringRef representing the string for which the offset is | ||
| /// requested. | ||
| /// | ||
| /// \returns A 32-bit unsigned integer representing the offset of the string. | ||
| uint32_t offsetFromString(StringRef str); | ||
alx32 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// Builds a map from function names to FunctionInfo pointers based on the | ||
| /// provided `Funcs` vector. | ||
| /// | ||
| /// \param Funcs A reference to a vector of FunctionInfo objects. | ||
| /// | ||
| /// \returns A StringMap mapping function names (StringRef) to their | ||
| /// corresponding FunctionInfo pointers. | ||
| StringMap<FunctionInfo *> buildFunctionMap(std::vector<FunctionInfo> &Funcs); | ||
|
|
||
| /// Processes the parsed YAML functions and updates the `FuncMap` accordingly. | ||
| /// | ||
| /// \param functionsYAML A constant reference to an llvm::yaml::FunctionsYAML | ||
| /// object containing parsed YAML data. | ||
| /// \param FuncMap A reference to a StringMap mapping function names to | ||
| /// FunctionInfo pointers. | ||
| /// | ||
| /// \returns An `llvm::Error` indicating success or describing any issues | ||
| /// encountered during processing. | ||
| llvm::Error | ||
| processYAMLFunctions(const llvm::yaml::FunctionsYAML &functionsYAML, | ||
| StringMap<FunctionInfo *> &FuncMap); | ||
|
|
||
| /// Map of existing string offsets to CachedHashStringRef. | ||
| DenseMap<uint64_t, CachedHashStringRef> &StringOffsetMap; | ||
|
|
||
| /// The gSYM string table builder. | ||
| StringTableBuilder &StrTab; | ||
|
|
||
| /// The gSYM string storage - we store generated strings here. | ||
| StringSet<> &StringStorage; | ||
| }; | ||
|
|
||
| raw_ostream &operator<<(raw_ostream &OS, const CallSiteInfo &CSI); | ||
| raw_ostream &operator<<(raw_ostream &OS, const CallSiteInfoCollection &CSIC); | ||
|
|
||
| } // namespace gsym | ||
| } // namespace llvm | ||
|
|
||
| #endif // LLVM_DEBUGINFO_GSYM_CALLSITEINFO_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.