================ @@ -2697,58 +2737,41 @@ void request_dataBreakpointInfo(const llvm::json::Object &request) { GetUnsigned(arguments, "variablesReference", 0); llvm::StringRef name = GetString(arguments, "name"); lldb::SBFrame frame = g_dap.GetLLDBFrame(*arguments); - bool is_duplicated_variable_name = name.contains(" @"); + lldb::SBValue variable = FindVariable(variablesReference, name); + std::string addr, size; - lldb::SBValue variable; - if (lldb::SBValueList *top_scope = GetTopLevelScope(variablesReference)) { - // variablesReference is one of our scopes, not an actual variable it is - // asking for a variable in locals or globals or registers - int64_t end_idx = top_scope->GetSize(); - // Searching backward so that we choose the variable in closest scope - // among variables of the same name. - for (int64_t i = end_idx - 1; i >= 0; --i) { - lldb::SBValue curr_variable = top_scope->GetValueAtIndex(i); - std::string variable_name = CreateUniqueVariableNameForDisplay( - curr_variable, is_duplicated_variable_name); - if (variable_name == name) { - variable = curr_variable; - break; - } - } + if (variable.IsValid()) { + addr = llvm::utohexstr(variable.GetLoadAddress()); + size = llvm::utostr(variable.GetByteSize()); + } else if (variablesReference == 0 && frame.IsValid()) { + // Name might be an expression. In this case we assume that name is composed + // of the number of bytes to watch and expression, separated by '@': + // "${size}@${expression}" + llvm::StringRef expr; + std::tie(size, expr) = name.split('@'); + lldb::SBValue value = frame.EvaluateExpression(expr.data()); + if (value.GetError().Fail()) { + lldb::SBError error = value.GetError(); + const char *error_cstr = error.GetCString(); + body.try_emplace("dataId", nullptr); + body.try_emplace("description", error_cstr && error_cstr[0] + ? std::string(error_cstr) + : "evaluation failed"); + } else + addr = llvm::utohexstr(value.GetValueAsUnsigned()); ---------------- clayborg wrote:
We probably want to check this address by making sure it is valid. What if this return zero? https://github.com/llvm/llvm-project/pull/81541 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits