Bug 26644 - `info variables` does not show ones defined with #define
Summary: `info variables` does not show ones defined with #define
Status: UNCONFIRMED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: 9.2
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-22 10:21 UTC by Hi-Angel
Modified: 2020-09-24 12:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hi-Angel 2020-09-22 10:21:54 UTC
Currently `info variables` command does not print ones declared with `#define`. I mean, it kinda makes sense if you take the meaning of "variable" as of a mutable identifier. However this is not the meaning gdb uses because the command prints enum fields just fine, which are not mutable either. So this is a bug.

# Steps to reproduce (in terms of terminal commands)

    $ cat test2.c
    #define MY_MACRO 7

    int main() {}
    $ gcc test2.c -o a -g3 -O0
    $ gdb ./a
    Reading symbols from ./a...
    gdb λ br main
    Breakpoint 1 at 0x1122: file test2.c, line 3.
    gdb λ r
    Starting program: /tmp/a

    Breakpoint 1, main () at test2.c:3
    3       int main() {}
    gdb λ p MY_MACRO
    $1 = 7
    gdb λ info variables MY_MACRO
    All variables matching regular expression "MY_MACRO":
    gdb λ

## Expected

`info variables` would print `#define MY_MACRO 7`

## Actual

`info variables` did not print anything about MY_MACRO.
Comment 1 Tom Tromey 2020-09-23 19:51:49 UTC
gdb will show this with "info macro".
Macros aren't really variables, and often there are many
more in scope than you might think -- enough that they
would overwhelm the output relating to real variables,
which is probably what most users want.
Comment 2 Hi-Angel 2020-09-23 21:32:11 UTC
(In reply to Tom Tromey from comment #1)
> gdb will show this with "info macro".  Macros aren't really variables

You probably imply that macros can accept arguments, which makes them not to be
variables. Well… probably that's fair too. Feel free to close report if you don't
think it's actionable.

>, and often there are many more in scope than you might think -- enough that
> they would overwhelm the output relating to real variables, which is probably
> what most users want.

I don't think such problem is a thing. If you execute `info variables` with the original
testcase which does not even contain includes, you will get so overwhelming
amount of output that terminal scrollback won't have enough space. That's why `i
variables` supports regexps, to reduce the output.
Comment 3 Tom Tromey 2020-09-24 12:35:26 UTC
(In reply to Hi-Angel from comment #2)
> (In reply to Tom Tromey from comment #1)
> > gdb will show this with "info macro".  Macros aren't really variables
> 
> You probably imply that macros can accept arguments, which makes them not to
> be
> variables.

They also have different scoping and can expand to anything,
which isn't actually all that uncommon.

> I don't think such problem is a thing. If you execute `info variables` with
> the original
> testcase which does not even contain includes, you will get so overwhelming
> amount of output that terminal scrollback won't have enough space.

Try it on a real program, like say any random function in gdb itself,
and you'll see what I mean.