Skip to content

Commit

Permalink
This commit fixes issue Samsung#61
Browse files Browse the repository at this point in the history
Issue was caused by the fact, that SIGWINCH signal was
sent every time then debugee is stopped, but in case, if
input comes from not a terminal (from pipe, socket or a file),
liblinenoise was unable to handle SIGWINCH correctly and this
causes netcoredbg termination.
  • Loading branch information
0xfk0 authored and viewizard committed Apr 16, 2021
1 parent 1d56247 commit 094860c
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/protocols/cliprotocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
#ifdef _WIN32
#include <ConsoleApi.h>
#include <ProcessEnv.h>
#include <io.h>
#else
#include <termios.h>
#include <unistd.h>
#define _isatty(fd) ::isatty(fd)
#define _fileno(file) ::fileno(file)
#endif

#include "debugger/frames.h"
Expand Down Expand Up @@ -2164,12 +2167,21 @@ void CLIProtocol::applyCommandMode()
{
lock_guard lock(m_mutex);

// setup function which is called after Stop/Exit events to redraw screen, etc...
if (_isatty(_fileno(stdin)))
{
// setup function which is called after Stop/Exit events to redraw screen, etc...
#ifndef WIN32
m_repaint_fn = std::bind(pthread_kill, pthread_self(), SIGWINCH);
m_repaint_fn = std::bind(pthread_kill, pthread_self(), SIGWINCH);
#else
m_repaint_fn = []{ GenerateConsoleCtrlEvent(CTRL_C_EVENT , 0); };
m_repaint_fn = []{ GenerateConsoleCtrlEvent(CTRL_C_EVENT , 0); };
#endif
}
else
{
// if input comes from non (pseudo) terminals (pipes, files, sockets, etc...)
// no special function required (because SIGWINCH might not be handled corretly in this case).
m_repaint_fn = nullptr;
}
}


Expand All @@ -2195,11 +2207,15 @@ void CLIProtocol::CommandLoop()
m_commandMode = CommandMode::Synchronous;
applyCommandMode();

linenoiseInstallWindowChangeHandler();
linenoiseHistorySetMaxLen(DefaultHistoryDepth);
linenoiseHistoryLoad(HistoryFileName);
// Use linenoise features only if input comes from (pseudo)terminal.
if (_isatty(_fileno(stdin)))
{
linenoiseInstallWindowChangeHandler();
linenoiseHistorySetMaxLen(DefaultHistoryDepth);
linenoiseHistoryLoad(HistoryFileName);

linenoiseSetCompletionCallbackEx(completion_callback, this);
linenoiseSetCompletionCallbackEx(completion_callback, this);
}
}

// loop till eof, error, or exit request.
Expand Down

0 comments on commit 094860c

Please sign in to comment.