compile: Use -Wall, not -w

For a reason unknown to me GDB was using -w instead of -Wall for 'compile code'.
The problem is later patch for 'compile printf' really needs some warnings to
be able to catch for example missing format string parameters:
	(gdb) compile printf "%d\n"
GCC does not seem to be able to cancel -w (there is nothing like -no-w).

Besides that I think even 'compile code' can benefit from -Wall.

That #ifndef change in print_one_macro() is needed otherwise we get
macro-redefinition warnings for the GCC built-in macros (as -w is no
longer in effect).  For example, without the #ifndef/#endif one gets:

	compile -r -- void _gdb_expr(){int i = 5;}^M
	/tmp/gdbobj-xpU1yB/out4.c:4:0: warning: "__FILE__" redefined [-Wbuiltin-macro-redefined]^M
	/tmp/gdbobj-xpU1yB/out4.c:5:0: warning: "__LINE__" redefined^M
	...

It makes more sense to pick the inferior's version of the macros, hence
#ifndef instead of #undef.

That new testsuite XFAIL is there as if one changes the struct definition to be
compliant with cv-qualifiers (to prevent the warnings):
struct struct_type {
-  struct struct_type *selffield;
+  volatile struct struct_type *selffield;
only then GCC/GDB will hit the crash, described in that GDB PR 18202.


gdb/ChangeLog
2015-05-16  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* compile/compile-c-support.c (print_one_macro): Use #ifndef.
	(generate_register_struct): Use __gdb_uintptr for TYPE_CODE_PTR.
	(c_compute_program): Call generate_register_struct after typedefs.
	* compile/compile-loc2c.c (push, pushf_register_address)
	(pushf_register): Cast to GCC_UINTPTR.
	(do_compile_dwarf_expr_to_c): Use unused attribute.  Add space after
	type.  Use GCC_UINTPTR instead of void *.  Remove excessive cast.
	(compile_dwarf_expr_to_c): Use GCC_UINTPTR instead of void *.
	* compile/compile.c (_initialize_compile): Enable warnings for
	COMPILE_ARGS.

gdb/testsuite/ChangeLog
2015-05-16  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.compile/compile-ops.exp: Cast param to void.
	* gdb.compile/compile.exp: Complete type for _gdb_expr.
	(compile code struct_object.selffield = &struct_object): Add xfail.
This commit is contained in:
Jan Kratochvil 2015-05-16 14:20:45 +02:00
parent 5c65b58a58
commit 3a9558c494
7 changed files with 58 additions and 22 deletions

View File

@ -1,3 +1,16 @@
2015-05-16 Jan Kratochvil <jan.kratochvil@redhat.com>
* compile/compile-c-support.c (print_one_macro): Use #ifndef.
(generate_register_struct): Use __gdb_uintptr for TYPE_CODE_PTR.
(c_compute_program): Call generate_register_struct after typedefs.
* compile/compile-loc2c.c (push, pushf_register_address)
(pushf_register): Cast to GCC_UINTPTR.
(do_compile_dwarf_expr_to_c): Use unused attribute. Add space after
type. Use GCC_UINTPTR instead of void *. Remove excessive cast.
(compile_dwarf_expr_to_c): Use GCC_UINTPTR instead of void *.
* compile/compile.c (_initialize_compile): Enable warnings for
COMPILE_ARGS.
2015-05-16 Jan Kratochvil <jan.kratochvil@redhat.com>
* cli/cli-script.c (execute_control_command): Update

View File

@ -131,7 +131,9 @@ print_one_macro (const char *name, const struct macro_definition *macro,
if (line == 0)
return;
fprintf_filtered (file, "#define %s", name);
/* None of -Wno-builtin-macro-redefined, #undef first
or plain #define of the same value would avoid a warning. */
fprintf_filtered (file, "#ifndef %s\n# define %s", name, name);
if (macro->kind == macro_function_like)
{
@ -147,7 +149,7 @@ print_one_macro (const char *name, const struct macro_definition *macro,
fputs_filtered (")", file);
}
fprintf_filtered (file, " %s\n", macro->replacement);
fprintf_filtered (file, " %s\n#endif\n", macro->replacement);
}
/* Write macro definitions at PC to FILE. */
@ -252,7 +254,7 @@ generate_register_struct (struct ui_file *stream, struct gdbarch *gdbarch,
switch (TYPE_CODE (regtype))
{
case TYPE_CODE_PTR:
fprintf_filtered (stream, "void *%s", regname);
fprintf_filtered (stream, "__gdb_uintptr %s", regname);
break;
case TYPE_CODE_INT:
@ -340,8 +342,6 @@ c_compute_program (struct compile_instance *inst,
expr_block, expr_pc);
make_cleanup (xfree, registers_used);
generate_register_struct (buf, gdbarch, registers_used);
fputs_unfiltered ("typedef unsigned int"
" __attribute__ ((__mode__(__pointer__)))"
" __gdb_uintptr;\n",
@ -363,6 +363,8 @@ c_compute_program (struct compile_instance *inst,
" __gdb_int_%s;\n",
mode, mode);
}
generate_register_struct (buf, gdbarch, registers_used);
}
add_code_header (inst->scope, buf);

View File

@ -436,7 +436,8 @@ compute_stack_depth (enum bfd_endian byte_order, unsigned int addr_size,
static void
push (int indent, struct ui_file *stream, ULONGEST l)
{
fprintfi_filtered (indent, stream, "__gdb_stack[++__gdb_tos] = %s;\n",
fprintfi_filtered (indent, stream,
"__gdb_stack[++__gdb_tos] = (" GCC_UINTPTR ") %s;\n",
hex_string (l));
}
@ -520,7 +521,8 @@ pushf_register_address (int indent, struct ui_file *stream,
struct cleanup *cleanups = make_cleanup (xfree, regname);
registers_used[regnum] = 1;
pushf (indent, stream, "&" COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s",
pushf (indent, stream,
"(" GCC_UINTPTR ") &" COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s",
regname);
do_cleanups (cleanups);
@ -544,7 +546,8 @@ pushf_register (int indent, struct ui_file *stream,
pushf (indent, stream, COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s",
regname);
else
pushf (indent, stream, COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s + %s",
pushf (indent, stream,
COMPILE_I_SIMPLE_REGISTER_ARG_NAME "->%s + (" GCC_UINTPTR ") %s",
regname, hex_string (offset));
do_cleanups (cleanups);
@ -605,7 +608,8 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
++scope;
fprintfi_filtered (indent, stream, "%s%s;\n", type_name, result_name);
fprintfi_filtered (indent, stream, "__attribute__ ((unused)) %s %s;\n",
type_name, result_name);
fprintfi_filtered (indent, stream, "{\n");
indent += 2;
@ -899,7 +903,7 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
(long) (op_ptr - base));
do_compile_dwarf_expr_to_c (indent, stream,
"void *", fb_name,
GCC_UINTPTR, fb_name,
sym, pc,
arch, registers_used, addr_size,
datastart, datastart + datalen,
@ -1080,7 +1084,7 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
"__cfa_%ld", (long) (op_ptr - base));
do_compile_dwarf_expr_to_c (indent, stream,
"void *", cfa_name,
GCC_UINTPTR, cfa_name,
sym, pc, arch, registers_used,
addr_size,
cfa_start, cfa_end,
@ -1117,8 +1121,8 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
}
}
fprintfi_filtered (indent, stream, "%s = (%s) __gdb_stack[__gdb_tos];\n",
result_name, type_name);
fprintfi_filtered (indent, stream, "%s = __gdb_stack[__gdb_tos];\n",
result_name);
fprintfi_filtered (indent - 2, stream, "}\n");
do_cleanups (cleanup);
@ -1134,7 +1138,7 @@ compile_dwarf_expr_to_c (struct ui_file *stream, const char *result_name,
const gdb_byte *op_ptr, const gdb_byte *op_end,
struct dwarf2_per_cu_data *per_cu)
{
do_compile_dwarf_expr_to_c (2, stream, "void *", result_name, sym, pc,
do_compile_dwarf_expr_to_c (2, stream, GCC_UINTPTR, result_name, sym, pc,
arch, registers_used, addr_size, op_ptr, op_end,
NULL, per_cu);
}

View File

@ -680,8 +680,11 @@ String quoting is parsed like in shell, for example:\n\
absolute target address.
-fPIC is not used at is would require from GDB to generate .got. */
" -fPIE"
/* We don't want warnings. */
" -w"
/* We want warnings, except for some commonly happening for GDB commands. */
" -Wall "
" -Wno-implicit-function-declaration"
" -Wno-unused-but-set-variable"
" -Wno-unused-variable"
/* Override CU's possible -fstack-protector-strong. */
" -fno-stack-protector"
);

View File

@ -1,3 +1,9 @@
2015-05-16 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.compile/compile-ops.exp: Cast param to void.
* gdb.compile/compile.exp: Complete type for _gdb_expr.
(compile code struct_object.selffield = &struct_object): Add xfail.
2015-05-15 Joel Brobecker <brobecker@adacore.com>
* gdb.ada/arr_enum_with_gap: New testcase.

View File

@ -416,7 +416,7 @@ if {[skip_compile_feature_tests]} {
}
# If we have a bug, this will hang.
gdb_test_no_output "compile code param"
gdb_test_no_output "compile code (void) param"
# We can't access optimized-out variables, but their presence should
# not affect compilations that don't refer to them.

View File

@ -71,13 +71,13 @@ gdb_test_no_output "compile -- f = 10" \
gdb_test "compile f = 10;" ".*= 10;: No such file.*" \
"Test abbreviations and code collision"
gdb_test_no_output "compile -r -- _gdb_expr(){int i = 5;}" \
gdb_test_no_output "compile -r -- void _gdb_expr(){int i = 5;}" \
"Test delimiter with -r"
gdb_test_no_output "compile -raw -- _gdb_expr(){int i = 5;}" \
gdb_test_no_output "compile -raw -- void _gdb_expr(){int i = 5;}" \
"Test delimiter with -raw"
gdb_test "compile -- -r _gdb_expr(){int i = 5;}" \
gdb_test "compile -- -r void _gdb_expr(){int i = 5;}" \
".* error: 'r' undeclared \\(first use in this function\\).*" \
"Test delimiter with -r after it"
@ -189,7 +189,15 @@ gdb_test "p localvar" " = 1"
# Test setting fields and also many different types.
#
gdb_test_no_output "compile code struct_object.selffield = &struct_object"
set test "compile code struct_object.selffield = &struct_object"
gdb_test_multiple $test $test {
-re "^$test\r\n$gdb_prompt $" {
pass "$test"
}
-re "gdb command line:1:25: warning: assignment discards 'volatile' qualifier from pointer target type \\\[-Wdiscarded-qualifiers\\\]\r\n$gdb_prompt $" {
xfail "$test (PR compile/18202)"
}
}
gdb_test "print struct_object.selffield == &struct_object" " = 1"
gdb_test_no_output "compile code struct_object.charfield = 1"
@ -261,7 +269,7 @@ gdb_test "print 'compile.c'::globalshadow" " = 77000" \
# Test GOT vs. resolving jit function pointers.
gdb_test_no_output "compile -raw -- int func(){return 21;} _gdb_expr(){int (*funcp)()=func; if (funcp()!=21) abort();}" \
gdb_test_no_output "compile -raw -- int func(){return 21;} void _gdb_expr(){ void abort (void); int (*funcp)()=func; if (funcp()!=21) abort(); }" \
"pointer to jit function"
#