Some Debug Tricks

 Debugging can be really boring, expecially when you have no clue on what goes wrong, but on the bright side, that's how software engineer gains experience. It's also very fun to explore some cool commands from Devops folks. One thing I learned is remote debugging, which is really cool as long as info sec people don't yell at you.

Remote Debugging can be in AWS environment, here is some commands I wrote down.

aws ssm start-session --target xxxxxxxxxx --document-name AWS-StartPortForwardingSession --parameters '{"portNumber":["5005"],"localPortNumber":["5005"]}'

add -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 as VM argument in the java -jar command, then app will listen 5005 and wait for the handshake

Start to run a remote JVM configuration on IntelliJ, just need to make sure hostname(I also test with 2 PC under same WIFI, just need local ip) is correct. Now we can put a debugger in the source code and start debugging.

Here is something I found in local testing. Seeing a maven error "no main manifest attribute, in target/xxxxxxxx.jar", and just need to run "mvn package spring-boot:repackage

Changed properties file and recreated jar with command "jar cvfM0 xxx.jar *"

Another helpful skill is to analyze stack trace with IntelliJ, this way we can identify issue more effectively.

This debugging session is all about keystore, so I would like to also keep that in the book.

we use a keystore and a truststore when our application needs to communicate over SSL/TLSA Java keystore stores private key entries, certificates with public keys or just secret keys that we may use for various cryptographic purposes. It stores each by an alias for ease of lookup. we'll use a keystore when we are a server and want to use HTTPS. In Java, we use it to trust the third party we're about to communicate with.


For debugging another repo in the current project, click add maven projects and select the pom file of the repo, then restart in debug mode.


For Nginx, turn on rewrite log and set error log to debug, add_header to verify variable, use map to manipulate string like

map $host $tmpvalue {

  ~^([a-z]+).([a-z]+).([a-z]+).([a-z]+)    $3_$2;

  default 'env_dev';

}

Comments