Android Eclipse Debugging: Getting Intermediate Values - android

Is there any way to get the eclipse debugger to report the intermediate return values of the functional subterms of a complex android expression without declaring variables for every subterm?
For example, in the following code I would like to know the return values of each function (getPaddingRight, getPaddingLeft etc.):
if (tview.getPaint().measureText(q_text.toString(<=tview.getWidth()-tview.getPaddingRight()-tview.getPaddingLeft()){
//take actions
}
Edit: if you mouse over the q_text or tview you get the properties for that object, but not the return value of the function. You can just look up the value for getWidth for example by looking at the mMeasuredWidth property of the tview object, but I'm wondering if there is a general solution for the return value of any function.

I finally found an easy way to do this:
Go to eclipse debug view (Widow->Open Perspective->Debug)
Click on the expressions tab (Top right mini-widow, 1 of 3 tabs Variables, Breakpoints, Expressions)
Enter the value of your function or variable or whatever, click on it and the resulting expression will be displayed.
Note: If the tab "Expressions" is not in the upper right window then right click on one of the variabls in the "Variables" tab and click on the "Watch" menu entry and the "Expressions" tab will appear.
Using Helios Service Release 2

Related

is there any way to conditional Debugging in android studio

Is there any way to have conditional Debug in android studio?
for example I wanna go to debug mode when a specific variable value is.
for example:
for(MyClass myclass: ClassList){
String title = myclass.gettitle(); // this is where break point is
}
Before that I do not need the debug mode. I just wanna examine the app on that exact value. for example when title="KickBoxing" in this case I should check the variable value and if it is not my required value I should press F9 to go to next value. maybe this takes 50 times to get to my desired value.
It is possible to add a condition for a breakpoint. Add a breakpoint, as you normally do, and click with the right mouse button on it. You will be prompt with a dialog. In the condition you can put some java code.
E.g. you could put "kickBoxing".equals(title)
this way the debugger will stop on that breakpoint only when the condition is true.
(photo taken from http://javafortesters.com/)
You can do that with Android Studio:
Set a breakpoint on the line you need.
Right-click on the breakpoint
Paste your condition into the field named Condition
For example, your condition should be like myclass.gettitle().equals("KickBoxing")

What is Android Studio shortcut to show function return type, parameter type & names all at the same time?

While I'm typing a function name:
String response;
response.split| // *** '|' denotes the caret position ***
Android Studio shows its declaration and the documentation. I can see return type, parameter names&types and doc all at the same time:
But when I'm inside parentheses, it shows parameters but no return type. (Cmd+P or Ctrl+P)
String response;
response.split(|)
If I press F1 (mac) or Ctrl+Q(win) inside parentheses, sometimes it doens't show anything because there's an error (for not completing the line), but when it shows it shows return type & parameter type but omits parameter names.
Does anyone know the shortcut(and its name) to show the first one - return type, parameter types, and (possibly) documentation all at the same time - while I'm inside parentheses?
Thanks!
I guess this is the one you are looking for, CTRL + space and hover move to any option
CTRL + P
CTRL + Q
CTRL + space
It appears to be out of our control. Based on Intellij IDEA 15.0.4 it's possible but not consistent; at first glance it seems the complete documentation as you desire is given by default for methods which have a single implementation while methods with multiple list them.
This is for List#add (multiple implementations):
And this is for List#get (single implementation):
Another example just to begin to confirm my thoughts, here's Iterator<T>#forEachRemaining (also single implementation):
Perhaps it would be too cluttered to be useful if each were listed.
As you may know, it's possible to jump to a single one in the list by tabbing and pressing enter on the one you want. Then you can use the arrows at the top to go back to see another. Not ideal but better than nothing.

How to print out values while debugging

In Xcode I am able to "po" any values while debugging. Is there a way to do this in Android Studio?
For example, if I hit a breakpoint and want to print out certain values in realtime as opposed to having to use Logs in my code?
You can do the following steps:
1- Set BreakPoint in the line you want to evaluate Ctrl+F8.
2- Run your code in debug mode or press Shift+F9.
3- When reached to the BreakPoint press Alt+F8 or click on the following button.
4- Then type your value in text-field and click on the Evaluate button.
References:
https://www.jetbrains.com/help/idea/debugging-code.html
https://www.jetbrains.com/help/idea/evaluating-expressions.html
Use Watches. It gives you the ability to evaluate expressions.
When you hit debug point, there are two ways to check values :
(1) Add Watch for any variable
(2) Hover over any variable, the value will be displayed there
If it's a c/c++ project, you still can use lldb command in Android Studio.
Here's the official document. When you hit the breakpoint, you will see a tab named "lldb" next to the variables tab.

Break on variable value change in Android Studio 1.1.0?

I know I could set a breakpoint at every line where my code changes the variable, but is there an option such as right-clicking a variable (to "Add to Watches") that would stop when a variable changes value?
I think C++ has this option. See this.
And Eclipse? See this.
Is this implemented in AS?
You can break on value changes of some variables in Android Studio 1.1.0.
Android Studio calls them 'Java Field Watchpoints'.
From the breakpoints windows, (Run -> "View breakpoints...") or Ctrl+Shift+F8,
you can add "Java Field Watchpoints" from the plus in the top left corner, and then select your class and variable.
If the goal is simply to set a watchpoint where execution halts if a variable's value changes, there are two methods:
Pressing Ctrl-shift-F8 to set a watchpoint brings up this dialog:
That looks more powerful but it's confusing because it lacks the option I need; and there's an extra step: filling in the dialog box below:
Once you fill it in correctly, you get the same options for stopping execution as in the simpler method below:
Define the variable on one line ending with a semicolon.
Left-click in the area where you set a normal breakpoint and up pops a dialog box.
Choose options to suit your needs.
Any instance where the value of the variable prefDbExists changes, execution will pause as at any "normal" (unconditional) breakpoint. And that's all I needed when I asked the original question.
EDIT: Fully qualified class name is {package name}.{class name})
What you seek for is commonly known as "WatchPoint".
You will find detailed answer and examples on the doc. page of JetBrains - IntelliJ - Idea which is the basis for Android Studio.
https://www.jetbrains.com/help/idea/2016.3/creating-field-watchpoints.html
For me this works perfectly !
Add a Kotlin Field Watchpoint by clicking on the space next to the line number for the field declaration in Android Studio. Select Kotlin Field Watchpoint from the Set Breakpoint menu. You will now get a breakpoint whenever that value changes.

IntelliJ Live Templates bug with completeSmart() function

I am trying to create a Live-Template in Android Studio that will somewhat speed up creation of findViewById(...)
Part of it is self-learning, and part is curious in creating such live-templates.
I want to be able to type in the following...
Button find + (enter)
...and that should create something like this...
Button btnAdd = (Button) findViewById(R.id.btnAddition);
My current implementation has issues...
...and these issues stem from the use of completeSmart(). Whenever you use completeSmart(), the template ignores everything after that call and ends editing.
For example, If I moved the CAST named-variable up one slot (above ID), then the cast would be automatically filled out and it would not let me easily edit ID anymore. Same as below picture, but without btnAddition. Just ...findViewById(R.id.);
With my current setup, I have CAST on the very bottom so I can easily edit all of the named-variables; however, the use of completeSmart() does not let the template end (Place the cursor by the $END$ marker - Line 29 in the picture below) when I am complete.
Instead, it places the cursor right after the cast, like so...
...when it should be placed on the start of the next line. This template does put a new line in, but the cursor does not go there at the end. Why?
So I want this...
1 ) Since I already but in Button, I want to cast to be Button. I should not have to type in in twice!
you should use method typeOfVariable()
you can change like this:

Categories

Resources