简体   繁体   English

如何在C静态函数上设置VxWorks断点?

[英]How do I set a VxWorks breakpoint on a C static function?

I work on a vxworks platform in C. I am not able to set a breakpoint on a static C function. 我在C中的vxworks平台上工作。我无法在静态C函数上设置断点。 In fact when I do a lkup on the function name when the code is loaded on my card it is not found. 实际上,当我在卡上加载代码时对函数名称执行lkup时,找不到它。

If I use nm and grep to find the symbol in the executable it looks exactly like the name of the function. 如果我使用nm和grep在可执行文件中查找符号,则它看起来与函数名称完全相同。 We are porting code to our platform which uses (correctly) the static keyword for a large number of functions but it's a pain that I can't set a breakpoint on any of these. 我们正在将代码移植到我们的平台上,该平台(正确地)将static关键字用于大量函数,但是我无法在其中任何一个函数上设置断点是一件很痛苦的事情。

Does any one know why I can't see the C static functions on lkup and how to look them up and set the breakpoint. 有谁知道为什么我看不到lkup上的C静态函数以及如何查找它们并设置断点。

Thanks, 谢谢,

Rob

Assuming the routine really exists as you'd expect (ie, not optimized away or inlined) - I've used a couple approaches in situations like this: 假定例程确实如您期望的那样存在(即未优化或内联)-在这种情况下,我使用了几种方法:

Assembly breakpoint 装配断点

  • let's say you want to set a breakpoint at static function foo() . 假设您要在静态函数foo()处设置断点。 Find code that calls foo() - let's say bar() calls foo() . 查找调用foo()代码-假设bar()调用foo() Where bar() calls foo() , set a breakpoint. 如果bar()调用foo() ,则设置一个断点。

  • run until you hit the breakpoint where bar() calls foo() . 一直运行到到达bar()调用foo()的断点为止。 step at the assembly level. 在组装级别上执行。 This should put you at the first instruction of foo() . 这应该使您处于foo()的第一条指令上。 Note that you might have to step through a few instructions if there are parameters being passed - hopefully you know what a branch / subroutine call looks like in your architecture. 请注意,如果传递了参数,则可能必须逐步完成一些说明-希望您知道架构中的分支/子例程调用是什么样子。

  • Set an assembly breakpoint when you land at the first instruction of foo() . 当您到达foo()的第一条指令时,设置一个汇编断点。

Function pointer 功能指针

I've also worked around this by initializing a function pointer with foo() 's address. 我也通过使用foo()的地址初始化函数指针来解决此问题。 When system is running, read the function pointer in the debugger. 当系统运行时,读取调试器中的函数指针。 Get foo() 's address. 获取foo()的地址。 Set breakpoint based on this address. 根据该地址设置断点。

Note that in these cases you might not have interleaved source, though. 请注意,在这些情况下,您可能没有交错的源。

I don't think it is possible to do what you want. 我认为您不可能做任何想做的事情。 The compiler is not required to generate symbols for static functions, it may even inline them. 不需要编译器为静态函数生成符号,它甚至可以内联它们。

Example: 例:

$ gcc -o test test.c
$ nm test | grep foo
0000000000400524 t foo
$ gcc -O2 -o test test.c
$ nm test | grep foo
$

From the sound of it, you are using the shell to do your debugging and setting breakpoints. 从它的声音来看,您正在使用Shell进行调试和设置断点。
If that's the case, you might have an issue since a static function has internal linkage and is no longer a globally visible function (to the shell). 在这种情况下,您可能会遇到问题,因为静态函数具有内部链接,并且不再是全局可见的函数(对于Shell)。

If you are using DKMs and using the ld command to load the modules, you can add a parameter to LD that will also include static symbols which you should then be able to manipulate in the shell. 如果您正在使用DKM并使用ld命令来加载模块,则可以向LD添加一个参数,该参数还将包含静态符号,然后您应该可以在外壳中对其进行操作。

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

相关问题 如何在C for Python中设置静态类变量? - How do I set a static class variable in C for Python? 如何使用ac程序将命令写入vxworks shell - How can I write commands to the vxworks shell with a c program 如何在Vxworks中实现C定时器 - How to implement C timer in Vxworks 如何在C中的一组函数声明中强制执行函数签名? - How do I enforce function signatures on a set of function declarations in C? 如何在内核源代码中的fork.c中设置断点以获得函数的地址? - How to set breakpoint to obtain address of a function in fork.c , in the kernel source? 如何向内部函数添加断点 - How can I add breakpoint to internal function 当 char* x 指向值等于“hello”的字符串时,如何在 gdb 中设置条件断点? - How do I set a conditional breakpoint in gdb, when char* x points to a string whose value equals “hello”? 如何引用 C 中出现在需要它的函数之后的静态数据? - How do I reference a static data in C that appears after the function that needs it? 如何在vxworks 6.7中设置wdb进行内核前调试? - How do I setup wdb for Pre-Kernel debugging in vxworks 6.7? 如何创建要在两个.c源文件中使用的静态函数? - How do I create a static function to be used in two .c source files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM