C\#당신 이 사용 하지 않 았 을 수도 있 는 디 버 깅 창 방법 중 일부

14268 단어 C#디버그 창
먼저 설명:디 버 깅 모드 에 들 어가 지 않 았 다 면 기본 디 버 깅 창 은 다음 과 같 습 니 다.
image
시작 전 준비:
새 콘 솔 프로그램 DebugWindowDemo:
Program.cs 의 코드 를 다음 과 같이 수정 합 니 다

using System;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;

class S
    {
       public static void Main()
        {
            pcount = Environment.ProcessorCount;
            Console.WriteLine("Proc count = " + pcount);
            ThreadPool.SetMinThreads(4, -1);
            ThreadPool.SetMaxThreads(4, -1);

            t1 = new Task(A, 1);
            t2 = new Task(A, 2);
            t3 = new Task(A, 3);
            t4 = new Task(A, 4);
            Console.WriteLine("Starting t1 " + t1.Id.ToString());
            t1.Start();
            Console.WriteLine("Starting t2 " + t2.Id.ToString());
            t2.Start();
            Console.WriteLine("Starting t3 " + t3.Id.ToString());
            t3.Start();
            Console.WriteLine("Starting t4 " + t4.Id.ToString());
            t4.Start();

            Console.ReadLine();
        }

        static void A(object o)
        {
            B(o);
        }
        static void B(object o)
        {
            C(o);
        }
        static void C(object o)
        {
            int temp = (int)o;

            Interlocked.Increment(ref aa);
            while (aa < 4)
            {

            }

            if (temp == 1)
            {
                // BP1 - all tasks in C

                Debugger.Break();
                waitFor1 = false;
            }
            else
            {
                while (waitFor1)
                {

                }
            }
            switch (temp)
            {
                case 1:
                    D(o);
                    break;
                case 2:
                    F(o);
                    break;
                case 3:
                case 4:
                    I(o);
                    break;
                default:
                    Debug.Assert(false, "fool");
                    break;
            }
        }
        static void D(object o)
        {
            E(o);
        }
        static void E(object o)
        {
            // break here at the same time as H and K

            while (bb < 2)
            {

            }
            //BP2 - 1 in E, 2 in H, 3 in J, 4 in K

            Debugger.Break();
            Interlocked.Increment(ref bb);

            //after

            L(o);
        }
        static void F(object o)
        {
            G(o);
        }
        static void G(object o)
        {
            H(o);
        }
        static void H(object o)
        {
            // break here at the same time as E and K

            Interlocked.Increment(ref bb);
            Monitor.Enter(mylock);
            while (bb < 3)
            {

            }
            Monitor.Exit(mylock);


            //after

            L(o);
        }
        static void I(object o)
        {
            J(o);
        }
        static void J(object o)
        {
            int temp2 = (int)o;

            switch (temp2)
            {
                case 3:
                    t4.Wait();
                    break;
                case 4:
                    K(o);
                    break;
                default:
                    Debug.Assert(false, "fool2");
                    break;
            }
        }
        static void K(object o)
        {
            // break here at the same time as E and H

            Interlocked.Increment(ref bb);
            Monitor.Enter(mylock);
            while (bb < 3)
            {

            }
            Monitor.Exit(mylock);


            //after

            L(o);
        }
        static void L(object oo)
        {
            int temp3 = (int)oo;

            switch (temp3)
            {
                case 1:
                    M(oo);
                    break;
                case 2:
                    N(oo);
                    break;
                case 4:
                    O(oo);
                    break;
                default:
                    Debug.Assert(false, "fool3");
                    break;
            }
        }
        static void M(object o)
        {
            // breaks here at the same time as N and Q

            Interlocked.Increment(ref cc);
            while (cc < 3)
            {

            }
            //BP3 - 1 in M, 2 in N, 3 still in J, 4 in O, 5 in Q

            Debugger.Break();
            Interlocked.Increment(ref cc);
            while (true)
                Thread.Sleep(500); // for ever

        }
        static void N(object o)
        {
            // breaks here at the same time as M and Q

            Interlocked.Increment(ref cc);
            while (cc < 4)
            {

            }
            R(o);
        }
        static void O(object o)
        {
            Task t5 = Task.Factory.StartNew(P, TaskCreationOptions.AttachedToParent);
            t5.Wait();
            R(o);
        }
        static void P()
        {
            Console.WriteLine("t5 runs " + Task.CurrentId.ToString());
            Q();
        }
        static void Q()
        {
            // breaks here at the same time as N and M

            Interlocked.Increment(ref cc);
            while (cc < 4)
            {

            }
            // task 5 dies here freeing task 4 (its parent)

            Console.WriteLine("t5 dies " + Task.CurrentId.ToString());
            waitFor5 = false;
        }
        static void R(object o)
        {
            if ((int)o == 2)
            {
                //wait for task5 to die

                while (waitFor5) { ;}


                int i;
                //spin up all procs

                for (i = 0; i < pcount - 4; i++)
                {
                    Task t = Task.Factory.StartNew(() => { while (true);});
                    Console.WriteLine("Started task " + t.Id.ToString());
                }

                Task.Factory.StartNew(T, i + 1 + 5, TaskCreationOptions.AttachedToParent); //scheduled

                Task.Factory.StartNew(T, i + 2 + 5, TaskCreationOptions.AttachedToParent); //scheduled

                Task.Factory.StartNew(T, i + 3 + 5, TaskCreationOptions.AttachedToParent); //scheduled

                Task.Factory.StartNew(T, i + 4 + 5, TaskCreationOptions.AttachedToParent); //scheduled

                Task.Factory.StartNew(T, (i + 5 + 5).ToString(), TaskCreationOptions.AttachedToParent); //scheduled


                //BP4 - 1 in M, 2 in R, 3 in J, 4 in R, 5 died

                Debugger.Break();
            }
            else
            {
                Debug.Assert((int)o == 4);
                t3.Wait();
            }
        }
        static void T(object o)
        {
            Console.WriteLine("Scheduled run " + Task.CurrentId.ToString());
        }
        static Task t1, t2, t3, t4;
        static int aa = 0;
        static int bb = 0;
        static int cc = 0;
        static bool waitFor1 = true;
        static bool waitFor5 = true;
        static int pcount;
        static S mylock = new S();
    }

F5 를 누 르 면 실행 을 시작 합 니 다.
Debugger.Break()때문에;
그래서 여기까지 실 행 될 때 Debugger 는 중단 합 니 다.
이 럴 때 디 버 깅 창 을 보면 몇 개의 창 이 더 있 습 니 다.
image
디 버 깅->창->병렬 작업 을 누 르 면 인터페이스 가 다음 과 같 습 니 다.
image
F5 를 누 르 고 계속 실행:
image  
해당 대기 임 무 를 더 블 클릭 하면 이 작업 스 레 드 가 왜 기 다 렸 는 지 알 수 있 습 니 다.
예 를 들 면:
image
F5 를 계속 누 르 고 실행 하면 다음 을 볼 수 있 습 니 다.
image
어쨌든 현재 실행 중인 병행 작업 에 대해 서 는 모두 볼 수 있 습 니 다.
프로그램 을 닫 고 F5 를 다시 시작 하여 디 버 깅 모드 로 들 어 갑 니 다.
디 버 깅 선택->창->병렬 스 택
볼 수 있 습 니 다:
image
그 중에서 파란색 선 은 현재 실행 중인 라인 을 대표 합 니 다.
방법 보기 의 S.C 를 오른쪽 클릭 하면 오른쪽 메뉴 를 볼 수 있 습 니 다image
클릭 하여 전환 방법 보기
image
볼 수 있 습 니 다:
image
프로그램 을 닫 고 F5 를 다시 시작 하여 디 버 깅 모드 로 들 어 갑 니 다.
디 버 깅->창->스 레 드 클릭:
볼 수 있 습 니 다:
image
현재 콘 솔 의 모든 스 레 드 가 여기에 있 습 니 다.
스 레 드 에서 오른쪽 단 추 를 누 르 면 스 레 드 를 동결 할 수 있 습 니 다:
image
동결 스 레 드 즉 Pause 스 레 드,
얼 어 붙 은 스 레 드 가 해 제 될 수 있 습 니 다.즉,Resume 입 니 다.
다른 창:
디 버 깅->창->모듈:현재 프로그램 이 불 러 온 모든 모듈 을 볼 수 있 습 니 다.
image
디버그->창->프로 세 스:
image
디버그->창->어 셈 블 리 반대:
image
디버그->창->레지스터:
image
디버그->창->스 택 호출:
스 택 창 을 호출 하 는 것 은 자주 사용 하 는 창 입 니 다:
image
위의 그림 은 먼저 A 방법 을 호출 하고,이어서 B 방법,이어서 C 방법 을 나타 낸다.
C 방법 은 B 호출 이 고 B 방법 은 A 호출 이 라 고 볼 수도 있다.
다른 창 은 비교적 자주 사용 하 는데 소개 하지 않 겠 습 니 다.당신 이 사용 하지 않 은 창 이 있 지 않 습 니까?

좋은 웹페이지 즐겨찾기