boost正则表达式构造函数中的互斥断言 我使用Boost 1.47,用代码源C++编译器(4.5.1),从Windows 7交叉编译为目标Ubuntu。
编译调试版本(即启用断言)时,会触发断言:boost正则表达式构造函数中的互斥断言 我使用Boost 1.47,用代码源C++编译器(4.5.1),从Windows 7交叉编译为目标Ubuntu。,c++,regex,linux,boost,initialization,C++,Regex,Linux,Boost,Initialization,编译调试版本(即启用断言)时,会触发断言: pthread_mutex_lock.c:62: __pthread_mutex_lock: Assertion 'mutex->__data.__owner == 0' failed. 在发布模式下编译时,不会触发断言,程序工作正常(据我们所知) 这是在Ubuntu 10.x Arm板下发生的 因此,pthread_mutex_锁似乎认为互斥锁是由与当前线程不同的线程设置的。此时在我的程序中,我们仍然是单线程的,在调用regex构造函数之前,
pthread_mutex_lock.c:62: __pthread_mutex_lock: Assertion 'mutex->__data.__owner == 0' failed.
在发布模式下编译时,不会触发断言,程序工作正常(据我们所知)
这是在Ubuntu 10.x Arm板下发生的
因此,pthread_mutex_锁似乎认为互斥锁是由与当前线程不同的线程设置的。此时在我的程序中,我们仍然是单线程的,在调用regex构造函数之前,通过在main中打印pthread_self进行验证。也就是说,它不应该使断言失败
下面是触发问题的代码片段
// Set connection server address and port from a URL
bool MyHttpsXmlClient::set_server_url(const std::string& server_url)
{
#ifdef BOOST_HAS_THREADS
cout <<"Boost has threads" << endl;
#else
cout <<"WARNING: boost does not support threads" << endl;
#endif
#ifdef PTHREAD_MUTEX_INITIALIZER
cout << "pthread mutex initializer" << endl;
#endif
{
pthread_t id = pthread_self();
printf("regex: Current threadid: %d\n",id);
}
const boost::regex e("^((http|https)://)?([^:]*)(:([0-9]*))?"); // 2: service, 3: host, 5: port // <-- dies in here
模板化代码为:
// out of line members;
// these are the only members that mutate the basic_regex object,
// and are designed to provide the strong exception guarentee
// (in the event of a throw, the state of the object remains unchanged).
//
template <class charT, class traits>
basic_regex<charT, traits>& basic_regex<charT, traits>::do_assign(const charT* p1,
const charT* p2,
flag_type f)
{
shared_ptr<re_detail::basic_regex_implementation<charT, traits> > temp;
if(!m_pimpl.get())
{
temp = shared_ptr<re_detail::basic_regex_implementation<charT, traits> >(new re_detail::basic_regex_implementation<charT, traits>());
}
else
{
temp = shared_ptr<re_detail::basic_regex_implementation<charT, traits> >(new re_detail::basic_regex_implementation<charT, traits>(m_pimpl->m_ptraits));
}
temp->assign(p1, p2, f);
temp.swap(m_pimpl);
return *this;
}
我使用这些偏移量来检查内存中的数据。这些值没有意义:
例如,\uuu data.\uu lock
字段(一个int)是0xb086b580。\u计数
(无符号整数)为0x6078af00,\u所有者
(整数)为0x6078af00
这使我想到,不知何故,这个互斥体的初始化没有执行。或者它已经完全损坏,但我倾向于错过初始化,因为当我链接调试boost库时,没有断言
现在,我假设无论查询的是什么互斥体,都是用于使regex线程安全的全局/静态互斥体,并且不知何故它没有初始化
- 有人遇到过类似的情况吗?Ubuntu是否需要一些额外的步骤来确保互斥初始化
- 我的实现假设正确吗
- 如果它是正确的,有人能告诉我这个互斥锁是在哪里声明的,它的初始化是在哪里发生的吗
- 对进一步的调试步骤有什么建议吗?我想我可能不得不下载源代码并在其中重建跟踪(希望StackOverflow能在我到达这一点之前帮助我)
\uuu data.\uu lock
字段(一个int)是0xb086b580。\u计数
(无符号的>整数)为0x6078af00,\u所有者
(整数)为0x6078af00
这听起来好像代码的不同部分对各种结构应该有多大有不同的看法。一些需要检查的事项:
- 是否有任何
可以放大数据结构,但在整个代码库中设置不一致?(在Windows上,#define
因此类漏洞而臭名昭著)\u SECURE\u SCL
- 你们做结构包装吗?如果您在头中的任何位置设置了
,但忘记在头的末尾取消设置,则其后包含的任何数据结构的布局都将与程序中的其他位置不同#pragma pack
静态int实例
,由ifdef boost\u xpressive\u debug\u CYCLE\u TEST
保护。
// out of line members;
// these are the only members that mutate the basic_regex object,
// and are designed to provide the strong exception guarentee
// (in the event of a throw, the state of the object remains unchanged).
//
template <class charT, class traits>
basic_regex<charT, traits>& basic_regex<charT, traits>::do_assign(const charT* p1,
const charT* p2,
flag_type f)
{
shared_ptr<re_detail::basic_regex_implementation<charT, traits> > temp;
if(!m_pimpl.get())
{
temp = shared_ptr<re_detail::basic_regex_implementation<charT, traits> >(new re_detail::basic_regex_implementation<charT, traits>());
}
else
{
temp = shared_ptr<re_detail::basic_regex_implementation<charT, traits> >(new re_detail::basic_regex_implementation<charT, traits>(m_pimpl->m_ptraits));
}
temp->assign(p1, p2, f);
temp.swap(m_pimpl);
return *this;
}
/* Data structures for mutex handling. The structure of the attribute
type is not exposed on purpose. */
typedef union
{
struct __pthread_mutex_s
{
int __lock;
unsigned int __count;
int __owner;
/* KIND must stay at this position in the structure to maintain
binary compatibility. */
int __kind;
unsigned int __nusers;
__extension__ union
{
int __spins;
__pthread_slist_t __list;
};
} __data;
char __size[__SIZEOF_PTHREAD_MUTEX_T];
long int __align;