gdb错误:找不到方法(null)是什么

时间:2013-06-05 13:44:02

标签: c++ debugging gdb

  ?58                  pinNodes.push_back(node);                                                                                                                            ?
   ?59              }                                                                                                                                                        ?
   ?60              nlb::application::Application::instance().interpreter().eval(QString("unset %1").arg(pinIterListVarName));                                               ?
   ?61                                                                                                                                                                       ?
   ?62              if (!pinNodes.empty()) {                                                                                                                                 ?
   ?63                  insert(0, pinNodes.begin(), pinNodes.end());                                                                                                         ?
   ?64              }                                                                                                                                                        ?
   ?65          } catch (const std::exception& e) {                                                                                                                          ?
B+>?66              SA_ASSERT(false, e.what());                                                                                                                              ?
   ?67          }                                                                                                                                                            ?
   ?68      }           

这是来自gdb。我已将断点设置为失败的断言。当我尝试使用p e.what() gdb打印Couldn't find method (null)what

来打印失败原因时

打印e表示不完整。

(gdb) p e
$4 = (const struct std::exception &) @0x58f1990: <incomplete type>

我如何打印?

如果SA_ASSERT的条件为false,则调用此

void printTrace(unsigned int startDepth, QString& buff)
{

    const size_t maxDepth = 200;
    size_t stackDepth;
    void *stackAddrs[maxDepth];
    char **stackStrings;

    stackDepth = backtrace(stackAddrs, maxDepth);
    stackStrings = backtrace_symbols(stackAddrs, stackDepth);

    buff += "Call stack\n";

    unsigned int line = 1;

    for (size_t i = startDepth; i < stackDepth; i++) {
        size_t sz = 500; // just a guess, template names will go much wider
        char *function = reinterpret_cast<char*>(malloc(sz));
        char *begin = 0, *end = 0;
        // find the parentheses and address offset surrounding the mangled name
        for (char *j = stackStrings[i]; *j != 0; ++j) {
            if (*j == '(') {
                begin = j;
            } else if (*j == '+') {
                end = j;
            }
        }
        if (begin && end) {
            begin++;
            *end = 0;
            // found our mangled name, now in [begin, end)
            int status;
            char *ret = abi::__cxa_demangle(begin, function, &sz, &status);
            if (ret) {
                // return value may be a realloc() of the input
                function = ret;
            } else {
                // demangling failed, just pretend it's a C function
                // with no args
                std::strncpy(function, begin, sz);
                std::strncat(function, "()", sz);
                function[sz-1] = ' ';
            }
            buff += QString::number(line++) + QString(")    ") + function + "\n";
        } else {
            // didn't find the mangled name, just print the whole line
            buff += QString::number(line++) + QString(")    ") + stackStrings[i] + "\n";
        }
        free(function);
    }

    free(stackStrings); // malloc()ed by backtrace_symbols

}

gdb版本

GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".

1 个答案:

答案 0 :(得分:2)

不完整的类型意味着您缺少一些debuginfo。没有它,gdb不能做太多。例如,它无法打印该类型的对象,因为它不知道该类型的布局方式。

6.8版很老了。如果可以,你应该升级。从那时起,C ++支持已经有很多错误修复。

“(null)”看起来像一个gdb错误。当你尝试printf NULL(至少使用glibc)时会发生这种情况。但是,这个错误很可能在过去5年的某个时候得到修复。

相关问题