A lot of cpu state is stored in global variables, as is memory handling.
The sim_size support needs unwinding at some point. But at least this
is an improvement on the status quo.
In preparation for converting to nrun, call the common functions that
are needed. This doesn't produce any new warnings, and the generated
code should be the same.
The sbrk syscall assumes the sbrk region starts after the bss and the
current implementation requires a bss section to exist. Since there
is no requirement for programs to have a bss in general, we want to
drop this check. However, there is still the sbrk syscall that wants
to know about the region.
Since libgloss doesn't actually use the sbrk syscall (it implements
sbrk in its own way), and the sim really shouldn't enforce a specific
memory layout on programs, lets simply delete sbrk support. Now it
always returns an error.
A lot of cpu state is stored in global variables, as is memory handling.
The sim_size support needs unwinding at some point. But at least this
is an improvement on the status quo.
The build line was missing the normal BUILD_xxx flags. Once we added
that, we get warnings that weren't shown before. As we fix those, we
notice that the -d option segfaults because it tries to write readonly
memory. Fix that too as part of the const/prototype clean up.
Simon Marchi:
I think this patch is wrong. Starting with that commit (f30d5c7),
some tests (e.g. mi-break.exp) started to fail for me, because
of gdb segfaulting.
The address of expr is passed to the cleanup. When the cleanup is ran,
expr is no longer in scope, so what is at that address is probably not
safe to use anymore. That's my guess.
gdb/ChangeLog
2015-03-27 Jan Kratochvil <jan.kratochvil@redhat.com>
Revert:
2015-03-26 Jan Kratochvil <jan.kratochvil@redhat.com>
Code cleanup.
* printcmd.c (print_command_1): Move expr variable scope.
GCC 4.4.7 generates the following warning:
| cc1: warnings being treated as errors
| dtrace-probe.c: In function ‘dtrace_process_dof_probe’:
| dtrace-probe.c:416: error: ‘expr’ may be used uninitialized in this function
| make[2]: *** [dtrace-probe.o] Error 1
Later versions (GCC 5) do a better job and don't generate the warning,
but it does not hurt to pre-initialize "expr" to NULL.
gdb/ChangeLog:
* dtrace-probe.c (dtrace_process_dof_probe): Initialize expr to NULL.
Indexes returned for special sections are off by one, i.e. with N+4
sections last one has index N+4 returned which is outside allocated
obstack (at the same time index N is not used at all).
In worst case, if sections obstack is allocated up to end of chunk,
writing last section data will cause buffer overrun and some data
corruption.
Here's output from Valgrind::
==14630== Invalid write of size 8
==14630== at 0x551B1A: add_to_objfile_sections_full (objfiles.c:225)
==14630== by 0x552768: allocate_objfile (objfiles.c:324)
==14630== by 0x4E8E2E: symbol_file_add_with_addrs (symfile.c:1171)
==14630== by 0x4E9453: symbol_file_add_from_bfd (symfile.c:1280)
==14630== by 0x4E9453: symbol_file_add (symfile.c:1295)
==14630== by 0x4E94B7: symbol_file_add_main_1 (symfile.c:1320)
==14630== by 0x514246: catch_command_errors_const (main.c:398)
==14630== by 0x5150AA: captured_main (main.c:1061)
==14630== by 0x51123C: catch_errors (exceptions.c:240)
==14630== by 0x51569A: gdb_main (main.c:1164)
==14630== by 0x408824: main (gdb.c:32)
==14630== Address 0x635f3b8 is 8 bytes after a block of size 4,064 alloc'd
==14630== at 0x4C2ABA0: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14630== by 0x60F797: xmalloc (common-utils.c:41)
==14630== by 0x5E787FB: _obstack_begin (obstack.c:184)
==14630== by 0x552679: allocate_objfile (objfiles.c:294)
==14630== by 0x4E8E2E: symbol_file_add_with_addrs (symfile.c:1171)
==14630== by 0x4E9453: symbol_file_add_from_bfd (symfile.c:1280)
==14630== by 0x4E9453: symbol_file_add (symfile.c:1295)
==14630== by 0x4E94B7: symbol_file_add_main_1 (symfile.c:1320)
==14630== by 0x514246: catch_command_errors_const (main.c:398)
==14630== by 0x5150AA: captured_main (main.c:1061)
==14630== by 0x51123C: catch_errors (exceptions.c:240)
==14630== by 0x51569A: gdb_main (main.c:1164)
==14630== by 0x408824: main (gdb.c:32)
gdb/ChangeLog:
* gdb_bfd.c (gdb_bfd_section_index): Fix off-by-one for special
sections.
Allows .dynbss copy of shared library protected visibility variables
if they are read-only.
To recap: Copying a variable from a shared library into an executable's
.dynbss is an old hack invented for non-PIC executables, to avoid the
text relocations you'd otherwise need to access a shared library
variable. This works with ELF shared libraries because global
symbols can be overridden. The trouble is that protected visibility
symbols can't be overridden. A shared library will continue to access
it's own protected visibility variable while the executable accesses a
copy. If either the shared library or the executable updates the
value then the copy diverges from the original. This is wrong since
there is only one definition of the variable in the application.
So I made the linker report an error on attempting to copy protected
visibility variables into .dynbss. However, you'll notice the above
paragraph contains an "If". An application that does not modify the
variable value remains correct even though two copies of the variable
exist. The linker can detect this situation if the variable was
defined in a read-only section.
PR ld/15228
PR ld/18167
* elflink.c (elf_merge_st_other): Add "sec" parameter. Don't set
protected_def when symbol section is read-only. Adjust all calls.
* elf-bfd.h (struct elf_link_hash_entry): Update protected_def comment.
Exactly like x86_64-*-mingw, SYMBOL_PREFIX should not be set to "_" for
x86_64_*_cygwin
gdb/testuite/ChangeLog:
* lib/gdb.exp (gdb_target_symbol_prefix_flags): Don't set
SYMBOL_PREFIX for x86_64-*-cygwin.
The debugger on Solaris has been broken since the introduction of
DTrace probe support:
(gdb) start
Temporary breakpoint 1 at 0x80593bc: file simple_main.adb, line 4.
Starting program: /[...]/simple_main
[Thread debugging using libthread_db enabled]
No definition of "mutex_t" in current context.
The problem occurs while trying to parse a probe's argument,
and the exception propagates all the way to the top. This patch
fixes the issue by containing the exception and falling back on
using the "long" builtin type if the argument's type could not
be determined.
Also, the parsing should be done using the C language parser.
gdb/ChangeLog:
* dtrace-probe.c (dtrace_process_dof_probe): Contain any
exception raised while parsing the probe arguments.
Force parsing to be done using the C language parser.
* expression.h (parse_expression_with_language): Declare.
* parse.c (parse_expression_with_language): New function.
Variables with a DW_AT_const_value but without a DW_AT_location were not
getting added to the partial symbol table. They are added to the full
symbol table, however, when the compilation unit's psymtabs are
expanded.
Before:
(gdb) p one
No symbol "one" in current context.
(gdb) mt flush-symbol-cache
(gdb) mt expand one.c
(gdb) p one
$1 = 1
After:
(gdb) p one
$1 = 1
To the user it's pretty strange, as depending on whether tab completion
has forced expansion of all CUs or not the lookup might succeed, or not
if the failure was already added to the symbol cache.
This commit simply makes sure to add constants to the partial symbol
tables.
gdb/testsuite/ChangeLog:
PR symtab/18148
* gdb.dwarf2/dw2-intercu.S (one, two): Add variables that have a
const_value but not a location.
* gdb.dwarf2/dw2-intercu.exp: Add tests that constants without
location defined in non-main CUs are visible.
gdb/ChangeLog:
PR symtab/18148
* dwarf2read.c (struct partial_die_info): Add has_const_value
member.
(add_partial_symbol): Don't punt on symbols that have const_value
attributes.
(read_partial_die): Detect DW_AT_const_value.
On Windows amd64, setting a breakpoint on a symbol imported from a
shared library after that library is loaded creates a breakpoint with
two locations, one on the import stub, and another in the shared
library, while on i386, the breakpoint is only set in the shared
library.
This is due to the minimal symbol for the import stub not being
correctly given the type mst_solib_trampoline on Windows amd64, unlike
Windows i386.
As currently written, coff_symfile_read is always skipping over the
character after the "__imp_" (amd64) or "_imp_" (i386) prefix,
assuming that it is '_'. However, while i386 is an underscored
target, amd64 is not.
On x86_64-pc-cygwin, it fixes:
- FAIL: gdb.base/solib-symbol.exp: foo in libmd
+ PASS: gdb.base/solib-symbol.exp: foo in libmd
Unfortunately, several other tests which passed now fail but that's
because this issue was masking other problems.
No change on i686-pc-cygwin.
gdb/ChangeLog:
2015-03-26 Pedro Alves <palves@redhat.com>
Jon TURNEY <jon.turney@dronecode.org.uk>
* coffread.c (coff_symfile_read): When constructing the name of an
import stub symbol from import symbol for amd64, only skip the
char after _imp_ if the target is underscored (like i386) and the
char is indeed the target's leading char.
break-asm-file.exp has some manually written dwarf to create some line
number entries like this,
[0x0000013d] Extended opcode 2: set Address to 0x40053f
[0x00000144] Advance Line by 4 to 7
[0x00000146] Copy
[0x00000147] Extended opcode 2: set Address to 0x400541
[0x0000014e] Advance Line by 1 to 8
[0x00000150] Copy
[0x00000151] Extended opcode 2: set Address to 0x400547
[0x00000158] Extended opcode 1: End of Sequence
0x40053f is the start address of function func, and is mapped to line
7. 0x400541 is within function func, and is mapped to line 8.
(gdb) disassemble /r 0x40053f,+8
Dump of assembler code from 0x40053f to 0x400547:
0x000000000040053f <func+0>: 00 00 add %al,(%rax)
0x0000000000400541 <func+2>: 00 00 add %al,(%rax)
0x0000000000400543 <func+4>: 00 00 add %al,(%rax)
0x0000000000400545 <func+6>: 00 00 add %al,(%rax)
in the following test,
(gdb) break a/break-asm-file0.s:func
Breakpoint 1 at 0x40053f: file a/break-asm-file0.s, line 7.
As we can see, breakpoint is set at the start address of function func
on x86, which means no prologue is skipped. On other targets, such as
arm and aarch64, breakpoint is set at the address *after* the start
address, which is mapped to line 8. Then test fails.
In fact, it is lucky this test doesn't fail on x86 and x86_64, whose
gdbarch method skip_prologue doesn't reply on skip_prologue_using_sal
if producer isn't clang.
if (find_pc_partial_function (start_pc, NULL, &func_addr, NULL))
{
CORE_ADDR post_prologue_pc
= skip_prologue_using_sal (gdbarch, func_addr);
struct compunit_symtab *cust = find_pc_compunit_symtab (func_addr);
/* Clang always emits a line note before the prologue and another
one after. We trust clang to emit usable line notes. */
if (post_prologue_pc
&& (cust != NULL
&& COMPUNIT_PRODUCER (cust) != NULL
&& startswith (COMPUNIT_PRODUCER (cust), "clang ")))
return max (start_pc, post_prologue_pc);
}
so it doesn't return and go further to prologue analyser. Since ".int 0"
isn't an instruction of prologue, nothing is skipped, starting address
is used, and test passes.
however, on targets which don't have such producer checking, the first
line number entry is skipped, and skip_prologue_using_sal returns sal
represents the second line number entry.
The idea of this patch is to force GDB stop at somewhere which is stilled
mapped to line 7 after skipping prologue. I choose to add a new line
number entry for the following instruction but mapped to the same line (7),
because I see the comments in dwarf2read.c,
... fact that two consecutive
line number entries for the same line is a heuristic used by gcc
to denote the end of the prologue.
then the line table becomes:
[0x000000d4] Extended opcode 2: set Address to 0x400529
[0x000000db] Advance Line by 4 to 7
[0x000000dd] Copy
[0x000000de] Extended opcode 2: set Address to 0x40052a
[0x000000e5] Advance Line by 0 to 7
[0x000000e7] Copy
[0x000000e8] Extended opcode 2: set Address to 0x40052b
[0x000000ef] Advance Line by 1 to 8
[0x000000f1] Copy
[0x000000f2] Extended opcode 2: set Address to 0x40052c
[0x000000f9] Extended opcode 1: End of Sequence
gdb/testsuite:
2015-03-26 Yao Qi <yao.qi@linaro.org>
PR testsuite/18139
* gdb.linespec/break-asm-file0.s (func): New label .Lfunc_2.
Add a line number entry for the same line.
* gdb.linespec/break-asm-file1.s (func): New label .Lfunc_2.
Add a line number entry for the same line.
There are some hard-coded stuff in .s files, such as .int 0 and
address offset, which isn't portable. This patch is to replace
".int 0" with nop and address offset with labels.
gdb/testsuite:
2015-03-26 Yao Qi <yao.qi@linaro.org>
* gdb.linespec/break-asm-file0.s (func2): Use nop instead of
.int 0.
(func): Likewise. Add .Lfunc_1 label.
Use .Lfunc_1 label.
* gdb.linespec/break-asm-file1.s (func3): Use nop instead of
.int 0.
(func): Likewise.
Use .Lfunc_1 label.
If I add some nop into break-asm-file1.s like this,
--- INDEX:/gdb/testsuite/gdb.linespec/break-asm-file1.s
+++ WORKDIR:/gdb/testsuite/gdb.linespec/break-asm-file1.s
@@ -31,8 +31,8 @@ _func:
.type func, %function
func:
.Lbegin_func:
- .int 0
- .int 0
+ nop
+ nop
.Lend_func:
.size func, .-func
.Lend_text1:
I get the following error:
Running gdb/testsuite/gdb.linespec/break-asm-file.exp ...
gdb/testsuite/gdb.linespec/break-asm-file1.s: Assembler messages:^M
gdb/testsuite/gdb.linespec/break-asm-file1.s: Fatal error: duplicate .debug_line sections
break-asm-file0.s and break-asm-file1.s have already had debug information
(written manually), so don't need to generate debug infor for them.
gdb/testsuite:
2015-03-26 Yao Qi <yao.qi@linaro.org>
* gdb.linespec/break-asm-file.exp: Don't call prepare_for_testing.
Call gdb_compile instead to compile each .s files without debug
information.
Hi,
I see the following two fails in gdb.base/savedregs.exp on aarch64-linux,
info frame 2^M
Stack frame at 0x7ffffffa60:^M
pc = 0x40085c in thrower (/home/yao/SourceCode/gnu/gdb/git/gdb/testsuite/gdb.base/savedregs.c:49); saved pc = 0x400898^M
called by frame at 0x7ffffffa70, caller of frame at 0x7fffffe800^M
source language c.^M
Arglist at 0x7ffffffa60, args: ^M
Locals at 0x7ffffffa60, Previous frame's sp is 0x7ffffffa60^M
(gdb) FAIL: gdb.base/savedregs.exp: Get thrower info frame
info frame 2^M
Stack frame at 0x7fffffe800:^M
pc = 0x400840 in catcher (/home/yao/SourceCode/gnu/gdb/git/gdb/testsuite/gdb.base/savedregs.c:42); saved pc = 0x7fb7ffc350^M
called by frame at 0x7fffffe800, caller of frame at 0x7fffffe7e0^M
source language c.^M
Arglist at 0x7fffffe7f0, args: sig=11^M
Locals at 0x7fffffe7f0, Previous frame's sp is 0x7fffffe800
(gdb) FAIL: gdb.base/savedregs.exp: Get catcher info frame
looks the test expects to match "Saved registers:" from the output of
"info frame", but no registers are saved on these two frames, because
thrower and catcher are simple and leaf functions.
(gdb) disassemble thrower
Dump of assembler code for function thrower:
0x0000000000400858 <+0>: mov x0, #0x0 // #0
0x000000000040085c <+4>: strb wzr, [x0]
0x0000000000400860 <+8>: ret
End of assembler dump.
(gdb) disassemble catcher
Dump of assembler code for function catcher:
0x0000000000400838 <+0>: sub sp, sp, #0x10
0x000000000040083c <+4>: str w0, [sp,#12]
0x0000000000400840 <+8>: adrp x0, 0x410000
0x0000000000400844 <+12>: add x0, x0, #0xb9c
0x0000000000400848 <+16>: mov w1, #0x1 // #1
0x000000000040084c <+20>: str w1, [x0]
0x0000000000400850 <+24>: add sp, sp, #0x10
0x0000000000400854 <+28>: ret
There are two ways to fix these fails, one is to modify functions to
force some registers saved (for example, doing function call in them),
and the other one is to relax the pattern to optionally match
"Saved registers:". I did both, and feel that the latter is simple,
so here is it.
gdb/testsuite:
2015-03-26 Yao Qi <yao.qi@linaro.org>
* gdb.base/savedregs.exp (process_saved_regs): Make
"Saved registers:" optional in the pattern.
The gdb TUI is calling gdb_print_insn() (which calls
disassemble_init_powerpc()) enough to show up high in profiles. As
suggested by Alan, only initialise if the indices are empty.
opcodes/ChangeLog:
2015-03-25 Anton Blanchard <anton@samba.org>
* ppc-dis.c (disassemble_init_powerpc): Only initialise
powerpc_opcd_indices and vle_opcd_indices once.
Ensure that injection of a stub section does not break a link where
there is an xpectation that flow of control can pass from one input
section to another simply by linking the input sections in series.
The solution here is to allow stub sections to be inserted after any
input section (existing behaviour), but inject an additional branch at
the start of each stub section such that control flow falling into the
stub section will branch over the stub section.