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.
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.
PR binutils/17512
* peXXIgen.c (pe_print_pdata): Fail if the section's virtual size
is larger than its real size.
(rsrc_print_section): Fix off-by-one error checking for overflow.
* pei-x86_64.c (pex64_bfd_print_pdata): Handle empty unwind
sections.
* dwarf.c (get_encoded_value): Warn and return if the encoded
value is more than 64-bits long.
(SAFE_BYTE_GET): Do not attempt to read more than 64-bits.
(process_extended_line_op): Add more range checks.
(decode_location_expression): Use the return value from
display_block. Add more range checks.
(read_debug_line_header): Add range check.
(display_debug_lines_raw): Add range checks.
(display_debug_frames): Silently skip multiple zero terminators.
Add range checks.
(process_cu_tu_index): Check for non-existant or empty sections.
Use SAFE_BYTE_GET instead of byte_get.
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.
PR binutils/17531
* readelf.c (get_unwind_section_word): Skip reloc processing if
there are no relocs associated with the section.
(decode_tic6x_unwind_bytecode): Warn and return if the stack
pointer adjustment falls off the end of the buffer.
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.
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.
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.
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.
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.
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.
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.
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.
* x86_64.cc (Target_x86_64<size>::Scan::global): Don't make PLT
entry for R_X86_64_GOTPLT64.
(Target_x86_64<size>::Relocate::relocate): Update comments for
R_X86_64_GOTPLT64.
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.
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.
PR binutils/17512
* dwarf.c (get_encoded_value): Add an 'end' parameter. Change the
'data' parameter to a double pointer and return the updated value.
(decode_location_expression): Update call to get_encoded_value.
(frame_need_space): Handle the case where one or both of the
mallocs fails.
(read_cie): Initialise the cie pointer, even if the read fails.
(display_debug_frames): Warn if the calculated block_end is before
the start of the block. Break the loop if the CIE could not be
read. Update call to get_encoded_value. Warn if the read CFA
expressions are too big.
* ieee.c (ieee_archive_p) Skip processing if no bytes are read at
all.
(ieee_object_p): Likewise.
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.
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.
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.
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.
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.
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.