Superkkt Blog

오늘 디버깅을 하는 중에 UTF-8 한글 문자열이 GDB에서 깨져 보이는걸 발견했다. 터미널도 UTF-8 환경이였고 전에는 한글이 잘 보였는데 오늘따라 이상하게 안보이더군. 전후 사정상 분명히 문자열은 UTF-8로 인코딩된 한글 메세지인데..

그래서 한글을 확인할 방법이 없을까 생각하다가 GDB에 메모리 덤프 기능이 있는걸 사용해봤다.

(gdb) help dump
Dump target code/data to a local file.

List of dump subcommands:

dump binary -- Write target code/data to a raw binary file
dump ihex -- Write target code/data to an intel hex file
dump memory -- Write contents of memory to a raw binary file
dump srec -- Write target code/data to an srec file
dump tekhex -- Write target code/data to a tekhex file
dump value -- Write the value of an expression to a raw binary file

위에 나열된 타입 중 원하는걸 사용하면 되고 나는 메모리 덤프가 필요했기 때문에 dump memory 명령을 사용했다.

(gdb) help dump memory
Write contents of memory to a raw binary file.
Arguments are FILE START STOP.  Writes the contents of memory within the
range [START .. STOP) to the specifed FILE in raw target ordered bytes.
(gbd)
(gdb) dump memory /tmp/mem_dump glob[0] glob[0]+strlen(glob[0])

dump memory 명령에 원하는 메모리의 위치를 16진수 어드레스를 직접 적어줘도 되고 계산하기 귀찮으면 위와 같이 변수명과 변수의 길이를 계산해서 넣어줘도 된다.

위와 반대로 파일의 내용을 메로리로 넣을수도 있다. 아래는 buggy.dat라는 파일의 내용을 received 변수에 넣어주는 것이다.
(gdb) restore buggy.dat binary received
Restoring binary file buggy.dat into memory (0xbfeda890 to 0xbfeda8b8)
2007/01/19 10:34 2007/01/19 10:34

trackbacks

trackbacks rss

이 글에는 트랙백을 보낼 수 없습니다

Leave a Comment