In WinDbg commands, how can I refer to a register with the same name as a global variable?
<p>Suppose I want to debug this program using the WinDbg, cdb, or ntsd debuggers for Windows:</p>

<pre><code>/* test.c */
#include &lt;stdio.h&gt;

int rip = 42;

int main(void)
{
    puts("Hello world!");
    return (0);
}
</code></pre>

<p>I compile the program for AMD64 and run it under WinDbg. I set a breakpoint at main(), and when the breakpoint hits, I want to inspect the value at the RIP register (program counter), and the memory around that value if the value is treated as a pointer.</p>

<p>I can see the value of the register directly with <code>r rip</code>, but when I try to look at the memory around that address, WinDbg shows me a different address! Having read the symbols in test.pdb, WinDbg sees that <code>rip</code> is a global variable declared in the C code and shows me the memory around <code>&amp;rip</code>.</p>

<pre><code>0:000&gt; bu test!main

0:000&gt; g
Breakpoint 0 hit
test!main:
00007ff6`de1868d0 4883ec28        sub     rsp,28h

0:000&gt; r rip
rip=00007ff6de1868d0

0:000&gt; db rip
00007ff6`de1f2000  2a 00 00 00 ff ff ff ff-01 00 00 00 00 00 00 00  *...............
00007ff6`de1f2010  01 00 00 00 02 00 00 00-ff ff ff ff ff ff ff ff  ................
00007ff6`de1f2020  00 00 00 00 00 00 00 00-43 46 92 e5 1b df 00 00  ........CF......
00007ff6`de1f2030  bc b9 6d 1a e4 20 ff ff-00 00 00 00 00 00 00 00  ..m.. ..........
00007ff6`de1f2040  00 01 00 00 00 00 00 00-ca b0 1e de f6 7f 00 00  ................
00007ff6`de1f2050  00 00 00 00 00 80 00 00-00 00 00 00 00 80 00 00  ................
00007ff6`de1f2060  d0 66 fc c2 f2 01 03 00-ab 90 ec 5e 22 c0 b2 44  .f.........^"..D
00007ff6`de1f2070  a5 dd fd 71 6a 22 2a 15-00 00 00 00 00 00 00 00  ...qj"*.........

0:000&gt; ? rip
Evaluate expression: 140698265264128 = 00007ff6`de1f2000

0:000&gt; ? dwo(rip)
Evaluate expression: 42 = 00000000`0000002a
</code></pre>

<p>This is really annoying, but as long as I'm aware of it, it isn't a problem when manually reading data like this. But if I want to <em>use</em> the register value, for example in scripting the debugger, then there is no easy workaround:</p>

<pre><code>0:000&gt; bu test!main ".if (dwo(rip) == 0n42) { .echo Whoops! I don't want to get here! }"

0:000&gt; g
Whoops! I don't want to get here!
test!main:
00007ff6`de1868d0 4883ec28        sub     rsp,28h
</code></pre>

<p>This problem, that symbols in the program hide register names, makes things really difficult for me. An actual scenario this broke:</p>

<ol>
<li>I wanted to set a breakpoint on CreateFileW(), a very commonly called Windows API function.</li>
<li>Since I only cared about one particular file, I wanted to inspect the filename, which is passed in the RCX register, and continue past the breakpoint unless the filename matched the file I wanted.</li>
<li>But I couldn't write this condition, because another module in the program defined a symbol <code>foobar!rcx</code>, and any references to <code>rcx</code> I make in the command to execute on the breakpoint refer to that global variable!</li>
</ol>

<p>So how do I tell WinDbg that yes, I really meant to read the register? And what if I want to write that register? There must be a simple thing I am missing here.</p>