插入C++;映射导致无限递归? 我试图编写一些代码,允许我从外部> C”/>代码>函数中插入C++映射。代码如下: class CFITracing { std::unordered_map<uintptr_t, uintptr_t> CallerCalleePairs; std::map<std::string, int> BranchResults; public: void HandleCallerCallee(uintptr_t Caller, uintptr_t Callee); void HandleBranchResult(int cond, char* branchName); void printResults(); }; ... void CFITracing::HandleBranchResult(int cond, char* branchName) { std::string branchStr(branchName); printf("%s\n", "pre"); /* segfault at this line, regardless of what string I use as a key (even "hi") */ BranchResults[branchStr] = cond; printf("%s\n", "success"); } CFITracing CFIT; __attribute__((used)) __attribute__((optnone)) extern "C" void __trace(int cond, char* branchName) { CFIT.HandleBranchResult(cond, branchName); }

插入C++;映射导致无限递归? 我试图编写一些代码,允许我从外部> C”/>代码>函数中插入C++映射。代码如下: class CFITracing { std::unordered_map<uintptr_t, uintptr_t> CallerCalleePairs; std::map<std::string, int> BranchResults; public: void HandleCallerCallee(uintptr_t Caller, uintptr_t Callee); void HandleBranchResult(int cond, char* branchName); void printResults(); }; ... void CFITracing::HandleBranchResult(int cond, char* branchName) { std::string branchStr(branchName); printf("%s\n", "pre"); /* segfault at this line, regardless of what string I use as a key (even "hi") */ BranchResults[branchStr] = cond; printf("%s\n", "success"); } CFITracing CFIT; __attribute__((used)) __attribute__((optnone)) extern "C" void __trace(int cond, char* branchName) { CFIT.HandleBranchResult(cond, branchName); },c++,c,trace,C++,C,Trace,堆栈溢出的存在,再加上重复的打印,让我觉得无限递归已经被触发。我认为可能是我创建了某种类型的未定义行为,但我不确定如何编写此代码来防止它,因为我需要通过此extern“C”\uu trace()函数插入映射 因此,我的问题如下:有没有什么快速的方法可以阻止这种行为的发生?如果没有,我应该如何重新设计它,因为我需要通过extern“C”函数插入地图?谢谢你的帮助 您说您正在以非标准方式插入对\u trace的调用。您是否确保这些调用正确处理寄存器并符合正确的调用约定?您强制转换到std::stri

堆栈溢出的存在,再加上重复的打印,让我觉得无限递归已经被触发。我认为可能是我创建了某种类型的未定义行为,但我不确定如何编写此代码来防止它,因为我需要通过此
extern“C”\uu trace()
函数插入映射


因此,我的问题如下:有没有什么快速的方法可以阻止这种行为的发生?如果没有,我应该如何重新设计它,因为我需要通过
extern“C”
函数插入地图?谢谢你的帮助

您说您正在以非标准方式插入对
\u trace
的调用。您是否确保这些调用正确处理寄存器并符合正确的调用约定?您强制转换到std::string branchStr(branchName);你在哪里使用它?您能展示branchStr()的实现吗?这是多线程代码吗?您确定在使用指针插入映射时该指针有效吗?@rsjaffe我正在使用LLVM编译器将这些调用插入LLVM IR,LLVM验证器允许进行编译,因此我认为寄存器处理低于插入调用时的抽象级别。另外,当我删除映射插入时,程序按预期工作,因此_跟踪调用本身似乎不会引起问题branchName的函数内部发生了什么?因为您实际上
BranchResults[char*branchName]=cond
==20881== Stack overflow in thread #1: can't grow stack to 0x1ffe801000
==20881== 
==20881== Process terminating with default action of signal 11 (SIGSEGV)
==20881==  Access not within mapped region at address 0x1FFE801FF8
==20881== Stack overflow in thread #1: can't grow stack to 0x1ffe801000
==20881==    at 0x58069A2: _IO_file_xsputn@@GLIBC_2.2.5 (fileops.c:1220)