Programing

gdb가“process-id에 대한 Mach 작업 포트를 찾을 수 없습니다”오류와 함께 실패

crosscheck 2020. 7. 6. 07:54
반응형

gdb가“process-id에 대한 Mach 작업 포트를 찾을 수 없습니다”오류와 함께 실패


내 앱은 정상적으로 실행되지만 gdb는 다음 오류로 디버깅하지 못합니다

(gdb) run
Starting program: /path/to/app 
Unable to find Mach task port for process-id 83767: (os/kern) failure (0x5).

OS X Lion을 사용하고 있습니다. GDB 버전은

$ gdb --version
GNU gdb 6.3.50-20050815 (Apple version gdb-1752) (Sat Jan 28 03:02:46 UTC 2012)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".

Snow Leopard 및 이후 Mac OS 버전에서는 gdb실행 파일 을 공동 디자인하는 것만으로는 충분하지 않습니다 .

http://www.opensource.apple.com/source/lldb/lldb-69/docs/code-signing.txt 를 사용하려면이 안내서를 따라야합니다 .

이 안내서에서는이를 수행하는 방법을 설명 lldb하지만 프로세스는 동일합니다 gdb.


내가로 변경하면 작동합니다 sudo gdb executableFileName! :)


인증서를 작성하고 gdb에 서명해야합니다.

  • "키 체인 액세스"응용 프로그램 열기 (/ 응용 프로그램 / 유틸리티 / Keychain Access.app)
  • 메뉴 열기 / 키 체인 접근 / 인증서 보조 / 인증서 생성 ...
  • 이름 (예에서 gdb-cert)을 선택하고 "Identity Type"을 "Self Signed Root"로 설정하고 "Certificate Type"을 "Code Signing"으로 설정 한 다음 "Let me override defaults"를 선택하십시오. "계속"을 클릭하십시오. 사전 정의 된 365 일 기간을 3650 일로 연장 할 수 있습니다.
  • "인증서 위치 지정"화면이 나타날 때까지 "계속"을 여러 번 클릭 한 다음 "키 체인을 시스템"으로 설정하십시오.
  • 인증서를 "시스템"키 체인에 저장할 수 없으면 "로그인"키 체인에 인증서를 작성한 다음 내보내십시오. 그런 다음이를 "시스템"키 체인으로 가져올 수 있습니다.
  • 키 체인에서 "시스템"을 선택하면 새 인증서를 찾을 수 있습니다. 인증서의 상황에 맞는 메뉴를 사용하여“정보 입수”를 선택하고“신뢰”항목을 연 다음“코드 서명”을“항상 신뢰”로 설정하십시오.
  • 인증서를 사용하고 현재 실행중인 "taskgated"프로세스를 종료하여 "taskgated"서비스를 다시 시작하려면 "Keychain Access"응용 프로그램을 종료해야합니다. 또는 컴퓨터를 다시 시작할 수 있습니다.
  • 마지막으로 gdb에 서명 할 수 있습니다 :

    sudo codesign -s gdb-cert /usr/local/bin/ggdb

    sudo ggdb ./myprog


문제는 원하지 않는 루트 사용자로 로그인하지 않았다는 것입니다. 액세스 할 수 있도록 gdb에 대한 인증서를 작성해야합니다. 이 튜토리얼을 따라 가면 좋을 것입니다 ...

http://sourceware.org/gdb/wiki/BuildingOnDarwin

다른 모든 방법이 실패하면 sudo gdb executableFileName을 사용하십시오.


이 링크 에는이 오류가 사라지게하는 가장 명확하고 자세한 단계별 설명이 나와 있습니다.

내 경우에는 "시스템"키로 키를 가져야했습니다. 그렇지 않으면 작동하지 않습니다 (모든 URL이 언급하지는 않음).

또한 taskgated킬 ( killing) 은 다시 시작해야하는 실행 가능한 대안입니다.

또한 MacPorts를을 제거 나는이 과정을 시작하여 현재 GDB를 제거하기 전에 brew uninstall gdb.


El Capitan에서 작동하려면이 명령이 필요했습니다.

sudo security add-trust -d -r trustRoot -p basic -p codeSign -k /Library/Keychains/System.keychain ~/Desktop/gdb-cert.cer

튜토리얼을 따랐 으며 모든 것이 정상입니다.


MacOSX에서 lldb는 코드 서명되어야합니다. 디버그 및 릴리스 빌드는 lldb_codesign이라는 코드 서명 인증서를 사용하여 코드 서명하도록 설정되어 있습니다.

If you don't have one yet you will need to:
- Launch /Applications/Utilities/Keychain Access.app

- In Keychain Access select the "login" keychain in the "Keychains"
  list in the upper left hand corner of the window.

- Select the following menu item:

    Keychain Access->Certificate Assistant->Create a Certificate...

- Set the following settings

    Name = lldb_codesign
    Identity Type = Self Signed Root
    Certificate Type = Code Signing

- Click Continue
- Click Continue
- Click Done
- Click on the "My Certificates"
- Double click on your new lldb_codesign certificate
- Turn down the "Trust" disclosure triangle

    Change:
        When using this certificate: Always Trust

- Enter your login password to confirm and make it trusted

The next steps are necessary on SnowLeopard, but are probably because of a bug
how Keychain Access makes certificates.

- Option-drag the new lldb_codesign certificate from the login keychain to
  the System keychain in the Keychains pane of the main Keychain Access window
  to make a copy of this certificate in the System keychain.  You'll have to
  authorize a few more times, set it to be "Always trusted" when asked.
- Switch to the System keychain, and drag the copy of lldb_codesign you just
  made there onto the desktop.
- Switch to Terminal, and run the following:

sudo security add-trust -d -r trustRoot -p basic -p codeSign -k /Library/Keychains/System.keychain ~/Desktop/lldb_codesign.cer

- Right click on the "lldb_codesign" certificate in the "System" keychain (NOT
  "login", but the one in "System"), and select "Delete" to delete it from
  the "System" keychain.
- Reboot
- Clean and rebuild lldb and you should be able to debug.

That should do it.

[참고 :-lldb는 mac에서 gdb로 사용됩니다.]


여기 내 문제를 해결 한 정말 유용한 안내서 가 있습니다 (OSX 10.13.6).

  1. 열린 키 체인 접근
  2. 메뉴에서 키 체인 접근> 인증 지원> 인증서 작성을여십시오.
  3. 이름을 입력하십시오 (예 : gdbc)
    • 신원 유형 : 자체 서명 된 루트
    • 인증 유형 : 코드 서명
    • Check: let me override defaults
  4. Continue until it prompts you for: "specify a location for..."
  5. Set Keychain location to System
  6. Create a certificate and close assistant.
  7. Find the certificate in System keychains, right click it > get info (or just double click it)
  8. Expand Trust, set Code signing to always trust
  9. Restart taskgated in terminal: killall taskgated
  10. Run codesign -fs gdbc /usr/local/bin/gdb in terminal: this asks for the root password

These instructions work for OSX High Sierra and avoid running gdb as root (yuck!). I recently updated from OSX 10.13.2 to 10.3.3. I think this is when gdb 8.0.1 (installed w/ homebrew) started failing for me.

I had difficulty with other people's instructions. After different instructions, everything was a mess. So I started a fresh. I more or less followed these instructions.

Clean the mess :

  1. brew uninstall --force gdb # This deletes _all_ versions of gdb on the machine
  2. In Applications -> Utilities -> Keychain Access, I deleted all previous gdb certificates and keys (be sure you know what you're doing here!). It's unclear if this is necessary, but since I'd buggered up trying to create those certificates and keys using other instructions I eliminated them anyways. I had keys and certificates in both login and system.

Now reinstall gdb.

  1. brew install gdb
  2. Within Keychain Access, go to menu Keychain Access-> Certificate Assistant -> Create a Certificate
  3. Check "Let me override defaults" and set
Name : gdb-cert
Identity Type: Self Signed Root
Certificate Type : Code Signing

[X] Let me override defaults
  1. On 1st Certificate Information page:
Serial Number : 1
Validity Period (days): 3650
  1. On 2nd Certificate Information page, I left all fields blank except those already filled in.

  2. On Key Pair Information page, I left the defaults

Key Size : 2048
Algorithm : RSA
  1. On Key Usage Extension page, I left the defaults checked.
[X] Include Key Usage Extension
[X] This extension is critical
Capabilities:
[X] Signature
  1. On Extended Key Usage Extension page, I left the defaults checked.
[X] Include Extended Key Usage Extension
[X] This extension is critical
Capabilities:
[X] Code Signing
  1. On Basic Constraints Extension Page, nothing was checked (default).

  2. On Subject Alternate Name Extension page, I left the default checked and didn't add anything else.

[X] Include Subject Alternate Name Extension
  1. On Specify a Location for the certificate page, I set
Keychain: System
  1. I clicked Create and was prompted for my password.

  2. Back in the Keychain Access app, I went to System and right clicked on gdb-cert and under dropdown menu Trust, I changed all the fields to Always Trust.

  3. Rebooted computer.

  4. At the Terminal, I ran codesign -s gdb-cert /usr/local/bin/gdb. I entered my password when prompted.

  5. At the Terminal, I ran echo "set startup-with-shell off" >> ~/.gdbinit

  6. I ran gdb myprogram and then start within the gdb console. Here, I believe, it prompted for me for my password. After that, all subsequent runs, it did not prompt for my password.


This is a weird approach but it worked for me(MacOs HighSierra 10.13.3). Install CLion. It comes with gdb. Once run the gdb using Terminal. Copy the gdb program to your usr/local/bin/. No problem of signin, sudo etc.


Following the instructions here Codesign gdb on macOS seemed to resolve this issue, for me, on macOS High Sierra (10.13.3).

참고URL : https://stackoverflow.com/questions/11504377/gdb-fails-with-unable-to-find-mach-task-port-for-process-id-error

반응형