Skip to content

Inject F-Script into application requires gdb #13

@abarnert

Description

@abarnert

Recent versions of Xcode no longer come with a gdb symlink, so you have to use lldb instead.

While lldb does have synonyms for its commands that make everything work, its command-line arguments are different. You have to use --source rather than -command, and if you use -n you have to give it an argument (which also makes things simpler, because now you can just pass the process name as an argument instead of having to hack up the script with sed—or just use -p with the PID, which means no quoting issues).

If you don't need admin privileges, the whole thing can be an AppleScript:

tell application "System Events"
    unix id of the first process whose frontmost is true
end tell

Then pass the result to a shell script with input as arguments:

lldb --attach-pid "$*" <<EOF
p (char)[[NSBundle bundleWithPath:@"/Library/Frameworks/FScript.framework"] load]
p (void)[FScriptMenuItem insertInMainMenu]
detach
quit
EOF

If you do, then you can remove the first line of gdbtemp.txt (and rename it to lldbtemp.txt while you're at it) and replace the existing AppleScript with:

tell application "System Events"
    set pid to unix id of the first process whose frontmost is true
end tell

do shell script "lldb -attach-pid" & pid & " --source=/tmp/lldbtemp.txt" with administrator privileges

Personally, I've created an fscript-inject shell script:

#!/bin/bash
lldb --attach-pid "$1" <<EOF
p (char)[[NSBundle bundleWithPath:@"/Library/Frameworks/FScript.framework"] load]
p (void)[FScriptMenuItem insertInMainMenu]
detach
quit
EOF

So my workflow is just one AppleScript:

tell application "System Events"
    set pid to unix id of the first process whose frontmost is true
end tell

do shell script "fscript-inject " & pid with administrator privileges

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions