[CLI] Fixed bug: 'p' command without arguments. (#249)
authorKirill Frolov/Platform Lab /SRR/Staff Engineer/Samsung Electronics <k.frolov@samsung.com>
Thu, 24 Sep 2020 17:05:44 +0000 (20:05 +0300)
committerAlexander Soldatov/Platform Lab /SRR/Staff Engineer/Samsung Electronics <soldatov.a@samsung.com>
Thu, 24 Sep 2020 17:05:44 +0000 (20:05 +0300)
The issue #243: command "p" without arguments leads to segfault.

src/debug/netcoredbg/cliprotocol.cpp
src/debug/netcoredbg/cliprotocol.h

index c615238919177ad17d1cc29e1eebe038a8610789..722452c8911a47a081db47dd5175dec2ffabe6f2 100644 (file)
@@ -532,22 +532,33 @@ HRESULT CLIProtocol::PrintVariable(int threadId, uint64_t frameId, std::list<std
 
 HRESULT CLIProtocol::doPrint(const std::vector<std::string> &args, std::string &output)
 {
-    HRESULT Status;
+    if (!args.empty())
+    {
+        m_lastPrintArg = args[0];
+    }
+    else if (m_lastPrintArg.empty())
+    {
+        puts("The history is empty.");
+        return S_OK;
+    }
+
     std::ostringstream ss;
+
+    HRESULT Status;
     std::string result;
     std::list<std::string> tokens;
-    
+
     ss << "\n";
     int threadId = m_debugger->GetLastStoppedThreadId();
     uint64_t frameId = StackFrame(threadId, 0, "").id;
     Variable v(0);
-    Tokenizer tokenizer(args[0], ".[");
+    Tokenizer tokenizer(m_lastPrintArg, ".[");
     while (tokenizer.Next(result))
     {
         if (result.back() == ']')
         {
             tokens.push_back('[' + result);
-        } 
+        }
         else {
             tokens.push_back(result);
         }
@@ -558,7 +569,7 @@ HRESULT CLIProtocol::doPrint(const std::vector<std::string> &args, std::string &
     v.name = tokens.front();
     PrintVariable (threadId, frameId, tokens.begin(), v, ss, true);
     output = ss.str();
-    return S_OK;    
+    return S_OK;
 }
 
 HRESULT CLIProtocol::doQuit(const std::vector<std::string> &, std::string &)
index c98f2b062f413b2c04aef6dfc78959b4654182e2..9089e74f70e5779d9714c4d19b2bb11880ebe92f 100644 (file)
@@ -87,4 +87,6 @@ private:
     void DeleteFunctionBreakpoints(const std::unordered_set<uint32_t> &ids);
     static HRESULT PrintFrameLocation(const StackFrame &stackFrame, std::string &output);
     bool ParseLine(const std::string &str, std::string &token, std::string &cmd, std::vector<std::string> &args);
+
+    std::string m_lastPrintArg;
 };