Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 188 additions & 0 deletions llvm/include/llvm/DebugInfo/GSYM/CallSiteInfo.h
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"
#include "llvm/DebugInfo/GSYM/ExtractRanges.h"
#include "llvm/Support/YAMLParser.h"
#include <string>
#include <unordered_map>
#include <vector>

namespace llvm {
class DataExtractor;
class raw_ostream;
class StringTableBuilder;
class CachedHashStringRef;

namespace yaml {
struct CallSiteYAML;
struct FunctionYAML;
struct FunctionsYAML;
} // namespace yaml

namespace gsym {
class FileWriter;
struct FunctionInfo;
struct CallSiteInfo {
enum Flags : uint8_t {
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;

/// Offsets into the string table for function names regex patterns.
std::vector<uint32_t> MatchRegex;

/// 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).
///
/// \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
/// 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);

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
/// 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.
///
/// 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.
///
/// \returns An `llvm::Error` indicating success or describing any issues
/// encountered during the loading process.
llvm::Error loadYAML(std::vector<FunctionInfo> &Funcs, StringRef YAMLFile);

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;

/// 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);

/// 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
10 changes: 7 additions & 3 deletions llvm/include/llvm/DebugInfo/GSYM/FunctionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLVM_DEBUGINFO_GSYM_FUNCTIONINFO_H

#include "llvm/ADT/SmallString.h"
#include "llvm/DebugInfo/GSYM/CallSiteInfo.h"
#include "llvm/DebugInfo/GSYM/ExtractRanges.h"
#include "llvm/DebugInfo/GSYM/InlineInfo.h"
#include "llvm/DebugInfo/GSYM/LineTable.h"
Expand Down Expand Up @@ -63,7 +64,9 @@ class GsymReader;
/// enum InfoType {
/// EndOfList = 0u,
/// LineTableInfo = 1u,
/// InlineInfo = 2u
/// InlineInfo = 2u,
/// MergedFunctionsInfo = 3u,
/// CallSiteInfo = 4u
/// };
///
/// This stream of tuples is terminated by a "InfoType" whose value is
Expand All @@ -73,7 +76,7 @@ class GsymReader;
/// clients to still parse the format and skip over any data that they don't
/// understand or want to parse.
///
/// So the function information encoding essientially looks like:
/// So the function information encoding essentially looks like:
///
/// struct {
/// uint32_t Size;
Expand All @@ -92,6 +95,7 @@ struct FunctionInfo {
std::optional<LineTable> OptLineTable;
std::optional<InlineInfo> Inline;
std::optional<MergedFunctionsInfo> MergedFunctions;
std::optional<CallSiteInfoCollection> CallSites;
/// If we encode a FunctionInfo during segmenting so we know its size, we can
/// cache that encoding here so we don't need to re-encode it when saving the
/// GSYM file.
Expand All @@ -107,7 +111,7 @@ struct FunctionInfo {
/// debug info, we might end up with multiple FunctionInfo objects for the
/// same range and we need to be able to tell which one is the better object
/// to use.
bool hasRichInfo() const { return OptLineTable || Inline; }
bool hasRichInfo() const { return OptLineTable || Inline || CallSites; }

/// Query if a FunctionInfo object is valid.
///
Expand Down
11 changes: 10 additions & 1 deletion llvm/include/llvm/DebugInfo/GSYM/GsymCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,22 @@ class GsymCreator {
/// \param FI The function info object to emplace into our functions list.
void addFunctionInfo(FunctionInfo &&FI);

/// Load call site information from a YAML file.
///
/// This function reads call site information from a specified YAML file and
/// adds it to the GSYM data.
///
/// \param YAMLFile The path to the YAML file containing call site
/// information.
llvm::Error loadCallSitesFromYAML(StringRef YAMLFile);

/// Organize merged FunctionInfo's
///
/// This method processes the list of function infos (Funcs) to identify and
/// group functions with overlapping address ranges.
///
/// \param Out Output stream to report information about how merged
/// FunctionInfo's were handeled.
/// FunctionInfo's were handled.
void prepareMergedFunctions(OutputAggregator &Out);

/// Finalize the data in the GSYM creator prior to saving the data out.
Expand Down
20 changes: 20 additions & 0 deletions llvm/include/llvm/DebugInfo/GSYM/GsymReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,26 @@ class GsymReader {
/// \param MFI The object to dump.
void dump(raw_ostream &OS, const MergedFunctionsInfo &MFI);

/// Dump a CallSiteInfo object.
///
/// This function will output the details of a CallSiteInfo object in a
/// human-readable format.
///
/// \param OS The output stream to dump to.
///
/// \param CSI The CallSiteInfo object to dump.
void dump(raw_ostream &OS, const CallSiteInfo &CSI);

/// Dump a CallSiteInfoCollection object.
///
/// This function will iterate over a collection of CallSiteInfo objects and
/// dump each one.
///
/// \param OS The output stream to dump to.
///
/// \param CSIC The CallSiteInfoCollection object to dump.
void dump(raw_ostream &OS, const CallSiteInfoCollection &CSIC);

/// Dump a LineTable object.
///
/// This function will convert any string table indexes and file indexes
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/DebugInfo/GSYM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_llvm_component_library(LLVMDebugInfoGSYM
InlineInfo.cpp
LineTable.cpp
LookupResult.cpp
CallSiteInfo.cpp
MergedFunctionsInfo.cpp
ObjectFileTransformer.cpp
ExtractRanges.cpp
Expand Down
Loading
Loading