Translate

[GDB][OSX] Mac 에 gdb 설치하기



Linux 와는 다르게 OSX에는 gdb 가 기본적으로 설치되어 있지 않아서 설치하느라 이곳저곳 찾아봤는데 제대로 된 곳을 발견했다.


리리와 포포 - [맥] MAC에 GDB 설치하기!



내가 작업한 부분을 정리해서 올린다.


설치방법은 의외로 간단하다.


1004lucifer:~ 1004lucifer$
1004lucifer:~ 1004lucifer$ gdb
-bash: gdb: command not found
1004lucifer:~ 1004lucifer$
1004lucifer:~ 1004lucifer$ brew
-bash: brew: command not found
1004lucifer:~ 1004lucifer$
1004lucifer:~ 1004lucifer$
1004lucifer:~ 1004lucifer$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir /usr/local
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local
==> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Counting objects: 213620, done.
remote: Compressing objects: 100% (56570/56570), done.
remote: Total 213620 (delta 155911), reused 213512 (delta 155834)
Receiving objects: 100% (213620/213620), 46.39 MiB | 2.56 MiB/s, done.
Resolving deltas: 100% (155911/155911), done.
From https://github.com/Homebrew/homebrew
* [new branch] master -> origin/master
HEAD is now at e62d8d9 authexec: migrating taps
==> Installation successful!
==> Next steps
Run `brew doctor` before you install anything
Run `brew help` to get started
1004lucifer:~ 1004lucifer$
1004lucifer:~ 1004lucifer$
1004lucifer:~ 1004lucifer$
1004lucifer:~ 1004lucifer$
1004lucifer:~ 1004lucifer$ brew install homebrew/dupes/gdb
Cloning into '/usr/local/Library/Taps/homebrew/homebrew-dupes'...
remote: Counting objects: 1471, done.
remote: Total 1471 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (1471/1471), 292.99 KiB | 69.00 KiB/s, done.
Resolving deltas: 100% (809/809), done.
Checking connectivity... done.
Tapped 36 formulae
==> Installing gdb from homebrew/homebrew-dupes
==> Installing dependencies for gdb: xz, pkg-config, readline
==> Installing gdb dependency: xz
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/xz-5.0.7.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring xz-5.0.7.mavericks.bottle.tar.gz
🍺 /usr/local/Cellar/xz/5.0.7: 58 files, 1.5M
==> Installing gdb dependency: pkg-config
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/pkg-config-0.28.mavericks.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring pkg-config-0.28.mavericks.bottle.2.tar.gz
🍺 /usr/local/Cellar/pkg-config/0.28: 10 files, 604K
==> Installing gdb dependency: readline
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/readline-6.3.8.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring readline-6.3.8.mavericks.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.

Mac OS X provides similar software, and installing this software in
parallel can cause all kinds of trouble.

OS X provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

LDFLAGS: -L/usr/local/opt/readline/lib
CPPFLAGS: -I/usr/local/opt/readline/include

==> Summary
🍺 /usr/local/Cellar/readline/6.3.8: 40 files, 2.1M
==> Installing gdb
==> Downloading http://ftpmirror.gnu.org/gdb/gdb-7.8.1.tar.xz
######################################################################## 100.0%
curl: (28) Connection timed out after 5037 milliseconds
Trying a mirror...
==> Downloading http://ftp.gnu.org/gnu/gdb/gdb-7.8.1.tar.xz
######################################################################## 100.0%
==> Patching
patching file gdb/darwin-nat.c
==> ./configure --prefix=/usr/local/Cellar/gdb/7.8.1 --with-system-readline --with-lzma --with-python=/usr
==> make
==> make install
==> Caveats
gdb requires special privileges to access Mach ports.
You will need to codesign the binary. For instructions, see:

http://sourceware.org/gdb/wiki/BuildingOnDarwin
==> Summary
🍺 /usr/local/Cellar/gdb/7.8.1: 42 files, 5.7M, built in 13.2 minutes
1004lucifer:~ 1004lucifer$
1004lucifer:~ 1004lucifer$
1004lucifer:~ 1004lucifer$ gdb
GNU gdb (GDB) 7.8.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin13.3.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb)




gdb 설치 후 run 명령어를 하려면 인증서 작업을 해줘야 한다.




Launchpad 에서 유틸리티/기타 선택 후 '키체인 접근' 아이콘 클릭






키체인 접근 메뉴 => 인증서 지원 => 인증서 생성






다음과 같이 셋팅 (이름은 임의로 지정)






다음과 같이 셋팅





'계속' 버튼을 여러번 누른 후 '인증서에 대한 위치 지정' 항목이 나오면 다음과 같이 셋팅 후 '생성' 버튼 클릭






'완료' 버튼 클릭






키체인 항목에서 '시스템' 선택 후 방금 생성한 키체인의 정보가져오기 선택






'신뢰' 부분에서 '항상 신뢰'를 선택






위의 설정이 되면 인증서 아이콘이 아래와 같이 변경됨.






다음과 같이 명령어 입력 후 재부팅


1004lucifer:~ 1004lucifer$ 
1004lucifer:~ 1004lucifer$ codesign -s gdb-cert /usr/local/bin/gdb
1004lucifer:~ 1004lucifer$ 











PS.
gdb 설치만 하고 인증서 작업을 하지 않은경우 디버깅 시 run 명령 시 다음과 같은 문제가 발생된다.



1004lucifer:~ 1004lucifer$ 
1004lucifer:~ 1004lucifer$ gdb like
GNU gdb (GDB) 7.8.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin13.3.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from like...Reading symbols from /Users/btb/Documents/test/like.dSYM/Contents/Resources/DWARF/like...done.
done.
(gdb) list
3 void lovecall();
4
5 char *getname() {
6 char name[128];
7
8 printf("Input name : ");
9 scanf("%s", name);
10 return name;
11 }
12
(gdb) b main
Breakpoint 1 at 0x100000e0c: file like.c, line 17.
(gdb) r
Starting program: /Users/btb/Documents/test/like 
Unable to find Mach task port for process-id 440: (os/kern) failure (0x5).
 (please check gdb is codesigned - see taskgated(8))
(gdb) 
(gdb)




댓글

댓글 쓰기