I want to set a watchpoint on the static local s_db
:
static sqlite3*& GetSqliteDb()
{
static std::once_flag flag;
static sqlite3* s_db = NULL;
std::call_once(flag, []() {
s_db = ...
...
});
}
I've tried setting a watchpoint with file::function::name
, but its giving me trouble:
$ gdb
GNU gdb (GDB) 7.6.2
Copyright (C) 2013 Free Software Foundation, Inc.
...
(gdb) file ./bin/Debug/ac-test
Reading symbols from ...
(gdb) watch ac-sqlite.cpp::GetSqliteDb::s_db
No symbol "ac" in current context.
(gdb) watch "ac-sqlite.cpp::GetSqliteDb::s_db"
Cannot watch constant value `"ac-sqlite.cpp::GetSqliteDb::s_db"'.
(gdb) watch GetSqliteDb()::s_db
A syntax error in expression, near `s_db'.
(gdb) watch GetSqliteDb::s_db
No symbol "s_db" in specified context.
(gdb) watch s_db
No symbol "s_db" in current context.
(gdb)
For completeness, I built with -O0 -g3
, so even symbolic constant names are available.
How do I set a watchpoint for writes on the static local s_db
?
It seems that if I set a watchpoint with a mangled C++ name then everything is OK. If I set a watchpoint with a demangled C++ name then gdb does not find a static varable in a function. This is an example that I tested with gcc and gdb on Windows:
This is nm output:
This is a gdb session:
Update
I tested the same example on RHEL 6.3 (2.6.32-279.el6.x86_64) with gdb 7.6.2 and it sets a watchpoint correctly. So I cannot reproduce the problem on this platform: