|
12 | 12 | #include <sstream>
|
13 | 13 | #include <string.h>
|
14 | 14 |
|
| 15 | +#include "llvm/ADT/StringRef.h" |
15 | 16 | #include "llvm/Support/FormatAdapters.h"
|
16 | 17 | #include "llvm/Support/FormatVariadic.h"
|
17 | 18 | #include "llvm/Support/Path.h"
|
@@ -1211,34 +1212,34 @@ llvm::json::Value CreateVariable(lldb::SBValue v, int64_t variablesReference,
|
1211 | 1212 | // give a hint to the IDE that the type has indexed children so that the
|
1212 | 1213 | // request can be broken up in grabbing only a few children at a time. We
|
1213 | 1214 | // want to be careful and only call "v.GetNumChildren()" if we have an array
|
1214 |
| - // type or if we have a synthetic child provider. We don't want to call |
1215 |
| - // "v.GetNumChildren()" on all objects as class, struct and union types |
1216 |
| - // don't need to be completed if they are never expanded. So we want to |
1217 |
| - // avoid calling this to only cases where we it makes sense to keep |
| 1215 | + // type or if we have a synthetic child provider producing indexed children. |
| 1216 | + // We don't want to call "v.GetNumChildren()" on all objects as class, struct |
| 1217 | + // and union types don't need to be completed if they are never expanded. So |
| 1218 | + // we want to avoid calling this to only cases where we it makes sense to keep |
1218 | 1219 | // performance high during normal debugging.
|
1219 | 1220 |
|
1220 | 1221 | // If we have an array type, say that it is indexed and provide the number
|
1221 | 1222 | // of children in case we have a huge array. If we don't do this, then we
|
1222 | 1223 | // might take a while to produce all children at onces which can delay your
|
1223 | 1224 | // debug session.
|
1224 |
| - const bool is_array = desc.type_obj.IsArrayType(); |
1225 |
| - const bool is_synthetic = v.IsSynthetic(); |
1226 |
| - if (is_array || is_synthetic) { |
1227 |
| - const auto num_children = v.GetNumChildren(); |
1228 |
| - // We create a "[raw]" fake child for each synthetic type, so we have to |
1229 |
| - // account for it when returning indexed variables. We don't need to do |
1230 |
| - // this for non-indexed ones. |
1231 |
| - bool has_raw_child = is_synthetic && g_dap.enable_synthetic_child_debugging; |
1232 |
| - int actual_num_children = num_children + (has_raw_child ? 1 : 0); |
1233 |
| - if (is_array) { |
1234 |
| - object.try_emplace("indexedVariables", actual_num_children); |
1235 |
| - } else if (num_children > 0) { |
1236 |
| - // If a type has a synthetic child provider, then the SBType of "v" |
1237 |
| - // won't tell us anything about what might be displayed. So we can check |
1238 |
| - // if the first child's name is "[0]" and then we can say it is indexed. |
1239 |
| - const char *first_child_name = v.GetChildAtIndex(0).GetName(); |
1240 |
| - if (first_child_name && strcmp(first_child_name, "[0]") == 0) |
1241 |
| - object.try_emplace("indexedVariables", actual_num_children); |
| 1225 | + if (desc.type_obj.IsArrayType()) { |
| 1226 | + object.try_emplace("indexedVariables", v.GetNumChildren()); |
| 1227 | + } else if (v.IsSynthetic()) { |
| 1228 | + // For a type with a synthetic child provider, the SBType of "v" won't tell |
| 1229 | + // us anything about what might be displayed. Instead, we check if the first |
| 1230 | + // child's name is "[0]" and then say it is indexed. We call |
| 1231 | + // GetNumChildren() only if the child name matches to avoid a potentially |
| 1232 | + // expensive operation. |
| 1233 | + if (lldb::SBValue first_child = v.GetChildAtIndex(0)) { |
| 1234 | + llvm::StringRef first_child_name = first_child.GetName(); |
| 1235 | + if (first_child_name == "[0]") { |
| 1236 | + size_t num_children = v.GetNumChildren(); |
| 1237 | + // If we are creating a "[raw]" fake child for each synthetic type, we |
| 1238 | + // have to account for it when returning indexed variables. |
| 1239 | + if (g_dap.enable_synthetic_child_debugging) |
| 1240 | + ++num_children; |
| 1241 | + object.try_emplace("indexedVariables", num_children); |
| 1242 | + } |
1242 | 1243 | }
|
1243 | 1244 | }
|
1244 | 1245 | EmplaceSafeString(object, "type", desc.display_type_name);
|
|
0 commit comments