.gdbinit 中的变量别名?

发布于 2024-11-28 13:06:32 字数 600 浏览 1 评论 0原文

这可能吗?

举一个具体的例子,考虑下面的宏:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

找回味觉 2024-12-05 13:06:33

用户定义的命令只比执行前的字符串替换多一点。您的示例 pos textLabel text 将两个参数传递给仅考虑一个参数的命令。第二个被扔掉了。在执行之前,它应该产生 po [self textLabel] 。您所做的与以下 java-sum-function 相当:
int sum(int[] args){return args.get(0);}

您需要的是 sth 这里提到

define pos
    if $argc == 1
        po [self $arg0]
    end
    if $argc == 2
        po [[self $arg0] $arg1]
    end
    ..... (as many you need)
end

我没有发现任何类型的循环。因此,这应该是执行此操作的唯一方法,除非可以从 args 中弹出 arg0 并且允许用户定义命令的递归调用。但我认为完成上面的例子更容易。

pi 应该以相同的方式实现,

define pi
    if $argc == 1
        print (int)[self $arg0]
    end
    if $argc == 2
        print (int)[[self $arg0] $arg1]
    end
    ....
end

也许有更好的解决方案,但这会让您朝着目的地更进一步。

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 in po [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 :

define pos
    if $argc == 1
        po [self $arg0]
    end
    if $argc == 2
        po [[self $arg0] $arg1]
    end
    ..... (as many you need)
end

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 way

define pi
    if $argc == 1
        print (int)[self $arg0]
    end
    if $argc == 2
        print (int)[[self $arg0] $arg1]
    end
    ....
end

maybe there is a better solution but this brings you a step further towards your destination.

蝶…霜飞 2024-12-05 13:06:33

如果您尝试使用

圆周率
在终端中使用命令查看对象的值,或者您想在运行时更改该值,所以这里是解决方案:

现在这是在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文