brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · 16ecb1d Raw
83 lines · cpp
1//===-- Expression.cpp ----------------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "lldb/Expression/Expression.h"10#include "lldb/Target/ExecutionContextScope.h"11#include "lldb/Target/Target.h"12 13#include "llvm/ADT/SmallVector.h"14#include "llvm/ADT/StringExtras.h"15#include "llvm/ADT/StringRef.h"16#include "llvm/Support/Error.h"17 18using namespace lldb_private;19 20Expression::Expression(Target &target)21    : m_target_wp(target.shared_from_this()),22      m_jit_start_addr(LLDB_INVALID_ADDRESS),23      m_jit_end_addr(LLDB_INVALID_ADDRESS) {24  // Can't make any kind of expression without a target.25  assert(m_target_wp.lock());26}27 28Expression::Expression(ExecutionContextScope &exe_scope)29    : m_target_wp(exe_scope.CalculateTarget()),30      m_jit_start_addr(LLDB_INVALID_ADDRESS),31      m_jit_end_addr(LLDB_INVALID_ADDRESS) {32  assert(m_target_wp.lock());33}34 35llvm::Expected<FunctionCallLabel>36lldb_private::FunctionCallLabel::fromString(llvm::StringRef label) {37  llvm::SmallVector<llvm::StringRef, 5> components;38  label.split(components, ":", /*MaxSplit=*/4);39 40  if (components.size() != 5)41    return llvm::createStringError("malformed function call label.");42 43  if (components[0] != FunctionCallLabelPrefix)44    return llvm::createStringError(llvm::formatv(45        "expected function call label prefix '{0}' but found '{1}' instead.",46        FunctionCallLabelPrefix, components[0]));47 48  llvm::StringRef discriminator = components[1];49  llvm::StringRef module_label = components[2];50  llvm::StringRef die_label = components[3];51  llvm::StringRef lookup_name = components[4];52 53  lldb::user_id_t module_id = 0;54  if (!llvm::to_integer(module_label, module_id))55    return llvm::createStringError(56        llvm::formatv("failed to parse module ID from '{0}'.", module_label));57 58  lldb::user_id_t die_id;59  if (!llvm::to_integer(die_label, die_id))60    return llvm::createStringError(61        llvm::formatv("failed to parse symbol ID from '{0}'.", die_label));62 63  return FunctionCallLabel{/*.discriminator=*/discriminator,64                           /*.module_id=*/module_id,65                           /*.symbol_id=*/die_id,66                           /*.lookup_name=*/lookup_name};67}68 69std::string lldb_private::FunctionCallLabel::toString() const {70  return llvm::formatv("{0}:{1}:{2:x}:{3:x}:{4}", FunctionCallLabelPrefix,71                       discriminator, module_id, symbol_id, lookup_name)72      .str();73}74 75void llvm::format_provider<FunctionCallLabel>::format(76    const FunctionCallLabel &label, raw_ostream &OS, StringRef Style) {77  OS << llvm::formatv("FunctionCallLabel{ discriminator: {0}, module_id: "78                      "{1:x}, symbol_id: {2:x}, "79                      "lookup_name: {3} }",80                      label.discriminator, label.module_id, label.symbol_id,81                      label.lookup_name);82}83