小编lal*_*rde的帖子

gcc编译器标志和符号表之间的不兼容函数地址

我已经编译了一个项目(openssh,但这并不重要)

CFLAGS="-ggdb3 -O0 -lm -finstrument-functions"
Run Code Online (Sandbox Code Playgroud)

符号表是(小提取):

nm -o somepath/sbin/sshd
/mypath/install/sbin/sshd:000f3548 d auth_method
/mypath/install/sbin/sshd:0001a90f t auth_openfile
/mypath/install/sbin/sshd:0001ab90 T auth_openkeyfile
/mypath/install/sbin/sshd:0001ac31 T auth_openprincipals
/mypath/install/sbin/sshd:0001d73a T auth_parse_options
/mypath/install/sbin/sshd:0000e362 T auth_password
Run Code Online (Sandbox Code Playgroud)

我打印函数地址时获得的__cyg_profile_func_enter|exit是:

0xb768f8ee
0xb768f66c
0xb768f66c
0xb76d9ae8
Run Code Online (Sandbox Code Playgroud)

显然是不一样的范围,在看了所有的数字后确认.

据我所知,nm提供偏移地址.什么__cyg_profile_func_enter时候项目中有很多文件?是否还有其他转换功能?

gcc文档中,不应该:

          void __cyg_profile_func_enter (void *this_fn,
                                         void *call_site);
          void __cyg_profile_func_exit  (void *this_fn,
                                         void *call_site);

The first argument is the address of the start of the current function, which may be looked up exactly in the symbol table.
Run Code Online (Sandbox Code Playgroud)

那么,我想让它做什么工作呢?

编辑:我的ptrace.c,我添加了一个互斥锁 …

gcc profiling debug-symbols

5
推荐指数
1
解决办法
246
查看次数

未跟踪的文件仍以git状态显示

我使用.git/info/exclude跟踪了一些文件夹和文件:

doc
*.txt
doc/*.txt
doc/somefile.txt
Run Code Online (Sandbox Code Playgroud)

但是git status表示它仍然被跟踪:

$ git st
# On branch dev
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   doc/somefile.txt
Run Code Online (Sandbox Code Playgroud)

其他奇怪的事情ls-files表明它没有跟踪:

$ git ls-files --ignored --exclude-from=.git/info/exclude
doc/somefile.txt
$ touch /tmp/xxx
$ git ls-files --ignored --exclude-from=/tmp/xxx
$
Run Code Online (Sandbox Code Playgroud)

我在git版本1.8.1.5

所以我得出结论,我可能会误解某些事情或做错事.有什么好主意吗?

git

4
推荐指数
1
解决办法
1763
查看次数

在C++中malloc/free和new/delete兼容性?

还有的malloc /自由和新的一个很好的比较/删除这里,好解释如何malloc()和free()的工作在这里.显然,我们不会混用它们 - 免费使用new或使用malloc删除.

我们可以看到许多开源项目,有许多贡献者,使用这两种机制,同时尊重上述"无混合"规则.通常,在一个文件中只有一种方式(一个作者,一个偏好).我已经分叉了这样一个项目,我正在使用new/delete添加一些功能.但我遇到了一些奇怪的记忆腐败.当然,我可能对他们负责,但.....

这让我想问一些"天真"的问题:

  1. 我可以在同一个编译单元(*.o)中同时使用malloc/free和new/delete机制 - 当然,尊重"无混合"规则?

  2. 我可以交错两种机制,就像在这段代码中一样吗?

    int *a = (int *) malloc (1000 * sizeof int);
    
    int *b = new int[1000];
    
    // some code
    
    free a;
    
    delete[] b;
    
    Run Code Online (Sandbox Code Playgroud)

c++ malloc free new-operator delete-operator

4
推荐指数
1
解决办法
3978
查看次数

如何在 Python 2.7 中声明一个空字典的空字典?

要声明一个空字典,我这样做:

mydict = dict()
Run Code Online (Sandbox Code Playgroud)

要声明一个空字典的空字典,我也可以这样做:

mydictofdict = dict()
Run Code Online (Sandbox Code Playgroud)

然后在需要时添加字典:

mydict1 = dict()
mydictofdict.update({1:mydict1})
Run Code Online (Sandbox Code Playgroud)

以及需要时其中的元素:

mydictofdict[1].update({'mykey1':'myval1'})
Run Code Online (Sandbox Code Playgroud)

它是pythonic吗?有没有更好的方法来执行它?

python dictionary python-2.7

4
推荐指数
1
解决办法
2988
查看次数

如何在使用sed或awk预处理C/C++代码时可靠地定位函数?

我希望通过使用sed/awk预处理源文件来直接检测我的代码.我不能使用其他方法,如调试器跟踪或gcc选项-finstrument-functions.在最后一种情况下,地址以某种我无法管理的方式重新定位,我错过了与符号表的对应关系.这里介绍的其他方法(ptrace,etrace,callgraph等)或者在这里可以很好地用于一个简单的例子,但不是在我的真实项目中.

问题在于,在处理大型开源项目时,函数的编写标准不仅在C和C++文件之间不同,而且通常在同一文件中.的{可以是在参数列表的结尾,或在另一行,结构或分配可使用的起始{,制作简单功能解析假.

因此,在函数定义的开头插入宏的上述链接中提供的解决方案通常不起作用,并且通过手工代码行(KLOC)进行校正是不可行的.

sed 's/^{/{ENTRY/'
Run Code Online (Sandbox Code Playgroud)

那么,如何使用在sed或awk中使用的正则表达式可靠地定位C/C++代码中的函数定义?可能通过使用gcc预编译代码的一部分?我正在寻找一些可能在船上的东西.

c c++ regex awk sed

3
推荐指数
1
解决办法
132
查看次数

我无法链接libfortuna库

我在Linux下构建了FreeBSD libfortuna库.我做了什么来管理这只是评论#include <malloc_np.h>的src/px.hSRC/internal.h,做make,make install并创建在我的系统标准路径库的符号链接.

然后,我为它写了一个小测试程序:

#include <cstdlib>
#include <fortuna.h>

int main () {
  int i = 0;
  fortuna_get_bytes (4, (unsigned char *) &i);
  printf ("test fortuna i = %d \n", i);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

然后编译并链接:

g++ -I/usr/local/include/fortuna -O0 -g3 -Wall -fmessage-length=0 -c test.cpp
g++ -g -L/usr/local/lib/ -o test test.o -lfortuna
test.o: In function `main':
/home/alain/Documents/Poker/WorkSpace/libfortuna/test/test.cpp:14: undefined reference to `fortuna_get_bytes(unsigned int, unsigned char*)'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

我也尝试了 …

c++ linux linker g++ undefined-reference

1
推荐指数
1
解决办法
142
查看次数

错误:将“const …”作为“…”的“this”参数传递会丢弃限定符

我有与hereherehere相同的问题,除了我为参数和函数设置了const:

#include <unordered_map>
#include <functional>

namespace zzz {

struct identity_t {
    static const int ID_SIZE = 5;
    static const int LSB = 4; // = ID_SIZE - 1
    unsigned char id[ID_SIZE];
    inline bool operator< (const identity_t& rhs) const {
        for (int i = 0; i < ID_SIZE; i++) if (id[i] != rhs.id[i]) return (id[i] < rhs.id[i]);
        return false; // equal
    }
    unsigned char operator[] (const int& i) {return id[i];}
};

class hash_identity_t {
public:
    long …
Run Code Online (Sandbox Code Playgroud)

c++ unordered-map constants

0
推荐指数
1
解决办法
1万
查看次数