Commit 77831620 by Cary Coutant Committed by Cary Coutant

Add support for debugging with ICF (Identical Code Folding).

gcc/ChangeLog:
	Add support for debugging with ICF (Identical Code Folding).
	* calls.c (debug.h): New #include.
	(emit_call_1): Call virtual_call_token debug hook.
	* common.opt (-fenable-icf-debug): New option.
	* dwarf2out.c (dwarf2_debug_hooks): Add entries for new hooks (two
	locations in the source).
	(poc_label_num): New variable.
	(dcall_entry, vcall_entry): New typedefs.
	(dcall_table, vcall_table): New variables.
	(struct vcall_insn): New type.
	(vcall_insn_table): New variable.
	(DEBUG_DCALL_SECTION, DEBUG_VCALL_SECTION): New macros.
	(size_of_dcall_table): New function.
	(output_dcall_table): New function.
	(size_of_vcall_table): New function.
	(output_vcall_table): New function.
	(dwarf2out_direct_call): New function.
	(vcall_insn_table_hash): New function.
	(vcall_insn_table_eq): New function.
	(dwarf2out_virtual_call_token): New function.
	(dwarf2out_virtual_call): New function.
	(dwarf2out_init): Allocate new tables and sections.
	(prune_unused_types): Mark DIEs referenced from direct call table.
	(dwarf2out_finish): Output direct and virtual call tables.
	* final.c (final_scan_insn): Call direct_call and virtual_call
	debug hooks.
	* debug.h (struct gcc_debug_hooks): Add direct_call,
	virtual_call_token, virtual_call hooks.
	(debug_nothing_uid): New function.
	* debug.c (do_nothing_debug_hooks): Add dummy entries for new hooks.
	(debug_nothing_uid): New function.
	* dbxout.c (dbx_debug_hooks): Add dummy entries for new hooks.
	* sdbout.c (sdb_debug_hooks): Likewise.
	* vmsdbgout.c (vmsdbg_debug_hooks): Likewise.
	* doc/invoke.texi (-fenable-icf-debug): New option.

gcc/testsuite/ChangeLog:
	Add support for debugging with ICF (Identical Code Folding).
	* g++.dg/debug/dwarf2/icf.C: New test.

From-SVN: r152577
parent 968e5728
2009-10-08 Cary Coutant <ccoutant@google.com>
Add support for debugging with ICF (Identical Code Folding).
* calls.c (debug.h): New #include.
(emit_call_1): Call virtual_call_token debug hook.
* common.opt (-fenable-icf-debug): New option.
* dwarf2out.c (dwarf2_debug_hooks): Add entries for new hooks (two
locations in the source).
(poc_label_num): New variable.
(dcall_entry, vcall_entry): New typedefs.
(dcall_table, vcall_table): New variables.
(struct vcall_insn): New type.
(vcall_insn_table): New variable.
(DEBUG_DCALL_SECTION, DEBUG_VCALL_SECTION): New macros.
(size_of_dcall_table): New function.
(output_dcall_table): New function.
(size_of_vcall_table): New function.
(output_vcall_table): New function.
(dwarf2out_direct_call): New function.
(vcall_insn_table_hash): New function.
(vcall_insn_table_eq): New function.
(dwarf2out_virtual_call_token): New function.
(dwarf2out_virtual_call): New function.
(dwarf2out_init): Allocate new tables and sections.
(prune_unused_types): Mark DIEs referenced from direct call table.
(dwarf2out_finish): Output direct and virtual call tables.
* final.c (final_scan_insn): Call direct_call and virtual_call
debug hooks.
* debug.h (struct gcc_debug_hooks): Add direct_call,
virtual_call_token, virtual_call hooks.
(debug_nothing_uid): New function.
* debug.c (do_nothing_debug_hooks): Add dummy entries for new hooks.
(debug_nothing_uid): New function.
* dbxout.c (dbx_debug_hooks): Add dummy entries for new hooks.
* sdbout.c (sdb_debug_hooks): Likewise.
* vmsdbgout.c (vmsdbg_debug_hooks): Likewise.
* doc/invoke.texi (-fenable-icf-debug): New option.
2009-10-08 Alexandre Oliva <aoliva@redhat.com>
PR debug/41353
......@@ -39,6 +39,7 @@ along with GCC; see the file COPYING3. If not see
#include "sbitmap.h"
#include "langhooks.h"
#include "target.h"
#include "debug.h"
#include "cgraph.h"
#include "except.h"
#include "dbgcnt.h"
......@@ -394,6 +395,11 @@ emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNU
SIBLING_CALL_P (call_insn) = ((ecf_flags & ECF_SIBCALL) != 0);
/* Record debug information for virtual calls. */
if (flag_enable_icf_debug && fndecl == NULL)
(*debug_hooks->virtual_call_token) (CALL_EXPR_FN (fntree),
INSN_UID (call_insn));
/* Restore this now, so that we do defer pops for this call's args
if the context of the call as a whole permits. */
inhibit_defer_pop = old_inhibit_defer_pop;
......
......@@ -502,6 +502,10 @@ femit-class-debug-always
Common Report Var(flag_emit_class_debug_always) Init(0)
Do not suppress C++ class debug information.
fenable-icf-debug
Common Report Var(flag_enable_icf_debug)
Generate debug information to support Identical Code Folding (ICF)
fexceptions
Common Report Var(flag_exceptions) Optimization
Enable exception handling
......
......@@ -373,6 +373,9 @@ const struct gcc_debug_hooks dbx_debug_hooks =
dbxout_handle_pch, /* handle_pch */
debug_nothing_rtx, /* var_location */
debug_nothing_void, /* switch_text_section */
debug_nothing_tree, /* direct_call */
debug_nothing_tree_int, /* virtual_call_token */
debug_nothing_uid, /* virtual_call */
debug_nothing_tree_tree, /* set_name */
0 /* start_end_main_source_file */
};
......@@ -406,6 +409,9 @@ const struct gcc_debug_hooks xcoff_debug_hooks =
dbxout_handle_pch, /* handle_pch */
debug_nothing_rtx, /* var_location */
debug_nothing_void, /* switch_text_section */
debug_nothing_tree, /* direct_call */
debug_nothing_tree_int, /* virtual_call_token */
debug_nothing_uid, /* virtual_call */
debug_nothing_tree_tree, /* set_name */
0 /* start_end_main_source_file */
};
......
......@@ -50,6 +50,9 @@ const struct gcc_debug_hooks do_nothing_debug_hooks =
debug_nothing_int, /* handle_pch */
debug_nothing_rtx, /* var_location */
debug_nothing_void, /* switch_text_section */
debug_nothing_tree, /* direct_call */
debug_nothing_tree_int, /* virtual_call_token */
debug_nothing_uid, /* virtual_call */
debug_nothing_tree_tree, /* set_name */
0 /* start_end_main_source_file */
};
......@@ -127,3 +130,8 @@ debug_nothing_tree_int (tree decl ATTRIBUTE_UNUSED,
int local ATTRIBUTE_UNUSED)
{
}
void
debug_nothing_uid (int uid ATTRIBUTE_UNUSED)
{
}
......@@ -126,6 +126,25 @@ struct gcc_debug_hooks
text sections. */
void (* switch_text_section) (void);
/* Records a direct call to the function DECL, noting the point of call
and the debug info for the function. Called from final_scan_insn
when ICF debugging is enabled. */
void (* direct_call) (tree decl);
/* Records the OBJ_TYPE_REF_TOKEN for a virtual call through ADDR, which
for C++ is the vtable slot index, noting the INSN_UID for the call
instruction. Called from calls.c:emit_call_1 when ICF debugging is
enabled. It's necessary to do this during lowering because the
call instruction and the OBJ_TYPE_REF become separated after that
point. */
void (* virtual_call_token) (tree addr, int insn_uid);
/* Records a virtual call given INSN_UID, which is the UID of the call
instruction. The UID is then mapped to the vtable slot index noted
during the lowering phase. Called from final_scan_insn when ICF
debugging is enabled. */
void (* virtual_call) (int insn_uid);
/* Called from grokdeclarator. Replaces the anonymous name with the
type name. */
void (* set_name) (tree, tree);
......@@ -151,6 +170,7 @@ extern void debug_nothing_tree_int (tree, int);
extern void debug_nothing_tree_tree_tree_bool (tree, tree, tree, bool);
extern bool debug_true_const_tree (const_tree);
extern void debug_nothing_rtx (rtx);
extern void debug_nothing_uid (int);
/* Hooks for various debug formats. */
extern const struct gcc_debug_hooks do_nothing_debug_hooks;
......
......@@ -307,6 +307,7 @@ Objective-C and Objective-C++ Dialects}.
-fcompare-debug@r{[}=@var{opts}@r{]} -fcompare-debug-second @gol
-feliminate-dwarf2-dups -feliminate-unused-debug-types @gol
-feliminate-unused-debug-symbols -femit-class-debug-always @gol
-fenable-icf-debug @gol
-fmem-report -fpre-ipa-mem-report -fpost-ipa-mem-report -fprofile-arcs @gol
-frandom-seed=@var{string} -fsched-verbose=@var{n} @gol
-fsel-sched-verbose -fsel-sched-dump-cfg -fsel-sched-pipelining-verbose @gol
......@@ -4609,6 +4610,11 @@ The default is @samp{-femit-struct-debug-detailed=all}.
This option works only with DWARF 2.
@item -fenable-icf-debug
@opindex fenable-icf-debug
Generate additional debug information to support identical code folding (ICF).
This option only works with DWARF version 2 or higher.
@item -fno-merge-debug-strings
@opindex fmerge-debug-strings
@opindex fno-merge-debug-strings
......
......@@ -2684,6 +2684,26 @@ final_scan_insn (rtx insn, FILE *file, int optimize ATTRIBUTE_UNUSED,
/* Output assembler code from the template. */
output_asm_insn (templ, recog_data.operand);
/* Record point-of-call information for ICF debugging. */
if (flag_enable_icf_debug && CALL_P (insn))
{
rtx x = call_from_call_insn (insn);
x = XEXP (x, 0);
if (x && MEM_P (x))
{
if (GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
{
tree t;
x = XEXP (x, 0);
t = SYMBOL_REF_DECL (x);
if (t)
(*debug_hooks->direct_call) (t);
}
else
(*debug_hooks->virtual_call) (INSN_UID (insn));
}
}
/* Some target machines need to postscan each insn after
it is output. */
if (targetm.asm_out.final_postscan_insn)
......
......@@ -337,6 +337,9 @@ const struct gcc_debug_hooks sdb_debug_hooks =
debug_nothing_int, /* handle_pch */
debug_nothing_rtx, /* var_location */
debug_nothing_void, /* switch_text_section */
debug_nothing_tree, /* direct_call */
debug_nothing_tree_int, /* virtual_call_token */
debug_nothing_uid, /* virtual_call */
debug_nothing_tree_tree, /* set_name */
0 /* start_end_main_source_file */
};
......@@ -1725,6 +1728,9 @@ const struct gcc_debug_hooks sdb_debug_hooks =
0, /* handle_pch */
0, /* var_location */
0, /* switch_text_section */
0, /* direct_call */
0, /* virtual_call_token */
0, /* virtual_call */
0, /* set_name */
0 /* start_end_main_source_file */
};
......
2009-10-08 Cary Coutant <ccoutant@google.com>
Add support for debugging with ICF (Identical Code Folding).
* g++.dg/debug/dwarf2/icf.C: New test.
2009-10-08 Adam Nemet <anemet@caviumnetworks.com>
* gcc.target/mips/truncate-6.c: New test.
......
// Test support for ICF debugging.
// { dg-do compile }
// { dg-options "-O0 -gdwarf-2 -fenable-icf-debug -dA" }
class A
{
public:
A();
virtual void work();
virtual int p();
private:
int i;
};
class B
{
public:
B();
~B();
void work(const A* a);
private:
int j;
};
int
test1(A* a)
{
a->work();
}
int
test2(A* a)
{
if (a->p())
{
B b;
b.work(a);
}
}
// Verify that we get .debug_dcall and .debug_vcall tables generated
// and that we see entries for both virtual calls.
// { dg-final { scan-assembler "\\.section.*\.debug_dcall" } }
// { dg-final { scan-assembler "\\.section.*\.debug_vcall" } }
// { dg-final { scan-assembler "New caller" } }
// { dg-final { scan-assembler "Caller DIE offset" } }
// { dg-final { scan-assembler "Point of call" } }
// { dg-final { scan-assembler "Callee DIE offset" } }
// { dg-final { scan-assembler "0x0.*Vtable slot" } }
// { dg-final { scan-assembler "0x1.*Vtable slot" } }
......@@ -213,6 +213,9 @@ const struct gcc_debug_hooks vmsdbg_debug_hooks
debug_nothing_int, /* handle_pch */
debug_nothing_rtx, /* var_location */
debug_nothing_void, /* switch_text_section */
debug_nothing_tree, /* direct_call */
debug_nothing_tree_int, /* virtual_call_token */
debug_nothing_uid, /* virtual_call */
debug_nothing_tree_tree, /* set_name */
0 /* start_end_main_source_file */
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment