Microsoft MVP성태의 닷넷 이야기
VS.NET IDE: 193. C# - Visual Studio의 자식 프로세스 디버깅 [링크 복사], [링크+제목 복사],
조회: 6207
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 

(시리즈 글이 4개 있습니다.)
VS.NET IDE: 47. Orcas - Web Browser Debugger를 이용한 보호 모드의 ActiveX 컨트롤 디버깅
; https://www.sysnet.pe.kr/2/0/500

디버깅 기술: 25. 보호 모드로 응용 프로그램 디버깅하는 방법
; https://www.sysnet.pe.kr/2/0/682

디버깅 기술: 26. 보호 모드로 응용 프로그램 디버깅하는 방법 - 두 번째 이야기
; https://www.sysnet.pe.kr/2/0/683

VS.NET IDE: 193. C# - Visual Studio의 자식 프로세스 디버깅
; https://www.sysnet.pe.kr/2/0/13720




C# - Visual Studio의 자식 프로세스 디버깅

실제로 테스트를 해볼까요? ^^

ConsoleApp1, ConsoleApp2 각각 2개의 Console Application을 다음과 같은 코드로 만듭니다.

// ConsoleApp1
using System.Diagnostics;

internal class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello, ConsoleApp1!");

        Process.Start("ConsoleApp2.exe").WaitForExit();
    }
}

// ConsoleApp2

internal class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello, ConsoleApp2!"); // 여기에 BP 설정
    }
}

이후 ConsoleApp1을 ("Set as Startup Project" 메뉴를 이용해) Startup Project로 설정하고, ConsoleApp2의 Console.WriteLine에 BP를 걸어 둔 다음 F5 디버깅으로 실행하면 BP가 안 걸립니다.

왜냐하면 기본적으로 Visual Studio는 (windbg와는 달리) 자식 프로세스에 대한 디버깅을 지원하지 않기 때문입니다. 대신 마이크로소프트는 이에 대한 보완으로 별도의 확장 패키지를 내놓았습니다.

Microsoft Child Process Debugging Power Tool (Visual Studio 2015, 2017, 2019)
; https://marketplace.visualstudio.com/items?itemName=vsdbgplat.MicrosoftChildProcessDebuggingPowerTool

Microsoft Child Process Debugging Power Tool 2022
; https://marketplace.visualstudio.com/items?itemName=vsdbgplat.MicrosoftChildProcessDebuggingPowerTool2022

이것을 설치한 후, "Debug" / "Other Debug Targets" / "Child Process Debugging Settings" 메뉴를 선택하면 이런 창이 뜨는데,

vs_child_debug_1.png

위의 화면처럼 "Enable child process debugging"을 체크하고 "Save" 버튼을 누르면, 이제 자식 프로세스까지 디버깅이 가능합니다.




그런데, 위의 상태로 디버깅을 해도 여전히 ConsoleApp2의 BP는 걸리지 않습니다. 이에 대한 원인은, 위의 화면에서 잘 설명하고 있습니다.

This window controls which child processes are debugging, and what type of code is debugged within the process. Settings apply to the current solution.

This extension has two requirements: (1) the parent (launching) process must be debgged with the native (unmanaged) debug enging and (2) the parent process much launch the child process using the CreateProcess, CreateProcessAsUser, CreateProcessWithLogonW or CreateProcessWithLogonW Win32 APIs.


따라서, 닷넷 프로세스에 대한 디버깅의 경우 "Startup Project"로 지정된 프로젝트의 속성 창에서 "Debug" / "General"의 "Open debug launch profiles UI" 링크를 눌러 나오는 "Enable native code debugging"을 체크해야 합니다.

이후, 다시 F5 디버깅을 하면 ConsoleApp2의 BP가 걸립니다. (사실, 이에 대한 언급이 "Microsoft Child Process Debugging Power Tool" 소개 페이지에 실려 있습니다.)




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 8/29/2024]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 31  [32]  33  34  35  36  37  38  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
13137정성태10/8/202214141.NET Framework: 2055. 리눅스 환경의 .NET Core 3/5+ 메모리 덤프로부터 닷넷 모듈을 추출하는 방법
13136정성태10/7/202214497.NET Framework: 2054. .NET Core/5+ SDK 설치 없이 dotnet-dump 사용하는 방법
13135정성태10/5/202215014.NET Framework: 2053. 리눅스 환경의 .NET Core 3/5+ 메모리 덤프를 분석하는 방법 - 두 번째 이야기 [1]
13134정성태10/4/202212215오류 유형: 820. There is a problem with AMD Radeon RX 5600 XT device. For more information, search for 'graphics device driver error code 31'
13133정성태10/4/202213357Windows: 211. Windows - (commit이 아닌) reserved 메모리 사용량 확인 방법 [1]
13132정성태10/3/202213388스크립트: 42. 파이썬 - latexify-py 패키지 소개 - 함수를 mathjax 식으로 표현
13131정성태10/3/202217190.NET Framework: 2052. C# - Windows Forms의 데이터 바인딩 지원(DataBinding, DataSource) [2]파일 다운로드1
13130정성태9/28/202213005.NET Framework: 2051. .NET Core/5+ - 에러 로깅을 위한 Middleware가 동작하지 않는 경우파일 다운로드1
13129정성태9/27/202213626.NET Framework: 2050. .NET Core를 IIS에서 호스팅하는 경우 .NET Framework CLR이 함께 로드되는 환경
13128정성태9/23/202216555C/C++: 158. Visual C++ - IDL 구문 중 "unsigned long"을 인식하지 못하는 #import [1]파일 다운로드1
13127정성태9/22/202214817Windows: 210. WSL에 systemd 도입
13126정성태9/15/202215342.NET Framework: 2049. C# 11 - 정적 메서드에 대한 delegate 처리 시 cache 적용
13125정성태9/14/202215761.NET Framework: 2048. C# 11 - 구조체 필드의 자동 초기화(auto-default structs)
13124정성태9/13/202215535.NET Framework: 2047. Golang, Python, C#에서의 CRC32 사용
13123정성태9/8/202215590.NET Framework: 2046. C# 11 - 멤버(속성/필드)에 지정할 수 있는 required 예약어 추가
13122정성태8/26/202216001.NET Framework: 2045. C# 11 - 메서드 매개 변수에 대한 nameof 지원
13121정성태8/23/202212414C/C++: 157. Golang - 구조체의 slice 필드를 Reflection을 이용해 변경하는 방법
13120정성태8/19/202215997Windows: 209. Windows NT Service에서 UI를 다루는 방법 [3]
13119정성태8/18/202215134.NET Framework: 2044. .NET Core/5+ 프로젝트에서 참조 DLL이 보관된 공통 디렉터리를 지정하는 방법
13118정성태8/18/202212676.NET Framework: 2043. WPF Color의 기본 색 영역은 (sRGB가 아닌) scRGB [2]
13117정성태8/17/202216339.NET Framework: 2042. C# 11 - 파일 범위 내에서 유효한 타입 정의 (File-local types)파일 다운로드1
13116정성태8/4/202216781.NET Framework: 2041. C# - Socket.Close 시 Socket.Receive 메서드에서 예외가 발생하는 문제파일 다운로드1
13115정성태8/3/202217349.NET Framework: 2040. C# - ValueTask와 Task의 성능 비교 [1]파일 다운로드1
13114정성태8/2/202217225.NET Framework: 2039. C# - Task와 비교해 본 ValueTask 사용법파일 다운로드1
13113정성태7/31/202216714.NET Framework: 2038. C# 11 - Span 타입에 대한 패턴 매칭 (Pattern matching on ReadOnlySpan<char>)
13112정성태7/30/202217585.NET Framework: 2037. C# 11 - 목록 패턴(List patterns) [1]파일 다운로드1
... 31  [32]  33  34  35  36  37  38  39  40  41  42  43  44  45  ...