52

I use print (CEthPacket*) 0xeb609a0 to examine an object at the given address and get A syntax error in expression, near ') 0xeb609a0'.

What am I doing wrong?

EDIT: CEthPacket is a C++ class and I'm on gdb Fedora (6.8-37.el5).

jackhab
  • 17,128
  • 37
  • 99
  • 136

4 Answers4

81

I just ran in to similar issue, and, from a colleague of mine, I learnt that you need to provide the namespace that the class belongs to within a single quotes as following:

(gdb) p ('MyScope::MyClass'*) ptr; 
ByteNudger
  • 1,545
  • 5
  • 29
  • 37
Tsh
  • 811
  • 6
  • 3
  • 8
    And what about templates? How do I tell gdb that this value is a `std::vector*`, for example? – ulidtko Nov 16 '12 at 15:22
  • 1
    @ulidtko The best I found is to use the mangled name. I made [a separate Q&A](https://stackoverflow.com/q/56467595/1896169), where I say barely more than that. – Justin Jun 05 '19 at 20:55
7

You didn't say on which platform, which version of GDB, or what CEthPacket is.

My first guess is that you should try print (struct CEthPacket *) 0xeb609a0 instead.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
2

Also your starting namespace is the one from current stack. If you want to start from root you have to use ::NS1::NS2::Obj.

Mamue
  • 21
  • 1
-1

I just ran into a very similar error. It was caused because I was trying to reference an object that is not defined in the scope of the current stack frame. Try changing to a stack frame where the CEthrPacket object is defined.