Commit Graph

35429 Commits

Author SHA1 Message Date
Doug Evans 7bab9b58fd Split up end_symtab_from_static_block into two.
This patch is conceptually quite simple.
If you look at end_symtab_from_static_block you'll see
that the static_block == NULL case is completely different
than the non-NULL case.

There's a lot of complexity to handle the NULL case but it seems
entirely unnecessary.  For example, whether blockvector is NULL
is decided at the start, before this for loop:

  for (subfile = subfiles; subfile; subfile = nextsub)

Secondly, after the for loop, we test symtab for non-NULL here:

  /* Set this for the main source file.  */
  if (symtab)

but symtab will only ever be non-NULL if blockvector was non-NULL.
And if blockvector was non_NULL so will symtab.

The other case to consider is these lines of code executed before
the for loop:

  /* Read the line table if it has to be read separately.
     This is only used by xcoffread.c.  */
  if (objfile->sf->sym_read_linetable != NULL)
    objfile->sf->sym_read_linetable (objfile);

  /* Handle the case where the debug info specifies a different path
     for the main source file.  It can cause us to lose track of its
     line number information.  */
  watch_main_source_file_lossage ();

From my reading of the code, neither of these is useful
in the static_block == NULL case.

Thus we can make the code more readable by splitting these two cases up,
which is what this patch does.

gdb/ChangeLog:

	* buildsym.c (main_subfile): New static global.
	(free_subfiles_list): New function.
	(start_symtab): Set main_subfile.
	(restart_symtab): Replace init of subfiles, current_subfile with
	call to free_subfiles_list.
	(watch_main_source_file_lossage): Use main_subfile.
	(reset_symtab_globals): Replace init of current_subfile with call
	to free_subfiles_list.
	(end_symtab_without_blockvector, end_symtab_with_blockvector): New
	functions, split out from ...
	(end_symtab_from_static_block): ... here.  Rewrite to call them.
2014-11-18 08:28:04 -08:00
Doug Evans f194fefb5e The result of symtab expansion is always a primary symtab.
gdb/ChangeLog:

	* dwarf2read.c (dw2_instantiate_symtab): Add assert.
	(dw2_lookup_symbol): Remove unnecessary test for primary symbol table.
	* psymtab.c (lookup_symbol_aux_psymtabs): Ditto.
	(psymtab_to_symtab): Add comment and assert.
	(map_matching_symbols_psymtab): Remove unnecessary test for
	non-primary symtab.
2014-11-18 08:08:00 -08:00
Luis Machado 470e2f4e30 I caught a few mingw32-specific failures for some of the gdb.reverse
tests.

FAIL: gdb.reverse/consecutive-precsave.exp: reload precord save file
FAIL: gdb.reverse/finish-precsave.exp: reload precord save file
FAIL: gdb.reverse/until-precsave.exp: reload core file
FAIL: gdb.reverse/watch-precsave.exp: reload core file
FAIL: gdb.reverse/step-precsave.exp: reload core file
FAIL: gdb.reverse/break-precsave.exp: reload precord save file
FAIL: gdb.reverse/sigall-precsave.exp: reload precord save file

They happen for two reasons.

- mingw32 does not define SIGTRAP, so upon recording a core file, the
signal information will be missing, which in turn causes GDB to not
display the stopping signal when it loads the same core file.  An
earlier message warns about this:

"warning: Signal SIGTRAP does not exist on this system."

- The testcase is crafted in a way that expects a pattern of the
stopping signal message instead of a successful core file read message.

The following patch fixes this by changing the old pattern to a more
reasonable one, while still ignoring the fact that mingw32-based GDB
does not record a SIGTRAP in a core file because it does not define
it.

gdb/testsuite/

2014-11-18  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.reverse/break-precsave: Expect completion message for
	core file reads.
	* gdb.reverse/consecutive-precsave.exp: Likewise.
	* gdb.reverse/finish-precsave.exp: Likewise.
	* gdb.reverse/i386-precsave.exp: Likewise.
	* gdb.reverse/machinestate-precsave.exp: Likewise.
	* gdb.reverse/sigall-precsave.exp: Likewise.
	* gdb.reverse/solib-precsave.exp: Likewise.
	* gdb.reverse/step-precsave.exp: Likewise.
	* gdb.reverse/until-precsave.exp: Likewise.
	* gdb.reverse/watch-precsave.exp: Likewise.
2014-11-18 11:16:37 -02:00
Andreas Arnez a267f3ad3f GDB testsuite: More fixes for warnings with -std=gnu11
Fix some more C compiler warnings for missing function return types
and implicit function declarations in the GDB testsuite.

gdb/testsuite/ChangeLog:

	* gdb.base/bp-permanent.c: Include unistd.h.
	* gdb.python/py-framefilter-mi.c (main): Add return type.
	* gdb.python/py-framefilter.c (main): Likewise.
	* gdb.trace/actions-changed.c (main): Likewise.
2014-11-17 10:26:31 +01:00
Andreas Arnez 12084a9ae1 Eliminate literal line numbers in mi-until.exp
Remove literal line numbers from the regexps in mi-until.exp.  Add
appropriate eye-catchers to until.c and refer to those instead.

This change fixes the test case after having disturbed the line
numbering with the previous fix for compiler warnings with -std=gnu11.

gdb/testsuite/ChangeLog:

	* gdb.mi/until.c: Add eye-catchers.
	* gdb.mi/mi-until.exp: Refer to eye-catchers instead of literal
	line numbers.
2014-11-17 10:26:30 +01:00
Andreas Arnez dc7e1a77a4 Drop remaining references to removed source lines in break1.c and ur1.c
In some .exp files it was missed to remove the references to
eye-catchers like "set breakpoint 9 here" when the non-prototype
function header variants they belonged to were deleted.  This patch
cleans this up.

gdb/testsuite/ChangeLog:

	* gdb.base/condbreak.exp: Drop references to removed non-prototype
	function header variants in break1.c.
	* gdb.base/ena-dis-br.exp: Likewise.
	* gdb.base/hbreak2.exp: Likewise.
	* gdb.reverse/until-precsave.exp: Drop references to removed
	non-prototype function header variants in ur1.c.
	* gdb.reverse/until-reverse.exp: Likewise.
2014-11-17 10:26:30 +01:00
Joel Brobecker 43968415b0 [gdbserver/lynx] spurious failure to write in inferior memory
We noticed the following error on ppc-lynx178, using just about
any program:

        (gdb) tar remote mytarget:4444
        Remote debugging using mytarget:4444
        0x000100c8 in _start ()
        (gdb) b try
        Breakpoint 1 at 0x10844: file try.adb, line 11.
        (gdb) cont
        Continuing.
 !!!->  Cannot remove breakpoints because program is no longer writable.
 !!!->  Further execution is probably impossible.

        Breakpoint 1, try () at try.adb:11
        11          Local : Integer := 18;

And, of course, trying to continue yielded the expected outcome:

       (gdb) c
       Continuing.
       warning: Error removing breakpoint 1
       Cannot remove breakpoints because program is no longer writable.
       Further execution is probably impossible.

It turns out that the problem is caused by an intentional test
against a variable with an undefined value. After GDB receives
notification of the inferior stopping, it tries to remove the
breakpoint by sending a memory-write packet ("X10844,4:9 ").
This leads us to lynx_write_memory, where it tries to split
the memory-write into chunks of 4 bytes. And, in order to handle
writes which are not aligned on word boundaries, we have the
following code:

      if (skip > 0 || truncate > 0)
        /* We need to read the memory at this address in order to preserve
           the data that we are not overwriting.  */
        lynx_read_memory (addr, (unsigned char *) &buf, xfer_size);
        if (errno)
          return errno;

(the comment explains what the code is about).

Unfortunately, the not-so-glaring error that we've made here is
that we're checking ERRNO regardless of whether we've called
lynx_read_memory. In our case, because we are writing 4 bytes
aligned on a word boundary, we do not call lynx_read_memory and
therefore test an ERRNO with an undefined value.

gdb/gdbserver/ChangeLog:

        * lynx-low.c (lynx_write_memory): Put lynx_read_memory and
        corresponding ERRNO check in same block.
2014-11-17 07:23:27 +04:00
Petr Machata 41c7760520 dwarf.exp: In 64-bit units, emit also abbrev offset as a 64-bit field
Dwarf::tu and Dwarf::cu allow selection of units with 64-bit offsets
through an option.  When selected, unit size is encoded properly, but
offset to abbreviation unit is still encoded in a 4-byte field.  This
patch fixes the problem.

Reproducer:

Dwarf::assemble "blah.s" {
    tu {is_64 1 version 4 addr_size 8} 0x1122334455667788 the_type {
	type_unit {} { the_type: }
    }

    cu {is_64 1 version 4 addr_size 8} {
	compile_unit {{language @DW_LANG_C}} {}
    }
}

gdb/testsuite:

	* lib/dwarf.exp  (Dwarf::cu, Dwarf::tu): Emit
	${_cu_offset_size} bytes abbrev offset.
2014-11-17 08:31:47 +08:00
Doug Evans a3f89f9768 Add copyright headers. 2014-11-15 10:20:21 -08:00
Doug Evans 34248c3af7 PR symtab/17559
Basically the problem is that "symtab" is ambiguous.
Is it the primary symtab (where we canonically think of
blockvectors as being stored) or is it for a specific file
(where each file's line table is stored) ?

gdb_disassembly wants the symtab that contains the line table
but is instead getting the primary symtab.

gdb/ChangeLog:

	PR symtab/17559
	* symtab.c (find_pc_line_symtab): New function.
	* symtab.h (find_pc_line_symtab): Declare.
	* disasm.c (gdb_disassembly): Call find_pc_line_symtab instead of
	find_pc_symtab.
	* tui/tui-disasm.c (tui_set_disassem_content): Ditto.
	* tui/tui-hooks.c (tui_selected_frame_level_changed_hook): Ditto.
	* tui/tui-source.c (tui_vertical_source_scroll): Ditto.
	* tui/tui-win.c (make_visible_with_new_height): Ditto.
	* tui/tui-winsource.c (tui_horizontal_source_scroll): Ditto.
	(tui_display_main): Call find_pc_line_symtab instead of find_pc_line.

gdb/testsuite/ChangeLog:

	PR symtab/17559
	* gdb.base/line-symtabs.exp: New file.
	* gdb.base/line-symtabs.c: New file.
	* gdb.base/line-symtabs.h: New file.
2014-11-15 10:08:34 -08:00
Doug Evans 2097ae2584 expand_symtab_containing_pc: Renamed from find_pc_sect_symtab_via_partial.
This patch just renames one function.
Its only caller is in stack.c where we're printing a backtrace
with non-zero info_verbose and we want to make sure all the needed
symtabs are expanded before printing the backtrace
so that debug symbol reading messages don't pollute the backtrace.

I think the new name of the function makes clearer to the reader
what is going on.

gdb/ChangeLog:

	* symtab.c (expand_symtab_containing_pc): Renamed from
	find_pc_sect_symtab_via_partial.  All callers updated.
2014-11-15 08:05:22 -08:00
Yao Qi 1ada499f30 Add missing parenthesis
One parenthesis is missing, and it causes a compilation error.  This
patch is to fix it.

gdb:

2014-11-15  Yao Qi  <yao@codesourcery.com>

	* go32-nat.c (go32_create_inferior): Add missing parenthesis.
2014-11-15 17:04:30 +08:00
Joel Brobecker 355e210214 common-defs.h: include <stdarg.h> before <stdio.h>
When trying to build gdbserver on ppc-lynx178, the compiler reports
while trying to compile gdbserver/ax.c that vsprintf is not declared.
Looking at my C99 reference manual (a draft), I see the following
synopsis:

    #include <stdarg.h>
    #include <stdio.h>
    int vsprintf(char * restrict s, [etc]);

Looking at stdio.h on LynxOS-178, if found where vsprintf gets
declared:

    #if defined(__varargs_h) || defined(__stdarg_h) \
            || defined(_VARARGS_H) || defined(_STDARG_H)
    extern int vsprintf             _AP((char *, const char *, va_list));
    #endif

Digging further, I noticed that common-defs.h, which is included
via server.h, includes stdarg.h after including stdio, explaining
why vsprintf does not get declared in this case.

This patch fixes the problem by including stdarg.h before stdio.h.

gdb/ChangeLog:

        * common/common-defs.h: Move <stdarg.h> #include ahead of
        <stdio.h> #include.

Tested on x86_64-linux.
2014-11-14 21:00:45 +04:00
Pedro Alves 830301108d handle 'iconv's that define EILSEQ to ENOENT
We're currently pulling gnulib's errno module as a dependency of some
other module.  That provides an errno.h that defines EILSEQ to a
distinct value if the system's errno.h doesn't define it already.

However, GNU iconv does this:

 /* Get errno declaration and values. */
 #include <errno.h>
 /* Some systems, like SunOS 4, don't have EILSEQ. Some systems, like BSD/OS,
    have EILSEQ in a different header.  On these systems, define EILSEQ
    ourselves. */
 #ifndef EILSEQ
 #define EILSEQ @EILSEQ@
 #endif

That's in:

 http://git.savannah.gnu.org/cgit/libiconv.git/tree/include/iconv.h.in

The "different header" mentioned is wchar.h.  This is handled in:

 http://git.savannah.gnu.org/cgit/libiconv.git/tree/m4/eilseq.m4

which defines @EILSEQ@ to ENOENT if EILSEQ isn't found in either
errno.h or wchar.h.

So if iconv sets errno to EILSEQ on such system's, it's really setting
it to ENOENT.  And when we check for EILSEQ, we're checking for
gnulib's value.  The result is we won't detect the error correctly.

As we dropped support for both SunOS 4 or old BSD/OS, maybe we don't
need to care about the wchar.h issue anymore.  Still, AFAICS, gnulib's
m4/errno_h.m4 doesn't know that EILSEQ may be defined in wchar.h, and
so on such systems, ISTM gnulib ends up defining an incompatible
EILSEQ itself, but I think that should be fixed on the gnulib side, by
making it extract the EILSEQ value out of the system's wchar.h, like
GNU iconv does.

So that leaves handling the case of gnulib making up a EILSEQ value,
which we take as meaning the system really doesn't really define it,
which will be the same systems GNU iconv sets errno to ENOENT instead
of EILSEQ.

Looking at glibc's iconv it seems that ENOENT is never used there.
It seems it's safe to always treat ENOENT the same as EILSEQ.

The current EILSEQ definition under PHONY_ICONV is obviously stale as
gnulib garantees there's always a EILSEQ defined.

Tested on x86_64 Fedora 20.

gdb/
2014-11-14  Pedro Alves  <palves@redhat.com>

	* charset.c [PHONY_ICONV && !EILSEQ] (EILSEQ): Don't define.
	[!PHONY_ICONV] (gdb_iconv): New function.
	[!PHONY_ICONV] (iconv): Redefine to gdb_iconv.
2014-11-14 15:58:09 +00:00
Yao Qi 646da0594c Fix dw2-ifort-parameter.exp fail with clang
The patch <https://sourceware.org/ml/gdb-patches/2014-03/msg00202.html>
fixed dw2-ifort-parameter.exp on powerpc64 by adding some labels to
get the start and end address of function func.  This should also fix the
fail on thumb mode, however, this style is quite specific to gcc, and
other compiler, such as clang, may not guarantee the order of global
asms and functions.  The test fails with clang:

$ make check RUNTESTFLAGS='dw2-ifort-parameter.exp CC_FOR_TARGET=clang'
(gdb) p/x param^M
No symbol "param" in current context.^M
(gdb) FAIL: gdb.dwarf2/dw2-ifort-parameter.exp: p/x param

With this patch applied, dw2-ifort-parameter.exp still passes for gcc
on arm thumb mode and popwerpc64, and it also passes for clang on
x86_linux.

gdb/testsuite:

2014-11-14  Yao Qi  <yao@codesourcery.com>

	* gdb.dwarf2/dw2-ifort-parameter.c: Remove inline asm.
	(func): Add label func_label.
	* gdb.dwarf2/dw2-ifort-parameter.exp (Dwarf::assemble):
	Replace low_pc and high_pc with MACRO_AT_range.
	Replace name, low_pc and high_pc with MACRO_AT_func.
2014-11-14 08:55:07 +08:00
Yao Qi 9301ebe667 Fix implptr-optimized-out.exp fail
Hi,
I see the fail in gdb.dwarf2/implptr-optimized-out.exp in thumb mode

(gdb) p p->f^M
No symbol "p" in current context.^M
(gdb) FAIL: gdb.dwarf2/implptr-optimized-out.exp: p p->f

and the crash on powerpc64

(gdb) continue^M
Continuing.^M
^M
Program received signal SIGSEGV, Segmentation fault.^M
0x7d82100810000828 in ?? ()

The cause of both is that we incorrectly set attribute low_pc, since
main isn't resolved to function start address on these targets.

In this patch, we replace attributes name, low_pc and high_pc with
MACRO_AT_func.  The fail on thumb mode is fixed, and crash on
powerpc64 is fixed too.

gdb/testsuite:

2014-11-14  Yao Qi  <yao@codesourcery.com>

	* gdb.dwarf2/implptr-optimized-out.exp (Dwarf::assemble):
	Replace name, low_pc and high_pc with MACRO_AT_func.
2014-11-14 08:55:06 +08:00
Yao Qi f166b54272 Use Dwarf::assemble in implptr-optimized-out.exp
This patch is to use dwarf::assemble to generate debug information, and
remove implptr-optimized-out.S as a result.

gdb/testsuite:

2014-11-14  Yao Qi  <yao@codesourcery.com>

	* gdb.dwarf2/implptr-optimized-out.exp: Use Dwarf::assemble to
	produce debug information.
	* gdb.dwarf2/implptr-optimized-out.S: Removed.
2014-11-14 08:55:06 +08:00
Yao Qi 0f6e71e32f Get start and end address of main in dwz.exp
On arm-none-eabi target thumb mode, I see the following fail,

p the_int^M
$2 = 99^M
(gdb) FAIL: gdb.dwarf2/dwz.exp: p the_int

and on powerpc64 target, we even can't get function main from object
file,

disassemble main^M
No function contains specified address.^M
(gdb) FAIL: gdb.dwarf2/dwz.exp: disassemble main

This patch is to use MACRO_AT_func attribute to get the main's start
address and end address correctly, and also remove some code dwz.exp
getting main's length.  This patch fixes fails on both thumb mode and
powerpc64 target.

PASS: gdb.dwarf2/dwz.exp: p other_int
PASS: gdb.dwarf2/dwz.exp: p the_int

gdb/testsuite:

2014-11-14  Yao Qi  <yao@codesourcery.com>

	* gdb.dwarf2/dwz.exp: Remove the code to compile main.c to
	object and get function length.
	(Dwarf::assemble): Replace name, low_pc and high_pc attributes
	with MACRO_AT_func.
	(top-level): Replace gdb_compile and clean_restart with
	prepare_for_testing.
	* gdb.dwarf2/main.c (main): Add label main_label.
2014-11-14 08:55:06 +08:00
Yao Qi 876c4df947 DW attribute macro MACRO_AT_func and MACRO_AT_range
This patch addes DW macro attributes MACRO_AT_func and MACRO_AT_range
in dwarf assembler, which emits "DW_AT_low_pc func_start addr" and
"DW_AT_high_pc func_end addr".  func_start and func_end are computed
automatically by proc function_range.

These two attributes are pseudo attribute or macro attribute, which
means they are not standard dwarf attribute in dwarf spec.  Then can
be substituted or expanded to standard attributes or macro attributes.
See details in the comments to them.  Dwarf assembler is extended to
handle them.

Now the attributes name/low_pc/high_pc can be replaced with
MACRO_AT_func like this:

    subprogram {
	{name main}
	{low_pc main_start addr}
	{high_pc main_end addr}
    }

becomes:

    subprogram {
	{MACRO_AT_func { main ${srcdir}/${subdir}/${srcfile} }}
    }

users don't have to worry about the start and end of function main, and
they only need to add a label main_label in main.

gdb/testsuite:

2014-11-14  Yao Qi  <yao@codesourcery.com>

	* lib/dwarf.exp (function_range): New procedure.
	(Dwarf::_handle_macro_at_func): New procedure.
	(Dwarf::_handle_macro_at_range): New procedure.
	(Dwarf): Handle MACRO_AT_func and MACRO_AT_range.
2014-11-14 08:55:06 +08:00
Yao Qi 02ad9cf101 New proc _handle_attribute
This patch is to move some code to a new procedure _handle_attribute,
which will be used in my following patches.

gdb/testsuite:

2014-11-14  Yao Qi  <yao@codesourcery.com>

	* lib/dwarf.exp (_handle_DW_TAG): Move some code to ...
	(_handle_attribute): New procedure.
2014-11-14 08:55:06 +08:00
Doug Evans a8719064e8 PR symtab/17591
gdb/ChangeLog:

	PR symtab/17591
	* dwarf2read.c (find_slot_in_mapped_hash): Handle
	"(anonymous namespace)".
2014-11-13 16:50:51 -08:00
Doug Evans 60f7655a4a dwarf2read.c (update_enumeration_type_from_children): Avoid infinite loop.
gdb/ChangeLog:

	* dwarf2read.c (update_enumeration_type_from_children): Avoid
	infinite loop.
2014-11-13 15:43:12 -08:00
Jan Kratochvil 5784b3caf8 NEWS: Fix typo.
gdb/ChangeLog
2014-11-13  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* NEWS (maint set target-async): Fix typo.
2014-11-13 18:56:48 +01:00
Andreas Arnez a59add0c2e GDB testsuite: Fix warnings with -std=gnu11
Since upstream GCC has changed the default C language dialect to
'gnu11', it yields multiple warnings in the GDB testsuite for missing
function return types and implicit function declarations.  This patch
attempts to fix these.

gdb/testsuite/ChangeLog:

	* gdb.ada/cond_lang/foo.c (callme): Add return type.
	* gdb.base/call-sc.c (zed): Likewise.
	* gdb.base/checkpoint.c (main): Likewise.
	* gdb.base/dump.c (main): Likewise.
	* gdb.base/gcore.c (main): Likewise.
	* gdb.base/huge.c (main): Likewise.
	* gdb.base/multi-forks.c (main): Likewise.
	* gdb.base/pr10179-a.c (main): Likewise.
	* gdb.base/savedregs.c (main): Likewise.
	* gdb.base/sigaltstack.c (main): Likewise.
	* gdb.base/siginfo.c (main): Likewise.
	* gdb.base/structs.c (zed): Likewise.
	* gdb.mi/mi-stack.c (callee3, callee2, callee1, main): Likewise.
	* gdb.mi/mi-syn-frame.c (main): Likewise.
	* gdb.mi/until.c (foo, main): Likewise.
	* gdb.base/global-var-nested-by-dso.c (b_main, c_main): Declare.
	* gdb.base/solib-weak.c (foo): Declare.
	* gdb.base/attach-twice.c: Include stdio.h.
	* gdb.base/weaklib1.c: Likewise.
	* gdb.base/weaklib2.c: Likewise.
	* gdb.base/catch-signal-fork.c: Include stdio.h and sys/wait.h.
	* gdb.mi/mi-condbreak-call-thr-state-mt.c: Include stdio.h and
	unistd.h.
	* gdb.base/attach-pie-misread.c: Include stdlib.h.
	* gdb.mi/mi-exit-code.c: Likewise.
	* gdb.base/break-interp-lib.c: Include string.h.
	* gdb.base/coremaker.c: Likewise.
	* gdb.base/testenv.c: Likewise.
	* gdb.python/py-finish-breakpoint.c: Likewise.
	* gdb.base/inferior-died.c: Include sys/wait.h.
	* gdb.base/fileio.c: Include time.h.
	* gdb.base/async-shell.c: Include unistd.h.
	* gdb.base/dprintf-non-stop.c: Likewise.
	* gdb.base/info-os.c: Likewise.
	* gdb.mi/mi-console.c: Likewise.
	* gdb.mi/watch-nonstop.c: Likewise.
	* gdb.python/py-events.c: Likewise.
	* gdb.base/async.c (baz): Move up before its invocation.
	* gdb.base/code_elim2.c (my_global_func): Likewise.
	* gdb.base/skip-solib-lib.c (multiply): Likewise.
	* gdb.base/advance.c (func2): Likewise.
2014-11-13 10:20:44 +01:00
Andreas Arnez 3b5d599733 GDB testsuite: drop non-prototype C function header variants
Remove many old-style function header variants in C source files of
the GDB test suite, using the 'unifdef' tool with '-DPROTOTYPES=1'.

gdb/testsuite/ChangeLog:

	* gdb.base/annota1.c: Remove #ifdef PROTOTYPES, keep prototyped
	variant.
	* gdb.base/annota3.c: Likewise.
	* gdb.base/async.c: Likewise.
	* gdb.base/average.c: Likewise.
	* gdb.base/call-ar-st.c: Likewise.
	* gdb.base/call-rt-st.c: Likewise.
	* gdb.base/call-sc.c: Likewise.
	* gdb.base/call-strs.c: Likewise.
	* gdb.base/ending-run.c: Likewise.
	* gdb.base/execd-prog.c: Likewise.
	* gdb.base/exprs.c: Likewise.
	* gdb.base/foll-exec.c: Likewise.
	* gdb.base/foll-fork.c: Likewise.
	* gdb.base/foll-vfork.c: Likewise.
	* gdb.base/funcargs.c: Likewise.
	* gdb.base/gcore.c: Likewise.
	* gdb.base/jump.c: Likewise.
	* gdb.base/langs0.c: Likewise.
	* gdb.base/langs1.c: Likewise.
	* gdb.base/langs2.c: Likewise.
	* gdb.base/mips_pro.c: Likewise.
	* gdb.base/nodebug.c: Likewise.
	* gdb.base/opaque0.c: Likewise.
	* gdb.base/opaque1.c: Likewise.
	* gdb.base/recurse.c: Likewise.
	* gdb.base/run.c: Likewise.
	* gdb.base/scope0.c: Likewise.
	* gdb.base/scope1.c: Likewise.
	* gdb.base/setshow.c: Likewise.
	* gdb.base/setvar.c: Likewise.
	* gdb.base/shmain.c: Likewise.
	* gdb.base/shr1.c: Likewise.
	* gdb.base/shr2.c: Likewise.
	* gdb.base/sigall.c: Likewise.
	* gdb.base/signals.c: Likewise.
	* gdb.base/so-indr-cl.c: Likewise.
	* gdb.base/solib2.c: Likewise.
	* gdb.base/structs.c: Likewise.
	* gdb.base/sum.c: Likewise.
	* gdb.base/vforked-prog.c: Likewise.
	* gdb.base/watchpoint.c: Likewise.
	* gdb.reverse/shr2.c: Likewise.
	* gdb.reverse/until-reverse.c: Likewise.
	* gdb.reverse/ur1.c: Likewise.
	* gdb.reverse/watch-reverse.c: Likewise.
2014-11-13 10:20:44 +01:00
Andreas Arnez 066a77c580 Drop non-prototype C function header variants: 'sepdebug' test case
Remove old-style function header variants from sepdebug.c.  Eliminate
references to the removed locations "breakpoint 9" and "breakpoint 13"
from sepdebug.exp.

gdb/testsuite/ChangeLog:

	* gdb.base/sepdebug.c: Remove #ifdef PROTOTYPES, keep prototyped
	variant.
	* gdb.base/sepdebug.exp: Drop references to removed code.
2014-11-13 10:20:43 +01:00
Andreas Arnez 4f204ea54e Drop non-prototype C function header variants: 'list' test case
Remove old-style function header variants from list0.h and list1.c.
Fill the removed lines with comments or empty lines, such that the
line numbering is undisturbed.  Changes to the line numbering would
require heavy adjustments to list.exp, where many line numbers are
hard-coded, as well as a fair amount of knowledge about the source
code in and around certain lines.  Thus the dependency on the line
numbering can not be eliminated so easily, and it may not even be a
useful goal for a "list" test case.  Another option might be to adjust
the literal line numbers in list.exp, but even that is not as
straightforward as it may seem, since the test case expects certain
source lines to be exactly n lines apart.

gdb/testsuite/ChangeLog:

	* gdb.base/list0.h: Remove #ifdef PROTOTYPES, keep prototyped
	variant.  Preserve original line numbering.
	* gdb.base/list1.c: Likewise.
2014-11-13 10:20:43 +01:00
Andreas Arnez 3b377a3aa7 Drop non-prototype C function header variants: 'break' test case
Remove old-style function headers from break.c and break1.c.  Adjust
break.exp accordingly; in particular eliminate references to the
removed locations "breakpoint 9, 13, and 16" from break.exp.

gdb/testsuite/ChangeLog:

	* gdb.base/break.c: Remove #ifdef PROTOTYPES, keep prototyped
	variant.
	* gdb.base/break1.c: Likewise.
	* gdb.base/break.exp: Drop references to removed code.
2014-11-13 10:20:42 +01:00
Andreas Arnez e444df73e9 Drop non-prototype C function header variants: solib1.c
Clean up solib1.c by removing the #ifdef PROTOTYPES conditional.

gdb/testsuite/ChangeLog:

	* gdb.base/solib1.c: Remove #ifdef PROTOTYPES, keep prototyped
	variant.
2014-11-13 10:20:42 +01:00
Andreas Arnez 8008f2a759 callfuncs.exp: Indent perform_all_tests()
The previous patch did not indent perform_all_tests() correctly after
moving the main logic into it, to avoid obscuring the functional
changes.  This patch fixes the indentation.

gdb/testsuite/ChangeLog:

	* gdb.base/callfuncs.exp (perform_all_tests): Re-indent.
2014-11-13 10:20:41 +01:00
Andreas Arnez a5a0688714 Perform all tests in callfuncs.exp with and without C function prototypes
In callfuncs.exp, compile callfuncs.c with and without C function
header prototypes and execute all tests after each compilation.

gdb/testsuite/ChangeLog:

	* gdb.base/callfuncs.exp: Remove 'prototypes' variable.  Move main
	logic into perform_all_tests() and invoke it with and without
	function header prototypes.
	(do_function_calls): Remove conditional XFAIL for PR 5318.
	(rerun_and_prepare): Remove duplicate code.
	(perform_all_tests): New.  Main logic moved here.
2014-11-13 10:20:40 +01:00
Andreas Arnez 44dba9b9cd 'callfuncs' test case: Fixes in conditionally compiled code
The C source file for the 'callfuncs' test case did not compile with
-DNO_PROTOTYPES or -DPROTOTYPES.  This patch fixes various syntax
errors under #ifdef NO_PROTOTYPES and a small typo under #ifdef
PROTOTYPES.

gdb/testsuite/ChangeLog:

	* gdb.base/callfuncs.c (t_float_many_args): Fix syntax error in
	code guarded by #ifdef NO_PROTOTYPES.
	(t_double_many_args): Likewise.
	(DEF_FUNC_MANY_ARGS_1): Likewise.
	(DEF_FUNC_VALUES_1): Likewise.
	(t_structs_ldc): Renamed from t_structs_fc in conditional code
	guarded by #ifdef PROTOTYPES.
2014-11-13 10:20:40 +01:00
Andreas Arnez d1fbcd564a Eliminate literal line numbers in mi-console.exp
Remove the literal line number from a regexp in mi-console.exp.  Add
an appropriate eye-catcher to mi-console.c and refer to that instead.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-console.c: Add eye-catcher.
	* gdb.mi/mi-console.exp (semihosted_string): Refer to eye-catcher
	instead of literal line number.
2014-11-13 10:20:39 +01:00
Andreas Arnez b0e59b8f1c Eliminate literal line numbers in shlib-call.exp
Remove the literal line number from a regexp in shlib-call.exp.  Add
an appropriate eye-catcher to shr2.c and refer to that instead.

gdb/testsuite/ChangeLog:

	* gdb.base/shr2.c: Add eye-catcher.
	* gdb.base/shlib-call.exp: Refer to eye-catcher instead of literal
	line number.
2014-11-13 10:20:39 +01:00
Andreas Arnez 78f98cca31 Eliminate literal line numbers in jump.exp
Remove literal line numbers from the regexps in jump.exp.  Add
appropriate eye-catchers to jump.c and refer to those instead.

gdb/testsuite/ChangeLog:

	* gdb.base/jump.c: Add eye-catchers.
	* gdb.base/jump.exp: Refer to eye-catchers instead of literal line
	numbers.
2014-11-13 10:20:38 +01:00
Andreas Arnez 58fa2af0b3 Eliminate literal line numbers in foll-exec.exp
Remove literal line numbers from the regexps in foll-exec.exp.  Add
appropriate eye-catchers to foll-exec.c and execd-proc.c and refer to
those instead.

gdb/testsuite/ChangeLog:

	* gdb.base/execd-prog.c: Add eye-catchers.
	* gdb.base/foll-exec.c: Likewise.
	* gdb.base/foll-exec.exp: Refer to eye-catchers instead of literal
	line numbers.
2014-11-13 10:20:38 +01:00
Andreas Arnez 04e5059ba6 Eliminate literal line numbers in ending-run.exp
Remove literal line numbers from the regexps in ending-run.exp.  Add
appropriate eye-catchers to ending-run.c and refer to those instead.

gdb/testsuite/ChangeLog:

	* gdb.base/ending-run.c: Add eye-catchers.
	* gdb.base/ending-run.exp: Refer to eye-catchers instead of
	literal line numbers.
2014-11-13 10:20:37 +01:00
Andreas Arnez dbfdb174e3 Eliminate literal line numbers in call-rt-st.exp
Remove literal line numbers from the regexps in call-rt-st.exp.  Add
appropriate eye-catchers to call-rt-st.c and refer to those instead.

gdb/testsuite/ChangeLog:

	* gdb.base/call-rt-st.c: Add eye-catchers.
	* gdb.base/call-rt-st.exp: Refer to eye-catchers instead of
	literal line numbers.
2014-11-13 10:14:30 +01:00
Andreas Arnez 888a2adec7 Eliminate literal line numbers in call-ar-st.exp
Remove literal line numbers from the regexps in call-ar-st.exp.  Add
appropriate eye-catchers to call-ar-st.c and refer to those instead.

gdb/testsuite/ChangeLog:

	* gdb.base/call-ar-st.c: Add eye-catchers.
	* gdb.base/call-ar-st.exp: Refer to eye-catchers instead of
	literal line numbers.
2014-11-13 10:14:30 +01:00
Andreas Arnez 6acc2ddee2 Eliminate literal line numbers in dbx.exp
Remove literal line numbers from the commands and regexps in dbx.exp.
Add appropriate eye-catchers to average.c and sum.c and refer to those
instead.

gdb/testsuite/ChangeLog:

	* gdb.base/average.c: Add eye-catchers.
	* gdb.base/sum.c: Likewise.
	* gdb.base/dbx.exp: Use eye-catchers to determine line numbers for
	regexps dynamically.
2014-11-13 10:14:29 +01:00
Andreas Arnez 9ecfcd1d02 Eliminate literal line numbers in so-impl-ld.exp
Remove literal line numbers from the regexps in so-impl-ld.exp.  Add
appropriate eye-catchers to solib1.c and refer to those instead.

gdb/testsuite/ChangeLog:

	* gdb.base/solib1.c: Add eye-catchers.
	* gdb.base/so-impl-ld.exp: Match against eye-catchers instead of
	literal line numbers.
2014-11-13 10:14:29 +01:00
Pedro Alves 40e91bc71f GDBserver: clean up 'cont_thread' handling
As no place in the backends check cont_thread anymore, we can stop
setting and clearing it in places that resume the target and wait for
events.  Instead simply clear it whenever a new GDB connects.

gdb/gdbserver/
2014-11-12  Pedro Alves  <palves@redhat.com>

	* server.c (cont_thread): Update comment.
	(start_inferior, attach_inferior): No longer clear cont_thread.
	(handle_v_cont): No longer set cont_thread.
	(captured_main): Clear cont_thread each time a GDB connects.
2014-11-12 11:30:49 +00:00
Pedro Alves c2c118cfe1 GDBserver: don't resume all threads if the Hc thread disapears
There's code in linux_wait_1 that resumes all threads if the Hc thread
disappears.  It's the wrong thing to do, as GDB has told GDBserver to
resume only one thread, because e.g., the user has scheduler-locking
enabled, or because GDB was stepping the program over a breakpoint.
Resuming all threads behind GDB's back can't be good in either case.

The right thing to do is to detect that that the (only) resumed thread
is gone, and let GDB know about it.  The Linux backend is already
doing that nowadays, since:

 commit fa96cb382c
 Author:     Pedro Alves <palves@redhat.com>
 AuthorDate: Thu Feb 27 14:30:08 2014 +0000

     Teach GDBserver's Linux backend about no unwaited-for children (TARGET_WAITKIND_NO_RESUMED).

The backend detects that all resumed threads have disappeared, and
returns TARGET_WAITKIND_NO_RESUMED to the core of GDBserver, which
then reports an error to GDB.

There's no need to frob the passed in ptid to wait for the continue
thread either -- linux_wait_for_event only returns events for resumed
threads.

The badness (of resuming threads) can actually be observed in the
testsuite, if we force-disable vCont support in GDBserver -- before
the patch, gdb.threads/no-unwaited-for-left.exp hangs if we disable
vCont:

 (gdb) continue
 Continuing.
 FAIL: gdb.threads/no-unwaited-for-left.exp: continue to breakpoint: break-here (timeout)
 ... more cascading timeouts ....

After the patch, gdb.threads/no-unwaited-for-left.exp behaves the same
with or without vCont support:

 (gdb) continue
 Continuing.
 [New Thread 32226]
 [Switching to Thread 32226]

 Breakpoint 2, thread_a (arg=0x0) at /home/pedro/gdb/mygit/build/../src/gdb/testsuite/gdb.threads/no-unwaited-for-left.c:28
 28	  return 0; /* break-here */
 (gdb) PASS: gdb.threads/no-unwaited-for-left.exp: continue to breakpoint: break-here
...
 continue
 Continuing.
 warning: Remote failure reply: E.No unwaited-for children left.

 [Thread 32222] #1 stopped.
 (gdb) FAIL: gdb.threads/no-unwaited-for-left.exp: continue stops when the main thread exits

Overall, this is also good for getting rid of a RSP detail from the backend.

gdb/gdbserver/
2014-11-12  Pedro Alves  <palves@redhat.com>

	* linux-low.c (linux_wait_1): Don't force a wait for the Hc
	thread, and don't resume all threads if the Hc thread has exited.
2014-11-12 11:30:49 +00:00
Pedro Alves 78708b7c8c GDBserver: ctrl-c after leader has exited
The target->request_interrupt callback implements the handling for
ctrl-c.  User types ctrl-c in GDB, GDB sends a \003 to the remote
target, and the remote targets stops the program with a SIGINT, just
like if the user typed ctrl-c in GDBserver's terminal.

The trouble is that using kill_lwp(signal_pid, SIGINT) sends the
SIGINT directly to the program's main thread.  If that thread has
exited already, then that kill won't do anything.

Instead, send the SIGINT to the process group, just like GDB
does (see inf-ptrace.c:inf_ptrace_stop).

gdb.threads/leader-exit.exp is extended to cover the scenario.  It
fails against GDBserver before the patch.

Tested on x86_64 Fedora 20, native and GDBserver.

gdb/gdbserver/
2014-11-12  Pedro Alves  <palves@redhat.com>

	* linux-low.c (linux_request_interrupt): Always send a SIGINT to
	the process group instead of to a specific LWP.

gdb/testsuite/
2014-11-12  Pedro Alves  <palves@redhat.com>

	* gdb.threads/leader-exit.exp: Test sending ctrl-c works after the
	leader has exited.
2014-11-12 11:30:49 +00:00
Pedro Alves 6218dc4bdb Garbage collect the infwait_state global
No longer used since the non-continuable watchpoints handling rework.

gdb/
2014-11-12  Pedro Alves  <palves@redhat.com>

	* infrun.c (enum infwait_states, infwait_state): Delete.
2014-11-12 11:02:11 +00:00
Pedro Alves af48d08f97 fix skipping permanent breakpoints
The gdb.arch/i386-bp_permanent.exp test is currently failing an
assertion recently added:

 (gdb) stepi
 ../../src/gdb/infrun.c:2237: internal-error: resume: Assertion `sig != GDB_SIGNAL_0' failed.
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.
 Quit this debugging session? (y or n)
 FAIL: gdb.arch/i386-bp_permanent.exp: Single stepping past permanent breakpoint. (GDB internal error)

The assertion expects that the only reason we currently need to step a
breakpoint instruction is when we have a signal to deliver.  But when
stepping a permanent breakpoint (with or without a signal) we also
reach this code.

The assertion is correct and the permanent breakpoints skipping code
is wrong.

Consider the case of the user doing "step/stepi" when stopped at a
permanent breakpoint.  GDB's `resume' calls the
gdbarch_skip_permanent_breakpoint hook and then happily continues
stepping:

  /* Normally, by the time we reach `resume', the breakpoints are either
     removed or inserted, as appropriate.  The exception is if we're sitting
     at a permanent breakpoint; we need to step over it, but permanent
     breakpoints can't be removed.  So we have to test for it here.  */
  if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here)
    {
      gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
    }

But since gdbarch_skip_permanent_breakpoint already advanced the PC
manually, this ends up executing the instruction that is _after_ the
breakpoint instruction.  The user-visible result is that a single-step
steps two instructions.

The gdb.arch/i386-bp_permanent.exp test is actually ensuring that
that's indeed how things work.  It runs to an int3 instruction, does
"stepi", and checks that "leave" was executed with that "stepi".  Like
this:

 (gdb) b *0x0804848c
 Breakpoint 2 at 0x804848c
 (gdb) c
 Continuing.

 Breakpoint 2, 0x0804848c in standard ()
 (gdb) disassemble
 Dump of assembler code for function standard:
    0x08048488 <+0>:     push   %ebp
    0x08048489 <+1>:     mov    %esp,%ebp
    0x0804848b <+3>:     push   %edi
 => 0x0804848c <+4>:     int3
    0x0804848d <+5>:     leave
    0x0804848e <+6>:     ret
    0x0804848f <+7>:     nop
 (gdb) si
 0x0804848e in standard ()
 (gdb) disassemble
 Dump of assembler code for function standard:
    0x08048488 <+0>:     push   %ebp
    0x08048489 <+1>:     mov    %esp,%ebp
    0x0804848b <+3>:     push   %edi
    0x0804848c <+4>:     int3
    0x0804848d <+5>:     leave
 => 0x0804848e <+6>:     ret
    0x0804848f <+7>:     nop
 End of assembler dump.
 (gdb)

One would instead expect that a stepi at 0x0804848c stops at
0x0804848d, _before_ the "leave" is executed.  This commit changes GDB
this way.  Care is taken to make stepping into a signal handler when
the step starts at a permanent breakpoint instruction work correctly.

The patch adjusts gdb.arch/i386-bp_permanent.exp in this direction,
and also makes it work on x86_64 (currently it only works on i*86).

The patch also adds a new gdb.base/bp-permanent.exp test that
exercises many different code paths related to stepping permanent
breakpoints, including the stepping with signals cases.  The test uses
"hack/trick" to make it work on all (or most) platforms -- it doesn't
really hard code a breakpoint instruction.

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/
2014-11-12  Pedro Alves  <palves@redhat.com>

	* infrun.c (resume): Clear the thread's 'stepped_breakpoint' flag.
	Rewrite stepping over a permanent breakpoint.
	(thread_still_needs_step_over, proceed): Don't set
	stepping_over_breakpoint for permanent breakpoints.
	(handle_signal_stop): Don't clear stepped_breakpoint.  Also pull
	single-step breakpoints out of the target on hardware step
	targets.
	(process_event_stop_test): If stepping a permanent breakpoint
	doesn't hit the step-resume breakpoint, delete the step-resume
	breakpoint.
	(switch_back_to_stepped_thread): Also check if the stepped thread
	has advanced already on hardware step targets.
	(currently_stepping): Return true if the thread stepped a
	breakpoint.

gdb/testsuite/
2014-11-12  Pedro Alves  <palves@redhat.com>

	* gdb.arch/i386-bp_permanent.c: New file.
	* gdb.arch/i386-bp_permanent.exp: Don't skip on x86_64.
	(srcfile): Set to i386-bp_permanent.c.
	(top level): Adjust to work in both 32-bit and 64-bit modes.  Test
	that stepi does not execute the 'leave' instruction, instead of
	testing it does execute.
	* gdb.base/bp-permanent.c: New file.
	* gdb.base/bp-permanent.exp: New file.
2014-11-12 10:39:00 +00:00
Pedro Alves 1a853c5224 make "permanent breakpoints" per location and disableable
"permanent"-ness is currently a property of the breakpoint.  But, it
should actually be an implementation detail of a _location_.  Consider
this bit in infrun.c:

  /* Normally, by the time we reach `resume', the breakpoints are either
     removed or inserted, as appropriate.  The exception is if we're sitting
     at a permanent breakpoint; we need to step over it, but permanent
     breakpoints can't be removed.  So we have to test for it here.  */
  if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here)
    {
      if (gdbarch_skip_permanent_breakpoint_p (gdbarch))
	gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
      else
	error (_("\
The program is stopped at a permanent breakpoint, but GDB does not know\n\
how to step past a permanent breakpoint on this architecture.  Try using\n\
a command like `return' or `jump' to continue execution."));
    }

This will wrongly skip a non-breakpoint instruction if we have a
multiple location breakpoint where the whole breakpoint was set to
"permanent" because one of the locations happened to be permanent,
even if the one GDB is resuming from is not.

Related, because the permanent breakpoints are only marked as such in
init_breakpoint_sal, we currently miss marking momentary breakpoints
as permanent.  A test added by a following patch trips on that.
Making permanent-ness be per-location, and marking locations as such
in add_location_to_breakpoint, the natural place to do this, fixes
this issue...

... and then exposes a latent issue with mark_breakpoints_out.  It's
clearing the inserted flag of permanent breakpoints.  This results in
assertions failing like this:

 Breakpoint 1, main () at testsuite/gdb.base/callexit.c:32
 32        return 0;
 (gdb) call callexit()
 [Inferior 1 (process 15849) exited normally]
 gdb/breakpoint.c:12854: internal-error: allegedly permanent breakpoint is not actually inserted
 A problem internal to GDB has been detected,
 further debugging may prove unreliable.

The call dummy breakpoint, which is a momentary breakpoint, is set on
top of a manually inserted breakpoint instruction, and so is now
rightfully marked as a permanent breakpoint.  See "Write a legitimate
instruction at the point where the infcall breakpoint is going to be
inserted." comment in infcall.c.

Re. make_breakpoint_permanent.  That's only called by solib-pa64.c.
Permanent breakpoints were actually originally invented for HP-UX [1].
I believe that that call (the only one in the tree) is unnecessary
nowadays, given that nowadays the core breakpoints code analyzes the
instruction under the breakpoint to automatically detect whether it's
setting a breakpoint on top of a breakpoint instruction in the
program.  I know close to nothing about HP-PA/HP-UX, though.

[1] https://sourceware.org/ml/gdb-patches/1999-q3/msg00245.html, and
    https://sourceware.org/ml/gdb-patches/1999-q3/msg00242.html

In addition to the per-location issue, "permanent breakpoints" are
currently always displayed as enabled=='n':

 (gdb) b main
 Breakpoint 3 at 0x40053c: file ../../../src/gdb/testsuite/gdb.arch/i386-permbkpt.S, line 29.
 (gdb) info breakpoints
 Num     Type           Disp Enb Address            What
 3       breakpoint     keep n   0x000000000040053c ../../../src/gdb/testsuite/gdb.arch/i386-permbkpt.S:29

But OTOH they're always enabled; there's no way to disable them...

In turn, this means that if one adds commands to such a breakpoint,
they're _always_ run:

 (gdb) start
 Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.arch/i386-permbkpt
 ...
 Temporary breakpoint 1, main () at ../../../src/gdb/testsuite/gdb.arch/i386-permbkpt.S:29
 29              int3
 (gdb) b main
 Breakpoint 2 at 0x40053c: file ../../../src/gdb/testsuite/gdb.arch/i386-permbkpt.S, line 29.
 (gdb) info breakpoints
 Num     Type           Disp Enb Address            What
 2       breakpoint     keep n   0x000000000040053c ../../../src/gdb/testsuite/gdb.arch/i386-permbkpt.S:29
 (gdb) commands
 Type commands for breakpoint(s) 2, one per line.
 End with a line saying just "end".
 >echo "hello!"
 >end
 (gdb) disable 2
 (gdb) start
 The program being debugged has been started already.
 Start it from the beginning? (y or n) y
 Temporary breakpoint 3 at 0x40053c: file ../../../src/gdb/testsuite/gdb.arch/i386-permbkpt.S, line 29.
 Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.arch/i386-permbkpt

 Breakpoint 2, main () at ../../../src/gdb/testsuite/gdb.arch/i386-permbkpt.S:29
 29              int3
 "hello!"(gdb)

IMO, one should be able to disable such a breakpoint, and GDB should
then behave just like if the user hadn't created the breakpoint in the
first place (that is, report a SIGTRAP).

By making permanent-ness a property of the location, and eliminating
the bp_permanent enum enable_state state ends up fixing that as well.

No tests are added for these changes yet; they'll be added in a follow
up patch, as skipping permanent breakpoints is currently broken and
trips on an assertion in infrun.

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/ChangeLog:
2014-11-12  Pedro Alves  <palves@redhat.com>

	Mark locations as permanent, not the whole breakpoint.
	* breakpoint.c (remove_breakpoint_1, remove_breakpoint): Adjust.
	(mark_breakpoints_out): Don't mark permanent breakpoints as
	uninserted.
	(breakpoint_init_inferior): Use mark_breakpoints_out.
	(breakpoint_here_p): Adjust.
	(bpstat_stop_status, describe_other_breakpoints): Remove handling
	of permanent breakpoints.
	(make_breakpoint_permanent): Mark each location as permanent,
	instead of marking the breakpoint.
	(add_location_to_breakpoint): If the location is permanent, mark
	it as such, and as inserted.
	(init_breakpoint_sal): Don't make the breakpoint permanent here.
	(bp_location_compare, update_global_location_list): Adjust.
	(update_breakpoint_locations): Don't make the breakpoint permanent
	here.
	(disable_breakpoint, enable_breakpoint_disp): Don't skip permanent
	breakpoints.
	* breakpoint.h (enum enable_state) <bp_permanent>: Delete field.
	(struct bp_location) <permanent>: New field.
	* guile/scm-breakpoint.c (bpscm_enable_state_to_string): Remove
	reference to bp_permanent.
2014-11-12 10:37:57 +00:00
Pedro Alves ae9bb220ca add a default method for gdbarch_skip_permanent_breakpoint
breakpoint.c uses gdbarch_breakpoint_from_pc to determine whether a
breakpoint location points at a permanent breakpoint:

 static int
 bp_loc_is_permanent (struct bp_location *loc)
 {
 ...
   addr = loc->address;
   bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
 ...
  if (target_read_memory (loc->address, target_mem, len) == 0
      && memcmp (target_mem, bpoint, len) == 0)
    retval = 1;
 ...

So I think we should default the gdbarch_skip_permanent_breakpoint
hook to advancing the PC by the length of the breakpoint instruction,
as determined by gdbarch_breakpoint_from_pc.  I believe that simple
implementation does the right thing for most architectures.  If
there's an oddball architecture where that doesn't work, then it
should override the hook, just like it should be overriding the hook
if there was no default anyway.

The only two implementation of skip_permanent_breakpoint are
i386_skip_permanent_breakpoint, for x86, and
hppa_skip_permanent_breakpoint, for PA-RISC/HP-UX

The x86 implementation is trivial, and can clearly be replaced by the
new default.

I don't know about the HP-UX one though, I know almost nothing about
PA.  It may well be advancing the PC ends up being equivalent.
Otherwise, it must be that "jump $pc_after_bp" doesn't work either...

Tested on x86_64 Fedora 20 native and gdbserver.

gdb/
2014-11-12  Pedro Alves  <palves@redhat.com>

	* arch-utils.c (default_skip_permanent_breakpoint): New function.
	* arch-utils.h (default_skip_permanent_breakpoint): New
	declaration.
	* gdbarch.sh (skip_permanent_breakpoint): Now an 'f' function.
	Install default_skip_permanent_breakpoint as default method.
	* i386-tdep.c (i386_skip_permanent_breakpoint): Delete function.
	(i386_gdbarch_init): Don't install it.
	* infrun.c (resume): Assume there's always a
	gdbarch_skip_permanent_breakpoint implementation.
	* gdbarch.h, gdbarch.c: Regenerate.
2014-11-12 10:32:53 +00:00
Daniel Colascione 015de6884f Warn users about mismatched PID namespaces
Linux supports multiple "PID namespaces".  Processes in different PID
namespaces have different views of the system process list.  Sometimes,
a single process can appear in more than one PID namespace, but with a
different PID in each.  When GDB and its target are in different PID
namespaces, various features can break due to the mismatch between
what the target believes its PID to be and what GDB believes its PID
to be.  The most visible broken functionality is thread enumeration
silently failing.

This patch explicitly warns users against trying to debug across PID
namespaces.

The patch introduced no new failures in my test suite run on an x86_64
installation of Ubuntu 14.10.  It doesn't include a test: writing an
automated test that exercises this code would be very involved because
CLONE_NEWNS requires CAP_SYS_ADMIN; the easier way to reproduce the
problem is to start a new lxc container.

gdb/
2014-11-11  Daniel Colascione  <dancol@dancol.org>

	Warn about cross-PID-namespace debugging.
	* nat/linux-procfs.h (linux_proc_pid_get_ns): New prototype.
	* nat/linux-procfs.c (linux_proc_pid_get_ns): New function.
	* linux-thread-db.c (check_pid_namespace_match): New function.
	(thread_db_inferior_created): Call it.
2014-11-11 14:18:23 +00:00
Doug Evans 26a8485972 symmisc.c: Remove trailing whitespace.
gdb/ChangeLog:

	* symmisc.c (print_objfile_statistics): Remove trailing whitespace.
	(maintenance_info_symtabs, maintenance_check_symtabs): Ditto.
2014-11-10 17:19:57 -08:00