This revision was automatically updated to reflect the committed changes.
Closed by commit rGe21fc8770ca4: Add offsetof support to expression evaluator. 
(authored by teemperor).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64917/new/

https://reviews.llvm.org/D64917

Files:
  lldb/packages/Python/lldbsuite/test/lang/c/offsetof/Makefile
  lldb/packages/Python/lldbsuite/test/lang/c/offsetof/TestOffsetof.py
  lldb/packages/Python/lldbsuite/test/lang/c/offsetof/main.c
  lldb/packages/Python/lldbsuite/test/lang/cpp/offsetof/Makefile
  lldb/packages/Python/lldbsuite/test/lang/cpp/offsetof/TestOffsetofCpp.py
  lldb/packages/Python/lldbsuite/test/lang/cpp/offsetof/main.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp


Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
@@ -30,6 +30,9 @@
 using namespace lldb_private;
 
 const char *ClangExpressionSourceCode::g_expression_prefix = R"(
+#ifndef offsetof
+#define offsetof(t, d) __builtin_offsetof(t, d)
+#endif
 #ifndef NULL
 #define NULL (__null)
 #endif
Index: lldb/packages/Python/lldbsuite/test/lang/cpp/offsetof/main.cpp
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/cpp/offsetof/main.cpp
@@ -0,0 +1,25 @@
+#include <cstdint>
+
+class Base {
+  int32_t a;
+};
+class Class1 : Base {
+public:
+  int32_t b;
+};
+
+class EmptyBase {
+};
+class Class2 : EmptyBase {
+public:
+  int32_t b;
+};
+
+int main(int argc, char **argv) {
+  Class1 c1;
+  Class2 c2;
+  //% self.expect("expr offsetof(Base, a)", substrs=["= 0"])
+  //% self.expect("expr offsetof(Class1, b)", substrs=["= 4"])
+  //% self.expect("expr offsetof(Class2, b)", substrs=["= 0"])
+  return c1.b + c2.b;
+}
Index: lldb/packages/Python/lldbsuite/test/lang/cpp/offsetof/TestOffsetofCpp.py
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/cpp/offsetof/TestOffsetofCpp.py
@@ -0,0 +1,3 @@
+from lldbsuite.test import lldbinline
+
+lldbinline.MakeInlineTest(__file__, globals())
Index: lldb/packages/Python/lldbsuite/test/lang/cpp/offsetof/Makefile
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/cpp/offsetof/Makefile
@@ -0,0 +1,3 @@
+LEVEL = ../../../make
+CXX_SOURCES := main.cpp
+include $(LEVEL)/Makefile.rules
Index: lldb/packages/Python/lldbsuite/test/lang/c/offsetof/main.c
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/c/offsetof/main.c
@@ -0,0 +1,12 @@
+#include <stdint.h>
+
+struct Foo {
+  int8_t a;
+  int16_t b;
+};
+
+int main (int argc, char const *argv[]) {
+    struct Foo f;
+    return f.a; //% self.expect("expr offsetof(Foo, a)", substrs = ['= 0'])
+                //% self.expect("expr offsetof(Foo, b)", substrs = ['= 2'])
+}
Index: lldb/packages/Python/lldbsuite/test/lang/c/offsetof/TestOffsetof.py
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/c/offsetof/TestOffsetof.py
@@ -0,0 +1,3 @@
+from lldbsuite.test import lldbinline
+
+lldbinline.MakeInlineTest(__file__, globals())
Index: lldb/packages/Python/lldbsuite/test/lang/c/offsetof/Makefile
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/c/offsetof/Makefile
@@ -0,0 +1,3 @@
+LEVEL = ../../../make
+C_SOURCES := main.c
+include $(LEVEL)/Makefile.rules


Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
@@ -30,6 +30,9 @@
 using namespace lldb_private;
 
 const char *ClangExpressionSourceCode::g_expression_prefix = R"(
+#ifndef offsetof
+#define offsetof(t, d) __builtin_offsetof(t, d)
+#endif
 #ifndef NULL
 #define NULL (__null)
 #endif
Index: lldb/packages/Python/lldbsuite/test/lang/cpp/offsetof/main.cpp
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/cpp/offsetof/main.cpp
@@ -0,0 +1,25 @@
+#include <cstdint>
+
+class Base {
+  int32_t a;
+};
+class Class1 : Base {
+public:
+  int32_t b;
+};
+
+class EmptyBase {
+};
+class Class2 : EmptyBase {
+public:
+  int32_t b;
+};
+
+int main(int argc, char **argv) {
+  Class1 c1;
+  Class2 c2;
+  //% self.expect("expr offsetof(Base, a)", substrs=["= 0"])
+  //% self.expect("expr offsetof(Class1, b)", substrs=["= 4"])
+  //% self.expect("expr offsetof(Class2, b)", substrs=["= 0"])
+  return c1.b + c2.b;
+}
Index: lldb/packages/Python/lldbsuite/test/lang/cpp/offsetof/TestOffsetofCpp.py
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/cpp/offsetof/TestOffsetofCpp.py
@@ -0,0 +1,3 @@
+from lldbsuite.test import lldbinline
+
+lldbinline.MakeInlineTest(__file__, globals())
Index: lldb/packages/Python/lldbsuite/test/lang/cpp/offsetof/Makefile
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/cpp/offsetof/Makefile
@@ -0,0 +1,3 @@
+LEVEL = ../../../make
+CXX_SOURCES := main.cpp
+include $(LEVEL)/Makefile.rules
Index: lldb/packages/Python/lldbsuite/test/lang/c/offsetof/main.c
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/c/offsetof/main.c
@@ -0,0 +1,12 @@
+#include <stdint.h>
+
+struct Foo {
+  int8_t a;
+  int16_t b;
+};
+
+int main (int argc, char const *argv[]) {
+    struct Foo f;
+    return f.a; //% self.expect("expr offsetof(Foo, a)", substrs = ['= 0'])
+                //% self.expect("expr offsetof(Foo, b)", substrs = ['= 2'])
+}
Index: lldb/packages/Python/lldbsuite/test/lang/c/offsetof/TestOffsetof.py
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/c/offsetof/TestOffsetof.py
@@ -0,0 +1,3 @@
+from lldbsuite.test import lldbinline
+
+lldbinline.MakeInlineTest(__file__, globals())
Index: lldb/packages/Python/lldbsuite/test/lang/c/offsetof/Makefile
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/lang/c/offsetof/Makefile
@@ -0,0 +1,3 @@
+LEVEL = ../../../make
+C_SOURCES := main.c
+include $(LEVEL)/Makefile.rules
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to