• gdb结合valgrind一起使用


    一、简介

            这篇文章使我学习gdb与valgrind一起使用的记录

    二、gdb和valgrind结合使用

           这个是一个例子Use Valgrind, GDB, and vgdb to debug | Red Hat Developer 里面有个简单的示例,这个示例让我看到这个工具挺强大的。

    下面使我代码的结构

    makefile中,记得启用调试选项。

    在一个终端输入:

     valgrind  -q --vgdb-error=0 ./main //成功运行后,会显示pid号

     在另一个终端输入:

    gdb ./main

    成功后

    再输入target remote | vgdb --pid=***

    现在,你就可以愉快的调试了。

    在gdb端,运行,可以看到valgrind 的一些监视器的一些命令

     具体是:

    1. general valgrind monitor commands:
    2. help [debug] : monitor command help. With debug: + debugging commands
    3. v.wait [<ms>] : sleep <ms> (default 0) then continue
    4. v.info all_errors : show all errors found so far
    5. v.info last_error : show last error found
    6. v.info location <addr> : show information about location <addr>
    7. v.info n_errs_found [msg] : show the nr of errors found so far and the given msg
    8. v.info open_fds : show open file descriptors (only if --track-fds=yes)
    9. v.kill : kill the Valgrind process
    10. v.set gdb_output : set valgrind output to gdb
    11. v.set log_output : set valgrind output to log
    12. v.set mixed_output : set valgrind output to log, interactive output to gdb
    13. v.set merge-recursive-frames <num> : merge recursive calls in max <num> frames
    14. v.set vgdb-error <errornr> : debug me at error >= <errornr>
    15. memcheck monitor commands:
    16. xb <addr> [<len>]
    17. prints validity bits for <len> (or 1) bytes at <addr>
    18. bit values 0 = valid, 1 = invalid, __ = unaddressable byte
    19. Then prints the bytes values below the corresponding validity bits
    20. in a layout similar to the gdb command 'x /xb '
    21. Example: xb 0x8049c78 10
    22. get_vbits <addr> [<len>]
    23. Similar to xb, but only prints the validity bytes by group of 4.
    24. make_memory [noaccess|undefined
    25. |defined|Definedifaddressable] <addr> [<len>]
    26. mark <len> (or 1) bytes at <addr> with the given accessibility
    27. check_memory [addressable|defined] <addr> [<len>]
    28. check that <len> (or 1) bytes at <addr> have the given accessibility
    29. and outputs a description of <addr>
    30. leak_check [full*|summary|xtleak]
    31. [kinds kind1,kind2,...|reachable|possibleleak*|definiteleak]
    32. [heuristics heur1,heur2,...]
    33. [increased*|changed|any]
    34. [unlimited*|limited <max_loss_records_output>]
    35. * = defaults
    36. xtleak produces an xtree full leak result in xtleak.kcg.%p.%n
    37. where kind is one of:
    38. definite indirect possible reachable all none
    39. where heur is one of:
    40. stdstring length64 newarray multipleinheritance all none*
    41. Examples: leak_check
    42. leak_check summary any
    43. leak_check full kinds indirect,possible
    44. leak_check full reachable any limited 100
    45. block_list <loss_record_nr>|<loss_record_nr_from>..<loss_record_nr_to>
    46. [unlimited*|limited <max_blocks>]
    47. [heuristics heur1,heur2,...]
    48. after a leak search, shows the list of blocks of <loss_record_nr>
    49. (or of the range <loss_record_nr_from>..<loss_record_nr_to>).
    50. With heuristics, only shows the blocks found via heur1,heur2,...
    51. * = defaults
    52. who_points_at <addr> [<len>]
    53. shows places pointing inside <len> (default 1) bytes at <addr>
    54. (with len 1, only shows "start pointers" pointing exactly to <addr>,
    55. with len > 1, will also show "interior pointers")
    56. xtmemory [<filename>]
    57. dump xtree memory profile in <filename> (default xtmemory.kcg.%p.%n)
    58. 给我解释一下,仔细的解释

     使用方式,比如:

     monitor v.info last_error

  • 相关阅读:
    【轻量化网络】MobileNet系列
    Django思维导图-路由
    MySQL in和exists 查询分析
    TypeScript中的Symbol,确实唯一。。。
    前端Vue小兔鲜儿电商项目实战Day07
    外国固定资产管理系统功能有哪些
    python使用清华源下载包
    cs231n--深度学习训练方法
    ROS1云课→19仿真turtlebot(stage)
    Dijkstra算法基础详解,附有练习题
  • 原文地址:https://blog.csdn.net/weixin_46430043/article/details/132561206