programing

line by line c - Linux ubuntu에서의 c++ 코드 디버깅

copyandpastes 2022. 10. 2. 22:33
반응형

line by line c - Linux ubuntu에서의 c++ 코드 디버깅

우분투에서 gedit을 사용하여 코딩하고 단말기에서 프로그램을 실행하고 있습니다.Turboc 또는 netbeans를 사용하여 Windows에서 작업하는 동안 코드를 한 줄씩 디버깅할 수 있습니다.우분투 터미널에서 어떻게 해요?아니면 다른 선택지가 있나요?

gdb(Gnu 디버거)는 최적의 선택입니다.

apt-get install gdb

man gdb

1.    cc -g file.c             //       compile your program ,this will generate a.out file with required debugging information 

2.    gdb a.out                //        start with gdb

3.    b main                   //        to set break point at main       

4.     run                     //        run now , and it will stop at break point main 

5.     s                       //        option s is to step single line and even step into functions

6.     n                       //        option n is to execute next line and step over functions  

7.     p    variable name      //        to print the value of variable at that particular instance very helpful  

man gdb가 더 많은 정보를 줄 이다.

여기에서는 모든 유용한 gdb 명령어와 간단한 cpp 프로그램을 사용한 예를 보여 줍니다.

GDB 매뉴얼

GDB(Gnu DeBugger)는 c/c++에 가장 적합한 도구입니다.gcc가 설치되어 있는 경우 시스템에 이미 설치되어 있을 수 있습니다.

이 기능을 사용하려면 , 반드시 프로그램을 컴파일 해 주세요.-g플래그:

gcc -g myprog.c -o myprog

다음으로 디버거를 기동합니다.

gdb ./myprog

다음은 작업을 시작하기 위한 몇 가지 기본 명령어입니다.

b lineno           - set a break point at line 'lineno'
b srcfile:lineno   - set a break point in source file 'srcfile' at line 'lineno'
r                  - run the program
s                  - step through the next line of code
c                  - continue execution up to the next breakpoint
p varname          - print the value of the variable 'varname'

여기에는 gdb를 사용할 수 있습니다.

gdb가 아직 설치되어 있지 않은 경우 설치합니다.

sudo apt-get install gdb

그런 다음 다음과 같이 선택한 실행 파일을 디버깅할 수 있습니다.

gdb <executable name>

완전한 대화형 디버깅세션을 얻을 수 있습니다.

코드 관리, 강조 표시, 디버깅 기능을 제공하는 IDE(http://en.wikipedia.org/wiki/Integrated_development_environment) 를 사용할 수 있습니다.이것들 중 아무거나 시도해 보세요.

또는 다음을 사용할 수 있습니다.gdb( https://www.gnu.org/software/gdb/) 를 명령줄에서 직접 참조해 주세요.

언급URL : https://stackoverflow.com/questions/18271363/line-by-line-c-c-code-debugging-in-linux-ubuntu

반응형