Print variables improvements for structures and arrays
authorOleg Lekarev <o.lekarev@samsung.com>
Fri, 28 Aug 2020 08:23:48 +0000 (11:23 +0300)
committerAlexander Soldatov/Platform Lab /SRR/Staff Engineer/Samsung Electronics <soldatov.a@samsung.com>
Fri, 11 Sep 2020 10:58:36 +0000 (13:58 +0300)
src/debug/netcoredbg/cliprotocol.cpp
src/debug/netcoredbg/cliprotocol.h

index 4d21de1b49e6cf8fe4edaae14a2161d49a20738f..1617efb60ec982b25bad0494324fac63fb08d49b 100644 (file)
@@ -478,20 +478,45 @@ HRESULT CLIProtocol::doNext(const std::vector<std::string> &args, std::string &o
     return StepCommand(args, output, Debugger::STEP_OVER);    
 }
 
-HRESULT CLIProtocol::PrintVariable(int threadId, uint64_t frameId, std::string name, Variable v, std::ostringstream &ss)
+HRESULT CLIProtocol::PrintVariable(int threadId, uint64_t frameId, std::queue<std::string> filters, Variable v, std::ostringstream &ss)
 {
-    ss << name << " = " << v.value;
+    if(!filters.empty())
+    {
+        filters.pop();
+    }
+
+    ss << v.name;
+    if (filters.empty())
+    {
+        ss << " = " << v.value;
+    } else if (filters.front().front() != '[') {
+        ss << ".";
+    }
+    
     if (v.namedVariables > 0)
     {
         std::vector<Variable> children;
-        ss << ": {";
+        if (filters.empty()) 
+        {
+            ss << ": {";
+        }
         m_debugger->GetVariables(v.variablesReference, VariablesNamed, 0, v.namedVariables, children);
         for (auto &child : children)
         {
-            PrintVariable(threadId, frameId, child.name, child, ss);
-            ss << ", ";
+            if (filters.empty())
+            {
+                PrintVariable(threadId, frameId, filters, child, ss);
+                ss << ", ";
+            } else if (child.name == filters.front())
+            {
+                PrintVariable(threadId, frameId, filters, child, ss);
+            }
+        }
+        ss << "\b\b";
+        if (filters.empty())
+        {
+            ss << "}";
         }
-        ss << "\b\b}";
     }
     return S_OK;
 }
@@ -500,13 +525,28 @@ HRESULT CLIProtocol::doPrint(const std::vector<std::string> &args, std::string &
 {
     HRESULT Status;
     std::ostringstream ss;
-
+    std::string result;
+    std::queue<std::string> filters;
+    
     ss << "\n";
     int threadId = m_debugger->GetLastStoppedThreadId();
     uint64_t frameId = StackFrame(threadId, 0, "").id;
     Variable v(0);
-    IfFailRet(m_debugger->Evaluate(frameId, args[0], v, output));
-    PrintVariable (threadId, frameId, args[0], v, ss);
+    Tokenizer tokenizer(args[0], ".[");
+    while (tokenizer.Next(result))
+    {
+        if (result.back() == ']')
+        {
+            filters.push('[' + result);
+        } 
+        else {
+            filters.push(result);
+        }
+    }
+    printf("\n");
+    IfFailRet(m_debugger->Evaluate(frameId, filters.front(), v, output));
+    v.name = filters.front();
+    PrintVariable (threadId, frameId, filters, v, ss);
     output = ss.str();
     return S_OK;    
 }
index 3bae0a0a224ecf166f0c6a2af4811c29594e9aa8..2f5bd08818042dbb90b6f4fe533702ce6f73b2a8 100644 (file)
@@ -8,6 +8,7 @@
 #include <unordered_map>
 #include <unordered_set>
 #include <vector>
+#include <queue>
 
 #include "debugger.h"
 #include "iprotocol.h"
@@ -81,7 +82,7 @@ private:
     HRESULT PrintFrames(int threadId, std::string &output, int lowFrame, int highFrame);
     HRESULT SetBreakpoint(const std::string &filename, int linenum, const std::string &condition, Breakpoint &breakpoints);
     HRESULT SetFunctionBreakpoint(const std::string &module, const std::string &funcname, const std::string &params, const std::string &condition, Breakpoint &breakpoint);
-    HRESULT PrintVariable(int threadId, uint64_t frameId, std::string name, Variable v, std::ostringstream &output);
+    HRESULT PrintVariable(int threadId, uint64_t frameId, std::queue<std::string> filters, Variable v, std::ostringstream &output);
     void DeleteBreakpoints(const std::unordered_set<uint32_t> &ids);
     void DeleteFunctionBreakpoints(const std::unordered_set<uint32_t> &ids);
     static HRESULT PrintFrameLocation(const StackFrame &stackFrame, std::string &output);