当前位置:网站首页>GDB debugging container and command saving

GDB debugging container and command saving

2022-06-24 04:59:00 mariolu

One 、gdb Debug the contents of the container or smart pointer

Sometimes we need debug some core A document or program , But if you meet STL Containers ,p What is printed out is some red black trees or original data organizations , This brings us unnecessary trouble in debugging .

gdb Built in Python Support , So it's easy to write a function to print out any stl The content of the structure .gcc 4.5 The required... Has been provided python Script , In order to make gdb Intelligently handle stl data structure .

https://gist.github.com/skyscribe/3978082 A script like this provides some macros for print containers , Or here :http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt

With these macros , You can print out the response container

wget http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt
cat dbinit_stl_views-1.03.txt >> ~/.gdbinit

#       std::vector<T> -- via pvector command
#       std::list<T> -- via plist or plist_member command
#       std::map<T,T> -- via pmap or pmap_member command
#       std::multimap<T,T> -- via pmap or pmap_member command
#       std::set<T> -- via pset command
#       std::multiset<T> -- via pset command
#       std::deque<T> -- via pdequeue command
#       std::stack<T> -- via pstack command
#       std::queue<T> -- via pqueue command
#       std::priority_queue<T> -- via ppqueue command
#       std::bitset<n> -- via pbitset command
#       std::string -- via pstring command
#       std::widestring -- via pwstring command

We can put these in ~/.gdbinit In file . stay gdb When debugging , Use source ~/.gdbinit Load these macro actions .

If your gdb In operation , You need to restart and enable , These macros take effect .

Read these code macros , It can also help you understand stl structure .

By the way , stay ~/.gdbinit You can put in some of your common gdb Set command . for instance

set print elements 0  // Set to print all elements 
set print pretty on  // Printing structure format is more intuitive 
set print object on
set print static-members on
set print vtbl on
set print demangle on
set demangle-style gnu-v3
set print sevenbit-strings off

Two 、gdb Debugging history saving

Another useful thing is to save gdb Commissioning history ,set history save on A related command is set history remove-duplicates <count>. The order is “ Controls the deletion of duplicate history entries in the command history list . If the count is not zero ,gdb The last counted history entries will be reviewed and the first entry that duplicates the current entry will be deleted . Add to the command history list . If the count is unlimited , Then the hindsight is unbounded . If the count is 0, The deletion of duplicate history entries is disabled ". set history remove-duplicates <count> By default ,gdb Save history to... In the current directory ./.gdb_history In file . If you want the command history to be independent of the directory you are in , Need to include : set history filename ~/.gdb_history

原网站

版权声明
本文为[mariolu]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/08/20210831000344648j.html