2016-06-14 104 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添加相同的細節,特別是如果你相信它是相同的。謝謝! –