SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => Topic started by: kwilliams on July 14, 2021, 12:28:47 am

Title: Attach to Virtual Machine not working
Post by: kwilliams on July 14, 2021, 12:28:47 am
Hi,

I have a Scala project that I want to debug. When I select Debug -> Attach Debugger -> Attach to Java Virtual Machine, nothing happens. I expected a dialog to ask for remote debugging information like the port.
Title: Re: Attach to Virtual Machine not working
Post by: patrick on July 14, 2021, 02:33:10 pm
I'm assuming you've got the SBT project you mentioned in another post open.

It should pop up a modal dialog when you select that. And it looks like if there's an error before then, it should pop up a message box.  Very strange.

Can you still type in the editor window after that?  Is there any output in the "Build" tool window?  If you try it again, look in the status bar at the bottom left, is there any message there?

If you're on Linux, what window manager are you using?
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on July 20, 2021, 09:00:10 pm
Thanks for responding.

It turns out that I did not have my JDK configured in the SlickEdit project. So now, I get a pop-up that say: "could not find a 'tool.jar' for your configured JDK.".

I am using OpenJDK 11. Searching around, it sounds like OpenJdk may have moved things around a bit. The contents of tools.jar, rt.jar and a couple other have been moved to different jar files.

It sounds like Slickedit would need to update to account for this unless there is some way to tell it to look somewhere else.
Title: Re: Attach to Virtual Machine not working
Post by: patrick on July 21, 2021, 01:54:35 pm
Tools.jar got repackaged for Java 1.9 I think.  The debugger code should account for that, and it works for me on OpenJDK 11.0.11.   I suspect the version comparison, it's got a lot of cases from dealing with the version conventions of different JDK providers over the years, so there may be some corner case it's failing on that I'm not seeing.

What's the output you get for "java --version" on your system?  And if you go into the Tools -> Options dialog, and go to Languages -> Application Languages -> Java -> Compiler Properties, what's in the "Compiler Name" pulldown?
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on July 21, 2021, 05:07:42 pm
My Java version is Amazon Corretto-11.0.6 and compiler name is JDK 11.0.6
Title: Re: Attach to Virtual Machine not working
Post by: patrick on July 21, 2021, 06:31:35 pm
I can reproduce with JDK as well.  Taking a look at it, it should be hot-fixable.
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on July 21, 2021, 08:04:16 pm
Awesome!

thanks for looking into this.
Title: Re: Attach to Virtual Machine not working
Post by: patrick on July 23, 2021, 02:16:58 pm
The fix for this will be in the next 25.0.2 hotfix. 
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on August 27, 2021, 06:35:51 pm
I applied the hotfix, but now I get “Error waiting for pydbgp connection: Socket timed out” (which is weird because I tried to attach to a java jvm and pydbg is a Python debugger).

It’s waiting for a connection on 127.0.0.1:55151.

I using the following menu: “Debug->Attach-Debugger->Attach to Java Virtual Machine”

I confirmed that I could attach to the VM with the JDB command line.

Am I doing it wrong?

Here is the text of the dbg.xml file:
<debug>
<logging v="0"/>
<setJDWPEnvironment v="0"/>
<jdwpHost v="127.0.0.1"/>
<jdwpPort v="5006"/>
<idePort v="55151"/>
<workingDir v="C:\Code\MI\7.5Exp\EnGen\Client\Library\"/>
</debug>

In subsequent attempts the attach dialog would not come up, even after restart.

btw, I'm running Windows 10.

Thank you.

Kurt

Title: Re: Attach to Virtual Machine not working
Post by: patrick on August 27, 2021, 07:53:57 pm
Hmm, the "pydbgp" reference is a UI mistake from sharing some of the setup UI, it's using the right protocol underneath.

Nothing looks obviously wrong with the dbg.xml.   With a timeout like that, it sounds like something that could have prevented the debuggee from connecting back to our debugger.  If the debuggee had died, we would pick up on that before a full timeout.

We can enable some debug logging.  Restart SlickEdit, go to the SlickEdit command line and type in "set-var def-debug-logging 2", and then try to attach the debugger.  This will produce some output in the Build window.  (and if it gets far enough, also some output will go into your configuration directory under logs/debug.log.  On windows, the default configuration directory is under Documents\My SlickEdit Config.   You can also see it in the Help -> About dialog).

Post the output from those two places.  And afterwards, run "set-var def-debug-logging 0", it's a persistent setting and can build up a large set of logs pretty fast.

It probably doesn't matter, but what version of SBT are you using?
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on August 27, 2021, 08:10:00 pm
Thanks for getting back to me.

I'm using SBT 1.4.7

I set the logging variable but I'm not seeing logs (I saw user.cfg.xml update with the set-var command).

I currently can't get the attach dialog to come up. Maybe I need to re-install?

<edit>
I re-installed but the "Attach to Java Virtual Machine" dialog does not come up when I select it. Others do (like "Debug Java Program")
Title: Re: Attach to Virtual Machine not working
Post by: patrick on August 27, 2021, 08:22:22 pm
In theory, you should either get an error dialog at this point, or the attach dialog, so I'm not sure why you don't get anything.  It does sound odd, if you go to the SlickEdit command line and just run scala-attach, do you get a dialog? 

You shouldn't need to re-install.  The install directory is read-only, only things in the configuration directory gets changed.  You can try starting with a clean config if you want to rule out a configuration problem.  Go to a cmd.exe or powershell prompt, and start SlickEdit like this:  c:\Program Files\SlickEdit Pro 2020\win\vs.exe -sc %TEMP%\seconfig     And you can open up your project and see if you can attach then.

Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on August 27, 2021, 08:31:49 pm
scala-attach didn't show a dialog either.

running with a clean config gave me the old "can't find tools.jar" so I had to apply the hotfix. Then I was back to no attach dialog.

also nothing is logged when I use 'set-var def_debug_logging 2' as far as I can tell.
Title: Re: Attach to Virtual Machine not working
Post by: patrick on August 27, 2021, 09:13:21 pm
So not even any output in the Build window?

I'll trace through the codepath again, maybe I missed some way for you to get nothing.
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on August 27, 2021, 09:22:26 pm
nope. nothing. I tried again just to be sure. the build window was empty.

there doesn't seem to be any indication that the set-var command did anything (other than what showed up the the user.cfg.xml). Is there a get?

I tried some other debug related actions to see if any of those would induce a log message but so far nothing.
Title: Re: Attach to Virtual Machine not working
Post by: patrick on August 30, 2021, 12:40:46 pm
If you type in "set-var def-debug-logging" like that without any value, it will prompt for a value and show the current value. 

It may be just be failing too soon for anything to be logged, so don't spend much time trying to get something out of it.  I'm still looking to see if there's some path for it to fail without showing a dialog when scala-attach runs. 
Title: Re: Attach to Virtual Machine not working
Post by: patrick on August 30, 2021, 01:11:09 pm
I think I found a place where getting an error when looking at the configured java compilers can cause a silent failure.

Save the attached scala.e file and then go to Macro -> Load Module and load it.  And then try running scala-attach at the command line again, and see if you get a message box with a message and error code.
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on August 30, 2021, 05:17:59 pm
when I load the module, I get: "Expecting procedure name - identifier not found - import may be required".

I tried scala-attach anyway but still no pop-up or message in build-window.

confirmed the the def-debug-looging var is getting set.
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on August 30, 2021, 05:43:20 pm
It looks like the error is on line 1312. the call to 'CheckLatestJDK'?
Title: Re: Attach to Virtual Machine not working
Post by: patrick on August 30, 2021, 06:04:48 pm
That's odd, is the latest 25.0.2 hotfix still loaded?  That function didn't exist in base 25.0.2, but it was added in the last hotfix with the version fix.  You can look in Help -> About and see what hotfix is applied.
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on August 30, 2021, 06:08:22 pm
according to help --> about, I have hotifx_se2502_3_cumulative.zip (revision 3)
Title: Re: Attach to Virtual Machine not working
Post by: patrick on August 30, 2021, 07:30:21 pm
I made the mistake of trying it on a build of that hotfix branch rather than a 25.0.2 + hotfix package, the loading include path is a little different, which seems to be the problem here.

Download the attached .ex file, and put it in the same directory you put the scala.e you downloaded earlier.  And then try the load command again.  Let me know if it still doesn't load.   
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on August 30, 2021, 08:21:42 pm
Ok. I got a little farther. Upon module load, I get a "Slick-C Error" pop-up that says "Invalid pointer argument, file=Subject.ex offset=430" with a call-stack (attached).

If I ignore that and try a scala-attach, I get: "refactor error? -7500"
Title: Re: Attach to Virtual Machine not working
Post by: patrick on August 30, 2021, 08:59:06 pm
Ok, for the purposes of debugging, we can ignore the pointer exception.  I'll address that in the fix that I have to do anyway because of the missing error dialog.  It can only occur when manually loading scala.e when the editor has already loaded a scala project or file.  Go ahead and restart the editor so we don't have to worry about fallout from that. 

The error code is strange, because it indicates we asked for information on an invalid JDK name.  But the name we're asking for is the one it returns as the active configuration earlier.  If you look in Tools -> Options -> Languages -> Application Languages -> Java -> Compiler Properties, does your JDK show up in the list, and does the information look right?

In your configuration directory ($HOME/.slickedit/25.0.2 for Linux, "My Documents\My SlickEdit Config\25.0.2" on windows), can you get the users.cfg.xml and compilers.xml file, and post them?
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on August 30, 2021, 09:38:11 pm
Progress:
The compiler was not set, I thought I had it set before but maybe it got reset to defaults somehow?. That was part of the problem. I'm still getting the connection timeout error but lots of output in the build window.

attached are the compilers.xml, user.cfg.xml and a the build-window-output when the connection timeout happens.

Also, my trial expires tomorrow. That last thing I need working for us to migrate from VS-code to SlickEdit is the debugger. Is there any way to extend the trial? Otherwise I might be able to get approval to buy a single license for now.

Thanks again.

Kurt
Title: Re: Attach to Virtual Machine not working
Post by: patrick on August 30, 2021, 11:16:54 pm
I can't answer the trial question, but I forwarded it to someone who can.

I've only started looking through the Build window log.  Can you check to see if there's a debug.log in the configuration directory, under logs?  Gotten far enough this time there might be a log there this time.  And if not, that narrows the possibilities. 
Title: Re: Attach to Virtual Machine not working
Post by: SlickEdit Support on August 31, 2021, 12:05:15 am
PM sent to your Inbox Kurt.

Best,
SlickEdit Support
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on August 31, 2021, 12:37:08 am
Thanks!

see debug.log attached
Title: Re: Attach to Virtual Machine not working
Post by: patrick on August 31, 2021, 01:38:24 pm
Thanks for the logs.  I got enough information from the logs so that I can reproduce it most of the time.  Very odd, the debugging backend is attached to the JVM running scala, but something is going wrong where it never connects to the "UI" part of debugging that we host, so it times out.  And there seems to be a bad socket handle mixed in there somewhere.

I'll update once I have some sort of fix you can apply.
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on August 31, 2021, 04:03:01 pm
that's good. non-reproducable issues are the worst. I think I tried this with the firewall disabled just in case.

Let me know if you need anything from me.

Kurt
Title: Re: Attach to Virtual Machine not working
Post by: patrick on September 07, 2021, 02:56:20 pm
Just a quick update, I've found and fixed the problem with the attach.  I did have to make some changes to a protocol used by multiple debuggers, so I've still got some testing to finish up. Once that's done, there will be a jar file and a DLL file to update to apply the fix.
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on September 07, 2021, 04:28:57 pm
Yes!

Thank you!

Looking forward to trying it out
Title: Re: Attach to Virtual Machine not working
Post by: SlickEdit Support on September 08, 2021, 08:58:41 pm
PM sent.

SlickEdit Support
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on September 08, 2021, 11:09:03 pm
I got the files and installed them. I was able to attach (i seems like I have to restart slick-edit for it to attach again). I got a bunch of failed attach attempts due to socket timeouts.

Once I attach, I put a breakpoint in the code and it does not get hit.
Title: Re: Attach to Virtual Machine not working
Post by: patrick on September 09, 2021, 12:28:41 pm
Hmm.  Having to restart to attach again without timeouts is strange, unless whatever is causing the breakpoint to be missed is leaving the listener in a bad state.

I think the only thing to do is reproduce with the logging on.  Go ahead and restart SlickEdit if you haven't already, go to the SlickEdit command prompt and type in "set-var def-debug-logging 1" and then attach and do what you did before.  After it fails to hit the breakpoint, wait at least 30 seconds (to outlive any timeouts that might log extra information), and then Debug -> Stop Debugging.  There are two logs.  One is the output in the build window, which you can copy and paste out to a file.  The other will be under My Documents\My SlickEdit Config\25.0.2\logs\debug.log.   I don't think they'll exceed the attachment size limit for the forum, but it might not hurt to zip them up before posting.

Afterwards "set-var def-debug-logging 0" again, because it's a persistent over restarts, and can eat up drive space quickly.
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on September 10, 2021, 07:59:04 pm
The good new it I think the failure to attach was user error. I think I was running my app without the debug settings so the JVM was not listening for a debugger.

Attached are my logs after setting a breakpoint.

Title: Re: Attach to Virtual Machine not working
Post by: patrick on September 10, 2021, 08:32:36 pm
Taking a look.  The output from the build window looks short - did it get cut off?  Or maybe the rest of the output was buffered until the debugger ended, and didn't make it to the build window until the debugger ended.

From the debug.log, I can see some of the set breakpoints commands timing out waiting for a response.  Sort of, it looks like we got "breakpoint set" responses about 2sec after we asked for them after we had moved on, so maybe they got set, hard to tell without the rest of the build window log.  I am not sure why it would take that long to set a breakpoint, I need to look at that code next to see what could block that. 
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on September 10, 2021, 08:59:39 pm
I thought I selected all in that window, I'll try it again and see if I get a better log in the build window.
Title: Re: Attach to Virtual Machine not working
Post by: patrick on September 10, 2021, 10:51:46 pm
No problem.  I should have remembered to mentioned that the debugger needs to be stopped before collecting the log from the Build window.  Both the backend and the Build window itself do enough buffering where a surprising amount of the logs can be in limbo until the backend quits.

Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on September 13, 2021, 09:26:36 pm
ok. I'll be in the office again tomorrow. I'll test again and stop the debugger first.
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on September 14, 2021, 05:38:45 pm
Ok.

I got some new logs attached. The reason the last one was so short is that there is a weird character after the "command:" traces that appears to be interpreted as end of file or end of string (null?). I had to edit those out in the build window and then I could copy and paste it all.

Also, I am able to attach every time but it takes the full 30 second "waiting for pydgb count down". Not a major issue on my end but I thought it might be interesting.

Title: Re: Attach to Virtual Machine not working
Post by: patrick on September 14, 2021, 08:43:22 pm
That makes sense.  I was dealing with that log entirely in SlickEdit, so I didn't run into that.  I should  remap that char in the logging. I just need to know the terminator char is there, I don't need to see it.

Thanks for getting the logs, it answer a lot of my questions from the debug.log.  The breakpoints are being deferred as if the JVM hadn't loaded the classes the breakpoints are set in yet.  Which isn't impossible, I can't say how likely that is for your target program.  But I don't see the breakpoints getting resolved as the program runs, so I'm suspicious that the breakpoints are being incorrectly deferred.  Or we've missed the load events.   So I don't know what's up yet, but this gives me a couple areas of the code to look at.


Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on September 14, 2021, 08:48:07 pm
Interesting. We do some late loading of classes that are defined in plugins, but the place where I put the breakpoint was in a core piece of the program that I'm certain is loaded (or else it wouldn't be working).
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on September 14, 2021, 08:49:58 pm
Also maybe of note is that we do not do a fat-jar. there are many jars that comprise the program and we use the jar file directories in the class-path
Title: Re: Attach to Virtual Machine not working
Post by: patrick on September 15, 2021, 05:12:47 pm
I haven't found anything wrong with the deferral code.  I mixed it up, trying debugging some different programs on Windows, using the different JDKs, but wasn't able to reproduce it either.

So I've had to settle on adding some more logging in a couple of places.  I'm only logging extra information for the files you had breakpoints set in before, otherwise we'd be swamped.  So use the same breakpoints as before if you can, doesn't matter if they're on the same lines or not, just that they're in the same .scala files.  And I fixed the logging so there won't be nulls in the Build window output anymore, so you won't have to do any extra steps with that output.   So:

1) Re-download the se-scala-debugger-assembly-1.0.0.jar from the link you got the updated one from, and copy it over the one in the install directory under resource/tools/scaladbgp
2) set def-debug-logging to 1 again.
3) Reproduce like you did before, with breakpoints in the same files, attaching, and waiting at least 30 seconds before ending the debug session.
4) We only need the output from the Build window, don't need the debug.log anymore.

This should give me the only bit of information I'm missing from the previous logs to decide how the deferral bug is happening.

Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on September 16, 2021, 12:39:08 am
sounds good. I'll grab the jar and run another test in the morning.
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on September 16, 2021, 07:35:07 pm
Here are the new logs. Thanks for fixing the nulls in the logging. That made it a lot easier.
Title: Re: Attach to Virtual Machine not working
Post by: patrick on September 16, 2021, 08:50:07 pm
That did it, I can reproduce it with the information from that log.  I've followed it enough to determine it's not going to be a quick fix confined to the backend, so there won't be a updated download today at least.

Thanks for sending in those logs.

Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on September 16, 2021, 09:09:55 pm
awesome!
I'll wait to here from you then.
Thanks!
Title: Re: Attach to Virtual Machine not working
Post by: patrick on September 17, 2021, 07:54:08 pm
Ok, I've updated the vsdebug.dll and the jar file.  You can download and re-apply those, and it should be able to hit the breakpoints.

Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on September 20, 2021, 04:49:30 pm
Ok. I'll give it a try.
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on September 21, 2021, 09:48:12 pm
Ok, now when I attempt to place a breakpoint, I get: "Error enabling breakpoint: DBGP error: Parse error in command".

When I click OK in the error pop-up, my breakpoint is disabled.

I've attached the usual logs.
Title: Re: Attach to Virtual Machine not working
Post by: patrick on September 23, 2021, 01:28:22 pm
That's unexpected, it means we don't have a package + class associated with the breakpoint locations.   We use the tagging information to fill that out.  I do need to fix it to give a better error for this before the debugger tries to attach, having a package + class (or just class for the main module with no package statement) is required to set the breakpoints reliably for Scala.

For that project, in standard edit mode (not the debugger) run "toggle-breakpoints" in the SlickEdit command line to bring up the breakpoints window.  Are there any breakpoints that have empty "Class" columns? If you use F9 to get rid of and then re-add the breakpoint with an empty Class column at the same location, does the class field get populated?   If you go to that location in the editor window, does the "Current context" widget that's probably at the top of your editor (unless you removed it via View -> Toolbars) show any package + class, or is it blank? 

If the tagging really isn't marking a class/package for that location, we'll need to debug the tagging to see why that is, either by getting a high level idea of where the breakpoints are set (ie, "in the body of a Seq.map that's in a object method"), or getting some sort of example that can reproduce a place where a breakpoint can't be set. 
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on September 23, 2021, 05:38:27 pm
yep, the class is empty for any breakpoints I set in that file. breakpoints in another file in the project seem to fill in the class.
Title: Re: Attach to Virtual Machine not working
Post by: patrick on September 23, 2021, 06:37:24 pm
Are these breakpoints in a method, or on a property initialization in a class or object somewhere?  Or somewhere else I'm not considering?

For the files I have tried so far, the only place I can get a blank Class for the breakpoint is trying to set one outside of a object/class/method body.  There may be a error parsing your file that's leaving us with no class/package information for that line, but I can't see that without an example that reproduces it.  That's why I'm trying to get a general idea of what sort of Scala statements are around your breakpoint lines. 

One other way to narrow it down would be to delete pieces of the code before the breakpoint in one of the problem files, take out whole vars or methods at a time.  After each one, use F9 to clear and re-set the breakpoint.  If it comes back with the Class field populated, than the parser is likely having problems with the last thing you deleted, and then we can figure out if you can PM that snippet or a (sanitized version with identifier names changed) to me so I can try to track down the problem from there.
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on September 23, 2021, 07:06:27 pm
they were in a try block inside a future.

it looked a little like this:
Future { blocking { try { <breakpoints in here> } catch {...} } }
Title: Re: Attach to Virtual Machine not working
Post by: patrick on September 23, 2021, 08:02:57 pm
Ok.  So if I do a skeleton of that layout inside a method like the following, I it works, so I think we're parsing the overall structure correctly.  Here's the actual snippet I put in an existing function:
Code: [Select]
val f = Future { blocking {
                try {
                    do_something()
                } catch {
                    case Bad() => ()
                }
            } }

Messing around with adding bad syntax to this to this, I can get it to fail to set a breakpoint either by putting bad syntax in the body of the try, or in the body of the catch.  So in this case is is possible code coming after the breakpoint can cause it to fail the parse, if we fail in the catch body.

So more blind divide and conquer - remove the body of the catch block, does the breakpoint resolve a class when  you toggle it then?  If so, put it back, and remove catch clauses until you get to clause that changes the behavior.  And then, it's either the destructuring in the catch clause, or something in the body of the clause, and we can go from there.

If clearing the catch clause doesn't make it go away, start removing statements in the try body, before the breakpoint until the breakpoint can resolve, and we can drill down into the last statement you deleted before it started working.
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on September 23, 2021, 08:43:05 pm
Ok. I'll try that and see what I find. It may take me a bit. I have my hair on fire right now with a high priority task.

More to follow.
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on September 30, 2021, 07:27:19 pm
Just got back in to test this and discovered that my trial expired :(
Title: Re: Attach to Virtual Machine not working
Post by: SlickEdit Support on October 01, 2021, 01:44:11 pm
New trial license on the way; check your Inbox :)

Best,
SlickEdit Support
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on October 06, 2021, 07:39:19 pm
Got it. Thanks!

I tried putting breakpoints in some different files that did not have as much syntactical complexity. I can't set a breakpoint anywhere. even in a simple method. I get the same "parse error in command" everywhere.

I also noticed that the application becomes unresponsive as if it is at a breakpoint.

Is this a package/scope issue? The packages do not match the file paths for this project.

Update: Somehow I got it to break. It made me locate the file I had put the breakpoint in even though the file was open in the editor and the breakpoint was shown.  The editor seemed out of sync with the debugger though because I deleted all breakpoints. I think it is because it is really slow.

I was able to step through code but it was REALLY slow and unresponsive and I could not view any variables (possibly because they were defined outside of the project in another jar file?).

I could only get it to break again sporadically.

Disabling a breakpoint gave me the error message: "Index of debugger item is out of range or invalid"

sorry for the data-dump.
Title: Re: Attach to Virtual Machine not working
Post by: patrick on October 08, 2021, 01:51:59 pm
That does sound strange.  The package/filesystem mismatch shouldn't be a problem, with the exception that it's probably the reason you were prompted for the file location.  That is a UI bug that needs to be fixed, it's essentially using the method we use with Java, where the local path will match up with packages.   But the backend knows the path to the source won't match the package path.  (that's also the reason it needs a valid package attached to a breakpoint - without that, we can pick the wrong class for breakpoints if there are several classes with the same name in different packages).

I'm not sure why it would be slow for steps.  Most of the data we fetch on breakpoints is the stack frames, so it might depend either the depth or number of locals.  The number of threads shouldn't matter unless we're pulling whole stack unnecessarily, but I'll double check that.  I'll have to test this out with some extremes and see if something is slowing down in a non-linear way that could explain the speed.

My worry is that the slowness is the reason you had the program stopped while the SlickEdit UI didn't show it as being stopped - something timed out, and maybe got the two pieces out of sync, so I want to figure out the slow behavior.  This may also explain the missing variables if we've timed out walking the stack and querying locals.   I think it's a coincidence that the missing variables were defined in another jar - at the JVM/JDI level the source of a class isn't a distinguished, and would look the same to us as any other. 

That still leaves the parsing problem that makes it so we can't resolve breakpoints at certain points in your source.  Unless I find an example of that happening, the only thing you can do on your end is some of the test edits I suggested earlier to try to narrow down what sort of statement or declaration.

So for now I'll look and see if I can reproduce the slowness.  At this point, it sounds like it was chaotic and slow enough for you to get it to stop, where I won't get a log of that for now, unless I get stumped on the performance.

Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on October 11, 2021, 05:41:31 pm
Thanks Patrick.

I will try to create a small example program and experiment with some of the code patterns we use to see if I can break without the slowness so I can see better what is happening.

I'm wondering if project size has anything to do with the slowness. Our projects are pretty big. Our total Scala code size is 2-3 million loc. The project I was trying to debug is smaller but still pretty big.
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on October 12, 2021, 07:41:09 pm
I created a simple project to test with. I attached the scala source for it. I was able to set breakpoints and step through code with some weird behavior but it basically worked so maybe performance was the issue there. Below is some notes on what I found.

Breakpoints behave strangely. Breakpoints that are set before you attach sometimes do not trigger. removing them produced some strange behavior, the breakpoint would move a few lines down instead of going away. removing those would also jump around. Deleting all breakpoints and creating them after attach seems to work.

if you are running sbt in the build window, the attach command injects commands into the sbt context. this fails and you have to exit sbt. This is not too much of a problem if you're aware of it. I can run SBT from a terminal window.

If you step into a method, the IDE asks you to locate the file, which is perfect. If you cancel this, you must step out or it will keep asking

Breaking on line 27 of the attached file, I see the following:
In the Autos window:
   local variable i shows its value
        local variable stuff2 shows its contents
   Thread shows **DBGP error: Error evaluating code**

In the watches window, several times I got:
Name| Value
Error | **Thread has no stack frames**

"Add watch" in the context menu did nothing. If I try to edit the "Error" item to watch one of my local variables, I get "Error querying watch: Index of debugger item is out of range or invalid"

The last time I tried debugging I was able to watch everything defined in the for loop (which compiles to an anonymous function) but not outside of it.

I'm not sure what made Watch start working. I played with it several times and I only got it working the last one.

Hope that helps.
Title: Re: Attach to Virtual Machine not working
Post by: patrick on October 13, 2021, 05:24:17 pm
I'm looking at it.  I've found what looks like is the root cause of the unpredictable behavior.  I've only got a partial fix implemented right now, and more testing to do.  But what I have has been enough to let me run your example through SBT without any breakpoints being missed, or having missing locals or missing stack frame messages.  I've got more work to do on the fix, and then retest with large amounts of threads, classes and stack frames to confirm it's still not slow for those cases.  And chase down some related things, like why toggle-breakpoints sometimes is disabled while the debugger is active.

So I expect I'll have something for you tomorrow, and what I'll probably do is just provide it as a new installer that is 25.0.2 + these fixes.  This will let you install this version to a different location, so we don't have to keep changing your main install.
Title: Re: Attach to Virtual Machine not working
Post by: kwilliams on October 13, 2021, 05:37:22 pm
Awesome!

I'll wait to hear from you.