Solved

Anybody know of a debugger whose variable window shows call stack object properties

Posted on 2015-02-23
13
106 Views
Last Modified: 2015-02-28
I'm using a debugger for php.  In break mode, I can navigate the call stack to examine code and the variables window for any stack frame; however, the "this" variables window panel seems only to report property values associated with the scope of the current breakpoint (i.e. top stack frame) instead of the currently selected stack frame.

I'm curious if anyone knows of a debugger (for php or any other OO  languages) which display the properties of the object associated with a stack frame, and in addition, those property values displayed are those which were in effect at the time that stack frame was the current/top frame?
0
Comment
Question by:SAbboushi
13 Comments
 
LVL 13

Expert Comment

by:George K.
ID: 40626759
Hi,

Have a look at  Xdebug 2 and let me know.
http://xdebug.org/docs/stack_trace
0
 
LVL 40
ID: 40626779
Such a debugger would require a lot of resources, because it has to record the state of a lot of variables.

Think about what is should record in big loops or recursions that deal with objects that have a lot of properties. And one of the things that designers try to optimize when they create a debugger is that it uses few resources in order to have as little impact as possible on the running application.

I do not know if php has the concept of a local variable, but in VB.NET, to solve such a problem, I simply create a local variable at the point where I want to check my class level variable, and assign it the value of the variable I want to check. When I hit a breakpoint, I simply navigate to the calling method from the Call Stack and get the from of the local variable.
0
 

Author Comment

by:SAbboushi
ID: 40626831
Merci Jacques-

Thanks for sharing your thoughts.

Anyone else?  I'm not looking for any solutions here, just whether or not anyone knows of a debugger which behaves as I've described.
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

Author Comment

by:SAbboushi
ID: 40626851
Thanks George - I scanned through the link you posted, but a lot of it is beyond my knowledge, so I couldn't tell...
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40627080
PHP has both local variables and object properties.  The latter are referred to with $this-> prepended to the variable name.  These local variables are visible only inside the method that defines the variables.  Object properties are visible in other methods, subject to the rules of scope inheritance, and outside of the scope of the object via var_dump() as shown here.
http://iconoun.com/demo/temp_sabboushi.php

Outputs:
int(3)
int(4)
object(Thing)#1 (1) {
  ["y"]=>
  int(4)
}

<?php // demo/temp_sabboushi.php

/**
 * SEE: http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28622868.html
 */
error_reporting(E_ALL);
echo '<pre>';

Class Thing
{
    public function set_a_variable($x)
    {
        $y = $x;
        var_dump($y);
    }

    public function set_a_property($x)
    {
        $this->y = $x;
        var_dump($this->y);
    }
}

$abc = new Thing;
$abc->set_a_variable(3);
$abc->set_a_property(4);

// VISUALIZE THE OBJECT - SHOWS ONLY PROPERTIES, NOT VARIABLES
var_dump($abc);

Open in new window

As a practical matter, developers do not use debuggers in PHP any more.  Instead we rely on unit testing with products like phpunit.  These tools allow us to create mock objects with highly predictable inputs and outputs, and we can use these mock objects to run our code and get a near-real-time report of success or failure in each of the inflection points.  A phpunit test takes at most a few seconds, even for a complex application.  If you run one prior to every commit, you can be sure that your new code additions did not break any of your earlier code!
0
 

Author Comment

by:SAbboushi
ID: 40627189
Thanks Ray.  I'll look into phpunit.

Anyone else?
0
 
LVL 10

Expert Comment

by:Jeffrey Dake
ID: 40632388
I am mostly a Java developer and I use the debugger in eclipse. Java is a different beast then php and the debugger does let you look at any allocated object. However like the others it will still only show you variables that are within the call hierarchy.   Java is kind of a memory hog, which for debugging is kind of helpful. Not sure if this helps at all.
0
 

Author Comment

by:SAbboushi
ID: 40633835
Hi Jeffrey - thanks for your response.

However like the others it will still only show you variables that are within the call hierarchy.

Can you clarify using the following java example (first time I've looked at java, so I hope my example is adequate):  

1  import java.io.*;
2  public class EmployeeTest{
3  
4     public static void main(String args[]){
5        Employee empOne = new Employee("James Smith");
6        this.arrOne = empOne.arrOne;
7  	  ArrayList2 arrTwo = new ArrayList2();
8     }
9  }

Open in new window

import java.io.*;
public class Employee{
  String name;

  public Employee(String name){
    this.name = name;
    ArrayList1 arrOne = new ArrayList1();
    this.arrOne = arrOne.list;
  }
}

Open in new window

public class ArrayList1 {
  public ArrayList1 {
    ArrayList<String> list = new ArrayList<String>();
    list.add("Item1");
    list.add("Item2");
    list.add("Item3");
    this.list = list;    
  }
}

Open in new window

public class ArrayList2 {
  public ArrayList2 {
    ArrayList<String> list = new ArrayList<String>();
    list.add("ItemA");
    list.add("ItemB");
    list.add("ItemC");
    this.list = list;
    ... Q1: If I break here, I expect the variables window to have a variable
                'list' that I can expand to see 'ItemA'...'ItemC'; I also expect an 
                entry somewhere for 'this' with property 'list' which I can also 
                expand to see 'ItemA'...'ItemC', correct?
    ... Q2: I expect the Call Stack to have an entry for EmployeeTest.main 
                line: 7 
               If you select that call stack entry and look at the variables 
               window, I expect to see 'empOne.arrOne'.  If so, can you expand 
               'empOne.arrOne' and see elements 'Item1'...'Item3'?
    ... Q3: I expect there to be an entry somewhere for 'this' with property 
               'arrOne'. If so, can you expand 'this.arrOne' and see elements 
               'Item1'...'Item3'?
    
            Responding with a screen shot of the call stack and the variable 
             windows for both stack frame entries would be really helpful, but 
             I'd be grateful if you merely gave me a correct answer ; )
            
             The key issue here is whether variables in the variables window 
             for all call stack frames maintain the correct scope values, 
             particularly for those variables/properties which must be 
             expanded (like arrays) in order to see their values (e.g. array 
             elements)
  }
}

Open in new window

0
 
LVL 10

Accepted Solution

by:
Jeffrey Dake earned 500 total points
ID: 40636722
Sorry it took awhile to get back.  I have attached three pictures that I think will show what you were expecting see.  The debug window in the top right shows the values of the variables, and the left screen shows the call hierarchy that you can jump through.

First shows values of the list
debug1.jpg
More data on the list.
debug2.jpg
Going back to see the employee record.
debug3.jpg
Hope this helps
0
 

Author Comment

by:SAbboushi
ID: 40636746
Perfect!  Thanks for spending the time to do that!

I also confirmed that Visual Studios (I tested php) behaves the same way i.e. retaining all variables for each stack frame.

Thanks again for your help.

PS - Curious if/what corrections you needed to make to my code (I don't know java, so I imagine it had some errors...)
0
 

Author Closing Comment

by:SAbboushi
ID: 40636747
Excellent!!
0
 
LVL 10

Expert Comment

by:Jeffrey Dake
ID: 40636767
Most of it worked as is.  Your usages of the keyword this. didn't always work, because you didn't have any instances variables of the class to set it too.  Here are the files I used.
ArrayList1.java
ArrayList2.java
Employee.java
EmployeeTest.java
0
 

Author Comment

by:SAbboushi
ID: 40637398
Thanks--
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jboss 7.1 start up error 1 40
PHP and MSSQL Arrays and Variables 3 25
PHP Mail error 3 28
Using Modal's in to Retrieve Data from MySql and Populate Forms 13 39
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question