xref: /llvm-project/lldb/test/API/functionalities/data-formatter/stringprinter/main.cpp (revision acf77bd2fd90d3b1347e50219c556057ef882d55)
199451b44SJordan Rupprecht #include <string>
28093c2eaSPavel Labath #include <cstring>
38093c2eaSPavel Labath 
48093c2eaSPavel Labath struct A {
58093c2eaSPavel Labath   char data[4];
68093c2eaSPavel Labath   char overflow[4];
78093c2eaSPavel Labath };
899451b44SJordan Rupprecht 
911dc235cSPavel Labath #define MAKE_VARS3(c, v, s)                                                    \
1011dc235cSPavel Labath   c v s char c##v##s##chararray[] = #c #v #s "char";                           \
1111dc235cSPavel Labath   c v s char *c##v##s##charstar = c##v##s##chararray
1211dc235cSPavel Labath #define MAKE_VARS2(c, v)                                                       \
1311dc235cSPavel Labath   MAKE_VARS3(c, v, );                                                          \
1411dc235cSPavel Labath   MAKE_VARS3(c, v, signed);                                                    \
1511dc235cSPavel Labath   MAKE_VARS3(c, v, unsigned)
1611dc235cSPavel Labath #define MAKE_VARS(c)                                                           \
1711dc235cSPavel Labath   MAKE_VARS2(c, );                                                             \
1811dc235cSPavel Labath   MAKE_VARS2(c, volatile)
1911dc235cSPavel Labath 
2011dc235cSPavel Labath MAKE_VARS();
2111dc235cSPavel Labath MAKE_VARS(const);
2211dc235cSPavel Labath 
2311dc235cSPavel Labath template<typename T>
2411dc235cSPavel Labath struct S {
2511dc235cSPavel Labath   int x = 0;
2611dc235cSPavel Labath };
2711dc235cSPavel Labath S<char[5]> Schar5;
2811dc235cSPavel Labath S<char *> Scharstar;
2911dc235cSPavel Labath 
main(int argc,char const * argv[])3099451b44SJordan Rupprecht int main (int argc, char const *argv[])
3199451b44SJordan Rupprecht {
32*acf77bd2SPavel Labath     const char manytrailingnuls[] = "F\0OO\0BA\0R\0\0\0\0";
33ca0ce99fSPavel Labath     A a, b, c;
348093c2eaSPavel Labath     // Deliberately write past the end of data to test that the formatter stops
358093c2eaSPavel Labath     // at the end of array.
368093c2eaSPavel Labath     memcpy(a.data, "FOOBAR", 7);
378093c2eaSPavel Labath     memcpy(b.data, "FO\0BAR", 7);
38ca0ce99fSPavel Labath     memcpy(c.data, "F\0O\0AR", 7);
3999451b44SJordan Rupprecht     std::string stdstring("Hello\t\tWorld\nI am here\t\tto say hello\n"); //%self.addTearDownHook(lambda x: x.runCmd("setting set escape-non-printables true"))
4011dc235cSPavel Labath     const char *charwithtabs = stdstring.c_str();
4199451b44SJordan Rupprecht     std::string longstring(
4299451b44SJordan Rupprecht "I am a very long string; in fact I am longer than any reasonable length that a string should be; quite long indeed; oh my, so many words; so many letters; this is kind of like writing a poem; except in real life all that is happening"
4399451b44SJordan Rupprecht " is just me producing a very very long set of words; there is text here, text there, text everywhere; it fills me with glee to see so much text; all around me it's just letters, and symbols, and other pleasant drawings that cause me"
4499451b44SJordan Rupprecht " a large amount of joy upon visually seeing them with my eyes; well, this is now a lot of letters, but it is still not enough for the purpose of the test I want to test, so maybe I should copy and paste this a few times, you know.."
4599451b44SJordan Rupprecht " for science, or something"
4699451b44SJordan Rupprecht       "I am a very long string; in fact I am longer than any reasonable length that a string should be; quite long indeed; oh my, so many words; so many letters; this is kind of like writing a poem; except in real life all that is happening"
4799451b44SJordan Rupprecht       " is just me producing a very very long set of words; there is text here, text there, text everywhere; it fills me with glee to see so much text; all around me it's just letters, and symbols, and other pleasant drawings that cause me"
4899451b44SJordan Rupprecht       " a large amount of joy upon visually seeing them with my eyes; well, this is now a lot of letters, but it is still not enough for the purpose of the test I want to test, so maybe I should copy and paste this a few times, you know.."
4999451b44SJordan Rupprecht       " for science, or something"
5099451b44SJordan Rupprecht             "I am a very long string; in fact I am longer than any reasonable length that a string should be; quite long indeed; oh my, so many words; so many letters; this is kind of like writing a poem; except in real life all that is happening"
5199451b44SJordan Rupprecht             " is just me producing a very very long set of words; there is text here, text there, text everywhere; it fills me with glee to see so much text; all around me it's just letters, and symbols, and other pleasant drawings that cause me"
5299451b44SJordan Rupprecht             " a large amount of joy upon visually seeing them with my eyes; well, this is now a lot of letters, but it is still not enough for the purpose of the test I want to test, so maybe I should copy and paste this a few times, you know.."
5399451b44SJordan Rupprecht             " for science, or something"
5499451b44SJordan Rupprecht       );
5599451b44SJordan Rupprecht     const char* longconstcharstar = longstring.c_str();
5699451b44SJordan Rupprecht     return 0;     //% if self.TraceOn(): self.runCmd('frame variable')
5711dc235cSPavel Labath     //%
588093c2eaSPavel Labath     //% self.expect_var_path('stdstring', summary='"Hello\\t\\tWorld\\nI am here\\t\\tto say hello\\n"')
5911dc235cSPavel Labath     //% self.expect_var_path('charwithtabs', summary='"Hello\\t\\tWorld\\nI am here\\t\\tto say hello\\n"')
60ca0ce99fSPavel Labath     //% self.expect_var_path("a.data", summary='"FOOB"')
61ca0ce99fSPavel Labath     //% self.expect_var_path("b.data", summary=r'"FO\0B"')
62ca0ce99fSPavel Labath     //% self.expect_var_path("c.data", summary=r'"F\0O"')
63*acf77bd2SPavel Labath     //% self.expect_var_path("manytrailingnuls", summary=r'"F\0OO\0BA\0R"')
64ca0ce99fSPavel Labath     //%
6511dc235cSPavel Labath     //% for c in ["", "const"]:
6611dc235cSPavel Labath     //%   for v in ["", "volatile"]:
6731c7165aSPavel Labath     //%     for s in ["", "unsigned"]:
6811dc235cSPavel Labath     //%       summary = '"'+c+v+s+'char"'
6911dc235cSPavel Labath     //%       self.expect_var_path(c+v+s+"chararray", summary=summary)
7011dc235cSPavel Labath     //% # These should be printed normally
7111dc235cSPavel Labath     //%       self.expect_var_path(c+v+s+"charstar", summary=summary)
7211dc235cSPavel Labath     //% Schar5 = self.expect_var_path("Schar5",
7311dc235cSPavel Labath     //%     children=[ValueCheck(name="x", value="0")])
7411dc235cSPavel Labath     //% self.assertIsNone(Schar5.GetSummary())
7511dc235cSPavel Labath     //% Scharstar = self.expect_var_path("Scharstar",
7611dc235cSPavel Labath     //%     children=[ValueCheck(name="x", value="0")])
7711dc235cSPavel Labath     //% self.assertIsNone(Scharstar.GetSummary())
7811dc235cSPavel Labath     //%
7999451b44SJordan Rupprecht     //% self.runCmd("setting set escape-non-printables false")
808093c2eaSPavel Labath     //% self.expect_var_path('stdstring', summary='"Hello\t\tWorld\nI am here\t\tto say hello\n"')
8111dc235cSPavel Labath     //% self.expect_var_path('charwithtabs', summary='"Hello\t\tWorld\nI am here\t\tto say hello\n"')
8299451b44SJordan Rupprecht     //% self.assertTrue(self.frame().FindVariable('longstring').GetSummary().endswith('"...'))
8399451b44SJordan Rupprecht     //% self.assertTrue(self.frame().FindVariable('longconstcharstar').GetSummary().endswith('"...'))
84ca0ce99fSPavel Labath     // FIXME: make "b.data" and "c.data" work sanely
8599451b44SJordan Rupprecht }
8699451b44SJordan Rupprecht 
87