This is the mail archive of the
mailing list for the GCC project.
Re: How to access the virtual table?
- From: Swati Rathi <swatirathi at cse dot iitb dot ac dot in>
- To: Jan Hubicka <hubicka at ucw dot cz>
- Cc: GCC Development <gcc at gcc dot gnu dot org>
- Date: Fri, 12 Sep 2014 17:28:37 +0530
- Subject: Re: How to access the virtual table?
- Authentication-results: sourceware.org; auth=none
- References: <54127DF0 dot 9080800 at cse dot iitb dot ac dot in> <20140912064455 dot GB31443 at atrey dot karlin dot mff dot cuni dot cz>
On Friday 12 September 2014 12:14 PM, Jan Hubicka wrote:
I am trying to access the virtual table.
My pass is hooked after pass_ipa_pta.
Consider Class A which contains virtual function.
An object created as :
is translated in GIMPLE as
struct A a;
From variable "a" we can get its type which is "struct A".
I tried to see how the dump_vtable function access the table.
To access the virtual table for class A, Below is the code which I tried.
tree t = TREE_TYPE (a);
tree binfo = TYPE_BINFO (t);
tree vtab = BINFO_VTABLE (binfo);
FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (DECL_INITIAL
(vtab)), ix, value)
Using the above iterator, entries of the virtual table should be accessible.
However, I am not able to do so.
You can check dump_tree (vtab) to see if you are seeing an VAR_DECL. BINFO_VTABLE
is usually POINTER_PLUS_EXPR, so you want to access DECL_INITIAL
of TREE_OPERAND (vtab) in that case.
If you want to access an virtual method with given token (position in vtable),
you can just use gimple_get_virt_method_for_binfo (or borrow code from there
for things you need).
Thanks a lot. This helped.
Kindly inform me the way to access the virtual table.
Also how to fetch the functions from that virtual table?