DDD 사용법


A.    정의

Display Data Debugger로 다른 디버거보다 사용하는데 편리한 인터페이스를 제공하고, 디버깅에 필요한 환경을 손쉽게 설정할 수 있다. 기본적으로 gdb를 기반으로 하여 인터페이스만을 제공한다.

 

B.    설치

Ubuntu : $ sudo apt-get install ddd

 

C.    실행

$ ddd

$ ddd <program>

$ ddd <program> core

“core”라는 파일은 프로그램의 실행 중에 문제가 있을 때마다 생성되는 파일로 프로그램에 대한 많은 정보를 담고 있다. 만약 시스템이 코어덤프를 만들지 않는다면 코어에 관련된 환경 변수를 확인하면 된다.

$ ddd <program> <process_id>

       process_id는 프로그램이 실행되고 있는 중간에도 디버깅을 할 수 있게 해준다.

 

D.    DDD창 설명

 

-       소스창 : 브레이크 포인트 설정, 자료구조 선택 등에 사용

-       명령창 : ddd 명령어 집합을 나타내며, 사용자는 이를 통해 명령을 내림

-       gdb 콘솔 : gdb에게 직접 명령을 내리거나 ddd에서 print 명령에 대한 결과 출력시 사용

 

E.     명령어

-       Interrupt : 프로그램 강제 종료

-       Step : 프로그램을 한 행씩 수행, 함수 호출을 만나게 되면 함수 내부로 들어감

-       Next : 프로그램을 한 행씩 수행, 함수 호출을 만나면 함수 내부로 들어가지 않음

-       Stepi : 어셈블리 레벨에서 명령어 하나씩 수행, Step과 같이 함수 호출을 만나면 함수 내부로 들어감

-       Nexti : 어셈블리 레벨에서 명령어 하나씩 수행, Next와 같이 함수 호출을 만나면 함수 내부로 들어가지 않음

-       Until : 반복문을 벗어남

-       Finish : 함수를 벗어남

-       Cont : 다음 브레이크 포인트를 만날 때까지 계속 수행

-       Kill : 프로그램 수행 종료

-       Up : 상위 스택 프레임으로 이동

-       Down : 하위 스택 프레임으로 이동

-       Undo : 이전 상황으로 자료구조 값들을 되돌림

-       Redo : Undo 수행 이전 상황으로 되돌림

-       Edit : 소스의 내용이 수정되었다면 수정된 소스를 소스창에 보이기 위해 사용

-       Make : 프로그램을 새로 컴파일

 

F.     Break Point

-       Break Point 생성을 원하는 지점의 행이 시작되는 부분에 마우스 오른쪽 버튼 클릭

-       Set Break Point 선택

 

G.    Break Point 메뉴

-       Set Temporary Breakpoint : 일회성 브레이크 포인트 생성, X가 붙은 STOP 마크로 표현

-       Countinue Until Here : 반복문 수행 중 각 반복 후 멈출 위치를 지정

-       Set Execution Position : 프로그램 실행 경로를 지정한 위치로 점프

 

H.    Break Point 조건 설정

-       Break Point에서 마우스 오른쪽 버튼 클릭

-       Properties 선택

-       Condition 속성 설정 후 조건 지정

 

I.      Break Point 설정 메뉴

-       Disable Breakpoint : 브레이크 포인트를 일시적으로 끔

-       Delete Breakpoint : 설정한 브레이크 포인트 제거

Posted by OnewayK
,

[에러의 종류]

런타임 에러

실행시에 발생하는 에러.

대부분 프로그래밍시의 설계미숙으로 일어나며, 외에 기계적 결함 등으로 일어나기도 한다. 설계 실수로 인한 오류인 경우 대표적으로 무한 루프(반복문 안의 조건문의 실수로 인해 반복문을 빠져 나가지 못함) 또는 xx/0 등이 있다.

 

컴파일타임 에러

컴파일시 발생하는 에러.

대부분이 문법적인 오류. 경우 컴파일이 되지 않고 Warning이나 Error 문구가 상태창에 뜨게 된다.

문법 오류와 의미적 오류 등이 있으며, 문장을 끝내는 세미콜론(;)이나 조건문이나 반복문 등의 형식이 맞지 않아서 발생하는 Syntax Error(신택스 에러), 데이터 타입 에러, 함수 선언 에러 여러 가지 에러가 있다.

 

논리 에러

논리 오류로 인해 발생하는 에러.

프로그램 실행은 되지만 프로그래머가 의도하지 않은 결과가 나오는 경우이다.

주로 알고리즘 계산 미스, 복잡한 반복문을 확실하게 설계해놓지 않고 쓰는 경우 발생한다.

 

[에러의 예시]

1. 오류 코드로 보는 오류 유형

error C2228: Left of .identifier must have class/struct/union type

- 원인

class struct, union으로 선언한 변수를 사용하는 경우 .identifier부분이 class, struct union에서 정의한 변수명이 아닌 경우, 혹은 포인터를 사용하면서 -> 아니라 .으로 사용한 경우 발생

- 해결법

class, struct, union에서 선언한 변수명과 맞는지 체크하고 포인터 사용하는 경우 . 아닌 -> 접근

 

error C2143: syntax error : missing ; before if

- 원인

if 발생 이전에 ; 빠진 경우에 발생

- 해결법

명령어가 끝나는 곳에 ; 붙여준다.

 

error C2065: .identifier : undeclared identifier

- 원인

.identifier 선언되지 않고 사용되는 경우에 발생

- 해결법

.identifier 부분 스펠링 확인, 대소문자 확인, 헤더파일이 정확히 include되었는지 확인

 

error C2106: = left operand must be 1-value

- a=b 경우 a쪽에 b 값을 넣을 없는 경우에 발생

 

error LNK2001: unresolved external symbol _main

error LNK1120: 1 unresolved externals

- main 부분을 찾을 없는 경우 발생

 

error C1010: unexpected end of file while looking for precompiled header directive

- 원인

비주얼C에서 precompiled header *.c혹은 *.cpp파일에 include하지 않은 경우 발생

- 해결법

소스파일에 #include stdafx.h추가

Project-setting0c/c++ tab Project Option text bok에서 /Yustdafx.h부분을 찾아 삭제

 

error C2143: syntax error : missing ; before }

error C1004: unexpected end of file found

- 원인

{ } 쌍이 맞지 않는 경우 발생

C2143 경우 } 개수가 { 개수보다 많은 경우

C1004 에러의 경우 { 개수가 } 개수보다 많은 경우

- 해결법

{ } 개수를 맞게 조정

 

error C2146: syntax error: missing ; before identifier printf

- 원인

printf 앞에 세미콜론(;) 빠짐

- 해결법

세미콜론(;) 빠진 곳에 세미콜론(;) 추가

 

2. 오류 문구로 보는 오류 유형

2-1. 호출 / 선언시

warning C4013: printf undefined; assuming extern returning int

- printf 문을 호출하기 위한 #include<stdio.h> 선언하지 않음

 

a : undeclared identifier

- 변수 a 선언되지 않았다. 선언(int, float ) 변수가 없음

 

Declaration is not allowed here

- while, for, do, if, switch 등의 제어문에는 선언문이 없다.

 

Invalid Indirection

- 간접 연산자(*) void pointer 선언이 필요 없음

ex)

int main (void)

{

             void *p;

             *p = 10; // Invalid Indirection

             return 0;

}

 

Multiple declaration for identifier

- identifier(변수나 함수 ) 한번 이상 또는 중복 선언되었다.

ex)

int a;

float a;

 

2-2. 빠뜨림

syntax error : missing ) before ;

- 세미콜론 앞에 ) 빠짐

 

( expected

) expected

, expected

< expected

{ expected

} expected

- (, ), , , <, {, }, :, ; 등이 빠졌음

 

Declaration syntax error

- 원인

프로그램 선언부에서 symbol 빠졌거나 추가가 필요하다는 의미

- 해결법

현재의 라인이나 이전의 라인에서 세미콜론(;)이나 괄호({,}) 등을 검사해야 한다.

 

Undefined symbol identifier

- 사용된 변수 등이 선언부에 빠짐

- 철자상의 오류

 

Case statement missing :

- case 문은 다음에 : 빠졌다.

 

Declaration missing ;

- struct union 선언문에는 반드시 끝에 세미콜론(;) 나와야 한다.

 

Declaration terminated incorrectly

- 함수에서 세미콜론 등이 잘못 위치하여 프로그램에 오류가 발생하여 종료

 

Declaration was expected

- 필요한 부호가 빠졌다는 의미.

- 콤마(,), 세미콜론(;), 괄호((,),{,}) 등이 빠짐

 

Unable to open include file filename

- 컴파일러가 명명한 파일 이름을 찾을 없을

- 파일이 존재하지 않거나 경로가 올바르지 않은 경우

 

Undefined label identifier

- goto 문과 상응하는 label 정의가 없음

 

Compound statement missing }

- 중괄호 ({, }) 불일치

 

Array bounds missing ]

OR Delete array size missing ]

OR Operator [] missing ]

OR Subscripting missing ]

- ] 빠졌다. [ 연산자로 선언되었다.

 

2-3. 문법 구조 오류

Cannot case from type1 to type2

- type 1 type 2 서로 일치 하지 않은 경우

- 포인터는 정수형과 실수형으로 cast 할수 있지만 구조체나 배열은 어느 것으로도 cast 불가능

Misplaced break

- break 문은 switch 문이나 루프 안에서만 사용

 

Misplaced countinue

- continue 문은 루프 안에서만 사용 가능하다.

 

Ambiguity between function1 and function2

Address of overloaded function function doest match type

- 함수 사이의 변수가 일치하지 않는다.

 

Array must have at least one element

- 배열은 하나 이상의 요소가 함께 선언되어야 한다.

 

Cannot overload main

- main 한번 이상 쓰였다.

 

Undefined symbol identifier

- identifier 선언되지 않았다.

 

Abnormal program termination

- 주로 메모리 부족으로 인한 오류

 

Divide error

Floating point error: Divide by 0

- 0으로 나누었을 발생

 

Posted by OnewayK
,

IP 주소로 PC에 해당 포트가 오픈되어 있는지 확인


using System;

using System.Text;

using System.Net.Sockets;

using System.Net.NetworkInformation;

using System.Net;



public class CheckPort

{


    public static void Main(string[] args)

    {

        try

        {

if (args.Length < 1)

{

Console.WriteLine("Usage : CheckPort.exe [IP] [Port]");

Console.WriteLine("        CheckPort.exe 192.168.0.1 80");

return;

}

string ip = args[0];

int port = Convert.ToInt32(args[1]);

if (PingTest(ip))

{

Console.WriteLine("{0} PING OK", ip);

if (ConnectTest(ip, port))

{

Console.WriteLine("{0}:{1} is open.", ip, port);

}

else

{

Console.WriteLine("{0}:{1} is closed.", ip, port);

}

}

else

{

Console.WriteLine("{0} PING NG", ip);

}

}

        catch (Exception e)

        {

            Console.WriteLine(e.Message);

        }


    }  

private static bool PingTest(string ip)

{

bool result = false;

try

{

Ping pp = new Ping();

PingOptions po = new PingOptions();


po.DontFragment = true;


byte[] buf = Encoding.ASCII.GetBytes("aaaaaaaaaaaaaaaaaaaa");


PingReply reply = pp.Send(

IPAddress.Parse(ip),

10, buf, po

);


if (reply.Status == IPStatus.Success)

{

result= true;

}

else

{

result = false;

}

return result;

}

catch

{

throw;

}

}



private static bool ConnectTest(string ip, int port)

{

bool result = false;


Socket socket = null;

try

{

socket = new Socket(

AddressFamily.InterNetwork,

SocketType.Stream, 

ProtocolType.Tcp

);


socket.SetSocketOption(

SocketOptionLevel.Socket,

SocketOptionName.DontLinger,

false

);



IAsyncResult ret = socket.BeginConnect(ip, port, null, null);


result = ret.AsyncWaitHandle.WaitOne(100, true);

}

catch { }

finally

{

if (socket != null)

{

socket.Close();

}

}

return result;

}



}





netstat 구현


using System;

using System.Net;

using System.Net.Networkinformation


namespace MyNetstat

{

class Program

{

static void Main(string[] args)

{

IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();


IPEndPoint[] endPoints = ipProperties.GetActiveTcpListeners();

TcpConnectioninformation[] tcpConnections = ipProperties.GetActiveTcpConnections();


foreach(TcpConnectioninformation info in tcpConnections)

{

Console.WriteLine("Local: " + info.LocalEndPoint.Address.ToString() 

+ ":" + info.LocalEndPoint.Port.ToString() 

+ "\nRemote: " + info.RemoteEndPoint.Address.ToString() 

+ ":" + info.RemoteEndPoint.Port.ToString() 

+ "\nState : " + info.State.ToString() + "\n\n");

}

Console.ReadLine();

}

}

} 

'LANGUAGE > C#' 카테고리의 다른 글

프로세스 정보 얻어 오는 방법  (0) 2015.11.04
Posted by OnewayK
,