2016-06-14 56 views
2

我有一个巨大的嵌套数据结构(来自JSON精灵)的问题。在调试时,当这个结构充满数据时,Eclipse在每一步都等待GDB打印数据后开始工作非常缓慢。问题是,即使我没有扩展这个数据结构,Eclipse也收集了很多关于局部变量的信息。当漂亮的打印关闭时,它可以正常工作,但是当然我在STL容器内看不到任何东西。Eclipse CDT(4.5.1)与漂亮的打印工作缓慢

我使用打印机从GDB SVN

这里是一个小的一段代码,可以使类似的问题:

#include <iostream> 
#include <string> 
#include <map> 

int main() { 
    std::map<std::string, std::map<std::string, std::map<std::string, std::string>>> mega_map; 

    const int factor = 50; 
    for (int c = 0; c < factor; ++c){ 
     std::map<std::string, std::map<std::string, std::string>> b_map; 
     for (int b = 0; b < factor; ++b){ 
      std::map<std::string, std::string> a_map; 
      for (int a = 0; a < factor; ++a){ 
       std::string a_str = "a"; 
       a_str += (std::to_string(a)); 
       auto a_pair = std::make_pair("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + a_str, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"); 
       a_map.insert(a_pair); 
      } 
      std::string b_str = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; 
      b_str += (std::to_string(b)); 
      b_map[b_str] = a_map; 
     } 
     std::string c_str = "cccccccccccccccccccccccccccccccccccccccc"; 
     c_str += (std::to_string(c)); 
     mega_map[c_str] = b_map; 
    } 
    return 0; 
} 

只是要在“回归”制动,你会看到,它需要很多时间在'变量'窗口中获取某些内容。在那段时间你不能调试。

GDB set print elements number-of-elements中有一个标志,它可以限制要打印的容器中的元素的数量,它可以工作,但是当我对这些嵌套结构不感兴趣时​​,这些设置会影响我想要检查的其他容器。

任何想法如何解决它?

谢谢。

回答

0

我们(同事和我)今天就碰到这个问题并进行了调查,这里是我们的结论。不幸的是,我们没有找到解决这个问题的方法,只是使用了一些设置,但在CDT和GDB中发现了一些可以帮助缓解的问题。如果您可以构建自己的CDT或GDB,它可能会对您有所帮助。

CDT向当地人询问GDB,使用-stack-list-locals,同时获得他们的值的参数。对于一个相当印刷容器,GDB结束包括小孩:

std::vector of length 20, capacity 20 = {<children here>} 

对于嵌套数据结构,它可以最终巨大。一个解决办法是让CDT不要求这些值。它将正确使用变量对象,并在扩展数据结构时根据需要请求值。这里的DIFF:

diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIStack.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIStack.java 
index c319eb8..23bbb8a 100644 
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIStack.java 
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/MIStack.java 
@@ -859,7 +859,7 @@ implements IStack, ICachingService { 
      fMICommandCache.execute(
        // Don't ask for value when we are visualizing trace data, since some 
        // data will not be there, and the command will fail 
-     fCommandFactory.createMIStackListLocals(frameDmc, !fTraceVisualization), 
+     fCommandFactory.createMIStackListLocals(frameDmc, false), 
        new DataRequestMonitor<MIStackListLocalsInfo>(getExecutor(), rm) { 
         @Override 
         protected void handleSuccess() { 
@@ -988,7 +988,7 @@ implements IStack, ICachingService { 
       // the result without the values 
       // Don't ask for value when we are visualizing trace data, since some 
       // data will not be there, and the command will fail 
-    fCommandFactory.createMIStackListLocals(frameDmc, !fTraceVisualization), 
+    fCommandFactory.createMIStackListLocals(frameDmc, false), 
       new DataRequestMonitor<MIStackListLocalsInfo>(getExecutor(), countingRm) { 
        @Override 
        protected void handleSuccess() { 

还有其他一些情况下,CDT将发行,使GDB吐出完整递归数据结构的要求,也就是说,如果你在变量选择的变量查看,或者如果你悬停它。然后您会在“详细信息”部分注意到完整的展开值。但是,如果您在步骤中没有选择该变量,则会迅速执行。

GDB中的可能的修复方法是不使其递归输出漂亮的数据结构。本hack例如他们限制儿童的一层:

diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c 
index 66929bf..b213699 100644 
--- a/gdb/python/py-prettyprint.c 
+++ b/gdb/python/py-prettyprint.c 
@@ -700,7 +700,7 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang, 
    /* Print the section */ 
    print_result = print_string_repr (printer.get(), hint.get(), stream, 
        recurse, options, language, gdbarch); 
- if (print_result != string_repr_error) 
+ if (print_result != string_repr_error && recurse == 0) 
    print_children (printer.get(), hint.get(), stream, recurse, options, 
      language, print_result == string_repr_none); 

甲贡献到上游GDB可以考虑其中该递归限制是具有reasonnable值的设定。

+0

这看起来与https://bugs.eclipse.org/bugs/show_bug.cgi?id=519561非常相似,我很欣赏你所做的分析。你能否给bug添加相同的细节,特别是如果你相信它是相同的。谢谢! –