Minor modifications for Windows compatibility
authorOleg Lekarev <o.lekarev@samsung.com>
Thu, 13 Aug 2020 15:59:49 +0000 (18:59 +0300)
committerOleg Lekarev <o.lekarev@samsung.com>
Tue, 25 Aug 2020 09:47:05 +0000 (12:47 +0300)
src/debug/netcoredbg/CMakeLists.txt
src/debug/netcoredbg/cliprotocol.cpp
src/debug/netcoredbg/cliprotocol.h
src/debug/netcoredbg/main.cpp

index 8bcd292eed51eec7da1feef33468c1e3748c7a6a..5b214941c438d4321d117f49de418f2b01e046d0 100644 (file)
@@ -31,6 +31,7 @@ include_directories(${CORECLR_DIR}/src/coreclr/hosts/inc)
 # Build native part of the debugger
 
 include_directories(${PROJECT_SOURCE_DIR}/third_party)
+include_directories(${PROJECT_SOURCE_DIR}/third_party/linenoise-ng/include)
 
 set(netcoredbg_SRC
     main.cpp
@@ -66,7 +67,7 @@ endif()
 add_executable(netcoredbg ${netcoredbg_SRC})
 
 if (WIN32)
-    target_link_libraries(netcoredbg corguids wsock32 ws2_32)
+    target_link_libraries(netcoredbg corguids wsock32 ws2_32 linenoise)
 else()
     target_link_libraries(netcoredbg corguids dl pthread linenoise)
 endif()
index 1d207ec3b7c4d26ce088ad74454b9c4bb7110378..bd012bbabe9d5c14a262180f7896f9b22746f370 100644 (file)
@@ -14,8 +14,6 @@
 #include <iostream>
 #include <iomanip>
 #include <csignal>
-#include <unistd.h>
-#include <sys/syscall.h>
 
 #include "logger.h"
 #include "tokenizer.h"
@@ -294,8 +292,9 @@ void CLIProtocol::EmitStoppedEvent(StoppedEvent event)
         default:
             return;
     }
-
+#ifndef WIN32
     pthread_kill(tid, SIGWINCH);
+#endif
 }
 
 void CLIProtocol::EmitExitedEvent(ExitedEvent event)
@@ -303,7 +302,9 @@ void CLIProtocol::EmitExitedEvent(ExitedEvent event)
     LogFuncEntry();
 
     printf("\nstopped, reason: exited, exit-code: %i\n", event.exitCode);
+#ifndef WIN32
     pthread_kill(tid, SIGWINCH);
+#endif
 }
 
 void CLIProtocol::EmitContinuedEvent(int threadId)
@@ -578,9 +579,9 @@ void CLIProtocol::CommandLoop()
 {
     std::string token;
     std::string input;
-
+#ifndef WIN32
     tid = pthread_self();
-
+#endif
     linenoiseInstallWindowChangeHandler();
     linenoiseHistoryLoad(history.c_str());
 
@@ -600,7 +601,9 @@ void CLIProtocol::CommandLoop()
         std::string command;
         if (!ParseLine(input, token, command, args))
         {
-            printf("%s \x1b[1;31mFailed to parse input\n\x1b[0m", token.c_str());
+            printf("%s", redOn.c_str());
+            printf("%s Failed to parse input\n", token.c_str());
+            printf("%s", colorOff.c_str());
             continue;
         }
 
@@ -626,11 +629,15 @@ void CLIProtocol::CommandLoop()
         {
             if (output.empty())
             {
-                printf("%s \x1b[1;31mError: 0x%08x\n\x1b[0m", token.c_str(), hr);
+                printf("%s", redOn.c_str());
+                printf("%s Error: 0x%08x\n", token.c_str(), hr);
+                printf("%s", colorOff.c_str());
             }
             else
             {
-                printf("%s \x1b[1;31m%s\n\x1b[0m", token.c_str(), output.c_str());
+                printf("%s", redOn.c_str());
+                printf("%s %s\n", token.c_str(), output.c_str());
+                printf("%s", colorOff.c_str());
             }
         }
         linenoiseHistoryAdd(cmdline.get());
index 72a5abd690fd4a1ed2d83b5fe1dca11b462e540d..94a0ed091d7f87c31a547e9a5ed484adfa8adbc8 100644 (file)
@@ -24,13 +24,21 @@ class CLIProtocol : public IProtocol
     std::unordered_map<uint32_t, FunctionBreakpoint> m_funcBreakpoints;
     std::string prompt;
     std::string history;
+    std::string redOn;
+    std::string colorOff;
+#ifndef WIN32
     pthread_t tid;
-
+#endif
     static HRESULT PrintBreakpoint(const Breakpoint &b, std::string &output);
 
 public:
 
-    CLIProtocol() : IProtocol(), m_varCounter(0), prompt("\x1b[1;32mcli\x1b[0m> "), history(".history") {}
+    CLIProtocol() : IProtocol(), m_varCounter(0), prompt("\x1b[1;32mcli\x1b[0m> "), history(".history"),
+#ifndef WIN32
+                                 redOn("\033[1;31m"), colorOff("\033[0m") {}
+#else
+                                 redOn(""), colorOff("") {}
+#endif                                
     void EmitInitializedEvent() override {}
     void EmitStoppedEvent(StoppedEvent event) override;
     void EmitExitedEvent(ExitedEvent event) override;
index 0b12da25edd779b0e0b13d06eed9ddfebb95c989..c288262678a95aa5da8e9289f4bb2698535b00b8 100644 (file)
@@ -8,8 +8,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <unistd.h>
-
 #include "manageddebugger.h"
 #include "miprotocol.h"
 #include "vscodeprotocol.h"