binutils-gdb/gdb/testsuite/gdb.base
Pedro Alves 08351840ea Stale breakpoint instructions, spurious SIGTRAPS.
Without the code portion of the patch, we get these failures:

 FAIL: gdb.base/break-unload-file.exp: always-inserted on: break: continue
 FAIL: gdb.base/break-unload-file.exp: always-inserted on: hbreak: continue
 FAIL: gdb.base/sym-file.exp: stale bkpts: continue to breakpoint: end here

They all looks like random SIGTRAPs:

 continue
 Continuing.

 Program received signal SIGTRAP, Trace/breakpoint trap.
 0x0000000000400541 in foo () at ../../../src/gdb/testsuite/gdb.base/break-unload-file.c:21
 21      }
 (gdb) FAIL: gdb.base/break-unload-file.exp: always-inserted on: break: continue

(This is a regression caused by the remove-symbol-file command
series.)

break-unload-file.exp is about having breakpoints inserted, and then
doing "file".  I caught this while writing a test that does "file
PROGRAM", while PROGRAM was already loaded, which internally does
"file" first, because I wanted to force a breakpoint_re_set, but the
test is more explicit in case GDB ever optimizes out that re-set.

The problem is that unloading the file with "file" ends up in
disable_breakpoints_in_freed_objfile, which marks all breakpoint
locations of the objfile as both shlib_disabled, _and_ clears the
inserted flag, without actually removing the breakpoints from the
inferior.  Now, usually, in all-stop, breakpoints will already be
removed from the inferior before the user can issue the "file"
command, but, with non-stop, or breakpoints always-inserted on mode,
breakpoints stay inserted even while the user has the prompt.  In the
latter case, then, if we let the program continue, and it executes the
address where we had previously set the breakpoint, it'll actually
execute the breakpoint instruction that we left behind...

Now, one issue is that the intent of
disable_breakpoints_in_freed_objfile is really to handle the unloading
of OBJF_USERLOADED objfiles.  These are objfiles that were added with
add-symbol-file and that are removed with remove-symbol-file.

"add-symbol-file"'s docs in the manual clearly say these commands are
used to let GDB know about dynamically loaded code:

 You would use this command when @var{filename} has been dynamically
 loaded (by some other means) into the program that is running.

Similarly, the online help says:

 (gdb) help add-symbol-file
 Load symbols from FILE, assuming FILE has been dynamically loaded.

So it makes sense to, like when shared libraries are unloaded through
the generic solib machinery, mark the breakpoint locations as
shlib_disabled.  But, the "file" command is not about dynamically
loaded code, it's about the main program.  So the patch makes
disable_breakpoints_in_freed_objfile skip all objfiles but
OBJF_USERLOADED ones, thus skipping the main objfile.

Then, the reason that disable_breakpoints_in_freed_objfile was
clearing the inserted flag isn't clear, but likely to avoid breakpoint
removal errors, assuming remove-symbol-file was called after the
dynamic object was already unmapped from the inferior.  In that case,
it'd okay to simply clear the inserted flag, but not so if the user
for example does remove-symbol-file to remove the library because he
made a mistake in the library's address, and wants to re-do
add-symbol-file with the correct address.

To address all that, I propose an alternative implementation, that
handles both cases.  The patch includes changes to sym-file.exp to
cover them.

This implementation leaves the inserted flag alone, and handles
breakpoint insertion/removal failure gracefully when the locations are
in OBJF_USERLOADED objfiles, just like we handle insertion/removal
failure gracefully for locations in shared libraries.

To try to make sure we aren't patching back stale shadow memory
contents into the inferior, in case the program mapped a different
library at the same address where we had the breakpoint, without the
user having had a chance of remove-symbol-file'ing before, this adds a
new memory_validate_breakpoint function that checks if the breakpoint
instruction is still in memory.  ppc_linux_memory_remove_breakpoint
does this unconditionally for all memory breakpoints, and questions
whether memory_remove_breakpoint should be changed to do this for all
breakpoints.  Possibly yes, though I'm not certain, hence this
baby-steps patch.

Tested on x86_64 Fedora 17, native and gdbserver.

gdb/
2014-04-23  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (insert_bp_location): Tolerate errors if the
	breakpoint is set in a user-loaded objfile.
	(remove_breakpoint_1): Likewise.  Also tolerate errors if the
	location is marked shlib_disabled.  If the breakpoint is set in a
	user-loaded objfile is a GDB-side memory breakpoint, validate it
	before uninsertion.  (disable_breakpoints_in_freed_objfile): Skip
	non-OBJF_USERLOADED objfiles.  Don't clear the location's inserted
	flag.
	* mem-break.c (memory_validate_breakpoint): New function.
	* objfiles.c (userloaded_objfile_contains_address_p): New
	function.
	* objfiles.h (userloaded_objfile_contains_address_p): Declare.
	* target.h (memory_validate_breakpoint): New declaration.

gdb/testsuite/
2014-04-23  Pedro Alves  <palves@redhat.com>

	* gdb.base/break-unload-file.c: New file.
	* gdb.base/break-unload-file.exp: New file.
	* gdb.base/sym-file-lib.c (baz): New function.
	* gdb.base/sym-file-loader.c (struct segment) <mapped_size>: New
	field.
	(load): Store the segment's mapped size.
	(unload): New function.
	(unload_shlib): New function.
	* gdb.base/sym-file-loader.h (unload_shlib): New declaration.
	* gdb.base/sym-file-main.c (main): Unload, and reload the library,
	set a breakpoint at baz, and call it.
	* gdb.base/sym-file.exp: New tests for stale breakpoint
	instructions.
2014-04-23 15:09:27 +01:00
..
comp-dir/subdir
a2-run.exp
advance.c
advance.exp
alias.exp
all-bin.exp
all-types.c
annota1.c
annota1.exp
annota3.c
annota3.exp
anon.c
anon.exp
args.c
args.exp
argv0-symlink.c
argv0-symlink.exp
arithmet.exp
arrayidx.c
arrayidx.exp
assign.exp
async-shell.c
async-shell.exp
async.c gdb.base/async.exp: Fix stepi& test. 2014-03-19 15:50:53 +00:00
async.exp gdb.base/async.exp: Enable it. 2014-03-19 15:55:06 +00:00
attach2.c
attach-pie-misread.c
attach-pie-misread.exp
attach-pie-noexec.c
attach-pie-noexec.exp
attach-twice.c
attach-twice.exp
attach.c
attach.exp Fix internal warning when "gdb -p xxx" 2014-03-21 11:23:06 +08:00
auto-load-script
auto-load.c
auto-load.exp
auxv.c
auxv.exp
average.c
bang.exp
bar.c
baz.c
bfp-test.c
bfp-test.exp
bigcore.c
bigcore.exp
bitfields2.c
bitfields2.exp
bitfields.c
bitfields.exp
bitops.exp
branches.c
break1.c
break-always.c
break-always.exp
break-caller-line.c
break-caller-line.exp
break-entry.exp
break-inline.c
break-inline.exp
break-interp-lib.c
break-interp-main.c
break-interp.exp
break-on-linker-gcd-function.cc
break-on-linker-gcd-function.exp
break-probes-solib.c
break-probes.c
break-probes.exp
break-unload-file.c Stale breakpoint instructions, spurious SIGTRAPS. 2014-04-23 15:09:27 +01:00
break-unload-file.exp Stale breakpoint instructions, spurious SIGTRAPS. 2014-04-23 15:09:27 +01:00
break.c
break.exp
breakpoint-shadow.c
breakpoint-shadow.exp PR gdb/16575: stale breakpoint instructions in the code cache 2014-03-05 14:18:28 +00:00
call-ar-st.c
call-ar-st.exp
call-rt-st.c
call-rt-st.exp
call-sc.c
call-sc.exp
call-signal-resume.exp
call-signals.c
call-strs.c
call-strs.exp
callexit.c
callexit.exp
callfuncs.c
callfuncs.exp
catch-load-so.c
catch-load.c
catch-load.exp
catch-signal-fork.c
catch-signal-fork.exp
catch-signal.c
catch-signal.exp
catch-syscall.c
catch-syscall.exp
charset-malloc.c
charset.c
charset.exp
checkpoint.c
checkpoint.exp
chng-syms.c
chng-syms.exp
code_elim1.c
code_elim2.c
code_elim.exp
code-expr.exp
commands.exp
completion.exp Check file exists before completion tests 2014-04-11 12:54:09 +08:00
complex.c
complex.exp
comprdebug.exp
cond-eval-mode.c Conditional Z1 breakpoint hangs GDBserver. 2014-04-10 17:14:12 +01:00
cond-eval-mode.exp Conditional Z1 breakpoint hangs GDBserver. 2014-04-10 17:14:12 +01:00
cond-expr.exp
condbreak-call-false.c make dprintf.exp pass in target async mode 2014-03-20 17:49:51 +00:00
condbreak-call-false.exp make dprintf.exp pass in target async mode 2014-03-20 17:49:51 +00:00
condbreak.exp
consecutive-step-over.c Consecutive step-overs trigger internal error. 2014-04-22 19:21:16 +01:00
consecutive-step-over.exp Consecutive step-overs trigger internal error. 2014-04-22 19:21:16 +01:00
consecutive.c
consecutive.exp
constvars.c
constvars.exp
corefile.exp fix regressions with target-async 2014-03-12 13:05:58 -06:00
coremaker2.c
coremaker.c
ctxobj-f.c
ctxobj-m.c
ctxobj-v.c
ctxobj.exp
cursal.c
cursal.exp
cvexpr.c
cvexpr.exp
d10v.ld
d10vovly.c
dbx.exp
debug-expr.c
debug-expr.exp
default.exp Rename Solaris's target to "target child" like most other ports. 2014-03-13 12:30:38 +00:00
define.exp
del.c
del.exp
detach.exp
dfp-exprs.exp
dfp-test.c
dfp-test.exp
disabled-location.c
disabled-location.exp
disasm-end-cu-1.c
disasm-end-cu-2.c
disasm-end-cu.exp
disp-step-fork.c
disp-step-syscall.exp
disp-step-vfork.c
display.c
display.exp
dmsym_main.c
dmsym.c
dmsym.exp
dprintf-next.c
dprintf-next.exp
dprintf-non-stop.c
dprintf-non-stop.exp
dprintf-pending.c
dprintf-pending.exp
dprintf-pendshr.c
dprintf.c
dprintf.exp Fix PR breakpoints/16101: gdb.base/dprintf.exp agent-printf failures with non-Z0-supporting gdbservers 2014-03-24 19:30:50 +00:00
dump.c
dump.exp
dup-sect.exp
dup-sect.S
duplicate-bp.c
duplicate-bp.exp
echo.exp
empty_exe.exp
ena-dis-br.exp
ending-run.c
ending-run.exp
enum_cond.c
enum_cond.exp
enumval.c
enumval.exp
environ.exp
eu-strip-infcall.c
eu-strip-infcall.exp
eval-avoid-side-effects.exp
eval-skip.exp
eval.exp
exe-lock.exp
execd-prog.c
exitsignal.exp
expand-psymtabs.c
expand-psymtabs.exp
exprs.c
exprs.exp
fileio.c
fileio.exp
filesym.c
filesym.exp Skip tests on completion and readline when readline lib isn't used 2014-03-26 21:11:08 +08:00
find-unmapped.c
find-unmapped.exp
find.c
find.exp
finish.exp
fixsection.c
fixsection.exp
fixsectshr.c
float.c
float.exp
foll-exec.c
foll-exec.exp
foll-fork.c
foll-fork.exp
foll-vfork-exit.c
foll-vfork.c
foll-vfork.exp
foo.c
fortran-sym-case.c
fortran-sym-case.exp
frame-args.c
frame-args.exp
freebpcmd.c
freebpcmd.exp
fullname.c
fullname.exp
fullpath-expand-func.c
fullpath-expand.c
fullpath-expand.exp
func-ptr.c
func-ptr.exp
funcargs.c
funcargs.exp
gcore-buffer-overflow.c
gcore-buffer-overflow.exp
gcore-relro-lib.c
gcore-relro-main.c
gcore-relro-pie.c
gcore-relro-pie.exp
gcore-relro.exp
gcore.c
gcore.exp
gdb1056.exp
gdb1090.c
gdb1090.exp
gdb1250.c
gdb1250.exp
gdb1555-main.c
gdb1555.c
gdb1555.exp
gdb1821.c
gdb1821.exp
gdb11530.c
gdb11530.exp
gdb11531.c
gdb11531.exp
gdb_history
gdb-sigterm.c Fix SIGTERM signal safety (PR gdb/15358). 2014-03-18 22:48:06 +01:00
gdb-sigterm.exp testsuite: Remove needless linux-nat requirement in gdb-sigterm.exp. 2014-03-24 17:37:32 +01:00
gdbindex-stabs-dwarf.c
gdbindex-stabs.c
gdbindex-stabs.exp
gdbvars.c
gdbvars.exp
gnu_vector.c
gnu_vector.exp
gnu-debugdata.c
gnu-debugdata.exp
gnu-ifunc-lib.c
gnu-ifunc.c
gnu-ifunc.exp
grbx.c
hashline1.exp
hashline2.exp
hashline3.exp
hbreak2.exp
hbreak-in-shr-unsupported-shr.c Don't suppress errors inserting/removing hardware breakpoints in shared 2014-04-23 15:06:47 +01:00
hbreak-in-shr-unsupported.c Don't suppress errors inserting/removing hardware breakpoints in shared 2014-04-23 15:06:47 +01:00
hbreak-in-shr-unsupported.exp Don't suppress errors inserting/removing hardware breakpoints in shared 2014-04-23 15:06:47 +01:00
hbreak-unmapped.c Don't suppress errors inserting/removing hardware breakpoints in shared 2014-04-23 15:06:47 +01:00
hbreak-unmapped.exp Don't suppress errors inserting/removing hardware breakpoints in shared 2014-04-23 15:06:47 +01:00
hbreak.c
hbreak.exp
help.exp
hook-stop-continue.c
hook-stop-continue.exp
hook-stop-frame.c
hook-stop-frame.exp
huge.c
huge.exp
ifelse.exp
included.c
included.exp
included.h
inferior-died.c
inferior-died.exp
infnan.c
infnan.exp
info-fun-solib.c
info-fun.c
info-fun.exp
info-macros.c
info-macros.exp
info-os.c
info-os.exp
info-proc.exp
info-shared-solib1.c
info-shared-solib2.c
info-shared.c
info-shared.exp
info-target.exp
infoline.c
infoline.exp
int-type.c
interact.exp
interp.c
interp.exp
interrupt-noterm.c
interrupt-noterm.exp
interrupt.c
interrupt.exp
jit-dlmain.c
jit-main.c
jit-simple.c
jit-simple.exp
jit-so.exp
jit-solib.c
jit.exp
jump.c
jump.exp
kill-after-signal.c
kill-after-signal.exp
label.c
label.exp
langs0.c
langs1.c
langs1.f
langs2.c
langs2.cxx
langs.exp
ldbl_e308.c
ldbl_e308.exp
lineinc1.h
lineinc2.h
lineinc3.h
lineinc.c
lineinc.exp
linespecs.exp
list0.c
list0.h
list1.c
list.exp
logical.exp
long_long.c
long_long.exp
longest-types.c
longest-types.exp
longjmp.c
longjmp.exp
m32r.ld
m32rovly.c
macscp1.c
macscp2.h
macscp3.h
macscp4.h
macscp.exp Skip tests on completion and readline when readline lib isn't used 2014-03-26 21:11:08 +08:00
maint.exp
Makefile.in
memattr.c
memattr.exp gdb.base/memattr.exp regexp improvements. 2014-04-16 17:42:29 +01:00
mips_pro.c
mips_pro.exp
miscexprs.c
miscexprs.exp
morestack.c
morestack.exp
moribund-step.exp
multi-forks.c
multi-forks.exp
nextoverexit.c
nextoverexit.exp
nodebug.c
nodebug.exp
nofield.c
nofield.exp
normal.c
nostdlib.c
nostdlib.exp
opaque0.c
opaque1.c
opaque.exp
overlays.c
overlays.exp
ovlymgr.c
ovlymgr.h
page.exp
pc-fp.c
pc-fp.exp
pending.c
pending.exp
pendshr.c
permissions.exp
pi.txt
pie-execl.c
pie-execl.exp
pointers.c
pointers.exp
pr10179-a.c
pr10179-b.c
pr10179.exp
pr11022.c
pr11022.exp
prelink-lib.c
prelink.c
prelink.exp
print-file-var-lib1.c
print-file-var-lib2.c
print-file-var-main.c
print-file-var.exp
print-symbol-loading-lib.c New option "set print symbol-loading". 2014-03-31 12:07:48 -07:00
print-symbol-loading-main.c New option "set print symbol-loading". 2014-03-31 12:07:48 -07:00
print-symbol-loading.exp New option "set print symbol-loading". 2014-03-31 12:07:48 -07:00
printcmds.c
printcmds.exp [testsuite] Set target-charset to ascii 2014-04-17 10:33:19 +08:00
prologue-include.c
prologue-include.exp
prologue-include.h
prologue.c
prologue.exp
psymtab1.c
psymtab2.c
psymtab.exp
ptr-typedef.c
ptr-typedef.exp
ptype1.c
ptype.c
ptype.exp
radix.exp
random-signal.c
random-signal.exp
randomize.c
randomize.exp
range-stepping.c
range-stepping.exp
readline-ask.c
readline-ask.exp Skip tests on completion and readline when readline lib isn't used 2014-03-26 21:11:08 +08:00
readline-ask.inputrc
readline.exp Skip tests on completion and readline when readline lib isn't used 2014-03-26 21:11:08 +08:00
realname-expand-real.c
realname-expand.c
realname-expand.exp
recpar.c
recpar.exp
recurse.c
recurse.exp
relational.exp
relativedebug.c
relativedebug.exp
relocate.c
relocate.exp
remote.c
remote.exp
remotetimeout.exp
reread1.c
reread2.c
reread.exp
restore.c
restore.exp
return2.c
return2.exp
return-nodebug1.c
return-nodebug.c
return-nodebug.exp
return.c
return.exp
run.c
save-bp.c
save-bp.exp
savedregs.c
savedregs.exp
scope0.c
scope1.c
scope.exp
sect-cmd.exp
segv.c
sep-proc.c
sep.c
sep.exp
sepdebug2.c
sepdebug.c
sepdebug.exp
sepsymtab.c
sepsymtab.exp
set-lang-auto.exp
set-noassign.exp
setshow.c
setshow.exp Escape backslash in windows path 2014-04-03 14:51:40 +08:00
setvar.c
setvar.exp [testsuite] Set target-charset to ascii 2014-04-17 10:33:19 +08:00
shell.exp
shlib-call.exp
shmain.c
shr1.c
shr2.c
shreloc1.c
shreloc2.c
shreloc.c
shreloc.exp
sigall.c
sigall.exp
sigaltstack.c
sigaltstack.exp
sigbpt.c
sigbpt.exp
sigchld.c
sigchld.exp
siginfo-addr.c
siginfo-addr.exp
siginfo-infcall.c
siginfo-infcall.exp
siginfo-obj.c
siginfo-obj.exp
siginfo-thread.c
siginfo-thread.exp
siginfo.c
siginfo.exp
signals.c
signals.exp
signest.c
signest.exp
signull.c
signull.exp
sigrepeat.c
sigrepeat.exp
sigstep.c
sigstep.exp
sizeof.c
sizeof.exp
skip1.c
skip-solib-lib.c
skip-solib-main.c
skip-solib.exp
skip.c
skip.exp
so-disc-shr.c
so-impl-ld.c
so-impl-ld.exp
so-indr-cl.c
so-indr-cl.exp
solib1.c
solib2.c
solib-corrupted.exp
solib-disc.c
solib-disc.exp
solib-display-lib.c
solib-display-main.c
solib-display.exp
solib-nodir.exp
solib-overlap-lib.c
solib-overlap-main.c
solib-overlap.exp
solib-search-lib1.c
solib-search-lib2.c
solib-search.c
solib-search.exp
solib-search.h
solib-symbol-lib.c
solib-symbol-main.c
solib-symbol.exp
solib-weak.c
solib-weak.exp
solib.c
solib.exp
source-dir.exp Allow ';' as a directory separator 2014-03-31 15:00:28 +08:00
source-error.gdb
source-execution.c "source", foreground execution commands, and target-async 2014-03-25 11:45:53 +00:00
source-execution.exp "source", foreground execution commands, and target-async 2014-03-25 11:45:53 +00:00
source-execution.gdb "source", foreground execution commands, and target-async 2014-03-25 11:45:53 +00:00
source-nofile.gdb
source-test.gdb
source.exp
spu.ld
ss.h
stack-checking.c
stack-checking.exp
stale-infcall.c
stale-infcall.exp
stap-probe.c
stap-probe.exp
start.c
start.exp
step-break.c
step-break.exp
step-bt.c
step-bt.exp
step-line.c
step-line.exp
step-line.inp
step-resume-infcall.c
step-resume-infcall.exp
step-symless.c
step-symless.exp
step-test.c
step-test.exp
store.c
store.exp
structs2.c
structs2.exp
structs3.c
structs3.exp
structs.c
structs.exp
subst.exp
sum.c
sym-file-lib.c Stale breakpoint instructions, spurious SIGTRAPS. 2014-04-23 15:09:27 +01:00
sym-file-loader.c Stale breakpoint instructions, spurious SIGTRAPS. 2014-04-23 15:09:27 +01:00
sym-file-loader.h Stale breakpoint instructions, spurious SIGTRAPS. 2014-04-23 15:09:27 +01:00
sym-file-main.c Stale breakpoint instructions, spurious SIGTRAPS. 2014-04-23 15:09:27 +01:00
sym-file.exp Stale breakpoint instructions, spurious SIGTRAPS. 2014-04-23 15:09:27 +01:00
symbol-without-target_section.c
symbol-without-target_section.exp
term.c
term.exp
testenv.c
testenv.exp
trace-commands.exp
tui-layout.exp
twice.c
twice.exp
type-opaque-lib.c
type-opaque-main.c
type-opaque.exp
ui-redirect.exp
unload.c
unload.exp
unloadshr2.c
unloadshr.c
until.exp
unwindonsignal.c
unwindonsignal.exp
valgrind-db-attach.c
valgrind-db-attach.exp
valgrind-infcall.c
valgrind-infcall.exp
value-double-free.c
value-double-free.exp
varargs.c
varargs.exp
vforked-prog.c
vla-datatypes.c test: basic c99 vla tests for C primitives 2014-04-14 09:27:42 -07:00
vla-datatypes.exp test: basic c99 vla tests for C primitives 2014-04-14 09:27:42 -07:00
vla-ptr.c test: evaluate pointers to C99 vla correctly. 2014-04-14 09:26:22 -07:00
vla-ptr.exp test: evaluate pointers to C99 vla correctly. 2014-04-14 09:26:22 -07:00
vla-sideeffect.c vla: evaluate operand of sizeof if its type is a vla 2014-04-14 09:21:46 -07:00
vla-sideeffect.exp vla: evaluate operand of sizeof if its type is a vla 2014-04-14 09:21:46 -07:00
volatile.exp
watch_thread_num.c
watch_thread_num.exp
watch-cond-infcall.c
watch-cond-infcall.exp
watch-cond.c
watch-cond.exp
watch-non-mem.c
watch-non-mem.exp
watch-read.c
watch-read.exp
watch-vfork.c
watch-vfork.exp
watchpoint-cond-gone-stripped.c
watchpoint-cond-gone.c
watchpoint-cond-gone.exp
watchpoint-delete.c
watchpoint-delete.exp
watchpoint-hw-hit-once.c
watchpoint-hw-hit-once.exp
watchpoint-hw.c
watchpoint-hw.exp
watchpoint-solib-shr.c
watchpoint-solib.c
watchpoint-solib.exp
watchpoint.c
watchpoint.exp PR breakpoints/7143 - Watchpoint does not trigger when first set 2014-03-20 13:41:08 +00:00
watchpoints.c
watchpoints.exp
wchar.c
wchar.exp
weaklib1.c
weaklib2.c
whatis-exp.exp
whatis.c
whatis.exp