Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: How to step through and break point debug Starsetor  (Read 4530 times)

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
How to step through and break point debug Starsetor
« on: April 06, 2014, 07:34:48 AM »

I've seen the thread http://fractalsoftworks.com/forum/index.php?topic=3723.15 on debugging, but adding log lines to my code...

Nothing makes sense, and anyway, I used Netbeans and attached a debugger to the Starsector java process, altered the vmparams. It connects to the java VM debugger...and there are about two breakpoints related to EnergyWeaponShunt and a whole lot of nothing else.

Is there anyway to step through Starsector's mod code as it runs? I really need to see why this code is not running as intended.
Logged

TJJ

  • Admiral
  • *****
  • Posts: 1905
    • View Profile
Re: How to step through and break point debug Starsetor
« Reply #1 on: April 07, 2014, 01:11:25 PM »

I'm not particularly familiar with Netbeans, however I can show you how to do it in Eclipse if you like?
« Last Edit: April 07, 2014, 01:13:12 PM by TJJ »
Logged

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: How to step through and break point debug Starsetor
« Reply #2 on: April 07, 2014, 01:37:54 PM »

That would be sweet.
Logged

TJJ

  • Admiral
  • *****
  • Posts: 1905
    • View Profile
Re: How to step through and break point debug Starsetor
« Reply #3 on: April 07, 2014, 02:02:48 PM »

pm sent
Logged

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile
Re: How to step through and break point debug Starsetor
« Reply #4 on: April 07, 2014, 02:24:04 PM »

You've edited your vmparams/.bat file, right?

Specifically, you need to add the following somewhere in your arguments (not at the end of the line):

Code
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=51324 -Dorg.codehaus.janino.source_debugging.enable=true

The first enables debugging and tells Java what port your debugger should connect on. If you want the game to pause loading until the debugger is connected change suspend=n to suspend=y. That will let you ensure the debugger attachment is working.

The second part of the above line enables debugging for loose scripts, not just jarred code (that part might not be necessary, but I included it just in case debugging isn't enabled in the embedded Janino compiler...).

Once you have that added, you just add your breakpoints in Netbeans (click the line number, a pink shape should appear), compile your code (if it's a jar), launch Starsector, then go back in Netbeans and go to Debug/Attach Debugger. You'd need the following settings for the line I posted above:
Spoiler
[close]


Once the debugger is attached and the game hits your breakpoint, the game suspends and you can carefully step through your code in the IDE line-by-line and watch the variables change as it runs. There are special controls for this found under Debug (everything in the section that starts with Step Over). Step Into will enter a method and step through its code, Step Over just executes the current line (without stepping into a method if it's called in that line), Step Out runs the entire current method, Continue runs until the next breakpoint is hit.

If there's anything I missed, let me know. There's also a decent Netbeans guide if you're interested.
« Last Edit: April 07, 2014, 02:28:46 PM by LazyWizard »
Logged

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: How to step through and break point debug Starsetor
« Reply #5 on: April 07, 2014, 02:38:37 PM »

Thanks lazy! I'll try it out now.
Logged

Toxcity

  • Admiral
  • *****
  • Posts: 561
    • View Profile
Re: How to step through and break point debug Starsetor
« Reply #6 on: April 15, 2014, 05:54:14 PM »

Can you use these directions to debug with Eclipse?
Logged

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: How to step through and break point debug Starsetor
« Reply #7 on: April 15, 2014, 06:39:00 PM »

Can you use these directions to debug with Eclipse?

TJJ seems to be a eclipse user, try sending a PM to him. Although in theory it's all the same.
Logged

TJJ

  • Admiral
  • *****
  • Posts: 1905
    • View Profile
Re: How to step through and break point debug Starsetor
« Reply #8 on: April 15, 2014, 07:03:22 PM »

Can you use these directions to debug with Eclipse?

Yeah.

- create a new Eclipse (Java) project in your current Workspace
- Within the project create a linked folder that points to your starfarer folder
- open up starsector-core\starsector.bat and use it as a reference to setup your project's classpath by adding all the jars that it lists to the classpath (see green text below)
- add starsector-core as a source folder
- create a new run/debug configuration, set the "main class" to be com.fs.starfarer.StarfarerLauncher, and add all the VM arguments listed in the starsector.bat (see blue text below).
- launch the run/debug configuration, and you'll be able to debug everything that you've got source for, whether it's a precompiled library, or a runtime compiled janino class*.

*At the moment janino is set to include debug info, so you don't need the "-Dorg.codehaus.janino.source_debugging.enable=true" flag set. Though this might change in the future, so explicitly setting it won't do any harm.

Quote
..\jre\bin\java -Djava.library.path=native\windows -Xms512m -Xmx512m -Dcom.fs.starfarer.settings.paths.logs=. -Dcom.fs.starfarer.settings.paths.saves=saves -Dcom.fs.starfarer.settings.paths.screenshots=screenshots -Dcom.fs.starfarer.settings.paths.mods=mods -classpath janino.jar;commons-compiler.jar;commons-compiler-jdk.jar;starfarer.res.jar;starfarer.api.jar;starfarer_obf.jar;jogg-0.0.7.jar;jorbis-0.0.15.jar;json.jar;lwjgl.jar;lwjgl_util_applet.jar;jinput.jar;lwjgl_test.jar;log4j-1.2.9.jar;lwjgl_util.jar;fs.sound_obf.jar;fs.common_obf.jar;xstream-1.4.2.jar com.fs.starfarer.StarfarerLauncher
Logged

Toxcity

  • Admiral
  • *****
  • Posts: 561
    • View Profile
Re: How to step through and break point debug Starsetor
« Reply #9 on: April 15, 2014, 08:00:05 PM »

Logged