diff options
author | Pedro Alves <palves@redhat.com> | 2017-04-04 20:03:25 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2017-04-04 20:03:25 +0100 |
commit | ecfb656c37b982479d8eb07f240b434772d98fd6 (patch) | |
tree | e87a230ac686748f42607b24dadb075fc0c6becd /gdb/common | |
parent | d194f1fe51cb85b8a919b7ee9e3a7715b0ec9744 (diff) | |
download | gdb-ecfb656c37b982479d8eb07f240b434772d98fd6.zip gdb-ecfb656c37b982479d8eb07f240b434772d98fd6.tar.gz gdb-ecfb656c37b982479d8eb07f240b434772d98fd6.tar.bz2 |
dwarf2read.c: Make dir_index and file_name_index strong typedefs
This should help catch mistakes related to mixing the 1-based DWARF
indexes with 0-based std::vector indexes, since the new types do not
implicitly convert to anything.
The change in read_formatted_entries relates to the fact that doing
the seemingly simpler:
- uintp = &fe.dir_index;
+ uintp = (unsigned int *) &fe.dir_index;
would be undefined C/C++. So to address that, I made the function
extract the form before assigning to the file_entry. It felt natural
to use gdb::optional for "do I have this value", and this is what
motivated the previous patch that added the missing observer methods
to gdb::optional.
gdb/ChangeLog:
2017-04-04 Pedro Alves <palves@redhat.com>
* common/underlying.h: New file.
* dwarf2read.c: Include "common/gdb_optional.h" and
"common/underlying.h".
(dir_index, file_name_index): New types.
(file_entry): Use them.
(file_entry::include): Use to_underlying.
(line_header::add_file_name): Use dir_index.
(read_formatted_entries): Use gdb::optional. Read form before
writting to file_entry.
(dwarf_decode_line_header): Use dir_index.
(lnp_state_machine::current_file): Use to_underlying.
(lnp_state_machine::file): Change type to file_name_index.
(dwarf_record_line): Use to_underlying.
(init_lnp_state_machine): Use file_name_index.
(dwarf_decode_lines_1): Use dir_index and file_name_index.
Diffstat (limited to 'gdb/common')
-rw-r--r-- | gdb/common/underlying.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/gdb/common/underlying.h b/gdb/common/underlying.h new file mode 100644 index 0000000..41ff117 --- /dev/null +++ b/gdb/common/underlying.h @@ -0,0 +1,32 @@ +/* Copyright (C) 2017 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef COMMON_UNDERLYING_H +#define COMMON_UNDERLYING_H + +#include <type_traits> + +/* Convert an enum to its underlying value. */ + +template<typename E> +constexpr typename std::underlying_type<E>::type +to_underlying (E val) noexcept +{ + return static_cast<typename std::underlying_type<E>::type> (val); +} + +#endif |