@@ -136,14 +136,14 @@ std::vector<std::string> GetStrings(const llvm::json::Object *obj,
136
136
// / first children, so that the user can get a glimpse of its contents at a
137
137
// / glance.
138
138
static std::optional<std::string>
139
- GetSyntheticSummaryForContainer (lldb::SBValue &v) {
139
+ TryCreateAutoSummaryForContainer (lldb::SBValue &v) {
140
140
// We gate this feature because it performs GetNumChildren(), which can
141
141
// cause performance issues because LLDB needs to complete possibly huge
142
142
// types.
143
143
if (!g_vsc.enable_auto_variable_summaries )
144
144
return std::nullopt;
145
145
146
- if (v. TypeIsPointerType () || !v.MightHaveChildren ())
146
+ if (!v.MightHaveChildren ())
147
147
return std::nullopt;
148
148
// / As this operation can be potentially slow, we limit the total time spent
149
149
// / fetching children to a few ms.
@@ -194,28 +194,18 @@ GetSyntheticSummaryForContainer(lldb::SBValue &v) {
194
194
return summary;
195
195
}
196
196
197
- // / Return whether we should dereference an SBValue in order to generate a more
198
- // / meaningful summary string .
199
- static bool ShouldBeDereferencedForSummary (lldb::SBValue &v ) {
197
+ // / Try to create a summary string for the given value that doesn't have a
198
+ // / summary of its own .
199
+ static std::optional<std::string> TryCreateAutoSummary (lldb::SBValue value ) {
200
200
if (!g_vsc.enable_auto_variable_summaries )
201
- return false ;
202
-
203
- if (!v.GetType ().IsPointerType () && !v.GetType ().IsReferenceType ())
204
- return false ;
205
-
206
- // If we are referencing a pointer, we don't dereference to avoid confusing
207
- // the user with the addresses that could shown in the summary.
208
- if (v.Dereference ().GetType ().IsPointerType ())
209
- return false ;
210
-
211
- // If it's synthetic or a pointer to a basic type that provides a summary, we
212
- // don't dereference.
213
- if ((v.IsSynthetic () || v.GetType ().GetPointeeType ().GetBasicType () !=
214
- lldb::eBasicTypeInvalid) &&
215
- !llvm::StringRef (v.GetSummary ()).empty ()) {
216
- return false ;
217
- }
218
- return true ;
201
+ return std::nullopt;
202
+
203
+ // We use the dereferenced value for generating the summary.
204
+ if (value.GetType ().IsPointerType () || value.GetType ().IsReferenceType ())
205
+ value = value.Dereference ();
206
+
207
+ // We only support auto summaries for containers.
208
+ return TryCreateAutoSummaryForContainer (value);
219
209
}
220
210
221
211
void SetValueForKey (lldb::SBValue &v, llvm::json::Object &object,
@@ -227,36 +217,20 @@ void SetValueForKey(lldb::SBValue &v, llvm::json::Object &object,
227
217
if (!error.Success ()) {
228
218
strm << " <error: " << error.GetCString () << " >" ;
229
219
} else {
230
- auto tryDumpSummaryAndValue = [&strm](lldb::SBValue value) {
231
- llvm::StringRef val = value.GetValue ();
232
- llvm::StringRef summary = value.GetSummary ();
233
- if (!val.empty ()) {
234
- strm << val;
235
- if (!summary.empty ())
236
- strm << ' ' << summary;
237
- return true ;
238
- }
239
- if (!summary.empty ()) {
240
- strm << ' ' << summary;
241
- return true ;
242
- }
243
- if (auto container_summary = GetSyntheticSummaryForContainer (value)) {
244
- strm << *container_summary;
245
- return true ;
246
- }
247
- return false ;
248
- };
249
-
250
- // We first try to get the summary from its dereferenced value.
251
- bool done = ShouldBeDereferencedForSummary (v) &&
252
- tryDumpSummaryAndValue (v.Dereference ());
253
-
254
- // We then try to get it from the current value itself.
255
- if (!done)
256
- done = tryDumpSummaryAndValue (v);
257
-
258
- // As last resort, we print its type and address if available.
259
- if (!done) {
220
+ llvm::StringRef value = v.GetValue ();
221
+ llvm::StringRef nonAutoSummary = v.GetSummary ();
222
+ std::optional<std::string> summary = !nonAutoSummary.empty ()
223
+ ? nonAutoSummary.str ()
224
+ : TryCreateAutoSummary (v);
225
+ if (!value.empty ()) {
226
+ strm << value;
227
+ if (summary)
228
+ strm << ' ' << *summary;
229
+ } else if (summary) {
230
+ strm << *summary;
231
+
232
+ // As last resort, we print its type and address if available.
233
+ } else {
260
234
if (llvm::StringRef type_name = v.GetType ().GetDisplayTypeName ();
261
235
!type_name.empty ()) {
262
236
strm << type_name;
0 commit comments