Go to the documentation of this file.
42 Value::Value() : m_value(), m_compiler_type(), m_data_buffer() {}
45 : m_value(scalar), m_compiler_type(), m_data_buffer() {}
48 : m_value(), m_compiler_type(), m_value_type(
ValueType::HostAddress),
54 : m_value(v.m_value), m_compiler_type(v.m_compiler_type),
55 m_context(v.m_context), m_value_type(v.m_value_type),
56 m_context_type(v.m_context_type), m_data_buffer() {
57 const uintptr_t rhs_value =
59 if ((rhs_value != 0) &&
75 const uintptr_t rhs_value =
77 if ((rhs_value != 0) &&
102 strm->
Printf(
", value_type = %s, context = %p, context_type = %s",
126 return static_cast<RegisterInfo *
>(
m_context);
147 if (scalar_size > 0) {
148 const size_t new_size = curr_size + scalar_size;
160 const uint8_t *src = rhs.
GetBuffer().GetBytes();
162 if (src && src_len > 0) {
163 const size_t new_size = curr_size + src_len;
165 ::memcpy(
m_data_buffer.GetBytes() + curr_size, src, src_len);
210 if (std::optional<uint64_t> size =
GetCompilerType().GetByteSize(scope)) {
218 if (error_ptr && error_ptr->
Success())
308 std::optional<uint64_t> type_size = ast_type.
GetByteSize(
311 if (type_size && *type_size == 0)
316 error.SetErrorString(
"invalid value");
328 limit_byte_size = *type_size;
335 error.SetErrorString(
"extracting data from value failed");
339 if (exe_ctx ==
nullptr) {
340 error.SetErrorString(
"can't read load address (no execution context)");
343 if (process ==
nullptr || !process->
IsAlive()) {
351 if (!target_sections.
IsEmpty()) {
362 error.SetErrorString(
"can't read load address (invalid process)");
376 if (exe_ctx ==
nullptr) {
377 error.SetErrorString(
"can't read file address (no execution context)");
379 error.SetErrorString(
"can't read file address (invalid target)");
383 error.SetErrorString(
"invalid file address");
385 if (module ==
nullptr) {
397 bool resolved =
false;
403 bool process_launched_and_stopped =
410 process_launched_and_stopped) {
412 address = load_address;
422 file_so_addr = so_addr;
433 error.SetErrorStringWithFormat(
434 "unable to resolve the module for file address 0x%" PRIx64
435 " for variable '%s' in %s",
439 error.SetErrorStringWithFormat(
440 "unable to resolve the module for file address 0x%" PRIx64
445 error.SetErrorStringWithFormat(
446 "unable to resolve the module for file address 0x%" PRIx64
447 " for variable '%s'",
450 error.SetErrorStringWithFormat(
451 "unable to resolve the module for file address 0x%" PRIx64,
458 error.SetErrorString(
459 "can't read memory from file address without more context");
487 error.SetErrorStringWithFormat(
"invalid %s address",
507 auto data_sp = std::make_shared<DataBufferHeap>(byte_size,
'\0');
511 uint8_t *dst =
const_cast<uint8_t *
>(data.
PeekData(0, byte_size));
512 if (dst !=
nullptr) {
516 error.SetErrorString(
"trying to read from host address of 0.");
519 memcpy(dst,
reinterpret_cast<uint8_t *
>(address), byte_size);
523 const bool force_live_memory =
true;
525 error, force_live_memory) !=
527 error.SetErrorStringWithFormat(
528 "read memory from 0x%" PRIx64
" failed", (uint64_t)address);
538 const size_t bytes_read =
540 if (bytes_read != byte_size)
541 error.SetErrorStringWithFormat(
542 "read memory from 0x%" PRIx64
" failed (%u of %u bytes read)",
545 error.SetErrorStringWithFormat(
"read memory from 0x%" PRIx64
546 " failed (invalid process)",
551 error.SetErrorStringWithFormat(
"unsupported AddressType value (%i)",
555 error.SetErrorString(
"out of memory");
577 if (
error.Success()) {
585 if ((uintptr_t)addr != (uintptr_t)
m_data_buffer.GetBytes()) {
591 if ((uintptr_t)addr != (uintptr_t)
m_data_buffer.GetBytes()) {
618 switch (value_type) {
624 return "file address";
626 return "load address";
628 return "host address";
630 llvm_unreachable(
"enum cases exhausted.");
634 switch (context_type) {
638 return "RegisterInfo *";
644 llvm_unreachable(
"enum cases exhausted.");
bool GetValueAsScalar(const DataExtractor &data, lldb::offset_t data_offset, size_t data_byte_size, Scalar &value, ExecutionContextScope *exe_scope) const
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
lldb::Format GetValueDefaultFormat()
@ Scalar
A raw scalar value.
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
lldb::offset_t GetByteSize() const override
AddressType GetValueAddressType() const
DataBufferHeap & GetBuffer()
@ Variable
lldb_private::Variable *.
bool IsValid() const
Check if the object state is valid.
void AppendData(const void *src, uint64_t src_len)
virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Format
Display format definitions.
bool GetData(DataExtractor &data, size_t limit_byte_size=UINT32_MAX) const
lldb::offset_t SetByteSize(lldb::offset_t byte_size)
Set the number of bytes in the data buffer.
std::optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
void SetValueType(ValueType value_type)
Process * GetProcessPtr() const
Returns a pointer to the process object.
@ LLDBType
lldb_private::Type *.
Status GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data, Module *module)
@ FileAddress
A file address value.
ValueType GetValueType() const
Value * GetValueAtIndex(size_t idx)
CompilerType m_compiler_type
size_t GetAsMemoryData(void *dst, size_t dst_len, lldb::ByteOrder dst_byte_order, Status &error) const
@ eAddressTypeHost
Address is an address in the process that is running this code.
void CopyData(const void *src, lldb::offset_t src_len)
Makes a copy of the src_len bytes in src.
Target & GetTarget()
Get the target object pointer for this module.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
bool ValueOf(ExecutionContext *exe_ctx)
@ LoadAddress
A load address value.
virtual bool IsAlive()
Check if a process is still alive.
static const char * GetValueTypeAsCString(ValueType context_type)
ConstString GetName() const
Value & operator=(const Value &rhs)
lldb::StateType GetState()
Get accessor for the current process state.
RegisterInfo * GetRegisterInfo() const
void SetCompilerType(const CompilerType &compiler_type)
const Scalar & GetScalar() const
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
static llvm::raw_ostream & error(Stream &strm)
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
bool Success() const
Test for success condition.
void PushValue(const Value &value)
bool StateIsStoppedState(lldb::StateType state, bool must_exist)
Check if a state represents a state where the process or thread is stopped.
void ConvertToLoadAddress(Module *module, Target *target)
Convert this value's file address to a load address, if possible.
unsigned long long ULongLong(unsigned long long fail_value=0) const
lldb::Format GetFormat() const
bool ResolveFileAddress(lldb::addr_t vm_addr, Address &so_addr)
virtual lldb::ByteOrder GetByteOrder() const =0
Gets whether endian swapping should occur when extracting data from this object file.
void AppendBytes(const void *bytes, int len)
ValueType
Type that describes Value::m_value.
size_t GetByteSize() const
DataBufferHeap m_data_buffer
@ eAddressTypeLoad
Address is an address as in the current target inferior process.
static const char * GetContextTypeAsCString(ContextType context_type)
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, bool allow_section_end=false) const
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
size_t GetPointerByteSize() const
AST related queries.
Scalar & ResolveValue(ExecutionContext *exe_ctx)
ContextType m_context_type
const ArchSpec & GetArchitecture() const
size_t ReadMemory(const Address &addr, void *dst, size_t dst_len, Status &error, bool force_live_memory=false, lldb::addr_t *load_addr_ptr=nullptr)
ExecutionContextScope * GetBestExecutionContextScope() const
@ HostAddress
A host address value (for memory in the process that < A is using liblldb).
bool GetData(DataExtractor &data)
lldb::ByteOrder InlHostByteOrder()
@ eAddressTypeFile
Address is an address as found in an object or symbol file.
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
CompilerType GetForwardCompilerType()
lldb::ModuleSP module_sp
The Module for a given query.
void CalculateSymbolContext(SymbolContext *sc)
SectionLoadList & GetSectionLoadList()
#define LLDB_INVALID_ADDRESS
Generic representation of a type in a programming language.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
const CompilerType & GetCompilerType()
@ RegisterInfo
RegisterInfo * (can be a scalar or a vector register).
Target & GetTargetRef() const
Returns a reference to the target object.
void SetBytes(const void *bytes, int len)
A class that represents a running process on the host machine.
virtual uint32_t GetAddressByteSize() const =0
Gets the address size in bytes for the current object file.
size_t ResizeData(size_t len)
ContextType
Type that describes Value::m_context.
bool IsSectionOffset() const
Check if an address is section offset.
void Clear()
Clear the object state.
uint64_t GetValueByteSize(Status *error_ptr, ExecutionContext *exe_ctx)
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Target * GetTargetPtr() const
Returns a pointer to the target object.
size_t AppendDataToHostBuffer(const Value &rhs)
void GetValue(Stream *s, bool show_type) const