Skip to content

Commit

Permalink
Merge pull request #5 from dwoz/notjustrelenv
Browse files Browse the repository at this point in the history
Not just for relenv
  • Loading branch information
dwoz authored Sep 7, 2024
2 parents 7a50182 + 201d985 commit 99eb947
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 75 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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 }}

Expand All @@ -90,6 +89,7 @@ jobs:
needs:
- pre-commit
- test
- test-python-package
- build-python-package
secrets:
PYPI_API_TOKEN: "${{ secrets.PYPI_API_TOKEN }}"
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/pre-commit-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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 }}
39 changes: 39 additions & 0 deletions .github/workflows/test-package-action.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .pre-commit-hooks/check_changelog_entries.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <pid>
gdbdbg-info <pid>
```

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:

Expand All @@ -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 <pid> manhole.py
gdbdbg <pid> manhole.py
```
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 10 additions & 10 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[metadata]
name = relenv-gdb
version = 0.1.0
name = gdbdbg
version = attr: gdbdbg.__version__
author = Daniel A. Wozniak
author_email = <dwozniak@vmware.com>
description = gdb debugger for relenv
author_email = <dwozniak@broadcom.com>
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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/gdbdbg/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2024 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0

__version__ = "0.2.0"
File renamed without changes.
2 changes: 1 addition & 1 deletion src/relenv_gdb/dbg.py → src/gdbdbg/dbg.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
27 changes: 27 additions & 0 deletions src/gdbdbg/gdbinit.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion src/relenv_gdb/inject.py → src/gdbdbg/inject.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/relenv_gdb/util.py → src/gdbdbg/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 VMware, Inc.
# Copyright 2023-2024 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0
"""
Utility methods.
Expand Down
Empty file removed src/relenv_gdb/__init__.py
Empty file.
34 changes: 0 additions & 34 deletions src/relenv_gdb/gdbinit.py

This file was deleted.

0 comments on commit 99eb947

Please sign in to comment.