title: Log whether a global variable has been read or written
body: <h2><strong>Requirement:</strong></h2>
  
  <p>Given a C program I have to identify whether the functions accessing global variables are reading them or writing them.</p>
  
  <p><strong>Example code:</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  /* global variable declaration */
  int g = 20;
  
  int main()
  {
  
      /* writing the global variable */
      g = 10;
  
      /* reading the global variable */
      printf ("value of g = %d\n",  g);
  
      return 0;
  }
  </code></pre>
  
  <p>Executing the above code I want to generate a log file in the below format:</p>
  
  <pre><code>1- Global variable a written in function main() "TIME_STAMP"
  2- Global variable a read in function main() "TIME_STAMP"
  </code></pre>
  
  <hr>
  
  <h2>Research:</h2>
  
  <p>I am cetainly able to acheive this by doing a static analysis of source code as per below logic:</p>
  
  <ul>
  <li>Go through the c code and identify the statements where the global
  variable is read. </li>
  <li>Then analysis the c code statement to identify if
  it is a read or write statement.(Checking if ++ or -- operator is
  used with global variable or any assignemnt has been made to the
  global variable)</li>
  <li>Add a log statement above the identified statement which will execute
  along with this statement execution.</li>
  </ul>
  
  <p>This is not a proper implementation.</p>
  
  <p><strong>Some studies:</strong></p>
  
  <p>I have gone through how debuggers are able to capture information.</p>
  
  <p>Some links in the internet:
  <a href="https://stackoverflow.com/questions/8004945/how-to-catch-a-memory-write-and-call-function-with-address-of-write">How to catch a memory write and call function with address of write</a></p>