diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 40ca50a..151a11e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,13 +1,5 @@ name: CI -concurrency: - # Concurrency is defined in a way that concurrent builds against branches do - # not cancel previous builds. - # However, for every new build against the same pull request source branch, - # all older builds against that same branch get canceled. - group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.repository }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - on: workflow_call: inputs: @@ -64,22 +56,29 @@ jobs: with: changed-files: ${{ needs.get-changed-files.outputs.changed-files }} + test: + name: Test + needs: + - get-changed-files + uses: ./.github/workflows/test-action.yml + with: + changed-files: ${{ needs.get-changed-files.outputs.changed-files }} + build-python-package: name: Python Package uses: ./.github/workflows/package-action.yml - if: always() needs: - pre-commit + - test with: kind: "${{ inputs.kind }}" - cmd: python -m build - #cmd: "${{ inputs.package_command }}" + cmd: "${{ inputs.package_command }}" - test: - name: Test + test-python-package: + name: Test Python Package needs: - get-changed-files - uses: ./.github/workflows/test-action.yml + uses: ./.github/workflows/test-package-action.yml with: changed-files: ${{ needs.get-changed-files.outputs.changed-files }} @@ -90,6 +89,7 @@ jobs: needs: - pre-commit - test + - test-python-package - build-python-package secrets: PYPI_API_TOKEN: "${{ secrets.PYPI_API_TOKEN }}" diff --git a/.github/workflows/pre-commit-action.yml b/.github/workflows/pre-commit-action.yml index 12d334b..5aaed73 100644 --- a/.github/workflows/pre-commit-action.yml +++ b/.github/workflows/pre-commit-action.yml @@ -22,6 +22,8 @@ jobs: sudo apt-get install -y git gcc make zlib1g-dev libc-dev libffi-dev g++ libxml2 libxml2-dev libxslt-dev libcurl4-openssl-dev libssl-dev libgnutls28-dev - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Install Pre-Commit run: | @@ -37,4 +39,4 @@ jobs: - name: Check Changed Files On PR if: github.event_name == 'pull_request' && fromJSON(inputs.changed-files)['repo'] == 'true' run: | - pre-commit run --show-diff-on-failure --color=always --files ${{ join(fromJSON(inputs.changed-files)['repo_files'], ' ') }} + pre-commit run --show-diff-on-failure --color=always --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }} diff --git a/.github/workflows/test-package-action.yml b/.github/workflows/test-package-action.yml new file mode 100644 index 0000000..b4d529f --- /dev/null +++ b/.github/workflows/test-package-action.yml @@ -0,0 +1,39 @@ +name: Package Tests + +on: + workflow_call: + inputs: + changed-files: + required: true + type: string + description: JSON string containing information about changed files + +jobs: + test: + strategy: + fail-fast: false + matrix: + runs-on: + - ubuntu-latest + - macos-12 + - macos-13-xlarge + - windows-latest + + name: Package Test ${{ matrix.runs-on }} + runs-on: ${{ matrix.runs-on }} + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Install python dependencies + run: | + pip3 install pytest + + - name: Run tests + run: | + pytest -v diff --git a/.pre-commit-hooks/check_changelog_entries.py b/.pre-commit-hooks/check_changelog_entries.py index a7064f1..47680ae 100644 --- a/.pre-commit-hooks/check_changelog_entries.py +++ b/.pre-commit-hooks/check_changelog_entries.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright 2021-2023 VMware, Inc. +# Copyright 2021-2024 VMware, Inc. # SPDX-License-Identifier: Apache-2.0 # # pylint: skip-file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..086c48d --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,22 @@ +0.2.0 +===== + +This is the first public release. + +* Automation of test release pipeline +* Upgrade gdb and relenv versions used while building +* Fix issues in wheel missing needed shared libraries +* Improve inject script reliability by using PyRun_SimpleFile instead of + PyRun_SimpleString. +* Add script to build wheel in docker container. + +0.1.0 +===== + +Initial release. + +* Bundles gdb in a wheel. +* Adds gdb entry point to start gdb. +* Adds dbg entry point to quickly get information threads and their python stack + traces. +* Adds inject entrypoint to inject python into a running cpython process. diff --git a/README.md b/README.md index 75930a3..187d6e5 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,14 @@ -On Debian based distributions you must install the gdb and salt-dbg system -packages. +gdbdbg +====== -On RPM based distributions you must install the salt-debuginfo and gdb system -packages. - -relenv-dbg will gather some general debugging information as well as the stack traces from each thread. +gdbdbg will gather some general debugging information as well as the stack +traces from each thread. ``` -/opts/saltstack/extras-3.10/bin/relenv-dbg +gdbdbg-info ``` -relenv-inject can be used to inject some python code into the running process. +gdbdbg-inject can be used to inject some python code into the running process. If you have manhole installed you can write a script like this: @@ -19,8 +17,8 @@ import manhole manhole.install() ``` -And inject it with relenv-inject: +And inject it with gdbdbg-inject: ``` -/opts/saltstack/extras-3.10/bin/relenv-inject manhole.py +gdbdbg manhole.py ``` diff --git a/pyproject.toml b/pyproject.toml index fb4a8be..9fafdf5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,10 +5,10 @@ requires = [ "relenv", ] build-backend = "build" -backend-path = ["src/relenv_gdb"] +backend-path = ["src/gdbdbg"] [tool.isort] -skip = "src/relenv_gdb/libpython.py" +skip = "libpython.py" [tool.black] force_exclude = "libpython.py" diff --git a/setup.cfg b/setup.cfg index ec6a8c2..72b4191 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,13 +1,13 @@ [metadata] -name = relenv-gdb -version = 0.1.0 +name = gdbdbg +version = attr: gdbdbg.__version__ author = Daniel A. Wozniak -author_email = -description = gdb debugger for relenv +author_email = +description = gdb debugger long_description = file: README.md long_description_content_type = text/markdown -url = https://github.com/saltstack/relenv-gdb - Bug Tracker = https://github.com/saltstack/relenv-gdb/issues +url = https://github.com/saltstack/gdbdbg + Bug Tracker = https://github.com/saltstack/gdbdbg/issues classifiers = Programming Language :: Python :: 3 License :: OSI Approved :: Apache Software License @@ -31,9 +31,9 @@ where=src [options.entry_points] console_scripts = - relenv-gdb = relenv_gdb.gdbinit:main - relenv-dbg = relenv_gdb.dbg:main - relenv-inject = relenv_gdb.inject:main + gdbdbg = gdbdbg.dbg:main + gdbdbg-gdb = gdbdbg.gdbinit:main + gdbdbg-inject = gdbdbg.inject:main [flake8] max-line-length = 120 @@ -53,7 +53,7 @@ exclude = setup.py, # Ignore our custom pre-commit hooks .pre-commit-hooks - src/relenv_gdb/libpython.py + src/gdbdbg/libpython.py ignore = # D104 Missing docstring in public package diff --git a/src/gdbdbg/__init__.py b/src/gdbdbg/__init__.py new file mode 100644 index 0000000..4c25c8c --- /dev/null +++ b/src/gdbdbg/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 VMware, Inc. +# SPDX-License-Identifier: Apache-2.0 + +__version__ = "0.2.0" diff --git a/src/relenv_gdb/build.py b/src/gdbdbg/build.py similarity index 100% rename from src/relenv_gdb/build.py rename to src/gdbdbg/build.py diff --git a/src/relenv_gdb/dbg.py b/src/gdbdbg/dbg.py similarity index 98% rename from src/relenv_gdb/dbg.py rename to src/gdbdbg/dbg.py index 3cf168a..e1c56d4 100755 --- a/src/relenv_gdb/dbg.py +++ b/src/gdbdbg/dbg.py @@ -1,4 +1,4 @@ -# Copyright 2023 VMware, Inc. +# Copyright 2023-2024 VMware, Inc. # SPDX-License-Identifier: Apache-2.0 """ Use gdb to pull python stack traces a parent process and all of it's children. diff --git a/src/gdbdbg/gdbinit.py b/src/gdbdbg/gdbinit.py new file mode 100644 index 0000000..2c6de5a --- /dev/null +++ b/src/gdbdbg/gdbinit.py @@ -0,0 +1,27 @@ +# Copyright 2023-2024 VMware, Inc. +# SPDX-License-Identifier: Apache-2.0 +# +""" +Localize gdb startup to the current relenv. +""" +import os +import pathlib +import sys + +real_gdb_bin = pathlib.Path(__file__).parent / "gdb" / "bin" / "gdb" +data_directory = pathlib.Path(__file__).parent / "gdb" / "share" / "gdb" + + +def main(): + """Wrap gdb startup.""" + os.environ["PYTHONPATH"] = os.pathsep.join(sys.path) + if os.execve in os.supports_fd: + with open(real_gdb_bin, "rb") as fp: + sys.stdout.flush() + sys.stderr.flush() + args = [sys.argv[0], f"--data-directory={data_directory}"] + sys.argv[1:] + os.execve(fp.fileno(), args, os.environ) + else: + cmd = real_gdb_bin + args = [real_gdb_bin, f"--data-directory={data_directory}"] + sys.argv[1:] + os.execve(cmd, args, os.environ) diff --git a/src/relenv_gdb/inject.py b/src/gdbdbg/inject.py similarity index 98% rename from src/relenv_gdb/inject.py rename to src/gdbdbg/inject.py index 3cf7214..4b8c48c 100644 --- a/src/relenv_gdb/inject.py +++ b/src/gdbdbg/inject.py @@ -1,4 +1,4 @@ -# Copyright 2023 VMware, Inc. +# Copyright 2023-2024 VMware, Inc. # SPDX-License-Identifier: Apache-2.0 """ Inject python code into a running process. diff --git a/src/relenv_gdb/libpython.py b/src/gdbdbg/libpython.py similarity index 100% rename from src/relenv_gdb/libpython.py rename to src/gdbdbg/libpython.py diff --git a/src/relenv_gdb/util.py b/src/gdbdbg/util.py similarity index 96% rename from src/relenv_gdb/util.py rename to src/gdbdbg/util.py index 7db2940..2700498 100644 --- a/src/relenv_gdb/util.py +++ b/src/gdbdbg/util.py @@ -1,4 +1,4 @@ -# Copyright 2023 VMware, Inc. +# Copyright 2023-2024 VMware, Inc. # SPDX-License-Identifier: Apache-2.0 """ Utility methods. diff --git a/src/relenv_gdb/__init__.py b/src/relenv_gdb/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/relenv_gdb/gdbinit.py b/src/relenv_gdb/gdbinit.py deleted file mode 100644 index ff57dcf..0000000 --- a/src/relenv_gdb/gdbinit.py +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright 2023 VMware, Inc. -# SPDX-License-Identifier: Apache-2.0 -# -""" -Localize gdb startup to the current relenv. -""" -import os -import pathlib -import sys - -real_gdb_bin = pathlib.Path(__file__).parent / "gdb" / "bin" / "gdb" -data_directory = pathlib.Path(__file__).parent / "gdb" / "share" / "gdb" - - -def main(): - """Wrap gdb startup.""" - if hasattr(sys, "RELENV"): - os.environ["PYTHONHOME"] = f"{sys.RELENV}" - if os.execve in os.supports_fd: - with open(real_gdb_bin, "rb") as fp: - sys.stdout.flush() - sys.stderr.flush() - args = [sys.argv[0], f"--data-directory={data_directory}"] + sys.argv[ - 1: - ] - os.execve(fp.fileno(), args, os.environ) - else: - cmd = real_gdb_bin - args = [real_gdb_bin, f"--data-directory={data_directory}"] + sys.argv[1:] - os.execve(cmd, args, os.environ) - else: - sys.stderr.write("Not running in a relenv environment.") - sys.stderr.flush() - sys.exit(1)