代码之家  ›  专栏  ›  技术社区  ›  asksol

在gdb中调试Objective-C时向对象发送消息,不带符号

  •  11
  • asksol  · 技术社区  · 18 年前

    我正在尝试向gdb中的Objective-C对象发送消息。

    (gdb) p $esi
    $2 = (void *) 0x1268160
    (gdb) po $esi
    <NSArray: 0x1359c0>
    (gdb) po [$esi count]
    Target does not respond to this message selector.
    

    3 回复  |  直到 10 年前
        1
  •  10
  •   Kendall Helmstetter Gelner    18 年前

    如果必须重写gdb并在对象不允许时向其发送消息,则可以使用PerformSelect:

    (gdb) print (int)[receivedData count]
    Target does not respond to this message selector.
    
    (gdb) print (int)[receivedData performSelector:@selector(count) ]
    2008-09-15 00:46:35.854 Executable[1008:20b] *** -[NSConcreteMutableData count]:
    unrecognized selector sent to instance 0x105f2e0
    

    (gdb) print (int)[receivedData performSelector:@selector(count) withObject:myObject ]
    
        2
  •  1
  •   John Calsbeek    18 年前

    有没有可能你需要投 $esi ?

    p (NSUInteger)[(NSArray *)$esi count]
    
        3
  •  0
  •   asksol    18 年前

    @[约翰·卡尔斯贝克]

    然后它抱怨缺少符号。

    (gdb) p (NSUInteger)[(NSObject*)$esi retainCount]
    No symbol table is loaded.  Use the "file" command.
    (gdb) p [(NSArray *)$esi count]
    No symbol "NSArray" in current context.
    

    (gdb) add-symbol-file /System/Library/Frameworks/Foundation.framework/Foundation 
    add symbol table from file "/System/Library/Frameworks/Foundation.framework/Foundation"? (y or n) y
    Reading symbols from /System/Library/Frameworks/Foundation.framework/Foundation...done.
    

    但还是没有运气:

    (gdb) p [(NSArray *)$esi count]
    No symbol "NSArray" in current context.
    

    无论如何,我不认为强制转换是解决这个问题的方法,你不需要知道它是什么类型的对象,就可以向它发送消息。

    (gdb) p $eax
    $11 = 367589056
    (gdb) po $eax
    <NSCFArray 0x15e8f6c0>(
        file://localhost/Users/ask/Documents/composing-fractals.pdf
    )
    
    (gdb) p (int)[$eax retainCount]
    $12 = 1
    

    所以我想我正在调查的物体有问题。。。或者别的什么。

    谢谢你的帮助!