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
18using namespace lldb_private;
19
21 : m_target_wp(target.shared_from_this()),
24 // Can't make any kind of expression without a target.
25 assert(m_target_wp.lock());
26}
27
34
35llvm::Expected<FunctionCallLabel>
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
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
70 return llvm::formatv("{0}:{1}:{2:x}:{3:x}:{4}", FunctionCallLabelPrefix,
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}
"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