How to debug System Service on AOSP? - java

I wrote a simple system service that exposes the port 8545 on the localhost, but when I try to see if it runs, there is no open port.
Is there any way I can debug my System Service and/or gain insight into the logs?

Ok I found an answer:
Just before the phone is booting you need to execute in the terminal adb logcat, once it boots it should show the logs.
But because there are so many logs you should pipe it into less, then a vim instance is started with all the logs:
adb logcat | less

Related

JDB doesn't work when attaching to a running Android process

I want to attach debugger to running android application on a physical device connected through USB.
The device is rooted using magisk. The ro.debuggable property also set to 1 using resetprop to make all apps debuggable.
For example, the app will be calculator (com.android.calculator2).
The exact steps I did:
adb kill-server
Make sure to restart the adb server.
adb devices Start the server again and make sure the device is authorized.
Run the app (calculator in my example).
adb shell ps | grep calculator Find the app ID.
u0_a88 4445 16282 4193244 133532 0 0 S com.android.calculator2
The app ID is 4445.
adb jdwp | grep 4445 Make sure the app id is in the debuggable applications list.
Output: 4445. So the app is debuggable.
adb forward tcp:7777 jdwp:4445 Forward 7777 local tcp port to jdwp.
jdb -attach localhost:7777 Connect JDB to the port.
And here is the problem. At the last step nothing happens. JDB doesn't exit nor connect, also it doesn't output anything on any input command.
I also tried Android Studio. I tried two options. Manually add configuration to connect to remote JVM and use Attach Debugger to Android Process option.
The first option (connect to remote JVM configuration) doesn't work. I used this command line flags: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:7777. Port forwarding is done the same way. Android Studio as well does not connect nor exit or print error. Just nothing.
But the Attach Debugger to Android Process option works great. It successfully connects to the app and I can debug it and set breakpoints as expected.
I also want to mention that I used am set-debug-app command before to make the app wait for the debugger to connect before start. When either jdb from command line or Android Studio remote connect to JVM option is used, the app doesn't resume, so it seems like Android doesn't see the debugger at all. But when I connect the debugger via Attach Debugger to Android Process, the app resumes after attaching the debugger as expected.
Why JDB does not attach to the app while Android Studio does via option Attach Debugger to Android Process?
What I do wrong?
This happens if you also have Android Studio running. Studio monitors all debuggable process via track-jdwp and redirect the jdwp traffic to itself to keep tabs on the app lifecycle (via DDMS).
Close Android Studio and try the same jdb command again.

Intellij IDEA getting remote logs while debugging

On my project I have several QA environments, and quite frequently need to debug it. I'm using 'Remote JVM Debug' and it works fine, but also I want to see logs. I already configured bash script to run tailf over SSH and write it to local file and in debug configuration define local file to see it in log tab of Debug view. But now I'm running these scripts manually and then running debug, and after dubug session I need to stop tailf and disconnect SSH. If I put this scripts to 'Before launch' section, it will wait until this scripts will be completed, and wont start debug itself. I know that I can define run this scripts in background, but I want them to disconnect and terminate when I'm stopping debugging. Is there some solution for this?

Attaching a remote debug to tanuki service wrapper application

I am attempting to configure an application for remote debugging. I am attempting to use the instructions under https://wrapper.tanukisoftware.com/doc/english/qna-eclipse-remote.html and have added the following lines to my wrapper.conf
wrapper.java.additional.16=-Xdebug
wrapper.java.additional.17=-Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y
When I start my application using console console the application does not freeze with the following:
Listening for transport dt_socket at address: 8001
instead it carries on running and I cannot connect to it. Can anyone advise what settings I may be missing in order to allow the application to be remotely debugged.
One of the earlier configuration number was commented out
#wrapper.java.additional.13
This appears to mean that 14,15,16,17 were also ignored. I re-numbered these and can now debug.

How to figure out what port my application is using from inside Eclipse?

I am trying to write a program that will interface with my bank using OFX4J (Java implementation of OFX). Since I am getting an error, I want to see what exactly I am sending them that is generating the error. I downloaded the Eclipse Web Tools zip, installed it, and opened the TCP/IP monitor, but when I run the program it doesn't pick up anything. I assume this is because it isn't listening to the right port.
How do I see what port my application is using?
in Linux / MacOS, you can do it from terminal: netstat -vatp tcp | grep LISTEN. If you want to actually figure out some ports - just put out breakpoint into a constructor of java.net.Socket#Socket(java.lang.String, int) or java.net.ServerSocket#ServerSocket(int, int, java.net.InetAddress) and start up the application again in debug mode.

Play activator debug gets terminated on trying to remote debug from eclipse

I am new to play framework. I have an existing play application. I am supposed to understand it and make enhancements. So I am running the application on my windows 7 machine. It runs fine. On using debug(activator -jvm-debug), the jvm starts listening on default port 9999. Till this point everything is fine. When I start debugging it as a remote java application from my eclipse, the process listening on the port 9999 gets terminated. I have been monitoring the activity on Windows Resource Monitor. I have no clue where to check for the issue. Any help will be greatly appreciated
Thank you
The common things that you can check for a generic situation like
Message: “Failed to connect to remote VM. Connection Refused”
1) Have you setup the remote VM to accept connections?
java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=10000,suspend‌​=n yourServer
2) Is there a firewall in the way? Are you specifying the correct host / port?

Categories

Resources