How to trigger breakpoints inside a script called by publish? - matlab

I wrote some script called drawCurves.m to draw some curves. Then I called this script via publish function:
publish('drawCurves.m', 'outputDir', destPath, 'showCode', false)
Unfortunately, no any breakpoints set inside drawCurves trigger. If I call script directly by name, breakpoints do trigger.
Is it possible to fix somehow?

The publish command calls a private function evalmxdom to actually run the code in your file. You can find evalmxdom at $matlabroot%\toolbox\matlab\codetools\private\evalmxdom.m, where $matlabroot$ is your MATLAB installation directory.
If you read through it, you'll find a section at around line 60 where it stores the current breakpoints, turns them all off, and then sets things up so that the original breakpoints are restored when publishing is finished.
You'll notice that the code calls a subfunction safeDbclear that clears the breakpoints. Try commenting out the contents of that subfunction, and publishing again.
NB:
I'm on R2017a: if you're on a different version and this file has changed between versions, the line numbers may be different.
Be careful: you will be modifying files that are part of your MATLAB installation here. Take a backup of the file before you make a change to it.
This may well mess up some aspects of publishing - it's turning off breakpoints for a reason.

Related

How to add parameters to a running process or exe by default?

Objective:
I'm trying to use a program called Texmod.exe to start another program (exe) with certain parameters.
Background:
Texmod is program that opens up another exe and extracts/replaces textures that are pulled up in the second program while it is running. I'm trying to start the second exe with the parameters: -AlwaysFocus -ControllerOffset=1 -SaveDataId=2. Starting the second exe with shortcuts/.bat that have these parameters in a command line DOES work. However, I would like to do this in conjunction with Texmod.
Complications:
I'm using Texmod v0.9 b which doesn't support starting an exe with command line parameters. Newer versions, such as the open source reboot known as uMod, does support but it doesn't replace textures as well and crashes often compared to the original version.
Texmod.exe must start the second exe directly. Texmod can't select a shortcut to start the exe. I've tried making Texmod start another exe/.bat that then starts the second desired exe with parameters but this causes Texmod not to function.
Methods I have thought about but not sure if they work or even possible:
Somehow forcing all processes started by Texmod.exe to start with certain parameters
Somehow force the desired exe to always start with certain parameters regardless of start method (via Texmod, shortcuts, .bat, etc)
Add parameters to the process started by the desired exe after it is already running
Obviously I'm open to any ideas. Is what I'm asking even possible? Sorry if it seems unclear or I sound irrational; my knowledge on this is limited.
Edit: #Toby Speight I'm not sure what you mean by an example of the code I'm having trouble with as I'm just wondering if it's possible to perform the scenario I described. This is where I got the Texmod program from (it's the oldest release texmod.zip - Original TexMod 0.9 beta). I've searched the internet for possible solutions but I've found very few so some of the methods I've tried are:
Used Texmod.exe to start a desktop shortcut with target: "directory to exe" -AlwaysFocus -ControllerOffset=1 -SaveDataId=2. The result was Texmod couldn't use the shortcut and just opened the exe without the parameters.
Used Texmod to start an exe named caller.exe which started the exe I desired using the method described here. In command.txt, described by the instructions, I put ""name of exe.exe" -AlwaysFocus -ControllerOffset=1 -SaveDataId=2." The result was the exe started with the parameters but Texmod failed to modify the textures because it was modifying textures pulled up by caller.exe instead.
Used Texmod to open a .bat file with the lines: ""name of exe.exe" -AlwaysFocus -ControllerOffset=1 -SaveDataId=2." The result was the same as attempt described in #2.
Edit2: I also stumbled on this page where someone else claims they managed to achieve what sounds like the objective I desire. However, I do not know enough about code to understand it. If someone could look over this to see if it would work or see if they can modify it to fit the arguments that I desire.
You can use windows registry to force Windows run another app when specific .exe is called. Let me show an example: i'm trying to use TexMod with Remember Me.
Required setup:
Create a copy of game .exe, place it near original with different name, eg RememberMe_copy.exe
Go to windows registry location HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options
create new key named as original .exe, in my case it's RememberMe.exe. Registry key looks like a folder.
In this key, create new string value named Debugger with full path to copy of .exe with required commandline args. For example: "C:\Program Files (x86)\Steam\steamapps\common\Remember Me\Binaries\Win32\RememberMe_copy.exe" -ReadPoolSizeFromIni. Note the path to .exe is quoted, commandline arguments are not. String value has type REG_SZ.
Now when you try to run anything called RememberMe.exe, Windows will instead run the RememberMe_copy.exe with specified parameters (and something else but we don't care). This feature is left in Windows for debugging purposes.
Finally, open TexMod, select RememberMe.exe. It will think it's running original file, but instead Windows will silently run another file with another parameters. As there is nothing else in between, TexMod is happy.
Why can't we use single file? Well, Windows will run original .exe instead of original .exe, then instead of it will run original .exe... causing infinite loop.

Matlab - Force to Retain Breakpoints

I wish to know, if there is a way to force Matlab to retain all historically placed breakpoints -red dots which enable code debugging- in the Matlab Editor/Debugger inside functions, classes, etc. from one session to another, for example, and without being deleted with clear all commands.
It would be easy for debugging huge pieces of software while changes are introduced, and because Matlab sometimes simply shut down because of internal errors.
Thanks fellows.
dbstop is the cleaner solution. Just insert it in the place you want the debugging to stop and this will not be removed until you edit or comment the line.
You need to save the breakpoints and reload them in next session. You can use dbstatus to get a structure that contains information about all breakpoints and save it into a file:
s = dbstatus('-completenames');
save FILENAME s
and later retrieve them using dbstop
load FILENAME
dbstop(s);
You can automate it by including it in startup.m and finish.m files (create them on default user path if they don't exist).

MATLAB doesn't find files I downloaded while the script is running

My problem is as described. My script downloads files through an external call to cmd (using the system function and then .NET to make keypresses). The issue is that when it tries to fopen these files I downloaded (filenames from a text file I write as I download), it doesn't find them, causing an error. When I run the script again after seeing it fail, it works but only up to the point where it's trying to download/call new files again, where it runs into the same problem.
Are new files downloaded during when a script is running somehow not visible to the search path? Because the folder is most definitely in my search path (seeing as it works outside of during-script downloads). It's not that it isn't getting the files fast enough either, cause they appear in my folder almost instantly, and I've tried a delay to allow for it to recognize it, but that didn't work either.
I'm not sure if it's important to note that the script calls an external function which tries to read the files from the .txt list I create in the main script.
Any ideas?
The script to download the files looks like so:
NET.addAssembly('System.Windows.Forms');
sendkey = #(strkey) System.Windows.Forms.SendKeys.SendWait(strkey);
system('start cygwinbatch.bat')
pause(.1)
sendkey(callStr1)
sendkey('{ENTER}')
pause(.1)
sendkey(callStr2)
sendkey('{ENTER}')
pause(.1)
sendkey('exit')
pause(2)
sendkey('{ENTER}')
But that is not the main reason I am asking: I am confident that the downloads are occurring when the script calls them, because I see them appearing in my folder as it called. I am more confused as to why MATLAB doesn't seem to know they are there while the script is running, and I have to stop it and run it again for it to recognize the ones I've downloaded already.
Thank you,
Aaron
The answer here is probably to run the 'rehash' function. Matlab does not look for new files while executing an operation, and in some environments misses new files even during interactive activity.
Running the rehash function forces Matlab to search through its full path and determine if there are any new files.
I've never tried to run rehash in the middle of an operation though. ...
My guess is that the MATLAB interpreter is trying to look ahead and is throwing errors based on a snapshot of what the filesystem looked like before the files were downloaded. Do you get different behavior if you run it one line at a time using F9? If that's the case then you may be able to prevent the interpreter from looking ahead by using eval().

MatLab - Undefined function or variable 'script'

I have a script, called TESTSCRIPT. It was running fine since I created it several hours ago, but now whenever I try to run it, either by pressing F5 or using the command prompt, I get the error message
Undefined function or variable 'TESTSCRIPT'
TESTSCRIPT is in fact a solution to another script file that had suffered the same consequence. I have read through many people's MatLab Forum posts, and I have tried many, if not all, the solutions given:
Checked, double checked, and triple checked the Matlab paths using path, which TESTSCRIPT, and pwd. All return the correct paths.
Changed file and function names so that they wouldn't match any function or file I don't know about within the MatLab paths.
Creating a new file, and copying the code. This provided a temporary solution, until now.
Commented out all but the declaration of two variables. Still get the same error message.
Changed computers. This didn't change anything.
The only thing that stood out when I did all these was when I typed which TESTSCRIPT and got <path>\MATLAB\TESTSCRIPT\TESTSCRIPT.m % Has no license available. I definitely do have a license, because I've been using it for the last 8-9 months without a problem.
I cannot put breakpoints within the code. When I try, a window pops up and says:
License Checkout failed.
License Manager Error -39
along with other stuff.
Scripts older than a week run fine when I hit F5. If I select a piece of code, within TESTSCRIPT, and run just that selection (by pressing F9), that runs without a problem.
My first thought was the file is corrupt, but then a new file would have worked, and this being the third time I've had to creat a new set of files, I'm confident it is not the case.
What is going on, and how do I solve this?
UPDATE
This seems to have resolved itself when I closed and opened MatLab. It does not explain why it has done this, but the problem seems to be solved.
Both dec2rad and pi are builtin functions, rename both variables to avoid the error.

Retrieve Variables/Accesing Variables in different Workspaces

I imported some data and them cleaned it up, there is a lot of data so this is quite time consuming.
I then wrote a scipt that uses these variables.
However when I went to run the script, it says that these varibles are not know. In the workspace editor is only shows variables declared in the script.
Q1.) Is there a way to get the original variables back?
Secondly as the clean up operation takes quite some time I don't want to have to import that data and clean in every time I run the M-file.
Q2.) So once I have the cleaned data how do I make these variables available to an M file (do I have to declare them as global or something like that?)
To be clear I tried to just debug the script rather than running it from the command window, I just wnat to get the base variables back now if possible!
ahem there was a errant clear used in the script that's why all the variables were disappearing.
A misplaced Clear or Clear all may be the problem. Similar thing happened to me once.