Skip to content

Commit 4dda702

Browse files
fix tests
1 parent db12ff1 commit 4dda702

22 files changed

+160
-39
lines changed

lldb/source/DataFormatters/FormatterBytecode.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
#include "FormatterBytecode.h"
1010
#include "lldb/Utility/LLDBLog.h"
1111
#include "lldb/ValueObject/ValueObject.h"
12+
#include "lldb/ValueObject/ValueObjectConstResult.h"
1213
#include "llvm/ADT/StringExtras.h"
1314
#include "llvm/Support/DataExtractor.h"
1415
#include "llvm/Support/Format.h"
1516
#include "llvm/Support/FormatProviders.h"
1617
#include "llvm/Support/FormatVariadicDetails.h"
17-
#include <lldb/ValueObject/ValueObjectConstResult.h>
1818

1919
using namespace lldb;
2020
namespace lldb_private {
@@ -490,10 +490,10 @@ llvm::Error Interpret(std::vector<ControlStackElement> &control,
490490
TYPE_CHECK(Object, String);
491491
auto name = data.Pop<std::string>();
492492
POP_VALOBJ(valobj);
493-
auto index_or_err = valobj->GetIndexOfChildWithName(name);
494-
if (!index_or_err)
493+
if (auto index_or_err = valobj->GetIndexOfChildWithName(name))
494+
data.Push((uint64_t)*index_or_err);
495+
else
495496
return index_or_err.takeError();
496-
data.Push((uint64_t)*index_or_err);
497497
break;
498498
}
499499
case sel_get_type: {

lldb/source/DataFormatters/TypeSynthetic.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ TypeFilterImpl::FrontEnd::GetIndexOfChildWithName(ConstString name) {
6767
}
6868
}
6969
}
70-
return UINT32_MAX;
70+
return llvm::createStringError(
71+
"'SyntheticChildrenFrontEnd::FrontEnd' cannot find index of child '%s'",
72+
name.AsCString());
7173
}
7274

7375
std::string TypeFilterImpl::GetDescription() {

lldb/source/DataFormatters/VectorType.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ class VectorTypeSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
272272
llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name) override {
273273
const char *item_name = name.GetCString();
274274
uint32_t idx = ExtractIndexFromString(item_name);
275-
if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
275+
if (idx == UINT32_MAX ||
276+
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
276277
return llvm::createStringError(
277278
"'SyntheticChildrenFrontEnd::VectorTypeSyntheticFrontEnd' cannot "
278279
"find index of child '%s'",

lldb/source/Plugins/Language/CPlusPlus/GenericBitset.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ class GenericBitsetFrontEnd : public SyntheticChildrenFrontEnd {
2929
GenericBitsetFrontEnd(ValueObject &valobj, StdLib stdlib);
3030

3131
llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name) override {
32-
return formatters::ExtractIndexFromString(name.GetCString());
32+
size_t idx = formatters::ExtractIndexFromString(name.GetCString());
33+
if (idx == UINT32_MAX) {
34+
return llvm::createStringError(
35+
"'SyntheticChildrenFrontend::GenericBitsetFrontEnd' cannot find "
36+
"index of child '%s'",
37+
name.AsCString());
38+
}
39+
return idx;
3340
}
3441

3542
lldb::ChildCacheState Update() override;

lldb/source/Plugins/Language/CPlusPlus/GenericOptional.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ class GenericOptionalFrontend : public SyntheticChildrenFrontEnd {
3939
llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name) override {
4040
if (name == "$$dereference$$")
4141
return 0;
42-
return formatters::ExtractIndexFromString(name.GetCString());
42+
size_t idx = formatters::ExtractIndexFromString(name.GetCString());
43+
if (idx == UINT32_MAX) {
44+
return llvm::createStringError(
45+
"'SyntheticChildrenFrontend::GenericOptionalFrontend' cannot find "
46+
"index of child '%s'",
47+
name.AsCString());
48+
}
49+
return idx;
4350
}
4451

4552
llvm::Expected<uint32_t> CalculateNumChildren() override {

lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,10 @@ ExtractLibcxxStringInfo(ValueObject &valobj) {
465465
return {};
466466

467467
auto index_or_err = l->GetIndexOfChildWithName("__data_");
468-
if (!index_or_err)
468+
if (!index_or_err) {
469469
LLDB_LOG_ERROR(GetLog(LLDBLog::Types), index_or_err.takeError(), "{0}");
470-
return {};
470+
return {};
471+
}
471472

472473
StringLayout layout =
473474
*index_or_err == 0 ? StringLayout::DSC : StringLayout::CSD;

lldb/source/Plugins/Language/CPlusPlus/LibCxxInitializerList.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,20 @@ lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::Update() {
103103
llvm::Expected<size_t>
104104
lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
105105
GetIndexOfChildWithName(ConstString name) {
106-
if (!m_start)
107-
return UINT32_MAX;
108-
return ExtractIndexFromString(name.GetCString());
106+
if (!m_start) {
107+
return llvm::createStringError(
108+
"'SyntheticChildrenFrontend::LibcxxInitializerListSyntheticFrontEnd' "
109+
"cannot find index of child '%s'",
110+
name.AsCString());
111+
}
112+
size_t idx = ExtractIndexFromString(name.GetCString());
113+
if (idx == UINT32_MAX) {
114+
return llvm::createStringError(
115+
"'SyntheticChildrenFrontend::LibcxxInitializerListSyntheticFrontEnd' "
116+
"cannot find index of child '%s'",
117+
name.AsCString());
118+
}
119+
return idx;
109120
}
110121

111122
lldb_private::SyntheticChildrenFrontEnd *

lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,14 @@ class ListIterator {
107107
class AbstractListFrontEnd : public SyntheticChildrenFrontEnd {
108108
public:
109109
llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name) override {
110-
return ExtractIndexFromString(name.GetCString());
110+
size_t idx = ExtractIndexFromString(name.GetCString());
111+
if (idx == UINT32_MAX) {
112+
return llvm::createStringError(
113+
"'SyntheticChildrenFrontend::AbstractListFrontEnd' cannot find index "
114+
"of child '%s'",
115+
name.AsCString());
116+
}
117+
return idx;
111118
}
112119
lldb::ChildCacheState Update() override;
113120

lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,14 @@ lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::Update() {
395395

396396
llvm::Expected<size_t> lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::
397397
GetIndexOfChildWithName(ConstString name) {
398-
return ExtractIndexFromString(name.GetCString());
398+
size_t idx = ExtractIndexFromString(name.GetCString());
399+
if (idx == UINT32_MAX) {
400+
return llvm::createStringError(
401+
"'SyntheticChildrenFrontend::LibcxxStdMapSyntheticFrontEnd' cannot "
402+
"find index of child '%s'",
403+
name.AsCString());
404+
}
405+
return idx;
399406
}
400407

401408
SyntheticChildrenFrontEnd *

lldb/source/Plugins/Language/CPlusPlus/LibCxxProxyArray.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,14 @@ lldb_private::formatters::LibcxxStdProxyArraySyntheticFrontEnd::
181181
"'SyntheticChildrenFrontend::LibcxxStdProxyArraySyntheticFrontEnd' "
182182
"cannot find index of child '%s'",
183183
name.AsCString());
184-
return ExtractIndexFromString(name.GetCString());
184+
size_t idx = ExtractIndexFromString(name.GetCString());
185+
if (idx == UINT32_MAX) {
186+
return llvm::createStringError(
187+
"'SyntheticChildrenFrontend::LibcxxStdProxyArraySyntheticFrontEnd' "
188+
"cannot find index of child '%s'",
189+
name.AsCString());
190+
}
191+
return idx;
185192
}
186193

187194
lldb_private::SyntheticChildrenFrontEnd *

lldb/source/Plugins/Language/CPlusPlus/LibCxxSliceArray.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,14 @@ lldb_private::formatters::LibcxxStdSliceArraySyntheticFrontEnd::
152152
"'SyntheticChildrenFrontend::LibcxxStdSliceArraySyntheticFrontEnd' "
153153
"cannot find index of child '%s'",
154154
name.AsCString());
155-
return ExtractIndexFromString(name.GetCString());
155+
size_t idx = ExtractIndexFromString(name.GetCString());
156+
if (idx == UINT32_MAX) {
157+
return llvm::createStringError(
158+
"'SyntheticChildrenFrontend::LibcxxStdSliceArraySyntheticFrontEnd' "
159+
"cannot find index of child '%s'",
160+
name.AsCString());
161+
}
162+
return idx;
156163
}
157164

158165
lldb_private::SyntheticChildrenFrontEnd *

lldb/source/Plugins/Language/CPlusPlus/LibCxxSpan.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,14 @@ llvm::Expected<size_t> lldb_private::formatters::
134134
"'SyntheticChildrenFrontEnd::LibcxxStdSpanSyntheticFrontEnd' cannot "
135135
"find index of child '%s'",
136136
name.AsCString());
137-
return ExtractIndexFromString(name.GetCString());
137+
size_t idx = ExtractIndexFromString(name.GetCString());
138+
if (idx == UINT32_MAX) {
139+
return llvm::createStringError(
140+
"'SyntheticChildrenFrontend::LibcxxStdSpanSyntheticFrontEnd' cannot "
141+
"find index of child '%s'",
142+
name.AsCString());
143+
}
144+
return idx;
138145
}
139146

140147
lldb_private::SyntheticChildrenFrontEnd *

lldb/source/Plugins/Language/CPlusPlus/LibCxxTuple.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ class TupleFrontEnd: public SyntheticChildrenFrontEnd {
2121
}
2222

2323
llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name) override {
24-
return formatters::ExtractIndexFromString(name.GetCString());
24+
size_t idx = formatters::ExtractIndexFromString(name.GetCString());
25+
if (idx == UINT32_MAX) {
26+
return llvm::createStringError(
27+
"'SyntheticChildrenFrontend::TupleFrontEnd' cannot find index of "
28+
"child '%s'",
29+
name.AsCString());
30+
}
31+
return idx;
2532
}
2633

2734
lldb::ChildCacheState Update() override;

lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,14 @@ lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::Update() {
294294
llvm::Expected<size_t>
295295
lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::
296296
GetIndexOfChildWithName(ConstString name) {
297-
return ExtractIndexFromString(name.GetCString());
297+
size_t idx = ExtractIndexFromString(name.GetCString());
298+
if (idx == UINT32_MAX) {
299+
return llvm::createStringError(
300+
"'SyntheticChildrenFrontend::LibcxxStdUnorderedMapSyntheticFrontEnd' "
301+
"cannot find index of child '%s'",
302+
name.AsCString());
303+
}
304+
return idx;
298305
}
299306

300307
SyntheticChildrenFrontEnd *

lldb/source/Plugins/Language/CPlusPlus/LibCxxValarray.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,14 @@ lldb_private::formatters::LibcxxStdValarraySyntheticFrontEnd::
131131
"'SyntheticChildrenFrontEnd::LibcxxStdValarraySyntheticFrontEnd' "
132132
"cannot find index of child '%s'",
133133
name.AsCString());
134-
return ExtractIndexFromString(name.GetCString());
134+
size_t idx = ExtractIndexFromString(name.GetCString());
135+
if (idx == UINT32_MAX) {
136+
return llvm::createStringError(
137+
"'SyntheticChildrenFrontend::LibcxxStdValarraySyntheticFrontEnd' "
138+
"cannot find index of child '%s'",
139+
name.AsCString());
140+
}
141+
return idx;
135142
}
136143

137144
lldb_private::SyntheticChildrenFrontEnd *

lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,15 @@ lldb_private::formatters::LibcxxStdVectorSyntheticFrontEnd::
171171
"'SyntheticChildrenFrontEnd::LibcxxStdVectorSyntheticFrontEnd' cannot "
172172
"find index of child '%s'",
173173
name.AsCString());
174-
return ExtractIndexFromString(name.GetCString());
174+
size_t index = formatters::ExtractIndexFromString(name.GetCString());
175+
if (index == UINT32_MAX) {
176+
return llvm::createStringError(
177+
"'SyntheticChildrenFrontEnd::LibcxxStdVectorSyntheticFrontEnd' cannot "
178+
"find index of "
179+
"child '%s'",
180+
name.AsCString());
181+
}
182+
return index;
175183
}
176184

177185
lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::
@@ -273,7 +281,8 @@ lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEnd::
273281
name.AsCString());
274282
const char *item_name = name.GetCString();
275283
uint32_t idx = ExtractIndexFromString(item_name);
276-
if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
284+
if (idx == UINT32_MAX ||
285+
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
277286
return llvm::createStringError(
278287
"'SyntheticChildrenFrontEnd::LibcxxVectorBoolSyntheticFrontEnd' cannot "
279288
"find index of child '%s'",

lldb/source/Plugins/Language/CPlusPlus/LibStdcppTuple.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,15 @@ LibStdcppTupleSyntheticFrontEnd::CalculateNumChildren() {
9898

9999
llvm::Expected<size_t>
100100
LibStdcppTupleSyntheticFrontEnd::GetIndexOfChildWithName(ConstString name) {
101-
return ExtractIndexFromString(name.GetCString());
101+
size_t index = formatters::ExtractIndexFromString(name.GetCString());
102+
if (index == UINT32_MAX) {
103+
return llvm::createStringError(
104+
"'SyntheticChildrenFrontEnd::LibStdcppTupleSyntheticFrontEnd' cannot "
105+
"find index of "
106+
"child '%s'",
107+
name.AsCString());
108+
}
109+
return index;
102110
}
103111

104112
SyntheticChildrenFrontEnd *

lldb/source/Plugins/Language/ObjC/NSArray.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,13 @@ lldb_private::formatters::GenericNSArrayMSyntheticFrontEnd<D32, D64>::Update() {
529529
llvm::Expected<size_t> lldb_private::formatters::NSArrayMSyntheticFrontEndBase::
530530
GetIndexOfChildWithName(ConstString name) {
531531
const char *item_name = name.GetCString();
532-
uint32_t idx = ExtractIndexFromString(item_name);
533-
if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
534-
return UINT32_MAX;
532+
size_t idx = ExtractIndexFromString(item_name);
533+
if (idx == UINT32_MAX ||
534+
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
535+
return llvm::createStringError(
536+
"'SyntheticChildrenFrontend::NSArrayMSyntheticFrontEndBase' cannot "
537+
"find index of child '%s'",
538+
name.AsCString());
535539
return idx;
536540
}
537541

@@ -616,8 +620,12 @@ lldb_private::formatters::GenericNSArrayISyntheticFrontEnd<
616620
D32, D64, Inline>::GetIndexOfChildWithName(ConstString name) {
617621
const char *item_name = name.GetCString();
618622
uint32_t idx = ExtractIndexFromString(item_name);
619-
if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
620-
return UINT32_MAX;
623+
if (idx == UINT32_MAX ||
624+
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
625+
return llvm::createStringError(
626+
"'SyntheticChildrenFrontEnd::ObjCClassSyntheticChildrenFrontEnd' "
627+
"cannot find index of child '%s'",
628+
name.AsCString());
621629
return idx;
622630
}
623631

lldb/source/Plugins/Language/ObjC/NSDictionary.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,8 @@ llvm::Expected<size_t> lldb_private::formatters::
589589
NSDictionaryISyntheticFrontEnd::GetIndexOfChildWithName(ConstString name) {
590590
const char *item_name = name.GetCString();
591591
uint32_t idx = ExtractIndexFromString(item_name);
592-
if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
592+
if (idx == UINT32_MAX ||
593+
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
593594
return llvm::createStringError(
594595
"'SyntheticChildrenFrontEnd::NSDictionaryISyntheticFrontEnd' cannot "
595596
"find index of child '%s'",
@@ -725,7 +726,8 @@ llvm::Expected<size_t> lldb_private::formatters::
725726
NSCFDictionarySyntheticFrontEnd::GetIndexOfChildWithName(ConstString name) {
726727
const char *item_name = name.GetCString();
727728
const uint32_t idx = ExtractIndexFromString(item_name);
728-
if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
729+
if (idx == UINT32_MAX ||
730+
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
729731
return llvm::createStringError(
730732
"'SyntheticChildrenFrontEnd::NSCFDictionarySyntheticFrontEnd' cannot "
731733
"find index of child '%s'",
@@ -860,7 +862,8 @@ lldb_private::formatters::NSConstantDictionarySyntheticFrontEnd::
860862
GetIndexOfChildWithName(ConstString name) {
861863
const char *item_name = name.GetCString();
862864
uint32_t idx = ExtractIndexFromString(item_name);
863-
if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
865+
if (idx == UINT32_MAX ||
866+
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
864867
return llvm::createStringError(
865868
"'SyntheticChildrenFrontEnd::NSConstantDictionarySyntheticFrontEnd' "
866869
"cannot find index of child '%s'",
@@ -1065,7 +1068,8 @@ lldb_private::formatters::GenericNSDictionaryMSyntheticFrontEnd<
10651068
D32, D64>::GetIndexOfChildWithName(ConstString name) {
10661069
const char *item_name = name.GetCString();
10671070
uint32_t idx = ExtractIndexFromString(item_name);
1068-
if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
1071+
if (idx == UINT32_MAX ||
1072+
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
10691073
return llvm::createStringError(
10701074
"'SyntheticChildrenFrontEnd::GenericNSDictionaryMSyntheticFrontEnd' "
10711075
"cannot find index of child '%s'",
@@ -1225,7 +1229,8 @@ llvm::Expected<size_t> lldb_private::formatters::Foundation1100::
12251229
NSDictionaryMSyntheticFrontEnd::GetIndexOfChildWithName(ConstString name) {
12261230
const char *item_name = name.GetCString();
12271231
uint32_t idx = ExtractIndexFromString(item_name);
1228-
if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
1232+
if (idx == UINT32_MAX ||
1233+
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
12291234
return llvm::createStringError(
12301235
"'SyntheticChildrenFrontEnd::NSDictionaryMSyntheticFrontEnd' cannot "
12311236
"find index of child '%s'",

lldb/source/Plugins/Language/ObjC/NSIndexPath.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ class NSIndexPathSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
129129
llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name) override {
130130
const char *item_name = name.GetCString();
131131
uint32_t idx = ExtractIndexFromString(item_name);
132-
if (idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())
132+
if (idx == UINT32_MAX ||
133+
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors()))
133134
return llvm::createStringError(
134135
"'SyntheticChildrenFrontEnd::NSIndexPathSyntheticFrontEnd' cannot "
135136
"find index of child '%s'",

0 commit comments

Comments
 (0)