Author: teemperor Date: Thu Jul 18 10:58:04 2019 New Revision: 366476 URL: http://llvm.org/viewvc/llvm-project?rev=366476&view=rev Log: Add offsetof support to expression evaluator.
Summary: We currently don't support offsetof in the expression evaluator as it is implemented as a macro (which then calls __builtin_offsetof) in stddef.h. The best solution would be to include that header (or even better, import Clang's builtin module), but header-parsing and (cross-platform) importing modules is not ready yet. Until we get this working with modules I would say we add the macro to our existing macro list as we already do with other macros from stddef.h/stdint.h. We should be able to drop all of them once we can import the relevant modules by default. rdar://26040641 Reviewers: shafik, davide Reviewed By: davide Subscribers: clayborg, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D64917 Added: lldb/trunk/packages/Python/lldbsuite/test/lang/c/offsetof/ lldb/trunk/packages/Python/lldbsuite/test/lang/c/offsetof/Makefile lldb/trunk/packages/Python/lldbsuite/test/lang/c/offsetof/TestOffsetof.py lldb/trunk/packages/Python/lldbsuite/test/lang/c/offsetof/main.c lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/offsetof/ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/offsetof/Makefile lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/offsetof/TestOffsetofCpp.py lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/offsetof/main.cpp Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp Added: lldb/trunk/packages/Python/lldbsuite/test/lang/c/offsetof/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/offsetof/Makefile?rev=366476&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/c/offsetof/Makefile (added) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/offsetof/Makefile Thu Jul 18 10:58:04 2019 @@ -0,0 +1,3 @@ +LEVEL = ../../../make +C_SOURCES := main.c +include $(LEVEL)/Makefile.rules Added: lldb/trunk/packages/Python/lldbsuite/test/lang/c/offsetof/TestOffsetof.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/offsetof/TestOffsetof.py?rev=366476&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/c/offsetof/TestOffsetof.py (added) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/offsetof/TestOffsetof.py Thu Jul 18 10:58:04 2019 @@ -0,0 +1,3 @@ +from lldbsuite.test import lldbinline + +lldbinline.MakeInlineTest(__file__, globals()) Added: lldb/trunk/packages/Python/lldbsuite/test/lang/c/offsetof/main.c URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/offsetof/main.c?rev=366476&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/c/offsetof/main.c (added) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/offsetof/main.c Thu Jul 18 10:58:04 2019 @@ -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']) +} Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/offsetof/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/offsetof/Makefile?rev=366476&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/offsetof/Makefile (added) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/offsetof/Makefile Thu Jul 18 10:58:04 2019 @@ -0,0 +1,3 @@ +LEVEL = ../../../make +CXX_SOURCES := main.cpp +include $(LEVEL)/Makefile.rules Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/offsetof/TestOffsetofCpp.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/offsetof/TestOffsetofCpp.py?rev=366476&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/offsetof/TestOffsetofCpp.py (added) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/offsetof/TestOffsetofCpp.py Thu Jul 18 10:58:04 2019 @@ -0,0 +1,3 @@ +from lldbsuite.test import lldbinline + +lldbinline.MakeInlineTest(__file__, globals()) Added: lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/offsetof/main.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/offsetof/main.cpp?rev=366476&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/offsetof/main.cpp (added) +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/offsetof/main.cpp Thu Jul 18 10:58:04 2019 @@ -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; +} Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp?rev=366476&r1=366475&r2=366476&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp (original) +++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp Thu Jul 18 10:58:04 2019 @@ -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 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits