vbox的更動 56933 路徑 trunk/src/bldprogs
- 時間撮記:
- 2015-7-14 下午02:46:43 (9 年 以前)
- 位置:
- trunk/src/bldprogs
- 檔案:
-
- 新增 1 筆資料
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/bldprogs/gccplugin.cpp
r56920 r56933 27 27 #include "tree.h" 28 28 #include "tree-pass.h" 29 #include "cp/cp-tree.h" 29 30 30 31 … … 39 40 * Defined Constants And Macros * 40 41 *********************************************************************************************************************************/ 42 #define GCCPLUGIN_DEBUG 41 43 /** Debug printf. */ 42 #if 144 #ifdef GCCPLUGIN_DEBUG 43 45 # define dprintf(...) do { fprintf(stderr, __VA_ARGS__); } while (0) 44 46 #else … … 47 49 48 50 51 /** For use with messages. */ 52 #define MY_LOC(a_hPreferred, a_pState) \ 53 (DECL_P(a_hPreferred) ? DECL_SOURCE_LOCATION(a_hPreferred) : gimple_location((a_pState)->hStmt)) 54 55 56 /******************************************************************************* 57 * Structures and Typedefs * 58 *******************************************************************************/ 59 /** Checker state. */ 60 typedef struct MYCHECKSTATE 61 { 62 gimple hStmt; 63 long iFmt; 64 long iArgs; 65 } MYCHECKSTATE; 66 /** Pointer to my checker state. */ 67 typedef MYCHECKSTATE *PMYCHECKSTATE; 68 69 49 70 /********************************************************************************************************************************* 50 71 * Internal Functions * … … 71 92 { 72 93 .type = GIMPLE_PASS, 73 .name = " iprt-format-checks",94 .name = "*iprt-format-checks", /* asterisk = no dump */ 74 95 .optinfo_flags = 0, 75 96 .gate = MyPassGateCallback, … … 93 114 .reference_pass_name = "ssa", 94 115 .ref_pass_instance_number = 1, 95 .pos_op = PASS_POS_INSERT_ AFTER,116 .pos_op = PASS_POS_INSERT_BEFORE, 96 117 }; 97 118 … … 114 135 115 136 137 #ifdef GCCPLUGIN_DEBUG 138 139 /** 140 * Debug function for printing the scope of a decl. 141 * @param hDecl Declaration to print scope for. 142 */ 143 static void dprintScope(tree hDecl) 144 { 145 tree hScope = CP_DECL_CONTEXT(hDecl); 146 if (hScope == global_namespace) 147 return; 148 if (TREE_CODE(hScope) == RECORD_TYPE) 149 hScope = TYPE_NAME(hScope); 150 151 /* recurse */ 152 dprintScope(hScope); 153 154 /* name the scope. */ 155 dprintf("::%s", DECL_NAME(hScope) ? IDENTIFIER_POINTER(DECL_NAME(hScope)) : "<noname>"); 156 } 157 158 159 /** 160 * Debug function for printing a declaration. 161 * @param hDecl The declaration to print. 162 */ 163 static void dprintDecl(tree hDecl) 164 { 165 enum tree_code const enmDeclCode = TREE_CODE(hDecl); 166 tree const hType = TREE_TYPE(hDecl); 167 enum tree_code const enmTypeCode = hType ? TREE_CODE(hType) : (enum tree_code)-1; 168 #if 0 169 if ( enmTypeCode == RECORD_TYPE 170 && enmDeclCode == TYPE_DECL 171 && DECL_ARTIFICIAL(hDecl)) 172 dprint_class(hType); 173 #endif 174 175 dprintf("%s ", tree_code_name[enmDeclCode]); 176 dprintScope(hDecl); 177 dprintf("::%s", DECL_NAME(hDecl) ? IDENTIFIER_POINTER(DECL_NAME(hDecl)) : "<noname>"); 178 if (hType) 179 dprintf(" type %s", tree_code_name[enmTypeCode]); 180 dprintf(" @%s:%d", DECL_SOURCE_FILE(hDecl), DECL_SOURCE_LINE(hDecl)); 181 } 182 183 #endif /* GCCPLUGIN_DEBUG */ 184 185 116 186 /** 117 187 * Gate callback for my pass that indicates whether it should execute or not. … … 125 195 126 196 197 static void MyCheckFormatWorker(PMYCHECKSTATE pState, tree hFmtArg) 198 { 199 200 } 201 202 203 /** 204 * Deal recursively with special format string constructs. 205 * 206 * This will call MyCheckFormatWorker to validate each format string. 207 * 208 * @param pState The format string check state. 209 * @param hFmtArg The format string node. 210 */ 211 static void MyCheckFormatRecursive(PMYCHECKSTATE pState, tree hFmtArg) 212 { 213 if (integer_zerop(hFmtArg)) 214 warning_at(MY_LOC(hFmtArg, pState), 0, "Format string should not be NULL"); 215 else 216 { 217 /** @todo more to do here. ternary expression, ++. */ 218 219 MyCheckFormatWorker(pState, hFmtArg); 220 } 221 } 222 223 127 224 /** 128 225 * Execute my pass. … … 133 230 dprintf("MyPassExecuteCallback:\n"); 134 231 232 /* 233 * Enumerate the basic blocks. 234 */ 135 235 basic_block hBasicBlock; 136 236 FOR_EACH_BB(hBasicBlock) … … 138 238 dprintf(" hBasicBlock=%p\n", hBasicBlock); 139 239 140 for (gimple_stmt_iterator hStmtItr = gsi_start_bb(hBasicBlock); gsi_end_p(hStmtItr); gsi_next(&hStmtItr)) 240 /* 241 * Enumerate the statements in the current basic block. 242 * We're interested in calls to functions with the __iprt_format__ attribute. 243 */ 244 for (gimple_stmt_iterator hStmtItr = gsi_start_bb(hBasicBlock); !gsi_end_p(hStmtItr); gsi_next(&hStmtItr)) 141 245 { 142 gimple hStmt = gsi_stmt(hStmtItr); 143 dprintf(" hStmt=%p ops=%d\n", hStmt, gimple_num_ops(hStmt)); 144 246 gimple const hStmt = gsi_stmt(hStmtItr); 247 enum gimple_code const enmCode = gimple_code(hStmt); 248 #ifdef GCCPLUGIN_DEBUG 249 unsigned const cOps = gimple_num_ops(hStmt); 250 dprintf(" hStmt=%p %s (%d) ops=%d\n", hStmt, gimple_code_name[enmCode], enmCode, cOps); 251 for (unsigned iOp = 0; iOp < cOps; iOp++) 252 { 253 tree const hOp = gimple_op(hStmt, iOp); 254 if (hOp) 255 dprintf(" %02d: %p, code %s(%d)\n", iOp, hOp, tree_code_name[TREE_CODE(hOp)], TREE_CODE(hOp)); 256 else 257 dprintf(" %02d: NULL_TREE\n", iOp); 258 } 259 #endif 260 if (enmCode == GIMPLE_CALL) 261 { 262 /* 263 * Check if the function type has the __iprt_format__ attribute. 264 */ 265 tree const hFn = gimple_call_fn(hStmt); 266 tree const hFnType = gimple_call_fntype(hStmt); 267 tree const hAttr = lookup_attribute("iprt_format", TYPE_ATTRIBUTES(hFnType)); 268 #ifdef GCCPLUGIN_DEBUG 269 tree const hFnDecl = gimple_call_fndecl(hStmt); 270 dprintf(" hFn =%p %s(%d); args=%d\n", 271 hFn, tree_code_name[TREE_CODE(hFn)], TREE_CODE(hFn), gimple_call_num_args(hStmt)); 272 if (hFnDecl) 273 dprintf(" hFnDecl=%p %s(%d) type=%p %s:%d\n", hFnDecl, tree_code_name[TREE_CODE(hFnDecl)], 274 TREE_CODE(hFnDecl), TREE_TYPE(hFnDecl), DECL_SOURCE_FILE(hFnDecl), DECL_SOURCE_LINE(hFnDecl)); 275 if (hFnType) 276 dprintf(" hFnType=%p %s(%d)\n", hFnType, tree_code_name[TREE_CODE(hFnType)], TREE_CODE(hFnType)); 277 #endif 278 if (hAttr) 279 { 280 /* 281 * Yeah, it has the attribute! 282 */ 283 tree const hAttrArgs = TREE_VALUE(hAttr); 284 MYCHECKSTATE State; 285 State.iFmt = TREE_INT_CST(TREE_VALUE(hAttrArgs)).to_shwi(); 286 State.iArgs = TREE_INT_CST(TREE_VALUE(TREE_CHAIN(hAttrArgs))).to_shwi(); 287 State.hStmt = hStmt; 288 dprintf(" %s() __iprt_format__(iFmt=%ld, iArgs=%ld)\n", 289 DECL_NAME(hFnDecl) ? IDENTIFIER_POINTER(DECL_NAME(hFnDecl)) : "<unamed>", State.iFmt, State.iArgs); 290 291 MyCheckFormatRecursive(&State, gimple_call_arg(hStmt, State.iFmt - 1)); 292 } 293 } 145 294 } 146 295 } … … 162 311 static tree AttributeHandler(tree *phOnNode, tree hAttrName, tree hAttrArgs, int fFlags, bool *pfDontAddAttrib) 163 312 { 164 dprintf("AttributeHandler: name=%s fFlags=%#x 313 dprintf("AttributeHandler: name=%s fFlags=%#x", IDENTIFIER_POINTER(hAttrName), fFlags); 165 314 long iFmt = TREE_INT_CST(TREE_VALUE(hAttrArgs)).to_shwi(); 166 315 long iArgs = TREE_INT_CST(TREE_VALUE(TREE_CHAIN(hAttrArgs))).to_shwi(); 167 dprintf(" iFmt=%ld iArgs=%ld\n", iFmt, iArgs);316 dprintf(" iFmt=%ld iArgs=%ld", iFmt, iArgs); 168 317 169 318 tree hType = *phOnNode; 319 dprintf(" hType=%p %s(%d)\n", hType, tree_code_name[TREE_CODE(hType)], TREE_CODE(hType)); 170 320 171 321 if (pfDontAddAttrib)
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器