[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 08:23:27 +01:00
|
|
|
//===-- LibStdcpp.cpp -----------------------------------------------------===//
|
2013-02-21 19:57:10 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00: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
|
2013-02-21 19:57:10 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-09-04 21:01:18 +00:00
|
|
|
#include "LibStdcpp.h"
|
2013-02-21 19:57:10 +00:00
|
|
|
|
[lldb] Move clang-based files out of Symbol
Summary:
This change represents the move of ClangASTImporter, ClangASTMetadata,
ClangExternalASTSourceCallbacks, ClangUtil, CxxModuleHandler, and
TypeSystemClang from lldbSource to lldbPluginExpressionParserClang.h
This explicitly removes knowledge of clang internals from lldbSymbol,
moving towards a more generic core implementation of lldb.
Reviewers: JDevlieghere, davide, aprantl, teemperor, clayborg, labath, jingham, shafik
Subscribers: emaste, mgorny, arphaman, jfb, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73661
2020-01-29 11:59:28 -08:00
|
|
|
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
|
2013-02-21 19:57:10 +00:00
|
|
|
#include "lldb/Core/ValueObject.h"
|
|
|
|
#include "lldb/Core/ValueObjectConstResult.h"
|
2015-10-22 00:23:38 +00:00
|
|
|
#include "lldb/DataFormatters/StringPrinter.h"
|
2015-09-04 00:33:51 +00:00
|
|
|
#include "lldb/DataFormatters/VectorIterator.h"
|
2013-02-21 19:57:10 +00:00
|
|
|
#include "lldb/Target/Target.h"
|
2017-03-04 01:30:05 +00:00
|
|
|
#include "lldb/Utility/DataBufferHeap.h"
|
2017-02-14 19:06:07 +00:00
|
|
|
#include "lldb/Utility/Endian.h"
|
2017-05-12 04:51:55 +00:00
|
|
|
#include "lldb/Utility/Status.h"
|
2017-02-02 21:39:50 +00:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2013-02-21 19:57:10 +00:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
using namespace lldb_private::formatters;
|
|
|
|
|
2016-07-06 09:50:00 +00:00
|
|
|
namespace {
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-09-04 00:33:51 +00:00
|
|
|
class LibstdcppMapIteratorSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
|
2016-07-06 09:50:00 +00:00
|
|
|
/*
|
|
|
|
(std::_Rb_tree_iterator<std::pair<const int, std::basic_string<char,
|
|
|
|
std::char_traits<char>, std::allocator<char> > > >) ibeg = {
|
|
|
|
(_Base_ptr) _M_node = 0x0000000100103910 {
|
|
|
|
(std::_Rb_tree_color) _M_color = _S_black
|
|
|
|
(std::_Rb_tree_node_base::_Base_ptr) _M_parent = 0x00000001001038c0
|
|
|
|
(std::_Rb_tree_node_base::_Base_ptr) _M_left = 0x0000000000000000
|
|
|
|
(std::_Rb_tree_node_base::_Base_ptr) _M_right = 0x0000000000000000
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2016-02-29 19:41:30 +00:00
|
|
|
|
2016-07-06 09:50:00 +00:00
|
|
|
public:
|
|
|
|
explicit LibstdcppMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-09-04 00:33:51 +00:00
|
|
|
size_t CalculateNumChildren() override;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-09-04 00:33:51 +00:00
|
|
|
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-09-04 00:33:51 +00:00
|
|
|
bool Update() override;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-09-04 00:33:51 +00:00
|
|
|
bool MightHaveChildren() override;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-03-06 21:22:25 +00:00
|
|
|
size_t GetIndexOfChildWithName(ConstString name) override;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-09-04 00:33:51 +00:00
|
|
|
private:
|
|
|
|
ExecutionContextRef m_exe_ctx_ref;
|
2022-03-14 13:32:03 -07:00
|
|
|
lldb::addr_t m_pair_address = 0;
|
2015-09-04 00:33:51 +00:00
|
|
|
CompilerType m_pair_type;
|
|
|
|
lldb::ValueObjectSP m_pair_sp;
|
|
|
|
};
|
|
|
|
|
2016-10-25 13:24:53 +00:00
|
|
|
class LibStdcppSharedPtrSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
|
|
|
|
public:
|
|
|
|
explicit LibStdcppSharedPtrSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
|
|
|
|
|
|
|
|
size_t CalculateNumChildren() override;
|
|
|
|
|
|
|
|
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
|
|
|
|
|
|
|
|
bool Update() override;
|
|
|
|
|
|
|
|
bool MightHaveChildren() override;
|
|
|
|
|
2019-03-06 21:22:25 +00:00
|
|
|
size_t GetIndexOfChildWithName(ConstString name) override;
|
2016-10-25 13:24:53 +00:00
|
|
|
};
|
|
|
|
|
2016-07-06 09:50:00 +00:00
|
|
|
} // end of anonymous namespace
|
2013-02-21 19:57:10 +00:00
|
|
|
|
2015-09-04 00:33:51 +00:00
|
|
|
LibstdcppMapIteratorSyntheticFrontEnd::LibstdcppMapIteratorSyntheticFrontEnd(
|
|
|
|
lldb::ValueObjectSP valobj_sp)
|
2022-03-14 13:32:03 -07:00
|
|
|
: SyntheticChildrenFrontEnd(*valobj_sp), m_exe_ctx_ref(), m_pair_type(),
|
|
|
|
m_pair_sp() {
|
2013-02-21 19:57:10 +00:00
|
|
|
if (valobj_sp)
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2015-09-04 00:33:51 +00:00
|
|
|
bool LibstdcppMapIteratorSyntheticFrontEnd::Update() {
|
2013-02-21 19:57:10 +00:00
|
|
|
ValueObjectSP valobj_sp = m_backend.GetSP();
|
|
|
|
if (!valobj_sp)
|
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-02-21 19:57:10 +00:00
|
|
|
TargetSP target_sp(valobj_sp->GetTargetSP());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-02-21 19:57:10 +00:00
|
|
|
if (!target_sp)
|
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-02-21 19:57:10 +00:00
|
|
|
bool is_64bit = (target_sp->GetArchitecture().GetAddressByteSize() == 8);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-02-21 19:57:10 +00:00
|
|
|
if (!valobj_sp)
|
|
|
|
return false;
|
|
|
|
m_exe_ctx_ref = valobj_sp->GetExecutionContextRef();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-02-21 19:57:10 +00:00
|
|
|
ValueObjectSP _M_node_sp(
|
|
|
|
valobj_sp->GetChildMemberWithName(ConstString("_M_node"), true));
|
|
|
|
if (!_M_node_sp)
|
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-02-21 19:57:10 +00:00
|
|
|
m_pair_address = _M_node_sp->GetValueAsUnsigned(0);
|
|
|
|
if (m_pair_address == 0)
|
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-02-21 19:57:10 +00:00
|
|
|
m_pair_address += (is_64bit ? 32 : 16);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-08-24 23:46:31 +00:00
|
|
|
CompilerType my_type(valobj_sp->GetCompilerType());
|
2015-08-13 00:24:24 +00:00
|
|
|
if (my_type.GetNumTemplateArguments() >= 1) {
|
2017-11-13 14:26:21 +00:00
|
|
|
CompilerType pair_type = my_type.GetTypeTemplateArgument(0);
|
|
|
|
if (!pair_type)
|
2013-02-21 19:57:10 +00:00
|
|
|
return false;
|
2013-07-11 22:46:58 +00:00
|
|
|
m_pair_type = pair_type;
|
2013-02-21 19:57:10 +00:00
|
|
|
} else
|
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-02-21 19:57:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-04 00:33:51 +00:00
|
|
|
size_t LibstdcppMapIteratorSyntheticFrontEnd::CalculateNumChildren() {
|
2013-02-21 19:57:10 +00:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::ValueObjectSP
|
2015-09-04 00:33:51 +00:00
|
|
|
LibstdcppMapIteratorSyntheticFrontEnd::GetChildAtIndex(size_t idx) {
|
2013-07-11 22:46:58 +00:00
|
|
|
if (m_pair_address != 0 && m_pair_type) {
|
|
|
|
if (!m_pair_sp)
|
2014-12-09 19:51:20 +00:00
|
|
|
m_pair_sp = CreateValueObjectFromAddress("pair", m_pair_address,
|
|
|
|
m_exe_ctx_ref, m_pair_type);
|
2013-07-11 22:46:58 +00:00
|
|
|
if (m_pair_sp)
|
|
|
|
return m_pair_sp->GetChildAtIndex(idx, true);
|
|
|
|
}
|
2013-02-21 19:57:10 +00:00
|
|
|
return lldb::ValueObjectSP();
|
|
|
|
}
|
|
|
|
|
2015-09-04 00:33:51 +00:00
|
|
|
bool LibstdcppMapIteratorSyntheticFrontEnd::MightHaveChildren() { return true; }
|
2013-02-21 19:57:10 +00:00
|
|
|
|
2015-09-04 00:33:51 +00:00
|
|
|
size_t LibstdcppMapIteratorSyntheticFrontEnd::GetIndexOfChildWithName(
|
2019-03-06 21:22:25 +00:00
|
|
|
ConstString name) {
|
Allow direct comparison of ConstString against StringRef
Summary:
When we want to compare a ConstString against a string literal (or any other non-ConstString),
we currently have to explicitly turn the other string into a ConstString. This makes sense as
comparing ConstStrings against each other is only a fast pointer comparison.
However, currently we (rather incorrectly) use in several places in LLDB temporary ConstStrings when
we just want to compare a given ConstString against a hardcoded value, for example like this:
```
if (extension != ConstString(".oat") && extension != ConstString(".odex"))
```
Obviously this kind of defeats the point of ConstStrings. In the comparison above we would
construct two temporary ConstStrings every time we hit the given code. Constructing a
ConstString is relatively expensive: we need to go to the StringPool, take a read and possibly
an exclusive write-lock and then look up our temporary string in the string map of the pool.
So we do a lot of heavy work for essentially just comparing a <6 characters in two strings.
I initially wanted to just fix these issues by turning the temporary ConstString in static variables/
members, but that made the code much less readable. Instead I propose to add a new overload
for the ConstString comparison operator that takes a StringRef. This comparison operator directly
compares the ConstString content against the given StringRef without turning the StringRef into
a ConstString.
This means that the example above can look like this now:
```
if (extension != ".oat" && extension != ".odex")
```
It also no longer has to unlock/lock two locks and call multiple functions in other TUs for constructing
the temporary ConstString instances. Instead this should end up just being a direct string comparison
of the two given strings on most compilers.
This patch also directly updates all uses of temporary and short ConstStrings in LLDB to use this new
comparison operator. It also adds a some unit tests for the new and old comparison operator.
Reviewers: #lldb, JDevlieghere, espindola, amccarth
Reviewed By: JDevlieghere, amccarth
Subscribers: amccarth, clayborg, JDevlieghere, emaste, arichardson, MaskRay, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D60667
llvm-svn: 359281
2019-04-26 07:21:36 +00:00
|
|
|
if (name == "first")
|
2013-02-21 19:57:10 +00:00
|
|
|
return 0;
|
Allow direct comparison of ConstString against StringRef
Summary:
When we want to compare a ConstString against a string literal (or any other non-ConstString),
we currently have to explicitly turn the other string into a ConstString. This makes sense as
comparing ConstStrings against each other is only a fast pointer comparison.
However, currently we (rather incorrectly) use in several places in LLDB temporary ConstStrings when
we just want to compare a given ConstString against a hardcoded value, for example like this:
```
if (extension != ConstString(".oat") && extension != ConstString(".odex"))
```
Obviously this kind of defeats the point of ConstStrings. In the comparison above we would
construct two temporary ConstStrings every time we hit the given code. Constructing a
ConstString is relatively expensive: we need to go to the StringPool, take a read and possibly
an exclusive write-lock and then look up our temporary string in the string map of the pool.
So we do a lot of heavy work for essentially just comparing a <6 characters in two strings.
I initially wanted to just fix these issues by turning the temporary ConstString in static variables/
members, but that made the code much less readable. Instead I propose to add a new overload
for the ConstString comparison operator that takes a StringRef. This comparison operator directly
compares the ConstString content against the given StringRef without turning the StringRef into
a ConstString.
This means that the example above can look like this now:
```
if (extension != ".oat" && extension != ".odex")
```
It also no longer has to unlock/lock two locks and call multiple functions in other TUs for constructing
the temporary ConstString instances. Instead this should end up just being a direct string comparison
of the two given strings on most compilers.
This patch also directly updates all uses of temporary and short ConstStrings in LLDB to use this new
comparison operator. It also adds a some unit tests for the new and old comparison operator.
Reviewers: #lldb, JDevlieghere, espindola, amccarth
Reviewed By: JDevlieghere, amccarth
Subscribers: amccarth, clayborg, JDevlieghere, emaste, arichardson, MaskRay, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D60667
llvm-svn: 359281
2019-04-26 07:21:36 +00:00
|
|
|
if (name == "second")
|
2013-02-21 19:57:10 +00:00
|
|
|
return 1;
|
|
|
|
return UINT32_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
SyntheticChildrenFrontEnd *
|
|
|
|
lldb_private::formatters::LibstdcppMapIteratorSyntheticFrontEndCreator(
|
|
|
|
CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
|
2016-02-29 19:41:30 +00:00
|
|
|
return (valobj_sp ? new LibstdcppMapIteratorSyntheticFrontEnd(valobj_sp)
|
|
|
|
: nullptr);
|
2013-02-21 19:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
(lldb) fr var ibeg --ptr-depth 1
|
|
|
|
(__gnu_cxx::__normal_iterator<int *, std::vector<int, std::allocator<int> > >)
|
|
|
|
ibeg = {
|
|
|
|
_M_current = 0x00000001001037a0 {
|
|
|
|
*_M_current = 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
SyntheticChildrenFrontEnd *
|
|
|
|
lldb_private::formatters::LibStdcppVectorIteratorSyntheticFrontEndCreator(
|
|
|
|
CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
|
|
|
|
static ConstString g_item_name;
|
|
|
|
if (!g_item_name)
|
|
|
|
g_item_name.SetCString("_M_current");
|
2016-02-29 19:41:30 +00:00
|
|
|
return (valobj_sp
|
|
|
|
? new VectorIteratorSyntheticFrontEnd(valobj_sp, g_item_name)
|
|
|
|
: nullptr);
|
2013-02-21 19:57:10 +00:00
|
|
|
}
|
2015-09-03 01:29:42 +00:00
|
|
|
|
|
|
|
lldb_private::formatters::VectorIteratorSyntheticFrontEnd::
|
|
|
|
VectorIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp,
|
|
|
|
ConstString item_name)
|
2016-02-29 19:41:30 +00:00
|
|
|
: SyntheticChildrenFrontEnd(*valobj_sp), m_exe_ctx_ref(),
|
|
|
|
m_item_name(item_name), m_item_sp() {
|
2015-09-03 01:29:42 +00:00
|
|
|
if (valobj_sp)
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2016-07-06 09:50:00 +00:00
|
|
|
bool VectorIteratorSyntheticFrontEnd::Update() {
|
2015-09-03 01:29:42 +00:00
|
|
|
m_item_sp.reset();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-09-03 01:29:42 +00:00
|
|
|
ValueObjectSP valobj_sp = m_backend.GetSP();
|
|
|
|
if (!valobj_sp)
|
|
|
|
return false;
|
|
|
|
|
2016-07-06 09:50:00 +00:00
|
|
|
if (!valobj_sp)
|
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-07-06 09:50:00 +00:00
|
|
|
ValueObjectSP item_ptr(valobj_sp->GetChildMemberWithName(m_item_name, true));
|
2015-09-03 01:29:42 +00:00
|
|
|
if (!item_ptr)
|
|
|
|
return false;
|
|
|
|
if (item_ptr->GetValueAsUnsigned(0) == 0)
|
|
|
|
return false;
|
2017-05-12 04:51:55 +00:00
|
|
|
Status err;
|
2016-07-06 09:50:00 +00:00
|
|
|
m_exe_ctx_ref = valobj_sp->GetExecutionContextRef();
|
|
|
|
m_item_sp = CreateValueObjectFromAddress(
|
2015-09-03 01:29:42 +00:00
|
|
|
"item", item_ptr->GetValueAsUnsigned(0), m_exe_ctx_ref,
|
2016-07-06 09:50:00 +00:00
|
|
|
item_ptr->GetCompilerType().GetPointeeType());
|
2015-09-03 01:29:42 +00:00
|
|
|
if (err.Fail())
|
|
|
|
m_item_sp.reset();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-06 09:50:00 +00:00
|
|
|
size_t VectorIteratorSyntheticFrontEnd::CalculateNumChildren() { return 1; }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-09-03 01:29:42 +00:00
|
|
|
lldb::ValueObjectSP
|
2016-07-06 09:50:00 +00:00
|
|
|
VectorIteratorSyntheticFrontEnd::GetChildAtIndex(size_t idx) {
|
2015-09-03 01:29:42 +00:00
|
|
|
if (idx == 0)
|
|
|
|
return m_item_sp;
|
|
|
|
return lldb::ValueObjectSP();
|
|
|
|
}
|
|
|
|
|
2016-07-06 09:50:00 +00:00
|
|
|
bool VectorIteratorSyntheticFrontEnd::MightHaveChildren() { return true; }
|
2015-09-03 01:29:42 +00:00
|
|
|
|
2016-07-06 09:50:00 +00:00
|
|
|
size_t VectorIteratorSyntheticFrontEnd::GetIndexOfChildWithName(
|
2019-03-06 21:22:25 +00:00
|
|
|
ConstString name) {
|
Allow direct comparison of ConstString against StringRef
Summary:
When we want to compare a ConstString against a string literal (or any other non-ConstString),
we currently have to explicitly turn the other string into a ConstString. This makes sense as
comparing ConstStrings against each other is only a fast pointer comparison.
However, currently we (rather incorrectly) use in several places in LLDB temporary ConstStrings when
we just want to compare a given ConstString against a hardcoded value, for example like this:
```
if (extension != ConstString(".oat") && extension != ConstString(".odex"))
```
Obviously this kind of defeats the point of ConstStrings. In the comparison above we would
construct two temporary ConstStrings every time we hit the given code. Constructing a
ConstString is relatively expensive: we need to go to the StringPool, take a read and possibly
an exclusive write-lock and then look up our temporary string in the string map of the pool.
So we do a lot of heavy work for essentially just comparing a <6 characters in two strings.
I initially wanted to just fix these issues by turning the temporary ConstString in static variables/
members, but that made the code much less readable. Instead I propose to add a new overload
for the ConstString comparison operator that takes a StringRef. This comparison operator directly
compares the ConstString content against the given StringRef without turning the StringRef into
a ConstString.
This means that the example above can look like this now:
```
if (extension != ".oat" && extension != ".odex")
```
It also no longer has to unlock/lock two locks and call multiple functions in other TUs for constructing
the temporary ConstString instances. Instead this should end up just being a direct string comparison
of the two given strings on most compilers.
This patch also directly updates all uses of temporary and short ConstStrings in LLDB to use this new
comparison operator. It also adds a some unit tests for the new and old comparison operator.
Reviewers: #lldb, JDevlieghere, espindola, amccarth
Reviewed By: JDevlieghere, amccarth
Subscribers: amccarth, clayborg, JDevlieghere, emaste, arichardson, MaskRay, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D60667
llvm-svn: 359281
2019-04-26 07:21:36 +00:00
|
|
|
if (name == "item")
|
2015-09-03 01:29:42 +00:00
|
|
|
return 0;
|
|
|
|
return UINT32_MAX;
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:23:38 +00:00
|
|
|
bool lldb_private::formatters::LibStdcppStringSummaryProvider(
|
|
|
|
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
|
|
|
|
const bool scalar_is_load_addr = true;
|
|
|
|
AddressType addr_type;
|
|
|
|
lldb::addr_t addr_of_string =
|
|
|
|
valobj.GetAddressOf(scalar_is_load_addr, &addr_type);
|
|
|
|
if (addr_of_string != LLDB_INVALID_ADDRESS) {
|
|
|
|
switch (addr_type) {
|
|
|
|
case eAddressTypeLoad: {
|
|
|
|
ProcessSP process_sp(valobj.GetProcessSP());
|
|
|
|
if (!process_sp)
|
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-10-22 00:23:38 +00:00
|
|
|
StringPrinter::ReadStringAndDumpToStreamOptions options(valobj);
|
2017-05-12 04:51:55 +00:00
|
|
|
Status error;
|
2015-10-22 00:23:38 +00:00
|
|
|
lldb::addr_t addr_of_data =
|
|
|
|
process_sp->ReadPointerFromMemory(addr_of_string, error);
|
|
|
|
if (error.Fail() || addr_of_data == 0 ||
|
|
|
|
addr_of_data == LLDB_INVALID_ADDRESS)
|
|
|
|
return false;
|
|
|
|
options.SetLocation(addr_of_data);
|
2021-11-03 13:43:33 +01:00
|
|
|
options.SetTargetSP(valobj.GetTargetSP());
|
2015-10-22 00:23:38 +00:00
|
|
|
options.SetStream(&stream);
|
|
|
|
options.SetNeedsZeroTermination(false);
|
|
|
|
options.SetBinaryZeroIsTerminator(true);
|
|
|
|
lldb::addr_t size_of_data = process_sp->ReadPointerFromMemory(
|
|
|
|
addr_of_string + process_sp->GetAddressByteSize(), error);
|
|
|
|
if (error.Fail())
|
|
|
|
return false;
|
|
|
|
options.SetSourceSize(size_of_data);
|
2020-03-19 12:20:18 +01:00
|
|
|
options.SetHasSourceSize(true);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-10-22 00:23:38 +00:00
|
|
|
if (!StringPrinter::ReadStringAndDumpToStream<
|
|
|
|
StringPrinter::StringElementType::UTF8>(options)) {
|
|
|
|
stream.Printf("Summary Unavailable");
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return true;
|
|
|
|
} break;
|
|
|
|
case eAddressTypeHost:
|
|
|
|
break;
|
|
|
|
case eAddressTypeInvalid:
|
|
|
|
case eAddressTypeFile:
|
|
|
|
break;
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2015-10-22 00:23:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool lldb_private::formatters::LibStdcppWStringSummaryProvider(
|
|
|
|
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
|
|
|
|
const bool scalar_is_load_addr = true;
|
|
|
|
AddressType addr_type;
|
|
|
|
lldb::addr_t addr_of_string =
|
|
|
|
valobj.GetAddressOf(scalar_is_load_addr, &addr_type);
|
|
|
|
if (addr_of_string != LLDB_INVALID_ADDRESS) {
|
|
|
|
switch (addr_type) {
|
|
|
|
case eAddressTypeLoad: {
|
|
|
|
ProcessSP process_sp(valobj.GetProcessSP());
|
|
|
|
if (!process_sp)
|
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-10-22 00:23:38 +00:00
|
|
|
CompilerType wchar_compiler_type =
|
|
|
|
valobj.GetCompilerType().GetBasicTypeFromAST(lldb::eBasicTypeWChar);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-10-22 00:23:38 +00:00
|
|
|
if (!wchar_compiler_type)
|
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-01-15 18:07:52 +00:00
|
|
|
// Safe to pass nullptr for exe_scope here.
|
2019-01-15 20:33:58 +00:00
|
|
|
llvm::Optional<uint64_t> size = wchar_compiler_type.GetBitSize(nullptr);
|
2019-01-15 18:07:52 +00:00
|
|
|
if (!size)
|
|
|
|
return false;
|
|
|
|
const uint32_t wchar_size = *size;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-10-22 00:23:38 +00:00
|
|
|
StringPrinter::ReadStringAndDumpToStreamOptions options(valobj);
|
2017-05-12 04:51:55 +00:00
|
|
|
Status error;
|
2015-10-22 00:23:38 +00:00
|
|
|
lldb::addr_t addr_of_data =
|
|
|
|
process_sp->ReadPointerFromMemory(addr_of_string, error);
|
|
|
|
if (error.Fail() || addr_of_data == 0 ||
|
|
|
|
addr_of_data == LLDB_INVALID_ADDRESS)
|
|
|
|
return false;
|
|
|
|
options.SetLocation(addr_of_data);
|
2021-11-03 13:43:33 +01:00
|
|
|
options.SetTargetSP(valobj.GetTargetSP());
|
2015-10-22 00:23:38 +00:00
|
|
|
options.SetStream(&stream);
|
|
|
|
options.SetNeedsZeroTermination(false);
|
|
|
|
options.SetBinaryZeroIsTerminator(false);
|
|
|
|
lldb::addr_t size_of_data = process_sp->ReadPointerFromMemory(
|
|
|
|
addr_of_string + process_sp->GetAddressByteSize(), error);
|
|
|
|
if (error.Fail())
|
|
|
|
return false;
|
|
|
|
options.SetSourceSize(size_of_data);
|
2020-03-19 12:20:18 +01:00
|
|
|
options.SetHasSourceSize(true);
|
2015-10-22 00:23:38 +00:00
|
|
|
options.SetPrefixToken("L");
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2015-10-22 00:23:38 +00:00
|
|
|
switch (wchar_size) {
|
|
|
|
case 8:
|
|
|
|
return StringPrinter::ReadStringAndDumpToStream<
|
|
|
|
StringPrinter::StringElementType::UTF8>(options);
|
|
|
|
case 16:
|
|
|
|
return StringPrinter::ReadStringAndDumpToStream<
|
|
|
|
StringPrinter::StringElementType::UTF16>(options);
|
|
|
|
case 32:
|
|
|
|
return StringPrinter::ReadStringAndDumpToStream<
|
|
|
|
StringPrinter::StringElementType::UTF32>(options);
|
|
|
|
default:
|
|
|
|
stream.Printf("size for wchar_t is not valid");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} break;
|
|
|
|
case eAddressTypeHost:
|
|
|
|
break;
|
|
|
|
case eAddressTypeInvalid:
|
|
|
|
case eAddressTypeFile:
|
|
|
|
break;
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2015-10-22 00:23:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-10-25 13:24:53 +00:00
|
|
|
|
|
|
|
LibStdcppSharedPtrSyntheticFrontEnd::LibStdcppSharedPtrSyntheticFrontEnd(
|
|
|
|
lldb::ValueObjectSP valobj_sp)
|
|
|
|
: SyntheticChildrenFrontEnd(*valobj_sp) {
|
|
|
|
if (valobj_sp)
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t LibStdcppSharedPtrSyntheticFrontEnd::CalculateNumChildren() { return 1; }
|
|
|
|
|
|
|
|
lldb::ValueObjectSP
|
|
|
|
LibStdcppSharedPtrSyntheticFrontEnd::GetChildAtIndex(size_t idx) {
|
|
|
|
ValueObjectSP valobj_sp = m_backend.GetSP();
|
|
|
|
if (!valobj_sp)
|
|
|
|
return lldb::ValueObjectSP();
|
|
|
|
|
|
|
|
if (idx == 0)
|
|
|
|
return valobj_sp->GetChildMemberWithName(ConstString("_M_ptr"), true);
|
|
|
|
else
|
|
|
|
return lldb::ValueObjectSP();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LibStdcppSharedPtrSyntheticFrontEnd::Update() { return false; }
|
|
|
|
|
|
|
|
bool LibStdcppSharedPtrSyntheticFrontEnd::MightHaveChildren() { return true; }
|
|
|
|
|
|
|
|
size_t LibStdcppSharedPtrSyntheticFrontEnd::GetIndexOfChildWithName(
|
2019-03-06 21:22:25 +00:00
|
|
|
ConstString name) {
|
Allow direct comparison of ConstString against StringRef
Summary:
When we want to compare a ConstString against a string literal (or any other non-ConstString),
we currently have to explicitly turn the other string into a ConstString. This makes sense as
comparing ConstStrings against each other is only a fast pointer comparison.
However, currently we (rather incorrectly) use in several places in LLDB temporary ConstStrings when
we just want to compare a given ConstString against a hardcoded value, for example like this:
```
if (extension != ConstString(".oat") && extension != ConstString(".odex"))
```
Obviously this kind of defeats the point of ConstStrings. In the comparison above we would
construct two temporary ConstStrings every time we hit the given code. Constructing a
ConstString is relatively expensive: we need to go to the StringPool, take a read and possibly
an exclusive write-lock and then look up our temporary string in the string map of the pool.
So we do a lot of heavy work for essentially just comparing a <6 characters in two strings.
I initially wanted to just fix these issues by turning the temporary ConstString in static variables/
members, but that made the code much less readable. Instead I propose to add a new overload
for the ConstString comparison operator that takes a StringRef. This comparison operator directly
compares the ConstString content against the given StringRef without turning the StringRef into
a ConstString.
This means that the example above can look like this now:
```
if (extension != ".oat" && extension != ".odex")
```
It also no longer has to unlock/lock two locks and call multiple functions in other TUs for constructing
the temporary ConstString instances. Instead this should end up just being a direct string comparison
of the two given strings on most compilers.
This patch also directly updates all uses of temporary and short ConstStrings in LLDB to use this new
comparison operator. It also adds a some unit tests for the new and old comparison operator.
Reviewers: #lldb, JDevlieghere, espindola, amccarth
Reviewed By: JDevlieghere, amccarth
Subscribers: amccarth, clayborg, JDevlieghere, emaste, arichardson, MaskRay, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D60667
llvm-svn: 359281
2019-04-26 07:21:36 +00:00
|
|
|
if (name == "_M_ptr")
|
2016-10-25 13:24:53 +00:00
|
|
|
return 0;
|
|
|
|
return UINT32_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
SyntheticChildrenFrontEnd *
|
|
|
|
lldb_private::formatters::LibStdcppSharedPtrSyntheticFrontEndCreator(
|
|
|
|
CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
|
|
|
|
return (valobj_sp ? new LibStdcppSharedPtrSyntheticFrontEnd(valobj_sp)
|
|
|
|
: nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool lldb_private::formatters::LibStdcppSmartPointerSummaryProvider(
|
|
|
|
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
|
|
|
|
ValueObjectSP valobj_sp(valobj.GetNonSyntheticValue());
|
|
|
|
if (!valobj_sp)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ValueObjectSP ptr_sp(
|
|
|
|
valobj_sp->GetChildMemberWithName(ConstString("_M_ptr"), true));
|
|
|
|
if (!ptr_sp)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ValueObjectSP usecount_sp(valobj_sp->GetChildAtNamePath(
|
|
|
|
{ConstString("_M_refcount"), ConstString("_M_pi"),
|
|
|
|
ConstString("_M_use_count")}));
|
|
|
|
if (!usecount_sp)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (ptr_sp->GetValueAsUnsigned(0) == 0 ||
|
|
|
|
usecount_sp->GetValueAsUnsigned(0) == 0) {
|
|
|
|
stream.Printf("nullptr");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status error;
|
2016-10-25 13:24:53 +00:00
|
|
|
ValueObjectSP pointee_sp = ptr_sp->Dereference(error);
|
|
|
|
if (pointee_sp && error.Success()) {
|
|
|
|
if (pointee_sp->DumpPrintableRepresentation(
|
|
|
|
stream, ValueObject::eValueObjectRepresentationStyleSummary,
|
|
|
|
lldb::eFormatInvalid,
|
2016-11-07 23:32:20 +00:00
|
|
|
ValueObject::PrintableRepresentationSpecialCases::eDisable,
|
|
|
|
false)) {
|
2016-10-25 13:24:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stream.Printf("ptr = 0x%" PRIx64, ptr_sp->GetValueAsUnsigned(0));
|
|
|
|
return true;
|
|
|
|
}
|