aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
Diffstat (limited to 'gdb')
-rwxr-xr-xgdb/contrib/codespell-log.sh95
-rw-r--r--gdb/dwarf2/cu.h9
-rw-r--r--gdb/dwarf2/read.c9
-rw-r--r--gdb/solib.c2
-rwxr-xr-xgdb/syscalls/riscv-canonicalize-syscall-gen.py2
5 files changed, 110 insertions, 7 deletions
diff --git a/gdb/contrib/codespell-log.sh b/gdb/contrib/codespell-log.sh
new file mode 100755
index 0000000..10780f8
--- /dev/null
+++ b/gdb/contrib/codespell-log.sh
@@ -0,0 +1,95 @@
+#!/usr/bin/env bash
+
+# Copyright (C) 2025 Free Software Foundation, Inc.
+# 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/>.
+
+# Script to be used as pre-commit commit-msg hook to spell-check the commit
+# log using codespell.
+#
+# Using codespell directly as a pre-commit commit-msg hook has the drawback
+# that:
+# - if codespell fails, the commit fails
+# - if the commit log mentions a typo correction, it'll require a
+# codespell:ignore annotation.
+#
+# This script works around these problems by treating codespell output as a
+# hint, and ignoring codespell exit status.
+#
+# Implementation note: rather than using codespell directly, this script uses
+# pre-commit to call codespell, because it allows us to control the codespell
+# version that is used.
+
+# Exit on error.
+set -e
+
+# Initialize temporary file names.
+cfg=""
+output=""
+
+cleanup()
+{
+ for f in "$cfg" "$output"; do
+ if [ "$f" != "" ]; then
+ rm -f "$f"
+ fi
+ done
+}
+
+# Schedule cleanup.
+trap cleanup EXIT
+
+# Create temporary files.
+cfg=$(mktemp)
+output=$(mktemp)
+
+gen_cfg ()
+{
+ cat > "$1" <<EOF
+repos:
+- repo: https://github.com/codespell-project/codespell
+ rev: v2.4.1
+ hooks:
+ - id: codespell
+ name: codespell-log-internal
+ stages: [manual]
+ args: [--config, gdb/contrib/setup.cfg]
+EOF
+}
+
+# Generate pre-commit configuration file.
+gen_cfg "$cfg"
+
+# Setup pre-commit command to run.
+cmd=(pre-commit \
+ run \
+ -c "$cfg" \
+ codespell \
+ --hook-stage manual \
+ --files "$@")
+
+# Run pre-commit command.
+if "${cmd[@]}" \
+ > "$output" \
+ 2>&1; then
+ # Command succeeded quietly, we're done.
+ exit 0
+fi
+
+# Command failed quietly, now show the output.
+#
+# Simply doing "cat $output" doesn't produce colored output, so we just
+# run the command again, that should be fast enough.
+#
+# Ignore codespell exit status.
+"${cmd[@]}" || true
diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h
index 5683291..6eda19b 100644
--- a/gdb/dwarf2/cu.h
+++ b/gdb/dwarf2/cu.h
@@ -99,6 +99,15 @@ struct dwarf2_cu
void add_dependence (dwarf2_per_cu *ref_per_cu)
{ m_dependencies.emplace (ref_per_cu); }
+ /* Find the DIE at section offset SECT_OFF.
+
+ Return nullptr if not found. */
+ die_info *find_die (sect_offset sect_off) const
+ {
+ auto it = die_hash.find (sect_off);
+ return it != die_hash.end () ? *it : nullptr;
+ }
+
/* The header of the compilation unit. */
struct comp_unit_head header;
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 2523ca8..6b7f2c7 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -18260,8 +18260,7 @@ follow_die_offset (sect_offset sect_off, int offset_in_dwz,
*ref_cu = target_cu;
- auto it = target_cu->die_hash.find (sect_off);
- return it != target_cu->die_hash.end () ? *it : nullptr;
+ return target_cu->find_die (sect_off);
}
/* Follow reference attribute ATTR of SRC_DIE.
@@ -18629,8 +18628,8 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
gdb_assert (sig_cu != NULL);
gdb_assert (to_underlying (sig_type->type_offset_in_section) != 0);
- if (auto die_it = sig_cu->die_hash.find (sig_type->type_offset_in_section);
- die_it != sig_cu->die_hash.end ())
+ if (die_info *die = sig_cu->find_die (sig_type->type_offset_in_section);
+ die != nullptr)
{
/* For .gdb_index version 7 keep track of included TUs.
http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
@@ -18639,7 +18638,7 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
(*ref_cu)->per_cu->imported_symtabs.push_back (sig_cu->per_cu);
*ref_cu = sig_cu;
- return *die_it;
+ return die;
}
return NULL;
diff --git a/gdb/solib.c b/gdb/solib.c
index 5c5cfbd..85ec6bb 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1230,7 +1230,7 @@ info_linker_namespace_command (const char *pattern, int from_tty)
break;
}
uiout->message
- (_ ("There are %ld libraries loaded in linker namespace [[%d]]\n"),
+ (_ ("There are %zu libraries loaded in linker namespace [[%d]]\n"),
solibs_to_print.size (), ns);
uiout->message
(_ ("Displaying libraries for linker namespace [[%d]]:\n"), ns);
diff --git a/gdb/syscalls/riscv-canonicalize-syscall-gen.py b/gdb/syscalls/riscv-canonicalize-syscall-gen.py
index 40039bb..c7dda93 100755
--- a/gdb/syscalls/riscv-canonicalize-syscall-gen.py
+++ b/gdb/syscalls/riscv-canonicalize-syscall-gen.py
@@ -111,7 +111,7 @@ class Generator:
canon_syscalls[syscall_num] = value
# this is a place for corner cases
elif syscall_name == "mmap":
- gdb_old_syscall_name = "gdb_sys_old_mmap"
+ gdb_old_syscall_name = "gdb_old_mmap"
value = (
f" case {syscall_num}: return {gdb_old_syscall_name};\n"
)