xref: /llvm-project/lldb/test/API/functionalities/data-formatter/bytecode-summary/main.cpp (revision 87659a17d0703c1244211d9f8d1f0c21e816f0e1)
1 // A bare-bones llvm::Optional reimplementation.
2 
3 template <typename T> struct MyOptionalStorage {
4   MyOptionalStorage(T val) : value(val), hasVal(true) {}
5   MyOptionalStorage() {}
6   T value;
7   bool hasVal = false;
8 };
9 
10 template <typename T> struct MyOptional {
11   MyOptionalStorage<T> Storage;
12   MyOptional(T val) : Storage(val) {}
13   MyOptional() {}
14   T &operator*() { return Storage.value; }
15 };
16 
17 void stop() {}
18 
19 int main(int argc, char **argv) {
20   MyOptional<int> x, y = 42;
21   stop(); // break here
22   return *y;
23 }
24 
25 // Produced from the assembler in
26 // Shell/ScriptInterpreter/Python/Inputs/FormatterBytecode/formatter.py
27 __attribute__((used, section("__DATA_CONST,__lldbformatters"))) unsigned char
28     _MyOptional_type_summary[] =
29         "\x01"             // version
30         "\xa4"             // record size
31         "\x01"             // record size
32         "\x10"             // type name size
33         "^MyOptional<.+>$" // type name
34         "\x00"             // flags
35         "\x00"             // sig_summary
36         "\x8d"             // program size
37         "\x01"             // program size
38         "\x1\x22\x7Storage#\x12\x60\x1,C\x10\x1\x5\x11\x2\x1\x22\x6hasVal#"
39         "\x12\x60\x1,\x10\x1e\x2\x22\x1b<could not read MyOptional>\x10G#!\x60 "
40         "\x0P\x10\x6\x22\x4None\x10\x36\x1#\x15\x60 "
41         "\x0#\x16\x60\x5\x22\x5value#\x12\x60\x5#\x17\x60\x1,"
42         "\x10\x6\x22\x4None\x10\x11\x1#\x0\x60\x1#R\x60\x10\x3# "
43         "\x60\x10\x1\x2\x12\x12\x12\x12"; // summary function
44