Skip to content

Commit 5b14c1d

Browse files
committed
fixed whitespace and DbgMsgSrc
1 parent 014ad8f commit 5b14c1d

File tree

3 files changed

+149
-145
lines changed

3 files changed

+149
-145
lines changed

DbgMsgSrc/DbgMsgSrc.cpp

Lines changed: 143 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class WinsockInitialization : boost::noncopyable
3030
public:
3131
explicit WinsockInitialization(int major = 2, int minor = 2)
3232
{
33-
WSADATA wsaData = { 0 };
33+
WSADATA wsaData = {0};
3434
int rc = WSAStartup(MAKEWORD(major, minor), &wsaData);
3535
if (rc != 0)
3636
ThrowWin32Error(rc, "WSAStartup");
@@ -59,7 +59,7 @@ void DbgMsgSrc(double freq)
5959
for (;;)
6060
{
6161
Sleep(10);
62-
while (count < (GetTickCount() - t0)*msgPerTick)
62+
while (count < (GetTickCount() - t0) * msgPerTick)
6363
{
6464
if (count % 10 == 0)
6565
cdbg << "Een, twee, drie, vier, vijf, zes, zeven, acht, negen, tien, elf, twaalf, dertien, veertien, vijftien, zestien, zeventien, achttien, negentien, twintig, eenentwintig, tweeentwintig, drieentwintig, vierentwintig, vijfentwintig, zesentwintig, zevenentwintig, achtentwintig, negenentwintig, dertig.\n";
@@ -135,16 +135,16 @@ void DbgMsgClearTest()
135135
char buffer[200];
136136

137137
int line = 1;
138-
for (int i=0; i< 400; ++i)
138+
for (int i = 0; i < 400; ++i)
139139
{
140140
sprintf_s(buffer, "Message %d", line);
141141
OutputDebugStringA(buffer);
142142
++line;
143143
}
144-
144+
145145
OutputDebugStringA(" ----> DBGVIEWCLEAR\n");
146146

147-
for (int i=0; i< 10; ++i)
147+
for (int i = 0; i < 10; ++i)
148148
{
149149
sprintf_s(buffer, "Message %d", line);
150150
OutputDebugStringA(buffer);
@@ -170,8 +170,8 @@ void testLongString()
170170
ss << "X";
171171

172172
ss << "\n";
173-
test = ss.str();
174-
173+
test = ss.str();
174+
175175
OutputDebugStringA(test.c_str());
176176
}
177177

@@ -212,7 +212,7 @@ void Output(const std::string& filename)
212212

213213
void EndlessTest()
214214
{
215-
int length = 40; //260
215+
int length = 40; //260
216216
std::ostringstream ss;
217217
ss << "123456:jan-7890_ABC__DEF-te m_test";
218218
ss << length;
@@ -263,7 +263,7 @@ void SeparateProcessTest()
263263

264264
void CoutCerrTest()
265265
{
266-
for (int i=1; i <= 5; ++i)
266+
for (int i = 1; i <= 5; ++i)
267267
{
268268
std::cout << "========= cycle " << i << "/5 ========\n";
269269
std::cout << "Message on cout 1\n";
@@ -310,31 +310,30 @@ void CoutCerrTest2()
310310

311311
void PrintUsage()
312312
{
313-
std::cout <<
314-
"Usage: DbgMsgSrc <opt>\n"
315-
"\n"
316-
" -1 read 'titan_crash_debugview_43mb.log' and output it through OutputDebugStringA\n"
317-
" -2 <filename> read <filename> and output it through OutputDebugStringA\n"
318-
" -3 run endless test\n"
319-
" -s run -n repeatedly (10x / second) in separate processes)\n"
320-
" -w Send OutputDebugStringA 'WithoutNewLine'\n"
321-
" -n Send OutputDebugStringA 'WithNewLine\\n'\n"
322-
" -e Send empty OutputDebugStringA message (does not trigger DBwinMutex!)\n"
323-
// about -4:
324-
// we cannot guarantee what happens if 1x OutputDebugStringA is send
325-
// the process might already be gone be time we handle the message
326-
// however, if 2 messages are send, the process is guarenteed to be alive
327-
// at least after receiving the first message but before setting the m_dbWinBufferReady flag..
328-
// (because before setting the flag the traced process is still waiting for the flag)
329-
// this means sending 2 messages and dieing ASAP afterwards is the worst-case we can still handle reliablely.
330-
" -4 Send 2x OutputDebugStringA 'WithNewLine\\n' (process handle cache test)\n"
331-
" -5 Send OutputDebugStringA '1\\n2\\n3\\n'\n"
332-
" -6 Send OutputDebugStringA '1 ' '2 ' '3\\n' in separate messages\n"
333-
" -7 DbgMsgTest, sends 5 different test lines, using different newlines styles\n"
334-
" -8 <frequency> DbgMsgSrc, Send OutputDebugStringA test lines with the specified frequency\n"
335-
" -9 DBGVIEWCLEAR test\n"
336-
" -A cout/cerr test\n"
337-
" -u <address> <port> Send UDP messsages to address:port\n";
313+
std::cout << "Usage: DbgMsgSrc <opt>\n"
314+
"\n"
315+
" -1 read 'titan_crash_debugview_43mb.log' and output it through OutputDebugStringA\n"
316+
" -2 <filename> read <filename> and output it through OutputDebugStringA\n"
317+
" -3 run endless test\n"
318+
" -s run -n repeatedly (10x / second) in separate processes)\n"
319+
" -w Send OutputDebugStringA 'WithoutNewLine'\n"
320+
" -n Send OutputDebugStringA 'WithNewLine\\n'\n"
321+
" -e Send empty OutputDebugStringA message (does not trigger DBwinMutex!)\n"
322+
// about -4:
323+
// we cannot guarantee what happens if 1x OutputDebugStringA is send
324+
// the process might already be gone be time we handle the message
325+
// however, if 2 messages are send, the process is guarenteed to be alive
326+
// at least after receiving the first message but before setting the m_dbWinBufferReady flag..
327+
// (because before setting the flag the traced process is still waiting for the flag)
328+
// this means sending 2 messages and dieing ASAP afterwards is the worst-case we can still handle reliablely.
329+
" -4 Send 2x OutputDebugStringA 'WithNewLine\\n' (process handle cache test)\n"
330+
" -5 Send OutputDebugStringA '1\\n2\\n3\\n'\n"
331+
" -6 Send OutputDebugStringA '1 ' '2 ' '3\\n' in separate messages\n"
332+
" -7 DbgMsgTest, sends 5 different test lines, using different newlines styles\n"
333+
" -8 <frequency> DbgMsgSrc, Send OutputDebugStringA test lines with the specified frequency\n"
334+
" -9 DBGVIEWCLEAR test\n"
335+
" -A cout/cerr test\n"
336+
" -u <address> <port> Send UDP messsages to address:port\n";
338337
}
339338

340339
int Main(int argc, char* argv[])
@@ -346,122 +345,129 @@ int Main(int argc, char* argv[])
346345
//HANDLE handle3 = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
347346
//printf(" %p, %p, %p\n", handle1, handle2, handle3);
348347

349-
int i = 0;
350-
std::string arg(argv[i]);
351-
if (arg == "-1")
352-
{
353-
Output("titan_crash_debugview_43mb.log");
354-
return 0;
355-
}
356-
else if (arg == "-2")
348+
for (int i = 1; i < argc; ++i)
357349
{
358-
if (i + 1 < argc)
350+
std::string arg(argv[i]);
351+
if (arg == "-1")
359352
{
360-
Output(argv[i + 1]);
353+
Output("titan_crash_debugview_43mb.log");
354+
return 0;
361355
}
362-
else
356+
else if (arg == "-2")
363357
{
364-
PrintUsage();
365-
return -1;
358+
if (i + 1 < argc)
359+
{
360+
Output(argv[i + 1]);
361+
}
362+
else
363+
{
364+
PrintUsage();
365+
return -1;
366+
}
367+
return 0;
366368
}
367-
return 0;
368-
}
369-
else if (arg == "-3")
370-
{
371-
EndlessTest();
372-
return 0;
373-
}
374-
else if (arg == "-s") // run separate process test
375-
{
376-
SeparateProcessTest();
377-
return 0;
378-
}
379-
else if (arg == "-w")
380-
{
381-
std::cout << "Send OutputDebugStringA 'WithoutNewLine ' (15 bytes)\n";
382-
OutputDebugStringA("WithoutNewLine ");
383-
return 0;
384-
}
385-
else if (arg == "-n")
386-
{
387-
std::cout << "Send OutputDebugStringA 'With-a-NewLine \\n' (16 bytes)\n";
388-
OutputDebugStringA("With-a-NewLine \n");
389-
return 0;
390-
}
391-
else if (arg == "-e")
392-
{
393-
std::cout << "Send empty OutputDebugStringA message (0 bytes)\n";
394-
OutputDebugStringA(""); //empty message
395-
return 0;
396-
}
397-
else if (arg == "-4")
398-
{
399-
std::cout << "Send 2x OutputDebugStringA 'WithNewLine\\n (24 bytes)'\n";
400-
OutputDebugStringA("WithNewLine\n");
401-
OutputDebugStringA("WithNewLine\n");
402-
return 0;
403-
}
404-
else if (arg == "-5")
405-
{
406-
std::cout << "Send OutputDebugStringA '1\\n2\\n3\\n' (6 bytes)\n";
407-
OutputDebugStringA("1\n2\n3\n");
408-
return 0;
409-
}
410-
else if (arg == "-6")
411-
{
412-
std::cout << "Send OutputDebugStringA '1 ' '2 ' '3\\n' in separate messages (6 bytes)\n";
413-
OutputDebugStringA("1 ");
414-
OutputDebugStringA("2 ");
415-
OutputDebugStringA("3\n");
416-
return 0;
417-
}
418-
else if (arg == "-7")
419-
{
420-
DbgMsgTest();
421-
return 7;
422-
}
423-
else if (arg == "-8")
424-
{
425-
if (i + 1 < argc)
369+
else if (arg == "-3")
426370
{
427-
DbgMsgSrc(std::stoi(argv[i + 1]));
371+
EndlessTest();
372+
return 0;
428373
}
429-
else
374+
else if (arg == "-s") // run separate process test
375+
{
376+
SeparateProcessTest();
377+
return 0;
378+
}
379+
else if (arg == "-w")
380+
{
381+
std::cout << "Send OutputDebugStringA 'WithoutNewLine ' (15 bytes)\n";
382+
OutputDebugStringA("WithoutNewLine ");
383+
return 0;
384+
}
385+
else if (arg == "-n")
386+
{
387+
std::cout << "Send OutputDebugStringA 'With-a-NewLine \\n' (16 bytes)\n";
388+
OutputDebugStringA("With-a-NewLine \n");
389+
return 0;
390+
}
391+
else if (arg == "-e")
392+
{
393+
std::cout << "Send empty OutputDebugStringA message (0 bytes)\n";
394+
OutputDebugStringA(""); //empty message
395+
return 0;
396+
}
397+
else if (arg == "-4")
398+
{
399+
std::cout << "Send 2x OutputDebugStringA 'WithNewLine\\n (24 bytes)'\n";
400+
OutputDebugStringA("WithNewLine\n");
401+
OutputDebugStringA("WithNewLine\n");
402+
return 0;
403+
}
404+
else if (arg == "-5")
405+
{
406+
std::cout << "Send OutputDebugStringA '1\\n2\\n3\\n' (6 bytes)\n";
407+
OutputDebugStringA("1\n2\n3\n");
408+
return 0;
409+
}
410+
else if (arg == "-6")
411+
{
412+
std::cout << "Send OutputDebugStringA '1 ' '2 ' '3\\n' in separate messages (6 bytes)\n";
413+
OutputDebugStringA("1 ");
414+
OutputDebugStringA("2 ");
415+
OutputDebugStringA("3\n");
416+
return 0;
417+
}
418+
else if (arg == "-7")
419+
{
420+
DbgMsgTest();
421+
return 7;
422+
}
423+
else if (arg == "-8")
424+
{
425+
if (i + 1 < argc)
426+
{
427+
DbgMsgSrc(std::stoi(argv[i + 1]));
428+
}
429+
else
430+
{
431+
PrintUsage();
432+
return -1;
433+
}
434+
return 0;
435+
}
436+
else if (arg == "-9")
437+
{
438+
DbgMsgClearTest();
439+
return 0;
440+
}
441+
else if (arg == "-A")
442+
{
443+
CoutCerrTest();
444+
return 0;
445+
}
446+
else if (arg == "-u")
430447
{
448+
if (i + 2 < argc)
449+
{
450+
UdpTest(argv[i + 1], std::stoi(argv[i + 2]));
451+
return 0;
452+
}
431453
PrintUsage();
432454
return -1;
433455
}
434-
return 0;
435-
}
436-
else if (arg == "-9")
437-
{
438-
DbgMsgClearTest();
439-
return 0;
440-
}
441-
else if (arg == "-A")
442-
{
443-
CoutCerrTest();
444-
return 0;
445-
}
446-
else if (arg == "-u")
447-
{
448-
if (i + 2 < argc)
456+
else if (arg == "-B")
449457
{
450-
UdpTest(argv[i + 1], std::stoi(argv[i + 2]));
458+
CoutCerrTest2();
459+
return 0;
460+
}
461+
else if (arg == "-C")
462+
{
463+
SocketTest();
464+
return 0;
465+
}
466+
else
467+
{
468+
Output(arg);
451469
return 0;
452470
}
453-
PrintUsage();
454-
return -1;
455-
}
456-
else if (arg == "-B")
457-
{
458-
CoutCerrTest2();
459-
return 0;
460-
}
461-
else if (arg == "-C")
462-
{
463-
SocketTest();
464-
return 0;
465471
}
466472
PrintUsage();
467473
return EXIT_SUCCESS;
@@ -470,8 +476,7 @@ int Main(int argc, char* argv[])
470476
} // namespace DbgMsgSrc
471477
} // namespace fusion
472478

473-
int main(int argc, char* argv[])
474-
try
479+
int main(int argc, char* argv[]) try
475480
{
476481
return fusion::DbgMsgSrc::Main(argc, argv);
477482
}

DebugView++/MainFrame.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,8 @@ void CMainFrame::UpdateStatusBar()
436436
UISetText(ID_VIEW_PANE, GetSelectionInfoText(L"View", GetView().GetViewRange()).c_str());
437437
UISetText(ID_LOGFILE_PANE, GetSelectionInfoText(L"Log", GetLogFileRange()).c_str());
438438

439-
size_t memoryUsage = ProcessInfo::GetPrivateBytes() - m_initialPrivateBytes;
440-
if (memoryUsage < 0)
441-
memoryUsage = 0;
439+
auto currentUsage = ProcessInfo::GetPrivateBytes();
440+
auto memoryUsage = currentUsage > m_initialPrivateBytes ? currentUsage - m_initialPrivateBytes : 0;
442441
UISetText(ID_MEMORY_PANE, FormatBytes(memoryUsage).c_str());
443442
}
444443

0 commit comments

Comments
 (0)