Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
부모글 보이기/감추기
(연관된 글이 1개 있습니다.)
3.1 PDB 파일에 따른 Debug 정보 - WinForm + Library 유형의 프로젝트

테스트를 위해서, C# 라이브러리 유형의 "BaseLibrary" 프로젝트와 C# WinForm 유형의 "WinForm" 프로젝트를 생성합니다.

BaseLibrary 에는 다음과 같은 ThrowClass.cs 파일 하나만 존재합니다.

    public class ThrowClass
    {
        public void TestMethod()
        {
	// 예외를 발생시키기 위한 코드
            FileStream fs = File.Open(@"C:\\test_nothing.txt", FileMode.Open);
            fs.Close();
        }
    }

WinForm 프로젝트에서는 다음과 같이 코드를 사용하는 Form1.cs 파일이 있습니다.

        private void Form1_Load(object sender, EventArgs e)
        {
            BaseLibrary.ThrowClass throwClass = new BaseLibrary.ThrowClass();
            throwClass.TestMethod();
        }

자, 이제 환경을 어떻게 구성하는지에 따라서 우리가 얼마나 유용한 오류 정보를 얻을 수 있는지 알아보겠습니다.

첫번째로 BaseLibrary.pdb / WinForm.pdb 파일이 실행 파일과 동일한 폴더에 함께 있는 경우

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.IO.FileNotFoundException: Could not find file 'C:\test_nothing.txt'.
File name: 'C:\test_nothing.txt'
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, 
        FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at System.IO.File.Open(String path, FileMode mode)
   at BaseLibrary.ThrowClass.TestMethod() in D:\temp2\PdbSample\BaseLibrary\ThrowClass.cs:line 14
   at WinForm.Form1.Form1_Load(Object sender, EventArgs e) in D:\temp2\PdbSample\WinFormApp\WinForm\Form1.cs:line 21
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

굵은 글씨체로 표시한 부분을 보시면 PDB 파일이 있음으로 인해서 실제 소스 파일명과 라인을 확인할 수 있습니다. 위와 같은 결과는 프로젝트를 Debug 또는 Release 빌드에 상관없이 PDB 파일만 있으면 동일하게 얻어낼 수 있습니다. VS.NET 2003 까지는 Debug 빌드에서만 PDB 파일이 생성되었으나, 반갑게도 VS.NET 2005 로 오면서는 Release 빌드에서도 "pdb-only" 유형의 PDB 파일을 생성하는 것이 기본 설정으로 되어 있습니다. (즉, VS.NET 2003 사용자라면 release 빌드 버전에서 PDB 파일을 생성하도록 프로젝트 설정을 해주는 것이 권장됩니다.)

이제, BaseLibrary.pdb 파일을 실행경로에서 삭제해 봅니다. 그런 후 실행해 보면 다음과 같은 오류 정보를 얻을 수 있습니다.

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.IO.FileNotFoundException: Could not find file 'C:\test_nothing.txt'.
File name: 'C:\test_nothing.txt'
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights,
         FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at System.IO.File.Open(String path, FileMode mode)
   at BaseLibrary.ThrowClass.TestMethod()
   at WinForm.Form1.Form1_Load(Object sender, EventArgs e) in D:\temp2\PdbSample\WinFormApp\WinForm\Form1.cs:line 21
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

위의 로그를 보자 마자 감이 잡히시겠지요 ^^ 이젠 BaseLibrary 에 있던 소스 파일의 경로와 오류를 발생시킨 라인은 얻어낼 수 없습니다. 단지, TestMethod 라는 것만 얻어낼 수가 있습니다. 예상하시겠지만, WinForm.pdb 파일을 삭제하고 BaseLibrary.pdb 파일이 있는 경우에는 결과는 반대로 나옵니다. 또한 둘다 없는 경우라면 말할 필요도 없겠지요.

이 예를 통해서 알 수 있는 점이 한가지 있지요. ^^ 만약, 여러분들이 3rd party 라이브러리 개발 업체라면 해당 제품의 빌드 버전에 해당하는 PDB 파일도 가지고 있으면 도움이 된다는 것입니다. 역어셈블이 되는 .NET 의 상황을 고려한다면 PDB 파일을 애당초 배포하는 것도 고려해 볼 수 있습니다. 그럼으로써, 고객들이 그 라이브러리를 사용하면서 오류가 발생하면 구체적인 오류 보고를 해줄 수 있기 때문입니다. 물론, PDB 파일이 없는 경우에도 가능한 수준의 예측이 가능합니다. 예를 들어, 위의 예제에서 PDB 파일이 없는 경우를 보면,

   at System.IO.File.Open(String path, FileMode mode)
   at BaseLibrary.ThrowClass.TestMethod()

ThrowClass 클래스의 TestMethod 메서드에서 오류가 발생한 것을 볼 수 있고, 그 메서드 내부의 File.Open 하는 부분에서 오류가 났음을 알 수 있습니다. 하지만, 만약 해당 TestMethod 에서 File.Open 하는 코드가 여러 군데에서 사용되어지고 있다면 이번에는 어느 부분에서 오류가 발생했는지 알아낼 수 있는 방법이 없습니다.

이제, PDB 파일의 유용성을 조금씩 느끼실 수 있으시겠지요! ^^
첨부된 파일은 3.1, 3.2, 3.3 토픽에서 사용되고 있는 예제 솔루션입니다.
[연관 글]






[최초 등록일: ]
[최종 수정일: 3/6/2007]

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

비밀번호

댓글 작성자
 




... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13242정성태2/4/20234602디버깅 기술: 189. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.UnauthorizedAccessException
13241정성태2/3/20234036디버깅 기술: 188. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.IO.FileNotFoundException
13240정성태2/1/20234184디버깅 기술: 187. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.Web.HttpException
13239정성태2/1/20233873디버깅 기술: 186. C# - CacheDependency의 숨겨진 예외 - System.Web.HttpException
13238정성태1/31/20236002.NET Framework: 2092. IIS 웹 사이트를 TLS 1.2 또는 TLS 1.3 프로토콜로만 운영하는 방법
13237정성태1/30/20235700.NET Framework: 2091. C# - 웹 사이트가 어떤 버전의 TLS/SSL을 지원하는지 확인하는 방법
13236정성태1/29/20235189개발 환경 구성: 663. openssl을 이용해 인트라넷 IIS 사이트의 SSL 인증서 생성
13235정성태1/29/20234828개발 환경 구성: 662. openssl - 윈도우 환경의 명령행에서 SAN 적용하는 방법
13234정성태1/28/20235910개발 환경 구성: 661. dnSpy를 이용해 소스 코드가 없는 .NET 어셈블리의 코드를 변경하는 방법 [1]
13233정성태1/28/20237289오류 유형: 840. C# - WebClient로 https 호출 시 "The request was aborted: Could not create SSL/TLS secure channel" 예외 발생
13232정성태1/27/20234951스크립트: 43. uwsgi의 --processes와 --threads 옵션
13231정성태1/27/20233964오류 유형: 839. python - TypeError: '...' object is not callable
13230정성태1/26/20234341개발 환경 구성: 660. WSL 2 내부로부터 호스트 측의 네트워크로 UDP 데이터가 1개의 패킷으로만 제한되는 문제
13229정성태1/25/20235375.NET Framework: 2090. C# - UDP Datagram의 최대 크기
13228정성태1/24/20235484.NET Framework: 2089. C# - WMI 논리 디스크가 속한 물리 디스크의 정보를 얻는 방법 [2]파일 다운로드1
13227정성태1/23/20235147개발 환경 구성: 659. Windows - IP MTU 값을 바꿀 수 있을까요? [1]
13226정성태1/23/20234825.NET Framework: 2088. .NET 5부터 지원하는 GetRawSocketOption 사용 시 주의할 점
13225정성태1/21/20234019개발 환경 구성: 658. Windows에서 실행 중인 소켓 서버를 다른 PC 또는 WSL에서 접속할 수 없는 경우
13224정성태1/21/20234455Windows: 221. Windows - Private/Public/Domain이 아닌 네트워크 어댑터 단위로 방화벽을 on/off하는 방법
13223정성태1/20/20234612오류 유형: 838. RDP 연결 오류 - The two computers couldn't connect in the amount of time allotted
13222정성태1/20/20234314개발 환경 구성: 657. WSL - DockerDesktop.vhdx 파일 위치를 옮기는 방법
13221정성태1/19/20234478Linux: 57. C# - 리눅스 프로세스 메모리 정보파일 다운로드1
13220정성태1/19/20234592오류 유형: 837. NETSDK1045 The current .NET SDK does not support targeting .NET ...
13219정성태1/18/20234205Windows: 220. 네트워크의 인터넷 접속 가능 여부에 대한 판단 기준
13218정성태1/17/20234098VS.NET IDE: 178. Visual Studio 17.5 (Preview 2) - 포트 터널링을 이용한 웹 응용 프로그램의 외부 접근 허용
13217정성태1/13/20234714디버깅 기술: 185. windbg - 64비트 운영체제에서 작업 관리자로 뜬 32비트 프로세스의 덤프를 sos로 디버깅하는 방법
... [16]  17  18  19  20  21  22  23  24  25  26  27  28  29  30  ...