dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: How to find where a variable takes value? gdb - watch- is time consuming, ineffective

  1. #1
    Join Date
    Jun 2015
    Posts
    19

    How to find all assignments the values to variables,by '=' or by func or as ref value

    How to find where a variable takes value (preferably c++ source and grep,awk&sed and regex tools, variable is Integer,char* and string can get value by =, or arbitrary function without =)

    -We're dealing with a great deal of code and watch- in debugger- can be done but in many cases it is time consuming and ineffective.
    for direct assignments we can write:

    $grep -nE '^\s*i\s*=' directory_of_code | grep -v '=='
    Last edited by alwaystudent; August 9th, 2019 at 06:48 AM. Reason: misspelling

  2. #2
    Join Date
    Jan 2015
    Posts
    14

    Re: How to find where a variable takes value? gdb - watch- is time consuming, ineffec

    What is making using the debugger so difficult? Do you have extremely large functions? Quite a few global variables? Both?

  3. #3
    Join Date
    Jun 2015
    Posts
    19

    Re: How to find where a variable takes value? gdb - watch- is time consuming, ineffec

    Quote Originally Posted by jlb1 View Post
    What is making using the debugger so difficult? Do you have extremely large functions? Quite a few global variables? Both?
    In fact,both of them, but let me explain my request,
    Is there any static code analysing tool to make file base on source, to give us where a variable takes value

  4. #4
    Join Date
    Jan 2015
    Posts
    14

    Re: How to find where a variable takes value? gdb - watch- is time consuming, ineffec

    In fact,both of them
    Then perhaps you should work on fixing these issues. If you eliminate the global variables and properly pass variables back and forth to your functions as required you will find that locating where a variable gets changed will get orders of magnitude easier. Also if your functions are small doing one thing well you will find that they will not need so many parameters and will be much easier to debug.

    Is there any static code analysing tool to make file base on source, to give us where a variable takes value
    Probably, you mentioned grep, what do you find that is lacking with this tool. It should be able to show every location where a variable is referenced.

  5. #5
    Join Date
    Jun 2015
    Posts
    19

    Re: How to find where a variable takes value? gdb - watch- is time consuming, ineffec

    ,for simple case, the direct assignments we have:
    grep -nE '^\s*i\s*=' directory_of_code | grep -v '=='

  6. #6
    Join Date
    Jan 2015
    Posts
    14

    Re: How to find where a variable takes value? gdb - watch- is time consuming, ineffec

    That really doesn't answer the question of "what do you find that is lacking with this tool".

    But if you're looking to see where a particular variable is possibly being changed I would expect to see a variable name somewhere in your grep expression.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)