.gdbinit 中的变量别名?
这可能吗?
举一个具体的例子,考虑下面的宏:
define pos
po ([self $arg0])
end
所以现在如果我输入 pos 文本,它就会变成 po [self text]。但对于多个参数,它会失败,例如 pos textLabel 文本变成 po [self textLabel] 而不是所需的 po [[self textLabel]text]。
再举个例子,正如这三个命令
po someIvar_
po [self someMethod]
po [[self someMethod]someOtherMethod]
打印出所引用的三个对象的描述一样,定义一个对整数执行相同操作的宏 pi 会很棒,即
pi [self someMethod]
与调用相同
print (int)[self someMethod],
,并且对于
pi [[self someMethod]someOtherMethod].
Is this possible?
To make a concrete example, consider the following macro:
define pos
po ([self $arg0])
end
So now if I input pos text, it gets turned into po [self text]. But with multiple arguments, it fails, e.g. pos textLabel text gets turned into po [self textLabel] rather than the desired po [[self textLabel]text].
For another example, just as the three commands
po someIvar_
po [self someMethod]
po [[self someMethod]someOtherMethod]
print out the descriptions of the three objects referenced, it would be great to define a macro pi that does the same thing for integers, i.e.
pi [self someMethod]
is the same as calling
print (int)[self someMethod],
and similarly for
pi [[self someMethod]someOtherMethod].
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
用户定义的命令只比执行前的字符串替换多一点。您的示例
pos textLabel text
将两个参数传递给仅考虑一个参数的命令。第二个被扔掉了。在执行之前,它应该产生po [self textLabel]
。您所做的与以下 java-sum-function 相当:int sum(int[] args){return args.get(0);}
您需要的是 sth 这里提到:
我没有发现任何类型的循环。因此,这应该是执行此操作的唯一方法,除非可以从 args 中弹出 arg0 并且允许用户定义命令的递归调用。但我认为完成上面的例子更容易。
pi
应该以相同的方式实现,也许有更好的解决方案,但这会让您朝着目的地更进一步。
user-defined commands are just a bit more than string-replaces before executing. Your example
pos textLabel text
passes two parameters to a command which only considers one parameter. The second is thrown away. It should result inpo [self textLabel]
before executing. What you do is comparable to the following java-sum-function:int sum(int[] args){return args.get(0);}
what you need is sth mentioned here :
I have not found any kind of a loop. So this should be the only way to do this except it is possible to to pop arg0 out of args and recursive-calls of user-defined-commands are allowed. But I think its easier to complete the example above.
pi
should be implemented the same waymaybe there is a better solution but this brings you a step further towards your destination.
如果您尝试使用
婆
圆周率
在终端中使用命令查看对象的值,或者您想在运行时更改该值,所以这里是解决方案:
现在这是在 XCode 4 中调试和分析目标 c 代码的最佳解决方案。如果您想更改值在运行时,您可以轻松更改变量,只需单击“运行 > 显示 > 表达式...”
在那里您可以为变量名称提供值。
但我怀疑你的问题不是 Objective-C 的问题,但我仍然尽力提供解决方案。
If you are trying to use
po
pi
command in terminal to see the value of an object or you want to change the value at runtime so here is the solution:
Now here is the best solution to debug and analyze the objective c code in XCode 4. If you want to change the value of a variable at runtime you can change very easily by just Click "Run > Show > Expressions...
and there you can provide value to your variable name.
But I suspect that your problem is not the Objective-C problem, but still I did my best to provide the solution.