import inspect
import os
import sys


def find_lldb_root():
    lldb_root = os.path.dirname(inspect.getfile(inspect.currentframe()))
    while True:
        lldb_root = os.path.dirname(lldb_root)
        if lldb_root is None:
            return None

        test_path = os.path.join(lldb_root, "use_lldb_suite_root.py")
        if os.path.isfile(test_path):
            return lldb_root
    return None

lldb_root = find_lldb_root()
if lldb_root is not None:
    import imp
    fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
    try:
        imp.load_module("use_lldb_suite_root", fp, pathname, desc)
    finally:
        if fp:
            fp.close()

import inspect
import os
import sys


def find_lldb_root():
    lldb_root = os.path.dirname(
        os.path.abspath(inspect.getfile(inspect.currentframe()))
    )
    while True:
        lldb_root = os.path.dirname(lldb_root)
        if lldb_root is None:
            return None

        test_path = os.path.join(lldb_root, "use_lldb_suite_root.py")
        if os.path.isfile(test_path):
            return lldb_root
    return None

lldb_root = find_lldb_root()
if lldb_root is not None:
    import imp
    fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
    try:
        imp.load_module("use_lldb_suite_root", fp, pathname, desc)
    finally:
        if fp:
            fp.close()

Modify lldb_suite.py to enable python debugging
Modify lldb_suite.py to enable python debugging

Summary:
pudb and pdb interfere with the behavior of the inspect module. calling
`inspect.getfile(inspect.currentframe())` returns a different result
depending on whether or not you're in a debugger. Calling
`os.path.abspath` on the result of `inspect.getfile(...)` normalizes the
result between the two environments.

Patch by Nathan Lanza <lanza@fb.com>

Differential Revision: https://reviews.llvm.org/D49620

git-svn-id: 4c4cc70b1ef44ba2b7963015e681894188cea27e@338923 91177308-0d34-0410-b5e6-96231b3b80d8

  import inspect
  import os
  import sys
  
  
  def find_lldb_root():
+     lldb_root = os.path.dirname(
-     lldb_root = os.path.dirname(inspect.getfile(inspect.currentframe()))
+         os.path.abspath(inspect.getfile(inspect.currentframe()))
+     )
      while True:
          lldb_root = os.path.dirname(lldb_root)
          if lldb_root is None:
              return None
  
          test_path = os.path.join(lldb_root, "use_lldb_suite_root.py")
          if os.path.isfile(test_path):
              return lldb_root
      return None
  
  lldb_root = find_lldb_root()
  if lldb_root is not None:
      import imp
      fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
      try:
          imp.load_module("use_lldb_suite_root", fp, pathname, desc)
      finally:
          if fp:
              fp.close()
  
Modify lldb_suite.py to enable python debugging
## Code Before:
import inspect
import os
import sys


def find_lldb_root():
    lldb_root = os.path.dirname(inspect.getfile(inspect.currentframe()))
    while True:
        lldb_root = os.path.dirname(lldb_root)
        if lldb_root is None:
            return None

        test_path = os.path.join(lldb_root, "use_lldb_suite_root.py")
        if os.path.isfile(test_path):
            return lldb_root
    return None

lldb_root = find_lldb_root()
if lldb_root is not None:
    import imp
    fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
    try:
        imp.load_module("use_lldb_suite_root", fp, pathname, desc)
    finally:
        if fp:
            fp.close()

## Instruction:
Modify lldb_suite.py to enable python debugging
## Code After:
import inspect
import os
import sys


def find_lldb_root():
    lldb_root = os.path.dirname(
        os.path.abspath(inspect.getfile(inspect.currentframe()))
    )
    while True:
        lldb_root = os.path.dirname(lldb_root)
        if lldb_root is None:
            return None

        test_path = os.path.join(lldb_root, "use_lldb_suite_root.py")
        if os.path.isfile(test_path):
            return lldb_root
    return None

lldb_root = find_lldb_root()
if lldb_root is not None:
    import imp
    fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
    try:
        imp.load_module("use_lldb_suite_root", fp, pathname, desc)
    finally:
        if fp:
            fp.close()
