Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some enhancements about pwndbg.gdblib.config #1315

Merged
merged 7 commits into from
Oct 22, 2022

Conversation

lebr0nli
Copy link
Contributor

@lebr0nli lebr0nli commented Oct 21, 2022

Summary about this PR:

  • Support all parameter-class when create a GDB parameter

  • Use get_show_string to render better output when using show <param> (although GDB 12.x will do similar things by default, this function just makes sure every version can have that kind of output)

  • Show more information when using help set <param> and help show <param> if we create a config with help_docstring parameter.

Here are some examples of the updates included in this PR:

  1. gdb.PARAM_AUTO_BOOLEAN with help_docstring

In Python script:

pwndbg.gdblib.config.add_param(
    "test",
    None,
    "test",
    help_docstring="on == AAAA\noff == BBBB\nauto == CCCC",
    param_class=gdb.PARAM_AUTO_BOOLEAN,
    scope="test",
)

In GDB:

pwndbg> show test
The current value of 'test' is 'auto'
pwndbg> set test on
Set test to 'on'
pwndbg> set test off
Set test to 'off'
pwndbg> set test auto_with_typo
"on", "off" or "auto" expected.
pwndbg> show test
The current value of 'test' is 'off'
pwndbg> set test auto
Set test to 'auto'
pwndbg> show test
The current value of 'test' is 'auto'
pwndbg> help show test
Show test
on == AAAA
off == BBBB
auto == CCCC
pwndbg> help set test
Set test
on == AAAA
off == BBBB
auto == CCCC
  1. gdb.PARAM_AUTO_BOOLEAN with help_docstring

In Python script:

pwndbg.gdblib.config.add_param(
    "test",
    "A",
    "test",
    help_docstring="A == AAAA\nB == BBBB\nC == CCCC",
    param_class=gdb.PARAM_ENUM,
    enum_sequence=["A", "B", "C"],
    scope="test",
)

In GDB:

pwndbg> show test
The current value of 'test' is 'A'
pwndbg> set test B
Set test to 'B'
pwndbg> set test C
Set test to 'C'
pwndbg> set test D
Undefined item: "D".
pwndbg> show test
The current value of 'test' is 'C'
pwndbg> help show test
Show test
A == AAAA
B == BBBB
C == CCCC
pwndbg> help set test
Set test
A == AAAA
B == BBBB
C == CCCC

* Support all parameter-class

* Use `get_show_string` to render better output when using `show <param>`

* Show more information when using `help set <param>` and `help show <param>` if we create a config with `help_docstring` parameter.

Some examples of the updates included in this commit:

1. `gdb.PARAM_AUTO_BOOLEAN` with `help_docstring`

In Python script:

```
pwndbg.gdblib.config.add_param(
    "test",
    None,
    "test",
    "on == AAAA\noff == BBBB\nauto == CCCC",
    gdb.PARAM_AUTO_BOOLEAN,
    scope="test",
)
```

In GDB:

```
pwndbg> show test
The current value of 'test' is 'auto'
pwndbg> set test on
Set test to 'on'
pwndbg> set test off
Set test to 'off'
pwndbg> set test auto_with_typo
"on", "off" or "auto" expected.
pwndbg> show test
The current value of 'test' is 'off'
pwndbg> set test auto
Set test to 'auto'
pwndbg> show test
The current value of 'test' is 'auto'
pwndbg> help show test
Show test
on == AAAA
off == BBBB
auto == CCCC
pwndbg> help set test
Set test
on == AAAA
off == BBBB
auto == CCCC
```

2. `gdb.PARAM_AUTO_BOOLEAN` with `help_docstring`

In Python script:

```
pwndbg.gdblib.config.add_param(
    "test",
    "A",
    "test",
    "A == AAAA\nB == BBBB\nC == CCCC",
    gdb.PARAM_ENUM,
    ["A", "B", "C"],
    scope="test",
)
```

In GDB:

```
pwndbg> show test
The current value of 'test' is 'A'
pwndbg> set test B
Set test to 'B'
pwndbg> set test C
Set test to 'C'
pwndbg> set test D
Undefined item: "D".
pwndbg> show test
The current value of 'test' is 'C'
pwndbg> help show test
Show test
A == AAAA
B == BBBB
C == CCCC
pwndbg> help set test
Set test
A == AAAA
B == BBBB
C == CCCC
```
@codecov-commenter
Copy link

codecov-commenter commented Oct 21, 2022

Codecov Report

Merging #1315 (2921927) into dev (5a323b4) will decrease coverage by 0.00%.
The diff coverage is 71.05%.

@@            Coverage Diff             @@
##              dev    #1315      +/-   ##
==========================================
- Coverage   55.04%   55.03%   -0.01%     
==========================================
  Files         156      156              
  Lines       19397    19410      +13     
  Branches     1804     1809       +5     
==========================================
+ Hits        10677    10683       +6     
- Misses       8276     8278       +2     
- Partials      444      449       +5     
Impacted Files Coverage Δ
pwndbg/gdblib/config.py 68.88% <42.10%> (-10.53%) ⬇️
pwndbg/color/theme.py 100.00% <100.00%> (ø)
pwndbg/glibc.py 75.43% <100.00%> (ø)
pwndbg/heap/__init__.py 90.90% <100.00%> (+0.58%) ⬆️
pwndbg/lib/config.py 90.80% <100.00%> (+0.56%) ⬆️
pwndbg/commands/vmmap.py 43.15% <0.00%> (-1.18%) ⬇️
pwndbg/lib/memory.py 93.15% <0.00%> (-0.28%) ⬇️
pwndbg/disasm/arch.py 78.94% <0.00%> (ø)
pwndbg/commands/flags.py 37.03% <0.00%> (ø)
pwndbg/disasm/__init__.py 59.58% <0.00%> (ø)
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@gsingh93 gsingh93 self-requested a review October 21, 2022 19:53
Copy link
Member

@gsingh93 gsingh93 left a comment

Choose a reason for hiding this comment

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

Thanks for doing this and thanks for adding so many comments :) It was very easy to review.

pwndbg/gdblib/config.py Outdated Show resolved Hide resolved
pwndbg/gdblib/config.py Outdated Show resolved Hide resolved
pwndbg/gdblib/config.py Outdated Show resolved Hide resolved
pwndbg/heap/__init__.py Outdated Show resolved Hide resolved
tests/gdb-tests/tests/test_gdblib_parameter.py Outdated Show resolved Hide resolved
):
# Note: This is really weird, according to GDB docs, 0 should mean "unlimited" for gdb.PARAM_UINTEGER and gdb.PARAM_INTEGER, but somehow GDB sets the value to `None` actually :/
# And hilarious thing is that GDB won't let you set the default value to `None` when you construct the `gdb.Parameter` object with `gdb.PARAM_UINTEGER` or `gdb.PARAM_INTEGER` lol
# Maybe it's a bug of GDB?
Copy link
Member

Choose a reason for hiding this comment

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

Let's consider reporting this upstream if we can.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I sent it to the mailing list of GDB now.

Copy link
Member

Choose a reason for hiding this comment

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

Link the discussion in a comment reply to this PR pls

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://sourceware.org/pipermail/gdb/2022-October/050398.html

Update: https://sourceware.org/pipermail/gdb/2022-October/050426.html
If I didn't misunderstand something, seems like the value in Python to represent unlimited will only be None instead of some integers in the future.
So we'll probably need to update the code here, the tests' params, and _value_to_gdb_native() to fit the new API in the future.

Copy link
Member

@gsingh93 gsingh93 left a comment

Choose a reason for hiding this comment

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

LGTM, will let @disconnect3d take a look and merge.

Comment on lines +23 to +32
def __init__(
self,
name,
default,
docstring,
help_docstring=None,
param_class=None,
enum_sequence=None,
scope="config",
):
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should also add the * in here to force keyword params starting from help_docstring?

Copy link
Member

Choose a reason for hiding this comment

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

That probably makes sense, 👍.

Btw one note: docstring and help_docstring is not so obvious I guess? I already merged this but noticed this only now. Maybe we should rename docstring to set_show_doc?

@disconnect3d disconnect3d merged commit 5b56071 into pwndbg:dev Oct 22, 2022
lebr0nli added a commit to lebr0nli/pwndbg that referenced this pull request Nov 21, 2022
* Add `*`: pwndbg#1315 (comment)

* Use `set_show_doc` instead of `docstring`: pwndbg#1315 (comment)
lebr0nli added a commit to lebr0nli/pwndbg that referenced this pull request Nov 21, 2022
* Add `*`: pwndbg#1315 (comment)

* Use `set_show_doc` instead of `docstring`: pwndbg#1315 (comment)
disconnect3d pushed a commit that referenced this pull request Nov 26, 2022
…lated to config (#1388)

* Add a config for the `vis_heap_chunks` command

After this commit, we can use `set default-visualize-chunk-number <number>` to set the default value of the `count` argument of the `vis_heap_chunks` command.

* Add a test for `default-visualize-chunk-number`

* Refactor some code related to config

* Add `*`: #1315 (comment)

* Use `set_show_doc` instead of `docstring`: #1315 (comment)
@lebr0nli lebr0nli deleted the update-config branch December 5, 2022 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants