<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Approximatrix Forums — Debugging. Variables in the stack frame (activation record).]]></title>
		<link>http://forums.approximatrix.com/viewtopic.php?id=428</link>
		<atom:link href="http://forums.approximatrix.com/extern.php?action=feed&amp;tid=428&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Debugging. Variables in the stack frame (activation record)..]]></description>
		<lastBuildDate>Thu, 29 Jan 2015 13:19:54 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Debugging. Variables in the stack frame (activation record).]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=1859#p1859</link>
			<description><![CDATA[<p>David,</p><p>You are correct, it wasn&#039;t scoping the variables.&nbsp; However, the debugger seems to have issues with these scoped arrays.&nbsp; When you request a list of local variables from the debugger within <em>yyy</em>, the debugger responds with 3:</p><ul><li><p>a</p></li><li><p>b</p></li><li><p>x.0</p></li></ul><p>The first two, being scalars, are as one would expect.&nbsp; The third, however, is a memory reference to the beginning of the <em>x</em> array.&nbsp; Simply Fortran currently filters and drops these as they are not &quot;useful.&quot;&nbsp; &nbsp;If, using the GNU Debugger command line, one were to request the value of <em>x.0</em>, the debugger will either refuse or it will provide the hexadecimal memory location.&nbsp; If, again using the GNU Debugger command line, one were to request the value of <em>x</em>, the debugger will show:</p><div class="codebox"><pre><code>numchild=&quot;0&quot;,value=&quot;[0]&quot;,type=&quot;real(kind=4) (*)&quot;</code></pre></div><p>The above is not only useless, but also incorrect.&nbsp; </p><p>I believe what you&#039;re seeing is a result of the not-so-perfect support for the Fortran language in the GNU Debugger.&nbsp; It seems to be having difficulties with subroutines/functions embedded within other subroutines/functions.&nbsp; </p><p>However, this might also be a result of the Fortran compiler itself. I base this on the fact that the debugger sees the subroutine as <em>foo::yyy</em>, implying that the owner of <em>yyy</em> is the module <em>foo</em> rather than the subroutine <em>foo::xxx</em>.&nbsp; The compiler may either be transforming the subroutines internally or emitting mildly incorrect debugger information that is subsequently confusing the debugger itself.</p><p>The third possibility, and, as I type this, I think it could be correct, is that the compiler is far smarter than you or I are giving it credit for.&nbsp; It may be seeing that <em>yyy</em> is only using <em>x(1)</em> and is delivering only that value as a local through the artificial <em>x.0</em>.&nbsp; Even with debugging-safe optimizations or no optimizations, the compiler will still take some steps to &quot;optimize&quot;&nbsp; away variables.</p><p>I&#039;ll look into this issue further.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Thu, 29 Jan 2015 13:19:54 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=1859#p1859</guid>
		</item>
		<item>
			<title><![CDATA[Re: Debugging. Variables in the stack frame (activation record).]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=1853#p1853</link>
			<description><![CDATA[<div class="quotebox"><cite>jeff wrote:</cite><blockquote><p>The behavior you&#039;re seeing in both examples is most likely because the debugger&#039;s Variables list is showing &quot;local&quot; variables rather than &quot;in-scope&quot; variables.&nbsp; In your second example, the variable <em>x</em> is clearly visible inside <em>quick_sort</em>, but it isn&#039;t local to <em>quick_sort</em>.&nbsp; Therefore, it simply will not appear in the Variables list.</p></blockquote></div><p>Unfortunately you are mistaken and this is not how it is working.</p><p>In the following code if you break on the line <strong>print, * a</strong> inside yyy you will see that variable <em>a</em> <strong>is listed</strong> (despite the fact it is not local to yyy) but array <em>x</em> <strong>is not listed</strong>. So there is an inconsistency here which is not explained by your comment above and probably needs to be.</p><p>When I have been debugging my real codes I am finding that sometimes I can see host variables and sometimes I cannot.</p><p>I would urge you to look again and see if you might missed something. </p><p>I am not suggesting you make any big changes here just look and see if the variable <em>x</em> should be listed in the same way as <em>a</em> or at least explain why this inconsistency exists.</p><div class="codebox"><pre><code>module foo
   implicit none   
contains
   subroutine xxx(x)
      real, intent(inout) :: x(:)
      real :: a
      a = 1.0
      call yyy(2.0)
   contains
      recursive subroutine yyy(b)
         real, intent(in) :: b
         print *, a
         print *, b
         print *, x(1)
      end subroutine yyy
   end subroutine xxx
end module foo

program main
   use foo
   real :: x(100)
   x = (/(real(i), i=1, 100)/)
   call xxx(x)
end program main</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (davidb)]]></author>
			<pubDate>Wed, 28 Jan 2015 18:42:13 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=1853#p1853</guid>
		</item>
		<item>
			<title><![CDATA[Re: Debugging. Variables in the stack frame (activation record).]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=1849#p1849</link>
			<description><![CDATA[<p>David,</p><p>The behavior you&#039;re seeing in both examples is most likely because the debugger&#039;s Variables list is showing &quot;local&quot; variables rather than &quot;in-scope&quot; variables.&nbsp; In your second example, the variable <em>x</em> is clearly visible inside <em>quick_sort</em>, but it isn&#039;t local to <em>quick_sort</em>.&nbsp; Therefore, it simply will not appear in the Variables list.</p><p>If the debugger did list &quot;in-scope&quot; variables, you&#039;d also see things like public module variables and global variables within functions and subroutines.&nbsp; I can see how that feature, as an option, would be useful.&nbsp; However, it would be considerably more difficult to implement due to how Simply Fortran interfaces with the GNU Debugger.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Wed, 28 Jan 2015 12:56:58 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=1849#p1849</guid>
		</item>
		<item>
			<title><![CDATA[Re: Debugging. Variables in the stack frame (activation record).]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=1848#p1848</link>
			<description><![CDATA[<p>... however, I don&#039;t know why the variable x isn&#039;t listed when I step into the <strong>quick_sor</strong>t subroutine in the following example.</p><p>Unless dummy arguments in the host subroutine/function are somehow being missed?</p><div class="codebox"><pre><code>module sorting
   implicit none   
contains
   subroutine sort(x)
      real, intent(inout) :: x(:)
      call quick_sort(1,size(x))
   contains
      recursive subroutine quick_sort(l, u)
         integer, intent(in) :: l, u
         integer :: m
         m = (l+u)/2
         print *, x(l), x(u), x(m)
         ! ... the rest of subroutine is omitted 
      end subroutine quick_sort
   end subroutine sort
end module sorting

program main
   use sorting
   real :: x(100)
   x = (/(real(i), i=1, 100)/)
   call sort(x)
end program main</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (davidb)]]></author>
			<pubDate>Wed, 28 Jan 2015 07:32:35 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=1848#p1848</guid>
		</item>
		<item>
			<title><![CDATA[Debugging. Variables in the stack frame (activation record).]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=1844#p1844</link>
			<description><![CDATA[<p>At first I thought this was a subtle bug in the debugger but now I think it is a feature which is possibly quite helpful (and might even be improved upon -- see later).</p><p>The following code uses adaptive trapezoidal rule to integrate sin(x) between 0 and pi/2 (of course the result should be 1.0). The main function <strong>integrate</strong> calls a recursive subroutine <strong>trapezium</strong> which calls itself to sub-divide the integral interval to achieve a specific tolerance on the result.</p><p>The <strong>trapezium</strong> subroutine is an internal subroutine to <strong>integrate</strong>. The function <strong>integrate</strong> is the host of subroutine <strong>trapezium</strong>. Variables declared in <strong>integrate</strong> are in scope (may be referenced) when <strong>trapezium</strong> is called (both initially and for subsequent recursive calls).</p><p>When stepping into <strong>trapezium</strong> in the debugger I note that:</p><p>- Host variables <em>min_interval</em> and <em>integrate</em> (the result variable) are listed in the variables panel.<br />- The other host variables, <em>fnc_lower</em>, <em>fnc_upper</em>, <em>lower</em>, <em>upper</em>, <em>tolerance</em> are not listed.<br />- Host variable <em>tol</em> is not listed but is, in any case, hidden by the local variable of the same name.</p><p>It seems then that host variables are only listed if they are in scope <span class="bbu">and</span> are actually referenced in <strong>trapezium</strong>.<br />This is potentially useful I think.</p><div class="codebox"><pre><code>module quad
   implicit none
   
contains

   function f(x)
      real, intent(in) :: x
      real :: f
      f = sin(x)
   end function f

   function integrate(lower, upper, tolerance)
      real, intent(in) :: lower, upper, tolerance
      real :: integrate, fnc_lower, fnc_upper, min_interval, tol
      min_interval = (upper - lower)/100.0
      fnc_lower = f(lower)
      fnc_upper = f(upper)
      integrate = 0.0
      tol = tolerance
      call trapezium(lower, upper, fnc_lower, fnc_upper, tol)
   contains
      recursive subroutine trapezium(a, b, fna, fnb, tol)
         real, intent(in) :: a, b, fna, fnb, tol
         real :: c, fnc, area1, area2, error
         c = 0.5*(a + b)
         fnc = f(c)
         area1 = 0.5*(fna + fnb)*(b - a)
         area2 = 0.25*(fna + 2.0*fnc + fnb)*(b - a)
         error = (area2 - area1)/3.0
         if (abs(error) &lt; tol .or. b - a &lt; min_interval) then
            integrate = integrate + area2 + error
         else
            call trapezium(a, c, fna, fnc, 0.5*tol)
            call trapezium(c, b, fnc, fnb, 0.5*tol)
         end if
      end subroutine trapezium
   end function integrate
end module quad

program main
   use quad
   real :: pi, area
   pi = 4.0*atan(1.0)
   area = integrate(0.0, pi/2.0, 1.0e-5)
   print *,&#039;Area under curve = &#039;, area
end program main</code></pre></div><p>Now, the missing host variables can be listed by switching to the stack list in the panels window, selecting <strong>integrate</strong> and then switching back to the variables list.</p><p>This is OK, but I wonder if it could be improved upon by allowing the variables from two or more stack frames to be seen at the same time? My simplest view of this is to give access to up to 4 left-hand panels (tiled on top of each other) which users can configure as they see fit.</p><p>Views on this are sought.</p>]]></description>
			<author><![CDATA[null@example.com (davidb)]]></author>
			<pubDate>Tue, 27 Jan 2015 08:42:47 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=1844#p1844</guid>
		</item>
	</channel>
</rss>
