C 在调试器中运行函数/方法
我试图在调试器中运行以下函数 我有一个由解析器创建的带注释的语法树。我可以使用LLDB浏览树,但我想使用一个函数来浏览树。我不知道如何在LLDB中做到这一点C 在调试器中运行函数/方法,c,lldb,C,Lldb,我试图在调试器中运行以下函数 我有一个由解析器创建的带注释的语法树。我可以使用LLDB浏览树,但我想使用一个函数来浏览树。我不知道如何在LLDB中做到这一点 IrNode*findNthIrNodeOfTypeHelper(State * N, IrNode * root, IrNodeType expectedType, int* nth) { if (root->type == expectedType) { if(*nth == 0)
IrNode*findNthIrNodeOfTypeHelper(State * N, IrNode * root, IrNodeType expectedType, int* nth)
{
if (root->type == expectedType)
{
if(*nth == 0)
{
return root;
}
*nth = *nth - 1;
}
IrNode * nthNode;
if (root->irLeftChild != NULL &&
(nthNode = findNthIrNodeOfTypeHelper(N, root->irLeftChild, expectedType, nth)) != NULL)
{
return nthNode;
}
if (root->irRightChild != NULL &&
(nthNode = findNthIrNodeOfTypeHelper(N, root->irRightChild, expectedType, nth)) != NULL)
{
return nthNode;
}
return NULL;
}
我不确定你到底在问什么,但是给你一个C程序,比如
#include <stdlib.h>
struct elem {
struct elem *left;
struct elem *right;
int datum;
};
int element_number = 0;
struct elem *new_elem ()
{
struct elem *e = (struct elem *) malloc (sizeof (struct elem));
e->left = NULL;
e->right = NULL;
e->datum = element_number++;
return e;
}
int main ()
{
struct elem *root = new_elem();
root->left = new_elem();
root->left->left = new_elem();
root->right = new_elem();
root->right->left = new_elem();
root->right->left->right = new_elem();
root->right->right = new_elem();
return root->datum;
}
然后使用它:
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100000f85 a.out`main + 117 at a.c:29
26 root->right->left->right = new_elem();
27 root->right->right = new_elem();
28
-> 29 return root->datum;
30 }
Target 0: (a.out) stopped.
Process 36029 launched: '/tmp/a.out' (x86_64)
(lldb) print_tree root
datum: 0
left:
datum: 1
left:
datum: 2
right:
datum: 3
left:
datum: 4
right:
datum: 5
right:
datum: 6
(lldb) q
你的问题是什么?你尝试了什么,你期望什么,你得到了什么?
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100000f85 a.out`main + 117 at a.c:29
26 root->right->left->right = new_elem();
27 root->right->right = new_elem();
28
-> 29 return root->datum;
30 }
Target 0: (a.out) stopped.
Process 36029 launched: '/tmp/a.out' (x86_64)
(lldb) print_tree root
datum: 0
left:
datum: 1
left:
datum: 2
right:
datum: 3
left:
datum: 4
right:
datum: 5
right:
datum: 6
(lldb) q