[PATCH v2 1/8] gdb: move some stabs functions to gdb/buildsym-legacy.h

Guinevere Larsen
2025-10-20T15:33:32Z

The gdb/stabsread.h and .c files define 2 things that, while originally
intended only for stabs reading, actually end up being used for coff,
ecoff and maybe more debuginfo formats. That is the function "hashname",
and the macro HASHSIZE. Both are used for small hashtables when reading
some symbols with incomplete information.

With the upcoming removal of stabs code, this code should be moved
somewhere, and the location that looked most reasonable was
gdb/buildsym-legacy. No change in behavior is expected after this
commit.
---
gdb/buildsym-legacy.h | 10 ++++++++++
gdb/stabsread.c | 8 --------
gdb/stabsread.h | 9 ++-------
3 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/gdb/buildsym-legacy.h b/gdb/buildsym-legacy.h
index 4ae8e1a7b66..06d39e8529f 100644
--- a/gdb/buildsym-legacy.h
+++ b/gdb/buildsym-legacy.h
@@ -21,6 +21,16 @@

#include "buildsym.h"

+/* Legacy hash for symbol names used for several debuginfo formats. */
+
+#define HASHSIZE 127
+
+static inline int
+hashname (const char *name)
+{
+ return fast_hash (name, strlen (name)) % HASHSIZE;
+}
+
/* This module provides definitions used for creating and adding to
the symbol table. These routines are called from various symbol-
file-reading routines. This file holds the legacy API, which
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index 733fc9e6ddc..60cd5702396 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -7190,14 +7190,6 @@ find_name_end (const char *name)
}
}

-/* See stabsread.h. */
-
-int
-hashname (const char *name)
-{
- return fast_hash (name, strlen (name)) % HASHSIZE;
-}
-
/* Initializer for this module. */

INIT_GDB_FILE (stabsread)
diff --git a/gdb/stabsread.h b/gdb/stabsread.h
index 15f73266e1c..1c9ce854dff 100644
--- a/gdb/stabsread.h
+++ b/gdb/stabsread.h
@@ -19,6 +19,8 @@
#ifndef GDB_STABSREAD_H
#define GDB_STABSREAD_H

+#include "buildsym-legacy.h"
+
struct objfile;
struct legacy_psymtab;
enum language;
@@ -26,13 +28,6 @@ enum language;
/* Definitions, prototypes, etc for stabs debugging format support
functions. */

-#define HASHSIZE 127 /* Size of things hashed via
- hashname(). */
-
-/* Compute a small integer hash code for the given name. */
-
-extern int hashname (const char *name);
-
/* Count symbols as they are processed, for error messages. */

extern unsigned int symnum;
--
2.51.0