工具找到C codeBase的全局/静态变量 [英] Tool to find global/static variables in C codebase

查看:148
本文介绍了工具找到C codeBase的全局/静态变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个C ++ - 为其最初是为微处理器编写一个更大的C codeBase的包装(一类)。现在,我们要模拟代理人运行此C $ C $的c多个实例。当我们想看看他们是如何相互作用,我们需要同时运行它们。如果可能的话,我们希望在一个进程中运行它们。

I have created a C++-wrapper (a class) for a larger C codebase which was originally written for a microprocessor. Now we want to simulate multiple instances of "agents" running this C code. As we want to see how they interact, we need to run them simultaneously. If possible, we'd like to run them in one process.

这失败起初因为C code使用静态变量,因此没有线程安全的。我们认为我们已经删除了所有的静态和全局变量,但仍然没有得到预期的结果。 (一切都正常运行,如果我们只有一个实例。)

This failed at first because the C code used static variables and thus wasn't thread safe. We thought we had removed all static and global variables but still don't get the expected results. (Everything runs fine if we have only one instance.)

所以我的问题是:不是寻找这样的变量整个code基,有可能有助于发现问题的工具?在C code的写在Keil公司的μVision,现在在Visual Studio编译2008团队套件。

So my question is: instead of searching the whole code base for such variables, is there any tool that might assist to find the problem? The C code was written in Keil μVision and is now compiled in Visual Studio 2008 Team Suite.

感谢您的建议!

推荐答案

如果您可以在多个UNIX十岁上下的环境构建它,你应该有一个尺寸命令你可以在的.o 文件运行会告诉你数据 BSS 段大小为每个的.o 文件。这是查找静态存储持续时间的变量(只要看看非零尺寸在这些字段中)。

If you can build it in a more unix-ish environment, you should have a size command you can run on .o files that will tell you the data and bss segment sizes for each .o file. This is a very quick way to find variables of static storage duration (just look for nonzero sizes in either of these fields).

也许你可以尝试使用MinGW或Cygwin的建设,或寻找MSVC的工具类似的工具。

Perhaps you could try building with mingw or cygwin, or looking for a similar tool in the MSVC toolset.

这篇关于工具找到C codeBase的全局/静态变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆