Eclipse / CDT로 C ++ 코드를 디버깅 할 때 더 나은 변수 탐색
Eclipse와 CDT를 사용하여 C ++ 코드를 디버그하기 위해 변수 창은 번거롭고 표준 템플릿 라이브러리 또는 boost (예 : shared_ptr)에 정의 된 유형에 대해 그다지 유익하지 않습니다.
std :: vector의 경우 다음과 같은 예입니다.
bar {...}
std::_Vector_base<TSample<MyTraits>, std::allocator<TSample<MyTraits> > >
_M_impl {...}
std::allocator<TSample<MyTraits> > {...}
_M_start 0x00007ffff7fb5010
_M_finish 0x00007ffff7fd4410
_M_end_of_storage 0x00007ffff7fd5010
이러한 유형의 내부에 대한이 정보가 유용 할지라도 거의 모든 경우에 std :: vector에 대한 값 목록과 같은보다 명확한 표현을 기대합니다. 이를 수행 할 수있는 도구, 플러그인 또는 기타 수정 사항이 있습니까?
편집하다
다음 솔루션은 Linux에서 작동하지 않습니다. 우분투 14.04, eclipse, g ++, gdb를 사용하고 있습니다.
gdb-python 패키지를 찾을 수없고 Linux는 mingw를 사용하지 않습니다.
구조를 예쁘게 인쇄하려면 파이썬을 사용할 수있는 GDB 버전이 필요합니다. 최소한 mingw를 사용하는 Windows에서는 이것이 기본 설치에서 제공되지 않는다는 것을 알고 있습니다.
Pretty Printers는 주어진 구조를 표시하는 방법을 gdb에 알려주는 파이썬 모듈입니다. 직접 작성할 수 있지만 다운로드 할 수있는 STL 용 프린터가 이미 있습니다.
Windows에서 프리티 프린터를 사용하려면 (지침은 다른 OS와 유사해야 함) :
전제 조건
Python 2.7이 설치되어 있고 시스템 경로에 있는지 확인하십시오.
MinGW-get이 설치되어 있는지 확인하십시오
http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/
SVN 클라이언트가 설치되어 있는지 확인
설치:
명령 셸을 열고 다음을 입력합니다.
mingw-get install gdb-python완료되면 로컬 디렉토리로 이동하고 다음을 입력하여 프린터를 설치합니다.
svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python.gdbinit를 열고 (필요한 경우 텍스트 편집기에서 생성) "C : / directory"를 프린터를 체크인 한 폴더로 대체하여 다음을 입력합니다.
Python
import sys
sys.path.insert (0, 'C : / directory')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end
Eclipse 설정
- Windows> 환경 설정> C / C ++> 디버그> GDB로 이동하십시오.
- GDB 디버거가 파이썬 지원 GDB에 대한 경로를 넣는 경우 gdb-python27.exe와 같은 이름의 mingw / bin 폴더에있을 가능성이 큽니다.
- GDB 명령 파일에 앞서 만든 .gdb 초기화 파일의 경로를 입력합니다.
그게 다야, 평소처럼 디버그하면 stl 구조가 훨씬 더 읽기 쉬워야합니다.
글쎄, gdb는 기본적으로 STL 컨테이너를 지원하지 않습니다. STL 객체의 내부 동작을 노출하기 때문에 이것이 틀렸다고 말할 수는 없지만 대부분의 경우 우리가 원하는 것이 아닙니다.
gdb 7.0을 사용하는 경우 예쁜 프린터를 활용할 수 있습니다. 이 웹 사이트 http://sourceware.org/gdb/wiki/STLSupport 에는 설정 방법에 대한 매우 간단한 자습서가 있습니다. 관심있는 부분 아래에 복사했습니다.
최신 Python libstdc ++ 프린터를 컴퓨터의 한 위치에 체크 아웃합니다. 로컬 디렉토리에서 다음을 수행하십시오.
svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python~ / .gdbinit에 다음을 추가하십시오. 경로는 위의 python 모듈이 체크 아웃 된 위치와 일치해야합니다. 따라서 / home / maude / gdb_printers /로 체크 아웃하면 경로는 다음 예제와 같습니다.
python import sys sys.path.insert(0, '/home/maude/gdb_printers/python') from libstdcxx.v6.printers import register_libstdcxx_printers register_libstdcxx_printers (None) endThe path should be the only element that needs to be adjusted in the example above. Once loaded, STL classes that the printers support should printed in a more human-readable format. To print the classes in the old style, use the /r (raw) switch in the print command (i.e., print /r foo). This will print the classes as if the Python pretty-printers were not loaded.
Since you're using eclipse cdt, don't forget to point your debug configuration to your .gdbinit file. When creating a new Debug Configuration, go to the Debugger tab and put the path to the .gdbinit file in the "GDB command file" field.
I hope that helps!
In debug view in variables list expand vector:
"vector_name" -> std::_Vector_base<"datatype"> -> _M_impl
then right click on _M_start and select "Display as array...", type its length and then click OK. Now you can expand each item of your vector.
If you have gdb support for CDT (see, for example, GDB in Eclipse), you could try this: De-referencing STL containers
Long ago I also stumbled upon your same problem. It was a pain to check the STL containers. Then I found that link and added to my .gdbinit file some of those definitions. Life was easier after that.
NOTE: My gdb version is 7.1 and adding those definitions work fine. I don't know if in newer versions of gdb they are already included.
I would like to expand on the Windows 7 response because some key steps are left out:
This is for MinGW users with Eclipse CDT
0) If you don't have python GDB, open a shell/command and use MinGW-get.exe to 'install' Python-enabled GDB e.g.
MinGw-get.exe install gdb-python
1a) Get Python 2.7.x from http://python.org/download/ and install
1b) Make sure PYTHONPATH and PYTHONHOME are set in your environment:
PYTHONPATH should be C:\Python27\Lib (or similar)
PYTHONHOME should be C:\Python27
1c) Add PYTHONHOME to your PATH
%PYTHONHOME%;...
2a) Open a text enter, enter the following statements. Notice the 3rd line is pointing to where the python scripts are located. See notes below about this!
python
import sys
sys.path.insert(0, 'C:/MinGW/share/gcc-4.6.1/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end
2b) Save as '.gdbinit' NOTE: Windows explorer will not let you name a file that starts with with a period from explorer. Most text edits (including Notepad) will let you. GDB init files are like 'scripts' of GDB commands that GBD will execute upon loading.
2c) The '.gdbinit' file needs to be in the working directory of GDB (most likely this is your projects root directory but your IDE can tell you.
3) Open your Eclipse (or other IDE) Preferences dialog. Go to the C++ Debugger sub-menu.
4) Configure Eclipse to use C:\MinGW\bin\gdb-python27.exe as the debugger and your .gdbinit as the config file.
5a) Re-create all your debug launch configurations (delete the old one and create a new one from scratch).
--OR--
5b) Edit each debug configuration and point it to the new gdb-python.exe AND point it to the.
If you run into issues:
--Don't forget to change the location to the python directory in the above python code! This directory is created by MinGW, so don't go looking to download the pretty printers, MinGW did it for you in step zero. Just goto your MinGW install director, the share folder, the GCC folder (has version number) and you will find python folder. This location is what should be in python script loaded by GDB.
--Also, the .gdbinit is a PITA, make sure its named correctly and in the working folder of GDB which isn't necessarily where gdb-python.exe is located! Look at your GDB output when loading GDB to see if a) 'python-enabled' appears during load and that the statements in the .gdbinit are appearing.
--Finally, I had alot of issues with the system variables. If python gives you 'ImportError' then most likely you have not set PYTHONPATH or PYTHONHOME.
--The directory with 'gdb-python27' (e.g. C:\MinGW\bin') should also be on your path and if it is, it makes setting up eclipse a bit nicer because you don't need to put in absolute paths. But still, sometimes the .gbdinit needs an absoulte path. if it works you'll see output from gbd (console->gdb traces) like this on startup of debugger:
835,059 4^done
835,059 (gdb)
835,059 5-enable-pretty-printing
835,069 5^done
....
835,129 12^done
835,129 (gdb)
835,129 13source C:\MinGW\bin\.gdbinit
835,139 &"source C:\\MinGW\\bin\\.gdbinit\n"
835,142 13^done
835,142 (gdb)
I know that JDT (Java environment in eclipse) provides custom "formatters" to be applied when displaying variable values in debug views. A quick look at google for the same in CDT brings this page:
http://wiki.eclipse.org/CDT/Better_Debugging_%28GSoC_project%29
I don't know if this has been yet integrated in the main CDT line, may be you can try to right click on a variable while debugging (in the last CDT) and see if there is a custom formater entry. If not available I recomend you to add a new tracker entry in CDT tracker to ask this enhancement.
'program story' 카테고리의 다른 글
| MySQL Workbench (6.3.9)가 MacOS High Sierra와 호환되지 않습니까? (0) | 2020.11.12 |
|---|---|
| 물체가 피클 가능 (또는 피클 가능)된다는 것은 무엇을 의미합니까? (0) | 2020.11.12 |
| Await 연산자는 Async 메서드 내에서만 사용할 수 있습니다. (0) | 2020.11.12 |
| JSDoc에서 약속의 해결 및 거부 유형을 지정하는 방법은 무엇입니까? (0) | 2020.11.12 |
| 자바의 퍼지 문자열 검색 라이브러리 (0) | 2020.11.12 |