how can i programmatically access v8 debugger variables list

62 views
Skip to first unread message

Leo Cono

unread,
Jan 29, 2015, 8:51:33 AM1/29/15
to nod...@googlegroups.com
 

I am writing an AOP Container. I want to get a list of objects and functions contained in the app.js script. I can see that all of this is available with NodeClipse V8 Debugger Variables list.

Question is: what code do I need to write to have access to the V8 Debugger Variables list?

Thanks, Leo

Andrey

unread,
Jan 29, 2015, 10:44:04 PM1/29/15
to nod...@googlegroups.com
You need to issue backtrace / frame / scope / scopes requests - see https://code.google.com/p/v8-wiki/wiki/DebuggerProtocol#Request_backtrace

You can use built-in debugger client for this ( ` require("_debugger") ` ) or npm modules - such as https://github.com/node-inspector/v8-debug or https://github.com/sidorares/v8-debugger-protocol

You can also access this information from script itself by talking to debug agent object ( you need to use "expose_debug_as" switch, for example node --expose_debug_as=v8debug to see v8debug reference in a global scope )
This is example to list all variables on exception: https://gist.github.com/sidorares/9181766
And example how to connect using built-in debugger: https://gist.github.com/sidorares/5bf04ccfb86aee6897fe

Andrey

Leo Cono

unread,
Feb 8, 2015, 10:32:10 PM2/8/15
to nod...@googlegroups.com
V8 embedded debugger is not compatible with NodeClipse
I am using node.js and "this", as well as, this.global is empty

I finally figured it out on my own and this is how you do reflection with Node.js.
Here is an Aspect Oriented Programming (AOP) Container using Cujo.js Meld.js


app-separate-files.js
var business_object = require('./user.js');
var node_framework = require('./trace-meldaround.js');
var user = new business_object.User('Leo');

var trace = new node_framework.Trace('Hello Meld App');
trace.doTrace();
user.sayHello();
user.sayGoodBye();
 
trace-meldaround.js
var meld, joinPoint;
meld = require('./meld.js');
joinPoint = meld.joinpoint;
var log4js = require('./att_node_framework/log4js-node-master/lib/log4js'); // include log4js
log4js.configure({ // configure to use all types in different files.
    appenders: [
        {   type: 'file',
            filename: '../logs/error.log', // specify the path where u want logs folder error.log
            category: 'error',
            maxLogSize: 20480,
            backups: 10
        },
        {   type: 'file',
            filename: '../logs/info.log', // specify the path where u want logs folder info.log
            category: 'info',
            maxLogSize: 20480,
            backups: 10
        },
        {   type: 'file',
            filename: '../logs/debug.log', // specify the path where u want logs folder debug.log
            category: 'debug',
            maxLogSize: 20480,
            backups: 10
        }
    ]
});
var loggerinfo = log4js.getLogger('info'); // initialize the var to use.
var loggererror = log4js.getLogger('error'); // initialize the var to use.
var loggerdebug = log4js.getLogger('debug'); // initialize the var to use.
var Trace = function(AppName){
 this.appName = AppName;
 };

 Trace.prototype.doTrace = function(){
 
  function sayMeld(jp) {  
   console.log('meldaround function called for Application : ' + Trace.constructor.AppName);
   console.log('JoinPoint Method: ' +  jp.method);
   console.log('JoinPoint Target: ' + jp.target);
   console.log('JoinPoint Args: ' + jp.args.toString());
   console.log('JoinPoint Result: ' + jp.result);
   console.log('JoinPoint Exception: ' + jp.exception);
   loggerinfo.info('Calling Method: ' + jp.method);
   loggererror.info('This is Error Logger');
   loggerdebug.info('JoinPoint Method: ' +  jp.method);
   loggerdebug.info('JoinPoint Target: ' + jp.target);
   loggerdebug.info('JoinPoint Args: ' + jp.args.toString());
   loggerdebug.info('JoinPoint Result: ' + jp.result);
   loggerdebug.info('JoinPoint Exception: ' + jp.exception);  
  }
 
 
  var appObjects = module.parent.children; 
  var methods = [];
  var objects = [];
  for (var i=0; i<appObjects.length;i++){
   if (typeof appObjects[i] == 'object'){
     objects.push(appObjects[i]);
    
     var funcObj = appObjects[i].exports;
     if (typeof funcObj == 'object')
     {
      for (var key in funcObj){
       var k =0;
       var prototypeObj = funcObj[key].prototype;
       methods[i] = [];
       for (var proto in prototypeObj){                           
         methods[i][k] = proto;
         k++;
       }                   
      }
     }    
    }
  }
 
  for (var j=0; j<objects.length; j++){
   var ObjectName;
   for (var key2 in objects[j].exports){   
    ObjectName = key2;
    console.log(objects[j].exports[ObjectName].prototype);
   
    for (var n=0; n<methods[j].length; n++){
     if (ObjectName != 'Trace'){
     meld.around(objects[j].exports[ObjectName].prototype, methods[j][n], function(joinPoint){
      sayMeld(joinPoint);
     
      joinPoint.proceed();
     });
     }
    }
   }     
 }
 
  //meld.around(User.constructor.prototype, 'sayHello', function(joinPoint){
 };
 exports.Trace = Trace;

-Leo Cono

Leo Cono

unread,
Feb 11, 2015, 1:59:41 PM2/11/15
to nod...@googlegroups.com
NodeClipse Eclipse plug-in for Node.js does not work with the embedded V8 Debugger.
Instead I accessed the JavaScript Application module exports to do reflection with Node.js apps since "this" object is empty.
Here is the code:

app.js code:

var business_object = require('./user.js');

var node_framework = require('./trace-meldaround.js');

var user = new business_object.User('Leo');


var trace = new node_framework.Trace('Hello Meld App');

trace.doTrace();

user.sayHello();

user.sayGoodBye();


user.js code:

var User = function(name){
    this.name = name;
    };

    User.prototype.sayHello = function(){
        console.log('hello ' + this.name);
    };

    User.prototype.sayGoodBye = function(){
        console.log('Good Bye ' + this.name);
    };

    exports.User = User;

 

trace-meldaround.js Code:

var meld, joinPoint;


meld = require('./meld.js');
joinPoint = meld.joinpoint;

var log4js = require('./node_framework/log4js-node-master/lib/log4js'); // include log4js
    };

    exports.Trace = Trace;


On Thursday, January 29, 2015 at 8:51:33 AM UTC-5, Leo Cono wrote:
Reply all
Reply to author
Forward
0 new messages