00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #define __STDC_LIMIT_MACROS
00041 #include <stdint.h>
00042 #include <stdio.h>
00043 #if defined(BUILD_OS_DARWIN)
00044 #include <darwin_elf.h>
00045 #else
00046 #include <elf.h>
00047 #endif
00048 #include <sys/elf_whirl.h>
00049 #include <sys/types.h>
00050 #include <ctype.h>
00051 #include <limits.h>
00052 #include "wn.h"
00053 #include "wn_map.h"
00054 #include "wn_util.h"
00055 #include "dwarf_DST.h"
00056 #include "ipc_file.h"
00057 #include "wb_util.h"
00058 #include "cg_browser.h"
00059 #include "cgb.h"
00060
00061 extern void s_cg_ipa_debug(const char init_buffer[]);
00062
00063 static CGB_PHASE CGB_Current_Phase = CGBP_NONE;
00064
00065 static CGB_COMMAND CGBS_Command_List[] =
00066 {
00067 'S', CGBR_NONE, NULL, "Print info about SUMMARY_SYMBOLs",
00068 'I', CGBR_NONE, NULL, "Print info about IVARs",
00069 'F', CGBR_NONE, NULL, "Print info about SUMMARY_FORMALs",
00070 'G', CGBR_NONE, NULL, "Print info about SUMMARY_GLOBALs",
00071 'A', CGBR_NONE, NULL, "Print info about SUMMARY_ACTUALs",
00072 'V', CGBR_NONE, NULL, "Print info about SUMMARY_VALUEs",
00073 'C', CGBR_NONE, NULL, "Print info about SUMMARY_COMMONs",
00074 'K', CGBR_NONE, NULL, "Print info about SUMMARY_COMMON_SHAPEs",
00075 'D', CGBR_NONE, NULL, "Print info about SUMMARY_CONTROL_DEPENDENCEs",
00076 'L', CGBR_NONE, NULL, "Print info about SUMMARY_CALLSITEs",
00077 'P', CGBR_NONE, NULL, "Print info about SUMMARY_PROCEDUREs",
00078 'a', CGBR_NONE, NULL, "Print info about CFG_NODE_INFOs",
00079 's', CGBR_NONE, NULL, "Print info about SCALAR_INFOs",
00080 'R', CGBR_NONE, NULL, "Print info about REGION_ARRAYSs",
00081 'r', CGBR_NONE, NULL, "Print info about PROJECTED_REGIONs",
00082 'n', CGBR_NONE, NULL, "Print info about PROJECTED_NODEs",
00083 't', CGBR_NONE, NULL, "Print info about TERMs",
00084 'l', CGBR_NONE, NULL, "Print info about LOOPINFOs",
00085 'p', CGBR_NONE, NULL, "Print info about SUMMARY_PHIs",
00086 'x', CGBR_NONE, NULL, "Print info about SUMMARY_CHIs",
00087 'T', CGBR_NONE, NULL, "Print info about TCONs",
00088 'E', CGBR_NONE, NULL, "Print info about SUMMARY_EXPRs",
00089 'X', CGBR_NONE, NULL, "Print info about SUMMARY_STIDs",
00090 'Y', CGBR_NONE, NULL, "Print info about SUMMARY_STMTs",
00091 'f', CGBR_NONE, NULL, "Print info about SUMMARY_FEEDBACKs",
00092 '=', CGBR_NONE, NULL, "Locate a summary at this address",
00093 'H', CGBR_NONE, NULL, "Print this information",
00094 'h', CGBR_NONE, NULL, "Print this information",
00095 '\0', CGBR_NONE, NULL, ""
00096 };
00097
00098 static CGB_COMMAND CGB_Command_List[] =
00099 {
00100 'R', CGBR_NONE, NULL, "Print the roots of call graph",
00101 'G', CGBR_NONE, NULL, "Print the call graph",
00102 'C', CGBR_NONE, NULL, "Print the callers of this node",
00103 'c', CGBR_NONE, NULL, "Print the callees of this node",
00104 'E', CGBR_NONE, NULL, "Print the edges in to this node",
00105 'e', CGBR_NONE, NULL, "Print the edges out of this node",
00106 'M', CGBR_NONE, NULL, "Print Mod/Ref info at this node",
00107 'V', CGBR_NONE, NULL, "Print Values for execution cost at this node",
00108 'X', CGBR_NONE, NULL, "Print Expressions for execution cost at this node",
00109 'P', CGBR_NONE, NULL, "Print Constant Propagation info at this node",
00110 '=', CGBR_NONE, NULL, "Set the current node to the following address",
00111 'v', CGBR_NONE, NULL, "Set the current vertex to the following number",
00112 '@', CGBR_NONE, NULL, "Set the current node to this numbered node",
00113 'F', CGBR_NONE, NULL, "Find the node with the given name",
00114 'W', CGBR_NONE, NULL, "Enter whirl browser at current node",
00115 'd', CGBR_NONE, NULL, "Toggle Da Vinci mode",
00116 'S', CGBR_NONE, &CGBS_Command_List[0],
00117 "Print summary info (Type SH for commands)",
00118 's', CGBR_NONE, NULL, "Print the symbol table entry for this node",
00119 't', CGBR_NONE, NULL, "Print the type table entry for this node",
00120 '<', CGBR_NONE, NULL, "Increase the fanciness level for printing",
00121 '>', CGBR_NONE, NULL, "Decrease the fanciness level for printing",
00122 'H', CGBR_NONE, NULL, "Print this information",
00123 'h', CGBR_NONE, NULL, "Print this information",
00124 '\0', CGBR_NONE, NULL, ""
00125 };
00126
00127 extern void CGB_Set_Phase(CGB_PHASE CGB_Phase)
00128 {
00129 CGB_Current_Phase = CGB_Phase;
00130 }
00131
00132 extern void CGB_Initialize(CG_BROWSER* cgb,
00133 IPA_CALL_GRAPH* ipa_cg)
00134 {
00135 cgb->Set_Ipa_Cg(ipa_cg);
00136 cgb->Set_Command_List(CGB_Command_List);
00137 }
00138
00139 extern void CGB_Terminate(CG_BROWSER* cgb)
00140 {
00141 cgb->Set_Ipa_Cg(NULL);
00142 }
00143
00144 extern "C" void cg_sdebug(const char init_buffer[])
00145 {
00146 switch (CGB_Current_Phase) {
00147 case CGBP_IPA:
00148 s_cg_ipa_debug(init_buffer);
00149 break;
00150 default:
00151 fprintf(stdout, "Call graph browser not valid in this phase.\n");
00152 break;
00153 }
00154 }
00155
00156 extern void scgb(const char init_buffer[])
00157 {
00158 cg_sdebug(init_buffer);
00159 }
00160
00161 extern void cg_debug()
00162 {
00163 cg_sdebug("");
00164 }
00165
00166 extern void cgb()
00167 {
00168 cg_debug();
00169 }