binutils-gdb/gdbsupport
Simon Marchi 4d7188abfd gdbsupport: add debug assertions in gdb::optional::get
The libstdc++ version of optional contains some runtime checks enabled
when _GLIBCXX_DEBUG is defined.  I think it would be useful if our
version contained similar checks.

Add checks in the two `get` methods, also conditional on _GLIBCXX_DEBUG.
I think it's simpler to use that macro rather than introducing a new
GDB-specific one, as I think that if somebody is interested in enabling
these runtime checks, they'll also be interested in enabling the
libstdc++ runtime checks (and vice-versa).

I implemented these checks using gdb_assert.  Note that gdb_assert
throws (after querying the user), and we are in noexcept methods.  That
means that std::terminate / abort will immediately be called.  I think
this is ok, since if those were "real" _GLIBCXX_DEBUG checks, abort
would be called straight away.

If I add a dummy failure, it looks like so:

    $ ./gdb -q -nx --data-directory=data-directory
    /home/simark/src/binutils-gdb/gdb/../gdbsupport/gdb_optional.h:206: internal-error: T& gdb::optional<T>::get() [with T = int]: Assertion `this->has_value ()' failed.
    A problem internal to GDB has been detected,
    further debugging may prove unreliable.
    Quit this debugging session? (y or n) n
    [1]    658767 abort (core dumped)  ./gdb -q -nx --data-directory=data-directory

Change-Id: Iadfdcd131425bd2ca6a2de30d7b22e9b3cc67793
2021-08-03 08:50:56 -04:00
..
.dir-locals.el
.gitattributes
acinclude.m4
aclocal.m4
agent.cc
agent.h
alt-stack.h
array-view.h
ax.def
block-signals.h
break-common.h
btrace-common.cc
btrace-common.h
buffer.cc
buffer.h
byte-vector.h
ChangeLog-2020-2021 gdb: move remaining ChangeLogs to legacy files 2021-07-26 12:20:33 +01:00
check-defines.el
cleanups.cc
cleanups.h
common-debug.cc
common-debug.h
common-defs.h [gdb/build] Disable attribute nonnull 2021-07-30 14:07:40 +02:00
common-exceptions.cc
common-exceptions.h Replace exception_print_same with operator!= 2021-07-30 08:42:39 -06:00
common-gdbthread.h
common-inferior.cc
common-inferior.h gdb: make inferior::m_cwd an std::string 2021-07-23 15:38:54 -04:00
common-regcache.cc
common-regcache.h
common-types.h
common-utils.cc
common-utils.h
common.m4
config.in
configure
configure.ac
create-version.sh
def-vector.h
default-init-alloc.h
eintr.h
enum-flags.h
environ.cc
environ.h
errors.cc
errors.h
event-loop.cc
event-loop.h
fileio.cc
fileio.h
filestuff.cc
filestuff.h
filtered-iterator.h
format.cc
format.h
forward-scope-exit.h
function-view.h
gdb_assert.h
gdb_binary_search.h
gdb_locale.h
gdb_optional.h gdbsupport: add debug assertions in gdb::optional::get 2021-08-03 08:50:56 -04:00
gdb_proc_service.h
gdb_ref_ptr.h
gdb_select.h
gdb_setjmp.h
gdb_signals.h
gdb_splay_tree.h
gdb_string_view.h
gdb_string_view.tcc
gdb_sys_time.h
gdb_tilde_expand.cc
gdb_tilde_expand.h
gdb_unique_ptr.h
gdb_unlinker.h
gdb_vecs.cc
gdb_vecs.h
gdb_wait.cc
gdb_wait.h
gdb-dlfcn.cc
gdb-dlfcn.h
gdb-safe-ctype.h
gdb-sigmask.h
hash_enum.h
host-defs.h
intrusive_list.h gdb: use intrusive list for step-over chain 2021-07-12 20:46:52 -04:00
iterator-range.h gdb: introduce iterator_range, remove next_adapter 2021-07-06 15:02:05 -04:00
job-control.cc
job-control.h
Makefile.am
Makefile.in
netstuff.cc
netstuff.h
new-op.cc
next-iterator.h gdb: introduce iterator_range, remove next_adapter 2021-07-06 15:02:05 -04:00
observable.h
offset-type.h
parallel-for.h
pathstuff.cc
pathstuff.h
poison.h
preprocessor.h
print-utils.cc
print-utils.h
ptid.cc gdb: maintain per-process-target list of resumed threads with pending wait status 2021-07-12 20:46:53 -04:00
ptid.h gdb: maintain per-process-target list of resumed threads with pending wait status 2021-07-12 20:46:53 -04:00
ptrace.m4
README
refcounted-object.h
reference-to-pointer-iterator.h gdb: use intrusive list for step-over chain 2021-07-12 20:46:52 -04:00
rsp-low.cc
rsp-low.h
run-time-clock.cc
run-time-clock.h
safe-iterator.h gdb: make all_inferiors_safe actually work 2021-07-17 08:54:40 -04:00
safe-strerror.cc
scope-exit.h
scoped_fd.h
scoped_ignore_signal.h
scoped_ignore_sigttou.h
scoped_mmap.cc
scoped_mmap.h
scoped_restore.h
search.cc
search.h
selftest.cc
selftest.h
selftest.m4
signals-state-save-restore.cc
signals-state-save-restore.h
signals.cc
symbol.h
tdesc.cc
tdesc.h
thread-pool.cc
thread-pool.h
traits.h
underlying.h
valid-expr.h
version.h
warning.m4
x86-xstate.h
xml-utils.cc
xml-utils.h

This is a helper library that is used by gdb and gdbserver.

To send patches, follow the gdb patch submission instructions in
../gdb/CONTRIBUTE.  For maintainers, see ../gdb/MAINTAINERS.