Debuggung Plugins

I’ve been starting to develop some plugins and I’m wondering what other folks do for debugging. Since I’m simultaneously learning C/C++ and the SC API, it would be very useful to have more info from the server when it crashes. My plugin sometimes crashes and it’s not always clear why.

I figure I can use perf if I have to but I wonder if there’s some in-build SC functionality I can harness. Maybe some option when compiling from source?

Compile with cmake .. -DCMAKE_BUILD_TYPE=Debug or cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo (the default), and run scsynth in a debugger.

// in SC, get the scsynth options
s.options.asOptionsString
->  -u 57110 -a 1024 -i 2 -o 2 -m 131072 -R 0 -l 1

// Linux, using gdb (in the terminal, not in SC):
$ gdb --args scsynth -u 57110 -a 1024 -i 2 -o 2 -m 131072 -R 0 -l 1
..... blah blah
(gdb) run
..... blah blah
SuperCollider 3 server ready.

// back in SC:
s.startAliveThread;

Requested notification messages from server 'localhost'
localhost: server process's maxLogins (1) matches with my options.
localhost: keeping clientID (0) as confirmed by server process.

… and you’re running. Do something crashy and you can poke around in gdb.

hjh

Awesome; thanks!

Since we’re on the topic, I often get a SIGSEGV when trying to assign a buffer to a variable after getting it with the innards of GET_BUF:

float* data = unit->m_buf->data;

I’m doing this in the constructor; is one not supposed to get the contents of a buffer in the constructor? I only need the contents of the buffer once and would like to avoid retrieving the same information on each next().

[EDIT: Solved. I was getting the bufnum incorrectly.]

I’m certainly no expert when it comes to terminal commands but

$ gdb --args scsynth ...... //whatever

is giving me

-bash: gbd: command not found

How can I fix this? I would just debug from Xcode using smaller functions in int main() but I thought there must be a better way…

what is gbd? Looks like a typo for gdb?

1 Like

ok that’s the first half of the problem. I made a typo that time, but when I run gdb the right way (lol), I get
scsynth: No such file or directory.

what system are you on? And where is your scsynth executable?
I’m guessing if you are on a *NIX system (Linux or OS X) that you don’t have scsynth in your $PATH - so you either need to provide a full path, or cd to the directory where scsynth is and use ./scsynth

1 Like

trying this on MacOS which now is LLDB - I cannot get it to work despite looking at this (GDB to LLDB command map - 🐛 LLDB) - it starts but SC refuses to ‘startAliveThread’.

Has anyone got it to work on a recent macos, or even better, get XCode configured to debug with a GUI?

actually i just forgot to ‘run’ but then I still get the same error as I got when I was trying to link it in XCode’s debugger:

error: process exited with status -1 (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.))

ok fun part here: I compiled SC from scratch and it links. So it has to do with lovely Apple paranoid security practice… now I have to troubleshoot SC compile from scratch but that is in another thread.

once I manage to make it all work, let me know if anyone wants an instruction list :wink: