read_command_lines_1 had some (IMNSHO) spaghetti-ish code for cleanup
handling. This makes the code much simpler to understand, by
introducing an outer cleanup.
This is another case where a stylistic change for the checker is also
nice for the reader.
* cli/cli-script.c (read_command_lines_1): Use a null cleanup
for 'old_chain'. Do not check 'head' before processing
cleanups.
mi-cmd-stack.d had a conditional cleanup, "cleanup_tuple" that
confused the checker. However, there was no need for this, since it
was only used via do_cleanups at the end of the function, just before
another call to do_cleanups.
So, while this is a stylistic patch for the checker, I also consider
it a generic improvement for readers of the code.
* mi/mi-cmd-stack.c (list_arg_or_local): Remove
"cleanup_tuple".
This is a stylistic change to make some code in dbxread.c analyzable
by the checker.
* dbxread.c (dbx_read_symtab): Declare 'back_to' in a more
inner scope. Unconditionally call do_cleanups.
This is a stylistic change to make it so the checker can analyze a
function in linux-thread-db.c.
* linux-thread-db.c (thread_db_load_search): Unconditionally
call do_cleanups.
solib_aix_bfd_open has an early "return" that doesn't run cleanups.
This fixes the problem by dropping the null_cleanup and using a later
cleanup as the master cleanup for the function.
* solib-aix.c (solib_aix_bfd_open): Don't use a null cleanup
for 'cleanup'; instead use a later one.
The checker does not understand the idiom
if (except.reason < 0) {
do_cleanups (whatever);
GDB_PY_HANDLE_EXCEPTION (except);
}
because it doesn't realize that the nested 'if' actually has the same
condition.
This fixes instances of this to be more explicit.
* python/py-breakpoint.c (bppy_get_commands): Use
explicit, unconditional return.
* python/py-frame.c (frapy_read_var): Likewise.
* python/python.c (gdbpy_decode_line): Likewise.
cp_lookup_symbol_imports_or_template could return without
running cleanups.
* cp-namespace.c (cp_lookup_symbol_imports_or_template): Call
do_cleanups on all return paths.
Some code in mipsread.c could leak cleanups along some return paths.
* mipsread.c (read_alphacoff_dynamic_symtab): Call do_cleanups
along all return paths.
find_separate_debug_file could leak a cleanup along some return paths.
* symfile.c (find_separate_debug_file): Call do_cleanups
along all return paths.
search_symbols had some bad code resulting in a cleanup being both
discarded and run.
* symtab.c (search_symbols): Introduce a null cleanup for
'retval_chain'.
Some code in py-value.c could exit a loop without running some
cleanups made in the loop.
* python/py-value.c (valpy_binop): Call do_cleanups before
exiting loop.
print_children, in py-prettyprint.c, could call do_cleanups twice on
the same cleanup.
* python/py-prettyprint.c (print_children): Remove extra
do_cleanups call.
One return path in bppy_get_commands was missing a do_cleanups call.
* python/py-breakpoint.c (bppy_get_commands): Call do_cleanups
along all return paths.
This is another stylistic patch. It changes cli-logging.c to be
analyzable by the checker, again following the method of adding an
outer cleanup and unconditionally calling do_cleanups.
* cli/cli-logging.c (set_logging_redirect): Unconditionally
call do_cleanups.
c_value_of_root is missing a call to do_cleanups at one return.
This fixes the problem by removing that return and letting control
fall through.
* varobj.c (c_value_of_root): Call do_cleanups along all
return paths.
This is another cosmetic patch. It introduces an "outer" cleanup in
trace_dump_command and arranges to unconditionally call do_cleanups.
This lets the checker analyze the function.
* tracepoint.c (trace_dump_command): Unconditionally call
do_cleanups.
First, output_thread_groups leaks a cleanup along one return path.
Second, parse_cmd_to_aexpr could return without running its cleanups,
if there was an exception in a TRY_CATCH.
* breakpoint.c (output_thread_groups, parse_cmd_to_aexpr): Call
do_cleanups earlier.
list_available_thread_groups, in mi-main.c, leaks a cleanup.
This changes it to call do_cleanups.
* mi/mi-main.c (list_available_thread_groups): Call do_cleanups.
This is one of the stylistic patches. The code here in inf-ptrace.c
is not incorrect, but it is in a style that the cleanup checker cannot
handle. This patch changes it to a simpler style, following the usual
method of introducing an unconditional "outer" cleanup.
* inf-ptrace.c (inf_ptrace_create_inferior): Unconditionally
call discard_cleanups.
(inf_ptrace_attach): Likewise.
remote-mips.c has a few 'return's where cleanups are not run.
* remote-mips.c (mips_exit_debug): Call do_cleanups on all
return paths.
(mips_initialize): Likewise.
(common_open): Call do_cleanups.
internal_vproblem can return, so this introduces proper cleanup
handling there. Otherwise it may make a cleanup that is leaked.
* utils.c (internal_vproblem): Call do_cleanups.
This fixes a linespec bug noticed by the cleanup checker.
find_linespec_symbols did this:
cleanup = demangle_for_lookup (name, state->language->la_language,
&lookup_name);
[...]
cleanup = make_cleanup (xfree, canon);
But this is wrong, as it makes a subsequent call to do_cleanups not
clean up all the local state.
* linespec.c (find_linespec_symbols): Don't reassign to 'cleanup'.
This is a stylistic patch to make it so the checker can analyze
print_command_1. This amounts to installing an outer cleanup and
unconditionally invoking it.
* printcmd.c (print_command_1): Unconditionally call do_cleanups.
Fix some bugs pointed out by the cleanup checker. This one just fixes
some simple CLI reports, where CLI commands know that their caller
will do cleanups. This an older style with few instances, so it is
simpler to fix them up than to teach the checker about it.
* cli/cli-cmds.c (cd_command, alias_command): Call do_cleanups.
* cli/cli-dump.c (restore_binary_file): Call do_cleanups.
* interps.c (interpreter_exec_cmd): Call do_cleanups.
* source.c (show_substitute_path_command): Call do_cleanups.
(unset_substitute_path_command, set_substitute_path_command):
Likewise.
* symfile.c (load_command): Call do_cleanups.
This patch adds the cleanup checker. This is a Python plugin for GCC
that checks some rules for cleanup handling. In particular it tries
to notice when cleanups are left dangling at the end of a function.
It does this by applying a few simple rules.
First, it understands that a function whose return type is "struct
cleanup *" is a "cleanup constructor". Such functions are expected to
return the first cleanup that they make.
Then, it has the notion of a "master cleanup". The checker keeps a
stack of all cleanups made in a basic block. The first element is
pushed on the stack is the master cleanup -- the one that must later
be passed to either do_cleanups or discard_cleanups.
It is not perfect -- some constructs confuse it. So, part of this
series rewrites some code in gdb so that it is analyzable. I'll note
these spots and you can decide whether or not this is a good idea.
This patch also changes gcc-with-excheck to give it options. Now you
must use either -Xc (for the cleanup checker) or -Xx (for the
exception checker).
* contrib/cleanup_check.py: New file.
* contrib/gcc-with-excheck: Add option parsing.
* mi/mi-cmds.c (mi_cmds): Define MI command
'-exec-arguments' by macro DEF_MI_CMD_CLI_1 instead of
DEF_MI_CMD_CLI.
gdb/testsuite/
* gdb.mi/mi-cmd-param-changed.exp (test_command_param_changed):
Add a test that no MI notification is emitted when executing
-exec-arguments.
* write.c (resolve_reloc_expr_symbols): On REL targets don't
convert relocs who have no relocatable field either. Rephrase
the conditional so that the PC-relative check is only applied
for REL targets.
gas/testsuite/
* gas/mips/jalr3.d: New test.
* gas/mips/jalr3-n32.d: New test.
* gas/mips/jalr3-n64.d: New test.
* gas/mips/jalr3.s: New test source.
* gas/mips/mips.exp: Run the new tests.
ld/testsuite/
* ld-mips-elf/jalr3.dd: New test.
* ld-mips-elf/jalr3.ld: New test linker script.
* ld-mips-elf/mips-elf.exp: Run the new test.
alternate debug info source.
(dwarf_debug_sections): Add entries for alternate .debug_str and
.debug_info sections.
(dwarf_debug_section_enum): Likewise.
(read_alt_indirect_string): New function. Handles a
DW_FORM_GNU_strp_alt attribute.
(read_alt_indirect_ref): New function. Handles a
DW_FORM_GNU_ref_alt attribute.
(read_attribute_value): Process DW_FORM_GNU_ref_alt and
DW_FORM_GNU_strp_alt.
(find_abstract_instance_name): Handle DW_FORM_GNU_ref_alt
attributes.
(_bfd_dwarf2_cleanup_debug_info): Free alternate debug info
sources.
* opncls.c (GNU_DEBUGALTLINK): Define.
(bfd_get_alt_debug_link_info): New function.
(separate_alt_debug_file_exists): New function.
(find_separate_debug_file): Add parameters for fetch and check
functions.
(bfd_follow_gnu_debugaltlink): New function.
* bfd-in2.h: Regenerate.
I noticed that gdb.multi/multi-arch.exp wasn't passing with
extended-remote GDBserver with my pending multi-process+multi-arch
series anymore on current mainline, while it used to pass before:
(gdb) run
Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.multi/ma-hangout
Process /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.multi/ma-hangout created; pid = 32067
Warning:
Cannot insert breakpoint 2.
Error accessing memory address 0x4005c2: Unknown error -1.
Cannot insert breakpoint -1.
Temporarily disabling shared library breakpoints:
breakpoint #-1
(gdb) FAIL: gdb.multi/multi-arch.exp: starting inferior 2
Investigating manually, I found an easy way to reproduce. You just
need breakpoints on distinct inferiors, and a way to have GDB install
them in one go:
(gdb) set breakpoint always-inserted on
(gdb) info breakpoints
Num Type Disp Enb Address What
2 breakpoint del n <MULTIPLE>
2.1 y 0x00000000004005c2 in main at ../../../src/gdb/testsuite/gdb.multi/hello.c:40 inf 1
2.2 y 0x08048475 in main at ../../../src/gdb/testsuite/gdb.multi/hangout.c:22 inf 2
(gdb) enable 2
Warning:
Cannot insert breakpoint 2.
Error accessing memory address 0x4005c2: Unknown error -1.
And turning on remote debugging, we see:
(gdb) set debug remote 1
(gdb) disable 2
(gdb) enable 2
Sending packet: $Z0,4005c2,1#71...Packet received: E01
Sending packet: $Z0,8048475,1#87...Packet received: OK
Warning:
Cannot insert breakpoint 2.
Error accessing memory address 0x4005c2: Unknown error -1.
Notice that each of those Z0 breakpoints should be set in different
processes. However, no Hg packet to select a process has been sent in
between, so GDBserver tries to plant both on the same process that
happens to be current. The first Z0 then not so surprisingly fails.
IOW, the blame is on GDB, for telling GDBserver to plant both
breakpoints in the same process.
remote.c has a lazy scheme where it keeps a local cache of the
remote's selected general thread, and delays updating it on the remote
side until necessary (memory/register reads/writes, etc.). This is
done to reduce RSP traffic. The bug is that the Zx breakpoint
insert/remove methods weren't committing the selected thread/process
back to the remote side:
Breakpoint 3, remote_insert_breakpoint (gdbarch=0x1383ae0, bp_tgt=0x140c2b0) at ../../src/gdb/remote.c:8148
8148 if (remote_protocol_packets[PACKET_Z0].support != PACKET_DISABLE)
(top-gdb) p inferior_ptid
$3 = {pid = 3670, lwp = 0, tid = 3670}
(top-gdb) p general_thread
$4 = {pid = 3671, lwp = 0, tid = 3671}
IOW, a call to set_general_process is missing.
I did some auditing over remote.c, and added calls to all places I
found missing it.
This only used to work by chance before. breakpoint.c switches to a
thread of the target process before installing a breakpoint location.
That calls switch_to_thread. Before:
2012-07-27 Yao Qi <yao@codesourcery.com>
* thread.c (switch_to_thread): Don't call registers_changed.
that caused the register caches to all be flushed and refetched before
installing the breakpoint location. Given fetching registers commits
the remote general thread (with Hg), masking out the latent bug.
Tested on x86_64 Fedora 17 with GDBserver.
gdb/
2013-05-29 Pedro Alves <palves@redhat.com>
* remote.c (remote_insert_breakpoint, remote_remove_breakpoint)
(remote_insert_watchpoint, remote_remove_watchpoint)
(remote_insert_hw_breakpoint, remote_remove_hw_breakpoint)
(remote_verify_memory, compare_sections_command)
(remote_search_memory): Set the general process/thread on the
remote side.
The aarch64-without-fpu description is unused.
Linux requires an FPU, so the AArch64 native port always returns the
with-fpu variant:
static const struct target_desc *
aarch64_linux_read_description (struct target_ops *ops)
{
initialize_tdesc_aarch64 ();
return tdesc_aarch64;
}
When the target doesn't report a target description at all, we
fallback to a register set with an FPU:
aarch64_gdbarch_init ()
...
if (!tdesc_has_registers (tdesc))
tdesc = tdesc_aarch64;
This just removes the dead description.
Tested by building on x86_64 Fedora 17 with --enable=targets=all.
gdb/
2013-05-29 Pedro Alves <palves@redhat.com>
* aarch64-tdep.c: Don't include "features/aarch64-without-fpu.c".
(_initialize_aarch64_tdep): Don't call
initialize_tdesc_aarch64_without_fpu.
* features/Makefile (WHICH): Remove reference to
aarch64-without-fpu.
* features/aarch64-without-fpu.c: Delete file.
* regformats/aarch64-without-fpu.dat: Delete file.
* config/tc-mips.c (macro) <ld>: Don't use $zero for address
calculation.
gas/testsuite/
* gas/mips/ld-zero.d: New test.
* gas/mips/ld-zero-2.d: New test.
* gas/mips/ld-zero-3.d: New test.
* gas/mips/ld-zero-q.d: New test.
* gas/mips/ld-zero-u.d: New test.
* gas/mips/ecoff@ld-zero-3.d: New test.
* gas/mips/micromips@ld-zero-2.d: New test.
* gas/mips/micromips@ld-zero-3.d: New test.
* gas/mips/ld-zero.s: New test source.
* gas/mips/ld-zero-2.s: New test source.
* gas/mips/ld-zero-3.s: New test source.
* gas/mips/ld-zero-q.s: New test source.
* gas/mips/ld-zero-u.s: New test source.
* gas/mips/mips.exp: Run the new tests.