LLDB mainline
Expression.cpp
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8
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#include "llvm/Support/ErrorExtras.h"
18
19using namespace lldb_private;
20
22 : m_target_wp(target.shared_from_this()),
25 // Can't make any kind of expression without a target.
26 assert(m_target_wp.lock());
27}
28
35
36llvm::Expected<FunctionCallLabel>
38 llvm::SmallVector<llvm::StringRef, 5> components;
39 label.split(components, ":", /*MaxSplit=*/4);
40
41 if (components.size() != 5)
42 return llvm::createStringError("malformed function call label.");
43
44 if (components[0] != FunctionCallLabelPrefix)
45 return llvm::createStringErrorV(
46 "expected function call label prefix '{0}' but found '{1}' instead.",
47 FunctionCallLabelPrefix, components[0]);
48
49 llvm::StringRef discriminator = components[1];
50 llvm::StringRef module_label = components[2];
51 llvm::StringRef die_label = components[3];
52 llvm::StringRef lookup_name = components[4];
53
55 if (!llvm::to_integer(module_label, module_id))
56 return llvm::createStringErrorV("failed to parse module ID from '{0}'.",
57 module_label);
58
59 lldb::user_id_t die_id;
60 if (!llvm::to_integer(die_label, die_id))
61 return llvm::createStringErrorV("failed to parse symbol ID from '{0}'.",
62 die_label);
63
64 return FunctionCallLabel{/*.discriminator=*/discriminator,
65 /*.module_id=*/module_id,
66 /*.symbol_id=*/die_id,
67 /*.lookup_name=*/lookup_name};
68}
69
71 return llvm::formatv("{0}:{1}:{2:x}:{3:x}:{4}", FunctionCallLabelPrefix,
73 .str();
74}
75
76void llvm::format_provider<FunctionCallLabel>::format(
77 const FunctionCallLabel &label, raw_ostream &OS, StringRef Style) {
78 OS << llvm::formatv("FunctionCallLabel{ discriminator: {0}, module_id: "
79 "{1:x}, symbol_id: {2:x}, "
80 "lookup_name: {3} }",
81 label.discriminator, label.module_id, label.symbol_id,
82 label.lookup_name);
83}
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
lldb::addr_t m_jit_end_addr
The address of the JITted function within the JIT allocation.
Definition Expression.h:95
lldb::addr_t m_jit_start_addr
An expression might have a process, but it doesn't need to (e.g.
Definition Expression.h:92
lldb::TargetWP m_target_wp
Definition Expression.h:88
Expression(Target &target)
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
constexpr llvm::StringRef FunctionCallLabelPrefix
LLDB attaches this prefix to mangled names of functions that get called from JITted expressions.
Definition Expression.h:151
uint64_t user_id_t
Definition lldb-types.h:82
Holds parsed information about a function call label that LLDB attaches as an AsmLabel to function AS...
Definition Expression.h:110
lldb::user_id_t symbol_id
Unique identifier of the function symbol on which to perform the function call.
Definition Expression.h:122
std::string toString() const
Encode this FunctionCallLabel into its string representation.
llvm::StringRef discriminator
Arbitrary string which language plugins can interpret for their own needs.
Definition Expression.h:113
llvm::StringRef lookup_name
Name to use when searching for the function symbol in module_id.
Definition Expression.h:131
static llvm::Expected< FunctionCallLabel > fromString(llvm::StringRef label)
Decodes the specified function label into a FunctionCallLabel.
lldb::user_id_t module_id
Unique identifier of the lldb_private::Module which contains the symbol identified by symbol_id.
Definition Expression.h:117