Showing posts with label Debugger. Show all posts
Showing posts with label Debugger. Show all posts

Monday, March 01, 2010

Debugging rails with ruby-debug

1. setup
$> sudo gem install ruby-debug

2. start rails webrick/mongrel web server
$> script/server --debugger

3. using debugger in controller

class PeopleController < ApplicationController def new debugger # 当应用程序访问到此行时,在console中会出现debugger控制台 @person = Person.new end end

4. debugger shell 命令帮助
(rdb:40) help
ruby-debug help v0.10.3
Type 'help ' for help on a specific command

Available commands:
backtrace delete enable help next quit show
break disable eval info p reload source
catch display exit irb pp restart step
condition down finish list ps save thread
continue edit frame method putl set trace

其中比较常用的是next/list/continue/method/backtrace命令。

更多关于ruby-debug,查看以下链接:
http://articles.sitepoint.com/article/debug-rails-app-ruby-debug
http://guides.rubyonrails.org/debugging_rails_applications.html

Friday, July 13, 2007

Javascript Debugger functions


<script type="text/javascript" charset="utf-8">
// Helper function to parse out the name from the text of the function
function getFunctionName(f)
{
if (/function (\w+)/.test(String(f)))
return RegExp.$1;
else
return "";
}

// Manually piece together a stack trace using the caller property
function constructStackTrace(f)
{
if (!f)
return "";

var thisRecord = getFunctionName(f) + "(";

for (var i=0; i< f.arguments.length; i++) {
thisRecord += String(f.arguments[i]);
// add a comma if this isn’t the last argument
if (i+1 < f.arguments.length)
thisRecord += ", ";
}

return thisRecord + ")\n" + constructStackTrace(f.caller);
}

// Retrieve a stack trace. Works in Mozilla and IE.
function getStackTrace() {
var err = new Error;
// if stack property exists, use it; else construct it manually
if (err.stack)
return err.stack;
else
/* alert(getStackTrace.caller);*/
return constructStackTrace(getStackTrace.caller);
}

function a(x)
{
document.writeln(x);
document.writeln("<br/>\n----Stack trace below----\n<br/>");
document.writeln(getStackTrace());
/* document.writeln((new Error).stack);*/
}
function b(x) {
a(x+1);
}
function c(x) {
b(x+1);
}
c(10);
</script>