aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2022-10-03 09:11:00 +0200
committerMartin Liska <mliska@suse.cz>2022-10-11 14:13:26 +0200
commit857bddbe737bc963bd9e5a3b24743a9bba5d2d7b (patch)
tree487913f1480b0ace5fa040e07f2b839c9eb00175 /bfd
parentc6422d7be70f14bf7140085f2fc7a592737f5df5 (diff)
downloadgdb-857bddbe737bc963bd9e5a3b24743a9bba5d2d7b.zip
gdb-857bddbe737bc963bd9e5a3b24743a9bba5d2d7b.tar.gz
gdb-857bddbe737bc963bd9e5a3b24743a9bba5d2d7b.tar.bz2
refactor usage of compressed_debug_section_type
bfd/ChangeLog: * bfd-in.h (bfd_hash_set_default_size): Add COMPRESS_UNKNOWN enum value. (struct compressed_type_tuple): New. * bfd-in2.h (bfd_hash_set_default_size): Regenerate. (struct compressed_type_tuple): Likewise. * libbfd.c (ARRAY_SIZE): New macro. (bfd_get_compression_algorithm): New function. (bfd_get_compression_algorithm_name): Likewise. gas/ChangeLog: * as.c: Do not special-case, use the new functions. ld/ChangeLog: * emultempl/elf.em: Do not special-case, use the new functions. * lexsup.c (elf_static_list_options): Likewise.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/bfd-in.h20
-rw-r--r--bfd/bfd-in2.h20
-rw-r--r--bfd/libbfd.c36
3 files changed, 70 insertions, 6 deletions
diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index 4765ea8..82e33d4 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -335,15 +335,23 @@ extern void bfd_hash_traverse
this size. */
extern unsigned long bfd_hash_set_default_size (unsigned long);
-/* Types of compressed DWARF debug sections. We currently support
- zlib. */
+/* Types of compressed DWARF debug sections. */
enum compressed_debug_section_type
{
COMPRESS_DEBUG_NONE = 0,
COMPRESS_DEBUG = 1 << 0,
COMPRESS_DEBUG_GNU_ZLIB = COMPRESS_DEBUG | 1 << 1,
COMPRESS_DEBUG_GABI_ZLIB = COMPRESS_DEBUG | 1 << 2,
- COMPRESS_DEBUG_ZSTD = COMPRESS_DEBUG | 1 << 3
+ COMPRESS_DEBUG_ZSTD = COMPRESS_DEBUG | 1 << 3,
+ COMPRESS_UNKNOWN = 1 << 4
+};
+
+/* Tuple for compressed_debug_section_type and their name. */
+
+struct compressed_type_tuple
+{
+ enum compressed_debug_section_type type;
+ const char *name;
};
/* This structure is used to keep track of stabs in sections
@@ -456,6 +464,12 @@ extern void bfd_free_window
(bfd_window *);
extern bool bfd_get_file_window
(bfd *, file_ptr, bfd_size_type, bfd_window *, bool);
+
+
+extern enum compressed_debug_section_type bfd_get_compression_algorithm
+ (const char *);
+extern const char *bfd_get_compression_algorithm_name
+ (enum compressed_debug_section_type);
/* Externally visible ELF routines. */
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index d9b49a8..25e1806 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -342,15 +342,23 @@ extern void bfd_hash_traverse
this size. */
extern unsigned long bfd_hash_set_default_size (unsigned long);
-/* Types of compressed DWARF debug sections. We currently support
- zlib. */
+/* Types of compressed DWARF debug sections. */
enum compressed_debug_section_type
{
COMPRESS_DEBUG_NONE = 0,
COMPRESS_DEBUG = 1 << 0,
COMPRESS_DEBUG_GNU_ZLIB = COMPRESS_DEBUG | 1 << 1,
COMPRESS_DEBUG_GABI_ZLIB = COMPRESS_DEBUG | 1 << 2,
- COMPRESS_DEBUG_ZSTD = COMPRESS_DEBUG | 1 << 3
+ COMPRESS_DEBUG_ZSTD = COMPRESS_DEBUG | 1 << 3,
+ COMPRESS_UNKNOWN = 1 << 4
+};
+
+/* Tuple for compressed_debug_section_type and their name. */
+
+struct compressed_type_tuple
+{
+ enum compressed_debug_section_type type;
+ const char *name;
};
/* This structure is used to keep track of stabs in sections
@@ -463,6 +471,12 @@ extern void bfd_free_window
(bfd_window *);
extern bool bfd_get_file_window
(bfd *, file_ptr, bfd_size_type, bfd_window *, bool);
+
+
+extern enum compressed_debug_section_type bfd_get_compression_algorithm
+ (const char *);
+extern const char *bfd_get_compression_algorithm_name
+ (enum compressed_debug_section_type);
/* Externally visible ELF routines. */
diff --git a/bfd/libbfd.c b/bfd/libbfd.c
index d33f341..14e7d8e 100644
--- a/bfd/libbfd.c
+++ b/bfd/libbfd.c
@@ -1244,3 +1244,39 @@ _bfd_generic_init_private_section_data (bfd *ibfd ATTRIBUTE_UNUSED,
{
return true;
}
+
+/* Display texts for type of compressed DWARF debug sections. */
+static const struct compressed_type_tuple compressed_debug_section_names[] =
+{
+ { COMPRESS_DEBUG_NONE, "none" },
+ { COMPRESS_DEBUG, "zlib" },
+ { COMPRESS_DEBUG_GNU_ZLIB, "zlib-gnu" },
+ { COMPRESS_DEBUG_GABI_ZLIB, "zlib-gabi" },
+ { COMPRESS_DEBUG_ZSTD, "zstd" },
+};
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
+#endif
+
+/* Return compressed_debug_section_type from a string representation. */
+enum compressed_debug_section_type
+bfd_get_compression_algorithm (const char *name)
+{
+ for (unsigned i = 0; i < ARRAY_SIZE (compressed_debug_section_names); ++i)
+ if (strcasecmp (compressed_debug_section_names[i].name, name) == 0)
+ return compressed_debug_section_names[i].type;
+
+ return COMPRESS_UNKNOWN;
+}
+
+/* Return compression algorithm name based on the type. */
+const char *
+bfd_get_compression_algorithm_name (enum compressed_debug_section_type type)
+{
+ for (unsigned i = 0; i < ARRAY_SIZE (compressed_debug_section_names); ++i)
+ if (type == compressed_debug_section_names[i].type)
+ return compressed_debug_section_names[i].name;
+
+ return NULL;
+}