如何在gdb中运行程序中更改std :: map?

时间:2016-05-24 14:15:40

标签: c++ gdb

我有程序使用一些'Log'类进行日志记录。其中有一个静态变量,其中日志级别为。

class Log
{
private:
    static LogFilter filter;
    ....

LogFilter内置std::map,其中存储了特定的日志级别

class LogFilter
{
public:
    LogFilter();

    void setLevel(LogEntryClass::EntryClass e, int level);
    int getLevel(LogEntryClass::EntryClass e);

private:
    std::map<LogEntryClass::EntryClass, int> filter;
};

LogEntryClass是一个内部有EntryClass枚举的类。

class LogEntryClass
{
public:
    enum EntryClass
    {
        UndefinedLog = 0,
        ErrorLog,
        WarningLog,
        EventLog,
        InfoLog,
        DebugLog,
        UserLog,
        CoreInfoLog,
        CoreErrorLog,
        CoreDebugLog
    };    
    static std::string toString(const EntryClass& e);
};

日志级别在程序启动时从配置文件设置。但现在我想在程序运行时更改日志级别。我可以从gdb和打印日志级别附加到它,但我不知道如何更改该映射中的值

(gdb) print Log::filter.filter
$46 = std::map with 9 elements = {[LogEntryClass::ErrorLog] = 15, [LogEntryClass::WarningLog] = 15, 
  [LogEntryClass::EventLog] = 15, [LogEntryClass::InfoLog] = 15, [LogEntryClass::DebugLog] = 15, [LogEntryClass::UserLog] = 15, 
  [LogEntryClass::CoreInfoLog] = 0, [LogEntryClass::CoreErrorLog] = 0, [LogEntryClass::CoreDebugLog] = 0}

即使我带了_M_t地图成员,我也看不到它的数据在哪里:

(gdb) print Log::filter.filter._M_t
$47 = {
  _M_impl = {<std::allocator<std::_Rb_tree_node<std::pair<LogEntryClass::EntryClass const, int> > >> = {<__gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<LogEntryClass::EntryClass const, int> > >> = {<No data fields>}, <No data fields>}, 
    _M_key_compare = {<std::binary_function<LogEntryClass::EntryClass, LogEntryClass::EntryClass, bool>> = {<No data fields>}, <No data fields>}, _M_header = {_M_color = std::_S_red, _M_parent = 0xa04b70, _M_left = 0xa04cf0, _M_right = 0xa04c00}, 
    _M_node_count = 9}}


(gdb) print Log::filter.filter._M_t._M_impl
$48 = {<std::allocator<std::_Rb_tree_node<std::pair<LogEntryClass::EntryClass const, int> > >> = {<__gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<LogEntryClass::EntryClass const, int> > >> = {<No data fields>}, <No data fields>}, 
  _M_key_compare = {<std::binary_function<LogEntryClass::EntryClass, LogEntryClass::EntryClass, bool>> = {<No data fields>}, <No data fields>}, _M_header = {_M_color = std::_S_red, _M_parent = 0xa04b70, _M_left = 0xa04cf0, _M_right = 0xa04c00}, _M_node_count = 9}

我无法调用任何map方法

(gdb) print Log::filter.filter.begin()
One of the arguments you tried to pass to begin could not be converted to what the function wants.
(gdb) print Log::filter.filter.at(1)
One of the arguments you tried to pass to at could not be converted to what the function wants.

我需要的是更新map中的一个整数值。有没有办法,甚至任何丑陋的黑客?

0 个答案:

没有答案