Issues on attach to process with macOS Xcode for C++ add-ins

Issues on attach to process with macOS Xcode for C++ add-ins

rbin_robotik
Contributor Contributor
3,571 Views
5 Replies
Message 1 of 6

Issues on attach to process with macOS Xcode for C++ add-ins

rbin_robotik
Contributor
Contributor

Hello,

 

I am having an issue when I try to attach the Xcode debugger to the active Fusion 360 process on macOS. I am following the instructions on the documentation, i.e. follow Debug -> Attach to Process -> select Fusion 360.

 

The following is what I see on Xcode after it fails to attach to the Fusion 360 process

 

Could not attach to pid : “45751”
Domain: IDEDebugSessionErrorDomain
Code: 3
Failure Reason: attach failed (Not allowed to attach to process.  Look in the console messages (Console.app), near the debugserver entries, when the attach failed.  The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.)
User Info: {
    DVTErrorCreationDateKey = "2023-04-07 20:50:41 +0000";
    DVTRadarComponentKey = 855031;
    IDERunOperationFailingWorker = DBGLLDBLauncher;
    RawUnderlyingErrorMessage = "attach failed (Not allowed to attach to process.  Look in the console messages (Console.app), near the debugserver entries, when the attach failed.  The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.)";
}
--

Analytics Event: com.apple.dt.IDERunOperationWorkerFinished : {
    "device_model" = "MacBookPro15,2";
    "device_osBuild" = "13.3 (22E252)";
    "device_platform" = "com.apple.platform.macosx";
    "launchSession_schemeCommand" = Run;
    "launchSession_state" = 1;
    "launchSession_targetArch" = "x86_64";
    "operation_duration_ms" = 171;
    "operation_errorCode" = 3;
    "operation_errorDomain" = IDEDebugSessionErrorDomain;
    "operation_errorWorker" = DBGLLDBLauncher;
    "operation_name" = IDERunOperationWorkerGroup;
    "param_consoleMode" = 0;
    "param_debugger_attachToExtensions" = 0;
    "param_debugger_attachToXPC" = 1;
    "param_debugger_type" = 3;
    "param_destination_isProxy" = 0;
    "param_destination_platform" = "com.apple.platform.macosx";
    "param_diag_MainThreadChecker_stopOnIssue" = 0;
    "param_diag_MallocStackLogging_enableDuringAttach" = 0;
    "param_diag_MallocStackLogging_enableForXPC" = 0;
    "param_diag_allowLocationSimulation" = 0;
    "param_diag_checker_tpc_enable" = 0;
    "param_diag_gpu_frameCapture_enable" = 0;
    "param_diag_gpu_shaderValidation_enable" = 0;
    "param_diag_gpu_validation_enable" = 1;
    "param_diag_memoryGraphOnResourceException" = 0;
    "param_diag_queueDebugging_enable" = 1;
    "param_diag_runtimeProfile_generate" = 0;
    "param_diag_sanitizer_asan_enable" = 0;
    "param_diag_sanitizer_tsan_enable" = 0;
    "param_diag_sanitizer_tsan_stopOnIssue" = 0;
    "param_diag_sanitizer_ubsan_stopOnIssue" = 0;
    "param_diag_showNonLocalizedStrings" = 0;
    "param_diag_viewDebugging_enabled" = 1;
    "param_diag_viewDebugging_insertDylibOnLaunch" = 1;
    "param_install_style" = 2;
    "param_launcher_UID" = 2;
    "param_launcher_allowDeviceSensorReplayData" = 0;
    "param_launcher_kind" = 0;
    "param_launcher_style" = 99;
    "param_launcher_substyle" = 256;
    "param_runnable_appExtensionHostRunMode" = 0;
    "param_testing_launchedForTesting" = 0;
    "param_testing_suppressSimulatorApp" = 0;
    "param_testing_usingCLI" = 0;
    "sdk_canonicalName" = "macosx13.3";
    "sdk_osVersion" = "13.3";
    "sdk_variant" = macos;
}
--


System Information

macOS Version 13.3 (Build 22E252)
Xcode 14.3 (21812) (Build 14E222b)
Timestamp: 2023-04-07T13:50:41-07:00

 

I followed the instructions on the error message; recorded a session on the Console app and found the "debugserver" lines. As a result, I was able to pinpoint the details on the issue:

 

[LaunchAttach] (46575) about to task_for_pid(45751)
----
macOSTaskPolicy: (com.apple.debugserver) may not get the task control port of (Autodesk Fusion ) (pid: 45751): (Autodesk Fusion ) is hardened, (Autodesk Fusion ) doesn't have get-task-allow, (com.apple.debugserver) is a declared debugger(com.apple.debugserver) is not a declared read-only debugger
----
error: [LaunchAttach] MachTask::TaskPortForProcessID task_for_pid(45751) failed: ::task_for_pid ( target_tport = 0x0203, pid = 45751, &task ) => err = 0x00000005 ((os/kern) failure)
----
skipping details here, but in summary, it throws an exception and logs the previously shared message

 

I'd be happy if you had some suggestions on how to fix this issue.

0 Likes
Accepted solutions (1)
3,572 Views
5 Replies
Replies (5)
Message 2 of 6

rbin_robotik
Contributor
Contributor

One thing you could try is to disable the "Enable Hardened Runtime" option in the Fusion 360 build settings, rebuild the application, and then try to attach to the process again.


 @bbcorhitter thanks for your answer, but it feels like we would need a bit more to achieve what you discussed above. I am not sure regular users of Fusion 360 have the ability to rebuild the application as you suggested.

 


If that does not work, you could also try signing the application with a development certificate that includes

the get-task-allow entitlement, which allows debugging.

 

Would you please elaborate on this a bit more? I am actually wondering if this is a legitimate answer for my question, but it shouldn't be that hard to debug a C++ add-in on macOS.

 


It's also worth noting that some applications may intentionally prevent debugging to protect their intellectual property, and attempting to circumvent those protections may violate their terms of use.

 

FYI, there is a tutorial on how to debug scripts and add-ins here: https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-ECC0A398-4D89-4776-A054-F7B432F7FCF6#Debuggi...

 

 

0 Likes
Message 3 of 6

alanGLX5F
Observer
Observer

I'm having exactly the same issue attempting to debug one of the C++ samples from the documentation. As far as I can see, the problem here is that Fusion 360 is hardened - not surprisingly. Consequently its impossible to attach to it. However, maybe I'm getting the wrong end of the stick here. If this is the case then the helpful documentation on how debug a script on a mac using XCode is sadly wrong. I imagine it works for Fusion 360 developers because they can 'unhardened' their development builds. Any suggestions/corrections on this would be very welcome.

Message 4 of 6

Paul_Kersting
Observer
Observer
Hi,
i have removed the code signature from Fusion 360 and can attach the process.

codesign --remove-signature /Users/<YourUserName>/Library/Application\ Support/Autodesk/webdeploy/production/<CurrentProductionNumber>/Autodesk\ Fusion\ 360.app/Contents/MacOS/Autodesk\ Fusion\ 360
0 Likes
Message 5 of 6

BrianEkins
Mentor
Mentor
Accepted solution

A change was made in the September release to fix this. It's listed as a fix on the What's New page.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 6 of 6

rbin_robotik
Contributor
Contributor
I tested it very quickly with the default C++ template code (i.e. HelloAddIn) on an Intel Mac with macOS Sonoma 14.1.1 & Xcode 15.0.1, and it worked perfectly. I'll test it later on a relatively larger code base with VSCode instead of Xcode using the same platform, but I don't think it would be an issue anymore.
0 Likes