[Lldb-commits] [lldb] [llvm] [lldb-dap] Add support for data breakpoint. (PR #81541)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Tue Feb 13 13:41:16 PST 2024


================
@@ -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());
----------------
clayborg wrote:

Need some error checking here. `variable.GetLoadAddress()` will only return a valid address if the variable is actually in memory. So if `variable.GetLoadAddress()` returns LLDB_INVALID_ADDRESS we need to return an appropriate error like "<name> does not exist in memory, its location is <location>" where <location> is the result of `const char *SBValue::GetLocation()`.

https://github.com/llvm/llvm-project/pull/81541


More information about the lldb-commits mailing list