Differences

This shows you the differences between two versions of the page.

Link to this comparison view

mgl:workingwithc [2020/07/20 00:23]
mgl:workingwithc [2020/07/20 23:19]
Line 34: Line 34:
 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