自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

詳解C語言動態(tài)跟蹤工具ProbeVue如何調試Java應用程序

開發(fā) 后端
在AIX 6.1中引入的ProbeVue是一個動態(tài)跟蹤工具。本文詳解C語言動態(tài)跟蹤工具ProbeVue如何調試Java應用程序,解釋探測幾種Java函數(shù)的語言語法以及訪問函數(shù)參數(shù)的方法。還討論編寫Vue腳本的要點和限制。

在51CTO的Unix操作系統(tǒng)開發(fā)中我們介紹過AIX6 的安全新特性。 AIX 6.1 中引入的 ProbeVue 是一個動態(tài)跟蹤工具。它最初的設計目的是動態(tài)地跟蹤 C 應用程序和系統(tǒng)中的系統(tǒng)調用。隨著時間的推移,它現(xiàn)在支持調試Java應用程序,還支持獲取實時轉儲和基本系統(tǒng)調用。本文討論 ProbeVue 對 Java 的支持。

ProbeVue 具有以下特性:

◆跟蹤鉤子不需要作為源代碼的組成部分預先編譯。

◆ProbeVue 適用于 32/64 位內核和應用程序,不需要做任何修改。

◆在通過 ProbeVue 放置跟蹤鉤子之前,它們并不存在。

◆可以立即查看跟蹤活動捕捉的跟蹤數(shù)據(jù),可以作為終端輸出顯示它們,或者保存到文件中供以后查看。

◆跟蹤鉤子可以應用于任何函數(shù)的入口或出口(當前對于系統(tǒng)調用只支持出口探測點)。

◆當探測類型為入口時,可以探測傳遞給函數(shù)的參數(shù),這要求在 Vue 腳本的開頭或通過頭文件定義函數(shù)原型。

◆通過在出口點應用跟蹤鉤子并指定函數(shù)原型,可以探測函數(shù)的退出/返回值。

◆可以使用 ProbeVue 進行性能分析和問題調試。

使用 ProbeVue 的前提條件

◆AIX V6.10 和更高版本

◆文件集:不需要特殊的文件集,基本操作系統(tǒng)附帶所需的文件集。

◆在嘗試探測之前需要啟用 ProbeVue 特性,可以使用 SMIT 啟用它。

Vue 腳本語法

◆探測 Java 函數(shù)

  1. @@uftjava:PID:*:"fully qualified function name":entry  

◆探測 Java 庫例程:與 Java 函數(shù)相同。

命令語法

單獨啟動 Java 應用程序和 ProbeVue

◆Java 應用程序

  1. 對于 32 位:java -agentlib:probevuejava <additional parameters> myjavaapp  
  2. 對于 64 位:java -agentlib:probevuejava64 <additional parameters> myjavaapp  
  3.  

◆ProbeVue

  1. ProbeVue <additional arguments> myscript.e <script arguments> 
  2.  

作為 ProbeVue 的子進程啟動 Java 應用程序

◆對于 32 位:probevue -X <path of java> -A "-agentlib:probevuejava <additional parameters> my javaapp" myscript.e

◆對于 64 位:probevue -X <path of java> -A "-agentlib:probevuejava64 <additional parameters> my javaapp" myscript.e

基本探測示例

基本探測示例:myjava.java

  1. import java.lang.reflect.*;  
  2. import java.util.*;  
  3. import java.lang.*;  
  4.  
  5. class myclass1  
  6. {  
  7.         int i;  
  8.         float f;  
  9.         double d;  
  10.         boolean b;  
  11.         String s;  
  12.         public myclass1(int j)  
  13.         {  
  14.                 i=j;  
  15.         }  
  16.         public void set_i(int j)  
  17.                 {  
  18.                         i=j;  
  19.                 }  
  20.         public void set_f(float j)  
  21.                 {  
  22.                         f=j;  
  23.                 }  
  24.         public void set_d(double j)  
  25.                 {  
  26.                         d=j;  
  27.                 }  
  28.         public void set_b(boolean j)  
  29.                 {  
  30.                         b=j;  
  31.                 }  
  32.         public void set_s(String j)  
  33.                 {  
  34.                         s=j;  
  35.                 }  
  36.         public  void print_i()  
  37.                 {  
  38.                         System.out.println("Value of Integer i:"+i);  
  39.                         System.out.println("Value of Float f:"+f);  
  40.                         System.out.println("Value of Double d:"+d);  
  41.                         System.out.println("Value of Boolean b:"+b);  
  42.                         System.out.println("Value of String s:"+s);  
  43.                 }  
  44. }  
  45. public class myjava  
  46. {  
  47.         public static void main(String args[]) throws java.lang.InterruptedException  
  48.         {  
  49.                 Thread.sleep(60);  
  50.                 System.out.println("In main");  
  51.                 myclass1 MC1=new myclass1(20);  
  52.                 MC1.set_i(10);  
  53.                 MC1.set_f((float)10.03);  
  54.                 MC1.set_d(10.1123);  
  55.                 MC1.set_b(false);  
  56.                 MC1.set_s("ProbeVue");  
  57.                 MC1.print_i();  
  58.                 int [] int1;  
  59.                 int1 = new int[10];  
  60.                 for(int i=0;i<10;i++)  
  61.                 Array.set(int1,i,(int)i);  
  62.                 for(int i=0;i<10;i++)  
  63.                 {  
  64.                         System.out.println(Array.getInt(int1,i));  
  65.                  }  
  66.  
  67.  
  68.         }  
  69. }  
  70.  

執(zhí)行基本探測的 Vue 腳本:basic_probing.e

  1. @@BEGIN  
  2. {  
  3. // Declare and Initialize the variable to track the number of calls made   
  4. // to Array.set function  
  5.         int Number_Of_Calls_Of_Array_set;  
  6.         Number_Of_Calls_Of_Array_set=0;  
  7. }  
  8. //Probe String to trace the calls to function myclass1.set_d  
  9. @@uftjava:$__CPID:*:"myclass1.set_d":entry  
  10. {  
  11. //Printing the message for user notification that this function has been called  
  12. //By adding ProbeVue tag to message we can easily filter out the ProbeVue messages only.  
  13.         printf("ProbeVue - Entered  myclass1.set_d function \n");  
  14. }  
  15. @@uftjava:$__CPID:*:"myclass1.set_f":entry  
  16. {  
  17.         printf("ProbeVue - Entered  myclass1.set_f function \n");  
  18. }  
  19. @@uftjava:$__CPID:*:"myclass1.set_i":entry  
  20. {  
  21.         printf("ProbeVue - Entered  myclass1.set_i function \n");  
  22. }  
  23. @@uftjava:$__CPID:*:"myclass1.set_s":entry  
  24. {  
  25.         printf("ProbeVue - Entered  myclass1.set_s function \n");  
  26. }  
  27. @@uftjava:$__CPID:*:"myclass1.set_b":entry  
  28. {  
  29.         printf("ProbeVue - Entered  myclass1.set_b function \n");  
  30. }  
  31. @@uftjava:$__CPID:*:"myjava.main":entry  
  32. {  
  33.         printf("ProbeVue - Entered myjava.main function \n");  
  34. // Printing the Process Id and Parent Process Id  
  35.         printf("       Process Id : %ld\n",__pid);  
  36.         printf("Parent Process Id : %ld\n",__ppid);  
  37. }  
  38. @@uftjava:$__CPID:*:"java.lang.reflect.Array.set":entry  
  39. {  
  40.         printf("ProbeVue - Entered java.lang.reflect.Array.set function \n");  
  41. // Increment the count whenever the function is called  
  42.         Number_Of_Calls_Of_Array_set++;  
  43. }  
  44. @@syscall:$__CPID:exit:entry  
  45. {  
  46. // Exit when the application exits  
  47.         exit();  
  48. }  
  49. @@END  
  50. {  
  51. //This is executed when ProbeVue session exits and prints the following message.  
  52.         printf("Number Of times function - \"java.lang.reflect.Array.set\" called is   
  53.    : %d\n",Number_Of_Calls_Of_Array_set);  
  54. }  
  55.  

輸出

  1. # probevue -X `which java` -A "-agentlib:probevuejava myjava" basic_probing.e  
  2. ProbeVue - Entered myjava.main function  
  3.        Process Id : 7209080  
  4. Parent Process Id : 5767168  
  5. In main  
  6. Value of Integer i:10  
  7. ProbeVue - Entered  myclass1.set_i function  
  8. ProbeVue - Entered  myclass1.set_f function  
  9. ProbeVue - Entered  myclass1.set_d function  
  10. ProbeVue - Entered  myclass1.set_b function  
  11. ProbeVue - Entered  myclass1.set_s function  
  12. Value of Float f:10.03  
  13. Value of Double d:10.1123  
  14. Value of Boolean b:false  
  15. Value of String s:ProbeVue  
  16. 0  
  17. 1  
  18. 2  
  19. 3  
  20. 4  
  21. 5  
  22. 6  
  23. 7  
  24. 8  
  25. 9  
  26. ProbeVue - Entered java.lang.reflect.Array.set function  
  27. ProbeVue - Entered java.lang.reflect.Array.set function  
  28. ProbeVue - Entered java.lang.reflect.Array.set function  
  29. ProbeVue - Entered java.lang.reflect.Array.set function  
  30. ProbeVue - Entered java.lang.reflect.Array.set function  
  31. ProbeVue - Entered java.lang.reflect.Array.set function  
  32. ProbeVue - Entered java.lang.reflect.Array.set function  
  33. ProbeVue - Entered java.lang.reflect.Array.set function  
  34. ProbeVue - Entered java.lang.reflect.Array.set function  
  35. ProbeVue - Entered java.lang.reflect.Array.set function  
  36. Number Of times function - "java.lang.reflect.Array.set" called is : 10  
  37.  

訪問參數(shù)

除了提供放置探測的功能之外,ProbeVue 還允許收集傳遞給函數(shù)的參數(shù)值。對于訪問參數(shù),不需要為 ProbeVue 指定函數(shù)原型。

注意,Java 應用程序代碼與前一個示例相同,也是 myjava.java。

訪問參數(shù)的示例 Vue 腳本

  1. # cat accessing_argument.e  
  2. @@uftjava:$__CPID:*:"myclass1.set_d":entry  
  3. {  
  4. //Declaring Vue variable - d of type double  
  5.         double d;  
  6.         d=__arg2;  
  7.         printf("ProbeVue - Entered  myclass1.set_d function with   
  8.    argument :%llf\n",__arg2);  
  9.         printf("ProbeVue Variable d : %llf\n",d);  
  10. // Above is to demonstrate that argument values could be stored in Vue variables and then  
  11. // either operated and printed or printed directly  
  12. }  
  13. @@uftjava:$__CPID:*:"myclass1.set_f":entry  
  14. {  
  15.         printf("ProbeVue - Entered  myclass1.set_f function with argument :%f\n",__arg2);  
  16. }  
  17. @@uftjava:$__CPID:*:"myclass1.set_i":entry  
  18. {  
  19.         printf("ProbeVue - Entered  myclass1.set_i function with argument :%d\n",__arg2);  
  20. }  
  21. @@uftjava:$__CPID:*:"myclass1.set_s":entry  
  22. {  
  23. //Declaring String type Vue variable - s with its size  
  24.         String s[100];  
  25. //String type variable of Java can be directly copied to String type variable of Vue  
  26.         s=__arg2;  
  27.         printf("ProbeVue - Entered  myclass1.set_s function with argument :%s\n",__arg2);  
  28.         printf("ProbeVue Variable s : %s\n",s);  
  29. }  
  30. @@uftjava:$__CPID:*:"myclass1.set_b":entry  
  31. {  
  32.         printf("ProbeVue - Entered  myclass1.set_b function with argument :%d\n",__arg2);  
  33. }  
  34. @@uftjava:$__CPID:*:"myjava.main":entry  
  35. {  
  36.         printf("ProbeVue - Entered Probed Main\n");  
  37. }  
  38. @@uftjava:$__CPID:*:"java.lang.reflect.Array.set":entry  
  39. {  
  40.         printf("ProbeVue - Entered java.lang.reflect.Array.set function with   
  41.    2nd argument as : %d\n",__arg2);  
  42. }  
  43. @@syscall:$__CPID:exit:entry  
  44. {  
  45.         exit();  
  46. }  
  47.  

輸出

  1. #probevue -X `which java` -A "-agentlib:probevuejava myjava" accessing_argument.e  
  2. ProbeVue - Entered Probed Main  
  3. In main  
  4. Value of Integer i:10  
  5. ProbeVue - Entered  myclass1.set_i function with argument :10  
  6. ProbeVue - Entered  myclass1.set_f function with argument :10.030000  
  7. ProbeVue - Entered  myclass1.set_d function with argument :10.112300  
  8. ProbeVue Variable d : 10.112300  
  9. ProbeVue - Entered  myclass1.set_b function with argument :0  
  10. ProbeVue - Entered  myclass1.set_s function with argument :ProbeVue  
  11. ProbeVue Variable s : ProbeVue  
  12. Value of Float f:10.03  
  13. Value of Double d:10.1123  
  14. Value of Boolean b:false  
  15. Value of String s:ProbeVue  
  16. 0  
  17. 1  
  18. 2  
  19. 3  
  20. 4  
  21. 5  
  22. 6  
  23. 7  
  24. 8  
  25. 9  
  26. ProbeVue - Entered java.lang.reflect.Array.set function with 2nd argument as : 0  
  27. ProbeVue - Entered java.lang.reflect.Array.set function with 2nd argument as : 1  
  28. ProbeVue - Entered java.lang.reflect.Array.set function with 2nd argument as : 2  
  29. ProbeVue - Entered java.lang.reflect.Array.set function with 2nd argument as : 3  
  30. ProbeVue - Entered java.lang.reflect.Array.set function with 2nd argument as : 4  
  31. ProbeVue - Entered java.lang.reflect.Array.set function with 2nd argument as : 5  
  32. ProbeVue - Entered java.lang.reflect.Array.set function with 2nd argument as : 6  
  33. ProbeVue - Entered java.lang.reflect.Array.set function with 2nd argument as : 7  
  34. ProbeVue - Entered java.lang.reflect.Array.set function with 2nd argument as : 8  
  35. ProbeVue - Entered java.lang.reflect.Array.set function with 2nd argument as : 9  
  36.  

注意以下幾點:

◆對于靜態(tài)函數(shù),可以使用 __arg1 訪問函數(shù)的第一個實際參數(shù)。

◆對于非靜態(tài)函數(shù),可以使用 __arg2 訪問函數(shù)的第一個實際參數(shù),因為作為 __arg1 隱式地傳遞 this 指針。

其他要點

◆ProbeVue 腳本可以使用完全限定名(例如 java.lang.Math.PI)讀取 Java 類中的靜態(tài)變量和常量。

◆沒有替代 @@uftjava 的語法。

◆不需要指定函數(shù)原型,也不需要頭文件。

◆不需要通過使用 copy_userdata 訪問基本數(shù)據(jù)類型。

◆Java 的布爾數(shù)據(jù)類型映射到 ProbeVue 的整數(shù)數(shù)據(jù)類型,1 值代表 true,0 值代表 false。

◆Java 的字符串數(shù)據(jù)類型映射到 ProbeVue 的字符串數(shù)據(jù)類型。

◆__pname 提供進程名稱 "java" 而不是應用程序名,比如 myjavaapp。

◆所有其他函數(shù)的使用方法相同。

◆可以用 -agentlib:probevuejava 標志啟動 Java 應用程序,但是以后再啟動 ProbeVue 會話。

◆可以探測靜態(tài)和非靜態(tài)函數(shù)。

◆如果在 ProbeVue 命令行上用 -X 選項啟動 JVM,那么只能探測 Java 類中的 main 函數(shù)。這迫使 JVM 等到 ProbeVue 啟動之后才啟動 Java 應用程序。

可能實現(xiàn)的場景

◆統(tǒng)計調用某一函數(shù)的次數(shù)。

◆跟蹤調用各個函數(shù)的次序。

◆檢查參數(shù)值是否正確。

限制

◆只支持 JVM V1.5 和更高版本。

◆目前不支持訪問數(shù)組、實例變量和對象引用。

◆不支持探測重載和多態(tài)的函數(shù)。

◆目前不支持 get_function Vue 函數(shù)。

◆不能探測 Java 函數(shù)的出口點,因此不能獲取函數(shù)的返回值。

【編輯推薦】

  1. 盤點四大頂級Java編程工具
  2. 簡述Java語言的對象克隆特性
  3. 用Java語言進行Unicode代理編程
  4. 分裂與妥協(xié) IBM的Java平臺策略簡析
責任編輯:佚名 來源: developerworks
相關推薦

2012-02-15 13:26:56

IndexedDB

2016-03-12 21:46:56

Inspeckage應用程序動態(tài)分析

2010-04-01 15:10:06

Visual Stud

2022-12-25 18:03:13

Debug原理軟件

2011-04-01 11:01:02

應用程序BlackBerryJava

2011-05-05 18:08:43

云計算Windows AzuPaaS

2010-01-28 09:44:08

C++應用程序

2023-09-22 09:41:28

LinuxC語言

2013-04-22 09:21:43

2011-07-06 10:22:31

XCode IOS object-C

2012-11-28 11:14:39

IBMdW

2014-05-22 10:03:29

2013-02-22 09:28:45

MEAP軟件移動應用開發(fā)HTML5

2011-05-18 10:42:48

2010-01-14 11:14:47

C++應用程序

2010-01-25 16:41:08

C++應用程序

2011-11-17 15:17:37

AdobeAIR調試性能

2011-07-26 14:44:53

調試 Xcode

2011-07-07 16:08:41

2010-01-04 10:41:14

Silverlight
點贊
收藏

51CTO技術棧公眾號