weixing ji <bit...@gmail.com> writes: > I am writing a plugin which is invoked at the event > "PLUGIN_OVERRIDE_GATE". My question is how to access all the local > variables of a function if I get a FUNC_DECL tree node. I have tried > as following: > for(block = DECL_INITIAL(fn_decl); block; block = TREE_CHAIN(block)) > { > for (temp = BLOCK_VARS (block); temp; temp = TREE_CHAIN (temp)) > { > cerr << tree_code_name[TREE_CODE(temp)] << ; > } > } > But this code does not work and it results in a segment fault. Could > someone tell me how to do that?
A good way to pin down problems of this sort is to compile your plugin with -DENABLE_TREE_CHECKING. That will cause the macros in tree.h to check that they are being invoked reasonably. However, I do not know what the problem is here. You should probably write this code using BLOCK_CHAIN and DECL_CHAIN rather than TREE_CHAIN, but those two both expand to TREE_CHAIN anyhow so I don't see why it would matter. Ian