How to print and use constants with gdb (via Xcode)?

I am debugging a Cocoa application using xcode-gdb. I am at a break point and I need to look at the value of some Cocoa constants (i.e.NSControlKeyMask) and do some test with the values ​​in the current stack. In particular, I'm in

- (void) keyDown: (NSEvent *) e 
and i did
set $ mf = (int) [e modifierFlags]
at the gdb command prompt. Now i want to do
p $ mf & NSControlKeyMask
, and gdb tells me "There is no" NSControlKeyMask "character in the current context.

UPDATE:
Xcode has a Fix and Continue text function . "Therefore, I used Dan M. and n8gray's solution with this function, so I do not need to proxy for each constant.

+5
source share
5 answers

If no variables are actually created with the given type, then the debugging information for the corresponding characters does not end with gcc. Then, if you ask gdb about this type, it does not know what you are talking about, because there is no debugging information for this type, and it will give you the error "There is no character in the current context."

A workaround to this problem would usually be to explicitly add a dummy type-related variable somewhere in the code. Here is a simple example that you can check to find out what I'm talking about:

enum an_enum_type {
  foo,
  bar,
  baz
};

int main (int argc, char *argv [])
{
  return baz;
}

Save this program to a file called test.cpp and compile it with this command:

g++ -o test -g -O0 test.cpp

gdb "p/x baz". " baz ".

, :

enum an_enum_type {
  foo,
  bar,
  baz
};

an_enum_type dummy;

int main (int argc, char *argv [])
{
  return baz;
}

, , gdb. , "p/x baz", "0x2" , , , .

, , NSEvent.h , NSControlKeyMask - . , ( ). , . , NSControlKeyMask .

+6

gcc, -g3, . -g gcc:

-glevel
    Request debugging information and also use level to specify how much information. The default level is 2.

    Level 0 produces no debug information at all. Thus, -g0 negates -g.

    Level 1 produces minimal information, enough for making backtraces in parts 
            of the program that you don't plan to debug. This includes descriptions
            of functions and external variables, but no information about local 
            variables and no line numbers.

    Level 3 includes extra information, such as all the macro definitions present 
            in the program. Some debuggers support macro expansion when you use
            -g3. 

, -g3, gdb.

+3

., , , . - :

int myNSControlKeyMask = NSControlKeyMask;
int myNSOptionKeyMask = NSOptionKeyMask;
...

gdb, .h.

+2

NSControlKeyMask . .h. NSControlKeyMask + , .

+1

, ++, Obj-C iPhone. "a" .
error, a - int. -g3 . , gdb int. SDK 3.0, , gdb , .

0

All Articles