Development

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Accessing function code from CFG

    8 answers - 369 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hi all,
    In an IPA pass, for each CFG node, I have a tree decl member from
    which I can access the return type, name of the function, argument
    names and its types, but I can't seem to find a way to get the
    function code. I would guess it would be a basic block list but I
    don't know where I can get it.
    Any suggestions?
    Regards,
  • No.1 | | 577 bytes | |

    Paulo J. Matos wrote on 03/02/07 10:12:

    In an IPA pass, for each CFG node, I have a tree decl member from
    which I can access the return type, name of the function, argument
    names and its types, but I can't seem to find a way to get the
    function code. I would guess it would be a basic block list but I
    don't know where I can get it.

    You need to get at the function structure from the cgraph node with
    DECL_STRUCT_FUNCTIN (cgraph_node->decl). Then you can use one of the
    CFG accessors like basic_block_info_for_function().
  • No.2 | | 662 bytes | |

    3/2/07, Diego Novillo <dnovillo (AT) redhat (DOT) comwrote:
    Paulo J. Matos wrote on 03/02/07 10:12:

    In an IPA pass, for each CFG node, I have a tree decl member from
    which I can access the return type, name of the function, argument
    names and its types, but I can't seem to find a way to get the
    function code. I would guess it would be a basic block list but I
    don't know where I can get it.

    You need to get at the function structure from the cgraph node with
    DECL_STRUCT_FUNCTIN (cgraph_node->decl). Then you can use one of the
    CFG accessors like basic_block_info_for_function().

    Great! :-) Thank you!
  • No.3 | | 988 bytes | |

    3/2/07, Diego Novillo <dnovillo (AT) redhat (DOT) comwrote:
    Paulo J. Matos wrote on 03/02/07 10:12:

    In an IPA pass, for each CFG node, I have a tree decl member from
    which I can access the return type, name of the function, argument
    names and its types, but I can't seem to find a way to get the
    function code. I would guess it would be a basic block list but I
    don't know where I can get it.

    You need to get at the function structure from the cgraph node with
    DECL_STRUCT_FUNCTIN (cgraph_node->decl). Then you can use one of the
    CFG accessors like basic_block_info_for_function().

    For functions to which DECL_STRUCT_FUNCTIN (cgraph_node->decl) != 0,
    I'm always getting
    VARRAY_ACTIVE_SIZE(basic_block_info_for_function(D ECL_STRUCT_FUNCTIN
    (cgraph_node->decl))) == 0.

    Is this normal? It seems there are no basic blocks set for the
    functions. Probably my pass is being run before the bbs are created?
  • No.4 | | 331 bytes | |

    Paulo J. Matos wrote on 03/07/07 10:36:

    Is this normal? It seems there are no basic blocks set for the
    functions. Probably my pass is being run before the bbs are created?

    Looks like it. Set a breakpoint in build_tree_cfg and your function.
    If gdb stops in your function first, you found the problem.
  • No.5 | | 1562 bytes | |

    3/7/07, Diego Novillo <dnovillo (AT) redhat (DOT) comwrote:
    Paulo J. Matos wrote on 03/07/07 10:36:

    Is this normal? It seems there are no basic blocks set for the
    functions. Probably my pass is being run before the bbs are created?

    Looks like it. Set a breakpoint in build_tree_cfg and your function.
    If gdb stops in your function first, you found the problem.

    Now, this is wierd, probably I'm just doing it wrong, gdb is not
    finding any build_tree_cfg or my pass pass_gsvt, but it find, for
    example xmalloc.
    $ gdb gcc-bin/bin/gcc
    GNU gdb 6.6
    Copyright (C) 2006 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB. Type "show warranty" for details.
    This GDB was configured as "x86_64-pc-linux-gnu"
    Using host libthread_db library "/lib/libthread_db.so.1".
    (gdb) break build_tree_cfg
    Function "build_tree_cfg" not defined.
    Make breakpoint pending on future shared library load? (y or [n]) n
    (gdb) break pass_gsvt
    Function "pass_gsvt" not defined.
    Make breakpoint pending on future shared library load? (y or [n]) n
    (gdb) break xmalloc
    Breakpoint 1 at 0x415f30: file //gsvt/libiberty/xmalloc.c, line 145.

    Same results if I use objdump -t gcc | grep <whatever>
    finds xmalloc but no build_tree_cfg or pass_gsvt.

    What am I missing?
  • No.6 | | 203 bytes | |

    Paulo J. Matos wrote on 03/07/07 11:43:
    What am I missing?
    You are debugging the wrong binary. I'd suggest you browse through
    You need to debug one of cc1/cc1plus/jc1
  • No.7 | | 540 bytes | |

    3/7/07, Diego Novillo <dnovillo (AT) redhat (DOT) comwrote:
    Paulo J. Matos wrote on 03/07/07 11:43:

    What am I missing?

    You are debugging the wrong binary. I'd suggest you browse through

    You need to debug one of cc1/cc1plus/jc1

    Thank you. It seems I've not found my error then. build_tree_cfg is
    called 4 times before my pass. I guess it's one for each function I
    have in my source file.

    So, how come no bbs are created? Is there any other way to test where
    the problem lies?
  • No.8 | | 993 bytes | |

    3/7/07, Paulo J. Matos <pocm (AT) soton (DOT) ac.ukwrote:
    3/7/07, Diego Novillo <dnovillo (AT) redhat (DOT) comwrote:
    Paulo J. Matos wrote on 03/07/07 11:43:

    What am I missing?

    You are debugging the wrong binary. I'd suggest you browse through

    You need to debug one of cc1/cc1plus/jc1
    --
    Thank you. It seems I've not found my error then. build_tree_cfg is
    called 4 times before my pass. I guess it's one for each function I
    have in my source file.

    So, how come no bbs are created? Is there any other way to test where
    the problem lies?

    As a side note, if I instead try to access BBs through FR_EACH_BB_FN
    I get the basic blocks I wanted. :)
    struct function *fdecl = DECL_STRUCT_FUNCTIN(node->decl);
    basic_block bb;
    FR_EACH_BB_FN(bb, fdecl) {
    printf("For each bb!\n");
    }

    This will print "For each bb!" a couple of times for each function.
    Seems to be working this way around! :) heh!

Re: Accessing function code from CFG


max 4000 letters.
Your nickname that display:
In order to stop the spam: 4 + 3 =
QUESTION ON "Development"

EMSDN.COM