Valgrind和"警告:新的重定向与现有的冲突"

Any*_*orn 13 c++ valgrind

我在Valgrind得到这个.

--24101-- REDIR: 0xbb20580 (operator delete(void*)) redirected to 0x93b7d48 (operator delete(void*))
--24101-- REDIR: 0xbb22580 (operator new[](unsigned long)) redirected to 0x93b88b7 (operator new[](unsigned long))
==24101== WARNING: new redirection conflicts with existing -- ignoring it
--24101--     new: 0x15632010 (__GI_strlen         ) R-> 0x093b96b0 strlen
--24101-- REDIR: 0xbb205c0 (operator delete[](void*)) redirected to 0x93b79c4 (operator delete[](void*))
Run Code Online (Sandbox Code Playgroud)

有什么顾虑吗?

Jes*_*sse 18

Valgrind的魔力很大一部分就是如何拦截/重定向函数调用以跟踪世界状态.

据我所知,重定向是使用共享对象/函数名称模式实现的,当匹配"重定向"调用新地址时.检查valgrind源代码,我们找到了'重定向器'的概念:

The redirector holds two pieces of state:

Specs  - a set of   (soname pattern, fnname pattern) -> redir addr
Active - a set of   orig addr -> (bool, redir addr)
Run Code Online (Sandbox Code Playgroud)

(m_redir.c第104行)

所以'Specs'提供共享对象/函数名称来映射映射,'Actives'代表映射本身.

主动计算:

Active = empty
for spec in Specs {
   sopatt = spec.soname pattern
   fnpatt = spec.fnname pattern
   redir  = spec.redir addr
   for so matching sopatt in SyminfoState {
      for fn matching fnpatt in fnnames_of(so) {
         &fn -> redir is added to Active
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

(m_redir.c第120行)

这里也提到了"冲突重定向"的想法:

Clearly we must impose the requirement that domain(Active) contains
no duplicates.  The difficulty is how to constrain Specs enough to
avoid getting into that situation.  It's easy to write specs which
could cause conflicting bindings in Active, eg:

   (libpthread.so, pthread_mutex_lock) ->    a1
   (libpthread.so, pthread_*)          ->    a2

for a1 != a2.  Or even hairier:

   (libpthread.so, pthread_mutex_*) ->    a1
   (libpthread.so, pthread_*_lock)  ->    a2
Run Code Online (Sandbox Code Playgroud)

(m_redir.c第152行)

为了利益,这里是您生成警告的地方:

old = VG_(OSetGen_Lookup)( activeSet, &act.from_addr );
if (old) {
   /* Dodgy.  Conflicting binding. */
   vg_assert(old->from_addr == act.from_addr);
   if (old->to_addr != act.to_addr) {
      /* we have to ignore it -- otherwise activeSet would contain
         conflicting bindings. */
      what = "new redirection conflicts with existing -- ignoring it";
      goto bad;
   } 
Run Code Online (Sandbox Code Playgroud)

(m_redir.c第664行)

因此,在所有这些之后,可以安全地假设:

  1. 重定向消息是正常valgrind操作的一部分.
  2. 警告消息可能是规范模式冲突的结果(在这种情况下可能不是引起关注的重要原因.)

参考文献:Valgrind手册,Valgrind 3.6.1源码

  • 请注意,当我像这样使用valgrind时,我得到了这些:`valgrind --leak-check = full -v./ your_program`.如果我删除`-v`,我就不会收到它们.非常好,有这个问题和答案,勇敢的家伙!:)我的意思是我很困惑发生了什么! (4认同)