This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/23444] New: Syntax error for watch -l and print


https://sourceware.org/bugzilla/show_bug.cgi?id=23444

            Bug ID: 23444
           Summary: Syntax error for watch -l and print
           Product: gdb
           Version: 8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
          Assignee: unassigned at sourceware dot org
          Reporter: ftfish at gmail dot com
  Target Milestone: ---

Hi all,

I encountered a syntax error problem while debugging with `watch -l`.
The problem seems to happen when a class in a namespace has the same
name as the namespace.
A minimal working example:

# main.cpp
#include <iostream>

using namespace std;

namespace NS {

enum T {a, b, c};

class NS {
    T field = b;
public:
    void test() {
        cout << field << endl;
    }
};

}

int main()
{
    NS::NS x;
    x.test();

    return 0;
}


# log
(gdb) b NS::NS::test
Breakpoint 1 at 0x40089c: file main.cpp, line 13.
(gdb) run
Starting program: /test/a.out 

Breakpoint 1, NS::NS::test (this=0x7fffffffcb5c) at main.cpp:13
13              cout << field << endl;
(gdb) watch -l field
A syntax error in expression, near `) 0x00007fffffffcb5c'.
(gdb) p field
$1 = NS::b
(gdb) p &field
$2 = (NS::T *) 0x7fffffffcb5c
(gdb) watch *(NS::T *) 0x7fffffffcb5c
A syntax error in expression, near `) 0x7fffffffcb5c'.
(gdb) p *(NS::T *) 0x7fffffffcb5c
A syntax error in expression, near `) 0x7fffffffcb5c'.
(gdb) watch *(::NS::T *) 0x7fffffffcb5c
Hardware watchpoint 2: *(::NS::T *) 0x7fffffffcb5c
(gdb) p *(::NS::T *) 0x7fffffffcb5c
$3 = NS::b
(gdb) ptype NS
type = class NS::NS {
  private:
    NS::T field;

  public:
    void test(void);
}
(gdb) ptype ::NS
type = namespace NS
(gdb) watch -l this->field
A syntax error in expression, near `) 0x00007fffffffcb5c'.
(gdb) 


GDB 8.1
C++ Compiler: gcc-7.2.1 linuxx86_64
OS: SUSE Linux Enterprise 12 SP2, 64bit
Compiler arguments: g++ -g main.cpp

Any help/pointer is appreciated. To me it seems a bug because `watch`
works but `watch -l` does not.

Thanks
Joe

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]