MAC에서 GDB

MAC에서 GDB "codesigned - see taskgated(8) error" 해결방법

in

macOS 에서 BigSur 이상의 OS 버전에서 GDB 사용시 “please check gdb is codesigned - see taskgated(8)” 에러가 나오면서 정상적으로 동작하지 않을 때가 있습니다.

(gdb) start
Temporary breakpoint 3 at 0x100003f84
Starting program: /Users/user/test
Unable to find Mach task port for process-id 54916: (os/kern) failure (0x5).
 (please check gdb is codesigned - see taskgated(8))

image GDB Error Message

여기서는 macOS Ventura에서 해당 에러를 해결하는 과정을 소개합니다.

Generate Certificate

Keychain Access에서 인증서를 추가합니다.

상단 탭에서 “Keychain Access” -> “Certificate Assistant” -> “Create a Certificate”를 클릭합니다.

image Keychain Access Menu

아래처럼 세팅 후 Continue를 눌러줍니다.

- Name: gdb-cert
- Identity Type: Self Signed Root
- Certificate Type: Code signing
- Check The "Let me override defaults"

image Create Your Certificate

적당한 Serial Number와 Validity Period를 설정해 줍니다.

- Serial Number: 365
- Validity Period (days): 365

image Certificate Information

“Specify a Location For The Certificate”가 나올때까지 Continue 한 후 Keychain을 System으로 설정후 Create 버튼을 눌러줍니다.

image Specify a Location For The Certificate

패스워드를 입력 합니다.

image Input Password

Done을 눌러줍니다.

image Conclusion

Keychain Access -> 좌측탭 System 클릭 -> “gdb-cert” 오른쪽 클릭 -> get info… -> Trust의 “When using this certificate” 값을 “Always Trust”로 변경해줍니다.

image Keychain Settings

Make XML File

임의의 위치에 xml 파일을 만들어 줍니다.

임의의 위치(홈 디렉터리)에 아래의 내용이 적힌 “gdb-entitlement.xml” xml 파일을 만들어 줍니다.

$ vim gdb-entitlement.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.cs.allow-jit</key>
    <true/>
    <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
    <true/>
    <key>com.apple.security.cs.allow-dyld-environment-variables</key>
    <true/>
    <key>com.apple.security.cs.disable-library-validation</key>
    <true/>
    <key>com.apple.security.cs.disable-executable-page-protection</key>
    <true/>
    <key>com.apple.security.cs.debugger</key>
    <true/>
    <key>com.apple.security.get-task-allow</key>
    <true/>
</dict>
</plist>

마무리 설정을 해줍니다.

마지막으로 아래의 명령어를 입력해서 인증서 관련 설정을 마무리 해줍니다. gdb path는 which gdb 명령어를 입력해서 찾을 수 있습니다.

# gdb path를 구해줍니다.
$ which gdb
/usr/local/bin/gdb
# <gdb_path>에 위에서 구한 gdb 경로를 입력해줍니다.
$ codesign --entitlements gdb-entitlement.xml -fs gdb-cert <gdb_path>
/usr/local/bin/gdb: replacing existing signature

image codesign gdb-cert

아래의 명령어로 GDB Config file을 생성해 줍니다.

$ echo "set startup-with-shell off" >> ~/.gdbinit

image generate .gdbinit

동작 확인

GDB가 정상적으로 동작하는것을 확인할 수 있습니다.

image gdb start