title: Calling a function as a go routine produces different call stack from go routine as anonymous func
body: <p>I have a function named PrintCaller() which calls runtime.Caller() and skipping one frame to obtain and print the callers (of PrintCaller's) file name and line number. This works as expected when ran synchronously, and if called asynchronous as an anonymous function. However, if ran with just the <code>go</code> keyword, the stack frame of the caller is replaced with some internal function call.</p>
  <p>For example, this is the function:</p>
  <pre><code>func printCaller(wait chan bool) {
      _, fileName, line, _ := runtime.Caller(1)
      fmt.Printf(&quot;Filename: %s, line: %d\n&quot;, fileName, line)
  }
  </code></pre>
  <p>If I call is like this:</p>
  <pre><code>func main() {
      printCaller()
      go func(){printCaller()}()
      go printCaller()
  }
  </code></pre>
  <p>The output is:</p>
  <pre><code>Filename: /tmp/sandbox297971268/prog.go, line: 19
  Filename: /tmp/sandbox297971268/prog.go, line: 22
  Filename: /usr/local/go-faketime/src/runtime/asm_amd64.s, line: 1374
  </code></pre>
  <p>Working example here: <a href="https://play.golang.org/p/Jv21SVDY2Ln" rel="nofollow noreferrer">https://play.golang.org/p/Jv21SVDY2Ln</a></p>
  <p>Why does this happen when I call <code>go PrintCaller()</code>, but not when I call <code>go func(){PrintCaller()}()</code>? Also, is there any way to make this work using <code>go PrintCaller()</code>?</p>