Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions packages/gdb/build.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
let { standaloneTest, Attrs, BuildSpec, Local, OutputBin, OutputData, Source, Test, .. } = import "minimal.ncl" in
let base = import "../base/build.ncl" in
let bash = import "../bash/build.ncl" in
let coreutils = import "../coreutils/build.ncl" in
let expat = import "../expat/build.ncl" in
let gcc = import "../gcc/build.ncl" in
let glibc = import "../glibc/build.ncl" in
let gmp = import "../gmp/build.ncl" in
let make = import "../make/build.ncl" in
let mpfr = import "../mpfr/build.ncl" in
let ncurses = import "../ncurses/build.ncl" in
let pkgconf = import "../pkgconf/build.ncl" in
let python = import "../python/build.ncl" in
let readline = import "../readline/build.ncl" in
let toolchain = import "../toolchain/build.ncl" in
let xz = import "../xz/build.ncl" in
let zlib = import "../zlib/build.ncl" in
let zstd = import "../zstd/build.ncl" in

let version = "17.2" in
{
name = "gdb",
build_deps = [
{ file = "build.sh" } | Local,
{
url = "gs://minimal-staging-archives/gdb-%{version}.tar.xz",
sha256 = "1c036c0d72e4b3d1fb5c94c88632add6f9d76f4d7c4d2ea793c12a9f19a3228c",
} | Source,
base,
toolchain,
gcc,
make,
pkgconf,
glibc,
# Terminal + line editing. Built --with-system-readline so gdb uses OUR
# readline rather than its bundled copy — a bundled copy would be invisible
# to pkgscan, which is the same reasoning applied to rizin's use_sys_* flags.
ncurses,
readline,
# XML target descriptions and remote memory maps. Effectively required in
# practice even though configure treats it as optional.
expat,
# Debug-info compression formats gdb reads directly from ELF sections.
zlib,
xz,
zstd,
# Expression arithmetic.
gmp,
mpfr,
# LOAD-BEARING: gef is a Python extension and cannot load into a gdb built
# without --with-python. See build.sh.
python,
],
runtime_deps = [
bash,
# `gcore` is a shell script with a `#!/usr/bin/env` shebang, so env must be
# present at RUNTIME or the script is unrunnable. Caught by the
# missing_runtime_deps checker rather than by us noticing.
coreutils,
ncurses,
readline,
expat,
zlib,
xz,
zstd,
gmp,
mpfr,
python,
],
Comment on lines +54 to +69

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- packages/gdb/build.ncl ---'
cat -n packages/gdb/build.ncl
printf '%s\n' '--- binutils package files ---'
fd -i 'build.ncl|build.sh' packages/binutils packages 2>/dev/null | head -40
printf '%s\n' '--- binutils declarations ---'
rg -n -C 4 'objcopy|readelf|OutputBin|runtime_deps|build_deps|exports|binutils' packages/binutils packages/gdb 2>/dev/null
printf '%s\n' '--- gdb-add-index references ---'
rg -n -C 3 'gdb-add-index|gdb_add_index' . --glob '!packages/gdb/build.ncl'

Repository: gominimal/pkgs

Length of output: 17810


🏁 Script executed:

#!/bin/bash
set -eu
cat -n packages/gdb/build.ncl
printf '%s\n' '--- binutils ---'
fd -i 'build.ncl|build.sh' packages | rg '/binutils/'
rg -n -C 4 'objcopy|readelf|OutputBin|runtime_deps|build_deps|gdb-add-index|gdb_add_index' packages/binutils packages/gdb 2>/dev/null || true

Repository: gominimal/pkgs

Length of output: 11776


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- complete binutils manifest ---'
cat -n packages/binutils/build.ncl | sed -n '1,135p'
printf '%s\n' '--- packages importing binutils ---'
rg -n -C 3 'import "\.\./binutils/build\.ncl"|subsetOf binutils|binutils,' packages --glob 'build.ncl'
printf '%s\n' '--- dependency and capability test conventions ---'
rg -n -C 5 'gdb-add-index|objcopy|readelf|test_deps = .*binutils|capabilities =|class = .Standalone' packages --glob 'build.ncl' | head -240
printf '%s\n' '--- local package metadata/checker definitions ---'
rg -n -C 4 'missing_runtime_deps|runtime_deps|test_deps|OutputBin|subsetOf' . --glob '*.ncl' --glob '*.md' --glob '*.rs' --glob '*.go' | head -260

Repository: gominimal/pkgs

Length of output: 50370


🌐 Web query:

GNU GDB 17.2 gdb-add-index source script objcopy readelf PATH

💡 Result:

The gdb-add-index utility is a helper script provided with GNU GDB (including version 17.2) designed to speed up GDB startup by adding an index section to a symbol file [1][2][3]. By default, gdb-add-index searches the PATH environment variable to locate the required programs: gdb, objcopy, and readelf [2][3]. If you need to use specific versions of these tools or if they are not in your system's PATH, you can override the default search by setting the following environment variables [2][3][4]: GDB: Specifies the path to the gdb executable [3]. OBJCOPY: Specifies the path to the objcopy executable [3]. READELF: Specifies the path to the readelf executable [3]. The script uses readelf to inspect the binary for existing indices and objcopy to inject the newly created.gdb_index (or DWARF 5.debug_names and.debug_str) section into the target file [2][5][3]. The target symbol file must be writable for the operation to succeed [2][3].

Citations:


🏁 Script executed:

#!/bin/bash
set -eu
cat -n packages/binutils/build.ncl | sed -n '1,135p'
rg -n -C 3 'import "\.\./binutils/build\.ncl"|subsetOf binutils|binutils,' packages --glob 'build.ncl'
rg -n -C 5 'gdb-add-index|objcopy|readelf|test_deps|capabilities' packages --glob 'build.ncl' | head -240

Repository: gominimal/pkgs

Length of output: 41014


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- subsetOf definitions and examples ---'
rg -n -C 8 'subsetOf' packages/minimal.ncl minimal.ncl packages --glob '*.ncl' | head -180
printf '%s\n' '--- test schema/documentation ---'
rg -n -C 6 'test_deps|Standalone|capabilities|runtime_deps' . --glob 'minimal.ncl' --glob '*.md' --glob '*.ncl' | head -220
printf '%s\n' '--- gdb build and test script ---'
cat -n packages/gdb/build.sh | sed -n '1,90p'
printf '%s\n' '--- upstream script ---'
curl -fsSL https://gnu.googlesource.com/binutils-gdb/+/refs/tags/gdb-17.2/gdb/contrib/gdb-add-index.sh?format=TEXT \
  | base64 -d | sed -n '1,220p'

Repository: gominimal/pkgs

Length of output: 26286


🏁 Script executed:

#!/bin/bash
set -eu
rg -n -C 8 'subsetOf' packages/minimal.ncl minimal.ncl packages --glob '*.ncl' | head -180
rg -n -C 6 'test_deps|Standalone|capabilities|runtime_deps' . --glob 'minimal.ncl' --glob '*.md' --glob '*.ncl' | head -220
cat -n packages/gdb/build.sh | sed -n '1,90p'
curl -fsSL 'https://gnu.googlesource.com/binutils-gdb/+/refs/tags/gdb-17.2/gdb/contrib/gdb-add-index.sh?format=TEXT' | base64 -d | sed -n '1,220p'

Repository: gominimal/pkgs

Length of output: 27039


Declare gdb-add-index’s binutils tools at runtime.

Import binutils and subsetOf, then add subsetOf binutils ["objcopy", "readelf"] to runtime_deps; add a standalone test that runs gdb-add-index on a copied debuggable ELF.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/gdb/build.ncl` around lines 54 - 69, Update the runtime dependency
declaration in build.ncl by importing binutils and subsetOf, then add subsetOf
binutils ["objcopy", "readelf"] to runtime_deps for gdb-add-index. Add a
standalone test that copies a debuggable ELF and runs gdb-add-index against it.


cmd = "./build.sh",
build_args = {
include version,
},

outputs = {
gdb = { glob = "usr/bin/gdb" } | OutputBin,
gdb_add_index = { glob = "usr/bin/gdb-add-index" } | OutputBin,
gcore = { glob = "usr/bin/gcore" } | OutputBin,
gdbserver = { glob = "usr/bin/gdbserver" } | OutputBin,
# gdb's Python runtime support files — the `python` directory it loads its
# own pretty-printers and commands from.
gdb_data = { glob = "usr/share/gdb/**" } | OutputData,
},
tests = {
smoketest = standaloneTest "/bin/gdb --version",

# PIN THE TWO PROPERTIES THE CONFIGURE FLAGS EXIST FOR. Both regress
# SILENTLY: configure probes for Python and for target support, and if
# either probe fails it prints a note and carries on to a successful build.
# You would get a gdb that installs, runs, passes a --version smoketest, and
# is useless for the thing it was packaged to do.
capabilities =
{
class = 'Standalone,
test_deps = [base],
cmds = [
# --with-python: gef is a Python extension. Without this gdb reports
# "Python scripting is not supported in this copy of GDB" and gef
# cannot load at all.
["/bin/bash", "-c", "gdb -batch -ex 'python print(\"py-ok\")' | grep -q py-ok"],
# --enable-targets=all: a foreign architecture must be selectable, or
# gdb cannot disassemble a binary emulated under qemu-user's gdbstub.
# i386 is foreign on every arch we build for.
["/bin/bash", "-c", "gdb -batch -ex 'set architecture' 2>&1 | grep -q i386"],
],
} | Test,
},

attrs =
{
upstream_version = version,
license_spdx = "GPL-3.0-or-later",
source_provenance = {
category = 'GnuProject,
name = "gdb",
},
} | Attrs,
} | BuildSpec
60 changes: 60 additions & 0 deletions packages/gdb/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh
set -e

tar -xof "gdb-${MINIMAL_ARG_VERSION}.tar.xz"
cd "gdb-${MINIMAL_ARG_VERSION}"

case $(uname -m) in
x86_64) MARCH="-march=x86-64-v3" ;;
aarch64) MARCH="-march=armv8-a" ;;
*) MARCH="" ;;
esac

# Reproducibility flags per the pkgs AGENTS.md C/C++ stack: two builds of the
# same source must be byte-identical.
export CFLAGS="$MARCH -O2 -pipe -gno-record-gcc-switches -ffile-prefix-map=$(pwd)=/builddir"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="-Wl,--build-id=none"
export ARFLAGS=Drc

# The gdb tarball ships the ENTIRE binutils-gdb tree — bfd, gas, ld, gprof and
# the binutils programs are all in here. Building them would silently produce a
# second `ld`/`objdump`/`as` that collide with our binutils package. Disable all
# of them; we want exactly one binary out of this tree.
#
# --with-python is LOAD-BEARING, not a nicety: gef is a Python extension and
# cannot load into a gdb built without Python support. Since the whole point of
# packaging gdb here is to carry gef, a non-Python gdb would satisfy the build
# and fail the actual goal.
#
# --enable-targets=all costs nothing at build time and lets gdb disassemble
# foreign architectures — which is what makes it useful against a binary being
# emulated under qemu-user's gdbstub, and mirrors the fix the binutils package
# still needs.
#
# MAKEINFO=true skips building the info manuals so we do not have to package
# texinfo for a doc format nothing here reads.
./configure \
--prefix=/usr \
--disable-binutils \
--disable-ld \
--disable-gas \
--disable-gprof \
--disable-gold \
--disable-sim \
--disable-nls \
--disable-werror \
--with-python=/usr/bin/python3 \
--with-system-readline \
--with-system-zlib \
--enable-targets=all \
MAKEINFO=true

make -j"$(nproc)" MAKEINFO=true
make install DESTDIR="$OUTPUT_DIR" MAKEINFO=true

# `make install` from this tree also drops libbfd/libopcodes headers and static
# archives that belong to the binutils package. Remove them so the two packages
# cannot disagree about who owns bfd.h.
rm -rf "$OUTPUT_DIR/usr/include" "$OUTPUT_DIR/usr/lib/libbfd."* "$OUTPUT_DIR/usr/lib/libopcodes."*
rm -rf "$OUTPUT_DIR/usr/share/info" "$OUTPUT_DIR/usr/share/locale"
Comment on lines +59 to +60

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove all installed libtool archives.

Autotools C/C++ package builds must remove installed .la files. The current cleanup only removes selected bfd/opcodes artifacts, so add a staged-tree cleanup before output capture.

Proposed fix
 rm -rf "$OUTPUT_DIR/usr/include" "$OUTPUT_DIR/usr/lib/libbfd."* "$OUTPUT_DIR/usr/lib/libopcodes."*
 rm -rf "$OUTPUT_DIR/usr/share/info" "$OUTPUT_DIR/usr/share/locale"
+find "$OUTPUT_DIR" -type f -name '*.la' -delete
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
rm -rf "$OUTPUT_DIR/usr/include" "$OUTPUT_DIR/usr/lib/libbfd."* "$OUTPUT_DIR/usr/lib/libopcodes."*
rm -rf "$OUTPUT_DIR/usr/share/info" "$OUTPUT_DIR/usr/share/locale"
rm -rf "$OUTPUT_DIR/usr/include" "$OUTPUT_DIR/usr/lib/libbfd."* "$OUTPUT_DIR/usr/lib/libopcodes."*
rm -rf "$OUTPUT_DIR/usr/share/info" "$OUTPUT_DIR/usr/share/locale"
find "$OUTPUT_DIR" -type f -name '*.la' -delete
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/gdb/build.sh` around lines 59 - 60, Extend the cleanup commands in
build.sh to remove every installed libtool archive (*.la) from the staged
$OUTPUT_DIR tree before output capture. Keep the existing bfd/opcodes and
documentation cleanup unchanged, and apply the removal recursively so archives
in any output subdirectory are deleted.

Source: Coding guidelines