paip. 调试技术打印堆栈 uapi print stack java php python 总结.

时间:2022-02-04 08:06:22
paip. 调试技术打印堆栈 uapi print stack java php python 总结.


作者Attilax  艾龙,  EMAIL:1466519819@qq.com
来源:attilax的专栏
地址:http://blog.csdn.net/attilax


---------uapi
打印堆栈:printStack    god.printstack()
得到堆栈String:getStack


----------------php,
debug_print_backtrace(),加入error line的前面行上...
保存stack到文件:print_r(debug_backtrace());




C:\phpdeskc9>D:\wamp\php\php.exe  E:\DedeCMS-V5.7-UTF8-SP1-Full\uploads\del_some
_dir.php E:\OfflineExplorerPortable\Download budejie,xiaohua
#0  c() called at [E:\DedeCMS-V5.7-UTF8-SP1-Full\uploads\del_some_dir.php:31]
#1  b() called at [E:\DedeCMS-V5.7-UTF8-SP1-Full\uploads\del_some_dir.php:27]
#2  a() called at [E:\DedeCMS-V5.7-UTF8-SP1-Full\uploads\del_some_dir.php:38]


Fatal error: Call to undefined function d() in E:\DedeCMS-V5.7-UTF8-SP1-Full\upl
oads\del_some_dir.php on line 35




 debug_backtrace() 函数生成一个 backtrace。[1]
该函数返回一个关联数组




------------java 
e.printStackTrace() 


保存stack到文件,方法1
StackTraceElement [] messages=ex.getStackTrace();
   int length=messages.length;
   for(int i=0;i<length;i++){
    System.out.println("ClassName:"+messages[i].getClassName());
    System.out.println("getFileName:"+messages[i].getFileName());
    System.out.println("getLineNumber:"+messages[i].getLineNumber());
    System.out.println("getMethodName:"+messages[i].getMethodName());
    System.out.println("toString:"+messages[i].toString());
    }
   }
   
 保存stack到文件,方法2
public String getTrace(Throwable t) {
        StringWriter stringWriter= new StringWriter();
        PrintWriter writer= new PrintWriter(stringWriter);
        t.printStackTrace(writer);
        StringBuffer buffer= stringWriter.getBuffer();
        return buffer.toString();
    }


------------python
info = traceback.format_exc()
print info


参考:
python异常处理及异常信息追踪 - 趣客(放糖的绿豆汤) - Power by SupDo!.htm