public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Unexpected behavior of `gdb.PARAM_INTEGER` and `gdb.PARAM_UINTEGER` parameter
@ 2022-10-22  8:36 利承昕
  2022-10-31 10:12 ` Andrew Burgess
  0 siblings, 1 reply; 2+ messages in thread
From: 利承昕 @ 2022-10-22  8:36 UTC (permalink / raw)
  To: gdb

[-- Attachment #1: Type: text/plain, Size: 1644 bytes --]

Hi,

I've noticed that if we use Python API to create a `gdb.PARAM_INTEGER` or
`gdb.PARAM_UINTEGER` parameter this way:

```
$ cat test.py

import gdb
class ExampleParam(gdb.Parameter):
    def __init__ (self, name):
        super(ExampleParam, self).__init__ (name, gdb.COMMAND_DATA,
gdb.PARAM_INTEGER)
        self.value = 0
        self.saved_value = True

    def get_set_string (self):
        print(self.value)
        return "Set to %r" % self.value

ExampleParam("example”)
```

According to the docs here:
https://sourceware.org/gdb/onlinedocs/gdb/Parameters-In-Python.html, `0`
should be interpreted to mean "unlimited", so I expected that when a
`gdb.PARAM_INTEGER` or `gdb.PARAM_UINTEGER` parameter’s value is
"unlimited" in GDB, then the value in Python will be interpreted to 0.

But somehow, GDB interprets `None` to mean "unlimited" for that parameter
we created:

```
$ gdb -q -nx -ex 'source test.py’
(gdb) show example
The current value of 'example' is "unlimited”.
(gdb) pi gdb.parameter("example") is None
True
(gdb) set example unlimited
None
Set to None
(gdb) pi gdb.parameter("example") is None
True
(gdb) show example
The current value of 'example' is "unlimited".
(gdb) set example 0
None
Set to None
(gdb) pi gdb.parameter("example") is None
True
(gdb) show example
The current value of 'example' is "unlimited".
```

You can notice that GDB set the value of the `example` to `None` instead of
`0`.

Is this the expected result?

My GDB version is GNU gdb (Ubuntu 12.0.90-0ubuntu1) 12.0.90, and I'm on
Ubuntu 22.04.1 LTS.

Best Regards,
Alan Li

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Unexpected behavior of `gdb.PARAM_INTEGER` and `gdb.PARAM_UINTEGER` parameter
  2022-10-22  8:36 Unexpected behavior of `gdb.PARAM_INTEGER` and `gdb.PARAM_UINTEGER` parameter 利承昕
@ 2022-10-31 10:12 ` Andrew Burgess
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Burgess @ 2022-10-31 10:12 UTC (permalink / raw)
  To: 利承昕, gdb

利承昕 via Gdb <gdb@sourceware.org> writes:

> Hi,
>
> I've noticed that if we use Python API to create a `gdb.PARAM_INTEGER` or
> `gdb.PARAM_UINTEGER` parameter this way:
>
> ```
> $ cat test.py
>
> import gdb
> class ExampleParam(gdb.Parameter):
>     def __init__ (self, name):
>         super(ExampleParam, self).__init__ (name, gdb.COMMAND_DATA,
> gdb.PARAM_INTEGER)
>         self.value = 0
>         self.saved_value = True
>
>     def get_set_string (self):
>         print(self.value)
>         return "Set to %r" % self.value
>
> ExampleParam("example”)
> ```
>
> According to the docs here:
> https://sourceware.org/gdb/onlinedocs/gdb/Parameters-In-Python.html, `0`
> should be interpreted to mean "unlimited", so I expected that when a
> `gdb.PARAM_INTEGER` or `gdb.PARAM_UINTEGER` parameter’s value is
> "unlimited" in GDB, then the value in Python will be interpreted to 0.

You are correct that this area is not well documented.  These parameter
types have always returned None for unlimited, so I don't think we'd
want to consider changing the behaviour at this point.

There is already a related patch on the mailing list that will improve
the documentation of these parameter types:

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

Thanks,
Andrew

>
> But somehow, GDB interprets `None` to mean "unlimited" for that parameter
> we created:
>
> ```
> $ gdb -q -nx -ex 'source test.py’
> (gdb) show example
> The current value of 'example' is "unlimited”.
> (gdb) pi gdb.parameter("example") is None
> True
> (gdb) set example unlimited
> None
> Set to None
> (gdb) pi gdb.parameter("example") is None
> True
> (gdb) show example
> The current value of 'example' is "unlimited".
> (gdb) set example 0
> None
> Set to None
> (gdb) pi gdb.parameter("example") is None
> True
> (gdb) show example
> The current value of 'example' is "unlimited".
> ```
>
> You can notice that GDB set the value of the `example` to `None` instead of
> `0`.
>
> Is this the expected result?
>
> My GDB version is GNU gdb (Ubuntu 12.0.90-0ubuntu1) 12.0.90, and I'm on
> Ubuntu 22.04.1 LTS.
>
> Best Regards,
> Alan Li


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-31 10:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-22  8:36 Unexpected behavior of `gdb.PARAM_INTEGER` and `gdb.PARAM_UINTEGER` parameter 利承昕
2022-10-31 10:12 ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).