2017-07-18 2 views
2

tout le monde,sortie récursive de l'auto statique sous-classe contenu de chaîne dans la commande d'impression gdb

J'utilise OpenFOAM et il a fait sa propre mousse :: string et mousse :: type de mot comme celui-ci:

(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 &); 
} 

maintenant, il est possible d'imprimer Foam::string::null comme ceci:

(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>}} 

Cependant, quand il vient à Foam::word::null, gdb produira une sortie récursive infinie comme ceci:

(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", 

Ma question est:

Quel est le problème avec ce genre de C++ structure de classe dans gdb et comment imprimer un meilleur résultat.

Merci!

+0

Pourquoi utilisez-vous 'std :: __ cxx11 :: basic_string' au lieu de habituel' std :: string'? – ks1322

Répondre

4

Vous pouvez essayer ceci:

set print static-members off 

Cela devrait se traduire par une sortie plus facile à gérer, car la récursion passe par un membre statique. Alternativement, vous pouvez écrire un Python pretty-printer pour le type, mais c'est bien sûr beaucoup plus impliqué.

1

Je viens de rencontrer ce problème avec eclipse, ce qui a entraîné une panne silencieuse de la session de débogage. Cela souffle vraiment, et «désactiver les membres statiques d'impression» est une solution de contournement, mais pas une solution viable

+0

Le problème est supposément corrigé avec GDB 8.1 (non vérifié moi-même), voir le commit correspondant: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h = a43f3893f6cb66dfca7f628cd159a008009ad06f –