简体   繁体   English

如何根据 C “字符串”的长度闯入 Xcode 的调试器?

[英]How to break into Xcode's debugger based on the length of a C “String”?

After searching online I found two ways to calculate the length of a C "String" [really character array]网上搜索后发现有两种方法可以计算一个C "String" [真字符数组]的长度

C array length: C 数组长度:

*(&arr + 1) - arr *(&arr + 1) - arr

OR或者

sizeof(arr) / sizeof(arr(0))大小(arr)/大小(arr(0))

only the one using sizeof works in Xcode's debugger.只有使用 sizeof 的那个在 Xcode 的调试器中有效。

I need to break into the debugger when a variable declared as "char* output[]" is 5.当声明为“char* output[]”的变量为 5 时,我需要进入调试器。

I tried "sizeof(output)/sizeof(output[0]) == 5" and it doesn't seem to be working, the break never triggers.我尝试了“sizeof(output)/sizeof(output[0]) == 5”,但它似乎不起作用,中断永远不会触发。

What am I doing wrong?我究竟做错了什么?

You have to execute something based on the test, otherwise the compiler will ignore it as a meaningless statement (although it should have flagged it if warnings were enabled).您必须根据测试执行某些操作,否则编译器会将其视为无意义的语句而忽略(尽管如果启用了警告,它应该已标记它)。

void r(void)
{   
    printf("Condition was triggered\n");
}

main()
{
    do_stuff();
    if(sizeof(output)/sizeof(output[0]) == 5)
    {
       r();
    }

then set a breakpoint on r().然后在 r() 上设置断点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM