Attach: invalid state after attach: Exited

On Mac, i'm trying to attach to a process, since the API process control doesnt work at all (says Success but never started the process,
and the API doesnt actually match the internal usage in CommandObjectProcess, so i dont know how to use it)

Shortened version of what i"m doing:

lldb::SBDebugger debugger = lldb::SBDebugger::Create();
lldb::SBTarget target = debugger.CreateTarget(fileName);
lldb::SBProcess process = target.CreateProcess();
lldb::SBError error = process.Attach(pid):
print error.GetCString() --> "invalid state after attach: Exited"

I suppose thats not how its intended to be used? Did i miss to reset some state before attempting an attach?
The process itself runs fine, by the way.

print error.GetCString() --> "invalid state after attach: Exited"

Nevermind. Works with sudo. Looks like i did the codesign thing wrong.