aboutsummaryrefslogtreecommitdiff
path: root/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/main.cpp
blob: 6a1266528d5e6e93646072c42741ab134b65ac93 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Evil hack: To simulate memory corruption, we want to fiddle with some internals of std::list.
// Make those accessible to us.
#define private public
#define protected public

#ifdef _LIBCPP_INLINE_VISIBILITY
#undef _LIBCPP_INLINE_VISIBILITY
#endif
#define _LIBCPP_INLINE_VISIBILITY
#include <list>

#include <assert.h>

typedef std::list<int> int_list;

int main()
{
#ifdef LLDB_USING_LIBCPP
    int_list *numbers_list = new int_list{1,2,3,4,5,6,7,8,9,10};

    auto *third_elem = numbers_list->__end_.__next_->__next_->__next_; // Set break point at this line.
    assert(third_elem->__value_ == 3);
    auto *fifth_elem = third_elem->__next_->__next_;
    assert(fifth_elem->__value_ == 5);
    fifth_elem->__next_ = third_elem;
#endif

    // Any attempt to free the list will probably crash the program. Let's just leak it.
    return 0; // Set second break point at this line.
}