каждый,
Я использую OpenFOAM, и он сделал свой собственный тип Foam :: string и Foam :: word следующим образом:
(gdb) ptype Foam::word
type = class Foam::word : public Foam::string {
public:
static pointer typeName;
static int debug;
static const Foam::word null;
private:
void stripInvalid(void);
public:
word(void);
word(const Foam::word &);
word(pointer, bool);
word(pointer, size_type, bool);
word(const Foam::string &, bool);
word(const std::__cxx11::string &, bool);
word(Foam::Istream &);
static bool valid(char);
void operator=(const Foam::word &);
void operator=(const Foam::string &);
void operator=(const std::__cxx11::string &);
void operator=(pointer);
}
(gdb) ptype Foam::string
type = class Foam::string : public std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > {
public:
static pointer typeName;
static int debug;
static const Foam::string null;
string(void);
string(const std::__cxx11::string &);
string(pointer);
string(pointer, size_type);
string(char);
string(Foam::Istream &);
size_type count(char) const;
bool match(const std::__cxx11::string &) const;
Foam::string & replace(const Foam::string &, const Foam::string &, size_type);
Foam::string & replaceAll(const Foam::string &, const Foam::string &, size_type);
Foam::string & expand(bool);
bool removeRepeated(char);
Foam::string removeRepeated(char) const;
bool removeTrailing(char);
Foam::string removeTrailing(char) const;
Foam::string operator()(size_type, size_type) const;
Foam::string operator()(size_type) const;
static bool stripInvalid<Foam::word>(Foam::string &);
static bool stripInvalid<Foam::fileName>(Foam::string &);
static bool valid<Foam::word>(const Foam::string &);
static bool valid<Foam::fileName>(const Foam::string &);
}
Теперь можно распечатать Foam::string::null
как это:
(gdb) p Foam::string::null
$82 = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0, static null = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "",
static typeName = 0x7ffff4e38b8a "string", static debug = 0, static null = <same as static member of an already seen type>}}
Однако когда дело доходит до Foam::word::null
GDB будет производить бесконечный рекурсивный вывод, например так:
(gdb) p Foam::word::null
$83 = {<Foam::string> = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0,
static null = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0, static null = <same as static member of an already seen type>}},
static typeName = 0x7ffff4e398eb "word", static debug = 0, static null = {<Foam::string> = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0,
static null = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0, static null = <same as static member of an already seen type>}},
static typeName = 0x7ffff4e398eb "word", static debug = 0, static null = {<Foam::string> = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0,
static null = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0, static null = <same as static member of an already seen type>}},
static typeName = 0x7ffff4e398eb "word", static debug = 0, static null = {<Foam::string> = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0,
static null = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0, static null = <same as static member of an already seen type>}},
static typeName = 0x7ffff4e398eb "word", static debug = 0, static null = {<Foam::string> = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0,
static null = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0, static null = <same as static member of an already seen type>}},
static typeName = 0x7ffff4e398eb "word", static debug = 0, static null = {<Foam::string> = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0,
static null = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0, static null = <same as static member of an already seen type>}},
static typeName = 0x7ffff4e398eb "word", static debug = 0, static null = {<Foam::string> = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0,
static null = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0, static null = <same as static member of an already seen type>}},
static typeName = 0x7ffff4e398eb "word", static debug = 0, static null = {<Foam::string> = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0,
static null = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0, static null = <same as static member of an already seen type>}},
static typeName = 0x7ffff4e398eb "word", static debug = 0, static null = {<Foam::string> = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0,
static null = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0, static null = <same as static member of an already seen type>}},
static typeName = 0x7ffff4e398eb "word", static debug = 0, static null = {<Foam::string> = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0,
static null = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0, static null = <same as static member of an already seen type>}},
static typeName = 0x7ffff4e398eb "word", static debug = 0, static null = {<Foam::string> = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0,
static null = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0, static null = <same as static member of an already seen type>}},
static typeName = 0x7ffff4e398eb "word", static debug = 0, static null = {<Foam::string> = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0,
static null = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0, static null = <same as static member of an already seen type>}},
static typeName = 0x7ffff4e398eb "word", static debug = 0, static null = {<Foam::string> = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0,
static null = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0, static null = <same as static member of an already seen type>}},
static typeName = 0x7ffff4e398eb "word", static debug = 0, static null = {<Foam::string> = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0,
static null = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0, static null = <same as static member of an already seen type>}},
static typeName = 0x7ffff4e398eb "word", static debug = 0, static null = {<Foam::string> = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0,
static null = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string", static debug = 0, static null = <same as static member of an already seen type>}},
static typeName = 0x7ffff4e398eb "word", static debug = 0, static null = {<Foam::string> = {<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >> = "", static typeName = 0x7ffff4e38b8a "string",
Мой вопрос:
Что не так с такой структурой классов c ++ в gdb и как вывести лучший результат.
Спасибо!
Вы можете попробовать это:
set print static-members off
Это должно привести к более управляемому выводу, потому что рекурсия происходит через статический член. В качестве альтернативы, вы можете написать Симпатичный принтер Python для типа, но это, конечно, гораздо более сложным.
Я только что столкнулся с этой проблемой с eclipse, что привело к тихому сбою сеанса отладки.
Это действительно дует, и «отключить печать статических элементов» — это обходной путь, но не жизнеспособное решение