[nemiver] Ignore unknown RESULT in -var-list-children output



commit cdafd6f540df6451dd5b98fffb9f6b276f7ab090
Author: Dodji Seketeli <dodji redhat com>
Date:   Thu Jul 2 14:25:06 2009 +0200

    Ignore unknown RESULT in -var-list-children output
    
    	* src/dbgengine/nmv-gdbmi-parser.cc (GDBMIParser::parse_var_list_children):
    	When parsing the result of -var-list-children,
    	ignore the MI RESULTs that we don't know about. This fixes
    	a parsing error we have when parsing the result of
    	-var-list-children with pretty printers enabled. It triggers
    	the presence of a 'displayhint' MI RESULT. We know ignore it.
    	* tests/test-gdbmi.cc (test_var_list_children): New test.
    	* tests/test-vars.cc (on_changed_variables_listed_signal):
    	Make this more robust wrt libstdc++ versions.

 src/dbgengine/nmv-gdbmi-parser.cc |   22 +++++++++++++++++-----
 tests/test-gdbmi.cc               |   17 +++++++++++++++++
 tests/test-vars.cc                |    7 +++++--
 3 files changed, 39 insertions(+), 7 deletions(-)
---
diff --git a/src/dbgengine/nmv-gdbmi-parser.cc b/src/dbgengine/nmv-gdbmi-parser.cc
index cde7db4..dfe2420 100644
--- a/src/dbgengine/nmv-gdbmi-parser.cc
+++ b/src/dbgengine/nmv-gdbmi-parser.cc
@@ -3194,12 +3194,24 @@ GDBMIParser::parse_var_list_children
         return false;
     }
     ++cur;
-    SKIP_BLANK2 (cur);
-    result.reset ();
-    if (!parse_gdbmi_result (cur, cur, result) || !result) {
-        LOG_PARSING_ERROR2 (cur);
-        return false;
+
+    // Go look for the "children" RESULT, and ignore the other ones
+    // we might encounter.
+    for (;;) {
+        SKIP_BLANK2 (cur);
+        if (RAW_CHAR_AT (cur) == ',') {
+            ++cur;
+            SKIP_BLANK2 (cur);
+        }
+        result.reset ();
+        if (!parse_gdbmi_result (cur, cur, result) || !result) {
+            LOG_PARSING_ERROR2 (cur);
+            return false;
+        }
+        if (result->variable () == "children")
+            break;
     }
+
     if (result->variable () != "children") {
         LOG_ERROR ("expected gdbmi variable " << "children" << ", got: "
                    << result->variable () << "\'");
diff --git a/tests/test-gdbmi.cc b/tests/test-gdbmi.cc
index 0e8deb2..a2f9219 100644
--- a/tests/test-gdbmi.cc
+++ b/tests/test-gdbmi.cc
@@ -27,6 +27,8 @@ static const char *gv_running_async_output0 =
 static const char *gv_running_async_output1 =
 "*running,thread-id=\"1\"\n";
 
+static const char *gv_var_list_children0="numchild=\"2\",displayhint=\"string\",children=[child={name=\"var1.public.m_first_name.public\",exp=\"public\",numchild=\"1\",value=\"\",thread-id=\"1\"},child={name=\"var1.public.m_first_name.private\",exp=\"private\",numchild=\"1\",value=\"\",thread-id=\"1\"}]";
+
 static const char *gv_output_record0 =
 "&\"Failed to read a valid object file image from memory.\\n\"\n"
 "~\"[Thread debugging using libthread_db enabled]\\n\"\n"
@@ -265,6 +267,20 @@ test_running_async_output ()
 }
 
 void
+test_var_list_children ()
+{
+
+    GDBMIParser parser (gv_var_list_children0);
+
+    bool is_ok=false;
+    UString::size_type to=0 ;
+    std::vector<IDebugger::VariableSafePtr> vars;
+    is_ok = parser.parse_var_list_children (0, to, vars);
+    BOOST_REQUIRE (is_ok);
+    BOOST_REQUIRE (vars.size () == 2);
+}
+
+void
 test_output_record ()
 {
     bool is_ok=false;
@@ -809,6 +825,7 @@ init_unit_test_suite (int argc, char **argv)
     suite->add (BOOST_TEST_CASE (&test_attr0)) ;
     suite->add (BOOST_TEST_CASE (&test_stoppped_async_output)) ;
     suite->add (BOOST_TEST_CASE (&test_running_async_output)) ;
+    suite->add (BOOST_TEST_CASE (&test_var_list_children)) ;
     suite->add (BOOST_TEST_CASE (&test_output_record)) ;
     suite->add (BOOST_TEST_CASE (&test_stack0)) ;
     suite->add (BOOST_TEST_CASE (&test_stack_arguments0)) ;
diff --git a/tests/test-vars.cc b/tests/test-vars.cc
index 7fd8f3c..098e1d2 100644
--- a/tests/test-vars.cc
+++ b/tests/test-vars.cc
@@ -152,8 +152,11 @@ on_changed_variables_listed_signal
 {
     IDebugger::VariableSafePtr root = a_vars.front ()->root ();
     THROW_IF_FAIL (root);
+    MESSAGE ("nb_elems: " << (int) a_vars.size ());
     int nb_elems = a_vars.size ();
-    BOOST_REQUIRE (nb_elems == 3);
+    // We can't know for sure how many elemens got changed, as that
+    // depend on the version of stl we are testing against.
+    BOOST_REQUIRE (nb_elems >= 3);
     MESSAGE ("The changed members are: ");
     for (list<IDebugger::VariableSafePtr>::const_iterator it = a_vars.begin ();
          it != a_vars.end ();
@@ -226,7 +229,7 @@ on_stopped_signal (IDebugger::StopReason /*a_reason*/,
         MESSAGE ("Requested creation of variable 'person'");
     } else if (nb_stops == 6) {
         // We passed the point where we changed the value of the members
-        // of the 'person' variale, in fooprog.
+        // of the 'person' variable, in fooprog.
         // let's now ask the debugger to tell us which descendant variable
         // was changed exactly.
         a_debugger->list_changed_variables



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]