Skip to content

Commit 5d4425e

Browse files
committed
store the Process handle for ProcessReader
1 parent 086ea25 commit 5d4425e

File tree

5 files changed

+39
-14
lines changed

5 files changed

+39
-14
lines changed

DebugView++/MainFrame.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,19 +517,15 @@ void CMainFrame::OnContextMenu(HWND hWnd, CPoint pt)
517517

518518
void CMainFrame::HandleDroppedFile(const std::wstring& file)
519519
{
520-
if (!IsPaused())
521-
Pause();
522520
SetTitle(file);
523521
using boost::algorithm::iequals;
524522
auto ext = std::experimental::filesystem::path(file).extension().wstring();
525523
if (iequals(ext, L".exe"))
526524
{
527-
m_logSources.AddMessage(stringbuilder() << "Started capturing output of " << Str(file) << "\n");
528525
Run(file);
529526
}
530527
else if (iequals(ext, L".cmd") || iequals(ext, L".bat"))
531528
{
532-
m_logSources.AddMessage(stringbuilder() << "Started capturing output of " << Str(file) << "\n");
533529
m_logSources.AddProcessReader(L"cmd.exe", wstringbuilder() << L"/Q /C \"" << file << "\"");
534530
}
535531
else
@@ -560,7 +556,7 @@ void CMainFrame::OnDropped(const std::wstring uri)
560556
}
561557

562558
Win32::Process process(httpmonitor, uri);
563-
m_httpMonitorHandle = Win32::DuplicateHandle(process.GetProcessHandle());
559+
m_httpMonitorHandle = Win32::DuplicateHandle(process.GetProcessHandle());
564560
m_jobs.AddProcessByHandle(m_httpMonitorHandle.get());
565561
}
566562
else

DebugView++Lib/PolledLogSource.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
namespace fusion {
1515
namespace debugviewpp {
1616

17+
18+
PollLine::PollLine(Win32::Handle handle, const std::string& message, const LogSource* pLogSource) :
19+
timesValid(false),
20+
time(0.0),
21+
systemTime(FILETIME()),
22+
handle(std::move(handle)),
23+
message(message),
24+
pLogSource(pLogSource)
25+
{
26+
}
27+
1728
PollLine::PollLine(DWORD pid, const std::string& processName, const std::string& message, const LogSource* pLogSource) :
1829
timesValid(false),
1930
time(0.0),
@@ -95,7 +106,9 @@ void PolledLogSource::Notify()
95106

96107
for (auto& line : m_backBuffer)
97108
{
98-
if (line.timesValid)
109+
if (line.handle)
110+
Add(line.handle.release(), line.message);
111+
else if (line.timesValid)
99112
Add(line.time, line.systemTime, line.pid, line.processName, line.message);
100113
else
101114
Add(line.pid, line.processName, line.message);
@@ -107,6 +120,12 @@ void PolledLogSource::Poll()
107120
{
108121
}
109122

123+
void PolledLogSource::AddMessage(Win32::Handle handle, const std::string& message)
124+
{
125+
std::lock_guard<std::mutex> lock(m_mutex);
126+
m_lines.push_back(PollLine(std::move(handle), message, this));
127+
}
128+
110129
void PolledLogSource::AddMessage(DWORD pid, const std::string& processName, const std::string& message)
111130
{
112131
std::lock_guard<std::mutex> lock(m_mutex);

DebugView++Lib/ProcessReader.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// (C) Copyright Gert-Jan de Vos and Jan Wilmans 2013.
22
// Distributed under the Boost Software License, Version 1.0.
3-
// (See accompanying file LICENSE_1_0.txt or copy at
3+
// (See accompanying file LICENSE_1_0.txt or copy at
44
// http://www.boost.org/LICENSE_1_0.txt)
55

66
// Repository at: https://github.com/djeedjay/DebugViewPP/
@@ -21,6 +21,8 @@ ProcessReader::ProcessReader(Timer& timer, ILineBuffer& linebuffer, const std::w
2121
m_stderr(timer, linebuffer, m_process.GetStdErr(), m_process.GetProcessId(), Str(m_process.GetName()).str() + ":stderr", 0)
2222
{
2323
SetDescription(m_process.GetName() + L" stdout/stderr");
24+
AddMessage(Win32::DuplicateHandle(m_process.GetProcessHandle()), "Started capturing output of stdout/stderr");
25+
Signal();
2426
StartThread();
2527
}
2628

@@ -30,7 +32,8 @@ ProcessReader::~ProcessReader()
3032

3133
void ProcessReader::Abort()
3234
{
33-
AddMessage(m_process.GetProcessId(), Str(m_process.GetName()).str(), "<process terminated>");
35+
AddMessage(m_process.GetProcessId(), Str(m_process.GetName()).str(), "<process reader aborted>");
36+
Signal();
3437
PolledLogSource::Abort();
3538
}
3639

@@ -45,5 +48,5 @@ void ProcessReader::Poll()
4548
m_stderr.Poll(*this);
4649
}
4750

48-
} // namespace debugviewpp
51+
} // namespace debugviewpp
4952
} // namespace fusion

Win32Lib/Win32Lib.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ void HFile::resize(size_t size) const
505505
ThrowLastError("_chsize");
506506
}
507507

508+
// SEH (Structured Exception Handling) return codes are in the 0xC000000-0xfffff00 range
508509
std::wstring GetSEHcodeDescription(DWORD code)
509510
{
510511
switch (code) {
@@ -528,6 +529,8 @@ std::wstring GetSEHcodeDescription(DWORD code)
528529
case EXCEPTION_PRIV_INSTRUCTION: return L"EXCEPTION_PRIV_INSTRUCTION";
529530
case EXCEPTION_SINGLE_STEP: return L"EXCEPTION_SINGLE_STEP";
530531
case EXCEPTION_STACK_OVERFLOW: return L"EXCEPTION_STACK_OVERFLOW";
532+
533+
// undocumented? but regularly seen codes
531534
case 0xC0000142: return L"DllMain returned false";
532535
case 0xC0000022: return L"executable or one of the dependant dlls do not have execute rights";
533536
default: return L"UNKNOWN EXCEPTION";
@@ -540,6 +543,7 @@ std::wstring GetHresultMessage(HRESULT hr)
540543
return err.ErrorMessage();
541544
}
542545

546+
// RESULT return codes are in the 0x8000000-0xbffffff range
543547
std::wstring GetHresultName(HRESULT hr)
544548
{
545549
switch (hr) {

include/DebugView++Lib/PolledLogSource.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ class ILineBuffer;
1818

1919
struct PollLine
2020
{
21-
PollLine(DWORD pid, const std::string& processName, const std::string& message, const LogSource* pLogSource);
22-
PollLine(double time, FILETIME systemTime, DWORD pid, const std::string& processName, const std::string& message, const LogSource* pLogSource);
21+
PollLine(Win32::Handle handle, const std::string& message, const LogSource* pLogSource);
22+
PollLine(DWORD pid, const std::string& processName, const std::string& message, const LogSource* pLogSource);
23+
PollLine(double time, FILETIME systemTime, DWORD pid, const std::string& processName, const std::string& message, const LogSource* pLogSource);
2324

2425
bool timesValid;
2526
double time;
2627
FILETIME systemTime;
27-
DWORD pid;
28+
Win32::Handle handle;
29+
DWORD pid;
2830
std::string processName;
2931
std::string message;
3032
const LogSource* pLogSource;
@@ -43,8 +45,9 @@ class PolledLogSource : public LogSource
4345

4446
// in contrast to the LogSource::Add methdods, these methods are de-coupled using m_backBuffer so they
4547
// can be used to add messages from any thread. The typical use-case are messages from the UI thread.
46-
void AddMessage(DWORD pid, const std::string& processName, const std::string& message);
47-
void AddMessage(const std::string& message);
48+
void AddMessage(Win32::Handle handle, const std::string& message);
49+
void AddMessage(DWORD pid, const std::string& processName, const std::string& message);
50+
void AddMessage(const std::string& message);
4851
void AddMessage(double time, FILETIME systemTime, DWORD pid, const std::string& processName, const std::string& message);
4952

5053
void Signal();

0 commit comments

Comments
 (0)