Jump to content

Welcome to DreamBot!

Download for Free

Supercharge Your Bots

Run unlimited bots today using DreamBot's Covert Mode and
stay more protected.

Upgrade Now
Frequently Asked Questions
  • Are you not able to open the client? Make sure you have Java 8 installed
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
OSRS Gambling

Interested in advertising your business? Reach out today!

Download the DreamBot client today!
slasso

How to Remote Debug Your Scripts

Recommended Posts

Hi everyone, my first tut!

 

This tutorial will teach you how to remotely connect to your dreambot scripts through Eclipse or IntelliJ to be able to pause and step through lines of code one at a time. For the most part, I will be using Eclipse. I don't use IntelliJ but I will go through the steps for it as well.

 

Let's get started.

 

I'm going to assume you have java set up properly to run java commands on a command line or terminal. check with a command like 'java -version'. You should see something like:

          java version "1.8.0_91"
         Java SE Runtime Environment (build 1.8.0_91-b14)

         Java HotSpot 64-Bit Server VM (build 25.91-b14, mixed mode)

 

If you don't see this then you need add JAVA_HOME/bin to your path. Here's brief summaries for this on Windows and Linux:

 

 

On Windows right click PC->propertoes->advanced system settings->environment variables. Add new variable named JAVA_HOME and path is location of your JDK, ex: 'C:\Program Files\Java\jdk1.8.0_73'. Edit the existing PATH variable and add a new entry '%JAVA_HOME%\bin'.

On Linux edit your ~/.bashrc and add JAVA_HOME and update PATH, export etc.. then 'source ~/.bashrc'

 

 

 

Now export your script-to-test.jar to your DreamBot\scripts directory like normal. Make sure the compiled jar matches your source code, i.e., don't edit your source after exporting the jar, it will mess up the lines and such when debugging.

 

We are going to open up a DreamBot client.jar through command line with additional flags for debugging. To do this open up a command prompt/terminal in your DreamBot\BotData directory.

Now run this command, 'java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=12345 -jar client.jar', as shown below:

 

WVpasN2.png

 

This will open up DreamBot and open up the port you specify to listen for a debugging program, notice the first line of the output "Listening for transport dt_socket at address: 12345".

 

We will connect to this now in Eclipse/IntelliJ.

 

Eclipse method:

 

 

  1. Right-click on the project you want to debug and have already exported the latest code into a jar. Click Debug As->Debug Configurations
  2.  
  3. On the left-hand side will be a list of different configurations. Find Remote Java Application and right-click->new
  4.  
  5. In 'Host' make keep it localhost, unless you have dreambot deployed on a remote machine or something, in which case use the hostname of that.
  6.  
  7. In 'Port' enter the port that the client.jar is listening on. In the example above it is 12345
  8.  
  9. Click Apply->Debug
  10.  
  11. Now to see that eclipse is actually doing something with our dreambot client, go to Window->Perspective->Open Perspective->Debug. We can now see a new box for Debug which has the client running.
  12.  

 vSsCYVU.pngbne867z.pngmdF50HG.pngJByEqfs.pngoXbQtfl.png

 

Now we're able to set breakpoints and run our scripts in DreamBot like normal.

  VqXll0C.png  W3tANz0.png

 

 

You're now connected to your script on debug mode! You can hover over any object to see it's value and fields it has, etc. Step over lines of code, anything. 

 

 

 

 

IntelliJ method:

 

 

  1. Click Run->Edit Configurations
  2. Click the + to add a new configuration and select 'Remote'.
  3. Name it anything you want.
  4. 'Select source using module's classpath' should be your scripts project that you exported the jar for.
  5. Change the port to the port you specified earlier. (12345 in my example)
  6. Click apply and ok.
  7. To set a breakpoint, click in the left margin of a line of code in your script.
  8. Click Run-> Debug 'your-debug-config-name'
  9. Go to DreamBot and start your script.
  10. Your breakpoints should now get triggered.

You're now connected to your script on debug mode! Step over lines of code, anything. 

 

 

 

Debug is a very powerful tool and any developer in Java should always use it.

Edited by slasso

Share this post


Link to post
Share on other sites

nice man

Thanks (:

 

I've never done this before, this is really cool. Does this allow the usage of Java Flight Control to monitor resource usage? If not I might make a tut on how to use it for scripts too ;)

I'm not sure. I've never used that before

Share this post


Link to post
Share on other sites

I fixed a typo in the command. The debug args have to be first before the -jar flag or it won't work.

 

java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=12345 -jar client.jar

Share this post


Link to post
Share on other sites

If you use IntelliJ (and probably for Eclipse too), you can take this further.
You can create a Debug Config that builds your script and launches DreamBot with remote debug, so the output gets piped directly to your IntelliJ console.

 

  1. Make an executable script to launch Dreambot in debug mode
    1. Open new text file
    2. Insert the remote debug command. I used the modern JDK argument: java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar client.jar
    3. Save as .cmd on Windows
    4. Place in Dreambot BotData directory
  2. Make new "Remote" run/debug configuration in IntelliJ
  3. Make sure your port matches the port from the remote debug command
  4. Add "Build Artifacts" to the "Before launch" section and select your script
  5. Add "Run External Tool", then add a new tool
    1. Under "Program", select the file you saved as .cmd

Now when you run that configuration the IntelliJ console is used for the debug output. It's much quicker to launch everything and immediately get debug feedback.

Share this post


Link to post
Share on other sites

If you use IntelliJ (and probably for Eclipse too), you can take this further.

You can create a Debug Config that builds your script and launches DreamBot with remote debug, so the output gets piped directly to your IntelliJ console.

 

  • Make an executable script to launch Dreambot in debug mode
    • Open new text file
    • Insert the remote debug command. I used the modern JDK argument: java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar client.jar
    • Save as .cmd on Windows
    • Place in Dreambot BotData directory
  • Make new "Remote" run/debug configuration in IntelliJ
  • Make sure your port matches the port from the remote debug command
  • Add "Build Artifacts" to the "Before launch" section and select your script
  • Add "Run External Tool", then add a new tool
    • Under "Program", select the file you saved as .cmd
Now when you run that configuration the IntelliJ console is used for the debug output. It's much quicker to launch everything and immediately get debug feedback.

On this note you can also do something really simple which saves a lot of typing when testing without building. Right click inside botData folder right click and hit create shortcut. In the option for typing in the shortcut you type in the command that would be entered in cmd. This will open cmd and start the client with remote debugging

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...