aprantl created this revision.
aprantl added a reviewer: jingham.
Herald added a project: LLDB.

by respecting the "artificial" attribute on variables. Function arguments that 
are artificial and useful to end-users are being whitelisted by the language 
runtime.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61451

Files:
  lldb/include/lldb/Target/CPPLanguageRuntime.h
  lldb/include/lldb/Target/ObjCLanguageRuntime.h
  lldb/packages/Python/lldbsuite/test/lang/c/vla/TestVLA.py
  lldb/source/Target/CPPLanguageRuntime.cpp
  lldb/source/Target/ObjCLanguageRuntime.cpp

Index: lldb/source/Target/ObjCLanguageRuntime.cpp
===================================================================
--- lldb/source/Target/ObjCLanguageRuntime.cpp
+++ lldb/source/Target/ObjCLanguageRuntime.cpp
@@ -16,6 +16,7 @@
 #include "lldb/Symbol/SymbolFile.h"
 #include "lldb/Symbol/Type.h"
 #include "lldb/Symbol/TypeList.h"
+#include "lldb/Symbol/Variable.h"
 #include "lldb/Target/ObjCLanguageRuntime.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Utility/Log.h"
@@ -37,6 +38,25 @@
       m_isa_to_descriptor_stop_id(UINT32_MAX), m_complete_class_cache(),
       m_negative_complete_class_cache() {}
 
+bool ObjCLanguageRuntime::IsWhitelistedRuntimeValue(ConstString name) {
+  static ConstString g_self = ConstString("self");
+  static ConstString g_cmd = ConstString("_cmd");
+  return name == g_self || name == g_cmd;
+}
+
+bool ObjCLanguageRuntime::IsRuntimeSupportValue(ValueObject &valobj) {
+  // All runtime support values have to be marked as artificial by the
+  // compiler. But not all artificial variables should be hidden from
+  // the user.
+  if (!valobj.GetVariable())
+    return false;
+  if (!valobj.GetVariable()->IsArtificial())
+    return false;
+
+  // Whitelist "self" and "_cmd".
+  return !IsWhitelistedRuntimeValue(valobj.GetName());
+}
+
 bool ObjCLanguageRuntime::AddClass(ObjCISA isa,
                                    const ClassDescriptorSP &descriptor_sp,
                                    const char *class_name) {
Index: lldb/source/Target/CPPLanguageRuntime.cpp
===================================================================
--- lldb/source/Target/CPPLanguageRuntime.cpp
+++ lldb/source/Target/CPPLanguageRuntime.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/Target/CPPLanguageRuntime.h"
+#include "lldb/Target/ObjCLanguageRuntime.h"
 
 #include <string.h>
 
@@ -15,6 +16,7 @@
 #include "llvm/ADT/StringRef.h"
 
 #include "lldb/Symbol/Block.h"
+#include "lldb/Symbol/Variable.h"
 #include "lldb/Symbol/VariableList.h"
 
 #include "lldb/Core/PluginManager.h"
@@ -31,12 +33,30 @@
 using namespace lldb;
 using namespace lldb_private;
 
+static ConstString g_this = ConstString("this");
+
 // Destructor
 CPPLanguageRuntime::~CPPLanguageRuntime() {}
 
 CPPLanguageRuntime::CPPLanguageRuntime(Process *process)
     : LanguageRuntime(process) {}
 
+bool CPPLanguageRuntime::IsRuntimeSupportValue(ValueObject &valobj) {
+  // All runtime support values have to be marked as artificial by the
+  // compiler. But not all artificial variables should be hidden from
+  // the user.
+  if (!valobj.GetVariable())
+    return false;
+  if (!valobj.GetVariable()->IsArtificial())
+    return false;
+
+  // Whitelist "this" and since there is no ObjC++ runtime, any ObjC names.
+  ConstString name = valobj.GetName();
+  if (name == g_this)
+    return true;
+  return !ObjCLanguageRuntime::IsWhitelistedRuntimeValue(name);
+}
+
 bool CPPLanguageRuntime::GetObjectDescription(Stream &str,
                                               ValueObject &object) {
   // C++ has no generic way to do this.
@@ -317,7 +337,7 @@
   StackFrameSP frame = thread.GetStackFrameAtIndex(0);
 
   if (frame) {
-    ValueObjectSP value_sp = frame->FindVariable(ConstString("this"));
+    ValueObjectSP value_sp = frame->FindVariable(g_this);
 
     CPPLanguageRuntime::LibCppStdFunctionCallableInfo callable_info =
         FindLibCppStdFunctionCallableInfo(value_sp);
Index: lldb/packages/Python/lldbsuite/test/lang/c/vla/TestVLA.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lang/c/vla/TestVLA.py
+++ lldb/packages/Python/lldbsuite/test/lang/c/vla/TestVLA.py
@@ -14,12 +14,23 @@
         _, process, _, _ = lldbutil.run_to_source_breakpoint(
             self, "break here", lldb.SBFileSpec('main.c'))
 
+        # Make sure no helper expressions show up in frame variable.
+        var_opts = lldb.SBVariablesOptions()
+        var_opts.SetIncludeArguments(False)
+        var_opts.SetIncludeLocals(True)
+        var_opts.SetInScopeOnly(True)
+        var_opts.SetIncludeStatics(False)
+        var_opts.SetIncludeRuntimeSupportValues(False)
+        var_opts.SetUseDynamic(lldb.eDynamicCanRunTarget)
+        all_locals = self.frame().GetVariables(var_opts)
+        self.assertEqual(len(all_locals), 1)
+        
         def test(a, array):
             for i in range(a):
                 self.expect("fr v vla[%d]"%i, substrs=["int", "%d"%(a-i)])
                 self.expect("expr vla[%d]"%i, substrs=["int", "%d"%(a-i)])
-            self.expect("frame var vla", substrs=array)
-            self.expect("expr      vla", error=True, substrs=["incomplete"])
+            self.expect("fr v vla", substrs=array)
+            self.expect("expr vla", error=True, substrs=["incomplete"])
 
         test(2, ["int []", "[0] = 2, [1] = 1"])
         process.Continue()
Index: lldb/include/lldb/Target/ObjCLanguageRuntime.h
===================================================================
--- lldb/include/lldb/Target/ObjCLanguageRuntime.h
+++ lldb/include/lldb/Target/ObjCLanguageRuntime.h
@@ -292,6 +292,11 @@
   bool GetTypeBitSize(const CompilerType &compiler_type,
                       uint64_t &size) override;
 
+  /// Check whether the name is "self" or "_cmd" and should show up in
+  /// "frame variable".
+  static bool IsWhitelistedRuntimeValue(ConstString name);
+  bool IsRuntimeSupportValue(ValueObject &valobj) override;
+
 protected:
   // Classes that inherit from ObjCLanguageRuntime can see and modify these
   ObjCLanguageRuntime(Process *process);
Index: lldb/include/lldb/Target/CPPLanguageRuntime.h
===================================================================
--- lldb/include/lldb/Target/CPPLanguageRuntime.h
+++ lldb/include/lldb/Target/CPPLanguageRuntime.h
@@ -63,6 +63,7 @@
   lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread,
                                                   bool stop_others);
 
+  bool IsRuntimeSupportValue(ValueObject &valobj) override;
 protected:
   // Classes that inherit from CPPLanguageRuntime can see and modify these
   CPPLanguageRuntime(Process *process);
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to