성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Roll A Lisp In C - Reading ; https...
[정성태] Java - How to use the Foreign Funct...
[정성태] 제가 큰 실수를 했군요. ^^; Delegate를 통한 Bein...
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>(닷넷) 프로세스(EXE)에 디버거가 연결되어 있는지 아는 방법</h1> <p> 닷넷의 경우 BCL에 Debugger.IsAttached 속성을 통해 디버거 연결 여부를 알아낼 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Debugger.IsAttached Property ; <a target='tab' href='https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.debugger.isattached?view=netframework-4.8'>https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.debugger.isattached?view=netframework-4.8</a> </pre> <br /> 그런데 "Debug Diagnostic Tool"로 프로세스를 연결한 경우에는,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > 프로세스 비정상 종료 시 "Debug Diagnostic Tool"를 이용해 덤프를 남기는 방법 ; <a target='tab' href='http://www.sysnet.pe.kr/2/0/1786'>http://www.sysnet.pe.kr/2/0/1786</a> </pre> <br /> Debugger.IsAttached가 false를 반환합니다. 이유를 찾아보니 다음의 글에 나오는 군요. ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > #if (DEBUG) VS System.Diagnostics.Debugger.IsAttached ; <a target='tab' href='https://stackoverflow.com/questions/7073266/if-debug-vs-system-diagnostics-debugger-isattached'>https://stackoverflow.com/questions/7073266/if-debug-vs-system-diagnostics-debugger-isattached</a> C# Detect if Debugger is Attached ; <a target='tab' href='https://www.codeproject.com/articles/670193/csharp-detect-if-debugger-is-attached'>https://www.codeproject.com/articles/670193/csharp-detect-if-debugger-is-attached</a> </pre> <br /> 즉, Debugger.IsAttached는 'managed debugger'가 연결되었을 때만 True이고, 'native debugger'가 연결된 경우에는 false를 반환한다고 합니다. 따라서 이런 경우에는 IsDebuggerPresent Win32 API를 P/Invoke 호출로 사용하면 됩니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > IsDebuggerPresent function ; <a target='tab' href='https://docs.microsoft.com/en-us/windows/win32/api/debugapi/nf-debugapi-isdebuggerpresent'>https://docs.microsoft.com/en-us/windows/win32/api/debugapi/nf-debugapi-isdebuggerpresent</a> </pre> <br /> 이 함수는 managed/native 상관없이 디버거 연결 여부를 반환합니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 이 외에 이름이 약간 혼란스러운 API도 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > CheckRemoteDebuggerPresent ; <a target='tab' href='https://docs.microsoft.com/en-us/windows/win32/api/debugapi/nf-debugapi-checkremotedebuggerpresent'>https://docs.microsoft.com/en-us/windows/win32/api/debugapi/nf-debugapi-checkremotedebuggerpresent</a> BOOL WINAPI CheckRemoteDebuggerPresent( _In_ HANDLE hProcess, _Inout_ PBOOL pbDebuggerPresent ); </pre> <br /> 함수 이름만 보면, 왠지 "원격 디버깅"으로 연결된 것인지를 알려주는 API인 듯싶은데 그게 아니라 디버거 연결 여부를 알고 싶은 프로세스가 다를 때 사용하는 함수입니다.<br /> <br /> 가령, 자신이 만든 디버거로 다른 프로세스를 연결하고 싶을 때 해당 프로세스가 이미 다른 디버거에 의해 연결되어 있다면 이를 사용자에게 알려줘야 할 것입니다. 바로 이럴 때 CheckRemoteDebuggerPresent의 첫 번째 인자에 해당 프로세스의 핸들 값을 전달하면 되는 것입니다.<br /> <br /> 결국 IsDebuggerPresent API는 CheckRemoteDebuggerPresent로 다음과 같이 동일하게 구현할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > BOOL pbIsPresent = FALSE; CheckRemoteDebuggerPresent(GetCurrentProcess(), &pbIsPresent); // == IsDebuggerPresent </pre> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1337
(왼쪽의 숫자를 입력해야 합니다.)