This shows you the differences between two versions of the page.
mgl:workingwithc [2020/07/20 00:23] |
mgl:workingwithc [2020/07/20 23:48] |
||
---|---|---|---|
Line 3: | Line 3: | ||
The following section has been tested on: | The following section has been tested on: | ||
- | macOS High Sierra (10.13.6), Matlab 2014b, XCode 10.1 | + | - macOS High Sierra (10.13.6), Matlab 2014b, XCode 10.1 |
+ | - macOS Sierra (10.12.6), Matlab 2016b, Xcode 9.2 | ||
One might have to work with C to meddle with low-level codes for softwares, or for developing new programs. There are different kinds of files for C: | One might have to work with C to meddle with low-level codes for softwares, or for developing new programs. There are different kinds of files for C: | ||
Line 34: | Line 35: | ||
The steps are outlined [[https://www.mathworks.com/matlabcentral/answers/299329-how-to-debug-mex-file-on-mac-platforms|here]] but I outline them here again. The debugging process works through XCode debugger, which can be programmed to be triggered by Matlab Executable. | The steps are outlined [[https://www.mathworks.com/matlabcentral/answers/299329-how-to-debug-mex-file-on-mac-platforms|here]] but I outline them here again. The debugging process works through XCode debugger, which can be programmed to be triggered by Matlab Executable. | ||
- | - We want to debug a function whos source code is, for instance, yprime.c | + | - We want to debug a function whose source code is, for instance, mglPrivateSetGammaTable.c |
- | - Recompile source mex file with debugging symbols <code> mex -g yprime.c </code> | + | - Recompile source mex file with debugging symbols (-g flag)<code> mex -g mglPrivateSetGammaTable.c </code> |
- | - Create a new XCode workspace, and configure it to use for debugging | + | - Configure a new Xcode workspace for debugging |
- | - Add the file(s) to be debugged into the XCode workspace | + | - Create a new XCode workspace |
+ | - Xcode > File > New > Workspace > Save with a name (e.g. mgl_debug) in an appropriate location (e.g. /User/josh/proj/mgl/mgllib). You can press Command+shift+G to find the folder | ||
+ | - Add the file(s) to be debugged | ||
+ | - Drag and drop the file mglPrivateSetGammaTable.c to workspace | ||
+ | - Uncheck "Destination: copy items into destination group's folder (if needed)" | ||
- Create a scheme | - Create a scheme | ||
+ | - Product > Scheme > New Scheme | ||
+ | - target: none > Name: debug> OK | ||
+ | - Run > Info > Executable option "other" > Command + Shift + G > path to Matlab executable (e.g. /Applications/MATLAB_R2016b.app/Contents/MacOS/MATLAB_maci64) | ||
+ | - Select "Wait for executable to be launched" | ||
+ | - Close | ||
- Set a symbolic breakpoint (this allows the debugger not to stop on communication signals between the apps) | - Set a symbolic breakpoint (this allows the debugger not to stop on communication signals between the apps) | ||
+ | - Debug > Breakpoints > Create Symbolic Breakpoint | ||
+ | - Symbol: NSApplicationMain | ||
+ | - Add action > type in: <code> process handle -p true -n false -s false SIGSEGV SIGBUS </code> | ||
+ | - Check Automatically continue after evaluating | ||
+ | - (If the editor disappears, right click on new breakpoint > edit breakpoint) | ||
- Set breakpoints in the mex file | - Set breakpoints in the mex file | ||
+ | - View > Navigators > show project navigator > .c file to debug > click gutter to set breakpoints | ||
- Start the Xcode debugger | - Start the Xcode debugger | ||
+ | - Product > Run | ||
+ | - This should set the Xcode message on top of the Xcode window to "Waiting for MATLAB to launch" | ||
- Launch a new instance of matlab from terminal | - Launch a new instance of matlab from terminal | ||
- | - Run the mex file | + | - Start Matlab executable from terminal (go to the path for the Matlab you indicated on the scheme) then type ./matlab |
+ | - This should set the Xcode message on top of the Xcode window to "Running MATLAB: debug" | ||
+ | - Run the mex file from Matlab in the terminal you just opened |