[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- Value.cpp ---------------------------------------------------------===//
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Core/Value.h"
|
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Core/Address.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
2015-08-12 06:53:00 +08:00
|
|
|
#include "lldb/Symbol/CompilerType.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
|
|
|
#include "lldb/Symbol/SymbolContext.h"
|
|
|
|
#include "lldb/Symbol/Type.h"
|
|
|
|
#include "lldb/Symbol/Variable.h"
|
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
2013-12-06 09:12:00 +08:00
|
|
|
#include "lldb/Target/SectionLoadList.h"
|
2011-02-16 05:59:32 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Utility/ConstString.h"
|
2017-03-04 09:30:05 +08:00
|
|
|
#include "lldb/Utility/DataBufferHeap.h"
|
|
|
|
#include "lldb/Utility/DataExtractor.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Utility/Endian.h"
|
|
|
|
#include "lldb/Utility/FileSpec.h"
|
2018-08-07 19:07:21 +08:00
|
|
|
#include "lldb/Utility/State.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/lldb-defines.h"
|
|
|
|
#include "lldb/lldb-forward.h"
|
|
|
|
#include "lldb/lldb-types.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2017-04-07 05:28:29 +08:00
|
|
|
|
2021-05-26 18:19:37 +08:00
|
|
|
#include <cinttypes>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2020-11-04 00:22:35 +08:00
|
|
|
Value::Value() : m_value(), m_compiler_type(), m_data_buffer() {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
Value::Value(const Scalar &scalar)
|
2022-03-15 04:32:03 +08:00
|
|
|
: m_value(scalar), m_compiler_type(), m_data_buffer() {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-12 08:24:33 +08:00
|
|
|
Value::Value(const void *bytes, int len)
|
2022-03-15 04:32:03 +08:00
|
|
|
: m_value(), m_compiler_type(), m_value_type(ValueType::HostAddress),
|
2011-07-07 09:59:51 +08:00
|
|
|
m_data_buffer() {
|
2014-07-12 08:24:33 +08:00
|
|
|
SetBytes(bytes, len);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-07-07 09:59:51 +08:00
|
|
|
Value::Value(const Value &v)
|
2020-11-04 00:22:35 +08:00
|
|
|
: m_value(v.m_value), m_compiler_type(v.m_compiler_type),
|
|
|
|
m_context(v.m_context), m_value_type(v.m_value_type),
|
|
|
|
m_context_type(v.m_context_type), m_data_buffer() {
|
2014-05-17 05:49:19 +08:00
|
|
|
const uintptr_t rhs_value =
|
2011-07-07 09:59:51 +08:00
|
|
|
(uintptr_t)v.m_value.ULongLong(LLDB_INVALID_ADDRESS);
|
2014-05-17 05:49:19 +08:00
|
|
|
if ((rhs_value != 0) &&
|
2010-06-09 00:52:24 +08:00
|
|
|
(rhs_value == (uintptr_t)v.m_data_buffer.GetBytes())) {
|
|
|
|
m_data_buffer.CopyData(v.m_data_buffer.GetBytes(),
|
|
|
|
v.m_data_buffer.GetByteSize());
|
|
|
|
|
2011-07-07 09:59:51 +08:00
|
|
|
m_value = (uintptr_t)m_data_buffer.GetBytes();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-12 08:24:33 +08:00
|
|
|
Value &Value::operator=(const Value &rhs) {
|
2013-07-12 06:46:58 +08:00
|
|
|
if (this != &rhs) {
|
|
|
|
m_value = rhs.m_value;
|
2015-09-24 11:54:50 +08:00
|
|
|
m_compiler_type = rhs.m_compiler_type;
|
2013-07-12 06:46:58 +08:00
|
|
|
m_context = rhs.m_context;
|
|
|
|
m_value_type = rhs.m_value_type;
|
|
|
|
m_context_type = rhs.m_context_type;
|
2014-05-17 05:49:19 +08:00
|
|
|
const uintptr_t rhs_value =
|
|
|
|
(uintptr_t)rhs.m_value.ULongLong(LLDB_INVALID_ADDRESS);
|
|
|
|
if ((rhs_value != 0) &&
|
|
|
|
(rhs_value == (uintptr_t)rhs.m_data_buffer.GetBytes())) {
|
2010-06-09 00:52:24 +08:00
|
|
|
m_data_buffer.CopyData(rhs.m_data_buffer.GetBytes(),
|
|
|
|
rhs.m_data_buffer.GetByteSize());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
m_value = (uintptr_t)m_data_buffer.GetBytes();
|
|
|
|
}
|
|
|
|
}
|
2011-01-26 07:55:37 +08:00
|
|
|
return *this;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-01-26 07:55:37 +08:00
|
|
|
void Value::SetBytes(const void *bytes, int len) {
|
2021-02-12 04:57:04 +08:00
|
|
|
m_value_type = ValueType::HostAddress;
|
2011-01-26 07:55:37 +08:00
|
|
|
m_data_buffer.CopyData(bytes, len);
|
|
|
|
m_value = (uintptr_t)m_data_buffer.GetBytes();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-05-17 05:49:19 +08:00
|
|
|
void Value::AppendBytes(const void *bytes, int len) {
|
2021-02-12 04:57:04 +08:00
|
|
|
m_value_type = ValueType::HostAddress;
|
2014-05-17 05:49:19 +08:00
|
|
|
m_data_buffer.AppendData(bytes, len);
|
|
|
|
m_value = (uintptr_t)m_data_buffer.GetBytes();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void Value::Dump(Stream *strm) {
|
|
|
|
m_value.GetValue(strm, true);
|
|
|
|
strm->Printf(", value_type = %s, context = %p, context_type = %s",
|
|
|
|
Value::GetValueTypeAsCString(m_value_type), m_context,
|
2014-05-17 05:49:19 +08:00
|
|
|
Value::GetContextTypeAsCString(m_context_type));
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Value::ValueType Value::GetValueType() const { return m_value_type; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
AddressType Value::GetValueAddressType() const {
|
2014-05-17 05:49:19 +08:00
|
|
|
switch (m_value_type) {
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::Invalid:
|
|
|
|
case ValueType::Scalar:
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::LoadAddress:
|
2010-06-09 00:52:24 +08:00
|
|
|
return eAddressTypeLoad;
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::FileAddress:
|
2010-06-09 00:52:24 +08:00
|
|
|
return eAddressTypeFile;
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::HostAddress:
|
2010-06-09 00:52:24 +08:00
|
|
|
return eAddressTypeHost;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return eAddressTypeInvalid;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-05-01 04:45:04 +08:00
|
|
|
RegisterInfo *Value::GetRegisterInfo() const {
|
2021-02-12 04:57:04 +08:00
|
|
|
if (m_context_type == ContextType::RegisterInfo)
|
2010-06-09 00:52:24 +08:00
|
|
|
return static_cast<RegisterInfo *>(m_context);
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
return nullptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Type *Value::GetType() {
|
2021-02-12 04:57:04 +08:00
|
|
|
if (m_context_type == ContextType::LLDBType)
|
2010-06-09 00:52:24 +08:00
|
|
|
return static_cast<Type *>(m_context);
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
return nullptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-05-17 05:49:19 +08:00
|
|
|
size_t Value::AppendDataToHostBuffer(const Value &rhs) {
|
2017-11-15 02:19:41 +08:00
|
|
|
if (this == &rhs)
|
|
|
|
return 0;
|
|
|
|
|
2011-01-26 07:55:37 +08:00
|
|
|
size_t curr_size = m_data_buffer.GetByteSize();
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2011-01-26 07:55:37 +08:00
|
|
|
switch (rhs.GetValueType()) {
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::Invalid:
|
|
|
|
return 0;
|
|
|
|
case ValueType::Scalar: {
|
2011-01-26 07:55:37 +08:00
|
|
|
const size_t scalar_size = rhs.m_value.GetByteSize();
|
2014-08-01 02:19:28 +08:00
|
|
|
if (scalar_size > 0) {
|
|
|
|
const size_t new_size = curr_size + scalar_size;
|
|
|
|
if (ResizeData(new_size) == new_size) {
|
2011-01-26 07:55:37 +08:00
|
|
|
rhs.m_value.GetAsMemoryData(m_data_buffer.GetBytes() + curr_size,
|
|
|
|
scalar_size, endian::InlHostByteOrder(),
|
|
|
|
error);
|
|
|
|
return scalar_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::FileAddress:
|
|
|
|
case ValueType::LoadAddress:
|
|
|
|
case ValueType::HostAddress: {
|
2010-06-09 00:52:24 +08:00
|
|
|
const uint8_t *src = rhs.GetBuffer().GetBytes();
|
|
|
|
const size_t src_len = rhs.GetBuffer().GetByteSize();
|
2014-08-01 02:19:28 +08:00
|
|
|
if (src && src_len > 0) {
|
2010-06-09 00:52:24 +08:00
|
|
|
const size_t new_size = curr_size + src_len;
|
|
|
|
if (ResizeData(new_size) == new_size) {
|
|
|
|
::memcpy(m_data_buffer.GetBytes() + curr_size, src, src_len);
|
|
|
|
return src_len;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
} break;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-01 04:45:04 +08:00
|
|
|
size_t Value::ResizeData(size_t len) {
|
2021-02-12 04:57:04 +08:00
|
|
|
m_value_type = ValueType::HostAddress;
|
2010-11-13 11:52:47 +08:00
|
|
|
m_data_buffer.SetByteSize(len);
|
2010-06-09 00:52:24 +08:00
|
|
|
m_value = (uintptr_t)m_data_buffer.GetBytes();
|
|
|
|
return m_data_buffer.GetByteSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Value::ValueOf(ExecutionContext *exe_ctx) {
|
2010-11-13 11:52:47 +08:00
|
|
|
switch (m_context_type) {
|
2021-02-12 04:57:04 +08:00
|
|
|
case ContextType::Invalid:
|
|
|
|
case ContextType::RegisterInfo: // RegisterInfo *
|
|
|
|
case ContextType::LLDBType: // Type *
|
2010-06-09 00:52:24 +08:00
|
|
|
break;
|
|
|
|
|
2021-02-12 04:57:04 +08:00
|
|
|
case ContextType::Variable: // Variable *
|
2014-08-01 02:19:28 +08:00
|
|
|
ResolveValue(exe_ctx);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
uint64_t Value::GetValueByteSize(Status *error_ptr, ExecutionContext *exe_ctx) {
|
2010-06-09 00:52:24 +08:00
|
|
|
switch (m_context_type) {
|
2021-02-12 04:57:04 +08:00
|
|
|
case ContextType::RegisterInfo: // RegisterInfo *
|
2019-01-17 05:19:20 +08:00
|
|
|
if (GetRegisterInfo()) {
|
|
|
|
if (error_ptr)
|
|
|
|
error_ptr->Clear();
|
|
|
|
return GetRegisterInfo()->byte_size;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
break;
|
|
|
|
|
2021-02-12 04:57:04 +08:00
|
|
|
case ContextType::Invalid:
|
|
|
|
case ContextType::LLDBType: // Type *
|
|
|
|
case ContextType::Variable: // Variable *
|
2016-09-07 04:57:50 +08:00
|
|
|
{
|
2019-01-17 05:19:20 +08:00
|
|
|
auto *scope = exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr;
|
|
|
|
if (llvm::Optional<uint64_t> size = GetCompilerType().GetByteSize(scope)) {
|
|
|
|
if (error_ptr)
|
|
|
|
error_ptr->Clear();
|
|
|
|
return *size;
|
2019-01-16 20:19:22 +08:00
|
|
|
}
|
2019-01-17 05:19:20 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-01-16 05:26:03 +08:00
|
|
|
}
|
2019-01-17 05:19:20 +08:00
|
|
|
if (error_ptr && error_ptr->Success())
|
|
|
|
error_ptr->SetErrorString("Unable to determine byte size.");
|
|
|
|
return 0;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2015-10-15 06:44:30 +08:00
|
|
|
const CompilerType &Value::GetCompilerType() {
|
|
|
|
if (!m_compiler_type.IsValid()) {
|
2010-06-09 00:52:24 +08:00
|
|
|
switch (m_context_type) {
|
2021-02-12 04:57:04 +08:00
|
|
|
case ContextType::Invalid:
|
2010-06-09 00:52:24 +08:00
|
|
|
break;
|
|
|
|
|
2021-02-12 04:57:04 +08:00
|
|
|
case ContextType::RegisterInfo:
|
2010-06-09 00:52:24 +08:00
|
|
|
break; // TODO: Eventually convert into a compiler type?
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2021-02-12 04:57:04 +08:00
|
|
|
case ContextType::LLDBType: {
|
2015-08-25 07:46:31 +08:00
|
|
|
Type *lldb_type = GetType();
|
2015-09-24 11:54:50 +08:00
|
|
|
if (lldb_type)
|
|
|
|
m_compiler_type = lldb_type->GetForwardCompilerType();
|
2013-07-12 06:46:58 +08:00
|
|
|
} break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2021-02-12 04:57:04 +08:00
|
|
|
case ContextType::Variable: {
|
2013-07-12 06:46:58 +08:00
|
|
|
Variable *variable = GetVariable();
|
|
|
|
if (variable) {
|
|
|
|
Type *variable_type = variable->GetType();
|
|
|
|
if (variable_type)
|
2015-09-24 11:54:50 +08:00
|
|
|
m_compiler_type = variable_type->GetForwardCompilerType();
|
2013-07-12 06:46:58 +08:00
|
|
|
}
|
|
|
|
} break;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2015-09-24 11:54:50 +08:00
|
|
|
return m_compiler_type;
|
2013-07-12 06:46:58 +08:00
|
|
|
}
|
|
|
|
|
2015-09-24 11:54:50 +08:00
|
|
|
void Value::SetCompilerType(const CompilerType &compiler_type) {
|
|
|
|
m_compiler_type = compiler_type;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::Format Value::GetValueDefaultFormat() {
|
|
|
|
switch (m_context_type) {
|
2021-02-12 04:57:04 +08:00
|
|
|
case ContextType::RegisterInfo:
|
2010-06-09 00:52:24 +08:00
|
|
|
if (GetRegisterInfo())
|
|
|
|
return GetRegisterInfo()->format;
|
|
|
|
break;
|
|
|
|
|
2021-02-12 04:57:04 +08:00
|
|
|
case ContextType::Invalid:
|
|
|
|
case ContextType::LLDBType:
|
|
|
|
case ContextType::Variable: {
|
2015-08-25 07:46:31 +08:00
|
|
|
const CompilerType &ast_type = GetCompilerType();
|
2013-07-12 06:46:58 +08:00
|
|
|
if (ast_type.IsValid())
|
|
|
|
return ast_type.GetFormat();
|
2016-09-07 04:57:50 +08:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// Return a good default in case we can't figure anything out
|
|
|
|
return eFormatHex;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-12-14 10:59:59 +08:00
|
|
|
bool Value::GetData(DataExtractor &data) {
|
|
|
|
switch (m_value_type) {
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::Invalid:
|
|
|
|
return false;
|
|
|
|
case ValueType::Scalar:
|
2010-12-14 10:59:59 +08:00
|
|
|
if (m_value.GetData(data))
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::LoadAddress:
|
|
|
|
case ValueType::FileAddress:
|
|
|
|
case ValueType::HostAddress:
|
2010-12-14 10:59:59 +08:00
|
|
|
if (m_data_buffer.GetByteSize()) {
|
|
|
|
data.SetData(m_data_buffer.GetBytes(), m_data_buffer.GetByteSize(),
|
|
|
|
data.GetByteOrder());
|
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status Value::GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data,
|
2019-08-09 03:22:32 +08:00
|
|
|
Module *module) {
|
2010-12-14 10:59:59 +08:00
|
|
|
data.Clear();
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2010-12-14 10:59:59 +08:00
|
|
|
lldb::addr_t address = LLDB_INVALID_ADDRESS;
|
|
|
|
AddressType address_type = eAddressTypeFile;
|
|
|
|
Address file_so_addr;
|
|
|
|
const CompilerType &ast_type = GetCompilerType();
|
2019-11-06 02:53:01 +08:00
|
|
|
llvm::Optional<uint64_t> type_size = ast_type.GetByteSize(
|
|
|
|
exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr);
|
|
|
|
// Nothing to be done for a zero-sized type.
|
|
|
|
if (type_size && *type_size == 0)
|
|
|
|
return error;
|
|
|
|
|
2010-12-14 10:59:59 +08:00
|
|
|
switch (m_value_type) {
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::Invalid:
|
|
|
|
error.SetErrorString("invalid value");
|
|
|
|
break;
|
|
|
|
case ValueType::Scalar: {
|
2010-12-14 10:59:59 +08:00
|
|
|
data.SetByteOrder(endian::InlHostByteOrder());
|
2013-07-12 06:46:58 +08:00
|
|
|
if (ast_type.IsValid())
|
2010-12-14 10:59:59 +08:00
|
|
|
data.SetAddressByteSize(ast_type.GetPointerByteSize());
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2010-12-14 10:59:59 +08:00
|
|
|
data.SetAddressByteSize(sizeof(void *));
|
|
|
|
|
|
|
|
uint32_t limit_byte_size = UINT32_MAX;
|
|
|
|
|
2019-11-06 02:53:01 +08:00
|
|
|
if (type_size)
|
|
|
|
limit_byte_size = *type_size;
|
2010-12-14 10:59:59 +08:00
|
|
|
|
2013-01-12 02:01:02 +08:00
|
|
|
if (limit_byte_size <= m_value.GetByteSize()) {
|
2013-07-12 06:46:58 +08:00
|
|
|
if (m_value.GetData(data, limit_byte_size))
|
|
|
|
return error; // Success;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2020-07-21 13:57:06 +08:00
|
|
|
error.SetErrorString("extracting data from value failed");
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::LoadAddress:
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
if (exe_ctx == nullptr) {
|
2015-11-07 12:40:13 +08:00
|
|
|
error.SetErrorString("can't read load address (no execution context)");
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2011-09-22 12:58:26 +08:00
|
|
|
Process *process = exe_ctx->GetProcessPtr();
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
if (process == nullptr || !process->IsAlive()) {
|
2013-01-12 02:01:02 +08:00
|
|
|
Target *target = exe_ctx->GetTargetPtr();
|
|
|
|
if (target) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Allow expressions to run and evaluate things when the target has
|
|
|
|
// memory sections loaded. This allows you to use "target modules
|
|
|
|
// load" to load your executable and any shared libraries, then
|
|
|
|
// execute commands where you can look at types in data sections.
|
2015-11-07 12:40:13 +08:00
|
|
|
const SectionLoadList &target_sections = target->GetSectionLoadList();
|
2013-01-12 02:01:02 +08:00
|
|
|
if (!target_sections.IsEmpty()) {
|
|
|
|
address = m_value.ULongLong(LLDB_INVALID_ADDRESS);
|
|
|
|
if (target_sections.ResolveLoadAddress(address, file_so_addr)) {
|
|
|
|
address_type = eAddressTypeLoad;
|
2015-11-07 12:40:13 +08:00
|
|
|
data.SetByteOrder(target->GetArchitecture().GetByteOrder());
|
2013-10-09 10:32:37 +08:00
|
|
|
data.SetAddressByteSize(
|
|
|
|
target->GetArchitecture().GetAddressByteSize());
|
|
|
|
} else
|
|
|
|
address = LLDB_INVALID_ADDRESS;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
} else {
|
2011-06-30 06:09:02 +08:00
|
|
|
error.SetErrorString("can't read load address (invalid process)");
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2011-07-07 09:59:51 +08:00
|
|
|
} else {
|
2013-01-12 02:01:02 +08:00
|
|
|
address = m_value.ULongLong(LLDB_INVALID_ADDRESS);
|
|
|
|
address_type = eAddressTypeLoad;
|
|
|
|
data.SetByteOrder(
|
|
|
|
process->GetTarget().GetArchitecture().GetByteOrder());
|
|
|
|
data.SetAddressByteSize(
|
|
|
|
process->GetTarget().GetArchitecture().GetAddressByteSize());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-01-12 02:01:02 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::FileAddress:
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
if (exe_ctx == nullptr) {
|
2013-01-12 02:01:02 +08:00
|
|
|
error.SetErrorString("can't read file address (no execution context)");
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
} else if (exe_ctx->GetTargetPtr() == nullptr) {
|
2013-01-12 02:01:02 +08:00
|
|
|
error.SetErrorString("can't read file address (invalid target)");
|
|
|
|
} else {
|
|
|
|
address = m_value.ULongLong(LLDB_INVALID_ADDRESS);
|
|
|
|
if (address == LLDB_INVALID_ADDRESS) {
|
|
|
|
error.SetErrorString("invalid file address");
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
if (module == nullptr) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// The only thing we can currently lock down to a module so that we
|
|
|
|
// can resolve a file address, is a variable.
|
2011-07-07 09:59:51 +08:00
|
|
|
Variable *variable = GetVariable();
|
|
|
|
if (variable) {
|
|
|
|
SymbolContext var_sc;
|
|
|
|
variable->CalculateSymbolContext(&var_sc);
|
|
|
|
module = var_sc.module_sp.get();
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-06-30 06:09:02 +08:00
|
|
|
if (module) {
|
|
|
|
bool resolved = false;
|
|
|
|
ObjectFile *objfile = module->GetObjectFile();
|
|
|
|
if (objfile) {
|
|
|
|
Address so_addr(address, objfile->GetSectionList());
|
|
|
|
addr_t load_address =
|
|
|
|
so_addr.GetLoadAddress(exe_ctx->GetTargetPtr());
|
|
|
|
bool process_launched_and_stopped =
|
|
|
|
exe_ctx->GetProcessPtr()
|
2011-09-22 12:58:26 +08:00
|
|
|
? StateIsStoppedState(exe_ctx->GetProcessPtr()->GetState(),
|
|
|
|
true /* must_exist */)
|
2011-06-30 06:09:02 +08:00
|
|
|
: false;
|
|
|
|
// Don't use the load address if the process has exited.
|
2011-07-07 09:59:51 +08:00
|
|
|
if (load_address != LLDB_INVALID_ADDRESS &&
|
2010-06-09 00:52:24 +08:00
|
|
|
process_launched_and_stopped) {
|
2011-07-07 09:59:51 +08:00
|
|
|
resolved = true;
|
|
|
|
address = load_address;
|
|
|
|
address_type = eAddressTypeLoad;
|
2013-01-12 02:01:02 +08:00
|
|
|
data.SetByteOrder(
|
2011-09-22 12:58:26 +08:00
|
|
|
exe_ctx->GetTargetRef().GetArchitecture().GetByteOrder());
|
|
|
|
data.SetAddressByteSize(exe_ctx->GetTargetRef()
|
2013-01-12 02:01:02 +08:00
|
|
|
.GetArchitecture()
|
|
|
|
.GetAddressByteSize());
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2011-07-07 09:59:51 +08:00
|
|
|
if (so_addr.IsSectionOffset()) {
|
|
|
|
resolved = true;
|
|
|
|
file_so_addr = so_addr;
|
|
|
|
data.SetByteOrder(objfile->GetByteOrder());
|
|
|
|
data.SetAddressByteSize(objfile->GetAddressByteSize());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-07-07 09:59:51 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-07-07 09:59:51 +08:00
|
|
|
if (!resolved) {
|
|
|
|
Variable *variable = GetVariable();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-07 09:59:51 +08:00
|
|
|
if (module) {
|
|
|
|
if (variable)
|
2012-02-03 06:11:13 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
2012-02-03 03:55:18 +08:00
|
|
|
"unable to resolve the module for file address 0x%" PRIx64
|
|
|
|
" for variable '%s' in %s",
|
2011-09-22 12:58:26 +08:00
|
|
|
address, variable->GetName().AsCString(""),
|
2011-07-07 09:59:51 +08:00
|
|
|
module->GetFileSpec().GetPath().c_str());
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2011-07-07 09:59:51 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"unable to resolve the module for file address 0x%" PRIx64
|
2013-04-30 01:25:54 +08:00
|
|
|
" in %s",
|
|
|
|
address, module->GetFileSpec().GetPath().c_str());
|
2011-07-07 09:59:51 +08:00
|
|
|
} else {
|
2013-04-30 01:25:54 +08:00
|
|
|
if (variable)
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"unable to resolve the module for file address 0x%" PRIx64
|
2012-11-30 05:49:15 +08:00
|
|
|
" for variable '%s'",
|
2011-07-07 09:59:51 +08:00
|
|
|
address, variable->GetName().AsCString(""));
|
|
|
|
else
|
2012-11-30 05:49:15 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"unable to resolve the module for file address 0x%" PRIx64,
|
|
|
|
address);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
2011-07-07 09:59:51 +08:00
|
|
|
// Can't convert a file address to anything valid without more
|
|
|
|
// context (which Module it came from)
|
2013-01-12 02:01:02 +08:00
|
|
|
error.SetErrorString(
|
2011-07-07 09:59:51 +08:00
|
|
|
"can't read memory from file address without more context");
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::HostAddress:
|
2011-07-07 09:59:51 +08:00
|
|
|
address = m_value.ULongLong(LLDB_INVALID_ADDRESS);
|
2012-04-24 09:23:23 +08:00
|
|
|
address_type = eAddressTypeHost;
|
|
|
|
if (exe_ctx) {
|
|
|
|
Target *target = exe_ctx->GetTargetPtr();
|
2013-01-12 02:01:02 +08:00
|
|
|
if (target) {
|
|
|
|
data.SetByteOrder(target->GetArchitecture().GetByteOrder());
|
2012-04-24 09:23:23 +08:00
|
|
|
data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize());
|
2010-06-09 00:52:24 +08:00
|
|
|
break;
|
2012-04-24 09:23:23 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2012-04-24 09:23:23 +08:00
|
|
|
// fallback to host settings
|
2015-11-07 12:40:13 +08:00
|
|
|
data.SetByteOrder(endian::InlHostByteOrder());
|
2013-05-21 06:58:35 +08:00
|
|
|
data.SetAddressByteSize(sizeof(void *));
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// Bail if we encountered any errors
|
|
|
|
if (error.Fail())
|
2016-03-10 08:14:29 +08:00
|
|
|
return error;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (address == LLDB_INVALID_ADDRESS) {
|
|
|
|
error.SetErrorStringWithFormat("invalid %s address",
|
|
|
|
address_type == eAddressTypeHost ? "host"
|
2010-11-02 09:50:16 +08:00
|
|
|
: "load");
|
2010-06-09 00:52:24 +08:00
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-11-04 15:35:56 +08:00
|
|
|
// If we got here, we need to read the value from memory.
|
2010-11-02 09:50:16 +08:00
|
|
|
size_t byte_size = GetValueByteSize(&error, exe_ctx);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-11-04 15:35:56 +08:00
|
|
|
// Bail if we encountered any errors getting the byte size.
|
2015-10-15 06:44:30 +08:00
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-01-17 05:19:20 +08:00
|
|
|
// No memory to read for zero-sized types.
|
|
|
|
if (byte_size == 0)
|
|
|
|
return error;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// Make sure we have enough room within "data", and if we don't make
|
|
|
|
// something large enough that does
|
2019-08-09 03:22:32 +08:00
|
|
|
if (!data.ValidOffsetForDataOfSize(0, byte_size)) {
|
|
|
|
auto data_sp = std::make_shared<DataBufferHeap>(byte_size, '\0');
|
2010-06-09 00:52:24 +08:00
|
|
|
data.SetData(data_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-08-09 03:22:32 +08:00
|
|
|
uint8_t *dst = const_cast<uint8_t *>(data.PeekData(0, byte_size));
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
if (dst != nullptr) {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (address_type == eAddressTypeHost) {
|
2014-03-21 01:13:28 +08:00
|
|
|
// The address is an address in this process, so just copy it.
|
|
|
|
if (address == 0) {
|
2020-07-21 13:57:06 +08:00
|
|
|
error.SetErrorString("trying to read from host address of 0.");
|
2010-06-09 00:52:24 +08:00
|
|
|
return error;
|
|
|
|
}
|
2017-11-03 05:35:26 +08:00
|
|
|
memcpy(dst, reinterpret_cast<uint8_t *>(address), byte_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
} else if ((address_type == eAddressTypeLoad) ||
|
2011-06-30 06:09:02 +08:00
|
|
|
(address_type == eAddressTypeFile)) {
|
|
|
|
if (file_so_addr.IsValid()) {
|
2021-04-17 07:10:16 +08:00
|
|
|
const bool force_live_memory = true;
|
|
|
|
if (exe_ctx->GetTargetRef().ReadMemory(file_so_addr, dst, byte_size,
|
|
|
|
error, force_live_memory) !=
|
|
|
|
byte_size) {
|
2012-11-30 05:49:15 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"read memory from 0x%" PRIx64 " failed", (uint64_t)address);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
} else {
|
2018-05-01 00:49:04 +08:00
|
|
|
// The execution context might have a NULL process, but it might have a
|
|
|
|
// valid process in the exe_ctx->target, so use the
|
|
|
|
// ExecutionContext::GetProcess accessor to ensure we get the process
|
|
|
|
// if there is one.
|
2011-09-22 12:58:26 +08:00
|
|
|
Process *process = exe_ctx->GetProcessPtr();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-07-07 09:59:51 +08:00
|
|
|
if (process) {
|
|
|
|
const size_t bytes_read =
|
2011-03-25 05:19:54 +08:00
|
|
|
process->ReadMemory(address, dst, byte_size, error);
|
2011-09-22 12:58:26 +08:00
|
|
|
if (bytes_read != byte_size)
|
2014-03-21 01:13:28 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
2011-03-25 05:19:54 +08:00
|
|
|
"read memory from 0x%" PRIx64 " failed (%u of %u bytes read)",
|
|
|
|
(uint64_t)address, (uint32_t)bytes_read, (uint32_t)byte_size);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2011-03-25 05:19:54 +08:00
|
|
|
error.SetErrorStringWithFormat("read memory from 0x%" PRIx64
|
2013-01-12 02:01:02 +08:00
|
|
|
" failed (invalid process)",
|
2012-11-30 05:49:15 +08:00
|
|
|
(uint64_t)address);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
2013-04-30 01:25:54 +08:00
|
|
|
error.SetErrorStringWithFormat("unsupported AddressType value (%i)",
|
2012-04-24 09:23:23 +08:00
|
|
|
address_type);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
} else {
|
2020-07-21 13:57:06 +08:00
|
|
|
error.SetErrorString("out of memory");
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
Scalar &Value::ResolveValue(ExecutionContext *exe_ctx) {
|
2015-09-24 11:54:50 +08:00
|
|
|
const CompilerType &compiler_type = GetCompilerType();
|
|
|
|
if (compiler_type.IsValid()) {
|
2010-06-09 00:52:24 +08:00
|
|
|
switch (m_value_type) {
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::Invalid:
|
|
|
|
case ValueType::Scalar: // raw scalar value
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::FileAddress:
|
|
|
|
case ValueType::LoadAddress: // load address value
|
|
|
|
case ValueType::HostAddress: // host address value (for memory in the process
|
2010-06-09 00:52:24 +08:00
|
|
|
// that is using liblldb)
|
|
|
|
{
|
|
|
|
DataExtractor data;
|
2013-01-12 02:01:02 +08:00
|
|
|
lldb::addr_t addr = m_value.ULongLong(LLDB_INVALID_ADDRESS);
|
2019-08-09 03:22:32 +08:00
|
|
|
Status error(GetValueAsData(exe_ctx, data, nullptr));
|
2013-01-12 02:01:02 +08:00
|
|
|
if (error.Success()) {
|
2011-07-07 09:59:51 +08:00
|
|
|
Scalar scalar;
|
2020-07-22 04:53:43 +08:00
|
|
|
if (compiler_type.GetValueAsScalar(
|
|
|
|
data, 0, data.GetByteSize(), scalar,
|
|
|
|
exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr)) {
|
2010-06-09 00:52:24 +08:00
|
|
|
m_value = scalar;
|
2021-02-12 04:57:04 +08:00
|
|
|
m_value_type = ValueType::Scalar;
|
2010-06-09 00:52:24 +08:00
|
|
|
} else {
|
|
|
|
if ((uintptr_t)addr != (uintptr_t)m_data_buffer.GetBytes()) {
|
|
|
|
m_value.Clear();
|
2021-02-12 04:57:04 +08:00
|
|
|
m_value_type = ValueType::Scalar;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2010-06-09 00:52:24 +08:00
|
|
|
if ((uintptr_t)addr != (uintptr_t)m_data_buffer.GetBytes()) {
|
|
|
|
m_value.Clear();
|
2021-02-12 04:57:04 +08:00
|
|
|
m_value_type = ValueType::Scalar;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return m_value;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Variable *Value::GetVariable() {
|
2021-02-12 04:57:04 +08:00
|
|
|
if (m_context_type == ContextType::Variable)
|
2010-06-09 00:52:24 +08:00
|
|
|
return static_cast<Variable *>(m_context);
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
return nullptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
void Value::Clear() {
|
2010-06-09 00:52:24 +08:00
|
|
|
m_value.Clear();
|
2015-09-24 11:54:50 +08:00
|
|
|
m_compiler_type.Clear();
|
2021-02-12 04:57:04 +08:00
|
|
|
m_value_type = ValueType::Scalar;
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
m_context = nullptr;
|
2021-02-12 04:57:04 +08:00
|
|
|
m_context_type = ContextType::Invalid;
|
2013-07-12 06:46:58 +08:00
|
|
|
m_data_buffer.Clear();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
const char *Value::GetValueTypeAsCString(ValueType value_type) {
|
|
|
|
switch (value_type) {
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::Invalid:
|
|
|
|
return "invalid";
|
|
|
|
case ValueType::Scalar:
|
2010-06-09 00:52:24 +08:00
|
|
|
return "scalar";
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::FileAddress:
|
2010-06-09 00:52:24 +08:00
|
|
|
return "file address";
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::LoadAddress:
|
2010-06-09 00:52:24 +08:00
|
|
|
return "load address";
|
2021-02-12 04:57:04 +08:00
|
|
|
case ValueType::HostAddress:
|
2010-06-09 00:52:24 +08:00
|
|
|
return "host address";
|
2016-09-07 04:57:50 +08:00
|
|
|
};
|
2021-02-12 04:57:04 +08:00
|
|
|
llvm_unreachable("enum cases exhausted.");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
const char *Value::GetContextTypeAsCString(ContextType context_type) {
|
|
|
|
switch (context_type) {
|
2021-02-12 04:57:04 +08:00
|
|
|
case ContextType::Invalid:
|
2011-07-07 09:59:51 +08:00
|
|
|
return "invalid";
|
2021-02-12 04:57:04 +08:00
|
|
|
case ContextType::RegisterInfo:
|
2011-07-07 09:59:51 +08:00
|
|
|
return "RegisterInfo *";
|
2021-02-12 04:57:04 +08:00
|
|
|
case ContextType::LLDBType:
|
2011-07-07 09:59:51 +08:00
|
|
|
return "Type *";
|
2021-02-12 04:57:04 +08:00
|
|
|
case ContextType::Variable:
|
2011-07-07 09:59:51 +08:00
|
|
|
return "Variable *";
|
2016-09-07 04:57:50 +08:00
|
|
|
};
|
2021-02-12 04:57:04 +08:00
|
|
|
llvm_unreachable("enum cases exhausted.");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2018-05-04 07:32:47 +08:00
|
|
|
void Value::ConvertToLoadAddress(Module *module, Target *target) {
|
2021-02-12 04:57:04 +08:00
|
|
|
if (!module || !target || (GetValueType() != ValueType::FileAddress))
|
2018-05-04 07:32:47 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
lldb::addr_t file_addr = GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
|
|
|
|
if (file_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Address so_addr;
|
|
|
|
if (!module->ResolveFileAddress(file_addr, so_addr))
|
|
|
|
return;
|
|
|
|
lldb::addr_t load_addr = so_addr.GetLoadAddress(target);
|
|
|
|
if (load_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
return;
|
|
|
|
|
2021-02-12 04:57:04 +08:00
|
|
|
SetValueType(Value::ValueType::LoadAddress);
|
2018-05-04 07:32:47 +08:00
|
|
|
GetScalar() = load_addr;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void ValueList::PushValue(const Value &value) { m_values.push_back(value); }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t ValueList::GetSize() { return m_values.size(); }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Value *ValueList::GetValueAtIndex(size_t idx) {
|
|
|
|
if (idx < GetSize()) {
|
|
|
|
return &(m_values[idx]);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ValueList::Clear() { m_values.clear(); }
|